diff options
14 files changed, 220 insertions, 131 deletions
diff --git a/core/java/android/hardware/biometrics/ComponentInfoInternal.java b/core/java/android/hardware/biometrics/ComponentInfoInternal.java index 3b61a56bd9f1..2e708de21762 100644 --- a/core/java/android/hardware/biometrics/ComponentInfoInternal.java +++ b/core/java/android/hardware/biometrics/ComponentInfoInternal.java @@ -19,6 +19,8 @@ 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, @@ -90,12 +92,19 @@ public class ComponentInfoInternal implements Parcelable { dest.writeString(softwareVersion); } - @Override - public String toString() { - return "ComponentId: " + componentId - + ", HardwareVersion: " + hardwareVersion - + ", FirmwareVersion: " + firmwareVersion - + ", SerialNumber " + serialNumber - + ", SoftwareVersion: " + 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(); } } diff --git a/core/java/android/hardware/biometrics/IBiometricService.aidl b/core/java/android/hardware/biometrics/IBiometricService.aidl index c88af5aad738..1a38c8897b76 100644 --- a/core/java/android/hardware/biometrics/IBiometricService.aidl +++ b/core/java/android/hardware/biometrics/IBiometricService.aidl @@ -58,10 +58,10 @@ interface IBiometricService { boolean hasEnrolledBiometrics(int userId, String opPackageName); // Registers an authenticator (e.g. face, fingerprint, iris). - // Id must be unique, whereas strength and modality don't need to be. + // Sensor Id in sensor props must be unique, whereas modality doesn't need to be. // TODO(b/123321528): Turn strength and modality into enums. @EnforcePermission("USE_BIOMETRIC_INTERNAL") - void registerAuthenticator(int id, int modality, int strength, + void registerAuthenticator(int modality, in SensorPropertiesInternal props, IBiometricAuthenticator authenticator); // Register callback for when keyguard biometric eligibility changes. diff --git a/services/core/java/com/android/server/biometrics/BiometricSensor.java b/services/core/java/com/android/server/biometrics/BiometricSensor.java index 937e3f8f8668..bac44809883f 100644 --- a/services/core/java/com/android/server/biometrics/BiometricSensor.java +++ b/services/core/java/com/android/server/biometrics/BiometricSensor.java @@ -22,14 +22,20 @@ 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, @@ -67,6 +73,7 @@ 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 @@ -86,15 +93,16 @@ public abstract class BiometricSensor { */ abstract boolean confirmationSupported(); - BiometricSensor(@NonNull Context context, int id, int modality, - @Authenticators.Types int strength, IBiometricAuthenticator impl) { + BiometricSensor(@NonNull Context context, int modality, @NonNull SensorPropertiesInternal props, + IBiometricAuthenticator impl) { this.mContext = context; - this.id = id; + this.id = props.sensorId; this.modality = modality; - this.oemStrength = strength; + this.oemStrength = Utils.propertyStrengthToAuthenticatorStrength(props.sensorStrength); + this.componentInfo = Collections.unmodifiableList(props.componentInfo); this.impl = impl; - mUpdatedStrength = strength; + mUpdatedStrength = oemStrength; goToStateUnknown(); } @@ -178,8 +186,25 @@ 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(); + } } diff --git a/services/core/java/com/android/server/biometrics/BiometricService.java b/services/core/java/com/android/server/biometrics/BiometricService.java index ffa5d2055e92..f44d14bfa12c 100644 --- a/services/core/java/com/android/server/biometrics/BiometricService.java +++ b/services/core/java/com/android/server/biometrics/BiometricService.java @@ -62,6 +62,7 @@ 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; @@ -638,13 +639,16 @@ public class BiometricService extends SystemService { @android.annotation.EnforcePermission(android.Manifest.permission.USE_BIOMETRIC_INTERNAL) @Override - public synchronized void registerAuthenticator(int id, int modality, - @Authenticators.Types int strength, + public synchronized void registerAuthenticator(int modality, + @NonNull SensorPropertiesInternal props, @NonNull IBiometricAuthenticator authenticator) { super.registerAuthenticator_enforcePermission(); - Slog.d(TAG, "Registering ID: " + id + @Authenticators.Types final int strength = + Utils.propertyStrengthToAuthenticatorStrength(props.sensorStrength); + + Slog.d(TAG, "Registering ID: " + props.sensorId + " Modality: " + modality + " Strength: " + strength); @@ -665,12 +669,12 @@ public class BiometricService extends SystemService { } for (BiometricSensor sensor : mSensors) { - if (sensor.id == id) { + if (sensor.id == props.sensorId) { throw new IllegalStateException("Cannot register duplicate authenticator"); } } - mSensors.add(new BiometricSensor(getContext(), id, modality, strength, authenticator) { + mSensors.add(new BiometricSensor(getContext(), modality, props, authenticator) { @Override boolean confirmationAlwaysRequired(int userId) { return mSettingObserver.getConfirmationAlwaysRequired(modality, userId); @@ -1360,13 +1364,17 @@ public class BiometricService extends SystemService { return null; } - private void dumpInternal(PrintWriter pw) { + private void dumpInternal(PrintWriter printWriter) { + IndentingPrintWriter pw = new IndentingPrintWriter(printWriter); + pw.println("Legacy Settings: " + mSettingObserver.mUseLegacyFaceOnlySettings); pw.println(); pw.println("Sensors:"); for (BiometricSensor sensor : mSensors) { - pw.println(" " + sensor); + pw.increaseIndent(); + sensor.dump(pw); + pw.decreaseIndent(); } pw.println(); pw.println("CurrentSession: " + mAuthSession); diff --git a/services/core/java/com/android/server/biometrics/sensors/face/FaceServiceRegistry.java b/services/core/java/com/android/server/biometrics/sensors/face/FaceServiceRegistry.java index 0f0a81d24473..d43045b4450f 100644 --- a/services/core/java/com/android/server/biometrics/sensors/face/FaceServiceRegistry.java +++ b/services/core/java/com/android/server/biometrics/sensors/face/FaceServiceRegistry.java @@ -20,7 +20,6 @@ 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; @@ -28,7 +27,6 @@ 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; @@ -53,10 +51,8 @@ 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(props.sensorId, TYPE_FACE, strength, + service.registerAuthenticator(TYPE_FACE, props, new FaceAuthenticator(mService, props.sensorId)); } catch (RemoteException e) { Slog.e(TAG, "Remote exception when registering sensorId: " + props.sensorId); diff --git a/services/core/java/com/android/server/biometrics/sensors/fingerprint/FingerprintServiceRegistry.java b/services/core/java/com/android/server/biometrics/sensors/fingerprint/FingerprintServiceRegistry.java index 33810b764f23..6d210eac542b 100644 --- a/services/core/java/com/android/server/biometrics/sensors/fingerprint/FingerprintServiceRegistry.java +++ b/services/core/java/com/android/server/biometrics/sensors/fingerprint/FingerprintServiceRegistry.java @@ -20,7 +20,6 @@ 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; @@ -28,7 +27,6 @@ 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; @@ -53,10 +51,8 @@ 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(props.sensorId, TYPE_FINGERPRINT, strength, + service.registerAuthenticator(TYPE_FINGERPRINT, props, new FingerprintAuthenticator(mService, props.sensorId)); } catch (RemoteException e) { Slog.e(TAG, "Remote exception when registering sensorId: " + props.sensorId); diff --git a/services/core/java/com/android/server/biometrics/sensors/iris/IrisService.java b/services/core/java/com/android/server/biometrics/sensors/iris/IrisService.java index 35ea36c5d56f..f27761fd644c 100644 --- a/services/core/java/com/android/server/biometrics/sensors/iris/IrisService.java +++ b/services/core/java/com/android/server/biometrics/sensors/iris/IrisService.java @@ -16,12 +16,10 @@ 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; @@ -33,7 +31,6 @@ import android.util.Slog; import com.android.server.ServiceThread; import com.android.server.SystemService; -import com.android.server.biometrics.Utils; import java.util.List; @@ -75,17 +72,12 @@ 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(sensorId, TYPE_IRIS, strength, - authenticator); + biometricService.registerAuthenticator(TYPE_IRIS, hidlSensor, + new IrisAuthenticator(mServiceWrapper, hidlSensor.sensorId)); } catch (RemoteException e) { - Slog.e(TAG, "Remote exception when registering sensorId: " + sensorId); + Slog.e(TAG, "Remote exception when registering sensorId: " + + hidlSensor.sensorId); } } }); diff --git a/services/tests/servicestests/src/com/android/server/biometrics/AuthServiceTest.java b/services/tests/servicestests/src/com/android/server/biometrics/AuthServiceTest.java index 6216c66aa54f..4b86dd048cd1 100644 --- a/services/tests/servicestests/src/com/android/server/biometrics/AuthServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/biometrics/AuthServiceTest.java @@ -152,8 +152,7 @@ public class AuthServiceTest { verify(mBiometricService, never()).registerAuthenticator( anyInt(), - anyInt(), - anyInt(), + any(), any()); } diff --git a/services/tests/servicestests/src/com/android/server/biometrics/AuthSessionTest.java b/services/tests/servicestests/src/com/android/server/biometrics/AuthSessionTest.java index 4cdca268fc4b..dbf5021d3c6b 100644 --- a/services/tests/servicestests/src/com/android/server/biometrics/AuthSessionTest.java +++ b/services/tests/servicestests/src/com/android/server/biometrics/AuthSessionTest.java @@ -44,13 +44,14 @@ import android.app.admin.DevicePolicyManager; import android.app.trust.ITrustManager; import android.content.Context; 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.FingerprintSensorProperties; import android.hardware.fingerprint.FingerprintSensorPropertiesInternal; import android.os.Binder; @@ -458,9 +459,16 @@ 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(mContext, id, + + 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, TYPE_FINGERPRINT /* modality */, - Authenticators.BIOMETRIC_STRONG /* strength */, + props, fingerprintAuthenticator) { @Override boolean confirmationAlwaysRequired(int userId) { @@ -473,21 +481,6 @@ 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); } @@ -495,9 +488,13 @@ 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, id, + mSensors.add(new BiometricSensor(mContext, TYPE_FACE /* modality */, - Authenticators.BIOMETRIC_STRONG /* strength */, + new FaceSensorPropertiesInternal(id, + SensorProperties.STRENGTH_STRONG, 5 /* maxEnrollmentsPerUser */, + List.of() /* componentInfo */, FaceSensorProperties.TYPE_UNKNOWN, + true /* supportsFace Detection */, true /* supportsSelfIllumination */, + false /* resetLockoutRequiresHardwareAuthToken */), authenticator) { @Override boolean confirmationAlwaysRequired(int userId) { diff --git a/services/tests/servicestests/src/com/android/server/biometrics/BiometricServiceTest.java b/services/tests/servicestests/src/com/android/server/biometrics/BiometricServiceTest.java index 168642e3533f..b51a8c4e1b6c 100644 --- a/services/tests/servicestests/src/com/android/server/biometrics/BiometricServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/biometrics/BiometricServiceTest.java @@ -19,6 +19,7 @@ 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; @@ -66,7 +67,11 @@ 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; @@ -93,6 +98,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import java.util.List; import java.util.Random; @Presubmit @@ -114,6 +120,7 @@ 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; @@ -193,6 +200,11 @@ 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 @@ -328,8 +340,7 @@ public class BiometricServiceTest { mBiometricService = new BiometricService(mContext, mInjector); mBiometricService.onStart(); - mBiometricService.mImpl.registerAuthenticator(0 /* id */, - TYPE_FINGERPRINT, Authenticators.BIOMETRIC_STRONG, + mBiometricService.mImpl.registerAuthenticator(TYPE_FINGERPRINT, mFingerprintProps, mFingerprintAuthenticator); invokeAuthenticate(mBiometricService.mImpl, mReceiver1, false /* requireConfirmation */, @@ -401,8 +412,7 @@ public class BiometricServiceTest { mBiometricService = new BiometricService(mContext, mInjector); mBiometricService.onStart(); - mBiometricService.mImpl.registerAuthenticator(0 /* id */, - TYPE_FINGERPRINT, Authenticators.BIOMETRIC_STRONG, + mBiometricService.mImpl.registerAuthenticator(TYPE_FINGERPRINT, mFingerprintProps, mFingerprintAuthenticator); invokeAuthenticate(mBiometricService.mImpl, mReceiver1, false /* requireConfirmation */, @@ -1334,9 +1344,13 @@ public class BiometricServiceTest { for (int i = 0; i < testCases.length; i++) { final BiometricSensor sensor = - new BiometricSensor(mContext, 0 /* id */, + new BiometricSensor(mContext, TYPE_FINGERPRINT, - testCases[i][0], + new FingerprintSensorPropertiesInternal(i /* id */, + Utils.authenticatorStrengthToPropertyStrength(testCases[i][0]), + 5 /* maxEnrollmentsPerUser */, List.of() /* componentInfo */, + FingerprintSensorProperties.TYPE_UNKNOWN, + false /* resetLockoutRequiresHardwareAuthToken */), mock(IBiometricAuthenticator.class)) { @Override boolean confirmationAlwaysRequired(int userId) { @@ -1364,8 +1378,7 @@ public class BiometricServiceTest { when(mFingerprintAuthenticator.hasEnrolledTemplates(anyInt(), any())) .thenReturn(true); when(mFingerprintAuthenticator.isHardwareDetected(any())).thenReturn(true); - mBiometricService.mImpl.registerAuthenticator(0 /* testId */, - TYPE_FINGERPRINT, Authenticators.BIOMETRIC_STRONG, + mBiometricService.mImpl.registerAuthenticator(TYPE_FINGERPRINT, mFingerprintProps, mFingerprintAuthenticator); verify(mBiometricService.mBiometricStrengthController).updateStrengths(); @@ -1376,15 +1389,14 @@ 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); - mBiometricService.mImpl.registerAuthenticator(testId /* id */, - TYPE_FINGERPRINT, Authenticators.BIOMETRIC_STRONG, + + final int testId = SENSOR_ID_FINGERPRINT; + mBiometricService.mImpl.registerAuthenticator(TYPE_FINGERPRINT, mFingerprintProps, mFingerprintAuthenticator); // Downgrade the authenticator @@ -1484,11 +1496,9 @@ public class BiometricServiceTest { mBiometricService.onStart(); mBiometricService.mImpl.registerAuthenticator( - 0 /* id */, 2 /* modality */, 15 /* strength */, - mFingerprintAuthenticator); + 2 /* modality */, mFingerprintProps, mFingerprintAuthenticator); mBiometricService.mImpl.registerAuthenticator( - 0 /* id */, 2 /* modality */, 15 /* strength */, - mFingerprintAuthenticator); + 2 /* modality */, mFingerprintProps, mFingerprintAuthenticator); } @Test(expected = IllegalArgumentException.class) @@ -1498,9 +1508,7 @@ public class BiometricServiceTest { mBiometricService.onStart(); mBiometricService.mImpl.registerAuthenticator( - 0 /* id */, 2 /* modality */, - Authenticators.BIOMETRIC_STRONG /* strength */, - null /* authenticator */); + 2 /* modality */, mFingerprintProps, null /* authenticator */); } @Test @@ -1511,8 +1519,13 @@ public class BiometricServiceTest { for (String s : mInjector.getConfiguration(null)) { SensorConfig config = new SensorConfig(s); - mBiometricService.mImpl.registerAuthenticator(config.id, config.modality, - config.strength, mFingerprintAuthenticator); + mBiometricService.mImpl.registerAuthenticator(config.modality, + new FingerprintSensorPropertiesInternal(config.id, + Utils.authenticatorStrengthToPropertyStrength(config.strength), + 5 /* maxEnrollmentsPerUser */, List.of() /* componentInfo */, + FingerprintSensorProperties.TYPE_UNKNOWN, + false /* resetLockoutRequiresHardwareAuthToken */), + mFingerprintAuthenticator); } } @@ -1609,7 +1622,12 @@ public class BiometricServiceTest { when(mFingerprintAuthenticator.isHardwareDetected(any())).thenReturn(true); when(mFingerprintAuthenticator.getLockoutModeForUser(anyInt())) .thenReturn(LockoutTracker.LOCKOUT_NONE); - mBiometricService.mImpl.registerAuthenticator(SENSOR_ID_FINGERPRINT, modality, strength, + mBiometricService.mImpl.registerAuthenticator(modality, + new FingerprintSensorPropertiesInternal(SENSOR_ID_FINGERPRINT, + Utils.authenticatorStrengthToPropertyStrength(strength), + 5 /* maxEnrollmentsPerUser */, List.of() /* componentInfo */, + FingerprintSensorProperties.TYPE_UNKNOWN, + false /* resetLockoutRequiresHardwareAuthToken */), mFingerprintAuthenticator); } @@ -1618,7 +1636,13 @@ public class BiometricServiceTest { when(mFaceAuthenticator.isHardwareDetected(any())).thenReturn(true); when(mFaceAuthenticator.getLockoutModeForUser(anyInt())) .thenReturn(LockoutTracker.LOCKOUT_NONE); - mBiometricService.mImpl.registerAuthenticator(SENSOR_ID_FACE, modality, strength, + 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); } } @@ -1641,15 +1665,27 @@ public class BiometricServiceTest { when(mFingerprintAuthenticator.hasEnrolledTemplates(anyInt(), any())) .thenReturn(true); when(mFingerprintAuthenticator.isHardwareDetected(any())).thenReturn(true); - mBiometricService.mImpl.registerAuthenticator(SENSOR_ID_FINGERPRINT, modality, - strength, mFingerprintAuthenticator); + mBiometricService.mImpl.registerAuthenticator(modality, + new FingerprintSensorPropertiesInternal(SENSOR_ID_FINGERPRINT, + Utils.authenticatorStrengthToPropertyStrength(strength), + 5 /* maxEnrollmentsPerUser */, List.of() /* componentInfo */, + FingerprintSensorProperties.TYPE_UNKNOWN, + false /* resetLockoutRequiresHardwareAuthToken */), + mFingerprintAuthenticator); } if ((modality & BiometricAuthenticator.TYPE_FACE) != 0) { when(mFaceAuthenticator.hasEnrolledTemplates(anyInt(), any())).thenReturn(true); when(mFaceAuthenticator.isHardwareDetected(any())).thenReturn(true); - mBiometricService.mImpl.registerAuthenticator(SENSOR_ID_FACE, modality, - strength, mFaceAuthenticator); + 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); } } } diff --git a/services/tests/servicestests/src/com/android/server/biometrics/InvalidationTrackerTest.java b/services/tests/servicestests/src/com/android/server/biometrics/InvalidationTrackerTest.java index ee5ab92065ee..f7539bd27c9d 100644 --- a/services/tests/servicestests/src/com/android/server/biometrics/InvalidationTrackerTest.java +++ b/services/tests/servicestests/src/com/android/server/biometrics/InvalidationTrackerTest.java @@ -16,6 +16,9 @@ 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; @@ -27,9 +30,13 @@ 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; @@ -42,6 +49,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import java.util.ArrayList; +import java.util.List; @Presubmit @SmallTest @@ -59,26 +67,54 @@ 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, 0 /* id */, - BiometricAuthenticator.TYPE_FINGERPRINT, Authenticators.BIOMETRIC_STRONG, + 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 */), authenticator1); final IBiometricAuthenticator authenticator2 = mock(IBiometricAuthenticator.class); when(authenticator2.hasEnrolledTemplates(anyInt(), any())).thenReturn(true); - final TestSensor sensor2 = new TestSensor(mContext, 1 /* id */, - BiometricAuthenticator.TYPE_FINGERPRINT, Authenticators.BIOMETRIC_STRONG, + 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 */), authenticator2); final IBiometricAuthenticator authenticator3 = mock(IBiometricAuthenticator.class); when(authenticator3.hasEnrolledTemplates(anyInt(), any())).thenReturn(true); - final TestSensor sensor3 = new TestSensor(mContext, 2 /* id */, - BiometricAuthenticator.TYPE_FACE, Authenticators.BIOMETRIC_STRONG, + 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 */), authenticator3); final IBiometricAuthenticator authenticator4 = mock(IBiometricAuthenticator.class); when(authenticator4.hasEnrolledTemplates(anyInt(), any())).thenReturn(true); - final TestSensor sensor4 = new TestSensor(mContext, 3 /* id */, - BiometricAuthenticator.TYPE_FACE, Authenticators.BIOMETRIC_WEAK, + 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 */), authenticator4); final ArrayList<BiometricSensor> sensors = new ArrayList<>(); @@ -113,9 +149,9 @@ public class InvalidationTrackerTest { private static class TestSensor extends BiometricSensor { - TestSensor(@NonNull Context context, int id, int modality, int strength, + TestSensor(@NonNull Context context, int modality, @NonNull SensorPropertiesInternal props, @NonNull IBiometricAuthenticator impl) { - super(context, id, modality, strength, impl); + super(context, modality, props, impl); } @Override diff --git a/services/tests/servicestests/src/com/android/server/biometrics/sensors/face/FaceServiceRegistryTest.java b/services/tests/servicestests/src/com/android/server/biometrics/sensors/face/FaceServiceRegistryTest.java index 903ed9082481..d3f04dfcfa17 100644 --- a/services/tests/servicestests/src/com/android/server/biometrics/sensors/face/FaceServiceRegistryTest.java +++ b/services/tests/servicestests/src/com/android/server/biometrics/sensors/face/FaceServiceRegistryTest.java @@ -17,8 +17,6 @@ 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; @@ -70,9 +68,7 @@ public class FaceServiceRegistryTest { @Mock private ServiceProvider mProvider2; @Captor - private ArgumentCaptor<Integer> mIdCaptor; - @Captor - private ArgumentCaptor<Integer> mStrengthCaptor; + private ArgumentCaptor<FaceSensorPropertiesInternal> mPropsCaptor; private FaceSensorPropertiesInternal mProvider1Props; private FaceSensorPropertiesInternal mProvider2Props; @@ -82,13 +78,13 @@ public class FaceServiceRegistryTest { public void setup() { mProvider1Props = new FaceSensorPropertiesInternal(SENSOR_ID_1, STRENGTH_WEAK, 5 /* maxEnrollmentsPerUser */, - List.of(), FaceSensorProperties.TYPE_RGB, + List.of() /* componentInfo */, FaceSensorProperties.TYPE_RGB, true /* supportsFace Detection */, true /* supportsSelfIllumination */, false /* resetLockoutRequiresHardwareAuthToken */); mProvider2Props = new FaceSensorPropertiesInternal(SENSOR_ID_2, STRENGTH_STRONG, 5 /* maxEnrollmentsPerUser */, - List.of(), FaceSensorProperties.TYPE_IR, + List.of() /* componentInfo */, FaceSensorProperties.TYPE_IR, true /* supportsFace Detection */, true /* supportsSelfIllumination */, false /* resetLockoutRequiresHardwareAuthToken */); @@ -107,10 +103,9 @@ public class FaceServiceRegistryTest { assertThat(mRegistry.getProviders()).containsExactly(mProvider1, mProvider2); assertThat(mRegistry.getAllProperties()).containsExactly(mProvider1Props, mProvider2Props); verify(mBiometricService, times(2)).registerAuthenticator( - 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); + eq(TYPE_FACE), mPropsCaptor.capture(), any()); + assertThat(mPropsCaptor.getAllValues()) + .containsExactly(mProvider1Props, mProvider2Props); } @Test diff --git a/services/tests/servicestests/src/com/android/server/biometrics/sensors/fingerprint/FingerprintServiceRegistryTest.java b/services/tests/servicestests/src/com/android/server/biometrics/sensors/fingerprint/FingerprintServiceRegistryTest.java index 13c3f64fec93..6e09069e654b 100644 --- a/services/tests/servicestests/src/com/android/server/biometrics/sensors/fingerprint/FingerprintServiceRegistryTest.java +++ b/services/tests/servicestests/src/com/android/server/biometrics/sensors/fingerprint/FingerprintServiceRegistryTest.java @@ -17,8 +17,6 @@ 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; @@ -70,9 +68,7 @@ public class FingerprintServiceRegistryTest { @Mock private ServiceProvider mProvider2; @Captor - private ArgumentCaptor<Integer> mIdCaptor; - @Captor - private ArgumentCaptor<Integer> mStrengthCaptor; + private ArgumentCaptor<FingerprintSensorPropertiesInternal> mPropsCaptor; private FingerprintSensorPropertiesInternal mProvider1Props; private FingerprintSensorPropertiesInternal mProvider2Props; @@ -82,11 +78,11 @@ public class FingerprintServiceRegistryTest { public void setup() { mProvider1Props = new FingerprintSensorPropertiesInternal(SENSOR_ID_1, STRENGTH_WEAK, 5 /* maxEnrollmentsPerUser */, - List.of(), FingerprintSensorProperties.TYPE_UDFPS_OPTICAL, + List.of() /* componentInfo */, FingerprintSensorProperties.TYPE_UDFPS_OPTICAL, false /* resetLockoutRequiresHardwareAuthToken */); mProvider2Props = new FingerprintSensorPropertiesInternal(SENSOR_ID_2, STRENGTH_STRONG, 5 /* maxEnrollmentsPerUser */, - List.of(), FingerprintSensorProperties.TYPE_UNKNOWN, + List.of() /* componentInfo */, FingerprintSensorProperties.TYPE_UNKNOWN, false /* resetLockoutRequiresHardwareAuthToken */); when(mProvider1.getSensorProperties()).thenReturn(List.of(mProvider1Props)); @@ -103,10 +99,9 @@ public class FingerprintServiceRegistryTest { assertThat(mRegistry.getProviders()).containsExactly(mProvider1, mProvider2); assertThat(mRegistry.getAllProperties()).containsExactly(mProvider1Props, mProvider2Props); verify(mBiometricService, times(2)).registerAuthenticator( - 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); + eq(TYPE_FINGERPRINT), mPropsCaptor.capture(), any()); + assertThat(mPropsCaptor.getAllValues()) + .containsExactly(mProvider1Props, mProvider2Props); } @Test diff --git a/services/tests/servicestests/src/com/android/server/biometrics/sensors/fingerprint/FingerprintServiceTest.java b/services/tests/servicestests/src/com/android/server/biometrics/sensors/fingerprint/FingerprintServiceTest.java index 25a700a5275f..1089c07e6787 100644 --- a/services/tests/servicestests/src/com/android/server/biometrics/sensors/fingerprint/FingerprintServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/biometrics/sensors/fingerprint/FingerprintServiceTest.java @@ -110,15 +110,17 @@ public class FingerprintServiceTest { private final FingerprintSensorPropertiesInternal mSensorPropsDefault = new FingerprintSensorPropertiesInternal(ID_DEFAULT, STRENGTH_STRONG, 2 /* maxEnrollmentsPerUser */, - List.of(), + List.of() /* componentInfo */, TYPE_REAR, false /* resetLockoutRequiresHardwareAuthToken */); private final FingerprintSensorPropertiesInternal mSensorPropsVirtual = new FingerprintSensorPropertiesInternal(ID_VIRTUAL, STRENGTH_STRONG, 2 /* maxEnrollmentsPerUser */, - List.of(), + List.of() /* componentInfo */, TYPE_UDFPS_OPTICAL, false /* resetLockoutRequiresHardwareAuthToken */); + @Captor + private ArgumentCaptor<FingerprintSensorPropertiesInternal> mPropsCaptor; private FingerprintService mService; @Before @@ -166,7 +168,8 @@ public class FingerprintServiceTest { mService.mServiceWrapper.registerAuthenticators(HIDL_AUTHENTICATORS); waitForRegistration(); - verify(mIBiometricService).registerAuthenticator(eq(ID_DEFAULT), anyInt(), anyInt(), any()); + verify(mIBiometricService).registerAuthenticator(anyInt(), mPropsCaptor.capture(), any()); + assertThat(mPropsCaptor.getAllValues()).containsExactly(mSensorPropsDefault); } @Test @@ -178,7 +181,8 @@ public class FingerprintServiceTest { mService.mServiceWrapper.registerAuthenticators(HIDL_AUTHENTICATORS); waitForRegistration(); - verify(mIBiometricService).registerAuthenticator(eq(ID_VIRTUAL), anyInt(), anyInt(), any()); + verify(mIBiometricService).registerAuthenticator(anyInt(), mPropsCaptor.capture(), any()); + assertThat(mPropsCaptor.getAllValues()).containsExactly(mSensorPropsVirtual); } @Test @@ -188,7 +192,8 @@ public class FingerprintServiceTest { mService.mServiceWrapper.registerAuthenticators(HIDL_AUTHENTICATORS); waitForRegistration(); - verify(mIBiometricService).registerAuthenticator(eq(ID_VIRTUAL), anyInt(), anyInt(), any()); + verify(mIBiometricService).registerAuthenticator(anyInt(), mPropsCaptor.capture(), any()); + assertThat(mPropsCaptor.getAllValues()).containsExactly(mSensorPropsVirtual); } private void waitForRegistration() throws Exception { |