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

Commit 07653f0b authored by Felipe Leme's avatar Felipe Leme
Browse files

Fixed guest check so it allows multiple pre-created users.

Also fixed shell cmd so it does not require name for pre-created users

Bug: 111451156
Bug: 132111956

Test: adb shell pm create-user --pre-create-only --guest # couple times

Change-Id: Ie256d55bdfe685f040d16223fcc70f2f2b7969da
(cherry picked from commit e35f5b01)
parent 75166c84
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -2279,10 +2279,14 @@ class PackageManagerShellCommand extends ShellCommand {
            }
        }
        String arg = getNextArg();
        if (arg == null) {
        if (arg == null && !preCreateOnly) {
            getErrPrintWriter().println("Error: no user name specified.");
            return 1;
        }
        if (arg != null && preCreateOnly) {
            getErrPrintWriter().println("Warning: name is ignored for pre-created users");
        }

        name = arg;
        UserInfo info;
        IUserManager um = IUserManager.Stub.asInterface(
+3 −2
Original line number Diff line number Diff line
@@ -2805,7 +2805,7 @@ public class UserManagerService extends IUserManager.Stub {
                    return null;
                }
                // If we're adding a guest and there already exists one, bail.
                if (isGuest && findCurrentGuestUser() != null) {
                if (isGuest && !preCreate && findCurrentGuestUser() != null) {
                    Log.e(LOG_TAG, "Cannot add guest user. Guest user already exists.");
                    return null;
                }
@@ -3044,7 +3044,8 @@ public class UserManagerService extends IUserManager.Stub {
            final int size = mUsers.size();
            for (int i = 0; i < size; i++) {
                final UserInfo user = mUsers.valueAt(i).info;
                if (user.isGuest() && !user.guestToRemove && !mRemovingUserIds.get(user.id)) {
                if (user.isGuest() && !user.guestToRemove && !user.preCreated
                        && !mRemovingUserIds.get(user.id)) {
                    return user;
                }
            }