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

Commit 41cdc47b authored by Beverly's avatar Beverly
Browse files

Only showKeyguard on strongAuthChanges for currUser

If strongAuth changes to a different user, we don't
want to show the keyguard based on the current
user's lockout state because this can cause
showing the keyguard multiple times.

For example, let's say there's user 0 and user 10.
Before this change, we could get into a situation where:
1. Both user 0 and user 10 are locked out.
2. Pin/pattern/password is entered successfully which
updates the strongAuth (lockout state) of both users 0 and 10.
3. SysUI receives a signal that user 10's strong auth
has been updated first; user 0's lockout state has not been
updated yet and is the current user, so this triggers
showing the keyguard (UNEXPECTED).
4. SysUI then receives a signal that user 0's strong auth
has been updated.

This CL avoids the situation at step #3 where we're showing
the keyguard before SysUI has the opportunity to receive
the update that user 0's lockout state is no longer locked out.

Test: atest KeyguardViewMediatorTest
Fixes: 331182254
Flag: EXEMPT bugfix
Change-Id: I46e0d969c64c50d8926ef38bf92811e0e79f30a5
parent 6129796b
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -870,6 +870,10 @@ public class KeyguardViewMediator implements CoreStartable,

        @Override
        public void onStrongAuthStateChanged(int userId) {
            // Do not react to strong auth changes of users that aren't the current user
            if (userId != mSelectedUserInteractor.getSelectedUserId()) {
                return;
            }
            if (mLockPatternUtils.isUserInLockdown(mSelectedUserInteractor.getSelectedUserId())) {
                doKeyguardLocked(null);
            }
+32 −1
Original line number Diff line number Diff line
@@ -490,7 +490,8 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
        captureKeyguardUpdateMonitorCallback();
        assertFalse(mViewMediator.isShowingAndNotOccluded());

        // WHEN lockdown occurs
        // WHEN lockdown occurs for current user
        when(mSelectedUserInteractor.getSelectedUserId()).thenReturn(0);
        when(mLockPatternUtils.isUserInLockdown(anyInt())).thenReturn(true);
        mKeyguardUpdateMonitorCallbackCaptor.getValue().onStrongAuthStateChanged(0);

@@ -499,6 +500,36 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
        assertTrue(mViewMediator.isShowingAndNotOccluded());
    }

    @Test
    @TestableLooper.RunWithLooper(setAsMainLooper = true)
    public void onLockdown_onlyShowKeyguardIfMainUserHadStrongAuthChanged() {
        // GIVEN main user is in lockdown
        mViewMediator.onSystemReady();
        mViewMediator.setKeyguardEnabled(false);
        TestableLooper.get(this).processAllMessages();
        captureKeyguardUpdateMonitorCallback();
        assertFalse(mViewMediator.isShowingAndNotOccluded());

        int currentUserId = 0;
        int otherUserId = 10;
        when(mSelectedUserInteractor.getSelectedUserId()).thenReturn(currentUserId);
        when(mLockPatternUtils.isUserInLockdown(currentUserId)).thenReturn(true);

        // WHEN a different user's strong auth changes
        mKeyguardUpdateMonitorCallbackCaptor.getValue().onStrongAuthStateChanged(otherUserId);

        // THEN keyguard is not shown
        TestableLooper.get(this).processAllMessages();
        assertFalse(mViewMediator.isShowingAndNotOccluded());

        // when the current user's strong auth changes
        mKeyguardUpdateMonitorCallbackCaptor.getValue().onStrongAuthStateChanged(currentUserId);

        // THEN keyguard is shown
        TestableLooper.get(this).processAllMessages();
        assertTrue(mViewMediator.isShowingAndNotOccluded());
    }

    @Test
    @TestableLooper.RunWithLooper(setAsMainLooper = true)
    public void showKeyguardAfterKeyguardNotEnabled() {