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