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

Commit 8f7bd454 authored by Gavin Corkery's avatar Gavin Corkery Committed by Android (Google) Code Review
Browse files

Merge "Enforce that sdk sandbox may only bind/start allowed services" into tm-dev

parents 92ad3ae5 65a00767
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -2949,6 +2949,27 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
    }
    /**
     * If the caller is an {@link Process#isSdkSandboxUid(int) SDK sandbox uid}, enforces that the
     * SDK sandbox has permission to start or bind to a given service.
     *
     * @param intent the intent used to start or bind to the service.
     * @throws IllegalStateException if {@link SdkSandboxManagerLocal} cannot be resolved.
     * @throws SecurityException if the SDK sandbox is not allowed to bind to this service.
     */
    private void enforceAllowedToStartOrBindServiceIfSdkSandbox(Intent intent) {
        if (Process.isSdkSandboxUid(Binder.getCallingUid())) {
            SdkSandboxManagerLocal sdkSandboxManagerLocal =
                    LocalManagerRegistry.getManager(SdkSandboxManagerLocal.class);
            if (sdkSandboxManagerLocal != null) {
                sdkSandboxManagerLocal.enforceAllowedToStartOrBindService(intent);
            } else {
                throw new IllegalStateException("SdkSandboxManagerLocal not found when checking"
                        + " whether SDK sandbox uid may start or bind to a service.");
            }
        }
    }
    @Override
    public void setPackageScreenCompatMode(String packageName, int mode) {
        mActivityTaskManager.setPackageScreenCompatMode(packageName, mode);
@@ -12363,6 +12384,7 @@ public class ActivityManagerService extends IActivityManager.Stub
            String callingFeatureId, int userId)
            throws TransactionTooLargeException {
        enforceNotIsolatedCaller("startService");
        enforceAllowedToStartOrBindServiceIfSdkSandbox(service);
        // Refuse possible leaked file descriptors
        if (service != null && service.hasFileDescriptors() == true) {
            throw new IllegalArgumentException("File descriptors passed in Intent");
@@ -12523,6 +12545,7 @@ public class ActivityManagerService extends IActivityManager.Stub
            String sdkSandboxClientAppPackage, String callingPackage, int userId)
            throws TransactionTooLargeException {
        enforceNotIsolatedCaller("bindService");
        enforceAllowedToStartOrBindServiceIfSdkSandbox(service);
        // Refuse possible leaked file descriptors
        if (service != null && service.hasFileDescriptors() == true) {