BroadcastQueue: ignore racing finish messages.

Since moving to enqueueFinishReceiver(), we've noticed an uptick in
our checkState() failing.  Our current hunch is that we're racing
with the remote app thread, but further investigation is needed.

Reduce this check to a log message for the moment to keep dogfooding
metrics clean.

Bug: 256999794
Test: atest FrameworksMockingServicesTests:BroadcastRecordTest
Test: atest FrameworksMockingServicesTests:BroadcastQueueTest
Test: atest FrameworksMockingServicesTests:BroadcastQueueModernImplTest
Change-Id: I90acd7ebbea0a7a8ab89db8f3c7463f9a9a909c7
This commit is contained in:
Jeff Sharkey
2022-11-02 10:20:37 -06:00
parent b84c3cbe22
commit d3c7497de3
2 changed files with 18 additions and 4 deletions

View File

@@ -77,6 +77,18 @@ public abstract class BroadcastQueue {
}
}
static void checkState(boolean expression, @NonNull String msg) {
if (!expression) {
throw new IllegalStateException(msg);
}
}
static void checkStateWtf(boolean expression, @NonNull String msg) {
if (!expression) {
Slog.wtf(TAG, new IllegalStateException(msg));
}
}
static int traceBegin(@NonNull String methodName) {
final int cookie = methodName.hashCode();
Trace.asyncTraceForTrackBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER,

View File

@@ -25,7 +25,6 @@ import static com.android.internal.util.FrameworkStatsLog.BROADCAST_DELIVERY_EVE
import static com.android.internal.util.FrameworkStatsLog.BROADCAST_DELIVERY_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_WARM;
import static com.android.internal.util.FrameworkStatsLog.BROADCAST_DELIVERY_EVENT_REPORTED__RECEIVER_TYPE__MANIFEST;
import static com.android.internal.util.FrameworkStatsLog.BROADCAST_DELIVERY_EVENT_REPORTED__RECEIVER_TYPE__RUNTIME;
import static com.android.internal.util.Preconditions.checkState;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_BROADCAST;
import static com.android.server.am.BroadcastProcessQueue.insertIntoRunnableList;
import static com.android.server.am.BroadcastProcessQueue.reasonToString;
@@ -757,7 +756,7 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
}
final Intent receiverIntent = r.getReceiverIntent(receiver);
if (receiverIntent == null) {
enqueueFinishReceiver(queue, BroadcastRecord.DELIVERY_SKIPPED, "isInFullBackup");
enqueueFinishReceiver(queue, BroadcastRecord.DELIVERY_SKIPPED, "getReceiverIntent");
return;
}
@@ -917,9 +916,12 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
private boolean finishReceiverLocked(@NonNull BroadcastProcessQueue queue,
@DeliveryState int deliveryState, @NonNull String reason) {
final int cookie = traceBegin("finishReceiver");
checkState(queue.isActive(), "isActive");
if (!queue.isActive()) {
logw("Ignoring finish; no active broadcast for " + queue);
return false;
}
final int cookie = traceBegin("finishReceiver");
final ProcessRecord app = queue.app;
final BroadcastRecord r = queue.getActive();
final int index = queue.getActiveIndex();