Merge "Fix incomplete consolidation of kill-all-background"

This commit is contained in:
TreeHugger Robot
2019-03-08 04:17:38 +00:00
committed by Android (Google) Code Review
2 changed files with 9 additions and 22 deletions

View File

@@ -3969,11 +3969,12 @@ public class ActivityManagerService extends IActivityManager.Stub
final long callingId = Binder.clearCallingIdentity();
try {
synchronized (this) {
mProcessList.killAllBackgroundProcessesLocked();
// Allow memory level to go down (the flag needs to be set before updating oom adj)
// because this method is also used to simulate low memory.
mAllowLowerMemLevel = true;
mProcessList.killPackageProcessesLocked(null /* packageName */, -1 /* appId */,
UserHandle.USER_ALL, ProcessList.CACHED_APP_MIN_ADJ, "kill all background");
updateOomAdjLocked();
doLowMemReportIfNeededLocked(null);
}
} finally {

View File

@@ -2085,25 +2085,6 @@ public final class ProcessList {
}
}
void killAllBackgroundProcessesLocked() {
final ArrayList<ProcessRecord> procs = new ArrayList<>();
final int NP = mProcessNames.getMap().size();
for (int ip = 0; ip < NP; ip++) {
final SparseArray<ProcessRecord> apps = mProcessNames.getMap().valueAt(ip);
final int NA = apps.size();
for (int ia = 0; ia < NA; ia++) {
final ProcessRecord app = apps.valueAt(ia);
if (app.isPersistent()) {
// We don't kill persistent processes.
continue;
}
if (app.removed || app.setAdj >= ProcessList.CACHED_APP_MIN_ADJ) {
procs.add(app);
}
}
}
}
@GuardedBy("mService")
boolean killPackageProcessesLocked(String packageName, int appId, int userId, int minOomAdj,
String reason) {
@@ -2140,6 +2121,11 @@ public final class ProcessList {
// Skip process if it doesn't meet our oom adj requirement.
if (app.setAdj < minOomAdj) {
// Note it is still possible to have a process with oom adj 0 in the killed
// processes, but it does not mean misjudgment. E.g. a bound service process
// and its client activity process are both in the background, so they are
// collected to be killed. If the client activity is killed first, the service
// may be scheduled to unbind and become an executing service (oom adj 0).
continue;
}