BroadcastQueue: fix subtle OOM adjustment bug.

updateOomAdjPendingTargetsLocked() only takes effect for processes
that are already running as warm; it doesn't work on a process that
is still being cold started.

This change fixes the bug by making an explicit update call once
a pending cold start has become a warm process.

Bug: 255985948
Test: atest CtsAppTestCases:ActivityManagerProcessStateTest#testBackgroundCheckBroadcastService
Change-Id: I7e42984c7b7fd6e496fc9245304f1eff8ad71075
This commit is contained in:
Jeff Sharkey
2022-10-28 14:47:06 -06:00
parent 2f57686ace
commit 5564cddbd7

View File

@@ -412,21 +412,24 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
queue.runningTraceTrackName = TAG + ".mRunning[" + queueIndex + "]";
queue.runningOomAdjusted = queue.isPendingManifest();
// If already warm, we can make OOM adjust request immediately;
// otherwise we need to wait until process becomes warm
if (processWarm) {
notifyStartedRunning(queue);
updateOomAdj |= queue.runningOomAdjusted;
}
// If we're already warm, schedule next pending broadcast now;
// otherwise we'll wait for the cold start to circle back around
queue.makeActiveNextPending();
if (processWarm) {
queue.traceProcessRunningBegin();
notifyStartedRunning(queue);
scheduleReceiverWarmLocked(queue);
} else {
queue.traceProcessStartingBegin();
scheduleReceiverColdLocked(queue);
}
// Only kick off an OOM adjustment pass if needed
updateOomAdj |= queue.runningOomAdjusted;
// Move to considering next runnable queue
queue = nextQueue;
}
@@ -464,9 +467,13 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
// now; dispatch its next broadcast and clear the slot
mRunningColdStart = null;
// Now that we're running warm, we can finally request that OOM
// adjust we've been waiting for
notifyStartedRunning(queue);
mService.updateOomAdjPendingTargetsLocked(OOM_ADJ_REASON_START_RECEIVER);
queue.traceProcessEnd();
queue.traceProcessRunningBegin();
notifyStartedRunning(queue);
scheduleReceiverWarmLocked(queue);
// We might be willing to kick off another cold start