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