Loading services/java/com/android/server/am/ActivityManagerService.java +76 −41 Original line number Original line Diff line number Diff line Loading @@ -253,6 +253,9 @@ public final class ActivityManagerService extends ActivityManagerNative // giving up on them and unfreezing the screen. // giving up on them and unfreezing the screen. static final int USER_SWITCH_TIMEOUT = 2*1000; static final int USER_SWITCH_TIMEOUT = 2*1000; // Maximum number of users we allow to be running at a time. static final int MAX_RUNNING_USERS = 3; static final int MY_PID = Process.myPid(); static final int MY_PID = Process.myPid(); static final String[] EMPTY_STRING_ARRAY = new String[0]; static final String[] EMPTY_STRING_ARRAY = new String[0]; Loading Loading @@ -14123,6 +14126,33 @@ public final class ActivityManagerService extends ActivityManagerNative android.Manifest.permission.RECEIVE_BOOT_COMPLETED, android.Manifest.permission.RECEIVE_BOOT_COMPLETED, false, false, MY_PID, Process.SYSTEM_UID, userId); false, false, MY_PID, Process.SYSTEM_UID, userId); } } int num = mUserLru.size(); int i = 0; while (num > MAX_RUNNING_USERS && i < mUserLru.size()) { Integer oldUserId = mUserLru.get(i); UserStartedState oldUss = mStartedUsers.get(oldUserId); if (oldUss == null) { // Shouldn't happen, but be sane if it does. mUserLru.remove(i); num--; continue; } if (oldUss.mState == UserStartedState.STATE_STOPPING) { // This user is already stopping, doesn't count. num--; i++; continue; } if (oldUserId == UserHandle.USER_OWNER || oldUserId == mCurrentUserId) { // Owner and current can't be stopped, but count as running. i++; continue; } // This is a user to be stopped. stopUserLocked(oldUserId, null); num--; i++; } } } } } Loading @@ -14141,6 +14171,11 @@ public final class ActivityManagerService extends ActivityManagerNative throw new IllegalArgumentException("Can't stop primary user " + userId); throw new IllegalArgumentException("Can't stop primary user " + userId); } } synchronized (this) { synchronized (this) { return stopUserLocked(userId, callback); } } private int stopUserLocked(final int userId, final IStopUserCallback callback) { if (mCurrentUserId == userId) { if (mCurrentUserId == userId) { return ActivityManager.USER_OP_IS_CURRENT; return ActivityManager.USER_OP_IS_CURRENT; } } Loading Loading @@ -14188,7 +14223,6 @@ public final class ActivityManagerService extends ActivityManagerNative Binder.restoreCallingIdentity(ident); Binder.restoreCallingIdentity(ident); } } } } } return ActivityManager.USER_OP_SUCCESS; return ActivityManager.USER_OP_SUCCESS; } } Loading @@ -14206,6 +14240,7 @@ public final class ActivityManagerService extends ActivityManagerNative stopped = true; stopped = true; // User can no longer run. // User can no longer run. mStartedUsers.remove(userId); mStartedUsers.remove(userId); mUserLru.remove(Integer.valueOf(userId)); // Clean up all state and processes associated with the user. // Clean up all state and processes associated with the user. // Kill all the processes for the user. // Kill all the processes for the user. Loading
services/java/com/android/server/am/ActivityManagerService.java +76 −41 Original line number Original line Diff line number Diff line Loading @@ -253,6 +253,9 @@ public final class ActivityManagerService extends ActivityManagerNative // giving up on them and unfreezing the screen. // giving up on them and unfreezing the screen. static final int USER_SWITCH_TIMEOUT = 2*1000; static final int USER_SWITCH_TIMEOUT = 2*1000; // Maximum number of users we allow to be running at a time. static final int MAX_RUNNING_USERS = 3; static final int MY_PID = Process.myPid(); static final int MY_PID = Process.myPid(); static final String[] EMPTY_STRING_ARRAY = new String[0]; static final String[] EMPTY_STRING_ARRAY = new String[0]; Loading Loading @@ -14123,6 +14126,33 @@ public final class ActivityManagerService extends ActivityManagerNative android.Manifest.permission.RECEIVE_BOOT_COMPLETED, android.Manifest.permission.RECEIVE_BOOT_COMPLETED, false, false, MY_PID, Process.SYSTEM_UID, userId); false, false, MY_PID, Process.SYSTEM_UID, userId); } } int num = mUserLru.size(); int i = 0; while (num > MAX_RUNNING_USERS && i < mUserLru.size()) { Integer oldUserId = mUserLru.get(i); UserStartedState oldUss = mStartedUsers.get(oldUserId); if (oldUss == null) { // Shouldn't happen, but be sane if it does. mUserLru.remove(i); num--; continue; } if (oldUss.mState == UserStartedState.STATE_STOPPING) { // This user is already stopping, doesn't count. num--; i++; continue; } if (oldUserId == UserHandle.USER_OWNER || oldUserId == mCurrentUserId) { // Owner and current can't be stopped, but count as running. i++; continue; } // This is a user to be stopped. stopUserLocked(oldUserId, null); num--; i++; } } } } } Loading @@ -14141,6 +14171,11 @@ public final class ActivityManagerService extends ActivityManagerNative throw new IllegalArgumentException("Can't stop primary user " + userId); throw new IllegalArgumentException("Can't stop primary user " + userId); } } synchronized (this) { synchronized (this) { return stopUserLocked(userId, callback); } } private int stopUserLocked(final int userId, final IStopUserCallback callback) { if (mCurrentUserId == userId) { if (mCurrentUserId == userId) { return ActivityManager.USER_OP_IS_CURRENT; return ActivityManager.USER_OP_IS_CURRENT; } } Loading Loading @@ -14188,7 +14223,6 @@ public final class ActivityManagerService extends ActivityManagerNative Binder.restoreCallingIdentity(ident); Binder.restoreCallingIdentity(ident); } } } } } return ActivityManager.USER_OP_SUCCESS; return ActivityManager.USER_OP_SUCCESS; } } Loading @@ -14206,6 +14240,7 @@ public final class ActivityManagerService extends ActivityManagerNative stopped = true; stopped = true; // User can no longer run. // User can no longer run. mStartedUsers.remove(userId); mStartedUsers.remove(userId); mUserLru.remove(Integer.valueOf(userId)); // Clean up all state and processes associated with the user. // Clean up all state and processes associated with the user. // Kill all the processes for the user. // Kill all the processes for the user.