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

Commit f584f014 authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Allow adding a user while still removing other users

When at the user limit, removing and adding a user causes a race
condition where the deleted user is still being removed and adding
another one fails.

This change excludes deleted users from the counting to compare
against the limit.

Also fix an ArrayIndexOutOfBounds recently introduced in AppOpsService.

Bug: 13282768
Change-Id: Ib79659e7604396583a280dbbc560b288a6d9051c
parent 0208462f
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();
    }

    /**