Update face detectInteraction
1) Sets the sensor property based on the HAL, instead of hard coding false 2) Schedules/cancels detection when requested 3) Updates biometric dumpsys to include internal properties Test: atest com.android.server.biometrics Test: adb shell dumpsys biometric Test: manual Bug: 184672091 Change-Id: I2fb1db0994f6d2ed235420967d78e70f1b13cdd0
This commit is contained in:
@@ -96,6 +96,7 @@ public class FaceSensorPropertiesInternal extends SensorPropertiesInternal {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ID: " + sensorId + ", Strength: " + sensorStrength + ", Type: " + sensorType;
|
||||
return "ID: " + sensorId + ", Strength: " + sensorStrength + ", Type: " + sensorType
|
||||
+ ", SupportsFaceDetection: " + supportsFaceDetection;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2131,8 +2131,14 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
|
||||
|
||||
// Scan even when encrypted or timeout to show a preemptive bouncer when bypassing.
|
||||
// Lock-down mode shouldn't scan, since it is more explicit.
|
||||
boolean strongAuthAllowsScanning = (!isEncryptedOrTimedOut || canBypass && !mBouncer)
|
||||
&& !isLockDown;
|
||||
boolean strongAuthAllowsScanning = (!isEncryptedOrTimedOut || canBypass && !mBouncer);
|
||||
|
||||
// If the device supports face detection (without authentication), allow it to happen
|
||||
// if the device is in lockdown mode. Otherwise, prevent scanning.
|
||||
boolean supportsDetectOnly = mFaceSensorProperties.get(0).supportsFaceDetection;
|
||||
if (isLockDown && !supportsDetectOnly) {
|
||||
strongAuthAllowsScanning = false;
|
||||
}
|
||||
|
||||
// Only listen if this KeyguardUpdateMonitor belongs to the primary user. There is an
|
||||
// instance of KeyguardUpdateMonitor for each user but KeyguardUpdateMonitor is user-aware.
|
||||
|
||||
@@ -19,10 +19,13 @@ package com.android.server.biometrics;
|
||||
import static android.hardware.biometrics.BiometricManager.Authenticators;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.NonNull;
|
||||
import android.content.Context;
|
||||
import android.hardware.biometrics.BiometricConstants;
|
||||
import android.hardware.biometrics.BiometricManager;
|
||||
import android.hardware.biometrics.IBiometricAuthenticator;
|
||||
import android.hardware.biometrics.IBiometricSensorReceiver;
|
||||
import android.hardware.biometrics.SensorPropertiesInternal;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Slog;
|
||||
@@ -62,6 +65,7 @@ public abstract class BiometricSensor {
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@interface SensorState {}
|
||||
|
||||
@NonNull private final Context mContext;
|
||||
public final int id;
|
||||
public final @Authenticators.Types int oemStrength; // strength as configured by the OEM
|
||||
public final int modality;
|
||||
@@ -84,8 +88,9 @@ public abstract class BiometricSensor {
|
||||
*/
|
||||
abstract boolean confirmationSupported();
|
||||
|
||||
BiometricSensor(int id, int modality, @Authenticators.Types int strength,
|
||||
IBiometricAuthenticator impl) {
|
||||
BiometricSensor(@NonNull Context context, int id, int modality,
|
||||
@Authenticators.Types int strength, IBiometricAuthenticator impl) {
|
||||
this.mContext = context;
|
||||
this.id = id;
|
||||
this.modality = modality;
|
||||
this.oemStrength = strength;
|
||||
@@ -169,12 +174,19 @@ public abstract class BiometricSensor {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
SensorPropertiesInternal properties = null;
|
||||
try {
|
||||
properties = impl.getSensorProperties(mContext.getOpPackageName());
|
||||
} catch (RemoteException e) {
|
||||
Slog.e(TAG, "Remote exception", e);
|
||||
}
|
||||
|
||||
return "ID(" + id + ")"
|
||||
+ ", oemStrength: " + oemStrength
|
||||
+ ", updatedStrength: " + mUpdatedStrength
|
||||
+ ", modality " + modality
|
||||
+ ", state: " + mSensorState
|
||||
+ ", cookie: " + mCookie
|
||||
+ ", authenticator: " + impl;
|
||||
+ ", props: " + properties;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -725,7 +725,7 @@ public class BiometricService extends SystemService {
|
||||
}
|
||||
}
|
||||
|
||||
mSensors.add(new BiometricSensor(id, modality, strength, authenticator) {
|
||||
mSensors.add(new BiometricSensor(getContext(), id, modality, strength, authenticator) {
|
||||
@Override
|
||||
boolean confirmationAlwaysRequired(int userId) {
|
||||
return mSettingObserver.getConfirmationAlwaysRequired(modality, userId);
|
||||
@@ -1351,13 +1351,8 @@ public class BiometricService extends SystemService {
|
||||
for (BiometricSensor sensor : mSensors) {
|
||||
pw.println(" " + sensor);
|
||||
}
|
||||
pw.println();
|
||||
pw.println("CurrentSession: " + mCurrentAuthSession);
|
||||
|
||||
final List<FingerprintSensorPropertiesInternal> fpProps =
|
||||
mInjector.getFingerprintSensorProperties(getContext());
|
||||
pw.println("FingerprintSensorProperties: " + fpProps.size());
|
||||
for (FingerprintSensorPropertiesInternal prop : fpProps) {
|
||||
pw.println(" " + prop);
|
||||
}
|
||||
pw.println();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -559,22 +559,21 @@ public class BiometricScheduler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests to cancel authentication.
|
||||
* Requests to cancel authentication or detection.
|
||||
* @param token from the caller, should match the token passed in when requesting authentication
|
||||
*/
|
||||
public void cancelAuthentication(IBinder token) {
|
||||
public void cancelAuthenticationOrDetection(IBinder token) {
|
||||
if (mCurrentOperation == null) {
|
||||
Slog.e(getTag(), "Unable to cancel authentication, null operation");
|
||||
return;
|
||||
}
|
||||
final boolean isAuthenticating =
|
||||
mCurrentOperation.mClientMonitor instanceof AuthenticationConsumer;
|
||||
final boolean isCorrectClient = isAuthenticationOrDetectionOperation(mCurrentOperation);
|
||||
final boolean tokenMatches = mCurrentOperation.mClientMonitor.getToken() == token;
|
||||
|
||||
if (isAuthenticating && tokenMatches) {
|
||||
Slog.d(getTag(), "Cancelling authentication: " + mCurrentOperation);
|
||||
if (isCorrectClient && tokenMatches) {
|
||||
Slog.d(getTag(), "Cancelling: " + mCurrentOperation);
|
||||
cancelInternal(mCurrentOperation);
|
||||
} else if (!isAuthenticating) {
|
||||
} else if (!isCorrectClient) {
|
||||
// Look through the current queue for all authentication clients for the specified
|
||||
// token, and mark them as STATE_WAITING_IN_QUEUE_CANCELING. Note that we're marking
|
||||
// all of them, instead of just the first one, since the API surface currently doesn't
|
||||
@@ -582,7 +581,7 @@ public class BiometricScheduler {
|
||||
// process. However, this generally does not happen anyway, and would be a class of
|
||||
// bugs on its own.
|
||||
for (Operation operation : mPendingOperations) {
|
||||
if (operation.mClientMonitor instanceof AuthenticationConsumer
|
||||
if (isAuthenticationOrDetectionOperation(operation)
|
||||
&& operation.mClientMonitor.getToken() == token) {
|
||||
Slog.d(getTag(), "Marking " + operation
|
||||
+ " as STATE_WAITING_IN_QUEUE_CANCELING");
|
||||
@@ -592,6 +591,13 @@ public class BiometricScheduler {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isAuthenticationOrDetectionOperation(@NonNull Operation operation) {
|
||||
final boolean isAuthentication = operation.mClientMonitor
|
||||
instanceof AuthenticationConsumer;
|
||||
final boolean isDetection = operation.mClientMonitor instanceof DetectionConsumer;
|
||||
return isAuthentication || isDetection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the current operation
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.server.biometrics.sensors;
|
||||
|
||||
/**
|
||||
* Interface that clients interested/eligible for interaction detection events should implement.
|
||||
*/
|
||||
public interface DetectionConsumer {
|
||||
void onInteractionDetected();
|
||||
}
|
||||
@@ -296,7 +296,15 @@ public class FaceService extends SystemService implements BiometricServiceCallba
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO(b/152413782): Implement this once it's supported in the HAL
|
||||
final Pair<Integer, ServiceProvider> provider = getSingleProvider();
|
||||
if (provider == null) {
|
||||
Slog.w(TAG, "Null provider for detectFace");
|
||||
return;
|
||||
}
|
||||
|
||||
provider.second.scheduleFaceDetect(provider.first, token, userId,
|
||||
new ClientMonitorCallbackConverter(receiver), opPackageName,
|
||||
BiometricsProtoEnums.CLIENT_KEYGUARD);
|
||||
}
|
||||
|
||||
@Override // Binder call
|
||||
@@ -353,7 +361,13 @@ public class FaceService extends SystemService implements BiometricServiceCallba
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO(b/152413782): Implement this once it's supported in the HAL
|
||||
final Pair<Integer, ServiceProvider> provider = getSingleProvider();
|
||||
if (provider == null) {
|
||||
Slog.w(TAG, "Null provider for cancelFaceDetect");
|
||||
return;
|
||||
}
|
||||
|
||||
provider.second.cancelFaceDetect(provider.first, token);
|
||||
}
|
||||
|
||||
@Override // Binder call
|
||||
|
||||
@@ -101,12 +101,17 @@ public interface ServiceProvider {
|
||||
|
||||
void cancelEnrollment(int sensorId, @NonNull IBinder token);
|
||||
|
||||
void scheduleFaceDetect(int sensorId, @NonNull IBinder token, int userId,
|
||||
@NonNull ClientMonitorCallbackConverter callback, @NonNull String opPackageName,
|
||||
int statsClient);
|
||||
|
||||
void cancelFaceDetect(int sensorId, @NonNull IBinder token);
|
||||
|
||||
void scheduleAuthenticate(int sensorId, @NonNull IBinder token, long operationId, int userId,
|
||||
int cookie, @NonNull ClientMonitorCallbackConverter callback,
|
||||
@NonNull String opPackageName, boolean restricted, int statsClient,
|
||||
boolean allowBackgroundAuthentication);
|
||||
|
||||
|
||||
void cancelAuthentication(int sensorId, @NonNull IBinder token);
|
||||
|
||||
void scheduleRemove(int sensorId, @NonNull IBinder token, int faceId, int userId,
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.server.biometrics.sensors.face.aidl;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.hardware.biometrics.BiometricsProtoEnums;
|
||||
import android.hardware.biometrics.common.ICancellationSignal;
|
||||
import android.hardware.biometrics.face.ISession;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Slog;
|
||||
|
||||
import com.android.server.biometrics.BiometricsProto;
|
||||
import com.android.server.biometrics.sensors.AcquisitionClient;
|
||||
import com.android.server.biometrics.sensors.ClientMonitorCallbackConverter;
|
||||
import com.android.server.biometrics.sensors.DetectionConsumer;
|
||||
|
||||
/**
|
||||
* Performs face detection without exposing any matching information (e.g. accept/reject have the
|
||||
* same haptic, lockout counter is not increased).
|
||||
*/
|
||||
public class FaceDetectClient extends AcquisitionClient<ISession> implements DetectionConsumer {
|
||||
|
||||
private static final String TAG = "FaceDetectClient";
|
||||
|
||||
private final boolean mIsStrongBiometric;
|
||||
@Nullable private ICancellationSignal mCancellationSignal;
|
||||
|
||||
public FaceDetectClient(@NonNull Context context, @NonNull LazyDaemon<ISession> lazyDaemon,
|
||||
@NonNull IBinder token, @NonNull ClientMonitorCallbackConverter listener, int userId,
|
||||
@NonNull String owner, int sensorId, boolean isStrongBiometric, int statsClient) {
|
||||
super(context, lazyDaemon, token, listener, userId, owner, 0 /* cookie */, sensorId,
|
||||
BiometricsProtoEnums.MODALITY_FACE, BiometricsProtoEnums.ACTION_AUTHENTICATE,
|
||||
statsClient);
|
||||
mIsStrongBiometric = isStrongBiometric;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(@NonNull Callback callback) {
|
||||
super.start(callback);
|
||||
startHalOperation();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void stopHalOperation() {
|
||||
try {
|
||||
mCancellationSignal.cancel();
|
||||
} catch (RemoteException e) {
|
||||
Slog.e(TAG, "Remote exception", e);
|
||||
mCallback.onClientFinished(this, false /* success */);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startHalOperation() {
|
||||
try {
|
||||
mCancellationSignal = getFreshDaemon().detectInteraction();
|
||||
} catch (RemoteException e) {
|
||||
Slog.e(TAG, "Remote exception when requesting face detect", e);
|
||||
mCallback.onClientFinished(this, false /* success */);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInteractionDetected() {
|
||||
vibrateSuccess();
|
||||
|
||||
try {
|
||||
getListener().onDetected(getSensorId(), getTargetUserId(), mIsStrongBiometric);
|
||||
mCallback.onClientFinished(this, true /* success */);
|
||||
} catch (RemoteException e) {
|
||||
Slog.e(TAG, "Remote exception when sending onDetected", e);
|
||||
mCallback.onClientFinished(this, false /* success */);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProtoEnum() {
|
||||
return BiometricsProto.CM_DETECT_INTERACTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean interruptsPrecedingClients() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -110,7 +110,7 @@ public class FaceProvider implements IBinder.DeathRecipient, ServiceProvider {
|
||||
Slog.e(getTag(), "Stopping background authentication, top: "
|
||||
+ topPackage + " currentClient: " + client);
|
||||
mSensors.valueAt(i).getScheduler()
|
||||
.cancelAuthentication(client.getToken());
|
||||
.cancelAuthenticationOrDetection(client.getToken());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -145,7 +145,7 @@ public class FaceProvider implements IBinder.DeathRecipient, ServiceProvider {
|
||||
final FaceSensorPropertiesInternal internalProp = new FaceSensorPropertiesInternal(
|
||||
prop.commonProps.sensorId, prop.commonProps.sensorStrength,
|
||||
prop.commonProps.maxEnrollmentsPerUser, componentInfo, prop.sensorType,
|
||||
false /* supportsFaceDetection */, prop.halControlsPreview,
|
||||
prop.supportsDetectInteraction, prop.halControlsPreview,
|
||||
false /* resetLockoutRequiresChallenge */);
|
||||
final Sensor sensor = new Sensor(getTag() + "/" + sensorId, this, mContext, mHandler,
|
||||
internalProp);
|
||||
@@ -345,6 +345,25 @@ public class FaceProvider implements IBinder.DeathRecipient, ServiceProvider {
|
||||
mHandler.post(() -> mSensors.get(sensorId).getScheduler().cancelEnrollment(token));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scheduleFaceDetect(int sensorId, @NonNull IBinder token,
|
||||
int userId, @NonNull ClientMonitorCallbackConverter callback,
|
||||
@NonNull String opPackageName, int statsClient) {
|
||||
mHandler.post(() -> {
|
||||
final boolean isStrongBiometric = Utils.isStrongBiometric(sensorId);
|
||||
final FaceDetectClient client = new FaceDetectClient(mContext,
|
||||
mSensors.get(sensorId).getLazySession(), token, callback, userId, opPackageName,
|
||||
sensorId, isStrongBiometric, statsClient);
|
||||
scheduleForSensor(sensorId, client);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelFaceDetect(int sensorId, @NonNull IBinder token) {
|
||||
mHandler.post(() -> mSensors.get(sensorId).getScheduler()
|
||||
.cancelAuthenticationOrDetection(token));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scheduleAuthenticate(int sensorId, @NonNull IBinder token, long operationId,
|
||||
int userId, int cookie, @NonNull ClientMonitorCallbackConverter callback,
|
||||
@@ -364,7 +383,8 @@ public class FaceProvider implements IBinder.DeathRecipient, ServiceProvider {
|
||||
|
||||
@Override
|
||||
public void cancelAuthentication(int sensorId, @NonNull IBinder token) {
|
||||
mHandler.post(() -> mSensors.get(sensorId).getScheduler().cancelAuthentication(token));
|
||||
mHandler.post(() -> mSensors.get(sensorId).getScheduler()
|
||||
.cancelAuthenticationOrDetection(token));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -337,7 +337,17 @@ public class Sensor {
|
||||
|
||||
@Override
|
||||
public void onInteractionDetected() {
|
||||
// no-op
|
||||
mHandler.post(() -> {
|
||||
final BaseClientMonitor client = mScheduler.getCurrentClient();
|
||||
if (!(client instanceof FaceDetectClient)) {
|
||||
Slog.e(mTag, "onInteractionDetected for wrong client: "
|
||||
+ Utils.getClientName(client));
|
||||
return;
|
||||
}
|
||||
|
||||
final FaceDetectClient detectClient = (FaceDetectClient) client;
|
||||
detectClient.onInteractionDetected();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -637,6 +637,20 @@ public class Face10 implements IHwBinder.DeathRecipient, ServiceProvider {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scheduleFaceDetect(int sensorId, @NonNull IBinder token,
|
||||
int userId, @NonNull ClientMonitorCallbackConverter callback,
|
||||
@NonNull String opPackageName, int statsClient) {
|
||||
throw new IllegalStateException("Face detect not supported by IBiometricsFace@1.0. Did you"
|
||||
+ "forget to check the supportsFaceDetection flag?");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelFaceDetect(int sensorId, @NonNull IBinder token) {
|
||||
throw new IllegalStateException("Face detect not supported by IBiometricsFace@1.0. Did you"
|
||||
+ "forget to check the supportsFaceDetection flag?");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scheduleAuthenticate(int sensorId, @NonNull IBinder token, long operationId,
|
||||
int userId, int cookie, @NonNull ClientMonitorCallbackConverter receiver,
|
||||
@@ -657,7 +671,7 @@ public class Face10 implements IHwBinder.DeathRecipient, ServiceProvider {
|
||||
@Override
|
||||
public void cancelAuthentication(int sensorId, @NonNull IBinder token) {
|
||||
mHandler.post(() -> {
|
||||
mScheduler.cancelAuthentication(token);
|
||||
mScheduler.cancelAuthenticationOrDetection(token);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,12 @@ class FingerprintDetectClient extends AcquisitionClient<ISession> {
|
||||
mUdfpsOverlayController = udfpsOverlayController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(@NonNull Callback callback) {
|
||||
super.start(callback);
|
||||
startHalOperation();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void stopHalOperation() {
|
||||
UdfpsHelper.hideUdfpsOverlay(getSensorId(), mUdfpsOverlayController);
|
||||
|
||||
@@ -115,7 +115,7 @@ public class FingerprintProvider implements IBinder.DeathRecipient, ServiceProvi
|
||||
Slog.e(getTag(), "Stopping background authentication, top: "
|
||||
+ topPackage + " currentClient: " + client);
|
||||
mSensors.valueAt(i).getScheduler()
|
||||
.cancelAuthentication(client.getToken());
|
||||
.cancelAuthenticationOrDetection(client.getToken());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -383,7 +383,8 @@ public class FingerprintProvider implements IBinder.DeathRecipient, ServiceProvi
|
||||
|
||||
@Override
|
||||
public void cancelAuthentication(int sensorId, @NonNull IBinder token) {
|
||||
mHandler.post(() -> mSensors.get(sensorId).getScheduler().cancelAuthentication(token));
|
||||
mHandler.post(() -> mSensors.get(sensorId).getScheduler()
|
||||
.cancelAuthenticationOrDetection(token));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -143,7 +143,7 @@ public class Fingerprint21 implements IHwBinder.DeathRecipient, ServiceProvider
|
||||
&& !client.isAlreadyDone()) {
|
||||
Slog.e(TAG, "Stopping background authentication, top: "
|
||||
+ topPackage + " currentClient: " + client);
|
||||
mScheduler.cancelAuthentication(client.getToken());
|
||||
mScheduler.cancelAuthenticationOrDetection(client.getToken());
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -644,7 +644,7 @@ public class Fingerprint21 implements IHwBinder.DeathRecipient, ServiceProvider
|
||||
|
||||
@Override
|
||||
public void cancelAuthentication(int sensorId, @NonNull IBinder token) {
|
||||
mHandler.post(() -> mScheduler.cancelAuthentication(token));
|
||||
mHandler.post(() -> mScheduler.cancelAuthenticationOrDetection(token));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -279,7 +279,7 @@ public class AuthSessionTest {
|
||||
IBiometricAuthenticator fingerprintAuthenticator = mock(IBiometricAuthenticator.class);
|
||||
when(fingerprintAuthenticator.isHardwareDetected(any())).thenReturn(true);
|
||||
when(fingerprintAuthenticator.hasEnrolledTemplates(anyInt(), any())).thenReturn(true);
|
||||
mSensors.add(new BiometricSensor(id,
|
||||
mSensors.add(new BiometricSensor(mContext, id,
|
||||
TYPE_FINGERPRINT /* modality */,
|
||||
Authenticators.BIOMETRIC_STRONG /* strength */,
|
||||
fingerprintAuthenticator) {
|
||||
@@ -314,7 +314,7 @@ public class AuthSessionTest {
|
||||
IBiometricAuthenticator authenticator) throws RemoteException {
|
||||
when(authenticator.isHardwareDetected(any())).thenReturn(true);
|
||||
when(authenticator.hasEnrolledTemplates(anyInt(), any())).thenReturn(true);
|
||||
mSensors.add(new BiometricSensor(id,
|
||||
mSensors.add(new BiometricSensor(mContext, id,
|
||||
TYPE_FACE /* modality */,
|
||||
Authenticators.BIOMETRIC_STRONG /* strength */,
|
||||
authenticator) {
|
||||
|
||||
@@ -1278,10 +1278,10 @@ public class BiometricServiceTest {
|
||||
|
||||
for (int i = 0; i < testCases.length; i++) {
|
||||
final BiometricSensor sensor =
|
||||
new BiometricSensor(0 /* id */,
|
||||
new BiometricSensor(mContext, 0 /* id */,
|
||||
BiometricAuthenticator.TYPE_FINGERPRINT,
|
||||
testCases[i][0],
|
||||
null /* impl */) {
|
||||
mock(IBiometricAuthenticator.class)) {
|
||||
@Override
|
||||
boolean confirmationAlwaysRequired(int userId) {
|
||||
return false;
|
||||
|
||||
@@ -24,6 +24,7 @@ import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.content.Context;
|
||||
import android.hardware.biometrics.BiometricAuthenticator;
|
||||
import android.hardware.biometrics.BiometricManager.Authenticators;
|
||||
@@ -35,7 +36,10 @@ import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.server.biometrics.BiometricService.InvalidationTracker;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -43,29 +47,37 @@ import java.util.ArrayList;
|
||||
@SmallTest
|
||||
public class InvalidationTrackerTest {
|
||||
|
||||
@Mock
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCallbackReceived_whenAllStrongSensorsInvalidated() throws Exception {
|
||||
final IBiometricAuthenticator authenticator1 = mock(IBiometricAuthenticator.class);
|
||||
when(authenticator1.hasEnrolledTemplates(anyInt(), any())).thenReturn(true);
|
||||
final TestSensor sensor1 = new TestSensor(0 /* id */,
|
||||
final TestSensor sensor1 = new TestSensor(mContext, 0 /* id */,
|
||||
BiometricAuthenticator.TYPE_FINGERPRINT, Authenticators.BIOMETRIC_STRONG,
|
||||
authenticator1);
|
||||
|
||||
final IBiometricAuthenticator authenticator2 = mock(IBiometricAuthenticator.class);
|
||||
when(authenticator2.hasEnrolledTemplates(anyInt(), any())).thenReturn(true);
|
||||
final TestSensor sensor2 = new TestSensor(1 /* id */,
|
||||
final TestSensor sensor2 = new TestSensor(mContext, 1 /* id */,
|
||||
BiometricAuthenticator.TYPE_FINGERPRINT, Authenticators.BIOMETRIC_STRONG,
|
||||
authenticator2);
|
||||
|
||||
final IBiometricAuthenticator authenticator3 = mock(IBiometricAuthenticator.class);
|
||||
when(authenticator3.hasEnrolledTemplates(anyInt(), any())).thenReturn(true);
|
||||
final TestSensor sensor3 = new TestSensor(2 /* id */,
|
||||
final TestSensor sensor3 = new TestSensor(mContext, 2 /* id */,
|
||||
BiometricAuthenticator.TYPE_FACE, Authenticators.BIOMETRIC_STRONG,
|
||||
authenticator3);
|
||||
|
||||
final IBiometricAuthenticator authenticator4 = mock(IBiometricAuthenticator.class);
|
||||
when(authenticator4.hasEnrolledTemplates(anyInt(), any())).thenReturn(true);
|
||||
final TestSensor sensor4 = new TestSensor(3 /* id */,
|
||||
final TestSensor sensor4 = new TestSensor(mContext, 3 /* id */,
|
||||
BiometricAuthenticator.TYPE_FACE, Authenticators.BIOMETRIC_WEAK,
|
||||
authenticator4);
|
||||
|
||||
@@ -101,8 +113,9 @@ public class InvalidationTrackerTest {
|
||||
|
||||
private static class TestSensor extends BiometricSensor {
|
||||
|
||||
TestSensor(int id, int modality, int strength, IBiometricAuthenticator impl) {
|
||||
super(id, modality, strength, impl);
|
||||
TestSensor(@NonNull Context context, int id, int modality, int strength,
|
||||
@NonNull IBiometricAuthenticator impl) {
|
||||
super(context, id, modality, strength, impl);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -188,7 +188,7 @@ public class BiometricSchedulerTest {
|
||||
// Request it to be canceled. The operation can be canceled immediately, and the scheduler
|
||||
// should go back to idle, since in this case the framework has not even requested the HAL
|
||||
// to authenticate yet.
|
||||
mScheduler.cancelAuthentication(mToken);
|
||||
mScheduler.cancelAuthenticationOrDetection(mToken);
|
||||
assertNull(mScheduler.mCurrentOperation);
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ public class BiometricSchedulerTest {
|
||||
mScheduler.mPendingOperations.getFirst().mState);
|
||||
|
||||
// Request cancel before the authentication client has started
|
||||
mScheduler.cancelAuthentication(mToken);
|
||||
mScheduler.cancelAuthenticationOrDetection(mToken);
|
||||
waitForIdle();
|
||||
assertEquals(Operation.STATE_WAITING_IN_QUEUE_CANCELING,
|
||||
mScheduler.mPendingOperations.getFirst().mState);
|
||||
|
||||
Reference in New Issue
Block a user