Loading services/core/java/com/android/server/am/BroadcastProcessQueue.java +16 −0 Original line number Diff line number Diff line Loading @@ -750,6 +750,22 @@ class BroadcastProcessQueue { return mCountManifest > 0; } /** * Quickly determine if this queue has ordered broadcasts waiting to be delivered, * which indicates we should request an OOM adjust. */ public boolean isPendingOrdered() { return mCountOrdered > 0; } /** * Quickly determine if this queue has broadcasts waiting to be delivered for which result is * expected from the senders, which indicates we should request an OOM adjust. */ public boolean isPendingResultTo() { return mCountResultTo > 0; } /** * Report whether this queue is currently handling an urgent broadcast. */ Loading services/core/java/com/android/server/am/BroadcastQueueModernImpl.java +3 −1 Original line number Diff line number Diff line Loading @@ -466,7 +466,9 @@ class BroadcastQueueModernImpl extends BroadcastQueue { // Emit all trace events for this process into a consistent track queue.runningTraceTrackName = TAG + ".mRunning[" + queueIndex + "]"; queue.runningOomAdjusted = queue.isPendingManifest(); queue.runningOomAdjusted = queue.isPendingManifest() || queue.isPendingOrdered() || queue.isPendingResultTo(); // If already warm, we can make OOM adjust request immediately; // otherwise we need to wait until process becomes warm Loading services/tests/mockingservicestests/src/com/android/server/am/BroadcastQueueTest.java +36 −0 Original line number Diff line number Diff line Loading @@ -1821,6 +1821,42 @@ public class BroadcastQueueTest { verify(mAms, atLeastOnce()).enqueueOomAdjTargetLocked(any()); } /** * Verify that we OOM adjust for ordered broadcast receivers. */ @Test public void testOomAdjust_Ordered() throws Exception { final ProcessRecord callerApp = makeActiveProcessRecord(PACKAGE_RED); final IIntentReceiver orderedResultTo = mock(IIntentReceiver.class); final Intent airplane = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); enqueueBroadcast(makeOrderedBroadcastRecord(airplane, callerApp, List.of(makeManifestReceiver(PACKAGE_GREEN, CLASS_GREEN), makeManifestReceiver(PACKAGE_GREEN, CLASS_BLUE), makeManifestReceiver(PACKAGE_GREEN, CLASS_RED)), orderedResultTo, null)); waitForIdle(); verify(mAms, atLeastOnce()).enqueueOomAdjTargetLocked(any()); } /** * Verify that we OOM adjust for resultTo broadcast receivers. */ @Test public void testOomAdjust_ResultTo() throws Exception { final ProcessRecord callerApp = makeActiveProcessRecord(PACKAGE_RED); final IIntentReceiver resultTo = mock(IIntentReceiver.class); final Intent airplane = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); enqueueBroadcast(makeBroadcastRecord(airplane, callerApp, List.of(makeManifestReceiver(PACKAGE_GREEN, CLASS_GREEN), makeManifestReceiver(PACKAGE_GREEN, CLASS_BLUE), makeManifestReceiver(PACKAGE_GREEN, CLASS_RED)), resultTo)); waitForIdle(); verify(mAms, atLeastOnce()).enqueueOomAdjTargetLocked(any()); } /** * Verify that we never OOM adjust for registered receivers. */ Loading Loading
services/core/java/com/android/server/am/BroadcastProcessQueue.java +16 −0 Original line number Diff line number Diff line Loading @@ -750,6 +750,22 @@ class BroadcastProcessQueue { return mCountManifest > 0; } /** * Quickly determine if this queue has ordered broadcasts waiting to be delivered, * which indicates we should request an OOM adjust. */ public boolean isPendingOrdered() { return mCountOrdered > 0; } /** * Quickly determine if this queue has broadcasts waiting to be delivered for which result is * expected from the senders, which indicates we should request an OOM adjust. */ public boolean isPendingResultTo() { return mCountResultTo > 0; } /** * Report whether this queue is currently handling an urgent broadcast. */ Loading
services/core/java/com/android/server/am/BroadcastQueueModernImpl.java +3 −1 Original line number Diff line number Diff line Loading @@ -466,7 +466,9 @@ class BroadcastQueueModernImpl extends BroadcastQueue { // Emit all trace events for this process into a consistent track queue.runningTraceTrackName = TAG + ".mRunning[" + queueIndex + "]"; queue.runningOomAdjusted = queue.isPendingManifest(); queue.runningOomAdjusted = queue.isPendingManifest() || queue.isPendingOrdered() || queue.isPendingResultTo(); // If already warm, we can make OOM adjust request immediately; // otherwise we need to wait until process becomes warm Loading
services/tests/mockingservicestests/src/com/android/server/am/BroadcastQueueTest.java +36 −0 Original line number Diff line number Diff line Loading @@ -1821,6 +1821,42 @@ public class BroadcastQueueTest { verify(mAms, atLeastOnce()).enqueueOomAdjTargetLocked(any()); } /** * Verify that we OOM adjust for ordered broadcast receivers. */ @Test public void testOomAdjust_Ordered() throws Exception { final ProcessRecord callerApp = makeActiveProcessRecord(PACKAGE_RED); final IIntentReceiver orderedResultTo = mock(IIntentReceiver.class); final Intent airplane = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); enqueueBroadcast(makeOrderedBroadcastRecord(airplane, callerApp, List.of(makeManifestReceiver(PACKAGE_GREEN, CLASS_GREEN), makeManifestReceiver(PACKAGE_GREEN, CLASS_BLUE), makeManifestReceiver(PACKAGE_GREEN, CLASS_RED)), orderedResultTo, null)); waitForIdle(); verify(mAms, atLeastOnce()).enqueueOomAdjTargetLocked(any()); } /** * Verify that we OOM adjust for resultTo broadcast receivers. */ @Test public void testOomAdjust_ResultTo() throws Exception { final ProcessRecord callerApp = makeActiveProcessRecord(PACKAGE_RED); final IIntentReceiver resultTo = mock(IIntentReceiver.class); final Intent airplane = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); enqueueBroadcast(makeBroadcastRecord(airplane, callerApp, List.of(makeManifestReceiver(PACKAGE_GREEN, CLASS_GREEN), makeManifestReceiver(PACKAGE_GREEN, CLASS_BLUE), makeManifestReceiver(PACKAGE_GREEN, CLASS_RED)), resultTo)); waitForIdle(); verify(mAms, atLeastOnce()).enqueueOomAdjTargetLocked(any()); } /** * Verify that we never OOM adjust for registered receivers. */ Loading