diff options
| author | 2024-04-05 13:33:45 +0000 | |
|---|---|---|
| committer | 2024-04-10 14:15:10 +0000 | |
| commit | d0071d27f84e8f7a7c62f8c1a22cc47a9f51cd2c (patch) | |
| tree | 998d9b8f95797d0d500e1f9cf7db87cae42712e4 | |
| parent | 47ad7f750f424016b856098b440cb4a24fc1aa14 (diff) | |
Enable biometric virtual sensors separately
Bug: 330927425
Test: atest BiometricsE2eTests:BiometricPromptAuthSuccessTest
atest FrameworksServicesTests:FingerprintServiceTest
atest FrameworksServicesTests:FaceServiceTest
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:f84de6e6d0d3ee99f1037b17409aa9e87e7a4bfb)
Merged-In: I71133b40fb57f9c2657df3cbffd3836a256f1432
Change-Id: I71133b40fb57f9c2657df3cbffd3836a256f1432
7 files changed, 69 insertions, 12 deletions
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 03fa8413f2cc..8439833c3754 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -10919,7 +10919,7 @@ public final class Settings { "biometric_debug_enabled"; /** - * Whether or not virtual sensors are enabled. + * Whether or not both fingerprint and face virtual sensors are enabled. * @hide */ @TestApi @@ -10927,6 +10927,22 @@ public final class Settings { public static final String BIOMETRIC_VIRTUAL_ENABLED = "biometric_virtual_enabled"; /** + * Whether or not fingerprint virtual sensors are enabled. + * @hide + */ + @FlaggedApi("com.android.server.biometrics.face_vhal_feature") + public static final String BIOMETRIC_FINGERPRINT_VIRTUAL_ENABLED = + "biometric_fingerprint_virtual_enabled"; + + /** + * Whether or not face virtual sensors are enabled. + * @hide + */ + @FlaggedApi("com.android.server.biometrics.face_vhal_feature") + public static final String BIOMETRIC_FACE_VIRTUAL_ENABLED = + "biometric_face_virtual_enabled"; + + /** * Whether or not biometric is allowed on Keyguard. * @hide */ diff --git a/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java b/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java index 28cdc6db192b..4f9e11a2bde2 100644 --- a/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java +++ b/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java @@ -848,6 +848,8 @@ public class SettingsBackupTest { Settings.Secure.BIOMETRIC_APP_ENABLED, Settings.Secure.BIOMETRIC_KEYGUARD_ENABLED, Settings.Secure.BIOMETRIC_VIRTUAL_ENABLED, + Settings.Secure.BIOMETRIC_FINGERPRINT_VIRTUAL_ENABLED, + Settings.Secure.BIOMETRIC_FACE_VIRTUAL_ENABLED, Settings.Secure.BLUETOOTH_ADDR_VALID, Settings.Secure.BLUETOOTH_ADDRESS, Settings.Secure.BLUETOOTH_NAME, diff --git a/services/core/java/com/android/server/biometrics/Utils.java b/services/core/java/com/android/server/biometrics/Utils.java index f51b62d77ab9..4af30a923b4c 100644 --- a/services/core/java/com/android/server/biometrics/Utils.java +++ b/services/core/java/com/android/server/biometrics/Utils.java @@ -89,11 +89,23 @@ public class Utils { return true; } - /** If virtualized biometrics are supported (requires debug build). */ - public static boolean isVirtualEnabled(@NonNull Context context) { + /** If virtualized fingerprint sensor is supported. */ + public static boolean isFingerprintVirtualEnabled(@NonNull Context context) { return Build.isDebuggable() - && Settings.Secure.getIntForUser(context.getContentResolver(), - Settings.Secure.BIOMETRIC_VIRTUAL_ENABLED, 0, UserHandle.USER_CURRENT) == 1; + && (Settings.Secure.getIntForUser(context.getContentResolver(), + Settings.Secure.BIOMETRIC_FINGERPRINT_VIRTUAL_ENABLED, 0, + UserHandle.USER_CURRENT) == 1 + || Settings.Secure.getIntForUser(context.getContentResolver(), + Settings.Secure.BIOMETRIC_VIRTUAL_ENABLED, 0, UserHandle.USER_CURRENT) == 1); + } + + /** If virtualized face sensor is supported. */ + public static boolean isFaceVirtualEnabled(@NonNull Context context) { + return Build.isDebuggable() + && (Settings.Secure.getIntForUser(context.getContentResolver(), + Settings.Secure.BIOMETRIC_FACE_VIRTUAL_ENABLED, 0, UserHandle.USER_CURRENT) == 1 + || Settings.Secure.getIntForUser(context.getContentResolver(), + Settings.Secure.BIOMETRIC_VIRTUAL_ENABLED, 0, UserHandle.USER_CURRENT) == 1); } /** diff --git a/services/core/java/com/android/server/biometrics/sensors/face/FaceService.java b/services/core/java/com/android/server/biometrics/sensors/face/FaceService.java index 7ee2a7ababb3..f4c34ca50222 100644 --- a/services/core/java/com/android/server/biometrics/sensors/face/FaceService.java +++ b/services/core/java/com/android/server/biometrics/sensors/face/FaceService.java @@ -748,7 +748,7 @@ public class FaceService extends SystemService { final Pair<String, SensorProps[]> virtualSensorProps = faceSensorConfigurations .getSensorPairForInstance("virtual"); - if (Utils.isVirtualEnabled(getContext())) { + if (Utils.isFaceVirtualEnabled(getContext())) { if (virtualSensorProps != null) { return virtualSensorProps; } else { @@ -778,7 +778,7 @@ public class FaceService extends SystemService { } final int virtualAt = aidlInstances.indexOf("virtual"); - if (Flags.faceVhalFeature() && Utils.isVirtualEnabled(getContext())) { + if (Flags.faceVhalFeature() && Utils.isFaceVirtualEnabled(getContext())) { if (virtualAt != -1) { //only virtual instance should be returned Slog.i(TAG, "virtual hal is used"); @@ -920,7 +920,7 @@ public class FaceService extends SystemService { void syncEnrollmentsNow() { Utils.checkPermissionOrShell(getContext(), MANAGE_FACE); - if (Flags.faceVhalFeature() && Utils.isVirtualEnabled(getContext())) { + if (Flags.faceVhalFeature() && Utils.isFaceVirtualEnabled(getContext())) { Slog.i(TAG, "Sync virtual enrollments"); final int userId = ActivityManager.getCurrentUser(); for (ServiceProvider provider : mRegistry.getProviders()) { diff --git a/services/core/java/com/android/server/biometrics/sensors/fingerprint/FingerprintService.java b/services/core/java/com/android/server/biometrics/sensors/fingerprint/FingerprintService.java index 1ba12134ab29..97856917755e 100644 --- a/services/core/java/com/android/server/biometrics/sensors/fingerprint/FingerprintService.java +++ b/services/core/java/com/android/server/biometrics/sensors/fingerprint/FingerprintService.java @@ -1136,7 +1136,7 @@ public class FingerprintService extends SystemService { final Pair<String, SensorProps[]> virtualSensorPropsPair = fingerprintSensorConfigurations .getSensorPairForInstance("virtual"); - if (Utils.isVirtualEnabled(getContext())) { + if (Utils.isFingerprintVirtualEnabled(getContext())) { if (virtualSensorPropsPair != null) { return virtualSensorPropsPair; } else { @@ -1160,7 +1160,7 @@ public class FingerprintService extends SystemService { } final int virtualAt = aidlInstances.indexOf("virtual"); - if (Utils.isVirtualEnabled(getContext())) { + if (Utils.isFingerprintVirtualEnabled(getContext())) { if (virtualAt != -1) { //only virtual instance should be returned Slog.i(TAG, "virtual hal is used"); @@ -1286,7 +1286,7 @@ public class FingerprintService extends SystemService { void syncEnrollmentsNow() { Utils.checkPermissionOrShell(getContext(), MANAGE_FINGERPRINT); - if (Utils.isVirtualEnabled(getContext())) { + if (Utils.isFingerprintVirtualEnabled(getContext())) { Slog.i(TAG, "Sync virtual enrollments"); final int userId = ActivityManager.getCurrentUser(); final CountDownLatch latch = new CountDownLatch(mRegistry.getProviders().size()); @@ -1315,7 +1315,7 @@ public class FingerprintService extends SystemService { } void simulateVhalFingerDown() { - if (Utils.isVirtualEnabled(getContext())) { + if (Utils.isFingerprintVirtualEnabled(getContext())) { Slog.i(TAG, "Simulate virtual HAL finger down event"); final Pair<Integer, ServiceProvider> provider = mRegistry.getSingleProvider(); if (provider != null) { diff --git a/services/tests/servicestests/src/com/android/server/biometrics/sensors/face/FaceServiceTest.java b/services/tests/servicestests/src/com/android/server/biometrics/sensors/face/FaceServiceTest.java index 3aaac2e9cf1b..65999aec02f5 100644 --- a/services/tests/servicestests/src/com/android/server/biometrics/sensors/face/FaceServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/biometrics/sensors/face/FaceServiceTest.java @@ -196,6 +196,21 @@ public class FaceServiceTest { } @Test + @RequiresFlagsEnabled({Flags.FLAG_DE_HIDL, Flags.FLAG_FACE_VHAL_FEATURE}) + public void registerAuthenticatorsLegacy_virtualFaceOnly() throws Exception { + initService(); + Settings.Secure.putInt(mSettingsRule.mockContentResolver(mContext), + Settings.Secure.BIOMETRIC_FACE_VIRTUAL_ENABLED, 1); + + mFaceService.mServiceWrapper.registerAuthenticatorsLegacy(mFaceSensorConfigurations); + waitForRegistration(); + + verify(mIBiometricService).registerAuthenticator(eq(ID_VIRTUAL), + eq(BiometricAuthenticator.TYPE_FACE), + eq(Utils.propertyStrengthToAuthenticatorStrength(STRENGTH_STRONG)), any()); + } + + @Test @RequiresFlagsEnabled(Flags.FLAG_DE_HIDL) public void registerAuthenticatorsLegacy_virtualAlwaysWhenNoOther() throws Exception { mFaceSensorConfigurations = new FaceSensorConfigurations(false); 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 88956b614eae..cdbf1f7910ce 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 @@ -243,6 +243,18 @@ public class FingerprintServiceTest { } @Test + public void registerAuthenticators_virtualFingerprintOnly() throws Exception { + initServiceWith(NAME_DEFAULT, NAME_VIRTUAL); + Settings.Secure.putInt(mSettingsRule.mockContentResolver(mContext), + Settings.Secure.BIOMETRIC_FINGERPRINT_VIRTUAL_ENABLED, 1); + + mService.mServiceWrapper.registerAuthenticators(HIDL_AUTHENTICATORS); + waitForRegistration(); + + verify(mIBiometricService).registerAuthenticator(eq(ID_VIRTUAL), anyInt(), anyInt(), any()); + } + + @Test @RequiresFlagsEnabled(Flags.FLAG_DE_HIDL) public void registerAuthenticatorsLegacy_virtualOnly() throws Exception { initServiceWith(NAME_DEFAULT, NAME_VIRTUAL); |