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

This commit is contained in:
Amith Yamasani
2014-05-20 01:02:58 +00:00
committed by Android (Google) Code Review
2 changed files with 14 additions and 3 deletions

View File

@@ -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) {

View File

@@ -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();
}
/**