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

Commit be8b98b9 authored by Nicolas Prévot's avatar Nicolas Prévot Committed by Android (Google) Code Review
Browse files

Merge "Allow non-owner users to have managed profiles."

parents 3014e63f b818681d
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -145,6 +145,17 @@ public class UserInfo implements Parcelable {
        return (!hideSystemUser || id != UserHandle.USER_SYSTEM) && supportsSwitchTo();
    }

    /* @hide */
    public boolean canHaveProfile() {
        if (isManagedProfile() || isGuest() || isRestricted()) {
            return false;
        }
        if (UserManager.isSplitSystemUser()) {
            return id != UserHandle.USER_SYSTEM;
        }
        return id == UserHandle.USER_OWNER;
    }

    public UserInfo() {
    }

+1 −1
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ interface IUserManager {
    UserInfo getPrimaryUser();
    List<UserInfo> getUsers(boolean excludeDying);
    List<UserInfo> getProfiles(int userHandle, boolean enabledOnly);
    boolean canAddMoreManagedProfiles();
    boolean canAddMoreManagedProfiles(int userId);
    UserInfo getProfileParent(int userHandle);
    UserInfo getUserInfo(int userHandle);
    long getUserCreationTime(int userHandle);
+2 −2
Original line number Diff line number Diff line
@@ -1024,9 +1024,9 @@ public class UserManager {
     * @return true if more managed profiles can be added, false if limit has been reached.
     * @hide
     */
    public boolean canAddMoreManagedProfiles() {
    public boolean canAddMoreManagedProfiles(int userId) {
        try {
            return mService.canAddMoreManagedProfiles();
            return mService.canAddMoreManagedProfiles(userId);
        } catch (RemoteException re) {
            Log.w(TAG, "Could not check if we can add more managed profiles", re);
            return false;
+11 −10
Original line number Diff line number Diff line
@@ -133,7 +133,7 @@ public class UserManagerService extends IUserManager.Stub {

    private static final long EPOCH_PLUS_30_YEARS = 30L * 365 * 24 * 60 * 60 * 1000L; // ms

    // Maximum number of managed profiles permitted is 1. This cannot be increased
    // Maximum number of managed profiles permitted per user is 1. This cannot be increased
    // without first making sure that the rest of the framework is prepared for it.
    private static final int MAX_MANAGED_PROFILES = 1;

@@ -627,7 +627,7 @@ public class UserManagerService extends IUserManager.Stub {
    }

    @Override
    public boolean canAddMoreManagedProfiles() {
    public boolean canAddMoreManagedProfiles(int userId) {
        checkManageUsersPermission("check if more managed profiles can be added.");
        if (ActivityManager.isLowRamDeviceStatic()) {
            return false;
@@ -636,10 +636,14 @@ public class UserManagerService extends IUserManager.Stub {
                PackageManager.FEATURE_MANAGED_USERS)) {
            return false;
        }
        synchronized(mPackagesLock) {
        // Limit number of managed profiles that can be created
            if (numberOfUsersOfTypeLocked(UserInfo.FLAG_MANAGED_PROFILE, true)
                    >= MAX_MANAGED_PROFILES) {
        int managedProfilesCount = getProfiles(userId, true).size() - 1;
        if (managedProfilesCount >= MAX_MANAGED_PROFILES) {
            return false;
        }
        synchronized(mPackagesLock) {
            UserInfo userInfo = getUserInfoLocked(userId);
            if (!userInfo.canHaveProfile()) {
                return false;
            }
            int usersCount = getAliveUsersExcludingGuestsCountLocked();
@@ -1238,10 +1242,6 @@ public class UserManagerService extends IUserManager.Stub {
    @Override
    public UserInfo createProfileForUser(String name, int flags, int userId) {
        checkManageUsersPermission("Only the system can create users");
        if (userId != UserHandle.USER_OWNER) {
            Slog.w(LOG_TAG, "Only user owner can have profiles");
            return null;
        }
        return createUserInternal(name, flags, userId);
    }

@@ -1273,7 +1273,8 @@ public class UserManagerService extends IUserManager.Stub {
                        parent = getUserInfoLocked(parentId);
                        if (parent == null) return null;
                    }
                    if (isManagedProfile && !canAddMoreManagedProfiles()) {
                    if (isManagedProfile && !canAddMoreManagedProfiles(parentId)) {
                        Log.e(LOG_TAG, "Cannot add more managed profiles for user " + parentId);
                        return null;
                    }
                    if (!isGuest && !isManagedProfile && isUserLimitReachedLocked()) {