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