blob: 1734182b3a9a5130db5a1ad982f905456a21a19d [file] [log] [blame]
Kenny Root15a4d2f2010-03-11 18:20:12 -08001/*
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 Project9066cfe2009-03-03 19:31:44 -080017package android.content.pm;
18
Hai Zhange0297132019-01-17 18:26:16 -080019import android.annotation.SystemApi;
Mathew Inwood5c0d3542018-08-14 13:54:31 +010020import android.annotation.UnsupportedAppUsage;
Dianne Hackborn6d8dfbd2013-09-23 17:38:51 -070021import android.content.ComponentName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.content.IntentFilter;
23import android.graphics.drawable.Drawable;
24import android.os.Parcel;
25import android.os.Parcelable;
Nicolas Prevot88cc3462014-05-14 14:51:48 +010026import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.text.TextUtils;
28import android.util.Printer;
Jeff Sharkey85f5f812013-10-07 10:16:12 -070029import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030
31import java.text.Collator;
32import java.util.Comparator;
33
34/**
35 * Information that is returned from resolving an intent
36 * against an IntentFilter. This partially corresponds to
37 * information collected from the AndroidManifest.xml's
38 * <intent> tags.
39 */
40public class ResolveInfo implements Parcelable {
Jeff Sharkey85f5f812013-10-07 10:16:12 -070041 private static final String TAG = "ResolveInfo";
42
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043 /**
Jeff Sharkey85f5f812013-10-07 10:16:12 -070044 * The activity or broadcast receiver that corresponds to this resolution
45 * match, if this resolution is for an activity or broadcast receiver.
46 * Exactly one of {@link #activityInfo}, {@link #serviceInfo}, or
47 * {@link #providerInfo} will be non-null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048 */
49 public ActivityInfo activityInfo;
Sudheer Shanka9ded7602015-05-19 21:17:25 +010050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051 /**
Jeff Sharkey85f5f812013-10-07 10:16:12 -070052 * The service that corresponds to this resolution match, if this resolution
53 * is for a service. Exactly one of {@link #activityInfo},
54 * {@link #serviceInfo}, or {@link #providerInfo} will be non-null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 */
56 public ServiceInfo serviceInfo;
Jeff Sharkey85f5f812013-10-07 10:16:12 -070057
58 /**
59 * The provider that corresponds to this resolution match, if this
60 * resolution is for a provider. Exactly one of {@link #activityInfo},
61 * {@link #serviceInfo}, or {@link #providerInfo} will be non-null.
62 */
63 public ProviderInfo providerInfo;
64
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065 /**
Todd Kennedye9910222017-02-21 16:00:11 -080066 * An auxiliary response that may modify the resolved information. This is
67 * only set under certain circumstances; such as when resolving instant apps
68 * or components defined in un-installed splits.
Todd Kennedy7440f172015-12-09 14:31:22 -080069 * @hide
70 */
Todd Kennedye9910222017-02-21 16:00:11 -080071 public AuxiliaryResolveInfo auxiliaryInfo;
Todd Kennedy7440f172015-12-09 14:31:22 -080072
73 /**
Todd Kennedy533c9ff2017-02-27 11:45:13 -080074 * Whether or not an instant app is available for the resolved intent.
75 */
Jeff Sharkeyf29d1962017-05-01 15:09:11 -060076 public boolean isInstantAppAvailable;
77
78 /** @removed */
79 @Deprecated
Todd Kennedy533c9ff2017-02-27 11:45:13 -080080 public boolean instantAppAvailable;
81
82 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083 * The IntentFilter that was matched for this ResolveInfo.
84 */
85 public IntentFilter filter;
Sudheer Shanka9ded7602015-05-19 21:17:25 +010086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087 /**
88 * The declared priority of this match. Comes from the "priority"
89 * attribute or, if not set, defaults to 0. Higher values are a higher
90 * priority.
91 */
92 public int priority;
Sudheer Shanka9ded7602015-05-19 21:17:25 +010093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 /**
95 * Order of result according to the user's preference. If the user
96 * has not set a preference for this result, the value is 0; higher
97 * values are a higher priority.
98 */
99 public int preferredOrder;
Sudheer Shanka9ded7602015-05-19 21:17:25 +0100100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101 /**
102 * The system's evaluation of how well the activity matches the
103 * IntentFilter. This is a match constant, a combination of
104 * {@link IntentFilter#MATCH_CATEGORY_MASK IntentFilter.MATCH_CATEGORY_MASK}
105 * and {@link IntentFilter#MATCH_ADJUSTMENT_MASK IntentFiler.MATCH_ADJUSTMENT_MASK}.
106 */
107 public int match;
Sudheer Shanka9ded7602015-05-19 21:17:25 +0100108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 /**
110 * Only set when returned by
111 * {@link PackageManager#queryIntentActivityOptions}, this tells you
112 * which of the given specific intents this result came from. 0 is the
113 * first in the list, < 0 means it came from the generic Intent query.
114 */
115 public int specificIndex = -1;
Sudheer Shanka9ded7602015-05-19 21:17:25 +0100116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 /**
118 * This filter has specified the Intent.CATEGORY_DEFAULT, meaning it
119 * would like to be considered a default action that the user can
120 * perform on this data.
121 */
122 public boolean isDefault;
Sudheer Shanka9ded7602015-05-19 21:17:25 +0100123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 /**
125 * A string resource identifier (in the package's resources) of this
126 * match's label. From the "label" attribute or, if not set, 0.
127 */
128 public int labelRes;
Sudheer Shanka9ded7602015-05-19 21:17:25 +0100129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 /**
131 * The actual string retrieve from <var>labelRes</var> or null if none
132 * was provided.
133 */
134 public CharSequence nonLocalizedLabel;
Sudheer Shanka9ded7602015-05-19 21:17:25 +0100135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136 /**
137 * A drawable resource identifier (in the package's resources) of this
Sudheer Shanka9ded7602015-05-19 21:17:25 +0100138 * match's icon. From the "icon" attribute or, if not set, 0. It is
139 * set only if the icon can be obtained by resource id alone.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 */
141 public int icon;
142
143 /**
Dianne Hackborneb034652009-09-07 00:49:58 -0700144 * Optional -- if non-null, the {@link #labelRes} and {@link #icon}
145 * resources will be loaded from this package, rather than the one
146 * containing the resolved component.
147 */
148 public String resolvePackageName;
Dianne Hackbornd99b2932011-08-18 14:39:58 -0700149
150 /**
Nicolas Prevot88cc3462014-05-14 14:51:48 +0100151 * If not equal to UserHandle.USER_CURRENT, then the intent will be forwarded to this user.
152 * @hide
153 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100154 @UnsupportedAppUsage
Nicolas Prevot88cc3462014-05-14 14:51:48 +0100155 public int targetUserId;
156
157 /**
Sudheer Shanka9ded7602015-05-19 21:17:25 +0100158 * Set to true if the icon cannot be obtained by resource ids alone.
159 * It is set to true for ResolveInfos from the managed profile: They need to
160 * have their icon badged, so it cannot be obtained by resource ids alone.
Nicolas Prevot88cc3462014-05-14 14:51:48 +0100161 * @hide
162 */
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100163 public boolean noResourceId;
Nicolas Prevot88cc3462014-05-14 14:51:48 +0100164
165 /**
Sudheer Shanka9ded7602015-05-19 21:17:25 +0100166 * Same as {@link #icon} but it will always correspond to "icon" attribute
167 * regardless of {@link #noResourceId} value.
168 * @hide
169 */
170 public int iconResourceId;
171
172 /**
Dianne Hackbornd99b2932011-08-18 14:39:58 -0700173 * @hide Target comes from system process?
174 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100175 @UnsupportedAppUsage
Dianne Hackbornd99b2932011-08-18 14:39:58 -0700176 public boolean system;
177
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -0800178 /**
Hai Zhange0297132019-01-17 18:26:16 -0800179 * Will be set to {@code true} if the {@link IntentFilter} responsible for intent
180 * resolution is classified as a "browser".
181 *
182 * @hide
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -0800183 */
Hai Zhange0297132019-01-17 18:26:16 -0800184 @SystemApi
Fabrice Di Meglio7d014ce2015-04-08 16:17:46 -0700185 public boolean handleAllWebDataURI;
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -0800186
Jeff Sharkey2a90f6732016-01-06 12:26:11 -0700187 /** {@hide} */
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100188 @UnsupportedAppUsage
Jeff Sharkey2a90f6732016-01-06 12:26:11 -0700189 public ComponentInfo getComponentInfo() {
Jeff Sharkey85f5f812013-10-07 10:16:12 -0700190 if (activityInfo != null) return activityInfo;
191 if (serviceInfo != null) return serviceInfo;
192 if (providerInfo != null) return providerInfo;
193 throw new IllegalStateException("Missing ComponentInfo!");
194 }
195
Dianne Hackborneb034652009-09-07 00:49:58 -0700196 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197 * Retrieve the current textual label associated with this resolution. This
198 * will call back on the given PackageManager to load the label from
199 * the application.
Sudheer Shanka9ded7602015-05-19 21:17:25 +0100200 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800201 * @param pm A PackageManager from which the label can be loaded; usually
202 * the PackageManager from which you originally retrieved this item.
Sudheer Shanka9ded7602015-05-19 21:17:25 +0100203 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 * @return Returns a CharSequence containing the resolutions's label. If the
205 * item does not have a label, its name is returned.
206 */
207 public CharSequence loadLabel(PackageManager pm) {
208 if (nonLocalizedLabel != null) {
209 return nonLocalizedLabel;
210 }
Dianne Hackborneb034652009-09-07 00:49:58 -0700211 CharSequence label;
212 if (resolvePackageName != null && labelRes != 0) {
213 label = pm.getText(resolvePackageName, labelRes, null);
214 if (label != null) {
Romain Guy2aba11f2010-03-29 16:03:01 -0700215 return label.toString().trim();
Dianne Hackborneb034652009-09-07 00:49:58 -0700216 }
217 }
Jeff Sharkey85f5f812013-10-07 10:16:12 -0700218 ComponentInfo ci = getComponentInfo();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219 ApplicationInfo ai = ci.applicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220 if (labelRes != 0) {
221 label = pm.getText(ci.packageName, labelRes, ai);
222 if (label != null) {
Romain Guy2aba11f2010-03-29 16:03:01 -0700223 return label.toString().trim();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 }
225 }
Romain Guy2aba11f2010-03-29 16:03:01 -0700226
227 CharSequence data = ci.loadLabel(pm);
228 // Make the data safe
229 if (data != null) data = data.toString().trim();
230 return data;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 }
Sudheer Shanka9ded7602015-05-19 21:17:25 +0100232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233 /**
Svet Ganovd96953a2017-10-18 17:12:17 -0700234 * @return The resource that would be used when loading
235 * the label for this resolve info.
236 *
237 * @hide
238 */
239 public int resolveLabelResId() {
240 if (labelRes != 0) {
241 return labelRes;
242 }
243 final ComponentInfo componentInfo = getComponentInfo();
244 if (componentInfo.labelRes != 0) {
245 return componentInfo.labelRes;
246 }
247 return componentInfo.applicationInfo.labelRes;
248 }
249
250 /**
251 * @return The resource that would be used when loading
252 * the icon for this resolve info.
253 *
254 * @hide
255 */
256 public int resolveIconResId() {
257 if (icon != 0) {
258 return icon;
259 }
260 final ComponentInfo componentInfo = getComponentInfo();
261 if (componentInfo.icon != 0) {
262 return componentInfo.icon;
263 }
264 return componentInfo.applicationInfo.icon;
265 }
266
267 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 * Retrieve the current graphical icon associated with this resolution. This
269 * will call back on the given PackageManager to load the icon from
270 * the application.
Sudheer Shanka9ded7602015-05-19 21:17:25 +0100271 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 * @param pm A PackageManager from which the icon can be loaded; usually
273 * the PackageManager from which you originally retrieved this item.
Sudheer Shanka9ded7602015-05-19 21:17:25 +0100274 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 * @return Returns a Drawable containing the resolution's icon. If the
276 * item does not have an icon, the default activity icon is returned.
277 */
278 public Drawable loadIcon(PackageManager pm) {
Sudheer Shanka9ded7602015-05-19 21:17:25 +0100279 Drawable dr = null;
280 if (resolvePackageName != null && iconResourceId != 0) {
281 dr = pm.getDrawable(resolvePackageName, iconResourceId, null);
Dianne Hackborneb034652009-09-07 00:49:58 -0700282 }
Jeff Sharkey85f5f812013-10-07 10:16:12 -0700283 ComponentInfo ci = getComponentInfo();
Sudheer Shanka9ded7602015-05-19 21:17:25 +0100284 if (dr == null && iconResourceId != 0) {
285 ApplicationInfo ai = ci.applicationInfo;
286 dr = pm.getDrawable(ci.packageName, iconResourceId, ai);
287 }
288 if (dr != null) {
Jeff Sharkeyad357d12018-02-02 13:25:31 -0700289 return pm.getUserBadgedIcon(dr, new UserHandle(pm.getUserId()));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800290 }
291 return ci.loadIcon(pm);
292 }
Ricky Wai1281b182015-04-29 14:57:04 +0100293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294 /**
295 * Return the icon resource identifier to use for this match. If the
296 * match defines an icon, that is used; else if the activity defines
297 * an icon, that is used; else, the application icon is used.
Ricky Wai1281b182015-04-29 14:57:04 +0100298 * This function does not check noResourceId flag.
299 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800300 * @return The icon associated with this match.
301 */
Ricky Wai1281b182015-04-29 14:57:04 +0100302 final int getIconResourceInternal() {
Sudheer Shanka9ded7602015-05-19 21:17:25 +0100303 if (iconResourceId != 0) return iconResourceId;
Jeff Sharkey85f5f812013-10-07 10:16:12 -0700304 final ComponentInfo ci = getComponentInfo();
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100305 if (ci != null) {
Nicolas Prevot88cc3462014-05-14 14:51:48 +0100306 return ci.getIconResource();
307 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308 return 0;
309 }
310
Ricky Wai1281b182015-04-29 14:57:04 +0100311 /**
312 * Return the icon resource identifier to use for this match. If the
313 * match defines an icon, that is used; else if the activity defines
314 * an icon, that is used; else, the application icon is used.
315 *
316 * @return The icon associated with this match.
317 */
318 public final int getIconResource() {
319 if (noResourceId) return 0;
320 return getIconResourceInternal();
321 }
322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323 public void dump(Printer pw, String prefix) {
Dianne Hackborn6ac42ae2015-12-08 17:22:10 -0800324 dump(pw, prefix, PackageItemInfo.DUMP_FLAG_ALL);
325 }
326
327 /** @hide */
Yohei Yukawa8f272172017-08-31 00:26:01 -0700328 public void dump(Printer pw, String prefix, int dumpFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329 if (filter != null) {
330 pw.println(prefix + "Filter:");
331 filter.dump(pw, prefix + " ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332 }
333 pw.println(prefix + "priority=" + priority
334 + " preferredOrder=" + preferredOrder
335 + " match=0x" + Integer.toHexString(match)
336 + " specificIndex=" + specificIndex
337 + " isDefault=" + isDefault);
Dianne Hackborneb034652009-09-07 00:49:58 -0700338 if (resolvePackageName != null) {
339 pw.println(prefix + "resolvePackageName=" + resolvePackageName);
340 }
341 if (labelRes != 0 || nonLocalizedLabel != null || icon != 0) {
342 pw.println(prefix + "labelRes=0x" + Integer.toHexString(labelRes)
343 + " nonLocalizedLabel=" + nonLocalizedLabel
344 + " icon=0x" + Integer.toHexString(icon));
345 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 if (activityInfo != null) {
347 pw.println(prefix + "ActivityInfo:");
Yohei Yukawa8f272172017-08-31 00:26:01 -0700348 activityInfo.dump(pw, prefix + " ", dumpFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800349 } else if (serviceInfo != null) {
350 pw.println(prefix + "ServiceInfo:");
Yohei Yukawa8f272172017-08-31 00:26:01 -0700351 serviceInfo.dump(pw, prefix + " ", dumpFlags);
Jeff Sharkey85f5f812013-10-07 10:16:12 -0700352 } else if (providerInfo != null) {
353 pw.println(prefix + "ProviderInfo:");
Yohei Yukawa8f272172017-08-31 00:26:01 -0700354 providerInfo.dump(pw, prefix + " ", dumpFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355 }
356 }
Dianne Hackborn6ac42ae2015-12-08 17:22:10 -0800357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358 public ResolveInfo() {
Nicolas Prevot88cc3462014-05-14 14:51:48 +0100359 targetUserId = UserHandle.USER_CURRENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800360 }
361
Dianne Hackborn8da429e2012-09-23 12:52:19 -0700362 public ResolveInfo(ResolveInfo orig) {
363 activityInfo = orig.activityInfo;
364 serviceInfo = orig.serviceInfo;
Jeff Sharkey85f5f812013-10-07 10:16:12 -0700365 providerInfo = orig.providerInfo;
Dianne Hackborn8da429e2012-09-23 12:52:19 -0700366 filter = orig.filter;
367 priority = orig.priority;
368 preferredOrder = orig.preferredOrder;
369 match = orig.match;
370 specificIndex = orig.specificIndex;
371 labelRes = orig.labelRes;
372 nonLocalizedLabel = orig.nonLocalizedLabel;
373 icon = orig.icon;
374 resolvePackageName = orig.resolvePackageName;
Sudheer Shanka9ded7602015-05-19 21:17:25 +0100375 noResourceId = orig.noResourceId;
376 iconResourceId = orig.iconResourceId;
Dianne Hackborn8da429e2012-09-23 12:52:19 -0700377 system = orig.system;
Nicolas Prevot88cc3462014-05-14 14:51:48 +0100378 targetUserId = orig.targetUserId;
Fabrice Di Meglio7d014ce2015-04-08 16:17:46 -0700379 handleAllWebDataURI = orig.handleAllWebDataURI;
Jeff Sharkeyf29d1962017-05-01 15:09:11 -0600380 isInstantAppAvailable = orig.isInstantAppAvailable;
381 instantAppAvailable = isInstantAppAvailable;
Dianne Hackborn8da429e2012-09-23 12:52:19 -0700382 }
383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 public String toString() {
Jeff Sharkey85f5f812013-10-07 10:16:12 -0700385 final ComponentInfo ci = getComponentInfo();
Dianne Hackborn6d8dfbd2013-09-23 17:38:51 -0700386 StringBuilder sb = new StringBuilder(128);
387 sb.append("ResolveInfo{");
388 sb.append(Integer.toHexString(System.identityHashCode(this)));
389 sb.append(' ');
390 ComponentName.appendShortString(sb, ci.packageName, ci.name);
391 if (priority != 0) {
392 sb.append(" p=");
393 sb.append(priority);
394 }
395 if (preferredOrder != 0) {
396 sb.append(" o=");
397 sb.append(preferredOrder);
398 }
399 sb.append(" m=0x");
400 sb.append(Integer.toHexString(match));
Nicolas Prevot88cc3462014-05-14 14:51:48 +0100401 if (targetUserId != UserHandle.USER_CURRENT) {
402 sb.append(" targetUserId=");
403 sb.append(targetUserId);
404 }
Dianne Hackborn6d8dfbd2013-09-23 17:38:51 -0700405 sb.append('}');
406 return sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800407 }
408
409 public int describeContents() {
410 return 0;
411 }
412
413 public void writeToParcel(Parcel dest, int parcelableFlags) {
414 if (activityInfo != null) {
415 dest.writeInt(1);
416 activityInfo.writeToParcel(dest, parcelableFlags);
417 } else if (serviceInfo != null) {
418 dest.writeInt(2);
419 serviceInfo.writeToParcel(dest, parcelableFlags);
Jeff Sharkey85f5f812013-10-07 10:16:12 -0700420 } else if (providerInfo != null) {
421 dest.writeInt(3);
422 providerInfo.writeToParcel(dest, parcelableFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423 } else {
424 dest.writeInt(0);
425 }
426 if (filter != null) {
427 dest.writeInt(1);
428 filter.writeToParcel(dest, parcelableFlags);
429 } else {
430 dest.writeInt(0);
431 }
432 dest.writeInt(priority);
433 dest.writeInt(preferredOrder);
434 dest.writeInt(match);
435 dest.writeInt(specificIndex);
436 dest.writeInt(labelRes);
437 TextUtils.writeToParcel(nonLocalizedLabel, dest, parcelableFlags);
438 dest.writeInt(icon);
Dianne Hackborneb034652009-09-07 00:49:58 -0700439 dest.writeString(resolvePackageName);
Nicolas Prevot88cc3462014-05-14 14:51:48 +0100440 dest.writeInt(targetUserId);
Dianne Hackbornd99b2932011-08-18 14:39:58 -0700441 dest.writeInt(system ? 1 : 0);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100442 dest.writeInt(noResourceId ? 1 : 0);
Sudheer Shanka9ded7602015-05-19 21:17:25 +0100443 dest.writeInt(iconResourceId);
Fabrice Di Meglio7d014ce2015-04-08 16:17:46 -0700444 dest.writeInt(handleAllWebDataURI ? 1 : 0);
Jeff Sharkeyf29d1962017-05-01 15:09:11 -0600445 dest.writeInt(isInstantAppAvailable ? 1 : 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800446 }
447
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700448 public static final @android.annotation.NonNull Creator<ResolveInfo> CREATOR
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449 = new Creator<ResolveInfo>() {
450 public ResolveInfo createFromParcel(Parcel source) {
451 return new ResolveInfo(source);
452 }
453 public ResolveInfo[] newArray(int size) {
454 return new ResolveInfo[size];
455 }
456 };
457
458 private ResolveInfo(Parcel source) {
Jeff Sharkey85f5f812013-10-07 10:16:12 -0700459 activityInfo = null;
460 serviceInfo = null;
461 providerInfo = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 switch (source.readInt()) {
463 case 1:
464 activityInfo = ActivityInfo.CREATOR.createFromParcel(source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800465 break;
466 case 2:
467 serviceInfo = ServiceInfo.CREATOR.createFromParcel(source);
Jeff Sharkey85f5f812013-10-07 10:16:12 -0700468 break;
469 case 3:
470 providerInfo = ProviderInfo.CREATOR.createFromParcel(source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471 break;
472 default:
Jeff Sharkey85f5f812013-10-07 10:16:12 -0700473 Slog.w(TAG, "Missing ComponentInfo!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800474 break;
475 }
476 if (source.readInt() != 0) {
477 filter = IntentFilter.CREATOR.createFromParcel(source);
478 }
479 priority = source.readInt();
480 preferredOrder = source.readInt();
481 match = source.readInt();
482 specificIndex = source.readInt();
483 labelRes = source.readInt();
484 nonLocalizedLabel
485 = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
486 icon = source.readInt();
Dianne Hackborneb034652009-09-07 00:49:58 -0700487 resolvePackageName = source.readString();
Nicolas Prevot88cc3462014-05-14 14:51:48 +0100488 targetUserId = source.readInt();
Dianne Hackbornd99b2932011-08-18 14:39:58 -0700489 system = source.readInt() != 0;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100490 noResourceId = source.readInt() != 0;
Sudheer Shanka9ded7602015-05-19 21:17:25 +0100491 iconResourceId = source.readInt();
Fabrice Di Meglio7d014ce2015-04-08 16:17:46 -0700492 handleAllWebDataURI = source.readInt() != 0;
Jeff Sharkeyf29d1962017-05-01 15:09:11 -0600493 instantAppAvailable = isInstantAppAvailable = source.readInt() != 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800494 }
Sudheer Shanka9ded7602015-05-19 21:17:25 +0100495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 public static class DisplayNameComparator
497 implements Comparator<ResolveInfo> {
498 public DisplayNameComparator(PackageManager pm) {
499 mPM = pm;
Adam Powell0256c6f2013-05-29 16:42:33 -0700500 mCollator.setStrength(Collator.PRIMARY);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 }
502
503 public final int compare(ResolveInfo a, ResolveInfo b) {
Nicolas Prevot88cc3462014-05-14 14:51:48 +0100504 // We want to put the one targeted to another user at the end of the dialog.
505 if (a.targetUserId != UserHandle.USER_CURRENT) {
506 return 1;
507 }
508 if (b.targetUserId != UserHandle.USER_CURRENT) {
509 return -1;
510 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 CharSequence sa = a.loadLabel(mPM);
512 if (sa == null) sa = a.activityInfo.name;
513 CharSequence sb = b.loadLabel(mPM);
514 if (sb == null) sb = b.activityInfo.name;
515
Adam Powell0256c6f2013-05-29 16:42:33 -0700516 return mCollator.compare(sa.toString(), sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 }
518
Adam Powell0256c6f2013-05-29 16:42:33 -0700519 private final Collator mCollator = Collator.getInstance();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520 private PackageManager mPM;
521 }
522}