Fix FingerprintEnrollmentActivity rotaiton crash

1. When FragmentActivity rotated, FragmentManager will call default
   fragment constructor w/o parameters. Remove parameters of
   FingerprintEnrollIntroFragment constructor. And also remove
   BiometricsFragmentFactory because of useless now.
2. Remove some LiveData inside AutoCredentialViewModel because it causes
   jitter on activity transition.
3. Save and restore data inside AutoCredentialViewModel for handling
   activity recreation during rotation.
4. clear FingerprintEnrollIntroViewModel.mActionLiveData to prevent
   that activity gets previous action after recreate
5. Fix launching wrong activity during setupwizard

Bug: 259626932
Test: atest AutoCredentialViewModelTest CredentialModelTest
            FingerprintEnrollIntroViewModelTest
Change-Id: Ia26c86dc99ad91dbddef90538d9f5e5583585063
This commit is contained in:
Milton Wu
2022-11-22 16:37:11 +08:00
parent f137463ddc
commit 5174310392
9 changed files with 520 additions and 246 deletions

View File

@@ -1,57 +0,0 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.biometrics2.factory;
import android.app.Application;
import android.app.admin.DevicePolicyManager;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentFactory;
import androidx.lifecycle.ViewModelProvider;
import com.android.settings.biometrics2.ui.view.FingerprintEnrollIntroFragment;
/**
* Fragment factory for biometrics
*/
public class BiometricsFragmentFactory extends FragmentFactory {
private final Application mApplication;
private final ViewModelProvider mViewModelProvider;
public BiometricsFragmentFactory(Application application,
ViewModelProvider viewModelProvider) {
mApplication = application;
mViewModelProvider = viewModelProvider;
}
@NonNull
@Override
public Fragment instantiate(@NonNull ClassLoader classLoader, @NonNull String className) {
final Class<? extends Fragment> clazz = loadFragmentClass(classLoader, className);
if (FingerprintEnrollIntroFragment.class.equals(clazz)) {
final DevicePolicyManager devicePolicyManager =
mApplication.getSystemService(DevicePolicyManager.class);
if (devicePolicyManager != null) {
return new FingerprintEnrollIntroFragment(mViewModelProvider,
devicePolicyManager.getResources());
}
}
return super.instantiate(classLoader, className);
}
}