Merge \\"Reduce shell power over user management.\\" into mnc-dev am: 964500fd43
am: 9bfa0ad22f
Change-Id: I952f6a12be0c1edc6027ccce785d47d7f84757ef
This commit is contained in:
@@ -1400,6 +1400,14 @@
|
|||||||
<permission android:name="android.permission.MANAGE_USERS"
|
<permission android:name="android.permission.MANAGE_USERS"
|
||||||
android:protectionLevel="signature|privileged" />
|
android:protectionLevel="signature|privileged" />
|
||||||
|
|
||||||
|
<!-- @hide Allows an application to create, remove users and get the list of
|
||||||
|
users on the device. Applications holding this permission can only create restricted,
|
||||||
|
guest, and managed users. For creating other kind of users,
|
||||||
|
{@link android.Manifest.permission#MANAGE_USERS} is needed.
|
||||||
|
This permission is not available to third party applications. -->
|
||||||
|
<permission android:name="android.permission.CREATE_USERS"
|
||||||
|
android:protectionLevel="signature" />
|
||||||
|
|
||||||
<!-- @hide Allows an application to set the profile owners and the device owner.
|
<!-- @hide Allows an application to set the profile owners and the device owner.
|
||||||
This permission is not available to third party applications.-->
|
This permission is not available to third party applications.-->
|
||||||
<permission android:name="android.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS"
|
<permission android:name="android.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS"
|
||||||
|
|||||||
@@ -89,7 +89,7 @@
|
|||||||
<uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE" />
|
<uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
|
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
|
||||||
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
|
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
|
||||||
<uses-permission android:name="android.permission.MANAGE_USERS" />
|
<uses-permission android:name="android.permission.CREATE_USERS" />
|
||||||
<uses-permission android:name="android.permission.MANAGE_DEVICE_ADMINS" />
|
<uses-permission android:name="android.permission.MANAGE_DEVICE_ADMINS" />
|
||||||
<uses-permission android:name="android.permission.BLUETOOTH_STACK" />
|
<uses-permission android:name="android.permission.BLUETOOTH_STACK" />
|
||||||
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
|
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
|
||||||
|
|||||||
@@ -125,6 +125,11 @@ public class UserManagerService extends IUserManager.Stub {
|
|||||||
private static final String RESTRICTIONS_FILE_PREFIX = "res_";
|
private static final String RESTRICTIONS_FILE_PREFIX = "res_";
|
||||||
private static final String XML_SUFFIX = ".xml";
|
private static final String XML_SUFFIX = ".xml";
|
||||||
|
|
||||||
|
private static final int ALLOWED_FLAGS_FOR_CREATE_USERS_PERMISSION =
|
||||||
|
UserInfo.FLAG_MANAGED_PROFILE
|
||||||
|
| UserInfo.FLAG_RESTRICTED
|
||||||
|
| UserInfo.FLAG_GUEST;
|
||||||
|
|
||||||
private static final int MIN_USER_ID = 10;
|
private static final int MIN_USER_ID = 10;
|
||||||
|
|
||||||
private static final int USER_VERSION = 5;
|
private static final int USER_VERSION = 5;
|
||||||
@@ -277,7 +282,7 @@ public class UserManagerService extends IUserManager.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UserInfo> getUsers(boolean excludeDying) {
|
public List<UserInfo> getUsers(boolean excludeDying) {
|
||||||
checkManageUsersPermission("query users");
|
checkManageOrCreateUsersPermission("query users");
|
||||||
synchronized (mPackagesLock) {
|
synchronized (mPackagesLock) {
|
||||||
ArrayList<UserInfo> users = new ArrayList<UserInfo>(mUsers.size());
|
ArrayList<UserInfo> users = new ArrayList<UserInfo>(mUsers.size());
|
||||||
for (int i = 0; i < mUsers.size(); i++) {
|
for (int i = 0; i < mUsers.size(); i++) {
|
||||||
@@ -388,7 +393,7 @@ public class UserManagerService extends IUserManager.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserInfo getUserInfo(int userId) {
|
public UserInfo getUserInfo(int userId) {
|
||||||
checkManageUsersPermission("query user");
|
checkManageOrCreateUsersPermission("query user");
|
||||||
synchronized (mPackagesLock) {
|
synchronized (mPackagesLock) {
|
||||||
return getUserInfoLocked(userId);
|
return getUserInfoLocked(userId);
|
||||||
}
|
}
|
||||||
@@ -676,6 +681,71 @@ public class UserManagerService extends IUserManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enforces that only the system UID or root's UID or apps that have the
|
||||||
|
* {@link android.Manifest.permission#MANAGE_USERS MANAGE_USERS} or
|
||||||
|
* {@link android.Manifest.permission#CREATE_USERS CREATE_USERS}
|
||||||
|
* can make certain calls to the UserManager.
|
||||||
|
*
|
||||||
|
* @param message used as message if SecurityException is thrown
|
||||||
|
* @throws SecurityException if the caller is not system or root
|
||||||
|
* @see #hasManageOrCreateUsersPermission()
|
||||||
|
*/
|
||||||
|
private static final void checkManageOrCreateUsersPermission(String message) {
|
||||||
|
if (!hasManageOrCreateUsersPermission()) {
|
||||||
|
throw new SecurityException(
|
||||||
|
"You either need MANAGE_USERS or CREATE_USERS permission to: " + message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Similar to {@link #checkManageOrCreateUsersPermission(String)} but when the caller is tries
|
||||||
|
* to create user/profiles other than what is allowed for
|
||||||
|
* {@link android.Manifest.permission#CREATE_USERS CREATE_USERS} permission, then it will only
|
||||||
|
* allow callers with {@link android.Manifest.permission#MANAGE_USERS MANAGE_USERS} permission.
|
||||||
|
*/
|
||||||
|
private static final void checkManageOrCreateUsersPermission(int creationFlags) {
|
||||||
|
if ((creationFlags & ~ALLOWED_FLAGS_FOR_CREATE_USERS_PERMISSION) == 0) {
|
||||||
|
if (!hasManageOrCreateUsersPermission()) {
|
||||||
|
throw new SecurityException("You either need MANAGE_USERS or CREATE_USERS "
|
||||||
|
+ "permission to create an user with flags: " + creationFlags);
|
||||||
|
}
|
||||||
|
} else if (!hasManageUsersPermission()) {
|
||||||
|
throw new SecurityException("You need MANAGE_USERS permission to create an user "
|
||||||
|
+ " with flags: " + creationFlags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return whether the calling UID is system UID or root's UID or the calling app has the
|
||||||
|
* {@link android.Manifest.permission#MANAGE_USERS MANAGE_USERS}.
|
||||||
|
*/
|
||||||
|
private static final boolean hasManageUsersPermission() {
|
||||||
|
final int callingUid = Binder.getCallingUid();
|
||||||
|
return UserHandle.isSameApp(callingUid, Process.SYSTEM_UID)
|
||||||
|
|| callingUid == Process.ROOT_UID
|
||||||
|
|| ActivityManager.checkComponentPermission(
|
||||||
|
android.Manifest.permission.MANAGE_USERS,
|
||||||
|
callingUid, -1, true) == PackageManager.PERMISSION_GRANTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return whether the calling UID is system UID or root's UID or the calling app has the
|
||||||
|
* {@link android.Manifest.permission#MANAGE_USERS MANAGE_USERS} or
|
||||||
|
* {@link android.Manifest.permission#CREATE_USERS CREATE_USERS}.
|
||||||
|
*/
|
||||||
|
private static final boolean hasManageOrCreateUsersPermission() {
|
||||||
|
final int callingUid = Binder.getCallingUid();
|
||||||
|
return UserHandle.isSameApp(callingUid, Process.SYSTEM_UID)
|
||||||
|
|| callingUid == Process.ROOT_UID
|
||||||
|
|| ActivityManager.checkComponentPermission(
|
||||||
|
android.Manifest.permission.MANAGE_USERS,
|
||||||
|
callingUid, -1, true) == PackageManager.PERMISSION_GRANTED
|
||||||
|
|| ActivityManager.checkComponentPermission(
|
||||||
|
android.Manifest.permission.CREATE_USERS,
|
||||||
|
callingUid, -1, true) == PackageManager.PERMISSION_GRANTED;
|
||||||
|
}
|
||||||
|
|
||||||
private static void checkSystemOrRoot(String message) {
|
private static void checkSystemOrRoot(String message) {
|
||||||
final int uid = Binder.getCallingUid();
|
final int uid = Binder.getCallingUid();
|
||||||
if (uid != Process.SYSTEM_UID && uid != 0) {
|
if (uid != Process.SYSTEM_UID && uid != 0) {
|
||||||
@@ -1227,7 +1297,7 @@ public class UserManagerService extends IUserManager.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserInfo createProfileForUser(String name, int flags, int userId) {
|
public UserInfo createProfileForUser(String name, int flags, int userId) {
|
||||||
checkManageUsersPermission("Only the system can create users");
|
checkManageOrCreateUsersPermission(flags);
|
||||||
if (userId != UserHandle.USER_OWNER) {
|
if (userId != UserHandle.USER_OWNER) {
|
||||||
Slog.w(LOG_TAG, "Only user owner can have profiles");
|
Slog.w(LOG_TAG, "Only user owner can have profiles");
|
||||||
return null;
|
return null;
|
||||||
@@ -1237,7 +1307,7 @@ public class UserManagerService extends IUserManager.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserInfo createUser(String name, int flags) {
|
public UserInfo createUser(String name, int flags) {
|
||||||
checkManageUsersPermission("Only the system can create users");
|
checkManageOrCreateUsersPermission(flags);
|
||||||
return createUserInternal(name, flags, UserHandle.USER_NULL);
|
return createUserInternal(name, flags, UserHandle.USER_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1402,7 +1472,7 @@ public class UserManagerService extends IUserManager.Stub {
|
|||||||
* @param userHandle the user's id
|
* @param userHandle the user's id
|
||||||
*/
|
*/
|
||||||
public boolean removeUser(int userHandle) {
|
public boolean removeUser(int userHandle) {
|
||||||
checkManageUsersPermission("Only the system can remove users");
|
checkManageOrCreateUsersPermission("Only the system can remove users");
|
||||||
if (getUserRestrictions(UserHandle.getCallingUserId()).getBoolean(
|
if (getUserRestrictions(UserHandle.getCallingUserId()).getBoolean(
|
||||||
UserManager.DISALLOW_REMOVE_USER, false)) {
|
UserManager.DISALLOW_REMOVE_USER, false)) {
|
||||||
Log.w(LOG_TAG, "Cannot remove user. DISALLOW_REMOVE_USER is enabled.");
|
Log.w(LOG_TAG, "Cannot remove user. DISALLOW_REMOVE_USER is enabled.");
|
||||||
|
|||||||
Reference in New Issue
Block a user