Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b642e394 authored by Kevin Chyn's avatar Kevin Chyn Committed by Android (Google) Code Review
Browse files

Merge changes I36727599,Iaed8a5cb

* changes:
  Credential UI should not respond to background taps
  AuthService should not attempt to register a null <Biometric>Service
parents 5aa3e9af 517d7fb8
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -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);
+14 −0
Original line number Diff line number Diff line
@@ -177,6 +177,20 @@ public class AuthContainerViewTest extends SysuiTestCase {
        assertEquals(Utils.CREDENTIAL_PATTERN, mAuthContainer.mCredentialView.mCredentialType);
    }

    @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);
+51 −7
Original line number Diff line number Diff line
@@ -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:
+32 −4
Original line number Diff line number Diff line
@@ -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());
    }