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

Commit 12a69868 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

[1/?] Reduce BroadcastQueue interface complexity.

Start pruning down the methods surfaced through BroadcastQueue,
which reduces the surface area future implementations will have to
think about.

Begin adding documentation to well-understood methods.

Bug: 243656033
Test: atest CtsContentTestCases:BroadcastReceiverTest
Change-Id: I401b61640b38a677e1bf9b8986475daa044122e0
parent 676adec2
Loading
Loading
Loading
Loading
+16 −11
Original line number Diff line number Diff line
@@ -10626,8 +10626,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        if (!onlyHistory && !onlyReceivers && dumpAll) {
            pw.println();
            for (BroadcastQueue queue : mBroadcastQueues) {
                pw.println("  mBroadcastsScheduled [" + queue.mQueueName + "]="
                        + queue.hasBroadcastsScheduled());
                pw.println("  Queue " + queue.toString() + ": " + queue.describeState());
            }
            pw.println("  mHandler:");
            mHandler.dump(new PrintWriterPrinter(pw), "    ");
@@ -13082,17 +13081,23 @@ public class ActivityManagerService extends IActivityManager.Stub
    }
    boolean isPendingBroadcastProcessLocked(int pid) {
        return mFgBroadcastQueue.isPendingBroadcastProcessLocked(pid)
                || mBgBroadcastQueue.isPendingBroadcastProcessLocked(pid)
                || mBgOffloadBroadcastQueue.isPendingBroadcastProcessLocked(pid)
                || mFgOffloadBroadcastQueue.isPendingBroadcastProcessLocked(pid);
        for (BroadcastQueue queue : mBroadcastQueues) {
            BroadcastRecord r = queue.getPendingBroadcastLocked();
            if (r != null && r.curApp.getPid() == pid) {
                return true;
            }
        }
        return false;
    }
    boolean isPendingBroadcastProcessLocked(ProcessRecord app) {
        return mFgBroadcastQueue.isPendingBroadcastProcessLocked(app)
                || mBgBroadcastQueue.isPendingBroadcastProcessLocked(app)
                || mBgOffloadBroadcastQueue.isPendingBroadcastProcessLocked(app)
                || mFgOffloadBroadcastQueue.isPendingBroadcastProcessLocked(app);
        for (BroadcastQueue queue : mBroadcastQueues) {
            BroadcastRecord r = queue.getPendingBroadcastLocked();
            if (r != null && r.curApp == app) {
                return true;
            }
        }
        return false;
    }
    void skipPendingBroadcastLocked(int pid) {
@@ -17890,7 +17895,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                            pw.flush();
                        }
                        Slog.v(TAG, msg);
                        queue.cancelDeferrals();
                        queue.flush();
                        idle = false;
                    }
                }
+29 −8
Original line number Diff line number Diff line
@@ -61,16 +61,10 @@ public abstract class BroadcastQueue {

    public abstract boolean isDelayBehindServices();

    public abstract boolean hasBroadcastsScheduled();

    public abstract BroadcastRecord getPendingBroadcastLocked();

    public abstract BroadcastRecord getActiveBroadcastLocked();

    public abstract boolean isPendingBroadcastProcessLocked(int pid);

    public abstract boolean isPendingBroadcastProcessLocked(ProcessRecord app);

    public abstract void enqueueParallelBroadcastLocked(BroadcastRecord r);

    public abstract void enqueueOrderedBroadcastLocked(BroadcastRecord r);
@@ -91,6 +85,13 @@ public abstract class BroadcastQueue {

    public abstract BroadcastRecord getMatchingOrderedReceiver(IBinder receiver);

    /**
     * Signal delivered back from a {@link BroadcastReceiver} to indicate that
     * it's finished processing the current broadcast being dispatched to it.
     * <p>
     * If this signal isn't delivered back in a timely fashion, we assume the
     * receiver has somehow wedged and we trigger an ANR.
     */
    public abstract boolean finishReceiverLocked(BroadcastRecord r, int resultCode,
            String resultData, Bundle resultExtras, boolean resultAbort, boolean waitForServices);

@@ -104,15 +105,35 @@ public abstract class BroadcastQueue {

    public abstract void processNextBroadcastLocked(boolean fromMsg, boolean skipOomAdj);

    /**
     * Signal from OS internals that the given package (or some subset of that
     * package) has been disabled or uninstalled, and that any pending
     * broadcasts should be cleaned up.
     */
    public abstract boolean cleanupDisabledPackageReceiversLocked(
            String packageName, Set<String> filterByClasses, int userId, boolean doit);

    /**
     * Quickly determine if this queue has broadcasts that are still waiting to
     * be delivered at some point in the future.
     *
     * @see #flush()
     */
    public abstract boolean isIdle();

    public abstract void cancelDeferrals();

    /**
     * Brief summary of internal state, useful for debugging purposes.
     */
    public abstract String describeState();

    /**
     * Flush any broadcasts still waiting to be delivered, causing them to be
     * delivered as soon as possible.
     *
     * @see #isIdle()
     */
    public abstract void flush();

    public abstract void dumpDebug(ProtoOutputStream proto, long fieldId);

    public abstract boolean dumpLocked(FileDescriptor fd, PrintWriter pw, String[] args,
+4 −17
Original line number Diff line number Diff line
@@ -223,19 +223,10 @@ public class BroadcastQueueImpl extends BroadcastQueue {
        mConstants.startObserving(mHandler, resolver);
    }

    @Override
    public String toString() {
        return mQueueName;
    }

    public boolean isDelayBehindServices() {
        return mDelayBehindServices;
    }

    public boolean hasBroadcastsScheduled() {
        return mBroadcastsScheduled;
    }

    public BroadcastRecord getPendingBroadcastLocked() {
        return mPendingBroadcast;
    }
@@ -244,14 +235,6 @@ public class BroadcastQueueImpl extends BroadcastQueue {
        return mDispatcher.getActiveBroadcastLocked();
    }

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

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

    public void enqueueParallelBroadcastLocked(BroadcastRecord r) {
        r.enqueueClockTime = System.currentTimeMillis();
        r.enqueueTime = SystemClock.uptimeMillis();
@@ -1706,6 +1689,10 @@ public class BroadcastQueueImpl extends BroadcastQueue {
                && (mPendingBroadcast == null);
    }

    public void flush() {
        cancelDeferrals();
    }

    // Used by wait-for-broadcast-idle : fast-forward all current deferrals to
    // be immediately deliverable.
    public void cancelDeferrals() {