Attach FingerprintEnrollFinishFragment to activity

Start FingerprintEnrollFinishFragment when enrolling page is done.

Bug: 260960831
Test: atest FingerprintEnrollmentActivityTest
      FingerprintEnrollmentViewModelTest
Change-Id: Ia751c20330dfdcac91e961acc70aa033b05de03f
This commit is contained in:
Milton Wu
2023-02-14 18:28:45 +08:00
parent 98c33afa77
commit 211313b52d
8 changed files with 283 additions and 399 deletions

View File

@@ -40,6 +40,9 @@ import static com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollFin
import static com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollFindSensorViewModel.FINGERPRINT_ENROLL_FIND_SENSOR_ACTION_SKIP;
import static com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollFindSensorViewModel.FINGERPRINT_ENROLL_FIND_SENSOR_ACTION_START;
import static com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollFindSensorViewModel.FingerprintEnrollFindSensorAction;
import static com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollFinishViewModel.FINGERPRINT_ENROLL_FINISH_ACTION_ADD_BUTTON_CLICK;
import static com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollFinishViewModel.FINGERPRINT_ENROLL_FINISH_ACTION_NEXT_BUTTON_CLICK;
import static com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollFinishViewModel.FingerprintEnrollFinishAction;
import static com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollIntroViewModel.FINGERPRINT_ENROLL_INTRO_ACTION_CONTINUE_ENROLL;
import static com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollIntroViewModel.FINGERPRINT_ENROLL_INTRO_ACTION_DONE_AND_FINISH;
import static com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollIntroViewModel.FINGERPRINT_ENROLL_INTRO_ACTION_SKIP_OR_CANCEL;
@@ -73,8 +76,6 @@ import androidx.lifecycle.viewmodel.MutableCreationExtras;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.biometrics.BiometricEnrollBase;
import com.android.settings.biometrics.fingerprint.FingerprintEnrollFinish;
import com.android.settings.biometrics.fingerprint.SetupFingerprintEnrollFinish;
import com.android.settings.biometrics2.data.repository.FingerprintRepository;
import com.android.settings.biometrics2.factory.BiometricsViewModelFactory;
import com.android.settings.biometrics2.ui.model.CredentialModel;
@@ -84,6 +85,7 @@ import com.android.settings.biometrics2.ui.viewmodel.AutoCredentialViewModel.Fin
import com.android.settings.biometrics2.ui.viewmodel.DeviceFoldedViewModel;
import com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollEnrollingViewModel;
import com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollFindSensorViewModel;
import com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollFinishViewModel;
import com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollIntroViewModel;
import com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollProgressViewModel;
import com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollmentViewModel;
@@ -156,11 +158,14 @@ public class FingerprintEnrollmentActivity extends FragmentActivity {
onEnrollingErrorDialogAction(action);
}
};
private final ActivityResultCallback<ActivityResult> mNextActivityResultCallback =
result -> mViewModel.onContinueEnrollActivityResult(result,
mAutoCredentialViewModel.getUserId());
private final ActivityResultLauncher<Intent> mNextActivityLauncher =
registerForActivityResult(new StartActivityForResult(), mNextActivityResultCallback);
private final Observer<Integer> mFinishActionObserver = action -> {
if (DEBUG) {
Log.d(TAG, "mFinishActionObserver(" + action + ")");
}
if (action != null) {
onFinishAction(action);
}
};
private final ActivityResultCallback<ActivityResult> mChooseLockResultCallback =
result -> onChooseOrConfirmLockResult(true /* isChooseLock */, result);
private final ActivityResultLauncher<Intent> mChooseLockLauncher =
@@ -195,6 +200,7 @@ public class FingerprintEnrollmentActivity extends FragmentActivity {
} else {
final FragmentManager manager = getSupportFragmentManager();
String[] tags = new String[] {
FINISH_TAG,
ENROLLING_UDFPS_TAG,
ENROLLING_SFPS_TAG,
ENROLLING_RFPS_TAG,
@@ -217,10 +223,15 @@ public class FingerprintEnrollmentActivity extends FragmentActivity {
|| tag.equals(FIND_RFPS_TAG)) {
attachFindSensorViewModel();
attachIntroViewModel();
} else { // ENROLLING_UDFPS_TAG, ENROLLING_SFPS_TAG, ENROLLING_RFPS_TAG
} else if (tag.equals(ENROLLING_UDFPS_TAG) || tag.equals(ENROLLING_SFPS_TAG)
|| tag.equals(ENROLLING_RFPS_TAG)) {
attachEnrollingViewModel();
attachFindSensorViewModel();
attachIntroViewModel();
} else { // FINISH_TAG
attachFinishViewModel();
attachFindSensorViewModel();
attachIntroViewModel();
}
break;
}
@@ -330,59 +341,37 @@ public class FingerprintEnrollmentActivity extends FragmentActivity {
mEnrollingErrorDialogActionObserver);
}
private void startFinishActivity() {
final FingerprintEnrollEnrollingViewModel enrollingViewModel =
mViewModelProvider.get(FingerprintEnrollEnrollingViewModel.class);
enrollingViewModel.clearActionLiveData();
private void startFinishFragment() {
attachFinishViewModel();
final boolean isSuw = mViewModel.getRequest().isSuw();
if (!mViewModel.isWaitingActivityResult().compareAndSet(false, true)) {
Log.w(TAG, "startNext, isSuw:" + isSuw + ", fail to set isWaiting flag");
}
Intent intent = new Intent(this, isSuw
? SetupFingerprintEnrollFinish.class
: FingerprintEnrollFinish.class);
intent.putExtras(mAutoCredentialViewModel.createCredentialIntentExtra());
intent.putExtras(mViewModel.getNextActivityBaseIntentExtras());
mNextActivityLauncher.launch(intent);
getSupportFragmentManager().beginTransaction()
.setReorderingAllowed(true)
.setCustomAnimations(R.anim.sud_slide_next_in, R.anim.sud_slide_next_out,
R.anim.sud_slide_back_in, R.anim.sud_slide_back_out)
.replace(R.id.fragment_container_view, FingerprintEnrollFinishFragment.class, null,
FINISH_TAG)
.addToBackStack(FINISH_TAG)
.commit();
}
private void attachFinishViewModel() {
final FingerprintEnrollFinishViewModel viewModel =
mViewModelProvider.get(FingerprintEnrollFinishViewModel.class);
viewModel.clearActionLiveData();
viewModel.getActionLiveData().observe(this, mFinishActionObserver);
}
private void onGenerateChallengeFailed(@NonNull Boolean ignoredBoolean) {
onSetActivityResult(new ActivityResult(RESULT_CANCELED, null));
}
/**
* Get intent which passing back to FingerprintSettings for late generateChallenge()
*/
@Nullable
private Intent createSetResultIntentWithGeneratingChallengeExtra(
@Nullable Intent activityResultIntent) {
if (!mViewModel.getRequest().isFromSettingsSummery()) {
return activityResultIntent;
}
final Bundle extra = mAutoCredentialViewModel.createGeneratingChallengeExtras();
if (extra != null) {
if (activityResultIntent == null) {
activityResultIntent = new Intent();
}
activityResultIntent.putExtras(extra);
}
return activityResultIntent;
}
private void onSetActivityResult(@NonNull ActivityResult result) {
final int resultCode = mViewModel.getRequest().isAfterSuwOrSuwSuggestedAction()
? RESULT_CANCELED
: result.getResultCode();
final Intent intent = resultCode == BiometricEnrollBase.RESULT_FINISHED
? createSetResultIntentWithGeneratingChallengeExtra(result.getData())
: result.getData();
final ActivityResult overrideResult = mViewModel.getOverrideActivityResult(
result, mAutoCredentialViewModel.createGeneratingChallengeExtras());
if (DEBUG) {
Log.d(TAG, "onSetActivityResult(" + result + "), call setResult(" + resultCode
+ ", " + intent + ")");
Log.d(TAG, "onSetActivityResult(" + result + "), override:" + overrideResult + ")");
}
setResult(resultCode, intent);
setResult(overrideResult.getResultCode(), overrideResult.getData());
finish();
}
@@ -471,7 +460,12 @@ public class FingerprintEnrollmentActivity extends FragmentActivity {
private void onEnrollingAction(@FingerprintEnrollEnrollingAction int action) {
switch (action) {
case FINGERPRINT_ENROLL_ENROLLING_ACTION_DONE: {
startFinishActivity();
mViewModel.setIsNewFingerprintAdded();
// Remove Enrolling page from backstack, and add Finish page. Latest backstack will
// be changed from Intro->FindSensor->Enrolling to Intro->FindSensor->Finish
getSupportFragmentManager().popBackStack();
startFinishFragment();
break;
}
case FINGERPRINT_ENROLL_ENROLLING_ACTION_SKIP: {
@@ -488,7 +482,18 @@ public class FingerprintEnrollmentActivity extends FragmentActivity {
break;
}
case FINGERPRINT_ENROLL_ENROLLING_CANCELED_BECAUSE_BACK_PRESSED: {
getSupportFragmentManager().popBackStack();
if (mViewModel.isNewFingerprintAdded()) {
// Add another fingerprint case. Remove Enrolling page from
// backstack, and add Finish page. Latest backstack will be changed from
// Intro->FindSensor->Enrolling to Intro->FindSensor->Finish
getSupportFragmentManager().popBackStack();
startFinishFragment();
} else {
// First fingerprint case. Remove Enrolling page from backstack, and add Finish
// page. Latest backstack will be changed from
// Intro->FindSensor->Enrolling to Intro->FindSensor
getSupportFragmentManager().popBackStack();
}
break;
}
}
@@ -505,12 +510,40 @@ public class FingerprintEnrollmentActivity extends FragmentActivity {
}
}
private void onFinishAction(@FingerprintEnrollFinishAction int action) {
switch (action) {
case FINGERPRINT_ENROLL_FINISH_ACTION_ADD_BUTTON_CLICK: {
getSupportFragmentManager().popBackStack(); // Remove Finish page from backstack
startEnrollingFragment();
break;
}
case FINGERPRINT_ENROLL_FINISH_ACTION_NEXT_BUTTON_CLICK: {
final Intent data;
if (mViewModel.getRequest().isSuw()) {
data = new Intent();
data.putExtras(mViewModel.getSuwFingerprintCountExtra(
mAutoCredentialViewModel.getUserId()));
} else {
data = null;
}
onSetActivityResult(new ActivityResult(BiometricEnrollBase.RESULT_FINISHED, data));
break;
}
}
}
@Override
protected void onPause() {
super.onPause();
mViewModel.checkFinishActivityDuringOnPause(isFinishing(), isChangingConfigurations());
}
@Override
protected void onDestroy() {
mViewModel.updateFingerprintSuggestionEnableState(mAutoCredentialViewModel.getUserId());
super.onDestroy();
}
@Override
protected void onApplyThemeResource(Resources.Theme theme, @StyleRes int resid, boolean first) {
theme.applyStyle(R.style.SetupWizardPartnerResource, true);