Show biometric-specific dialog when appropriate

1) We need to pass a "restriction" string from settings to the dialog,
   otherwise the biometric dialog could be shown in non-biometric
   flows
2) Updates ActionDisabledByAdminDialogHelper to pass the restrition
   to be taken into consideration when creating the controller
3) Sets an optional onClickListener on the positive button.

Bug: 5788943
Test: atest ParentalControlsUtilsTest
Change-Id: Iedff7fef50e186b2779f061f37d3080c910d2179
This commit is contained in:
Kevin Chyn
2021-06-15 13:34:11 -07:00
parent fc19953d28
commit 0c34d259a0
4 changed files with 16 additions and 5 deletions

View File

@@ -22,6 +22,7 @@ import android.content.Context;
import android.hardware.biometrics.BiometricAuthenticator;
import android.hardware.biometrics.ParentalControlsUtilsInternal;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.Log;
import androidx.annotation.NonNull;
@@ -49,7 +50,8 @@ public class ParentalControlsUtils {
final UserHandle userHandle = new UserHandle(UserHandle.myUserId());
if (ParentalControlsUtilsInternal.isTestModeEnabled(context)) {
Log.d(TAG, "Requiring consent for test flow");
return new RestrictedLockUtils.EnforcedAdmin(null /* ComponentName */, userHandle);
return new RestrictedLockUtils.EnforcedAdmin(null /* ComponentName */,
UserManager.DISALLOW_BIOMETRIC, userHandle);
}
final DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class);
@@ -69,7 +71,8 @@ public class ParentalControlsUtils {
userHandle)) {
final ComponentName cn =
ParentalControlsUtilsInternal.getSupervisionComponentName(dpm, userHandle);
return new RestrictedLockUtils.EnforcedAdmin(cn, userHandle);
return new RestrictedLockUtils.EnforcedAdmin(cn, UserManager.DISALLOW_BIOMETRIC,
userHandle);
} else {
return null;
}

View File

@@ -37,7 +37,7 @@ public class ActionDisabledByAdminDialog extends Activity
final RestrictedLockUtils.EnforcedAdmin enforcedAdmin =
getAdminDetailsFromIntent(getIntent());
final String restriction = getRestrictionFromIntent(getIntent());
mDialogHelper = new ActionDisabledByAdminDialogHelper(this);
mDialogHelper = new ActionDisabledByAdminDialogHelper(this, restriction);
mDialogHelper.prepareDialogBuilder(restriction, enforcedAdmin)
.setOnDismissListener(this)
.show();

View File

@@ -56,11 +56,16 @@ public final class ActionDisabledByAdminDialogHelper {
private final Activity mActivity;
public ActionDisabledByAdminDialogHelper(Activity activity) {
this(activity, null /* restriction */);
}
public ActionDisabledByAdminDialogHelper(Activity activity, String restriction) {
mActivity = activity;
mDialogView = (ViewGroup) LayoutInflater.from(mActivity).inflate(
R.layout.admin_support_details_dialog, null);
mActionDisabledByAdminController = ActionDisabledByAdminControllerFactory
.createInstance(mActivity, new DeviceAdminStringProviderImpl(mActivity));
.createInstance(mActivity, restriction,
new DeviceAdminStringProviderImpl(mActivity));
}
private @UserIdInt int getEnforcementAdminUserId(@NonNull EnforcedAdmin admin) {
@@ -74,7 +79,8 @@ public final class ActionDisabledByAdminDialogHelper {
public AlertDialog.Builder prepareDialogBuilder(String restriction,
EnforcedAdmin enforcedAdmin) {
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity)
.setPositiveButton(R.string.okay, null)
.setPositiveButton(R.string.okay,
mActionDisabledByAdminController.getPositiveButtonListener())
.setView(mDialogView);
prepareDialogBuilder(builder, restriction, enforcedAdmin);
return builder;

View File

@@ -35,6 +35,7 @@ import static android.hardware.biometrics.BiometricAuthenticator.TYPE_IRIS;
import android.hardware.biometrics.BiometricAuthenticator;
import android.os.UserHandle;
import android.os.UserManager;
import androidx.annotation.Nullable;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -92,6 +93,7 @@ public class ParentalControlsUtilsTest {
mSupervisionComponentName, tests[i][0] /* modality */,
tests[i][1] /* keyguardDisableFlags */);
assertNotNull(admin);
assertEquals(UserManager.DISALLOW_BIOMETRIC, admin.enforcedRestriction);
assertEquals(mSupervisionComponentName, admin.component);
}
}