Loading services/core/java/com/android/server/pm/UserManagerService.java +21 −18 Original line number Diff line number Diff line Loading @@ -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)) { Loading @@ -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) { Loading @@ -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"); } } } Loading Loading @@ -3817,12 +3818,14 @@ public class UserManagerService extends IUserManager.Stub { if (userVersion < 11) { // Add FLAG_MAIN if (isHeadlessSystemUserMode()) { 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; Loading services/core/java/com/android/server/pm/UserManagerServiceShellCommand.java +1 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading
services/core/java/com/android/server/pm/UserManagerService.java +21 −18 Original line number Diff line number Diff line Loading @@ -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)) { Loading @@ -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) { Loading @@ -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"); } } } Loading Loading @@ -3817,12 +3818,14 @@ public class UserManagerService extends IUserManager.Stub { if (userVersion < 11) { // Add FLAG_MAIN if (isHeadlessSystemUserMode()) { 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; Loading
services/core/java/com/android/server/pm/UserManagerServiceShellCommand.java +1 −0 Original line number Diff line number Diff line Loading @@ -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 Loading