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

Commit 41b56bc2 authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

Add BroadcastOptions.setDebugReason()

This new option allows a caller to pass a debug reason along with the
broadcast, which will be used for debugging and logging purposes.

Bug: 422072501
Test: manual
Flag: EXEMPT hidden api for logging purposes
Change-Id: I061a852834414c86bdc026adc0527c246254ea4d
parent d4fca214
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
@@ -1030,6 +1030,10 @@ class BroadcastController {
                    brOptions.setDebugLogEnabled(false);
                }
            }

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

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