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

Commit c4c1d09e authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Automerger Merge Worker
Browse files

Merge "Prioritize broadcasts to persistent processes." into udc-dev am: e546f6af

parents 8d18c01f e546f6af
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -18894,12 +18894,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);
        }
@@ -18912,7 +18914,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) {
@@ -18930,7 +18932,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
@@ -3447,7 +3447,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;
    }

+28 −0
Original line number Diff line number Diff line
@@ -246,6 +246,26 @@ public class BroadcastConstants {
    private static final String KEY_DELAY_URGENT_MILLIS = "bcast_delay_urgent_millis";
    private static final long DEFAULT_DELAY_URGENT_MILLIS = -120_000;

    /**
     * For {@link BroadcastQueueModernImpl}: Delay to apply to broadcasts to
     * foreground processes, typically a negative value to indicate they should be
     * executed before most other pending broadcasts.
     */
    public long DELAY_FOREGROUND_PROC_MILLIS = DEFAULT_DELAY_FOREGROUND_PROC_MILLIS;
    private static final String KEY_DELAY_FOREGROUND_PROC_MILLIS =
            "bcast_delay_foreground_proc_millis";
    private static final long DEFAULT_DELAY_FOREGROUND_PROC_MILLIS = -120_000;

    /**
     * For {@link BroadcastQueueModernImpl}: Delay to apply to broadcasts to
     * persistent processes, typically a negative value to indicate they should be
     * executed before most other pending broadcasts.
     */
    public long DELAY_PERSISTENT_PROC_MILLIS = DEFAULT_DELAY_FOREGROUND_PROC_MILLIS;
    private static final String KEY_DELAY_PERSISTENT_PROC_MILLIS =
            "bcast_delay_persistent_proc_millis";
    private static final long DEFAULT_DELAY_PERSISTENT_PROC_MILLIS = -120_000;

    /**
     * For {@link BroadcastQueueModernImpl}: Maximum number of complete
     * historical broadcasts to retain for debugging purposes.
@@ -411,6 +431,10 @@ public class BroadcastConstants {
                    DEFAULT_DELAY_CACHED_MILLIS);
            DELAY_URGENT_MILLIS = getDeviceConfigLong(KEY_DELAY_URGENT_MILLIS,
                    DEFAULT_DELAY_URGENT_MILLIS);
            DELAY_FOREGROUND_PROC_MILLIS = getDeviceConfigLong(KEY_DELAY_FOREGROUND_PROC_MILLIS,
                    DEFAULT_DELAY_FOREGROUND_PROC_MILLIS);
            DELAY_PERSISTENT_PROC_MILLIS = getDeviceConfigLong(KEY_DELAY_PERSISTENT_PROC_MILLIS,
                    DEFAULT_DELAY_PERSISTENT_PROC_MILLIS);
            MAX_HISTORY_COMPLETE_SIZE = getDeviceConfigInt(KEY_MAX_HISTORY_COMPLETE_SIZE,
                    DEFAULT_MAX_HISTORY_COMPLETE_SIZE);
            MAX_HISTORY_SUMMARY_SIZE = getDeviceConfigInt(KEY_MAX_HISTORY_SUMMARY_SIZE,
@@ -463,6 +487,10 @@ public class BroadcastConstants {
                    TimeUtils.formatDuration(DELAY_CACHED_MILLIS)).println();
            pw.print(KEY_DELAY_URGENT_MILLIS,
                    TimeUtils.formatDuration(DELAY_URGENT_MILLIS)).println();
            pw.print(KEY_DELAY_FOREGROUND_PROC_MILLIS,
                    TimeUtils.formatDuration(DELAY_FOREGROUND_PROC_MILLIS)).println();
            pw.print(KEY_DELAY_PERSISTENT_PROC_MILLIS,
                    TimeUtils.formatDuration(DELAY_PERSISTENT_PROC_MILLIS)).println();
            pw.print(KEY_MAX_HISTORY_COMPLETE_SIZE, MAX_HISTORY_COMPLETE_SIZE).println();
            pw.print(KEY_MAX_HISTORY_SUMMARY_SIZE, MAX_HISTORY_SUMMARY_SIZE).println();
            pw.print(KEY_MAX_CONSECUTIVE_URGENT_DISPATCHES,
+4 −4
Original line number Diff line number Diff line
@@ -1098,8 +1098,11 @@ class BroadcastProcessQueue {
                mRunnableAt = runnableAt + constants.DELAY_URGENT_MILLIS;
                mRunnableAtReason = REASON_INSTRUMENTED;
            } else if (mUidForeground) {
                mRunnableAt = runnableAt + constants.DELAY_URGENT_MILLIS;
                mRunnableAt = runnableAt + constants.DELAY_FOREGROUND_PROC_MILLIS;
                mRunnableAtReason = REASON_FOREGROUND;
            } else if (mProcessPersistent) {
                mRunnableAt = runnableAt + constants.DELAY_PERSISTENT_PROC_MILLIS;
                mRunnableAtReason = REASON_PERSISTENT;
            } else if (mCountOrdered > 0) {
                mRunnableAt = runnableAt;
                mRunnableAtReason = REASON_CONTAINS_ORDERED;
@@ -1112,9 +1115,6 @@ class BroadcastProcessQueue {
            } else if (mCountManifest > 0) {
                mRunnableAt = runnableAt;
                mRunnableAtReason = REASON_CONTAINS_MANIFEST;
            } else if (mProcessPersistent) {
                mRunnableAt = runnableAt;
                mRunnableAtReason = REASON_PERSISTENT;
            } else if (mUidCached) {
                if (r.deferUntilActive) {
                    // All enqueued broadcasts are deferrable, defer
+24 −0
Original line number Diff line number Diff line
@@ -537,6 +537,30 @@ public final class BroadcastQueueModernImplTest {
        assertEquals(BroadcastProcessQueue.REASON_NORMAL, queue.getRunnableAtReason());
    }

    @Test
    public void testRunnableAt_persistentProc() {
        final BroadcastProcessQueue queue = new BroadcastProcessQueue(mConstants, PACKAGE_GREEN,
                getUidForPackage(PACKAGE_GREEN));

        final Intent timeTick = new Intent(Intent.ACTION_TIME_TICK);
        final BroadcastRecord timeTickRecord = makeBroadcastRecord(timeTick,
                List.of(makeMockRegisteredReceiver()));
        enqueueOrReplaceBroadcast(queue, timeTickRecord, 0);

        assertThat(queue.getRunnableAt()).isGreaterThan(timeTickRecord.enqueueTime);
        assertEquals(BroadcastProcessQueue.REASON_NORMAL, queue.getRunnableAtReason());

        doReturn(true).when(mProcess).isPersistent();
        queue.setProcessAndUidState(mProcess, false, false);
        assertThat(queue.getRunnableAt()).isLessThan(timeTickRecord.enqueueTime);
        assertEquals(BroadcastProcessQueue.REASON_PERSISTENT, queue.getRunnableAtReason());

        doReturn(false).when(mProcess).isPersistent();
        queue.setProcessAndUidState(mProcess, false, false);
        assertThat(queue.getRunnableAt()).isGreaterThan(timeTickRecord.enqueueTime);
        assertEquals(BroadcastProcessQueue.REASON_NORMAL, queue.getRunnableAtReason());
    }

    /**
     * Verify that a cached process that would normally be delayed becomes
     * immediately runnable when the given broadcast is enqueued.