diff --git a/src/com/android/settings/biometrics/BiometricEnrollIntroduction.java b/src/com/android/settings/biometrics/BiometricEnrollIntroduction.java index db2f2913342..8634441e9bb 100644 --- a/src/com/android/settings/biometrics/BiometricEnrollIntroduction.java +++ b/src/com/android/settings/biometrics/BiometricEnrollIntroduction.java @@ -164,7 +164,7 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase // No password registered, launch into enrollment wizard. mConfirmingCredentials = true; launchChooseLock(); - } else if (mToken == null) { + } else if (!BiometricUtils.containsGatekeeperPassword(getIntent()) && mToken == null) { // It's possible to have a token but mLaunchedConfirmLock == false, since // ChooseLockGeneric can pass us a token. mConfirmingCredentials = true; diff --git a/src/com/android/settings/biometrics/face/FaceEnrollIntroduction.java b/src/com/android/settings/biometrics/face/FaceEnrollIntroduction.java index 378a3c12f5d..3db51fec4c7 100644 --- a/src/com/android/settings/biometrics/face/FaceEnrollIntroduction.java +++ b/src/com/android/settings/biometrics/face/FaceEnrollIntroduction.java @@ -46,19 +46,9 @@ public class FaceEnrollIntroduction extends BiometricEnrollIntroduction { @Override protected void onCreate(Bundle savedInstanceState) { - mFaceManager = Utils.getFaceManagerOrNull(this); - // Check if the Gateekeper Password exists. If so, request for a Gatekeeper HAT to be - // created. This needs to be cleaned up, since currently it's not very clear which - // superclass is responsible for what. Doing the check here is the least risky way. - if (mToken == null && BiometricUtils.containsGatekeeperPassword(getIntent())) { - // We either block on generateChallenge, or need to gray out the "next" button until - // the challenge is ready. Let's just do this for now. - final long challenge = mFaceManager.generateChallengeBlocking(); - mToken = BiometricUtils.requestGatekeeperHat(this, getIntent(), mUserId, challenge); - } - super.onCreate(savedInstanceState); + mFaceManager = Utils.getFaceManagerOrNull(this); mFaceFeatureProvider = FeatureFactory.getFactory(getApplicationContext()) .getFaceFeatureProvider(); @@ -106,6 +96,18 @@ public class FaceEnrollIntroduction extends BiometricEnrollIntroduction { ? R.string.security_settings_face_enroll_introduction_footer_part_2 : R.string.security_settings_face_settings_footer_attention_not_supported; footer2.setText(footer2TextResource); + + // This path is an entry point for SetNewPasswordController, e.g. + // adb shell am start -a android.app.action.SET_NEW_PASSWORD + if (mToken == null && BiometricUtils.containsGatekeeperPassword(getIntent())) { + mFooterBarMixin.getPrimaryButton().setEnabled(false); + // We either block on generateChallenge, or need to gray out the "next" button until + // the challenge is ready. Let's just do this for now. + mFaceManager.generateChallenge(challenge -> { + mToken = BiometricUtils.requestGatekeeperHat(this, getIntent(), mUserId, challenge); + mFooterBarMixin.getPrimaryButton().setEnabled(true); + }); + } } @Override diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensor.java b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensor.java index 00fdb0ae4f7..8795f7f6f5b 100644 --- a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensor.java +++ b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensor.java @@ -61,19 +61,25 @@ public class FingerprintEnrollFindSensor extends BiometricEnrollBase { setHeaderText(R.string.security_settings_fingerprint_enroll_find_sensor_title); + // This is an entry point for SetNewPasswordController, e.g. + // adb shell am start -a android.app.action.SET_NEW_PASSWORD if (mToken == null && BiometricUtils.containsGatekeeperPassword(getIntent())) { final FingerprintManager fpm = getSystemService(FingerprintManager.class); - final long challenge = fpm.generateChallengeBlocking(); - mToken = BiometricUtils.requestGatekeeperHat(this, getIntent(), mUserId, challenge); + fpm.generateChallenge(challenge -> { + mToken = BiometricUtils.requestGatekeeperHat(this, getIntent(), mUserId, challenge); - // Put this into the intent. This is really just to work around the fact that the - // enrollment sidecar gets the HAT from the activity's intent, rather than having - // it passed in. - getIntent().putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken); + // Put this into the intent. This is really just to work around the fact that the + // enrollment sidecar gets the HAT from the activity's intent, rather than having + // it passed in. + getIntent().putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken); + + startLookingForFingerprint(); + }); + } else if (mToken != null) { + // HAT passed in from somewhere else, such as FingerprintEnrollIntroduction + startLookingForFingerprint(); } - startLookingForFingerprint(); // already confirmed, so start looking for fingerprint - View animationView = findViewById(R.id.fingerprint_sensor_location_animation); if (animationView instanceof FingerprintFindSensorAnimation) { mAnimation = (FingerprintFindSensorAnimation) animationView; diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java b/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java index 3eaf506f44d..a2d67f41d86 100644 --- a/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java +++ b/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java @@ -411,6 +411,8 @@ public class FingerprintSettings extends SubSettings { private void updateAddPreference() { if (getActivity() == null) return; // Activity went away + final Preference addPreference = findPreference(KEY_FINGERPRINT_ADD); + /* Disable preference if too many fingerprints added */ final int max = getContext().getResources().getInteger( com.android.internal.R.integer.config_fingerprintMaxTemplatesPerUser); @@ -420,9 +422,8 @@ public class FingerprintSettings extends SubSettings { final boolean removalInProgress = mRemovalSidecar.inProgress(); CharSequence maxSummary = tooMany ? getContext().getString(R.string.fingerprint_add_max, max) : ""; - Preference addPreference = findPreference(KEY_FINGERPRINT_ADD); addPreference.setSummary(maxSummary); - addPreference.setEnabled(!tooMany && !removalInProgress); + addPreference.setEnabled(!tooMany && !removalInProgress && mToken != null); } private void createFooterPreference(PreferenceGroup root) { @@ -569,11 +570,19 @@ public class FingerprintSettings extends SubSettings { if (requestCode == CONFIRM_REQUEST || requestCode == CHOOSE_LOCK_GENERIC_REQUEST) { mLaunchedConfirm = false; if (resultCode == RESULT_FINISHED || resultCode == RESULT_OK) { - if (data != null) { - final long challenge = mFingerprintManager.generateChallengeBlocking(); - mToken = BiometricUtils.requestGatekeeperHat(getActivity(), data, mUserId, - challenge); + if (data != null && BiometricUtils.containsGatekeeperPassword(data)) { + mFingerprintManager.generateChallenge(challenge -> { + mToken = BiometricUtils.requestGatekeeperHat(getActivity(), data, + mUserId, challenge); + updateAddPreference(); + }); + } else { + Log.d(TAG, "Data null or GK PW missing"); + finish(); } + } else { + Log.d(TAG, "Password not confirmed"); + finish(); } } else if (requestCode == ADD_FINGERPRINT_REQUEST) { mEnrollClicked = false; @@ -583,11 +592,6 @@ public class FingerprintSettings extends SubSettings { activity.finish(); } } - - if (mToken == null) { - // Didn't get an authentication, finishing - getActivity().finish(); - } } @Override diff --git a/tests/robotests/src/com/android/settings/password/SetNewPasswordControllerTest.java b/tests/robotests/src/com/android/settings/password/SetNewPasswordControllerTest.java index c745a1d4e94..ce117b7ad72 100644 --- a/tests/robotests/src/com/android/settings/password/SetNewPasswordControllerTest.java +++ b/tests/robotests/src/com/android/settings/password/SetNewPasswordControllerTest.java @@ -54,8 +54,6 @@ import org.robolectric.RobolectricTestRunner; public final class SetNewPasswordControllerTest { private static final int CURRENT_USER_ID = 101; - private static final long FINGERPRINT_CHALLENGE = -9876512313131L; - private static final long FACE_CHALLENGE = 1352057789L; @Mock private PackageManager mPackageManager; @@ -76,11 +74,7 @@ public final class SetNewPasswordControllerTest { mSetNewPasswordController = new SetNewPasswordController( CURRENT_USER_ID, mPackageManager, mFingerprintManager, mFaceManager, mDevicePolicyManager, mUi); - - when(mFingerprintManager.generateChallengeBlocking()).thenReturn(FINGERPRINT_CHALLENGE); when(mPackageManager.hasSystemFeature(eq(FEATURE_FINGERPRINT))).thenReturn(true); - - when(mFaceManager.generateChallengeBlocking()).thenReturn(FACE_CHALLENGE); when(mPackageManager.hasSystemFeature(eq(FEATURE_FACE))).thenReturn(true); }