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

Commit 3742c3c7 authored by Yao Li's avatar Yao Li
Browse files

Boot to headless system user if config_bootToHeadlessSystemUser is true

Only do this under HSUM.

Bug: 350058102
Flag: EXEMPT new code protected by new config
Test: Set the new config to true in a build, boot up, and verify the result from "adb shell ps -e -o USER,UID,NAME | grep systemui" is user 0 (UID is lower than 1000000).
Test: atest FrameworksMockingServicesTests:com.android.server.pm.UserManagerServiceTest
Change-Id: I7cf36a9900cfe01383de9c935781fb00fe80f90c
parent 8ff361bd
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1372,6 +1372,10 @@ public class UserManagerService extends IUserManager.Stub {
        }

        if (isHeadlessSystemUserMode()) {
            if (mContext.getResources()
                    .getBoolean(com.android.internal.R.bool.config_bootToHeadlessSystemUser)) {
                return UserHandle.USER_SYSTEM;
            }
            // Return the previous foreground user, if there is one.
            final int previousUser = getPreviousFullUserToEnterForeground();
            if (previousUser != UserHandle.USER_NULL) {
+19 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import android.app.KeyguardManager;
import android.content.Context;
import android.content.pm.PackageManagerInternal;
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.multiuser.Flags;
import android.os.PowerManager;
import android.os.ServiceSpecificException;
@@ -152,6 +153,7 @@ public final class UserManagerServiceTest {
    private File mTestDir;

    private Context mSpiedContext;
    private Resources mSpyResources;

    private @Mock PackageManagerService mMockPms;
    private @Mock UserDataPreparer mMockUserDataPreparer;
@@ -193,6 +195,13 @@ public final class UserManagerServiceTest {
        doNothing().when(mSpiedContext).sendBroadcastAsUser(any(), any(), any());
        mockIsLowRamDevice(false);

        // Called when getting boot user. config_bootToHeadlessSystemUser is false by default.
        mSpyResources = spy(mSpiedContext.getResources());
        when(mSpiedContext.getResources()).thenReturn(mSpyResources);
        doReturn(false)
                .when(mSpyResources)
                .getBoolean(com.android.internal.R.bool.config_bootToHeadlessSystemUser);

        // Must construct UserManagerService in the UiThread
        mTestDir = new File(mRealContext.getDataDir(), "umstest");
        mTestDir.mkdirs();
@@ -849,6 +858,16 @@ public final class UserManagerServiceTest {
                        USER_TYPE_PROFILE_PRIVATE, 0, mainUser, null));
    }

    @Test
    public void testGetBootUser_enableBootToHeadlessSystemUser() {
        setSystemUserHeadless(true);
        doReturn(true)
                .when(mSpyResources)
                .getBoolean(com.android.internal.R.bool.config_bootToHeadlessSystemUser);

        assertThat(mUms.getBootUser()).isEqualTo(UserHandle.USER_SYSTEM);
    }

    /**
     * Returns true if the user's XML file has Default restrictions
     * @param userId Id of the user.