Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2e0b2357 authored by Palak Chaudhary's avatar Palak Chaudhary
Browse files

Use canSendBroadcast instead of enforceAllowedToSendBroadcast

Use canSendBroadcast to check if broadcast can be sent from sandbox
process which returns a boolean and lets ActivityManagerService handle
the denial of access before throwing an error

Bug: b/266069576

Test: atest SdkSandboxRestrictionsTest#testSendBroadcastsRestrictions_withAction
atest SdkSandboxRestrictionsTest#testSendBroadcastRestrictions_withoutAction

Change-Id: I846dcc733d498095460a28904e953245e65e5a68
parent 70811b33
Loading
Loading
Loading
Loading
+15 −10
Original line number Diff line number Diff line
@@ -14167,6 +14167,21 @@ public class ActivityManagerService extends IActivityManager.Stub
        // Ensure all internal loopers are registered for idle checks
        BroadcastLoopers.addMyLooper();
        if (Process.isSdkSandboxUid(realCallingUid)) {
            final SdkSandboxManagerLocal sdkSandboxManagerLocal = LocalManagerRegistry.getManager(
                    SdkSandboxManagerLocal.class);
            if (sdkSandboxManagerLocal == null) {
                throw new IllegalStateException("SdkSandboxManagerLocal not found when sending"
                        + " a broadcast from an SDK sandbox uid.");
            }
            if (!sdkSandboxManagerLocal.canSendBroadcast(intent)) {
                throw new SecurityException(
                        "Intent " + intent.getAction() + " may not be broadcast from an SDK sandbox"
                        + " uid. Given caller package " + callerPackage + " (pid=" + callingPid
                        + ", uid=" + callingUid + ")");
            }
        }
        if ((resultTo != null) && (resultToApp == null)) {
            if (resultTo.asBinder() instanceof BinderProxy) {
                // Warn when requesting results without a way to deliver them
@@ -14371,16 +14386,6 @@ public class ActivityManagerService extends IActivityManager.Stub
            }
        }
        if (Process.isSdkSandboxUid(realCallingUid)) {
            SdkSandboxManagerLocal sdkSandboxManagerLocal = LocalManagerRegistry.getManager(
                    SdkSandboxManagerLocal.class);
            if (sdkSandboxManagerLocal == null) {
                throw new IllegalStateException("SdkSandboxManagerLocal not found when sending"
                    + " a broadcast from an SDK sandbox uid.");
            }
            sdkSandboxManagerLocal.enforceAllowedToSendBroadcast(intent);
        }
        boolean timeoutExempt = false;
        if (action != null) {