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

Commit 1cf42893 authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Android Git Automerger
Browse files

am 8f2ec436: am 1e5aeecb: Merge "Don\'t allow more than 3 actively running...

am 8f2ec436: am 1e5aeecb: Merge "Don\'t allow more than 3 actively running users at a time." into jb-mr1-dev

* commit '8f2ec436':
  Don't allow more than 3 actively running users at a time.
parents 6f3fd45b 8f2ec436
Loading
Loading
Loading
Loading
+76 −41
Original line number Diff line number Diff line
@@ -253,6 +253,9 @@ public final class ActivityManagerService extends ActivityManagerNative
    // giving up on them and unfreezing the screen.
    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 String[] EMPTY_STRING_ARRAY = new String[0];
@@ -14125,6 +14128,33 @@ public final class ActivityManagerService extends ActivityManagerNative
                        android.Manifest.permission.RECEIVE_BOOT_COMPLETED,
                        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++;
            }
        }
    }
@@ -14143,6 +14173,11 @@ public final class ActivityManagerService extends ActivityManagerNative
            throw new IllegalArgumentException("Can't stop primary user " + userId);
        }
        synchronized (this) {
            return stopUserLocked(userId, callback);
        }
    }
    private int stopUserLocked(final int userId, final IStopUserCallback callback) {
        if (mCurrentUserId == userId) {
            return ActivityManager.USER_OP_IS_CURRENT;
        }
@@ -14190,7 +14225,6 @@ public final class ActivityManagerService extends ActivityManagerNative
                Binder.restoreCallingIdentity(ident);
            }
        }
        }
        return ActivityManager.USER_OP_SUCCESS;
    }
@@ -14208,6 +14242,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                stopped = true;
                // User can no longer run.
                mStartedUsers.remove(userId);
                mUserLru.remove(Integer.valueOf(userId));
                // Clean up all state and processes associated with the user.
                // Kill all the processes for the user.