Show Choose/ConfirmLock before showing BiometricEnrollIntroduction

Skip button is now shown when ChooseLock is launched by
BiometricEnroll, otherwise users are forced to use passwords
(maybe good thing?)

Bug: 111548033

Test: Pin/pattern/pass must be set/confirmed before enrollment
Test: Able to enroll FP in SUW and Settings

Change-Id: Ic4bbeb539e4bf01c1c402dec308943292b43406d
This commit is contained in:
Kevin Chyn
2018-12-17 18:42:52 -08:00
parent 3f5966bb48
commit 69e8a089d7
10 changed files with 61 additions and 93 deletions

View File

@@ -67,8 +67,11 @@ public abstract class BiometricEnrollBase extends InstrumentedActivity
*/
public static final int RESULT_TIMEOUT = RESULT_FIRST_USER + 2;
public static final int CONFIRM_REQUEST = 1;
public static final int ENROLLING = 2;
public static final int CHOOSE_LOCK_GENERIC_REQUEST = 1;
public static final int BIOMETRIC_FIND_SENSOR_REQUEST = 2;
public static final int LEARN_MORE_REQUEST = 3;
public static final int CONFIRM_REQUEST = 4;
public static final int ENROLLING = 5;
protected boolean mLaunchedConfirmLock;
protected byte[] mToken;
@@ -105,10 +108,6 @@ public abstract class BiometricEnrollBase extends InstrumentedActivity
initViews();
}
protected boolean shouldLaunchConfirmLock() {
return mToken == null && !mLaunchedConfirmLock;
}
protected void initViews() {
getWindow().setStatusBarColor(Color.TRANSPARENT);
Button nextButton = getNextButton();

View File

@@ -37,10 +37,6 @@ import com.google.android.setupdesign.span.LinkSpan;
public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase
implements LinkSpan.OnClickListener {
public static final int CHOOSE_LOCK_GENERIC_REQUEST = 1;
public static final int BIOMETRIC_FIND_SENSOR_REQUEST = 2;
public static final int LEARN_MORE_REQUEST = 3;
private UserManager mUserManager;
private boolean mHasPassword;
private boolean mBiometricUnlockDisabledByAdmin;
@@ -109,6 +105,11 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase
*/
protected abstract Intent getEnrollingIntent();
/**
* @return the title to be shown on the ConfirmLock screen.
*/
protected abstract int getConfirmLockTitleResId();
/**
* @param span
*/
@@ -133,6 +134,13 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase
mUserManager = UserManager.get(this);
updatePasswordQuality();
if (!mHasPassword) {
// No password registered, launch into enrollment wizard.
launchChooseLock();
} else {
launchConfirmLock(getConfirmLockTitleResId(), getChallenge());
}
}
@Override
@@ -157,13 +165,8 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase
@Override
protected void onNextButtonClick() {
if (!mHasPassword) {
// No biometrics registered, launch into enrollment wizard.
launchChooseLock();
} else {
// Lock thingy is already set up, launch directly into find sensor step from wizard.
launchFindSensor(null);
}
// Lock thingy is already set up, launch directly to the next page
launchNextEnrollingActivity(mToken);
}
private void launchChooseLock() {
@@ -181,7 +184,7 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase
startActivityForResult(intent, CHOOSE_LOCK_GENERIC_REQUEST);
}
private void launchFindSensor(byte[] token) {
private void launchNextEnrollingActivity(byte[] token) {
Intent intent = getEnrollingIntent();
if (token != null) {
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, token);
@@ -199,9 +202,9 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
final boolean isResultFinished = resultCode == RESULT_FINISHED;
final int result = isResultFinished ? RESULT_OK : RESULT_SKIP;
if (requestCode == BIOMETRIC_FIND_SENSOR_REQUEST) {
if (isResultFinished || resultCode == RESULT_SKIP) {
final int result = isResultFinished ? RESULT_OK : RESULT_SKIP;
setResult(result, data);
finish();
return;
@@ -209,10 +212,21 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase
} else if (requestCode == CHOOSE_LOCK_GENERIC_REQUEST) {
if (isResultFinished) {
updatePasswordQuality();
byte[] token = data.getByteArrayExtra(
mToken = data.getByteArrayExtra(
ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
launchFindSensor(token);
overridePendingTransition(R.anim.suw_slide_next_in, R.anim.suw_slide_next_out);
return;
} else {
setResult(result, data);
finish();
}
} else if (requestCode == CONFIRM_REQUEST) {
if (resultCode == RESULT_OK && data != null) {
mToken = data.getByteArrayExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
overridePendingTransition(R.anim.suw_slide_next_in, R.anim.suw_slide_next_out);
} else {
setResult(result, data);
finish();
}
} else if (requestCode == LEARN_MORE_REQUEST) {
overridePendingTransition(R.anim.suw_slide_back_in, R.anim.suw_slide_back_out);

View File

@@ -48,13 +48,6 @@ public abstract class BiometricsEnrollEnrolling extends BiometricEnrollBase
*/
protected abstract boolean shouldStartAutomatically();
/**
* @return true if enrollment should finish when onStop is called.
*/
protected boolean shouldFinishOnStop() {
return true;
}
@Override
protected void onStart() {
super.onStart();
@@ -70,7 +63,7 @@ public abstract class BiometricsEnrollEnrolling extends BiometricEnrollBase
mSidecar.setListener(null);
}
if (shouldFinishOnStop() && !isChangingConfigurations()) {
if (!isChangingConfigurations()) {
if (mSidecar != null) {
mSidecar.cancelEnrollment();
getSupportFragmentManager()

View File

@@ -44,7 +44,6 @@ public class FaceEnrollEnrolling extends BiometricsEnrollEnrolling {
private TextView mErrorText;
private Interpolator mLinearOutSlowInInterpolator;
private boolean mShouldFinishOnStop = true;
private FaceEnrollPreviewFragment mPreviewFragment;
private FaceFeatureProvider.Listener mListener = new FaceFeatureProvider.Listener() {
@@ -92,14 +91,8 @@ public class FaceEnrollEnrolling extends BiometricsEnrollEnrolling {
Button skipButton = findViewById(R.id.skip_button);
skipButton.setOnClickListener(this);
if (shouldLaunchConfirmLock()) {
launchConfirmLock(R.string.security_settings_face_preference_title,
Utils.getFaceManagerOrNull(this).generateChallenge());
mShouldFinishOnStop = false;
} else {
startEnrollment();
}
}
@Override
public void startEnrollment() {
@@ -129,11 +122,6 @@ public class FaceEnrollEnrolling extends BiometricsEnrollEnrolling {
return false;
}
@Override
protected boolean shouldFinishOnStop() {
return mShouldFinishOnStop;
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.FACE_ENROLL_ENROLLING;
@@ -178,23 +166,6 @@ public class FaceEnrollEnrolling extends BiometricsEnrollEnrolling {
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CONFIRM_REQUEST) {
if (resultCode == RESULT_OK && data != null) {
mShouldFinishOnStop = true;
mToken = data.getByteArrayExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
overridePendingTransition(R.anim.suw_slide_next_in, R.anim.suw_slide_next_out);
getIntent().putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
startEnrollment();
} else {
finish();
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
private void showErrorDialog(CharSequence msg, int msgId) {
BiometricErrorDialog dialog = FaceErrorDialog.newInstance(msg, msgId);
dialog.show(getSupportFragmentManager(), FaceErrorDialog.class.getName());

View File

@@ -102,6 +102,7 @@ public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
@Override
protected long getChallenge() {
mFaceManager = Utils.getFaceManagerOrNull(this);
if (mFaceManager == null) {
return 0;
}
@@ -118,6 +119,11 @@ public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
return new Intent(this, FaceEnrollEnrolling.class);
}
@Override
protected int getConfirmLockTitleResId() {
return R.string.security_settings_face_preference_title;
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.FACE_ENROLL_INTRO;

View File

@@ -51,12 +51,9 @@ public class FingerprintEnrollFindSensor extends BiometricEnrollBase {
setHeaderText(R.string.security_settings_fingerprint_enroll_find_sensor_title);
if (shouldLaunchConfirmLock()) {
launchConfirmLock(R.string.security_settings_fingerprint_preference_title,
Utils.getFingerprintManagerOrNull(this).preEnroll());
} else if (mToken != null) {
startLookingForFingerprint(); // already confirmed, so start looking for fingerprint
}
View animationView = findViewById(R.id.fingerprint_sensor_location_animation);
if (animationView instanceof FingerprintFindSensorAnimation) {
mAnimation = (FingerprintFindSensorAnimation) animationView;

View File

@@ -106,6 +106,7 @@ public class FingerprintEnrollIntroduction extends BiometricEnrollIntroduction {
@Override
protected long getChallenge() {
mFingerprintManager = Utils.getFingerprintManagerOrNull(this);
if (mFingerprintManager == null) {
return 0;
}
@@ -122,6 +123,11 @@ public class FingerprintEnrollIntroduction extends BiometricEnrollIntroduction {
return new Intent(this, FingerprintEnrollFindSensor.class);
}
@Override
protected int getConfirmLockTitleResId() {
return R.string.security_settings_fingerprint_preference_title;
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.FINGERPRINT_ENROLL_INTRO;

View File

@@ -135,8 +135,9 @@ public class SetupChooseLockPassword extends ChooseLockPassword {
@Override
protected void updateUi() {
super.updateUi();
mSkipButton.setVisibility(mForFingerprint ? View.GONE : View.VISIBLE);
// Show the skip button during SUW but not during Settings > Biometric Enrollment
mSkipButton.setVisibility(View.VISIBLE);
if (mOptionsButton != null) {
mOptionsButton.setVisibility(
mUiStage == Stage.Introduction ? View.VISIBLE : View.GONE);

View File

@@ -70,8 +70,7 @@ public class SetupChooseLockPattern extends ChooseLockPattern {
ChooseLockTypeDialogFragment.newInstance(mUserId)
.show(getChildFragmentManager(), null));
}
// enable skip button only during setup wizard and not with fingerprint flow.
if (!mForFingerprint) {
// Show the skip button during SUW but not during Settings > Biometric Enrollment
Button skipButton = view.findViewById(R.id.skip_button);
skipButton.setVisibility(View.VISIBLE);
skipButton.setOnClickListener(v -> {
@@ -80,7 +79,6 @@ public class SetupChooseLockPattern extends ChooseLockPattern {
.getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false));
dialog.show(getFragmentManager());
});
}
return view;
}

View File

@@ -164,23 +164,6 @@ public class SetupChooseLockPatternTest {
assertThat(findFragment(mActivity).mChosenPattern).isNull();
}
@Test
public void skipButton_shouldNotBeVisible_duringFingerprintFlow() {
final Intent intent =
SetupChooseLockPattern.modifyIntentForSetup(
application,
new IntentBuilder(application)
.setUserId(UserHandle.myUserId())
.setForFingerprint(true)
.build());
mActivity = ActivityController.of(new SetupChooseLockPattern(), intent).setup().get();
Button skipButton = mActivity.findViewById(R.id.skip_button);
assertThat(skipButton).isNotNull();
assertThat(skipButton.getVisibility()).isEqualTo(View.GONE);
}
private ChooseLockPatternFragment findFragment(FragmentActivity activity) {
return (ChooseLockPatternFragment)
activity.getSupportFragmentManager().findFragmentById(R.id.main_content);