ApplicationInfo.java revision d746057f2414cba2bdc69257cc5be8cb681bb592
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
17package android.content.pm;
18
19import android.content.pm.PackageManager.NameNotFoundException;
20import android.content.res.Resources;
21import android.graphics.drawable.Drawable;
22import android.os.Parcel;
23import android.os.Parcelable;
24import android.util.Printer;
25
26import com.android.internal.util.ArrayUtils;
27
28import java.text.Collator;
29import java.util.Arrays;
30import java.util.Comparator;
31import java.util.Objects;
32
33/**
34 * Information you can retrieve about a particular application.  This
35 * corresponds to information collected from the AndroidManifest.xml's
36 * <application> tag.
37 */
38public class ApplicationInfo extends PackageItemInfo implements Parcelable {
39
40    /**
41     * Default task affinity of all activities in this application. See
42     * {@link ActivityInfo#taskAffinity} for more information.  This comes
43     * from the "taskAffinity" attribute.
44     */
45    public String taskAffinity;
46
47    /**
48     * Optional name of a permission required to be able to access this
49     * application's components.  From the "permission" attribute.
50     */
51    public String permission;
52
53    /**
54     * The name of the process this application should run in.  From the
55     * "process" attribute or, if not set, the same as
56     * <var>packageName</var>.
57     */
58    public String processName;
59
60    /**
61     * Class implementing the Application object.  From the "class"
62     * attribute.
63     */
64    public String className;
65
66    /**
67     * A style resource identifier (in the package's resources) of the
68     * description of an application.  From the "description" attribute
69     * or, if not set, 0.
70     */
71    public int descriptionRes;
72
73    /**
74     * A style resource identifier (in the package's resources) of the
75     * default visual theme of the application.  From the "theme" attribute
76     * or, if not set, 0.
77     */
78    public int theme;
79
80    /**
81     * Class implementing the Application's manage space
82     * functionality.  From the "manageSpaceActivity"
83     * attribute. This is an optional attribute and will be null if
84     * applications don't specify it in their manifest
85     */
86    public String manageSpaceActivityName;
87
88    /**
89     * Class implementing the Application's backup functionality.  From
90     * the "backupAgent" attribute.  This is an optional attribute and
91     * will be null if the application does not specify it in its manifest.
92     *
93     * <p>If android:allowBackup is set to false, this attribute is ignored.
94     */
95    public String backupAgentName;
96
97    /**
98     * The default extra UI options for activities in this application.
99     * Set from the {@link android.R.attr#uiOptions} attribute in the
100     * activity's manifest.
101     */
102    public int uiOptions = 0;
103
104    /**
105     * Value for {@link #flags}: if set, this application is installed in the
106     * device's system image.
107     */
108    public static final int FLAG_SYSTEM = 1<<0;
109
110    /**
111     * Value for {@link #flags}: set to true if this application would like to
112     * allow debugging of its
113     * code, even when installed on a non-development system.  Comes
114     * from {@link android.R.styleable#AndroidManifestApplication_debuggable
115     * android:debuggable} of the &lt;application&gt; tag.
116     */
117    public static final int FLAG_DEBUGGABLE = 1<<1;
118
119    /**
120     * Value for {@link #flags}: set to true if this application has code
121     * associated with it.  Comes
122     * from {@link android.R.styleable#AndroidManifestApplication_hasCode
123     * android:hasCode} of the &lt;application&gt; tag.
124     */
125    public static final int FLAG_HAS_CODE = 1<<2;
126
127    /**
128     * Value for {@link #flags}: set to true if this application is persistent.
129     * Comes from {@link android.R.styleable#AndroidManifestApplication_persistent
130     * android:persistent} of the &lt;application&gt; tag.
131     */
132    public static final int FLAG_PERSISTENT = 1<<3;
133
134    /**
135     * Value for {@link #flags}: set to true if this application holds the
136     * {@link android.Manifest.permission#FACTORY_TEST} permission and the
137     * device is running in factory test mode.
138     */
139    public static final int FLAG_FACTORY_TEST = 1<<4;
140
141    /**
142     * Value for {@link #flags}: default value for the corresponding ActivityInfo flag.
143     * Comes from {@link android.R.styleable#AndroidManifestApplication_allowTaskReparenting
144     * android:allowTaskReparenting} of the &lt;application&gt; tag.
145     */
146    public static final int FLAG_ALLOW_TASK_REPARENTING = 1<<5;
147
148    /**
149     * Value for {@link #flags}: default value for the corresponding ActivityInfo flag.
150     * Comes from {@link android.R.styleable#AndroidManifestApplication_allowClearUserData
151     * android:allowClearUserData} of the &lt;application&gt; tag.
152     */
153    public static final int FLAG_ALLOW_CLEAR_USER_DATA = 1<<6;
154
155    /**
156     * Value for {@link #flags}: this is set if this application has been
157     * install as an update to a built-in system application.
158     */
159    public static final int FLAG_UPDATED_SYSTEM_APP = 1<<7;
160
161    /**
162     * Value for {@link #flags}: this is set of the application has specified
163     * {@link android.R.styleable#AndroidManifestApplication_testOnly
164     * android:testOnly} to be true.
165     */
166    public static final int FLAG_TEST_ONLY = 1<<8;
167
168    /**
169     * Value for {@link #flags}: true when the application's window can be
170     * reduced in size for smaller screens.  Corresponds to
171     * {@link android.R.styleable#AndroidManifestSupportsScreens_smallScreens
172     * android:smallScreens}.
173     */
174    public static final int FLAG_SUPPORTS_SMALL_SCREENS = 1<<9;
175
176    /**
177     * Value for {@link #flags}: true when the application's window can be
178     * displayed on normal screens.  Corresponds to
179     * {@link android.R.styleable#AndroidManifestSupportsScreens_normalScreens
180     * android:normalScreens}.
181     */
182    public static final int FLAG_SUPPORTS_NORMAL_SCREENS = 1<<10;
183
184    /**
185     * Value for {@link #flags}: true when the application's window can be
186     * increased in size for larger screens.  Corresponds to
187     * {@link android.R.styleable#AndroidManifestSupportsScreens_largeScreens
188     * android:largeScreens}.
189     */
190    public static final int FLAG_SUPPORTS_LARGE_SCREENS = 1<<11;
191
192    /**
193     * Value for {@link #flags}: true when the application knows how to adjust
194     * its UI for different screen sizes.  Corresponds to
195     * {@link android.R.styleable#AndroidManifestSupportsScreens_resizeable
196     * android:resizeable}.
197     */
198    public static final int FLAG_RESIZEABLE_FOR_SCREENS = 1<<12;
199
200    /**
201     * Value for {@link #flags}: true when the application knows how to
202     * accomodate different screen densities.  Corresponds to
203     * {@link android.R.styleable#AndroidManifestSupportsScreens_anyDensity
204     * android:anyDensity}.
205     */
206    public static final int FLAG_SUPPORTS_SCREEN_DENSITIES = 1<<13;
207
208    /**
209     * Value for {@link #flags}: set to true if this application would like to
210     * request the VM to operate under the safe mode. Comes from
211     * {@link android.R.styleable#AndroidManifestApplication_vmSafeMode
212     * android:vmSafeMode} of the &lt;application&gt; tag.
213     */
214    public static final int FLAG_VM_SAFE_MODE = 1<<14;
215
216    /**
217     * Value for {@link #flags}: set to <code>false</code> if the application does not wish
218     * to permit any OS-driven backups of its data; <code>true</code> otherwise.
219     *
220     * <p>Comes from the
221     * {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup}
222     * attribute of the &lt;application&gt; tag.
223     */
224    public static final int FLAG_ALLOW_BACKUP = 1<<15;
225
226    /**
227     * Value for {@link #flags}: set to <code>false</code> if the application must be kept
228     * in memory following a full-system restore operation; <code>true</code> otherwise.
229     * Ordinarily, during a full system restore operation each application is shut down
230     * following execution of its agent's onRestore() method.  Setting this attribute to
231     * <code>false</code> prevents this.  Most applications will not need to set this attribute.
232     *
233     * <p>If
234     * {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup}
235     * is set to <code>false</code> or no
236     * {@link android.R.styleable#AndroidManifestApplication_backupAgent android:backupAgent}
237     * is specified, this flag will be ignored.
238     *
239     * <p>Comes from the
240     * {@link android.R.styleable#AndroidManifestApplication_killAfterRestore android:killAfterRestore}
241     * attribute of the &lt;application&gt; tag.
242     */
243    public static final int FLAG_KILL_AFTER_RESTORE = 1<<16;
244
245    /**
246     * Value for {@link #flags}: Set to <code>true</code> if the application's backup
247     * agent claims to be able to handle restore data even "from the future,"
248     * i.e. from versions of the application with a versionCode greater than
249     * the one currently installed on the device.  <i>Use with caution!</i>  By default
250     * this attribute is <code>false</code> and the Backup Manager will ensure that data
251     * from "future" versions of the application are never supplied during a restore operation.
252     *
253     * <p>If
254     * {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup}
255     * is set to <code>false</code> or no
256     * {@link android.R.styleable#AndroidManifestApplication_backupAgent android:backupAgent}
257     * is specified, this flag will be ignored.
258     *
259     * <p>Comes from the
260     * {@link android.R.styleable#AndroidManifestApplication_restoreAnyVersion android:restoreAnyVersion}
261     * attribute of the &lt;application&gt; tag.
262     */
263    public static final int FLAG_RESTORE_ANY_VERSION = 1<<17;
264
265    /**
266     * Value for {@link #flags}: Set to true if the application is
267     * currently installed on external/removable/unprotected storage.  Such
268     * applications may not be available if their storage is not currently
269     * mounted.  When the storage it is on is not available, it will look like
270     * the application has been uninstalled (its .apk is no longer available)
271     * but its persistent data is not removed.
272     */
273    public static final int FLAG_EXTERNAL_STORAGE = 1<<18;
274
275    /**
276     * Value for {@link #flags}: true when the application's window can be
277     * increased in size for extra large screens.  Corresponds to
278     * {@link android.R.styleable#AndroidManifestSupportsScreens_xlargeScreens
279     * android:xlargeScreens}.
280     */
281    public static final int FLAG_SUPPORTS_XLARGE_SCREENS = 1<<19;
282
283    /**
284     * Value for {@link #flags}: true when the application has requested a
285     * large heap for its processes.  Corresponds to
286     * {@link android.R.styleable#AndroidManifestApplication_largeHeap
287     * android:largeHeap}.
288     */
289    public static final int FLAG_LARGE_HEAP = 1<<20;
290
291    /**
292     * Value for {@link #flags}: true if this application's package is in
293     * the stopped state.
294     */
295    public static final int FLAG_STOPPED = 1<<21;
296
297    /**
298     * Value for {@link #flags}: true  when the application is willing to support
299     * RTL (right to left). All activities will inherit this value.
300     *
301     * Set from the {@link android.R.attr#supportsRtl} attribute in the
302     * activity's manifest.
303     *
304     * Default value is false (no support for RTL).
305     */
306    public static final int FLAG_SUPPORTS_RTL = 1<<22;
307
308    /**
309     * Value for {@link #flags}: true if the application is currently
310     * installed for the calling user.
311     */
312    public static final int FLAG_INSTALLED = 1<<23;
313
314    /**
315     * Value for {@link #flags}: true if the application only has its
316     * data installed; the application package itself does not currently
317     * exist on the device.
318     */
319    public static final int FLAG_IS_DATA_ONLY = 1<<24;
320
321    /**
322     * Value for {@link #flags}: true if the application was declared to be a game, or
323     * false if it is a non-game application.
324     */
325    public static final int FLAG_IS_GAME = 1<<25;
326
327    /**
328     * Value for {@link #flags}: {@code true} if the application asks that only
329     * full-data streaming backups of its data be performed even though it defines
330     * a {@link android.app.backup.BackupAgent BackupAgent}, which normally
331     * indicates that the app will manage its backed-up data via incremental
332     * key/value updates.
333     */
334    public static final int FLAG_FULL_BACKUP_ONLY = 1<<26;
335
336    /**
337     * Value for {@link #flags}: set to {@code true} if the application
338     * is permitted to hold privileged permissions.
339     *
340     * {@hide}
341     */
342    public static final int FLAG_PRIVILEGED = 1<<30;
343
344    /**
345     * Value for {@link #flags}: Set to true if the application has been
346     * installed using the forward lock option.
347     *
348     * NOTE: DO NOT CHANGE THIS VALUE!  It is saved in packages.xml.
349     *
350     * {@hide}
351     */
352    public static final int FLAG_FORWARD_LOCK = 1<<29;
353
354    /**
355     * Value for {@link #flags}: set to <code>true</code> if the application
356     * has reported that it is heavy-weight, and thus can not participate in
357     * the normal application lifecycle.
358     *
359     * <p>Comes from the
360     * android.R.styleable#AndroidManifestApplication_cantSaveState
361     * attribute of the &lt;application&gt; tag.
362     *
363     * {@hide}
364     */
365    public static final int FLAG_CANT_SAVE_STATE = 1<<28;
366
367    /**
368     * Value for {@link #flags}: true if the application is blocked via restrictions and for
369     * most purposes is considered as not installed.
370     * {@hide}
371     */
372    public static final int FLAG_BLOCKED = 1<<27;
373
374    /**
375     * Flags associated with the application.  Any combination of
376     * {@link #FLAG_SYSTEM}, {@link #FLAG_DEBUGGABLE}, {@link #FLAG_HAS_CODE},
377     * {@link #FLAG_PERSISTENT}, {@link #FLAG_FACTORY_TEST}, and
378     * {@link #FLAG_ALLOW_TASK_REPARENTING}
379     * {@link #FLAG_ALLOW_CLEAR_USER_DATA}, {@link #FLAG_UPDATED_SYSTEM_APP},
380     * {@link #FLAG_TEST_ONLY}, {@link #FLAG_SUPPORTS_SMALL_SCREENS},
381     * {@link #FLAG_SUPPORTS_NORMAL_SCREENS},
382     * {@link #FLAG_SUPPORTS_LARGE_SCREENS}, {@link #FLAG_SUPPORTS_XLARGE_SCREENS},
383     * {@link #FLAG_RESIZEABLE_FOR_SCREENS},
384     * {@link #FLAG_SUPPORTS_SCREEN_DENSITIES}, {@link #FLAG_VM_SAFE_MODE},
385     * {@link #FLAG_INSTALLED}, {@link #FLAG_IS_GAME}.
386     */
387    public int flags = 0;
388
389    /**
390     * The required smallest screen width the application can run on.  If 0,
391     * nothing has been specified.  Comes from
392     * {@link android.R.styleable#AndroidManifestSupportsScreens_requiresSmallestWidthDp
393     * android:requiresSmallestWidthDp} attribute of the &lt;supports-screens&gt; tag.
394     */
395    public int requiresSmallestWidthDp = 0;
396
397    /**
398     * The maximum smallest screen width the application is designed for.  If 0,
399     * nothing has been specified.  Comes from
400     * {@link android.R.styleable#AndroidManifestSupportsScreens_compatibleWidthLimitDp
401     * android:compatibleWidthLimitDp} attribute of the &lt;supports-screens&gt; tag.
402     */
403    public int compatibleWidthLimitDp = 0;
404
405    /**
406     * The maximum smallest screen width the application will work on.  If 0,
407     * nothing has been specified.  Comes from
408     * {@link android.R.styleable#AndroidManifestSupportsScreens_largestWidthLimitDp
409     * android:largestWidthLimitDp} attribute of the &lt;supports-screens&gt; tag.
410     */
411    public int largestWidthLimitDp = 0;
412
413    /** {@hide} */
414    public String scanSourceDir;
415    /** {@hide} */
416    public String scanPublicSourceDir;
417
418    /**
419     * Full path to the base APK for this application.
420     */
421    public String sourceDir;
422
423    /**
424     * Full path to the publicly available parts of {@link #sourceDir},
425     * including resources and manifest. This may be different from
426     * {@link #sourceDir} if an application is forward locked.
427     */
428    public String publicSourceDir;
429
430    /**
431     * Full paths to zero or more split APKs that, when combined with the base
432     * APK defined in {@link #sourceDir}, form a complete application.
433     */
434    public String[] splitSourceDirs;
435
436    /**
437     * Full path to the publicly available parts of {@link #splitSourceDirs},
438     * including resources and manifest. This may be different from
439     * {@link #splitSourceDirs} if an application is forward locked.
440     */
441    public String[] splitPublicSourceDirs;
442
443    /**
444     * Full paths to the locations of extra resource packages this application
445     * uses. This field is only used if there are extra resource packages,
446     * otherwise it is null.
447     *
448     * {@hide}
449     */
450    public String[] resourceDirs;
451
452    /**
453     * String retrieved from the seinfo tag found in selinux policy. This value
454     * is useful in setting an SELinux security context on the process as well
455     * as its data directory.
456     *
457     * {@hide}
458     */
459    public String seinfo;
460
461    /**
462     * Paths to all shared libraries this application is linked against.  This
463     * field is only set if the {@link PackageManager#GET_SHARED_LIBRARY_FILES
464     * PackageManager.GET_SHARED_LIBRARY_FILES} flag was used when retrieving
465     * the structure.
466     */
467    public String[] sharedLibraryFiles;
468
469    /**
470     * Full path to a directory assigned to the package for its persistent
471     * data.
472     */
473    public String dataDir;
474
475    /**
476     * Full path to the directory where native JNI libraries are stored.
477     */
478    public String nativeLibraryDir;
479
480    /**
481     * The ABI that this application requires, This is inferred from the ABIs
482     * of the native JNI libraries the application bundles. Will be {@code null}
483     * if this application does not require any particular ABI.
484     *
485     * {@hide}
486     */
487    public String cpuAbi;
488
489    /**
490     * The kernel user-ID that has been assigned to this application;
491     * currently this is not a unique ID (multiple applications can have
492     * the same uid).
493     */
494    public int uid;
495
496    /**
497     * The minimum SDK version this application targets.  It may run on earlier
498     * versions, but it knows how to work with any new behavior added at this
499     * version.  Will be {@link android.os.Build.VERSION_CODES#CUR_DEVELOPMENT}
500     * if this is a development build and the app is targeting that.  You should
501     * compare that this number is >= the SDK version number at which your
502     * behavior was introduced.
503     */
504    public int targetSdkVersion;
505
506    /**
507     * The app's declared version code.
508     * @hide
509     */
510    public int versionCode;
511
512    /**
513     * When false, indicates that all components within this application are
514     * considered disabled, regardless of their individually set enabled status.
515     */
516    public boolean enabled = true;
517
518    /**
519     * For convenient access to the current enabled setting of this app.
520     * @hide
521     */
522    public int enabledSetting = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
523
524    /**
525     * For convenient access to package's install location.
526     * @hide
527     */
528    public int installLocation = PackageInfo.INSTALL_LOCATION_UNSPECIFIED;
529
530    public void dump(Printer pw, String prefix) {
531        super.dumpFront(pw, prefix);
532        if (className != null) {
533            pw.println(prefix + "className=" + className);
534        }
535        if (permission != null) {
536            pw.println(prefix + "permission=" + permission);
537        }
538        pw.println(prefix + "processName=" + processName);
539        pw.println(prefix + "taskAffinity=" + taskAffinity);
540        pw.println(prefix + "uid=" + uid + " flags=0x" + Integer.toHexString(flags)
541                + " theme=0x" + Integer.toHexString(theme));
542        pw.println(prefix + "requiresSmallestWidthDp=" + requiresSmallestWidthDp
543                + " compatibleWidthLimitDp=" + compatibleWidthLimitDp
544                + " largestWidthLimitDp=" + largestWidthLimitDp);
545        pw.println(prefix + "sourceDir=" + sourceDir);
546        if (!Objects.equals(sourceDir, publicSourceDir)) {
547            pw.println(prefix + "publicSourceDir=" + publicSourceDir);
548        }
549        if (!ArrayUtils.isEmpty(splitSourceDirs)) {
550            pw.println(prefix + "splitSourceDirs=" + Arrays.toString(splitSourceDirs));
551        }
552        if (!ArrayUtils.isEmpty(splitPublicSourceDirs)
553                && !Arrays.equals(splitSourceDirs, splitPublicSourceDirs)) {
554            pw.println(prefix + "splitPublicSourceDirs=" + Arrays.toString(splitPublicSourceDirs));
555        }
556        if (resourceDirs != null) {
557            pw.println(prefix + "resourceDirs=" + resourceDirs);
558        }
559        if (seinfo != null) {
560            pw.println(prefix + "seinfo=" + seinfo);
561        }
562        pw.println(prefix + "dataDir=" + dataDir);
563        if (sharedLibraryFiles != null) {
564            pw.println(prefix + "sharedLibraryFiles=" + sharedLibraryFiles);
565        }
566        pw.println(prefix + "enabled=" + enabled + " targetSdkVersion=" + targetSdkVersion
567                + " versionCode=" + versionCode);
568        if (manageSpaceActivityName != null) {
569            pw.println(prefix + "manageSpaceActivityName="+manageSpaceActivityName);
570        }
571        if (descriptionRes != 0) {
572            pw.println(prefix + "description=0x"+Integer.toHexString(descriptionRes));
573        }
574        if (uiOptions != 0) {
575            pw.println(prefix + "uiOptions=0x" + Integer.toHexString(uiOptions));
576        }
577        pw.println(prefix + "supportsRtl=" + (hasRtlSupport() ? "true" : "false"));
578        super.dumpBack(pw, prefix);
579    }
580
581    /**
582     * @return true if "supportsRtl" has been set to true in the AndroidManifest
583     * @hide
584     */
585    public boolean hasRtlSupport() {
586        return (flags & FLAG_SUPPORTS_RTL) == FLAG_SUPPORTS_RTL;
587    }
588
589    public static class DisplayNameComparator
590            implements Comparator<ApplicationInfo> {
591        public DisplayNameComparator(PackageManager pm) {
592            mPM = pm;
593        }
594
595        public final int compare(ApplicationInfo aa, ApplicationInfo ab) {
596            CharSequence  sa = mPM.getApplicationLabel(aa);
597            if (sa == null) {
598                sa = aa.packageName;
599            }
600            CharSequence  sb = mPM.getApplicationLabel(ab);
601            if (sb == null) {
602                sb = ab.packageName;
603            }
604
605            return sCollator.compare(sa.toString(), sb.toString());
606        }
607
608        private final Collator   sCollator = Collator.getInstance();
609        private PackageManager   mPM;
610    }
611
612    public ApplicationInfo() {
613    }
614
615    public ApplicationInfo(ApplicationInfo orig) {
616        super(orig);
617        taskAffinity = orig.taskAffinity;
618        permission = orig.permission;
619        processName = orig.processName;
620        className = orig.className;
621        theme = orig.theme;
622        flags = orig.flags;
623        requiresSmallestWidthDp = orig.requiresSmallestWidthDp;
624        compatibleWidthLimitDp = orig.compatibleWidthLimitDp;
625        largestWidthLimitDp = orig.largestWidthLimitDp;
626        sourceDir = orig.sourceDir;
627        publicSourceDir = orig.publicSourceDir;
628        splitSourceDirs = orig.splitSourceDirs;
629        splitPublicSourceDirs = orig.splitPublicSourceDirs;
630        nativeLibraryDir = orig.nativeLibraryDir;
631        cpuAbi = orig.cpuAbi;
632        resourceDirs = orig.resourceDirs;
633        seinfo = orig.seinfo;
634        sharedLibraryFiles = orig.sharedLibraryFiles;
635        dataDir = orig.dataDir;
636        uid = orig.uid;
637        targetSdkVersion = orig.targetSdkVersion;
638        versionCode = orig.versionCode;
639        enabled = orig.enabled;
640        enabledSetting = orig.enabledSetting;
641        installLocation = orig.installLocation;
642        manageSpaceActivityName = orig.manageSpaceActivityName;
643        descriptionRes = orig.descriptionRes;
644        uiOptions = orig.uiOptions;
645        backupAgentName = orig.backupAgentName;
646    }
647
648
649    public String toString() {
650        return "ApplicationInfo{"
651            + Integer.toHexString(System.identityHashCode(this))
652            + " " + packageName + "}";
653    }
654
655    public int describeContents() {
656        return 0;
657    }
658
659    public void writeToParcel(Parcel dest, int parcelableFlags) {
660        super.writeToParcel(dest, parcelableFlags);
661        dest.writeString(taskAffinity);
662        dest.writeString(permission);
663        dest.writeString(processName);
664        dest.writeString(className);
665        dest.writeInt(theme);
666        dest.writeInt(flags);
667        dest.writeInt(requiresSmallestWidthDp);
668        dest.writeInt(compatibleWidthLimitDp);
669        dest.writeInt(largestWidthLimitDp);
670        dest.writeString(sourceDir);
671        dest.writeString(publicSourceDir);
672        dest.writeStringArray(splitSourceDirs);
673        dest.writeStringArray(splitPublicSourceDirs);
674        dest.writeString(nativeLibraryDir);
675        dest.writeString(cpuAbi);
676        dest.writeStringArray(resourceDirs);
677        dest.writeString(seinfo);
678        dest.writeStringArray(sharedLibraryFiles);
679        dest.writeString(dataDir);
680        dest.writeInt(uid);
681        dest.writeInt(targetSdkVersion);
682        dest.writeInt(versionCode);
683        dest.writeInt(enabled ? 1 : 0);
684        dest.writeInt(enabledSetting);
685        dest.writeInt(installLocation);
686        dest.writeString(manageSpaceActivityName);
687        dest.writeString(backupAgentName);
688        dest.writeInt(descriptionRes);
689        dest.writeInt(uiOptions);
690    }
691
692    public static final Parcelable.Creator<ApplicationInfo> CREATOR
693            = new Parcelable.Creator<ApplicationInfo>() {
694        public ApplicationInfo createFromParcel(Parcel source) {
695            return new ApplicationInfo(source);
696        }
697        public ApplicationInfo[] newArray(int size) {
698            return new ApplicationInfo[size];
699        }
700    };
701
702    private ApplicationInfo(Parcel source) {
703        super(source);
704        taskAffinity = source.readString();
705        permission = source.readString();
706        processName = source.readString();
707        className = source.readString();
708        theme = source.readInt();
709        flags = source.readInt();
710        requiresSmallestWidthDp = source.readInt();
711        compatibleWidthLimitDp = source.readInt();
712        largestWidthLimitDp = source.readInt();
713        sourceDir = source.readString();
714        publicSourceDir = source.readString();
715        splitSourceDirs = source.readStringArray();
716        splitPublicSourceDirs = source.readStringArray();
717        nativeLibraryDir = source.readString();
718        cpuAbi = source.readString();
719        resourceDirs = source.readStringArray();
720        seinfo = source.readString();
721        sharedLibraryFiles = source.readStringArray();
722        dataDir = source.readString();
723        uid = source.readInt();
724        targetSdkVersion = source.readInt();
725        versionCode = source.readInt();
726        enabled = source.readInt() != 0;
727        enabledSetting = source.readInt();
728        installLocation = source.readInt();
729        manageSpaceActivityName = source.readString();
730        backupAgentName = source.readString();
731        descriptionRes = source.readInt();
732        uiOptions = source.readInt();
733    }
734
735    /**
736     * Retrieve the textual description of the application.  This
737     * will call back on the given PackageManager to load the description from
738     * the application.
739     *
740     * @param pm A PackageManager from which the label can be loaded; usually
741     * the PackageManager from which you originally retrieved this item.
742     *
743     * @return Returns a CharSequence containing the application's description.
744     * If there is no description, null is returned.
745     */
746    public CharSequence loadDescription(PackageManager pm) {
747        if (descriptionRes != 0) {
748            CharSequence label = pm.getText(packageName, descriptionRes, this);
749            if (label != null) {
750                return label;
751            }
752        }
753        return null;
754    }
755
756    /**
757     * Disable compatibility mode
758     *
759     * @hide
760     */
761    public void disableCompatibilityMode() {
762        flags |= (FLAG_SUPPORTS_LARGE_SCREENS | FLAG_SUPPORTS_NORMAL_SCREENS |
763                FLAG_SUPPORTS_SMALL_SCREENS | FLAG_RESIZEABLE_FOR_SCREENS |
764                FLAG_SUPPORTS_SCREEN_DENSITIES | FLAG_SUPPORTS_XLARGE_SCREENS);
765    }
766
767    /**
768     * @hide
769     */
770    @Override protected Drawable loadDefaultIcon(PackageManager pm) {
771        if ((flags & FLAG_EXTERNAL_STORAGE) != 0
772                && isPackageUnavailable(pm)) {
773            return Resources.getSystem().getDrawable(
774                    com.android.internal.R.drawable.sym_app_on_sd_unavailable_icon);
775        }
776        return pm.getDefaultActivityIcon();
777    }
778
779    private boolean isPackageUnavailable(PackageManager pm) {
780        try {
781            return pm.getPackageInfo(packageName, 0) == null;
782        } catch (NameNotFoundException ex) {
783            return true;
784        }
785    }
786
787    /**
788     * @hide
789     */
790    @Override protected ApplicationInfo getApplicationInfo() {
791        return this;
792    }
793
794    /** {@hide} */ public void setCodePath(String codePath) { scanSourceDir = codePath; }
795    /** {@hide} */ public void setBaseCodePath(String baseCodePath) { sourceDir = baseCodePath; }
796    /** {@hide} */ public void setSplitCodePaths(String[] splitCodePaths) { splitSourceDirs = splitCodePaths; }
797    /** {@hide} */ public void setResourcePath(String resourcePath) { scanPublicSourceDir = resourcePath; }
798    /** {@hide} */ public void setBaseResourcePath(String baseResourcePath) { publicSourceDir = baseResourcePath; }
799    /** {@hide} */ public void setSplitResourcePaths(String[] splitResourcePaths) { splitPublicSourceDirs = splitResourcePaths; }
800
801    /** {@hide} */ public String getCodePath() { return scanSourceDir; }
802    /** {@hide} */ public String getBaseCodePath() { return sourceDir; }
803    /** {@hide} */ public String[] getSplitCodePaths() { return splitSourceDirs; }
804    /** {@hide} */ public String getResourcePath() { return scanPublicSourceDir; }
805    /** {@hide} */ public String getBaseResourcePath() { return publicSourceDir; }
806    /** {@hide} */ public String[] getSplitResourcePaths() { return splitSourceDirs; }
807}
808