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

Commit 38d8cd36 authored by Philipp Weiß's avatar Philipp Weiß Committed by android-build-merger
Browse files

Merge "DPM.createAndManageUser should work even with DISALLOW_ADD_USER set" into nyc-dev

am: 09f85680

* commit '09f85680':
  DPM.createAndManageUser should work even with DISALLOW_ADD_USER set
parents d9ef8520 09f85680
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -1141,6 +1141,8 @@ public class UserManager {
        UserInfo user = null;
        try {
            user = mService.createUser(name, flags);
            // TODO: Keep this in sync with
            // UserManagerService.LocalService.createUserEvenWhenDisallowed
            if (user != null && !user.isAdmin()) {
                mService.setUserRestriction(DISALLOW_SMS, true, user.id);
                mService.setUserRestriction(DISALLOW_OUTGOING_CALLS, true, user.id);
+9 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package android.os;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.pm.UserInfo;
import android.graphics.Bitmap;

/**
@@ -106,4 +107,12 @@ public abstract class UserManagerInternal {
     * non-ephemeral users left.
     */
    public abstract void removeAllUsers();

    /**
     * Same as UserManager.createUser(), but bypasses the check for DISALLOW_ADD_USER.
     *
     * <p>Called by the {@link com.android.server.devicepolicy.DevicePolicyManagerService} when
     * createAndManageUser is called by the device owner.
     */
    public abstract UserInfo createUserEvenWhenDisallowed(String name, int flags);
}
+15 −0
Original line number Diff line number Diff line
@@ -1789,6 +1789,10 @@ public class UserManagerService extends IUserManager.Stub {
            Log.w(LOG_TAG, "Cannot add user. DISALLOW_ADD_USER is enabled.");
            return null;
        }
        return createUserInternalUnchecked(name, flags, parentId);
    }

    private UserInfo createUserInternalUnchecked(String name, int flags, int parentId) {
        if (ActivityManager.isLowRamDeviceStatic()) {
            return null;
        }
@@ -2975,6 +2979,17 @@ public class UserManagerService extends IUserManager.Stub {
                am.switchUser(UserHandle.USER_SYSTEM);
            }
        }

        @Override
        public UserInfo createUserEvenWhenDisallowed(String name, int flags) {
            UserInfo user = createUserInternalUnchecked(name, flags, UserHandle.USER_NULL);
            // Keep this in sync with UserManager.createUser
            if (user != null && !user.isAdmin()) {
                setUserRestriction(UserManager.DISALLOW_SMS, true, user.id);
                setUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS, true, user.id);
            }
            return user;
        }
    }

    /* Remove all the users except of the system one. */
+6 −1
Original line number Diff line number Diff line
@@ -6791,6 +6791,10 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
            throw new IllegalArgumentException("profileOwner " + profileOwner + " and admin "
                    + admin + " are not in the same package");
        }
        // Only allow the system user to use this method
        if (!mInjector.binderGetCallingUserHandle().isSystem()) {
            throw new SecurityException("createAndManageUser was called from non-system user");
        }
        // Create user.
        UserHandle user = null;
        synchronized (this) {
@@ -6802,7 +6806,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                if ((flags & DevicePolicyManager.MAKE_USER_EPHEMERAL) != 0) {
                    userInfoFlags |= UserInfo.FLAG_EPHEMERAL;
                }
                UserInfo userInfo = mUserManager.createUser(name, userInfoFlags);
                UserInfo userInfo = mUserManagerInternal.createUserEvenWhenDisallowed(name,
                        userInfoFlags);
                if (userInfo != null) {
                    user = userInfo.getUserHandle();
                }