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

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

Merge "Enforce a user limit" into jb-mr1-dev

parents 6fc7275d faea76ff
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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>
+15 −0
Original line number Diff line number Diff line
@@ -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));