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

Commit 0d6e4c8b authored by Achim Thesmann's avatar Achim Thesmann Committed by Android (Google) Code Review
Browse files

Merge "Cover IntentSender by BAL hardening" into main

parents 9f3a22ea ca050430
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -16,8 +16,11 @@

package android.content;

import static android.os.Build.VERSION_CODES.BAKLAVA;
import static android.os.Build.VERSION_CODES.VANILLA_ICE_CREAM;

import static com.android.window.flags.Flags.balCoverIntentSender;

import android.annotation.FlaggedApi;
import android.annotation.Nullable;
import android.app.ActivityManager;
@@ -75,6 +78,11 @@ public class IntentSender implements Parcelable {
    @EnabledAfter(targetSdkVersion = VANILLA_ICE_CREAM)
    private static final long REMOVE_HIDDEN_SEND_INTENT_METHOD = 356174596;

    /** If enabled PendingIntent hardening also applies to IntentSender. */
    @ChangeId
    @EnabledAfter(targetSdkVersion = BAKLAVA)
    private static final long COVER_INTENT_SENDER = 405995292;

    private static final Bundle SEND_INTENT_DEFAULT_OPTIONS =
            ActivityOptions.makeBasic().setPendingIntentBackgroundActivityStartMode(
                    ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_COMPAT).toBundle();
@@ -180,7 +188,7 @@ public class IntentSender implements Parcelable {
     */
    public void sendIntent(Context context, int code, Intent intent,
            OnFinished onFinished, Handler handler) throws SendIntentException {
        sendIntent(context, code, intent, null, SEND_INTENT_DEFAULT_OPTIONS,
        sendIntent(context, code, intent, null, getSendIntentDefaultOptions(),
                handler == null ? null : handler::post, onFinished);
    }

@@ -213,10 +221,21 @@ public class IntentSender implements Parcelable {
    public void sendIntent(Context context, int code, Intent intent,
            OnFinished onFinished, Handler handler, String requiredPermission)
            throws SendIntentException {
        sendIntent(context, code, intent, requiredPermission, SEND_INTENT_DEFAULT_OPTIONS,
        sendIntent(context, code, intent, requiredPermission, getSendIntentDefaultOptions(),
                handler == null ? null : handler::post, onFinished);
    }

    private Bundle getSendIntentDefaultOptions() {
        if (!balCoverIntentSender()) {
            return SEND_INTENT_DEFAULT_OPTIONS;
        }
        if (!CompatChanges.isChangeEnabled(COVER_INTENT_SENDER)) {
            return SEND_INTENT_DEFAULT_OPTIONS;
        }
        return null;
    }


    /**
     * Perform the operation associated with this IntentSender, allowing the
     * caller to specify information about the Intent to use and be notified
+7 −0
Original line number Diff line number Diff line
@@ -95,3 +95,10 @@ flag {
    description: "Enable additional logging."
    bug: "403398176"
}

flag {
    name: "bal_cover_intent_sender"
    namespace: "responsible_apis"
    description: "Cover IntentSender API in addition to PendingIntent."
    bug: "405995292"
}