Remove dependencies on old BiometricPrompt bundle
This moves the dependency to PromptInfo, which isn't optimal but is still much more readable / manageable Bug: 149067920 Test: adb shell am start -a android.app.action.CONFIRM_DEVICE_CREDENTIAL Change-Id: I7d9ba2084db76284d08f68dd2005190f06412a1e
This commit is contained in:
@@ -17,11 +17,10 @@
|
||||
package com.android.settings.password;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.DialogInterface;
|
||||
import android.hardware.biometrics.BiometricConstants;
|
||||
import android.hardware.biometrics.BiometricPrompt;
|
||||
import android.hardware.biometrics.BiometricPrompt.AuthenticationCallback;
|
||||
import android.hardware.biometrics.BiometricPrompt.AuthenticationResult;
|
||||
import android.hardware.biometrics.PromptInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.CancellationSignal;
|
||||
|
||||
@@ -38,6 +37,8 @@ public class BiometricFragment extends InstrumentedFragment {
|
||||
|
||||
private static final String TAG = "ConfirmDeviceCredential/BiometricFragment";
|
||||
|
||||
private static final String KEY_PROMPT_INFO = "prompt_info";
|
||||
|
||||
// Re-set by the application. Should be done upon orientation changes, etc
|
||||
private Executor mClientExecutor;
|
||||
private AuthenticationCallback mClientCallback;
|
||||
@@ -46,16 +47,14 @@ public class BiometricFragment extends InstrumentedFragment {
|
||||
private int mUserId;
|
||||
|
||||
// Created/Initialized once and retained
|
||||
private Bundle mBundle;
|
||||
private PromptInfo mPromptInfo;
|
||||
private BiometricPrompt mBiometricPrompt;
|
||||
private CancellationSignal mCancellationSignal;
|
||||
private boolean mAuthenticating;
|
||||
|
||||
private AuthenticationCallback mAuthenticationCallback =
|
||||
new AuthenticationCallback() {
|
||||
@Override
|
||||
public void onAuthenticationError(int error, @NonNull CharSequence message) {
|
||||
mAuthenticating = false;
|
||||
mClientExecutor.execute(() -> {
|
||||
mClientCallback.onAuthenticationError(error, message);
|
||||
});
|
||||
@@ -64,7 +63,6 @@ public class BiometricFragment extends InstrumentedFragment {
|
||||
|
||||
@Override
|
||||
public void onAuthenticationSucceeded(AuthenticationResult result) {
|
||||
mAuthenticating = false;
|
||||
mClientExecutor.execute(() -> {
|
||||
mClientCallback.onAuthenticationSucceeded(result);
|
||||
});
|
||||
@@ -86,22 +84,14 @@ public class BiometricFragment extends InstrumentedFragment {
|
||||
}
|
||||
};
|
||||
|
||||
private final DialogInterface.OnClickListener mNegativeButtonListener =
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
mAuthenticationCallback.onAuthenticationError(
|
||||
BiometricConstants.BIOMETRIC_ERROR_NEGATIVE_BUTTON,
|
||||
mBundle.getString(BiometricPrompt.KEY_NEGATIVE_TEXT));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param bundle Bundle passed from {@link BiometricPrompt.Builder#buildIntent()}
|
||||
* @param promptInfo
|
||||
* @return
|
||||
*/
|
||||
public static BiometricFragment newInstance(Bundle bundle) {
|
||||
public static BiometricFragment newInstance(PromptInfo promptInfo) {
|
||||
BiometricFragment biometricFragment = new BiometricFragment();
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putParcelable(KEY_PROMPT_INFO, promptInfo);
|
||||
biometricFragment.setArguments(bundle);
|
||||
return biometricFragment;
|
||||
}
|
||||
@@ -133,28 +123,27 @@ public class BiometricFragment extends InstrumentedFragment {
|
||||
super.onCreate(savedInstanceState);
|
||||
setRetainInstance(true);
|
||||
|
||||
mBundle = getArguments();
|
||||
final Bundle bundle = getArguments();
|
||||
final PromptInfo promptInfo = bundle.getParcelable(KEY_PROMPT_INFO);
|
||||
|
||||
final BiometricPrompt.Builder builder = new BiometricPrompt.Builder(getContext())
|
||||
.setTitle(mBundle.getString(BiometricPrompt.KEY_TITLE))
|
||||
.setTitle(promptInfo.getTitle())
|
||||
.setUseDefaultTitle() // use default title if title is null/empty
|
||||
.setDeviceCredentialAllowed(true)
|
||||
.setSubtitle(mBundle.getString(BiometricPrompt.KEY_SUBTITLE))
|
||||
.setDescription(mBundle.getString(BiometricPrompt.KEY_DESCRIPTION))
|
||||
.setSubtitle(promptInfo.getSubtitle())
|
||||
.setDescription(promptInfo.getDescription())
|
||||
.setTextForDeviceCredential(
|
||||
mBundle.getCharSequence(BiometricPrompt.KEY_DEVICE_CREDENTIAL_TITLE),
|
||||
mBundle.getCharSequence(BiometricPrompt.KEY_DEVICE_CREDENTIAL_SUBTITLE),
|
||||
mBundle.getCharSequence(BiometricPrompt.KEY_DEVICE_CREDENTIAL_DESCRIPTION))
|
||||
.setConfirmationRequired(mBundle.getBoolean(
|
||||
BiometricPrompt.KEY_REQUIRE_CONFIRMATION, true))
|
||||
.setDisallowBiometricsIfPolicyExists(mBundle.getBoolean(
|
||||
BiometricPrompt.EXTRA_DISALLOW_BIOMETRICS_IF_POLICY_EXISTS, false))
|
||||
promptInfo.getDeviceCredentialTitle(),
|
||||
promptInfo.getDeviceCredentialSubtitle(),
|
||||
promptInfo.getDeviceCredentialDescription())
|
||||
.setConfirmationRequired(promptInfo.isConfirmationRequested())
|
||||
.setDisallowBiometricsIfPolicyExists(
|
||||
promptInfo.isDisallowBiometricsIfPolicyExists())
|
||||
.setReceiveSystemEvents(true);
|
||||
|
||||
mBiometricPrompt = builder.build();
|
||||
mCancellationSignal = new CancellationSignal();
|
||||
|
||||
// TODO: CC doesn't use crypto for now
|
||||
mAuthenticating = true;
|
||||
mBiometricPrompt.authenticateUser(mCancellationSignal, mClientExecutor,
|
||||
mAuthenticationCallback, mUserId);
|
||||
}
|
||||
|
@@ -30,6 +30,7 @@ import android.hardware.biometrics.BiometricConstants;
|
||||
import android.hardware.biometrics.BiometricManager;
|
||||
import android.hardware.biometrics.BiometricPrompt;
|
||||
import android.hardware.biometrics.BiometricPrompt.AuthenticationCallback;
|
||||
import android.hardware.biometrics.PromptInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
@@ -183,7 +184,7 @@ public class ConfirmDeviceCredentialActivity extends FragmentActivity {
|
||||
Intent intent = getIntent();
|
||||
mContext = this;
|
||||
mCheckDevicePolicyManager = intent
|
||||
.getBooleanExtra(BiometricPrompt.EXTRA_DISALLOW_BIOMETRICS_IF_POLICY_EXISTS, false);
|
||||
.getBooleanExtra(KeyguardManager.EXTRA_DISALLOW_BIOMETRICS_IF_POLICY_EXISTS, false);
|
||||
mTitle = intent.getStringExtra(KeyguardManager.EXTRA_TITLE);
|
||||
mDetails = intent.getStringExtra(KeyguardManager.EXTRA_DESCRIPTION);
|
||||
String alternateButton = intent.getStringExtra(
|
||||
@@ -210,20 +211,19 @@ public class ConfirmDeviceCredentialActivity extends FragmentActivity {
|
||||
mChooseLockSettingsHelper = new ChooseLockSettingsHelper(this);
|
||||
final LockPatternUtils lockPatternUtils = new LockPatternUtils(this);
|
||||
|
||||
final Bundle bpBundle = new Bundle();
|
||||
bpBundle.putString(BiometricPrompt.KEY_TITLE, mTitle);
|
||||
bpBundle.putString(BiometricPrompt.KEY_DESCRIPTION, mDetails);
|
||||
bpBundle.putBoolean(BiometricPrompt.EXTRA_DISALLOW_BIOMETRICS_IF_POLICY_EXISTS,
|
||||
mCheckDevicePolicyManager);
|
||||
final PromptInfo promptInfo = new PromptInfo();
|
||||
promptInfo.setTitle(mTitle);
|
||||
promptInfo.setDescription(mDetails);
|
||||
promptInfo.setDisallowBiometricsIfPolicyExists(mCheckDevicePolicyManager);
|
||||
|
||||
final @LockPatternUtils.CredentialType int credentialType = Utils.getCredentialType(
|
||||
mContext, effectiveUserId);
|
||||
if (mTitle == null) {
|
||||
bpBundle.putString(BiometricPrompt.KEY_DEVICE_CREDENTIAL_TITLE,
|
||||
promptInfo.setDeviceCredentialTitle(
|
||||
getTitleFromCredentialType(credentialType, isManagedProfile));
|
||||
}
|
||||
if (mDetails == null) {
|
||||
bpBundle.putString(BiometricPrompt.KEY_DEVICE_CREDENTIAL_SUBTITLE,
|
||||
promptInfo.setSubtitle(
|
||||
getDetailsFromCredentialType(credentialType, isManagedProfile));
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ public class ConfirmDeviceCredentialActivity extends FragmentActivity {
|
||||
&& !lockPatternUtils.isSeparateProfileChallengeEnabled(mUserId)) {
|
||||
mCredentialMode = CREDENTIAL_MANAGED;
|
||||
if (isBiometricAllowed(effectiveUserId, mUserId)) {
|
||||
showBiometricPrompt(bpBundle);
|
||||
showBiometricPrompt(promptInfo);
|
||||
launchedBiometric = true;
|
||||
} else {
|
||||
showConfirmCredentials();
|
||||
@@ -250,7 +250,7 @@ public class ConfirmDeviceCredentialActivity extends FragmentActivity {
|
||||
if (isBiometricAllowed(effectiveUserId, mUserId)) {
|
||||
// Don't need to check if biometrics / pin/pattern/pass are enrolled. It will go to
|
||||
// onAuthenticationError and do the right thing automatically.
|
||||
showBiometricPrompt(bpBundle);
|
||||
showBiometricPrompt(promptInfo);
|
||||
launchedBiometric = true;
|
||||
} else {
|
||||
showConfirmCredentials();
|
||||
@@ -340,7 +340,7 @@ public class ConfirmDeviceCredentialActivity extends FragmentActivity {
|
||||
.hasPendingEscrowToken(realUserId);
|
||||
}
|
||||
|
||||
private void showBiometricPrompt(Bundle bundle) {
|
||||
private void showBiometricPrompt(PromptInfo promptInfo) {
|
||||
mBiometricManager.setActiveUser(mUserId);
|
||||
|
||||
mBiometricFragment = (BiometricFragment) getSupportFragmentManager()
|
||||
@@ -348,7 +348,7 @@ public class ConfirmDeviceCredentialActivity extends FragmentActivity {
|
||||
boolean newFragment = false;
|
||||
|
||||
if (mBiometricFragment == null) {
|
||||
mBiometricFragment = BiometricFragment.newInstance(bundle);
|
||||
mBiometricFragment = BiometricFragment.newInstance(promptInfo);
|
||||
newFragment = true;
|
||||
}
|
||||
mBiometricFragment.setCallbacks(mExecutor, mAuthenticationCallback);
|
||||
|
Reference in New Issue
Block a user