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

Commit de774164 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 12855999 from 1ac8ad10 to 25Q2-release

Change-Id: If85ac89feebb7150b21c9bc00c90a39648c24495
parents 95367bcc 1ac8ad10
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.os.BundleMerger;
import android.os.PowerExemptionManager;
import android.os.PowerExemptionManager.ReasonCode;
import android.os.PowerExemptionManager.TempAllowListType;
import android.os.Process;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -76,6 +77,7 @@ public class BroadcastOptions extends ComponentOptions {
            FLAG_IS_ALARM_BROADCAST,
            FLAG_SHARE_IDENTITY,
            FLAG_INTERACTIVE,
            FLAG_DEBUG_LOG,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface Flags {}
@@ -86,6 +88,7 @@ public class BroadcastOptions extends ComponentOptions {
    private static final int FLAG_IS_ALARM_BROADCAST = 1 << 3;
    private static final int FLAG_SHARE_IDENTITY = 1 << 4;
    private static final int FLAG_INTERACTIVE = 1 << 5;
    private static final int FLAG_DEBUG_LOG = 1 << 6;

    /**
     * Change ID which is invalid.
@@ -1081,6 +1084,34 @@ public class BroadcastOptions extends ComponentOptions {
        return super.getPendingIntentBackgroundActivityStartMode();
    }

    /**
     * If enabled, additional debug messages for broadcast delivery will be logged.
     *
     * <p> This will only take effect when used by {@link Process#SHELL_UID}
     * or {@link Process#ROOT_UID} or by apps under instrumentation.
     *
     * @hide
     */
    @NonNull
    public BroadcastOptions setDebugLogEnabled(boolean enabled) {
        if (enabled) {
            mFlags |= FLAG_DEBUG_LOG;
        } else {
            mFlags &= ~FLAG_DEBUG_LOG;
        }
        return this;
    }

    /**
     * @return if additional debug messages for broadcast delivery are enabled.
     *
     * @see #setDebugLogEnabled(boolean)
     * @hide
     */
    public boolean isDebugLogEnabled() {
        return (mFlags & FLAG_DEBUG_LOG) != 0;
    }

    /**
     * Returns the created options as a Bundle, which can be passed to
     * {@link android.content.Context#sendBroadcast(android.content.Intent)
+5 −1
Original line number Diff line number Diff line
@@ -10837,8 +10837,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) {
+48 −9
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@ import static com.android.server.am.ActivityManagerService.UPDATE_HTTP_PROXY_MSG
import static com.android.server.am.ActivityManagerService.UPDATE_TIME_PREFERENCE_MSG;
import static com.android.server.am.ActivityManagerService.UPDATE_TIME_ZONE;
import static com.android.server.am.ActivityManagerService.checkComponentPermission;
import static com.android.server.am.BroadcastRecord.debugLog;
import static com.android.server.am.BroadcastRecord.intentToString;

import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -1017,6 +1019,13 @@ class BroadcastController {
                        android.Manifest.permission.ACCESS_BROADCAST_RESPONSE_STATS,
                        callingPid, callingUid, "recordResponseEventWhileInBackground");
            }

            if (brOptions.isDebugLogEnabled()) {
                if (!isShellOrRoot(callingUid)
                        && (callerApp == null || !callerApp.hasActiveInstrumentation())) {
                    brOptions.setDebugLogEnabled(false);
                }
            }
        }

        // Verify that protected broadcasts are only being sent by system code,
@@ -1622,6 +1631,10 @@ class BroadcastController {
            }
        }
        while (ir < NR) {
            // Instant Apps cannot use FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS
            if (callerInstantApp) {
                intent.setFlags(intent.getFlags() & ~Intent.FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS);
            }
            if (receivers == null) {
                receivers = new ArrayList();
            }
@@ -1647,7 +1660,9 @@ class BroadcastController {
                    callerAppProcessState, mService.mPlatformCompat);
            broadcastSentEventRecord.setBroadcastRecord(r);

            if (DEBUG_BROADCAST) Slog.v(TAG_BROADCAST, "Enqueueing ordered broadcast " + r);
            if (DEBUG_BROADCAST || r.debugLog()) {
                Slog.v(TAG_BROADCAST, "Enqueueing broadcast " + r);
            }
            queue.enqueueBroadcastLocked(r);
        } else {
            // There was nobody interested in the broadcast, but we still want to record
@@ -1657,11 +1672,19 @@ class BroadcastController {
                // This was an implicit broadcast... let's record it for posterity.
                addBroadcastStatLocked(intent.getAction(), callerPackage, 0, 0, 0);
            }
            if (DEBUG_BROADCAST || debugLog(brOptions)) {
                Slog.v(TAG_BROADCAST, "Skipping broadcast " + intentToString(intent)
                        + " due to no receivers");
            }
        }

        return ActivityManager.BROADCAST_SUCCESS;
    }

    private boolean isShellOrRoot(int uid) {
        return uid == SHELL_UID || uid == ROOT_UID;
    }

    @GuardedBy("mService")
    private void scheduleCanceledResultTo(ProcessRecord resultToApp, IIntentReceiver resultTo,
            Intent intent, int userId, BroadcastOptions options, int callingUid,
@@ -2178,6 +2201,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 +2210,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 +2229,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 +2253,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 +2297,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 +2352,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);
Loading