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

Commit 2efdc51b authored by Matt Pietal's avatar Matt Pietal
Browse files

Update user switching processes

Add a new callback for UserController. If the user is secure, initiate
a call to SystemUI to lockNow(), and wait for the callback. If the
callback does not arrive, crash the system after some time.

During user switching, ensure that systemui locks the device immediately
if necessary and cancels any prior attempt to dismiss.

Also, ensure that any switch is user that occurs after WM has been
notified that SystemUI is going away is stopped.

Bug: 322157041
Test: atest KeyguardViewMediatorTest
Flag: EXEMPT bugfix
Merged-In: I32699e32fe1dbe94af2abe7e7ade5363a2b6cb55
Change-Id: I02df941d89467fc678c0749f4a2436ad8fee8b7b
parent 4ad9b1ed
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -201,6 +201,15 @@ public class KeyguardManager {
     */
    public static final String EXTRA_DISALLOW_BIOMETRICS_IF_POLICY_EXISTS = "check_dpm";

    /**
     * When switching to a secure user, system server will expect a callback when the UI has
     * completed the switch.
     *
     * @hide
     */
    public static final String LOCK_ON_USER_SWITCH_CALLBACK = "onSwitchCallback";


    /**
     *
     * Password lock type, see {@link #setLock}
+194 −36

File changed.

Preview size limit exceeded, changes collapsed.

+77 −4
Original line number Diff line number Diff line
@@ -238,6 +238,60 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
        KeyguardUpdateMonitor.setCurrentUser(mInitialUserId);
    }

    @Test
    @TestableLooper.RunWithLooper(setAsMainLooper = true)
    public void testGoingAwayFollowedByUserSwitchDoesNotHideKeyguard() {
        setCurrentUser(/* userId= */1099, /* isSecure= */false);

        // Setup keyguard
        mViewMediator.onSystemReady();
        processAllMessagesAndBgExecutorMessages();
        mViewMediator.setShowingLocked(true);

        // Request keyguard going away
        when(mKeyguardStateController.isKeyguardGoingAway()).thenReturn(true);
        mViewMediator.mKeyguardGoingAwayRunnable.run();

        // After the request, begin a switch to a new secure user
        int nextUserId = 500;
        setCurrentUser(nextUserId, /* isSecure= */true);

        // After that request has begun, have WM tell us to exit keyguard
        RemoteAnimationTarget[] apps = new RemoteAnimationTarget[]{
                mock(RemoteAnimationTarget.class)
        };
        RemoteAnimationTarget[] wallpapers = new RemoteAnimationTarget[]{
                mock(RemoteAnimationTarget.class)
        };
        IRemoteAnimationFinishedCallback callback = mock(IRemoteAnimationFinishedCallback.class);
        mViewMediator.startKeyguardExitAnimation(TRANSIT_OLD_KEYGUARD_GOING_AWAY, apps, wallpapers,
                null, callback);
        processAllMessagesAndBgExecutorMessages();

        // The call to exit should be rejected, and keyguard should still be visible
        verify(mKeyguardUnlockAnimationController, never()).notifyStartSurfaceBehindRemoteAnimation(
                any(), any(), anyLong(), anyBoolean());
        assertTrue(mViewMediator.isShowingAndNotOccluded());
    }

    @Test
    @TestableLooper.RunWithLooper(setAsMainLooper = true)
    public void testUserSwitchToSecureUserWhileKeyguardNotVisibleShowsKeyguard() {
        setCurrentUser(/* userId= */1099, /* isSecure= */true);

        // Setup keyguard as not visible
        mViewMediator.onSystemReady();
        processAllMessagesAndBgExecutorMessages();
        mViewMediator.setShowingLocked(false);
        processAllMessagesAndBgExecutorMessages();

        // Begin a switch to a new secure user
        int nextUserId = 500;
        setCurrentUser(nextUserId, /* isSecure= */true);

        assertTrue(mViewMediator.isShowingAndNotOccluded());
    }

    @Test
    @TestableLooper.RunWithLooper(setAsMainLooper = true)
    public void onLockdown_showKeyguard_evenIfKeyguardIsNotEnabledExternally() {
@@ -630,6 +684,9 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
    @Test
    @TestableLooper.RunWithLooper(setAsMainLooper = true)
    public void testCancelKeyguardExitAnimation_noPendingLock_keyguardWillNotBeShowing() {
        when(mPowerManager.isInteractive()).thenReturn(true);

        setCurrentUser(0, false);
        startMockKeyguardExitAnimation();
        cancelMockKeyguardExitAnimation();

@@ -638,7 +695,6 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
        TestableLooper.get(this).processAllMessages();

        assertFalse(mViewMediator.isShowingAndNotOccluded());
        verify(mKeyguardUnlockAnimationController).notifyFinishedKeyguardExitAnimation(false);
    }

    @Test
@@ -692,12 +748,21 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
        verify(mKeyguardUnlockAnimationController).notifyFinishedKeyguardExitAnimation(false);
    }

    /**
     * Interactions with the ActivityTaskManagerService and others are posted to an executor that
     * doesn't use the testable looper. Use this method to ensure those are run as well.
     */
    private void processAllMessagesAndBgExecutorMessages() {
        TestableLooper.get(this).processAllMessages();
        mUiBgExecutor.runAllReady();
    }

    /**
     * Configures mocks appropriately, then starts the keyguard exit animation.
     */
    private void startMockKeyguardExitAnimation() {
        mViewMediator.onSystemReady();
        TestableLooper.get(this).processAllMessages();
        processAllMessagesAndBgExecutorMessages();

        mViewMediator.setShowingLocked(true);

@@ -710,9 +775,10 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
        IRemoteAnimationFinishedCallback callback = mock(IRemoteAnimationFinishedCallback.class);

        when(mKeyguardStateController.isKeyguardGoingAway()).thenReturn(true);
        mViewMediator.mKeyguardGoingAwayRunnable.run();
        mViewMediator.startKeyguardExitAnimation(TRANSIT_OLD_KEYGUARD_GOING_AWAY, apps, wallpapers,
                null, callback);
        TestableLooper.get(this).processAllMessages();
        processAllMessagesAndBgExecutorMessages();
    }

    /**
@@ -721,7 +787,7 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
    private void cancelMockKeyguardExitAnimation() {
        when(mKeyguardStateController.isKeyguardGoingAway()).thenReturn(false);
        mViewMediator.cancelKeyguardExitAnimation();
        TestableLooper.get(this).processAllMessages();
        processAllMessagesAndBgExecutorMessages();
    }

    @Test
@@ -1027,4 +1093,11 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
    private void captureKeyguardUpdateMonitorCallback() {
        verify(mUpdateMonitor).registerCallback(mKeyguardUpdateMonitorCallbackCaptor.capture());
    }

    private void setCurrentUser(int userId, boolean isSecure) {
        when(mUserTracker.getUserId()).thenReturn(userId);
        when(mLockPatternUtils.isSecure(userId)).thenReturn(isSecure);
        mViewMediator.setCurrentUser(userId);
        processAllMessagesAndBgExecutorMessages();
    }
}
+20 −89

File changed.

Preview size limit exceeded, changes collapsed.

+6 −40

File changed.

Preview size limit exceeded, changes collapsed.