Skip to content

Commit 0cdbd07

Browse files
Dianne HackbornAndroid (Google) Code Review
authored andcommitted
Merge "Fix issue #7290206: Need API to get/look up user serial number" into jb-mr1-dev
2 parents 1934862 + 33f9cb8 commit 0cdbd07

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

api/17.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16615,6 +16615,8 @@ package android.os {
1661516615
}
1661616616

1661716617
public class UserManager {
16618+
method public long getSerialNumberForUser(android.os.UserHandle);
16619+
method public android.os.UserHandle getUserForSerialNumber(long);
1661816620
method public java.lang.String getUserName();
1661916621
method public boolean isUserAGoat();
1662016622
}

api/current.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16615,6 +16615,8 @@ package android.os {
1661516615
}
1661616616

1661716617
public class UserManager {
16618+
method public long getSerialNumberForUser(android.os.UserHandle);
16619+
method public android.os.UserHandle getUserForSerialNumber(long);
1661816620
method public java.lang.String getUserName();
1661916621
method public boolean isUserAGoat();
1662016622
}

core/java/android/os/UserManager.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,32 @@ public UserInfo getUserInfo(int userHandle) {
9797
}
9898
}
9999

100+
/**
101+
* Return the serial number for a user. This is a device-unique
102+
* number assigned to that user; if the user is deleted and new users
103+
* created, the new users will not be given the same serial number.
104+
* @param user The user whose serial number is to be retrieved.
105+
* @return The serial number of the given user.
106+
* @see #getUserForSerialNumber(long)
107+
*/
108+
public long getSerialNumberForUser(UserHandle user) {
109+
return getUserSerialNumber(user.getIdentifier());
110+
}
111+
112+
/**
113+
* Return the user associated with a serial number previously
114+
* returned by {@link #getSerialNumberForUser(UserHandle)}.
115+
* @param serialNumber The serial number of the user that is being
116+
* retrieved.
117+
* @return Return the user associated with the serial number, or null
118+
* if there is not one.
119+
* @see #getSerialNumberForUser(UserHandle)
120+
*/
121+
public UserHandle getUserForSerialNumber(long serialNumber) {
122+
int ident = getUserHandle((int)serialNumber);
123+
return ident >= 0 ? new UserHandle(ident) : null;
124+
}
125+
100126
/**
101127
* Creates a user with the specified name and options.
102128
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.

0 commit comments

Comments
 (0)