Skip to content

Commit 9c38d6e

Browse files
Amith YamasaniAndroid (Google) Code Review
authored andcommitted
Merge "UserHandle to UserSerialNo mapping" into jb-mr1-dev
2 parents bc11e52 + 2a00329 commit 9c38d6e

File tree

19 files changed

+196
-106
lines changed

19 files changed

+196
-106
lines changed

api/current.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ package android {
6868
field public static final java.lang.String KILL_BACKGROUND_PROCESSES = "android.permission.KILL_BACKGROUND_PROCESSES";
6969
field public static final java.lang.String MANAGE_ACCOUNTS = "android.permission.MANAGE_ACCOUNTS";
7070
field public static final java.lang.String MANAGE_APP_TOKENS = "android.permission.MANAGE_APP_TOKENS";
71+
field public static final java.lang.String MANAGE_USERS = "android.permission.MANAGE_USERS";
7172
field public static final java.lang.String MASTER_CLEAR = "android.permission.MASTER_CLEAR";
7273
field public static final java.lang.String MODIFY_AUDIO_SETTINGS = "android.permission.MODIFY_AUDIO_SETTINGS";
7374
field public static final java.lang.String MODIFY_PHONE_STATE = "android.permission.MODIFY_PHONE_STATE";

core/java/android/accounts/AccountManagerService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ protected UserAccounts getUserAccounts(int userId) {
369369
}
370370

371371
private void onUserRemoved(Intent intent) {
372-
int userId = intent.getIntExtra(Intent.EXTRA_USERID, -1);
372+
int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
373373
if (userId < 1) return;
374374

375375
UserAccounts accounts;

core/java/android/content/Intent.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,24 +2279,24 @@ public static Intent createChooser(Intent target, CharSequence title) {
22792279
"android.intent.action.PRE_BOOT_COMPLETED";
22802280

22812281
/**
2282-
* Broadcast sent to the system when a user is added. Carries an extra EXTRA_USERID that has the
2283-
* userid of the new user.
2282+
* Broadcast sent to the system when a user is added. Carries an extra EXTRA_USER_HANDLE that has the
2283+
* userHandle of the new user.
22842284
* @hide
22852285
*/
22862286
public static final String ACTION_USER_ADDED =
22872287
"android.intent.action.USER_ADDED";
22882288

22892289
/**
2290-
* Broadcast sent to the system when a user is removed. Carries an extra EXTRA_USERID that has
2291-
* the userid of the user.
2290+
* Broadcast sent to the system when a user is removed. Carries an extra EXTRA_USER_HANDLE that has
2291+
* the userHandle of the user.
22922292
* @hide
22932293
*/
22942294
public static final String ACTION_USER_REMOVED =
22952295
"android.intent.action.USER_REMOVED";
22962296

22972297
/**
2298-
* Broadcast sent to the system when the user switches. Carries an extra EXTRA_USERID that has
2299-
* the userid of the user to become the current one.
2298+
* Broadcast sent to the system when the user switches. Carries an extra EXTRA_USER_HANDLE that has
2299+
* the userHandle of the user to become the current one.
23002300
* @hide
23012301
*/
23022302
public static final String ACTION_USER_SWITCHED =
@@ -2852,12 +2852,12 @@ public static Intent createChooser(Intent target, CharSequence title) {
28522852
"android.intent.extra.LOCAL_ONLY";
28532853

28542854
/**
2855-
* The userid carried with broadcast intents related to addition, removal and switching of users
2855+
* The userHandle carried with broadcast intents related to addition, removal and switching of users
28562856
* - {@link #ACTION_USER_ADDED}, {@link #ACTION_USER_REMOVED} and {@link #ACTION_USER_SWITCHED}.
28572857
* @hide
28582858
*/
2859-
public static final String EXTRA_USERID =
2860-
"android.intent.extra.user_id";
2859+
public static final String EXTRA_USER_HANDLE =
2860+
"android.intent.extra.user_handle";
28612861

28622862
// ---------------------------------------------------------------------
28632863
// ---------------------------------------------------------------------

core/java/android/content/SyncManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ void maybeRescheduleSync(SyncResult syncResult, SyncOperation operation) {
895895
}
896896

897897
private void onUserRemoved(Intent intent) {
898-
int userId = intent.getIntExtra(Intent.EXTRA_USERID, -1);
898+
int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
899899
if (userId == -1) return;
900900

901901
// Clean up the storage engine database

core/java/android/content/pm/UserInfo.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class UserInfo implements Parcelable {
5353
public static final int FLAG_RESTRICTED = 0x00000008;
5454

5555
public int id;
56+
public int serialNumber;
5657
public String name;
5758
public String iconPath;
5859
public int flags;
@@ -88,6 +89,7 @@ public UserInfo(UserInfo orig) {
8889
iconPath = orig.iconPath;
8990
id = orig.id;
9091
flags = orig.flags;
92+
serialNumber = orig.serialNumber;
9193
}
9294

9395
@Override
@@ -104,6 +106,7 @@ public void writeToParcel(Parcel dest, int parcelableFlags) {
104106
dest.writeString(name);
105107
dest.writeString(iconPath);
106108
dest.writeInt(flags);
109+
dest.writeInt(serialNumber);
107110
}
108111

109112
public static final Parcelable.Creator<UserInfo> CREATOR
@@ -121,5 +124,6 @@ private UserInfo(Parcel source) {
121124
name = source.readString();
122125
iconPath = source.readString();
123126
flags = source.readInt();
127+
serialNumber = source.readInt();
124128
}
125129
}

core/java/android/os/IUserManager.aidl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,6 @@ interface IUserManager {
3333
void setGuestEnabled(boolean enable);
3434
boolean isGuestEnabled();
3535
void wipeUser(int userHandle);
36+
int getUserSerialNumber(int userHandle);
37+
int getUserHandle(int userSerialNumber);
3638
}

core/java/android/os/UserManager.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,40 @@ public void wipeUser(int userHandle) {
209209
public int getMaxSupportedUsers() {
210210
return mContext.getResources().getInteger(R.integer.config_multiuserMaximumUsers);
211211
}
212+
213+
/**
214+
* Returns a serial number on this device for a given userHandle. User handles can be recycled
215+
* when deleting and creating users, but serial numbers are not reused until the device is wiped.
216+
* @param userHandle
217+
* @return a serial number associated with that user, or -1 if the userHandle is not valid.
218+
* @hide
219+
*/
220+
public int getUserSerialNumber(int userHandle) {
221+
try {
222+
return mService.getUserSerialNumber(userHandle);
223+
} catch (RemoteException re) {
224+
Log.w(TAG, "Could not get serial number for user " + userHandle);
225+
}
226+
return -1;
227+
}
228+
229+
/**
230+
* Returns a userHandle on this device for a given user serial number. User handles can be
231+
* recycled when deleting and creating users, but serial numbers are not reused until the device
232+
* is wiped.
233+
* @param userSerialNumber
234+
* @return the userHandle associated with that user serial number, or -1 if the serial number
235+
* is not valid.
236+
* @hide
237+
*/
238+
public int getUserHandle(int userSerialNumber) {
239+
try {
240+
return mService.getUserHandle(userSerialNumber);
241+
} catch (RemoteException re) {
242+
Log.w(TAG, "Could not get userHandle for user " + userSerialNumber);
243+
}
244+
return -1;
245+
}
246+
247+
212248
}

core/res/AndroidManifest.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,6 @@
766766
android:protectionLevel="dangerous"
767767
android:label="@string/permlab_getTasks"
768768
android:description="@string/permdesc_getTasks" />
769-
770769
<!-- Allows an application to call APIs that allow it to do interactions
771770
across the users on the device, using singleton services and
772771
user-targeted broadcasts. This permission is not available to
@@ -786,6 +785,15 @@
786785
android:label="@string/permlab_interactAcrossUsersFull"
787786
android:description="@string/permdesc_interactAcrossUsersFull" />
788787

788+
<!-- Allows an application to call APIs that allow it to query and manage
789+
users on the device. This permission is not available to
790+
third party applications. -->
791+
<permission android:name="android.permission.MANAGE_USERS"
792+
android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
793+
android:protectionLevel="signature"
794+
android:label="@string/permlab_manageUsers"
795+
android:description="@string/permdesc_manageUsers" />
796+
789797
<!-- Allows an application to get full detailed information about
790798
recently running tasks, with full fidelity to the real state.
791799
@hide -->

core/res/res/values/strings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,11 @@
567567
<string name="permdesc_interactAcrossUsersFull">Allows all possible interactions across
568568
users.</string>
569569

570+
<!-- Title of an application permission, listed so the user can choose whether they want to allow the application to create/remove/query users. [CHAR LIMIT=none] -->
571+
<string name="permlab_manageUsers">manage users</string>
572+
<!-- Description of an application permission, listed so the user can choose whether they want to allow the application to create/remove/query users. [CHAR LIMIT=NONE] -->
573+
<string name="permdesc_manageUsers">Allows apps to manage users on the device, including query, creation and deletion.</string>
574+
570575
<!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. [CHAR LIMIT=50] -->
571576
<string name="permlab_getDetailedTasks">retrieve details of running apps</string>
572577
<!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. [CHAR LIMIT=NONE] -->

packages/SystemUI/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
1616
<uses-permission android:name="android.permission.REMOTE_AUDIO_PLAYBACK" />
1717

18-
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
18+
<uses-permission android:name="android.permission.MANAGE_USERS" />
1919

2020
<!-- Networking and telephony -->
2121
<uses-permission android:name="android.permission.BLUETOOTH" />

0 commit comments

Comments
 (0)