Pass Timeout back to upper biometric preference
When FaceSettings or FingerprintSettings are closed because of onStop(),
this information can't been passed back to previous Preference screen,
CombinedBiometricSettings, because handlePreferenceTreeClick() from
AbstractPreferenceController class only can launchActivity() throguh
preference's Context.
In order to recevice the activity result code from FaceSettings or
FingerprintSettings, add handleBiometricPreferenceTreeClick() method in
BiometricStatusPreferenceController. Then CombinedBiometricSettings uses
this method to show FaceSettings or FingerprintSettings through
launchActivityForResult().
Bug: 263057093
Test: atest BiometricNavigationUtilsTest
Test: Manually open camera through double-click power key on different
pages inside "Face & Fingerprint Unlock"
Change-Id: I99167739766ad5ea5f204b0f0543ba6ad18fac31
This commit is contained in:
@@ -33,6 +33,9 @@ import android.os.UserHandle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.activity.result.ActivityResult;
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
@@ -42,14 +45,19 @@ import androidx.preference.Preference;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.biometrics.BiometricEnrollBase;
|
||||
import com.android.settings.biometrics.BiometricStatusPreferenceController;
|
||||
import com.android.settings.biometrics.BiometricUtils;
|
||||
import com.android.settings.biometrics.BiometricsSplitScreenDialog;
|
||||
import com.android.settings.core.SettingsBaseActivity;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.password.ChooseLockGeneric;
|
||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.transition.SettingsTransitionHelper;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Base fragment with the confirming credential functionality for combined biometrics settings.
|
||||
*/
|
||||
@@ -78,6 +86,18 @@ public abstract class BiometricsSettingsBase extends DashboardFragment {
|
||||
@Nullable private String mRetryPreferenceKey = null;
|
||||
@Nullable private Bundle mRetryPreferenceExtra = null;
|
||||
|
||||
private final ActivityResultLauncher<Intent> mFaceOrFingerprintPreferenceLauncher =
|
||||
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
|
||||
this::onFaceOrFingerprintPreferenceResult);
|
||||
|
||||
private void onFaceOrFingerprintPreferenceResult(@Nullable ActivityResult result) {
|
||||
if (result != null && result.getResultCode() == BiometricEnrollBase.RESULT_TIMEOUT) {
|
||||
// When "Face Unlock" or "Fingerprint Unlock" is closed due to entering onStop(),
|
||||
// "Face & Fingerprint Unlock" shall also close itself and back to "Security" page.
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
@@ -165,7 +185,7 @@ public abstract class BiometricsSettingsBase extends DashboardFragment {
|
||||
extras.putByteArray(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, token);
|
||||
extras.putInt(BiometricEnrollBase.EXTRA_KEY_SENSOR_ID, sensorId);
|
||||
extras.putLong(BiometricEnrollBase.EXTRA_KEY_CHALLENGE, challenge);
|
||||
super.onPreferenceTreeClick(preference);
|
||||
onFaceOrFingerprintPreferenceTreeClick(preference);
|
||||
} catch (IllegalStateException e) {
|
||||
if (retry) {
|
||||
mRetryPreferenceKey = preference.getKey();
|
||||
@@ -200,7 +220,7 @@ public abstract class BiometricsSettingsBase extends DashboardFragment {
|
||||
final Bundle extras = preference.getExtras();
|
||||
extras.putByteArray(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, token);
|
||||
extras.putLong(BiometricEnrollBase.EXTRA_KEY_CHALLENGE, challenge);
|
||||
super.onPreferenceTreeClick(preference);
|
||||
onFaceOrFingerprintPreferenceTreeClick(preference);
|
||||
} catch (IllegalStateException e) {
|
||||
if (retry) {
|
||||
mRetryPreferenceKey = preference.getKey();
|
||||
@@ -224,6 +244,33 @@ public abstract class BiometricsSettingsBase extends DashboardFragment {
|
||||
return BiometricUtils.requestGatekeeperHat(context, gkPwHandle, userId, challenge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle preference tree click action for "Face Unlock" or "Fingerprint Unlock" with a launcher
|
||||
* because "Face & Fingerprint Unlock" has to close itself when it gets a specific activity
|
||||
* error code.
|
||||
*
|
||||
* @param preference "Face Unlock" or "Fingerprint Unlock" preference.
|
||||
*/
|
||||
private void onFaceOrFingerprintPreferenceTreeClick(@NonNull Preference preference) {
|
||||
Collection<List<AbstractPreferenceController>> controllers = getPreferenceControllers();
|
||||
for (List<AbstractPreferenceController> controllerList : controllers) {
|
||||
for (AbstractPreferenceController controller : controllerList) {
|
||||
if (controller instanceof BiometricStatusPreferenceController) {
|
||||
final BiometricStatusPreferenceController biometricController =
|
||||
(BiometricStatusPreferenceController) controller;
|
||||
if (biometricController.setPreferenceTreeClickLauncher(preference,
|
||||
mFaceOrFingerprintPreferenceLauncher)) {
|
||||
if (biometricController.handlePreferenceTreeClick(preference)) {
|
||||
writePreferenceClickMetric(preference);
|
||||
}
|
||||
biometricController.setPreferenceTreeClickLauncher(preference, null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(Preference preference) {
|
||||
return onRetryPreferenceTreeClick(preference, true)
|
||||
|
||||
Reference in New Issue
Block a user