Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3fa61b67 authored by Amith Yamasani's avatar Amith Yamasani Committed by Android (Google) Code Review
Browse files

Merge "Allow adding a user while still removing other users"

parents fe4e1b65 f584f014
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -1253,7 +1253,10 @@ public class AppOpsService extends IAppOpsService.Stub {
    public void removeUser(int userHandle) throws RemoteException {
        checkSystemUid("removeUser");
        mOpRestrictions.remove(userHandle);
        mProfileOwnerUids.removeAt(mProfileOwnerUids.indexOfKey(userHandle));
        final int index = mProfileOwnerUids.indexOfKey(userHandle);
        if (index >= 0) {
            mProfileOwnerUids.removeAt(index);
        }
    }

    private void checkSystemUid(String function) {
+10 −2
Original line number Diff line number Diff line
@@ -511,8 +511,16 @@ public class UserManagerService extends IUserManager.Stub {
     * Check if we've hit the limit of how many users can be created.
     */
    private boolean isUserLimitReachedLocked() {
        int nUsers = mUsers.size();
        return nUsers >= UserManager.getMaxSupportedUsers();
        int aliveUserCount = 0;
        final int totalUserCount = mUsers.size();
        // Skip over users being removed
        for (int i = 0; i < totalUserCount; i++) {
            UserInfo user = mUsers.valueAt(i);
            if (!mRemovingUserIds.get(user.id)) {
                aliveUserCount++;
            }
        }
        return aliveUserCount >= UserManager.getMaxSupportedUsers();
    }

    /**