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

Commit ddd58052 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add hidden flag for allowing system app to use BAL permission to launch...

Merge "Add hidden flag for allowing system app to use BAL permission to launch pending intent in background" into tm-dev am: 9cb2bb4e am: 0a444b32

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18486605



Change-Id: I7458bf01d3849774842bb6ae78d437f55d861f7b
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 2cbe9284 0a444b32
Loading
Loading
Loading
Loading
+30 −0
Original line number Original line Diff line number Diff line
@@ -38,7 +38,15 @@ public class ComponentOptions {
    public static final String KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED =
    public static final String KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED =
            "android.pendingIntent.backgroundActivityAllowed";
            "android.pendingIntent.backgroundActivityAllowed";


    /**
     * PendingIntent caller allows activity to be started if caller has BAL permission.
     * @hide
     */
    public static final String KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED_BY_PERMISSION =
            "android.pendingIntent.backgroundActivityAllowedByPermission";

    private boolean mPendingIntentBalAllowed = PENDING_INTENT_BAL_ALLOWED_DEFAULT;
    private boolean mPendingIntentBalAllowed = PENDING_INTENT_BAL_ALLOWED_DEFAULT;
    private boolean mPendingIntentBalAllowedByPermission = false;


    ComponentOptions() {
    ComponentOptions() {
    }
    }
@@ -50,6 +58,9 @@ public class ComponentOptions {
        setPendingIntentBackgroundActivityLaunchAllowed(
        setPendingIntentBackgroundActivityLaunchAllowed(
                opts.getBoolean(KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED,
                opts.getBoolean(KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED,
                        PENDING_INTENT_BAL_ALLOWED_DEFAULT));
                        PENDING_INTENT_BAL_ALLOWED_DEFAULT));
        setPendingIntentBackgroundActivityLaunchAllowedByPermission(
                opts.getBoolean(KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED_BY_PERMISSION,
                        false));
    }
    }


    /**
    /**
@@ -68,9 +79,28 @@ public class ComponentOptions {
        return mPendingIntentBalAllowed;
        return mPendingIntentBalAllowed;
    }
    }


    /**
     * Set PendingIntent activity can be launched from background if caller has BAL permission.
     * @hide
     */
    public void setPendingIntentBackgroundActivityLaunchAllowedByPermission(boolean allowed) {
        mPendingIntentBalAllowedByPermission = allowed;
    }

    /**
     * Get PendingIntent activity is allowed to be started in the background if the caller
     * has BAL permission.
     * @hide
     */
    public boolean isPendingIntentBackgroundActivityLaunchAllowedByPermission() {
        return mPendingIntentBalAllowedByPermission;
    }

    public Bundle toBundle() {
    public Bundle toBundle() {
        Bundle b = new Bundle();
        Bundle b = new Bundle();
        b.putBoolean(KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED, mPendingIntentBalAllowed);
        b.putBoolean(KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED, mPendingIntentBalAllowed);
        b.putBoolean(KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED_BY_PERMISSION,
                mPendingIntentBalAllowedByPermission);
        return b;
        return b;
    }
    }
}
}
+11 −0
Original line number Original line Diff line number Diff line
@@ -310,6 +310,17 @@ public final class PendingIntentRecord extends IIntentSender.Stub {
                requiredPermission, null, null, 0, 0, 0, options);
                requiredPermission, null, null, 0, 0, 0, options);
    }
    }


    /**
     * Return true if the activity options allows PendingIntent to use caller's BAL permission.
     */
    public static boolean isPendingIntentBalAllowedByPermission(
            @Nullable ActivityOptions activityOptions) {
        if (activityOptions == null) {
            return false;
        }
        return activityOptions.isPendingIntentBackgroundActivityLaunchAllowedByPermission();
    }

    public static boolean isPendingIntentBalAllowedByCaller(
    public static boolean isPendingIntentBalAllowedByCaller(
            @Nullable ActivityOptions activityOptions) {
            @Nullable ActivityOptions activityOptions) {
        if (activityOptions == null) {
        if (activityOptions == null) {
+3 −4
Original line number Original line Diff line number Diff line
@@ -1365,10 +1365,9 @@ class ActivityStarter {
                PendingIntentRecord.isPendingIntentBalAllowedByCaller(checkedOptions);
                PendingIntentRecord.isPendingIntentBalAllowedByCaller(checkedOptions);


        if (balAllowedByPiSender && realCallingUid != callingUid) {
        if (balAllowedByPiSender && realCallingUid != callingUid) {
            // If the caller is a legacy app, we won't check if the caller has BAL permission.
            final boolean useCallerPermission =
            final boolean isPiBalOptionEnabled = CompatChanges.isChangeEnabled(
                    PendingIntentRecord.isPendingIntentBalAllowedByPermission(checkedOptions);
                    ENABLE_PENDING_INTENT_BAL_OPTION, realCallingUid);
            if (useCallerPermission && ActivityManager.checkComponentPermission(
            if (isPiBalOptionEnabled && ActivityManager.checkComponentPermission(
                    android.Manifest.permission.START_ACTIVITIES_FROM_BACKGROUND,
                    android.Manifest.permission.START_ACTIVITIES_FROM_BACKGROUND,
                    realCallingUid, -1, true)
                    realCallingUid, -1, true)
                    == PackageManager.PERMISSION_GRANTED) {
                    == PackageManager.PERMISSION_GRANTED) {