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:
Kevin Chyn
2020-05-13 11:40:26 -07:00
parent 9c0ab6d713
commit f761b35ef5
2 changed files with 32 additions and 43 deletions

View File

@@ -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);
}