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

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

Allow dumping broadcasts matching a particular intent action.

Fixes: 386423975
Test: manual
Flag: EXEMPT changes dump output
Change-Id: I8138ad6dbec0119e9677a0f85f1b396f33c3cc22
parent 77598312
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -10828,8 +10828,12 @@ public class ActivityManagerService extends IActivityManager.Stub
                    opti++;
                }
                synchronized (this) {
                    // TODO: b/361161826 - Always pass in the dumpAll and let
                    // BroadcastController decide how to treat it.
                    final boolean requestDumpAll = "filter".equals(dumpPackage)
                            ? dumpAll : true;
                    mBroadcastController.dumpBroadcastsLocked(fd, pw, args, opti,
                            /* dumpAll= */ true, dumpPackage);
                            requestDumpAll, dumpPackage);
                }
            } else if ("broadcast-stats".equals(cmd)) {
                if (opti < args.length) {
+24 −8
Original line number Diff line number Diff line
@@ -2178,6 +2178,8 @@ class BroadcastController {
        boolean printedAnything = false;
        boolean onlyReceivers = false;
        int filteredUid = Process.INVALID_UID;
        boolean onlyFilter = false;
        String dumpIntentAction = null;

        if ("history".equals(dumpPackage)) {
            if (opti < args.length && "-s".equals(args[opti])) {
@@ -2185,8 +2187,7 @@ class BroadcastController {
            }
            onlyHistory = true;
            dumpPackage = null;
        }
        if ("receivers".equals(dumpPackage)) {
        } else if ("receivers".equals(dumpPackage)) {
            onlyReceivers = true;
            dumpPackage = null;
            if (opti + 2 <= args.length) {
@@ -2205,7 +2206,23 @@ class BroadcastController {
                    }
                }
            }
        } else if ("filter".equals(dumpPackage)) {
            onlyFilter = true;
            dumpPackage = null;
            if (opti + 2 <= args.length) {
                if ("--action".equals(args[opti++])) {
                    dumpIntentAction = args[opti++];
                    if (dumpIntentAction == null) {
                        pw.printf("Missing argument for --action option\n");
                        return;
                    }
                } else {
                    pw.printf("Unknown argument: %s\n", args[opti]);
                    return;
                }
            }
        }

        if (DEBUG_BROADCAST) {
            Slogf.d(TAG_BROADCAST, "dumpBroadcastsLocked(): dumpPackage=%s, onlyHistory=%b, "
                            + "onlyReceivers=%b, filteredUid=%d", dumpPackage, onlyHistory,
@@ -2213,7 +2230,7 @@ class BroadcastController {
        }

        pw.println("ACTIVITY MANAGER BROADCAST STATE (dumpsys activity broadcasts)");
        if (!onlyHistory && dumpAll) {
        if (!onlyHistory && !onlyFilter && dumpAll) {
            if (mRegisteredReceivers.size() > 0) {
                boolean printed = false;
                Iterator it = mRegisteredReceivers.values().iterator();
@@ -2257,14 +2274,14 @@ class BroadcastController {

        if (!onlyReceivers) {
            needSep = mBroadcastQueue.dumpLocked(fd, pw, args, opti,
                    dumpConstants, dumpHistory, dumpAll, dumpPackage, needSep);
                    dumpConstants, dumpHistory, dumpAll, dumpPackage, dumpIntentAction, needSep);
            printedAnything |= needSep;
        }

        needSep = true;

        synchronized (mStickyBroadcasts) {
            if (!onlyHistory && !onlyReceivers && mStickyBroadcasts != null
            if (!onlyHistory && !onlyReceivers && !onlyFilter && mStickyBroadcasts != null
                    && dumpPackage == null) {
                for (int user = 0; user < mStickyBroadcasts.size(); user++) {
                    if (needSep) {
@@ -2312,13 +2329,12 @@ class BroadcastController {
            }
        }

        if (!onlyHistory && !onlyReceivers && dumpAll) {
        if (!onlyHistory && !onlyReceivers && !onlyFilter && dumpAll) {
            pw.println();
            pw.println("  Queue " + mBroadcastQueue.toString() + ": "
            pw.println("  Queue " + mBroadcastQueue + ": "
                    + mBroadcastQueue.describeStateLocked());
            pw.println("  mHandler:");
            mService.mHandler.dump(new PrintWriterPrinter(pw), "    ");
            needSep = true;
            printedAnything = true;
        }

+34 −8
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Objects;

/**
 * Collection of recent historical broadcasts that are available to be dumped
@@ -163,10 +164,11 @@ public class BroadcastHistory {

    @NeverCompile
    public boolean dumpLocked(@NonNull PrintWriter pw, @Nullable String dumpPackage,
            @NonNull String queueName, @NonNull SimpleDateFormat sdf,
            boolean dumpAll, boolean needSep) {
        dumpBroadcastList(pw, sdf, mFrozenBroadcasts, "Frozen");
        dumpBroadcastList(pw, sdf, mPendingBroadcasts, "Pending");
            @Nullable String dumpIntentAction, @NonNull String queueName,
            @NonNull SimpleDateFormat sdf, boolean dumpAll) {
        boolean needSep = true;
        dumpBroadcastList(pw, sdf, mFrozenBroadcasts, dumpIntentAction, dumpAll, "Frozen");
        dumpBroadcastList(pw, sdf, mPendingBroadcasts, dumpIntentAction, dumpAll, "Pending");

        int i;
        boolean printed = false;
@@ -187,6 +189,10 @@ public class BroadcastHistory {
            if (dumpPackage != null && !dumpPackage.equals(r.callerPackage)) {
                continue;
            }
            if (dumpIntentAction != null && !Objects.equals(dumpIntentAction,
                    r.intent.getAction())) {
                continue;
            }
            if (!printed) {
                if (needSep) {
                    pw.println();
@@ -195,7 +201,14 @@ public class BroadcastHistory {
                pw.println("  Historical broadcasts [" + queueName + "]:");
                printed = true;
            }
            if (dumpAll) {
            if (dumpIntentAction != null) {
                pw.print("  Historical Broadcast " + queueName + " #");
                pw.print(i); pw.println(":");
                r.dump(pw, "    ", sdf);
                if (!dumpAll) {
                    break;
                }
            } else if (dumpAll) {
                pw.print("  Historical Broadcast " + queueName + " #");
                pw.print(i); pw.println(":");
                r.dump(pw, "    ", sdf);
@@ -213,7 +226,7 @@ public class BroadcastHistory {
            }
        } while (ringIndex != lastIndex);

        if (dumpPackage == null) {
        if (dumpPackage == null && dumpIntentAction == null) {
            lastIndex = ringIndex = mSummaryHistoryNext;
            if (dumpAll) {
                printed = false;
@@ -276,15 +289,28 @@ public class BroadcastHistory {
    }

    private void dumpBroadcastList(@NonNull PrintWriter pw, @NonNull SimpleDateFormat sdf,
            @NonNull ArrayList<BroadcastRecord> broadcasts, @NonNull String flavor) {
            @NonNull ArrayList<BroadcastRecord> broadcasts, @Nullable String dumpIntentAction,
            boolean dumpAll, @NonNull String flavor) {
        pw.print("  "); pw.print(flavor); pw.println(" broadcasts:");
        if (broadcasts.isEmpty()) {
            pw.println("    <empty>");
        } else {
            boolean printedAnything = false;
            for (int idx = broadcasts.size() - 1; idx >= 0; --idx) {
                final BroadcastRecord r = broadcasts.get(idx);
                if (dumpIntentAction != null && !Objects.equals(dumpIntentAction,
                        r.intent.getAction())) {
                    continue;
                }
                pw.print(flavor); pw.print("  broadcast #"); pw.print(idx); pw.println(":");
                r.dump(pw, "    ", sdf);
                printedAnything = true;
                if (dumpIntentAction != null && !dumpAll) {
                    break;
                }
            }
            if (!printedAnything) {
                pw.println("    <no-matches>");
            }
        }
    }
+3 −2
Original line number Diff line number Diff line
@@ -264,7 +264,8 @@ public abstract class BroadcastQueue {
    @GuardedBy("mService")
    public abstract boolean dumpLocked(@NonNull FileDescriptor fd, @NonNull PrintWriter pw,
            @NonNull String[] args, int opti, boolean dumpConstants, boolean dumpHistory,
            boolean dumpAll, @Nullable String dumpPackage, boolean needSep);
            boolean dumpAll, @Nullable String dumpPackage, @Nullable String dumpIntentAction,
            boolean needSep);

    /**
     * Execute {@link #dumpLocked} and store the output into
@@ -276,7 +277,7 @@ public abstract class BroadcastQueue {
                    PrintWriter pw = new PrintWriter(out)) {
                pw.print("Message: ");
                pw.println(msg);
                dumpLocked(fd, pw, null, 0, false, false, false, null, false);
                dumpLocked(fd, pw, null, 0, false, false, false, null, null, false);
                pw.flush();
            }
        }, DropBoxManager.IS_TEXT);
+26 −12
Original line number Diff line number Diff line
@@ -2417,12 +2417,33 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
    @GuardedBy("mService")
    public boolean dumpLocked(@NonNull FileDescriptor fd, @NonNull PrintWriter pw,
            @NonNull String[] args, int opti, boolean dumpConstants, boolean dumpHistory,
            boolean dumpAll, @Nullable String dumpPackage, boolean needSep) {
            boolean dumpAll, @Nullable String dumpPackage, @Nullable String dumpIntentAction,
            boolean needSep) {
        final long now = SystemClock.uptimeMillis();
        final IndentingPrintWriter ipw = new IndentingPrintWriter(pw);
        ipw.increaseIndent();
        ipw.println();

        if (dumpIntentAction == null) {
            dumpProcessQueues(ipw, now);
            dumpBroadcastsWithIgnoredPolicies(ipw);
            dumpForegroundUids(ipw);

            if (dumpConstants) {
                mFgConstants.dump(ipw);
                mBgConstants.dump(ipw);
            }
        }

        if (dumpHistory) {
            final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            needSep = mHistory.dumpLocked(ipw, dumpPackage, dumpIntentAction, mQueueName,
                    sdf, dumpAll);
        }
        return needSep;
    }

    private void dumpProcessQueues(@NonNull IndentingPrintWriter ipw, @UptimeMillisLong long now) {
        ipw.println("📋 Per-process queues:");
        ipw.increaseIndent();
        for (int i = 0; i < mProcessQueues.size(); i++) {
@@ -2470,28 +2491,21 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
        }
        ipw.decreaseIndent();
        ipw.println();
    }

    private void dumpBroadcastsWithIgnoredPolicies(@NonNull IndentingPrintWriter ipw) {
        ipw.println("Broadcasts with ignored delivery group policies:");
        ipw.increaseIndent();
        mService.dumpDeliveryGroupPolicyIgnoredActions(ipw);
        ipw.decreaseIndent();
        ipw.println();
    }

    private void dumpForegroundUids(@NonNull IndentingPrintWriter ipw) {
        ipw.println("Foreground UIDs:");
        ipw.increaseIndent();
        ipw.println(mUidForeground);
        ipw.decreaseIndent();
        ipw.println();

        if (dumpConstants) {
            mFgConstants.dump(ipw);
            mBgConstants.dump(ipw);
        }

        if (dumpHistory) {
            final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            needSep = mHistory.dumpLocked(ipw, dumpPackage, mQueueName, sdf, dumpAll, needSep);
        }
        return needSep;
    }
}
Loading