Merge "Remove permission requirement for some UserManager calls" into jb-mr1-dev

This commit is contained in:
Amith Yamasani
2012-08-22 10:31:30 -07:00
committed by Android (Google) Code Review
4 changed files with 33 additions and 14 deletions

View File

@@ -56,6 +56,7 @@ public class UserManager {
/** /**
* Returns the user name of the user making this call. * Returns the user name of the user making this call.
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
* @return the user name * @return the user name
*/ */
public String getUserName() { public String getUserName() {
@@ -69,6 +70,7 @@ public class UserManager {
/** /**
* Returns the UserInfo object describing a specific user. * Returns the UserInfo object describing a specific user.
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
* @param userHandle the user handle of the user whose information is being requested. * @param userHandle the user handle of the user whose information is being requested.
* @return the UserInfo object for a specific user. * @return the UserInfo object for a specific user.
* @hide * @hide
@@ -84,6 +86,7 @@ public class UserManager {
/** /**
* Creates a user with the specified name and options. * Creates a user with the specified name and options.
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
* *
* @param name the user's name * @param name the user's name
* @param flags flags that identify the type of user and other properties. * @param flags flags that identify the type of user and other properties.
@@ -103,6 +106,7 @@ public class UserManager {
/** /**
* Returns information for all users on this device. * Returns information for all users on this device.
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
* @return the list of users that were created. * @return the list of users that were created.
* @hide * @hide
*/ */
@@ -117,6 +121,7 @@ public class UserManager {
/** /**
* Removes a user and all associated data. * Removes a user and all associated data.
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
* @param userHandle the integer handle of the user, where 0 is the primary user. * @param userHandle the integer handle of the user, where 0 is the primary user.
* @hide * @hide
*/ */
@@ -131,6 +136,7 @@ public class UserManager {
/** /**
* Updates the user's name. * Updates the user's name.
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
* *
* @param userHandle the user's integer handle * @param userHandle the user's integer handle
* @param name the new name for the user * @param name the new name for the user
@@ -162,6 +168,7 @@ public class UserManager {
/** /**
* Enable or disable the use of a guest account. If disabled, the existing guest account * Enable or disable the use of a guest account. If disabled, the existing guest account
* will be wiped. * will be wiped.
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
* @param enable whether to enable a guest account. * @param enable whether to enable a guest account.
* @hide * @hide
*/ */
@@ -175,6 +182,7 @@ public class UserManager {
/** /**
* Checks if a guest user is enabled for this device. * Checks if a guest user is enabled for this device.
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
* @return whether a guest user is enabled * @return whether a guest user is enabled
* @hide * @hide
*/ */
@@ -189,6 +197,7 @@ public class UserManager {
/** /**
* Wipes all the data for a user, but doesn't remove the user. * Wipes all the data for a user, but doesn't remove the user.
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
* @param userHandle * @param userHandle
* @hide * @hide
*/ */

View File

@@ -790,7 +790,7 @@
third party applications. --> third party applications. -->
<permission android:name="android.permission.MANAGE_USERS" <permission android:name="android.permission.MANAGE_USERS"
android:permissionGroup="android.permission-group.SYSTEM_TOOLS" android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
android:protectionLevel="signature" android:protectionLevel="signature|system"
android:label="@string/permlab_manageUsers" android:label="@string/permlab_manageUsers"
android:description="@string/permdesc_manageUsers" /> android:description="@string/permdesc_manageUsers" />

View File

@@ -137,11 +137,17 @@ public class UserManagerService extends IUserManager.Stub {
public UserInfo getUserInfo(int userId) { public UserInfo getUserInfo(int userId) {
checkManageUsersPermission("query user"); checkManageUsersPermission("query user");
synchronized (mUsers) { synchronized (mUsers) {
UserInfo info = mUsers.get(userId); return getUserInfoLocked(userId);
return info;
} }
} }
/*
* Should be locked on mUsers before calling this.
*/
private UserInfo getUserInfoLocked(int userId) {
return mUsers.get(userId);
}
public boolean exists(int userId) { public boolean exists(int userId) {
synchronized (mUsers) { synchronized (mUsers) {
return ArrayUtils.contains(mUserIds, userId); return ArrayUtils.contains(mUserIds, userId);
@@ -212,8 +218,9 @@ public class UserManagerService extends IUserManager.Stub {
} }
/** /**
* Enforces that only the system UID or root's UID can call a method exposed * Enforces that only the system UID or root's UID or apps that have the
* via Binder. * {@link android.Manifest.permission.MANAGE_USERS MANAGE_USERS}
* permission can make certain calls to the UserManager.
* *
* @param message used as message if SecurityException is thrown * @param message used as message if SecurityException is thrown
* @throws SecurityException if the caller is not system or root * @throws SecurityException if the caller is not system or root
@@ -534,7 +541,7 @@ public class UserManagerService extends IUserManager.Stub {
public int getUserSerialNumber(int userHandle) { public int getUserSerialNumber(int userHandle) {
synchronized (mUsers) { synchronized (mUsers) {
if (!exists(userHandle)) return -1; if (!exists(userHandle)) return -1;
return getUserInfo(userHandle).serialNumber; return getUserInfoLocked(userHandle).serialNumber;
} }
} }
@@ -542,7 +549,7 @@ public class UserManagerService extends IUserManager.Stub {
public int getUserHandle(int userSerialNumber) { public int getUserHandle(int userSerialNumber) {
synchronized (mUsers) { synchronized (mUsers) {
for (int userId : mUserIds) { for (int userId : mUserIds) {
if (getUserInfo(userId).serialNumber == userSerialNumber) return userId; if (getUserInfoLocked(userId).serialNumber == userSerialNumber) return userId;
} }
// Not found // Not found
return -1; return -1;
@@ -617,14 +624,16 @@ public class UserManagerService extends IUserManager.Stub {
* @return * @return
*/ */
private int getNextAvailableId() { private int getNextAvailableId() {
int i = 0; synchronized (mUsers) {
while (i < Integer.MAX_VALUE) { int i = 0;
if (mUsers.indexOfKey(i) < 0) { while (i < Integer.MAX_VALUE) {
break; if (mUsers.indexOfKey(i) < 0) {
break;
}
i++;
} }
i++; return i;
} }
return i;
} }
private boolean createPackageFolders(int id, File userPath) { private boolean createPackageFolders(int id, File userPath) {

View File

@@ -34,7 +34,8 @@
<uses-permission android:name="android.permission.CONNECTIVITY_INTERNAL" /> <uses-permission android:name="android.permission.CONNECTIVITY_INTERNAL" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.MANAGE_USERS" /> <uses-permission android:name="android.permission.MANAGE_USERS" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
<application> <application>
<uses-library android:name="android.test.runner" /> <uses-library android:name="android.test.runner" />