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

Commit cfc85c89 authored by Keun-young Park's avatar Keun-young Park Committed by Android (Google) Code Review
Browse files

Merge changes from topic "car_user"

* changes:
  Do not skip user starting for user 0
  Revert "Revert "Decide the current user after PHASE_THIRD_PARTY boot phase""
parents bc9f5a51 0cb5ae7a
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -8835,7 +8835,6 @@ public class ActivityManagerService extends IActivityManager.Stub
        mAtmInternal.updateTopComponentForFactoryTest();
        retrieveSettings();
        final int currentUserId = mUserController.getCurrentUserId();
        mUgmInternal.onSystemReady();
        final PowerManagerInternal pmi = LocalServices.getService(PowerManagerInternal.class);
@@ -8849,6 +8848,16 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
        if (goingCallback != null) goingCallback.run();
        // Check the current user here as a user can be started inside goingCallback.run() from
        // other system services.
        final int currentUserId = mUserController.getCurrentUserId();
        Slog.i(TAG, "Current user:" + currentUserId);
        if (currentUserId != UserHandle.USER_SYSTEM && !mUserController.isSystemUserStarted()) {
            // User other than system user has started. Make sure that system user is already
            // started before switching user.
            throw new RuntimeException("System user not started while current user is:"
                    + currentUserId);
        }
        traceLog.traceBegin("ActivityManagerStartApps");
        mBatteryStatsService.noteEvent(BatteryStats.HistoryItem.EVENT_USER_RUNNING_START,
                Integer.toString(currentUserId), currentUserId);
+36 −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");
@@ -1743,6 +1754,24 @@ class UserController implements Handler.Callback {
        return state.state != UserState.STATE_STOPPING && state.state != UserState.STATE_SHUTDOWN;
    }

    /**
     * Check if system user is already started. Unlike other user, system user is in STATE_BOOTING
     * even if it is not explicitly started. So isUserRunning cannot give the right state
     * to check if system user is started or not.
     * @return true if system user is started.
     */
    boolean isSystemUserStarted() {
        synchronized (mLock) {
            UserState uss = mStartedUsers.get(UserHandle.USER_SYSTEM);
            if (uss == null) {
                return false;
            }
            return uss.state == UserState.STATE_RUNNING_LOCKED
                || uss.state == UserState.STATE_RUNNING_UNLOCKING
                || uss.state == UserState.STATE_RUNNING_UNLOCKED;
        }
    }

    UserInfo getCurrentUser() {
        if ((mInjector.checkCallingPermission(INTERACT_ACROSS_USERS)
                != PackageManager.PERMISSION_GRANTED) && (
+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 {