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

Commit 26d3496c authored by phweiss's avatar phweiss Committed by Taras Antoshchuk
Browse files

Add mimeGroup tag to intent filters

Intent filters can now have a |data| element
with a |mimeGroup| attribute on it. In a future
CL, the user can add mimeTypes to a mimeGroup,
which will cause the intent-filter to match all those
mimeTypes.

Bug: 134736173
Bug: 136635677
Test: atest android.content.pm.PackageParserTest#testPackageWithIntentFilters*

Change-Id: Ie44dc441e00c29d735814564b7f27b341a69a860
parent cce9df2a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -951,6 +951,7 @@ package android {
    field public static final int mediaRouteButtonStyle = 16843693; // 0x10103ad
    field public static final int mediaRouteTypes = 16843694; // 0x10103ae
    field public static final int menuCategory = 16843230; // 0x10101de
    field public static final int mimeGroup = 16844309; // 0x1010615
    field public static final int mimeType = 16842790; // 0x1010026
    field public static final int min = 16844089; // 0x1010539
    field public static final int minAspectRatio = 16844187; // 0x101059b
+71 −0
Original line number Diff line number Diff line
@@ -154,6 +154,7 @@ public class IntentFilter implements Parcelable {
    private static final String SSP_STR = "ssp";
    private static final String SCHEME_STR = "scheme";
    private static final String TYPE_STR = "type";
    private static final String GROUP_STR = "group";
    private static final String CAT_STR = "cat";
    private static final String NAME_STR = "name";
    private static final String ACTION_STR = "action";
@@ -281,6 +282,7 @@ public class IntentFilter implements Parcelable {
    private ArrayList<AuthorityEntry> mDataAuthorities = null;
    private ArrayList<PatternMatcher> mDataPaths = null;
    private ArrayList<String> mDataTypes = null;
    private ArrayList<String> mMimeGroups = null;
    private boolean mHasPartialTypes = false;

    private static final int STATE_VERIFY_AUTO         = 0x00000001;
@@ -469,6 +471,9 @@ public class IntentFilter implements Parcelable {
        if (o.mDataPaths != null) {
            mDataPaths = new ArrayList<PatternMatcher>(o.mDataPaths);
        }
        if (o.mMimeGroups != null) {
            mMimeGroups = new ArrayList<String>(o.mMimeGroups);
        }
        mHasPartialTypes = o.mHasPartialTypes;
        mVerifyState = o.mVerifyState;
        mInstantAppVisibility = o.mInstantAppVisibility;
@@ -836,6 +841,36 @@ public class IntentFilter implements Parcelable {
        return mDataTypes != null ? mDataTypes.iterator() : null;
    }

    /** @hide */
    public final void addMimeGroup(String name) {
        if (mMimeGroups == null) {
            mMimeGroups = new ArrayList<>();
        }
        if (!mMimeGroups.contains(name)) {
            mMimeGroups.add(name);
        }
    }

    /** @hide */
    public final boolean hasMimeGroup(String name) {
        return mMimeGroups != null && mMimeGroups.contains(name);
    }

    /** @hide */
    public final String getMimeGroup(int index) {
        return mMimeGroups.get(index);
    }

    /** @hide */
    public final int countMimeGroups() {
        return mMimeGroups != null ? mMimeGroups.size() : 0;
    }

    /** @hide */
    public final Iterator<String> mimeGroupsIterator() {
        return mMimeGroups != null ? mMimeGroups.iterator() : null;
    }

    /**
     * Add a new Intent data scheme to match against.  If any schemes are
     * included in the filter, then an Intent's data must be <em>either</em>
@@ -1625,6 +1660,12 @@ public class IntentFilter implements Parcelable {
            serializer.attribute(null, NAME_STR, type);
            serializer.endTag(null, TYPE_STR);
        }
        N = countMimeGroups();
        for (int i=0; i<N; i++) {
            serializer.startTag(null, GROUP_STR);
            serializer.attribute(null, NAME_STR, mMimeGroups.get(i));
            serializer.endTag(null, GROUP_STR);
        }
        N = countDataSchemes();
        for (int i=0; i<N; i++) {
            serializer.startTag(null, SCHEME_STR);
@@ -1717,6 +1758,11 @@ public class IntentFilter implements Parcelable {
                    } catch (MalformedMimeTypeException e) {
                    }
                }
            } else if (tagName.equals(GROUP_STR)) {
                String name = parser.getAttributeValue(null, NAME_STR);
                if (name != null) {
                    addMimeGroup(name);
                }
            } else if (tagName.equals(SCHEME_STR)) {
                String name = parser.getAttributeValue(null, NAME_STR);
                if (name != null) {
@@ -1802,6 +1848,12 @@ public class IntentFilter implements Parcelable {
                proto.write(IntentFilterProto.DATA_TYPES, it.next());
            }
        }
        if (mMimeGroups != null) {
            Iterator<String> it = mMimeGroups.iterator();
            while (it.hasNext()) {
                proto.write(IntentFilterProto.MIME_GROUPS, it.next());
            }
        }
        if (mPriority != 0 || mHasPartialTypes) {
            proto.write(IntentFilterProto.PRIORITY, mPriority);
            proto.write(IntentFilterProto.HAS_PARTIAL_TYPES, mHasPartialTypes);
@@ -1880,6 +1932,15 @@ public class IntentFilter implements Parcelable {
                du.println(sb.toString());
            }
        }
        if (mMimeGroups != null) {
            Iterator<String> it = mMimeGroups.iterator();
            while (it.hasNext()) {
                sb.setLength(0);
                sb.append(prefix); sb.append("MimeGroup: \"");
                sb.append(it.next()); sb.append("\"");
                du.println(sb.toString());
            }
        }
        if (mPriority != 0 || mOrder != 0 || mHasPartialTypes) {
            sb.setLength(0);
            sb.append(prefix); sb.append("mPriority="); sb.append(mPriority);
@@ -1929,6 +1990,12 @@ public class IntentFilter implements Parcelable {
        } else {
            dest.writeInt(0);
        }
        if (mMimeGroups != null) {
            dest.writeInt(1);
            dest.writeStringList(mMimeGroups);
        } else {
            dest.writeInt(0);
        }
        if (mDataSchemeSpecificParts != null) {
            final int N = mDataSchemeSpecificParts.size();
            dest.writeInt(N);
@@ -2005,6 +2072,10 @@ public class IntentFilter implements Parcelable {
            mDataTypes = new ArrayList<String>();
            source.readStringList(mDataTypes);
        }
        if (source.readInt() != 0) {
            mMimeGroups = new ArrayList<String>();
            source.readStringList(mMimeGroups);
        }
        int N = source.readInt();
        if (N > 0) {
            mDataSchemeSpecificParts = new ArrayList<PatternMatcher>(N);
+6 −0
Original line number Diff line number Diff line
@@ -3641,6 +3641,12 @@ public class ComponentParseUtils {
                    }
                }

                str = sa.getNonConfigurationString(
                        R.styleable.AndroidManifestData_mimeGroup, 0);
                if (str != null) {
                    intentInfo.addMimeGroup(str);
                }

                str = sa.getNonConfigurationString(
                        R.styleable.AndroidManifestData_scheme, 0);
                if (str != null) {
+2 −1
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ message IntentProto {
    optional string identifier = 13 [ (.android.privacy).dest = DEST_EXPLICIT ];
}

// Next Tag: 11
// Next Tag: 12
message IntentFilterProto {
    option (.android.msg_privacy).dest = DEST_AUTOMATIC;

@@ -86,6 +86,7 @@ message IntentFilterProto {
    optional int32 priority = 8;
    optional bool has_partial_types = 9;
    optional bool get_auto_verify = 10;
    repeated string mime_groups = 11;
}

message AuthorityEntryProto {
+3 −0
Original line number Diff line number Diff line
@@ -2809,6 +2809,9 @@
             case-sensitive, unlike formal RFC MIME types.  As a result,
             MIME types here should always use lower case letters.</em></p> -->
        <attr name="mimeType" format="string" />
        <!-- Specify a group of MIME types that are handled. MIME types can be added and
             removed to a package's MIME group via the PackageManager. -->
        <attr name="mimeGroup" format="string" />
        <!-- Specify a URI scheme that is handled, as per
             {@link android.content.IntentFilter#addDataScheme
             IntentFilter.addDataScheme()}.
Loading