diff options
-rw-r--r-- | service/src/com/android/car/user/CarUserService.java | 11 | ||||
-rw-r--r-- | tests/carservice_unit_test/src/com/android/car/user/CarUserServiceTest.java | 29 |
2 files changed, 38 insertions, 2 deletions
diff --git a/service/src/com/android/car/user/CarUserService.java b/service/src/com/android/car/user/CarUserService.java index 7c059aa700..6331ace477 100644 --- a/service/src/com/android/car/user/CarUserService.java +++ b/service/src/com/android/car/user/CarUserService.java @@ -2160,10 +2160,17 @@ public final class CarUserService extends ICarUserService.Stub implements CarSer } synchronized (mLockUser) { if (mUserIdForUserSwitchInProcess != USER_NULL) { + if (mUserIdForUserSwitchInProcess == toUserId) { + if (DBG) { + Slogf.d(TAG, "Ignoring, not legacy"); + } + return; + } if (DBG) { - Slogf.d(TAG, "Not needed, 'standard' switch"); + Slogf.d(TAG, "Resetting mUserIdForUserSwitchInProcess"); } - return; + mUserIdForUserSwitchInProcess = USER_NULL; + mRequestIdForUserSwitchInProcess = 0; } } diff --git a/tests/carservice_unit_test/src/com/android/car/user/CarUserServiceTest.java b/tests/carservice_unit_test/src/com/android/car/user/CarUserServiceTest.java index 87d8637a1c..9ec7a8c977 100644 --- a/tests/carservice_unit_test/src/com/android/car/user/CarUserServiceTest.java +++ b/tests/carservice_unit_test/src/com/android/car/user/CarUserServiceTest.java @@ -1123,6 +1123,35 @@ public final class CarUserServiceTest extends BaseCarUserServiceTestCase { } @Test + public void testSwitchUser_multipleCallsDifferentUser_beforeFirstUserUnlock_legacySwitch() + throws Exception { + mockExistingUsersAndCurrentUser(mAdminUser); + int requestId = 42; + mSwitchUserResponse.status = SwitchUserStatus.SUCCESS; + mSwitchUserResponse.requestId = requestId; + mockHalSwitch(mAdminUserId, mGuestUser, mSwitchUserResponse); + mockAmSwitchUser(mMockedActivityManager, mGuestUser, true); + + // First switch, using CarUserManager + switchUser(mGuestUserId, mAsyncCallTimeoutMs, mUserSwitchFuture); + + assertUserSwitchResult(getUserSwitchResult(mGuestUserId), + UserSwitchResult.STATUS_SUCCESSFUL); + // update current user due to successful user switch + mockCurrentUser(mGuestUser); + + assertHalSwitch(mAdminUserId, mGuestUserId); + // Unlock event was not sent, so it should not receive postSwitch + assertNoPostSwitch(); + + // Second switch, using legacy APIs + sendUserSwitchingEvent(mGuestUserId, mAdminUserId); + + verify(mUserHal).legacyUserSwitch( + isSwitchUserRequest(/* requestId= */ 0, mGuestUserId, mAdminUserId)); + } + + @Test public void testSwitchUser_multipleCallsDifferentUser_beforeHALResponded() throws Exception { mockExistingUsersAndCurrentUser(mAdminUser); |