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

Commit 1c1f58ca authored by Chandru's avatar Chandru
Browse files

Cleans up any stray instances of KeyguardUpdateMonitor that might still

have listeners attached to system services.

Test: atest KeyguardUpdateMonitorTest
Fixes: 246915415
Change-Id: I0d22116befbd4029e901e75db27bb6e083028118
parent d6c6f586
Loading
Loading
Loading
Loading
+18 −7
Original line number Diff line number Diff line
@@ -328,8 +328,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
    @After
    public void tearDown() {
        mMockitoSession.finishMocking();
        mKeyguardUpdateMonitor.removeCallback(mTestCallback);
        mKeyguardUpdateMonitor.destroy();
        cleanupKeyguardUpdateMonitor();
    }

    @Test
@@ -351,6 +350,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {

    @Test
    public void testSimStateInitialized() {
        cleanupKeyguardUpdateMonitor();
        final int subId = 3;
        final int state = TelephonyManager.SIM_STATE_ABSENT;

@@ -1205,7 +1205,9 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {

    @Test
    public void testShouldListenForFace_whenFaceManagerNotAvailable_returnsFalse() {
        mFaceManager = null;
        cleanupKeyguardUpdateMonitor();
        mSpiedContext.addMockSystemService(FaceManager.class, null);
        when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(false);
        mKeyguardUpdateMonitor = new TestableKeyguardUpdateMonitor(mSpiedContext);

        assertThat(mKeyguardUpdateMonitor.shouldListenForFace()).isFalse();
@@ -1258,6 +1260,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {

    @Test
    public void testShouldListenForFace_whenUserIsNotPrimary_returnsFalse() throws RemoteException {
        cleanupKeyguardUpdateMonitor();
        // This disables face auth
        when(mUserManager.isPrimaryUser()).thenReturn(false);
        mKeyguardUpdateMonitor =
@@ -1587,9 +1590,9 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {

    @Test
    public void testFingerAcquired_wakesUpPowerManager() {
        mContext.getOrCreateTestableResources().addOverride(
        cleanupKeyguardUpdateMonitor();
        mSpiedContext.getOrCreateTestableResources().addOverride(
                com.android.internal.R.bool.kg_wake_on_acquire_start, true);
        mSpiedContext = spy(mContext);
        mKeyguardUpdateMonitor = new TestableKeyguardUpdateMonitor(mSpiedContext);
        fingerprintAcquireStart();

@@ -1598,15 +1601,23 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {

    @Test
    public void testFingerAcquired_doesNotWakeUpPowerManager() {
        mContext.getOrCreateTestableResources().addOverride(
        cleanupKeyguardUpdateMonitor();
        mSpiedContext.getOrCreateTestableResources().addOverride(
                com.android.internal.R.bool.kg_wake_on_acquire_start, false);
        mSpiedContext = spy(mContext);
        mKeyguardUpdateMonitor = new TestableKeyguardUpdateMonitor(mSpiedContext);
        fingerprintAcquireStart();

        verify(mPowerManager, never()).wakeUp(anyLong(), anyInt(), anyString());
    }

    private void cleanupKeyguardUpdateMonitor() {
        if (mKeyguardUpdateMonitor != null) {
            mKeyguardUpdateMonitor.removeCallback(mTestCallback);
            mKeyguardUpdateMonitor.destroy();
            mKeyguardUpdateMonitor = null;
        }
    }

    private void faceAuthLockedOut() {
        mKeyguardUpdateMonitor.mFaceAuthenticationCallback
                .onAuthenticationError(FaceManager.FACE_ERROR_LOCKOUT_PERMANENT, "");