The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server; |
| 18 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 19 | import java.io.PrintWriter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import java.util.ArrayList; |
| 21 | import java.util.Collections; |
| 22 | import java.util.Comparator; |
| 23 | import java.util.HashMap; |
| 24 | import java.util.HashSet; |
| 25 | import java.util.Iterator; |
| 26 | import java.util.List; |
| 27 | import java.util.Map; |
| 28 | import java.util.Set; |
| 29 | |
Jeff Brown | 2c376fc | 2011-01-28 17:34:01 -0800 | [diff] [blame] | 30 | import android.net.Uri; |
| 31 | import android.util.FastImmutableArraySet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.util.Log; |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 33 | import android.util.PrintWriterPrinter; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 34 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import android.util.LogPrinter; |
| 36 | import android.util.Printer; |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 37 | import android.util.StringBuilderPrinter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import android.content.Intent; |
| 40 | import android.content.IntentFilter; |
| 41 | |
| 42 | /** |
| 43 | * {@hide} |
| 44 | */ |
Dianne Hackborn | 6c418d5 | 2011-06-29 14:05:33 -0700 | [diff] [blame] | 45 | public abstract class IntentResolver<F extends IntentFilter, R extends Object> { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | final private static String TAG = "IntentResolver"; |
| 47 | final private static boolean DEBUG = false; |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 48 | final private static boolean localLOGV = DEBUG || false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | |
| 50 | public void addFilter(F f) { |
| 51 | if (localLOGV) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 52 | Slog.v(TAG, "Adding filter: " + f); |
| 53 | f.dump(new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM), " "); |
| 54 | Slog.v(TAG, " Building Lookup Maps:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | mFilters.add(f); |
| 58 | int numS = register_intent_filter(f, f.schemesIterator(), |
| 59 | mSchemeToFilter, " Scheme: "); |
| 60 | int numT = register_mime_types(f, " Type: "); |
| 61 | if (numS == 0 && numT == 0) { |
| 62 | register_intent_filter(f, f.actionsIterator(), |
| 63 | mActionToFilter, " Action: "); |
| 64 | } |
| 65 | if (numT != 0) { |
| 66 | register_intent_filter(f, f.actionsIterator(), |
| 67 | mTypedActionToFilter, " TypedAction: "); |
| 68 | } |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 69 | |
| 70 | mOldResolver.addFilter(f); |
| 71 | verifyDataStructures(f); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | public void removeFilter(F f) { |
| 75 | removeFilterInternal(f); |
| 76 | mFilters.remove(f); |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 77 | |
| 78 | mOldResolver.removeFilter(f); |
| 79 | verifyDataStructures(f); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | void removeFilterInternal(F f) { |
| 83 | if (localLOGV) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 84 | Slog.v(TAG, "Removing filter: " + f); |
| 85 | f.dump(new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM), " "); |
| 86 | Slog.v(TAG, " Cleaning Lookup Maps:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | int numS = unregister_intent_filter(f, f.schemesIterator(), |
| 90 | mSchemeToFilter, " Scheme: "); |
| 91 | int numT = unregister_mime_types(f, " Type: "); |
| 92 | if (numS == 0 && numT == 0) { |
| 93 | unregister_intent_filter(f, f.actionsIterator(), |
| 94 | mActionToFilter, " Action: "); |
| 95 | } |
| 96 | if (numT != 0) { |
| 97 | unregister_intent_filter(f, f.actionsIterator(), |
| 98 | mTypedActionToFilter, " TypedAction: "); |
| 99 | } |
| 100 | } |
| 101 | |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 102 | boolean dumpMap(PrintWriter out, String titlePrefix, String title, |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 103 | String prefix, Map<String, F[]> map, String packageName, |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 104 | boolean printFilter) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | String eprefix = prefix + " "; |
| 106 | String fprefix = prefix + " "; |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 107 | boolean printedSomething = false; |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 108 | Printer printer = null; |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 109 | for (Map.Entry<String, F[]> e : map.entrySet()) { |
| 110 | F[] a = e.getValue(); |
| 111 | final int N = a.length; |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 112 | boolean printedHeader = false; |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 113 | F filter; |
| 114 | for (int i=0; i<N && (filter=a[i]) != null; i++) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 115 | if (packageName != null && !packageName.equals(packageForFilter(filter))) { |
| 116 | continue; |
| 117 | } |
| 118 | if (title != null) { |
| 119 | out.print(titlePrefix); out.println(title); |
| 120 | title = null; |
| 121 | } |
| 122 | if (!printedHeader) { |
| 123 | out.print(eprefix); out.print(e.getKey()); out.println(":"); |
| 124 | printedHeader = true; |
| 125 | } |
| 126 | printedSomething = true; |
| 127 | dumpFilter(out, fprefix, filter); |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 128 | if (printFilter) { |
| 129 | if (printer == null) { |
| 130 | printer = new PrintWriterPrinter(out); |
| 131 | } |
| 132 | filter.dump(printer, fprefix + " "); |
| 133 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | } |
| 135 | } |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 136 | return printedSomething; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | } |
| 138 | |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 139 | public boolean dump(PrintWriter out, String title, String prefix, String packageName, |
| 140 | boolean printFilter) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 141 | String innerPrefix = prefix + " "; |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 142 | String sepPrefix = "\n" + prefix; |
| 143 | String curPrefix = title + "\n" + prefix; |
| 144 | if (dumpMap(out, curPrefix, "Full MIME Types:", innerPrefix, |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 145 | mTypeToFilter, packageName, printFilter)) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 146 | curPrefix = sepPrefix; |
| 147 | } |
| 148 | if (dumpMap(out, curPrefix, "Base MIME Types:", innerPrefix, |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 149 | mBaseTypeToFilter, packageName, printFilter)) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 150 | curPrefix = sepPrefix; |
| 151 | } |
| 152 | if (dumpMap(out, curPrefix, "Wild MIME Types:", innerPrefix, |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 153 | mWildTypeToFilter, packageName, printFilter)) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 154 | curPrefix = sepPrefix; |
| 155 | } |
| 156 | if (dumpMap(out, curPrefix, "Schemes:", innerPrefix, |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 157 | mSchemeToFilter, packageName, printFilter)) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 158 | curPrefix = sepPrefix; |
| 159 | } |
| 160 | if (dumpMap(out, curPrefix, "Non-Data Actions:", innerPrefix, |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 161 | mActionToFilter, packageName, printFilter)) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 162 | curPrefix = sepPrefix; |
| 163 | } |
| 164 | if (dumpMap(out, curPrefix, "MIME Typed Actions:", innerPrefix, |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 165 | mTypedActionToFilter, packageName, printFilter)) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 166 | curPrefix = sepPrefix; |
| 167 | } |
| 168 | return curPrefix == sepPrefix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | private class IteratorWrapper implements Iterator<F> { |
| 172 | private final Iterator<F> mI; |
| 173 | private F mCur; |
| 174 | |
| 175 | IteratorWrapper(Iterator<F> it) { |
| 176 | mI = it; |
| 177 | } |
| 178 | |
| 179 | public boolean hasNext() { |
| 180 | return mI.hasNext(); |
| 181 | } |
| 182 | |
| 183 | public F next() { |
| 184 | return (mCur = mI.next()); |
| 185 | } |
| 186 | |
| 187 | public void remove() { |
| 188 | if (mCur != null) { |
| 189 | removeFilterInternal(mCur); |
| 190 | } |
| 191 | mI.remove(); |
| 192 | } |
| 193 | |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Returns an iterator allowing filters to be removed. |
| 198 | */ |
| 199 | public Iterator<F> filterIterator() { |
| 200 | return new IteratorWrapper(mFilters.iterator()); |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * Returns a read-only set of the filters. |
| 205 | */ |
| 206 | public Set<F> filterSet() { |
| 207 | return Collections.unmodifiableSet(mFilters); |
| 208 | } |
| 209 | |
Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 210 | public List<R> queryIntentFromList(Intent intent, String resolvedType, |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 211 | boolean defaultOnly, ArrayList<F[]> listCut, int userId) { |
Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 212 | ArrayList<R> resultList = new ArrayList<R>(); |
| 213 | |
| 214 | final boolean debug = localLOGV || |
| 215 | ((intent.getFlags() & Intent.FLAG_DEBUG_LOG_RESOLUTION) != 0); |
| 216 | |
Jeff Brown | 2c376fc | 2011-01-28 17:34:01 -0800 | [diff] [blame] | 217 | FastImmutableArraySet<String> categories = getFastIntentCategories(intent); |
Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 218 | final String scheme = intent.getScheme(); |
| 219 | int N = listCut.size(); |
| 220 | for (int i = 0; i < N; ++i) { |
Jeff Brown | 2c376fc | 2011-01-28 17:34:01 -0800 | [diff] [blame] | 221 | buildResolveList(intent, categories, debug, defaultOnly, |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 222 | resolvedType, scheme, listCut.get(i), resultList, userId); |
Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 223 | } |
| 224 | sortResults(resultList); |
| 225 | return resultList; |
| 226 | } |
| 227 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 228 | public List<R> queryIntent(Intent intent, String resolvedType, boolean defaultOnly, |
| 229 | int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | String scheme = intent.getScheme(); |
| 231 | |
| 232 | ArrayList<R> finalList = new ArrayList<R>(); |
| 233 | |
| 234 | final boolean debug = localLOGV || |
| 235 | ((intent.getFlags() & Intent.FLAG_DEBUG_LOG_RESOLUTION) != 0); |
| 236 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 237 | if (debug) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | TAG, "Resolving type " + resolvedType + " scheme " + scheme |
| 239 | + " of intent " + intent); |
| 240 | |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 241 | F[] firstTypeCut = null; |
| 242 | F[] secondTypeCut = null; |
| 243 | F[] thirdTypeCut = null; |
| 244 | F[] schemeCut = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 245 | |
| 246 | // If the intent includes a MIME type, then we want to collect all of |
| 247 | // the filters that match that MIME type. |
| 248 | if (resolvedType != null) { |
| 249 | int slashpos = resolvedType.indexOf('/'); |
| 250 | if (slashpos > 0) { |
| 251 | final String baseType = resolvedType.substring(0, slashpos); |
| 252 | if (!baseType.equals("*")) { |
| 253 | if (resolvedType.length() != slashpos+2 |
| 254 | || resolvedType.charAt(slashpos+1) != '*') { |
| 255 | // Not a wild card, so we can just look for all filters that |
| 256 | // completely match or wildcards whose base type matches. |
| 257 | firstTypeCut = mTypeToFilter.get(resolvedType); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 258 | if (debug) Slog.v(TAG, "First type cut: " + firstTypeCut); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | secondTypeCut = mWildTypeToFilter.get(baseType); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 260 | if (debug) Slog.v(TAG, "Second type cut: " + secondTypeCut); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | } else { |
| 262 | // We can match anything with our base type. |
| 263 | firstTypeCut = mBaseTypeToFilter.get(baseType); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 264 | if (debug) Slog.v(TAG, "First type cut: " + firstTypeCut); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 265 | secondTypeCut = mWildTypeToFilter.get(baseType); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 266 | if (debug) Slog.v(TAG, "Second type cut: " + secondTypeCut); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 267 | } |
| 268 | // Any */* types always apply, but we only need to do this |
| 269 | // if the intent type was not already */*. |
| 270 | thirdTypeCut = mWildTypeToFilter.get("*"); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 271 | if (debug) Slog.v(TAG, "Third type cut: " + thirdTypeCut); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | } else if (intent.getAction() != null) { |
| 273 | // The intent specified any type ({@literal *}/*). This |
| 274 | // can be a whole heck of a lot of things, so as a first |
| 275 | // cut let's use the action instead. |
| 276 | firstTypeCut = mTypedActionToFilter.get(intent.getAction()); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 277 | if (debug) Slog.v(TAG, "Typed Action list: " + firstTypeCut); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 278 | } |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | // If the intent includes a data URI, then we want to collect all of |
| 283 | // the filters that match its scheme (we will further refine matches |
| 284 | // on the authority and path by directly matching each resulting filter). |
| 285 | if (scheme != null) { |
| 286 | schemeCut = mSchemeToFilter.get(scheme); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 287 | if (debug) Slog.v(TAG, "Scheme list: " + schemeCut); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | // If the intent does not specify any data -- either a MIME type or |
| 291 | // a URI -- then we will only be looking for matches against empty |
| 292 | // data. |
| 293 | if (resolvedType == null && scheme == null && intent.getAction() != null) { |
| 294 | firstTypeCut = mActionToFilter.get(intent.getAction()); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 295 | if (debug) Slog.v(TAG, "Action list: " + firstTypeCut); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 296 | } |
| 297 | |
Jeff Brown | 2c376fc | 2011-01-28 17:34:01 -0800 | [diff] [blame] | 298 | FastImmutableArraySet<String> categories = getFastIntentCategories(intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 299 | if (firstTypeCut != null) { |
Jeff Brown | 2c376fc | 2011-01-28 17:34:01 -0800 | [diff] [blame] | 300 | buildResolveList(intent, categories, debug, defaultOnly, |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 301 | resolvedType, scheme, firstTypeCut, finalList, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 302 | } |
| 303 | if (secondTypeCut != null) { |
Jeff Brown | 2c376fc | 2011-01-28 17:34:01 -0800 | [diff] [blame] | 304 | buildResolveList(intent, categories, debug, defaultOnly, |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 305 | resolvedType, scheme, secondTypeCut, finalList, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 306 | } |
| 307 | if (thirdTypeCut != null) { |
Jeff Brown | 2c376fc | 2011-01-28 17:34:01 -0800 | [diff] [blame] | 308 | buildResolveList(intent, categories, debug, defaultOnly, |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 309 | resolvedType, scheme, thirdTypeCut, finalList, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 310 | } |
| 311 | if (schemeCut != null) { |
Jeff Brown | 2c376fc | 2011-01-28 17:34:01 -0800 | [diff] [blame] | 312 | buildResolveList(intent, categories, debug, defaultOnly, |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 313 | resolvedType, scheme, schemeCut, finalList, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | } |
| 315 | sortResults(finalList); |
| 316 | |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 317 | List<R> oldList = mOldResolver.queryIntent(intent, resolvedType, defaultOnly, userId); |
| 318 | if (oldList.size() != finalList.size()) { |
| 319 | ValidationFailure here = new ValidationFailure(); |
| 320 | here.fillInStackTrace(); |
| 321 | Log.wtf(TAG, "Query result " + intent + " size is " + finalList.size() |
| 322 | + "; old implementation is " + oldList.size(), here); |
| 323 | } |
| 324 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 325 | if (debug) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 326 | Slog.v(TAG, "Final result list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 327 | for (R r : finalList) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 328 | Slog.v(TAG, " " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | return finalList; |
| 332 | } |
| 333 | |
| 334 | /** |
| 335 | * Control whether the given filter is allowed to go into the result |
| 336 | * list. Mainly intended to prevent adding multiple filters for the |
| 337 | * same target object. |
| 338 | */ |
| 339 | protected boolean allowFilterResult(F filter, List<R> dest) { |
| 340 | return true; |
| 341 | } |
| 342 | |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 343 | /** |
| 344 | * Returns whether the object associated with the given filter is |
| 345 | * "stopped," that is whether it should not be included in the result |
| 346 | * if the intent requests to excluded stopped objects. |
| 347 | */ |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 348 | protected boolean isFilterStopped(F filter, int userId) { |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 349 | return false; |
| 350 | } |
| 351 | |
Dianne Hackborn | 6c418d5 | 2011-06-29 14:05:33 -0700 | [diff] [blame] | 352 | /** |
| 353 | * Return the package that owns this filter. This must be implemented to |
| 354 | * provide correct filtering of Intents that have specified a package name |
| 355 | * they are to be delivered to. |
| 356 | */ |
| 357 | protected abstract String packageForFilter(F filter); |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 358 | |
| 359 | protected abstract F[] newArray(int size); |
| 360 | |
Dianne Hackborn | 6c418d5 | 2011-06-29 14:05:33 -0700 | [diff] [blame] | 361 | @SuppressWarnings("unchecked") |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 362 | protected R newResult(F filter, int match, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 363 | return (R)filter; |
| 364 | } |
| 365 | |
Dianne Hackborn | 6c418d5 | 2011-06-29 14:05:33 -0700 | [diff] [blame] | 366 | @SuppressWarnings("unchecked") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 367 | protected void sortResults(List<R> results) { |
| 368 | Collections.sort(results, mResolvePrioritySorter); |
| 369 | } |
| 370 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 371 | protected void dumpFilter(PrintWriter out, String prefix, F filter) { |
| 372 | out.print(prefix); out.println(filter); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 373 | } |
| 374 | |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 375 | private final void addFilter(HashMap<String, F[]> map, String name, F filter) { |
| 376 | F[] array = map.get(name); |
| 377 | if (array == null) { |
| 378 | array = newArray(2); |
| 379 | map.put(name, array); |
| 380 | array[0] = filter; |
| 381 | } else { |
| 382 | final int N = array.length; |
| 383 | int i = N; |
| 384 | while (i > 0 && array[i-1] == null) { |
| 385 | i--; |
| 386 | } |
| 387 | if (i < N) { |
| 388 | array[i] = filter; |
| 389 | } else { |
| 390 | F[] newa = newArray((N*3)/2); |
| 391 | System.arraycopy(array, 0, newa, 0, N); |
| 392 | newa[N] = filter; |
| 393 | map.put(name, newa); |
| 394 | } |
| 395 | } |
| 396 | } |
| 397 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | private final int register_mime_types(F filter, String prefix) { |
| 399 | final Iterator<String> i = filter.typesIterator(); |
| 400 | if (i == null) { |
| 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | int num = 0; |
| 405 | while (i.hasNext()) { |
Kenny Root | 502e9a4 | 2011-01-10 13:48:15 -0800 | [diff] [blame] | 406 | String name = i.next(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 407 | num++; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 408 | if (localLOGV) Slog.v(TAG, prefix + name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 409 | String baseName = name; |
| 410 | final int slashpos = name.indexOf('/'); |
| 411 | if (slashpos > 0) { |
| 412 | baseName = name.substring(0, slashpos).intern(); |
| 413 | } else { |
| 414 | name = name + "/*"; |
| 415 | } |
| 416 | |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 417 | addFilter(mTypeToFilter, name, filter); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | |
| 419 | if (slashpos > 0) { |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 420 | addFilter(mBaseTypeToFilter, baseName, filter); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 421 | } else { |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 422 | addFilter(mWildTypeToFilter, baseName, filter); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | } |
| 424 | } |
| 425 | |
| 426 | return num; |
| 427 | } |
| 428 | |
| 429 | private final int unregister_mime_types(F filter, String prefix) { |
| 430 | final Iterator<String> i = filter.typesIterator(); |
| 431 | if (i == null) { |
| 432 | return 0; |
| 433 | } |
| 434 | |
| 435 | int num = 0; |
| 436 | while (i.hasNext()) { |
Kenny Root | 502e9a4 | 2011-01-10 13:48:15 -0800 | [diff] [blame] | 437 | String name = i.next(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 438 | num++; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 439 | if (localLOGV) Slog.v(TAG, prefix + name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 440 | String baseName = name; |
| 441 | final int slashpos = name.indexOf('/'); |
| 442 | if (slashpos > 0) { |
| 443 | baseName = name.substring(0, slashpos).intern(); |
| 444 | } else { |
| 445 | name = name + "/*"; |
| 446 | } |
| 447 | |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 448 | remove_all_objects(mTypeToFilter, name, filter); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 449 | |
| 450 | if (slashpos > 0) { |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 451 | remove_all_objects(mBaseTypeToFilter, baseName, filter); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 452 | } else { |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 453 | remove_all_objects(mWildTypeToFilter, baseName, filter); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 454 | } |
| 455 | } |
| 456 | return num; |
| 457 | } |
| 458 | |
| 459 | private final int register_intent_filter(F filter, Iterator<String> i, |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 460 | HashMap<String, F[]> dest, String prefix) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 461 | if (i == null) { |
| 462 | return 0; |
| 463 | } |
| 464 | |
| 465 | int num = 0; |
| 466 | while (i.hasNext()) { |
| 467 | String name = i.next(); |
| 468 | num++; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 469 | if (localLOGV) Slog.v(TAG, prefix + name); |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 470 | addFilter(dest, name, filter); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | } |
| 472 | return num; |
| 473 | } |
| 474 | |
| 475 | private final int unregister_intent_filter(F filter, Iterator<String> i, |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 476 | HashMap<String, F[]> dest, String prefix) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 477 | if (i == null) { |
| 478 | return 0; |
| 479 | } |
| 480 | |
| 481 | int num = 0; |
| 482 | while (i.hasNext()) { |
| 483 | String name = i.next(); |
| 484 | num++; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 485 | if (localLOGV) Slog.v(TAG, prefix + name); |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 486 | remove_all_objects(dest, name, filter); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 487 | } |
| 488 | return num; |
| 489 | } |
| 490 | |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 491 | private final void remove_all_objects(HashMap<String, F[]> map, String name, |
| 492 | Object object) { |
| 493 | F[] array = map.get(name); |
| 494 | if (array != null) { |
| 495 | int LAST = array.length-1; |
| 496 | while (LAST >= 0 && array[LAST] == null) { |
| 497 | LAST--; |
| 498 | } |
| 499 | for (int idx=LAST; idx>=0; idx--) { |
| 500 | if (array[idx] == object) { |
| 501 | final int remain = LAST - idx; |
| 502 | if (remain > 0) { |
| 503 | System.arraycopy(array, idx+1, array, idx, remain); |
| 504 | } |
| 505 | array[LAST] = null; |
| 506 | LAST--; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 507 | } |
| 508 | } |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 509 | if (LAST < 0) { |
| 510 | map.remove(name); |
| 511 | } else if (LAST < (array.length/2)) { |
| 512 | F[] newa = newArray(LAST+2); |
| 513 | System.arraycopy(array, 0, newa, 0, LAST+1); |
| 514 | map.put(name, newa); |
| 515 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 516 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 517 | } |
| 518 | |
Jeff Brown | 2c376fc | 2011-01-28 17:34:01 -0800 | [diff] [blame] | 519 | private static FastImmutableArraySet<String> getFastIntentCategories(Intent intent) { |
| 520 | final Set<String> categories = intent.getCategories(); |
| 521 | if (categories == null) { |
| 522 | return null; |
| 523 | } |
| 524 | return new FastImmutableArraySet<String>(categories.toArray(new String[categories.size()])); |
| 525 | } |
| 526 | |
| 527 | private void buildResolveList(Intent intent, FastImmutableArraySet<String> categories, |
| 528 | boolean debug, boolean defaultOnly, |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 529 | String resolvedType, String scheme, F[] src, List<R> dest, int userId) { |
Jeff Brown | 2c376fc | 2011-01-28 17:34:01 -0800 | [diff] [blame] | 530 | final String action = intent.getAction(); |
| 531 | final Uri data = intent.getData(); |
Dianne Hackborn | 6c418d5 | 2011-06-29 14:05:33 -0700 | [diff] [blame] | 532 | final String packageName = intent.getPackage(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 533 | |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 534 | final boolean excludingStopped = intent.isExcludingStopped(); |
| 535 | |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 536 | final int N = src != null ? src.length : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 537 | boolean hasNonDefaults = false; |
| 538 | int i; |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 539 | F filter; |
| 540 | for (i=0; i<N && (filter=src[i]) != null; i++) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 541 | int match; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 542 | if (debug) Slog.v(TAG, "Matching against filter " + filter); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 543 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 544 | if (excludingStopped && isFilterStopped(filter, userId)) { |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 545 | if (debug) { |
| 546 | Slog.v(TAG, " Filter's target is stopped; skipping"); |
| 547 | } |
| 548 | continue; |
| 549 | } |
| 550 | |
Dianne Hackborn | 6c418d5 | 2011-06-29 14:05:33 -0700 | [diff] [blame] | 551 | // Is delivery being limited to filters owned by a particular package? |
| 552 | if (packageName != null && !packageName.equals(packageForFilter(filter))) { |
| 553 | if (debug) { |
| 554 | Slog.v(TAG, " Filter is not from package " + packageName + "; skipping"); |
| 555 | } |
| 556 | continue; |
| 557 | } |
| 558 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 559 | // Do we already have this one? |
| 560 | if (!allowFilterResult(filter, dest)) { |
| 561 | if (debug) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 562 | Slog.v(TAG, " Filter's target already added"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 563 | } |
| 564 | continue; |
| 565 | } |
| 566 | |
Jeff Brown | 2c376fc | 2011-01-28 17:34:01 -0800 | [diff] [blame] | 567 | match = filter.match(action, resolvedType, scheme, data, categories, TAG); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 568 | if (match >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 569 | if (debug) Slog.v(TAG, " Filter matched! match=0x" + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 570 | Integer.toHexString(match)); |
| 571 | if (!defaultOnly || filter.hasCategory(Intent.CATEGORY_DEFAULT)) { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 572 | final R oneResult = newResult(filter, match, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 573 | if (oneResult != null) { |
| 574 | dest.add(oneResult); |
| 575 | } |
| 576 | } else { |
| 577 | hasNonDefaults = true; |
| 578 | } |
| 579 | } else { |
| 580 | if (debug) { |
| 581 | String reason; |
| 582 | switch (match) { |
| 583 | case IntentFilter.NO_MATCH_ACTION: reason = "action"; break; |
| 584 | case IntentFilter.NO_MATCH_CATEGORY: reason = "category"; break; |
| 585 | case IntentFilter.NO_MATCH_DATA: reason = "data"; break; |
| 586 | case IntentFilter.NO_MATCH_TYPE: reason = "type"; break; |
| 587 | default: reason = "unknown reason"; break; |
| 588 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 589 | Slog.v(TAG, " Filter did not match: " + reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 590 | } |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | if (dest.size() == 0 && hasNonDefaults) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 595 | Slog.w(TAG, "resolveIntent failed: found match, but none with Intent.CATEGORY_DEFAULT"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 596 | } |
| 597 | } |
| 598 | |
| 599 | // Sorts a List of IntentFilter objects into descending priority order. |
Dianne Hackborn | 6c418d5 | 2011-06-29 14:05:33 -0700 | [diff] [blame] | 600 | @SuppressWarnings("rawtypes") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 601 | private static final Comparator mResolvePrioritySorter = new Comparator() { |
| 602 | public int compare(Object o1, Object o2) { |
Kenny Root | 502e9a4 | 2011-01-10 13:48:15 -0800 | [diff] [blame] | 603 | final int q1 = ((IntentFilter) o1).getPriority(); |
| 604 | final int q2 = ((IntentFilter) o2).getPriority(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 605 | return (q1 > q2) ? -1 : ((q1 < q2) ? 1 : 0); |
| 606 | } |
| 607 | }; |
| 608 | |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 609 | static class ValidationFailure extends RuntimeException { |
| 610 | } |
| 611 | |
| 612 | private void verifyDataStructures(IntentFilter src) { |
| 613 | compareMaps(src, "mTypeToFilter", mTypeToFilter, mOldResolver.mTypeToFilter); |
| 614 | compareMaps(src, "mBaseTypeToFilter", mBaseTypeToFilter, mOldResolver.mBaseTypeToFilter); |
| 615 | compareMaps(src, "mWildTypeToFilter", mWildTypeToFilter, mOldResolver.mWildTypeToFilter); |
| 616 | compareMaps(src, "mSchemeToFilter", mSchemeToFilter, mOldResolver.mSchemeToFilter); |
| 617 | compareMaps(src, "mActionToFilter", mActionToFilter, mOldResolver.mActionToFilter); |
| 618 | compareMaps(src, "mTypedActionToFilter", mTypedActionToFilter, mOldResolver.mTypedActionToFilter); |
| 619 | } |
| 620 | |
| 621 | private void compareMaps(IntentFilter src, String name, HashMap<String, F[]> cur, |
| 622 | HashMap<String, ArrayList<F>> old) { |
| 623 | if (cur.size() != old.size()) { |
| 624 | StringBuilder missing = new StringBuilder(128); |
| 625 | for (Map.Entry<String, ArrayList<F>> e : old.entrySet()) { |
| 626 | final F[] curArray = cur.get(e.getKey()); |
| 627 | if (curArray == null) { |
| 628 | if (missing.length() > 0) { |
| 629 | missing.append(' '); |
| 630 | } |
| 631 | missing.append(e.getKey()); |
| 632 | } |
| 633 | } |
| 634 | StringBuilder extra = new StringBuilder(128); |
| 635 | for (Map.Entry<String, F[]> e : cur.entrySet()) { |
| 636 | if (old.get(e.getKey()) == null) { |
| 637 | if (extra.length() > 0) { |
| 638 | extra.append(' '); |
| 639 | } |
| 640 | extra.append(e.getKey()); |
| 641 | } |
| 642 | } |
| 643 | StringBuilder srcStr = new StringBuilder(1024); |
| 644 | StringBuilderPrinter printer = new StringBuilderPrinter(srcStr); |
| 645 | src.dump(printer, ""); |
| 646 | ValidationFailure here = new ValidationFailure(); |
| 647 | here.fillInStackTrace(); |
| 648 | Log.wtf(TAG, "New map " + name + " size is " + cur.size() |
| 649 | + "; old implementation is " + old.size() |
| 650 | + "; missing: " + missing.toString() |
| 651 | + "; extra: " + extra.toString() |
| 652 | + "; src: " + srcStr.toString(), here); |
| 653 | return; |
| 654 | } |
| 655 | for (Map.Entry<String, ArrayList<F>> e : old.entrySet()) { |
| 656 | final F[] curArray = cur.get(e.getKey()); |
| 657 | int curLen = curArray != null ? curArray.length : 0; |
| 658 | if (curLen == 0) { |
| 659 | ValidationFailure here = new ValidationFailure(); |
| 660 | here.fillInStackTrace(); |
| 661 | Log.wtf(TAG, "New map " + name + " doesn't contain expected key " |
| 662 | + e.getKey() + " (array=" + curArray + ")"); |
| 663 | return; |
| 664 | } |
| 665 | while (curLen > 0 && curArray[curLen-1] == null) { |
| 666 | curLen--; |
| 667 | } |
| 668 | final ArrayList<F> oldArray = e.getValue(); |
| 669 | final int oldLen = oldArray.size(); |
| 670 | if (curLen != oldLen) { |
| 671 | ValidationFailure here = new ValidationFailure(); |
| 672 | here.fillInStackTrace(); |
| 673 | Log.wtf(TAG, "New map " + name + " entry " + e.getKey() + " size is " |
| 674 | + curLen + "; old implementation is " + oldLen, here); |
| 675 | return; |
| 676 | } |
| 677 | for (int i=0; i<oldLen; i++) { |
| 678 | F f = oldArray.get(i); |
| 679 | boolean found = false; |
| 680 | for (int j=0; j<curLen; j++) { |
| 681 | if (curArray[j] == f) { |
| 682 | found = true; |
| 683 | break; |
| 684 | } |
| 685 | } |
| 686 | if (!found) { |
| 687 | ValidationFailure here = new ValidationFailure(); |
| 688 | here.fillInStackTrace(); |
| 689 | Log.wtf(TAG, "New map " + name + " entry + " + e.getKey() |
| 690 | + " doesn't contain expected filter " + f, here); |
| 691 | } |
| 692 | } |
| 693 | for (int i=0; i<curLen; i++) { |
| 694 | if (curArray[i] == null) { |
| 695 | ValidationFailure here = new ValidationFailure(); |
| 696 | here.fillInStackTrace(); |
| 697 | Log.wtf(TAG, "New map " + name + " entry + " + e.getKey() |
| 698 | + " has unexpected null at " + i + "; array: " + curArray, here); |
| 699 | break; |
| 700 | } |
| 701 | } |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | private final IntentResolverOld<F, R> mOldResolver = new IntentResolverOld<F, R>() { |
| 706 | @Override protected String packageForFilter(F filter) { |
| 707 | return IntentResolver.this.packageForFilter(filter); |
| 708 | } |
| 709 | @Override protected boolean allowFilterResult(F filter, List<R> dest) { |
| 710 | return IntentResolver.this.allowFilterResult(filter, dest); |
| 711 | } |
| 712 | @Override protected boolean isFilterStopped(F filter, int userId) { |
| 713 | return IntentResolver.this.isFilterStopped(filter, userId); |
| 714 | } |
| 715 | @Override protected R newResult(F filter, int match, int userId) { |
| 716 | return IntentResolver.this.newResult(filter, match, userId); |
| 717 | } |
| 718 | @Override protected void sortResults(List<R> results) { |
| 719 | IntentResolver.this.sortResults(results); |
| 720 | } |
| 721 | }; |
| 722 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 723 | /** |
| 724 | * All filters that have been registered. |
| 725 | */ |
| 726 | private final HashSet<F> mFilters = new HashSet<F>(); |
| 727 | |
| 728 | /** |
| 729 | * All of the MIME types that have been registered, such as "image/jpeg", |
| 730 | * "image/*", or "{@literal *}/*". |
| 731 | */ |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 732 | private final HashMap<String, F[]> mTypeToFilter = new HashMap<String, F[]>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 733 | |
| 734 | /** |
| 735 | * The base names of all of all fully qualified MIME types that have been |
| 736 | * registered, such as "image" or "*". Wild card MIME types such as |
| 737 | * "image/*" will not be here. |
| 738 | */ |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 739 | private final HashMap<String, F[]> mBaseTypeToFilter = new HashMap<String, F[]>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 740 | |
| 741 | /** |
| 742 | * The base names of all of the MIME types with a sub-type wildcard that |
| 743 | * have been registered. For example, a filter with "image/*" will be |
| 744 | * included here as "image" but one with "image/jpeg" will not be |
| 745 | * included here. This also includes the "*" for the "{@literal *}/*" |
| 746 | * MIME type. |
| 747 | */ |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 748 | private final HashMap<String, F[]> mWildTypeToFilter = new HashMap<String, F[]>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 749 | |
| 750 | /** |
| 751 | * All of the URI schemes (such as http) that have been registered. |
| 752 | */ |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 753 | private final HashMap<String, F[]> mSchemeToFilter = new HashMap<String, F[]>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 754 | |
| 755 | /** |
| 756 | * All of the actions that have been registered, but only those that did |
| 757 | * not specify data. |
| 758 | */ |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 759 | private final HashMap<String, F[]> mActionToFilter = new HashMap<String, F[]>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 760 | |
| 761 | /** |
| 762 | * All of the actions that have been registered and specified a MIME type. |
| 763 | */ |
Dianne Hackborn | 9ec6cdd | 2012-05-31 10:57:54 -0700 | [diff] [blame^] | 764 | private final HashMap<String, F[]> mTypedActionToFilter = new HashMap<String, F[]>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 765 | } |