diff options
author | Ying Zheng <yizheng@google.com> | 2018-06-19 16:01:05 -0700 |
---|---|---|
committer | Ying Zheng <yizheng@google.com> | 2018-06-20 16:42:07 -0700 |
commit | f4339b8cb132a3b6635f4516eb7f65cf8e074fe7 (patch) | |
tree | a0b8c826ec1b60d6a2cc0ff791e71dc9f78f7258 /tests/carservice_unit_test/src/com/android/car/user/CarUserServiceTest.java | |
parent | d812d4c1ac4590e98d41c01fab14f654ea0b3657 (diff) | |
download | Car-f4339b8cb132a3b6635f4516eb7f65cf8e074fe7.tar.gz |
Complete the logic around last active user, including:
- Update CarSettings last active user when user switched.
- Boot into the last active user if valid, or boot into the smallest
user id.
- Not allow deleting the last admin user, so we have a user 10+ to boot
into.
Test: Unit test
Bug: 110156344,110425490,110425354
Change-Id: I3e85805bf469bd17709973936e8c3285c8f44207
Diffstat (limited to 'tests/carservice_unit_test/src/com/android/car/user/CarUserServiceTest.java')
-rw-r--r-- | tests/carservice_unit_test/src/com/android/car/user/CarUserServiceTest.java | 46 |
1 files changed, 45 insertions, 1 deletions
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 20cb060f28..a6b48bf8f1 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 @@ -84,9 +84,10 @@ public class CarUserServiceTest { mCarUserService.init(); verify(mMockContext).registerReceiver(eq(mCarUserService), argument.capture()); IntentFilter intentFilter = argument.getValue(); - assertThat(intentFilter.countActions()).isEqualTo(1); + assertThat(intentFilter.countActions()).isEqualTo(2); assertThat(intentFilter.getAction(0)).isEqualTo(Intent.ACTION_LOCKED_BOOT_COMPLETED); + assertThat(intentFilter.getAction(1)).isEqualTo(Intent.ACTION_USER_SWITCHED); } /** @@ -139,4 +140,47 @@ public class CarUserServiceTest { verify(mCarUserManagerHelper). setUserRestriction(user0, UserManager.DISALLOW_MODIFY_ACCOUNTS, true); } + + /** + * Test that the {@link CarUserService} starts up the last active user on reboot. + */ + @Test + public void testStartsLastActiveUserOnReboot() { + List<UserInfo> users = new ArrayList<>(); + + int adminUserId = 10; + UserInfo admin = new UserInfo(adminUserId, CarUserService.OWNER_NAME, UserInfo.FLAG_ADMIN); + + int secUserId = 11; + UserInfo secUser = + new UserInfo(secUserId, CarUserService.OWNER_NAME, UserInfo.FLAG_ADMIN); + + users.add(admin); + users.add(secUser); + + doReturn(users).when(mCarUserManagerHelper).getAllUsers(); + doReturn(secUserId).when(mCarUserManagerHelper).getLastActiveUser(); + + mCarUserService.onReceive(mMockContext, + new Intent(Intent.ACTION_LOCKED_BOOT_COMPLETED)); + + verify(mCarUserManagerHelper).switchToUserId(secUserId); + } + + /** + * Test that the {@link CarUserService} updates last active user on user switch intent. + */ + @Test + public void testLastActiveUserUpdatedOnUserSwitch() { + int lastActiveUserId = 11; + + doReturn(false).when(mCarUserManagerHelper).isForegroundUserGuest(); + doReturn(lastActiveUserId).when(mCarUserManagerHelper).getCurrentForegroundUserId(); + + mCarUserService.onReceive(mMockContext, + new Intent(Intent.ACTION_USER_SWITCHED)); + + verify(mCarUserManagerHelper).setLastActiveUser( + lastActiveUserId, /* skipGlobalSetting= */ false); + } } |