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