blob: ff7b34773268a4d8b74fe301d1c85375162a2900 [file] [log] [blame]
Kenny Root15a4d2f2010-03-11 18:20:12 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080017package android.content.pm;
18
Philip P. Moltmannc1fda742018-10-05 16:52:35 -070019import static android.text.TextUtils.SAFE_STRING_FLAG_FIRST_LINE;
20import static android.text.TextUtils.SAFE_STRING_FLAG_SINGLE_LINE;
21import static android.text.TextUtils.SAFE_STRING_FLAG_TRIM;
22import static android.text.TextUtils.makeSafeForPresentation;
Philip P. Moltmanna6f5c702018-04-23 09:09:16 -070023
24import android.annotation.FloatRange;
Svetoslav Ganovaa8b0d72016-03-01 14:12:43 -080025import android.annotation.NonNull;
26import android.annotation.SystemApi;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.content.res.XmlResourceParser;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.graphics.drawable.Drawable;
29import android.os.Bundle;
30import android.os.Parcel;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +010031import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.text.TextUtils;
33import android.util.Printer;
Yi Jin148d7f42017-11-28 14:23:56 -080034import android.util.proto.ProtoOutputStream;
35
Philip P. Moltmanna6f5c702018-04-23 09:09:16 -070036import com.android.internal.util.Preconditions;
37
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import java.text.Collator;
39import java.util.Comparator;
40
41/**
42 * Base class containing information common to all package items held by
43 * the package manager. This provides a very common basic set of attributes:
44 * a label, icon, and meta-data. This class is not intended
45 * to be used by itself; it is simply here to share common definitions
46 * between all items returned by the package manager. As such, it does not
47 * itself implement Parcelable, but does provide convenience methods to assist
48 * in the implementation of Parcelable in subclasses.
49 */
50public class PackageItemInfo {
Todd Kennedy6e403952018-05-03 10:05:04 +010051 /** The maximum length of a safe label, in characters */
52 private static final int MAX_SAFE_LABEL_LENGTH = 50000;
Jeff Sharkeyb0613dc2018-02-27 14:38:04 -070053
Philip P. Moltmanna6f5c702018-04-23 09:09:16 -070054 /** @hide */
55 public static final float DEFAULT_MAX_LABEL_SIZE_PX = 500f;
56
57 /**
Philip P. Moltmanna6f5c702018-04-23 09:09:16 -070058 * Remove {@link Character#isWhitespace(int) whitespace} and non-breaking spaces from the edges
59 * of the label.
60 *
61 * @see #loadSafeLabel(PackageManager, float, int)
Philip P. Moltmannc1fda742018-10-05 16:52:35 -070062 *
63 * @deprecated Use {@link TextUtils#SAFE_STRING_FLAG_TRIM} instead
Philip P. Moltmanna6f5c702018-04-23 09:09:16 -070064 * @hide
65 */
Philip P. Moltmannc1fda742018-10-05 16:52:35 -070066 @Deprecated
Philip P. Moltmanna6f5c702018-04-23 09:09:16 -070067 @SystemApi
Philip P. Moltmannc1fda742018-10-05 16:52:35 -070068 public static final int SAFE_LABEL_FLAG_TRIM = SAFE_STRING_FLAG_TRIM;
Philip P. Moltmanna6f5c702018-04-23 09:09:16 -070069
70 /**
71 * Force entire string into single line of text (no newlines). Cannot be set at the same time as
72 * {@link #SAFE_LABEL_FLAG_FIRST_LINE}.
73 *
74 * @see #loadSafeLabel(PackageManager, float, int)
Philip P. Moltmannc1fda742018-10-05 16:52:35 -070075 *
76 * @deprecated Use {@link TextUtils#SAFE_STRING_FLAG_SINGLE_LINE} instead
Philip P. Moltmanna6f5c702018-04-23 09:09:16 -070077 * @hide
78 */
Philip P. Moltmannc1fda742018-10-05 16:52:35 -070079 @Deprecated
Philip P. Moltmanna6f5c702018-04-23 09:09:16 -070080 @SystemApi
Philip P. Moltmannc1fda742018-10-05 16:52:35 -070081 public static final int SAFE_LABEL_FLAG_SINGLE_LINE = SAFE_STRING_FLAG_SINGLE_LINE;
Philip P. Moltmanna6f5c702018-04-23 09:09:16 -070082
83 /**
84 * Return only first line of text (truncate at first newline). Cannot be set at the same time as
85 * {@link #SAFE_LABEL_FLAG_SINGLE_LINE}.
86 *
87 * @see #loadSafeLabel(PackageManager, float, int)
Philip P. Moltmannc1fda742018-10-05 16:52:35 -070088 *
89 * @deprecated Use {@link TextUtils#SAFE_STRING_FLAG_FIRST_LINE} instead
Philip P. Moltmanna6f5c702018-04-23 09:09:16 -070090 * @hide
91 */
Philip P. Moltmannc1fda742018-10-05 16:52:35 -070092 @Deprecated
Philip P. Moltmanna6f5c702018-04-23 09:09:16 -070093 @SystemApi
Philip P. Moltmannc1fda742018-10-05 16:52:35 -070094 public static final int SAFE_LABEL_FLAG_FIRST_LINE = SAFE_STRING_FLAG_FIRST_LINE;
Philip P. Moltmanna6f5c702018-04-23 09:09:16 -070095
Jeff Sharkeyb0613dc2018-02-27 14:38:04 -070096 private static volatile boolean sForceSafeLabels = false;
97
Philip P. Moltmann6af221c2018-09-18 16:46:52 -070098 /**
99 * Always use {@link #loadSafeLabel safe labels} when calling {@link #loadLabel}.
100 *
Philip P. Moltmann6af221c2018-09-18 16:46:52 -0700101 * @hide
102 */
Philip P. Moltmann2f692632018-08-31 09:30:18 -0700103 @SystemApi
Philip P. Moltmann20dd4312018-10-08 16:56:49 -0700104 public static void forceSafeLabels() {
105 sForceSafeLabels = true;
Jeff Sharkeyb0613dc2018-02-27 14:38:04 -0700106 }
107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 /**
109 * Public name of this item. From the "android:name" attribute.
110 */
111 public String name;
Svet Ganov67882122016-12-11 16:36:34 -0800112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113 /**
114 * Name of the package that this item is in.
115 */
116 public String packageName;
Svet Ganov67882122016-12-11 16:36:34 -0800117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118 /**
119 * A string resource identifier (in the package's resources) of this
120 * component's label. From the "label" attribute or, if not set, 0.
121 */
122 public int labelRes;
Svet Ganov67882122016-12-11 16:36:34 -0800123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 /**
125 * The string provided in the AndroidManifest file, if any. You
126 * probably don't want to use this. You probably want
127 * {@link PackageManager#getApplicationLabel}
128 */
129 public CharSequence nonLocalizedLabel;
Svet Ganov67882122016-12-11 16:36:34 -0800130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131 /**
132 * A drawable resource identifier (in the package's resources) of this
133 * component's icon. From the "icon" attribute or, if not set, 0.
134 */
135 public int icon;
Svet Ganov67882122016-12-11 16:36:34 -0800136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 /**
Adam Powell81cd2e92010-04-21 16:35:18 -0700138 * A drawable resource identifier (in the package's resources) of this
Jose Limaf78e3122014-03-06 12:13:15 -0800139 * component's banner. From the "banner" attribute or, if not set, 0.
140 */
141 public int banner;
142
143 /**
144 * A drawable resource identifier (in the package's resources) of this
Adam Powell81cd2e92010-04-21 16:35:18 -0700145 * component's logo. Logos may be larger/wider than icons and are
146 * displayed by certain UI elements in place of a name or name/icon
Svet Ganov67882122016-12-11 16:36:34 -0800147 * combination. From the "logo" attribute or, if not set, 0.
Adam Powell81cd2e92010-04-21 16:35:18 -0700148 */
149 public int logo;
Svet Ganov67882122016-12-11 16:36:34 -0800150
Adam Powell81cd2e92010-04-21 16:35:18 -0700151 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 * Additional meta-data associated with this component. This field
153 * will only be filled in if you set the
154 * {@link PackageManager#GET_META_DATA} flag when requesting the info.
155 */
156 public Bundle metaData;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100157
158 /**
159 * If different of UserHandle.USER_NULL, The icon of this item will be the one of that user.
160 * @hide
161 */
162 public int showUserIcon;
163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 public PackageItemInfo() {
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100165 showUserIcon = UserHandle.USER_NULL;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 }
167
168 public PackageItemInfo(PackageItemInfo orig) {
169 name = orig.name;
Romain Guy2aba11f2010-03-29 16:03:01 -0700170 if (name != null) name = name.trim();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171 packageName = orig.packageName;
172 labelRes = orig.labelRes;
173 nonLocalizedLabel = orig.nonLocalizedLabel;
Romain Guy2aba11f2010-03-29 16:03:01 -0700174 if (nonLocalizedLabel != null) nonLocalizedLabel = nonLocalizedLabel.toString().trim();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175 icon = orig.icon;
Jose Limaf78e3122014-03-06 12:13:15 -0800176 banner = orig.banner;
Adam Powell81cd2e92010-04-21 16:35:18 -0700177 logo = orig.logo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 metaData = orig.metaData;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100179 showUserIcon = orig.showUserIcon;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800180 }
181
182 /**
183 * Retrieve the current textual label associated with this item. This
184 * will call back on the given PackageManager to load the label from
185 * the application.
Svet Ganov67882122016-12-11 16:36:34 -0800186 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800187 * @param pm A PackageManager from which the label can be loaded; usually
188 * the PackageManager from which you originally retrieved this item.
Svet Ganov67882122016-12-11 16:36:34 -0800189 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 * @return Returns a CharSequence containing the item's label. If the
191 * item does not have a label, its name is returned.
192 */
Jeff Sharkeyb0613dc2018-02-27 14:38:04 -0700193 public @NonNull CharSequence loadLabel(@NonNull PackageManager pm) {
194 if (sForceSafeLabels) {
Philip P. Moltmannc1fda742018-10-05 16:52:35 -0700195 return loadSafeLabel(pm, DEFAULT_MAX_LABEL_SIZE_PX, SAFE_STRING_FLAG_TRIM
196 | SAFE_STRING_FLAG_FIRST_LINE);
Jeff Sharkeyb0613dc2018-02-27 14:38:04 -0700197 } else {
198 return loadUnsafeLabel(pm);
199 }
200 }
201
202 /** {@hide} */
203 public CharSequence loadUnsafeLabel(PackageManager pm) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 if (nonLocalizedLabel != null) {
205 return nonLocalizedLabel;
206 }
207 if (labelRes != 0) {
Jeff Brown07330792010-03-30 19:57:08 -0700208 CharSequence label = pm.getText(packageName, labelRes, getApplicationInfo());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 if (label != null) {
Romain Guy2aba11f2010-03-29 16:03:01 -0700210 return label.toString().trim();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211 }
212 }
Romain Guy2aba11f2010-03-29 16:03:01 -0700213 if (name != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 return name;
215 }
216 return packageName;
217 }
Svet Ganov67882122016-12-11 16:36:34 -0800218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219 /**
Philip P. Moltmanna6f5c702018-04-23 09:09:16 -0700220 * @hide
221 * @deprecated use loadSafeLabel(PackageManager, float, int) instead
222 */
223 @SystemApi
224 @Deprecated
225 public @NonNull CharSequence loadSafeLabel(@NonNull PackageManager pm) {
Philip P. Moltmannc1fda742018-10-05 16:52:35 -0700226 return loadSafeLabel(pm, DEFAULT_MAX_LABEL_SIZE_PX, SAFE_STRING_FLAG_TRIM
227 | SAFE_STRING_FLAG_FIRST_LINE);
Philip P. Moltmanna6f5c702018-04-23 09:09:16 -0700228 }
229
230 /**
Philip P. Moltmannc1fda742018-10-05 16:52:35 -0700231 * Calls {@link TextUtils#makeSafeForPresentation} for the label of this item.
Svetoslav Ganovaa8b0d72016-03-01 14:12:43 -0800232 *
Philip P. Moltmannc1fda742018-10-05 16:52:35 -0700233 * <p>For parameters see {@link TextUtils#makeSafeForPresentation}.
Svetoslav Ganovaa8b0d72016-03-01 14:12:43 -0800234 *
235 * @hide
Philip P. Moltmannc1fda742018-10-05 16:52:35 -0700236 */
Svetoslav Ganovaa8b0d72016-03-01 14:12:43 -0800237 @SystemApi
Philip P. Moltmanna6f5c702018-04-23 09:09:16 -0700238 public @NonNull CharSequence loadSafeLabel(@NonNull PackageManager pm,
Philip P. Moltmannc1fda742018-10-05 16:52:35 -0700239 @FloatRange(from = 0) float ellipsizeDip, @TextUtils.SafeStringFlags int flags) {
Philip P. Moltmanna6f5c702018-04-23 09:09:16 -0700240 Preconditions.checkNotNull(pm);
Philip P. Moltmanna6f5c702018-04-23 09:09:16 -0700241
Philip P. Moltmannc1fda742018-10-05 16:52:35 -0700242 return makeSafeForPresentation(loadUnsafeLabel(pm).toString(), MAX_SAFE_LABEL_LENGTH,
243 ellipsizeDip, flags);
Svetoslav Ganovaa8b0d72016-03-01 14:12:43 -0800244 }
245
246 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247 * Retrieve the current graphical icon associated with this item. This
248 * will call back on the given PackageManager to load the icon from
249 * the application.
Svet Ganov67882122016-12-11 16:36:34 -0800250 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800251 * @param pm A PackageManager from which the icon can be loaded; usually
252 * the PackageManager from which you originally retrieved this item.
Svet Ganov67882122016-12-11 16:36:34 -0800253 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800254 * @return Returns a Drawable containing the item's icon. If the
Jeff Brown07330792010-03-30 19:57:08 -0700255 * item does not have an icon, the item's default icon is returned
256 * such as the default activity icon.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800257 */
258 public Drawable loadIcon(PackageManager pm) {
Alexandra Gherghinaa71e3902014-07-25 20:03:47 +0100259 return pm.loadItemIcon(this, getApplicationInfo());
Jeff Brown07330792010-03-30 19:57:08 -0700260 }
Alexandra Gherghinaa71e3902014-07-25 20:03:47 +0100261
Jeff Brown07330792010-03-30 19:57:08 -0700262 /**
Benjamin Franzec2d48b2014-10-01 15:38:43 +0100263 * Retrieve the current graphical icon associated with this item without
264 * the addition of a work badge if applicable.
265 * This will call back on the given PackageManager to load the icon from
266 * the application.
267 *
268 * @param pm A PackageManager from which the icon can be loaded; usually
269 * the PackageManager from which you originally retrieved this item.
270 *
271 * @return Returns a Drawable containing the item's icon. If the
272 * item does not have an icon, the item's default icon is returned
273 * such as the default activity icon.
274 */
275 public Drawable loadUnbadgedIcon(PackageManager pm) {
276 return pm.loadUnbadgedItemIcon(this, getApplicationInfo());
277 }
278
279 /**
Jose Limaf78e3122014-03-06 12:13:15 -0800280 * Retrieve the current graphical banner associated with this item. This
281 * will call back on the given PackageManager to load the banner from
282 * the application.
283 *
284 * @param pm A PackageManager from which the banner can be loaded; usually
285 * the PackageManager from which you originally retrieved this item.
286 *
287 * @return Returns a Drawable containing the item's banner. If the item
288 * does not have a banner, this method will return null.
289 */
290 public Drawable loadBanner(PackageManager pm) {
291 if (banner != 0) {
292 Drawable dr = pm.getDrawable(packageName, banner, getApplicationInfo());
293 if (dr != null) {
294 return dr;
295 }
296 }
297 return loadDefaultBanner(pm);
298 }
299
300 /**
Jeff Brown07330792010-03-30 19:57:08 -0700301 * Retrieve the default graphical icon associated with this item.
Svet Ganov67882122016-12-11 16:36:34 -0800302 *
Jeff Brown07330792010-03-30 19:57:08 -0700303 * @param pm A PackageManager from which the icon can be loaded; usually
304 * the PackageManager from which you originally retrieved this item.
Svet Ganov67882122016-12-11 16:36:34 -0800305 *
Jeff Brown07330792010-03-30 19:57:08 -0700306 * @return Returns a Drawable containing the item's default icon
307 * such as the default activity icon.
Svet Ganov67882122016-12-11 16:36:34 -0800308 *
Jeff Brown07330792010-03-30 19:57:08 -0700309 * @hide
310 */
Alexandra Gherghinaa7093142014-07-30 13:43:39 +0100311 public Drawable loadDefaultIcon(PackageManager pm) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800312 return pm.getDefaultActivityIcon();
313 }
Jose Limaf78e3122014-03-06 12:13:15 -0800314
315 /**
316 * Retrieve the default graphical banner associated with this item.
317 *
318 * @param pm A PackageManager from which the banner can be loaded; usually
319 * the PackageManager from which you originally retrieved this item.
320 *
321 * @return Returns a Drawable containing the item's default banner
322 * or null if no default logo is available.
323 *
324 * @hide
325 */
326 protected Drawable loadDefaultBanner(PackageManager pm) {
327 return null;
328 }
329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800330 /**
Adam Powell81cd2e92010-04-21 16:35:18 -0700331 * Retrieve the current graphical logo associated with this item. This
332 * will call back on the given PackageManager to load the logo from
333 * the application.
Svet Ganov67882122016-12-11 16:36:34 -0800334 *
Adam Powell81cd2e92010-04-21 16:35:18 -0700335 * @param pm A PackageManager from which the logo can be loaded; usually
336 * the PackageManager from which you originally retrieved this item.
Svet Ganov67882122016-12-11 16:36:34 -0800337 *
Adam Powell81cd2e92010-04-21 16:35:18 -0700338 * @return Returns a Drawable containing the item's logo. If the item
339 * does not have a logo, this method will return null.
340 */
341 public Drawable loadLogo(PackageManager pm) {
342 if (logo != 0) {
343 Drawable d = pm.getDrawable(packageName, logo, getApplicationInfo());
344 if (d != null) {
345 return d;
346 }
347 }
348 return loadDefaultLogo(pm);
349 }
Svet Ganov67882122016-12-11 16:36:34 -0800350
Adam Powell81cd2e92010-04-21 16:35:18 -0700351 /**
352 * Retrieve the default graphical logo associated with this item.
Svet Ganov67882122016-12-11 16:36:34 -0800353 *
Adam Powell81cd2e92010-04-21 16:35:18 -0700354 * @param pm A PackageManager from which the logo can be loaded; usually
355 * the PackageManager from which you originally retrieved this item.
Svet Ganov67882122016-12-11 16:36:34 -0800356 *
Adam Powell81cd2e92010-04-21 16:35:18 -0700357 * @return Returns a Drawable containing the item's default logo
358 * or null if no default logo is available.
Svet Ganov67882122016-12-11 16:36:34 -0800359 *
Adam Powell81cd2e92010-04-21 16:35:18 -0700360 * @hide
361 */
362 protected Drawable loadDefaultLogo(PackageManager pm) {
363 return null;
364 }
Svet Ganov67882122016-12-11 16:36:34 -0800365
Adam Powell81cd2e92010-04-21 16:35:18 -0700366 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 * Load an XML resource attached to the meta-data of this item. This will
368 * retrieved the name meta-data entry, and if defined call back on the
369 * given PackageManager to load its XML file from the application.
Svet Ganov67882122016-12-11 16:36:34 -0800370 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 * @param pm A PackageManager from which the XML can be loaded; usually
372 * the PackageManager from which you originally retrieved this item.
373 * @param name Name of the meta-date you would like to load.
Svet Ganov67882122016-12-11 16:36:34 -0800374 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 * @return Returns an XmlPullParser you can use to parse the XML file
376 * assigned as the given meta-data. If the meta-data name is not defined
377 * or the XML resource could not be found, null is returned.
378 */
379 public XmlResourceParser loadXmlMetaData(PackageManager pm, String name) {
380 if (metaData != null) {
381 int resid = metaData.getInt(name);
382 if (resid != 0) {
Jeff Brown07330792010-03-30 19:57:08 -0700383 return pm.getXml(packageName, resid, getApplicationInfo());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 }
385 }
386 return null;
387 }
Amith Yamasani64442c12012-10-07 08:17:46 -0700388
Dianne Hackborn6ac42ae2015-12-08 17:22:10 -0800389 /**
390 * @hide Flag for dumping: include all details.
391 */
392 public static final int DUMP_FLAG_DETAILS = 1<<0;
393
394 /**
395 * @hide Flag for dumping: include nested ApplicationInfo.
396 */
397 public static final int DUMP_FLAG_APPLICATION = 1<<1;
398
399 /**
400 * @hide Flag for dumping: all flags to dump everything.
401 */
402 public static final int DUMP_FLAG_ALL = DUMP_FLAG_DETAILS | DUMP_FLAG_APPLICATION;
403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 protected void dumpFront(Printer pw, String prefix) {
Dianne Hackborn12527f92009-11-11 17:39:50 -0800405 if (name != null) {
406 pw.println(prefix + "name=" + name);
407 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800408 pw.println(prefix + "packageName=" + packageName);
Jose Limaf78e3122014-03-06 12:13:15 -0800409 if (labelRes != 0 || nonLocalizedLabel != null || icon != 0 || banner != 0) {
Dianne Hackborn12527f92009-11-11 17:39:50 -0800410 pw.println(prefix + "labelRes=0x" + Integer.toHexString(labelRes)
411 + " nonLocalizedLabel=" + nonLocalizedLabel
Jose Limaf78e3122014-03-06 12:13:15 -0800412 + " icon=0x" + Integer.toHexString(icon)
413 + " banner=0x" + Integer.toHexString(banner));
Dianne Hackborn12527f92009-11-11 17:39:50 -0800414 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800415 }
Svet Ganov67882122016-12-11 16:36:34 -0800416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800417 protected void dumpBack(Printer pw, String prefix) {
418 // no back here
419 }
Svet Ganov67882122016-12-11 16:36:34 -0800420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800421 public void writeToParcel(Parcel dest, int parcelableFlags) {
422 dest.writeString(name);
423 dest.writeString(packageName);
424 dest.writeInt(labelRes);
425 TextUtils.writeToParcel(nonLocalizedLabel, dest, parcelableFlags);
426 dest.writeInt(icon);
Adam Powell81cd2e92010-04-21 16:35:18 -0700427 dest.writeInt(logo);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800428 dest.writeBundle(metaData);
Jose Limaf78e3122014-03-06 12:13:15 -0800429 dest.writeInt(banner);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100430 dest.writeInt(showUserIcon);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431 }
Svet Ganov67882122016-12-11 16:36:34 -0800432
Yi Jin148d7f42017-11-28 14:23:56 -0800433 /**
434 * @hide
435 */
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800436 public void writeToProto(ProtoOutputStream proto, long fieldId, int dumpFlags) {
Yi Jin148d7f42017-11-28 14:23:56 -0800437 long token = proto.start(fieldId);
438 if (name != null) {
439 proto.write(PackageItemInfoProto.NAME, name);
440 }
441 proto.write(PackageItemInfoProto.PACKAGE_NAME, packageName);
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800442 proto.write(PackageItemInfoProto.LABEL_RES, labelRes);
443 if (nonLocalizedLabel != null) {
Yi Jin148d7f42017-11-28 14:23:56 -0800444 proto.write(PackageItemInfoProto.NON_LOCALIZED_LABEL, nonLocalizedLabel.toString());
Yi Jin148d7f42017-11-28 14:23:56 -0800445 }
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -0800446 proto.write(PackageItemInfoProto.ICON, icon);
447 proto.write(PackageItemInfoProto.BANNER, banner);
Yi Jin148d7f42017-11-28 14:23:56 -0800448 proto.end(token);
449 }
450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 protected PackageItemInfo(Parcel source) {
452 name = source.readString();
453 packageName = source.readString();
454 labelRes = source.readInt();
455 nonLocalizedLabel
456 = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
457 icon = source.readInt();
Adam Powell81cd2e92010-04-21 16:35:18 -0700458 logo = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800459 metaData = source.readBundle();
Jose Limaf78e3122014-03-06 12:13:15 -0800460 banner = source.readInt();
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100461 showUserIcon = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 }
463
Jeff Brown07330792010-03-30 19:57:08 -0700464 /**
465 * Get the ApplicationInfo for the application to which this item belongs,
466 * if available, otherwise returns null.
Svet Ganov67882122016-12-11 16:36:34 -0800467 *
Jeff Brown07330792010-03-30 19:57:08 -0700468 * @return Returns the ApplicationInfo of this item, or null if not known.
Svet Ganov67882122016-12-11 16:36:34 -0800469 *
Jeff Brown07330792010-03-30 19:57:08 -0700470 * @hide
471 */
472 protected ApplicationInfo getApplicationInfo() {
473 return null;
474 }
475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476 public static class DisplayNameComparator
477 implements Comparator<PackageItemInfo> {
478 public DisplayNameComparator(PackageManager pm) {
479 mPM = pm;
480 }
481
482 public final int compare(PackageItemInfo aa, PackageItemInfo ab) {
483 CharSequence sa = aa.loadLabel(mPM);
484 if (sa == null) sa = aa.name;
485 CharSequence sb = ab.loadLabel(mPM);
486 if (sb == null) sb = ab.name;
487 return sCollator.compare(sa.toString(), sb.toString());
488 }
489
490 private final Collator sCollator = Collator.getInstance();
491 private PackageManager mPM;
492 }
493}