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

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

Enforce a user limit

By default only 1 user is allowed. Some devices permit more than 1.
Set the real user limit in a device overlay for config.xml

Change-Id: I2e0bffa13393b954fcd20e55b92f20de980c58c0
parent 9f750af6
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));