blob: 53ffd55d5510560500c1292bc3da9fd5fda6ea9c [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
Svetoslav Ganovaa8b0d72016-03-01 14:12:43 -080019import android.annotation.NonNull;
20import android.annotation.SystemApi;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.content.res.XmlResourceParser;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.graphics.drawable.Drawable;
23import android.os.Bundle;
24import android.os.Parcel;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +010025import android.os.UserHandle;
fionaxue630f352016-05-31 14:47:14 -070026import android.text.Html;
Svetoslav Ganovaa8b0d72016-03-01 14:12:43 -080027import android.text.TextPaint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.text.TextUtils;
29import android.util.Printer;
Yi Jin148d7f42017-11-28 14:23:56 -080030import android.util.proto.ProtoOutputStream;
31
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import java.text.Collator;
33import java.util.Comparator;
34
35/**
36 * Base class containing information common to all package items held by
37 * the package manager. This provides a very common basic set of attributes:
38 * a label, icon, and meta-data. This class is not intended
39 * to be used by itself; it is simply here to share common definitions
40 * between all items returned by the package manager. As such, it does not
41 * itself implement Parcelable, but does provide convenience methods to assist
42 * in the implementation of Parcelable in subclasses.
43 */
44public class PackageItemInfo {
Svetoslav Ganovaa8b0d72016-03-01 14:12:43 -080045 private static final float MAX_LABEL_SIZE_PX = 500f;
Jeff Sharkeyb0613dc2018-02-27 14:38:04 -070046
47 private static volatile boolean sForceSafeLabels = false;
48
49 /** {@hide} */
50 public static void setForceSafeLabels(boolean forceSafeLabels) {
51 sForceSafeLabels = forceSafeLabels;
52 }
53
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054 /**
55 * Public name of this item. From the "android:name" attribute.
56 */
57 public String name;
Svet Ganov67882122016-12-11 16:36:34 -080058
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059 /**
60 * Name of the package that this item is in.
61 */
62 public String packageName;
Svet Ganov67882122016-12-11 16:36:34 -080063
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064 /**
65 * A string resource identifier (in the package's resources) of this
66 * component's label. From the "label" attribute or, if not set, 0.
67 */
68 public int labelRes;
Svet Ganov67882122016-12-11 16:36:34 -080069
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070 /**
71 * The string provided in the AndroidManifest file, if any. You
72 * probably don't want to use this. You probably want
73 * {@link PackageManager#getApplicationLabel}
74 */
75 public CharSequence nonLocalizedLabel;
Svet Ganov67882122016-12-11 16:36:34 -080076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077 /**
78 * A drawable resource identifier (in the package's resources) of this
79 * component's icon. From the "icon" attribute or, if not set, 0.
80 */
81 public int icon;
Svet Ganov67882122016-12-11 16:36:34 -080082
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083 /**
Adam Powell81cd2e92010-04-21 16:35:18 -070084 * A drawable resource identifier (in the package's resources) of this
Jose Limaf78e3122014-03-06 12:13:15 -080085 * component's banner. From the "banner" attribute or, if not set, 0.
86 */
87 public int banner;
88
89 /**
90 * A drawable resource identifier (in the package's resources) of this
Adam Powell81cd2e92010-04-21 16:35:18 -070091 * component's logo. Logos may be larger/wider than icons and are
92 * displayed by certain UI elements in place of a name or name/icon
Svet Ganov67882122016-12-11 16:36:34 -080093 * combination. From the "logo" attribute or, if not set, 0.
Adam Powell81cd2e92010-04-21 16:35:18 -070094 */
95 public int logo;
Svet Ganov67882122016-12-11 16:36:34 -080096
Adam Powell81cd2e92010-04-21 16:35:18 -070097 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 * Additional meta-data associated with this component. This field
99 * will only be filled in if you set the
100 * {@link PackageManager#GET_META_DATA} flag when requesting the info.
101 */
102 public Bundle metaData;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100103
104 /**
105 * If different of UserHandle.USER_NULL, The icon of this item will be the one of that user.
106 * @hide
107 */
108 public int showUserIcon;
109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 public PackageItemInfo() {
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100111 showUserIcon = UserHandle.USER_NULL;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112 }
113
114 public PackageItemInfo(PackageItemInfo orig) {
115 name = orig.name;
Romain Guy2aba11f2010-03-29 16:03:01 -0700116 if (name != null) name = name.trim();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 packageName = orig.packageName;
118 labelRes = orig.labelRes;
119 nonLocalizedLabel = orig.nonLocalizedLabel;
Romain Guy2aba11f2010-03-29 16:03:01 -0700120 if (nonLocalizedLabel != null) nonLocalizedLabel = nonLocalizedLabel.toString().trim();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121 icon = orig.icon;
Jose Limaf78e3122014-03-06 12:13:15 -0800122 banner = orig.banner;
Adam Powell81cd2e92010-04-21 16:35:18 -0700123 logo = orig.logo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 metaData = orig.metaData;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100125 showUserIcon = orig.showUserIcon;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126 }
127
128 /**
129 * Retrieve the current textual label associated with this item. This
130 * will call back on the given PackageManager to load the label from
131 * the application.
Svet Ganov67882122016-12-11 16:36:34 -0800132 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 * @param pm A PackageManager from which the label can be loaded; usually
134 * the PackageManager from which you originally retrieved this item.
Svet Ganov67882122016-12-11 16:36:34 -0800135 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136 * @return Returns a CharSequence containing the item's label. If the
137 * item does not have a label, its name is returned.
138 */
Jeff Sharkeyb0613dc2018-02-27 14:38:04 -0700139 public @NonNull CharSequence loadLabel(@NonNull PackageManager pm) {
140 if (sForceSafeLabels) {
141 return loadSafeLabel(pm);
142 } else {
143 return loadUnsafeLabel(pm);
144 }
145 }
146
147 /** {@hide} */
148 public CharSequence loadUnsafeLabel(PackageManager pm) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 if (nonLocalizedLabel != null) {
150 return nonLocalizedLabel;
151 }
152 if (labelRes != 0) {
Jeff Brown07330792010-03-30 19:57:08 -0700153 CharSequence label = pm.getText(packageName, labelRes, getApplicationInfo());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 if (label != null) {
Romain Guy2aba11f2010-03-29 16:03:01 -0700155 return label.toString().trim();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 }
157 }
Romain Guy2aba11f2010-03-29 16:03:01 -0700158 if (name != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 return name;
160 }
161 return packageName;
162 }
Svet Ganov67882122016-12-11 16:36:34 -0800163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 /**
Svetoslav Ganovaa8b0d72016-03-01 14:12:43 -0800165 * Same as {@link #loadLabel(PackageManager)} with the addition that
166 * the returned label is safe for being presented in the UI since it
167 * will not contain new lines and the length will be limited to a
168 * reasonable amount. This prevents a malicious party to influence UI
169 * layout via the app label misleading the user into performing a
170 * detrimental for them action. If the label is too long it will be
171 * truncated and ellipsized at the end.
172 *
173 * @param pm A PackageManager from which the label can be loaded; usually
174 * the PackageManager from which you originally retrieved this item
175 * @return Returns a CharSequence containing the item's label. If the
176 * item does not have a label, its name is returned.
177 *
178 * @hide
179 */
180 @SystemApi
181 public @NonNull CharSequence loadSafeLabel(@NonNull PackageManager pm) {
182 // loadLabel() always returns non-null
Jeff Sharkeyb0613dc2018-02-27 14:38:04 -0700183 String label = loadUnsafeLabel(pm).toString();
fionaxue630f352016-05-31 14:47:14 -0700184 // strip HTML tags to avoid <br> and other tags overwriting original message
185 String labelStr = Html.fromHtml(label).toString();
Svetoslav Ganovaa8b0d72016-03-01 14:12:43 -0800186
187 // If the label contains new line characters it may push the UI
188 // down to hide a part of it. Labels shouldn't have new line
189 // characters, so just truncate at the first time one is seen.
Svetoslav Ganovaa8b0d72016-03-01 14:12:43 -0800190 final int labelLength = labelStr.length();
191 int offset = 0;
192 while (offset < labelLength) {
193 final int codePoint = labelStr.codePointAt(offset);
194 final int type = Character.getType(codePoint);
195 if (type == Character.LINE_SEPARATOR
196 || type == Character.CONTROL
197 || type == Character.PARAGRAPH_SEPARATOR) {
198 labelStr = labelStr.substring(0, offset);
199 break;
200 }
fionaxue630f352016-05-31 14:47:14 -0700201 // replace all non-break space to " " in order to be trimmed
202 if (type == Character.SPACE_SEPARATOR) {
203 labelStr = labelStr.substring(0, offset) + " " + labelStr.substring(offset +
204 Character.charCount(codePoint));
205 }
Svetoslav Ganovaa8b0d72016-03-01 14:12:43 -0800206 offset += Character.charCount(codePoint);
207 }
208
fionaxue630f352016-05-31 14:47:14 -0700209 labelStr = labelStr.trim();
Svetoslav Ganovaa8b0d72016-03-01 14:12:43 -0800210 if (labelStr.isEmpty()) {
fionaxue630f352016-05-31 14:47:14 -0700211 return packageName;
Svetoslav Ganovaa8b0d72016-03-01 14:12:43 -0800212 }
Svetoslav Ganovaa8b0d72016-03-01 14:12:43 -0800213 TextPaint paint = new TextPaint();
214 paint.setTextSize(42);
215
216 return TextUtils.ellipsize(labelStr, paint, MAX_LABEL_SIZE_PX,
217 TextUtils.TruncateAt.END);
218 }
219
220 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 * Retrieve the current graphical icon associated with this item. This
222 * will call back on the given PackageManager to load the icon from
223 * the application.
Svet Ganov67882122016-12-11 16:36:34 -0800224 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 * @param pm A PackageManager from which the icon can be loaded; usually
226 * the PackageManager from which you originally retrieved this item.
Svet Ganov67882122016-12-11 16:36:34 -0800227 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 * @return Returns a Drawable containing the item's icon. If the
Jeff Brown07330792010-03-30 19:57:08 -0700229 * item does not have an icon, the item's default icon is returned
230 * such as the default activity icon.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 */
232 public Drawable loadIcon(PackageManager pm) {
Alexandra Gherghinaa71e3902014-07-25 20:03:47 +0100233 return pm.loadItemIcon(this, getApplicationInfo());
Jeff Brown07330792010-03-30 19:57:08 -0700234 }
Alexandra Gherghinaa71e3902014-07-25 20:03:47 +0100235
Jeff Brown07330792010-03-30 19:57:08 -0700236 /**
Benjamin Franzec2d48b2014-10-01 15:38:43 +0100237 * Retrieve the current graphical icon associated with this item without
238 * the addition of a work badge if applicable.
239 * This will call back on the given PackageManager to load the icon from
240 * the application.
241 *
242 * @param pm A PackageManager from which the icon can be loaded; usually
243 * the PackageManager from which you originally retrieved this item.
244 *
245 * @return Returns a Drawable containing the item's icon. If the
246 * item does not have an icon, the item's default icon is returned
247 * such as the default activity icon.
248 */
249 public Drawable loadUnbadgedIcon(PackageManager pm) {
250 return pm.loadUnbadgedItemIcon(this, getApplicationInfo());
251 }
252
253 /**
Jose Limaf78e3122014-03-06 12:13:15 -0800254 * Retrieve the current graphical banner associated with this item. This
255 * will call back on the given PackageManager to load the banner from
256 * the application.
257 *
258 * @param pm A PackageManager from which the banner can be loaded; usually
259 * the PackageManager from which you originally retrieved this item.
260 *
261 * @return Returns a Drawable containing the item's banner. If the item
262 * does not have a banner, this method will return null.
263 */
264 public Drawable loadBanner(PackageManager pm) {
265 if (banner != 0) {
266 Drawable dr = pm.getDrawable(packageName, banner, getApplicationInfo());
267 if (dr != null) {
268 return dr;
269 }
270 }
271 return loadDefaultBanner(pm);
272 }
273
274 /**
Jeff Brown07330792010-03-30 19:57:08 -0700275 * Retrieve the default graphical icon associated with this item.
Svet Ganov67882122016-12-11 16:36:34 -0800276 *
Jeff Brown07330792010-03-30 19:57:08 -0700277 * @param pm A PackageManager from which the icon can be loaded; usually
278 * the PackageManager from which you originally retrieved this item.
Svet Ganov67882122016-12-11 16:36:34 -0800279 *
Jeff Brown07330792010-03-30 19:57:08 -0700280 * @return Returns a Drawable containing the item's default icon
281 * such as the default activity icon.
Svet Ganov67882122016-12-11 16:36:34 -0800282 *
Jeff Brown07330792010-03-30 19:57:08 -0700283 * @hide
284 */
Alexandra Gherghinaa7093142014-07-30 13:43:39 +0100285 public Drawable loadDefaultIcon(PackageManager pm) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 return pm.getDefaultActivityIcon();
287 }
Jose Limaf78e3122014-03-06 12:13:15 -0800288
289 /**
290 * Retrieve the default graphical banner associated with this item.
291 *
292 * @param pm A PackageManager from which the banner can be loaded; usually
293 * the PackageManager from which you originally retrieved this item.
294 *
295 * @return Returns a Drawable containing the item's default banner
296 * or null if no default logo is available.
297 *
298 * @hide
299 */
300 protected Drawable loadDefaultBanner(PackageManager pm) {
301 return null;
302 }
303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304 /**
Adam Powell81cd2e92010-04-21 16:35:18 -0700305 * Retrieve the current graphical logo associated with this item. This
306 * will call back on the given PackageManager to load the logo from
307 * the application.
Svet Ganov67882122016-12-11 16:36:34 -0800308 *
Adam Powell81cd2e92010-04-21 16:35:18 -0700309 * @param pm A PackageManager from which the logo can be loaded; usually
310 * the PackageManager from which you originally retrieved this item.
Svet Ganov67882122016-12-11 16:36:34 -0800311 *
Adam Powell81cd2e92010-04-21 16:35:18 -0700312 * @return Returns a Drawable containing the item's logo. If the item
313 * does not have a logo, this method will return null.
314 */
315 public Drawable loadLogo(PackageManager pm) {
316 if (logo != 0) {
317 Drawable d = pm.getDrawable(packageName, logo, getApplicationInfo());
318 if (d != null) {
319 return d;
320 }
321 }
322 return loadDefaultLogo(pm);
323 }
Svet Ganov67882122016-12-11 16:36:34 -0800324
Adam Powell81cd2e92010-04-21 16:35:18 -0700325 /**
326 * Retrieve the default graphical logo associated with this item.
Svet Ganov67882122016-12-11 16:36:34 -0800327 *
Adam Powell81cd2e92010-04-21 16:35:18 -0700328 * @param pm A PackageManager from which the logo can be loaded; usually
329 * the PackageManager from which you originally retrieved this item.
Svet Ganov67882122016-12-11 16:36:34 -0800330 *
Adam Powell81cd2e92010-04-21 16:35:18 -0700331 * @return Returns a Drawable containing the item's default logo
332 * or null if no default logo is available.
Svet Ganov67882122016-12-11 16:36:34 -0800333 *
Adam Powell81cd2e92010-04-21 16:35:18 -0700334 * @hide
335 */
336 protected Drawable loadDefaultLogo(PackageManager pm) {
337 return null;
338 }
Svet Ganov67882122016-12-11 16:36:34 -0800339
Adam Powell81cd2e92010-04-21 16:35:18 -0700340 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 * Load an XML resource attached to the meta-data of this item. This will
342 * retrieved the name meta-data entry, and if defined call back on the
343 * given PackageManager to load its XML file from the application.
Svet Ganov67882122016-12-11 16:36:34 -0800344 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345 * @param pm A PackageManager from which the XML can be loaded; usually
346 * the PackageManager from which you originally retrieved this item.
347 * @param name Name of the meta-date you would like to load.
Svet Ganov67882122016-12-11 16:36:34 -0800348 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800349 * @return Returns an XmlPullParser you can use to parse the XML file
350 * assigned as the given meta-data. If the meta-data name is not defined
351 * or the XML resource could not be found, null is returned.
352 */
353 public XmlResourceParser loadXmlMetaData(PackageManager pm, String name) {
354 if (metaData != null) {
355 int resid = metaData.getInt(name);
356 if (resid != 0) {
Jeff Brown07330792010-03-30 19:57:08 -0700357 return pm.getXml(packageName, resid, getApplicationInfo());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358 }
359 }
360 return null;
361 }
Amith Yamasani64442c12012-10-07 08:17:46 -0700362
Dianne Hackborn6ac42ae2015-12-08 17:22:10 -0800363 /**
364 * @hide Flag for dumping: include all details.
365 */
366 public static final int DUMP_FLAG_DETAILS = 1<<0;
367
368 /**
369 * @hide Flag for dumping: include nested ApplicationInfo.
370 */
371 public static final int DUMP_FLAG_APPLICATION = 1<<1;
372
373 /**
374 * @hide Flag for dumping: all flags to dump everything.
375 */
376 public static final int DUMP_FLAG_ALL = DUMP_FLAG_DETAILS | DUMP_FLAG_APPLICATION;
377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 protected void dumpFront(Printer pw, String prefix) {
Dianne Hackborn12527f92009-11-11 17:39:50 -0800379 if (name != null) {
380 pw.println(prefix + "name=" + name);
381 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 pw.println(prefix + "packageName=" + packageName);
Jose Limaf78e3122014-03-06 12:13:15 -0800383 if (labelRes != 0 || nonLocalizedLabel != null || icon != 0 || banner != 0) {
Dianne Hackborn12527f92009-11-11 17:39:50 -0800384 pw.println(prefix + "labelRes=0x" + Integer.toHexString(labelRes)
385 + " nonLocalizedLabel=" + nonLocalizedLabel
Jose Limaf78e3122014-03-06 12:13:15 -0800386 + " icon=0x" + Integer.toHexString(icon)
387 + " banner=0x" + Integer.toHexString(banner));
Dianne Hackborn12527f92009-11-11 17:39:50 -0800388 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 }
Svet Ganov67882122016-12-11 16:36:34 -0800390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 protected void dumpBack(Printer pw, String prefix) {
392 // no back here
393 }
Svet Ganov67882122016-12-11 16:36:34 -0800394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 public void writeToParcel(Parcel dest, int parcelableFlags) {
396 dest.writeString(name);
397 dest.writeString(packageName);
398 dest.writeInt(labelRes);
399 TextUtils.writeToParcel(nonLocalizedLabel, dest, parcelableFlags);
400 dest.writeInt(icon);
Adam Powell81cd2e92010-04-21 16:35:18 -0700401 dest.writeInt(logo);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 dest.writeBundle(metaData);
Jose Limaf78e3122014-03-06 12:13:15 -0800403 dest.writeInt(banner);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100404 dest.writeInt(showUserIcon);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800405 }
Svet Ganov67882122016-12-11 16:36:34 -0800406
Yi Jin148d7f42017-11-28 14:23:56 -0800407 /**
408 * @hide
409 */
410 public void writeToProto(ProtoOutputStream proto, long fieldId) {
411 long token = proto.start(fieldId);
412 if (name != null) {
413 proto.write(PackageItemInfoProto.NAME, name);
414 }
415 proto.write(PackageItemInfoProto.PACKAGE_NAME, packageName);
416 if (labelRes != 0 || nonLocalizedLabel != null || icon != 0 || banner != 0) {
417 proto.write(PackageItemInfoProto.LABEL_RES, labelRes);
418 proto.write(PackageItemInfoProto.NON_LOCALIZED_LABEL, nonLocalizedLabel.toString());
419 proto.write(PackageItemInfoProto.ICON, icon);
420 proto.write(PackageItemInfoProto.BANNER, banner);
421 }
422 proto.end(token);
423 }
424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425 protected PackageItemInfo(Parcel source) {
426 name = source.readString();
427 packageName = source.readString();
428 labelRes = source.readInt();
429 nonLocalizedLabel
430 = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
431 icon = source.readInt();
Adam Powell81cd2e92010-04-21 16:35:18 -0700432 logo = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800433 metaData = source.readBundle();
Jose Limaf78e3122014-03-06 12:13:15 -0800434 banner = source.readInt();
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100435 showUserIcon = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436 }
437
Jeff Brown07330792010-03-30 19:57:08 -0700438 /**
439 * Get the ApplicationInfo for the application to which this item belongs,
440 * if available, otherwise returns null.
Svet Ganov67882122016-12-11 16:36:34 -0800441 *
Jeff Brown07330792010-03-30 19:57:08 -0700442 * @return Returns the ApplicationInfo of this item, or null if not known.
Svet Ganov67882122016-12-11 16:36:34 -0800443 *
Jeff Brown07330792010-03-30 19:57:08 -0700444 * @hide
445 */
446 protected ApplicationInfo getApplicationInfo() {
447 return null;
448 }
449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800450 public static class DisplayNameComparator
451 implements Comparator<PackageItemInfo> {
452 public DisplayNameComparator(PackageManager pm) {
453 mPM = pm;
454 }
455
456 public final int compare(PackageItemInfo aa, PackageItemInfo ab) {
457 CharSequence sa = aa.loadLabel(mPM);
458 if (sa == null) sa = aa.name;
459 CharSequence sb = ab.loadLabel(mPM);
460 if (sb == null) sb = ab.name;
461 return sCollator.compare(sa.toString(), sb.toString());
462 }
463
464 private final Collator sCollator = Collator.getInstance();
465 private PackageManager mPM;
466 }
467}