Merge "Fix UserController to not throw in stopUser"
This commit is contained in:
@@ -949,9 +949,8 @@ class UserController implements Handler.Callback {
|
||||
int stopUser(final int userId, final boolean force, boolean allowDelayedLocking,
|
||||
final IStopUserCallback stopUserCallback, KeyEvictedCallback keyEvictedCallback) {
|
||||
checkCallingPermission(INTERACT_ACROSS_USERS_FULL, "stopUser");
|
||||
if (userId < 0 || userId == UserHandle.USER_SYSTEM) {
|
||||
throw new IllegalArgumentException("Can't stop system user " + userId);
|
||||
}
|
||||
Preconditions.checkArgument(userId >= 0, "Invalid user id %d", userId);
|
||||
|
||||
enforceShellRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES, userId);
|
||||
synchronized (mLock) {
|
||||
return stopUsersLU(userId, force, allowDelayedLocking, stopUserCallback,
|
||||
|
||||
@@ -638,6 +638,39 @@ public class UserControllerTest {
|
||||
/* keyEvictedCallback= */ mKeyEvictedCallback, /* expectLocking= */ true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStopUser_invalidUser() {
|
||||
int userId = -1;
|
||||
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> mUserController.stopUser(userId, /* force= */ true,
|
||||
/* allowDelayedLocking= */ true, /* stopUserCallback= */ null,
|
||||
/* keyEvictedCallback= */ null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStopUser_systemUser() {
|
||||
int userId = UserHandle.USER_SYSTEM;
|
||||
|
||||
int r = mUserController.stopUser(userId, /* force= */ true,
|
||||
/* allowDelayedLocking= */ true, /* stopUserCallback= */ null,
|
||||
/* keyEvictedCallback= */ null);
|
||||
|
||||
assertThat(r).isEqualTo(ActivityManager.USER_OP_ERROR_IS_SYSTEM);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStopUser_currentUser() {
|
||||
setUpUser(TEST_USER_ID1, /* flags= */ 0);
|
||||
mUserController.startUser(TEST_USER_ID1, /* foreground= */ true);
|
||||
|
||||
int r = mUserController.stopUser(TEST_USER_ID1, /* force= */ true,
|
||||
/* allowDelayedLocking= */ true, /* stopUserCallback= */ null,
|
||||
/* keyEvictedCallback= */ null);
|
||||
|
||||
assertThat(r).isEqualTo(ActivityManager.USER_OP_IS_CURRENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test conditional delayed locking with mDelayUserDataLocking true.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user