Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 634cf313 authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Fix serial number assignment for new user on a freshly wiped device

Bug: 7280093

User serial number was not being bumped up from 0 on a freshly wiped device
due to the userlist not existing. This was resulting in the first 2 users
getting the same serial number, messing up C2DM message delivery. This issue
doesn't show up if you boot the device before adding a user, so it wasn't
discovered earlier.

Change-Id: I8a5d99b9ad2ccfb66a16cacac9548ba53f0be387
parent 33c36895
Loading
Loading
Loading
Loading
+5 −2
Original line number Original line Diff line number Diff line
@@ -78,6 +78,8 @@ public class UserManagerService extends IUserManager.Stub {
    private static final String USER_LIST_FILENAME = "userlist.xml";
    private static final String USER_LIST_FILENAME = "userlist.xml";
    private static final String USER_PHOTO_FILENAME = "photo.png";
    private static final String USER_PHOTO_FILENAME = "photo.png";


    private static final int MIN_USER_ID = 10;

    private static final long EPOCH_PLUS_30_YEARS = 30L * 365 * 24 * 60 * 60 * 1000L; // ms
    private static final long EPOCH_PLUS_30_YEARS = 30L * 365 * 24 * 60 * 60 * 1000L; // ms


    private final Context mContext;
    private final Context mContext;
@@ -459,6 +461,7 @@ public class UserManagerService extends IUserManager.Stub {
        UserInfo primary = new UserInfo(0, "Primary", null,
        UserInfo primary = new UserInfo(0, "Primary", null,
                UserInfo.FLAG_ADMIN | UserInfo.FLAG_PRIMARY);
                UserInfo.FLAG_ADMIN | UserInfo.FLAG_PRIMARY);
        mUsers.put(0, primary);
        mUsers.put(0, primary);
        mNextSerialNumber = MIN_USER_ID;
        updateUserIdsLocked();
        updateUserIdsLocked();


        writeUserListLocked();
        writeUserListLocked();
@@ -832,7 +835,7 @@ public class UserManagerService extends IUserManager.Stub {
     */
     */
    private int getNextAvailableIdLocked() {
    private int getNextAvailableIdLocked() {
        synchronized (mPackagesLock) {
        synchronized (mPackagesLock) {
            int i = 10;
            int i = MIN_USER_ID;
            while (i < Integer.MAX_VALUE) {
            while (i < Integer.MAX_VALUE) {
                if (mUsers.indexOfKey(i) < 0 && !mRemovingUserIds.contains(i)) {
                if (mUsers.indexOfKey(i) < 0 && !mRemovingUserIds.contains(i)) {
                    break;
                    break;
@@ -862,7 +865,7 @@ public class UserManagerService extends IUserManager.Stub {
            for (int i = 0; i < mUsers.size(); i++) {
            for (int i = 0; i < mUsers.size(); i++) {
                UserInfo user = mUsers.valueAt(i);
                UserInfo user = mUsers.valueAt(i);
                if (user == null) continue;
                if (user == null) continue;
                pw.print("  "); pw.print(user);
                pw.print("  "); pw.print(user); pw.print(" serialNo="); pw.print(user.serialNumber);
                if (mRemovingUserIds.contains(mUsers.keyAt(i))) pw.print(" <removing> ");
                if (mRemovingUserIds.contains(mUsers.keyAt(i))) pw.print(" <removing> ");
                if (user.partial) pw.print(" <partial>");
                if (user.partial) pw.print(" <partial>");
                pw.println();
                pw.println();