diff options
| -rw-r--r-- | services/core/java/com/android/server/pm/UserManagerService.java | 39 | ||||
| -rw-r--r-- | services/core/java/com/android/server/pm/UserManagerServiceShellCommand.java | 1 |
2 files changed, 22 insertions, 18 deletions
diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java index 2f98d3485d90..334317281a1c 100644 --- a/services/core/java/com/android/server/pm/UserManagerService.java +++ b/services/core/java/com/android/server/pm/UserManagerService.java @@ -3504,15 +3504,15 @@ public class UserManagerService extends IUserManager.Stub { return; } final int oldMainUserId = getMainUserIdUnchecked(); - final int oldFlags = systemUserData.info.flags; - final int newFlags; + final int oldSysFlags = systemUserData.info.flags; + final int newSysFlags; final String newUserType; if (newHeadlessSystemUserMode) { newUserType = UserManager.USER_TYPE_SYSTEM_HEADLESS; - newFlags = oldFlags & ~UserInfo.FLAG_FULL & ~UserInfo.FLAG_MAIN; + newSysFlags = oldSysFlags & ~UserInfo.FLAG_FULL & ~UserInfo.FLAG_MAIN; } else { newUserType = UserManager.USER_TYPE_FULL_SYSTEM; - newFlags = oldFlags | UserInfo.FLAG_FULL; + newSysFlags = oldSysFlags | UserInfo.FLAG_FULL | UserInfo.FLAG_MAIN; } if (systemUserData.info.userType.equals(newUserType)) { @@ -3523,18 +3523,19 @@ public class UserManagerService extends IUserManager.Stub { Slogf.i(LOG_TAG, "Persisting emulated system user data: type changed from %s to " + "%s, flags changed from %s to %s", systemUserData.info.userType, newUserType, - UserInfo.flagsToString(oldFlags), UserInfo.flagsToString(newFlags)); + UserInfo.flagsToString(oldSysFlags), UserInfo.flagsToString(newSysFlags)); systemUserData.info.userType = newUserType; - systemUserData.info.flags = newFlags; + systemUserData.info.flags = newSysFlags; writeUserLP(systemUserData); - // Switch the MainUser to a reasonable choice if needed. - // (But if there was no MainUser, we deliberately continue to have no MainUser.) + // Designate the MainUser to a reasonable choice if needed. final UserData oldMain = getUserDataNoChecks(oldMainUserId); if (newHeadlessSystemUserMode) { - if (oldMain != null && (oldMain.info.flags & UserInfo.FLAG_SYSTEM) != 0) { - // System was MainUser. So we need a new choice for Main. Pick the oldest. + final boolean mainIsAlreadyNonSystem = + oldMain != null && (oldMain.info.flags & UserInfo.FLAG_SYSTEM) == 0; + if (!mainIsAlreadyNonSystem && isMainUserPermanentAdmin()) { + // We need a new choice for Main. Pick the oldest. // If no oldest, don't set any. Let the BootUserInitializer do that later. final UserInfo newMainUser = getEarliestCreatedFullUser(); if (newMainUser != null) { @@ -3544,16 +3545,16 @@ public class UserManagerService extends IUserManager.Stub { } } } else { + // We already made user 0 Main above. Now strip it from the old Main user. // TODO(b/256624031): For now, we demand the Main user (if there is one) is // always the system in non-HSUM. In the future, when we relax this, change how // we handle MAIN. if (oldMain != null && (oldMain.info.flags & UserInfo.FLAG_SYSTEM) == 0) { - // Someone else was the MainUser; transfer it to System. Slogf.i(LOG_TAG, "Transferring Main to user 0 from " + oldMain.info.id); oldMain.info.flags &= ~UserInfo.FLAG_MAIN; - systemUserData.info.flags |= UserInfo.FLAG_MAIN; writeUserLP(oldMain); - writeUserLP(systemUserData); + } else { + Slogf.i(LOG_TAG, "Designated user 0 to be Main"); } } } @@ -3817,12 +3818,14 @@ public class UserManagerService extends IUserManager.Stub { if (userVersion < 11) { // Add FLAG_MAIN if (isHeadlessSystemUserMode()) { - final UserInfo earliestCreatedUser = getEarliestCreatedFullUser(); - if (earliestCreatedUser != null) { - earliestCreatedUser.flags |= UserInfo.FLAG_MAIN; - userIdsToWrite.add(earliestCreatedUser.id); + if (isMainUserPermanentAdmin()) { + final UserInfo earliestCreatedUser = getEarliestCreatedFullUser(); + if (earliestCreatedUser != null) { + earliestCreatedUser.flags |= UserInfo.FLAG_MAIN; + userIdsToWrite.add(earliestCreatedUser.id); + } } - } else { + } else { // not isHeadlessSystemUserMode synchronized (mUsersLock) { final UserData userData = mUsers.get(UserHandle.USER_SYSTEM); userData.info.flags |= UserInfo.FLAG_MAIN; diff --git a/services/core/java/com/android/server/pm/UserManagerServiceShellCommand.java b/services/core/java/com/android/server/pm/UserManagerServiceShellCommand.java index 98b24ea34853..333c98c4818d 100644 --- a/services/core/java/com/android/server/pm/UserManagerServiceShellCommand.java +++ b/services/core/java/com/android/server/pm/UserManagerServiceShellCommand.java @@ -380,6 +380,7 @@ public class UserManagerServiceShellCommand extends ShellCommand { final int pid = Process.myPid(); Slogf.i(LOG_TAG, "Restarting Android runtime(PID=%d) to finalize changes", pid); pw.println("Restarting Android runtime to finalize changes"); + pw.println("The restart may trigger a 'Broken pipe' message; this is to be expected."); pw.flush(); // Ideally there should be a cleaner / safer option to restart system_server, but |