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

Commit c5c6c1a7 authored by Kiran Ramachandra's avatar Kiran Ramachandra
Browse files

Enables opt-in strict intent resolution for apps

Strict intent resolution will enforce:
- Explicit intents should match the target component's intent filter
- Intents without an action should not match any intent filter

Attribute `intentMatchingFlags` defined in manifest.xml can be used for granular enforcement

Caller enforcement supported by app compact flags `ENFORCE_INTENTS_TO_MATCH_INTENT_FILTERS` & `BLOCK_NULL_ACTION_INTENTS` are discontinued

DesignDoc: go/safer-intents-w-design-doc

Bug: 364354494
Test: atest FrameworksCorePackageManagerTests:ParsedMainComponentUtilsTest CtsPackageManagerTestCases:SaferIntentTest PackageManagerServiceUnitTests
Flag: android.security.enable_intent_matching_flags

Change-Id: Iab5c369e1bdeae8db4def9adf3ff27961b072954
parent 47ec424d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1006,6 +1006,7 @@ package android {
    field public static final int insetRight = 16843192; // 0x10101b8
    field public static final int insetTop = 16843193; // 0x10101b9
    field public static final int installLocation = 16843447; // 0x10102b7
    field @FlaggedApi("android.security.enable_intent_matching_flags") public static final int intentMatchingFlags;
    field public static final int interactiveUiTimeout = 16844181; // 0x1010595
    field public static final int interpolator = 16843073; // 0x1010141
    field public static final int intro = 16844395; // 0x101066b
+15 −0
Original line number Diff line number Diff line
@@ -423,6 +423,8 @@ public class PackageImpl implements ParsedPackage, AndroidPackageInternal,

    private Map<String, Boolean> mFeatureFlagState = new ArrayMap<>();

    private int mIntentMatchingFlags;

    @NonNull
    public static PackageImpl forParsing(@NonNull String packageName, @NonNull String baseCodePath,
            @NonNull String codePath, @NonNull TypedArray manifestArray, boolean isCoreApp,
@@ -3270,6 +3272,7 @@ public class PackageImpl implements ParsedPackage, AndroidPackageInternal,
        dest.writeLong(this.mBooleans);
        dest.writeLong(this.mBooleans2);
        dest.writeBoolean(this.mAllowCrossUidActivitySwitchFromBelow);
        dest.writeInt(this.mIntentMatchingFlags);
    }

    private void writeFeatureFlagState(@NonNull Parcel dest) {
@@ -3461,6 +3464,7 @@ public class PackageImpl implements ParsedPackage, AndroidPackageInternal,
        this.mBooleans = in.readLong();
        this.mBooleans2 = in.readLong();
        this.mAllowCrossUidActivitySwitchFromBelow = in.readBoolean();
        this.mIntentMatchingFlags = in.readInt();

        assignDerivedFields();
        assignDerivedFields2();
@@ -3699,6 +3703,17 @@ public class PackageImpl implements ParsedPackage, AndroidPackageInternal,
        return this;
    }

    @Override
    public ParsingPackage setIntentMatchingFlags(int intentMatchingFlags) {
        mIntentMatchingFlags = intentMatchingFlags;
        return this;
    }

    @Override
    public int getIntentMatchingFlags() {
        return mIntentMatchingFlags;
    }

    // The following methods are explicitly not inside any interface. These are hidden under
    // PackageImpl which is only accessible to the system server. This is to prevent/discourage
    // usage of these fields outside of the utility classes.
+4 −2
Original line number Diff line number Diff line
@@ -109,7 +109,8 @@ public class ParsedActivityUtils {
                            R.styleable.AndroidManifestActivity_process,
                            R.styleable.AndroidManifestActivity_roundIcon,
                            R.styleable.AndroidManifestActivity_splitName,
                            R.styleable.AndroidManifestActivity_attributionTags);
                            R.styleable.AndroidManifestActivity_attributionTags,
                            R.styleable.AndroidManifestActivity_intentMatchingFlags);
            if (result.isError()) {
                return input.error(result);
            }
@@ -310,7 +311,8 @@ public class ParsedActivityUtils {
                    NOT_SET /*processAttr*/,
                    R.styleable.AndroidManifestActivityAlias_roundIcon,
                    NOT_SET /*splitNameAttr*/,
                    R.styleable.AndroidManifestActivityAlias_attributionTags);
                    R.styleable.AndroidManifestActivityAlias_attributionTags,
                    R.styleable.AndroidManifestActivityAlias_intentMatchingFlags);
            if (result.isError()) {
                return input.error(result);
            }
+5 −0
Original line number Diff line number Diff line
@@ -45,4 +45,9 @@ public interface ParsedMainComponent extends ParsedComponent {

    @Nullable
    String getSplitName();

    /**
     * Returns the intent matching flags.
     */
    int getIntentMatchingFlags();
}
+67 −5
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.DataClass;
import com.android.internal.util.Parcelling.BuiltIn.ForInternedString;

@@ -34,7 +33,6 @@ import libcore.util.EmptyArray;
 * @hide
 */
@DataClass(genGetters = true, genSetters = true, genBuilder = false, genParcelable = false)
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
public class ParsedMainComponentImpl extends ParsedComponentImpl implements ParsedMainComponent,
        Parcelable {

@@ -51,6 +49,30 @@ public class ParsedMainComponentImpl extends ParsedComponentImpl implements Pars
    @Nullable
    private String[] attributionTags;

    private int mIntentMatchingFlags;

    /**
     * Opt-out of all intent filter matching rules. The value corresponds to the <code>none</code>
     * value of {@link android.R.attr#intentMatchingFlags}
     * @hide
     */
    public static final int INTENT_MATCHING_FLAGS_NONE = 1;

    /**
     * Opt-in to enforce intent filter matching. The value corresponds to the
     * <code>enforceIntentFilter</code> value of {@link android.R.attr#intentMatchingFlags}
     * @hide
     */
    public static final int INTENT_MATCHING_FLAGS_ENFORCE_INTENT_FILTER = 1 << 1;

    /**
     * Allows intent filters to match actions even when the action value is null. The value
     * corresponds to the <code>allowNullAction</code> value of
     * {@link android.R.attr#intentMatchingFlags}
     * @hide
     */
    public static final int INTENT_MATCHING_FLAGS_ALLOW_NULL_ACTION = 1 << 2;

    public ParsedMainComponentImpl() {
    }

@@ -83,6 +105,20 @@ public class ParsedMainComponentImpl extends ParsedComponentImpl implements Pars
        return attributionTags == null ? EmptyArray.STRING : attributionTags;
    }

    /**
     * Sets the intent matching flags. This value is intended to be set from the "component" tags.
     * @see android.R.styleable#AndroidManifestApplication_intentMatchingFlags
     */
    public ParsedMainComponent setIntentMatchingFlags(int intentMatchingFlags) {
        mIntentMatchingFlags = intentMatchingFlags;
        return this;
    }

    @Override
    public int getIntentMatchingFlags() {
        return this.mIntentMatchingFlags;
    }

    @Override
    public int describeContents() {
        return 0;
@@ -98,6 +134,7 @@ public class ParsedMainComponentImpl extends ParsedComponentImpl implements Pars
        dest.writeInt(this.order);
        dest.writeString(this.splitName);
        dest.writeString8Array(this.attributionTags);
        dest.writeInt(this.mIntentMatchingFlags);
    }

    protected ParsedMainComponentImpl(Parcel in) {
@@ -109,6 +146,7 @@ public class ParsedMainComponentImpl extends ParsedComponentImpl implements Pars
        this.order = in.readInt();
        this.splitName = in.readString();
        this.attributionTags = in.createString8Array();
        this.mIntentMatchingFlags = in.readInt();
    }

    public static final Parcelable.Creator<ParsedMainComponentImpl> CREATOR =
@@ -139,6 +177,28 @@ public class ParsedMainComponentImpl extends ParsedComponentImpl implements Pars
    //@formatter:off


    @android.annotation.IntDef(prefix = "INTENT_MATCHING_FLAGS_", value = {
        INTENT_MATCHING_FLAGS_NONE,
        INTENT_MATCHING_FLAGS_ENFORCE_INTENT_FILTER,
        INTENT_MATCHING_FLAGS_ALLOW_NULL_ACTION
    })
    @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE)
    @DataClass.Generated.Member
    public @interface IntentMatchingFlags {}

    @DataClass.Generated.Member
    public static String intentMatchingFlagsToString(@IntentMatchingFlags int value) {
        switch (value) {
            case INTENT_MATCHING_FLAGS_NONE:
                    return "INTENT_MATCHING_FLAGS_NONE";
            case INTENT_MATCHING_FLAGS_ENFORCE_INTENT_FILTER:
                    return "INTENT_MATCHING_FLAGS_ENFORCE_INTENT_FILTER";
            case INTENT_MATCHING_FLAGS_ALLOW_NULL_ACTION:
                    return "INTENT_MATCHING_FLAGS_ALLOW_NULL_ACTION";
            default: return Integer.toHexString(value);
        }
    }

    @DataClass.Generated.Member
    public ParsedMainComponentImpl(
            @Nullable String processName,
@@ -147,7 +207,8 @@ public class ParsedMainComponentImpl extends ParsedComponentImpl implements Pars
            boolean exported,
            int order,
            @Nullable String splitName,
            @Nullable String[] attributionTags) {
            @Nullable String[] attributionTags,
            int intentMatchingFlags) {
        this.processName = processName;
        this.directBootAware = directBootAware;
        this.enabled = enabled;
@@ -155,6 +216,7 @@ public class ParsedMainComponentImpl extends ParsedComponentImpl implements Pars
        this.order = order;
        this.splitName = splitName;
        this.attributionTags = attributionTags;
        this.mIntentMatchingFlags = intentMatchingFlags;

        // onConstructed(); // You can define this method to get a callback
    }
@@ -226,10 +288,10 @@ public class ParsedMainComponentImpl extends ParsedComponentImpl implements Pars
    }

    @DataClass.Generated(
            time = 1701447884766L,
            time = 1729613643190L,
            codegenVersion = "1.0.23",
            sourceFile = "frameworks/base/core/java/com/android/internal/pm/pkg/component/ParsedMainComponentImpl.java",
            inputSignatures = "private @android.annotation.Nullable @com.android.internal.util.DataClass.ParcelWith(com.android.internal.util.Parcelling.BuiltIn.ForInternedString.class) java.lang.String processName\nprivate  boolean directBootAware\nprivate  boolean enabled\nprivate  boolean exported\nprivate  int order\nprivate @android.annotation.Nullable java.lang.String splitName\nprivate @android.annotation.Nullable java.lang.String[] attributionTags\npublic static final  android.os.Parcelable.Creator<com.android.internal.pm.pkg.component.ParsedMainComponentImpl> CREATOR\npublic  com.android.internal.pm.pkg.component.ParsedMainComponentImpl setProcessName(java.lang.String)\npublic  java.lang.String getClassName()\npublic @android.annotation.NonNull @java.lang.Override java.lang.String[] getAttributionTags()\npublic @java.lang.Override int describeContents()\npublic @java.lang.Override void writeToParcel(android.os.Parcel,int)\nclass ParsedMainComponentImpl extends com.android.internal.pm.pkg.component.ParsedComponentImpl implements [com.android.internal.pm.pkg.component.ParsedMainComponent, android.os.Parcelable]\n@com.android.internal.util.DataClass(genGetters=true, genSetters=true, genBuilder=false, genParcelable=false)")
            inputSignatures = "private @android.annotation.Nullable @com.android.internal.util.DataClass.ParcelWith(com.android.internal.util.Parcelling.BuiltIn.ForInternedString.class) java.lang.String processName\nprivate  boolean directBootAware\nprivate  boolean enabled\nprivate  boolean exported\nprivate  int order\nprivate @android.annotation.Nullable java.lang.String splitName\nprivate @android.annotation.Nullable java.lang.String[] attributionTags\nprivate  int mIntentMatchingFlags\npublic static final  int INTENT_MATCHING_FLAGS_NONE\npublic static final  int INTENT_MATCHING_FLAGS_ENFORCE_INTENT_FILTER\npublic static final  int INTENT_MATCHING_FLAGS_ALLOW_NULL_ACTION\npublic static final  android.os.Parcelable.Creator<com.android.internal.pm.pkg.component.ParsedMainComponentImpl> CREATOR\npublic  com.android.internal.pm.pkg.component.ParsedMainComponentImpl setProcessName(java.lang.String)\npublic  java.lang.String getClassName()\npublic @android.annotation.NonNull @java.lang.Override java.lang.String[] getAttributionTags()\npublic  com.android.internal.pm.pkg.component.ParsedMainComponent setIntentMatchingFlags(int)\npublic @java.lang.Override int getIntentMatchingFlags()\npublic @java.lang.Override int describeContents()\npublic @java.lang.Override void writeToParcel(android.os.Parcel,int)\nclass ParsedMainComponentImpl extends com.android.internal.pm.pkg.component.ParsedComponentImpl implements [com.android.internal.pm.pkg.component.ParsedMainComponent, android.os.Parcelable]\n@com.android.internal.util.DataClass(genGetters=true, genSetters=true, genBuilder=false, genParcelable=false)")
    @Deprecated
    private void __metadata() {}

Loading