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

Commit a7b56b2c authored by Adam Bookatz's avatar Adam Bookatz
Browse files

Restricted Users for MainUser

Previously, the parent of a restricted user had to be the system user
(in the creation method). On HSUM, we want this to be the main user. The
canHaveRestrictedProfile() method already took this into account, but
not the actual creation method. We fix this here.

Test: on a device without feature android.hardware.telephony, do the following:
make GtsGmsCoreMultiUserTestApp  &&    atest GtsGmscoreHostTestCases:com.google.android.gts.multiuser.RestrictedProfileHostTest
Bug: 414839808
Flag: EXEMPT bugfix
Change-Id: Id69ead7224ee901a18a5153f7627a7cd0b3f45ce
parent b21088ef
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -3108,6 +3108,13 @@ public class UserManagerService extends IUserManager.Stub {
    @Override
    public boolean canHaveRestrictedProfile(@UserIdInt int userId) {
        checkManageUsersPermission("canHaveRestrictedProfile");
        return canHaveRestrictedProfileNoChecks(userId);
    }

    private boolean canHaveRestrictedProfileNoChecks(@UserIdInt int userId) {
        if (isCreationOverrideEnabled()) {
            return true;
        }
        synchronized (mUsersLock) {
            final UserInfo userInfo = getUserInfoLU(userId);
            if (userInfo == null || !userInfo.canHaveProfile()) {
@@ -6113,10 +6120,9 @@ public class UserManagerService extends IUserManager.Stub {
                                    + " for user " + parentId,
                            UserManager.USER_OPERATION_ERROR_MAX_USERS);
                }
                if (isRestricted && (parentId != UserHandle.USER_SYSTEM)
                        && !isCreationOverrideEnabled()) {
                if (isRestricted && !canHaveRestrictedProfileNoChecks(parentId)) {
                    throwCheckedUserOperationException(
                            "Cannot add restricted profile - parent user must be system",
                            "Cannot add restricted profile for user " + parentId,
                            USER_OPERATION_ERROR_UNKNOWN);
                }