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

Commit 0cb5ae7a authored by Keun young Park's avatar Keun young Park
Browse files

Do not skip user starting for user 0

- USER_SYSTEM is in special state and startUser call is skipped without changing
  it into running state.
- Force the whole process for user 0 while non-user 0 keep the same behavior
  as it should not happen for those users.

Bug: 124460424
Test: Test system bootup (for 1st boot and subsequent boot)

Change-Id: I7adc6766c0ac33f766e7ca8769f555973f533ba3
parent e339eef4
Loading
Loading
Loading
Loading
+18 −7
Original line number Diff line number Diff line
@@ -956,8 +956,17 @@ class UserController implements Handler.Callback {
            final int oldUserId = getCurrentUserId();
            if (oldUserId == userId) {
                final UserState state = getStartedUserState(userId);
                if (state != null && state.state == STATE_RUNNING_UNLOCKED) {
                    // We'll skip all later code, so we must tell listener it's already unlocked.
                if (state == null) {
                    Slog.wtf(TAG, "Current user has no UserState");
                    // continue starting.
                } else {
                    if (userId == UserHandle.USER_SYSTEM && state.state == STATE_BOOTING) {
                        // system user start explicitly requested. should continue starting as it
                        // is not in running state.
                    } else {
                        if (state.state == STATE_RUNNING_UNLOCKED) {
                            // We'll skip all later code, so we must tell listener it's already
                            // unlocked.
                            try {
                                unlockListener.onFinished(userId, null);
                            } catch (RemoteException ignore) {
@@ -966,6 +975,8 @@ class UserController implements Handler.Callback {
                        }
                        return true;
                    }
                }
            }

            if (foreground) {
                mInjector.clearAllLockedTasks("startUser");
+17 −0
Original line number Diff line number Diff line
@@ -34,7 +34,9 @@ import static com.google.android.collect.Sets.newHashSet;
import static com.google.common.truth.Truth.assertWithMessage;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
@@ -64,6 +66,7 @@ import android.os.IRemoteCallback;
import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManagerInternal;
import android.platform.test.annotations.Presubmit;
import android.util.Log;
@@ -321,6 +324,14 @@ public class UserControllerTest {
        verify(mInjector.getWindowManager(), times(1)).setSwitchingUser(false);
    }

    @Test
    public void testExplicitSystenUserStartInBackground() {
        setUpUser(UserHandle.USER_SYSTEM, 0);
        assertFalse(mUserController.isSystemUserStarted());
        assertTrue(mUserController.startUser(UserHandle.USER_SYSTEM, false, null));
        assertTrue(mUserController.isSystemUserStarted());
    }

    private void setUpUser(int userId, int flags) {
        UserInfo userInfo = new UserInfo(userId, "User" + userId, flags);
        when(mInjector.mUserManagerMock.getUserInfo(eq(userId))).thenReturn(userInfo);
@@ -417,6 +428,12 @@ public class UserControllerTest {
        @Override
        void reportCurWakefulnessUsageEvent() {
        }

        @Override
        boolean isRuntimeRestarted() {
            // to pass all metrics related calls
            return true;
        }
    }

    private static class TestHandler extends Handler {