Skip to content

Commit ead7d90

Browse files
Dianne HackbornAndroid (Google) Code Review
authored andcommitted
Merge "Fix issue #7408647: Add getUserCount() API" into jb-mr1-dev
2 parents 38c904a + b26306a commit ead7d90

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

api/17.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16619,6 +16619,7 @@ package android.os {
1661916619

1662016620
public class UserManager {
1662116621
method public long getSerialNumberForUser(android.os.UserHandle);
16622+
method public int getUserCount();
1662216623
method public android.os.UserHandle getUserForSerialNumber(long);
1662316624
method public java.lang.String getUserName();
1662416625
method public boolean isUserAGoat();

api/current.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16619,6 +16619,7 @@ package android.os {
1661916619

1662016620
public class UserManager {
1662116621
method public long getSerialNumberForUser(android.os.UserHandle);
16622+
method public int getUserCount();
1662216623
method public android.os.UserHandle getUserForSerialNumber(long);
1662316624
method public java.lang.String getUserName();
1662416625
method public boolean isUserAGoat();

core/java/android/os/UserManager.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public boolean isUserRunningOrStopping(UserHandle user) {
122122
* @param userHandle the user handle of the user whose information is being requested.
123123
* @return the UserInfo object for a specific user.
124124
* @hide
125-
* */
125+
*/
126126
public UserInfo getUserInfo(int userHandle) {
127127
try {
128128
return mService.getUserInfo(userHandle);
@@ -134,10 +134,11 @@ public UserInfo getUserInfo(int userHandle) {
134134

135135
/**
136136
* Return the serial number for a user. This is a device-unique
137-
* number assigned to that user; if the user is deleted and new users
138-
* created, the new users will not be given the same serial number.
137+
* number assigned to that user; if the user is deleted and then a new
138+
* user created, the new users will not be given the same serial number.
139139
* @param user The user whose serial number is to be retrieved.
140-
* @return The serial number of the given user.
140+
* @return The serial number of the given user; returns -1 if the
141+
* given UserHandle does not exist.
141142
* @see #getUserForSerialNumber(long)
142143
*/
143144
public long getSerialNumberForUser(UserHandle user) {
@@ -178,6 +179,14 @@ public UserInfo createUser(String name, int flags) {
178179
}
179180
}
180181

182+
/**
183+
* Return the number of users currently created on the device.
184+
*/
185+
public int getUserCount() {
186+
List<UserInfo> users = getUsers();
187+
return users != null ? users.size() : 1;
188+
}
189+
181190
/**
182191
* Returns information for all users on this device.
183192
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.

0 commit comments

Comments
 (0)