Add mandatory biometric prompt to platform surfaces (1/N)

1. Face settings
2. Fingerprint settings
3. Change device credential

Flag: android.hardware.biometrics.Flags.MANDATORY_BIOMETRICS
Bug: 339910718
Test: atest UtilsTest

Change-Id: I69778d1733ea9fb312e7c26ae0fa23b6008dde5d
This commit is contained in:
Diya Bera
2024-06-28 16:55:57 +00:00
parent b67c157e2f
commit 049de84f2d
10 changed files with 275 additions and 3 deletions

View File

@@ -65,6 +65,7 @@ public abstract class BiometricsSettingsBase extends DashboardFragment {
static final int CONFIRM_REQUEST = 2001;
private static final int CHOOSE_LOCK_REQUEST = 2002;
protected static final int ACTIVE_UNLOCK_REQUEST = 2003;
private static final int BIOMETRIC_AUTH_REQUEST = 2004;
private static final String SAVE_STATE_CONFIRM_CREDETIAL = "confirm_credential";
private static final String DO_NOT_FINISH_ACTIVITY = "do_not_finish_activity";
@@ -72,10 +73,15 @@ public abstract class BiometricsSettingsBase extends DashboardFragment {
static final String RETRY_PREFERENCE_KEY = "retry_preference_key";
@VisibleForTesting
static final String RETRY_PREFERENCE_BUNDLE = "retry_preference_bundle";
private static final String BIOMETRICS_AUTH_REQUESTED = "biometrics_auth_requested";
private static final String BIOMETRICS_AUTHENTICATED_SUCCESSFULLY =
"biometrics_authenticated_successfully";
protected int mUserId;
protected long mGkPwHandle;
private boolean mConfirmCredential;
private boolean mBiometricsAuthenticationRequested;
private boolean mBiometricsSuccessfullyAuthenticated;
@Nullable private FaceManager mFaceManager;
@Nullable private FingerprintManager mFingerprintManager;
// Do not finish() if choosing/confirming credential, showing fp/face settings, or launching
@@ -113,6 +119,9 @@ public abstract class BiometricsSettingsBase extends DashboardFragment {
mGkPwHandle = BiometricUtils.getGatekeeperPasswordHandle(getIntent());
}
mBiometricsSuccessfullyAuthenticated = getIntent().getBooleanExtra(
BIOMETRICS_AUTHENTICATED_SUCCESSFULLY, false);
if (savedInstanceState != null) {
mConfirmCredential = savedInstanceState.getBoolean(SAVE_STATE_CONFIRM_CREDETIAL);
mDoNotFinishActivity = savedInstanceState.getBoolean(DO_NOT_FINISH_ACTIVITY);
@@ -123,11 +132,20 @@ public abstract class BiometricsSettingsBase extends DashboardFragment {
mGkPwHandle = savedInstanceState.getLong(
ChooseLockSettingsHelper.EXTRA_KEY_REQUEST_GK_PW_HANDLE);
}
mBiometricsAuthenticationRequested = savedInstanceState.getBoolean(
BIOMETRICS_AUTH_REQUESTED);
mBiometricsSuccessfullyAuthenticated = savedInstanceState.getBoolean(
BIOMETRICS_AUTHENTICATED_SUCCESSFULLY);
}
if (mGkPwHandle == 0L && !mConfirmCredential) {
mConfirmCredential = true;
launchChooseOrConfirmLock();
} else if (Utils.requestBiometricAuthenticationForMandatoryBiometrics(
getActivity(), mBiometricsSuccessfullyAuthenticated,
mBiometricsAuthenticationRequested)) {
mBiometricsAuthenticationRequested = true;
Utils.launchBiometricPromptForMandatoryBiometrics(this, BIOMETRIC_AUTH_REQUEST);
}
updateUnlockPhonePreferenceSummary();
@@ -141,6 +159,12 @@ public abstract class BiometricsSettingsBase extends DashboardFragment {
@Override
public void onResume() {
super.onResume();
if (Utils.requestBiometricAuthenticationForMandatoryBiometrics(getActivity(),
mBiometricsSuccessfullyAuthenticated, mBiometricsAuthenticationRequested)
&& mGkPwHandle != 0L) {
mBiometricsAuthenticationRequested = true;
Utils.launchBiometricPromptForMandatoryBiometrics(this, BIOMETRIC_AUTH_REQUEST);
}
if (!mConfirmCredential) {
mDoNotFinishActivity = false;
}
@@ -177,6 +201,9 @@ 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);
extras.putBoolean(
BiometricEnrollBase.EXTRA_BIOMETRICS_AUTHENTICATED_SUCCESSFULLY,
mBiometricsSuccessfullyAuthenticated);
onFaceOrFingerprintPreferenceTreeClick(preference);
} catch (IllegalStateException e) {
if (retry) {
@@ -206,6 +233,9 @@ 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);
extras.putBoolean(
BiometricEnrollBase.EXTRA_BIOMETRICS_AUTHENTICATED_SUCCESSFULLY,
mBiometricsSuccessfullyAuthenticated);
onFaceOrFingerprintPreferenceTreeClick(preference);
} catch (IllegalStateException e) {
if (retry) {
@@ -288,6 +318,10 @@ public abstract class BiometricsSettingsBase extends DashboardFragment {
outState.putString(RETRY_PREFERENCE_KEY, mRetryPreferenceKey);
outState.putBundle(RETRY_PREFERENCE_BUNDLE, mRetryPreferenceExtra);
}
outState.putBoolean(BIOMETRICS_AUTH_REQUESTED,
mBiometricsAuthenticationRequested);
outState.putBoolean(BIOMETRICS_AUTHENTICATED_SUCCESSFULLY,
mBiometricsSuccessfullyAuthenticated);
}
@Override
@@ -315,6 +349,13 @@ public abstract class BiometricsSettingsBase extends DashboardFragment {
}
mRetryPreferenceKey = null;
mRetryPreferenceExtra = null;
} else if (requestCode == BIOMETRIC_AUTH_REQUEST) {
mBiometricsAuthenticationRequested = false;
if (resultCode == RESULT_OK) {
mBiometricsSuccessfullyAuthenticated = true;
} else {
finish();
}
}
}