Check if "waitingFor" conditions are met when a receiver is finished.
Bug: 265440949 Test: atest services/tests/mockingservicestests/src/com/android/server/am/BroadcastQueueTest.java Test: atest services/tests/mockingservicestests/src/com/android/server/am/BroadcastQueueModernImplTest.java Change-Id: I1da5953c2a5cf7e800d2b2f8a49c64ce54bde2c7
This commit is contained in:
@@ -506,16 +506,7 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
|
||||
mService.updateOomAdjPendingTargetsLocked(OOM_ADJ_REASON_START_RECEIVER);
|
||||
}
|
||||
|
||||
if (waitingFor) {
|
||||
mWaitingFor.removeIf((pair) -> {
|
||||
if (pair.first.getAsBoolean()) {
|
||||
pair.second.countDown();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
checkAndRemoveWaitingFor();
|
||||
|
||||
traceEnd(cookie);
|
||||
}
|
||||
@@ -1156,6 +1147,9 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
|
||||
mLocalHandler.removeMessages(MSG_DELIVERY_TIMEOUT_HARD, queue);
|
||||
}
|
||||
|
||||
// Given that a receiver just finished, check if the "waitingFor" conditions are met.
|
||||
checkAndRemoveWaitingFor();
|
||||
|
||||
if (early) {
|
||||
// This is an early receiver that was transmitted as part of a group. The delivery
|
||||
// state has been updated but don't make any further decisions.
|
||||
@@ -1446,7 +1440,7 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
|
||||
waitFor(() -> isBeyondBarrierLocked(now, pw));
|
||||
}
|
||||
|
||||
public void waitFor(@NonNull BooleanSupplier condition) {
|
||||
private void waitFor(@NonNull BooleanSupplier condition) {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
synchronized (mService) {
|
||||
mWaitingFor.add(Pair.create(condition, latch));
|
||||
@@ -1468,6 +1462,19 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkAndRemoveWaitingFor() {
|
||||
if (!mWaitingFor.isEmpty()) {
|
||||
mWaitingFor.removeIf((pair) -> {
|
||||
if (pair.first.getAsBoolean()) {
|
||||
pair.second.countDown();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forceDelayBroadcastDelivery(@NonNull String targetPackage,
|
||||
long delayedDurationMs) {
|
||||
|
||||
Reference in New Issue
Block a user