Loading core/tests/coretests/src/com/android/internal/app/IntentForwarderActivityTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -267,8 +267,8 @@ public class IntentForwarderActivityTest { Intent.ACTION_VIEW, Intent.CATEGORY_BROWSABLE); IntentForwarderWrapperActivity activity = mActivityRule.launchActivity(intent); ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); verify(mIPm, times(2)).canForwardTo( intentCaptor.capture(), nullable(String.class), anyInt(), anyInt()); List<Intent> capturedIntents = intentCaptor.getAllValues(); Loading packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java +42 −3 Original line number Diff line number Diff line Loading @@ -235,6 +235,7 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable, private static final int NOTIFY_STARTED_GOING_TO_SLEEP = 17; private static final int SYSTEM_READY = 18; private static final int CANCEL_KEYGUARD_EXIT_ANIM = 19; private static final int USER_SWITCH_COMPLETE = 23; private final List<LockNowCallback> mLockNowCallbacks = new ArrayList<>(); Loading Loading @@ -393,6 +394,8 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable, private boolean mDeviceInteractive; private boolean mGoingToSleep; private final Object mDismissToken = new Object(); // last known state of the cellular connection private String mPhoneState = TelephonyManager.EXTRA_STATE_IDLE; Loading Loading @@ -556,6 +559,35 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable, } }; @VisibleForTesting protected UserTracker.Callback mUserChangedCallback = new UserTracker.Callback() { @Override public void onUserChanged(int newUser, Context userContext) { mHandler.sendMessage(mHandler.obtainMessage(USER_SWITCH_COMPLETE, newUser, 0)); } }; /** * Handle {@link #USER_SWITCH_COMPLETE} */ @VisibleForTesting void handleUserSwitchComplete(int userId) { Log.d(TAG, String.format("onUserSwitchComplete %d", userId)); if (userId != KeyguardUpdateMonitor.getCurrentUser()) { Log.i(TAG, "Ignoring user switch complete, new user change"); return; } // Calling dismiss on a secure user will show the bouncer // We are calling dismiss with a delay as there are race conditions in some scenarios // caused by async layout listeners if (!mLockPatternUtils.isSecure(userId)) { mHandler.postDelayed(() -> dismiss(null /* callback */, null /* message */), mDismissToken, 500); } } KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() { @Override Loading Loading @@ -1361,6 +1393,7 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable, com.android.internal.R.anim.lock_screen_behind_enter); mWorkLockController = new WorkLockActivityController(mContext, mUserTracker); mUserTracker.addCallback(mUserChangedCallback, mContext.getMainExecutor()); } @Override Loading Loading @@ -1439,6 +1472,7 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable, // explicitly DO NOT want to call // mKeyguardViewControllerLazy.get().setKeyguardGoingAwayState(false) // here, since that will mess with the device lock state. mKeyguardStateController.notifyKeyguardGoingAway(false); mUpdateMonitor.dispatchKeyguardGoingAway(false); notifyStartedGoingToSleep(); Loading Loading @@ -2126,7 +2160,8 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable, * Send message to keyguard telling it to hide itself * @see #handleHide() */ private void hideLocked() { @VisibleForTesting void hideLocked() { Trace.beginSection("KeyguardViewMediator#hideLocked"); if (DEBUG) Log.d(TAG, "hideLocked"); Message msg = mHandler.obtainMessage(HIDE); Loading Loading @@ -2197,6 +2232,7 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable, if (newUserId != KeyguardUpdateMonitor.getCurrentUser()) { Log.d(TAG, String.format("setCurrentUser %d", newUserId)); KeyguardUpdateMonitor.setCurrentUser(newUserId); mHandler.removeCallbacksAndMessages(mDismissToken); mHandler.removeMessages(DISMISS); mHandler.removeMessages(HIDE); mHandler.removeMessages(START_KEYGUARD_EXIT_ANIM); Loading Loading @@ -2365,6 +2401,9 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable, case SYSTEM_READY: handleSystemReady(); break; case USER_SWITCH_COMPLETE: handleUserSwitchComplete(msg.arg1); break; } } }; Loading Loading @@ -3683,8 +3722,8 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable, if (mUserId != currentUserId) { Log.e(TAG, "Not executing OnHideAnimationFinished.run() due to userId mismatch. " + "Requested: " + mUserId + ", current: " + currentUserId); resetStateLocked(); mShadeController.get().instantCollapseShade(); resetStateLocked(); return; } Loading packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardTransitionRepository.kt +13 −20 Original line number Diff line number Diff line Loading @@ -228,34 +228,27 @@ class KeyguardTransitionRepositoryImpl @Inject constructor() : KeyguardTransitio } private fun emitTransition(nextStep: TransitionStep, isManual: Boolean = false) { trace(nextStep, isManual) val emitted = _transitions.tryEmit(nextStep) if (!emitted) { Log.w(TAG, "Failed to emit next value without suspending") } logAndTrace(nextStep, isManual) _transitions.tryEmit(nextStep) lastStep = nextStep } private fun trace(step: TransitionStep, isManual: Boolean) { private fun logAndTrace(step: TransitionStep, isManual: Boolean) { if (step.transitionState == TransitionState.RUNNING) { return } val traceName = "Transition: ${step.from} -> ${step.to} " + if (isManual) { "(manual)" } else { "" } val manualStr = if (isManual) " (manual)" else "" val traceName = "Transition: ${step.from} -> ${step.to}$manualStr" val traceCookie = traceName.hashCode() if (step.transitionState == TransitionState.STARTED) { Trace.beginAsyncSection(traceName, traceCookie) } else if ( step.transitionState == TransitionState.FINISHED || step.transitionState == TransitionState.CANCELED ) { Trace.endAsyncSection(traceName, traceCookie) when (step.transitionState) { TransitionState.STARTED -> Trace.beginAsyncSection(traceName, traceCookie) TransitionState.FINISHED -> Trace.endAsyncSection(traceName, traceCookie) TransitionState.CANCELED -> Trace.endAsyncSection(traceName, traceCookie) else -> {} } Log.i(TAG, "${step.transitionState.name} transition: $step$manualStr") } companion object { Loading packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java +24 −12 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; Loading Loading @@ -57,6 +58,7 @@ import com.android.internal.widget.LockPatternUtils; import com.android.keyguard.KeyguardDisplayManager; import com.android.keyguard.KeyguardSecurityView; import com.android.keyguard.KeyguardUpdateMonitor; import com.android.keyguard.KeyguardUpdateMonitorCallback; import com.android.keyguard.mediator.ScreenOnCoordinator; import com.android.systemui.DejankUtils; import com.android.systemui.SysuiTestCase; Loading Loading @@ -189,8 +191,7 @@ public class KeyguardViewMediatorTest extends SysuiTestCase { // Setup keyguard mViewMediator.onSystemReady(); TestableLooper.get(this).processAllMessages(); mUiBgExecutor.runAllReady(); processAllMessagesAndBgExecutorMessages(); mViewMediator.setShowingLocked(true); // Request keyguard going away Loading @@ -207,8 +208,7 @@ public class KeyguardViewMediatorTest extends SysuiTestCase { IRemoteAnimationFinishedCallback callback = mock(IRemoteAnimationFinishedCallback.class); mViewMediator.startKeyguardExitAnimation(TRANSIT_OLD_KEYGUARD_GOING_AWAY, apps, wallpapers, null, callback); TestableLooper.get(this).processAllMessages(); mUiBgExecutor.runAllReady(); processAllMessagesAndBgExecutorMessages(); // Followed by a request to dismiss the keyguard completely mViewMediator.mViewMediatorCallback.keyguardDonePending(true, insecureUserId); Loading @@ -218,8 +218,7 @@ public class KeyguardViewMediatorTest extends SysuiTestCase { int nextUserId = 500; setCurrentUser(nextUserId, /* isSecure= */true); TestableLooper.get(this).processAllMessages(); mUiBgExecutor.runAllReady(); processAllMessagesAndBgExecutorMessages(); // This simulates the race condition in DejankUtils.postAfterTraversal() mPostAfterTraversalRunnable.run(); Loading Loading @@ -426,6 +425,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(); Loading Loading @@ -477,12 +479,21 @@ public class KeyguardViewMediatorTest extends SysuiTestCase { assertTrue(mViewMediator.isAnimatingBetweenKeyguardAndSurfaceBehind()); } /** * 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); Loading @@ -495,9 +506,11 @@ public class KeyguardViewMediatorTest extends SysuiTestCase { IRemoteAnimationFinishedCallback callback = mock(IRemoteAnimationFinishedCallback.class); when(mKeyguardStateController.isKeyguardGoingAway()).thenReturn(true); mViewMediator.hideLocked(); processAllMessagesAndBgExecutorMessages(); mViewMediator.startKeyguardExitAnimation(TRANSIT_OLD_KEYGUARD_GOING_AWAY, apps, wallpapers, null, callback); TestableLooper.get(this).processAllMessages(); processAllMessagesAndBgExecutorMessages(); } /** Loading @@ -506,7 +519,7 @@ public class KeyguardViewMediatorTest extends SysuiTestCase { private void cancelMockKeyguardExitAnimation() { when(mKeyguardStateController.isKeyguardGoingAway()).thenReturn(false); mViewMediator.cancelKeyguardExitAnimation(); TestableLooper.get(this).processAllMessages(); processAllMessagesAndBgExecutorMessages(); } @Test Loading Loading @@ -635,7 +648,6 @@ public class KeyguardViewMediatorTest extends SysuiTestCase { onHideAnimationFinished.getValue().run(); // This is executed when the user is incorrect verify(mShadeController).instantCollapseShade(); } Loading Loading @@ -686,9 +698,9 @@ public class KeyguardViewMediatorTest extends SysuiTestCase { } private void setCurrentUser(int userId, boolean isSecure) { when(mUserTracker.getUserId()).thenReturn(userId); when(mLockPatternUtils.isSecure(userId)).thenReturn(isSecure); mViewMediator.setCurrentUser(userId); TestableLooper.get(this).processAllMessages(); mUiBgExecutor.runAllReady(); processAllMessagesAndBgExecutorMessages(); } } services/tests/servicestests/src/com/android/server/am/UserControllerTest.java +12 −12 Original line number Diff line number Diff line Loading @@ -450,25 +450,25 @@ public class UserControllerTest { setUpUser(TEST_USER_ID1, 0); setUpUser(TEST_USER_ID2, 0); int numerOfUserSwitches = 1; int numberOfUserSwitches = 1; addForegroundUserAndContinueUserSwitch(TEST_USER_ID, UserHandle.USER_SYSTEM, numerOfUserSwitches, false); numberOfUserSwitches, false); // running: user 0, USER_ID assertTrue(mUserController.canStartMoreUsers()); assertEquals(Arrays.asList(new Integer[] {0, TEST_USER_ID}), mUserController.getRunningUsersLU()); numerOfUserSwitches++; numberOfUserSwitches++; addForegroundUserAndContinueUserSwitch(TEST_USER_ID1, TEST_USER_ID, numerOfUserSwitches, false); numberOfUserSwitches, false); // running: user 0, USER_ID, USER_ID1 assertFalse(mUserController.canStartMoreUsers()); assertEquals(Arrays.asList(new Integer[] {0, TEST_USER_ID, TEST_USER_ID1}), mUserController.getRunningUsersLU()); numerOfUserSwitches++; numberOfUserSwitches++; addForegroundUserAndContinueUserSwitch(TEST_USER_ID2, TEST_USER_ID1, numerOfUserSwitches, false); numberOfUserSwitches, false); UserState ussUser2 = mUserStates.get(TEST_USER_ID2); // skip middle step and call this directly. mUserController.finishUserSwitch(ussUser2); Loading @@ -493,20 +493,20 @@ public class UserControllerTest { setUpUser(TEST_USER_ID1, 0); setUpUser(TEST_USER_ID2, 0); int numerOfUserSwitches = 1; int numberOfUserSwitches = 1; addForegroundUserAndContinueUserSwitch(TEST_USER_ID, UserHandle.USER_SYSTEM, numerOfUserSwitches, false); numberOfUserSwitches, false); // running: user 0, USER_ID assertTrue(mUserController.canStartMoreUsers()); assertEquals(Arrays.asList(new Integer[] {0, TEST_USER_ID}), mUserController.getRunningUsersLU()); numerOfUserSwitches++; numberOfUserSwitches++; addForegroundUserAndContinueUserSwitch(TEST_USER_ID1, TEST_USER_ID, numerOfUserSwitches, true); numberOfUserSwitches, true); // running: user 0, USER_ID1 // stopped + unlocked: USER_ID numerOfUserSwitches++; numberOfUserSwitches++; assertTrue(mUserController.canStartMoreUsers()); assertEquals(Arrays.asList(new Integer[] {0, TEST_USER_ID1}), mUserController.getRunningUsersLU()); Loading @@ -521,7 +521,7 @@ public class UserControllerTest { .lockUserKey(anyInt()); addForegroundUserAndContinueUserSwitch(TEST_USER_ID2, TEST_USER_ID1, numerOfUserSwitches, true); numberOfUserSwitches, true); // running: user 0, USER_ID2 // stopped + unlocked: USER_ID1 // stopped + locked: USER_ID Loading Loading
core/tests/coretests/src/com/android/internal/app/IntentForwarderActivityTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -267,8 +267,8 @@ public class IntentForwarderActivityTest { Intent.ACTION_VIEW, Intent.CATEGORY_BROWSABLE); IntentForwarderWrapperActivity activity = mActivityRule.launchActivity(intent); ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); verify(mIPm, times(2)).canForwardTo( intentCaptor.capture(), nullable(String.class), anyInt(), anyInt()); List<Intent> capturedIntents = intentCaptor.getAllValues(); Loading
packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java +42 −3 Original line number Diff line number Diff line Loading @@ -235,6 +235,7 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable, private static final int NOTIFY_STARTED_GOING_TO_SLEEP = 17; private static final int SYSTEM_READY = 18; private static final int CANCEL_KEYGUARD_EXIT_ANIM = 19; private static final int USER_SWITCH_COMPLETE = 23; private final List<LockNowCallback> mLockNowCallbacks = new ArrayList<>(); Loading Loading @@ -393,6 +394,8 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable, private boolean mDeviceInteractive; private boolean mGoingToSleep; private final Object mDismissToken = new Object(); // last known state of the cellular connection private String mPhoneState = TelephonyManager.EXTRA_STATE_IDLE; Loading Loading @@ -556,6 +559,35 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable, } }; @VisibleForTesting protected UserTracker.Callback mUserChangedCallback = new UserTracker.Callback() { @Override public void onUserChanged(int newUser, Context userContext) { mHandler.sendMessage(mHandler.obtainMessage(USER_SWITCH_COMPLETE, newUser, 0)); } }; /** * Handle {@link #USER_SWITCH_COMPLETE} */ @VisibleForTesting void handleUserSwitchComplete(int userId) { Log.d(TAG, String.format("onUserSwitchComplete %d", userId)); if (userId != KeyguardUpdateMonitor.getCurrentUser()) { Log.i(TAG, "Ignoring user switch complete, new user change"); return; } // Calling dismiss on a secure user will show the bouncer // We are calling dismiss with a delay as there are race conditions in some scenarios // caused by async layout listeners if (!mLockPatternUtils.isSecure(userId)) { mHandler.postDelayed(() -> dismiss(null /* callback */, null /* message */), mDismissToken, 500); } } KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() { @Override Loading Loading @@ -1361,6 +1393,7 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable, com.android.internal.R.anim.lock_screen_behind_enter); mWorkLockController = new WorkLockActivityController(mContext, mUserTracker); mUserTracker.addCallback(mUserChangedCallback, mContext.getMainExecutor()); } @Override Loading Loading @@ -1439,6 +1472,7 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable, // explicitly DO NOT want to call // mKeyguardViewControllerLazy.get().setKeyguardGoingAwayState(false) // here, since that will mess with the device lock state. mKeyguardStateController.notifyKeyguardGoingAway(false); mUpdateMonitor.dispatchKeyguardGoingAway(false); notifyStartedGoingToSleep(); Loading Loading @@ -2126,7 +2160,8 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable, * Send message to keyguard telling it to hide itself * @see #handleHide() */ private void hideLocked() { @VisibleForTesting void hideLocked() { Trace.beginSection("KeyguardViewMediator#hideLocked"); if (DEBUG) Log.d(TAG, "hideLocked"); Message msg = mHandler.obtainMessage(HIDE); Loading Loading @@ -2197,6 +2232,7 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable, if (newUserId != KeyguardUpdateMonitor.getCurrentUser()) { Log.d(TAG, String.format("setCurrentUser %d", newUserId)); KeyguardUpdateMonitor.setCurrentUser(newUserId); mHandler.removeCallbacksAndMessages(mDismissToken); mHandler.removeMessages(DISMISS); mHandler.removeMessages(HIDE); mHandler.removeMessages(START_KEYGUARD_EXIT_ANIM); Loading Loading @@ -2365,6 +2401,9 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable, case SYSTEM_READY: handleSystemReady(); break; case USER_SWITCH_COMPLETE: handleUserSwitchComplete(msg.arg1); break; } } }; Loading Loading @@ -3683,8 +3722,8 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable, if (mUserId != currentUserId) { Log.e(TAG, "Not executing OnHideAnimationFinished.run() due to userId mismatch. " + "Requested: " + mUserId + ", current: " + currentUserId); resetStateLocked(); mShadeController.get().instantCollapseShade(); resetStateLocked(); return; } Loading
packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardTransitionRepository.kt +13 −20 Original line number Diff line number Diff line Loading @@ -228,34 +228,27 @@ class KeyguardTransitionRepositoryImpl @Inject constructor() : KeyguardTransitio } private fun emitTransition(nextStep: TransitionStep, isManual: Boolean = false) { trace(nextStep, isManual) val emitted = _transitions.tryEmit(nextStep) if (!emitted) { Log.w(TAG, "Failed to emit next value without suspending") } logAndTrace(nextStep, isManual) _transitions.tryEmit(nextStep) lastStep = nextStep } private fun trace(step: TransitionStep, isManual: Boolean) { private fun logAndTrace(step: TransitionStep, isManual: Boolean) { if (step.transitionState == TransitionState.RUNNING) { return } val traceName = "Transition: ${step.from} -> ${step.to} " + if (isManual) { "(manual)" } else { "" } val manualStr = if (isManual) " (manual)" else "" val traceName = "Transition: ${step.from} -> ${step.to}$manualStr" val traceCookie = traceName.hashCode() if (step.transitionState == TransitionState.STARTED) { Trace.beginAsyncSection(traceName, traceCookie) } else if ( step.transitionState == TransitionState.FINISHED || step.transitionState == TransitionState.CANCELED ) { Trace.endAsyncSection(traceName, traceCookie) when (step.transitionState) { TransitionState.STARTED -> Trace.beginAsyncSection(traceName, traceCookie) TransitionState.FINISHED -> Trace.endAsyncSection(traceName, traceCookie) TransitionState.CANCELED -> Trace.endAsyncSection(traceName, traceCookie) else -> {} } Log.i(TAG, "${step.transitionState.name} transition: $step$manualStr") } companion object { Loading
packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java +24 −12 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; Loading Loading @@ -57,6 +58,7 @@ import com.android.internal.widget.LockPatternUtils; import com.android.keyguard.KeyguardDisplayManager; import com.android.keyguard.KeyguardSecurityView; import com.android.keyguard.KeyguardUpdateMonitor; import com.android.keyguard.KeyguardUpdateMonitorCallback; import com.android.keyguard.mediator.ScreenOnCoordinator; import com.android.systemui.DejankUtils; import com.android.systemui.SysuiTestCase; Loading Loading @@ -189,8 +191,7 @@ public class KeyguardViewMediatorTest extends SysuiTestCase { // Setup keyguard mViewMediator.onSystemReady(); TestableLooper.get(this).processAllMessages(); mUiBgExecutor.runAllReady(); processAllMessagesAndBgExecutorMessages(); mViewMediator.setShowingLocked(true); // Request keyguard going away Loading @@ -207,8 +208,7 @@ public class KeyguardViewMediatorTest extends SysuiTestCase { IRemoteAnimationFinishedCallback callback = mock(IRemoteAnimationFinishedCallback.class); mViewMediator.startKeyguardExitAnimation(TRANSIT_OLD_KEYGUARD_GOING_AWAY, apps, wallpapers, null, callback); TestableLooper.get(this).processAllMessages(); mUiBgExecutor.runAllReady(); processAllMessagesAndBgExecutorMessages(); // Followed by a request to dismiss the keyguard completely mViewMediator.mViewMediatorCallback.keyguardDonePending(true, insecureUserId); Loading @@ -218,8 +218,7 @@ public class KeyguardViewMediatorTest extends SysuiTestCase { int nextUserId = 500; setCurrentUser(nextUserId, /* isSecure= */true); TestableLooper.get(this).processAllMessages(); mUiBgExecutor.runAllReady(); processAllMessagesAndBgExecutorMessages(); // This simulates the race condition in DejankUtils.postAfterTraversal() mPostAfterTraversalRunnable.run(); Loading Loading @@ -426,6 +425,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(); Loading Loading @@ -477,12 +479,21 @@ public class KeyguardViewMediatorTest extends SysuiTestCase { assertTrue(mViewMediator.isAnimatingBetweenKeyguardAndSurfaceBehind()); } /** * 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); Loading @@ -495,9 +506,11 @@ public class KeyguardViewMediatorTest extends SysuiTestCase { IRemoteAnimationFinishedCallback callback = mock(IRemoteAnimationFinishedCallback.class); when(mKeyguardStateController.isKeyguardGoingAway()).thenReturn(true); mViewMediator.hideLocked(); processAllMessagesAndBgExecutorMessages(); mViewMediator.startKeyguardExitAnimation(TRANSIT_OLD_KEYGUARD_GOING_AWAY, apps, wallpapers, null, callback); TestableLooper.get(this).processAllMessages(); processAllMessagesAndBgExecutorMessages(); } /** Loading @@ -506,7 +519,7 @@ public class KeyguardViewMediatorTest extends SysuiTestCase { private void cancelMockKeyguardExitAnimation() { when(mKeyguardStateController.isKeyguardGoingAway()).thenReturn(false); mViewMediator.cancelKeyguardExitAnimation(); TestableLooper.get(this).processAllMessages(); processAllMessagesAndBgExecutorMessages(); } @Test Loading Loading @@ -635,7 +648,6 @@ public class KeyguardViewMediatorTest extends SysuiTestCase { onHideAnimationFinished.getValue().run(); // This is executed when the user is incorrect verify(mShadeController).instantCollapseShade(); } Loading Loading @@ -686,9 +698,9 @@ public class KeyguardViewMediatorTest extends SysuiTestCase { } private void setCurrentUser(int userId, boolean isSecure) { when(mUserTracker.getUserId()).thenReturn(userId); when(mLockPatternUtils.isSecure(userId)).thenReturn(isSecure); mViewMediator.setCurrentUser(userId); TestableLooper.get(this).processAllMessages(); mUiBgExecutor.runAllReady(); processAllMessagesAndBgExecutorMessages(); } }
services/tests/servicestests/src/com/android/server/am/UserControllerTest.java +12 −12 Original line number Diff line number Diff line Loading @@ -450,25 +450,25 @@ public class UserControllerTest { setUpUser(TEST_USER_ID1, 0); setUpUser(TEST_USER_ID2, 0); int numerOfUserSwitches = 1; int numberOfUserSwitches = 1; addForegroundUserAndContinueUserSwitch(TEST_USER_ID, UserHandle.USER_SYSTEM, numerOfUserSwitches, false); numberOfUserSwitches, false); // running: user 0, USER_ID assertTrue(mUserController.canStartMoreUsers()); assertEquals(Arrays.asList(new Integer[] {0, TEST_USER_ID}), mUserController.getRunningUsersLU()); numerOfUserSwitches++; numberOfUserSwitches++; addForegroundUserAndContinueUserSwitch(TEST_USER_ID1, TEST_USER_ID, numerOfUserSwitches, false); numberOfUserSwitches, false); // running: user 0, USER_ID, USER_ID1 assertFalse(mUserController.canStartMoreUsers()); assertEquals(Arrays.asList(new Integer[] {0, TEST_USER_ID, TEST_USER_ID1}), mUserController.getRunningUsersLU()); numerOfUserSwitches++; numberOfUserSwitches++; addForegroundUserAndContinueUserSwitch(TEST_USER_ID2, TEST_USER_ID1, numerOfUserSwitches, false); numberOfUserSwitches, false); UserState ussUser2 = mUserStates.get(TEST_USER_ID2); // skip middle step and call this directly. mUserController.finishUserSwitch(ussUser2); Loading @@ -493,20 +493,20 @@ public class UserControllerTest { setUpUser(TEST_USER_ID1, 0); setUpUser(TEST_USER_ID2, 0); int numerOfUserSwitches = 1; int numberOfUserSwitches = 1; addForegroundUserAndContinueUserSwitch(TEST_USER_ID, UserHandle.USER_SYSTEM, numerOfUserSwitches, false); numberOfUserSwitches, false); // running: user 0, USER_ID assertTrue(mUserController.canStartMoreUsers()); assertEquals(Arrays.asList(new Integer[] {0, TEST_USER_ID}), mUserController.getRunningUsersLU()); numerOfUserSwitches++; numberOfUserSwitches++; addForegroundUserAndContinueUserSwitch(TEST_USER_ID1, TEST_USER_ID, numerOfUserSwitches, true); numberOfUserSwitches, true); // running: user 0, USER_ID1 // stopped + unlocked: USER_ID numerOfUserSwitches++; numberOfUserSwitches++; assertTrue(mUserController.canStartMoreUsers()); assertEquals(Arrays.asList(new Integer[] {0, TEST_USER_ID1}), mUserController.getRunningUsersLU()); Loading @@ -521,7 +521,7 @@ public class UserControllerTest { .lockUserKey(anyInt()); addForegroundUserAndContinueUserSwitch(TEST_USER_ID2, TEST_USER_ID1, numerOfUserSwitches, true); numberOfUserSwitches, true); // running: user 0, USER_ID2 // stopped + unlocked: USER_ID1 // stopped + locked: USER_ID Loading