Kenny Root | 15a4d2f | 2010-03-11 18:20:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | package android.content.pm; |
| 18 | |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 19 | import android.content.ComponentName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import android.content.IntentFilter; |
| 21 | import android.graphics.drawable.Drawable; |
| 22 | import android.os.Parcel; |
| 23 | import android.os.Parcelable; |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 24 | import android.os.UserHandle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import android.text.TextUtils; |
| 26 | import android.util.Printer; |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 27 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | |
| 29 | import java.text.Collator; |
| 30 | import java.util.Comparator; |
| 31 | |
| 32 | /** |
| 33 | * Information that is returned from resolving an intent |
| 34 | * against an IntentFilter. This partially corresponds to |
| 35 | * information collected from the AndroidManifest.xml's |
| 36 | * <intent> tags. |
| 37 | */ |
| 38 | public class ResolveInfo implements Parcelable { |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 39 | private static final String TAG = "ResolveInfo"; |
| 40 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | /** |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 42 | * The activity or broadcast receiver that corresponds to this resolution |
| 43 | * match, if this resolution is for an activity or broadcast receiver. |
| 44 | * Exactly one of {@link #activityInfo}, {@link #serviceInfo}, or |
| 45 | * {@link #providerInfo} will be non-null. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | */ |
| 47 | public ActivityInfo activityInfo; |
| 48 | |
| 49 | /** |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 50 | * The service that corresponds to this resolution match, if this resolution |
| 51 | * is for a service. Exactly one of {@link #activityInfo}, |
| 52 | * {@link #serviceInfo}, or {@link #providerInfo} will be non-null. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | */ |
| 54 | public ServiceInfo serviceInfo; |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * The provider that corresponds to this resolution match, if this |
| 58 | * resolution is for a provider. Exactly one of {@link #activityInfo}, |
| 59 | * {@link #serviceInfo}, or {@link #providerInfo} will be non-null. |
| 60 | */ |
| 61 | public ProviderInfo providerInfo; |
| 62 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | /** |
| 64 | * The IntentFilter that was matched for this ResolveInfo. |
| 65 | */ |
| 66 | public IntentFilter filter; |
| 67 | |
| 68 | /** |
| 69 | * The declared priority of this match. Comes from the "priority" |
| 70 | * attribute or, if not set, defaults to 0. Higher values are a higher |
| 71 | * priority. |
| 72 | */ |
| 73 | public int priority; |
| 74 | |
| 75 | /** |
| 76 | * Order of result according to the user's preference. If the user |
| 77 | * has not set a preference for this result, the value is 0; higher |
| 78 | * values are a higher priority. |
| 79 | */ |
| 80 | public int preferredOrder; |
| 81 | |
| 82 | /** |
| 83 | * The system's evaluation of how well the activity matches the |
| 84 | * IntentFilter. This is a match constant, a combination of |
| 85 | * {@link IntentFilter#MATCH_CATEGORY_MASK IntentFilter.MATCH_CATEGORY_MASK} |
| 86 | * and {@link IntentFilter#MATCH_ADJUSTMENT_MASK IntentFiler.MATCH_ADJUSTMENT_MASK}. |
| 87 | */ |
| 88 | public int match; |
| 89 | |
| 90 | /** |
| 91 | * Only set when returned by |
| 92 | * {@link PackageManager#queryIntentActivityOptions}, this tells you |
| 93 | * which of the given specific intents this result came from. 0 is the |
| 94 | * first in the list, < 0 means it came from the generic Intent query. |
| 95 | */ |
| 96 | public int specificIndex = -1; |
| 97 | |
| 98 | /** |
| 99 | * This filter has specified the Intent.CATEGORY_DEFAULT, meaning it |
| 100 | * would like to be considered a default action that the user can |
| 101 | * perform on this data. |
| 102 | */ |
| 103 | public boolean isDefault; |
| 104 | |
| 105 | /** |
| 106 | * A string resource identifier (in the package's resources) of this |
| 107 | * match's label. From the "label" attribute or, if not set, 0. |
| 108 | */ |
| 109 | public int labelRes; |
| 110 | |
| 111 | /** |
| 112 | * The actual string retrieve from <var>labelRes</var> or null if none |
| 113 | * was provided. |
| 114 | */ |
| 115 | public CharSequence nonLocalizedLabel; |
| 116 | |
| 117 | /** |
| 118 | * A drawable resource identifier (in the package's resources) of this |
| 119 | * match's icon. From the "icon" attribute or, if not set, 0. |
| 120 | */ |
| 121 | public int icon; |
| 122 | |
| 123 | /** |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 124 | * Optional -- if non-null, the {@link #labelRes} and {@link #icon} |
| 125 | * resources will be loaded from this package, rather than the one |
| 126 | * containing the resolved component. |
| 127 | */ |
| 128 | public String resolvePackageName; |
Dianne Hackborn | d99b293 | 2011-08-18 14:39:58 -0700 | [diff] [blame] | 129 | |
| 130 | /** |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 131 | * If not equal to UserHandle.USER_CURRENT, then the intent will be forwarded to this user. |
| 132 | * @hide |
| 133 | */ |
| 134 | public int targetUserId; |
| 135 | |
| 136 | /** |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 137 | * @hide |
| 138 | */ |
Nicolas Prevot | 7f7b0c7 | 2014-06-23 15:59:38 +0100 | [diff] [blame] | 139 | public boolean noResourceId; |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 140 | |
| 141 | /** |
Dianne Hackborn | d99b293 | 2011-08-18 14:39:58 -0700 | [diff] [blame] | 142 | * @hide Target comes from system process? |
| 143 | */ |
| 144 | public boolean system; |
| 145 | |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 146 | /** |
Fabrice Di Meglio | 7d014ce | 2015-04-08 16:17:46 -0700 | [diff] [blame] | 147 | * @hide Does the associated IntentFilter comes from a Browser ? |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 148 | */ |
Fabrice Di Meglio | 7d014ce | 2015-04-08 16:17:46 -0700 | [diff] [blame] | 149 | public boolean handleAllWebDataURI; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 150 | |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 151 | private ComponentInfo getComponentInfo() { |
| 152 | if (activityInfo != null) return activityInfo; |
| 153 | if (serviceInfo != null) return serviceInfo; |
| 154 | if (providerInfo != null) return providerInfo; |
| 155 | throw new IllegalStateException("Missing ComponentInfo!"); |
| 156 | } |
| 157 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 158 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | * Retrieve the current textual label associated with this resolution. This |
| 160 | * will call back on the given PackageManager to load the label from |
| 161 | * the application. |
| 162 | * |
| 163 | * @param pm A PackageManager from which the label can be loaded; usually |
| 164 | * the PackageManager from which you originally retrieved this item. |
| 165 | * |
| 166 | * @return Returns a CharSequence containing the resolutions's label. If the |
| 167 | * item does not have a label, its name is returned. |
| 168 | */ |
| 169 | public CharSequence loadLabel(PackageManager pm) { |
| 170 | if (nonLocalizedLabel != null) { |
| 171 | return nonLocalizedLabel; |
| 172 | } |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 173 | CharSequence label; |
| 174 | if (resolvePackageName != null && labelRes != 0) { |
| 175 | label = pm.getText(resolvePackageName, labelRes, null); |
| 176 | if (label != null) { |
Romain Guy | 2aba11f | 2010-03-29 16:03:01 -0700 | [diff] [blame] | 177 | return label.toString().trim(); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 178 | } |
| 179 | } |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 180 | ComponentInfo ci = getComponentInfo(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | ApplicationInfo ai = ci.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | if (labelRes != 0) { |
| 183 | label = pm.getText(ci.packageName, labelRes, ai); |
| 184 | if (label != null) { |
Romain Guy | 2aba11f | 2010-03-29 16:03:01 -0700 | [diff] [blame] | 185 | return label.toString().trim(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | } |
| 187 | } |
Romain Guy | 2aba11f | 2010-03-29 16:03:01 -0700 | [diff] [blame] | 188 | |
| 189 | CharSequence data = ci.loadLabel(pm); |
| 190 | // Make the data safe |
| 191 | if (data != null) data = data.toString().trim(); |
| 192 | return data; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Retrieve the current graphical icon associated with this resolution. This |
| 197 | * will call back on the given PackageManager to load the icon from |
| 198 | * the application. |
| 199 | * |
| 200 | * @param pm A PackageManager from which the icon can be loaded; usually |
| 201 | * the PackageManager from which you originally retrieved this item. |
| 202 | * |
| 203 | * @return Returns a Drawable containing the resolution's icon. If the |
| 204 | * item does not have an icon, the default activity icon is returned. |
| 205 | */ |
| 206 | public Drawable loadIcon(PackageManager pm) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 207 | Drawable dr; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 208 | if (resolvePackageName != null && icon != 0) { |
| 209 | dr = pm.getDrawable(resolvePackageName, icon, null); |
| 210 | if (dr != null) { |
| 211 | return dr; |
| 212 | } |
| 213 | } |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 214 | ComponentInfo ci = getComponentInfo(); |
Jeff Brown | 0733079 | 2010-03-30 19:57:08 -0700 | [diff] [blame] | 215 | ApplicationInfo ai = ci.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 | if (icon != 0) { |
| 217 | dr = pm.getDrawable(ci.packageName, icon, ai); |
| 218 | if (dr != null) { |
| 219 | return dr; |
| 220 | } |
| 221 | } |
| 222 | return ci.loadIcon(pm); |
| 223 | } |
Ricky Wai | 1281b18 | 2015-04-29 14:57:04 +0100 | [diff] [blame^] | 224 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | /** |
| 226 | * Return the icon resource identifier to use for this match. If the |
| 227 | * match defines an icon, that is used; else if the activity defines |
| 228 | * an icon, that is used; else, the application icon is used. |
Ricky Wai | 1281b18 | 2015-04-29 14:57:04 +0100 | [diff] [blame^] | 229 | * This function does not check noResourceId flag. |
| 230 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | * @return The icon associated with this match. |
| 232 | */ |
Ricky Wai | 1281b18 | 2015-04-29 14:57:04 +0100 | [diff] [blame^] | 233 | final int getIconResourceInternal() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | if (icon != 0) return icon; |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 235 | final ComponentInfo ci = getComponentInfo(); |
Nicolas Prevot | 7f7b0c7 | 2014-06-23 15:59:38 +0100 | [diff] [blame] | 236 | if (ci != null) { |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 237 | return ci.getIconResource(); |
| 238 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | return 0; |
| 240 | } |
| 241 | |
Ricky Wai | 1281b18 | 2015-04-29 14:57:04 +0100 | [diff] [blame^] | 242 | /** |
| 243 | * Return the icon resource identifier to use for this match. If the |
| 244 | * match defines an icon, that is used; else if the activity defines |
| 245 | * an icon, that is used; else, the application icon is used. |
| 246 | * |
| 247 | * @return The icon associated with this match. |
| 248 | */ |
| 249 | public final int getIconResource() { |
| 250 | if (noResourceId) return 0; |
| 251 | return getIconResourceInternal(); |
| 252 | } |
| 253 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | public void dump(Printer pw, String prefix) { |
| 255 | if (filter != null) { |
| 256 | pw.println(prefix + "Filter:"); |
| 257 | filter.dump(pw, prefix + " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 258 | } |
| 259 | pw.println(prefix + "priority=" + priority |
| 260 | + " preferredOrder=" + preferredOrder |
| 261 | + " match=0x" + Integer.toHexString(match) |
| 262 | + " specificIndex=" + specificIndex |
| 263 | + " isDefault=" + isDefault); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 264 | if (resolvePackageName != null) { |
| 265 | pw.println(prefix + "resolvePackageName=" + resolvePackageName); |
| 266 | } |
| 267 | if (labelRes != 0 || nonLocalizedLabel != null || icon != 0) { |
| 268 | pw.println(prefix + "labelRes=0x" + Integer.toHexString(labelRes) |
| 269 | + " nonLocalizedLabel=" + nonLocalizedLabel |
| 270 | + " icon=0x" + Integer.toHexString(icon)); |
| 271 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | if (activityInfo != null) { |
| 273 | pw.println(prefix + "ActivityInfo:"); |
| 274 | activityInfo.dump(pw, prefix + " "); |
| 275 | } else if (serviceInfo != null) { |
| 276 | pw.println(prefix + "ServiceInfo:"); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 277 | serviceInfo.dump(pw, prefix + " "); |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 278 | } else if (providerInfo != null) { |
| 279 | pw.println(prefix + "ProviderInfo:"); |
| 280 | providerInfo.dump(pw, prefix + " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | |
| 284 | public ResolveInfo() { |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 285 | targetUserId = UserHandle.USER_CURRENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | } |
| 287 | |
Dianne Hackborn | 8da429e | 2012-09-23 12:52:19 -0700 | [diff] [blame] | 288 | public ResolveInfo(ResolveInfo orig) { |
| 289 | activityInfo = orig.activityInfo; |
| 290 | serviceInfo = orig.serviceInfo; |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 291 | providerInfo = orig.providerInfo; |
Dianne Hackborn | 8da429e | 2012-09-23 12:52:19 -0700 | [diff] [blame] | 292 | filter = orig.filter; |
| 293 | priority = orig.priority; |
| 294 | preferredOrder = orig.preferredOrder; |
| 295 | match = orig.match; |
| 296 | specificIndex = orig.specificIndex; |
| 297 | labelRes = orig.labelRes; |
| 298 | nonLocalizedLabel = orig.nonLocalizedLabel; |
| 299 | icon = orig.icon; |
| 300 | resolvePackageName = orig.resolvePackageName; |
| 301 | system = orig.system; |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 302 | targetUserId = orig.targetUserId; |
Fabrice Di Meglio | 7d014ce | 2015-04-08 16:17:46 -0700 | [diff] [blame] | 303 | handleAllWebDataURI = orig.handleAllWebDataURI; |
Dianne Hackborn | 8da429e | 2012-09-23 12:52:19 -0700 | [diff] [blame] | 304 | } |
| 305 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 306 | public String toString() { |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 307 | final ComponentInfo ci = getComponentInfo(); |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 308 | StringBuilder sb = new StringBuilder(128); |
| 309 | sb.append("ResolveInfo{"); |
| 310 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 311 | sb.append(' '); |
| 312 | ComponentName.appendShortString(sb, ci.packageName, ci.name); |
| 313 | if (priority != 0) { |
| 314 | sb.append(" p="); |
| 315 | sb.append(priority); |
| 316 | } |
| 317 | if (preferredOrder != 0) { |
| 318 | sb.append(" o="); |
| 319 | sb.append(preferredOrder); |
| 320 | } |
| 321 | sb.append(" m=0x"); |
| 322 | sb.append(Integer.toHexString(match)); |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 323 | if (targetUserId != UserHandle.USER_CURRENT) { |
| 324 | sb.append(" targetUserId="); |
| 325 | sb.append(targetUserId); |
| 326 | } |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 327 | sb.append('}'); |
| 328 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | public int describeContents() { |
| 332 | return 0; |
| 333 | } |
| 334 | |
| 335 | public void writeToParcel(Parcel dest, int parcelableFlags) { |
| 336 | if (activityInfo != null) { |
| 337 | dest.writeInt(1); |
| 338 | activityInfo.writeToParcel(dest, parcelableFlags); |
| 339 | } else if (serviceInfo != null) { |
| 340 | dest.writeInt(2); |
| 341 | serviceInfo.writeToParcel(dest, parcelableFlags); |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 342 | } else if (providerInfo != null) { |
| 343 | dest.writeInt(3); |
| 344 | providerInfo.writeToParcel(dest, parcelableFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 345 | } else { |
| 346 | dest.writeInt(0); |
| 347 | } |
| 348 | if (filter != null) { |
| 349 | dest.writeInt(1); |
| 350 | filter.writeToParcel(dest, parcelableFlags); |
| 351 | } else { |
| 352 | dest.writeInt(0); |
| 353 | } |
| 354 | dest.writeInt(priority); |
| 355 | dest.writeInt(preferredOrder); |
| 356 | dest.writeInt(match); |
| 357 | dest.writeInt(specificIndex); |
| 358 | dest.writeInt(labelRes); |
| 359 | TextUtils.writeToParcel(nonLocalizedLabel, dest, parcelableFlags); |
| 360 | dest.writeInt(icon); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 361 | dest.writeString(resolvePackageName); |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 362 | dest.writeInt(targetUserId); |
Dianne Hackborn | d99b293 | 2011-08-18 14:39:58 -0700 | [diff] [blame] | 363 | dest.writeInt(system ? 1 : 0); |
Nicolas Prevot | 7f7b0c7 | 2014-06-23 15:59:38 +0100 | [diff] [blame] | 364 | dest.writeInt(noResourceId ? 1 : 0); |
Fabrice Di Meglio | 7d014ce | 2015-04-08 16:17:46 -0700 | [diff] [blame] | 365 | dest.writeInt(handleAllWebDataURI ? 1 : 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | public static final Creator<ResolveInfo> CREATOR |
| 369 | = new Creator<ResolveInfo>() { |
| 370 | public ResolveInfo createFromParcel(Parcel source) { |
| 371 | return new ResolveInfo(source); |
| 372 | } |
| 373 | public ResolveInfo[] newArray(int size) { |
| 374 | return new ResolveInfo[size]; |
| 375 | } |
| 376 | }; |
| 377 | |
| 378 | private ResolveInfo(Parcel source) { |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 379 | activityInfo = null; |
| 380 | serviceInfo = null; |
| 381 | providerInfo = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 382 | switch (source.readInt()) { |
| 383 | case 1: |
| 384 | activityInfo = ActivityInfo.CREATOR.createFromParcel(source); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 385 | break; |
| 386 | case 2: |
| 387 | serviceInfo = ServiceInfo.CREATOR.createFromParcel(source); |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 388 | break; |
| 389 | case 3: |
| 390 | providerInfo = ProviderInfo.CREATOR.createFromParcel(source); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 391 | break; |
| 392 | default: |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 393 | Slog.w(TAG, "Missing ComponentInfo!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 394 | break; |
| 395 | } |
| 396 | if (source.readInt() != 0) { |
| 397 | filter = IntentFilter.CREATOR.createFromParcel(source); |
| 398 | } |
| 399 | priority = source.readInt(); |
| 400 | preferredOrder = source.readInt(); |
| 401 | match = source.readInt(); |
| 402 | specificIndex = source.readInt(); |
| 403 | labelRes = source.readInt(); |
| 404 | nonLocalizedLabel |
| 405 | = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); |
| 406 | icon = source.readInt(); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 407 | resolvePackageName = source.readString(); |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 408 | targetUserId = source.readInt(); |
Dianne Hackborn | d99b293 | 2011-08-18 14:39:58 -0700 | [diff] [blame] | 409 | system = source.readInt() != 0; |
Nicolas Prevot | 7f7b0c7 | 2014-06-23 15:59:38 +0100 | [diff] [blame] | 410 | noResourceId = source.readInt() != 0; |
Fabrice Di Meglio | 7d014ce | 2015-04-08 16:17:46 -0700 | [diff] [blame] | 411 | handleAllWebDataURI = source.readInt() != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | public static class DisplayNameComparator |
| 415 | implements Comparator<ResolveInfo> { |
| 416 | public DisplayNameComparator(PackageManager pm) { |
| 417 | mPM = pm; |
Adam Powell | 0256c6f | 2013-05-29 16:42:33 -0700 | [diff] [blame] | 418 | mCollator.setStrength(Collator.PRIMARY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | public final int compare(ResolveInfo a, ResolveInfo b) { |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 422 | // We want to put the one targeted to another user at the end of the dialog. |
| 423 | if (a.targetUserId != UserHandle.USER_CURRENT) { |
| 424 | return 1; |
| 425 | } |
| 426 | if (b.targetUserId != UserHandle.USER_CURRENT) { |
| 427 | return -1; |
| 428 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | CharSequence sa = a.loadLabel(mPM); |
| 430 | if (sa == null) sa = a.activityInfo.name; |
| 431 | CharSequence sb = b.loadLabel(mPM); |
| 432 | if (sb == null) sb = b.activityInfo.name; |
| 433 | |
Adam Powell | 0256c6f | 2013-05-29 16:42:33 -0700 | [diff] [blame] | 434 | return mCollator.compare(sa.toString(), sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 435 | } |
| 436 | |
Adam Powell | 0256c6f | 2013-05-29 16:42:33 -0700 | [diff] [blame] | 437 | private final Collator mCollator = Collator.getInstance(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 438 | private PackageManager mPM; |
| 439 | } |
| 440 | } |