Loading core/java/android/hardware/biometrics/IBiometricService.aidl +1 −2 Original line number Diff line number Diff line Loading @@ -66,8 +66,7 @@ interface IBiometricService { // Register callback for when keyguard biometric eligibility changes. @EnforcePermission("USE_BIOMETRIC_INTERNAL") void registerEnabledOnKeyguardCallback(IBiometricEnabledOnKeyguardCallback callback, int callingUserId); void registerEnabledOnKeyguardCallback(IBiometricEnabledOnKeyguardCallback callback); // Notify BiometricService when <Biometric>Service is ready to start the prepared client. // Client lifecycle is still managed in <Biometric>Service. Loading services/core/java/com/android/server/biometrics/AuthService.java +1 −2 Original line number Diff line number Diff line Loading @@ -342,10 +342,9 @@ public class AuthService extends SystemService { public void registerEnabledOnKeyguardCallback( IBiometricEnabledOnKeyguardCallback callback) throws RemoteException { checkInternalPermission(); final int callingUserId = UserHandle.getCallingUserId(); final long identity = Binder.clearCallingIdentity(); try { mBiometricService.registerEnabledOnKeyguardCallback(callback, callingUserId); mBiometricService.registerEnabledOnKeyguardCallback(callback); } finally { Binder.restoreCallingIdentity(identity); } Loading services/core/java/com/android/server/biometrics/BiometricService.java +15 −3 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import android.app.trust.ITrustManager; import android.content.ContentResolver; import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.UserInfo; import android.database.ContentObserver; import android.hardware.biometrics.BiometricAuthenticator; import android.hardware.biometrics.BiometricConstants; Loading Loading @@ -58,6 +59,7 @@ import android.os.Looper; import android.os.RemoteException; import android.os.ServiceManager; import android.os.UserHandle; import android.os.UserManager; import android.provider.Settings; import android.security.KeyStore; import android.text.TextUtils; Loading Loading @@ -103,6 +105,7 @@ public class BiometricService extends SystemService { private final Random mRandom = new Random(); @NonNull private final Supplier<Long> mRequestCounter; @NonNull private final BiometricContext mBiometricContext; private final UserManager mUserManager; @VisibleForTesting IStatusBarService mStatusBarService; Loading Loading @@ -692,14 +695,18 @@ public class BiometricService extends SystemService { @android.annotation.EnforcePermission(android.Manifest.permission.USE_BIOMETRIC_INTERNAL) @Override // Binder call public void registerEnabledOnKeyguardCallback( IBiometricEnabledOnKeyguardCallback callback, int callingUserId) { IBiometricEnabledOnKeyguardCallback callback) { super.registerEnabledOnKeyguardCallback_enforcePermission(); mEnabledOnKeyguardCallbacks.add(new EnabledOnKeyguardCallback(callback)); final List<UserInfo> aliveUsers = mUserManager.getAliveUsers(); try { callback.onChanged(mSettingObserver.getEnabledOnKeyguard(callingUserId), callingUserId); for (UserInfo userInfo: aliveUsers) { final int userId = userInfo.id; callback.onChanged(mSettingObserver.getEnabledOnKeyguard(userId), userId); } } catch (RemoteException e) { Slog.w(TAG, "Remote exception", e); } Loading Loading @@ -1014,6 +1021,10 @@ public class BiometricService extends SystemService { public BiometricContext getBiometricContext(Context context) { return BiometricContext.getInstance(context); } public UserManager getUserManager(Context context) { return context.getSystemService(UserManager.class); } } /** Loading Loading @@ -1041,6 +1052,7 @@ public class BiometricService extends SystemService { mEnabledOnKeyguardCallbacks); mRequestCounter = mInjector.getRequestGenerator(); mBiometricContext = injector.getBiometricContext(context); mUserManager = injector.getUserManager(context); try { injector.getActivityManagerService().registerUserSwitchObserver( Loading services/tests/servicestests/src/com/android/server/biometrics/AuthServiceTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -367,7 +367,7 @@ public class AuthServiceTest { waitForIdle(); verify(mBiometricService).registerEnabledOnKeyguardCallback( eq(callback), eq(UserHandle.getCallingUserId())); eq(callback)); } private static void setInternalAndTestBiometricPermissions( Loading services/tests/servicestests/src/com/android/server/biometrics/BiometricServiceTest.java +34 −0 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; import android.app.IActivityManager; Loading @@ -55,12 +56,14 @@ import android.app.admin.DevicePolicyManager; import android.app.trust.ITrustManager; import android.content.ContentResolver; import android.content.Context; import android.content.pm.UserInfo; import android.content.res.Resources; import android.hardware.biometrics.BiometricAuthenticator; import android.hardware.biometrics.BiometricConstants; import android.hardware.biometrics.BiometricManager; import android.hardware.biometrics.BiometricPrompt; import android.hardware.biometrics.IBiometricAuthenticator; import android.hardware.biometrics.IBiometricEnabledOnKeyguardCallback; import android.hardware.biometrics.IBiometricSensorReceiver; import android.hardware.biometrics.IBiometricService; import android.hardware.biometrics.IBiometricServiceReceiver; Loading @@ -75,6 +78,7 @@ import android.hardware.fingerprint.FingerprintSensorPropertiesInternal; import android.os.Binder; import android.os.IBinder; import android.os.RemoteException; import android.os.UserManager; import android.platform.test.annotations.Presubmit; import android.security.KeyStore; import android.view.Display; Loading Loading @@ -152,6 +156,8 @@ public class BiometricServiceTest { private ISessionListener mSessionListener; @Mock private AuthSessionCoordinator mAuthSessionCoordinator; @Mock private UserManager mUserManager; BiometricContextProvider mBiometricContextProvider; Loading @@ -177,6 +183,7 @@ public class BiometricServiceTest { when(mInjector.getTrustManager()).thenReturn(mTrustManager); when(mInjector.getDevicePolicyManager(any())).thenReturn(mDevicePolicyManager); when(mInjector.getRequestGenerator()).thenReturn(() -> TEST_REQUEST_ID); when(mInjector.getUserManager(any())).thenReturn(mUserManager); when(mResources.getString(R.string.biometric_error_hw_unavailable)) .thenReturn(ERROR_HW_UNAVAILABLE); Loading Loading @@ -1597,6 +1604,33 @@ public class BiometricServiceTest { verify(mReceiver2, never()).onError(anyInt(), anyInt(), anyInt()); } @Test public void testRegisterEnabledOnKeyguardCallback() throws RemoteException { final UserInfo userInfo1 = new UserInfo(0 /* userId */, "user1" /* name */, 0 /* flags */); final UserInfo userInfo2 = new UserInfo(10 /* userId */, "user2" /* name */, 0 /* flags */); final List<UserInfo> aliveUsers = List.of(userInfo1, userInfo2); final IBiometricEnabledOnKeyguardCallback callback = mock(IBiometricEnabledOnKeyguardCallback.class); mBiometricService = new BiometricService(mContext, mInjector); when(mUserManager.getAliveUsers()).thenReturn(aliveUsers); when(mBiometricService.mSettingObserver.getEnabledOnKeyguard(userInfo1.id)) .thenReturn(true); when(mBiometricService.mSettingObserver.getEnabledOnKeyguard(userInfo2.id)) .thenReturn(false); when(callback.asBinder()).thenReturn(mock(IBinder.class)); mBiometricService.mImpl.registerEnabledOnKeyguardCallback(callback); waitForIdle(); verify(callback).asBinder(); verify(callback).onChanged(true, userInfo1.id); verify(callback).onChanged(false, userInfo2.id); verifyNoMoreInteractions(callback); } // Helper methods private int invokeCanAuthenticate(BiometricService service, int authenticators) Loading Loading
core/java/android/hardware/biometrics/IBiometricService.aidl +1 −2 Original line number Diff line number Diff line Loading @@ -66,8 +66,7 @@ interface IBiometricService { // Register callback for when keyguard biometric eligibility changes. @EnforcePermission("USE_BIOMETRIC_INTERNAL") void registerEnabledOnKeyguardCallback(IBiometricEnabledOnKeyguardCallback callback, int callingUserId); void registerEnabledOnKeyguardCallback(IBiometricEnabledOnKeyguardCallback callback); // Notify BiometricService when <Biometric>Service is ready to start the prepared client. // Client lifecycle is still managed in <Biometric>Service. Loading
services/core/java/com/android/server/biometrics/AuthService.java +1 −2 Original line number Diff line number Diff line Loading @@ -342,10 +342,9 @@ public class AuthService extends SystemService { public void registerEnabledOnKeyguardCallback( IBiometricEnabledOnKeyguardCallback callback) throws RemoteException { checkInternalPermission(); final int callingUserId = UserHandle.getCallingUserId(); final long identity = Binder.clearCallingIdentity(); try { mBiometricService.registerEnabledOnKeyguardCallback(callback, callingUserId); mBiometricService.registerEnabledOnKeyguardCallback(callback); } finally { Binder.restoreCallingIdentity(identity); } Loading
services/core/java/com/android/server/biometrics/BiometricService.java +15 −3 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import android.app.trust.ITrustManager; import android.content.ContentResolver; import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.UserInfo; import android.database.ContentObserver; import android.hardware.biometrics.BiometricAuthenticator; import android.hardware.biometrics.BiometricConstants; Loading Loading @@ -58,6 +59,7 @@ import android.os.Looper; import android.os.RemoteException; import android.os.ServiceManager; import android.os.UserHandle; import android.os.UserManager; import android.provider.Settings; import android.security.KeyStore; import android.text.TextUtils; Loading Loading @@ -103,6 +105,7 @@ public class BiometricService extends SystemService { private final Random mRandom = new Random(); @NonNull private final Supplier<Long> mRequestCounter; @NonNull private final BiometricContext mBiometricContext; private final UserManager mUserManager; @VisibleForTesting IStatusBarService mStatusBarService; Loading Loading @@ -692,14 +695,18 @@ public class BiometricService extends SystemService { @android.annotation.EnforcePermission(android.Manifest.permission.USE_BIOMETRIC_INTERNAL) @Override // Binder call public void registerEnabledOnKeyguardCallback( IBiometricEnabledOnKeyguardCallback callback, int callingUserId) { IBiometricEnabledOnKeyguardCallback callback) { super.registerEnabledOnKeyguardCallback_enforcePermission(); mEnabledOnKeyguardCallbacks.add(new EnabledOnKeyguardCallback(callback)); final List<UserInfo> aliveUsers = mUserManager.getAliveUsers(); try { callback.onChanged(mSettingObserver.getEnabledOnKeyguard(callingUserId), callingUserId); for (UserInfo userInfo: aliveUsers) { final int userId = userInfo.id; callback.onChanged(mSettingObserver.getEnabledOnKeyguard(userId), userId); } } catch (RemoteException e) { Slog.w(TAG, "Remote exception", e); } Loading Loading @@ -1014,6 +1021,10 @@ public class BiometricService extends SystemService { public BiometricContext getBiometricContext(Context context) { return BiometricContext.getInstance(context); } public UserManager getUserManager(Context context) { return context.getSystemService(UserManager.class); } } /** Loading Loading @@ -1041,6 +1052,7 @@ public class BiometricService extends SystemService { mEnabledOnKeyguardCallbacks); mRequestCounter = mInjector.getRequestGenerator(); mBiometricContext = injector.getBiometricContext(context); mUserManager = injector.getUserManager(context); try { injector.getActivityManagerService().registerUserSwitchObserver( Loading
services/tests/servicestests/src/com/android/server/biometrics/AuthServiceTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -367,7 +367,7 @@ public class AuthServiceTest { waitForIdle(); verify(mBiometricService).registerEnabledOnKeyguardCallback( eq(callback), eq(UserHandle.getCallingUserId())); eq(callback)); } private static void setInternalAndTestBiometricPermissions( Loading
services/tests/servicestests/src/com/android/server/biometrics/BiometricServiceTest.java +34 −0 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; import android.app.IActivityManager; Loading @@ -55,12 +56,14 @@ import android.app.admin.DevicePolicyManager; import android.app.trust.ITrustManager; import android.content.ContentResolver; import android.content.Context; import android.content.pm.UserInfo; import android.content.res.Resources; import android.hardware.biometrics.BiometricAuthenticator; import android.hardware.biometrics.BiometricConstants; import android.hardware.biometrics.BiometricManager; import android.hardware.biometrics.BiometricPrompt; import android.hardware.biometrics.IBiometricAuthenticator; import android.hardware.biometrics.IBiometricEnabledOnKeyguardCallback; import android.hardware.biometrics.IBiometricSensorReceiver; import android.hardware.biometrics.IBiometricService; import android.hardware.biometrics.IBiometricServiceReceiver; Loading @@ -75,6 +78,7 @@ import android.hardware.fingerprint.FingerprintSensorPropertiesInternal; import android.os.Binder; import android.os.IBinder; import android.os.RemoteException; import android.os.UserManager; import android.platform.test.annotations.Presubmit; import android.security.KeyStore; import android.view.Display; Loading Loading @@ -152,6 +156,8 @@ public class BiometricServiceTest { private ISessionListener mSessionListener; @Mock private AuthSessionCoordinator mAuthSessionCoordinator; @Mock private UserManager mUserManager; BiometricContextProvider mBiometricContextProvider; Loading @@ -177,6 +183,7 @@ public class BiometricServiceTest { when(mInjector.getTrustManager()).thenReturn(mTrustManager); when(mInjector.getDevicePolicyManager(any())).thenReturn(mDevicePolicyManager); when(mInjector.getRequestGenerator()).thenReturn(() -> TEST_REQUEST_ID); when(mInjector.getUserManager(any())).thenReturn(mUserManager); when(mResources.getString(R.string.biometric_error_hw_unavailable)) .thenReturn(ERROR_HW_UNAVAILABLE); Loading Loading @@ -1597,6 +1604,33 @@ public class BiometricServiceTest { verify(mReceiver2, never()).onError(anyInt(), anyInt(), anyInt()); } @Test public void testRegisterEnabledOnKeyguardCallback() throws RemoteException { final UserInfo userInfo1 = new UserInfo(0 /* userId */, "user1" /* name */, 0 /* flags */); final UserInfo userInfo2 = new UserInfo(10 /* userId */, "user2" /* name */, 0 /* flags */); final List<UserInfo> aliveUsers = List.of(userInfo1, userInfo2); final IBiometricEnabledOnKeyguardCallback callback = mock(IBiometricEnabledOnKeyguardCallback.class); mBiometricService = new BiometricService(mContext, mInjector); when(mUserManager.getAliveUsers()).thenReturn(aliveUsers); when(mBiometricService.mSettingObserver.getEnabledOnKeyguard(userInfo1.id)) .thenReturn(true); when(mBiometricService.mSettingObserver.getEnabledOnKeyguard(userInfo2.id)) .thenReturn(false); when(callback.asBinder()).thenReturn(mock(IBinder.class)); mBiometricService.mImpl.registerEnabledOnKeyguardCallback(callback); waitForIdle(); verify(callback).asBinder(); verify(callback).onChanged(true, userInfo1.id); verify(callback).onChanged(false, userInfo2.id); verifyNoMoreInteractions(callback); } // Helper methods private int invokeCanAuthenticate(BiometricService service, int authenticators) Loading