From 7b40358fa316038ce6a3243b8706c6f5b7a49536 Mon Sep 17 00:00:00 2001 From: Svet Ganov Date: Sun, 3 Jun 2018 21:09:55 -0700 Subject: [PATCH] Allow instant apps to send broadcasts to themselves When resolving the broadcast targets we did not consider instant apps even if the source is an instant app. This prevents the case of the instant app sending the broadcast to itself. The broadcast queue already enforces that if the broadcast is not from a full app that wants to advertise to instant apps or not from an instant app sending it to itself then it is not dispatched. Hence, the broadcast queue already determines the right targeting. This change makes sure that if the source is an instant app we also resolve instant apps and then the targeting logic in the boradcast queue would ensure that an instant app can only send a boradcast to its own UID. Test: cts-instant-tradefed run cts-instant-dev -m CtsBackgroundRestrictionsTestCases -t android.app.cts.backgroundrestrictions.BroadcastsTest #testNonSupportedBroadcastsNotDelivered_manifestReceiver bug:109583877 Change-Id: Ifb7230df87c4721e4c05d77b5957d825f3846ca7 --- .../com/android/server/am/ActivityManagerService.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index e95a9327cfb32..96733e24d31e0 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -21021,9 +21021,15 @@ public class ActivityManagerService extends IActivityManager.Stub } private List collectReceiverComponents(Intent intent, String resolvedType, - int callingUid, int[] users) { + int callingUid, boolean callerInstantApp, int[] users) { // TODO: come back and remove this assumption to triage all broadcasts int pmFlags = STOCK_PM_FLAGS | MATCH_DEBUG_TRIAGED_MISSING; + // Instant apps should be able to send broadcasts to themselves, so we would + // match instant receivers and later the broadcast queue would enforce that + // the broadcast cannot be sent to a receiver outside the instant UID. + if (callerInstantApp) { + pmFlags |= PackageManager.MATCH_INSTANT; + } List receivers = null; try { @@ -21652,7 +21658,8 @@ public class ActivityManagerService extends IActivityManager.Stub // Need to resolve the intent to interested receivers... if ((intent.getFlags()&Intent.FLAG_RECEIVER_REGISTERED_ONLY) == 0) { - receivers = collectReceiverComponents(intent, resolvedType, callingUid, users); + receivers = collectReceiverComponents(intent, resolvedType, callingUid, + callerInstantApp, users); } if (intent.getComponent() == null) { if (userId == UserHandle.USER_ALL && callingUid == SHELL_UID) {