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

Commit ff2d9147 authored by Oli Lan's avatar Oli Lan Committed by Automerger Merge Worker
Browse files

Merge "Delay boot complete broadcast for main user on HSUM." into udc-dev am: 0ad77cb1

parents 869bbe90 0ad77cb1
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -583,7 +583,10 @@ class UserController implements Handler.Callback {
                // user transitions to RUNNING_LOCKED.  However, in "headless system user mode", the
                // system user is explicitly started before the device has finished booting.  In
                // that case, we need to wait until onBootComplete() to send the broadcast.
                if (!(mInjector.isHeadlessSystemUserMode() && uss.mHandle.isSystem())) {
                // Similarly, this occurs after a user switch, but in HSUM we switch to the main
                // user before boot is complete, so again this should be delayed until
                // onBootComplete if boot has not yet completed.
                if (mAllowUserUnlocking) {
                    // ACTION_LOCKED_BOOT_COMPLETED
                    sendLockedBootCompletedBroadcast(resultTo, userId);
                }
@@ -2564,9 +2567,9 @@ class UserController implements Handler.Callback {
        // we should *not* transition users out of the BOOTING state using finishUserBoot(), as that
        // doesn't handle issuing the needed onUserStarting() call, and it would just race with an
        // explicit start anyway.  We do, however, need to send the "locked boot complete" broadcast
        // for the system user, as that got skipped earlier due to the *device* boot not being
        // complete yet.  We also need to try to unlock all started users, since until now explicit
        // user starts didn't proceed to unlocking, due to it being too early in the device boot.
        // as that got skipped earlier due to the *device* boot not being complete yet.
        // We also need to try to unlock all started users, since until now explicit user starts
        // didn't proceed to unlocking, due to it being too early in the device boot.
        //
        // USER_SYSTEM must be processed first.  It will be first in the array, as its ID is lowest.
        Preconditions.checkArgument(startedUsers.keyAt(0) == UserHandle.USER_SYSTEM);
@@ -2576,9 +2579,7 @@ class UserController implements Handler.Callback {
            if (!mInjector.isHeadlessSystemUserMode()) {
                finishUserBoot(uss, resultTo);
            } else {
                if (userId == UserHandle.USER_SYSTEM) {
                sendLockedBootCompletedBroadcast(resultTo, userId);
                }
                maybeUnlockUser(userId);
            }
        }
+25 −1
Original line number Diff line number Diff line
@@ -200,6 +200,7 @@ public class UserControllerTest {
            mUserController.setAllowUserUnlocking(true);
            setUpUser(TEST_USER_ID, NO_USERINFO_FLAGS);
            setUpUser(TEST_PRE_CREATED_USER_ID, NO_USERINFO_FLAGS, /* preCreated= */ true, null);
            mInjector.mRelevantUser = null;
        });
    }

@@ -232,6 +233,25 @@ public class UserControllerTest {
        verifyUserAssignedToDisplay(TEST_USER_ID, Display.DEFAULT_DISPLAY);
    }

    @Test
    public void testStartUser_background_duringBootHsum() {
        mockIsHeadlessSystemUserMode(true);
        mUserController.setAllowUserUnlocking(false);
        mInjector.mRelevantUser = TEST_USER_ID;
        boolean started = mUserController.startUser(TEST_USER_ID, USER_START_MODE_BACKGROUND);
        assertWithMessage("startUser(%s, foreground=false)", TEST_USER_ID).that(started).isTrue();

        // ACTION_LOCKED_BOOT_COMPLETED not sent yet
        startUserAssertions(newArrayList(Intent.ACTION_USER_STARTED, Intent.ACTION_USER_STARTING),
                START_BACKGROUND_USER_MESSAGE_CODES);

        mUserController.onBootComplete(null);

        startUserAssertions(newArrayList(Intent.ACTION_USER_STARTED, Intent.ACTION_USER_STARTING,
                        Intent.ACTION_LOCKED_BOOT_COMPLETED),
                START_BACKGROUND_USER_MESSAGE_CODES);
    }

    @Test
    public void testStartUser_sendsNoBroadcastsForSystemUserInNonHeadlessMode() {
        setUpUser(SYSTEM_USER_ID, UserInfo.FLAG_SYSTEM, /* preCreated= */ false,
@@ -1079,6 +1099,8 @@ public class UserControllerTest {

        private final Context mCtx;

        private Integer mRelevantUser;

        TestInjector(Context ctx) {
            super(null);
            mCtx = ctx;
@@ -1166,7 +1188,9 @@ public class UserControllerTest {
                boolean sticky, int callingPid, int callingUid, int realCallingUid,
                int realCallingPid, int userId) {
            Log.i(TAG, "broadcastIntentLocked " + intent);
            if (mRelevantUser == null || mRelevantUser == userId || userId == UserHandle.USER_ALL) {
                mSentIntents.add(intent);
            }
            return 0;
        }