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

Commit bd128a9e authored by Diya Bera's avatar Diya Bera
Browse files

Remove IPC calls from KeyguardUpdateMonitor

Test: atest KeyguardUpdateMonitorTest AuthControllerTest DozeSensorsTest LockIconViewControllerTest FaceServiceRegistryTest FingerprintServiceRegistryTest BiometricStateCallbackTest
Bug: 221037350
Change-Id: I76f6092f7dc1af45b3df12f86b2bf3ec4b00ff8f
parent 5a3bf4a7
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -2227,8 +2227,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
    private void updateFaceEnrolled(int userId) {
        mIsFaceEnrolled = whitelistIpcs(
                () -> mFaceManager != null && mFaceManager.isHardwareDetected()
                        && mFaceManager.hasEnrolledTemplates(userId)
                        && mBiometricEnabledForUser.get(userId));
                        && mBiometricEnabledForUser.get(userId))
                && mAuthController.isFaceAuthEnrolled(userId);
    }

    public boolean isFaceSupported() {
+12 −1
Original line number Diff line number Diff line
@@ -153,6 +153,7 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks,
    @Nullable private List<FingerprintSensorPropertiesInternal> mSidefpsProps;

    @NonNull private final SparseBooleanArray mUdfpsEnrolledForUser;
    @NonNull private final SparseBooleanArray mFaceEnrolledForUser;
    @NonNull private final SensorPrivacyManager mSensorPrivacyManager;
    private final WakefulnessLifecycle mWakefulnessLifecycle;
    private boolean mAllFingerprintAuthenticatorsRegistered;
@@ -349,6 +350,15 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks,
                }
            }
        }
        if (mFaceProps == null) {
            Log.d(TAG, "handleEnrollmentsChanged, mFaceProps is null");
        } else {
            for (FaceSensorPropertiesInternal prop : mFaceProps) {
                if (prop.sensorId == sensorId) {
                    mFaceEnrolledForUser.put(userId, hasEnrollments);
                }
            }
        }
        for (Callback cb : mCallbacks) {
            cb.onEnrollmentsChanged(modality);
        }
@@ -715,6 +725,7 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks,
        mWindowManager = windowManager;
        mInteractionJankMonitor = jankMonitor;
        mUdfpsEnrolledForUser = new SparseBooleanArray();
        mFaceEnrolledForUser = new SparseBooleanArray();
        mVibratorHelper = vibrator;

        mOrientationListener = new BiometricDisplayListener(
@@ -1067,7 +1078,7 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks,
            return false;
        }

        return mFaceManager.hasEnrolledTemplates(userId);
        return mFaceEnrolledForUser.get(userId);
    }

    /**
+2 −3
Original line number Diff line number Diff line
@@ -236,8 +236,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
        when(mActivityService.getCurrentUser()).thenReturn(mCurrentUserInfo);
        when(mActivityService.getCurrentUserId()).thenReturn(mCurrentUserId);
        when(mFaceManager.isHardwareDetected()).thenReturn(true);
        when(mFaceManager.hasEnrolledTemplates()).thenReturn(true);
        when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(true);
        when(mAuthController.isFaceAuthEnrolled(anyInt())).thenReturn(true);
        when(mFaceManager.getSensorPropertiesInternal()).thenReturn(mFaceSensorProperties);
        when(mSessionTracker.getSessionId(SESSION_KEYGUARD)).thenReturn(mKeyguardInstanceId);

@@ -592,7 +591,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {

        verify(mFaceManager).authenticate(any(), any(), any(), any(), anyInt(), anyBoolean());
        verify(mFaceManager).isHardwareDetected();
        verify(mFaceManager).hasEnrolledTemplates(anyInt());
        verify(mFaceManager, never()).hasEnrolledTemplates(anyInt());
    }

    @Test
+33 −5
Original line number Diff line number Diff line
@@ -25,7 +25,9 @@ import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_AWA
import static com.google.common.truth.Truth.assertThat;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -236,7 +238,7 @@ public class AuthControllerTest extends SysuiTestCase {
                        2 /* sensorId */,
                        SensorProperties.STRENGTH_STRONG,
                        1 /* maxEnrollmentsPerUser */,
                        fpComponentInfo,
                        faceComponentInfo,
                        FaceSensorProperties.TYPE_RGB,
                        true /* supportsFaceDetection */,
                        true /* supportsSelfIllumination */,
@@ -276,8 +278,6 @@ public class AuthControllerTest extends SysuiTestCase {
        reset(mFingerprintManager);
        reset(mFaceManager);

        when(mVibratorHelper.hasVibrator()).thenReturn(true);

        // This test requires an uninitialized AuthController.
        AuthController authController = new TestableAuthController(mContextSpy, mExecution,
                mCommandQueue, mActivityTaskManager, mWindowManager, mFingerprintManager,
@@ -308,8 +308,6 @@ public class AuthControllerTest extends SysuiTestCase {
        reset(mFingerprintManager);
        reset(mFaceManager);

        when(mVibratorHelper.hasVibrator()).thenReturn(true);

        // This test requires an uninitialized AuthController.
        AuthController authController = new TestableAuthController(mContextSpy, mExecution,
                mCommandQueue, mActivityTaskManager, mWindowManager, mFingerprintManager,
@@ -342,6 +340,36 @@ public class AuthControllerTest extends SysuiTestCase {
        // Nothing should crash.
    }

    @Test
    public void testFaceAuthEnrollmentStatus() throws RemoteException {
        final int userId = 0;

        reset(mFaceManager);
        mAuthController.start();

        verify(mFaceManager).addAuthenticatorsRegisteredCallback(
                mFaceAuthenticatorsRegisteredCaptor.capture());

        mFaceAuthenticatorsRegisteredCaptor.getValue().onAllAuthenticatorsRegistered(
                mFaceManager.getSensorPropertiesInternal());
        mTestableLooper.processAllMessages();

        verify(mFaceManager).registerBiometricStateListener(
                mBiometricStateCaptor.capture());

        assertFalse(mAuthController.isFaceAuthEnrolled(userId));

        // Enrollments changed for an unknown sensor.
        for (BiometricStateListener listener : mBiometricStateCaptor.getAllValues()) {
            listener.onEnrollmentsChanged(userId,
                    2 /* sensorId */, true /* hasEnrollments */);
        }
        mTestableLooper.processAllMessages();

        assertTrue(mAuthController.isFaceAuthEnrolled(userId));
    }


    @Test
    public void testSendsReasonUserCanceled_whenDismissedByUserCancel() throws Exception {
        showDialog(new int[]{1} /* sensorIds */, false /* credentialAllowed */);
+5 −4
Original line number Diff line number Diff line
@@ -600,8 +600,9 @@ public class FaceService extends SystemService {
                }
                try {
                    final SensorProps[] props = face.getSensorProps();
                    final FaceProvider provider = new FaceProvider(getContext(), props, instance,
                            mLockoutResetDispatcher, BiometricContext.getInstance(getContext()));
                    final FaceProvider provider = new FaceProvider(getContext(),
                            mBiometricStateCallback, props, instance, mLockoutResetDispatcher,
                            BiometricContext.getInstance(getContext()));
                    providers.add(provider);
                } catch (RemoteException e) {
                    Slog.e(TAG, "Remote exception in getSensorProps: " + fqName);
@@ -612,14 +613,14 @@ public class FaceService extends SystemService {
        }

        @android.annotation.EnforcePermission(android.Manifest.permission.USE_BIOMETRIC_INTERNAL)
        @Override // Binder call
        public void registerAuthenticators(
                @NonNull List<FaceSensorPropertiesInternal> hidlSensors) {
            mRegistry.registerAll(() -> {
                final List<ServiceProvider> providers = new ArrayList<>();
                for (FaceSensorPropertiesInternal hidlSensor : hidlSensors) {
                    providers.add(
                            Face10.newInstance(getContext(), hidlSensor, mLockoutResetDispatcher));
                            Face10.newInstance(getContext(), mBiometricStateCallback,
                                    hidlSensor, mLockoutResetDispatcher));
                }
                providers.addAll(getAidlProviders());
                return providers;
Loading