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

Commit 679538c8 authored by Jacob Hobbie's avatar Jacob Hobbie Committed by Automerger Merge Worker
Browse files

Merge "Updating receiver flag requirements and enforcement." into tm-dev am: 2a9b86c1

parents d06405cb 2a9b86c1
Loading
Loading
Loading
Loading
+20 −28
Original line number Diff line number Diff line
@@ -3054,13 +3054,11 @@ public abstract class Context {
     *
     * @param receiver The BroadcastReceiver to handle the broadcast.
     * @param filter Selects the Intent broadcasts to be received.
     * @param flags Additional options for the receiver. For apps targeting
     * {@link android.os.Build.VERSION_CODES#TIRAMISU},
     *              either {@link #RECEIVER_EXPORTED} or
     * {@link #RECEIVER_NOT_EXPORTED} must be specified if the receiver isn't being registered
     *              for <a href="{@docRoot}guide/components/broadcasts#system-broadcasts">system
     *              broadcasts</a> or an exception will be thrown. If
     *              {@link #RECEIVER_EXPORTED} is specified, a receiver may additionally
     * @param flags Additional options for the receiver. In a future release, either
     * {@link #RECEIVER_EXPORTED} or {@link #RECEIVER_NOT_EXPORTED} must be specified if the
     *             receiver isn't being registered for <a href="{@docRoot}guide/components
     *              /broadcasts#system-broadcasts">system broadcasts</a> or an exception will be
     *              thrown. If {@link #RECEIVER_EXPORTED} is specified, a receiver may additionally
     *              specify {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}. For a complete list of
     *              system broadcast actions, see the BROADCAST_ACTIONS.TXT file in the
     *              Android SDK. If both {@link #RECEIVER_EXPORTED} and
@@ -3137,13 +3135,11 @@ public abstract class Context {
     *      no permission is required.
     * @param scheduler Handler identifying the thread that will receive
     *      the Intent.  If null, the main thread of the process will be used.
     * @param flags Additional options for the receiver. For apps targeting
     * {@link android.os.Build.VERSION_CODES#TIRAMISU},
     *              either {@link #RECEIVER_EXPORTED} or
     * {@link #RECEIVER_NOT_EXPORTED} must be specified if the receiver isn't being registered
     *              for <a href="{@docRoot}guide/components/broadcasts#system-broadcasts">system
     *              broadcasts</a> or an exception will be thrown. If
     *              {@link #RECEIVER_EXPORTED} is specified, a receiver may additionally
     * @param flags Additional options for the receiver. In a future release, either
     * {@link #RECEIVER_EXPORTED} or {@link #RECEIVER_NOT_EXPORTED} must be specified if the
     *             receiver isn't being registered for <a href="{@docRoot}guide/components
     *              /broadcasts#system-broadcasts">system broadcasts</a> or an exception will be
     *              thrown. If {@link #RECEIVER_EXPORTED} is specified, a receiver may additionally
     *              specify {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}. For a complete list of
     *              system broadcast actions, see the BROADCAST_ACTIONS.TXT file in the
     *              Android SDK. If both {@link #RECEIVER_EXPORTED} and
@@ -3207,13 +3203,11 @@ public abstract class Context {
     *      no permission is required.
     * @param scheduler Handler identifying the thread that will receive
     *      the Intent. If {@code null}, the main thread of the process will be used.
     * @param flags Additional options for the receiver. For apps targeting
     * {@link android.os.Build.VERSION_CODES#TIRAMISU},
     *              either {@link #RECEIVER_EXPORTED} or
     * {@link #RECEIVER_NOT_EXPORTED} must be specified if the receiver isn't being registered
     *              for <a href="{@docRoot}guide/components/broadcasts#system-broadcasts">system
     *              broadcasts</a> or an exception will be thrown. If
     *              {@link #RECEIVER_EXPORTED} is specified, a receiver may additionally
     * @param flags Additional options for the receiver. In a future release, either
     * {@link #RECEIVER_EXPORTED} or {@link #RECEIVER_NOT_EXPORTED} must be specified if the
     *             receiver isn't being registered for <a href="{@docRoot}guide/components
     *              /broadcasts#system-broadcasts">system broadcasts</a> or an exception will be
     *              thrown. If {@link #RECEIVER_EXPORTED} is specified, a receiver may additionally
     *              specify {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}. For a complete list of
     *              system broadcast actions, see the BROADCAST_ACTIONS.TXT file in the
     *              Android SDK. If both {@link #RECEIVER_EXPORTED} and
@@ -3282,13 +3276,11 @@ public abstract class Context {
     *      no permission is required.
     * @param scheduler Handler identifying the thread that will receive
     *      the Intent.  If null, the main thread of the process will be used.
     * @param flags Additional options for the receiver. For apps targeting
     * {@link android.os.Build.VERSION_CODES#TIRAMISU},
     *              either {@link #RECEIVER_EXPORTED} or
     * {@link #RECEIVER_NOT_EXPORTED} must be specified if the receiver isn't being registered
     *              for <a href="{@docRoot}guide/components/broadcasts#system-broadcasts">system
     *              broadcasts</a> or an exception will be thrown. If
     *              {@link #RECEIVER_EXPORTED} is specified, a receiver may additionally
     * @param flags Additional options for the receiver. In a future release, either
     * {@link #RECEIVER_EXPORTED} or {@link #RECEIVER_NOT_EXPORTED} must be specified if the
     *             receiver isn't being registered for <a href="{@docRoot}guide/components
     *              /broadcasts#system-broadcasts">system broadcasts</a> or an exception will be
     *              thrown. If {@link #RECEIVER_EXPORTED} is specified, a receiver may additionally
     *              specify {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}. For a complete list of
     *              system broadcast actions, see the BROADCAST_ACTIONS.TXT file in the
     *              Android SDK. If both {@link #RECEIVER_EXPORTED} and
+10 −29
Original line number Diff line number Diff line
@@ -208,7 +208,7 @@ import android.app.usage.UsageStatsManagerInternal;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetManagerInternal;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledSince;
import android.compat.annotation.Disabled;
import android.content.AttributionSource;
import android.content.AutofillOptions;
import android.content.BroadcastReceiver;
@@ -461,14 +461,6 @@ public class ActivityManagerService extends IActivityManager.Stub
    private static final String SYSTEM_PROPERTY_DEVICE_PROVISIONED =
            "persist.sys.device_provisioned";
    /**
     * Enabling this flag enforces the requirement for context registered receivers to use one of
     * {@link Context#RECEIVER_EXPORTED} or {@link Context#RECEIVER_NOT_EXPORTED} for unprotected
     * broadcasts
     */
    private static final boolean ENFORCE_DYNAMIC_RECEIVER_EXPLICIT_EXPORT =
            SystemProperties.getBoolean("fw.enforce_dynamic_receiver_explicit_export", false);
    static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityManagerService" : TAG_AM;
    static final String TAG_BACKUP = TAG + POSTFIX_BACKUP;
    private static final String TAG_BROADCAST = TAG + POSTFIX_BROADCAST;
@@ -585,7 +577,7 @@ public class ActivityManagerService extends IActivityManager.Stub
     * unprotected broadcast in code.
     */
    @ChangeId
    @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
    @Disabled
    private static final long DYNAMIC_RECEIVER_EXPLICIT_EXPORT_REQUIRED = 161145287L;
    /**
@@ -13070,25 +13062,14 @@ public class ActivityManagerService extends IActivityManager.Stub
                    // sticky broadcast, no flag specified (flag isn't required)
                    flags |= Context.RECEIVER_EXPORTED;
                } else if (requireExplicitFlagForDynamicReceivers && !explicitExportStateDefined) {
                    if (ENFORCE_DYNAMIC_RECEIVER_EXPLICIT_EXPORT) {
                    throw new SecurityException(
                                callerPackage + ": Targeting T+ (version "
                                        + Build.VERSION_CODES.TIRAMISU
                                        + " and above) requires that one of RECEIVER_EXPORTED or "
                                        + "RECEIVER_NOT_EXPORTED be specified when registering a "
                                        + "receiver");
                    } else {
                        Slog.wtf(TAG,
                                callerPackage + ": Targeting T+ (version "
                                        + Build.VERSION_CODES.TIRAMISU
                                        + " and above) requires that one of RECEIVER_EXPORTED or "
                                        + "RECEIVER_NOT_EXPORTED be specified when registering a "
                                        + "receiver");
                            callerPackage + ": One of RECEIVER_EXPORTED or "
                                    + "RECEIVER_NOT_EXPORTED should be specified when a receiver "
                                    + "isn't being registered exclusively for system broadcasts");
                    // Assume default behavior-- flag check is not enforced
                        flags |= Context.RECEIVER_EXPORTED;
                    }
                } else if (!requireExplicitFlagForDynamicReceivers) {
                    // Change is not enabled, thus not targeting T+. Assume exported.
                } else if (!requireExplicitFlagForDynamicReceivers && (
                        (flags & Context.RECEIVER_NOT_EXPORTED) == 0)) {
                    // Change is not enabled, assume exported unless otherwise specified.
                    flags |= Context.RECEIVER_EXPORTED;
                }
            } else if ((flags & Context.RECEIVER_NOT_EXPORTED) == 0) {