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

Commit aa8651ce authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

[1/3] Factor out current BroadcastQueue implementation.

Upcoming work will look at making significant changes to the
BroadcastQueue internals, so this change factors out the current
implementation to aid A/B testing.

This surgical change is designed to be a no-op refactoring with no
actual behavior changes.

Bug: 243656033
Test: atest CtsContentTestCases:BroadcastReceiverTest
Change-Id: I8120b9e43d939fd7ec6bd6b0b6090b369f643aa6
parent f86af64d
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -10627,7 +10627,7 @@ public class ActivityManagerService extends IActivityManager.Stub
            pw.println();
            for (BroadcastQueue queue : mBroadcastQueues) {
                pw.println("  mBroadcastsScheduled [" + queue.mQueueName + "]="
                        + queue.mBroadcastsScheduled);
                        + queue.hasBroadcastsScheduled());
            }
            pw.println("  mHandler:");
            mHandler.dump(new PrintWriterPrinter(pw), "    ");
@@ -15186,7 +15186,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        // It's not the current receiver, but it might be starting up to become one
        for (BroadcastQueue queue : mBroadcastQueues) {
            final BroadcastRecord r = queue.mPendingBroadcast;
            final BroadcastRecord r = queue.getPendingBroadcastLocked();
            if (r != null && r.curApp == app) {
                // found it; report which queue it's in
                receivingQueues.add(queue);
@@ -15301,7 +15301,7 @@ public class ActivityManagerService extends IActivityManager.Stub
    @GuardedBy("this")
    final boolean canGcNowLocked() {
        for (BroadcastQueue q : mBroadcastQueues) {
            if (!q.mParallelBroadcasts.isEmpty() || !q.mDispatcher.isIdle()) {
            if (!q.isIdle()) {
                return false;
            }
        }
+28 −12
Original line number Diff line number Diff line
@@ -104,7 +104,7 @@ import java.util.Set;
 * foreground priority, and one for normal (background-priority) broadcasts, and one to
 * offload special broadcasts that we know take a long time, such as BOOT_COMPLETED.
 */
public final class BroadcastQueue {
public class BroadcastQueue {
    private static final String TAG = "BroadcastQueue";
    private static final String TAG_MU = TAG + POSTFIX_MU;
    private static final String TAG_BROADCAST = TAG + POSTFIX_BROADCAST;
@@ -254,11 +254,27 @@ public final class BroadcastQueue {
        return mQueueName;
    }

    public boolean isDelayBehindServices() {
        return mDelayBehindServices;
    }

    public boolean hasBroadcastsScheduled() {
        return mBroadcastsScheduled;
    }

    public BroadcastRecord getPendingBroadcastLocked() {
        return mPendingBroadcast;
    }

    public BroadcastRecord getActiveBroadcastLocked() {
        return mDispatcher.getActiveBroadcastLocked();
    }

    public boolean isPendingBroadcastProcessLocked(int pid) {
        return mPendingBroadcast != null && mPendingBroadcast.curApp.getPid() == pid;
    }

    boolean isPendingBroadcastProcessLocked(ProcessRecord app) {
    public boolean isPendingBroadcastProcessLocked(ProcessRecord app) {
        return mPendingBroadcast != null && mPendingBroadcast.curApp == app;
    }

@@ -606,8 +622,8 @@ public final class BroadcastQueue {

        // If we want to wait behind services *AND* we're finishing the head/
        // active broadcast on its queue
        if (waitForServices && r.curComponent != null && r.queue.mDelayBehindServices
                && r.queue.mDispatcher.getActiveBroadcastLocked() == r) {
        if (waitForServices && r.curComponent != null && r.queue.isDelayBehindServices()
                && r.queue.getActiveBroadcastLocked() == r) {
            ActivityInfo nextReceiver;
            if (r.nextReceiver < r.receivers.size()) {
                Object obj = r.receivers.get(r.nextReceiver);
@@ -652,7 +668,7 @@ public final class BroadcastQueue {
        }
    }

    void performReceiveLocked(ProcessRecord app, IIntentReceiver receiver,
    public void performReceiveLocked(ProcessRecord app, IIntentReceiver receiver,
            Intent intent, int resultCode, String data, Bundle extras,
            boolean ordered, boolean sticky, int sendingUser,
            int receiverUid, int callingUid, long dispatchDelay,
@@ -1195,7 +1211,7 @@ public final class BroadcastQueue {
        return intent;
    }

    final void processNextBroadcastLocked(boolean fromMsg, boolean skipOomAdj) {
    public void processNextBroadcastLocked(boolean fromMsg, boolean skipOomAdj) {
        BroadcastRecord r;

        if (DEBUG_BROADCAST) Slog.v(TAG_BROADCAST, "processNextBroadcast ["
@@ -2307,7 +2323,7 @@ public final class BroadcastQueue {
        mSummaryHistoryNext = ringAdvance(mSummaryHistoryNext, 1, MAX_BROADCAST_SUMMARY_HISTORY);
    }

    boolean cleanupDisabledPackageReceiversLocked(
    public boolean cleanupDisabledPackageReceiversLocked(
            String packageName, Set<String> filterByClasses, int userId, boolean doit) {
        boolean didSomething = false;
        for (int i = mParallelBroadcasts.size() - 1; i >= 0; i--) {
@@ -2358,28 +2374,28 @@ public final class BroadcastQueue {
                record.intent == null ? "" : record.intent.getAction());
    }

    boolean isIdle() {
    public boolean isIdle() {
        return mParallelBroadcasts.isEmpty() && mDispatcher.isIdle()
                && (mPendingBroadcast == null);
    }

    // Used by wait-for-broadcast-idle : fast-forward all current deferrals to
    // be immediately deliverable.
    void cancelDeferrals() {
    public void cancelDeferrals() {
        synchronized (mService) {
            mDispatcher.cancelDeferralsLocked();
            scheduleBroadcastsLocked();
        }
    }

    String describeState() {
    public String describeState() {
        synchronized (mService) {
            return mParallelBroadcasts.size() + " parallel; "
                    + mDispatcher.describeStateLocked();
        }
    }

    void dumpDebug(ProtoOutputStream proto, long fieldId) {
    public void dumpDebug(ProtoOutputStream proto, long fieldId) {
        long token = proto.start(fieldId);
        proto.write(BroadcastQueueProto.QUEUE_NAME, mQueueName);
        int N;
@@ -2425,7 +2441,7 @@ public final class BroadcastQueue {
        proto.end(token);
    }

    final boolean dumpLocked(FileDescriptor fd, PrintWriter pw, String[] args,
    public boolean dumpLocked(FileDescriptor fd, PrintWriter pw, String[] args,
            int opti, boolean dumpAll, String dumpPackage, boolean needSep) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        if (!mParallelBroadcasts.isEmpty() || !mDispatcher.isEmpty()