Loading services/core/java/com/android/server/am/UserController.java +8 −7 Original line number Diff line number Diff line Loading @@ -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); } Loading Loading @@ -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); Loading @@ -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); } } Loading services/tests/servicestests/src/com/android/server/am/UserControllerTest.java +25 −1 Original line number Diff line number Diff line Loading @@ -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; }); } Loading Loading @@ -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, Loading Loading @@ -1079,6 +1099,8 @@ public class UserControllerTest { private final Context mCtx; private Integer mRelevantUser; TestInjector(Context ctx) { super(null); mCtx = ctx; Loading Loading @@ -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; } Loading Loading
services/core/java/com/android/server/am/UserController.java +8 −7 Original line number Diff line number Diff line Loading @@ -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); } Loading Loading @@ -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); Loading @@ -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); } } Loading
services/tests/servicestests/src/com/android/server/am/UserControllerTest.java +25 −1 Original line number Diff line number Diff line Loading @@ -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; }); } Loading Loading @@ -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, Loading Loading @@ -1079,6 +1099,8 @@ public class UserControllerTest { private final Context mCtx; private Integer mRelevantUser; TestInjector(Context ctx) { super(null); mCtx = ctx; Loading Loading @@ -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; } Loading