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

Commit 661831e2 authored by Felipe Leme's avatar Felipe Leme
Browse files

Moarrr changes on 'cmd user set-system-user-mode-emulation'

- Updates system user packages.
- Fails when system user has a credential.

Test: adb shell cmd user set-system-user-mode-emulation full # on HSUM device
Test: adb shell dumpsys user | grep -A 2 headless
Bug: 226643927

Change-Id: Ia9426912157547e09ed2232a2f5a9d2af2b10aea
parent 3b9744ea
Loading
Loading
Loading
Loading
+18 −5
Original line number Diff line number Diff line
@@ -298,6 +298,9 @@ public class UserManagerService extends IUserManager.Stub {
    private PackageManagerInternal mPmInternal;
    private DevicePolicyManagerInternal mDevicePolicyManagerInternal;

    /** Indicates that this is the 1st boot after the system user mode was changed by emulation. */
    private boolean mUpdatingSystemUserMode;

    /**
     * Internal non-parcelable wrapper for UserInfo that is not exposed to other system apps.
     */
@@ -3006,10 +3009,8 @@ public class UserManagerService extends IUserManager.Stub {
            }
        }

        // TODO(b/203885212): need to update the system user packages; the "easiest way" woulbe
        // be setting "persist.pm.mock-upgrade", but that would require granting a new selinux
        // permission. Another options would be providing an internal API, or setting a
        // debug.xxx property - either way, we'll do that in a follow-up CL
        // Update emulated mode, which will used to triger an update on user packages
        mUpdatingSystemUserMode = true;
    }

    @GuardedBy({"mRestrictionsLock", "mPackagesLock"})
@@ -4356,7 +4357,7 @@ public class UserManagerService extends IUserManager.Stub {
    boolean installWhitelistedSystemPackages(boolean isFirstBoot, boolean isUpgrade,
            @Nullable ArraySet<String> existingPackages) {
        return mSystemPackageInstaller.installWhitelistedSystemPackages(
                isFirstBoot, isUpgrade, existingPackages);
                isFirstBoot || mUpdatingSystemUserMode, isUpgrade, existingPackages);
    }

    @Override
@@ -5759,6 +5760,15 @@ public class UserManagerService extends IUserManager.Stub {
            }

            final PrintWriter pw = getOutPrintWriter();

            // The headless system user cannot be locked; in theory, we could just make this check
            // when going full -> headless, but it doesn't hurt to check on both (and it makes the
            // code simpler)
            if (mLockPatternUtils.isSecure(UserHandle.USER_SYSTEM)) {
                pw.println("Cannot change system user mode when it has a credential");
                return -1;
            }

            final String mode = getNextArgRequired();
            final boolean isHeadlessSystemUserModeCurrently = UserManager
                    .isHeadlessSystemUserMode();
@@ -5916,6 +5926,9 @@ public class UserManagerService extends IUserManager.Stub {
        pw.println("  Is headless-system mode: " + isHeadlessSystemUserMode);
        if (isHeadlessSystemUserMode != isReallyHeadlessSystemUserMode()) {
            pw.println("  (emulated by 'cmd user set-system-user-mode-emulation')");
            if (mUpdatingSystemUserMode) {
                pw.println("  (and being updated after boot)");
            }
        }
        pw.println("  User version: " + mUserVersion);
        pw.println("  Owner name: " + getOwnerName());