blob: 7aa223cdf9095d48a6491be660c6abde17a5a8d7 [file] [log] [blame]
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17package android.content;
18
Todd Kennedyc05f5d12017-04-25 11:11:40 -070019import android.annotation.IntDef;
Todd Kennedy9c9fdf22017-03-06 10:58:27 -080020import android.annotation.SystemApi;
Mathew Inwood1c77a112018-08-14 14:06:26 +010021import android.annotation.UnsupportedAppUsage;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070022import android.net.Uri;
23import android.os.Parcel;
24import android.os.Parcelable;
25import android.os.PatternMatcher;
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -080026import android.text.TextUtils;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070027import android.util.AndroidException;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070028import android.util.Log;
29import android.util.Printer;
Yi Jin129fc6c2017-09-28 15:48:38 -070030import android.util.proto.ProtoOutputStream;
Dianne Hackborn2269d1572010-02-24 19:54:22 -080031
32import com.android.internal.util.XmlUtils;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070033
Gilles Debunne37051cd2011-05-25 16:27:13 -070034import org.xmlpull.v1.XmlPullParser;
35import org.xmlpull.v1.XmlPullParserException;
36import org.xmlpull.v1.XmlSerializer;
37
38import java.io.IOException;
Todd Kennedyc05f5d12017-04-25 11:11:40 -070039import java.lang.annotation.Retention;
40import java.lang.annotation.RetentionPolicy;
Gilles Debunne37051cd2011-05-25 16:27:13 -070041import java.util.ArrayList;
42import java.util.Iterator;
43import java.util.Set;
44
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070045/**
46 * Structured description of Intent values to be matched. An IntentFilter can
47 * match against actions, categories, and data (either via its type, scheme,
48 * and/or path) in an Intent. It also includes a "priority" value which is
49 * used to order multiple matching filters.
50 *
51 * <p>IntentFilter objects are often created in XML as part of a package's
52 * {@link android.R.styleable#AndroidManifest AndroidManifest.xml} file,
53 * using {@link android.R.styleable#AndroidManifestIntentFilter intent-filter}
54 * tags.
55 *
56 * <p>There are three Intent characteristics you can filter on: the
57 * <em>action</em>, <em>data</em>, and <em>categories</em>. For each of these
58 * characteristics you can provide
59 * multiple possible matching values (via {@link #addAction},
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -070060 * {@link #addDataType}, {@link #addDataScheme}, {@link #addDataSchemeSpecificPart},
61 * {@link #addDataAuthority}, {@link #addDataPath}, and {@link #addCategory}, respectively).
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070062 * For actions, the field
63 * will not be tested if no values have been given (treating it as a wildcard);
64 * if no data characteristics are specified, however, then the filter will
65 * only match intents that contain no data.
66 *
67 * <p>The data characteristic is
68 * itself divided into three attributes: type, scheme, authority, and path.
69 * Any that are
70 * specified must match the contents of the Intent. If you specify a scheme
71 * but no type, only Intent that does not have a type (such as mailto:) will
72 * match; a content: URI will never match because they always have a MIME type
73 * that is supplied by their content provider. Specifying a type with no scheme
74 * has somewhat special meaning: it will match either an Intent with no URI
75 * field, or an Intent with a content: or file: URI. If you specify neither,
76 * then only an Intent with no data or type will match. To specify an authority,
77 * you must also specify one or more schemes that it is associated with.
78 * To specify a path, you also must specify both one or more authorities and
79 * one or more schemes it is associated with.
80 *
Joe Fernandezb54e7a32011-10-03 15:09:50 -070081 * <div class="special reference">
82 * <h3>Developer Guides</h3>
83 * <p>For information about how to create and resolve intents, read the
84 * <a href="{@docRoot}guide/topics/intents/intents-filters.html">Intents and Intent Filters</a>
85 * developer guide.</p>
86 * </div>
87 *
88 * <h3>Filter Rules</h3>
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070089 * <p>A match is based on the following rules. Note that
90 * for an IntentFilter to match an Intent, three conditions must hold:
91 * the <strong>action</strong> and <strong>category</strong> must match, and
92 * the data (both the <strong>data type</strong> and
Dianne Hackborn0ea920d2013-10-11 09:40:18 -070093 * <strong>data scheme+authority+path</strong> if specified) must match
94 * (see {@link #match(ContentResolver, Intent, boolean, String)} for more details
95 * on how the data fields match).
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070096 *
97 * <p><strong>Action</strong> matches if any of the given values match the
Dianne Hackborna53ee352013-02-20 12:47:02 -080098 * Intent action; if the filter specifies no actions, then it will only match
99 * Intents that do not contain an action.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700100 *
101 * <p><strong>Data Type</strong> matches if any of the given values match the
102 * Intent type. The Intent
103 * type is determined by calling {@link Intent#resolveType}. A wildcard can be
104 * used for the MIME sub-type, in both the Intent and IntentFilter, so that the
105 * type "audio/*" will match "audio/mpeg", "audio/aiff", "audio/*", etc.
Dianne Hackbornb3cddae2009-04-13 16:54:00 -0700106 * <em>Note that MIME type matching here is <b>case sensitive</b>, unlike
107 * formal RFC MIME types!</em> You should thus always use lower case letters
108 * for your MIME types.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700109 *
110 * <p><strong>Data Scheme</strong> matches if any of the given values match the
111 * Intent data's scheme.
112 * The Intent scheme is determined by calling {@link Intent#getData}
113 * and {@link android.net.Uri#getScheme} on that URI.
Dianne Hackbornb3cddae2009-04-13 16:54:00 -0700114 * <em>Note that scheme matching here is <b>case sensitive</b>, unlike
115 * formal RFC schemes!</em> You should thus always use lower case letters
116 * for your schemes.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700117 *
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -0700118 * <p><strong>Data Scheme Specific Part</strong> matches if any of the given values match
119 * the Intent's data scheme specific part <em>and</em> one of the data schemes in the filter
120 * has matched the Intent, <em>or</em> no scheme specific parts were supplied in the filter.
121 * The Intent scheme specific part is determined by calling
122 * {@link Intent#getData} and {@link android.net.Uri#getSchemeSpecificPart} on that URI.
123 * <em>Note that scheme specific part matching is <b>case sensitive</b>.</em>
124 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700125 * <p><strong>Data Authority</strong> matches if any of the given values match
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -0700126 * the Intent's data authority <em>and</em> one of the data schemes in the filter
Josh Gao0febb232018-08-28 11:19:16 -0700127 * has matched the Intent, <em>or</em> no authorities were supplied in the filter.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700128 * The Intent authority is determined by calling
129 * {@link Intent#getData} and {@link android.net.Uri#getAuthority} on that URI.
Dianne Hackbornb3cddae2009-04-13 16:54:00 -0700130 * <em>Note that authority matching here is <b>case sensitive</b>, unlike
131 * formal RFC host names!</em> You should thus always use lower case letters
132 * for your authority.
Kevin Hufnaglee20b3d72016-09-22 18:33:57 -0700133 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700134 * <p><strong>Data Path</strong> matches if any of the given values match the
135 * Intent's data path <em>and</em> both a scheme and authority in the filter
136 * has matched against the Intent, <em>or</em> no paths were supplied in the
137 * filter. The Intent authority is determined by calling
138 * {@link Intent#getData} and {@link android.net.Uri#getPath} on that URI.
139 *
140 * <p><strong>Categories</strong> match if <em>all</em> of the categories in
141 * the Intent match categories given in the filter. Extra categories in the
142 * filter that are not in the Intent will not cause the match to fail. Note
143 * that unlike the action, an IntentFilter with no categories
144 * will only match an Intent that does not have any categories.
145 */
146public class IntentFilter implements Parcelable {
Todd Kennedy9c9fdf22017-03-06 10:58:27 -0800147 private static final String AGLOB_STR = "aglob";
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700148 private static final String SGLOB_STR = "sglob";
149 private static final String PREFIX_STR = "prefix";
150 private static final String LITERAL_STR = "literal";
151 private static final String PATH_STR = "path";
152 private static final String PORT_STR = "port";
153 private static final String HOST_STR = "host";
154 private static final String AUTH_STR = "auth";
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -0700155 private static final String SSP_STR = "ssp";
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700156 private static final String SCHEME_STR = "scheme";
157 private static final String TYPE_STR = "type";
158 private static final String CAT_STR = "cat";
159 private static final String NAME_STR = "name";
160 private static final String ACTION_STR = "action";
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -0800161 private static final String AUTO_VERIFY_STR = "autoVerify";
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700162
163 /**
164 * The filter {@link #setPriority} value at which system high-priority
165 * receivers are placed; that is, receivers that should execute before
166 * application code. Applications should never use filters with this or
167 * higher priorities.
168 *
169 * @see #setPriority
170 */
171 public static final int SYSTEM_HIGH_PRIORITY = 1000;
172
173 /**
174 * The filter {@link #setPriority} value at which system low-priority
175 * receivers are placed; that is, receivers that should execute after
176 * application code. Applications should never use filters with this or
177 * lower priorities.
178 *
179 * @see #setPriority
180 */
181 public static final int SYSTEM_LOW_PRIORITY = -1000;
182
183 /**
184 * The part of a match constant that describes the category of match
185 * that occurred. May be either {@link #MATCH_CATEGORY_EMPTY},
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -0700186 * {@link #MATCH_CATEGORY_SCHEME}, {@link #MATCH_CATEGORY_SCHEME_SPECIFIC_PART},
187 * {@link #MATCH_CATEGORY_HOST}, {@link #MATCH_CATEGORY_PORT},
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700188 * {@link #MATCH_CATEGORY_PATH}, or {@link #MATCH_CATEGORY_TYPE}. Higher
189 * values indicate a better match.
190 */
191 public static final int MATCH_CATEGORY_MASK = 0xfff0000;
192
193 /**
194 * The part of a match constant that applies a quality adjustment to the
195 * basic category of match. The value {@link #MATCH_ADJUSTMENT_NORMAL}
196 * is no adjustment; higher numbers than that improve the quality, while
197 * lower numbers reduce it.
198 */
199 public static final int MATCH_ADJUSTMENT_MASK = 0x000ffff;
200
201 /**
202 * Quality adjustment applied to the category of match that signifies
203 * the default, base value; higher numbers improve the quality while
204 * lower numbers reduce it.
205 */
206 public static final int MATCH_ADJUSTMENT_NORMAL = 0x8000;
207
208 /**
209 * The filter matched an intent that had no data specified.
210 */
211 public static final int MATCH_CATEGORY_EMPTY = 0x0100000;
212 /**
213 * The filter matched an intent with the same data URI scheme.
214 */
215 public static final int MATCH_CATEGORY_SCHEME = 0x0200000;
216 /**
217 * The filter matched an intent with the same data URI scheme and
218 * authority host.
219 */
220 public static final int MATCH_CATEGORY_HOST = 0x0300000;
221 /**
222 * The filter matched an intent with the same data URI scheme and
223 * authority host and port.
224 */
225 public static final int MATCH_CATEGORY_PORT = 0x0400000;
226 /**
227 * The filter matched an intent with the same data URI scheme,
228 * authority, and path.
229 */
230 public static final int MATCH_CATEGORY_PATH = 0x0500000;
231 /**
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -0700232 * The filter matched an intent with the same data URI scheme and
233 * scheme specific part.
234 */
235 public static final int MATCH_CATEGORY_SCHEME_SPECIFIC_PART = 0x0580000;
236 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700237 * The filter matched an intent with the same data MIME type.
238 */
239 public static final int MATCH_CATEGORY_TYPE = 0x0600000;
240
241 /**
242 * The filter didn't match due to different MIME types.
243 */
244 public static final int NO_MATCH_TYPE = -1;
245 /**
246 * The filter didn't match due to different data URIs.
247 */
248 public static final int NO_MATCH_DATA = -2;
249 /**
250 * The filter didn't match due to different actions.
251 */
252 public static final int NO_MATCH_ACTION = -3;
253 /**
254 * The filter didn't match because it required one or more categories
255 * that were not in the Intent.
256 */
257 public static final int NO_MATCH_CATEGORY = -4;
258
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -0800259 /**
260 * HTTP scheme.
261 *
262 * @see #addDataScheme(String)
Dianne Hackbornece0f4f2015-06-11 13:29:01 -0700263 * @hide
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -0800264 */
265 public static final String SCHEME_HTTP = "http";
266 /**
267 * HTTPS scheme.
268 *
269 * @see #addDataScheme(String)
Dianne Hackbornece0f4f2015-06-11 13:29:01 -0700270 * @hide
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -0800271 */
272 public static final String SCHEME_HTTPS = "https";
273
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700274 private int mPriority;
Mathew Inwood1c77a112018-08-14 14:06:26 +0100275 @UnsupportedAppUsage
Todd Kennedyc2e96d42016-09-08 15:34:03 -0700276 private int mOrder;
Mathew Inwood1c77a112018-08-14 14:06:26 +0100277 @UnsupportedAppUsage
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700278 private final ArrayList<String> mActions;
279 private ArrayList<String> mCategories = null;
280 private ArrayList<String> mDataSchemes = null;
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -0700281 private ArrayList<PatternMatcher> mDataSchemeSpecificParts = null;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700282 private ArrayList<AuthorityEntry> mDataAuthorities = null;
283 private ArrayList<PatternMatcher> mDataPaths = null;
284 private ArrayList<String> mDataTypes = null;
285 private boolean mHasPartialTypes = false;
286
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -0800287 private static final int STATE_VERIFY_AUTO = 0x00000001;
288 private static final int STATE_NEED_VERIFY = 0x00000010;
289 private static final int STATE_NEED_VERIFY_CHECKED = 0x00000100;
290 private static final int STATE_VERIFIED = 0x00001000;
291
292 private int mVerifyState;
Todd Kennedyc05f5d12017-04-25 11:11:40 -0700293 /** @hide */
294 public static final int VISIBILITY_NONE = 0;
295 /** @hide */
296 public static final int VISIBILITY_EXPLICIT = 1;
297 /** @hide */
298 public static final int VISIBILITY_IMPLICIT = 2;
299 /** @hide */
300 @IntDef(prefix = { "VISIBILITY_" }, value = {
301 VISIBILITY_NONE,
302 VISIBILITY_EXPLICIT,
303 VISIBILITY_IMPLICIT,
304 })
305 @Retention(RetentionPolicy.SOURCE)
306 public @interface InstantAppVisibility {}
Todd Kennedy66b5c042017-04-07 11:38:39 -0700307 /** Whether or not the intent filter is visible to instant apps. */
Todd Kennedyc05f5d12017-04-25 11:11:40 -0700308 private @InstantAppVisibility int mInstantAppVisibility;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700309 // These functions are the start of more optimized code for managing
310 // the string sets... not yet implemented.
311
312 private static int findStringInSet(String[] set, String string,
313 int[] lengths, int lenPos) {
314 if (set == null) return -1;
315 final int N = lengths[lenPos];
316 for (int i=0; i<N; i++) {
317 if (set[i].equals(string)) return i;
318 }
319 return -1;
320 }
321
322 private static String[] addStringToSet(String[] set, String string,
323 int[] lengths, int lenPos) {
324 if (findStringInSet(set, string, lengths, lenPos) >= 0) return set;
325 if (set == null) {
326 set = new String[2];
327 set[0] = string;
328 lengths[lenPos] = 1;
329 return set;
330 }
331 final int N = lengths[lenPos];
332 if (N < set.length) {
333 set[N] = string;
334 lengths[lenPos] = N+1;
335 return set;
336 }
337
338 String[] newSet = new String[(N*3)/2 + 2];
339 System.arraycopy(set, 0, newSet, 0, N);
340 set = newSet;
341 set[N] = string;
342 lengths[lenPos] = N+1;
343 return set;
344 }
345
346 private static String[] removeStringFromSet(String[] set, String string,
347 int[] lengths, int lenPos) {
348 int pos = findStringInSet(set, string, lengths, lenPos);
349 if (pos < 0) return set;
350 final int N = lengths[lenPos];
351 if (N > (set.length/4)) {
352 int copyLen = N-(pos+1);
353 if (copyLen > 0) {
354 System.arraycopy(set, pos+1, set, pos, copyLen);
355 }
356 set[N-1] = null;
357 lengths[lenPos] = N-1;
358 return set;
359 }
360
361 String[] newSet = new String[set.length/3];
362 if (pos > 0) System.arraycopy(set, 0, newSet, 0, pos);
363 if ((pos+1) < N) System.arraycopy(set, pos+1, newSet, pos, N-(pos+1));
364 return newSet;
365 }
366
367 /**
368 * This exception is thrown when a given MIME type does not have a valid
369 * syntax.
370 */
371 public static class MalformedMimeTypeException extends AndroidException {
372 public MalformedMimeTypeException() {
373 }
374
375 public MalformedMimeTypeException(String name) {
376 super(name);
377 }
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -0800378 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700379
380 /**
381 * Create a new IntentFilter instance with a specified action and MIME
382 * type, where you know the MIME type is correctly formatted. This catches
383 * the {@link MalformedMimeTypeException} exception that the constructor
384 * can call and turns it into a runtime exception.
385 *
Kevin Hufnaglee20b3d72016-09-22 18:33:57 -0700386 * @param action The action to match, such as Intent.ACTION_VIEW.
387 * @param dataType The type to match, such as "vnd.android.cursor.dir/person".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700388 *
389 * @return A new IntentFilter for the given action and type.
390 *
391 * @see #IntentFilter(String, String)
392 */
393 public static IntentFilter create(String action, String dataType) {
394 try {
395 return new IntentFilter(action, dataType);
396 } catch (MalformedMimeTypeException e) {
397 throw new RuntimeException("Bad MIME type", e);
398 }
399 }
400
401 /**
402 * New empty IntentFilter.
403 */
404 public IntentFilter() {
405 mPriority = 0;
406 mActions = new ArrayList<String>();
407 }
408
409 /**
410 * New IntentFilter that matches a single action with no data. If
411 * no data characteristics are subsequently specified, then the
412 * filter will only match intents that contain no data.
413 *
Kevin Hufnaglee20b3d72016-09-22 18:33:57 -0700414 * @param action The action to match, such as Intent.ACTION_MAIN.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700415 */
416 public IntentFilter(String action) {
417 mPriority = 0;
418 mActions = new ArrayList<String>();
419 addAction(action);
420 }
421
422 /**
423 * New IntentFilter that matches a single action and data type.
424 *
Dianne Hackbornb3cddae2009-04-13 16:54:00 -0700425 * <p><em>Note: MIME type matching in the Android framework is
426 * case-sensitive, unlike formal RFC MIME types. As a result,
427 * you should always write your MIME types with lower case letters,
428 * and any MIME types you receive from outside of Android should be
429 * converted to lower case before supplying them here.</em></p>
430 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700431 * <p>Throws {@link MalformedMimeTypeException} if the given MIME type is
432 * not syntactically correct.
433 *
Kevin Hufnaglee20b3d72016-09-22 18:33:57 -0700434 * @param action The action to match, such as Intent.ACTION_VIEW.
435 * @param dataType The type to match, such as "vnd.android.cursor.dir/person".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700436 *
437 */
438 public IntentFilter(String action, String dataType)
439 throws MalformedMimeTypeException {
440 mPriority = 0;
441 mActions = new ArrayList<String>();
Tom Gibara24847f32008-11-04 02:25:42 +0000442 addAction(action);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700443 addDataType(dataType);
444 }
445
446 /**
447 * New IntentFilter containing a copy of an existing filter.
448 *
449 * @param o The original filter to copy.
450 */
451 public IntentFilter(IntentFilter o) {
452 mPriority = o.mPriority;
Todd Kennedyc2e96d42016-09-08 15:34:03 -0700453 mOrder = o.mOrder;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700454 mActions = new ArrayList<String>(o.mActions);
455 if (o.mCategories != null) {
456 mCategories = new ArrayList<String>(o.mCategories);
457 }
458 if (o.mDataTypes != null) {
459 mDataTypes = new ArrayList<String>(o.mDataTypes);
460 }
461 if (o.mDataSchemes != null) {
462 mDataSchemes = new ArrayList<String>(o.mDataSchemes);
463 }
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -0700464 if (o.mDataSchemeSpecificParts != null) {
465 mDataSchemeSpecificParts = new ArrayList<PatternMatcher>(o.mDataSchemeSpecificParts);
466 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700467 if (o.mDataAuthorities != null) {
468 mDataAuthorities = new ArrayList<AuthorityEntry>(o.mDataAuthorities);
469 }
470 if (o.mDataPaths != null) {
471 mDataPaths = new ArrayList<PatternMatcher>(o.mDataPaths);
472 }
473 mHasPartialTypes = o.mHasPartialTypes;
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -0800474 mVerifyState = o.mVerifyState;
Todd Kennedyc05f5d12017-04-25 11:11:40 -0700475 mInstantAppVisibility = o.mInstantAppVisibility;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700476 }
477
478 /**
Todd Kennedy2c4078612016-04-06 10:57:51 -0700479 * Modify priority of this filter. This only affects receiver filters.
480 * The priority of activity filters are set in XML and cannot be changed
481 * programatically. The default priority is 0. Positive values will be
482 * before the default, lower values will be after it. Applications should
483 * use a value that is larger than {@link #SYSTEM_LOW_PRIORITY} and
484 * smaller than {@link #SYSTEM_HIGH_PRIORITY} .
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700485 *
486 * @param priority The new priority value.
487 *
488 * @see #getPriority
489 * @see #SYSTEM_LOW_PRIORITY
490 * @see #SYSTEM_HIGH_PRIORITY
491 */
492 public final void setPriority(int priority) {
493 mPriority = priority;
494 }
495
496 /**
497 * Return the priority of this filter.
498 *
499 * @return The priority of the filter.
500 *
501 * @see #setPriority
502 */
503 public final int getPriority() {
504 return mPriority;
505 }
506
Todd Kennedyc2e96d42016-09-08 15:34:03 -0700507 /** @hide */
Todd Kennedy9c9fdf22017-03-06 10:58:27 -0800508 @SystemApi
Todd Kennedyc2e96d42016-09-08 15:34:03 -0700509 public final void setOrder(int order) {
510 mOrder = order;
511 }
512
513 /** @hide */
Todd Kennedy9c9fdf22017-03-06 10:58:27 -0800514 @SystemApi
Todd Kennedyc2e96d42016-09-08 15:34:03 -0700515 public final int getOrder() {
516 return mOrder;
517 }
518
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700519 /**
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -0800520 * Set whether this filter will needs to be automatically verified against its data URIs or not.
521 * The default is false.
522 *
523 * The verification would need to happen only and only if the Intent action is
524 * {@link android.content.Intent#ACTION_VIEW} and the Intent category is
525 * {@link android.content.Intent#CATEGORY_BROWSABLE} and the Intent data scheme
526 * is "http" or "https".
527 *
528 * True means that the filter will need to use its data URIs to be verified.
529 *
530 * @param autoVerify The new autoVerify value.
531 *
532 * @see #getAutoVerify()
533 * @see #addAction(String)
534 * @see #getAction(int)
535 * @see #addCategory(String)
536 * @see #getCategory(int)
537 * @see #addDataScheme(String)
538 * @see #getDataScheme(int)
539 *
540 * @hide
541 */
Mathew Inwood1c77a112018-08-14 14:06:26 +0100542 @UnsupportedAppUsage
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -0800543 public final void setAutoVerify(boolean autoVerify) {
544 mVerifyState &= ~STATE_VERIFY_AUTO;
545 if (autoVerify) mVerifyState |= STATE_VERIFY_AUTO;
546 }
547
548 /**
549 * Return if this filter will needs to be automatically verified again its data URIs or not.
550 *
551 * @return True if the filter will needs to be automatically verified. False otherwise.
552 *
553 * @see #setAutoVerify(boolean)
554 *
555 * @hide
556 */
557 public final boolean getAutoVerify() {
Christopher Tate3decab62016-12-15 14:18:15 -0800558 return ((mVerifyState & STATE_VERIFY_AUTO) == STATE_VERIFY_AUTO);
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -0800559 }
560
561 /**
Christopher Tate21347442015-06-26 17:23:32 -0700562 * Return if this filter handle all HTTP or HTTPS data URI or not. This is the
563 * core check for whether a given activity qualifies as a "browser".
Fabrice Di Meglio7d014ce2015-04-08 16:17:46 -0700564 *
565 * @return True if the filter handle all HTTP or HTTPS data URI. False otherwise.
566 *
Fabrice Di Meglio2d897fb2015-04-09 20:03:23 -0700567 * This will check if:
568 *
569 * - either the Intent category is {@link android.content.Intent#CATEGORY_APP_BROWSER}
570 * - either the Intent action is {@link android.content.Intent#ACTION_VIEW} and
Fabrice Di Meglio7d014ce2015-04-08 16:17:46 -0700571 * the Intent category is {@link android.content.Intent#CATEGORY_BROWSABLE} and the Intent
572 * data scheme is "http" or "https" and that there is no specific host defined.
573 *
574 * @hide
575 */
576 public final boolean handleAllWebDataURI() {
Fabrice Di Meglio2d897fb2015-04-09 20:03:23 -0700577 return hasCategory(Intent.CATEGORY_APP_BROWSER) ||
Christopher Tate21347442015-06-26 17:23:32 -0700578 (handlesWebUris(false) && countDataAuthorities() == 0);
Fabrice Di Meglio7d014ce2015-04-08 16:17:46 -0700579 }
580
581 /**
Christopher Tate21347442015-06-26 17:23:32 -0700582 * Return if this filter handles HTTP or HTTPS data URIs.
Fabrice Di Meglio7d014ce2015-04-08 16:17:46 -0700583 *
Christopher Tate413020a2015-06-23 19:23:46 -0700584 * @return True if the filter handles ACTION_VIEW/CATEGORY_BROWSABLE,
Christopher Tate21347442015-06-26 17:23:32 -0700585 * has at least one HTTP or HTTPS data URI pattern defined, and optionally
586 * does not define any non-http/https data URI patterns.
Fabrice Di Meglio7d014ce2015-04-08 16:17:46 -0700587 *
588 * This will check if if the Intent action is {@link android.content.Intent#ACTION_VIEW} and
589 * the Intent category is {@link android.content.Intent#CATEGORY_BROWSABLE} and the Intent
590 * data scheme is "http" or "https".
591 *
Christopher Tate21347442015-06-26 17:23:32 -0700592 * @param onlyWebSchemes When true, requires that the intent filter declare
593 * that it handles *only* http: or https: schemes. This is a requirement for
594 * the intent filter's domain linkage being verifiable.
Fabrice Di Meglio7d014ce2015-04-08 16:17:46 -0700595 * @hide
596 */
Christopher Tate21347442015-06-26 17:23:32 -0700597 public final boolean handlesWebUris(boolean onlyWebSchemes) {
Christopher Tate413020a2015-06-23 19:23:46 -0700598 // Require ACTION_VIEW, CATEGORY_BROWSEABLE, and at least one scheme
599 if (!hasAction(Intent.ACTION_VIEW)
600 || !hasCategory(Intent.CATEGORY_BROWSABLE)
601 || mDataSchemes == null
602 || mDataSchemes.size() == 0) {
603 return false;
604 }
605
606 // Now allow only the schemes "http" and "https"
607 final int N = mDataSchemes.size();
608 for (int i = 0; i < N; i++) {
609 final String scheme = mDataSchemes.get(i);
Christopher Tate21347442015-06-26 17:23:32 -0700610 final boolean isWebScheme =
611 SCHEME_HTTP.equals(scheme) || SCHEME_HTTPS.equals(scheme);
612 if (onlyWebSchemes) {
613 // If we're specifically trying to ensure that there are no non-web schemes
614 // declared in this filter, then if we ever see a non-http/https scheme then
615 // we know it's a failure.
616 if (!isWebScheme) {
617 return false;
618 }
619 } else {
620 // If we see any http/https scheme declaration in this case then the
621 // filter matches what we're looking for.
622 if (isWebScheme) {
623 return true;
624 }
Christopher Tate413020a2015-06-23 19:23:46 -0700625 }
626 }
627
Christopher Tate21347442015-06-26 17:23:32 -0700628 // We get here if:
629 // 1) onlyWebSchemes and no non-web schemes were found, i.e success; or
630 // 2) !onlyWebSchemes and no http/https schemes were found, i.e. failure.
631 return onlyWebSchemes;
Fabrice Di Meglio7d014ce2015-04-08 16:17:46 -0700632 }
633
634 /**
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -0800635 * Return if this filter needs to be automatically verified again its data URIs or not.
636 *
637 * @return True if the filter needs to be automatically verified. False otherwise.
638 *
639 * This will check if if the Intent action is {@link android.content.Intent#ACTION_VIEW} and
640 * the Intent category is {@link android.content.Intent#CATEGORY_BROWSABLE} and the Intent
641 * data scheme is "http" or "https".
642 *
643 * @see #setAutoVerify(boolean)
644 *
645 * @hide
646 */
647 public final boolean needsVerification() {
Christopher Tate21347442015-06-26 17:23:32 -0700648 return getAutoVerify() && handlesWebUris(true);
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -0800649 }
650
651 /**
652 * Return if this filter has been verified
653 *
654 * @return true if the filter has been verified or if autoVerify is false.
655 *
656 * @hide
657 */
Mathew Inwood1c77a112018-08-14 14:06:26 +0100658 @UnsupportedAppUsage
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -0800659 public final boolean isVerified() {
660 if ((mVerifyState & STATE_NEED_VERIFY_CHECKED) == STATE_NEED_VERIFY_CHECKED) {
661 return ((mVerifyState & STATE_NEED_VERIFY) == STATE_NEED_VERIFY);
662 }
663 return false;
664 }
665
666 /**
667 * Set if this filter has been verified
668 *
669 * @param verified true if this filter has been verified. False otherwise.
670 *
671 * @hide
672 */
673 public void setVerified(boolean verified) {
674 mVerifyState |= STATE_NEED_VERIFY_CHECKED;
675 mVerifyState &= ~STATE_VERIFIED;
676 if (verified) mVerifyState |= STATE_VERIFIED;
677 }
678
Todd Kennedy7bc3a702016-12-08 14:54:48 -0800679 /** @hide */
Todd Kennedyc05f5d12017-04-25 11:11:40 -0700680 public void setVisibilityToInstantApp(@InstantAppVisibility int visibility) {
681 mInstantAppVisibility = visibility;
682 }
683 /** @hide */
684 public @InstantAppVisibility int getVisibilityToInstantApp() {
685 return mInstantAppVisibility;
Todd Kennedy7bc3a702016-12-08 14:54:48 -0800686 }
687 /** @hide */
Todd Kennedybe0b8892017-02-15 14:13:52 -0800688 public boolean isVisibleToInstantApp() {
Todd Kennedyc05f5d12017-04-25 11:11:40 -0700689 return mInstantAppVisibility != VISIBILITY_NONE;
690 }
691 /** @hide */
692 public boolean isExplicitlyVisibleToInstantApp() {
693 return mInstantAppVisibility == VISIBILITY_EXPLICIT;
694 }
695 /** @hide */
696 public boolean isImplicitlyVisibleToInstantApp() {
697 return mInstantAppVisibility == VISIBILITY_IMPLICIT;
Todd Kennedy7bc3a702016-12-08 14:54:48 -0800698 }
699
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -0800700 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700701 * Add a new Intent action to match against. If any actions are included
702 * in the filter, then an Intent's action must be one of those values for
703 * it to match. If no actions are included, the Intent action is ignored.
704 *
Kevin Hufnaglee20b3d72016-09-22 18:33:57 -0700705 * @param action Name of the action to match, such as Intent.ACTION_VIEW.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700706 */
707 public final void addAction(String action) {
708 if (!mActions.contains(action)) {
709 mActions.add(action.intern());
710 }
711 }
712
713 /**
714 * Return the number of actions in the filter.
715 */
716 public final int countActions() {
717 return mActions.size();
718 }
719
720 /**
721 * Return an action in the filter.
722 */
723 public final String getAction(int index) {
724 return mActions.get(index);
725 }
726
727 /**
728 * Is the given action included in the filter? Note that if the filter
729 * does not include any actions, false will <em>always</em> be returned.
730 *
731 * @param action The action to look for.
732 *
733 * @return True if the action is explicitly mentioned in the filter.
734 */
735 public final boolean hasAction(String action) {
Jeff Brown2c376fc2011-01-28 17:34:01 -0800736 return action != null && mActions.contains(action);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700737 }
738
739 /**
740 * Match this filter against an Intent's action. If the filter does not
741 * specify any actions, the match will always fail.
742 *
743 * @param action The desired action to look for.
744 *
Jeff Brown2c376fc2011-01-28 17:34:01 -0800745 * @return True if the action is listed in the filter.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700746 */
747 public final boolean matchAction(String action) {
Jeff Brown2c376fc2011-01-28 17:34:01 -0800748 return hasAction(action);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700749 }
750
751 /**
752 * Return an iterator over the filter's actions. If there are no actions,
753 * returns null.
754 */
755 public final Iterator<String> actionsIterator() {
756 return mActions != null ? mActions.iterator() : null;
757 }
758
759 /**
760 * Add a new Intent data type to match against. If any types are
761 * included in the filter, then an Intent's data must be <em>either</em>
762 * one of these types <em>or</em> a matching scheme. If no data types
763 * are included, then an Intent will only match if it specifies no data.
764 *
Dianne Hackbornb3cddae2009-04-13 16:54:00 -0700765 * <p><em>Note: MIME type matching in the Android framework is
766 * case-sensitive, unlike formal RFC MIME types. As a result,
767 * you should always write your MIME types with lower case letters,
768 * and any MIME types you receive from outside of Android should be
769 * converted to lower case before supplying them here.</em></p>
770 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700771 * <p>Throws {@link MalformedMimeTypeException} if the given MIME type is
772 * not syntactically correct.
773 *
Kevin Hufnaglee20b3d72016-09-22 18:33:57 -0700774 * @param type Name of the data type to match, such as "vnd.android.cursor.dir/person".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700775 *
776 * @see #matchData
777 */
778 public final void addDataType(String type)
779 throws MalformedMimeTypeException {
780 final int slashpos = type.indexOf('/');
781 final int typelen = type.length();
782 if (slashpos > 0 && typelen >= slashpos+2) {
783 if (mDataTypes == null) mDataTypes = new ArrayList<String>();
784 if (typelen == slashpos+2 && type.charAt(slashpos+1) == '*') {
785 String str = type.substring(0, slashpos);
786 if (!mDataTypes.contains(str)) {
787 mDataTypes.add(str.intern());
788 }
789 mHasPartialTypes = true;
790 } else {
791 if (!mDataTypes.contains(type)) {
792 mDataTypes.add(type.intern());
793 }
794 }
795 return;
796 }
797
798 throw new MalformedMimeTypeException(type);
799 }
800
801 /**
802 * Is the given data type included in the filter? Note that if the filter
803 * does not include any type, false will <em>always</em> be returned.
804 *
805 * @param type The data type to look for.
806 *
807 * @return True if the type is explicitly mentioned in the filter.
808 */
809 public final boolean hasDataType(String type) {
810 return mDataTypes != null && findMimeType(type);
811 }
812
Dianne Hackbornf2ac2762014-08-16 11:44:40 -0700813 /** @hide */
Mathew Inwood1c77a112018-08-14 14:06:26 +0100814 @UnsupportedAppUsage
Dianne Hackbornf2ac2762014-08-16 11:44:40 -0700815 public final boolean hasExactDataType(String type) {
816 return mDataTypes != null && mDataTypes.contains(type);
817 }
818
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700819 /**
820 * Return the number of data types in the filter.
821 */
822 public final int countDataTypes() {
823 return mDataTypes != null ? mDataTypes.size() : 0;
824 }
825
826 /**
827 * Return a data type in the filter.
828 */
829 public final String getDataType(int index) {
830 return mDataTypes.get(index);
831 }
832
833 /**
834 * Return an iterator over the filter's data types.
835 */
836 public final Iterator<String> typesIterator() {
837 return mDataTypes != null ? mDataTypes.iterator() : null;
838 }
839
840 /**
841 * Add a new Intent data scheme to match against. If any schemes are
842 * included in the filter, then an Intent's data must be <em>either</em>
843 * one of these schemes <em>or</em> a matching data type. If no schemes
844 * are included, then an Intent will match only if it includes no data.
845 *
Dianne Hackbornb3cddae2009-04-13 16:54:00 -0700846 * <p><em>Note: scheme matching in the Android framework is
847 * case-sensitive, unlike formal RFC schemes. As a result,
848 * you should always write your schemes with lower case letters,
849 * and any schemes you receive from outside of Android should be
850 * converted to lower case before supplying them here.</em></p>
851 *
Kevin Hufnaglee20b3d72016-09-22 18:33:57 -0700852 * @param scheme Name of the scheme to match, such as "http".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700853 *
854 * @see #matchData
855 */
856 public final void addDataScheme(String scheme) {
857 if (mDataSchemes == null) mDataSchemes = new ArrayList<String>();
858 if (!mDataSchemes.contains(scheme)) {
859 mDataSchemes.add(scheme.intern());
860 }
861 }
862
863 /**
864 * Return the number of data schemes in the filter.
865 */
866 public final int countDataSchemes() {
867 return mDataSchemes != null ? mDataSchemes.size() : 0;
868 }
869
870 /**
871 * Return a data scheme in the filter.
872 */
873 public final String getDataScheme(int index) {
874 return mDataSchemes.get(index);
875 }
876
877 /**
878 * Is the given data scheme included in the filter? Note that if the
879 * filter does not include any scheme, false will <em>always</em> be
880 * returned.
881 *
882 * @param scheme The data scheme to look for.
883 *
884 * @return True if the scheme is explicitly mentioned in the filter.
885 */
886 public final boolean hasDataScheme(String scheme) {
887 return mDataSchemes != null && mDataSchemes.contains(scheme);
888 }
889
890 /**
891 * Return an iterator over the filter's data schemes.
892 */
893 public final Iterator<String> schemesIterator() {
894 return mDataSchemes != null ? mDataSchemes.iterator() : null;
895 }
896
897 /**
898 * This is an entry for a single authority in the Iterator returned by
899 * {@link #authoritiesIterator()}.
900 */
901 public final static class AuthorityEntry {
902 private final String mOrigHost;
903 private final String mHost;
904 private final boolean mWild;
905 private final int mPort;
906
907 public AuthorityEntry(String host, String port) {
908 mOrigHost = host;
909 mWild = host.length() > 0 && host.charAt(0) == '*';
910 mHost = mWild ? host.substring(1).intern() : host;
911 mPort = port != null ? Integer.parseInt(port) : -1;
912 }
913
914 AuthorityEntry(Parcel src) {
915 mOrigHost = src.readString();
916 mHost = src.readString();
917 mWild = src.readInt() != 0;
918 mPort = src.readInt();
919 }
920
921 void writeToParcel(Parcel dest) {
922 dest.writeString(mOrigHost);
923 dest.writeString(mHost);
924 dest.writeInt(mWild ? 1 : 0);
925 dest.writeInt(mPort);
926 }
927
Yi Jin129fc6c2017-09-28 15:48:38 -0700928 void writeToProto(ProtoOutputStream proto, long fieldId) {
929 long token = proto.start(fieldId);
930 // The original host information is already contained in host and wild, no output now.
931 proto.write(AuthorityEntryProto.HOST, mHost);
932 proto.write(AuthorityEntryProto.WILD, mWild);
933 proto.write(AuthorityEntryProto.PORT, mPort);
934 proto.end(token);
935 }
936
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700937 public String getHost() {
938 return mOrigHost;
939 }
940
941 public int getPort() {
942 return mPort;
943 }
944
Dianne Hackbornf2ac2762014-08-16 11:44:40 -0700945 /** @hide */
946 public boolean match(AuthorityEntry other) {
947 if (mWild != other.mWild) {
948 return false;
949 }
950 if (!mHost.equals(other.mHost)) {
951 return false;
952 }
953 if (mPort != other.mPort) {
954 return false;
955 }
956 return true;
957 }
958
Todd Kennedy5585dd92016-03-29 13:07:01 -0700959 @Override
960 public boolean equals(Object obj) {
961 if (obj instanceof AuthorityEntry) {
962 final AuthorityEntry other = (AuthorityEntry)obj;
963 return match(other);
964 }
965 return false;
966 }
967
Dianne Hackbornb3cddae2009-04-13 16:54:00 -0700968 /**
969 * Determine whether this AuthorityEntry matches the given data Uri.
970 * <em>Note that this comparison is case-sensitive, unlike formal
971 * RFC host names. You thus should always normalize to lower-case.</em>
Kevin Hufnaglee20b3d72016-09-22 18:33:57 -0700972 *
Dianne Hackbornb3cddae2009-04-13 16:54:00 -0700973 * @param data The Uri to match.
974 * @return Returns either {@link IntentFilter#NO_MATCH_DATA},
975 * {@link IntentFilter#MATCH_CATEGORY_PORT}, or
976 * {@link IntentFilter#MATCH_CATEGORY_HOST}.
977 */
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700978 public int match(Uri data) {
979 String host = data.getHost();
980 if (host == null) {
981 return NO_MATCH_DATA;
982 }
Joe Onorato43a17652011-04-06 19:22:23 -0700983 if (false) Log.v("IntentFilter",
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700984 "Match host " + host + ": " + mHost);
985 if (mWild) {
986 if (host.length() < mHost.length()) {
987 return NO_MATCH_DATA;
988 }
989 host = host.substring(host.length()-mHost.length());
990 }
991 if (host.compareToIgnoreCase(mHost) != 0) {
992 return NO_MATCH_DATA;
993 }
994 if (mPort >= 0) {
995 if (mPort != data.getPort()) {
996 return NO_MATCH_DATA;
997 }
998 return MATCH_CATEGORY_PORT;
999 }
1000 return MATCH_CATEGORY_HOST;
1001 }
Todd Kennedy5585dd92016-03-29 13:07:01 -07001002 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001003
1004 /**
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07001005 * Add a new Intent data "scheme specific part" to match against. The filter must
1006 * include one or more schemes (via {@link #addDataScheme}) for the
1007 * scheme specific part to be considered. If any scheme specific parts are
1008 * included in the filter, then an Intent's data must match one of
1009 * them. If no scheme specific parts are included, then only the scheme must match.
1010 *
Dianne Hackbornebc15ef2013-10-09 17:36:57 -07001011 * <p>The "scheme specific part" that this matches against is the string returned
1012 * by {@link android.net.Uri#getSchemeSpecificPart() Uri.getSchemeSpecificPart}.
1013 * For Uris that contain a path, this kind of matching is not generally of interest,
1014 * since {@link #addDataAuthority(String, String)} and
1015 * {@link #addDataPath(String, int)} can provide a better mechanism for matching
1016 * them. However, for Uris that do not contain a path, the authority and path
1017 * are empty, so this is the only way to match against the non-scheme part.</p>
1018 *
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07001019 * @param ssp Either a raw string that must exactly match the scheme specific part
1020 * path, or a simple pattern, depending on <var>type</var>.
1021 * @param type Determines how <var>ssp</var> will be compared to
1022 * determine a match: either {@link PatternMatcher#PATTERN_LITERAL},
1023 * {@link PatternMatcher#PATTERN_PREFIX}, or
1024 * {@link PatternMatcher#PATTERN_SIMPLE_GLOB}.
1025 *
1026 * @see #matchData
1027 * @see #addDataScheme
1028 */
1029 public final void addDataSchemeSpecificPart(String ssp, int type) {
Dianne Hackbornb09491f2013-07-22 15:30:11 -07001030 addDataSchemeSpecificPart(new PatternMatcher(ssp, type));
1031 }
1032
1033 /** @hide */
1034 public final void addDataSchemeSpecificPart(PatternMatcher ssp) {
Dianne Hackborn439e9bc82013-06-12 19:13:49 -07001035 if (mDataSchemeSpecificParts == null) {
1036 mDataSchemeSpecificParts = new ArrayList<PatternMatcher>();
1037 }
Dianne Hackbornb09491f2013-07-22 15:30:11 -07001038 mDataSchemeSpecificParts.add(ssp);
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07001039 }
1040
1041 /**
1042 * Return the number of data scheme specific parts in the filter.
1043 */
1044 public final int countDataSchemeSpecificParts() {
1045 return mDataSchemeSpecificParts != null ? mDataSchemeSpecificParts.size() : 0;
1046 }
1047
1048 /**
1049 * Return a data scheme specific part in the filter.
1050 */
1051 public final PatternMatcher getDataSchemeSpecificPart(int index) {
1052 return mDataSchemeSpecificParts.get(index);
1053 }
1054
1055 /**
1056 * Is the given data scheme specific part included in the filter? Note that if the
1057 * filter does not include any scheme specific parts, false will <em>always</em> be
1058 * returned.
1059 *
1060 * @param data The scheme specific part that is being looked for.
1061 *
1062 * @return Returns true if the data string matches a scheme specific part listed in the
1063 * filter.
1064 */
1065 public final boolean hasDataSchemeSpecificPart(String data) {
1066 if (mDataSchemeSpecificParts == null) {
1067 return false;
1068 }
1069 final int numDataSchemeSpecificParts = mDataSchemeSpecificParts.size();
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07001070 for (int i = 0; i < numDataSchemeSpecificParts; i++) {
1071 final PatternMatcher pe = mDataSchemeSpecificParts.get(i);
1072 if (pe.match(data)) {
1073 return true;
1074 }
1075 }
1076 return false;
1077 }
1078
Dianne Hackbornf2ac2762014-08-16 11:44:40 -07001079 /** @hide */
Mathew Inwood1c77a112018-08-14 14:06:26 +01001080 @UnsupportedAppUsage
Dianne Hackbornf2ac2762014-08-16 11:44:40 -07001081 public final boolean hasDataSchemeSpecificPart(PatternMatcher ssp) {
1082 if (mDataSchemeSpecificParts == null) {
1083 return false;
1084 }
1085 final int numDataSchemeSpecificParts = mDataSchemeSpecificParts.size();
1086 for (int i = 0; i < numDataSchemeSpecificParts; i++) {
1087 final PatternMatcher pe = mDataSchemeSpecificParts.get(i);
1088 if (pe.getType() == ssp.getType() && pe.getPath().equals(ssp.getPath())) {
1089 return true;
1090 }
1091 }
1092 return false;
1093 }
1094
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07001095 /**
1096 * Return an iterator over the filter's data scheme specific parts.
1097 */
1098 public final Iterator<PatternMatcher> schemeSpecificPartsIterator() {
1099 return mDataSchemeSpecificParts != null ? mDataSchemeSpecificParts.iterator() : null;
1100 }
1101
1102 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001103 * Add a new Intent data authority to match against. The filter must
1104 * include one or more schemes (via {@link #addDataScheme}) for the
1105 * authority to be considered. If any authorities are
1106 * included in the filter, then an Intent's data must match one of
1107 * them. If no authorities are included, then only the scheme must match.
1108 *
Dianne Hackbornb3cddae2009-04-13 16:54:00 -07001109 * <p><em>Note: host name in the Android framework is
1110 * case-sensitive, unlike formal RFC host names. As a result,
1111 * you should always write your host names with lower case letters,
1112 * and any host names you receive from outside of Android should be
1113 * converted to lower case before supplying them here.</em></p>
1114 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001115 * @param host The host part of the authority to match. May start with a
1116 * single '*' to wildcard the front of the host name.
1117 * @param port Optional port part of the authority to match. If null, any
1118 * port is allowed.
1119 *
1120 * @see #matchData
1121 * @see #addDataScheme
1122 */
1123 public final void addDataAuthority(String host, String port) {
Dianne Hackbornb09491f2013-07-22 15:30:11 -07001124 if (port != null) port = port.intern();
1125 addDataAuthority(new AuthorityEntry(host.intern(), port));
1126 }
1127
1128 /** @hide */
1129 public final void addDataAuthority(AuthorityEntry ent) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001130 if (mDataAuthorities == null) mDataAuthorities =
1131 new ArrayList<AuthorityEntry>();
Dianne Hackbornb09491f2013-07-22 15:30:11 -07001132 mDataAuthorities.add(ent);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001133 }
1134
1135 /**
1136 * Return the number of data authorities in the filter.
1137 */
1138 public final int countDataAuthorities() {
1139 return mDataAuthorities != null ? mDataAuthorities.size() : 0;
1140 }
1141
1142 /**
1143 * Return a data authority in the filter.
1144 */
1145 public final AuthorityEntry getDataAuthority(int index) {
1146 return mDataAuthorities.get(index);
1147 }
1148
1149 /**
1150 * Is the given data authority included in the filter? Note that if the
1151 * filter does not include any authorities, false will <em>always</em> be
1152 * returned.
1153 *
1154 * @param data The data whose authority is being looked for.
1155 *
1156 * @return Returns true if the data string matches an authority listed in the
1157 * filter.
1158 */
1159 public final boolean hasDataAuthority(Uri data) {
1160 return matchDataAuthority(data) >= 0;
1161 }
1162
Dianne Hackbornf2ac2762014-08-16 11:44:40 -07001163 /** @hide */
Mathew Inwood1c77a112018-08-14 14:06:26 +01001164 @UnsupportedAppUsage
Dianne Hackbornf2ac2762014-08-16 11:44:40 -07001165 public final boolean hasDataAuthority(AuthorityEntry auth) {
1166 if (mDataAuthorities == null) {
1167 return false;
1168 }
1169 final int numDataAuthorities = mDataAuthorities.size();
1170 for (int i = 0; i < numDataAuthorities; i++) {
1171 if (mDataAuthorities.get(i).match(auth)) {
1172 return true;
1173 }
1174 }
1175 return false;
1176 }
1177
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001178 /**
1179 * Return an iterator over the filter's data authorities.
1180 */
1181 public final Iterator<AuthorityEntry> authoritiesIterator() {
1182 return mDataAuthorities != null ? mDataAuthorities.iterator() : null;
1183 }
1184
1185 /**
Gilles Debunne37051cd2011-05-25 16:27:13 -07001186 * Add a new Intent data path to match against. The filter must
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001187 * include one or more schemes (via {@link #addDataScheme}) <em>and</em>
1188 * one or more authorities (via {@link #addDataAuthority}) for the
1189 * path to be considered. If any paths are
1190 * included in the filter, then an Intent's data must match one of
1191 * them. If no paths are included, then only the scheme/authority must
1192 * match.
1193 *
1194 * <p>The path given here can either be a literal that must directly
1195 * match or match against a prefix, or it can be a simple globbing pattern.
1196 * If the latter, you can use '*' anywhere in the pattern to match zero
1197 * or more instances of the previous character, '.' as a wildcard to match
1198 * any character, and '\' to escape the next character.
1199 *
1200 * @param path Either a raw string that must exactly match the file
1201 * path, or a simple pattern, depending on <var>type</var>.
1202 * @param type Determines how <var>path</var> will be compared to
1203 * determine a match: either {@link PatternMatcher#PATTERN_LITERAL},
1204 * {@link PatternMatcher#PATTERN_PREFIX}, or
1205 * {@link PatternMatcher#PATTERN_SIMPLE_GLOB}.
1206 *
1207 * @see #matchData
1208 * @see #addDataScheme
1209 * @see #addDataAuthority
1210 */
1211 public final void addDataPath(String path, int type) {
Dianne Hackbornb09491f2013-07-22 15:30:11 -07001212 addDataPath(new PatternMatcher(path.intern(), type));
1213 }
1214
1215 /** @hide */
1216 public final void addDataPath(PatternMatcher path) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001217 if (mDataPaths == null) mDataPaths = new ArrayList<PatternMatcher>();
Dianne Hackbornb09491f2013-07-22 15:30:11 -07001218 mDataPaths.add(path);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001219 }
1220
1221 /**
1222 * Return the number of data paths in the filter.
1223 */
1224 public final int countDataPaths() {
1225 return mDataPaths != null ? mDataPaths.size() : 0;
1226 }
1227
1228 /**
1229 * Return a data path in the filter.
1230 */
1231 public final PatternMatcher getDataPath(int index) {
1232 return mDataPaths.get(index);
1233 }
1234
1235 /**
1236 * Is the given data path included in the filter? Note that if the
1237 * filter does not include any paths, false will <em>always</em> be
1238 * returned.
1239 *
1240 * @param data The data path to look for. This is without the scheme
1241 * prefix.
1242 *
1243 * @return True if the data string matches a path listed in the
1244 * filter.
1245 */
1246 public final boolean hasDataPath(String data) {
1247 if (mDataPaths == null) {
1248 return false;
1249 }
Jeff Brown2c376fc2011-01-28 17:34:01 -08001250 final int numDataPaths = mDataPaths.size();
1251 for (int i = 0; i < numDataPaths; i++) {
1252 final PatternMatcher pe = mDataPaths.get(i);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001253 if (pe.match(data)) {
1254 return true;
1255 }
1256 }
1257 return false;
1258 }
1259
Dianne Hackbornf2ac2762014-08-16 11:44:40 -07001260 /** @hide */
Mathew Inwood1c77a112018-08-14 14:06:26 +01001261 @UnsupportedAppUsage
Dianne Hackbornf2ac2762014-08-16 11:44:40 -07001262 public final boolean hasDataPath(PatternMatcher path) {
1263 if (mDataPaths == null) {
1264 return false;
1265 }
1266 final int numDataPaths = mDataPaths.size();
1267 for (int i = 0; i < numDataPaths; i++) {
1268 final PatternMatcher pe = mDataPaths.get(i);
1269 if (pe.getType() == path.getType() && pe.getPath().equals(path.getPath())) {
1270 return true;
1271 }
1272 }
1273 return false;
1274 }
1275
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001276 /**
1277 * Return an iterator over the filter's data paths.
1278 */
1279 public final Iterator<PatternMatcher> pathsIterator() {
1280 return mDataPaths != null ? mDataPaths.iterator() : null;
1281 }
1282
1283 /**
1284 * Match this intent filter against the given Intent data. This ignores
1285 * the data scheme -- unlike {@link #matchData}, the authority will match
1286 * regardless of whether there is a matching scheme.
1287 *
1288 * @param data The data whose authority is being looked for.
1289 *
1290 * @return Returns either {@link #MATCH_CATEGORY_HOST},
1291 * {@link #MATCH_CATEGORY_PORT}, {@link #NO_MATCH_DATA}.
1292 */
1293 public final int matchDataAuthority(Uri data) {
Dianne Hackborn9dc6c612015-07-28 17:30:59 -07001294 if (mDataAuthorities == null || data == null) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001295 return NO_MATCH_DATA;
1296 }
Jeff Brown2c376fc2011-01-28 17:34:01 -08001297 final int numDataAuthorities = mDataAuthorities.size();
1298 for (int i = 0; i < numDataAuthorities; i++) {
1299 final AuthorityEntry ae = mDataAuthorities.get(i);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001300 int match = ae.match(data);
1301 if (match >= 0) {
1302 return match;
1303 }
1304 }
1305 return NO_MATCH_DATA;
1306 }
1307
1308 /**
1309 * Match this filter against an Intent's data (type, scheme and path). If
1310 * the filter does not specify any types and does not specify any
1311 * schemes/paths, the match will only succeed if the intent does not
Dianne Hackborn0ea920d2013-10-11 09:40:18 -07001312 * also specify a type or data. If the filter does not specify any schemes,
1313 * it will implicitly match intents with no scheme, or the schemes "content:"
1314 * or "file:" (basically performing a MIME-type only match). If the filter
1315 * does not specify any MIME types, the Intent also must not specify a MIME
1316 * type.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001317 *
Dianne Hackbornb3cddae2009-04-13 16:54:00 -07001318 * <p>Be aware that to match against an authority, you must also specify a base
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001319 * scheme the authority is in. To match against a data path, both a scheme
1320 * and authority must be specified. If the filter does not specify any
1321 * types or schemes that it matches against, it is considered to be empty
1322 * (any authority or data path given is ignored, as if it were empty as
1323 * well).
1324 *
Dianne Hackbornb3cddae2009-04-13 16:54:00 -07001325 * <p><em>Note: MIME type, Uri scheme, and host name matching in the
1326 * Android framework is case-sensitive, unlike the formal RFC definitions.
1327 * As a result, you should always write these elements with lower case letters,
1328 * and normalize any MIME types or Uris you receive from
1329 * outside of Android to ensure these elements are lower case before
1330 * supplying them here.</em></p>
1331 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001332 * @param type The desired data type to look for, as returned by
1333 * Intent.resolveType().
1334 * @param scheme The desired data scheme to look for, as returned by
1335 * Intent.getScheme().
1336 * @param data The full data string to match against, as supplied in
1337 * Intent.data.
1338 *
1339 * @return Returns either a valid match constant (a combination of
1340 * {@link #MATCH_CATEGORY_MASK} and {@link #MATCH_ADJUSTMENT_MASK}),
1341 * or one of the error codes {@link #NO_MATCH_TYPE} if the type didn't match
1342 * or {@link #NO_MATCH_DATA} if the scheme/path didn't match.
1343 *
1344 * @see #match
1345 */
1346 public final int matchData(String type, String scheme, Uri data) {
1347 final ArrayList<String> types = mDataTypes;
1348 final ArrayList<String> schemes = mDataSchemes;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001349
1350 int match = MATCH_CATEGORY_EMPTY;
1351
1352 if (types == null && schemes == null) {
1353 return ((type == null && data == null)
1354 ? (MATCH_CATEGORY_EMPTY+MATCH_ADJUSTMENT_NORMAL) : NO_MATCH_DATA);
1355 }
1356
1357 if (schemes != null) {
1358 if (schemes.contains(scheme != null ? scheme : "")) {
1359 match = MATCH_CATEGORY_SCHEME;
1360 } else {
1361 return NO_MATCH_DATA;
1362 }
1363
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07001364 final ArrayList<PatternMatcher> schemeSpecificParts = mDataSchemeSpecificParts;
Dianne Hackborn9dc6c612015-07-28 17:30:59 -07001365 if (schemeSpecificParts != null && data != null) {
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07001366 match = hasDataSchemeSpecificPart(data.getSchemeSpecificPart())
1367 ? MATCH_CATEGORY_SCHEME_SPECIFIC_PART : NO_MATCH_DATA;
1368 }
1369 if (match != MATCH_CATEGORY_SCHEME_SPECIFIC_PART) {
1370 // If there isn't any matching ssp, we need to match an authority.
1371 final ArrayList<AuthorityEntry> authorities = mDataAuthorities;
1372 if (authorities != null) {
1373 int authMatch = matchDataAuthority(data);
1374 if (authMatch >= 0) {
1375 final ArrayList<PatternMatcher> paths = mDataPaths;
1376 if (paths == null) {
1377 match = authMatch;
1378 } else if (hasDataPath(data.getPath())) {
1379 match = MATCH_CATEGORY_PATH;
1380 } else {
1381 return NO_MATCH_DATA;
1382 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001383 } else {
1384 return NO_MATCH_DATA;
1385 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001386 }
1387 }
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07001388 // If neither an ssp nor an authority matched, we're done.
1389 if (match == NO_MATCH_DATA) {
1390 return NO_MATCH_DATA;
1391 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001392 } else {
1393 // Special case: match either an Intent with no data URI,
1394 // or with a scheme: URI. This is to give a convenience for
1395 // the common case where you want to deal with data in a
1396 // content provider, which is done by type, and we don't want
1397 // to force everyone to say they handle content: or file: URIs.
1398 if (scheme != null && !"".equals(scheme)
1399 && !"content".equals(scheme)
1400 && !"file".equals(scheme)) {
1401 return NO_MATCH_DATA;
1402 }
1403 }
1404
1405 if (types != null) {
1406 if (findMimeType(type)) {
1407 match = MATCH_CATEGORY_TYPE;
1408 } else {
1409 return NO_MATCH_TYPE;
1410 }
1411 } else {
1412 // If no MIME types are specified, then we will only match against
1413 // an Intent that does not have a MIME type.
1414 if (type != null) {
1415 return NO_MATCH_TYPE;
1416 }
1417 }
1418
1419 return match + MATCH_ADJUSTMENT_NORMAL;
1420 }
1421
1422 /**
1423 * Add a new Intent category to match against. The semantics of
1424 * categories is the opposite of actions -- an Intent includes the
1425 * categories that it requires, all of which must be included in the
1426 * filter in order to match. In other words, adding a category to the
1427 * filter has no impact on matching unless that category is specified in
1428 * the intent.
1429 *
Kevin Hufnaglee20b3d72016-09-22 18:33:57 -07001430 * @param category Name of category to match, such as Intent.CATEGORY_EMBED.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001431 */
1432 public final void addCategory(String category) {
1433 if (mCategories == null) mCategories = new ArrayList<String>();
1434 if (!mCategories.contains(category)) {
1435 mCategories.add(category.intern());
1436 }
1437 }
1438
1439 /**
1440 * Return the number of categories in the filter.
1441 */
1442 public final int countCategories() {
1443 return mCategories != null ? mCategories.size() : 0;
1444 }
1445
1446 /**
1447 * Return a category in the filter.
1448 */
1449 public final String getCategory(int index) {
1450 return mCategories.get(index);
1451 }
1452
1453 /**
1454 * Is the given category included in the filter?
1455 *
1456 * @param category The category that the filter supports.
1457 *
1458 * @return True if the category is explicitly mentioned in the filter.
1459 */
1460 public final boolean hasCategory(String category) {
1461 return mCategories != null && mCategories.contains(category);
1462 }
1463
1464 /**
1465 * Return an iterator over the filter's categories.
Kenny Rootd2d29252011-08-08 11:27:57 -07001466 *
1467 * @return Iterator if this filter has categories or {@code null} if none.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001468 */
1469 public final Iterator<String> categoriesIterator() {
1470 return mCategories != null ? mCategories.iterator() : null;
1471 }
1472
1473 /**
1474 * Match this filter against an Intent's categories. Each category in
1475 * the Intent must be specified by the filter; if any are not in the
1476 * filter, the match fails.
1477 *
1478 * @param categories The categories included in the intent, as returned by
1479 * Intent.getCategories().
1480 *
1481 * @return If all categories match (success), null; else the name of the
1482 * first category that didn't match.
1483 */
1484 public final String matchCategories(Set<String> categories) {
1485 if (categories == null) {
1486 return null;
1487 }
1488
1489 Iterator<String> it = categories.iterator();
1490
1491 if (mCategories == null) {
1492 return it.hasNext() ? it.next() : null;
1493 }
1494
1495 while (it.hasNext()) {
1496 final String category = it.next();
1497 if (!mCategories.contains(category)) {
1498 return category;
1499 }
1500 }
1501
1502 return null;
1503 }
1504
1505 /**
1506 * Test whether this filter matches the given <var>intent</var>.
1507 *
1508 * @param intent The Intent to compare against.
1509 * @param resolve If true, the intent's type will be resolved by calling
1510 * Intent.resolveType(); otherwise a simple match against
1511 * Intent.type will be performed.
1512 * @param logTag Tag to use in debugging messages.
1513 *
1514 * @return Returns either a valid match constant (a combination of
1515 * {@link #MATCH_CATEGORY_MASK} and {@link #MATCH_ADJUSTMENT_MASK}),
1516 * or one of the error codes {@link #NO_MATCH_TYPE} if the type didn't match,
1517 * {@link #NO_MATCH_DATA} if the scheme/path didn't match,
Dianne Hackborndc894042014-08-12 18:59:28 -07001518 * {@link #NO_MATCH_ACTION} if the action didn't match, or
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001519 * {@link #NO_MATCH_CATEGORY} if one or more categories didn't match.
1520 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001521 * @see #match(String, String, String, android.net.Uri , Set, String)
1522 */
1523 public final int match(ContentResolver resolver, Intent intent,
1524 boolean resolve, String logTag) {
1525 String type = resolve ? intent.resolveType(resolver) : intent.getType();
1526 return match(intent.getAction(), type, intent.getScheme(),
1527 intent.getData(), intent.getCategories(), logTag);
1528 }
1529
1530 /**
1531 * Test whether this filter matches the given intent data. A match is
1532 * only successful if the actions and categories in the Intent match
1533 * against the filter, as described in {@link IntentFilter}; in that case,
1534 * the match result returned will be as per {@link #matchData}.
1535 *
1536 * @param action The intent action to match against (Intent.getAction).
1537 * @param type The intent type to match against (Intent.resolveType()).
1538 * @param scheme The data scheme to match against (Intent.getScheme()).
1539 * @param data The data URI to match against (Intent.getData()).
1540 * @param categories The categories to match against
1541 * (Intent.getCategories()).
1542 * @param logTag Tag to use in debugging messages.
1543 *
1544 * @return Returns either a valid match constant (a combination of
1545 * {@link #MATCH_CATEGORY_MASK} and {@link #MATCH_ADJUSTMENT_MASK}),
1546 * or one of the error codes {@link #NO_MATCH_TYPE} if the type didn't match,
1547 * {@link #NO_MATCH_DATA} if the scheme/path didn't match,
Dianne Hackborndc894042014-08-12 18:59:28 -07001548 * {@link #NO_MATCH_ACTION} if the action didn't match, or
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001549 * {@link #NO_MATCH_CATEGORY} if one or more categories didn't match.
1550 *
1551 * @see #matchData
1552 * @see Intent#getAction
1553 * @see Intent#resolveType
1554 * @see Intent#getScheme
1555 * @see Intent#getData
1556 * @see Intent#getCategories
1557 */
1558 public final int match(String action, String type, String scheme,
1559 Uri data, Set<String> categories, String logTag) {
Jeff Brown239f77d2011-02-26 16:03:48 -08001560 if (action != null && !matchAction(action)) {
Joe Onorato43a17652011-04-06 19:22:23 -07001561 if (false) Log.v(
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001562 logTag, "No matching action " + action + " for " + this);
1563 return NO_MATCH_ACTION;
1564 }
1565
1566 int dataMatch = matchData(type, scheme, data);
1567 if (dataMatch < 0) {
Joe Onorato43a17652011-04-06 19:22:23 -07001568 if (false) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001569 if (dataMatch == NO_MATCH_TYPE) {
1570 Log.v(logTag, "No matching type " + type
1571 + " for " + this);
1572 }
1573 if (dataMatch == NO_MATCH_DATA) {
1574 Log.v(logTag, "No matching scheme/path " + data
1575 + " for " + this);
1576 }
1577 }
1578 return dataMatch;
1579 }
1580
Jeff Brown2c376fc2011-01-28 17:34:01 -08001581 String categoryMismatch = matchCategories(categories);
1582 if (categoryMismatch != null) {
Joe Onorato43a17652011-04-06 19:22:23 -07001583 if (false) {
Jeff Brown2c376fc2011-01-28 17:34:01 -08001584 Log.v(logTag, "No matching category " + categoryMismatch + " for " + this);
1585 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001586 return NO_MATCH_CATEGORY;
1587 }
1588
1589 // It would be nice to treat container activities as more
1590 // important than ones that can be embedded, but this is not the way...
1591 if (false) {
1592 if (categories != null) {
1593 dataMatch -= mCategories.size() - categories.size();
1594 }
1595 }
1596
1597 return dataMatch;
1598 }
1599
1600 /**
1601 * Write the contents of the IntentFilter as an XML stream.
1602 */
1603 public void writeToXml(XmlSerializer serializer) throws IOException {
Wale Ogunwale15b9fd22015-06-19 08:59:52 -07001604
1605 if (getAutoVerify()) {
1606 serializer.attribute(null, AUTO_VERIFY_STR, Boolean.toString(true));
1607 }
1608
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001609 int N = countActions();
1610 for (int i=0; i<N; i++) {
1611 serializer.startTag(null, ACTION_STR);
1612 serializer.attribute(null, NAME_STR, mActions.get(i));
1613 serializer.endTag(null, ACTION_STR);
1614 }
1615 N = countCategories();
1616 for (int i=0; i<N; i++) {
1617 serializer.startTag(null, CAT_STR);
1618 serializer.attribute(null, NAME_STR, mCategories.get(i));
1619 serializer.endTag(null, CAT_STR);
1620 }
1621 N = countDataTypes();
1622 for (int i=0; i<N; i++) {
1623 serializer.startTag(null, TYPE_STR);
1624 String type = mDataTypes.get(i);
1625 if (type.indexOf('/') < 0) type = type + "/*";
1626 serializer.attribute(null, NAME_STR, type);
1627 serializer.endTag(null, TYPE_STR);
1628 }
1629 N = countDataSchemes();
1630 for (int i=0; i<N; i++) {
1631 serializer.startTag(null, SCHEME_STR);
1632 serializer.attribute(null, NAME_STR, mDataSchemes.get(i));
1633 serializer.endTag(null, SCHEME_STR);
1634 }
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07001635 N = countDataSchemeSpecificParts();
1636 for (int i=0; i<N; i++) {
1637 serializer.startTag(null, SSP_STR);
1638 PatternMatcher pe = mDataSchemeSpecificParts.get(i);
1639 switch (pe.getType()) {
1640 case PatternMatcher.PATTERN_LITERAL:
1641 serializer.attribute(null, LITERAL_STR, pe.getPath());
1642 break;
1643 case PatternMatcher.PATTERN_PREFIX:
1644 serializer.attribute(null, PREFIX_STR, pe.getPath());
1645 break;
1646 case PatternMatcher.PATTERN_SIMPLE_GLOB:
1647 serializer.attribute(null, SGLOB_STR, pe.getPath());
1648 break;
Todd Kennedy9c9fdf22017-03-06 10:58:27 -08001649 case PatternMatcher.PATTERN_ADVANCED_GLOB:
1650 serializer.attribute(null, AGLOB_STR, pe.getPath());
1651 break;
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07001652 }
1653 serializer.endTag(null, SSP_STR);
1654 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001655 N = countDataAuthorities();
1656 for (int i=0; i<N; i++) {
1657 serializer.startTag(null, AUTH_STR);
1658 AuthorityEntry ae = mDataAuthorities.get(i);
1659 serializer.attribute(null, HOST_STR, ae.getHost());
1660 if (ae.getPort() >= 0) {
1661 serializer.attribute(null, PORT_STR, Integer.toString(ae.getPort()));
1662 }
1663 serializer.endTag(null, AUTH_STR);
1664 }
1665 N = countDataPaths();
1666 for (int i=0; i<N; i++) {
1667 serializer.startTag(null, PATH_STR);
1668 PatternMatcher pe = mDataPaths.get(i);
1669 switch (pe.getType()) {
1670 case PatternMatcher.PATTERN_LITERAL:
1671 serializer.attribute(null, LITERAL_STR, pe.getPath());
1672 break;
1673 case PatternMatcher.PATTERN_PREFIX:
1674 serializer.attribute(null, PREFIX_STR, pe.getPath());
1675 break;
1676 case PatternMatcher.PATTERN_SIMPLE_GLOB:
1677 serializer.attribute(null, SGLOB_STR, pe.getPath());
1678 break;
Todd Kennedy9c9fdf22017-03-06 10:58:27 -08001679 case PatternMatcher.PATTERN_ADVANCED_GLOB:
1680 serializer.attribute(null, AGLOB_STR, pe.getPath());
1681 break;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001682 }
1683 serializer.endTag(null, PATH_STR);
1684 }
1685 }
1686
1687 public void readFromXml(XmlPullParser parser) throws XmlPullParserException,
1688 IOException {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001689 String autoVerify = parser.getAttributeValue(null, AUTO_VERIFY_STR);
1690 setAutoVerify(TextUtils.isEmpty(autoVerify) ? false : Boolean.getBoolean(autoVerify));
1691
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001692 int outerDepth = parser.getDepth();
1693 int type;
1694 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1695 && (type != XmlPullParser.END_TAG
1696 || parser.getDepth() > outerDepth)) {
1697 if (type == XmlPullParser.END_TAG
1698 || type == XmlPullParser.TEXT) {
1699 continue;
1700 }
1701
1702 String tagName = parser.getName();
1703 if (tagName.equals(ACTION_STR)) {
1704 String name = parser.getAttributeValue(null, NAME_STR);
1705 if (name != null) {
1706 addAction(name);
1707 }
1708 } else if (tagName.equals(CAT_STR)) {
1709 String name = parser.getAttributeValue(null, NAME_STR);
1710 if (name != null) {
1711 addCategory(name);
1712 }
1713 } else if (tagName.equals(TYPE_STR)) {
1714 String name = parser.getAttributeValue(null, NAME_STR);
1715 if (name != null) {
1716 try {
1717 addDataType(name);
1718 } catch (MalformedMimeTypeException e) {
1719 }
1720 }
1721 } else if (tagName.equals(SCHEME_STR)) {
1722 String name = parser.getAttributeValue(null, NAME_STR);
1723 if (name != null) {
1724 addDataScheme(name);
1725 }
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07001726 } else if (tagName.equals(SSP_STR)) {
1727 String ssp = parser.getAttributeValue(null, LITERAL_STR);
1728 if (ssp != null) {
1729 addDataSchemeSpecificPart(ssp, PatternMatcher.PATTERN_LITERAL);
1730 } else if ((ssp=parser.getAttributeValue(null, PREFIX_STR)) != null) {
1731 addDataSchemeSpecificPart(ssp, PatternMatcher.PATTERN_PREFIX);
1732 } else if ((ssp=parser.getAttributeValue(null, SGLOB_STR)) != null) {
1733 addDataSchemeSpecificPart(ssp, PatternMatcher.PATTERN_SIMPLE_GLOB);
Todd Kennedy9c9fdf22017-03-06 10:58:27 -08001734 } else if ((ssp=parser.getAttributeValue(null, AGLOB_STR)) != null) {
1735 addDataSchemeSpecificPart(ssp, PatternMatcher.PATTERN_ADVANCED_GLOB);
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07001736 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001737 } else if (tagName.equals(AUTH_STR)) {
1738 String host = parser.getAttributeValue(null, HOST_STR);
1739 String port = parser.getAttributeValue(null, PORT_STR);
1740 if (host != null) {
1741 addDataAuthority(host, port);
1742 }
1743 } else if (tagName.equals(PATH_STR)) {
1744 String path = parser.getAttributeValue(null, LITERAL_STR);
1745 if (path != null) {
1746 addDataPath(path, PatternMatcher.PATTERN_LITERAL);
1747 } else if ((path=parser.getAttributeValue(null, PREFIX_STR)) != null) {
1748 addDataPath(path, PatternMatcher.PATTERN_PREFIX);
1749 } else if ((path=parser.getAttributeValue(null, SGLOB_STR)) != null) {
1750 addDataPath(path, PatternMatcher.PATTERN_SIMPLE_GLOB);
Todd Kennedy9c9fdf22017-03-06 10:58:27 -08001751 } else if ((path=parser.getAttributeValue(null, AGLOB_STR)) != null) {
1752 addDataPath(path, PatternMatcher.PATTERN_ADVANCED_GLOB);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001753 }
1754 } else {
1755 Log.w("IntentFilter", "Unknown tag parsing IntentFilter: " + tagName);
1756 }
1757 XmlUtils.skipCurrentTag(parser);
1758 }
1759 }
1760
Yi Jin129fc6c2017-09-28 15:48:38 -07001761 /** @hide */
1762 public void writeToProto(ProtoOutputStream proto, long fieldId) {
1763 long token = proto.start(fieldId);
1764 if (mActions.size() > 0) {
1765 Iterator<String> it = mActions.iterator();
1766 while (it.hasNext()) {
1767 proto.write(IntentFilterProto.ACTIONS, it.next());
1768 }
1769 }
1770 if (mCategories != null) {
1771 Iterator<String> it = mCategories.iterator();
1772 while (it.hasNext()) {
1773 proto.write(IntentFilterProto.CATEGORIES, it.next());
1774 }
1775 }
1776 if (mDataSchemes != null) {
1777 Iterator<String> it = mDataSchemes.iterator();
1778 while (it.hasNext()) {
1779 proto.write(IntentFilterProto.DATA_SCHEMES, it.next());
1780 }
1781 }
1782 if (mDataSchemeSpecificParts != null) {
1783 Iterator<PatternMatcher> it = mDataSchemeSpecificParts.iterator();
1784 while (it.hasNext()) {
1785 it.next().writeToProto(proto, IntentFilterProto.DATA_SCHEME_SPECS);
1786 }
1787 }
1788 if (mDataAuthorities != null) {
1789 Iterator<AuthorityEntry> it = mDataAuthorities.iterator();
1790 while (it.hasNext()) {
1791 it.next().writeToProto(proto, IntentFilterProto.DATA_AUTHORITIES);
1792 }
1793 }
1794 if (mDataPaths != null) {
1795 Iterator<PatternMatcher> it = mDataPaths.iterator();
1796 while (it.hasNext()) {
1797 it.next().writeToProto(proto, IntentFilterProto.DATA_PATHS);
1798 }
1799 }
1800 if (mDataTypes != null) {
1801 Iterator<String> it = mDataTypes.iterator();
1802 while (it.hasNext()) {
1803 proto.write(IntentFilterProto.DATA_TYPES, it.next());
1804 }
1805 }
1806 if (mPriority != 0 || mHasPartialTypes) {
1807 proto.write(IntentFilterProto.PRIORITY, mPriority);
1808 proto.write(IntentFilterProto.HAS_PARTIAL_TYPES, mHasPartialTypes);
1809 }
1810 proto.write(IntentFilterProto.GET_AUTO_VERIFY, getAutoVerify());
1811 proto.end(token);
1812 }
1813
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001814 public void dump(Printer du, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001815 StringBuilder sb = new StringBuilder(256);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001816 if (mActions.size() > 0) {
1817 Iterator<String> it = mActions.iterator();
1818 while (it.hasNext()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001819 sb.setLength(0);
1820 sb.append(prefix); sb.append("Action: \"");
1821 sb.append(it.next()); sb.append("\"");
1822 du.println(sb.toString());
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001823 }
1824 }
1825 if (mCategories != null) {
1826 Iterator<String> it = mCategories.iterator();
1827 while (it.hasNext()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001828 sb.setLength(0);
1829 sb.append(prefix); sb.append("Category: \"");
1830 sb.append(it.next()); sb.append("\"");
1831 du.println(sb.toString());
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001832 }
1833 }
1834 if (mDataSchemes != null) {
1835 Iterator<String> it = mDataSchemes.iterator();
1836 while (it.hasNext()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001837 sb.setLength(0);
1838 sb.append(prefix); sb.append("Scheme: \"");
1839 sb.append(it.next()); sb.append("\"");
1840 du.println(sb.toString());
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001841 }
1842 }
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07001843 if (mDataSchemeSpecificParts != null) {
1844 Iterator<PatternMatcher> it = mDataSchemeSpecificParts.iterator();
1845 while (it.hasNext()) {
1846 PatternMatcher pe = it.next();
1847 sb.setLength(0);
1848 sb.append(prefix); sb.append("Ssp: \"");
1849 sb.append(pe); sb.append("\"");
1850 du.println(sb.toString());
1851 }
1852 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001853 if (mDataAuthorities != null) {
1854 Iterator<AuthorityEntry> it = mDataAuthorities.iterator();
1855 while (it.hasNext()) {
1856 AuthorityEntry ae = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001857 sb.setLength(0);
1858 sb.append(prefix); sb.append("Authority: \"");
1859 sb.append(ae.mHost); sb.append("\": ");
1860 sb.append(ae.mPort);
1861 if (ae.mWild) sb.append(" WILD");
1862 du.println(sb.toString());
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001863 }
1864 }
1865 if (mDataPaths != null) {
1866 Iterator<PatternMatcher> it = mDataPaths.iterator();
1867 while (it.hasNext()) {
1868 PatternMatcher pe = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001869 sb.setLength(0);
1870 sb.append(prefix); sb.append("Path: \"");
1871 sb.append(pe); sb.append("\"");
1872 du.println(sb.toString());
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001873 }
1874 }
1875 if (mDataTypes != null) {
1876 Iterator<String> it = mDataTypes.iterator();
1877 while (it.hasNext()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001878 sb.setLength(0);
1879 sb.append(prefix); sb.append("Type: \"");
1880 sb.append(it.next()); sb.append("\"");
1881 du.println(sb.toString());
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001882 }
1883 }
Todd Kennedy6d418b62018-02-22 14:15:18 -08001884 if (mPriority != 0 || mOrder != 0 || mHasPartialTypes) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001885 sb.setLength(0);
1886 sb.append(prefix); sb.append("mPriority="); sb.append(mPriority);
Todd Kennedy6d418b62018-02-22 14:15:18 -08001887 sb.append(", mOrder="); sb.append(mOrder);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001888 sb.append(", mHasPartialTypes="); sb.append(mHasPartialTypes);
1889 du.println(sb.toString());
1890 }
Dianne Hackborn342e6032017-04-13 18:04:31 -07001891 if (getAutoVerify()) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001892 sb.setLength(0);
1893 sb.append(prefix); sb.append("AutoVerify="); sb.append(getAutoVerify());
1894 du.println(sb.toString());
1895 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001896 }
1897
1898 public static final Parcelable.Creator<IntentFilter> CREATOR
1899 = new Parcelable.Creator<IntentFilter>() {
1900 public IntentFilter createFromParcel(Parcel source) {
1901 return new IntentFilter(source);
1902 }
1903
1904 public IntentFilter[] newArray(int size) {
1905 return new IntentFilter[size];
1906 }
1907 };
1908
1909 public final int describeContents() {
1910 return 0;
1911 }
1912
1913 public final void writeToParcel(Parcel dest, int flags) {
1914 dest.writeStringList(mActions);
1915 if (mCategories != null) {
1916 dest.writeInt(1);
1917 dest.writeStringList(mCategories);
1918 } else {
1919 dest.writeInt(0);
1920 }
1921 if (mDataSchemes != null) {
1922 dest.writeInt(1);
1923 dest.writeStringList(mDataSchemes);
1924 } else {
1925 dest.writeInt(0);
1926 }
1927 if (mDataTypes != null) {
1928 dest.writeInt(1);
1929 dest.writeStringList(mDataTypes);
1930 } else {
1931 dest.writeInt(0);
1932 }
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07001933 if (mDataSchemeSpecificParts != null) {
1934 final int N = mDataSchemeSpecificParts.size();
1935 dest.writeInt(N);
1936 for (int i=0; i<N; i++) {
Dianne Hackborn439e9bc82013-06-12 19:13:49 -07001937 mDataSchemeSpecificParts.get(i).writeToParcel(dest, flags);
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07001938 }
1939 } else {
1940 dest.writeInt(0);
1941 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001942 if (mDataAuthorities != null) {
1943 final int N = mDataAuthorities.size();
1944 dest.writeInt(N);
1945 for (int i=0; i<N; i++) {
1946 mDataAuthorities.get(i).writeToParcel(dest);
1947 }
1948 } else {
1949 dest.writeInt(0);
1950 }
1951 if (mDataPaths != null) {
1952 final int N = mDataPaths.size();
1953 dest.writeInt(N);
1954 for (int i=0; i<N; i++) {
Dianne Hackborn439e9bc82013-06-12 19:13:49 -07001955 mDataPaths.get(i).writeToParcel(dest, flags);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001956 }
1957 } else {
1958 dest.writeInt(0);
1959 }
1960 dest.writeInt(mPriority);
1961 dest.writeInt(mHasPartialTypes ? 1 : 0);
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001962 dest.writeInt(getAutoVerify() ? 1 : 0);
Todd Kennedyc05f5d12017-04-25 11:11:40 -07001963 dest.writeInt(mInstantAppVisibility);
Todd Kennedy6d418b62018-02-22 14:15:18 -08001964 dest.writeInt(mOrder);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001965 }
1966
1967 /**
1968 * For debugging -- perform a check on the filter, return true if it passed
1969 * or false if it failed.
1970 *
1971 * {@hide}
1972 */
1973 public boolean debugCheck() {
1974 return true;
1975
1976 // This code looks for intent filters that do not specify data.
1977 /*
1978 if (mActions != null && mActions.size() == 1
1979 && mActions.contains(Intent.ACTION_MAIN)) {
1980 return true;
1981 }
1982
1983 if (mDataTypes == null && mDataSchemes == null) {
1984 Log.w("IntentFilter", "QUESTIONABLE INTENT FILTER:");
1985 dump(Log.WARN, "IntentFilter", " ");
1986 return false;
1987 }
1988
1989 return true;
1990 */
1991 }
1992
Narayan Kamathfb2afbf2016-11-24 13:22:40 +00001993 /** @hide */
1994 public IntentFilter(Parcel source) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001995 mActions = new ArrayList<String>();
1996 source.readStringList(mActions);
1997 if (source.readInt() != 0) {
1998 mCategories = new ArrayList<String>();
1999 source.readStringList(mCategories);
2000 }
2001 if (source.readInt() != 0) {
2002 mDataSchemes = new ArrayList<String>();
2003 source.readStringList(mDataSchemes);
2004 }
2005 if (source.readInt() != 0) {
2006 mDataTypes = new ArrayList<String>();
2007 source.readStringList(mDataTypes);
2008 }
2009 int N = source.readInt();
2010 if (N > 0) {
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07002011 mDataSchemeSpecificParts = new ArrayList<PatternMatcher>(N);
2012 for (int i=0; i<N; i++) {
2013 mDataSchemeSpecificParts.add(new PatternMatcher(source));
2014 }
2015 }
2016 N = source.readInt();
2017 if (N > 0) {
2018 mDataAuthorities = new ArrayList<AuthorityEntry>(N);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002019 for (int i=0; i<N; i++) {
2020 mDataAuthorities.add(new AuthorityEntry(source));
2021 }
2022 }
2023 N = source.readInt();
2024 if (N > 0) {
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -07002025 mDataPaths = new ArrayList<PatternMatcher>(N);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002026 for (int i=0; i<N; i++) {
2027 mDataPaths.add(new PatternMatcher(source));
2028 }
2029 }
2030 mPriority = source.readInt();
2031 mHasPartialTypes = source.readInt() > 0;
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08002032 setAutoVerify(source.readInt() > 0);
Todd Kennedyc05f5d12017-04-25 11:11:40 -07002033 setVisibilityToInstantApp(source.readInt());
Todd Kennedy6d418b62018-02-22 14:15:18 -08002034 mOrder = source.readInt();
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002035 }
2036
2037 private final boolean findMimeType(String type) {
2038 final ArrayList<String> t = mDataTypes;
2039
2040 if (type == null) {
2041 return false;
2042 }
2043
2044 if (t.contains(type)) {
2045 return true;
2046 }
2047
2048 // Deal with an Intent wanting to match every type in the IntentFilter.
2049 final int typeLength = type.length();
2050 if (typeLength == 3 && type.equals("*/*")) {
2051 return !t.isEmpty();
2052 }
2053
2054 // Deal with this IntentFilter wanting to match every Intent type.
2055 if (mHasPartialTypes && t.contains("*")) {
2056 return true;
2057 }
2058
2059 final int slashpos = type.indexOf('/');
2060 if (slashpos > 0) {
2061 if (mHasPartialTypes && t.contains(type.substring(0, slashpos))) {
2062 return true;
2063 }
2064 if (typeLength == slashpos+2 && type.charAt(slashpos+1) == '*') {
2065 // Need to look through all types for one that matches
2066 // our base...
Jeff Brown2c376fc2011-01-28 17:34:01 -08002067 final int numTypes = t.size();
2068 for (int i = 0; i < numTypes; i++) {
2069 final String v = t.get(i);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002070 if (type.regionMatches(0, v, 0, slashpos+1)) {
2071 return true;
2072 }
2073 }
2074 }
2075 }
2076
2077 return false;
2078 }
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08002079
2080 /**
2081 * @hide
2082 */
2083 public ArrayList<String> getHostsList() {
2084 ArrayList<String> result = new ArrayList<>();
2085 Iterator<IntentFilter.AuthorityEntry> it = authoritiesIterator();
2086 if (it != null) {
2087 while (it.hasNext()) {
2088 IntentFilter.AuthorityEntry entry = it.next();
2089 result.add(entry.getHost());
2090 }
2091 }
2092 return result;
2093 }
2094
2095 /**
2096 * @hide
2097 */
2098 public String[] getHosts() {
2099 ArrayList<String> list = getHostsList();
2100 return list.toArray(new String[list.size()]);
2101 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002102}