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