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

Commit 201e6965 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Created config_designateMainUser." into main

parents 0727926d e2260b7e
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -3263,6 +3263,18 @@
         ignored (as the initial user is the main user). -->
    <bool name="config_createInitialUser">false</bool>

    <!-- Whether the system should "designate" the main user on boot:
         - If it's true and the device doesn't have a main user (meaning it's the first boot or it
           migrated from false to true), then the system will either promote the first admin
           (migration) to be the main user, or create a main user (first boot).
         - If it's false and the device has a main user (meaning it migrated from true to false),
           then the main user will be "demoted" to just an admin.

         Notice that if config_isMainUserPermanentAdmin is true, this config is
         ignored (i.e, the system will act as it was true) as main user is required in this case.
    -->
    <bool name="config_designateMainUser">false</bool>

    <!-- Whether switch to headless system user is allowed. If allowed,
    headless system user can run in the foreground even though it is not a full user. -->
    <bool name="config_canSwitchToHeadlessSystemUser">false</bool>
+1 −0
Original line number Diff line number Diff line
@@ -365,6 +365,7 @@
  <java-symbol type="bool" name="config_isMainUserPermanentAdmin"/>
  <java-symbol type="bool" name="config_supportProfilesOnNonMainUser"/>
  <java-symbol type="bool" name="config_createInitialUser"/>
  <java-symbol type="bool" name="config_designateMainUser"/>
  <java-symbol type="bool" name="config_canSwitchToHeadlessSystemUser"/>
  <java-symbol type="bool" name="config_enableMultiUserUI"/>
  <java-symbol type="bool" name="config_enableMultipleAdmins"/>
+15 −13
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ public final class HsumBootUserInitializer {
            };

    /** Whether it should create a main user on first boot. */
    private final boolean mShouldCreateMainUser;
    private final boolean mShouldDesignateMainUser;

    /** Whether it should create an initial user, but without setting it as the main user. */
    private final boolean mShouldCreateInitialUser;
@@ -78,24 +78,24 @@ public final class HsumBootUserInitializer {
    /** Static factory method for creating a {@link HsumBootUserInitializer} instance. */
    public static @Nullable HsumBootUserInitializer createInstance(UserManagerService ums,
            ActivityManagerService ams, PackageManagerService pms, ContentResolver contentResolver,
            boolean shouldCreateInitialUser) {
            boolean shouldDesignateMainUser, boolean shouldCreateInitialUser) {

        if (!UserManager.isHeadlessSystemUserMode()) {
            return null;
        }
        return new HsumBootUserInitializer(ums, ams, pms, contentResolver,
                ums.isMainUserPermanentAdmin(), shouldCreateInitialUser);
                shouldDesignateMainUser, shouldCreateInitialUser);
    }

    @VisibleForTesting
    HsumBootUserInitializer(UserManagerService ums, ActivityManagerService ams,
            PackageManagerService pms, ContentResolver contentResolver,
            boolean shouldCreateMainUser, boolean shouldCreateInitialUser) {
            boolean shouldDesignateMainUser, boolean shouldCreateInitialUser) {
        mUms = ums;
        mAms = ams;
        mPms = pms;
        mContentResolver = contentResolver;
        mShouldCreateMainUser = shouldCreateMainUser;
        mShouldDesignateMainUser = shouldDesignateMainUser;
        mShouldCreateInitialUser = shouldCreateInitialUser;
    }

@@ -105,7 +105,7 @@ public final class HsumBootUserInitializer {
            Slogf.d(TAG, "preCreateInitialUserFlagInit())");
        }

        if (mShouldCreateMainUser) {
        if (mShouldDesignateMainUser) {
            t.traceBegin("createMainUserIfNeeded");
            preCreateInitialUserCreateMainUserIfNeeded();
            t.traceEnd();
@@ -153,9 +153,9 @@ public final class HsumBootUserInitializer {
     */
    public void init(TimingsTraceAndSlog t) {
        if (DEBUG) {
            Slogf.d(TAG, "init(): shouldCreateMainUser=%b, shouldCreateInitialUser=%b, "
            Slogf.d(TAG, "init(): mShouldDesignateMainUser=%b, shouldCreateInitialUser=%b, "
                    + "Flags.createInitialUser=%b",
                    mShouldCreateMainUser, mShouldCreateInitialUser, Flags.createInitialUser());
                    mShouldDesignateMainUser, mShouldCreateInitialUser, Flags.createInitialUser());
        } else {
            Slogf.i(TAG, "Initializing");
        }
@@ -169,8 +169,8 @@ public final class HsumBootUserInitializer {
        int mainUserId = mUms.getMainUserId();
        t.traceEnd();

        if (mShouldCreateMainUser) {
            createMainUserIfNeeded(t, mainUserId);
        if (mShouldDesignateMainUser) {
            designateMainUserIfNeeded(t, mainUserId);
            return;
        }

@@ -187,13 +187,15 @@ public final class HsumBootUserInitializer {
        }
    }

    private void createMainUserIfNeeded(TimingsTraceAndSlog t, @UserIdInt int mainUserId) {
        // Always tracing as it used to be done by the caller
    private void designateMainUserIfNeeded(TimingsTraceAndSlog t, @UserIdInt int mainUserId) {
        // Always tracing as it used to be done by the caller - removing it (as createInitialUser
        // also traces) could break existing performance tests (for that same reason, the name in
        // trace call is not changed)
        t.traceBegin("createMainUserIfNeeded");
        try {
            if (mainUserId != UserHandle.USER_NULL) {
                if (DEBUG) {
                    Slogf.d(TAG, "createMainUserIfNeeded(): found MainUser (userId=%d)",
                    Slogf.d(TAG, "designateMainUserIfNeeded(): found MainUser (userId=%d)",
                            mainUserId);
                }
                return;
+35 −2
Original line number Diff line number Diff line
@@ -552,6 +552,13 @@ public final class SystemServer implements Dumpable {
    private static final String SYSPROP_FDTRACK_INTERVAL =
            "persist.sys.debug.fdtrack_interval";

    /**
     * Property used to override (for development purposes, on debuggable builds) the resource
     * configs used by {@link #designateMainUserOnBoot()}
     */
    private static final String SYSPROP_DESIGNATE_MAIN_USER = "fw.designate_main_user_on_boot";


    private static int getMaxFd() {
        FileDescriptor fd = null;
        try {
@@ -721,6 +728,33 @@ public final class SystemServer implements Dumpable {
        TimeUtils.formatDuration(mRuntimeStartUptime, pw); pw.println();
        pw.print("Runtime start-elapsed time: ");
        TimeUtils.formatDuration(mRuntimeStartElapsedTime, pw); pw.println();

        var res = mSystemContext.getResources();
        pw.print("Designate main user on boot: ");
        pw.println(designateMainUserOnBoot());
        pw.print("  config_designateMainUser: ");
        pw.print(res.getBoolean(R.bool.config_designateMainUser));
        pw.print(" config_isMainUserPermanentAdmin: ");
        pw.print(res.getBoolean(R.bool.config_isMainUserPermanentAdmin));
        pw.print(" " + SYSPROP_DESIGNATE_MAIN_USER + ": ");
        pw.println(SystemProperties.get(SYSPROP_DESIGNATE_MAIN_USER, "N/A"));

        pw.print("Create initial user on boot: ");
        pw.println(createInitialUserOnBoot());
    }

    private boolean designateMainUserOnBoot() {
        var res = mSystemContext.getResources();
        boolean defaultValue = res.getBoolean(R.bool.config_designateMainUser)
                || res.getBoolean(R.bool.config_isMainUserPermanentAdmin);
        if (!Build.isDebuggable()) {
            return defaultValue;
        }
        return SystemProperties.getBoolean(SYSPROP_DESIGNATE_MAIN_USER, defaultValue);
    }

    private boolean createInitialUserOnBoot() {
        return mSystemContext.getResources().getBoolean(R.bool.config_createInitialUser);
    }

    /**
@@ -3043,8 +3077,7 @@ public final class SystemServer implements Dumpable {
        final HsumBootUserInitializer hsumBootUserInitializer =
                HsumBootUserInitializer.createInstance(mUserManagerService, mActivityManagerService,
                        mPackageManagerService, mContentResolver,
                        context.getResources().getBoolean(R.bool.config_createInitialUser)
                        );
                        designateMainUserOnBoot(), createInitialUserOnBoot());
        if (hsumBootUserInitializer != null) {
            t.traceBegin("HsumBootUserInitializer.init");
            hsumBootUserInitializer.init(t);