2 * Copyright (C) 2006 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package android.content;
19 import android.net.Uri;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 import android.os.PatternMatcher;
23 import android.util.AndroidException;
24 import android.util.Log;
25 import android.util.Printer;
27 import com.android.internal.util.XmlUtils;
29 import org.xmlpull.v1.XmlPullParser;
30 import org.xmlpull.v1.XmlPullParserException;
31 import org.xmlpull.v1.XmlSerializer;
33 import java.io.IOException;
34 import java.util.ArrayList;
35 import java.util.Iterator;
39 * Structured description of Intent values to be matched. An IntentFilter can
40 * match against actions, categories, and data (either via its type, scheme,
41 * and/or path) in an Intent. It also includes a "priority" value which is
42 * used to order multiple matching filters.
44 * <p>IntentFilter objects are often created in XML as part of a package's
45 * {@link android.R.styleable#AndroidManifest AndroidManifest.xml} file,
46 * using {@link android.R.styleable#AndroidManifestIntentFilter intent-filter}
49 * <p>There are three Intent characteristics you can filter on: the
50 * <em>action</em>, <em>data</em>, and <em>categories</em>. For each of these
51 * characteristics you can provide
52 * multiple possible matching values (via {@link #addAction},
53 * {@link #addDataType}, {@link #addDataScheme}, {@link #addDataSchemeSpecificPart},
54 * {@link #addDataAuthority}, {@link #addDataPath}, and {@link #addCategory}, respectively).
55 * For actions, the field
56 * will not be tested if no values have been given (treating it as a wildcard);
57 * if no data characteristics are specified, however, then the filter will
58 * only match intents that contain no data.
60 * <p>The data characteristic is
61 * itself divided into three attributes: type, scheme, authority, and path.
63 * specified must match the contents of the Intent. If you specify a scheme
64 * but no type, only Intent that does not have a type (such as mailto:) will
65 * match; a content: URI will never match because they always have a MIME type
66 * that is supplied by their content provider. Specifying a type with no scheme
67 * has somewhat special meaning: it will match either an Intent with no URI
68 * field, or an Intent with a content: or file: URI. If you specify neither,
69 * then only an Intent with no data or type will match. To specify an authority,
70 * you must also specify one or more schemes that it is associated with.
71 * To specify a path, you also must specify both one or more authorities and
72 * one or more schemes it is associated with.
74 * <div class="special reference">
75 * <h3>Developer Guides</h3>
76 * <p>For information about how to create and resolve intents, read the
77 * <a href="{@docRoot}guide/topics/intents/intents-filters.html">Intents and Intent Filters</a>
78 * developer guide.</p>
81 * <h3>Filter Rules</h3>
82 * <p>A match is based on the following rules. Note that
83 * for an IntentFilter to match an Intent, three conditions must hold:
84 * the <strong>action</strong> and <strong>category</strong> must match, and
85 * the data (both the <strong>data type</strong> and
86 * <strong>data scheme+authority+path</strong> if specified) must match.
88 * <p><strong>Action</strong> matches if any of the given values match the
89 * Intent action; if the filter specifies no actions, then it will only match
90 * Intents that do not contain an action.
92 * <p><strong>Data Type</strong> matches if any of the given values match the
93 * Intent type. The Intent
94 * type is determined by calling {@link Intent#resolveType}. A wildcard can be
95 * used for the MIME sub-type, in both the Intent and IntentFilter, so that the
96 * type "audio/*" will match "audio/mpeg", "audio/aiff", "audio/*", etc.
97 * <em>Note that MIME type matching here is <b>case sensitive</b>, unlike
98 * formal RFC MIME types!</em> You should thus always use lower case letters
99 * for your MIME types.
101 * <p><strong>Data Scheme</strong> matches if any of the given values match the
102 * Intent data's scheme.
103 * The Intent scheme is determined by calling {@link Intent#getData}
104 * and {@link android.net.Uri#getScheme} on that URI.
105 * <em>Note that scheme matching here is <b>case sensitive</b>, unlike
106 * formal RFC schemes!</em> You should thus always use lower case letters
109 * <p><strong>Data Scheme Specific Part</strong> matches if any of the given values match
110 * the Intent's data scheme specific part <em>and</em> one of the data schemes in the filter
111 * has matched the Intent, <em>or</em> no scheme specific parts were supplied in the filter.
112 * The Intent scheme specific part is determined by calling
113 * {@link Intent#getData} and {@link android.net.Uri#getSchemeSpecificPart} on that URI.
114 * <em>Note that scheme specific part matching is <b>case sensitive</b>.</em>
116 * <p><strong>Data Authority</strong> matches if any of the given values match
117 * the Intent's data authority <em>and</em> one of the data schemes in the filter
118 * has matched the Intent, <em>or</em> no authories were supplied in the filter.
119 * The Intent authority is determined by calling
120 * {@link Intent#getData} and {@link android.net.Uri#getAuthority} on that URI.
121 * <em>Note that authority matching here is <b>case sensitive</b>, unlike
122 * formal RFC host names!</em> You should thus always use lower case letters
123 * for your authority.
125 * <p><strong>Data Path</strong> matches if any of the given values match the
126 * Intent's data path <em>and</em> both a scheme and authority in the filter
127 * has matched against the Intent, <em>or</em> no paths were supplied in the
128 * filter. The Intent authority is determined by calling
129 * {@link Intent#getData} and {@link android.net.Uri#getPath} on that URI.
131 * <p><strong>Categories</strong> match if <em>all</em> of the categories in
132 * the Intent match categories given in the filter. Extra categories in the
133 * filter that are not in the Intent will not cause the match to fail. Note
134 * that unlike the action, an IntentFilter with no categories
135 * will only match an Intent that does not have any categories.
137 public class IntentFilter implements Parcelable {
138 private static final String SGLOB_STR = "sglob";
139 private static final String PREFIX_STR = "prefix";
140 private static final String LITERAL_STR = "literal";
141 private static final String PATH_STR = "path";
142 private static final String PORT_STR = "port";
143 private static final String HOST_STR = "host";
144 private static final String AUTH_STR = "auth";
145 private static final String SSP_STR = "ssp";
146 private static final String SCHEME_STR = "scheme";
147 private static final String TYPE_STR = "type";
148 private static final String CAT_STR = "cat";
149 private static final String NAME_STR = "name";
150 private static final String ACTION_STR = "action";
153 * The filter {@link #setPriority} value at which system high-priority
154 * receivers are placed; that is, receivers that should execute before
155 * application code. Applications should never use filters with this or
160 public static final int SYSTEM_HIGH_PRIORITY = 1000;
163 * The filter {@link #setPriority} value at which system low-priority
164 * receivers are placed; that is, receivers that should execute after
165 * application code. Applications should never use filters with this or
170 public static final int SYSTEM_LOW_PRIORITY = -1000;
173 * The part of a match constant that describes the category of match
174 * that occurred. May be either {@link #MATCH_CATEGORY_EMPTY},
175 * {@link #MATCH_CATEGORY_SCHEME}, {@link #MATCH_CATEGORY_SCHEME_SPECIFIC_PART},
176 * {@link #MATCH_CATEGORY_HOST}, {@link #MATCH_CATEGORY_PORT},
177 * {@link #MATCH_CATEGORY_PATH}, or {@link #MATCH_CATEGORY_TYPE}. Higher
178 * values indicate a better match.
180 public static final int MATCH_CATEGORY_MASK = 0xfff0000;
183 * The part of a match constant that applies a quality adjustment to the
184 * basic category of match. The value {@link #MATCH_ADJUSTMENT_NORMAL}
185 * is no adjustment; higher numbers than that improve the quality, while
186 * lower numbers reduce it.
188 public static final int MATCH_ADJUSTMENT_MASK = 0x000ffff;
191 * Quality adjustment applied to the category of match that signifies
192 * the default, base value; higher numbers improve the quality while
193 * lower numbers reduce it.
195 public static final int MATCH_ADJUSTMENT_NORMAL = 0x8000;
198 * The filter matched an intent that had no data specified.
200 public static final int MATCH_CATEGORY_EMPTY = 0x0100000;
202 * The filter matched an intent with the same data URI scheme.
204 public static final int MATCH_CATEGORY_SCHEME = 0x0200000;
206 * The filter matched an intent with the same data URI scheme and
209 public static final int MATCH_CATEGORY_HOST = 0x0300000;
211 * The filter matched an intent with the same data URI scheme and
212 * authority host and port.
214 public static final int MATCH_CATEGORY_PORT = 0x0400000;
216 * The filter matched an intent with the same data URI scheme,
217 * authority, and path.
219 public static final int MATCH_CATEGORY_PATH = 0x0500000;
221 * The filter matched an intent with the same data URI scheme and
222 * scheme specific part.
224 public static final int MATCH_CATEGORY_SCHEME_SPECIFIC_PART = 0x0580000;
226 * The filter matched an intent with the same data MIME type.
228 public static final int MATCH_CATEGORY_TYPE = 0x0600000;
231 * The filter didn't match due to different MIME types.
233 public static final int NO_MATCH_TYPE = -1;
235 * The filter didn't match due to different data URIs.
237 public static final int NO_MATCH_DATA = -2;
239 * The filter didn't match due to different actions.
241 public static final int NO_MATCH_ACTION = -3;
243 * The filter didn't match because it required one or more categories
244 * that were not in the Intent.
246 public static final int NO_MATCH_CATEGORY = -4;
248 private int mPriority;
249 private final ArrayList<String> mActions;
250 private ArrayList<String> mCategories = null;
251 private ArrayList<String> mDataSchemes = null;
252 private ArrayList<PatternMatcher> mDataSchemeSpecificParts = null;
253 private ArrayList<AuthorityEntry> mDataAuthorities = null;
254 private ArrayList<PatternMatcher> mDataPaths = null;
255 private ArrayList<String> mDataTypes = null;
256 private boolean mHasPartialTypes = false;
258 // These functions are the start of more optimized code for managing
259 // the string sets... not yet implemented.
261 private static int findStringInSet(String[] set, String string,
262 int[] lengths, int lenPos) {
263 if (set == null) return -1;
264 final int N = lengths[lenPos];
265 for (int i=0; i<N; i++) {
266 if (set[i].equals(string)) return i;
271 private static String[] addStringToSet(String[] set, String string,
272 int[] lengths, int lenPos) {
273 if (findStringInSet(set, string, lengths, lenPos) >= 0) return set;
280 final int N = lengths[lenPos];
281 if (N < set.length) {
283 lengths[lenPos] = N+1;
287 String[] newSet = new String[(N*3)/2 + 2];
288 System.arraycopy(set, 0, newSet, 0, N);
291 lengths[lenPos] = N+1;
295 private static String[] removeStringFromSet(String[] set, String string,
296 int[] lengths, int lenPos) {
297 int pos = findStringInSet(set, string, lengths, lenPos);
298 if (pos < 0) return set;
299 final int N = lengths[lenPos];
300 if (N > (set.length/4)) {
301 int copyLen = N-(pos+1);
303 System.arraycopy(set, pos+1, set, pos, copyLen);
306 lengths[lenPos] = N-1;
310 String[] newSet = new String[set.length/3];
311 if (pos > 0) System.arraycopy(set, 0, newSet, 0, pos);
312 if ((pos+1) < N) System.arraycopy(set, pos+1, newSet, pos, N-(pos+1));
317 * This exception is thrown when a given MIME type does not have a valid
320 public static class MalformedMimeTypeException extends AndroidException {
321 public MalformedMimeTypeException() {
324 public MalformedMimeTypeException(String name) {
330 * Create a new IntentFilter instance with a specified action and MIME
331 * type, where you know the MIME type is correctly formatted. This catches
332 * the {@link MalformedMimeTypeException} exception that the constructor
333 * can call and turns it into a runtime exception.
335 * @param action The action to match, i.e. Intent.ACTION_VIEW.
336 * @param dataType The type to match, i.e. "vnd.android.cursor.dir/person".
338 * @return A new IntentFilter for the given action and type.
340 * @see #IntentFilter(String, String)
342 public static IntentFilter create(String action, String dataType) {
344 return new IntentFilter(action, dataType);
345 } catch (MalformedMimeTypeException e) {
346 throw new RuntimeException("Bad MIME type", e);
351 * New empty IntentFilter.
353 public IntentFilter() {
355 mActions = new ArrayList<String>();
359 * New IntentFilter that matches a single action with no data. If
360 * no data characteristics are subsequently specified, then the
361 * filter will only match intents that contain no data.
363 * @param action The action to match, i.e. Intent.ACTION_MAIN.
365 public IntentFilter(String action) {
367 mActions = new ArrayList<String>();
372 * New IntentFilter that matches a single action and data type.
374 * <p><em>Note: MIME type matching in the Android framework is
375 * case-sensitive, unlike formal RFC MIME types. As a result,
376 * you should always write your MIME types with lower case letters,
377 * and any MIME types you receive from outside of Android should be
378 * converted to lower case before supplying them here.</em></p>
380 * <p>Throws {@link MalformedMimeTypeException} if the given MIME type is
381 * not syntactically correct.
383 * @param action The action to match, i.e. Intent.ACTION_VIEW.
384 * @param dataType The type to match, i.e. "vnd.android.cursor.dir/person".
387 public IntentFilter(String action, String dataType)
388 throws MalformedMimeTypeException {
390 mActions = new ArrayList<String>();
392 addDataType(dataType);
396 * New IntentFilter containing a copy of an existing filter.
398 * @param o The original filter to copy.
400 public IntentFilter(IntentFilter o) {
401 mPriority = o.mPriority;
402 mActions = new ArrayList<String>(o.mActions);
403 if (o.mCategories != null) {
404 mCategories = new ArrayList<String>(o.mCategories);
406 if (o.mDataTypes != null) {
407 mDataTypes = new ArrayList<String>(o.mDataTypes);
409 if (o.mDataSchemes != null) {
410 mDataSchemes = new ArrayList<String>(o.mDataSchemes);
412 if (o.mDataSchemeSpecificParts != null) {
413 mDataSchemeSpecificParts = new ArrayList<PatternMatcher>(o.mDataSchemeSpecificParts);
415 if (o.mDataAuthorities != null) {
416 mDataAuthorities = new ArrayList<AuthorityEntry>(o.mDataAuthorities);
418 if (o.mDataPaths != null) {
419 mDataPaths = new ArrayList<PatternMatcher>(o.mDataPaths);
421 mHasPartialTypes = o.mHasPartialTypes;
425 * Modify priority of this filter. The default priority is 0. Positive
426 * values will be before the default, lower values will be after it.
427 * Applications must use a value that is larger than
428 * {@link #SYSTEM_LOW_PRIORITY} and smaller than
429 * {@link #SYSTEM_HIGH_PRIORITY} .
431 * @param priority The new priority value.
434 * @see #SYSTEM_LOW_PRIORITY
435 * @see #SYSTEM_HIGH_PRIORITY
437 public final void setPriority(int priority) {
438 mPriority = priority;
442 * Return the priority of this filter.
444 * @return The priority of the filter.
448 public final int getPriority() {
453 * Add a new Intent action to match against. If any actions are included
454 * in the filter, then an Intent's action must be one of those values for
455 * it to match. If no actions are included, the Intent action is ignored.
457 * @param action Name of the action to match, i.e. Intent.ACTION_VIEW.
459 public final void addAction(String action) {
460 if (!mActions.contains(action)) {
461 mActions.add(action.intern());
466 * Return the number of actions in the filter.
468 public final int countActions() {
469 return mActions.size();
473 * Return an action in the filter.
475 public final String getAction(int index) {
476 return mActions.get(index);
480 * Is the given action included in the filter? Note that if the filter
481 * does not include any actions, false will <em>always</em> be returned.
483 * @param action The action to look for.
485 * @return True if the action is explicitly mentioned in the filter.
487 public final boolean hasAction(String action) {
488 return action != null && mActions.contains(action);
492 * Match this filter against an Intent's action. If the filter does not
493 * specify any actions, the match will always fail.
495 * @param action The desired action to look for.
497 * @return True if the action is listed in the filter.
499 public final boolean matchAction(String action) {
500 return hasAction(action);
504 * Return an iterator over the filter's actions. If there are no actions,
507 public final Iterator<String> actionsIterator() {
508 return mActions != null ? mActions.iterator() : null;
512 * Add a new Intent data type to match against. If any types are
513 * included in the filter, then an Intent's data must be <em>either</em>
514 * one of these types <em>or</em> a matching scheme. If no data types
515 * are included, then an Intent will only match if it specifies no data.
517 * <p><em>Note: MIME type matching in the Android framework is
518 * case-sensitive, unlike formal RFC MIME types. As a result,
519 * you should always write your MIME types with lower case letters,
520 * and any MIME types you receive from outside of Android should be
521 * converted to lower case before supplying them here.</em></p>
523 * <p>Throws {@link MalformedMimeTypeException} if the given MIME type is
524 * not syntactically correct.
526 * @param type Name of the data type to match, i.e. "vnd.android.cursor.dir/person".
530 public final void addDataType(String type)
531 throws MalformedMimeTypeException {
532 final int slashpos = type.indexOf('/');
533 final int typelen = type.length();
534 if (slashpos > 0 && typelen >= slashpos+2) {
535 if (mDataTypes == null) mDataTypes = new ArrayList<String>();
536 if (typelen == slashpos+2 && type.charAt(slashpos+1) == '*') {
537 String str = type.substring(0, slashpos);
538 if (!mDataTypes.contains(str)) {
539 mDataTypes.add(str.intern());
541 mHasPartialTypes = true;
543 if (!mDataTypes.contains(type)) {
544 mDataTypes.add(type.intern());
550 throw new MalformedMimeTypeException(type);
554 * Is the given data type included in the filter? Note that if the filter
555 * does not include any type, false will <em>always</em> be returned.
557 * @param type The data type to look for.
559 * @return True if the type is explicitly mentioned in the filter.
561 public final boolean hasDataType(String type) {
562 return mDataTypes != null && findMimeType(type);
566 * Return the number of data types in the filter.
568 public final int countDataTypes() {
569 return mDataTypes != null ? mDataTypes.size() : 0;
573 * Return a data type in the filter.
575 public final String getDataType(int index) {
576 return mDataTypes.get(index);
580 * Return an iterator over the filter's data types.
582 public final Iterator<String> typesIterator() {
583 return mDataTypes != null ? mDataTypes.iterator() : null;
587 * Add a new Intent data scheme to match against. If any schemes are
588 * included in the filter, then an Intent's data must be <em>either</em>
589 * one of these schemes <em>or</em> a matching data type. If no schemes
590 * are included, then an Intent will match only if it includes no data.
592 * <p><em>Note: scheme matching in the Android framework is
593 * case-sensitive, unlike formal RFC schemes. As a result,
594 * you should always write your schemes with lower case letters,
595 * and any schemes you receive from outside of Android should be
596 * converted to lower case before supplying them here.</em></p>
598 * @param scheme Name of the scheme to match, i.e. "http".
602 public final void addDataScheme(String scheme) {
603 if (mDataSchemes == null) mDataSchemes = new ArrayList<String>();
604 if (!mDataSchemes.contains(scheme)) {
605 mDataSchemes.add(scheme.intern());
610 * Return the number of data schemes in the filter.
612 public final int countDataSchemes() {
613 return mDataSchemes != null ? mDataSchemes.size() : 0;
617 * Return a data scheme in the filter.
619 public final String getDataScheme(int index) {
620 return mDataSchemes.get(index);
624 * Is the given data scheme included in the filter? Note that if the
625 * filter does not include any scheme, false will <em>always</em> be
628 * @param scheme The data scheme to look for.
630 * @return True if the scheme is explicitly mentioned in the filter.
632 public final boolean hasDataScheme(String scheme) {
633 return mDataSchemes != null && mDataSchemes.contains(scheme);
637 * Return an iterator over the filter's data schemes.
639 public final Iterator<String> schemesIterator() {
640 return mDataSchemes != null ? mDataSchemes.iterator() : null;
644 * This is an entry for a single authority in the Iterator returned by
645 * {@link #authoritiesIterator()}.
647 public final static class AuthorityEntry {
648 private final String mOrigHost;
649 private final String mHost;
650 private final boolean mWild;
651 private final int mPort;
653 public AuthorityEntry(String host, String port) {
655 mWild = host.length() > 0 && host.charAt(0) == '*';
656 mHost = mWild ? host.substring(1).intern() : host;
657 mPort = port != null ? Integer.parseInt(port) : -1;
660 AuthorityEntry(Parcel src) {
661 mOrigHost = src.readString();
662 mHost = src.readString();
663 mWild = src.readInt() != 0;
664 mPort = src.readInt();
667 void writeToParcel(Parcel dest) {
668 dest.writeString(mOrigHost);
669 dest.writeString(mHost);
670 dest.writeInt(mWild ? 1 : 0);
671 dest.writeInt(mPort);
674 public String getHost() {
678 public int getPort() {
683 * Determine whether this AuthorityEntry matches the given data Uri.
684 * <em>Note that this comparison is case-sensitive, unlike formal
685 * RFC host names. You thus should always normalize to lower-case.</em>
687 * @param data The Uri to match.
688 * @return Returns either {@link IntentFilter#NO_MATCH_DATA},
689 * {@link IntentFilter#MATCH_CATEGORY_PORT}, or
690 * {@link IntentFilter#MATCH_CATEGORY_HOST}.
692 public int match(Uri data) {
693 String host = data.getHost();
695 return NO_MATCH_DATA;
697 if (false) Log.v("IntentFilter",
698 "Match host " + host + ": " + mHost);
700 if (host.length() < mHost.length()) {
701 return NO_MATCH_DATA;
703 host = host.substring(host.length()-mHost.length());
705 if (host.compareToIgnoreCase(mHost) != 0) {
706 return NO_MATCH_DATA;
709 if (mPort != data.getPort()) {
710 return NO_MATCH_DATA;
712 return MATCH_CATEGORY_PORT;
714 return MATCH_CATEGORY_HOST;
719 * Add a new Intent data "scheme specific part" to match against. The filter must
720 * include one or more schemes (via {@link #addDataScheme}) for the
721 * scheme specific part to be considered. If any scheme specific parts are
722 * included in the filter, then an Intent's data must match one of
723 * them. If no scheme specific parts are included, then only the scheme must match.
725 * <p>The "scheme specific part" that this matches against is the string returned
726 * by {@link android.net.Uri#getSchemeSpecificPart() Uri.getSchemeSpecificPart}.
727 * For Uris that contain a path, this kind of matching is not generally of interest,
728 * since {@link #addDataAuthority(String, String)} and
729 * {@link #addDataPath(String, int)} can provide a better mechanism for matching
730 * them. However, for Uris that do not contain a path, the authority and path
731 * are empty, so this is the only way to match against the non-scheme part.</p>
733 * @param ssp Either a raw string that must exactly match the scheme specific part
734 * path, or a simple pattern, depending on <var>type</var>.
735 * @param type Determines how <var>ssp</var> will be compared to
736 * determine a match: either {@link PatternMatcher#PATTERN_LITERAL},
737 * {@link PatternMatcher#PATTERN_PREFIX}, or
738 * {@link PatternMatcher#PATTERN_SIMPLE_GLOB}.
741 * @see #addDataScheme
743 public final void addDataSchemeSpecificPart(String ssp, int type) {
744 addDataSchemeSpecificPart(new PatternMatcher(ssp, type));
748 public final void addDataSchemeSpecificPart(PatternMatcher ssp) {
749 if (mDataSchemeSpecificParts == null) {
750 mDataSchemeSpecificParts = new ArrayList<PatternMatcher>();
752 mDataSchemeSpecificParts.add(ssp);
756 * Return the number of data scheme specific parts in the filter.
758 public final int countDataSchemeSpecificParts() {
759 return mDataSchemeSpecificParts != null ? mDataSchemeSpecificParts.size() : 0;
763 * Return a data scheme specific part in the filter.
765 public final PatternMatcher getDataSchemeSpecificPart(int index) {
766 return mDataSchemeSpecificParts.get(index);
770 * Is the given data scheme specific part included in the filter? Note that if the
771 * filter does not include any scheme specific parts, false will <em>always</em> be
774 * @param data The scheme specific part that is being looked for.
776 * @return Returns true if the data string matches a scheme specific part listed in the
779 public final boolean hasDataSchemeSpecificPart(String data) {
780 if (mDataSchemeSpecificParts == null) {
783 final int numDataSchemeSpecificParts = mDataSchemeSpecificParts.size();
784 for (int i = 0; i < numDataSchemeSpecificParts; i++) {
785 final PatternMatcher pe = mDataSchemeSpecificParts.get(i);
786 if (pe.match(data)) {
794 * Return an iterator over the filter's data scheme specific parts.
796 public final Iterator<PatternMatcher> schemeSpecificPartsIterator() {
797 return mDataSchemeSpecificParts != null ? mDataSchemeSpecificParts.iterator() : null;
801 * Add a new Intent data authority to match against. The filter must
802 * include one or more schemes (via {@link #addDataScheme}) for the
803 * authority to be considered. If any authorities are
804 * included in the filter, then an Intent's data must match one of
805 * them. If no authorities are included, then only the scheme must match.
807 * <p><em>Note: host name in the Android framework is
808 * case-sensitive, unlike formal RFC host names. As a result,
809 * you should always write your host names with lower case letters,
810 * and any host names you receive from outside of Android should be
811 * converted to lower case before supplying them here.</em></p>
813 * @param host The host part of the authority to match. May start with a
814 * single '*' to wildcard the front of the host name.
815 * @param port Optional port part of the authority to match. If null, any
819 * @see #addDataScheme
821 public final void addDataAuthority(String host, String port) {
822 if (port != null) port = port.intern();
823 addDataAuthority(new AuthorityEntry(host.intern(), port));
827 public final void addDataAuthority(AuthorityEntry ent) {
828 if (mDataAuthorities == null) mDataAuthorities =
829 new ArrayList<AuthorityEntry>();
830 mDataAuthorities.add(ent);
834 * Return the number of data authorities in the filter.
836 public final int countDataAuthorities() {
837 return mDataAuthorities != null ? mDataAuthorities.size() : 0;
841 * Return a data authority in the filter.
843 public final AuthorityEntry getDataAuthority(int index) {
844 return mDataAuthorities.get(index);
848 * Is the given data authority included in the filter? Note that if the
849 * filter does not include any authorities, false will <em>always</em> be
852 * @param data The data whose authority is being looked for.
854 * @return Returns true if the data string matches an authority listed in the
857 public final boolean hasDataAuthority(Uri data) {
858 return matchDataAuthority(data) >= 0;
862 * Return an iterator over the filter's data authorities.
864 public final Iterator<AuthorityEntry> authoritiesIterator() {
865 return mDataAuthorities != null ? mDataAuthorities.iterator() : null;
869 * Add a new Intent data path to match against. The filter must
870 * include one or more schemes (via {@link #addDataScheme}) <em>and</em>
871 * one or more authorities (via {@link #addDataAuthority}) for the
872 * path to be considered. If any paths are
873 * included in the filter, then an Intent's data must match one of
874 * them. If no paths are included, then only the scheme/authority must
877 * <p>The path given here can either be a literal that must directly
878 * match or match against a prefix, or it can be a simple globbing pattern.
879 * If the latter, you can use '*' anywhere in the pattern to match zero
880 * or more instances of the previous character, '.' as a wildcard to match
881 * any character, and '\' to escape the next character.
883 * @param path Either a raw string that must exactly match the file
884 * path, or a simple pattern, depending on <var>type</var>.
885 * @param type Determines how <var>path</var> will be compared to
886 * determine a match: either {@link PatternMatcher#PATTERN_LITERAL},
887 * {@link PatternMatcher#PATTERN_PREFIX}, or
888 * {@link PatternMatcher#PATTERN_SIMPLE_GLOB}.
891 * @see #addDataScheme
892 * @see #addDataAuthority
894 public final void addDataPath(String path, int type) {
895 addDataPath(new PatternMatcher(path.intern(), type));
899 public final void addDataPath(PatternMatcher path) {
900 if (mDataPaths == null) mDataPaths = new ArrayList<PatternMatcher>();
901 mDataPaths.add(path);
905 * Return the number of data paths in the filter.
907 public final int countDataPaths() {
908 return mDataPaths != null ? mDataPaths.size() : 0;
912 * Return a data path in the filter.
914 public final PatternMatcher getDataPath(int index) {
915 return mDataPaths.get(index);
919 * Is the given data path included in the filter? Note that if the
920 * filter does not include any paths, false will <em>always</em> be
923 * @param data The data path to look for. This is without the scheme
926 * @return True if the data string matches a path listed in the
929 public final boolean hasDataPath(String data) {
930 if (mDataPaths == null) {
933 final int numDataPaths = mDataPaths.size();
934 for (int i = 0; i < numDataPaths; i++) {
935 final PatternMatcher pe = mDataPaths.get(i);
936 if (pe.match(data)) {
944 * Return an iterator over the filter's data paths.
946 public final Iterator<PatternMatcher> pathsIterator() {
947 return mDataPaths != null ? mDataPaths.iterator() : null;
951 * Match this intent filter against the given Intent data. This ignores
952 * the data scheme -- unlike {@link #matchData}, the authority will match
953 * regardless of whether there is a matching scheme.
955 * @param data The data whose authority is being looked for.
957 * @return Returns either {@link #MATCH_CATEGORY_HOST},
958 * {@link #MATCH_CATEGORY_PORT}, {@link #NO_MATCH_DATA}.
960 public final int matchDataAuthority(Uri data) {
961 if (mDataAuthorities == null) {
962 return NO_MATCH_DATA;
964 final int numDataAuthorities = mDataAuthorities.size();
965 for (int i = 0; i < numDataAuthorities; i++) {
966 final AuthorityEntry ae = mDataAuthorities.get(i);
967 int match = ae.match(data);
972 return NO_MATCH_DATA;
976 * Match this filter against an Intent's data (type, scheme and path). If
977 * the filter does not specify any types and does not specify any
978 * schemes/paths, the match will only succeed if the intent does not
979 * also specify a type or data.
981 * <p>Be aware that to match against an authority, you must also specify a base
982 * scheme the authority is in. To match against a data path, both a scheme
983 * and authority must be specified. If the filter does not specify any
984 * types or schemes that it matches against, it is considered to be empty
985 * (any authority or data path given is ignored, as if it were empty as
988 * <p><em>Note: MIME type, Uri scheme, and host name matching in the
989 * Android framework is case-sensitive, unlike the formal RFC definitions.
990 * As a result, you should always write these elements with lower case letters,
991 * and normalize any MIME types or Uris you receive from
992 * outside of Android to ensure these elements are lower case before
993 * supplying them here.</em></p>
995 * @param type The desired data type to look for, as returned by
996 * Intent.resolveType().
997 * @param scheme The desired data scheme to look for, as returned by
998 * Intent.getScheme().
999 * @param data The full data string to match against, as supplied in
1002 * @return Returns either a valid match constant (a combination of
1003 * {@link #MATCH_CATEGORY_MASK} and {@link #MATCH_ADJUSTMENT_MASK}),
1004 * or one of the error codes {@link #NO_MATCH_TYPE} if the type didn't match
1005 * or {@link #NO_MATCH_DATA} if the scheme/path didn't match.
1009 public final int matchData(String type, String scheme, Uri data) {
1010 final ArrayList<String> types = mDataTypes;
1011 final ArrayList<String> schemes = mDataSchemes;
1013 int match = MATCH_CATEGORY_EMPTY;
1015 if (types == null && schemes == null) {
1016 return ((type == null && data == null)
1017 ? (MATCH_CATEGORY_EMPTY+MATCH_ADJUSTMENT_NORMAL) : NO_MATCH_DATA);
1020 if (schemes != null) {
1021 if (schemes.contains(scheme != null ? scheme : "")) {
1022 match = MATCH_CATEGORY_SCHEME;
1024 return NO_MATCH_DATA;
1027 final ArrayList<PatternMatcher> schemeSpecificParts = mDataSchemeSpecificParts;
1028 if (schemeSpecificParts != null) {
1029 match = hasDataSchemeSpecificPart(data.getSchemeSpecificPart())
1030 ? MATCH_CATEGORY_SCHEME_SPECIFIC_PART : NO_MATCH_DATA;
1032 if (match != MATCH_CATEGORY_SCHEME_SPECIFIC_PART) {
1033 // If there isn't any matching ssp, we need to match an authority.
1034 final ArrayList<AuthorityEntry> authorities = mDataAuthorities;
1035 if (authorities != null) {
1036 int authMatch = matchDataAuthority(data);
1037 if (authMatch >= 0) {
1038 final ArrayList<PatternMatcher> paths = mDataPaths;
1039 if (paths == null) {
1041 } else if (hasDataPath(data.getPath())) {
1042 match = MATCH_CATEGORY_PATH;
1044 return NO_MATCH_DATA;
1047 return NO_MATCH_DATA;
1051 // If neither an ssp nor an authority matched, we're done.
1052 if (match == NO_MATCH_DATA) {
1053 return NO_MATCH_DATA;
1056 // Special case: match either an Intent with no data URI,
1057 // or with a scheme: URI. This is to give a convenience for
1058 // the common case where you want to deal with data in a
1059 // content provider, which is done by type, and we don't want
1060 // to force everyone to say they handle content: or file: URIs.
1061 if (scheme != null && !"".equals(scheme)
1062 && !"content".equals(scheme)
1063 && !"file".equals(scheme)) {
1064 return NO_MATCH_DATA;
1068 if (types != null) {
1069 if (findMimeType(type)) {
1070 match = MATCH_CATEGORY_TYPE;
1072 return NO_MATCH_TYPE;
1075 // If no MIME types are specified, then we will only match against
1076 // an Intent that does not have a MIME type.
1078 return NO_MATCH_TYPE;
1082 return match + MATCH_ADJUSTMENT_NORMAL;
1086 * Add a new Intent category to match against. The semantics of
1087 * categories is the opposite of actions -- an Intent includes the
1088 * categories that it requires, all of which must be included in the
1089 * filter in order to match. In other words, adding a category to the
1090 * filter has no impact on matching unless that category is specified in
1093 * @param category Name of category to match, i.e. Intent.CATEGORY_EMBED.
1095 public final void addCategory(String category) {
1096 if (mCategories == null) mCategories = new ArrayList<String>();
1097 if (!mCategories.contains(category)) {
1098 mCategories.add(category.intern());
1103 * Return the number of categories in the filter.
1105 public final int countCategories() {
1106 return mCategories != null ? mCategories.size() : 0;
1110 * Return a category in the filter.
1112 public final String getCategory(int index) {
1113 return mCategories.get(index);
1117 * Is the given category included in the filter?
1119 * @param category The category that the filter supports.
1121 * @return True if the category is explicitly mentioned in the filter.
1123 public final boolean hasCategory(String category) {
1124 return mCategories != null && mCategories.contains(category);
1128 * Return an iterator over the filter's categories.
1130 * @return Iterator if this filter has categories or {@code null} if none.
1132 public final Iterator<String> categoriesIterator() {
1133 return mCategories != null ? mCategories.iterator() : null;
1137 * Match this filter against an Intent's categories. Each category in
1138 * the Intent must be specified by the filter; if any are not in the
1139 * filter, the match fails.
1141 * @param categories The categories included in the intent, as returned by
1142 * Intent.getCategories().
1144 * @return If all categories match (success), null; else the name of the
1145 * first category that didn't match.
1147 public final String matchCategories(Set<String> categories) {
1148 if (categories == null) {
1152 Iterator<String> it = categories.iterator();
1154 if (mCategories == null) {
1155 return it.hasNext() ? it.next() : null;
1158 while (it.hasNext()) {
1159 final String category = it.next();
1160 if (!mCategories.contains(category)) {
1169 * Test whether this filter matches the given <var>intent</var>.
1171 * @param intent The Intent to compare against.
1172 * @param resolve If true, the intent's type will be resolved by calling
1173 * Intent.resolveType(); otherwise a simple match against
1174 * Intent.type will be performed.
1175 * @param logTag Tag to use in debugging messages.
1177 * @return Returns either a valid match constant (a combination of
1178 * {@link #MATCH_CATEGORY_MASK} and {@link #MATCH_ADJUSTMENT_MASK}),
1179 * or one of the error codes {@link #NO_MATCH_TYPE} if the type didn't match,
1180 * {@link #NO_MATCH_DATA} if the scheme/path didn't match,
1181 * {@link #NO_MATCH_ACTION if the action didn't match, or
1182 * {@link #NO_MATCH_CATEGORY} if one or more categories didn't match.
1184 * @return How well the filter matches. Negative if it doesn't match,
1185 * zero or positive positive value if it does with a higher
1186 * value representing a better match.
1188 * @see #match(String, String, String, android.net.Uri , Set, String)
1190 public final int match(ContentResolver resolver, Intent intent,
1191 boolean resolve, String logTag) {
1192 String type = resolve ? intent.resolveType(resolver) : intent.getType();
1193 return match(intent.getAction(), type, intent.getScheme(),
1194 intent.getData(), intent.getCategories(), logTag);
1198 * Test whether this filter matches the given intent data. A match is
1199 * only successful if the actions and categories in the Intent match
1200 * against the filter, as described in {@link IntentFilter}; in that case,
1201 * the match result returned will be as per {@link #matchData}.
1203 * @param action The intent action to match against (Intent.getAction).
1204 * @param type The intent type to match against (Intent.resolveType()).
1205 * @param scheme The data scheme to match against (Intent.getScheme()).
1206 * @param data The data URI to match against (Intent.getData()).
1207 * @param categories The categories to match against
1208 * (Intent.getCategories()).
1209 * @param logTag Tag to use in debugging messages.
1211 * @return Returns either a valid match constant (a combination of
1212 * {@link #MATCH_CATEGORY_MASK} and {@link #MATCH_ADJUSTMENT_MASK}),
1213 * or one of the error codes {@link #NO_MATCH_TYPE} if the type didn't match,
1214 * {@link #NO_MATCH_DATA} if the scheme/path didn't match,
1215 * {@link #NO_MATCH_ACTION if the action didn't match, or
1216 * {@link #NO_MATCH_CATEGORY} if one or more categories didn't match.
1219 * @see Intent#getAction
1220 * @see Intent#resolveType
1221 * @see Intent#getScheme
1222 * @see Intent#getData
1223 * @see Intent#getCategories
1225 public final int match(String action, String type, String scheme,
1226 Uri data, Set<String> categories, String logTag) {
1227 if (action != null && !matchAction(action)) {
1229 logTag, "No matching action " + action + " for " + this);
1230 return NO_MATCH_ACTION;
1233 int dataMatch = matchData(type, scheme, data);
1234 if (dataMatch < 0) {
1236 if (dataMatch == NO_MATCH_TYPE) {
1237 Log.v(logTag, "No matching type " + type
1240 if (dataMatch == NO_MATCH_DATA) {
1241 Log.v(logTag, "No matching scheme/path " + data
1248 String categoryMismatch = matchCategories(categories);
1249 if (categoryMismatch != null) {
1251 Log.v(logTag, "No matching category " + categoryMismatch + " for " + this);
1253 return NO_MATCH_CATEGORY;
1256 // It would be nice to treat container activities as more
1257 // important than ones that can be embedded, but this is not the way...
1259 if (categories != null) {
1260 dataMatch -= mCategories.size() - categories.size();
1268 * Write the contents of the IntentFilter as an XML stream.
1270 public void writeToXml(XmlSerializer serializer) throws IOException {
1271 int N = countActions();
1272 for (int i=0; i<N; i++) {
1273 serializer.startTag(null, ACTION_STR);
1274 serializer.attribute(null, NAME_STR, mActions.get(i));
1275 serializer.endTag(null, ACTION_STR);
1277 N = countCategories();
1278 for (int i=0; i<N; i++) {
1279 serializer.startTag(null, CAT_STR);
1280 serializer.attribute(null, NAME_STR, mCategories.get(i));
1281 serializer.endTag(null, CAT_STR);
1283 N = countDataTypes();
1284 for (int i=0; i<N; i++) {
1285 serializer.startTag(null, TYPE_STR);
1286 String type = mDataTypes.get(i);
1287 if (type.indexOf('/') < 0) type = type + "/*";
1288 serializer.attribute(null, NAME_STR, type);
1289 serializer.endTag(null, TYPE_STR);
1291 N = countDataSchemes();
1292 for (int i=0; i<N; i++) {
1293 serializer.startTag(null, SCHEME_STR);
1294 serializer.attribute(null, NAME_STR, mDataSchemes.get(i));
1295 serializer.endTag(null, SCHEME_STR);
1297 N = countDataSchemeSpecificParts();
1298 for (int i=0; i<N; i++) {
1299 serializer.startTag(null, SSP_STR);
1300 PatternMatcher pe = mDataSchemeSpecificParts.get(i);
1301 switch (pe.getType()) {
1302 case PatternMatcher.PATTERN_LITERAL:
1303 serializer.attribute(null, LITERAL_STR, pe.getPath());
1305 case PatternMatcher.PATTERN_PREFIX:
1306 serializer.attribute(null, PREFIX_STR, pe.getPath());
1308 case PatternMatcher.PATTERN_SIMPLE_GLOB:
1309 serializer.attribute(null, SGLOB_STR, pe.getPath());
1312 serializer.endTag(null, SSP_STR);
1314 N = countDataAuthorities();
1315 for (int i=0; i<N; i++) {
1316 serializer.startTag(null, AUTH_STR);
1317 AuthorityEntry ae = mDataAuthorities.get(i);
1318 serializer.attribute(null, HOST_STR, ae.getHost());
1319 if (ae.getPort() >= 0) {
1320 serializer.attribute(null, PORT_STR, Integer.toString(ae.getPort()));
1322 serializer.endTag(null, AUTH_STR);
1324 N = countDataPaths();
1325 for (int i=0; i<N; i++) {
1326 serializer.startTag(null, PATH_STR);
1327 PatternMatcher pe = mDataPaths.get(i);
1328 switch (pe.getType()) {
1329 case PatternMatcher.PATTERN_LITERAL:
1330 serializer.attribute(null, LITERAL_STR, pe.getPath());
1332 case PatternMatcher.PATTERN_PREFIX:
1333 serializer.attribute(null, PREFIX_STR, pe.getPath());
1335 case PatternMatcher.PATTERN_SIMPLE_GLOB:
1336 serializer.attribute(null, SGLOB_STR, pe.getPath());
1339 serializer.endTag(null, PATH_STR);
1343 public void readFromXml(XmlPullParser parser) throws XmlPullParserException,
1345 int outerDepth = parser.getDepth();
1347 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1348 && (type != XmlPullParser.END_TAG
1349 || parser.getDepth() > outerDepth)) {
1350 if (type == XmlPullParser.END_TAG
1351 || type == XmlPullParser.TEXT) {
1355 String tagName = parser.getName();
1356 if (tagName.equals(ACTION_STR)) {
1357 String name = parser.getAttributeValue(null, NAME_STR);
1361 } else if (tagName.equals(CAT_STR)) {
1362 String name = parser.getAttributeValue(null, NAME_STR);
1366 } else if (tagName.equals(TYPE_STR)) {
1367 String name = parser.getAttributeValue(null, NAME_STR);
1371 } catch (MalformedMimeTypeException e) {
1374 } else if (tagName.equals(SCHEME_STR)) {
1375 String name = parser.getAttributeValue(null, NAME_STR);
1377 addDataScheme(name);
1379 } else if (tagName.equals(SSP_STR)) {
1380 String ssp = parser.getAttributeValue(null, LITERAL_STR);
1382 addDataSchemeSpecificPart(ssp, PatternMatcher.PATTERN_LITERAL);
1383 } else if ((ssp=parser.getAttributeValue(null, PREFIX_STR)) != null) {
1384 addDataSchemeSpecificPart(ssp, PatternMatcher.PATTERN_PREFIX);
1385 } else if ((ssp=parser.getAttributeValue(null, SGLOB_STR)) != null) {
1386 addDataSchemeSpecificPart(ssp, PatternMatcher.PATTERN_SIMPLE_GLOB);
1388 } else if (tagName.equals(AUTH_STR)) {
1389 String host = parser.getAttributeValue(null, HOST_STR);
1390 String port = parser.getAttributeValue(null, PORT_STR);
1392 addDataAuthority(host, port);
1394 } else if (tagName.equals(PATH_STR)) {
1395 String path = parser.getAttributeValue(null, LITERAL_STR);
1397 addDataPath(path, PatternMatcher.PATTERN_LITERAL);
1398 } else if ((path=parser.getAttributeValue(null, PREFIX_STR)) != null) {
1399 addDataPath(path, PatternMatcher.PATTERN_PREFIX);
1400 } else if ((path=parser.getAttributeValue(null, SGLOB_STR)) != null) {
1401 addDataPath(path, PatternMatcher.PATTERN_SIMPLE_GLOB);
1404 Log.w("IntentFilter", "Unknown tag parsing IntentFilter: " + tagName);
1406 XmlUtils.skipCurrentTag(parser);
1410 public void dump(Printer du, String prefix) {
1411 StringBuilder sb = new StringBuilder(256);
1412 if (mActions.size() > 0) {
1413 Iterator<String> it = mActions.iterator();
1414 while (it.hasNext()) {
1416 sb.append(prefix); sb.append("Action: \"");
1417 sb.append(it.next()); sb.append("\"");
1418 du.println(sb.toString());
1421 if (mCategories != null) {
1422 Iterator<String> it = mCategories.iterator();
1423 while (it.hasNext()) {
1425 sb.append(prefix); sb.append("Category: \"");
1426 sb.append(it.next()); sb.append("\"");
1427 du.println(sb.toString());
1430 if (mDataSchemes != null) {
1431 Iterator<String> it = mDataSchemes.iterator();
1432 while (it.hasNext()) {
1434 sb.append(prefix); sb.append("Scheme: \"");
1435 sb.append(it.next()); sb.append("\"");
1436 du.println(sb.toString());
1439 if (mDataSchemeSpecificParts != null) {
1440 Iterator<PatternMatcher> it = mDataSchemeSpecificParts.iterator();
1441 while (it.hasNext()) {
1442 PatternMatcher pe = it.next();
1444 sb.append(prefix); sb.append("Ssp: \"");
1445 sb.append(pe); sb.append("\"");
1446 du.println(sb.toString());
1449 if (mDataAuthorities != null) {
1450 Iterator<AuthorityEntry> it = mDataAuthorities.iterator();
1451 while (it.hasNext()) {
1452 AuthorityEntry ae = it.next();
1454 sb.append(prefix); sb.append("Authority: \"");
1455 sb.append(ae.mHost); sb.append("\": ");
1456 sb.append(ae.mPort);
1457 if (ae.mWild) sb.append(" WILD");
1458 du.println(sb.toString());
1461 if (mDataPaths != null) {
1462 Iterator<PatternMatcher> it = mDataPaths.iterator();
1463 while (it.hasNext()) {
1464 PatternMatcher pe = it.next();
1466 sb.append(prefix); sb.append("Path: \"");
1467 sb.append(pe); sb.append("\"");
1468 du.println(sb.toString());
1471 if (mDataTypes != null) {
1472 Iterator<String> it = mDataTypes.iterator();
1473 while (it.hasNext()) {
1475 sb.append(prefix); sb.append("Type: \"");
1476 sb.append(it.next()); sb.append("\"");
1477 du.println(sb.toString());
1480 if (mPriority != 0 || mHasPartialTypes) {
1482 sb.append(prefix); sb.append("mPriority="); sb.append(mPriority);
1483 sb.append(", mHasPartialTypes="); sb.append(mHasPartialTypes);
1484 du.println(sb.toString());
1488 public static final Parcelable.Creator<IntentFilter> CREATOR
1489 = new Parcelable.Creator<IntentFilter>() {
1490 public IntentFilter createFromParcel(Parcel source) {
1491 return new IntentFilter(source);
1494 public IntentFilter[] newArray(int size) {
1495 return new IntentFilter[size];
1499 public final int describeContents() {
1503 public final void writeToParcel(Parcel dest, int flags) {
1504 dest.writeStringList(mActions);
1505 if (mCategories != null) {
1507 dest.writeStringList(mCategories);
1511 if (mDataSchemes != null) {
1513 dest.writeStringList(mDataSchemes);
1517 if (mDataTypes != null) {
1519 dest.writeStringList(mDataTypes);
1523 if (mDataSchemeSpecificParts != null) {
1524 final int N = mDataSchemeSpecificParts.size();
1526 for (int i=0; i<N; i++) {
1527 mDataSchemeSpecificParts.get(i).writeToParcel(dest, flags);
1532 if (mDataAuthorities != null) {
1533 final int N = mDataAuthorities.size();
1535 for (int i=0; i<N; i++) {
1536 mDataAuthorities.get(i).writeToParcel(dest);
1541 if (mDataPaths != null) {
1542 final int N = mDataPaths.size();
1544 for (int i=0; i<N; i++) {
1545 mDataPaths.get(i).writeToParcel(dest, flags);
1550 dest.writeInt(mPriority);
1551 dest.writeInt(mHasPartialTypes ? 1 : 0);
1555 * For debugging -- perform a check on the filter, return true if it passed
1556 * or false if it failed.
1560 public boolean debugCheck() {
1563 // This code looks for intent filters that do not specify data.
1565 if (mActions != null && mActions.size() == 1
1566 && mActions.contains(Intent.ACTION_MAIN)) {
1570 if (mDataTypes == null && mDataSchemes == null) {
1571 Log.w("IntentFilter", "QUESTIONABLE INTENT FILTER:");
1572 dump(Log.WARN, "IntentFilter", " ");
1580 private IntentFilter(Parcel source) {
1581 mActions = new ArrayList<String>();
1582 source.readStringList(mActions);
1583 if (source.readInt() != 0) {
1584 mCategories = new ArrayList<String>();
1585 source.readStringList(mCategories);
1587 if (source.readInt() != 0) {
1588 mDataSchemes = new ArrayList<String>();
1589 source.readStringList(mDataSchemes);
1591 if (source.readInt() != 0) {
1592 mDataTypes = new ArrayList<String>();
1593 source.readStringList(mDataTypes);
1595 int N = source.readInt();
1597 mDataSchemeSpecificParts = new ArrayList<PatternMatcher>(N);
1598 for (int i=0; i<N; i++) {
1599 mDataSchemeSpecificParts.add(new PatternMatcher(source));
1602 N = source.readInt();
1604 mDataAuthorities = new ArrayList<AuthorityEntry>(N);
1605 for (int i=0; i<N; i++) {
1606 mDataAuthorities.add(new AuthorityEntry(source));
1609 N = source.readInt();
1611 mDataPaths = new ArrayList<PatternMatcher>(N);
1612 for (int i=0; i<N; i++) {
1613 mDataPaths.add(new PatternMatcher(source));
1616 mPriority = source.readInt();
1617 mHasPartialTypes = source.readInt() > 0;
1620 private final boolean findMimeType(String type) {
1621 final ArrayList<String> t = mDataTypes;
1627 if (t.contains(type)) {
1631 // Deal with an Intent wanting to match every type in the IntentFilter.
1632 final int typeLength = type.length();
1633 if (typeLength == 3 && type.equals("*/*")) {
1634 return !t.isEmpty();
1637 // Deal with this IntentFilter wanting to match every Intent type.
1638 if (mHasPartialTypes && t.contains("*")) {
1642 final int slashpos = type.indexOf('/');
1644 if (mHasPartialTypes && t.contains(type.substring(0, slashpos))) {
1647 if (typeLength == slashpos+2 && type.charAt(slashpos+1) == '*') {
1648 // Need to look through all types for one that matches
1650 final int numTypes = t.size();
1651 for (int i = 0; i < numTypes; i++) {
1652 final String v = t.get(i);
1653 if (type.regionMatches(0, v, 0, slashpos+1)) {