From f4339b8cb132a3b6635f4516eb7f65cf8e074fe7 Mon Sep 17 00:00:00 2001 From: Ying Zheng Date: Tue, 19 Jun 2018 16:01:05 -0700 Subject: 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 --- .../com/android/car/user/CarUserServiceTest.java | 46 +++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'tests/carservice_unit_test/src/com/android/car/user/CarUserServiceTest.java') 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 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); + } } -- cgit v1.2.3