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 | |
Hai Zhang | e029713 | 2019-01-17 18:26:16 -0800 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 20 | import android.annotation.UnsupportedAppUsage; |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 21 | import android.content.ComponentName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.content.IntentFilter; |
| 23 | import android.graphics.drawable.Drawable; |
| 24 | import android.os.Parcel; |
| 25 | import android.os.Parcelable; |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 26 | import android.os.UserHandle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import android.text.TextUtils; |
| 28 | import android.util.Printer; |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 29 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | |
| 31 | import java.text.Collator; |
| 32 | import 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 | */ |
| 40 | public class ResolveInfo implements Parcelable { |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 41 | private static final String TAG = "ResolveInfo"; |
| 42 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | /** |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 44 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | */ |
| 49 | public ActivityInfo activityInfo; |
Sudheer Shanka | 9ded760 | 2015-05-19 21:17:25 +0100 | [diff] [blame] | 50 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | /** |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 52 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | */ |
| 56 | public ServiceInfo serviceInfo; |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 57 | |
| 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | /** |
Todd Kennedy | e991022 | 2017-02-21 16:00:11 -0800 | [diff] [blame] | 66 | * 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 Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 69 | * @hide |
| 70 | */ |
Todd Kennedy | e991022 | 2017-02-21 16:00:11 -0800 | [diff] [blame] | 71 | public AuxiliaryResolveInfo auxiliaryInfo; |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 72 | |
| 73 | /** |
Todd Kennedy | 533c9ff | 2017-02-27 11:45:13 -0800 | [diff] [blame] | 74 | * Whether or not an instant app is available for the resolved intent. |
| 75 | */ |
Jeff Sharkey | f29d196 | 2017-05-01 15:09:11 -0600 | [diff] [blame] | 76 | public boolean isInstantAppAvailable; |
| 77 | |
| 78 | /** @removed */ |
| 79 | @Deprecated |
Todd Kennedy | 533c9ff | 2017-02-27 11:45:13 -0800 | [diff] [blame] | 80 | public boolean instantAppAvailable; |
| 81 | |
| 82 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | * The IntentFilter that was matched for this ResolveInfo. |
| 84 | */ |
| 85 | public IntentFilter filter; |
Sudheer Shanka | 9ded760 | 2015-05-19 21:17:25 +0100 | [diff] [blame] | 86 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | /** |
| 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 Shanka | 9ded760 | 2015-05-19 21:17:25 +0100 | [diff] [blame] | 93 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | /** |
| 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 Shanka | 9ded760 | 2015-05-19 21:17:25 +0100 | [diff] [blame] | 100 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | /** |
| 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 Shanka | 9ded760 | 2015-05-19 21:17:25 +0100 | [diff] [blame] | 108 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | /** |
| 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 Shanka | 9ded760 | 2015-05-19 21:17:25 +0100 | [diff] [blame] | 116 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | /** |
| 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 Shanka | 9ded760 | 2015-05-19 21:17:25 +0100 | [diff] [blame] | 123 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | /** |
| 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 Shanka | 9ded760 | 2015-05-19 21:17:25 +0100 | [diff] [blame] | 129 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | /** |
| 131 | * The actual string retrieve from <var>labelRes</var> or null if none |
| 132 | * was provided. |
| 133 | */ |
| 134 | public CharSequence nonLocalizedLabel; |
Sudheer Shanka | 9ded760 | 2015-05-19 21:17:25 +0100 | [diff] [blame] | 135 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | /** |
| 137 | * A drawable resource identifier (in the package's resources) of this |
Sudheer Shanka | 9ded760 | 2015-05-19 21:17:25 +0100 | [diff] [blame] | 138 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | */ |
| 141 | public int icon; |
| 142 | |
| 143 | /** |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 144 | * 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 Hackborn | d99b293 | 2011-08-18 14:39:58 -0700 | [diff] [blame] | 149 | |
| 150 | /** |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 151 | * If not equal to UserHandle.USER_CURRENT, then the intent will be forwarded to this user. |
| 152 | * @hide |
| 153 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 154 | @UnsupportedAppUsage |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 155 | public int targetUserId; |
| 156 | |
| 157 | /** |
Sudheer Shanka | 9ded760 | 2015-05-19 21:17:25 +0100 | [diff] [blame] | 158 | * 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 Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 161 | * @hide |
| 162 | */ |
Nicolas Prevot | 7f7b0c7 | 2014-06-23 15:59:38 +0100 | [diff] [blame] | 163 | public boolean noResourceId; |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 164 | |
| 165 | /** |
Sudheer Shanka | 9ded760 | 2015-05-19 21:17:25 +0100 | [diff] [blame] | 166 | * 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 Hackborn | d99b293 | 2011-08-18 14:39:58 -0700 | [diff] [blame] | 173 | * @hide Target comes from system process? |
| 174 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 175 | @UnsupportedAppUsage |
Dianne Hackborn | d99b293 | 2011-08-18 14:39:58 -0700 | [diff] [blame] | 176 | public boolean system; |
| 177 | |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 178 | /** |
Hai Zhang | e029713 | 2019-01-17 18:26:16 -0800 | [diff] [blame] | 179 | * 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 Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 183 | */ |
Hai Zhang | e029713 | 2019-01-17 18:26:16 -0800 | [diff] [blame] | 184 | @SystemApi |
Fabrice Di Meglio | 7d014ce | 2015-04-08 16:17:46 -0700 | [diff] [blame] | 185 | public boolean handleAllWebDataURI; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 186 | |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 187 | /** {@hide} */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 188 | @UnsupportedAppUsage |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 189 | public ComponentInfo getComponentInfo() { |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 190 | 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 Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 196 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | * 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 Shanka | 9ded760 | 2015-05-19 21:17:25 +0100 | [diff] [blame] | 200 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | * @param pm A PackageManager from which the label can be loaded; usually |
| 202 | * the PackageManager from which you originally retrieved this item. |
Sudheer Shanka | 9ded760 | 2015-05-19 21:17:25 +0100 | [diff] [blame] | 203 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 204 | * @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 Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 211 | CharSequence label; |
| 212 | if (resolvePackageName != null && labelRes != 0) { |
| 213 | label = pm.getText(resolvePackageName, labelRes, null); |
| 214 | if (label != null) { |
Romain Guy | 2aba11f | 2010-03-29 16:03:01 -0700 | [diff] [blame] | 215 | return label.toString().trim(); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 216 | } |
| 217 | } |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 218 | ComponentInfo ci = getComponentInfo(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 219 | ApplicationInfo ai = ci.applicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 220 | if (labelRes != 0) { |
| 221 | label = pm.getText(ci.packageName, labelRes, ai); |
| 222 | if (label != null) { |
Romain Guy | 2aba11f | 2010-03-29 16:03:01 -0700 | [diff] [blame] | 223 | return label.toString().trim(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | } |
| 225 | } |
Romain Guy | 2aba11f | 2010-03-29 16:03:01 -0700 | [diff] [blame] | 226 | |
| 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | } |
Sudheer Shanka | 9ded760 | 2015-05-19 21:17:25 +0100 | [diff] [blame] | 232 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 233 | /** |
Svet Ganov | d96953a | 2017-10-18 17:12:17 -0700 | [diff] [blame] | 234 | * @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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 268 | * 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 Shanka | 9ded760 | 2015-05-19 21:17:25 +0100 | [diff] [blame] | 271 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | * @param pm A PackageManager from which the icon can be loaded; usually |
| 273 | * the PackageManager from which you originally retrieved this item. |
Sudheer Shanka | 9ded760 | 2015-05-19 21:17:25 +0100 | [diff] [blame] | 274 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | * @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 Shanka | 9ded760 | 2015-05-19 21:17:25 +0100 | [diff] [blame] | 279 | Drawable dr = null; |
| 280 | if (resolvePackageName != null && iconResourceId != 0) { |
| 281 | dr = pm.getDrawable(resolvePackageName, iconResourceId, null); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 282 | } |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 283 | ComponentInfo ci = getComponentInfo(); |
Sudheer Shanka | 9ded760 | 2015-05-19 21:17:25 +0100 | [diff] [blame] | 284 | if (dr == null && iconResourceId != 0) { |
| 285 | ApplicationInfo ai = ci.applicationInfo; |
| 286 | dr = pm.getDrawable(ci.packageName, iconResourceId, ai); |
| 287 | } |
| 288 | if (dr != null) { |
Jeff Sharkey | ad357d1 | 2018-02-02 13:25:31 -0700 | [diff] [blame] | 289 | return pm.getUserBadgedIcon(dr, new UserHandle(pm.getUserId())); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 290 | } |
| 291 | return ci.loadIcon(pm); |
| 292 | } |
Ricky Wai | 1281b18 | 2015-04-29 14:57:04 +0100 | [diff] [blame] | 293 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 294 | /** |
| 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 Wai | 1281b18 | 2015-04-29 14:57:04 +0100 | [diff] [blame] | 298 | * This function does not check noResourceId flag. |
| 299 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 300 | * @return The icon associated with this match. |
| 301 | */ |
Ricky Wai | 1281b18 | 2015-04-29 14:57:04 +0100 | [diff] [blame] | 302 | final int getIconResourceInternal() { |
Sudheer Shanka | 9ded760 | 2015-05-19 21:17:25 +0100 | [diff] [blame] | 303 | if (iconResourceId != 0) return iconResourceId; |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 304 | final ComponentInfo ci = getComponentInfo(); |
Nicolas Prevot | 7f7b0c7 | 2014-06-23 15:59:38 +0100 | [diff] [blame] | 305 | if (ci != null) { |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 306 | return ci.getIconResource(); |
| 307 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 308 | return 0; |
| 309 | } |
| 310 | |
Ricky Wai | 1281b18 | 2015-04-29 14:57:04 +0100 | [diff] [blame] | 311 | /** |
| 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 323 | public void dump(Printer pw, String prefix) { |
Dianne Hackborn | 6ac42ae | 2015-12-08 17:22:10 -0800 | [diff] [blame] | 324 | dump(pw, prefix, PackageItemInfo.DUMP_FLAG_ALL); |
| 325 | } |
| 326 | |
| 327 | /** @hide */ |
Yohei Yukawa | 8f27217 | 2017-08-31 00:26:01 -0700 | [diff] [blame] | 328 | public void dump(Printer pw, String prefix, int dumpFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | if (filter != null) { |
| 330 | pw.println(prefix + "Filter:"); |
| 331 | filter.dump(pw, prefix + " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | } |
| 333 | pw.println(prefix + "priority=" + priority |
| 334 | + " preferredOrder=" + preferredOrder |
| 335 | + " match=0x" + Integer.toHexString(match) |
| 336 | + " specificIndex=" + specificIndex |
| 337 | + " isDefault=" + isDefault); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 338 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 346 | if (activityInfo != null) { |
| 347 | pw.println(prefix + "ActivityInfo:"); |
Yohei Yukawa | 8f27217 | 2017-08-31 00:26:01 -0700 | [diff] [blame] | 348 | activityInfo.dump(pw, prefix + " ", dumpFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 349 | } else if (serviceInfo != null) { |
| 350 | pw.println(prefix + "ServiceInfo:"); |
Yohei Yukawa | 8f27217 | 2017-08-31 00:26:01 -0700 | [diff] [blame] | 351 | serviceInfo.dump(pw, prefix + " ", dumpFlags); |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 352 | } else if (providerInfo != null) { |
| 353 | pw.println(prefix + "ProviderInfo:"); |
Yohei Yukawa | 8f27217 | 2017-08-31 00:26:01 -0700 | [diff] [blame] | 354 | providerInfo.dump(pw, prefix + " ", dumpFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 355 | } |
| 356 | } |
Dianne Hackborn | 6ac42ae | 2015-12-08 17:22:10 -0800 | [diff] [blame] | 357 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 358 | public ResolveInfo() { |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 359 | targetUserId = UserHandle.USER_CURRENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 360 | } |
| 361 | |
Dianne Hackborn | 8da429e | 2012-09-23 12:52:19 -0700 | [diff] [blame] | 362 | public ResolveInfo(ResolveInfo orig) { |
| 363 | activityInfo = orig.activityInfo; |
| 364 | serviceInfo = orig.serviceInfo; |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 365 | providerInfo = orig.providerInfo; |
Dianne Hackborn | 8da429e | 2012-09-23 12:52:19 -0700 | [diff] [blame] | 366 | 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 Shanka | 9ded760 | 2015-05-19 21:17:25 +0100 | [diff] [blame] | 375 | noResourceId = orig.noResourceId; |
| 376 | iconResourceId = orig.iconResourceId; |
Dianne Hackborn | 8da429e | 2012-09-23 12:52:19 -0700 | [diff] [blame] | 377 | system = orig.system; |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 378 | targetUserId = orig.targetUserId; |
Fabrice Di Meglio | 7d014ce | 2015-04-08 16:17:46 -0700 | [diff] [blame] | 379 | handleAllWebDataURI = orig.handleAllWebDataURI; |
Jeff Sharkey | f29d196 | 2017-05-01 15:09:11 -0600 | [diff] [blame] | 380 | isInstantAppAvailable = orig.isInstantAppAvailable; |
| 381 | instantAppAvailable = isInstantAppAvailable; |
Dianne Hackborn | 8da429e | 2012-09-23 12:52:19 -0700 | [diff] [blame] | 382 | } |
| 383 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 384 | public String toString() { |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 385 | final ComponentInfo ci = getComponentInfo(); |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 386 | 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 Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 401 | if (targetUserId != UserHandle.USER_CURRENT) { |
| 402 | sb.append(" targetUserId="); |
| 403 | sb.append(targetUserId); |
| 404 | } |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 405 | sb.append('}'); |
| 406 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 407 | } |
| 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 Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 420 | } else if (providerInfo != null) { |
| 421 | dest.writeInt(3); |
| 422 | providerInfo.writeToParcel(dest, parcelableFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | } 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 Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 439 | dest.writeString(resolvePackageName); |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 440 | dest.writeInt(targetUserId); |
Dianne Hackborn | d99b293 | 2011-08-18 14:39:58 -0700 | [diff] [blame] | 441 | dest.writeInt(system ? 1 : 0); |
Nicolas Prevot | 7f7b0c7 | 2014-06-23 15:59:38 +0100 | [diff] [blame] | 442 | dest.writeInt(noResourceId ? 1 : 0); |
Sudheer Shanka | 9ded760 | 2015-05-19 21:17:25 +0100 | [diff] [blame] | 443 | dest.writeInt(iconResourceId); |
Fabrice Di Meglio | 7d014ce | 2015-04-08 16:17:46 -0700 | [diff] [blame] | 444 | dest.writeInt(handleAllWebDataURI ? 1 : 0); |
Jeff Sharkey | f29d196 | 2017-05-01 15:09:11 -0600 | [diff] [blame] | 445 | dest.writeInt(isInstantAppAvailable ? 1 : 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 446 | } |
| 447 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 448 | public static final @android.annotation.NonNull Creator<ResolveInfo> CREATOR |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 449 | = 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 Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 459 | activityInfo = null; |
| 460 | serviceInfo = null; |
| 461 | providerInfo = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 462 | switch (source.readInt()) { |
| 463 | case 1: |
| 464 | activityInfo = ActivityInfo.CREATOR.createFromParcel(source); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 465 | break; |
| 466 | case 2: |
| 467 | serviceInfo = ServiceInfo.CREATOR.createFromParcel(source); |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 468 | break; |
| 469 | case 3: |
| 470 | providerInfo = ProviderInfo.CREATOR.createFromParcel(source); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | break; |
| 472 | default: |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 473 | Slog.w(TAG, "Missing ComponentInfo!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 474 | 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 Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 487 | resolvePackageName = source.readString(); |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 488 | targetUserId = source.readInt(); |
Dianne Hackborn | d99b293 | 2011-08-18 14:39:58 -0700 | [diff] [blame] | 489 | system = source.readInt() != 0; |
Nicolas Prevot | 7f7b0c7 | 2014-06-23 15:59:38 +0100 | [diff] [blame] | 490 | noResourceId = source.readInt() != 0; |
Sudheer Shanka | 9ded760 | 2015-05-19 21:17:25 +0100 | [diff] [blame] | 491 | iconResourceId = source.readInt(); |
Fabrice Di Meglio | 7d014ce | 2015-04-08 16:17:46 -0700 | [diff] [blame] | 492 | handleAllWebDataURI = source.readInt() != 0; |
Jeff Sharkey | f29d196 | 2017-05-01 15:09:11 -0600 | [diff] [blame] | 493 | instantAppAvailable = isInstantAppAvailable = source.readInt() != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 494 | } |
Sudheer Shanka | 9ded760 | 2015-05-19 21:17:25 +0100 | [diff] [blame] | 495 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | public static class DisplayNameComparator |
| 497 | implements Comparator<ResolveInfo> { |
| 498 | public DisplayNameComparator(PackageManager pm) { |
| 499 | mPM = pm; |
Adam Powell | 0256c6f | 2013-05-29 16:42:33 -0700 | [diff] [blame] | 500 | mCollator.setStrength(Collator.PRIMARY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | public final int compare(ResolveInfo a, ResolveInfo b) { |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 504 | // 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 511 | 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 Powell | 0256c6f | 2013-05-29 16:42:33 -0700 | [diff] [blame] | 516 | return mCollator.compare(sa.toString(), sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 517 | } |
| 518 | |
Adam Powell | 0256c6f | 2013-05-29 16:42:33 -0700 | [diff] [blame] | 519 | private final Collator mCollator = Collator.getInstance(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 520 | private PackageManager mPM; |
| 521 | } |
| 522 | } |