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

This commit is contained in:
Philipp Weiß
2016-02-11 17:17:38 +00:00
committed by Android (Google) Code Review
4 changed files with 32 additions and 1 deletions

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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. */

View File

@@ -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();
}