[ActivityManager] Fix index out of bounds when updating next pss time.

Symptom:
System server crash.

Root Cause:
The value curProcState for array index is -1 if the process
has not attached yet.

Solution:
Skip computing for process which is not attached or curProcState
is nonexistent state.

Change-Id: I71aaf45bb78d73097ebe9dfebf76b72f2d243232
This commit is contained in:
riddle_hsu
2015-03-31 11:54:14 +08:00
parent 02c4bbb964
commit 6793fc328a
2 changed files with 13 additions and 7 deletions

View File

@@ -17667,8 +17667,12 @@ public final class ActivityManagerService extends ActivityManagerNative
mFullPssPending = true;
mPendingPssProcesses.ensureCapacity(mLruProcesses.size());
mPendingPssProcesses.clear();
for (int i=mLruProcesses.size()-1; i>=0; i--) {
for (int i = mLruProcesses.size() - 1; i >= 0; i--) {
ProcessRecord app = mLruProcesses.get(i);
if (app.thread == null
|| app.curProcState == ActivityManager.PROCESS_STATE_NONEXISTENT) {
continue;
}
if (memLowered || now > (app.lastStateTime+ProcessList.PSS_ALL_INTERVAL)) {
app.pssProcState = app.setProcState;
app.nextPssTime = ProcessList.computeNextPssTime(app.curProcState, true,
@@ -17984,8 +17988,8 @@ public final class ActivityManagerService extends ActivityManagerNative
}
}
}
if (app.setProcState < 0 || ProcessList.procStatesDifferForMem(app.curProcState,
app.setProcState)) {
if (app.setProcState == ActivityManager.PROCESS_STATE_NONEXISTENT
|| ProcessList.procStatesDifferForMem(app.curProcState, app.setProcState)) {
if (false && mTestPssMode && app.setProcState >= 0 && app.lastStateTime <= (now-200)) {
// Experimental code to more aggressively collect pss while
// running test... the problem is that this tends to collect

View File

@@ -16,6 +16,8 @@
package com.android.server.am;
import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT;
import android.util.ArraySet;
import android.util.EventLog;
import android.util.Slog;
@@ -83,10 +85,10 @@ final class ProcessRecord {
int curSchedGroup; // Currently desired scheduling class
int setSchedGroup; // Last set to background scheduling class
int trimMemoryLevel; // Last selected memory trimming level
int curProcState = -1; // Currently computed process state: ActivityManager.PROCESS_STATE_*
int repProcState = -1; // Last reported process state
int setProcState = -1; // Last set process state in process tracker
int pssProcState = -1; // The proc state we are currently requesting pss for
int curProcState = PROCESS_STATE_NONEXISTENT; // Currently computed process state
int repProcState = PROCESS_STATE_NONEXISTENT; // Last reported process state
int setProcState = PROCESS_STATE_NONEXISTENT; // Last set process state in process tracker
int pssProcState = PROCESS_STATE_NONEXISTENT; // Currently requesting pss for
boolean serviceb; // Process currently is on the service B list
boolean serviceHighRam; // We are forcing to service B list due to its RAM use
boolean setIsForeground; // Running foreground UI when last set?