Skip to content

Commit 0141fae

Browse files
Amith YamasaniAndroid (Google) Code Review
authored andcommitted
Merge "Allow services to query the info for a dying user." into jb-mr1-dev
2 parents 6a377f3 + 1638931 commit 0141fae

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public class UserManagerService extends IUserManager.Stub {
6262

6363
private static final String LOG_TAG = "UserManagerService";
6464

65+
private static final boolean DBG = false;
66+
6567
private static final String TAG_NAME = "name";
6668
private static final String ATTR_FLAGS = "flags";
6769
private static final String ATTR_ICON_PATH = "icon";
@@ -97,6 +99,9 @@ public class UserManagerService extends IUserManager.Stub {
9799
private int[] mUserIds;
98100
private boolean mGuestEnabled;
99101
private int mNextSerialNumber;
102+
// This resets on a reboot. Otherwise it keeps incrementing so that user ids are
103+
// not reused in quick succession
104+
private int mNextUserId = MIN_USER_ID;
100105

101106
private static UserManagerService sInstance;
102107

@@ -199,7 +204,8 @@ public UserInfo getUserInfo(int userId) {
199204
*/
200205
private UserInfo getUserInfoLocked(int userId) {
201206
UserInfo ui = mUsers.get(userId);
202-
if (ui != null && ui.partial) {
207+
// If it is partial and not in the process of being removed, return as unknown user.
208+
if (ui != null && ui.partial && !mRemovingUserIds.contains(userId)) {
203209
Slog.w(LOG_TAG, "getUserInfo: unknown user #" + userId);
204210
return null;
205211
}
@@ -668,6 +674,7 @@ public UserInfo createUser(String name, int flags) {
668674
long now = System.currentTimeMillis();
669675
userInfo.creationTime = (now > EPOCH_PLUS_30_YEARS) ? now : 0;
670676
userInfo.partial = true;
677+
Environment.getUserSystemDirectory(userInfo.id).mkdirs();
671678
mUsers.put(userId, userInfo);
672679
writeUserListLocked();
673680
writeUserLocked(userInfo);
@@ -709,7 +716,7 @@ public boolean removeUser(int userHandle) {
709716
user.partial = true;
710717
writeUserLocked(user);
711718
}
712-
719+
if (DBG) Slog.i(LOG_TAG, "Stopping user " + userHandle);
713720
int res;
714721
try {
715722
res = ActivityManagerNative.getDefault().stopUser(userHandle,
@@ -730,12 +737,13 @@ public void userStopAborted(int userId) {
730737
}
731738

732739
void finishRemoveUser(int userHandle) {
740+
if (DBG) Slog.i(LOG_TAG, "finishRemoveUser " + userHandle);
733741
synchronized (mInstallLock) {
734742
synchronized (mPackagesLock) {
735743
removeUserStateLocked(userHandle);
736744
}
737745
}
738-
746+
if (DBG) Slog.i(LOG_TAG, "Removed user " + userHandle + ", sending broadcast");
739747
// Let other services shutdown any activity
740748
long ident = Binder.clearCallingIdentity();
741749
try {
@@ -804,10 +812,11 @@ private void updateUserIdsLocked() {
804812
num++;
805813
}
806814
}
807-
int[] newUsers = new int[num];
815+
final int[] newUsers = new int[num];
816+
int n = 0;
808817
for (int i = 0; i < mUsers.size(); i++) {
809818
if (!mUsers.valueAt(i).partial) {
810-
newUsers[i] = mUsers.keyAt(i);
819+
newUsers[n++] = mUsers.keyAt(i);
811820
}
812821
}
813822
mUserIds = newUsers;
@@ -840,13 +849,14 @@ public void userForeground(int userId) {
840849
*/
841850
private int getNextAvailableIdLocked() {
842851
synchronized (mPackagesLock) {
843-
int i = MIN_USER_ID;
852+
int i = mNextUserId;
844853
while (i < Integer.MAX_VALUE) {
845854
if (mUsers.indexOfKey(i) < 0 && !mRemovingUserIds.contains(i)) {
846855
break;
847856
}
848857
i++;
849858
}
859+
mNextUserId = i + 1;
850860
return i;
851861
}
852862
}

0 commit comments

Comments
 (0)