ApplicationInfo.java revision 7a30a30ebece75f4a73fa604d4c7721d28eecc16
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.Environment;
23import android.os.Parcel;
24import android.os.Parcelable;
25import android.os.SystemProperties;
26import android.os.UserHandle;
27import android.os.storage.StorageManager;
28import android.text.TextUtils;
29import android.util.Printer;
30
31import com.android.internal.util.ArrayUtils;
32
33import java.text.Collator;
34import java.util.Arrays;
35import java.util.Comparator;
36import java.util.Objects;
37
38/**
39 * Information you can retrieve about a particular application.  This
40 * corresponds to information collected from the AndroidManifest.xml's
41 * <application> tag.
42 */
43public class ApplicationInfo extends PackageItemInfo implements Parcelable {
44
45    /**
46     * Default task affinity of all activities in this application. See
47     * {@link ActivityInfo#taskAffinity} for more information.  This comes
48     * from the "taskAffinity" attribute.
49     */
50    public String taskAffinity;
51
52    /**
53     * Optional name of a permission required to be able to access this
54     * application's components.  From the "permission" attribute.
55     */
56    public String permission;
57
58    /**
59     * The name of the process this application should run in.  From the
60     * "process" attribute or, if not set, the same as
61     * <var>packageName</var>.
62     */
63    public String processName;
64
65    /**
66     * Class implementing the Application object.  From the "class"
67     * attribute.
68     */
69    public String className;
70
71    /**
72     * A style resource identifier (in the package's resources) of the
73     * description of an application.  From the "description" attribute
74     * or, if not set, 0.
75     */
76    public int descriptionRes;
77
78    /**
79     * A style resource identifier (in the package's resources) of the
80     * default visual theme of the application.  From the "theme" attribute
81     * or, if not set, 0.
82     */
83    public int theme;
84
85    /**
86     * Class implementing the Application's manage space
87     * functionality.  From the "manageSpaceActivity"
88     * attribute. This is an optional attribute and will be null if
89     * applications don't specify it in their manifest
90     */
91    public String manageSpaceActivityName;
92
93    /**
94     * Class implementing the Application's backup functionality.  From
95     * the "backupAgent" attribute.  This is an optional attribute and
96     * will be null if the application does not specify it in its manifest.
97     *
98     * <p>If android:allowBackup is set to false, this attribute is ignored.
99     */
100    public String backupAgentName;
101
102    /**
103     * An optional attribute that indicates the app supports automatic backup of app data.
104     * <p>0 is the default and means the app's entire data folder + managed external storage will
105     * be backed up;
106     * Any negative value indicates the app does not support full-data backup, though it may still
107     * want to participate via the traditional key/value backup API;
108     * A positive number specifies an xml resource in which the application has defined its backup
109     * include/exclude criteria.
110     * <p>If android:allowBackup is set to false, this attribute is ignored.
111     *
112     * @see {@link android.content.Context#getNoBackupFilesDir}
113     * @see {@link #FLAG_ALLOW_BACKUP}
114     *
115     * @hide
116     */
117    public int fullBackupContent = 0;
118
119    /**
120     * The default extra UI options for activities in this application.
121     * Set from the {@link android.R.attr#uiOptions} attribute in the
122     * activity's manifest.
123     */
124    public int uiOptions = 0;
125
126    /**
127     * Value for {@link #flags}: if set, this application is installed in the
128     * device's system image.
129     */
130    public static final int FLAG_SYSTEM = 1<<0;
131
132    /**
133     * Value for {@link #flags}: set to true if this application would like to
134     * allow debugging of its
135     * code, even when installed on a non-development system.  Comes
136     * from {@link android.R.styleable#AndroidManifestApplication_debuggable
137     * android:debuggable} of the &lt;application&gt; tag.
138     */
139    public static final int FLAG_DEBUGGABLE = 1<<1;
140
141    /**
142     * Value for {@link #flags}: set to true if this application has code
143     * associated with it.  Comes
144     * from {@link android.R.styleable#AndroidManifestApplication_hasCode
145     * android:hasCode} of the &lt;application&gt; tag.
146     */
147    public static final int FLAG_HAS_CODE = 1<<2;
148
149    /**
150     * Value for {@link #flags}: set to true if this application is persistent.
151     * Comes from {@link android.R.styleable#AndroidManifestApplication_persistent
152     * android:persistent} of the &lt;application&gt; tag.
153     */
154    public static final int FLAG_PERSISTENT = 1<<3;
155
156    /**
157     * Value for {@link #flags}: set to true if this application holds the
158     * {@link android.Manifest.permission#FACTORY_TEST} permission and the
159     * device is running in factory test mode.
160     */
161    public static final int FLAG_FACTORY_TEST = 1<<4;
162
163    /**
164     * Value for {@link #flags}: default value for the corresponding ActivityInfo flag.
165     * Comes from {@link android.R.styleable#AndroidManifestApplication_allowTaskReparenting
166     * android:allowTaskReparenting} of the &lt;application&gt; tag.
167     */
168    public static final int FLAG_ALLOW_TASK_REPARENTING = 1<<5;
169
170    /**
171     * Value for {@link #flags}: default value for the corresponding ActivityInfo flag.
172     * Comes from {@link android.R.styleable#AndroidManifestApplication_allowClearUserData
173     * android:allowClearUserData} of the &lt;application&gt; tag.
174     */
175    public static final int FLAG_ALLOW_CLEAR_USER_DATA = 1<<6;
176
177    /**
178     * Value for {@link #flags}: this is set if this application has been
179     * install as an update to a built-in system application.
180     */
181    public static final int FLAG_UPDATED_SYSTEM_APP = 1<<7;
182
183    /**
184     * Value for {@link #flags}: this is set of the application has specified
185     * {@link android.R.styleable#AndroidManifestApplication_testOnly
186     * android:testOnly} to be true.
187     */
188    public static final int FLAG_TEST_ONLY = 1<<8;
189
190    /**
191     * Value for {@link #flags}: true when the application's window can be
192     * reduced in size for smaller screens.  Corresponds to
193     * {@link android.R.styleable#AndroidManifestSupportsScreens_smallScreens
194     * android:smallScreens}.
195     */
196    public static final int FLAG_SUPPORTS_SMALL_SCREENS = 1<<9;
197
198    /**
199     * Value for {@link #flags}: true when the application's window can be
200     * displayed on normal screens.  Corresponds to
201     * {@link android.R.styleable#AndroidManifestSupportsScreens_normalScreens
202     * android:normalScreens}.
203     */
204    public static final int FLAG_SUPPORTS_NORMAL_SCREENS = 1<<10;
205
206    /**
207     * Value for {@link #flags}: true when the application's window can be
208     * increased in size for larger screens.  Corresponds to
209     * {@link android.R.styleable#AndroidManifestSupportsScreens_largeScreens
210     * android:largeScreens}.
211     */
212    public static final int FLAG_SUPPORTS_LARGE_SCREENS = 1<<11;
213
214    /**
215     * Value for {@link #flags}: true when the application knows how to adjust
216     * its UI for different screen sizes.  Corresponds to
217     * {@link android.R.styleable#AndroidManifestSupportsScreens_resizeable
218     * android:resizeable}.
219     */
220    public static final int FLAG_RESIZEABLE_FOR_SCREENS = 1<<12;
221
222    /**
223     * Value for {@link #flags}: true when the application knows how to
224     * accomodate different screen densities.  Corresponds to
225     * {@link android.R.styleable#AndroidManifestSupportsScreens_anyDensity
226     * android:anyDensity}.
227     */
228    public static final int FLAG_SUPPORTS_SCREEN_DENSITIES = 1<<13;
229
230    /**
231     * Value for {@link #flags}: set to true if this application would like to
232     * request the VM to operate under the safe mode. Comes from
233     * {@link android.R.styleable#AndroidManifestApplication_vmSafeMode
234     * android:vmSafeMode} of the &lt;application&gt; tag.
235     */
236    public static final int FLAG_VM_SAFE_MODE = 1<<14;
237
238    /**
239     * Value for {@link #flags}: set to <code>false</code> if the application does not wish
240     * to permit any OS-driven backups of its data; <code>true</code> otherwise.
241     *
242     * <p>Comes from the
243     * {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup}
244     * attribute of the &lt;application&gt; tag.
245     */
246    public static final int FLAG_ALLOW_BACKUP = 1<<15;
247
248    /**
249     * Value for {@link #flags}: set to <code>false</code> if the application must be kept
250     * in memory following a full-system restore operation; <code>true</code> otherwise.
251     * Ordinarily, during a full system restore operation each application is shut down
252     * following execution of its agent's onRestore() method.  Setting this attribute to
253     * <code>false</code> prevents this.  Most applications will not need to set this attribute.
254     *
255     * <p>If
256     * {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup}
257     * is set to <code>false</code> or no
258     * {@link android.R.styleable#AndroidManifestApplication_backupAgent android:backupAgent}
259     * is specified, this flag will be ignored.
260     *
261     * <p>Comes from the
262     * {@link android.R.styleable#AndroidManifestApplication_killAfterRestore android:killAfterRestore}
263     * attribute of the &lt;application&gt; tag.
264     */
265    public static final int FLAG_KILL_AFTER_RESTORE = 1<<16;
266
267    /**
268     * Value for {@link #flags}: Set to <code>true</code> if the application's backup
269     * agent claims to be able to handle restore data even "from the future,"
270     * i.e. from versions of the application with a versionCode greater than
271     * the one currently installed on the device.  <i>Use with caution!</i>  By default
272     * this attribute is <code>false</code> and the Backup Manager will ensure that data
273     * from "future" versions of the application are never supplied during a restore operation.
274     *
275     * <p>If
276     * {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup}
277     * is set to <code>false</code> or no
278     * {@link android.R.styleable#AndroidManifestApplication_backupAgent android:backupAgent}
279     * is specified, this flag will be ignored.
280     *
281     * <p>Comes from the
282     * {@link android.R.styleable#AndroidManifestApplication_restoreAnyVersion android:restoreAnyVersion}
283     * attribute of the &lt;application&gt; tag.
284     */
285    public static final int FLAG_RESTORE_ANY_VERSION = 1<<17;
286
287    /**
288     * Value for {@link #flags}: Set to true if the application is
289     * currently installed on external/removable/unprotected storage.  Such
290     * applications may not be available if their storage is not currently
291     * mounted.  When the storage it is on is not available, it will look like
292     * the application has been uninstalled (its .apk is no longer available)
293     * but its persistent data is not removed.
294     */
295    public static final int FLAG_EXTERNAL_STORAGE = 1<<18;
296
297    /**
298     * Value for {@link #flags}: true when the application's window can be
299     * increased in size for extra large screens.  Corresponds to
300     * {@link android.R.styleable#AndroidManifestSupportsScreens_xlargeScreens
301     * android:xlargeScreens}.
302     */
303    public static final int FLAG_SUPPORTS_XLARGE_SCREENS = 1<<19;
304
305    /**
306     * Value for {@link #flags}: true when the application has requested a
307     * large heap for its processes.  Corresponds to
308     * {@link android.R.styleable#AndroidManifestApplication_largeHeap
309     * android:largeHeap}.
310     */
311    public static final int FLAG_LARGE_HEAP = 1<<20;
312
313    /**
314     * Value for {@link #flags}: true if this application's package is in
315     * the stopped state.
316     */
317    public static final int FLAG_STOPPED = 1<<21;
318
319    /**
320     * Value for {@link #flags}: true  when the application is willing to support
321     * RTL (right to left). All activities will inherit this value.
322     *
323     * Set from the {@link android.R.attr#supportsRtl} attribute in the
324     * activity's manifest.
325     *
326     * Default value is false (no support for RTL).
327     */
328    public static final int FLAG_SUPPORTS_RTL = 1<<22;
329
330    /**
331     * Value for {@link #flags}: true if the application is currently
332     * installed for the calling user.
333     */
334    public static final int FLAG_INSTALLED = 1<<23;
335
336    /**
337     * Value for {@link #flags}: true if the application only has its
338     * data installed; the application package itself does not currently
339     * exist on the device.
340     */
341    public static final int FLAG_IS_DATA_ONLY = 1<<24;
342
343    /**
344     * Value for {@link #flags}: true if the application was declared to be a game, or
345     * false if it is a non-game application.
346     */
347    public static final int FLAG_IS_GAME = 1<<25;
348
349    /**
350     * Value for {@link #flags}: {@code true} if the application asks that only
351     * full-data streaming backups of its data be performed even though it defines
352     * a {@link android.app.backup.BackupAgent BackupAgent}, which normally
353     * indicates that the app will manage its backed-up data via incremental
354     * key/value updates.
355     */
356    public static final int FLAG_FULL_BACKUP_ONLY = 1<<26;
357
358    /**
359     * Value for {@link #flags}: {@code true} if the application may use cleartext network traffic
360     * (e.g., HTTP rather than HTTPS; WebSockets rather than WebSockets Secure; XMPP, IMAP, STMP
361     * without STARTTLS or TLS). If {@code false}, the app declares that it does not intend to use
362     * cleartext network traffic, in which case platform components (e.g., HTTP stacks,
363     * {@code DownloadManager}, {@code MediaPlayer}) will refuse app's requests to use cleartext
364     * traffic. Third-party libraries are encouraged to honor this flag as well.
365     *
366     * <p>NOTE: {@code WebView} does not honor this flag.
367     *
368     * <p>This flag comes from
369     * {@link android.R.styleable#AndroidManifestApplication_usesCleartextTraffic
370     * android:usesCleartextTraffic} of the &lt;application&gt; tag.
371     */
372    public static final int FLAG_USES_CLEARTEXT_TRAFFIC = 1<<27;
373
374    /**
375     * When set installer extracts native libs from .apk files.
376     */
377    public static final int FLAG_EXTRACT_NATIVE_LIBS = 1<<28;
378
379    /**
380     * Value for {@link #flags}: {@code true} when the application's rendering
381     * should be hardware accelerated.
382     */
383    public static final int FLAG_HARDWARE_ACCELERATED = 1<<29;
384
385    /**
386     * Value for {@link #flags}: {@code true} if the application is blocked via restrictions
387     * and for most purposes is considered as not installed.
388     * {@hide}
389     */
390    public static final int FLAG_EPHEMERAL = 1<<30;
391
392    /**
393     * Value for {@link #flags}: true if code from this application will need to be
394     * loaded into other applications' processes. On devices that support multiple
395     * instruction sets, this implies the code might be loaded into a process that's
396     * using any of the devices supported instruction sets.
397     *
398     * <p> The system might treat such applications specially, for eg., by
399     * extracting the application's native libraries for all supported instruction
400     * sets or by compiling the application's dex code for all supported instruction
401     * sets.
402     */
403    public static final int FLAG_MULTIARCH  = 1 << 31;
404
405    /**
406     * Flags associated with the application.  Any combination of
407     * {@link #FLAG_SYSTEM}, {@link #FLAG_DEBUGGABLE}, {@link #FLAG_HAS_CODE},
408     * {@link #FLAG_PERSISTENT}, {@link #FLAG_FACTORY_TEST}, and
409     * {@link #FLAG_ALLOW_TASK_REPARENTING}
410     * {@link #FLAG_ALLOW_CLEAR_USER_DATA}, {@link #FLAG_UPDATED_SYSTEM_APP},
411     * {@link #FLAG_TEST_ONLY}, {@link #FLAG_SUPPORTS_SMALL_SCREENS},
412     * {@link #FLAG_SUPPORTS_NORMAL_SCREENS},
413     * {@link #FLAG_SUPPORTS_LARGE_SCREENS}, {@link #FLAG_SUPPORTS_XLARGE_SCREENS},
414     * {@link #FLAG_RESIZEABLE_FOR_SCREENS},
415     * {@link #FLAG_SUPPORTS_SCREEN_DENSITIES}, {@link #FLAG_VM_SAFE_MODE},
416     * {@link #FLAG_ALLOW_BACKUP}, {@link #FLAG_KILL_AFTER_RESTORE},
417     * {@link #FLAG_RESTORE_ANY_VERSION}, {@link #FLAG_EXTERNAL_STORAGE},
418     * {@link #FLAG_LARGE_HEAP}, {@link #FLAG_STOPPED},
419     * {@link #FLAG_SUPPORTS_RTL}, {@link #FLAG_INSTALLED},
420     * {@link #FLAG_IS_DATA_ONLY}, {@link #FLAG_IS_GAME},
421     * {@link #FLAG_FULL_BACKUP_ONLY}, {@link #FLAG_USES_CLEARTEXT_TRAFFIC},
422     * {@link #FLAG_MULTIARCH}.
423     */
424    public int flags = 0;
425
426    /**
427     * Value for {@link #privateFlags}: true if the application is hidden via restrictions and for
428     * most purposes is considered as not installed.
429     * {@hide}
430     */
431    public static final int PRIVATE_FLAG_HIDDEN = 1<<0;
432
433    /**
434     * Value for {@link #privateFlags}: set to <code>true</code> if the application
435     * has reported that it is heavy-weight, and thus can not participate in
436     * the normal application lifecycle.
437     *
438     * <p>Comes from the
439     * android.R.styleable#AndroidManifestApplication_cantSaveState
440     * attribute of the &lt;application&gt; tag.
441     *
442     * {@hide}
443     */
444    public static final int PRIVATE_FLAG_CANT_SAVE_STATE = 1<<1;
445
446    /**
447     * Value for {@link #privateFlags}: Set to true if the application has been
448     * installed using the forward lock option.
449     *
450     * NOTE: DO NOT CHANGE THIS VALUE!  It is saved in packages.xml.
451     *
452     * {@hide}
453     */
454    public static final int PRIVATE_FLAG_FORWARD_LOCK = 1<<2;
455
456    /**
457     * Value for {@link #privateFlags}: set to {@code true} if the application
458     * is permitted to hold privileged permissions.
459     *
460     * {@hide}
461     */
462    public static final int PRIVATE_FLAG_PRIVILEGED = 1<<3;
463
464    /**
465     * Value for {@link #flags}: {@code true} if the application has any IntentFiler with some
466     * data URI using HTTP or HTTPS with an associated VIEW action.
467     *
468     * {@hide}
469     */
470    public static final int PRIVATE_FLAG_HAS_DOMAIN_URLS = 1<<4;
471
472    /**
473     * When set, default data storage directory for given app is pointed at
474     * device-encrypted location.
475     *
476     * @hide
477     */
478    public static final int PRIVATE_FLAG_FORCE_DEVICE_ENCRYPTED = 1 << 5;
479
480    /**
481     * When set, assume that all components under the given app are encryption
482     * aware, unless otherwise specified.
483     *
484     * @hide
485     */
486    public static final int PRIVATE_FLAG_ENCRYPTION_AWARE = 1 << 6;
487
488    /**
489     * Value for {@link #privateFlags}: set to {@code true} if the application
490     * is AutoPlay.
491     *
492     * {@hide}
493     */
494    public static final int PRIVATE_FLAG_AUTOPLAY = 1 << 7;
495
496    /**
497     * When set, at least one component inside this application is encryption aware.
498     *
499     * @hide
500     */
501    public static final int PRIVATE_FLAG_PARTIALLY_ENCRYPTION_AWARE = 1 << 8;
502
503    /**
504     * Private/hidden flags. See {@code PRIVATE_FLAG_...} constants.
505     * {@hide}
506     */
507    public int privateFlags;
508
509    /**
510     * The required smallest screen width the application can run on.  If 0,
511     * nothing has been specified.  Comes from
512     * {@link android.R.styleable#AndroidManifestSupportsScreens_requiresSmallestWidthDp
513     * android:requiresSmallestWidthDp} attribute of the &lt;supports-screens&gt; tag.
514     */
515    public int requiresSmallestWidthDp = 0;
516
517    /**
518     * The maximum smallest screen width the application is designed for.  If 0,
519     * nothing has been specified.  Comes from
520     * {@link android.R.styleable#AndroidManifestSupportsScreens_compatibleWidthLimitDp
521     * android:compatibleWidthLimitDp} attribute of the &lt;supports-screens&gt; tag.
522     */
523    public int compatibleWidthLimitDp = 0;
524
525    /**
526     * The maximum smallest screen width the application will work on.  If 0,
527     * nothing has been specified.  Comes from
528     * {@link android.R.styleable#AndroidManifestSupportsScreens_largestWidthLimitDp
529     * android:largestWidthLimitDp} attribute of the &lt;supports-screens&gt; tag.
530     */
531    public int largestWidthLimitDp = 0;
532
533    /** {@hide} */
534    public String volumeUuid;
535    /** {@hide} */
536    public String scanSourceDir;
537    /** {@hide} */
538    public String scanPublicSourceDir;
539
540    /**
541     * Full path to the base APK for this application.
542     */
543    public String sourceDir;
544
545    /**
546     * Full path to the publicly available parts of {@link #sourceDir},
547     * including resources and manifest. This may be different from
548     * {@link #sourceDir} if an application is forward locked.
549     */
550    public String publicSourceDir;
551
552    /**
553     * Full paths to zero or more split APKs that, when combined with the base
554     * APK defined in {@link #sourceDir}, form a complete application.
555     */
556    public String[] splitSourceDirs;
557
558    /**
559     * Full path to the publicly available parts of {@link #splitSourceDirs},
560     * including resources and manifest. This may be different from
561     * {@link #splitSourceDirs} if an application is forward locked.
562     */
563    public String[] splitPublicSourceDirs;
564
565    /**
566     * Full paths to the locations of extra resource packages this application
567     * uses. This field is only used if there are extra resource packages,
568     * otherwise it is null.
569     *
570     * {@hide}
571     */
572    public String[] resourceDirs;
573
574    /**
575     * String retrieved from the seinfo tag found in selinux policy. This value
576     * can be overridden with a value set through the mac_permissions.xml policy
577     * construct. This value is useful in setting an SELinux security context on
578     * the process as well as its data directory. The String default is being used
579     * here to represent a catchall label when no policy matches.
580     *
581     * {@hide}
582     */
583    public String seinfo = "default";
584
585    /**
586     * Paths to all shared libraries this application is linked against.  This
587     * field is only set if the {@link PackageManager#GET_SHARED_LIBRARY_FILES
588     * PackageManager.GET_SHARED_LIBRARY_FILES} flag was used when retrieving
589     * the structure.
590     */
591    public String[] sharedLibraryFiles;
592
593    /**
594     * Full path to the default directory assigned to the package for its
595     * persistent data.
596     */
597    public String dataDir;
598
599    /**
600     * Full path to the device-encrypted directory assigned to the package for
601     * its persistent data.
602     */
603    public String deviceEncryptedDataDir;
604
605    /**
606     * Full path to the credential-encrypted directory assigned to the package
607     * for its persistent data.
608     */
609    public String credentialEncryptedDataDir;
610
611    /**
612     * Full path to the directory where native JNI libraries are stored.
613     */
614    public String nativeLibraryDir;
615
616    /**
617     * Full path where unpacked native libraries for {@link #secondaryCpuAbi}
618     * are stored, if present.
619     *
620     * The main reason this exists is for bundled multi-arch apps, where
621     * it's not trivial to calculate the location of libs for the secondary abi
622     * given the location of the primary.
623     *
624     * TODO: Change the layout of bundled installs so that we can use
625     * nativeLibraryRootDir & nativeLibraryRootRequiresIsa there as well.
626     * (e.g {@code [ "/system/app-lib/Foo/arm", "/system/app-lib/Foo/arm64" ]}
627     * instead of {@code [ "/system/lib/Foo", "/system/lib64/Foo" ]}.
628     *
629     * @hide
630     */
631    public String secondaryNativeLibraryDir;
632
633    /**
634     * The root path where unpacked native libraries are stored.
635     * <p>
636     * When {@link #nativeLibraryRootRequiresIsa} is set, the libraries are
637     * placed in ISA-specific subdirectories under this path, otherwise the
638     * libraries are placed directly at this path.
639     *
640     * @hide
641     */
642    public String nativeLibraryRootDir;
643
644    /**
645     * Flag indicating that ISA must be appended to
646     * {@link #nativeLibraryRootDir} to be useful.
647     *
648     * @hide
649     */
650    public boolean nativeLibraryRootRequiresIsa;
651
652    /**
653     * The primary ABI that this application requires, This is inferred from the ABIs
654     * of the native JNI libraries the application bundles. Will be {@code null}
655     * if this application does not require any particular ABI.
656     *
657     * If non-null, the application will always be launched with this ABI.
658     *
659     * {@hide}
660     */
661    public String primaryCpuAbi;
662
663    /**
664     * The secondary ABI for this application. Might be non-null for multi-arch
665     * installs. The application itself never uses this ABI, but other applications that
666     * use its code might.
667     *
668     * {@hide}
669     */
670    public String secondaryCpuAbi;
671
672    /**
673     * The kernel user-ID that has been assigned to this application;
674     * currently this is not a unique ID (multiple applications can have
675     * the same uid).
676     */
677    public int uid;
678
679    /**
680     * The minimum SDK version this application targets.  It may run on earlier
681     * versions, but it knows how to work with any new behavior added at this
682     * version.  Will be {@link android.os.Build.VERSION_CODES#CUR_DEVELOPMENT}
683     * if this is a development build and the app is targeting that.  You should
684     * compare that this number is >= the SDK version number at which your
685     * behavior was introduced.
686     */
687    public int targetSdkVersion;
688
689    /**
690     * The app's declared version code.
691     * @hide
692     */
693    public int versionCode;
694
695    /**
696     * When false, indicates that all components within this application are
697     * considered disabled, regardless of their individually set enabled status.
698     */
699    public boolean enabled = true;
700
701    /**
702     * For convenient access to the current enabled setting of this app.
703     * @hide
704     */
705    public int enabledSetting = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
706
707    /**
708     * For convenient access to package's install location.
709     * @hide
710     */
711    public int installLocation = PackageInfo.INSTALL_LOCATION_UNSPECIFIED;
712
713    public void dump(Printer pw, String prefix) {
714        super.dumpFront(pw, prefix);
715        if (className != null) {
716            pw.println(prefix + "className=" + className);
717        }
718        if (permission != null) {
719            pw.println(prefix + "permission=" + permission);
720        }
721        pw.println(prefix + "processName=" + processName);
722        pw.println(prefix + "taskAffinity=" + taskAffinity);
723        pw.println(prefix + "uid=" + uid + " flags=0x" + Integer.toHexString(flags)
724                + " privateFlags=0x" + Integer.toHexString(privateFlags)
725                + " theme=0x" + Integer.toHexString(theme));
726        pw.println(prefix + "requiresSmallestWidthDp=" + requiresSmallestWidthDp
727                + " compatibleWidthLimitDp=" + compatibleWidthLimitDp
728                + " largestWidthLimitDp=" + largestWidthLimitDp);
729        pw.println(prefix + "sourceDir=" + sourceDir);
730        if (!Objects.equals(sourceDir, publicSourceDir)) {
731            pw.println(prefix + "publicSourceDir=" + publicSourceDir);
732        }
733        if (!ArrayUtils.isEmpty(splitSourceDirs)) {
734            pw.println(prefix + "splitSourceDirs=" + Arrays.toString(splitSourceDirs));
735        }
736        if (!ArrayUtils.isEmpty(splitPublicSourceDirs)
737                && !Arrays.equals(splitSourceDirs, splitPublicSourceDirs)) {
738            pw.println(prefix + "splitPublicSourceDirs=" + Arrays.toString(splitPublicSourceDirs));
739        }
740        if (resourceDirs != null) {
741            pw.println(prefix + "resourceDirs=" + resourceDirs);
742        }
743        if (seinfo != null) {
744            pw.println(prefix + "seinfo=" + seinfo);
745        }
746        pw.println(prefix + "dataDir=" + dataDir);
747        pw.println(prefix + "deviceEncryptedDataDir=" + deviceEncryptedDataDir);
748        pw.println(prefix + "credentialEncryptedDataDir=" + credentialEncryptedDataDir);
749        if (sharedLibraryFiles != null) {
750            pw.println(prefix + "sharedLibraryFiles=" + Arrays.toString(sharedLibraryFiles));
751        }
752        pw.println(prefix + "enabled=" + enabled + " targetSdkVersion=" + targetSdkVersion
753                + " versionCode=" + versionCode);
754        if (manageSpaceActivityName != null) {
755            pw.println(prefix + "manageSpaceActivityName="+manageSpaceActivityName);
756        }
757        if (descriptionRes != 0) {
758            pw.println(prefix + "description=0x"+Integer.toHexString(descriptionRes));
759        }
760        if (uiOptions != 0) {
761            pw.println(prefix + "uiOptions=0x" + Integer.toHexString(uiOptions));
762        }
763        pw.println(prefix + "supportsRtl=" + (hasRtlSupport() ? "true" : "false"));
764        if (fullBackupContent > 0) {
765            pw.println(prefix + "fullBackupContent=@xml/" + fullBackupContent);
766        } else {
767            pw.println(prefix + "fullBackupContent=" + (fullBackupContent < 0 ? "false" : "true"));
768        }
769        super.dumpBack(pw, prefix);
770    }
771
772    /**
773     * @return true if "supportsRtl" has been set to true in the AndroidManifest
774     * @hide
775     */
776    public boolean hasRtlSupport() {
777        return (flags & FLAG_SUPPORTS_RTL) == FLAG_SUPPORTS_RTL;
778    }
779
780    public static class DisplayNameComparator
781            implements Comparator<ApplicationInfo> {
782        public DisplayNameComparator(PackageManager pm) {
783            mPM = pm;
784        }
785
786        public final int compare(ApplicationInfo aa, ApplicationInfo ab) {
787            CharSequence  sa = mPM.getApplicationLabel(aa);
788            if (sa == null) {
789                sa = aa.packageName;
790            }
791            CharSequence  sb = mPM.getApplicationLabel(ab);
792            if (sb == null) {
793                sb = ab.packageName;
794            }
795
796            return sCollator.compare(sa.toString(), sb.toString());
797        }
798
799        private final Collator   sCollator = Collator.getInstance();
800        private PackageManager   mPM;
801    }
802
803    public ApplicationInfo() {
804    }
805
806    public ApplicationInfo(ApplicationInfo orig) {
807        super(orig);
808        taskAffinity = orig.taskAffinity;
809        permission = orig.permission;
810        processName = orig.processName;
811        className = orig.className;
812        theme = orig.theme;
813        flags = orig.flags;
814        privateFlags = orig.privateFlags;
815        requiresSmallestWidthDp = orig.requiresSmallestWidthDp;
816        compatibleWidthLimitDp = orig.compatibleWidthLimitDp;
817        largestWidthLimitDp = orig.largestWidthLimitDp;
818        volumeUuid = orig.volumeUuid;
819        scanSourceDir = orig.scanSourceDir;
820        scanPublicSourceDir = orig.scanPublicSourceDir;
821        sourceDir = orig.sourceDir;
822        publicSourceDir = orig.publicSourceDir;
823        splitSourceDirs = orig.splitSourceDirs;
824        splitPublicSourceDirs = orig.splitPublicSourceDirs;
825        nativeLibraryDir = orig.nativeLibraryDir;
826        secondaryNativeLibraryDir = orig.secondaryNativeLibraryDir;
827        nativeLibraryRootDir = orig.nativeLibraryRootDir;
828        nativeLibraryRootRequiresIsa = orig.nativeLibraryRootRequiresIsa;
829        primaryCpuAbi = orig.primaryCpuAbi;
830        secondaryCpuAbi = orig.secondaryCpuAbi;
831        resourceDirs = orig.resourceDirs;
832        seinfo = orig.seinfo;
833        sharedLibraryFiles = orig.sharedLibraryFiles;
834        dataDir = orig.dataDir;
835        deviceEncryptedDataDir = orig.deviceEncryptedDataDir;
836        credentialEncryptedDataDir = orig.credentialEncryptedDataDir;
837        uid = orig.uid;
838        targetSdkVersion = orig.targetSdkVersion;
839        versionCode = orig.versionCode;
840        enabled = orig.enabled;
841        enabledSetting = orig.enabledSetting;
842        installLocation = orig.installLocation;
843        manageSpaceActivityName = orig.manageSpaceActivityName;
844        descriptionRes = orig.descriptionRes;
845        uiOptions = orig.uiOptions;
846        backupAgentName = orig.backupAgentName;
847        fullBackupContent = orig.fullBackupContent;
848    }
849
850    public String toString() {
851        return "ApplicationInfo{"
852            + Integer.toHexString(System.identityHashCode(this))
853            + " " + packageName + "}";
854    }
855
856    public int describeContents() {
857        return 0;
858    }
859
860    public void writeToParcel(Parcel dest, int parcelableFlags) {
861        super.writeToParcel(dest, parcelableFlags);
862        dest.writeString(taskAffinity);
863        dest.writeString(permission);
864        dest.writeString(processName);
865        dest.writeString(className);
866        dest.writeInt(theme);
867        dest.writeInt(flags);
868        dest.writeInt(privateFlags);
869        dest.writeInt(requiresSmallestWidthDp);
870        dest.writeInt(compatibleWidthLimitDp);
871        dest.writeInt(largestWidthLimitDp);
872        dest.writeString(volumeUuid);
873        dest.writeString(scanSourceDir);
874        dest.writeString(scanPublicSourceDir);
875        dest.writeString(sourceDir);
876        dest.writeString(publicSourceDir);
877        dest.writeStringArray(splitSourceDirs);
878        dest.writeStringArray(splitPublicSourceDirs);
879        dest.writeString(nativeLibraryDir);
880        dest.writeString(secondaryNativeLibraryDir);
881        dest.writeString(nativeLibraryRootDir);
882        dest.writeInt(nativeLibraryRootRequiresIsa ? 1 : 0);
883        dest.writeString(primaryCpuAbi);
884        dest.writeString(secondaryCpuAbi);
885        dest.writeStringArray(resourceDirs);
886        dest.writeString(seinfo);
887        dest.writeStringArray(sharedLibraryFiles);
888        dest.writeString(dataDir);
889        dest.writeString(deviceEncryptedDataDir);
890        dest.writeString(credentialEncryptedDataDir);
891        dest.writeInt(uid);
892        dest.writeInt(targetSdkVersion);
893        dest.writeInt(versionCode);
894        dest.writeInt(enabled ? 1 : 0);
895        dest.writeInt(enabledSetting);
896        dest.writeInt(installLocation);
897        dest.writeString(manageSpaceActivityName);
898        dest.writeString(backupAgentName);
899        dest.writeInt(descriptionRes);
900        dest.writeInt(uiOptions);
901        dest.writeInt(fullBackupContent);
902    }
903
904    public static final Parcelable.Creator<ApplicationInfo> CREATOR
905            = new Parcelable.Creator<ApplicationInfo>() {
906        public ApplicationInfo createFromParcel(Parcel source) {
907            return new ApplicationInfo(source);
908        }
909        public ApplicationInfo[] newArray(int size) {
910            return new ApplicationInfo[size];
911        }
912    };
913
914    private ApplicationInfo(Parcel source) {
915        super(source);
916        taskAffinity = source.readString();
917        permission = source.readString();
918        processName = source.readString();
919        className = source.readString();
920        theme = source.readInt();
921        flags = source.readInt();
922        privateFlags = source.readInt();
923        requiresSmallestWidthDp = source.readInt();
924        compatibleWidthLimitDp = source.readInt();
925        largestWidthLimitDp = source.readInt();
926        volumeUuid = source.readString();
927        scanSourceDir = source.readString();
928        scanPublicSourceDir = source.readString();
929        sourceDir = source.readString();
930        publicSourceDir = source.readString();
931        splitSourceDirs = source.readStringArray();
932        splitPublicSourceDirs = source.readStringArray();
933        nativeLibraryDir = source.readString();
934        secondaryNativeLibraryDir = source.readString();
935        nativeLibraryRootDir = source.readString();
936        nativeLibraryRootRequiresIsa = source.readInt() != 0;
937        primaryCpuAbi = source.readString();
938        secondaryCpuAbi = source.readString();
939        resourceDirs = source.readStringArray();
940        seinfo = source.readString();
941        sharedLibraryFiles = source.readStringArray();
942        dataDir = source.readString();
943        deviceEncryptedDataDir = source.readString();
944        credentialEncryptedDataDir = source.readString();
945        uid = source.readInt();
946        targetSdkVersion = source.readInt();
947        versionCode = source.readInt();
948        enabled = source.readInt() != 0;
949        enabledSetting = source.readInt();
950        installLocation = source.readInt();
951        manageSpaceActivityName = source.readString();
952        backupAgentName = source.readString();
953        descriptionRes = source.readInt();
954        uiOptions = source.readInt();
955        fullBackupContent = source.readInt();
956    }
957
958    /**
959     * Retrieve the textual description of the application.  This
960     * will call back on the given PackageManager to load the description from
961     * the application.
962     *
963     * @param pm A PackageManager from which the label can be loaded; usually
964     * the PackageManager from which you originally retrieved this item.
965     *
966     * @return Returns a CharSequence containing the application's description.
967     * If there is no description, null is returned.
968     */
969    public CharSequence loadDescription(PackageManager pm) {
970        if (descriptionRes != 0) {
971            CharSequence label = pm.getText(packageName, descriptionRes, this);
972            if (label != null) {
973                return label;
974            }
975        }
976        return null;
977    }
978
979    /**
980     * Disable compatibility mode
981     *
982     * @hide
983     */
984    public void disableCompatibilityMode() {
985        flags |= (FLAG_SUPPORTS_LARGE_SCREENS | FLAG_SUPPORTS_NORMAL_SCREENS |
986                FLAG_SUPPORTS_SMALL_SCREENS | FLAG_RESIZEABLE_FOR_SCREENS |
987                FLAG_SUPPORTS_SCREEN_DENSITIES | FLAG_SUPPORTS_XLARGE_SCREENS);
988    }
989
990    /** {@hide} */
991    public void initForUser(int userId) {
992        uid = UserHandle.getUid(userId, UserHandle.getAppId(uid));
993
994        if ("android".equals(packageName)) {
995            dataDir = Environment.getDataSystemDirectory().getAbsolutePath();
996            return;
997        }
998
999        deviceEncryptedDataDir = Environment
1000                .getDataUserDeviceEncryptedPackageDirectory(volumeUuid, userId, packageName)
1001                .getAbsolutePath();
1002        credentialEncryptedDataDir = Environment
1003                .getDataUserCredentialEncryptedPackageDirectory(volumeUuid, userId, packageName)
1004                .getAbsolutePath();
1005
1006        if ((privateFlags & PRIVATE_FLAG_FORCE_DEVICE_ENCRYPTED) != 0
1007                && StorageManager.isFileBasedEncryptionEnabled()) {
1008            dataDir = deviceEncryptedDataDir;
1009        } else {
1010            dataDir = credentialEncryptedDataDir;
1011        }
1012    }
1013
1014    /**
1015     * @hide
1016     */
1017    @Override
1018    public Drawable loadDefaultIcon(PackageManager pm) {
1019        if ((flags & FLAG_EXTERNAL_STORAGE) != 0
1020                && isPackageUnavailable(pm)) {
1021            return Resources.getSystem().getDrawable(
1022                    com.android.internal.R.drawable.sym_app_on_sd_unavailable_icon);
1023        }
1024        return pm.getDefaultActivityIcon();
1025    }
1026
1027    private boolean isPackageUnavailable(PackageManager pm) {
1028        try {
1029            return pm.getPackageInfo(packageName, 0) == null;
1030        } catch (NameNotFoundException ex) {
1031            return true;
1032        }
1033    }
1034
1035    /**
1036     * @hide
1037     */
1038    public boolean isForwardLocked() {
1039        return (privateFlags & ApplicationInfo.PRIVATE_FLAG_FORWARD_LOCK) != 0;
1040    }
1041
1042    /**
1043     * @hide
1044     */
1045    public boolean isSystemApp() {
1046        return (flags & ApplicationInfo.FLAG_SYSTEM) != 0;
1047    }
1048
1049    /**
1050     * @hide
1051     */
1052    public boolean isPrivilegedApp() {
1053        return (privateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0;
1054    }
1055
1056    /**
1057     * @hide
1058     */
1059    public boolean isUpdatedSystemApp() {
1060        return (flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0;
1061    }
1062
1063    /** @hide */
1064    public boolean isInternal() {
1065        return (flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) == 0;
1066    }
1067
1068    /** @hide */
1069    public boolean isExternalAsec() {
1070        return TextUtils.isEmpty(volumeUuid)
1071                && (flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0;
1072    }
1073
1074    /** @hide */
1075    public boolean isEncryptionAware() {
1076        return (privateFlags & ApplicationInfo.PRIVATE_FLAG_ENCRYPTION_AWARE) != 0;
1077    }
1078
1079    /** @hide */
1080    public boolean isPartiallyEncryptionAware() {
1081        return (privateFlags & ApplicationInfo.PRIVATE_FLAG_PARTIALLY_ENCRYPTION_AWARE) != 0;
1082    }
1083
1084    /**
1085     * @hide
1086     */
1087    public boolean isAutoPlayApp() {
1088        return (privateFlags & ApplicationInfo.PRIVATE_FLAG_AUTOPLAY) != 0;
1089    }
1090
1091    /**
1092     * @hide
1093     */
1094    @Override protected ApplicationInfo getApplicationInfo() {
1095        return this;
1096    }
1097
1098    /** {@hide} */ public void setCodePath(String codePath) { scanSourceDir = codePath; }
1099    /** {@hide} */ public void setBaseCodePath(String baseCodePath) { sourceDir = baseCodePath; }
1100    /** {@hide} */ public void setSplitCodePaths(String[] splitCodePaths) { splitSourceDirs = splitCodePaths; }
1101    /** {@hide} */ public void setResourcePath(String resourcePath) { scanPublicSourceDir = resourcePath; }
1102    /** {@hide} */ public void setBaseResourcePath(String baseResourcePath) { publicSourceDir = baseResourcePath; }
1103    /** {@hide} */ public void setSplitResourcePaths(String[] splitResourcePaths) { splitPublicSourceDirs = splitResourcePaths; }
1104
1105    /** {@hide} */ public String getCodePath() { return scanSourceDir; }
1106    /** {@hide} */ public String getBaseCodePath() { return sourceDir; }
1107    /** {@hide} */ public String[] getSplitCodePaths() { return splitSourceDirs; }
1108    /** {@hide} */ public String getResourcePath() { return scanPublicSourceDir; }
1109    /** {@hide} */ public String getBaseResourcePath() { return publicSourceDir; }
1110    /** {@hide} */ public String[] getSplitResourcePaths() { return splitSourceDirs; }
1111}
1112