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

Commit 36023cdd authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Android (Google) Code Review
Browse files

Merge "Add BroadcastOptions.setDebugReason()" into main

parents fcc0d7a0 41b56bc2
Loading
Loading
Loading
Loading
+35 −0
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ public class BroadcastOptions extends ComponentOptions {
    private @Nullable IntentFilter mDeliveryGroupMatchingFilter;
    private @DeferralPolicy int mDeferralPolicy;
    private @Nullable String[] mIncludedPackages;
    private @Nullable String mDebugReason;

    /** @hide */
    @IntDef(flag = true, prefix = { "FLAG_" }, value = {
@@ -239,6 +240,11 @@ public class BroadcastOptions extends ComponentOptions {
    private static final String KEY_INCLUDED_PACKAGES =
            "android:broadcast.includedPackageNames";

    /**
     * Corresponds to {@link #setDebugReason(String)}
     */
    private static final String KEY_DEBUG_REASON = "android:broadcast.debugReason";

    /**
     * The list of delivery group policies which specify how multiple broadcasts belonging to
     * the same delivery group has to be handled.
@@ -365,6 +371,7 @@ public class BroadcastOptions extends ComponentOptions {
                IntentFilter.class);
        mDeferralPolicy = opts.getInt(KEY_DEFERRAL_POLICY, DEFERRAL_POLICY_DEFAULT);
        mIncludedPackages = opts.getStringArray(KEY_INCLUDED_PACKAGES);
        mDebugReason = opts.getString(KEY_DEBUG_REASON);
    }

    /** @hide */
@@ -1143,6 +1150,31 @@ public class BroadcastOptions extends ComponentOptions {
        return mIncludedPackages;
    }

    /**
     * Set the reason for triggering the broadcast. This is meant to be used for
     * debugging and logging purposes.
     *
     * <p> This will only take effect when used by core uids, as determined by
     * {@link UserHandle#isCore(int)}.
     *
     * @hide
     */
    public BroadcastOptions setDebugReason(@Nullable String debugReason) {
        mDebugReason = debugReason;
        return this;
    }

    /**
     * Get the reason for triggering the broadcast, that was previously set using
     * {@link #setDebugReason(String)}.
     *
     * @hide
     */
    @Nullable
    public String getDebugReason() {
        return mDebugReason;
    }

    /**
     * Returns the created options as a Bundle, which can be passed to
     * {@link android.content.Context#sendBroadcast(android.content.Intent)
@@ -1212,6 +1244,9 @@ public class BroadcastOptions extends ComponentOptions {
        if (!ArrayUtils.isEmpty(mIncludedPackages)) {
            b.putStringArray(KEY_INCLUDED_PACKAGES, mIncludedPackages);
        }
        if (mDebugReason != null) {
            b.putString(KEY_DEBUG_REASON, mDebugReason);
        }
        return b;
    }

+4 −0
Original line number Diff line number Diff line
@@ -1032,6 +1032,10 @@ class BroadcastController {
                    brOptions.setDebugLogEnabled(false);
                }
            }

            if (!UserHandle.isCore(callingUid)) {
                brOptions.setDebugReason(null);
            }
        }

        // Verify that protected broadcasts are only being sent by system code,