Skip to content

Commit 98dddda

Browse files
Amith YamasaniAndroid (Google) Code Review
authored andcommitted
Merge "Remove permission requirement for some UserManager calls" into jb-mr1-dev
2 parents 6479ecd + 1952637 commit 98dddda

File tree

4 files changed

+33
-14
lines changed

4 files changed

+33
-14
lines changed

core/java/android/os/UserManager.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public int getUserHandle() {
5656

5757
/**
5858
* Returns the user name of the user making this call.
59+
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
5960
* @return the user name
6061
*/
6162
public String getUserName() {
@@ -69,6 +70,7 @@ public String getUserName() {
6970

7071
/**
7172
* Returns the UserInfo object describing a specific user.
73+
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
7274
* @param userHandle the user handle of the user whose information is being requested.
7375
* @return the UserInfo object for a specific user.
7476
* @hide
@@ -84,6 +86,7 @@ public UserInfo getUserInfo(int userHandle) {
8486

8587
/**
8688
* Creates a user with the specified name and options.
89+
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
8790
*
8891
* @param name the user's name
8992
* @param flags flags that identify the type of user and other properties.
@@ -103,6 +106,7 @@ public UserInfo createUser(String name, int flags) {
103106

104107
/**
105108
* Returns information for all users on this device.
109+
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
106110
* @return the list of users that were created.
107111
* @hide
108112
*/
@@ -117,6 +121,7 @@ public List<UserInfo> getUsers() {
117121

118122
/**
119123
* Removes a user and all associated data.
124+
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
120125
* @param userHandle the integer handle of the user, where 0 is the primary user.
121126
* @hide
122127
*/
@@ -131,6 +136,7 @@ public boolean removeUser(int userHandle) {
131136

132137
/**
133138
* Updates the user's name.
139+
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
134140
*
135141
* @param userHandle the user's integer handle
136142
* @param name the new name for the user
@@ -162,6 +168,7 @@ public ParcelFileDescriptor setUserIcon(int userHandle) {
162168
/**
163169
* Enable or disable the use of a guest account. If disabled, the existing guest account
164170
* will be wiped.
171+
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
165172
* @param enable whether to enable a guest account.
166173
* @hide
167174
*/
@@ -175,6 +182,7 @@ public void setGuestEnabled(boolean enable) {
175182

176183
/**
177184
* Checks if a guest user is enabled for this device.
185+
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
178186
* @return whether a guest user is enabled
179187
* @hide
180188
*/
@@ -189,6 +197,7 @@ public boolean isGuestEnabled() {
189197

190198
/**
191199
* Wipes all the data for a user, but doesn't remove the user.
200+
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
192201
* @param userHandle
193202
* @hide
194203
*/

core/res/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@
790790
third party applications. -->
791791
<permission android:name="android.permission.MANAGE_USERS"
792792
android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
793-
android:protectionLevel="signature"
793+
android:protectionLevel="signature|system"
794794
android:label="@string/permlab_manageUsers"
795795
android:description="@string/permdesc_manageUsers" />
796796

services/java/com/android/server/pm/UserManagerService.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,17 @@ public List<UserInfo> getUsers() {
137137
public UserInfo getUserInfo(int userId) {
138138
checkManageUsersPermission("query user");
139139
synchronized (mUsers) {
140-
UserInfo info = mUsers.get(userId);
141-
return info;
140+
return getUserInfoLocked(userId);
142141
}
143142
}
144143

144+
/*
145+
* Should be locked on mUsers before calling this.
146+
*/
147+
private UserInfo getUserInfoLocked(int userId) {
148+
return mUsers.get(userId);
149+
}
150+
145151
public boolean exists(int userId) {
146152
synchronized (mUsers) {
147153
return ArrayUtils.contains(mUserIds, userId);
@@ -212,8 +218,9 @@ public void wipeUser(int userHandle) {
212218
}
213219

214220
/**
215-
* Enforces that only the system UID or root's UID can call a method exposed
216-
* via Binder.
221+
* Enforces that only the system UID or root's UID or apps that have the
222+
* {@link android.Manifest.permission.MANAGE_USERS MANAGE_USERS}
223+
* permission can make certain calls to the UserManager.
217224
*
218225
* @param message used as message if SecurityException is thrown
219226
* @throws SecurityException if the caller is not system or root
@@ -534,15 +541,15 @@ public boolean removeUser(int userHandle) {
534541
public int getUserSerialNumber(int userHandle) {
535542
synchronized (mUsers) {
536543
if (!exists(userHandle)) return -1;
537-
return getUserInfo(userHandle).serialNumber;
544+
return getUserInfoLocked(userHandle).serialNumber;
538545
}
539546
}
540547

541548
@Override
542549
public int getUserHandle(int userSerialNumber) {
543550
synchronized (mUsers) {
544551
for (int userId : mUserIds) {
545-
if (getUserInfo(userId).serialNumber == userSerialNumber) return userId;
552+
if (getUserInfoLocked(userId).serialNumber == userSerialNumber) return userId;
546553
}
547554
// Not found
548555
return -1;
@@ -617,14 +624,16 @@ private void updateUserIdsLocked() {
617624
* @return
618625
*/
619626
private int getNextAvailableId() {
620-
int i = 0;
621-
while (i < Integer.MAX_VALUE) {
622-
if (mUsers.indexOfKey(i) < 0) {
623-
break;
627+
synchronized (mUsers) {
628+
int i = 0;
629+
while (i < Integer.MAX_VALUE) {
630+
if (mUsers.indexOfKey(i) < 0) {
631+
break;
632+
}
633+
i++;
624634
}
625-
i++;
635+
return i;
626636
}
627-
return i;
628637
}
629638

630639
private boolean createPackageFolders(int id, File userPath) {

services/tests/servicestests/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
<uses-permission android:name="android.permission.CONNECTIVITY_INTERNAL" />
3535
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
3636
<uses-permission android:name="android.permission.MANAGE_USERS" />
37-
37+
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
38+
3839
<application>
3940
<uses-library android:name="android.test.runner" />
4041

0 commit comments

Comments
 (0)