diff options
author | Felipe Leme <felipeal@google.com> | 2022-03-14 10:33:45 -0700 |
---|---|---|
committer | Felipe Leme <felipeal@google.com> | 2022-03-15 13:18:59 -0700 |
commit | 6030f5f372d787ee9bd3e466f281d817abeaf87a (patch) | |
tree | 32c139ad815d737dca18d9f60fb8a1f932036c6b | |
parent | a30e7191d8c60c0c8513d03a06dbbdf74667b299 (diff) | |
download | Car-6030f5f372d787ee9bd3e466f281d817abeaf87a.tar.gz |
Fixes CarUserService.notifyLegacyUserSwitch()
It should only be ignored when the user-switching callback is called
for the user currently being switched to.
Test: atest com.android.car.user.CarUserServiceTest#testSwitchUser_multipleCallsDifferentUser_beforeFirstUserUnlock_legacySwitch
Test: atest CarUserServiceTest # to make sure it didn't break anything
Bug: 219458116
Change-Id: I1c0e53814ccbea7b138a25e76f6e0f60cb00554c
-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); |