Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a7ec8f3a authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Android (Google) Code Review
Browse files

Merge "Check if "waitingFor" conditions are met when a receiver is finished."

parents e0a48b2f e31fb24f
Loading
Loading
Loading
Loading
+18 −11
Original line number Diff line number Diff line
@@ -508,16 +508,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);
    }
@@ -1181,6 +1172,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.
@@ -1509,7 +1503,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));
@@ -1531,6 +1525,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) {