Merge "Revert "Add ComponentInfo in sensor properties into dumpsys"" into udc-dev

This commit is contained in:
Haining Chen
2023-05-12 06:12:27 +00:00
committed by Android (Google) Code Review
14 changed files with 131 additions and 219 deletions

View File

@@ -19,8 +19,6 @@ package android.hardware.biometrics;
import android.annotation.NonNull;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.IndentingPrintWriter;
/**
* The internal class for storing the component info for a subsystem of the biometric sensor,
@@ -92,19 +90,12 @@ public class ComponentInfoInternal implements Parcelable {
dest.writeString(softwareVersion);
}
/**
* Print the component info into the given stream.
*
* @param pw The stream to dump the info into.
* @hide
*/
public void dump(@NonNull IndentingPrintWriter pw) {
pw.println(TextUtils.formatSimple("componentId: %s", componentId));
pw.increaseIndent();
pw.println(TextUtils.formatSimple("hardwareVersion: %s", hardwareVersion));
pw.println(TextUtils.formatSimple("firmwareVersion: %s", firmwareVersion));
pw.println(TextUtils.formatSimple("serialNumber: %s", serialNumber));
pw.println(TextUtils.formatSimple("softwareVersion: %s", softwareVersion));
pw.decreaseIndent();
@Override
public String toString() {
return "ComponentId: " + componentId
+ ", HardwareVersion: " + hardwareVersion
+ ", FirmwareVersion: " + firmwareVersion
+ ", SerialNumber " + serialNumber
+ ", SoftwareVersion: " + softwareVersion;
}
}

View File

@@ -58,10 +58,10 @@ interface IBiometricService {
boolean hasEnrolledBiometrics(int userId, String opPackageName);
// Registers an authenticator (e.g. face, fingerprint, iris).
// Sensor Id in sensor props must be unique, whereas modality doesn't need to be.
// Id must be unique, whereas strength and modality don't need to be.
// TODO(b/123321528): Turn strength and modality into enums.
@EnforcePermission("USE_BIOMETRIC_INTERNAL")
void registerAuthenticator(int modality, in SensorPropertiesInternal props,
void registerAuthenticator(int id, int modality, int strength,
IBiometricAuthenticator authenticator);
// Register callback for when keyguard biometric eligibility changes.

View File

@@ -22,20 +22,14 @@ import android.annotation.IntDef;
import android.annotation.NonNull;
import android.content.Context;
import android.hardware.biometrics.BiometricConstants;
import android.hardware.biometrics.ComponentInfoInternal;
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.text.TextUtils;
import android.util.IndentingPrintWriter;
import android.util.Slog;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Collections;
import java.util.List;
/**
* Wraps IBiometricAuthenticator implementation and stores information about the authenticator,
@@ -73,7 +67,6 @@ public abstract class BiometricSensor {
public final int id;
public final @Authenticators.Types int oemStrength; // strength as configured by the OEM
public final int modality;
@NonNull public final List<ComponentInfoInternal> componentInfo;
public final IBiometricAuthenticator impl;
private @Authenticators.Types int mUpdatedStrength; // updated by BiometricStrengthController
@@ -93,16 +86,15 @@ public abstract class BiometricSensor {
*/
abstract boolean confirmationSupported();
BiometricSensor(@NonNull Context context, int modality, @NonNull SensorPropertiesInternal props,
IBiometricAuthenticator impl) {
BiometricSensor(@NonNull Context context, int id, int modality,
@Authenticators.Types int strength, IBiometricAuthenticator impl) {
this.mContext = context;
this.id = props.sensorId;
this.id = id;
this.modality = modality;
this.oemStrength = Utils.propertyStrengthToAuthenticatorStrength(props.sensorStrength);
this.componentInfo = Collections.unmodifiableList(props.componentInfo);
this.oemStrength = strength;
this.impl = impl;
mUpdatedStrength = oemStrength;
mUpdatedStrength = strength;
goToStateUnknown();
}
@@ -186,25 +178,8 @@ public abstract class BiometricSensor {
return "ID(" + id + ")"
+ ", oemStrength: " + oemStrength
+ ", updatedStrength: " + mUpdatedStrength
+ ", modality: " + modality
+ ", modality " + modality
+ ", state: " + mSensorState
+ ", cookie: " + mCookie;
}
protected void dump(@NonNull IndentingPrintWriter pw) {
pw.println(TextUtils.formatSimple("ID: %d", id));
pw.increaseIndent();
pw.println(TextUtils.formatSimple("oemStrength: %d", oemStrength));
pw.println(TextUtils.formatSimple("updatedStrength: %d", mUpdatedStrength));
pw.println(TextUtils.formatSimple("modality: %d", modality));
pw.println("componentInfo:");
for (ComponentInfoInternal info : componentInfo) {
pw.increaseIndent();
info.dump(pw);
pw.decreaseIndent();
}
pw.println(TextUtils.formatSimple("state: %d", mSensorState));
pw.println(TextUtils.formatSimple("cookie: %d", mCookie));
pw.decreaseIndent();
}
}

View File

@@ -64,7 +64,6 @@ import android.provider.Settings;
import android.security.KeyStore;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.IndentingPrintWriter;
import android.util.Pair;
import android.util.Slog;
import android.util.proto.ProtoOutputStream;
@@ -642,16 +641,13 @@ public class BiometricService extends SystemService {
@android.annotation.EnforcePermission(android.Manifest.permission.USE_BIOMETRIC_INTERNAL)
@Override
public synchronized void registerAuthenticator(int modality,
@NonNull SensorPropertiesInternal props,
public synchronized void registerAuthenticator(int id, int modality,
@Authenticators.Types int strength,
@NonNull IBiometricAuthenticator authenticator) {
super.registerAuthenticator_enforcePermission();
@Authenticators.Types final int strength =
Utils.propertyStrengthToAuthenticatorStrength(props.sensorStrength);
Slog.d(TAG, "Registering ID: " + props.sensorId
Slog.d(TAG, "Registering ID: " + id
+ " Modality: " + modality
+ " Strength: " + strength);
@@ -672,12 +668,12 @@ public class BiometricService extends SystemService {
}
for (BiometricSensor sensor : mSensors) {
if (sensor.id == props.sensorId) {
if (sensor.id == id) {
throw new IllegalStateException("Cannot register duplicate authenticator");
}
}
mSensors.add(new BiometricSensor(getContext(), modality, props, authenticator) {
mSensors.add(new BiometricSensor(getContext(), id, modality, strength, authenticator) {
@Override
boolean confirmationAlwaysRequired(int userId) {
return mSettingObserver.getConfirmationAlwaysRequired(modality, userId);
@@ -1376,17 +1372,13 @@ public class BiometricService extends SystemService {
return null;
}
private void dumpInternal(PrintWriter printWriter) {
IndentingPrintWriter pw = new IndentingPrintWriter(printWriter);
private void dumpInternal(PrintWriter pw) {
pw.println("Legacy Settings: " + mSettingObserver.mUseLegacyFaceOnlySettings);
pw.println();
pw.println("Sensors:");
for (BiometricSensor sensor : mSensors) {
pw.increaseIndent();
sensor.dump(pw);
pw.decreaseIndent();
pw.println(" " + sensor);
}
pw.println();
pw.println("CurrentSession: " + mAuthSession);

View File

@@ -20,6 +20,7 @@ import static android.hardware.biometrics.BiometricAuthenticator.TYPE_FACE;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.hardware.biometrics.BiometricManager;
import android.hardware.biometrics.IBiometricService;
import android.hardware.face.FaceSensorPropertiesInternal;
import android.hardware.face.IFaceAuthenticatorsRegisteredCallback;
@@ -27,6 +28,7 @@ import android.hardware.face.IFaceService;
import android.os.RemoteException;
import android.util.Slog;
import com.android.server.biometrics.Utils;
import com.android.server.biometrics.sensors.BiometricServiceRegistry;
import java.util.List;
@@ -51,8 +53,10 @@ public class FaceServiceRegistry extends BiometricServiceRegistry<ServiceProvide
@Override
protected void registerService(@NonNull IBiometricService service,
@NonNull FaceSensorPropertiesInternal props) {
@BiometricManager.Authenticators.Types final int strength =
Utils.propertyStrengthToAuthenticatorStrength(props.sensorStrength);
try {
service.registerAuthenticator(TYPE_FACE, props,
service.registerAuthenticator(props.sensorId, TYPE_FACE, strength,
new FaceAuthenticator(mService, props.sensorId));
} catch (RemoteException e) {
Slog.e(TAG, "Remote exception when registering sensorId: " + props.sensorId);

View File

@@ -20,6 +20,7 @@ import static android.hardware.biometrics.BiometricAuthenticator.TYPE_FINGERPRIN
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.hardware.biometrics.BiometricManager;
import android.hardware.biometrics.IBiometricService;
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
import android.hardware.fingerprint.IFingerprintAuthenticatorsRegisteredCallback;
@@ -27,6 +28,7 @@ import android.hardware.fingerprint.IFingerprintService;
import android.os.RemoteException;
import android.util.Slog;
import com.android.server.biometrics.Utils;
import com.android.server.biometrics.sensors.BiometricServiceRegistry;
import java.util.List;
@@ -51,8 +53,10 @@ public class FingerprintServiceRegistry extends BiometricServiceRegistry<Service
@Override
protected void registerService(@NonNull IBiometricService service,
@NonNull FingerprintSensorPropertiesInternal props) {
@BiometricManager.Authenticators.Types final int strength =
Utils.propertyStrengthToAuthenticatorStrength(props.sensorStrength);
try {
service.registerAuthenticator(TYPE_FINGERPRINT, props,
service.registerAuthenticator(props.sensorId, TYPE_FINGERPRINT, strength,
new FingerprintAuthenticator(mService, props.sensorId));
} catch (RemoteException e) {
Slog.e(TAG, "Remote exception when registering sensorId: " + props.sensorId);

View File

@@ -16,10 +16,12 @@
package com.android.server.biometrics.sensors.iris;
import static android.Manifest.permission.USE_BIOMETRIC_INTERNAL;
import static android.hardware.biometrics.BiometricAuthenticator.TYPE_IRIS;
import android.annotation.NonNull;
import android.content.Context;
import android.hardware.biometrics.BiometricManager;
import android.hardware.biometrics.IBiometricService;
import android.hardware.biometrics.SensorPropertiesInternal;
import android.hardware.iris.IIrisService;
@@ -31,6 +33,7 @@ import android.util.Slog;
import com.android.server.ServiceThread;
import com.android.server.SystemService;
import com.android.server.biometrics.Utils;
import java.util.List;
@@ -72,12 +75,17 @@ public class IrisService extends SystemService {
ServiceManager.getService(Context.BIOMETRIC_SERVICE));
for (SensorPropertiesInternal hidlSensor : hidlSensors) {
final int sensorId = hidlSensor.sensorId;
final @BiometricManager.Authenticators.Types int strength =
Utils.propertyStrengthToAuthenticatorStrength(
hidlSensor.sensorStrength);
final IrisAuthenticator authenticator = new IrisAuthenticator(mServiceWrapper,
sensorId);
try {
biometricService.registerAuthenticator(TYPE_IRIS, hidlSensor,
new IrisAuthenticator(mServiceWrapper, hidlSensor.sensorId));
biometricService.registerAuthenticator(sensorId, TYPE_IRIS, strength,
authenticator);
} catch (RemoteException e) {
Slog.e(TAG, "Remote exception when registering sensorId: "
+ hidlSensor.sensorId);
Slog.e(TAG, "Remote exception when registering sensorId: " + sensorId);
}
}
});

View File

@@ -158,7 +158,8 @@ public class AuthServiceTest {
verify(mBiometricService, never()).registerAuthenticator(
anyInt(),
any(),
anyInt(),
anyInt(),
any());
}

View File

@@ -45,14 +45,13 @@ import android.app.trust.ITrustManager;
import android.content.Context;
import android.content.res.Resources;
import android.hardware.biometrics.BiometricManager.Authenticators;
import android.hardware.biometrics.ComponentInfoInternal;
import android.hardware.biometrics.IBiometricAuthenticator;
import android.hardware.biometrics.IBiometricSensorReceiver;
import android.hardware.biometrics.IBiometricServiceReceiver;
import android.hardware.biometrics.IBiometricSysuiReceiver;
import android.hardware.biometrics.PromptInfo;
import android.hardware.biometrics.SensorProperties;
import android.hardware.face.FaceSensorProperties;
import android.hardware.face.FaceSensorPropertiesInternal;
import android.hardware.fingerprint.FingerprintManager;
import android.hardware.fingerprint.FingerprintSensorProperties;
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
@@ -490,16 +489,9 @@ public class AuthSessionTest {
IBiometricAuthenticator fingerprintAuthenticator = mock(IBiometricAuthenticator.class);
when(fingerprintAuthenticator.isHardwareDetected(any())).thenReturn(true);
when(fingerprintAuthenticator.hasEnrolledTemplates(anyInt(), any())).thenReturn(true);
final FingerprintSensorPropertiesInternal props = new FingerprintSensorPropertiesInternal(
id, SensorProperties.STRENGTH_STRONG, 5 /* maxEnrollmentsPerUser */,
List.of() /* componentInfo */, type,
false /* resetLockoutRequiresHardwareAuthToken */);
mFingerprintSensorProps.add(props);
mSensors.add(new BiometricSensor(mContext,
mSensors.add(new BiometricSensor(mContext, id,
TYPE_FINGERPRINT /* modality */,
props,
Authenticators.BIOMETRIC_STRONG /* strength */,
fingerprintAuthenticator) {
@Override
boolean confirmationAlwaysRequired(int userId) {
@@ -512,6 +504,21 @@ public class AuthSessionTest {
}
});
final List<ComponentInfoInternal> componentInfo = new ArrayList<>();
componentInfo.add(new ComponentInfoInternal("faceSensor" /* componentId */,
"vendor/model/revision" /* hardwareVersion */, "1.01" /* firmwareVersion */,
"00000001" /* serialNumber */, "" /* softwareVersion */));
componentInfo.add(new ComponentInfoInternal("matchingAlgorithm" /* componentId */,
"" /* hardwareVersion */, "" /* firmwareVersion */, "" /* serialNumber */,
"vendor/version/revision" /* softwareVersion */));
mFingerprintSensorProps.add(new FingerprintSensorPropertiesInternal(id,
SensorProperties.STRENGTH_STRONG,
5 /* maxEnrollmentsPerUser */,
componentInfo,
type,
false /* resetLockoutRequiresHardwareAuthToken */));
when(mSettingObserver.getEnabledForApps(anyInt())).thenReturn(true);
}
@@ -519,13 +526,9 @@ public class AuthSessionTest {
IBiometricAuthenticator authenticator) throws RemoteException {
when(authenticator.isHardwareDetected(any())).thenReturn(true);
when(authenticator.hasEnrolledTemplates(anyInt(), any())).thenReturn(true);
mSensors.add(new BiometricSensor(mContext,
mSensors.add(new BiometricSensor(mContext, id,
TYPE_FACE /* modality */,
new FaceSensorPropertiesInternal(id,
SensorProperties.STRENGTH_STRONG, 5 /* maxEnrollmentsPerUser */,
List.of() /* componentInfo */, FaceSensorProperties.TYPE_UNKNOWN,
true /* supportsFace Detection */, true /* supportsSelfIllumination */,
false /* resetLockoutRequiresHardwareAuthToken */),
Authenticators.BIOMETRIC_STRONG /* strength */,
authenticator) {
@Override
boolean confirmationAlwaysRequired(int userId) {

View File

@@ -19,7 +19,6 @@ package com.android.server.biometrics;
import static android.hardware.biometrics.BiometricAuthenticator.TYPE_FINGERPRINT;
import static android.hardware.biometrics.BiometricManager.Authenticators;
import static android.hardware.biometrics.BiometricManager.BIOMETRIC_MULTI_SENSOR_DEFAULT;
import static android.hardware.biometrics.SensorProperties.STRENGTH_STRONG;
import static android.view.DisplayAdjustments.DEFAULT_DISPLAY_ADJUSTMENTS;
import static com.android.server.biometrics.BiometricServiceStateProto.STATE_AUTHENTICATED_PENDING_SYSUI;
@@ -70,11 +69,7 @@ import android.hardware.biometrics.IBiometricServiceReceiver;
import android.hardware.biometrics.IBiometricSysuiReceiver;
import android.hardware.biometrics.PromptInfo;
import android.hardware.display.DisplayManagerGlobal;
import android.hardware.face.FaceSensorProperties;
import android.hardware.face.FaceSensorPropertiesInternal;
import android.hardware.fingerprint.FingerprintManager;
import android.hardware.fingerprint.FingerprintSensorProperties;
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
import android.os.Binder;
import android.os.IBinder;
import android.os.RemoteException;
@@ -124,7 +119,6 @@ public class BiometricServiceTest {
private static final int SENSOR_ID_FINGERPRINT = 0;
private static final int SENSOR_ID_FACE = 1;
private FingerprintSensorPropertiesInternal mFingerprintProps;
private BiometricService mBiometricService;
@@ -207,11 +201,6 @@ public class BiometricServiceTest {
};
when(mInjector.getConfiguration(any())).thenReturn(config);
mFingerprintProps = new FingerprintSensorPropertiesInternal(SENSOR_ID_FINGERPRINT,
STRENGTH_STRONG, 5 /* maxEnrollmentsPerUser */, List.of() /* componentInfo */,
FingerprintSensorProperties.TYPE_UNKNOWN,
false /* resetLockoutRequiresHardwareAuthToken */);
}
@Test
@@ -347,7 +336,8 @@ public class BiometricServiceTest {
mBiometricService = new BiometricService(mContext, mInjector);
mBiometricService.onStart();
mBiometricService.mImpl.registerAuthenticator(TYPE_FINGERPRINT, mFingerprintProps,
mBiometricService.mImpl.registerAuthenticator(0 /* id */,
TYPE_FINGERPRINT, Authenticators.BIOMETRIC_STRONG,
mFingerprintAuthenticator);
invokeAuthenticate(mBiometricService.mImpl, mReceiver1, false /* requireConfirmation */,
@@ -419,7 +409,8 @@ public class BiometricServiceTest {
mBiometricService = new BiometricService(mContext, mInjector);
mBiometricService.onStart();
mBiometricService.mImpl.registerAuthenticator(TYPE_FINGERPRINT, mFingerprintProps,
mBiometricService.mImpl.registerAuthenticator(0 /* id */,
TYPE_FINGERPRINT, Authenticators.BIOMETRIC_STRONG,
mFingerprintAuthenticator);
invokeAuthenticate(mBiometricService.mImpl, mReceiver1, false /* requireConfirmation */,
@@ -1351,13 +1342,9 @@ public class BiometricServiceTest {
for (int i = 0; i < testCases.length; i++) {
final BiometricSensor sensor =
new BiometricSensor(mContext,
new BiometricSensor(mContext, 0 /* id */,
TYPE_FINGERPRINT,
new FingerprintSensorPropertiesInternal(i /* id */,
Utils.authenticatorStrengthToPropertyStrength(testCases[i][0]),
5 /* maxEnrollmentsPerUser */, List.of() /* componentInfo */,
FingerprintSensorProperties.TYPE_UNKNOWN,
false /* resetLockoutRequiresHardwareAuthToken */),
testCases[i][0],
mock(IBiometricAuthenticator.class)) {
@Override
boolean confirmationAlwaysRequired(int userId) {
@@ -1385,7 +1372,8 @@ public class BiometricServiceTest {
when(mFingerprintAuthenticator.hasEnrolledTemplates(anyInt(), any()))
.thenReturn(true);
when(mFingerprintAuthenticator.isHardwareDetected(any())).thenReturn(true);
mBiometricService.mImpl.registerAuthenticator(TYPE_FINGERPRINT, mFingerprintProps,
mBiometricService.mImpl.registerAuthenticator(0 /* testId */,
TYPE_FINGERPRINT, Authenticators.BIOMETRIC_STRONG,
mFingerprintAuthenticator);
verify(mBiometricService.mBiometricStrengthController).updateStrengths();
@@ -1396,14 +1384,15 @@ public class BiometricServiceTest {
mBiometricService = new BiometricService(mContext, mInjector);
mBiometricService.onStart();
final int testId = 0;
when(mBiometricService.mSettingObserver.getEnabledForApps(anyInt())).thenReturn(true);
when(mFingerprintAuthenticator.hasEnrolledTemplates(anyInt(), any()))
.thenReturn(true);
when(mFingerprintAuthenticator.isHardwareDetected(any())).thenReturn(true);
final int testId = SENSOR_ID_FINGERPRINT;
mBiometricService.mImpl.registerAuthenticator(TYPE_FINGERPRINT, mFingerprintProps,
mBiometricService.mImpl.registerAuthenticator(testId /* id */,
TYPE_FINGERPRINT, Authenticators.BIOMETRIC_STRONG,
mFingerprintAuthenticator);
// Downgrade the authenticator
@@ -1503,9 +1492,11 @@ public class BiometricServiceTest {
mBiometricService.onStart();
mBiometricService.mImpl.registerAuthenticator(
2 /* modality */, mFingerprintProps, mFingerprintAuthenticator);
0 /* id */, 2 /* modality */, 15 /* strength */,
mFingerprintAuthenticator);
mBiometricService.mImpl.registerAuthenticator(
2 /* modality */, mFingerprintProps, mFingerprintAuthenticator);
0 /* id */, 2 /* modality */, 15 /* strength */,
mFingerprintAuthenticator);
}
@Test(expected = IllegalArgumentException.class)
@@ -1515,7 +1506,9 @@ public class BiometricServiceTest {
mBiometricService.onStart();
mBiometricService.mImpl.registerAuthenticator(
2 /* modality */, mFingerprintProps, null /* authenticator */);
0 /* id */, 2 /* modality */,
Authenticators.BIOMETRIC_STRONG /* strength */,
null /* authenticator */);
}
@Test
@@ -1526,13 +1519,8 @@ public class BiometricServiceTest {
for (String s : mInjector.getConfiguration(null)) {
SensorConfig config = new SensorConfig(s);
mBiometricService.mImpl.registerAuthenticator(config.modality,
new FingerprintSensorPropertiesInternal(config.id,
Utils.authenticatorStrengthToPropertyStrength(config.strength),
5 /* maxEnrollmentsPerUser */, List.of() /* componentInfo */,
FingerprintSensorProperties.TYPE_UNKNOWN,
false /* resetLockoutRequiresHardwareAuthToken */),
mFingerprintAuthenticator);
mBiometricService.mImpl.registerAuthenticator(config.id, config.modality,
config.strength, mFingerprintAuthenticator);
}
}
@@ -1656,12 +1644,7 @@ public class BiometricServiceTest {
when(mFingerprintAuthenticator.isHardwareDetected(any())).thenReturn(true);
when(mFingerprintAuthenticator.getLockoutModeForUser(anyInt()))
.thenReturn(LockoutTracker.LOCKOUT_NONE);
mBiometricService.mImpl.registerAuthenticator(modality,
new FingerprintSensorPropertiesInternal(SENSOR_ID_FINGERPRINT,
Utils.authenticatorStrengthToPropertyStrength(strength),
5 /* maxEnrollmentsPerUser */, List.of() /* componentInfo */,
FingerprintSensorProperties.TYPE_UNKNOWN,
false /* resetLockoutRequiresHardwareAuthToken */),
mBiometricService.mImpl.registerAuthenticator(SENSOR_ID_FINGERPRINT, modality, strength,
mFingerprintAuthenticator);
}
@@ -1670,13 +1653,7 @@ public class BiometricServiceTest {
when(mFaceAuthenticator.isHardwareDetected(any())).thenReturn(true);
when(mFaceAuthenticator.getLockoutModeForUser(anyInt()))
.thenReturn(LockoutTracker.LOCKOUT_NONE);
mBiometricService.mImpl.registerAuthenticator(modality,
new FaceSensorPropertiesInternal(SENSOR_ID_FACE,
Utils.authenticatorStrengthToPropertyStrength(strength),
5 /* maxEnrollmentsPerUser */, List.of() /* componentInfo */,
FaceSensorProperties.TYPE_UNKNOWN, true /* supportsFace Detection */,
true /* supportsSelfIllumination */,
false /* resetLockoutRequiresHardwareAuthToken */),
mBiometricService.mImpl.registerAuthenticator(SENSOR_ID_FACE, modality, strength,
mFaceAuthenticator);
}
}
@@ -1699,27 +1676,15 @@ public class BiometricServiceTest {
when(mFingerprintAuthenticator.hasEnrolledTemplates(anyInt(), any()))
.thenReturn(true);
when(mFingerprintAuthenticator.isHardwareDetected(any())).thenReturn(true);
mBiometricService.mImpl.registerAuthenticator(modality,
new FingerprintSensorPropertiesInternal(SENSOR_ID_FINGERPRINT,
Utils.authenticatorStrengthToPropertyStrength(strength),
5 /* maxEnrollmentsPerUser */, List.of() /* componentInfo */,
FingerprintSensorProperties.TYPE_UNKNOWN,
false /* resetLockoutRequiresHardwareAuthToken */),
mFingerprintAuthenticator);
mBiometricService.mImpl.registerAuthenticator(SENSOR_ID_FINGERPRINT, modality,
strength, mFingerprintAuthenticator);
}
if ((modality & BiometricAuthenticator.TYPE_FACE) != 0) {
when(mFaceAuthenticator.hasEnrolledTemplates(anyInt(), any())).thenReturn(true);
when(mFaceAuthenticator.isHardwareDetected(any())).thenReturn(true);
mBiometricService.mImpl.registerAuthenticator(modality,
new FaceSensorPropertiesInternal(SENSOR_ID_FACE,
Utils.authenticatorStrengthToPropertyStrength(strength),
5 /* maxEnrollmentsPerUser */, List.of() /* componentInfo */,
FaceSensorProperties.TYPE_UNKNOWN,
true /* supportsFace Detection */,
true /* supportsSelfIllumination */,
false /* resetLockoutRequiresHardwareAuthToken */),
mFaceAuthenticator);
mBiometricService.mImpl.registerAuthenticator(SENSOR_ID_FACE, modality,
strength, mFaceAuthenticator);
}
}
}

View File

@@ -16,9 +16,6 @@
package com.android.server.biometrics;
import static android.hardware.biometrics.SensorProperties.STRENGTH_STRONG;
import static android.hardware.biometrics.SensorProperties.STRENGTH_WEAK;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
@@ -30,13 +27,9 @@ 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;
import android.hardware.biometrics.IBiometricAuthenticator;
import android.hardware.biometrics.IInvalidationCallback;
import android.hardware.biometrics.SensorPropertiesInternal;
import android.hardware.face.FaceSensorProperties;
import android.hardware.face.FaceSensorPropertiesInternal;
import android.hardware.fingerprint.FingerprintSensorProperties;
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
import android.platform.test.annotations.Presubmit;
import androidx.test.filters.SmallTest;
@@ -49,7 +42,6 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.ArrayList;
import java.util.List;
@Presubmit
@SmallTest
@@ -67,54 +59,26 @@ public class InvalidationTrackerTest {
public void testCallbackReceived_whenAllStrongSensorsInvalidated() throws Exception {
final IBiometricAuthenticator authenticator1 = mock(IBiometricAuthenticator.class);
when(authenticator1.hasEnrolledTemplates(anyInt(), any())).thenReturn(true);
final TestSensor sensor1 = new TestSensor(mContext,
BiometricAuthenticator.TYPE_FINGERPRINT,
new FingerprintSensorPropertiesInternal(0 /* id */,
STRENGTH_STRONG,
5 /* maxEnrollmentsPerUser */,
List.of() /* componentInfo */,
FingerprintSensorProperties.TYPE_UDFPS_OPTICAL,
false /* resetLockoutRequiresHardwareAuthToken */),
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(mContext,
BiometricAuthenticator.TYPE_FINGERPRINT,
new FingerprintSensorPropertiesInternal(1 /* id */,
STRENGTH_STRONG,
5 /* maxEnrollmentsPerUser */,
List.of() /* componentInfo */,
FingerprintSensorProperties.TYPE_REAR,
false /* resetLockoutRequiresHardwareAuthToken */),
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(mContext,
BiometricAuthenticator.TYPE_FACE,
new FaceSensorPropertiesInternal(2 /* id */,
STRENGTH_STRONG,
5 /* maxEnrollmentsPerUser */,
List.of() /* componentInfo */,
FaceSensorProperties.TYPE_RGB,
true /* supportsFace Detection */,
true /* supportsSelfIllumination */,
false /* resetLockoutRequiresHardwareAuthToken */),
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(mContext,
BiometricAuthenticator.TYPE_FACE,
new FaceSensorPropertiesInternal(3 /* id */,
STRENGTH_WEAK,
5 /* maxEnrollmentsPerUser */,
List.of() /* componentInfo */,
FaceSensorProperties.TYPE_IR,
true /* supportsFace Detection */,
true /* supportsSelfIllumination */,
false /* resetLockoutRequiresHardwareAuthToken */),
final TestSensor sensor4 = new TestSensor(mContext, 3 /* id */,
BiometricAuthenticator.TYPE_FACE, Authenticators.BIOMETRIC_WEAK,
authenticator4);
final ArrayList<BiometricSensor> sensors = new ArrayList<>();
@@ -149,9 +113,9 @@ public class InvalidationTrackerTest {
private static class TestSensor extends BiometricSensor {
TestSensor(@NonNull Context context, int modality, @NonNull SensorPropertiesInternal props,
TestSensor(@NonNull Context context, int id, int modality, int strength,
@NonNull IBiometricAuthenticator impl) {
super(context, modality, props, impl);
super(context, id, modality, strength, impl);
}
@Override

View File

@@ -17,6 +17,8 @@
package com.android.server.biometrics.sensors.face;
import static android.hardware.biometrics.BiometricAuthenticator.TYPE_FACE;
import static android.hardware.biometrics.BiometricManager.Authenticators.BIOMETRIC_STRONG;
import static android.hardware.biometrics.BiometricManager.Authenticators.BIOMETRIC_WEAK;
import static android.hardware.biometrics.SensorProperties.STRENGTH_STRONG;
import static android.hardware.biometrics.SensorProperties.STRENGTH_WEAK;
@@ -68,7 +70,9 @@ public class FaceServiceRegistryTest {
@Mock
private ServiceProvider mProvider2;
@Captor
private ArgumentCaptor<FaceSensorPropertiesInternal> mPropsCaptor;
private ArgumentCaptor<Integer> mIdCaptor;
@Captor
private ArgumentCaptor<Integer> mStrengthCaptor;
private FaceSensorPropertiesInternal mProvider1Props;
private FaceSensorPropertiesInternal mProvider2Props;
@@ -78,13 +82,13 @@ public class FaceServiceRegistryTest {
public void setup() {
mProvider1Props = new FaceSensorPropertiesInternal(SENSOR_ID_1,
STRENGTH_WEAK, 5 /* maxEnrollmentsPerUser */,
List.of() /* componentInfo */, FaceSensorProperties.TYPE_RGB,
List.of(), FaceSensorProperties.TYPE_RGB,
true /* supportsFace Detection */,
true /* supportsSelfIllumination */,
false /* resetLockoutRequiresHardwareAuthToken */);
mProvider2Props = new FaceSensorPropertiesInternal(SENSOR_ID_2,
STRENGTH_STRONG, 5 /* maxEnrollmentsPerUser */,
List.of() /* componentInfo */, FaceSensorProperties.TYPE_IR,
List.of(), FaceSensorProperties.TYPE_IR,
true /* supportsFace Detection */,
true /* supportsSelfIllumination */,
false /* resetLockoutRequiresHardwareAuthToken */);
@@ -103,9 +107,10 @@ public class FaceServiceRegistryTest {
assertThat(mRegistry.getProviders()).containsExactly(mProvider1, mProvider2);
assertThat(mRegistry.getAllProperties()).containsExactly(mProvider1Props, mProvider2Props);
verify(mBiometricService, times(2)).registerAuthenticator(
eq(TYPE_FACE), mPropsCaptor.capture(), any());
assertThat(mPropsCaptor.getAllValues())
.containsExactly(mProvider1Props, mProvider2Props);
mIdCaptor.capture(), eq(TYPE_FACE), mStrengthCaptor.capture(), any());
assertThat(mIdCaptor.getAllValues()).containsExactly(SENSOR_ID_1, SENSOR_ID_2);
assertThat(mStrengthCaptor.getAllValues())
.containsExactly(BIOMETRIC_WEAK, BIOMETRIC_STRONG);
}
@Test

View File

@@ -17,6 +17,8 @@
package com.android.server.biometrics.sensors.fingerprint;
import static android.hardware.biometrics.BiometricAuthenticator.TYPE_FINGERPRINT;
import static android.hardware.biometrics.BiometricManager.Authenticators.BIOMETRIC_STRONG;
import static android.hardware.biometrics.BiometricManager.Authenticators.BIOMETRIC_WEAK;
import static android.hardware.biometrics.SensorProperties.STRENGTH_STRONG;
import static android.hardware.biometrics.SensorProperties.STRENGTH_WEAK;
@@ -68,7 +70,9 @@ public class FingerprintServiceRegistryTest {
@Mock
private ServiceProvider mProvider2;
@Captor
private ArgumentCaptor<FingerprintSensorPropertiesInternal> mPropsCaptor;
private ArgumentCaptor<Integer> mIdCaptor;
@Captor
private ArgumentCaptor<Integer> mStrengthCaptor;
private FingerprintSensorPropertiesInternal mProvider1Props;
private FingerprintSensorPropertiesInternal mProvider2Props;
@@ -78,11 +82,11 @@ public class FingerprintServiceRegistryTest {
public void setup() {
mProvider1Props = new FingerprintSensorPropertiesInternal(SENSOR_ID_1,
STRENGTH_WEAK, 5 /* maxEnrollmentsPerUser */,
List.of() /* componentInfo */, FingerprintSensorProperties.TYPE_UDFPS_OPTICAL,
List.of(), FingerprintSensorProperties.TYPE_UDFPS_OPTICAL,
false /* resetLockoutRequiresHardwareAuthToken */);
mProvider2Props = new FingerprintSensorPropertiesInternal(SENSOR_ID_2,
STRENGTH_STRONG, 5 /* maxEnrollmentsPerUser */,
List.of() /* componentInfo */, FingerprintSensorProperties.TYPE_UNKNOWN,
List.of(), FingerprintSensorProperties.TYPE_UNKNOWN,
false /* resetLockoutRequiresHardwareAuthToken */);
when(mProvider1.getSensorProperties()).thenReturn(List.of(mProvider1Props));
@@ -99,9 +103,10 @@ public class FingerprintServiceRegistryTest {
assertThat(mRegistry.getProviders()).containsExactly(mProvider1, mProvider2);
assertThat(mRegistry.getAllProperties()).containsExactly(mProvider1Props, mProvider2Props);
verify(mBiometricService, times(2)).registerAuthenticator(
eq(TYPE_FINGERPRINT), mPropsCaptor.capture(), any());
assertThat(mPropsCaptor.getAllValues())
.containsExactly(mProvider1Props, mProvider2Props);
mIdCaptor.capture(), eq(TYPE_FINGERPRINT), mStrengthCaptor.capture(), any());
assertThat(mIdCaptor.getAllValues()).containsExactly(SENSOR_ID_1, SENSOR_ID_2);
assertThat(mStrengthCaptor.getAllValues())
.containsExactly(BIOMETRIC_WEAK, BIOMETRIC_STRONG);
}
@Test

View File

@@ -117,17 +117,15 @@ public class FingerprintServiceTest {
private final FingerprintSensorPropertiesInternal mSensorPropsDefault =
new FingerprintSensorPropertiesInternal(ID_DEFAULT, STRENGTH_STRONG,
2 /* maxEnrollmentsPerUser */,
List.of() /* componentInfo */,
List.of(),
TYPE_REAR,
false /* resetLockoutRequiresHardwareAuthToken */);
private final FingerprintSensorPropertiesInternal mSensorPropsVirtual =
new FingerprintSensorPropertiesInternal(ID_VIRTUAL, STRENGTH_STRONG,
2 /* maxEnrollmentsPerUser */,
List.of() /* componentInfo */,
List.of(),
TYPE_UDFPS_OPTICAL,
false /* resetLockoutRequiresHardwareAuthToken */);
@Captor
private ArgumentCaptor<FingerprintSensorPropertiesInternal> mPropsCaptor;
private FingerprintService mService;
@Before
@@ -178,8 +176,7 @@ public class FingerprintServiceTest {
mService.mServiceWrapper.registerAuthenticators(HIDL_AUTHENTICATORS);
waitForRegistration();
verify(mIBiometricService).registerAuthenticator(anyInt(), mPropsCaptor.capture(), any());
assertThat(mPropsCaptor.getAllValues()).containsExactly(mSensorPropsDefault);
verify(mIBiometricService).registerAuthenticator(eq(ID_DEFAULT), anyInt(), anyInt(), any());
}
@Test
@@ -191,8 +188,7 @@ public class FingerprintServiceTest {
mService.mServiceWrapper.registerAuthenticators(HIDL_AUTHENTICATORS);
waitForRegistration();
verify(mIBiometricService).registerAuthenticator(anyInt(), mPropsCaptor.capture(), any());
assertThat(mPropsCaptor.getAllValues()).containsExactly(mSensorPropsVirtual);
verify(mIBiometricService).registerAuthenticator(eq(ID_VIRTUAL), anyInt(), anyInt(), any());
}
@Test
@@ -202,8 +198,7 @@ public class FingerprintServiceTest {
mService.mServiceWrapper.registerAuthenticators(HIDL_AUTHENTICATORS);
waitForRegistration();
verify(mIBiometricService).registerAuthenticator(anyInt(), mPropsCaptor.capture(), any());
assertThat(mPropsCaptor.getAllValues()).containsExactly(mSensorPropsVirtual);
verify(mIBiometricService).registerAuthenticator(eq(ID_VIRTUAL), anyInt(), anyInt(), any());
}
private void waitForRegistration() throws Exception {