From 4a85611d5b7dcb877b09eb8d5e315577eb45313a Mon Sep 17 00:00:00 2001 From: Michael Groover Date: Thu, 15 Dec 2022 20:25:11 -0600 Subject: Update docs to reflect new receiver flag enforcement Android T allows apps to declare a runtime receiver as not exported by invoking registerReceiver with a new RECEIVER_NOT_EXPORTED flag; receivers registered with this flag will only receive broadcasts from the platform and the app itself. However to ensure developers can properly protect their receivers, all apps targeting U or later registering a receiver for non-system broadcasts must specify either the exported or not exported flag when invoking #registerReceiver. This commit updates the docs to reflect this new requirement. Bug: 234659204 Test: m -j offline-sdk-docs Change-Id: I86fe8b66f963064db7420bebb502c2d125327bc0 --- core/java/android/content/Context.java | 97 ++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 41 deletions(-) diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index 382e2bb6ee43..bb3bf5cc2b18 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -3045,6 +3045,14 @@ public abstract class Context { * Prior to that, it would be ignored and delivered to all matching registered * receivers. Be careful if using this for security.

* + *

For apps targeting {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE}, + * either {@link #RECEIVER_EXPORTED} or {@link #RECEIVER_NOT_EXPORTED} must be + * specified if the receiver is not being registered for system broadcasts + * or a {@link SecurityException} will be thrown. See {@link + * #registerReceiver(BroadcastReceiver, IntentFilter, int)} to register a receiver with + * flags. + * *

Note: this method cannot be called from a * {@link BroadcastReceiver} component; that is, from a BroadcastReceiver * that is declared in an application's manifest. It is okay, however, to call @@ -3084,16 +3092,16 @@ 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. In a future release, either - * {@link #RECEIVER_EXPORTED} or {@link #RECEIVER_NOT_EXPORTED} must be specified if the - * receiver isn't being registered for system broadcasts 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 - * {@link #RECEIVER_NOT_EXPORTED} are specified, an exception will be thrown as - * well. + * @param flags Additional options for the receiver. For apps targeting {@link + * android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE} either {@link #RECEIVER_EXPORTED} or + * {@link #RECEIVER_NOT_EXPORTED} must be specified if the receiver isn't being registered + * for system + * broadcasts or a {@link SecurityException} 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 {@link #RECEIVER_NOT_EXPORTED} are specified, an {@link + * IllegalArgumentException} will be thrown. * * @return The first sticky intent found that matches filter, * or null if there are none. @@ -3123,6 +3131,14 @@ public abstract class Context { * Prior to that, it would be ignored and delivered to all matching registered * receivers. Be careful if using this for security.

* + *

For apps targeting {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE}, + * either {@link #RECEIVER_EXPORTED} or {@link #RECEIVER_NOT_EXPORTED} must be + * specified if the receiver is not being registered for system broadcasts + * or a {@link SecurityException} will be thrown. See {@link + * #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler, int)} to register a + * receiver with flags. + * * @param receiver The BroadcastReceiver to handle the broadcast. * @param filter Selects the Intent broadcasts to be received. * @param broadcastPermission String naming a permissions that a @@ -3165,17 +3181,16 @@ 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. In a future release, either - * {@link #RECEIVER_EXPORTED} or {@link #RECEIVER_NOT_EXPORTED} must be specified if the - * receiver isn't being registered for system broadcasts 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 - * {@link #RECEIVER_NOT_EXPORTED} are specified, an exception will be thrown as - * well. - * + * @param flags Additional options for the receiver. For apps targeting {@link + * android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE} either {@link #RECEIVER_EXPORTED} or + * {@link #RECEIVER_NOT_EXPORTED} must be specified if the receiver isn't being registered + * for system + * broadcasts or a {@link SecurityException} 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 {@link #RECEIVER_NOT_EXPORTED} are specified, an {@link + * IllegalArgumentException} will be thrown. * @return The first sticky intent found that matches filter, * or null if there are none. * @@ -3233,16 +3248,16 @@ 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. In a future release, either - * {@link #RECEIVER_EXPORTED} or {@link #RECEIVER_NOT_EXPORTED} must be specified if the - * receiver isn't being registered for system broadcasts 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 - * {@link #RECEIVER_NOT_EXPORTED} are specified, an exception will be thrown as - * well. + * @param flags Additional options for the receiver. For apps targeting {@link + * android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE} either {@link #RECEIVER_EXPORTED} or + * {@link #RECEIVER_NOT_EXPORTED} must be specified if the receiver isn't being registered + * for system + * broadcasts or a {@link SecurityException} 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 {@link #RECEIVER_NOT_EXPORTED} are specified, an {@link + * IllegalArgumentException} will be thrown. * * @return The first sticky intent found that matches filter, * or {@code null} if there are none. @@ -3306,16 +3321,16 @@ 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. In a future release, either - * {@link #RECEIVER_EXPORTED} or {@link #RECEIVER_NOT_EXPORTED} must be specified if the - * receiver isn't being registered for system broadcasts 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 - * {@link #RECEIVER_NOT_EXPORTED} are specified, an exception will be thrown as - * well. + * @param flags Additional options for the receiver. For apps targeting {@link + * android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE} either {@link #RECEIVER_EXPORTED} or + * {@link #RECEIVER_NOT_EXPORTED} must be specified if the receiver isn't being registered + * for system + * broadcasts or a {@link SecurityException} 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 {@link #RECEIVER_NOT_EXPORTED} are specified, an {@link + * IllegalArgumentException} will be thrown. * * @return The first sticky intent found that matches filter, * or null if there are none. -- cgit v1.2.3-59-g8ed1b