From b625c1a73f751b8538876bd15adcd738d95a31e1 Mon Sep 17 00:00:00 2001 From: Jacob Hobbie Date: Thu, 11 Nov 2021 16:31:18 -0800 Subject: [PATCH] Allow protected or sticky broadcsts without flags. Protected broadcasts don't need to be marked as exported or not exported since they can only be sent by the system. We're also not enforcing the flag change for sticky broadcasts since they're just asking for the most recent value. Test: just changing it back to what it was Bug: 161145287 Change-Id: I0cffe51ae8ae319032c3fb54fa73f9abca5948f4 --- .../server/am/ActivityManagerService.java | 54 +++++++++++-------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 0eed1909944f3..1f9180b26f7ba 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -12662,30 +12662,38 @@ public class ActivityManagerService extends IActivityManager.Stub "Receiver can't specify both RECEIVER_EXPORTED and RECEIVER_NOT_EXPORTED" + "flag"); } - if (CompatChanges.isChangeEnabled(DYNAMIC_RECEIVER_EXPLICIT_EXPORT_REQUIRED, - callingUid) - && !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 + + // Don't enforce the flag check if we're EITHER registering for only protected + // broadcasts, or the receiver is null (a sticky broadcast). Sticky broadcasts should + // not be used generally, so we will be marking them as exported by default + final boolean requireExplicitFlagForDynamicReceivers = CompatChanges.isChangeEnabled( + DYNAMIC_RECEIVER_EXPLICIT_EXPORT_REQUIRED, callingUid); + if (!onlyProtectedBroadcasts) { + if (receiver == null && !explicitExportStateDefined) { + // 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. flags |= Context.RECEIVER_EXPORTED; } - } else if (!CompatChanges.isChangeEnabled(DYNAMIC_RECEIVER_EXPLICIT_EXPORT_REQUIRED, - callingUid)) { - // Change is not enabled, thus not targeting T+. Assume exported. - flags |= Context.RECEIVER_EXPORTED; } } @@ -12703,7 +12711,7 @@ public class ActivityManagerService extends IActivityManager.Stub (intent.getFlags() & Intent.FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS) == 0) { continue; } - // If intent has scheme "content", it will need to acccess + // If intent has scheme "content", it will need to access // provider that needs to lock mProviderMap in ActivityThread // and also it may need to wait application response, so we // cannot lock ActivityManagerService here.