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

Commit acbe214d authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

Make flushing broadcast loopers optional.

In some cases, it takes a while for the background thread
looper to finish and it seems unnecessary to increase runtime
of existing clients if they don't require this or if there are
no pending broadcasts waiting to be sent in these loopers.
If clients require this behavior, they can always use
the new option to force it.

Bug: 280316424
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: Iee5367dd02ba9e1878fe1d7c0920cf6c0c1c1e2a
parent 813b664c
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -18875,12 +18875,14 @@ public class ActivityManagerService extends IActivityManager.Stub
    @Override
    public void waitForBroadcastIdle() {
        waitForBroadcastIdle(LOG_WRITER_INFO);
        waitForBroadcastIdle(LOG_WRITER_INFO, false);
    }
    public void waitForBroadcastIdle(@NonNull PrintWriter pw) {
    void waitForBroadcastIdle(@NonNull PrintWriter pw, boolean flushBroadcastLoopers) {
        enforceCallingPermission(permission.DUMP, "waitForBroadcastIdle()");
        if (flushBroadcastLoopers) {
            BroadcastLoopers.waitForIdle(pw);
        }
        for (BroadcastQueue queue : mBroadcastQueues) {
            queue.waitForIdle(pw);
        }
@@ -18893,7 +18895,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        waitForBroadcastBarrier(LOG_WRITER_INFO, false, false);
    }
    public void waitForBroadcastBarrier(@NonNull PrintWriter pw,
    void waitForBroadcastBarrier(@NonNull PrintWriter pw,
            boolean flushBroadcastLoopers, boolean flushApplicationThreads) {
        enforceCallingPermission(permission.DUMP, "waitForBroadcastBarrier()");
        if (flushBroadcastLoopers) {
@@ -18911,7 +18913,7 @@ public class ActivityManagerService extends IActivityManager.Stub
     * Wait for all pending {@link IApplicationThread} events to be processed in
     * all currently running apps.
     */
    public void waitForApplicationBarrier(@NonNull PrintWriter pw) {
    void waitForApplicationBarrier(@NonNull PrintWriter pw) {
        final CountDownLatch finishedLatch = new CountDownLatch(1);
        final AtomicInteger pingCount = new AtomicInteger(0);
        final AtomicInteger pongCount = new AtomicInteger(0);
+11 −1
Original line number Diff line number Diff line
@@ -3445,7 +3445,17 @@ final class ActivityManagerShellCommand extends ShellCommand {

    int runWaitForBroadcastIdle(PrintWriter pw) throws RemoteException {
        pw = new PrintWriter(new TeeWriter(LOG_WRITER_INFO, pw));
        mInternal.waitForBroadcastIdle(pw);
        boolean flushBroadcastLoopers = false;
        String opt;
        while ((opt = getNextOption()) != null) {
            if (opt.equals("--flush-broadcast-loopers")) {
                flushBroadcastLoopers = true;
            } else {
                getErrPrintWriter().println("Error: Unknown option: " + opt);
                return -1;
            }
        }
        mInternal.waitForBroadcastIdle(pw, flushBroadcastLoopers);
        return 0;
    }