Merge "Add ignoreEnrollmentState to prompt info" into sc-v2-dev

This commit is contained in:
Joshua Mccloskey
2021-11-10 18:09:27 +00:00
committed by Android (Google) Code Review
9 changed files with 55 additions and 16 deletions

View File

@@ -407,6 +407,19 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
return this; return this;
} }
/**
* Flag to decide if authentication should ignore enrollment state.
* Defaults to false (not ignoring enrollment state)
* @param ignoreEnrollmentState
* @return This builder.
* @hide
*/
@NonNull
public Builder setIgnoreEnrollmentState(boolean ignoreEnrollmentState) {
mPromptInfo.setIgnoreEnrollmentState(ignoreEnrollmentState);
return this;
}
/** /**
* Creates a {@link BiometricPrompt}. * Creates a {@link BiometricPrompt}.
* *

View File

@@ -45,6 +45,7 @@ public class PromptInfo implements Parcelable {
private boolean mReceiveSystemEvents; private boolean mReceiveSystemEvents;
@NonNull private List<Integer> mAllowedSensorIds = new ArrayList<>(); @NonNull private List<Integer> mAllowedSensorIds = new ArrayList<>();
private boolean mAllowBackgroundAuthentication; private boolean mAllowBackgroundAuthentication;
private boolean mIgnoreEnrollmentState;
public PromptInfo() { public PromptInfo() {
@@ -66,6 +67,7 @@ public class PromptInfo implements Parcelable {
mReceiveSystemEvents = in.readBoolean(); mReceiveSystemEvents = in.readBoolean();
mAllowedSensorIds = in.readArrayList(Integer.class.getClassLoader()); mAllowedSensorIds = in.readArrayList(Integer.class.getClassLoader());
mAllowBackgroundAuthentication = in.readBoolean(); mAllowBackgroundAuthentication = in.readBoolean();
mIgnoreEnrollmentState = in.readBoolean();
} }
public static final Creator<PromptInfo> CREATOR = new Creator<PromptInfo>() { public static final Creator<PromptInfo> CREATOR = new Creator<PromptInfo>() {
@@ -102,6 +104,7 @@ public class PromptInfo implements Parcelable {
dest.writeBoolean(mReceiveSystemEvents); dest.writeBoolean(mReceiveSystemEvents);
dest.writeList(mAllowedSensorIds); dest.writeList(mAllowedSensorIds);
dest.writeBoolean(mAllowBackgroundAuthentication); dest.writeBoolean(mAllowBackgroundAuthentication);
dest.writeBoolean(mIgnoreEnrollmentState);
} }
public boolean containsTestConfigurations() { public boolean containsTestConfigurations() {
@@ -192,6 +195,10 @@ public class PromptInfo implements Parcelable {
mAllowBackgroundAuthentication = allow; mAllowBackgroundAuthentication = allow;
} }
public void setIgnoreEnrollmentState(boolean ignoreEnrollmentState) {
mIgnoreEnrollmentState = ignoreEnrollmentState;
}
// Getters // Getters
public CharSequence getTitle() { public CharSequence getTitle() {
@@ -261,4 +268,8 @@ public class PromptInfo implements Parcelable {
public boolean isAllowBackgroundAuthentication() { public boolean isAllowBackgroundAuthentication() {
return mAllowBackgroundAuthentication; return mAllowBackgroundAuthentication;
} }
public boolean isIgnoreEnrollmentState() {
return mIgnoreEnrollmentState;
}
} }

View File

@@ -531,7 +531,7 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
@RequiresPermission(anyOf = {USE_BIOMETRIC, USE_FINGERPRINT}) @RequiresPermission(anyOf = {USE_BIOMETRIC, USE_FINGERPRINT})
public void authenticate(@Nullable CryptoObject crypto, @Nullable CancellationSignal cancel, public void authenticate(@Nullable CryptoObject crypto, @Nullable CancellationSignal cancel,
int flags, @NonNull AuthenticationCallback callback, @Nullable Handler handler) { int flags, @NonNull AuthenticationCallback callback, @Nullable Handler handler) {
authenticate(crypto, cancel, callback, handler, mContext.getUserId()); authenticate(crypto, cancel, callback, handler, SENSOR_ID_ANY, mContext.getUserId(), flags);
} }
/** /**
@@ -541,7 +541,7 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
@RequiresPermission(anyOf = {USE_BIOMETRIC, USE_FINGERPRINT}) @RequiresPermission(anyOf = {USE_BIOMETRIC, USE_FINGERPRINT})
public void authenticate(@Nullable CryptoObject crypto, @Nullable CancellationSignal cancel, public void authenticate(@Nullable CryptoObject crypto, @Nullable CancellationSignal cancel,
@NonNull AuthenticationCallback callback, Handler handler, int userId) { @NonNull AuthenticationCallback callback, Handler handler, int userId) {
authenticate(crypto, cancel, callback, handler, SENSOR_ID_ANY, userId); authenticate(crypto, cancel, callback, handler, SENSOR_ID_ANY, userId, 0 /* flags */);
} }
/** /**
@@ -550,7 +550,8 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
*/ */
@RequiresPermission(anyOf = {USE_BIOMETRIC, USE_FINGERPRINT}) @RequiresPermission(anyOf = {USE_BIOMETRIC, USE_FINGERPRINT})
public void authenticate(@Nullable CryptoObject crypto, @Nullable CancellationSignal cancel, public void authenticate(@Nullable CryptoObject crypto, @Nullable CancellationSignal cancel,
@NonNull AuthenticationCallback callback, Handler handler, int sensorId, int userId) { @NonNull AuthenticationCallback callback, Handler handler, int sensorId, int userId,
int flags) {
FrameworkStatsLog.write(FrameworkStatsLog.AUTH_DEPRECATED_API_USED, FrameworkStatsLog.write(FrameworkStatsLog.AUTH_DEPRECATED_API_USED,
AUTH_DEPRECATED_APIUSED__DEPRECATED_API__API_FINGERPRINT_MANAGER_AUTHENTICATE, AUTH_DEPRECATED_APIUSED__DEPRECATED_API__API_FINGERPRINT_MANAGER_AUTHENTICATE,
@@ -566,6 +567,8 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
return; return;
} }
final boolean ignoreEnrollmentState = flags == 0 ? false : true;
if (mService != null) { if (mService != null) {
try { try {
useHandler(handler); useHandler(handler);
@@ -573,7 +576,7 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
mCryptoObject = crypto; mCryptoObject = crypto;
final long operationId = crypto != null ? crypto.getOpId() : 0; final long operationId = crypto != null ? crypto.getOpId() : 0;
final long authId = mService.authenticate(mToken, operationId, sensorId, userId, final long authId = mService.authenticate(mToken, operationId, sensorId, userId,
mServiceReceiver, mContext.getOpPackageName()); mServiceReceiver, mContext.getOpPackageName(), ignoreEnrollmentState);
if (cancel != null) { if (cancel != null) {
cancel.setOnCancelListener(new OnAuthenticationCancelListener(authId)); cancel.setOnCancelListener(new OnAuthenticationCancelListener(authId));
} }

View File

@@ -52,7 +52,8 @@ interface IFingerprintService {
// permission. This is effectively deprecated, since it only comes through FingerprintManager // permission. This is effectively deprecated, since it only comes through FingerprintManager
// now. A requestId is returned that can be used to cancel this operation. // now. A requestId is returned that can be used to cancel this operation.
long authenticate(IBinder token, long operationId, int sensorId, int userId, long authenticate(IBinder token, long operationId, int sensorId, int userId,
IFingerprintServiceReceiver receiver, String opPackageName); IFingerprintServiceReceiver receiver, String opPackageName,
boolean shouldIgnoreEnrollmentState);
// Uses the fingerprint hardware to detect for the presence of a finger, without giving details // Uses the fingerprint hardware to detect for the presence of a finger, without giving details
// about accept/reject/lockout. A requestId is returned that can be used to cancel this // about accept/reject/lockout. A requestId is returned that can be used to cancel this

View File

@@ -2407,7 +2407,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
} else { } else {
mFpm.authenticate(null /* crypto */, mFingerprintCancelSignal, mFpm.authenticate(null /* crypto */, mFingerprintCancelSignal,
mFingerprintAuthenticationCallback, null /* handler */, mFingerprintAuthenticationCallback, null /* handler */,
FingerprintManager.SENSOR_ID_ANY, userId); FingerprintManager.SENSOR_ID_ANY, userId, 0 /* flags */);
} }
setFingerprintRunningState(BIOMETRIC_STATE_RUNNING); setFingerprintRunningState(BIOMETRIC_STATE_RUNNING);
} }

View File

@@ -472,7 +472,8 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
mKeyguardUpdateMonitor.dispatchStartedGoingToSleep(0 /* why */); mKeyguardUpdateMonitor.dispatchStartedGoingToSleep(0 /* why */);
mTestableLooper.processAllMessages(); mTestableLooper.processAllMessages();
verify(mFingerprintManager).authenticate(any(), any(), any(), any(), anyInt(), anyInt()); verify(mFingerprintManager).authenticate(any(), any(), any(), any(), anyInt(), anyInt(),
anyInt());
verify(mFingerprintManager, never()).detectFingerprint(any(), any(), anyInt()); verify(mFingerprintManager, never()).detectFingerprint(any(), any(), anyInt());
} }

View File

@@ -1381,7 +1381,8 @@ public class BiometricService extends SystemService {
Slog.d(TAG, "handleAuthenticate: modality(" + preAuthStatus.first Slog.d(TAG, "handleAuthenticate: modality(" + preAuthStatus.first
+ "), status(" + preAuthStatus.second + "), preAuthInfo: " + preAuthInfo + "), status(" + preAuthStatus.second + "), preAuthInfo: " + preAuthInfo
+ " requestId: " + requestId); + " requestId: " + requestId + " promptInfo.isIgnoreEnrollmentState: "
+ promptInfo.isIgnoreEnrollmentState());
if (preAuthStatus.second == BiometricConstants.BIOMETRIC_SUCCESS) { if (preAuthStatus.second == BiometricConstants.BIOMETRIC_SUCCESS) {
// If BIOMETRIC_WEAK or BIOMETRIC_STRONG are allowed, but not enrolled, but // If BIOMETRIC_WEAK or BIOMETRIC_STRONG are allowed, but not enrolled, but

View File

@@ -83,6 +83,7 @@ class PreAuthInfo {
final List<Pair<BiometricSensor, Integer>> ineligibleSensors; final List<Pair<BiometricSensor, Integer>> ineligibleSensors;
final boolean credentialAvailable; final boolean credentialAvailable;
final boolean confirmationRequested; final boolean confirmationRequested;
final boolean ignoreEnrollmentState;
static PreAuthInfo create(ITrustManager trustManager, static PreAuthInfo create(ITrustManager trustManager,
DevicePolicyManager devicePolicyManager, DevicePolicyManager devicePolicyManager,
@@ -114,7 +115,8 @@ class PreAuthInfo {
@AuthenticatorStatus int status = getStatusForBiometricAuthenticator( @AuthenticatorStatus int status = getStatusForBiometricAuthenticator(
devicePolicyManager, settingObserver, sensor, userId, opPackageName, devicePolicyManager, settingObserver, sensor, userId, opPackageName,
checkDevicePolicyManager, requestedStrength, checkDevicePolicyManager, requestedStrength,
promptInfo.getAllowedSensorIds()); promptInfo.getAllowedSensorIds(),
promptInfo.isIgnoreEnrollmentState());
Slog.d(TAG, "Package: " + opPackageName Slog.d(TAG, "Package: " + opPackageName
+ " Sensor ID: " + sensor.id + " Sensor ID: " + sensor.id
@@ -130,7 +132,8 @@ class PreAuthInfo {
} }
return new PreAuthInfo(biometricRequested, requestedStrength, credentialRequested, return new PreAuthInfo(biometricRequested, requestedStrength, credentialRequested,
eligibleSensors, ineligibleSensors, credentialAvailable, confirmationRequested); eligibleSensors, ineligibleSensors, credentialAvailable, confirmationRequested,
promptInfo.isIgnoreEnrollmentState());
} }
/** /**
@@ -145,7 +148,8 @@ class PreAuthInfo {
BiometricService.SettingObserver settingObserver, BiometricService.SettingObserver settingObserver,
BiometricSensor sensor, int userId, String opPackageName, BiometricSensor sensor, int userId, String opPackageName,
boolean checkDevicePolicyManager, int requestedStrength, boolean checkDevicePolicyManager, int requestedStrength,
@NonNull List<Integer> requestedSensorIds) { @NonNull List<Integer> requestedSensorIds,
boolean ignoreEnrollmentState) {
if (!requestedSensorIds.isEmpty() && !requestedSensorIds.contains(sensor.id)) { if (!requestedSensorIds.isEmpty() && !requestedSensorIds.contains(sensor.id)) {
return BIOMETRIC_NO_HARDWARE; return BIOMETRIC_NO_HARDWARE;
@@ -167,7 +171,8 @@ class PreAuthInfo {
return BIOMETRIC_HARDWARE_NOT_DETECTED; return BIOMETRIC_HARDWARE_NOT_DETECTED;
} }
if (!sensor.impl.hasEnrolledTemplates(userId, opPackageName)) { if (!sensor.impl.hasEnrolledTemplates(userId, opPackageName)
&& !ignoreEnrollmentState) {
return BIOMETRIC_NOT_ENROLLED; return BIOMETRIC_NOT_ENROLLED;
} }
@@ -238,7 +243,7 @@ class PreAuthInfo {
private PreAuthInfo(boolean biometricRequested, int biometricStrengthRequested, private PreAuthInfo(boolean biometricRequested, int biometricStrengthRequested,
boolean credentialRequested, List<BiometricSensor> eligibleSensors, boolean credentialRequested, List<BiometricSensor> eligibleSensors,
List<Pair<BiometricSensor, Integer>> ineligibleSensors, boolean credentialAvailable, List<Pair<BiometricSensor, Integer>> ineligibleSensors, boolean credentialAvailable,
boolean confirmationRequested) { boolean confirmationRequested, boolean ignoreEnrollmentState) {
mBiometricRequested = biometricRequested; mBiometricRequested = biometricRequested;
mBiometricStrengthRequested = biometricStrengthRequested; mBiometricStrengthRequested = biometricStrengthRequested;
this.credentialRequested = credentialRequested; this.credentialRequested = credentialRequested;
@@ -247,6 +252,7 @@ class PreAuthInfo {
this.ineligibleSensors = ineligibleSensors; this.ineligibleSensors = ineligibleSensors;
this.credentialAvailable = credentialAvailable; this.credentialAvailable = credentialAvailable;
this.confirmationRequested = confirmationRequested; this.confirmationRequested = confirmationRequested;
this.ignoreEnrollmentState = ignoreEnrollmentState;
} }
private Pair<BiometricSensor, Integer> calculateErrorByPriority() { private Pair<BiometricSensor, Integer> calculateErrorByPriority() {

View File

@@ -281,7 +281,7 @@ public class FingerprintService extends SystemService {
@Override // Binder call @Override // Binder call
public long authenticate(final IBinder token, final long operationId, public long authenticate(final IBinder token, final long operationId,
final int sensorId, final int userId, final IFingerprintServiceReceiver receiver, final int sensorId, final int userId, final IFingerprintServiceReceiver receiver,
final String opPackageName) { final String opPackageName, boolean ignoreEnrollmentState) {
final int callingUid = Binder.getCallingUid(); final int callingUid = Binder.getCallingUid();
final int callingPid = Binder.getCallingPid(); final int callingPid = Binder.getCallingPid();
final int callingUserId = UserHandle.getCallingUserId(); final int callingUserId = UserHandle.getCallingUserId();
@@ -333,7 +333,8 @@ public class FingerprintService extends SystemService {
&& sensorProps != null && sensorProps.isAnyUdfpsType()) { && sensorProps != null && sensorProps.isAnyUdfpsType()) {
identity = Binder.clearCallingIdentity(); identity = Binder.clearCallingIdentity();
try { try {
return authenticateWithPrompt(operationId, sensorProps, userId, receiver); return authenticateWithPrompt(operationId, sensorProps, userId, receiver,
ignoreEnrollmentState);
} finally { } finally {
Binder.restoreCallingIdentity(identity); Binder.restoreCallingIdentity(identity);
} }
@@ -347,7 +348,8 @@ public class FingerprintService extends SystemService {
final long operationId, final long operationId,
@NonNull final FingerprintSensorPropertiesInternal props, @NonNull final FingerprintSensorPropertiesInternal props,
final int userId, final int userId,
final IFingerprintServiceReceiver receiver) { final IFingerprintServiceReceiver receiver,
boolean ignoreEnrollmentState) {
final Context context = getUiContext(); final Context context = getUiContext();
final Executor executor = context.getMainExecutor(); final Executor executor = context.getMainExecutor();
@@ -368,6 +370,7 @@ public class FingerprintService extends SystemService {
}) })
.setAllowedSensorIds(new ArrayList<>( .setAllowedSensorIds(new ArrayList<>(
Collections.singletonList(props.sensorId))) Collections.singletonList(props.sensorId)))
.setIgnoreEnrollmentState(ignoreEnrollmentState)
.build(); .build();
final BiometricPrompt.AuthenticationCallback promptCallback = final BiometricPrompt.AuthenticationCallback promptCallback =