From d48202e156b82079d133772d08af697080c4567f Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Wed, 26 Oct 2022 10:11:36 -0600 Subject: [PATCH] Subtle fix when queue becomes unrunnable. When broadcasts are skipped or failed during list traversal, we might encounter a queue that is no longer runnable; skip it. Also add new mPendingUrgent contents to dumpsys output. Bug: 253906105 Test: atest FrameworksMockingServicesTests:BroadcastRecordTest Test: atest FrameworksMockingServicesTests:BroadcastQueueTest Test: atest FrameworksMockingServicesTests:BroadcastQueueModernImplTest Change-Id: Ib85f3f33a9475cd4cd35f04afbc548e386b75c60 --- .../java/com/android/server/am/BroadcastProcessQueue.java | 6 +++++- .../com/android/server/am/BroadcastQueueModernImpl.java | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/am/BroadcastProcessQueue.java b/services/core/java/com/android/server/am/BroadcastProcessQueue.java index 5123517e272d3..de21996ac9cd2 100644 --- a/services/core/java/com/android/server/am/BroadcastProcessQueue.java +++ b/services/core/java/com/android/server/am/BroadcastProcessQueue.java @@ -807,7 +807,7 @@ class BroadcastProcessQueue { @NeverCompile public void dumpLocked(@UptimeMillisLong long now, @NonNull IndentingPrintWriter pw) { - if ((mActive == null) && mPending.isEmpty()) return; + if ((mActive == null) && isEmpty()) return; pw.print(toShortString()); if (isRunnable()) { @@ -823,6 +823,10 @@ class BroadcastProcessQueue { if (mActive != null) { dumpRecord(now, pw, mActive, mActiveIndex, mActiveBlockedUntilTerminalCount); } + for (SomeArgs args : mPendingUrgent) { + final BroadcastRecord r = (BroadcastRecord) args.arg1; + dumpRecord(now, pw, r, args.argi1, args.argi2); + } for (SomeArgs args : mPending) { final BroadcastRecord r = (BroadcastRecord) args.arg1; dumpRecord(now, pw, r, args.argi1, args.argi2); diff --git a/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java b/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java index 4c831bd47ee4c..490a484df4660 100644 --- a/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java +++ b/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java @@ -364,6 +364,13 @@ class BroadcastQueueModernImpl extends BroadcastQueue { BroadcastProcessQueue nextQueue = queue.runnableAtNext; final long runnableAt = queue.getRunnableAt(); + // When broadcasts are skipped or failed during list traversal, we + // might encounter a queue that is no longer runnable; skip it + if (!queue.isRunnable()) { + queue = nextQueue; + continue; + } + // If queues beyond this point aren't ready to run yet, schedule // another pass when they'll be runnable if (runnableAt > now && !waitingFor) {