Loading core/java/android/app/BroadcastOptions.java +0 −34 Original line number Diff line number Diff line Loading @@ -63,7 +63,6 @@ public class BroadcastOptions extends ComponentOptions { private long mRequireCompatChangeId = CHANGE_INVALID; private boolean mRequireCompatChangeEnabled = true; private boolean mIsAlarmBroadcast = false; private boolean mIsInteractiveBroadcast = false; private long mIdForResponseEvent; private @Nullable IntentFilter mRemoveMatchingFilter; private @DeliveryGroupPolicy int mDeliveryGroupPolicy; Loading Loading @@ -170,13 +169,6 @@ public class BroadcastOptions extends ComponentOptions { public static final String KEY_ALARM_BROADCAST = "android:broadcast.is_alarm"; /** * Corresponds to {@link #setInteractiveBroadcast(boolean)} * @hide */ public static final String KEY_INTERACTIVE_BROADCAST = "android:broadcast.is_interactive"; /** * @hide * @deprecated Use {@link android.os.PowerExemptionManager# Loading Loading @@ -308,7 +300,6 @@ public class BroadcastOptions extends ComponentOptions { mRequireCompatChangeEnabled = opts.getBoolean(KEY_REQUIRE_COMPAT_CHANGE_ENABLED, true); mIdForResponseEvent = opts.getLong(KEY_ID_FOR_RESPONSE_EVENT); mIsAlarmBroadcast = opts.getBoolean(KEY_ALARM_BROADCAST, false); mIsInteractiveBroadcast = opts.getBoolean(KEY_INTERACTIVE_BROADCAST, false); mRemoveMatchingFilter = opts.getParcelable(KEY_REMOVE_MATCHING_FILTER, IntentFilter.class); mDeliveryGroupPolicy = opts.getInt(KEY_DELIVERY_GROUP_POLICY, Loading Loading @@ -628,28 +619,6 @@ public class BroadcastOptions extends ComponentOptions { return mIsAlarmBroadcast; } /** * When set, this broadcast will be understood as having originated from * some direct interaction by the user such as a notification tap or button * press. Only the OS itself may use this option. * @hide * @param broadcastIsInteractive * @see #isInteractiveBroadcast() */ @RequiresPermission(android.Manifest.permission.BROADCAST_OPTION_INTERACTIVE) public void setInteractiveBroadcast(boolean broadcastIsInteractive) { mIsInteractiveBroadcast = broadcastIsInteractive; } /** * Did this broadcast originate with a direct user interaction? * @return true if this broadcast is the result of an interaction, false otherwise * @hide */ public boolean isInteractiveBroadcast() { return mIsInteractiveBroadcast; } /** * Did this broadcast originate from a push message from the server? * Loading Loading @@ -837,9 +806,6 @@ public class BroadcastOptions extends ComponentOptions { if (mIsAlarmBroadcast) { b.putBoolean(KEY_ALARM_BROADCAST, true); } if (mIsInteractiveBroadcast) { b.putBoolean(KEY_INTERACTIVE_BROADCAST, true); } if (mMinManifestReceiverApiLevel != 0) { b.putInt(KEY_MIN_MANIFEST_RECEIVER_API_LEVEL, mMinManifestReceiverApiLevel); } Loading core/java/android/app/ComponentOptions.java +34 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.app; import android.annotation.RequiresPermission; import android.os.Bundle; /** Loading Loading @@ -45,8 +46,15 @@ public class ComponentOptions { public static final String KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED_BY_PERMISSION = "android.pendingIntent.backgroundActivityAllowedByPermission"; /** * Corresponds to {@link #setInteractive(boolean)} * @hide */ public static final String KEY_INTERACTIVE = "android:component.isInteractive"; private boolean mPendingIntentBalAllowed = PENDING_INTENT_BAL_ALLOWED_DEFAULT; private boolean mPendingIntentBalAllowedByPermission = false; private boolean mIsInteractive = false; ComponentOptions() { } Loading @@ -61,6 +69,29 @@ public class ComponentOptions { setPendingIntentBackgroundActivityLaunchAllowedByPermission( opts.getBoolean(KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED_BY_PERMISSION, false)); mIsInteractive = opts.getBoolean(KEY_INTERACTIVE, false); } /** * When set, a broadcast will be understood as having originated from * some direct interaction by the user such as a notification tap or button * press. Only the OS itself may use this option. * @hide * @param interactive * @see #isInteractive() */ @RequiresPermission(android.Manifest.permission.COMPONENT_OPTION_INTERACTIVE) public void setInteractive(boolean interactive) { mIsInteractive = interactive; } /** * Did this PendingIntent send originate with a direct user interaction? * @return true if this is the result of an interaction, false otherwise * @hide */ public boolean isInteractive() { return mIsInteractive; } /** Loading Loading @@ -103,6 +134,9 @@ public class ComponentOptions { b.putBoolean(KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED_BY_PERMISSION, mPendingIntentBalAllowedByPermission); } if (mIsInteractive) { b.putBoolean(KEY_INTERACTIVE, true); } return b; } } core/res/AndroidManifest.xml +3 −3 Original line number Diff line number Diff line Loading @@ -3177,10 +3177,10 @@ <permission android:name="android.permission.START_FOREGROUND_SERVICES_FROM_BACKGROUND" android:protectionLevel="signature|privileged|vendorPrivileged|oem|verifier|role"/> <!-- Allows an application to hint that a broadcast is associated with an "interactive" usage scenario <!-- Allows an application to hint that a component lifecycle operation such as sending a broadcast is associated with an "interactive" usage scenario. @hide --> <permission android:name="android.permission.BROADCAST_OPTION_INTERACTIVE" <permission android:name="android.permission.COMPONENT_OPTION_INTERACTIVE" android:protectionLevel="signature|privileged" /> <!-- @SystemApi Must be required by activities that handle the intent action Loading core/tests/coretests/src/android/app/activity/BroadcastTest.java +6 −6 Original line number Diff line number Diff line Loading @@ -541,35 +541,35 @@ public class BroadcastTest extends ActivityTestsBase { public void testBroadcastOption_interactive() throws Exception { final BroadcastOptions options = BroadcastOptions.makeBasic(); options.setInteractiveBroadcast(true); options.setInteractive(true); final Intent intent = makeBroadcastIntent(BROADCAST_REGISTERED); try { getContext().sendBroadcast(intent, null, options.toBundle()); fail("No exception thrown with BroadcastOptions.setInteractiveBroadcast(true)"); fail("No exception thrown with BroadcastOptions.setInteractive(true)"); } catch (SecurityException se) { // Expected, correct behavior - this case intentionally empty } catch (Exception e) { fail("Unexpected exception " + e.getMessage() + " thrown with BroadcastOptions.setInteractiveBroadcast(true)"); + " thrown with BroadcastOptions.setInteractive(true)"); } } public void testBroadcastOption_interactive_PendingIntent() throws Exception { final BroadcastOptions options = BroadcastOptions.makeBasic(); options.setInteractiveBroadcast(true); options.setInteractive(true); final Intent intent = makeBroadcastIntent(BROADCAST_REGISTERED); PendingIntent brPending = PendingIntent.getBroadcast(getContext(), 1, intent, PendingIntent.FLAG_IMMUTABLE); try { brPending.send(getContext(), 1, null, null, null, null, options.toBundle()); fail("No exception thrown with BroadcastOptions.setInteractiveBroadcast(true)"); fail("No exception thrown with BroadcastOptions.setInteractive(true)"); } catch (SecurityException se) { // Expected, correct behavior - this case intentionally empty } catch (Exception e) { fail("Unexpected exception " + e.getMessage() + " thrown with BroadcastOptions.setInteractiveBroadcast(true)"); + " thrown with BroadcastOptions.setInteractive(true)"); } finally { brPending.cancel(); } Loading services/core/java/com/android/server/am/ActivityManagerService.java +4 −3 Original line number Diff line number Diff line Loading @@ -181,6 +181,7 @@ import android.app.ApplicationErrorReport; import android.app.ApplicationExitInfo; import android.app.ApplicationThreadConstants; import android.app.BroadcastOptions; import android.app.ComponentOptions; import android.app.ContentProviderHolder; import android.app.IActivityController; import android.app.IActivityManager; Loading Loading @@ -13914,10 +13915,10 @@ public class ActivityManagerService extends IActivityManager.Stub throw new SecurityException( "Non-system callers may not flag broadcasts as alarm"); } if (options.containsKey(BroadcastOptions.KEY_INTERACTIVE_BROADCAST)) { if (options.containsKey(ComponentOptions.KEY_INTERACTIVE)) { enforceCallingPermission( android.Manifest.permission.BROADCAST_OPTION_INTERACTIVE, "setInteractiveBroadcast"); android.Manifest.permission.COMPONENT_OPTION_INTERACTIVE, "setInteractive"); } } } Loading
core/java/android/app/BroadcastOptions.java +0 −34 Original line number Diff line number Diff line Loading @@ -63,7 +63,6 @@ public class BroadcastOptions extends ComponentOptions { private long mRequireCompatChangeId = CHANGE_INVALID; private boolean mRequireCompatChangeEnabled = true; private boolean mIsAlarmBroadcast = false; private boolean mIsInteractiveBroadcast = false; private long mIdForResponseEvent; private @Nullable IntentFilter mRemoveMatchingFilter; private @DeliveryGroupPolicy int mDeliveryGroupPolicy; Loading Loading @@ -170,13 +169,6 @@ public class BroadcastOptions extends ComponentOptions { public static final String KEY_ALARM_BROADCAST = "android:broadcast.is_alarm"; /** * Corresponds to {@link #setInteractiveBroadcast(boolean)} * @hide */ public static final String KEY_INTERACTIVE_BROADCAST = "android:broadcast.is_interactive"; /** * @hide * @deprecated Use {@link android.os.PowerExemptionManager# Loading Loading @@ -308,7 +300,6 @@ public class BroadcastOptions extends ComponentOptions { mRequireCompatChangeEnabled = opts.getBoolean(KEY_REQUIRE_COMPAT_CHANGE_ENABLED, true); mIdForResponseEvent = opts.getLong(KEY_ID_FOR_RESPONSE_EVENT); mIsAlarmBroadcast = opts.getBoolean(KEY_ALARM_BROADCAST, false); mIsInteractiveBroadcast = opts.getBoolean(KEY_INTERACTIVE_BROADCAST, false); mRemoveMatchingFilter = opts.getParcelable(KEY_REMOVE_MATCHING_FILTER, IntentFilter.class); mDeliveryGroupPolicy = opts.getInt(KEY_DELIVERY_GROUP_POLICY, Loading Loading @@ -628,28 +619,6 @@ public class BroadcastOptions extends ComponentOptions { return mIsAlarmBroadcast; } /** * When set, this broadcast will be understood as having originated from * some direct interaction by the user such as a notification tap or button * press. Only the OS itself may use this option. * @hide * @param broadcastIsInteractive * @see #isInteractiveBroadcast() */ @RequiresPermission(android.Manifest.permission.BROADCAST_OPTION_INTERACTIVE) public void setInteractiveBroadcast(boolean broadcastIsInteractive) { mIsInteractiveBroadcast = broadcastIsInteractive; } /** * Did this broadcast originate with a direct user interaction? * @return true if this broadcast is the result of an interaction, false otherwise * @hide */ public boolean isInteractiveBroadcast() { return mIsInteractiveBroadcast; } /** * Did this broadcast originate from a push message from the server? * Loading Loading @@ -837,9 +806,6 @@ public class BroadcastOptions extends ComponentOptions { if (mIsAlarmBroadcast) { b.putBoolean(KEY_ALARM_BROADCAST, true); } if (mIsInteractiveBroadcast) { b.putBoolean(KEY_INTERACTIVE_BROADCAST, true); } if (mMinManifestReceiverApiLevel != 0) { b.putInt(KEY_MIN_MANIFEST_RECEIVER_API_LEVEL, mMinManifestReceiverApiLevel); } Loading
core/java/android/app/ComponentOptions.java +34 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.app; import android.annotation.RequiresPermission; import android.os.Bundle; /** Loading Loading @@ -45,8 +46,15 @@ public class ComponentOptions { public static final String KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED_BY_PERMISSION = "android.pendingIntent.backgroundActivityAllowedByPermission"; /** * Corresponds to {@link #setInteractive(boolean)} * @hide */ public static final String KEY_INTERACTIVE = "android:component.isInteractive"; private boolean mPendingIntentBalAllowed = PENDING_INTENT_BAL_ALLOWED_DEFAULT; private boolean mPendingIntentBalAllowedByPermission = false; private boolean mIsInteractive = false; ComponentOptions() { } Loading @@ -61,6 +69,29 @@ public class ComponentOptions { setPendingIntentBackgroundActivityLaunchAllowedByPermission( opts.getBoolean(KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED_BY_PERMISSION, false)); mIsInteractive = opts.getBoolean(KEY_INTERACTIVE, false); } /** * When set, a broadcast will be understood as having originated from * some direct interaction by the user such as a notification tap or button * press. Only the OS itself may use this option. * @hide * @param interactive * @see #isInteractive() */ @RequiresPermission(android.Manifest.permission.COMPONENT_OPTION_INTERACTIVE) public void setInteractive(boolean interactive) { mIsInteractive = interactive; } /** * Did this PendingIntent send originate with a direct user interaction? * @return true if this is the result of an interaction, false otherwise * @hide */ public boolean isInteractive() { return mIsInteractive; } /** Loading Loading @@ -103,6 +134,9 @@ public class ComponentOptions { b.putBoolean(KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED_BY_PERMISSION, mPendingIntentBalAllowedByPermission); } if (mIsInteractive) { b.putBoolean(KEY_INTERACTIVE, true); } return b; } }
core/res/AndroidManifest.xml +3 −3 Original line number Diff line number Diff line Loading @@ -3177,10 +3177,10 @@ <permission android:name="android.permission.START_FOREGROUND_SERVICES_FROM_BACKGROUND" android:protectionLevel="signature|privileged|vendorPrivileged|oem|verifier|role"/> <!-- Allows an application to hint that a broadcast is associated with an "interactive" usage scenario <!-- Allows an application to hint that a component lifecycle operation such as sending a broadcast is associated with an "interactive" usage scenario. @hide --> <permission android:name="android.permission.BROADCAST_OPTION_INTERACTIVE" <permission android:name="android.permission.COMPONENT_OPTION_INTERACTIVE" android:protectionLevel="signature|privileged" /> <!-- @SystemApi Must be required by activities that handle the intent action Loading
core/tests/coretests/src/android/app/activity/BroadcastTest.java +6 −6 Original line number Diff line number Diff line Loading @@ -541,35 +541,35 @@ public class BroadcastTest extends ActivityTestsBase { public void testBroadcastOption_interactive() throws Exception { final BroadcastOptions options = BroadcastOptions.makeBasic(); options.setInteractiveBroadcast(true); options.setInteractive(true); final Intent intent = makeBroadcastIntent(BROADCAST_REGISTERED); try { getContext().sendBroadcast(intent, null, options.toBundle()); fail("No exception thrown with BroadcastOptions.setInteractiveBroadcast(true)"); fail("No exception thrown with BroadcastOptions.setInteractive(true)"); } catch (SecurityException se) { // Expected, correct behavior - this case intentionally empty } catch (Exception e) { fail("Unexpected exception " + e.getMessage() + " thrown with BroadcastOptions.setInteractiveBroadcast(true)"); + " thrown with BroadcastOptions.setInteractive(true)"); } } public void testBroadcastOption_interactive_PendingIntent() throws Exception { final BroadcastOptions options = BroadcastOptions.makeBasic(); options.setInteractiveBroadcast(true); options.setInteractive(true); final Intent intent = makeBroadcastIntent(BROADCAST_REGISTERED); PendingIntent brPending = PendingIntent.getBroadcast(getContext(), 1, intent, PendingIntent.FLAG_IMMUTABLE); try { brPending.send(getContext(), 1, null, null, null, null, options.toBundle()); fail("No exception thrown with BroadcastOptions.setInteractiveBroadcast(true)"); fail("No exception thrown with BroadcastOptions.setInteractive(true)"); } catch (SecurityException se) { // Expected, correct behavior - this case intentionally empty } catch (Exception e) { fail("Unexpected exception " + e.getMessage() + " thrown with BroadcastOptions.setInteractiveBroadcast(true)"); + " thrown with BroadcastOptions.setInteractive(true)"); } finally { brPending.cancel(); } Loading
services/core/java/com/android/server/am/ActivityManagerService.java +4 −3 Original line number Diff line number Diff line Loading @@ -181,6 +181,7 @@ import android.app.ApplicationErrorReport; import android.app.ApplicationExitInfo; import android.app.ApplicationThreadConstants; import android.app.BroadcastOptions; import android.app.ComponentOptions; import android.app.ContentProviderHolder; import android.app.IActivityController; import android.app.IActivityManager; Loading Loading @@ -13914,10 +13915,10 @@ public class ActivityManagerService extends IActivityManager.Stub throw new SecurityException( "Non-system callers may not flag broadcasts as alarm"); } if (options.containsKey(BroadcastOptions.KEY_INTERACTIVE_BROADCAST)) { if (options.containsKey(ComponentOptions.KEY_INTERACTIVE)) { enforceCallingPermission( android.Manifest.permission.BROADCAST_OPTION_INTERACTIVE, "setInteractiveBroadcast"); android.Manifest.permission.COMPONENT_OPTION_INTERACTIVE, "setInteractive"); } } }