am 8015f039: Merge "Enforce a user limit" into jb-mr1-dev

* commit '8015f039c744fb59c14920550705af958fc3c86d':
  Enforce a user limit
This commit is contained in:
Amith Yamasani
2012-09-11 11:11:23 -07:00
committed by Android Git Automerger
2 changed files with 16 additions and 1 deletions

View File

@@ -923,5 +923,5 @@
<bool name="config_syncstorageengine_masterSyncAutomatically">true</bool>
<!-- Maximum number of supported users -->
<integer name="config_multiuserMaximumUsers">10</integer>
<integer name="config_multiuserMaximumUsers">1</integer>
</resources>

View File

@@ -237,6 +237,18 @@ public class UserManagerService extends IUserManager.Stub {
// TODO:
}
/**
* Check if we've hit the limit of how many users can be created.
*/
private boolean isUserLimitReached() {
synchronized (mInstallLock) {
int nUsers = mUsers.size();
int userLimit = mContext.getResources().getInteger(
com.android.internal.R.integer.config_multiuserMaximumUsers);
return nUsers >= userLimit;
}
}
/**
* Enforces that only the system UID or root's UID or apps that have the
* {@link android.Manifest.permission.MANAGE_USERS MANAGE_USERS}
@@ -522,6 +534,9 @@ public class UserManagerService extends IUserManager.Stub {
@Override
public UserInfo createUser(String name, int flags) {
checkManageUsersPermission("Only the system can create users");
if (isUserLimitReached()) return null;
int userId = getNextAvailableId();
UserInfo userInfo = new UserInfo(userId, name, null, flags);
File userPath = new File(mBaseUserPath, Integer.toString(userId));