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

Commit 806c3c9c authored by Oli Lan's avatar Oli Lan
Browse files

Device provisioned / user setup complete changes in HsumBootUserInitializer.

With this change, we no longer set the DEVICE_PROVISIONED flag in
HsumBootUserInitializer, as the flag is set at the end of setup,
as intended.

For consistency with the non-HSUM configuration, we also set
USER_SETUP_COMPLETE for user 0 only when the device has been set up
at least once (i.e. only when DEVICE_PROVISIONED is true).

Bug: 261791491
Test: flash, check flag values, set up device, check flags again
Change-Id: I7e11661864200c477168b1089d14b5476736e597
parent f761035d
Loading
Loading
Loading
Loading
+25 −11
Original line number Diff line number Diff line
@@ -19,6 +19,9 @@ import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.content.ContentResolver;
import android.content.pm.UserInfo;
import android.database.ContentObserver;
import android.os.Handler;
import android.os.Looper;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
@@ -40,6 +43,21 @@ final class HsumBootUserInitializer {
    private final ActivityManagerService mAms;
    private final ContentResolver mContentResolver;

    private final ContentObserver mDeviceProvisionedObserver =
            new ContentObserver(new Handler(Looper.getMainLooper())) {
                @Override
                public void onChange(boolean selfChange) {
                    // Set USER_SETUP_COMPLETE for the (headless) system user only when the device
                    // has been set up at least once.
                    if (isDeviceProvisioned()) {
                        Slogf.i(TAG, "Marking USER_SETUP_COMPLETE for system user");
                        Settings.Secure.putInt(mContentResolver,
                                Settings.Secure.USER_SETUP_COMPLETE, 1);
                        mContentResolver.unregisterContentObserver(mDeviceProvisionedObserver);
                    }
                }
            };

    /** Whether this device should always have a non-removable MainUser, including at first boot. */
    private final boolean mShouldAlwaysHaveMainUser;

@@ -72,10 +90,6 @@ final class HsumBootUserInitializer {
    public void init(TimingsTraceAndSlog t) {
        Slogf.i(TAG, "init())");

        // TODO(b/204091126): in the long term, we need to decide who's reponsible for that,
        // this class or the setup wizard app
        provisionHeadlessSystemUser();

        if (mShouldAlwaysHaveMainUser) {
            t.traceBegin("createMainUserIfNeeded");
            createMainUserIfNeeded();
@@ -115,6 +129,7 @@ final class HsumBootUserInitializer {
     * apps have had the chance to set the boot user, if applicable.
     */
    public void systemRunning(TimingsTraceAndSlog t) {
        observeDeviceProvisioning();
        unlockSystemUser(t);

        try {
@@ -129,17 +144,16 @@ final class HsumBootUserInitializer {
        }
    }

    /* TODO(b/261791491): STOPSHIP - SUW should be responsible for this. */
    private void provisionHeadlessSystemUser() {
    private void observeDeviceProvisioning() {
        if (isDeviceProvisioned()) {
            Slogf.d(TAG, "provisionHeadlessSystemUser(): already provisioned");
            return;
        }

        Slogf.i(TAG, "Marking USER_SETUP_COMPLETE for system user");
        Settings.Secure.putInt(mContentResolver, Settings.Secure.USER_SETUP_COMPLETE, 1);
        Slogf.i(TAG, "Marking DEVICE_PROVISIONED for system user");
        Settings.Global.putInt(mContentResolver, Settings.Global.DEVICE_PROVISIONED, 1);
        mContentResolver.registerContentObserver(
                Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED),
                false,
                mDeviceProvisionedObserver
        );
    }

    private boolean isDeviceProvisioned() {