Integrate removeUser impl with ephemeral API
Use the newly created @hide API UserManager#removeUserOrSetEphemeral to
allow removing the current user.
Bug: 155913815
Test: m android.car-test-stubs-docs-update-current-api android.car-stubs-docs-update-current-api android.car-system-stubs-docs-update-current-api
Test: atest CarUserServiceTest RemoveUserResultTest
Test: Manual testing with `adb shell cmd car_service remove-user <userId>`
Change-Id: I2307d8ed35702e57f9a7b2a424271eb02ee91e10
diff --git a/service/src/com/android/car/user/CarUserService.java b/service/src/com/android/car/user/CarUserService.java
index b49ad6b..e63870f 100644
--- a/service/src/com/android/car/user/CarUserService.java
+++ b/service/src/com/android/car/user/CarUserService.java
@@ -1128,12 +1128,6 @@
EventLog.writeEvent(EventLogTags.CAR_USER_SVC_REMOVE_USER_REQ, userId,
hasCallerRestrictions ? 1 : 0);
- // If the requested user is the current user, return error.
- if (ActivityManager.getCurrentUser() == userId) {
- return logAndGetResults(userId,
- UserRemovalResult.STATUS_TARGET_USER_IS_CURRENT_USER);
- }
-
// If requested user is the only admin user, return error.
UserInfo userInfo = mUserManager.getUserInfo(userId);
if (userInfo == null) {
@@ -1173,17 +1167,29 @@
// First remove user from android and then remove from HAL because HAL remove user is one
// way call.
- if (!mUserManager.removeUser(userId)) {
+ int result = mUserManager.removeUserOrSetEphemeral(userId);
+ if (result == UserManager.REMOVE_RESULT_ERROR) {
return logAndGetResults(userId, UserRemovalResult.STATUS_ANDROID_FAILURE);
}
if (isLastAdmin) {
- Log.w(TAG_USER, "Last admin user successfully removed. User Id: " + userId);
+ Log.w(TAG_USER,
+ "Last admin user successfully removed or set ephemeral. User Id: " + userId);
}
- return logAndGetResults(userId,
- isLastAdmin ? UserRemovalResult.STATUS_SUCCESSFUL_LAST_ADMIN_REMOVED
- : UserRemovalResult.STATUS_SUCCESSFUL);
+ switch (result) {
+ case UserManager.REMOVE_RESULT_REMOVED:
+ case UserManager.REMOVE_RESULT_ALREADY_BEING_REMOVED:
+ return logAndGetResults(userId,
+ isLastAdmin ? UserRemovalResult.STATUS_SUCCESSFUL_LAST_ADMIN_REMOVED
+ : UserRemovalResult.STATUS_SUCCESSFUL);
+ case UserManager.REMOVE_RESULT_SET_EPHEMERAL:
+ return logAndGetResults(userId,
+ isLastAdmin ? UserRemovalResult.STATUS_SUCCESSFUL_LAST_ADMIN_SET_EPHEMERAL
+ : UserRemovalResult.STATUS_SUCCESSFUL_SET_EPHEMERAL);
+ default:
+ throw new IllegalStateException("Unknown user removal result code " + result);
+ }
}
private void notifyHalUserRemoved(@UserIdInt int userId) {