Add check for UID reuse.
The goal here is to make sure that we aren't allocating a UID that could have been in use since the last time the device booted. Bug: 8256571 (cherry picked from commit af70d15543c89a53f064492f4e3d17c446e00039) Change-Id: I8b11811df8d5a8ad1aa064abb43db020aceb29e3
This commit is contained in:
@ -122,6 +122,8 @@ final class Settings {
|
||||
private final HashMap<String, PackageSetting> mDisabledSysPackages =
|
||||
new HashMap<String, PackageSetting>();
|
||||
|
||||
private static int mFirstAvailableUid = 0;
|
||||
|
||||
// These are the last platform API version we were using for
|
||||
// the apps installed on internal and external storage. It is
|
||||
// used to grant newer permissions one time during a system upgrade.
|
||||
@ -735,6 +737,7 @@ final class Settings {
|
||||
} else {
|
||||
mOtherUserIds.remove(uid);
|
||||
}
|
||||
setFirstAvailableUid(uid+1);
|
||||
}
|
||||
|
||||
private void replaceUserIdLPw(int uid, Object obj) {
|
||||
@ -2513,11 +2516,18 @@ final class Settings {
|
||||
file.delete();
|
||||
}
|
||||
|
||||
// This should be called (at least) whenever an application is removed
|
||||
private void setFirstAvailableUid(int uid) {
|
||||
if (uid > mFirstAvailableUid) {
|
||||
mFirstAvailableUid = uid;
|
||||
}
|
||||
}
|
||||
|
||||
// Returns -1 if we could not find an available UserId to assign
|
||||
private int newUserIdLPw(Object obj) {
|
||||
// Let's be stupidly inefficient for now...
|
||||
final int N = mUserIds.size();
|
||||
for (int i = 0; i < N; i++) {
|
||||
for (int i = mFirstAvailableUid; i < N; i++) {
|
||||
if (mUserIds.get(i) == null) {
|
||||
mUserIds.set(i, obj);
|
||||
return Process.FIRST_APPLICATION_UID + i;
|
||||
|
Reference in New Issue
Block a user