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

Commit 68afcdc2 authored by Matt Pietal's avatar Matt Pietal Committed by Android (Google) Code Review
Browse files

Merge "User switching on boot race condition - unit tests" into main

parents db45101c b6afcfeb
Loading
Loading
Loading
Loading
+35 −1
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -1316,6 +1317,33 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
        assertThat(mKeyguardUpdateMonitor.isTrustUsuallyManaged(user)).isFalse();
    }

    @Test
    public void testKeyguardMonitorStartsWhileUserIsSwitching() {
        int userId = UserHandle.myUserId();
        when(mUserTracker.getUserId()).thenReturn(userId);

        /* First test the default behavior: handleUserSwitching() is not invoked */
        when(mUserTracker.isUserSwitching()).thenReturn(false);
        boolean invokeStartable = true;
        mKeyguardUpdateMonitor = new TestableKeyguardUpdateMonitor(mContext, invokeStartable);
        mKeyguardUpdateMonitor.registerCallback(mTestCallback);
        mTestableLooper.processAllMessages();

        verify(mTestCallback, never()).onUserSwitching(userId);

        reset(mTestCallback);

        /* Next test user switching is already in progress when started */
        when(mUserTracker.isUserSwitching()).thenReturn(true);
        invokeStartable = false;
        mKeyguardUpdateMonitor = new TestableKeyguardUpdateMonitor(mContext, invokeStartable);
        mKeyguardUpdateMonitor.registerCallback(mTestCallback);
        mKeyguardUpdateMonitor.start();
        mTestableLooper.processAllMessages();

        verify(mTestCallback).onUserSwitching(userId);
    }

    @Test
    public void testSecondaryLockscreenRequirement() {
        when(mSelectedUserInteractor.getSelectedUserId()).thenReturn(UserHandle.myUserId());
@@ -2448,6 +2476,10 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
        AtomicInteger mCachedSimState = new AtomicInteger(-1);

        protected TestableKeyguardUpdateMonitor(Context context) {
            this(context, true);
        }

        protected TestableKeyguardUpdateMonitor(Context context, boolean invokeStart) {
            super(context, mUserTracker,
                    TestableLooper.get(KeyguardUpdateMonitorTest.this).getLooper(),
                    mBroadcastDispatcher, mDumpManager,
@@ -2468,8 +2500,10 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
            setAlternateBouncerVisibility(false);
            setPrimaryBouncerVisibility(false);
            setStrongAuthTracker(KeyguardUpdateMonitorTest.this.mStrongAuthTracker);
            if (invokeStart) {
                start();
            }
        }

        public boolean hasSimStateJustChanged() {
            return mSimStateChanged.getAndSet(false);
+22 −0
Original line number Diff line number Diff line
@@ -311,6 +311,28 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
        }
    }

    @Test
    @TestableLooper.RunWithLooper(setAsMainLooper = true)
    public void testHandleSystemReadyWhileUserIsSwitching() {
        int userId = 1099;
        when(mUserTracker.getUserId()).thenReturn(userId);

        /* First test the default behavior: handleUserSwitching() is not invoked */
        when(mUserTracker.isUserSwitching()).thenReturn(false);
        mViewMediator.mUpdateCallback = mock(KeyguardUpdateMonitorCallback.class);
        mViewMediator.onSystemReady();
        TestableLooper.get(this).processAllMessages();

        verify(mViewMediator.mUpdateCallback, never()).onUserSwitching(userId);

        /* Next test user switching is already in progress when started */
        when(mUserTracker.isUserSwitching()).thenReturn(true);
        mViewMediator.onSystemReady();
        TestableLooper.get(this).processAllMessages();

        verify(mViewMediator.mUpdateCallback).onUserSwitching(userId);
    }

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