Remove remainder of generateChallengeBlocking

Test: make -j56 RunSettingsRoboTests

Face Tests:
Test: Open face settings, remove face, add face
Test: Open face settings, but cancel credential confirmation.
      Face settings does not show up
Test: adb shell am start -a android.app.action.SET_NEW_PASSWORD
      Able to enroll face

Fingerprint Tests:
Test: Open fingerprint settings, add button is shown
Test: Open fingerprint settings, but cancel credential confirmation.
      Fingerprint settings does not show up
Test: adb shell am start -a android.app.action.SET_NEW_PASSWORD
      Able to enroll fingerprint

Bug: 162533680
Change-Id: Ie448ed086e73b0b545bd3a2e62437c543f7aad6c
This commit is contained in:
Kevin Chyn
2020-07-30 15:38:54 -07:00
parent 66bfe45f99
commit bee84e2daa
5 changed files with 43 additions and 37 deletions

View File

@@ -164,7 +164,7 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase
// No password registered, launch into enrollment wizard. // No password registered, launch into enrollment wizard.
mConfirmingCredentials = true; mConfirmingCredentials = true;
launchChooseLock(); launchChooseLock();
} else if (mToken == null) { } else if (!BiometricUtils.containsGatekeeperPassword(getIntent()) && mToken == null) {
// It's possible to have a token but mLaunchedConfirmLock == false, since // It's possible to have a token but mLaunchedConfirmLock == false, since
// ChooseLockGeneric can pass us a token. // ChooseLockGeneric can pass us a token.
mConfirmingCredentials = true; mConfirmingCredentials = true;

View File

@@ -46,19 +46,9 @@ public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { 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); super.onCreate(savedInstanceState);
mFaceManager = Utils.getFaceManagerOrNull(this);
mFaceFeatureProvider = FeatureFactory.getFactory(getApplicationContext()) mFaceFeatureProvider = FeatureFactory.getFactory(getApplicationContext())
.getFaceFeatureProvider(); .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_enroll_introduction_footer_part_2
: R.string.security_settings_face_settings_footer_attention_not_supported; : R.string.security_settings_face_settings_footer_attention_not_supported;
footer2.setText(footer2TextResource); 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 @Override

View File

@@ -61,18 +61,24 @@ public class FingerprintEnrollFindSensor extends BiometricEnrollBase {
setHeaderText(R.string.security_settings_fingerprint_enroll_find_sensor_title); 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())) { if (mToken == null && BiometricUtils.containsGatekeeperPassword(getIntent())) {
final FingerprintManager fpm = getSystemService(FingerprintManager.class); final FingerprintManager fpm = getSystemService(FingerprintManager.class);
final long challenge = fpm.generateChallengeBlocking(); fpm.generateChallenge(challenge -> {
mToken = BiometricUtils.requestGatekeeperHat(this, getIntent(), mUserId, challenge); mToken = BiometricUtils.requestGatekeeperHat(this, getIntent(), mUserId, challenge);
// Put this into the intent. This is really just to work around the fact that the // 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 // enrollment sidecar gets the HAT from the activity's intent, rather than having
// it passed in. // it passed in.
getIntent().putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken); getIntent().putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
}
startLookingForFingerprint(); // already confirmed, so start looking for fingerprint startLookingForFingerprint();
});
} else if (mToken != null) {
// HAT passed in from somewhere else, such as FingerprintEnrollIntroduction
startLookingForFingerprint();
}
View animationView = findViewById(R.id.fingerprint_sensor_location_animation); View animationView = findViewById(R.id.fingerprint_sensor_location_animation);
if (animationView instanceof FingerprintFindSensorAnimation) { if (animationView instanceof FingerprintFindSensorAnimation) {

View File

@@ -411,6 +411,8 @@ public class FingerprintSettings extends SubSettings {
private void updateAddPreference() { private void updateAddPreference() {
if (getActivity() == null) return; // Activity went away if (getActivity() == null) return; // Activity went away
final Preference addPreference = findPreference(KEY_FINGERPRINT_ADD);
/* Disable preference if too many fingerprints added */ /* Disable preference if too many fingerprints added */
final int max = getContext().getResources().getInteger( final int max = getContext().getResources().getInteger(
com.android.internal.R.integer.config_fingerprintMaxTemplatesPerUser); com.android.internal.R.integer.config_fingerprintMaxTemplatesPerUser);
@@ -420,9 +422,8 @@ public class FingerprintSettings extends SubSettings {
final boolean removalInProgress = mRemovalSidecar.inProgress(); final boolean removalInProgress = mRemovalSidecar.inProgress();
CharSequence maxSummary = tooMany ? CharSequence maxSummary = tooMany ?
getContext().getString(R.string.fingerprint_add_max, max) : ""; getContext().getString(R.string.fingerprint_add_max, max) : "";
Preference addPreference = findPreference(KEY_FINGERPRINT_ADD);
addPreference.setSummary(maxSummary); addPreference.setSummary(maxSummary);
addPreference.setEnabled(!tooMany && !removalInProgress); addPreference.setEnabled(!tooMany && !removalInProgress && mToken != null);
} }
private void createFooterPreference(PreferenceGroup root) { private void createFooterPreference(PreferenceGroup root) {
@@ -569,11 +570,19 @@ public class FingerprintSettings extends SubSettings {
if (requestCode == CONFIRM_REQUEST || requestCode == CHOOSE_LOCK_GENERIC_REQUEST) { if (requestCode == CONFIRM_REQUEST || requestCode == CHOOSE_LOCK_GENERIC_REQUEST) {
mLaunchedConfirm = false; mLaunchedConfirm = false;
if (resultCode == RESULT_FINISHED || resultCode == RESULT_OK) { if (resultCode == RESULT_FINISHED || resultCode == RESULT_OK) {
if (data != null) { if (data != null && BiometricUtils.containsGatekeeperPassword(data)) {
final long challenge = mFingerprintManager.generateChallengeBlocking(); mFingerprintManager.generateChallenge(challenge -> {
mToken = BiometricUtils.requestGatekeeperHat(getActivity(), data, mUserId, mToken = BiometricUtils.requestGatekeeperHat(getActivity(), data,
challenge); 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) { } else if (requestCode == ADD_FINGERPRINT_REQUEST) {
mEnrollClicked = false; mEnrollClicked = false;
@@ -583,11 +592,6 @@ public class FingerprintSettings extends SubSettings {
activity.finish(); activity.finish();
} }
} }
if (mToken == null) {
// Didn't get an authentication, finishing
getActivity().finish();
}
} }
@Override @Override

View File

@@ -54,8 +54,6 @@ import org.robolectric.RobolectricTestRunner;
public final class SetNewPasswordControllerTest { public final class SetNewPasswordControllerTest {
private static final int CURRENT_USER_ID = 101; private static final int CURRENT_USER_ID = 101;
private static final long FINGERPRINT_CHALLENGE = -9876512313131L;
private static final long FACE_CHALLENGE = 1352057789L;
@Mock @Mock
private PackageManager mPackageManager; private PackageManager mPackageManager;
@@ -76,11 +74,7 @@ public final class SetNewPasswordControllerTest {
mSetNewPasswordController = new SetNewPasswordController( mSetNewPasswordController = new SetNewPasswordController(
CURRENT_USER_ID, mPackageManager, mFingerprintManager, mFaceManager, CURRENT_USER_ID, mPackageManager, mFingerprintManager, mFaceManager,
mDevicePolicyManager, mUi); mDevicePolicyManager, mUi);
when(mFingerprintManager.generateChallengeBlocking()).thenReturn(FINGERPRINT_CHALLENGE);
when(mPackageManager.hasSystemFeature(eq(FEATURE_FINGERPRINT))).thenReturn(true); when(mPackageManager.hasSystemFeature(eq(FEATURE_FINGERPRINT))).thenReturn(true);
when(mFaceManager.generateChallengeBlocking()).thenReturn(FACE_CHALLENGE);
when(mPackageManager.hasSystemFeature(eq(FEATURE_FACE))).thenReturn(true); when(mPackageManager.hasSystemFeature(eq(FEATURE_FACE))).thenReturn(true);
} }