-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntentFilter.java
More file actions
1948 lines (1811 loc) · 71.7 KB
/
Copy pathIntentFilter.java
File metadata and controls
1948 lines (1811 loc) · 71.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2006 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.content;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.PatternMatcher;
import android.text.TextUtils;
import android.util.AndroidException;
import android.util.Log;
import android.util.Printer;
import com.android.internal.util.XmlUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Set;
/**
* Structured description of Intent values to be matched. An IntentFilter can
* match against actions, categories, and data (either via its type, scheme,
* and/or path) in an Intent. It also includes a "priority" value which is
* used to order multiple matching filters.
*
* <p>IntentFilter objects are often created in XML as part of a package's
* {@link android.R.styleable#AndroidManifest AndroidManifest.xml} file,
* using {@link android.R.styleable#AndroidManifestIntentFilter intent-filter}
* tags.
*
* <p>There are three Intent characteristics you can filter on: the
* <em>action</em>, <em>data</em>, and <em>categories</em>. For each of these
* characteristics you can provide
* multiple possible matching values (via {@link #addAction},
* {@link #addDataType}, {@link #addDataScheme}, {@link #addDataSchemeSpecificPart},
* {@link #addDataAuthority}, {@link #addDataPath}, and {@link #addCategory}, respectively).
* For actions, the field
* will not be tested if no values have been given (treating it as a wildcard);
* if no data characteristics are specified, however, then the filter will
* only match intents that contain no data.
*
* <p>The data characteristic is
* itself divided into three attributes: type, scheme, authority, and path.
* Any that are
* specified must match the contents of the Intent. If you specify a scheme
* but no type, only Intent that does not have a type (such as mailto:) will
* match; a content: URI will never match because they always have a MIME type
* that is supplied by their content provider. Specifying a type with no scheme
* has somewhat special meaning: it will match either an Intent with no URI
* field, or an Intent with a content: or file: URI. If you specify neither,
* then only an Intent with no data or type will match. To specify an authority,
* you must also specify one or more schemes that it is associated with.
* To specify a path, you also must specify both one or more authorities and
* one or more schemes it is associated with.
*
* <div class="special reference">
* <h3>Developer Guides</h3>
* <p>For information about how to create and resolve intents, read the
* <a href="{@docRoot}guide/topics/intents/intents-filters.html">Intents and Intent Filters</a>
* developer guide.</p>
* </div>
*
* <h3>Filter Rules</h3>
* <p>A match is based on the following rules. Note that
* for an IntentFilter to match an Intent, three conditions must hold:
* the <strong>action</strong> and <strong>category</strong> must match, and
* the data (both the <strong>data type</strong> and
* <strong>data scheme+authority+path</strong> if specified) must match
* (see {@link #match(ContentResolver, Intent, boolean, String)} for more details
* on how the data fields match).
*
* <p><strong>Action</strong> matches if any of the given values match the
* Intent action; if the filter specifies no actions, then it will only match
* Intents that do not contain an action.
*
* <p><strong>Data Type</strong> matches if any of the given values match the
* Intent type. The Intent
* type is determined by calling {@link Intent#resolveType}. A wildcard can be
* used for the MIME sub-type, in both the Intent and IntentFilter, so that the
* type "audio/*" will match "audio/mpeg", "audio/aiff", "audio/*", etc.
* <em>Note that MIME type matching here is <b>case sensitive</b>, unlike
* formal RFC MIME types!</em> You should thus always use lower case letters
* for your MIME types.
*
* <p><strong>Data Scheme</strong> matches if any of the given values match the
* Intent data's scheme.
* The Intent scheme is determined by calling {@link Intent#getData}
* and {@link android.net.Uri#getScheme} on that URI.
* <em>Note that scheme matching here is <b>case sensitive</b>, unlike
* formal RFC schemes!</em> You should thus always use lower case letters
* for your schemes.
*
* <p><strong>Data Scheme Specific Part</strong> matches if any of the given values match
* the Intent's data scheme specific part <em>and</em> one of the data schemes in the filter
* has matched the Intent, <em>or</em> no scheme specific parts were supplied in the filter.
* The Intent scheme specific part is determined by calling
* {@link Intent#getData} and {@link android.net.Uri#getSchemeSpecificPart} on that URI.
* <em>Note that scheme specific part matching is <b>case sensitive</b>.</em>
*
* <p><strong>Data Authority</strong> matches if any of the given values match
* the Intent's data authority <em>and</em> one of the data schemes in the filter
* has matched the Intent, <em>or</em> no authories were supplied in the filter.
* The Intent authority is determined by calling
* {@link Intent#getData} and {@link android.net.Uri#getAuthority} on that URI.
* <em>Note that authority matching here is <b>case sensitive</b>, unlike
* formal RFC host names!</em> You should thus always use lower case letters
* for your authority.
*
* <p><strong>Data Path</strong> matches if any of the given values match the
* Intent's data path <em>and</em> both a scheme and authority in the filter
* has matched against the Intent, <em>or</em> no paths were supplied in the
* filter. The Intent authority is determined by calling
* {@link Intent#getData} and {@link android.net.Uri#getPath} on that URI.
*
* <p><strong>Categories</strong> match if <em>all</em> of the categories in
* the Intent match categories given in the filter. Extra categories in the
* filter that are not in the Intent will not cause the match to fail. Note
* that unlike the action, an IntentFilter with no categories
* will only match an Intent that does not have any categories.
*/
public class IntentFilter implements Parcelable {
private static final String SGLOB_STR = "sglob";
private static final String PREFIX_STR = "prefix";
private static final String LITERAL_STR = "literal";
private static final String PATH_STR = "path";
private static final String PORT_STR = "port";
private static final String HOST_STR = "host";
private static final String AUTH_STR = "auth";
private static final String SSP_STR = "ssp";
private static final String SCHEME_STR = "scheme";
private static final String TYPE_STR = "type";
private static final String CAT_STR = "cat";
private static final String NAME_STR = "name";
private static final String ACTION_STR = "action";
private static final String AUTO_VERIFY_STR = "autoVerify";
/**
* The filter {@link #setPriority} value at which system high-priority
* receivers are placed; that is, receivers that should execute before
* application code. Applications should never use filters with this or
* higher priorities.
*
* @see #setPriority
*/
public static final int SYSTEM_HIGH_PRIORITY = 1000;
/**
* The filter {@link #setPriority} value at which system low-priority
* receivers are placed; that is, receivers that should execute after
* application code. Applications should never use filters with this or
* lower priorities.
*
* @see #setPriority
*/
public static final int SYSTEM_LOW_PRIORITY = -1000;
/**
* The part of a match constant that describes the category of match
* that occurred. May be either {@link #MATCH_CATEGORY_EMPTY},
* {@link #MATCH_CATEGORY_SCHEME}, {@link #MATCH_CATEGORY_SCHEME_SPECIFIC_PART},
* {@link #MATCH_CATEGORY_HOST}, {@link #MATCH_CATEGORY_PORT},
* {@link #MATCH_CATEGORY_PATH}, or {@link #MATCH_CATEGORY_TYPE}. Higher
* values indicate a better match.
*/
public static final int MATCH_CATEGORY_MASK = 0xfff0000;
/**
* The part of a match constant that applies a quality adjustment to the
* basic category of match. The value {@link #MATCH_ADJUSTMENT_NORMAL}
* is no adjustment; higher numbers than that improve the quality, while
* lower numbers reduce it.
*/
public static final int MATCH_ADJUSTMENT_MASK = 0x000ffff;
/**
* Quality adjustment applied to the category of match that signifies
* the default, base value; higher numbers improve the quality while
* lower numbers reduce it.
*/
public static final int MATCH_ADJUSTMENT_NORMAL = 0x8000;
/**
* The filter matched an intent that had no data specified.
*/
public static final int MATCH_CATEGORY_EMPTY = 0x0100000;
/**
* The filter matched an intent with the same data URI scheme.
*/
public static final int MATCH_CATEGORY_SCHEME = 0x0200000;
/**
* The filter matched an intent with the same data URI scheme and
* authority host.
*/
public static final int MATCH_CATEGORY_HOST = 0x0300000;
/**
* The filter matched an intent with the same data URI scheme and
* authority host and port.
*/
public static final int MATCH_CATEGORY_PORT = 0x0400000;
/**
* The filter matched an intent with the same data URI scheme,
* authority, and path.
*/
public static final int MATCH_CATEGORY_PATH = 0x0500000;
/**
* The filter matched an intent with the same data URI scheme and
* scheme specific part.
*/
public static final int MATCH_CATEGORY_SCHEME_SPECIFIC_PART = 0x0580000;
/**
* The filter matched an intent with the same data MIME type.
*/
public static final int MATCH_CATEGORY_TYPE = 0x0600000;
/**
* The filter didn't match due to different MIME types.
*/
public static final int NO_MATCH_TYPE = -1;
/**
* The filter didn't match due to different data URIs.
*/
public static final int NO_MATCH_DATA = -2;
/**
* The filter didn't match due to different actions.
*/
public static final int NO_MATCH_ACTION = -3;
/**
* The filter didn't match because it required one or more categories
* that were not in the Intent.
*/
public static final int NO_MATCH_CATEGORY = -4;
/**
* HTTP scheme.
*
* @see #addDataScheme(String)
* @hide
*/
public static final String SCHEME_HTTP = "http";
/**
* HTTPS scheme.
*
* @see #addDataScheme(String)
* @hide
*/
public static final String SCHEME_HTTPS = "https";
private int mPriority;
private final ArrayList<String> mActions;
private ArrayList<String> mCategories = null;
private ArrayList<String> mDataSchemes = null;
private ArrayList<PatternMatcher> mDataSchemeSpecificParts = null;
private ArrayList<AuthorityEntry> mDataAuthorities = null;
private ArrayList<PatternMatcher> mDataPaths = null;
private ArrayList<String> mDataTypes = null;
private boolean mHasPartialTypes = false;
private static final int STATE_VERIFY_AUTO = 0x00000001;
private static final int STATE_NEED_VERIFY = 0x00000010;
private static final int STATE_NEED_VERIFY_CHECKED = 0x00000100;
private static final int STATE_VERIFIED = 0x00001000;
private int mVerifyState;
// These functions are the start of more optimized code for managing
// the string sets... not yet implemented.
private static int findStringInSet(String[] set, String string,
int[] lengths, int lenPos) {
if (set == null) return -1;
final int N = lengths[lenPos];
for (int i=0; i<N; i++) {
if (set[i].equals(string)) return i;
}
return -1;
}
private static String[] addStringToSet(String[] set, String string,
int[] lengths, int lenPos) {
if (findStringInSet(set, string, lengths, lenPos) >= 0) return set;
if (set == null) {
set = new String[2];
set[0] = string;
lengths[lenPos] = 1;
return set;
}
final int N = lengths[lenPos];
if (N < set.length) {
set[N] = string;
lengths[lenPos] = N+1;
return set;
}
String[] newSet = new String[(N*3)/2 + 2];
System.arraycopy(set, 0, newSet, 0, N);
set = newSet;
set[N] = string;
lengths[lenPos] = N+1;
return set;
}
private static String[] removeStringFromSet(String[] set, String string,
int[] lengths, int lenPos) {
int pos = findStringInSet(set, string, lengths, lenPos);
if (pos < 0) return set;
final int N = lengths[lenPos];
if (N > (set.length/4)) {
int copyLen = N-(pos+1);
if (copyLen > 0) {
System.arraycopy(set, pos+1, set, pos, copyLen);
}
set[N-1] = null;
lengths[lenPos] = N-1;
return set;
}
String[] newSet = new String[set.length/3];
if (pos > 0) System.arraycopy(set, 0, newSet, 0, pos);
if ((pos+1) < N) System.arraycopy(set, pos+1, newSet, pos, N-(pos+1));
return newSet;
}
/**
* This exception is thrown when a given MIME type does not have a valid
* syntax.
*/
public static class MalformedMimeTypeException extends AndroidException {
public MalformedMimeTypeException() {
}
public MalformedMimeTypeException(String name) {
super(name);
}
}
/**
* Create a new IntentFilter instance with a specified action and MIME
* type, where you know the MIME type is correctly formatted. This catches
* the {@link MalformedMimeTypeException} exception that the constructor
* can call and turns it into a runtime exception.
*
* @param action The action to match, i.e. Intent.ACTION_VIEW.
* @param dataType The type to match, i.e. "vnd.android.cursor.dir/person".
*
* @return A new IntentFilter for the given action and type.
*
* @see #IntentFilter(String, String)
*/
public static IntentFilter create(String action, String dataType) {
try {
return new IntentFilter(action, dataType);
} catch (MalformedMimeTypeException e) {
throw new RuntimeException("Bad MIME type", e);
}
}
/**
* New empty IntentFilter.
*/
public IntentFilter() {
mPriority = 0;
mActions = new ArrayList<String>();
}
/**
* New IntentFilter that matches a single action with no data. If
* no data characteristics are subsequently specified, then the
* filter will only match intents that contain no data.
*
* @param action The action to match, i.e. Intent.ACTION_MAIN.
*/
public IntentFilter(String action) {
mPriority = 0;
mActions = new ArrayList<String>();
addAction(action);
}
/**
* New IntentFilter that matches a single action and data type.
*
* <p><em>Note: MIME type matching in the Android framework is
* case-sensitive, unlike formal RFC MIME types. As a result,
* you should always write your MIME types with lower case letters,
* and any MIME types you receive from outside of Android should be
* converted to lower case before supplying them here.</em></p>
*
* <p>Throws {@link MalformedMimeTypeException} if the given MIME type is
* not syntactically correct.
*
* @param action The action to match, i.e. Intent.ACTION_VIEW.
* @param dataType The type to match, i.e. "vnd.android.cursor.dir/person".
*
*/
public IntentFilter(String action, String dataType)
throws MalformedMimeTypeException {
mPriority = 0;
mActions = new ArrayList<String>();
addAction(action);
addDataType(dataType);
}
/**
* New IntentFilter containing a copy of an existing filter.
*
* @param o The original filter to copy.
*/
public IntentFilter(IntentFilter o) {
mPriority = o.mPriority;
mActions = new ArrayList<String>(o.mActions);
if (o.mCategories != null) {
mCategories = new ArrayList<String>(o.mCategories);
}
if (o.mDataTypes != null) {
mDataTypes = new ArrayList<String>(o.mDataTypes);
}
if (o.mDataSchemes != null) {
mDataSchemes = new ArrayList<String>(o.mDataSchemes);
}
if (o.mDataSchemeSpecificParts != null) {
mDataSchemeSpecificParts = new ArrayList<PatternMatcher>(o.mDataSchemeSpecificParts);
}
if (o.mDataAuthorities != null) {
mDataAuthorities = new ArrayList<AuthorityEntry>(o.mDataAuthorities);
}
if (o.mDataPaths != null) {
mDataPaths = new ArrayList<PatternMatcher>(o.mDataPaths);
}
mHasPartialTypes = o.mHasPartialTypes;
mVerifyState = o.mVerifyState;
}
/**
* Modify priority of this filter. The default priority is 0. Positive
* values will be before the default, lower values will be after it.
* Applications must use a value that is larger than
* {@link #SYSTEM_LOW_PRIORITY} and smaller than
* {@link #SYSTEM_HIGH_PRIORITY} .
*
* @param priority The new priority value.
*
* @see #getPriority
* @see #SYSTEM_LOW_PRIORITY
* @see #SYSTEM_HIGH_PRIORITY
*/
public final void setPriority(int priority) {
mPriority = priority;
}
/**
* Return the priority of this filter.
*
* @return The priority of the filter.
*
* @see #setPriority
*/
public final int getPriority() {
return mPriority;
}
/**
* Set whether this filter will needs to be automatically verified against its data URIs or not.
* The default is false.
*
* The verification would need to happen only and only if the Intent action is
* {@link android.content.Intent#ACTION_VIEW} and the Intent category is
* {@link android.content.Intent#CATEGORY_BROWSABLE} and the Intent data scheme
* is "http" or "https".
*
* True means that the filter will need to use its data URIs to be verified.
*
* @param autoVerify The new autoVerify value.
*
* @see #getAutoVerify()
* @see #addAction(String)
* @see #getAction(int)
* @see #addCategory(String)
* @see #getCategory(int)
* @see #addDataScheme(String)
* @see #getDataScheme(int)
*
* @hide
*/
public final void setAutoVerify(boolean autoVerify) {
mVerifyState &= ~STATE_VERIFY_AUTO;
if (autoVerify) mVerifyState |= STATE_VERIFY_AUTO;
}
/**
* Return if this filter will needs to be automatically verified again its data URIs or not.
*
* @return True if the filter will needs to be automatically verified. False otherwise.
*
* @see #setAutoVerify(boolean)
*
* @hide
*/
public final boolean getAutoVerify() {
return ((mVerifyState & STATE_VERIFY_AUTO) == 1);
}
/**
* Return if this filter handle all HTTP or HTTPS data URI or not. This is the
* core check for whether a given activity qualifies as a "browser".
*
* @return True if the filter handle all HTTP or HTTPS data URI. False otherwise.
*
* This will check if:
*
* - either the Intent category is {@link android.content.Intent#CATEGORY_APP_BROWSER}
* - either the Intent action is {@link android.content.Intent#ACTION_VIEW} and
* the Intent category is {@link android.content.Intent#CATEGORY_BROWSABLE} and the Intent
* data scheme is "http" or "https" and that there is no specific host defined.
*
* @hide
*/
public final boolean handleAllWebDataURI() {
return hasCategory(Intent.CATEGORY_APP_BROWSER) ||
(handlesWebUris(false) && countDataAuthorities() == 0);
}
/**
* Return if this filter handles HTTP or HTTPS data URIs.
*
* @return True if the filter handles ACTION_VIEW/CATEGORY_BROWSABLE,
* has at least one HTTP or HTTPS data URI pattern defined, and optionally
* does not define any non-http/https data URI patterns.
*
* This will check if if the Intent action is {@link android.content.Intent#ACTION_VIEW} and
* the Intent category is {@link android.content.Intent#CATEGORY_BROWSABLE} and the Intent
* data scheme is "http" or "https".
*
* @param onlyWebSchemes When true, requires that the intent filter declare
* that it handles *only* http: or https: schemes. This is a requirement for
* the intent filter's domain linkage being verifiable.
* @hide
*/
public final boolean handlesWebUris(boolean onlyWebSchemes) {
// Require ACTION_VIEW, CATEGORY_BROWSEABLE, and at least one scheme
if (!hasAction(Intent.ACTION_VIEW)
|| !hasCategory(Intent.CATEGORY_BROWSABLE)
|| mDataSchemes == null
|| mDataSchemes.size() == 0) {
return false;
}
// Now allow only the schemes "http" and "https"
final int N = mDataSchemes.size();
for (int i = 0; i < N; i++) {
final String scheme = mDataSchemes.get(i);
final boolean isWebScheme =
SCHEME_HTTP.equals(scheme) || SCHEME_HTTPS.equals(scheme);
if (onlyWebSchemes) {
// If we're specifically trying to ensure that there are no non-web schemes
// declared in this filter, then if we ever see a non-http/https scheme then
// we know it's a failure.
if (!isWebScheme) {
return false;
}
} else {
// If we see any http/https scheme declaration in this case then the
// filter matches what we're looking for.
if (isWebScheme) {
return true;
}
}
}
// We get here if:
// 1) onlyWebSchemes and no non-web schemes were found, i.e success; or
// 2) !onlyWebSchemes and no http/https schemes were found, i.e. failure.
return onlyWebSchemes;
}
/**
* Return if this filter needs to be automatically verified again its data URIs or not.
*
* @return True if the filter needs to be automatically verified. False otherwise.
*
* This will check if if the Intent action is {@link android.content.Intent#ACTION_VIEW} and
* the Intent category is {@link android.content.Intent#CATEGORY_BROWSABLE} and the Intent
* data scheme is "http" or "https".
*
* @see #setAutoVerify(boolean)
*
* @hide
*/
public final boolean needsVerification() {
return getAutoVerify() && handlesWebUris(true);
}
/**
* Return if this filter has been verified
*
* @return true if the filter has been verified or if autoVerify is false.
*
* @hide
*/
public final boolean isVerified() {
if ((mVerifyState & STATE_NEED_VERIFY_CHECKED) == STATE_NEED_VERIFY_CHECKED) {
return ((mVerifyState & STATE_NEED_VERIFY) == STATE_NEED_VERIFY);
}
return false;
}
/**
* Set if this filter has been verified
*
* @param verified true if this filter has been verified. False otherwise.
*
* @hide
*/
public void setVerified(boolean verified) {
mVerifyState |= STATE_NEED_VERIFY_CHECKED;
mVerifyState &= ~STATE_VERIFIED;
if (verified) mVerifyState |= STATE_VERIFIED;
}
/**
* Add a new Intent action to match against. If any actions are included
* in the filter, then an Intent's action must be one of those values for
* it to match. If no actions are included, the Intent action is ignored.
*
* @param action Name of the action to match, i.e. Intent.ACTION_VIEW.
*/
public final void addAction(String action) {
if (!mActions.contains(action)) {
mActions.add(action.intern());
}
}
/**
* Return the number of actions in the filter.
*/
public final int countActions() {
return mActions.size();
}
/**
* Return an action in the filter.
*/
public final String getAction(int index) {
return mActions.get(index);
}
/**
* Is the given action included in the filter? Note that if the filter
* does not include any actions, false will <em>always</em> be returned.
*
* @param action The action to look for.
*
* @return True if the action is explicitly mentioned in the filter.
*/
public final boolean hasAction(String action) {
return action != null && mActions.contains(action);
}
/**
* Match this filter against an Intent's action. If the filter does not
* specify any actions, the match will always fail.
*
* @param action The desired action to look for.
*
* @return True if the action is listed in the filter.
*/
public final boolean matchAction(String action) {
return hasAction(action);
}
/**
* Return an iterator over the filter's actions. If there are no actions,
* returns null.
*/
public final Iterator<String> actionsIterator() {
return mActions != null ? mActions.iterator() : null;
}
/**
* Add a new Intent data type to match against. If any types are
* included in the filter, then an Intent's data must be <em>either</em>
* one of these types <em>or</em> a matching scheme. If no data types
* are included, then an Intent will only match if it specifies no data.
*
* <p><em>Note: MIME type matching in the Android framework is
* case-sensitive, unlike formal RFC MIME types. As a result,
* you should always write your MIME types with lower case letters,
* and any MIME types you receive from outside of Android should be
* converted to lower case before supplying them here.</em></p>
*
* <p>Throws {@link MalformedMimeTypeException} if the given MIME type is
* not syntactically correct.
*
* @param type Name of the data type to match, i.e. "vnd.android.cursor.dir/person".
*
* @see #matchData
*/
public final void addDataType(String type)
throws MalformedMimeTypeException {
final int slashpos = type.indexOf('/');
final int typelen = type.length();
if (slashpos > 0 && typelen >= slashpos+2) {
if (mDataTypes == null) mDataTypes = new ArrayList<String>();
if (typelen == slashpos+2 && type.charAt(slashpos+1) == '*') {
String str = type.substring(0, slashpos);
if (!mDataTypes.contains(str)) {
mDataTypes.add(str.intern());
}
mHasPartialTypes = true;
} else {
if (!mDataTypes.contains(type)) {
mDataTypes.add(type.intern());
}
}
return;
}
throw new MalformedMimeTypeException(type);
}
/**
* Is the given data type included in the filter? Note that if the filter
* does not include any type, false will <em>always</em> be returned.
*
* @param type The data type to look for.
*
* @return True if the type is explicitly mentioned in the filter.
*/
public final boolean hasDataType(String type) {
return mDataTypes != null && findMimeType(type);
}
/** @hide */
public final boolean hasExactDataType(String type) {
return mDataTypes != null && mDataTypes.contains(type);
}
/**
* Return the number of data types in the filter.
*/
public final int countDataTypes() {
return mDataTypes != null ? mDataTypes.size() : 0;
}
/**
* Return a data type in the filter.
*/
public final String getDataType(int index) {
return mDataTypes.get(index);
}
/**
* Return an iterator over the filter's data types.
*/
public final Iterator<String> typesIterator() {
return mDataTypes != null ? mDataTypes.iterator() : null;
}
/**
* Add a new Intent data scheme to match against. If any schemes are
* included in the filter, then an Intent's data must be <em>either</em>
* one of these schemes <em>or</em> a matching data type. If no schemes
* are included, then an Intent will match only if it includes no data.
*
* <p><em>Note: scheme matching in the Android framework is
* case-sensitive, unlike formal RFC schemes. As a result,
* you should always write your schemes with lower case letters,
* and any schemes you receive from outside of Android should be
* converted to lower case before supplying them here.</em></p>
*
* @param scheme Name of the scheme to match, i.e. "http".
*
* @see #matchData
*/
public final void addDataScheme(String scheme) {
if (mDataSchemes == null) mDataSchemes = new ArrayList<String>();
if (!mDataSchemes.contains(scheme)) {
mDataSchemes.add(scheme.intern());
}
}
/**
* Return the number of data schemes in the filter.
*/
public final int countDataSchemes() {
return mDataSchemes != null ? mDataSchemes.size() : 0;
}
/**
* Return a data scheme in the filter.
*/
public final String getDataScheme(int index) {
return mDataSchemes.get(index);
}
/**
* Is the given data scheme included in the filter? Note that if the
* filter does not include any scheme, false will <em>always</em> be
* returned.
*
* @param scheme The data scheme to look for.
*
* @return True if the scheme is explicitly mentioned in the filter.
*/
public final boolean hasDataScheme(String scheme) {
return mDataSchemes != null && mDataSchemes.contains(scheme);
}
/**
* Return an iterator over the filter's data schemes.
*/
public final Iterator<String> schemesIterator() {
return mDataSchemes != null ? mDataSchemes.iterator() : null;
}
/**
* This is an entry for a single authority in the Iterator returned by
* {@link #authoritiesIterator()}.
*/
public final static class AuthorityEntry {
private final String mOrigHost;
private final String mHost;
private final boolean mWild;
private final int mPort;
public AuthorityEntry(String host, String port) {
mOrigHost = host;
mWild = host.length() > 0 && host.charAt(0) == '*';
mHost = mWild ? host.substring(1).intern() : host;
mPort = port != null ? Integer.parseInt(port) : -1;
}
AuthorityEntry(Parcel src) {
mOrigHost = src.readString();
mHost = src.readString();
mWild = src.readInt() != 0;
mPort = src.readInt();
}
void writeToParcel(Parcel dest) {
dest.writeString(mOrigHost);
dest.writeString(mHost);
dest.writeInt(mWild ? 1 : 0);
dest.writeInt(mPort);
}
public String getHost() {
return mOrigHost;
}
public int getPort() {
return mPort;
}
/** @hide */
public boolean match(AuthorityEntry other) {
if (mWild != other.mWild) {
return false;
}
if (!mHost.equals(other.mHost)) {
return false;
}
if (mPort != other.mPort) {
return false;
}
return true;
}
/**
* Determine whether this AuthorityEntry matches the given data Uri.
* <em>Note that this comparison is case-sensitive, unlike formal
* RFC host names. You thus should always normalize to lower-case.</em>
*
* @param data The Uri to match.
* @return Returns either {@link IntentFilter#NO_MATCH_DATA},
* {@link IntentFilter#MATCH_CATEGORY_PORT}, or
* {@link IntentFilter#MATCH_CATEGORY_HOST}.
*/
public int match(Uri data) {
String host = data.getHost();
if (host == null) {
return NO_MATCH_DATA;
}
if (false) Log.v("IntentFilter",
"Match host " + host + ": " + mHost);
if (mWild) {
if (host.length() < mHost.length()) {
return NO_MATCH_DATA;
}
host = host.substring(host.length()-mHost.length());
}
if (host.compareToIgnoreCase(mHost) != 0) {
return NO_MATCH_DATA;
}
if (mPort >= 0) {
if (mPort != data.getPort()) {
return NO_MATCH_DATA;
}
return MATCH_CATEGORY_PORT;
}
return MATCH_CATEGORY_HOST;
}
};
/**
* Add a new Intent data "scheme specific part" to match against. The filter must
* include one or more schemes (via {@link #addDataScheme}) for the
* scheme specific part to be considered. If any scheme specific parts are
* included in the filter, then an Intent's data must match one of
* them. If no scheme specific parts are included, then only the scheme must match.
*
* <p>The "scheme specific part" that this matches against is the string returned
* by {@link android.net.Uri#getSchemeSpecificPart() Uri.getSchemeSpecificPart}.
* For Uris that contain a path, this kind of matching is not generally of interest,
* since {@link #addDataAuthority(String, String)} and
* {@link #addDataPath(String, int)} can provide a better mechanism for matching
* them. However, for Uris that do not contain a path, the authority and path
* are empty, so this is the only way to match against the non-scheme part.</p>
*
* @param ssp Either a raw string that must exactly match the scheme specific part
* path, or a simple pattern, depending on <var>type</var>.
* @param type Determines how <var>ssp</var> will be compared to
* determine a match: either {@link PatternMatcher#PATTERN_LITERAL},
* {@link PatternMatcher#PATTERN_PREFIX}, or
* {@link PatternMatcher#PATTERN_SIMPLE_GLOB}.
*
* @see #matchData
* @see #addDataScheme
*/
public final void addDataSchemeSpecificPart(String ssp, int type) {
addDataSchemeSpecificPart(new PatternMatcher(ssp, type));
}
/** @hide */
public final void addDataSchemeSpecificPart(PatternMatcher ssp) {
if (mDataSchemeSpecificParts == null) {
mDataSchemeSpecificParts = new ArrayList<PatternMatcher>();
}
mDataSchemeSpecificParts.add(ssp);
}
/**
* Return the number of data scheme specific parts in the filter.
*/
public final int countDataSchemeSpecificParts() {
return mDataSchemeSpecificParts != null ? mDataSchemeSpecificParts.size() : 0;
}
/**
* Return a data scheme specific part in the filter.
*/
public final PatternMatcher getDataSchemeSpecificPart(int index) {
return mDataSchemeSpecificParts.get(index);
}
/**
* Is the given data scheme specific part included in the filter? Note that if the
* filter does not include any scheme specific parts, false will <em>always</em> be
* returned.
*
* @param data The scheme specific part that is being looked for.
*
* @return Returns true if the data string matches a scheme specific part listed in the
* filter.
*/
public final boolean hasDataSchemeSpecificPart(String data) {
if (mDataSchemeSpecificParts == null) {
return false;
}
final int numDataSchemeSpecificParts = mDataSchemeSpecificParts.size();
for (int i = 0; i < numDataSchemeSpecificParts; i++) {
final PatternMatcher pe = mDataSchemeSpecificParts.get(i);
if (pe.match(data)) {
return true;
}
}
return false;
}
/** @hide */
public final boolean hasDataSchemeSpecificPart(PatternMatcher ssp) {
if (mDataSchemeSpecificParts == null) {
return false;