diff options
4 files changed, 104 insertions, 12 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java b/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java index 5c65977c8929..8a492a83b3df 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java @@ -87,7 +87,7 @@ public class AuthContainerView extends LinearLayout @VisibleForTesting @Nullable AuthBiometricView mBiometricView; @VisibleForTesting @Nullable AuthCredentialView mCredentialView; - private final ImageView mBackgroundView; + @VisibleForTesting final ImageView mBackgroundView; @VisibleForTesting final ScrollView mBiometricScrollView; private final View mPanelView; @@ -333,6 +333,12 @@ public class AuthContainerView extends LinearLayout throw new IllegalStateException("Unknown credential type: " + credentialType); } + // The background is used for detecting taps / cancelling authentication. Since the + // credential view is full-screen and should not be canceled from background taps, + // disable it. + mBackgroundView.setOnClickListener(null); + mBackgroundView.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO); + mCredentialView.setContainerView(this); mCredentialView.setEffectiveUserId(mEffectiveUserId); mCredentialView.setCredentialType(credentialType); diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.java index 486aac894d9b..c6c7b87da544 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.java @@ -178,6 +178,20 @@ public class AuthContainerViewTest extends SysuiTestCase { } @Test + public void testCredentialUI_disablesClickingOnBackground() { + // In the credential view, clicking on the background (to cancel authentication) is not + // valid. Thus, the listener should be null, and it should not be in the accessibility + // hierarchy. + initializeContainer(Authenticators.DEVICE_CREDENTIAL); + + mAuthContainer.onAttachedToWindowInternal(); + + verify(mAuthContainer.mBackgroundView).setOnClickListener(eq(null)); + verify(mAuthContainer.mBackgroundView).setImportantForAccessibility( + eq(View.IMPORTANT_FOR_ACCESSIBILITY_NO)); + } + + @Test public void testLayoutParams_hasSecureWindowFlag() { final IBinder windowToken = mock(IBinder.class); final WindowManager.LayoutParams layoutParams = diff --git a/services/core/java/com/android/server/biometrics/AuthService.java b/services/core/java/com/android/server/biometrics/AuthService.java index 0d88388742d2..0f549842a763 100644 --- a/services/core/java/com/android/server/biometrics/AuthService.java +++ b/services/core/java/com/android/server/biometrics/AuthService.java @@ -99,6 +99,33 @@ public class AuthService extends SystemService { public String[] getConfiguration(Context context) { return context.getResources().getStringArray(R.array.config_biometric_sensors); } + + /** + * Allows us to mock FingerprintService for testing + */ + @VisibleForTesting + public IFingerprintService getFingerprintService() { + return IFingerprintService.Stub.asInterface( + ServiceManager.getService(Context.FINGERPRINT_SERVICE)); + } + + /** + * Allows us to mock FaceService for testing + */ + @VisibleForTesting + public IFaceService getFaceService() { + return IFaceService.Stub.asInterface( + ServiceManager.getService(Context.FACE_SERVICE)); + } + + /** + * Allows us to mock IrisService for testing + */ + @VisibleForTesting + public IIrisService getIrisService() { + return IIrisService.Stub.asInterface( + ServiceManager.getService(Context.IRIS_SERVICE)); + } } private final class AuthServiceImpl extends IAuthService.Stub { @@ -178,7 +205,6 @@ public class AuthService extends SystemService { mInjector = injector; mImpl = new AuthServiceImpl(); - final PackageManager pm = context.getPackageManager(); } private void registerAuthenticator(SensorConfig config) throws RemoteException { @@ -191,18 +217,36 @@ public class AuthService extends SystemService { switch (config.mModality) { case TYPE_FINGERPRINT: - authenticator = new FingerprintAuthenticator(IFingerprintService.Stub.asInterface( - ServiceManager.getService(Context.FINGERPRINT_SERVICE))); + final IFingerprintService fingerprintService = mInjector.getFingerprintService(); + if (fingerprintService == null) { + Slog.e(TAG, "Attempting to register with null FingerprintService. Please check" + + " your device configuration."); + return; + } + + authenticator = new FingerprintAuthenticator(fingerprintService); break; case TYPE_FACE: - authenticator = new FaceAuthenticator(IFaceService.Stub.asInterface( - ServiceManager.getService(Context.FACE_SERVICE))); + final IFaceService faceService = mInjector.getFaceService(); + if (faceService == null) { + Slog.e(TAG, "Attempting to register with null FaceService. Please check your" + + " device configuration."); + return; + } + + authenticator = new FaceAuthenticator(faceService); break; case TYPE_IRIS: - authenticator = new IrisAuthenticator(IIrisService.Stub.asInterface( - ServiceManager.getService(Context.IRIS_SERVICE))); + final IIrisService irisService = mInjector.getIrisService(); + if (irisService == null) { + Slog.e(TAG, "Attempting to register with null IrisService. Please check your" + + " device configuration."); + return; + } + + authenticator = new IrisAuthenticator(irisService); break; default: 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 d38c80cdabe0..6aa928794244 100644 --- a/services/tests/servicestests/src/com/android/server/biometrics/AuthServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/biometrics/AuthServiceTest.java @@ -24,6 +24,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -32,6 +33,9 @@ import android.content.pm.PackageManager; import android.hardware.biometrics.IBiometricEnabledOnKeyguardCallback; import android.hardware.biometrics.IBiometricService; import android.hardware.biometrics.IBiometricServiceReceiver; +import android.hardware.face.IFaceService; +import android.hardware.fingerprint.IFingerprintService; +import android.hardware.iris.IIrisService; import android.os.Binder; import android.os.Bundle; @@ -61,6 +65,12 @@ public class AuthServiceTest { AuthService.Injector mInjector; @Mock IBiometricService mBiometricService; + @Mock + IFingerprintService mFingerprintService; + @Mock + IIrisService mIrisService; + @Mock + IFaceService mFaceService; @Before public void setUp() { @@ -76,10 +86,28 @@ public class AuthServiceTest { when(mContext.getPackageManager()).thenReturn(mPackageManager); when(mInjector.getBiometricService()).thenReturn(mBiometricService); when(mInjector.getConfiguration(any())).thenReturn(config); - when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) - .thenReturn(true); - when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_IRIS)).thenReturn(true); - when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(true); + when(mInjector.getFingerprintService()).thenReturn(mFingerprintService); + when(mInjector.getFaceService()).thenReturn(mFaceService); + when(mInjector.getIrisService()).thenReturn(mIrisService); + } + + @Test + public void testRegisterNullService_doesNotRegister() throws Exception { + + // Config contains Fingerprint, Iris, Face, but services are all null + + when(mInjector.getFingerprintService()).thenReturn(null); + when(mInjector.getFaceService()).thenReturn(null); + when(mInjector.getIrisService()).thenReturn(null); + + mAuthService = new AuthService(mContext, mInjector); + mAuthService.onStart(); + + verify(mBiometricService, never()).registerAuthenticator( + anyInt(), + anyInt(), + anyInt(), + any()); } |