Bypass cancel error code during "Add another"

1. When user chooses "Add another" on latest fingerprint enroll page, we
   shall bypass RESULT_CANCELED from FingerprintEnrollEnrolling. This is
   because user has successfully enrolled a fingerprint before enter
   FingerprintEnrollFinish page.

2. In FingerprintEnrollFindSensor
   A. Do not call startLookingForFingerprint() if mNextClick is true
      because it is wating the result back from
      FingerprintEnrollEnrolling, and let onActivityResult() mehtod to
      handle correct behavior.
   B. Add tests for following cases
      a. Sidecar existence
      b. Activity recycled and recreate in order to get activity result.

Bug: 243701933
Bug: 243762418

Test: ROBOTEST for SetupFingerprintEnrollFindSensorTest,
   FingerprintEnrollFindSensorTest, SetupFingerprintEnrollFinishTest

Test: Test scenarios w/ and w/o always_finish_activities
  1. Enroll a fingerprint but cancel it during enrolling in SuW
  2. Enroll a fingerprint in SuW
  3. Add another fingerprint in SuW
  4. Run "Add another" but cancel it during enrolling in SuW
  5. W/o enrolled fingerprint, add first fingerprint in settings
  6. W/o enrolled fingerprint, add first fingerprint but cancel it
     during enrolling in settings
  7. W/o enrolled fingerprint, add first fingerprint and choose "Add
     another" in settings
  8. W/o enrolled fingerprint, add first fingerprint and choose "Add
     another" then cancel it during enrolling in settings
  9. W/ 1 enrolled fingerprint, add fingerprint in settings
  10. W/ 1 enrolled fingerprint, add fingerprint but cancel it during
      enrolling in settings
  11. W/ 1 enrolled fingerprint, add fingerprint and choose "Add
      another" in settings
  12. W/ 1 enrolled fingerprint, add fingerprint and choose "Add
      another" then canel it during enrolling in settings

Change-Id: I03d8d8ebc39eb34f8fc28acb5cd267e37c7a0311
This commit is contained in:
Milton Wu
2022-08-26 09:57:40 +00:00
parent d3a1f700ee
commit af5a7d8dc0
3 changed files with 326 additions and 52 deletions

View File

@@ -134,6 +134,9 @@ public class FingerprintEnrollFindSensor extends BiometricEnrollBase implements
setHeaderText(R.string.security_settings_fingerprint_enroll_find_sensor_title);
setDescriptionText(R.string.security_settings_fingerprint_enroll_find_sensor_message);
}
if (savedInstanceState != null) {
mNextClicked = savedInstanceState.getBoolean(SAVED_STATE_IS_NEXT_CLICKED, mNextClicked);
}
// This is an entry point for SetNewPasswordController, e.g.
// adb shell am start -a android.app.action.SET_NEW_PASSWORD
@@ -148,11 +151,19 @@ public class FingerprintEnrollFindSensor extends BiometricEnrollBase implements
// it passed in.
getIntent().putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
startLookingForFingerprint();
// Do not start looking for fingerprint if this activity is re-created because it is
// waiting for activity result from enrolling activity.
if (!mNextClicked) {
startLookingForFingerprint();
}
});
} else if (mToken != null) {
// HAT passed in from somewhere else, such as FingerprintEnrollIntroduction
startLookingForFingerprint();
// Do not start looking for fingerprint if this activity is re-created because it is
// waiting for activity result from enrolling activity.
if (!mNextClicked) {
// HAT passed in from somewhere else, such as FingerprintEnrollIntroduction
startLookingForFingerprint();
}
} else {
// There's something wrong with the enrollment flow, this should never happen.
throw new IllegalStateException("HAT and GkPwHandle both missing...");
@@ -173,9 +184,6 @@ public class FingerprintEnrollFindSensor extends BiometricEnrollBase implements
mAnimation = (FingerprintFindSensorAnimation) animationView;
}
}
if (savedInstanceState != null) {
mNextClicked = savedInstanceState.getBoolean(SAVED_STATE_IS_NEXT_CLICKED, mNextClicked);
}
}
@Override
@@ -297,6 +305,7 @@ public class FingerprintEnrollFindSensor extends BiometricEnrollBase implements
return;
}
}
mSidecar.setListener(null);
getSupportFragmentManager().beginTransaction().remove(mSidecar).
commitAllowingStateLoss();
mSidecar = null;

View File

@@ -50,6 +50,8 @@ public class FingerprintEnrollFinish extends BiometricEnrollBase {
static final String FINGERPRINT_SUGGESTION_ACTIVITY =
"com.android.settings.SetupFingerprintSuggestionActivity";
private boolean mIsAddAnotherOrFinish;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -107,9 +109,23 @@ public class FingerprintEnrollFinish extends BiometricEnrollBase {
}
}
@Override
protected void onStart() {
super.onStart();
// Reset it to false every time activity back to fg because this flag is stateless between
// different life cycle.
mIsAddAnotherOrFinish = false;
}
@Override
protected void onNextButtonClick(View view) {
updateFingerprintSuggestionEnableState();
finishAndToNext();
}
private void finishAndToNext() {
mIsAddAnotherOrFinish = true;
setResult(RESULT_FINISHED);
if (WizardManagerHelper.isAnySetupWizard(getIntent())) {
postEnroll();
@@ -145,20 +161,21 @@ public class FingerprintEnrollFinish extends BiometricEnrollBase {
}
private void onAddAnotherButtonClick(View view) {
mIsAddAnotherOrFinish = true;
startActivityForResult(getFingerprintEnrollingIntent(), BiometricUtils.REQUEST_ADD_ANOTHER);
}
@Override
protected boolean shouldFinishWhenBackgrounded() {
return !isFinishing() && super.shouldFinishWhenBackgrounded();
return !mIsAddAnotherOrFinish && super.shouldFinishWhenBackgrounded();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
updateFingerprintSuggestionEnableState();
if (requestCode == BiometricUtils.REQUEST_ADD_ANOTHER && resultCode != RESULT_CANCELED) {
setResult(resultCode, data);
finish();
// If user cancel during "Add another", just use similar flow on "Next" button
finishAndToNext();
} else {
super.onActivityResult(requestCode, resultCode, data);
}