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

Commit fe35716b 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"...

Merge "DPM.createAndManageUser should work even with DISALLOW_ADD_USER set" into nyc-dev am: 09f85680
am: 38d8cd36

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


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


/**
/**
@@ -106,4 +107,12 @@ public abstract class UserManagerInternal {
     * non-ephemeral users left.
     * non-ephemeral users left.
     */
     */
    public abstract void removeAllUsers();
    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 Original line 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.");
            Log.w(LOG_TAG, "Cannot add user. DISALLOW_ADD_USER is enabled.");
            return null;
            return null;
        }
        }
        return createUserInternalUnchecked(name, flags, parentId);
    }

    private UserInfo createUserInternalUnchecked(String name, int flags, int parentId) {
        if (ActivityManager.isLowRamDeviceStatic()) {
        if (ActivityManager.isLowRamDeviceStatic()) {
            return null;
            return null;
        }
        }
@@ -2975,6 +2979,17 @@ public class UserManagerService extends IUserManager.Stub {
                am.switchUser(UserHandle.USER_SYSTEM);
                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. */
    /* Remove all the users except of the system one. */
+6 −1
Original line number Original line Diff line number Diff line
@@ -6791,6 +6791,10 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
            throw new IllegalArgumentException("profileOwner " + profileOwner + " and admin "
            throw new IllegalArgumentException("profileOwner " + profileOwner + " and admin "
                    + admin + " are not in the same package");
                    + 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.
        // Create user.
        UserHandle user = null;
        UserHandle user = null;
        synchronized (this) {
        synchronized (this) {
@@ -6802,7 +6806,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                if ((flags & DevicePolicyManager.MAKE_USER_EPHEMERAL) != 0) {
                if ((flags & DevicePolicyManager.MAKE_USER_EPHEMERAL) != 0) {
                    userInfoFlags |= UserInfo.FLAG_EPHEMERAL;
                    userInfoFlags |= UserInfo.FLAG_EPHEMERAL;
                }
                }
                UserInfo userInfo = mUserManager.createUser(name, userInfoFlags);
                UserInfo userInfo = mUserManagerInternal.createUserEvenWhenDisallowed(name,
                        userInfoFlags);
                if (userInfo != null) {
                if (userInfo != null) {
                    user = userInfo.getUserHandle();
                    user = userInfo.getUserHandle();
                }
                }