Updating receiver flag requirements and enforcement.
Since we're no longer planning on enforcing the flag requirement for exported/not exported in T, we should update the compat change so that it's disabled, which will allow developers to still test it, change the error message so it doesn't reference Android T, and remove the additional system property that enabled stricter enforcement. Test: atest ContextText Bug: 225057637 Change-Id: Ibdc079ef7e92954422ddde715b3a4ae358f552e3
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -207,7 +207,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;
|
||||
@@ -460,14 +460,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;
|
||||
@@ -584,7 +576,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;
|
||||
|
||||
/**
|
||||
@@ -13068,25 +13060,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");
|
||||
// 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.
|
||||
throw new SecurityException(
|
||||
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
|
||||
} 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) {
|
||||
|
||||
Reference in New Issue
Block a user