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 
17 package android.content.pm;
18 
19 import static android.os.Build.VERSION_CODES.DONUT;
20 
21 import android.annotation.IntDef;
22 import android.annotation.Nullable;
23 import android.annotation.SystemApi;
24 import android.annotation.TestApi;
25 import android.compat.annotation.UnsupportedAppUsage;
26 import android.content.Context;
27 import android.content.pm.PackageManager.NameNotFoundException;
28 import android.content.res.Resources;
29 import android.graphics.drawable.Drawable;
30 import android.os.Build;
31 import android.os.Environment;
32 import android.os.Parcel;
33 import android.os.Parcelable;
34 import android.os.UserHandle;
35 import android.os.storage.StorageManager;
36 import android.util.Printer;
37 import android.util.SparseArray;
38 import android.util.proto.ProtoOutputStream;
39 
40 import com.android.internal.util.ArrayUtils;
41 import com.android.server.SystemConfig;
42 
43 import java.lang.annotation.Retention;
44 import java.lang.annotation.RetentionPolicy;
45 import java.text.Collator;
46 import java.util.ArrayList;
47 import java.util.Arrays;
48 import java.util.Comparator;
49 import java.util.List;
50 import java.util.Objects;
51 import java.util.UUID;
52 
53 /**
54  * Information you can retrieve about a particular application.  This
55  * corresponds to information collected from the AndroidManifest.xml's
56  * <application> tag.
57  */
58 public class ApplicationInfo extends PackageItemInfo implements Parcelable {
59     /**
60      * Default task affinity of all activities in this application. See
61      * {@link ActivityInfo#taskAffinity} for more information.  This comes
62      * from the "taskAffinity" attribute.
63      */
64     public String taskAffinity;
65 
66     /**
67      * Optional name of a permission required to be able to access this
68      * application's components.  From the "permission" attribute.
69      */
70     public String permission;
71 
72     /**
73      * The name of the process this application should run in.  From the
74      * "process" attribute or, if not set, the same as
75      * <var>packageName</var>.
76      */
77     public String processName;
78 
79     /**
80      * Class implementing the Application object.  From the "class"
81      * attribute.
82      */
83     public String className;
84 
85     /**
86      * A style resource identifier (in the package's resources) of the
87      * description of an application.  From the "description" attribute
88      * or, if not set, 0.
89      */
90     public int descriptionRes;
91 
92     /**
93      * A style resource identifier (in the package's resources) of the
94      * default visual theme of the application.  From the "theme" attribute
95      * or, if not set, 0.
96      */
97     public int theme;
98 
99     /**
100      * Class implementing the Application's manage space
101      * functionality.  From the "manageSpaceActivity"
102      * attribute. This is an optional attribute and will be null if
103      * applications don't specify it in their manifest
104      */
105     public String manageSpaceActivityName;
106 
107     /**
108      * Class implementing the Application's backup functionality.  From
109      * the "backupAgent" attribute.  This is an optional attribute and
110      * will be null if the application does not specify it in its manifest.
111      *
112      * <p>If android:allowBackup is set to false, this attribute is ignored.
113      */
114     public String backupAgentName;
115 
116     /**
117      * An optional attribute that indicates the app supports automatic backup of app data.
118      * <p>0 is the default and means the app's entire data folder + managed external storage will
119      * be backed up;
120      * Any negative value indicates the app does not support full-data backup, though it may still
121      * want to participate via the traditional key/value backup API;
122      * A positive number specifies an xml resource in which the application has defined its backup
123      * include/exclude criteria.
124      * <p>If android:allowBackup is set to false, this attribute is ignored.
125      *
126      * @see android.content.Context#getNoBackupFilesDir()
127      * @see #FLAG_ALLOW_BACKUP
128      *
129      * @hide
130      */
131     @UnsupportedAppUsage
132     public int fullBackupContent = 0;
133 
134     /**
135      * <code>true</code> if the package is capable of presenting a unified interface representing
136      * multiple profiles.
137      * @hide
138      */
139     public boolean crossProfile;
140 
141     /**
142      * The default extra UI options for activities in this application.
143      * Set from the {@link android.R.attr#uiOptions} attribute in the
144      * activity's manifest.
145      */
146     public int uiOptions = 0;
147 
148     /**
149      * Value for {@link #flags}: if set, this application is installed in the
150      * device's system image.
151      */
152     public static final int FLAG_SYSTEM = 1<<0;
153 
154     /**
155      * Value for {@link #flags}: set to true if this application would like to
156      * allow debugging of its
157      * code, even when installed on a non-development system.  Comes
158      * from {@link android.R.styleable#AndroidManifestApplication_debuggable
159      * android:debuggable} of the &lt;application&gt; tag.
160      */
161     public static final int FLAG_DEBUGGABLE = 1<<1;
162 
163     /**
164      * Value for {@link #flags}: set to true if this application has code
165      * associated with it.  Comes
166      * from {@link android.R.styleable#AndroidManifestApplication_hasCode
167      * android:hasCode} of the &lt;application&gt; tag.
168      */
169     public static final int FLAG_HAS_CODE = 1<<2;
170 
171     /**
172      * Value for {@link #flags}: set to true if this application is persistent.
173      * Comes from {@link android.R.styleable#AndroidManifestApplication_persistent
174      * android:persistent} of the &lt;application&gt; tag.
175      */
176     public static final int FLAG_PERSISTENT = 1<<3;
177 
178     /**
179      * Value for {@link #flags}: set to true if this application holds the
180      * {@link android.Manifest.permission#FACTORY_TEST} permission and the
181      * device is running in factory test mode.
182      */
183     public static final int FLAG_FACTORY_TEST = 1<<4;
184 
185     /**
186      * Value for {@link #flags}: default value for the corresponding ActivityInfo flag.
187      * Comes from {@link android.R.styleable#AndroidManifestApplication_allowTaskReparenting
188      * android:allowTaskReparenting} of the &lt;application&gt; tag.
189      */
190     public static final int FLAG_ALLOW_TASK_REPARENTING = 1<<5;
191 
192     /**
193      * Value for {@link #flags}: default value for the corresponding ActivityInfo flag.
194      * Comes from {@link android.R.styleable#AndroidManifestApplication_allowClearUserData
195      * android:allowClearUserData} of the &lt;application&gt; tag.
196      */
197     public static final int FLAG_ALLOW_CLEAR_USER_DATA = 1<<6;
198 
199     /**
200      * Value for {@link #flags}: this is set if this application has been
201      * installed as an update to a built-in system application.
202      */
203     public static final int FLAG_UPDATED_SYSTEM_APP = 1<<7;
204 
205     /**
206      * Value for {@link #flags}: this is set if the application has specified
207      * {@link android.R.styleable#AndroidManifestApplication_testOnly
208      * android:testOnly} to be true.
209      */
210     public static final int FLAG_TEST_ONLY = 1<<8;
211 
212     /**
213      * Value for {@link #flags}: true when the application's window can be
214      * reduced in size for smaller screens.  Corresponds to
215      * {@link android.R.styleable#AndroidManifestSupportsScreens_smallScreens
216      * android:smallScreens}.
217      */
218     public static final int FLAG_SUPPORTS_SMALL_SCREENS = 1<<9;
219 
220     /**
221      * Value for {@link #flags}: true when the application's window can be
222      * displayed on normal screens.  Corresponds to
223      * {@link android.R.styleable#AndroidManifestSupportsScreens_normalScreens
224      * android:normalScreens}.
225      */
226     public static final int FLAG_SUPPORTS_NORMAL_SCREENS = 1<<10;
227 
228     /**
229      * Value for {@link #flags}: true when the application's window can be
230      * increased in size for larger screens.  Corresponds to
231      * {@link android.R.styleable#AndroidManifestSupportsScreens_largeScreens
232      * android:largeScreens}.
233      */
234     public static final int FLAG_SUPPORTS_LARGE_SCREENS = 1<<11;
235 
236     /**
237      * Value for {@link #flags}: true when the application knows how to adjust
238      * its UI for different screen sizes.  Corresponds to
239      * {@link android.R.styleable#AndroidManifestSupportsScreens_resizeable
240      * android:resizeable}.
241      */
242     public static final int FLAG_RESIZEABLE_FOR_SCREENS = 1<<12;
243 
244     /**
245      * Value for {@link #flags}: true when the application knows how to
246      * accommodate different screen densities.  Corresponds to
247      * {@link android.R.styleable#AndroidManifestSupportsScreens_anyDensity
248      * android:anyDensity}.
249      *
250      * @deprecated Set by default when targeting API 4 or higher and apps
251      *             should not set this to false.
252      */
253     @Deprecated
254     public static final int FLAG_SUPPORTS_SCREEN_DENSITIES = 1<<13;
255 
256     /**
257      * Value for {@link #flags}: set to true if this application would like to
258      * request the VM to operate under the safe mode. Comes from
259      * {@link android.R.styleable#AndroidManifestApplication_vmSafeMode
260      * android:vmSafeMode} of the &lt;application&gt; tag.
261      */
262     public static final int FLAG_VM_SAFE_MODE = 1<<14;
263 
264     /**
265      * Value for {@link #flags}: set to <code>false</code> if the application does not wish
266      * to permit any OS-driven backups of its data; <code>true</code> otherwise.
267      *
268      * <p>Comes from the
269      * {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup}
270      * attribute of the &lt;application&gt; tag.
271      */
272     public static final int FLAG_ALLOW_BACKUP = 1<<15;
273 
274     /**
275      * Value for {@link #flags}: set to <code>false</code> if the application must be kept
276      * in memory following a full-system restore operation; <code>true</code> otherwise.
277      * Ordinarily, during a full system restore operation each application is shut down
278      * following execution of its agent's onRestore() method.  Setting this attribute to
279      * <code>false</code> prevents this.  Most applications will not need to set this attribute.
280      *
281      * <p>If
282      * {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup}
283      * is set to <code>false</code> or no
284      * {@link android.R.styleable#AndroidManifestApplication_backupAgent android:backupAgent}
285      * is specified, this flag will be ignored.
286      *
287      * <p>Comes from the
288      * {@link android.R.styleable#AndroidManifestApplication_killAfterRestore android:killAfterRestore}
289      * attribute of the &lt;application&gt; tag.
290      */
291     public static final int FLAG_KILL_AFTER_RESTORE = 1<<16;
292 
293     /**
294      * Value for {@link #flags}: Set to <code>true</code> if the application's backup
295      * agent claims to be able to handle restore data even "from the future,"
296      * i.e. from versions of the application with a versionCode greater than
297      * the one currently installed on the device.  <i>Use with caution!</i>  By default
298      * this attribute is <code>false</code> and the Backup Manager will ensure that data
299      * from "future" versions of the application are never supplied during a restore operation.
300      *
301      * <p>If
302      * {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup}
303      * is set to <code>false</code> or no
304      * {@link android.R.styleable#AndroidManifestApplication_backupAgent android:backupAgent}
305      * is specified, this flag will be ignored.
306      *
307      * <p>Comes from the
308      * {@link android.R.styleable#AndroidManifestApplication_restoreAnyVersion android:restoreAnyVersion}
309      * attribute of the &lt;application&gt; tag.
310      */
311     public static final int FLAG_RESTORE_ANY_VERSION = 1<<17;
312 
313     /**
314      * Value for {@link #flags}: Set to true if the application is
315      * currently installed on external/removable/unprotected storage.  Such
316      * applications may not be available if their storage is not currently
317      * mounted.  When the storage it is on is not available, it will look like
318      * the application has been uninstalled (its .apk is no longer available)
319      * but its persistent data is not removed.
320      */
321     public static final int FLAG_EXTERNAL_STORAGE = 1<<18;
322 
323     /**
324      * Value for {@link #flags}: true when the application's window can be
325      * increased in size for extra large screens.  Corresponds to
326      * {@link android.R.styleable#AndroidManifestSupportsScreens_xlargeScreens
327      * android:xlargeScreens}.
328      */
329     public static final int FLAG_SUPPORTS_XLARGE_SCREENS = 1<<19;
330 
331     /**
332      * Value for {@link #flags}: true when the application has requested a
333      * large heap for its processes.  Corresponds to
334      * {@link android.R.styleable#AndroidManifestApplication_largeHeap
335      * android:largeHeap}.
336      */
337     public static final int FLAG_LARGE_HEAP = 1<<20;
338 
339     /**
340      * Value for {@link #flags}: true if this application's package is in
341      * the stopped state.
342      */
343     public static final int FLAG_STOPPED = 1<<21;
344 
345     /**
346      * Value for {@link #flags}: true  when the application is willing to support
347      * RTL (right to left). All activities will inherit this value.
348      *
349      * Set from the {@link android.R.attr#supportsRtl} attribute in the
350      * activity's manifest.
351      *
352      * Default value is false (no support for RTL).
353      */
354     public static final int FLAG_SUPPORTS_RTL = 1<<22;
355 
356     /**
357      * Value for {@link #flags}: true if the application is currently
358      * installed for the calling user.
359      */
360     public static final int FLAG_INSTALLED = 1<<23;
361 
362     /**
363      * Value for {@link #flags}: true if the application only has its
364      * data installed; the application package itself does not currently
365      * exist on the device.
366      */
367     public static final int FLAG_IS_DATA_ONLY = 1<<24;
368 
369     /**
370      * Value for {@link #flags}: true if the application was declared to be a
371      * game, or false if it is a non-game application.
372      *
373      * @deprecated use {@link #CATEGORY_GAME} instead.
374      */
375     @Deprecated
376     public static final int FLAG_IS_GAME = 1<<25;
377 
378     /**
379      * Value for {@link #flags}: {@code true} if the application asks that only
380      * full-data streaming backups of its data be performed even though it defines
381      * a {@link android.app.backup.BackupAgent BackupAgent}, which normally
382      * indicates that the app will manage its backed-up data via incremental
383      * key/value updates.
384      */
385     public static final int FLAG_FULL_BACKUP_ONLY = 1<<26;
386 
387     /**
388      * Value for {@link #flags}: {@code true} if the application may use cleartext network traffic
389      * (e.g., HTTP rather than HTTPS; WebSockets rather than WebSockets Secure; XMPP, IMAP, STMP
390      * without STARTTLS or TLS). If {@code false}, the app declares that it does not intend to use
391      * cleartext network traffic, in which case platform components (e.g., HTTP stacks,
392      * {@code DownloadManager}, {@code MediaPlayer}) will refuse app's requests to use cleartext
393      * traffic. Third-party libraries are encouraged to honor this flag as well.
394      *
395      * <p>NOTE: {@code WebView} honors this flag for applications targeting API level 26 and up.
396      *
397      * <p>This flag is ignored on Android N and above if an Android Network Security Config is
398      * present.
399      *
400      * <p>This flag comes from
401      * {@link android.R.styleable#AndroidManifestApplication_usesCleartextTraffic
402      * android:usesCleartextTraffic} of the &lt;application&gt; tag.
403      */
404     public static final int FLAG_USES_CLEARTEXT_TRAFFIC = 1<<27;
405 
406     /**
407      * When set installer extracts native libs from .apk files.
408      */
409     public static final int FLAG_EXTRACT_NATIVE_LIBS = 1<<28;
410 
411     /**
412      * Value for {@link #flags}: {@code true} when the application's rendering
413      * should be hardware accelerated.
414      */
415     public static final int FLAG_HARDWARE_ACCELERATED = 1<<29;
416 
417     /**
418      * Value for {@link #flags}: true if this application's package is in
419      * the suspended state.
420      */
421     public static final int FLAG_SUSPENDED = 1<<30;
422 
423     /**
424      * Value for {@link #flags}: true if code from this application will need to be
425      * loaded into other applications' processes. On devices that support multiple
426      * instruction sets, this implies the code might be loaded into a process that's
427      * using any of the devices supported instruction sets.
428      *
429      * <p> The system might treat such applications specially, for eg., by
430      * extracting the application's native libraries for all supported instruction
431      * sets or by compiling the application's dex code for all supported instruction
432      * sets.
433      */
434     public static final int FLAG_MULTIARCH  = 1 << 31;
435 
436     /**
437      * Flags associated with the application.  Any combination of
438      * {@link #FLAG_SYSTEM}, {@link #FLAG_DEBUGGABLE}, {@link #FLAG_HAS_CODE},
439      * {@link #FLAG_PERSISTENT}, {@link #FLAG_FACTORY_TEST}, and
440      * {@link #FLAG_ALLOW_TASK_REPARENTING}
441      * {@link #FLAG_ALLOW_CLEAR_USER_DATA}, {@link #FLAG_UPDATED_SYSTEM_APP},
442      * {@link #FLAG_TEST_ONLY}, {@link #FLAG_SUPPORTS_SMALL_SCREENS},
443      * {@link #FLAG_SUPPORTS_NORMAL_SCREENS},
444      * {@link #FLAG_SUPPORTS_LARGE_SCREENS}, {@link #FLAG_SUPPORTS_XLARGE_SCREENS},
445      * {@link #FLAG_RESIZEABLE_FOR_SCREENS},
446      * {@link #FLAG_SUPPORTS_SCREEN_DENSITIES}, {@link #FLAG_VM_SAFE_MODE},
447      * {@link #FLAG_ALLOW_BACKUP}, {@link #FLAG_KILL_AFTER_RESTORE},
448      * {@link #FLAG_RESTORE_ANY_VERSION}, {@link #FLAG_EXTERNAL_STORAGE},
449      * {@link #FLAG_LARGE_HEAP}, {@link #FLAG_STOPPED},
450      * {@link #FLAG_SUPPORTS_RTL}, {@link #FLAG_INSTALLED},
451      * {@link #FLAG_IS_DATA_ONLY}, {@link #FLAG_IS_GAME},
452      * {@link #FLAG_FULL_BACKUP_ONLY}, {@link #FLAG_USES_CLEARTEXT_TRAFFIC},
453      * {@link #FLAG_MULTIARCH}.
454      */
455     public int flags = 0;
456 
457     /**
458      * Value for {@link #privateFlags}: true if the application is hidden via restrictions and for
459      * most purposes is considered as not installed.
460      * {@hide}
461      */
462     public static final int PRIVATE_FLAG_HIDDEN = 1<<0;
463 
464     /**
465      * Value for {@link #privateFlags}: set to <code>true</code> if the application
466      * has reported that it is heavy-weight, and thus can not participate in
467      * the normal application lifecycle.
468      *
469      * <p>Comes from the
470      * android.R.styleable#AndroidManifestApplication_cantSaveState
471      * attribute of the &lt;application&gt; tag.
472      *
473      * {@hide}
474      */
475     public static final int PRIVATE_FLAG_CANT_SAVE_STATE = 1<<1;
476 
477     /**
478      * Value for {@link #privateFlags}: set to {@code true} if the application
479      * is permitted to hold privileged permissions.
480      *
481      * {@hide}
482      */
483     @UnsupportedAppUsage
484     @TestApi
485     public static final int PRIVATE_FLAG_PRIVILEGED = 1<<3;
486 
487     /**
488      * Value for {@link #privateFlags}: {@code true} if the application has any IntentFiler
489      * with some data URI using HTTP or HTTPS with an associated VIEW action.
490      *
491      * {@hide}
492      */
493     public static final int PRIVATE_FLAG_HAS_DOMAIN_URLS = 1<<4;
494 
495     /**
496      * When set, the default data storage directory for this app is pointed at
497      * the device-protected location.
498      *
499      * @hide
500      */
501     public static final int PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE = 1 << 5;
502 
503     /**
504      * When set, assume that all components under the given app are direct boot
505      * aware, unless otherwise specified.
506      *
507      * @hide
508      */
509     public static final int PRIVATE_FLAG_DIRECT_BOOT_AWARE = 1 << 6;
510 
511     /**
512      * Value for {@link #privateFlags}: {@code true} if the application is installed
513      * as instant app.
514      *
515      * @hide
516      */
517     public static final int PRIVATE_FLAG_INSTANT = 1 << 7;
518 
519     /**
520      * When set, at least one component inside this application is direct boot
521      * aware.
522      *
523      * @hide
524      */
525     public static final int PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE = 1 << 8;
526 
527 
528     /**
529      * When set, signals that the application is required for the system user and should not be
530      * uninstalled.
531      *
532      * @hide
533      */
534     public static final int PRIVATE_FLAG_REQUIRED_FOR_SYSTEM_USER = 1 << 9;
535 
536     /**
537      * When set, the application explicitly requested that its activities be resizeable by default.
538      * @see android.R.styleable#AndroidManifestActivity_resizeableActivity
539      *
540      * @hide
541      */
542     public static final int PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE = 1 << 10;
543 
544     /**
545      * When set, the application explicitly requested that its activities *not* be resizeable by
546      * default.
547      * @see android.R.styleable#AndroidManifestActivity_resizeableActivity
548      *
549      * @hide
550      */
551     public static final int PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_UNRESIZEABLE = 1 << 11;
552 
553     /**
554      * The application isn't requesting explicitly requesting for its activities to be resizeable or
555      * non-resizeable by default. So, we are making it activities resizeable by default based on the
556      * target SDK version of the app.
557      * @see android.R.styleable#AndroidManifestActivity_resizeableActivity
558      *
559      * NOTE: This only affects apps with target SDK >= N where the resizeableActivity attribute was
560      * introduced. It shouldn't be confused with {@link ActivityInfo#RESIZE_MODE_FORCE_RESIZEABLE}
561      * where certain pre-N apps are forced to the resizeable.
562      *
563      * @hide
564      */
565     public static final int PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION =
566             1 << 12;
567 
568     /**
569      * Value for {@link #privateFlags}: {@code true} means the OS should go ahead and
570      * run full-data backup operations for the app even when it is in a
571      * foreground-equivalent run state.  Defaults to {@code false} if unspecified.
572      * @hide
573      */
574     public static final int PRIVATE_FLAG_BACKUP_IN_FOREGROUND = 1 << 13;
575 
576     /**
577      * Value for {@link #privateFlags}: {@code true} means this application
578      * contains a static shared library. Defaults to {@code false} if unspecified.
579      * @hide
580      */
581     public static final int PRIVATE_FLAG_STATIC_SHARED_LIBRARY = 1 << 14;
582 
583     /**
584      * Value for {@link #privateFlags}: When set, the application will only have its splits loaded
585      * if they are required to load a component. Splits can be loaded on demand using the
586      * {@link Context#createContextForSplit(String)} API.
587      * @hide
588      */
589     public static final int PRIVATE_FLAG_ISOLATED_SPLIT_LOADING = 1 << 15;
590 
591     /**
592      * Value for {@link #privateFlags}: When set, the application was installed as
593      * a virtual preload.
594      * @hide
595      */
596     public static final int PRIVATE_FLAG_VIRTUAL_PRELOAD = 1 << 16;
597 
598     /**
599      * Value for {@link #privateFlags}: whether this app is pre-installed on the
600      * OEM partition of the system image.
601      * @hide
602      */
603     public static final int PRIVATE_FLAG_OEM = 1 << 17;
604 
605     /**
606      * Value for {@link #privateFlags}: whether this app is pre-installed on the
607      * vendor partition of the system image.
608      * @hide
609      */
610     public static final int PRIVATE_FLAG_VENDOR = 1 << 18;
611 
612     /**
613      * Value for {@link #privateFlags}: whether this app is pre-installed on the
614      * product partition of the system image.
615      * @hide
616      */
617     public static final int PRIVATE_FLAG_PRODUCT = 1 << 19;
618 
619     /**
620      * Value for {@link #privateFlags}: whether this app is signed with the
621      * platform key.
622      * @hide
623      */
624     public static final int PRIVATE_FLAG_SIGNED_WITH_PLATFORM_KEY = 1 << 20;
625 
626     /**
627      * Value for {@link #privateFlags}: whether this app is pre-installed on the
628      * system_ext partition of the system image.
629      * @hide
630      */
631     public static final int PRIVATE_FLAG_SYSTEM_EXT = 1 << 21;
632 
633     /**
634      * Indicates whether this package requires access to non-SDK APIs.
635      * Only system apps and tests are allowed to use this property.
636      * @hide
637      */
638     public static final int PRIVATE_FLAG_USES_NON_SDK_API = 1 << 22;
639 
640     /**
641      * Indicates whether this application can be profiled by the shell user,
642      * even when running on a device that is running in user mode.
643      * @hide
644      */
645     public static final int PRIVATE_FLAG_PROFILEABLE_BY_SHELL = 1 << 23;
646 
647     /**
648      * Indicates whether this package requires access to non-SDK APIs.
649      * Only system apps and tests are allowed to use this property.
650      * @hide
651      */
652     public static final int PRIVATE_FLAG_HAS_FRAGILE_USER_DATA = 1 << 24;
653 
654     /**
655      * Indicates whether this application wants to use the embedded dex in the APK, rather than
656      * extracted or locally compiled variants. This keeps the dex code protected by the APK
657      * signature. Such apps will always run in JIT mode (same when they are first installed), and
658      * the system will never generate ahead-of-time compiled code for them. Depending on the app's
659      * workload, there may be some run time performance change, noteably the cold start time.
660      *
661      * @hide
662      */
663     public static final int PRIVATE_FLAG_USE_EMBEDDED_DEX = 1 << 25;
664 
665     /**
666      * Value for {@link #privateFlags}: indicates whether this application's data will be cleared
667      * on a failed restore.
668      *
669      * <p>Comes from the
670      * android.R.styleable#AndroidManifestApplication_allowClearUserDataOnFailedRestore attribute
671      * of the &lt;application&gt; tag.
672      *
673      * @hide
674      */
675     public static final int PRIVATE_FLAG_ALLOW_CLEAR_USER_DATA_ON_FAILED_RESTORE = 1 << 26;
676 
677     /**
678      * Value for {@link #privateFlags}: true if the application allows its audio playback
679      * to be captured by other apps.
680      *
681      * @hide
682      */
683     public static final int PRIVATE_FLAG_ALLOW_AUDIO_PLAYBACK_CAPTURE  = 1 << 27;
684 
685     /**
686      * Indicates whether this package is in fact a runtime resource overlay.
687      *
688      * @hide
689      */
690     public static final int PRIVATE_FLAG_IS_RESOURCE_OVERLAY = 1 << 28;
691 
692     /**
693      * Value for {@link #privateFlags}: If {@code true} this app requests
694      * full external storage access. The request may not be honored due to
695      * policy or other reasons.
696      *
697      * @hide
698      */
699     public static final int PRIVATE_FLAG_REQUEST_LEGACY_EXTERNAL_STORAGE = 1 << 29;
700 
701     /**
702      * Value for {@link #privateFlags}: whether this app is pre-installed on the
703      * ODM partition of the system image.
704      * @hide
705      */
706     public static final int PRIVATE_FLAG_ODM = 1 << 30;
707 
708     /**
709      * Value for {@link #privateFlags}: If {@code true} this app allows heap tagging.
710      * {@link com.android.server.am.ProcessList#NATIVE_HEAP_POINTER_TAGGING}
711      * @hide
712      */
713     public static final int PRIVATE_FLAG_ALLOW_NATIVE_HEAP_POINTER_TAGGING = 1 << 31;
714 
715     /** @hide */
716     @IntDef(flag = true, prefix = { "PRIVATE_FLAG_" }, value = {
717             PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE,
718             PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION,
719             PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_UNRESIZEABLE,
720             PRIVATE_FLAG_BACKUP_IN_FOREGROUND,
721             PRIVATE_FLAG_CANT_SAVE_STATE,
722             PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE,
723             PRIVATE_FLAG_DIRECT_BOOT_AWARE,
724             PRIVATE_FLAG_HAS_DOMAIN_URLS,
725             PRIVATE_FLAG_HIDDEN,
726             PRIVATE_FLAG_INSTANT,
727             PRIVATE_FLAG_IS_RESOURCE_OVERLAY,
728             PRIVATE_FLAG_ISOLATED_SPLIT_LOADING,
729             PRIVATE_FLAG_OEM,
730             PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE,
731             PRIVATE_FLAG_USE_EMBEDDED_DEX,
732             PRIVATE_FLAG_PRIVILEGED,
733             PRIVATE_FLAG_PRODUCT,
734             PRIVATE_FLAG_SYSTEM_EXT,
735             PRIVATE_FLAG_PROFILEABLE_BY_SHELL,
736             PRIVATE_FLAG_REQUIRED_FOR_SYSTEM_USER,
737             PRIVATE_FLAG_SIGNED_WITH_PLATFORM_KEY,
738             PRIVATE_FLAG_STATIC_SHARED_LIBRARY,
739             PRIVATE_FLAG_VENDOR,
740             PRIVATE_FLAG_VIRTUAL_PRELOAD,
741             PRIVATE_FLAG_HAS_FRAGILE_USER_DATA,
742             PRIVATE_FLAG_ALLOW_CLEAR_USER_DATA_ON_FAILED_RESTORE,
743             PRIVATE_FLAG_ALLOW_AUDIO_PLAYBACK_CAPTURE,
744             PRIVATE_FLAG_REQUEST_LEGACY_EXTERNAL_STORAGE,
745             PRIVATE_FLAG_ODM,
746             PRIVATE_FLAG_ALLOW_NATIVE_HEAP_POINTER_TAGGING,
747     })
748     @Retention(RetentionPolicy.SOURCE)
749     public @interface ApplicationInfoPrivateFlags {}
750 
751     /**
752      * Constant corresponding to <code>allowed</code> in the
753      * {@link android.R.attr#autoRevokePermissions} attribute.
754      *
755      * @hide
756      */
757     public static final int AUTO_REVOKE_ALLOWED = 0;
758 
759     /**
760      * Constant corresponding to <code>discouraged</code> in the
761      * {@link android.R.attr#autoRevokePermissions} attribute.
762      *
763      * @hide
764      */
765     public static final int AUTO_REVOKE_DISCOURAGED = 1;
766 
767     /**
768      * Constant corresponding to <code>disallowed</code> in the
769      * {@link android.R.attr#autoRevokePermissions} attribute.
770      *
771      * @hide
772      */
773     public static final int AUTO_REVOKE_DISALLOWED = 2;
774 
775     /**
776      * Private/hidden flags. See {@code PRIVATE_FLAG_...} constants.
777      * @hide
778      */
779     @UnsupportedAppUsage
780     @TestApi
781     public @ApplicationInfoPrivateFlags int privateFlags;
782 
783     /**
784      * @hide
785      */
786     public static final String METADATA_PRELOADED_FONTS = "preloaded_fonts";
787 
788     /**
789      * The required smallest screen width the application can run on.  If 0,
790      * nothing has been specified.  Comes from
791      * {@link android.R.styleable#AndroidManifestSupportsScreens_requiresSmallestWidthDp
792      * android:requiresSmallestWidthDp} attribute of the &lt;supports-screens&gt; tag.
793      */
794     public int requiresSmallestWidthDp = 0;
795 
796     /**
797      * The maximum smallest screen width the application is designed for.  If 0,
798      * nothing has been specified.  Comes from
799      * {@link android.R.styleable#AndroidManifestSupportsScreens_compatibleWidthLimitDp
800      * android:compatibleWidthLimitDp} attribute of the &lt;supports-screens&gt; tag.
801      */
802     public int compatibleWidthLimitDp = 0;
803 
804     /**
805      * The maximum smallest screen width the application will work on.  If 0,
806      * nothing has been specified.  Comes from
807      * {@link android.R.styleable#AndroidManifestSupportsScreens_largestWidthLimitDp
808      * android:largestWidthLimitDp} attribute of the &lt;supports-screens&gt; tag.
809      */
810     public int largestWidthLimitDp = 0;
811 
812     /**
813      * Value indicating the maximum aspect ratio the application supports.
814      * <p>
815      * 0 means unset.
816      * @See {@link android.R.attr#maxAspectRatio}.
817      * @hide
818      */
819     public float maxAspectRatio;
820 
821     /**
822      * Value indicating the minimum aspect ratio the application supports.
823      * <p>
824      * 0 means unset.
825      * @see {@link android.R.attr#minAspectRatio}.
826      * @hide
827      */
828     public float minAspectRatio;
829 
830     /** @hide */
831     public String volumeUuid;
832 
833     /**
834      * UUID of the storage volume on which this application is being hosted. For
835      * apps hosted on the default internal storage at
836      * {@link Environment#getDataDirectory()}, the UUID value is
837      * {@link StorageManager#UUID_DEFAULT}.
838      */
839     public UUID storageUuid;
840 
841     /** {@hide} */
842     @UnsupportedAppUsage
843     public String scanSourceDir;
844     /** {@hide} */
845     @UnsupportedAppUsage
846     public String scanPublicSourceDir;
847 
848     /**
849      * Full path to the base APK for this application.
850      */
851     public String sourceDir;
852 
853     /**
854      * Full path to the publicly available parts of {@link #sourceDir},
855      * including resources and manifest. This may be different from
856      * {@link #sourceDir} if an application is forward locked.
857      */
858     public String publicSourceDir;
859 
860     /**
861      * The names of all installed split APKs, ordered lexicographically.
862      */
863     public String[] splitNames;
864 
865     /**
866      * Full paths to zero or more split APKs, indexed by the same order as {@link #splitNames}.
867      */
868     public String[] splitSourceDirs;
869 
870     /**
871      * Full path to the publicly available parts of {@link #splitSourceDirs},
872      * including resources and manifest. This may be different from
873      * {@link #splitSourceDirs} if an application is forward locked.
874      *
875      * @see #splitSourceDirs
876      */
877     public String[] splitPublicSourceDirs;
878 
879     /**
880      * Maps the dependencies between split APKs. All splits implicitly depend on the base APK.
881      *
882      * Available since platform version O.
883      *
884      * Only populated if the application opts in to isolated split loading via the
885      * {@link android.R.attr.isolatedSplits} attribute in the &lt;manifest&gt; tag of the app's
886      * AndroidManifest.xml.
887      *
888      * The keys and values are all indices into the {@link #splitNames}, {@link #splitSourceDirs},
889      * and {@link #splitPublicSourceDirs} arrays.
890      * Each key represents a split and its value is an array of splits. The first element of this
891      * array is the parent split, and the rest are configuration splits. These configuration splits
892      * have no dependencies themselves.
893      * Cycles do not exist because they are illegal and screened for during installation.
894      *
895      * May be null if no splits are installed, or if no dependencies exist between them.
896      *
897      * NOTE: Any change to the way split dependencies are stored must update the logic that
898      *       creates the class loader context for dexopt (DexoptUtils#getClassLoaderContexts).
899      *
900      * @hide
901      */
902     public SparseArray<int[]> splitDependencies;
903 
904     /**
905      * Full paths to the locations of extra resource packages (runtime overlays)
906      * this application uses. This field is only used if there are extra resource
907      * packages, otherwise it is null.
908      *
909      * {@hide}
910      */
911     @UnsupportedAppUsage
912     public String[] resourceDirs;
913 
914     /**
915      * String retrieved from the seinfo tag found in selinux policy. This value can be set through
916      * the mac_permissions.xml policy construct. This value is used for setting an SELinux security
917      * context on the process as well as its data directory.
918      *
919      * {@hide}
920      */
921     public String seInfo;
922 
923     /**
924      * The seinfo tag generated per-user. This value may change based upon the
925      * user's configuration. For example, when an instant app is installed for
926      * a user. It is an error if this field is ever {@code null} when trying to
927      * start a new process.
928      * <p>NOTE: We need to separate this out because we modify per-user values
929      * multiple times. This needs to be refactored since we're performing more
930      * work than necessary and these values should only be set once. When that
931      * happens, we can merge the per-user value with the seInfo state above.
932      *
933      * {@hide}
934      */
935     public String seInfoUser;
936 
937     /**
938      * Paths to all shared libraries this application is linked against.  This
939      * field is only set if the {@link PackageManager#GET_SHARED_LIBRARY_FILES
940      * PackageManager.GET_SHARED_LIBRARY_FILES} flag was used when retrieving
941      * the structure.
942      */
943     public String[] sharedLibraryFiles;
944 
945     /**
946      * List of all shared libraries this application is linked against.  This
947      * field is only set if the {@link PackageManager#GET_SHARED_LIBRARY_FILES
948      * PackageManager.GET_SHARED_LIBRARY_FILES} flag was used when retrieving
949      * the structure.
950      *
951      * {@hide}
952      */
953     public List<SharedLibraryInfo> sharedLibraryInfos;
954 
955     /**
956      * Full path to the default directory assigned to the package for its
957      * persistent data.
958      */
959     public String dataDir;
960 
961     /**
962      * Full path to the device-protected directory assigned to the package for
963      * its persistent data.
964      *
965      * @see Context#createDeviceProtectedStorageContext()
966      */
967     public String deviceProtectedDataDir;
968 
969     /**
970      * Full path to the credential-protected directory assigned to the package
971      * for its persistent data.
972      *
973      * @hide
974      */
975     @SystemApi
976     public String credentialProtectedDataDir;
977 
978     /**
979      * Full path to the directory where native JNI libraries are stored.
980      */
981     public String nativeLibraryDir;
982 
983     /**
984      * Full path where unpacked native libraries for {@link #secondaryCpuAbi}
985      * are stored, if present.
986      *
987      * The main reason this exists is for bundled multi-arch apps, where
988      * it's not trivial to calculate the location of libs for the secondary abi
989      * given the location of the primary.
990      *
991      * TODO: Change the layout of bundled installs so that we can use
992      * nativeLibraryRootDir & nativeLibraryRootRequiresIsa there as well.
993      * (e.g {@code [ "/system/app-lib/Foo/arm", "/system/app-lib/Foo/arm64" ]}
994      * instead of {@code [ "/system/lib/Foo", "/system/lib64/Foo" ]}.
995      *
996      * @hide
997      */
998     @UnsupportedAppUsage
999     public String secondaryNativeLibraryDir;
1000 
1001     /**
1002      * The root path where unpacked native libraries are stored.
1003      * <p>
1004      * When {@link #nativeLibraryRootRequiresIsa} is set, the libraries are
1005      * placed in ISA-specific subdirectories under this path, otherwise the
1006      * libraries are placed directly at this path.
1007      *
1008      * @hide
1009      */
1010     @UnsupportedAppUsage
1011     public String nativeLibraryRootDir;
1012 
1013     /**
1014      * Flag indicating that ISA must be appended to
1015      * {@link #nativeLibraryRootDir} to be useful.
1016      *
1017      * @hide
1018      */
1019     public boolean nativeLibraryRootRequiresIsa;
1020 
1021     /**
1022      * The primary ABI that this application requires, This is inferred from the ABIs
1023      * of the native JNI libraries the application bundles. Will be {@code null}
1024      * if this application does not require any particular ABI.
1025      *
1026      * If non-null, the application will always be launched with this ABI.
1027      *
1028      * {@hide}
1029      */
1030     @UnsupportedAppUsage
1031     public String primaryCpuAbi;
1032 
1033     /**
1034      * The secondary ABI for this application. Might be non-null for multi-arch
1035      * installs. The application itself never uses this ABI, but other applications that
1036      * use its code might.
1037      *
1038      * {@hide}
1039      */
1040     @UnsupportedAppUsage
1041     public String secondaryCpuAbi;
1042 
1043     /**
1044      * The kernel user-ID that has been assigned to this application;
1045      * currently this is not a unique ID (multiple applications can have
1046      * the same uid).
1047      */
1048     public int uid;
1049 
1050     /**
1051      * The minimum SDK version this application can run on. It will not run
1052      * on earlier versions.
1053      */
1054     public int minSdkVersion;
1055 
1056     /**
1057      * The minimum SDK version this application targets.  It may run on earlier
1058      * versions, but it knows how to work with any new behavior added at this
1059      * version.  Will be {@link android.os.Build.VERSION_CODES#CUR_DEVELOPMENT}
1060      * if this is a development build and the app is targeting that.  You should
1061      * compare that this number is >= the SDK version number at which your
1062      * behavior was introduced.
1063      */
1064     public int targetSdkVersion;
1065 
1066     /**
1067      * The app's declared version code.
1068      * @hide
1069      */
1070     public long longVersionCode;
1071 
1072     /**
1073      * An integer representation of the app's declared version code. This is being left in place as
1074      * some apps were using reflection to access it before the move to long in
1075      * {@link android.os.Build.VERSION_CODES#P}
1076      * @deprecated Use {@link #longVersionCode} instead.
1077      * @hide
1078      */
1079     @Deprecated
1080     @UnsupportedAppUsage
1081     public int versionCode;
1082 
1083     /**
1084      * The user-visible SDK version (ex. 26) of the framework against which the application claims
1085      * to have been compiled, or {@code 0} if not specified.
1086      * <p>
1087      * This property is the compile-time equivalent of
1088      * {@link android.os.Build.VERSION#CODENAME Build.VERSION.SDK_INT}.
1089      *
1090      * @hide For platform use only; we don't expect developers to need to read this value.
1091      */
1092     public int compileSdkVersion;
1093 
1094     /**
1095      * The development codename (ex. "O", "REL") of the framework against which the application
1096      * claims to have been compiled, or {@code null} if not specified.
1097      * <p>
1098      * This property is the compile-time equivalent of
1099      * {@link android.os.Build.VERSION#CODENAME Build.VERSION.CODENAME}.
1100      *
1101      * @hide For platform use only; we don't expect developers to need to read this value.
1102      */
1103     @Nullable
1104     public String compileSdkVersionCodename;
1105 
1106     /**
1107      * When false, indicates that all components within this application are
1108      * considered disabled, regardless of their individually set enabled status.
1109      */
1110     public boolean enabled = true;
1111 
1112     /**
1113      * For convenient access to the current enabled setting of this app.
1114      * @hide
1115      */
1116     @UnsupportedAppUsage
1117     public int enabledSetting = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
1118 
1119     /**
1120      * For convenient access to package's install location.
1121      * @hide
1122      */
1123     @UnsupportedAppUsage
1124     public int installLocation = PackageInfo.INSTALL_LOCATION_UNSPECIFIED;
1125 
1126     /**
1127      * Resource file providing the application's Network Security Config.
1128      * @hide
1129      */
1130     public int networkSecurityConfigRes;
1131 
1132     /**
1133      * Version of the sandbox the application wants to run in.
1134      * @hide
1135      */
1136     @SystemApi
1137     public int targetSandboxVersion;
1138 
1139     /**
1140      * The factory of this package, as specified by the &lt;manifest&gt;
1141      * tag's {@link android.R.styleable#AndroidManifestApplication_appComponentFactory}
1142      * attribute.
1143      */
1144     public String appComponentFactory;
1145 
1146     /**
1147      * Resource id of {@link com.android.internal.R.styleable.AndroidManifestProvider_icon}
1148      * @hide
1149      */
1150     public int iconRes;
1151 
1152     /**
1153      * Resource id of {@link com.android.internal.R.styleable.AndroidManifestProvider_roundIcon}
1154      * @hide
1155      */
1156     public int roundIconRes;
1157 
1158     /**
1159      * The category of this app. Categories are used to cluster multiple apps
1160      * together into meaningful groups, such as when summarizing battery,
1161      * network, or disk usage. Apps should only define this value when they fit
1162      * well into one of the specific categories.
1163      * <p>
1164      * Set from the {@link android.R.attr#appCategory} attribute in the
1165      * manifest. If the manifest doesn't define a category, this value may have
1166      * been provided by the installer via
1167      * {@link PackageManager#setApplicationCategoryHint(String, int)}.
1168      */
1169     public @Category int category = CATEGORY_UNDEFINED;
1170 
1171     /** {@hide} */
1172     @IntDef(prefix = { "CATEGORY_" }, value = {
1173             CATEGORY_UNDEFINED,
1174             CATEGORY_GAME,
1175             CATEGORY_AUDIO,
1176             CATEGORY_VIDEO,
1177             CATEGORY_IMAGE,
1178             CATEGORY_SOCIAL,
1179             CATEGORY_NEWS,
1180             CATEGORY_MAPS,
1181             CATEGORY_PRODUCTIVITY
1182     })
1183     @Retention(RetentionPolicy.SOURCE)
1184     public @interface Category {
1185     }
1186 
1187     /**
1188      * Value when category is undefined.
1189      *
1190      * @see #category
1191      */
1192     public static final int CATEGORY_UNDEFINED = -1;
1193 
1194     /**
1195      * Category for apps which are primarily games.
1196      *
1197      * @see #category
1198      */
1199     public static final int CATEGORY_GAME = 0;
1200 
1201     /**
1202      * Category for apps which primarily work with audio or music, such as music
1203      * players.
1204      *
1205      * @see #category
1206      */
1207     public static final int CATEGORY_AUDIO = 1;
1208 
1209     /**
1210      * Category for apps which primarily work with video or movies, such as
1211      * streaming video apps.
1212      *
1213      * @see #category
1214      */
1215     public static final int CATEGORY_VIDEO = 2;
1216 
1217     /**
1218      * Category for apps which primarily work with images or photos, such as
1219      * camera or gallery apps.
1220      *
1221      * @see #category
1222      */
1223     public static final int CATEGORY_IMAGE = 3;
1224 
1225     /**
1226      * Category for apps which are primarily social apps, such as messaging,
1227      * communication, email, or social network apps.
1228      *
1229      * @see #category
1230      */
1231     public static final int CATEGORY_SOCIAL = 4;
1232 
1233     /**
1234      * Category for apps which are primarily news apps, such as newspapers,
1235      * magazines, or sports apps.
1236      *
1237      * @see #category
1238      */
1239     public static final int CATEGORY_NEWS = 5;
1240 
1241     /**
1242      * Category for apps which are primarily maps apps, such as navigation apps.
1243      *
1244      * @see #category
1245      */
1246     public static final int CATEGORY_MAPS = 6;
1247 
1248     /**
1249      * Category for apps which are primarily productivity apps, such as cloud
1250      * storage or workplace apps.
1251      *
1252      * @see #category
1253      */
1254     public static final int CATEGORY_PRODUCTIVITY = 7;
1255 
1256     /**
1257      * Return a concise, localized title for the given
1258      * {@link ApplicationInfo#category} value, or {@code null} for unknown
1259      * values such as {@link #CATEGORY_UNDEFINED}.
1260      *
1261      * @see #category
1262      */
getCategoryTitle(Context context, @Category int category)1263     public static CharSequence getCategoryTitle(Context context, @Category int category) {
1264         switch (category) {
1265             case ApplicationInfo.CATEGORY_GAME:
1266                 return context.getText(com.android.internal.R.string.app_category_game);
1267             case ApplicationInfo.CATEGORY_AUDIO:
1268                 return context.getText(com.android.internal.R.string.app_category_audio);
1269             case ApplicationInfo.CATEGORY_VIDEO:
1270                 return context.getText(com.android.internal.R.string.app_category_video);
1271             case ApplicationInfo.CATEGORY_IMAGE:
1272                 return context.getText(com.android.internal.R.string.app_category_image);
1273             case ApplicationInfo.CATEGORY_SOCIAL:
1274                 return context.getText(com.android.internal.R.string.app_category_social);
1275             case ApplicationInfo.CATEGORY_NEWS:
1276                 return context.getText(com.android.internal.R.string.app_category_news);
1277             case ApplicationInfo.CATEGORY_MAPS:
1278                 return context.getText(com.android.internal.R.string.app_category_maps);
1279             case ApplicationInfo.CATEGORY_PRODUCTIVITY:
1280                 return context.getText(com.android.internal.R.string.app_category_productivity);
1281             default:
1282                 return null;
1283         }
1284     }
1285 
1286     /** @hide */
1287     public String classLoaderName;
1288 
1289     /** @hide */
1290     public String[] splitClassLoaderNames;
1291 
1292     /** @hide */
1293     public boolean hiddenUntilInstalled;
1294 
1295     /** @hide */
1296     public String zygotePreloadName;
1297 
1298     /**
1299      * Default (unspecified) setting of GWP-ASan.
1300      */
1301     public static final int GWP_ASAN_DEFAULT = -1;
1302 
1303     /**
1304      * Never enable GWP-ASan in this application or process.
1305      */
1306     public static final int GWP_ASAN_NEVER = 0;
1307 
1308     /**
1309      * Always enable GWP-ASan in this application or process.
1310      */
1311     public static final int GWP_ASAN_ALWAYS = 1;
1312 
1313     /**
1314      * These constants need to match the values of gwpAsanMode in application manifest.
1315      * @hide
1316      */
1317     @IntDef(prefix = {"GWP_ASAN_"}, value = {
1318             GWP_ASAN_DEFAULT,
1319             GWP_ASAN_NEVER,
1320             GWP_ASAN_ALWAYS,
1321     })
1322     @Retention(RetentionPolicy.SOURCE)
1323     public @interface GwpAsanMode {}
1324 
1325     /**
1326      * Indicates if the application has requested GWP-ASan to be enabled, disabled, or left
1327      * unspecified. Processes can override this setting.
1328      */
1329     private @GwpAsanMode int gwpAsanMode;
1330 
1331     /**
1332      * Represents the default policy. The actual policy used will depend on other properties of
1333      * the application, e.g. the target SDK version.
1334      * @hide
1335      */
1336     public static final int HIDDEN_API_ENFORCEMENT_DEFAULT = -1;
1337     /**
1338      * No API enforcement; the app can access the entire internal private API. Only for use by
1339      * system apps.
1340      * @hide
1341      */
1342     public static final int HIDDEN_API_ENFORCEMENT_DISABLED = 0;
1343     /**
1344      * No API enforcement, but enable the detection logic and warnings. Observed behaviour is the
1345      * same as {@link #HIDDEN_API_ENFORCEMENT_DISABLED} but you may see warnings in the log when
1346      * APIs are accessed.
1347      * @hide
1348      * */
1349     public static final int HIDDEN_API_ENFORCEMENT_JUST_WARN = 1;
1350     /**
1351      * Dark grey list enforcement. Enforces the dark grey and black lists
1352      * @hide
1353      */
1354     public static final int HIDDEN_API_ENFORCEMENT_ENABLED = 2;
1355 
1356     private static final int HIDDEN_API_ENFORCEMENT_MIN = HIDDEN_API_ENFORCEMENT_DEFAULT;
1357     private static final int HIDDEN_API_ENFORCEMENT_MAX = HIDDEN_API_ENFORCEMENT_ENABLED;
1358 
1359     /**
1360      * Values in this IntDef MUST be kept in sync with enum hiddenapi::EnforcementPolicy in
1361      * art/runtime/hidden_api.h
1362      * @hide
1363      */
1364     @IntDef(prefix = { "HIDDEN_API_ENFORCEMENT_" }, value = {
1365             HIDDEN_API_ENFORCEMENT_DEFAULT,
1366             HIDDEN_API_ENFORCEMENT_DISABLED,
1367             HIDDEN_API_ENFORCEMENT_JUST_WARN,
1368             HIDDEN_API_ENFORCEMENT_ENABLED,
1369     })
1370     @Retention(RetentionPolicy.SOURCE)
1371     public @interface HiddenApiEnforcementPolicy {}
1372 
1373     /** @hide */
isValidHiddenApiEnforcementPolicy(int policy)1374     public static boolean isValidHiddenApiEnforcementPolicy(int policy) {
1375         return policy >= HIDDEN_API_ENFORCEMENT_MIN && policy <= HIDDEN_API_ENFORCEMENT_MAX;
1376     }
1377 
1378     private int mHiddenApiPolicy = HIDDEN_API_ENFORCEMENT_DEFAULT;
1379 
dump(Printer pw, String prefix)1380     public void dump(Printer pw, String prefix) {
1381         dump(pw, prefix, DUMP_FLAG_ALL);
1382     }
1383 
1384     /** @hide */
dump(Printer pw, String prefix, int dumpFlags)1385     public void dump(Printer pw, String prefix, int dumpFlags) {
1386         super.dumpFront(pw, prefix);
1387         if ((dumpFlags & DUMP_FLAG_DETAILS) != 0 && className != null) {
1388             pw.println(prefix + "className=" + className);
1389         }
1390         if (permission != null) {
1391             pw.println(prefix + "permission=" + permission);
1392         }
1393         pw.println(prefix + "processName=" + processName);
1394         if ((dumpFlags & DUMP_FLAG_DETAILS) != 0) {
1395             pw.println(prefix + "taskAffinity=" + taskAffinity);
1396         }
1397         pw.println(prefix + "uid=" + uid + " flags=0x" + Integer.toHexString(flags)
1398                 + " privateFlags=0x" + Integer.toHexString(privateFlags)
1399                 + " theme=0x" + Integer.toHexString(theme));
1400         if ((dumpFlags & DUMP_FLAG_DETAILS) != 0) {
1401             pw.println(prefix + "requiresSmallestWidthDp=" + requiresSmallestWidthDp
1402                     + " compatibleWidthLimitDp=" + compatibleWidthLimitDp
1403                     + " largestWidthLimitDp=" + largestWidthLimitDp);
1404         }
1405         pw.println(prefix + "sourceDir=" + sourceDir);
1406         if (!Objects.equals(sourceDir, publicSourceDir)) {
1407             pw.println(prefix + "publicSourceDir=" + publicSourceDir);
1408         }
1409         if (!ArrayUtils.isEmpty(splitSourceDirs)) {
1410             pw.println(prefix + "splitSourceDirs=" + Arrays.toString(splitSourceDirs));
1411         }
1412         if (!ArrayUtils.isEmpty(splitPublicSourceDirs)
1413                 && !Arrays.equals(splitSourceDirs, splitPublicSourceDirs)) {
1414             pw.println(prefix + "splitPublicSourceDirs=" + Arrays.toString(splitPublicSourceDirs));
1415         }
1416         if (resourceDirs != null) {
1417             pw.println(prefix + "resourceDirs=" + Arrays.toString(resourceDirs));
1418         }
1419         if ((dumpFlags & DUMP_FLAG_DETAILS) != 0 && seInfo != null) {
1420             pw.println(prefix + "seinfo=" + seInfo);
1421             pw.println(prefix + "seinfoUser=" + seInfoUser);
1422         }
1423         pw.println(prefix + "dataDir=" + dataDir);
1424         if ((dumpFlags & DUMP_FLAG_DETAILS) != 0) {
1425             pw.println(prefix + "deviceProtectedDataDir=" + deviceProtectedDataDir);
1426             pw.println(prefix + "credentialProtectedDataDir=" + credentialProtectedDataDir);
1427             if (sharedLibraryFiles != null) {
1428                 pw.println(prefix + "sharedLibraryFiles=" + Arrays.toString(sharedLibraryFiles));
1429             }
1430         }
1431         if (classLoaderName != null) {
1432             pw.println(prefix + "classLoaderName=" + classLoaderName);
1433         }
1434         if (!ArrayUtils.isEmpty(splitClassLoaderNames)) {
1435             pw.println(prefix + "splitClassLoaderNames=" + Arrays.toString(splitClassLoaderNames));
1436         }
1437 
1438         pw.println(prefix + "enabled=" + enabled
1439                 + " minSdkVersion=" + minSdkVersion
1440                 + " targetSdkVersion=" + targetSdkVersion
1441                 + " versionCode=" + longVersionCode
1442                 + " targetSandboxVersion=" + targetSandboxVersion);
1443         if ((dumpFlags & DUMP_FLAG_DETAILS) != 0) {
1444             if (manageSpaceActivityName != null) {
1445                 pw.println(prefix + "manageSpaceActivityName=" + manageSpaceActivityName);
1446             }
1447             if (descriptionRes != 0) {
1448                 pw.println(prefix + "description=0x" + Integer.toHexString(descriptionRes));
1449             }
1450             if (uiOptions != 0) {
1451                 pw.println(prefix + "uiOptions=0x" + Integer.toHexString(uiOptions));
1452             }
1453             pw.println(prefix + "supportsRtl=" + (hasRtlSupport() ? "true" : "false"));
1454             if (fullBackupContent > 0) {
1455                 pw.println(prefix + "fullBackupContent=@xml/" + fullBackupContent);
1456             } else {
1457                 pw.println(prefix + "fullBackupContent="
1458                         + (fullBackupContent < 0 ? "false" : "true"));
1459             }
1460             pw.println(prefix + "crossProfile=" + (crossProfile ? "true" : "false"));
1461             if (networkSecurityConfigRes != 0) {
1462                 pw.println(prefix + "networkSecurityConfigRes=0x"
1463                         + Integer.toHexString(networkSecurityConfigRes));
1464             }
1465             if (category != CATEGORY_UNDEFINED) {
1466                 pw.println(prefix + "category=" + category);
1467             }
1468             pw.println(prefix + "HiddenApiEnforcementPolicy=" + getHiddenApiEnforcementPolicy());
1469             pw.println(prefix + "usesNonSdkApi=" + usesNonSdkApi());
1470             pw.println(prefix + "allowsPlaybackCapture="
1471                         + (isAudioPlaybackCaptureAllowed() ? "true" : "false"));
1472             if (gwpAsanMode != GWP_ASAN_DEFAULT) {
1473                 pw.println(prefix + "gwpAsanMode=" + gwpAsanMode);
1474             }
1475         }
1476         super.dumpBack(pw, prefix);
1477     }
1478 
1479     /** {@hide} */
dumpDebug(ProtoOutputStream proto, long fieldId, int dumpFlags)1480     public void dumpDebug(ProtoOutputStream proto, long fieldId, int dumpFlags) {
1481         long token = proto.start(fieldId);
1482         super.dumpDebug(proto, ApplicationInfoProto.PACKAGE, dumpFlags);
1483         proto.write(ApplicationInfoProto.PERMISSION, permission);
1484         proto.write(ApplicationInfoProto.PROCESS_NAME, processName);
1485         proto.write(ApplicationInfoProto.UID, uid);
1486         proto.write(ApplicationInfoProto.FLAGS, flags);
1487         proto.write(ApplicationInfoProto.PRIVATE_FLAGS, privateFlags);
1488         proto.write(ApplicationInfoProto.THEME, theme);
1489         proto.write(ApplicationInfoProto.SOURCE_DIR, sourceDir);
1490         if (!Objects.equals(sourceDir, publicSourceDir)) {
1491             proto.write(ApplicationInfoProto.PUBLIC_SOURCE_DIR, publicSourceDir);
1492         }
1493         if (!ArrayUtils.isEmpty(splitSourceDirs)) {
1494             for (String dir : splitSourceDirs) {
1495                 proto.write(ApplicationInfoProto.SPLIT_SOURCE_DIRS, dir);
1496             }
1497         }
1498         if (!ArrayUtils.isEmpty(splitPublicSourceDirs)
1499                 && !Arrays.equals(splitSourceDirs, splitPublicSourceDirs)) {
1500             for (String dir : splitPublicSourceDirs) {
1501                 proto.write(ApplicationInfoProto.SPLIT_PUBLIC_SOURCE_DIRS, dir);
1502             }
1503         }
1504         if (resourceDirs != null) {
1505             for (String dir : resourceDirs) {
1506                 proto.write(ApplicationInfoProto.RESOURCE_DIRS, dir);
1507             }
1508         }
1509         proto.write(ApplicationInfoProto.DATA_DIR, dataDir);
1510         proto.write(ApplicationInfoProto.CLASS_LOADER_NAME, classLoaderName);
1511         if (!ArrayUtils.isEmpty(splitClassLoaderNames)) {
1512             for (String name : splitClassLoaderNames) {
1513                 proto.write(ApplicationInfoProto.SPLIT_CLASS_LOADER_NAMES, name);
1514             }
1515         }
1516 
1517         long versionToken = proto.start(ApplicationInfoProto.VERSION);
1518         proto.write(ApplicationInfoProto.Version.ENABLED, enabled);
1519         proto.write(ApplicationInfoProto.Version.MIN_SDK_VERSION, minSdkVersion);
1520         proto.write(ApplicationInfoProto.Version.TARGET_SDK_VERSION, targetSdkVersion);
1521         proto.write(ApplicationInfoProto.Version.VERSION_CODE, longVersionCode);
1522         proto.write(ApplicationInfoProto.Version.TARGET_SANDBOX_VERSION, targetSandboxVersion);
1523         proto.end(versionToken);
1524 
1525         if ((dumpFlags & DUMP_FLAG_DETAILS) != 0) {
1526             long detailToken = proto.start(ApplicationInfoProto.DETAIL);
1527             if (className != null) {
1528                 proto.write(ApplicationInfoProto.Detail.CLASS_NAME, className);
1529             }
1530             proto.write(ApplicationInfoProto.Detail.TASK_AFFINITY, taskAffinity);
1531             proto.write(ApplicationInfoProto.Detail.REQUIRES_SMALLEST_WIDTH_DP,
1532                     requiresSmallestWidthDp);
1533             proto.write(ApplicationInfoProto.Detail.COMPATIBLE_WIDTH_LIMIT_DP,
1534                     compatibleWidthLimitDp);
1535             proto.write(ApplicationInfoProto.Detail.LARGEST_WIDTH_LIMIT_DP,
1536                     largestWidthLimitDp);
1537             if (seInfo != null) {
1538                 proto.write(ApplicationInfoProto.Detail.SEINFO, seInfo);
1539                 proto.write(ApplicationInfoProto.Detail.SEINFO_USER, seInfoUser);
1540             }
1541             proto.write(ApplicationInfoProto.Detail.DEVICE_PROTECTED_DATA_DIR,
1542                     deviceProtectedDataDir);
1543             proto.write(ApplicationInfoProto.Detail.CREDENTIAL_PROTECTED_DATA_DIR,
1544                     credentialProtectedDataDir);
1545             if (sharedLibraryFiles != null) {
1546                 for (String f : sharedLibraryFiles) {
1547                     proto.write(ApplicationInfoProto.Detail.SHARED_LIBRARY_FILES, f);
1548                 }
1549             }
1550             if (manageSpaceActivityName != null) {
1551                 proto.write(ApplicationInfoProto.Detail.MANAGE_SPACE_ACTIVITY_NAME,
1552                         manageSpaceActivityName);
1553             }
1554             if (descriptionRes != 0) {
1555                 proto.write(ApplicationInfoProto.Detail.DESCRIPTION_RES, descriptionRes);
1556             }
1557             if (uiOptions != 0) {
1558                 proto.write(ApplicationInfoProto.Detail.UI_OPTIONS, uiOptions);
1559             }
1560             proto.write(ApplicationInfoProto.Detail.SUPPORTS_RTL, hasRtlSupport());
1561             if (fullBackupContent > 0) {
1562                 proto.write(ApplicationInfoProto.Detail.CONTENT, "@xml/" + fullBackupContent);
1563             } else {
1564                 proto.write(ApplicationInfoProto.Detail.IS_FULL_BACKUP, fullBackupContent == 0);
1565             }
1566             if (networkSecurityConfigRes != 0) {
1567                 proto.write(ApplicationInfoProto.Detail.NETWORK_SECURITY_CONFIG_RES,
1568                         networkSecurityConfigRes);
1569             }
1570             if (category != CATEGORY_UNDEFINED) {
1571                 proto.write(ApplicationInfoProto.Detail.CATEGORY, category);
1572             }
1573             if (gwpAsanMode != GWP_ASAN_DEFAULT) {
1574                 proto.write(ApplicationInfoProto.Detail.ENABLE_GWP_ASAN, gwpAsanMode);
1575             }
1576             proto.end(detailToken);
1577         }
1578         proto.end(token);
1579     }
1580 
1581     /**
1582      * @return true if "supportsRtl" has been set to true in the AndroidManifest
1583      * @hide
1584      */
1585     @UnsupportedAppUsage
hasRtlSupport()1586     public boolean hasRtlSupport() {
1587         return (flags & FLAG_SUPPORTS_RTL) == FLAG_SUPPORTS_RTL;
1588     }
1589 
1590     /** {@hide} */
hasCode()1591     public boolean hasCode() {
1592         return (flags & FLAG_HAS_CODE) != 0;
1593     }
1594 
1595     public static class DisplayNameComparator
1596             implements Comparator<ApplicationInfo> {
DisplayNameComparator(PackageManager pm)1597         public DisplayNameComparator(PackageManager pm) {
1598             mPM = pm;
1599         }
1600 
compare(ApplicationInfo aa, ApplicationInfo ab)1601         public final int compare(ApplicationInfo aa, ApplicationInfo ab) {
1602             CharSequence  sa = mPM.getApplicationLabel(aa);
1603             if (sa == null) {
1604                 sa = aa.packageName;
1605             }
1606             CharSequence  sb = mPM.getApplicationLabel(ab);
1607             if (sb == null) {
1608                 sb = ab.packageName;
1609             }
1610 
1611             return sCollator.compare(sa.toString(), sb.toString());
1612         }
1613 
1614         @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
1615         private final Collator   sCollator = Collator.getInstance();
1616         @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
1617         private PackageManager   mPM;
1618     }
1619 
ApplicationInfo()1620     public ApplicationInfo() {
1621     }
1622 
ApplicationInfo(ApplicationInfo orig)1623     public ApplicationInfo(ApplicationInfo orig) {
1624         super(orig);
1625         taskAffinity = orig.taskAffinity;
1626         permission = orig.permission;
1627         processName = orig.processName;
1628         className = orig.className;
1629         theme = orig.theme;
1630         flags = orig.flags;
1631         privateFlags = orig.privateFlags;
1632         requiresSmallestWidthDp = orig.requiresSmallestWidthDp;
1633         compatibleWidthLimitDp = orig.compatibleWidthLimitDp;
1634         largestWidthLimitDp = orig.largestWidthLimitDp;
1635         volumeUuid = orig.volumeUuid;
1636         storageUuid = orig.storageUuid;
1637         scanSourceDir = orig.scanSourceDir;
1638         scanPublicSourceDir = orig.scanPublicSourceDir;
1639         sourceDir = orig.sourceDir;
1640         publicSourceDir = orig.publicSourceDir;
1641         splitNames = orig.splitNames;
1642         splitSourceDirs = orig.splitSourceDirs;
1643         splitPublicSourceDirs = orig.splitPublicSourceDirs;
1644         splitDependencies = orig.splitDependencies;
1645         nativeLibraryDir = orig.nativeLibraryDir;
1646         secondaryNativeLibraryDir = orig.secondaryNativeLibraryDir;
1647         nativeLibraryRootDir = orig.nativeLibraryRootDir;
1648         nativeLibraryRootRequiresIsa = orig.nativeLibraryRootRequiresIsa;
1649         primaryCpuAbi = orig.primaryCpuAbi;
1650         secondaryCpuAbi = orig.secondaryCpuAbi;
1651         resourceDirs = orig.resourceDirs;
1652         seInfo = orig.seInfo;
1653         seInfoUser = orig.seInfoUser;
1654         sharedLibraryFiles = orig.sharedLibraryFiles;
1655         sharedLibraryInfos = orig.sharedLibraryInfos;
1656         dataDir = orig.dataDir;
1657         deviceProtectedDataDir = orig.deviceProtectedDataDir;
1658         credentialProtectedDataDir = orig.credentialProtectedDataDir;
1659         uid = orig.uid;
1660         minSdkVersion = orig.minSdkVersion;
1661         targetSdkVersion = orig.targetSdkVersion;
1662         setVersionCode(orig.longVersionCode);
1663         enabled = orig.enabled;
1664         enabledSetting = orig.enabledSetting;
1665         installLocation = orig.installLocation;
1666         manageSpaceActivityName = orig.manageSpaceActivityName;
1667         descriptionRes = orig.descriptionRes;
1668         uiOptions = orig.uiOptions;
1669         backupAgentName = orig.backupAgentName;
1670         fullBackupContent = orig.fullBackupContent;
1671         crossProfile = orig.crossProfile;
1672         networkSecurityConfigRes = orig.networkSecurityConfigRes;
1673         category = orig.category;
1674         targetSandboxVersion = orig.targetSandboxVersion;
1675         classLoaderName = orig.classLoaderName;
1676         splitClassLoaderNames = orig.splitClassLoaderNames;
1677         appComponentFactory = orig.appComponentFactory;
1678         iconRes = orig.iconRes;
1679         roundIconRes = orig.roundIconRes;
1680         compileSdkVersion = orig.compileSdkVersion;
1681         compileSdkVersionCodename = orig.compileSdkVersionCodename;
1682         mHiddenApiPolicy = orig.mHiddenApiPolicy;
1683         hiddenUntilInstalled = orig.hiddenUntilInstalled;
1684         zygotePreloadName = orig.zygotePreloadName;
1685         gwpAsanMode = orig.gwpAsanMode;
1686     }
1687 
toString()1688     public String toString() {
1689         return "ApplicationInfo{"
1690             + Integer.toHexString(System.identityHashCode(this))
1691             + " " + packageName + "}";
1692     }
1693 
describeContents()1694     public int describeContents() {
1695         return 0;
1696     }
1697 
1698     @SuppressWarnings("unchecked")
writeToParcel(Parcel dest, int parcelableFlags)1699     public void writeToParcel(Parcel dest, int parcelableFlags) {
1700         if (dest.maybeWriteSquashed(this)) {
1701             return;
1702         }
1703         super.writeToParcel(dest, parcelableFlags);
1704         dest.writeString8(taskAffinity);
1705         dest.writeString8(permission);
1706         dest.writeString8(processName);
1707         dest.writeString8(className);
1708         dest.writeInt(theme);
1709         dest.writeInt(flags);
1710         dest.writeInt(privateFlags);
1711         dest.writeInt(requiresSmallestWidthDp);
1712         dest.writeInt(compatibleWidthLimitDp);
1713         dest.writeInt(largestWidthLimitDp);
1714         if (storageUuid != null) {
1715             dest.writeInt(1);
1716             dest.writeLong(storageUuid.getMostSignificantBits());
1717             dest.writeLong(storageUuid.getLeastSignificantBits());
1718         } else {
1719             dest.writeInt(0);
1720         }
1721         dest.writeString8(scanSourceDir);
1722         dest.writeString8(scanPublicSourceDir);
1723         dest.writeString8(sourceDir);
1724         dest.writeString8(publicSourceDir);
1725         dest.writeString8Array(splitNames);
1726         dest.writeString8Array(splitSourceDirs);
1727         dest.writeString8Array(splitPublicSourceDirs);
1728         dest.writeSparseArray((SparseArray) splitDependencies);
1729         dest.writeString8(nativeLibraryDir);
1730         dest.writeString8(secondaryNativeLibraryDir);
1731         dest.writeString8(nativeLibraryRootDir);
1732         dest.writeInt(nativeLibraryRootRequiresIsa ? 1 : 0);
1733         dest.writeString8(primaryCpuAbi);
1734         dest.writeString8(secondaryCpuAbi);
1735         dest.writeString8Array(resourceDirs);
1736         dest.writeString8(seInfo);
1737         dest.writeString8(seInfoUser);
1738         dest.writeString8Array(sharedLibraryFiles);
1739         dest.writeTypedList(sharedLibraryInfos);
1740         dest.writeString8(dataDir);
1741         dest.writeString8(deviceProtectedDataDir);
1742         dest.writeString8(credentialProtectedDataDir);
1743         dest.writeInt(uid);
1744         dest.writeInt(minSdkVersion);
1745         dest.writeInt(targetSdkVersion);
1746         dest.writeLong(longVersionCode);
1747         dest.writeInt(enabled ? 1 : 0);
1748         dest.writeInt(enabledSetting);
1749         dest.writeInt(installLocation);
1750         dest.writeString8(manageSpaceActivityName);
1751         dest.writeString8(backupAgentName);
1752         dest.writeInt(descriptionRes);
1753         dest.writeInt(uiOptions);
1754         dest.writeInt(fullBackupContent);
1755         dest.writeBoolean(crossProfile);
1756         dest.writeInt(networkSecurityConfigRes);
1757         dest.writeInt(category);
1758         dest.writeInt(targetSandboxVersion);
1759         dest.writeString8(classLoaderName);
1760         dest.writeString8Array(splitClassLoaderNames);
1761         dest.writeInt(compileSdkVersion);
1762         dest.writeString8(compileSdkVersionCodename);
1763         dest.writeString8(appComponentFactory);
1764         dest.writeInt(iconRes);
1765         dest.writeInt(roundIconRes);
1766         dest.writeInt(mHiddenApiPolicy);
1767         dest.writeInt(hiddenUntilInstalled ? 1 : 0);
1768         dest.writeString8(zygotePreloadName);
1769         dest.writeInt(gwpAsanMode);
1770     }
1771 
1772     public static final @android.annotation.NonNull Parcelable.Creator<ApplicationInfo> CREATOR
1773             = new Parcelable.Creator<ApplicationInfo>() {
1774         @Override
1775         public ApplicationInfo createFromParcel(Parcel source) {
1776             return source.readSquashed(ApplicationInfo::new);
1777         }
1778 
1779         @Override
1780         public ApplicationInfo[] newArray(int size) {
1781             return new ApplicationInfo[size];
1782         }
1783     };
1784 
1785     @SuppressWarnings("unchecked")
ApplicationInfo(Parcel source)1786     private ApplicationInfo(Parcel source) {
1787         super(source);
1788         taskAffinity = source.readString8();
1789         permission = source.readString8();
1790         processName = source.readString8();
1791         className = source.readString8();
1792         theme = source.readInt();
1793         flags = source.readInt();
1794         privateFlags = source.readInt();
1795         requiresSmallestWidthDp = source.readInt();
1796         compatibleWidthLimitDp = source.readInt();
1797         largestWidthLimitDp = source.readInt();
1798         if (source.readInt() != 0) {
1799             storageUuid = new UUID(source.readLong(), source.readLong());
1800             volumeUuid = StorageManager.convert(storageUuid);
1801         }
1802         scanSourceDir = source.readString8();
1803         scanPublicSourceDir = source.readString8();
1804         sourceDir = source.readString8();
1805         publicSourceDir = source.readString8();
1806         splitNames = source.createString8Array();
1807         splitSourceDirs = source.createString8Array();
1808         splitPublicSourceDirs = source.createString8Array();
1809         splitDependencies = source.readSparseArray(null);
1810         nativeLibraryDir = source.readString8();
1811         secondaryNativeLibraryDir = source.readString8();
1812         nativeLibraryRootDir = source.readString8();
1813         nativeLibraryRootRequiresIsa = source.readInt() != 0;
1814         primaryCpuAbi = source.readString8();
1815         secondaryCpuAbi = source.readString8();
1816         resourceDirs = source.createString8Array();
1817         seInfo = source.readString8();
1818         seInfoUser = source.readString8();
1819         sharedLibraryFiles = source.createString8Array();
1820         sharedLibraryInfos = source.createTypedArrayList(SharedLibraryInfo.CREATOR);
1821         dataDir = source.readString8();
1822         deviceProtectedDataDir = source.readString8();
1823         credentialProtectedDataDir = source.readString8();
1824         uid = source.readInt();
1825         minSdkVersion = source.readInt();
1826         targetSdkVersion = source.readInt();
1827         setVersionCode(source.readLong());
1828         enabled = source.readInt() != 0;
1829         enabledSetting = source.readInt();
1830         installLocation = source.readInt();
1831         manageSpaceActivityName = source.readString8();
1832         backupAgentName = source.readString8();
1833         descriptionRes = source.readInt();
1834         uiOptions = source.readInt();
1835         fullBackupContent = source.readInt();
1836         crossProfile = source.readBoolean();
1837         networkSecurityConfigRes = source.readInt();
1838         category = source.readInt();
1839         targetSandboxVersion = source.readInt();
1840         classLoaderName = source.readString8();
1841         splitClassLoaderNames = source.createString8Array();
1842         compileSdkVersion = source.readInt();
1843         compileSdkVersionCodename = source.readString8();
1844         appComponentFactory = source.readString8();
1845         iconRes = source.readInt();
1846         roundIconRes = source.readInt();
1847         mHiddenApiPolicy = source.readInt();
1848         hiddenUntilInstalled = source.readInt() != 0;
1849         zygotePreloadName = source.readString8();
1850         gwpAsanMode = source.readInt();
1851     }
1852 
1853     /**
1854      * Retrieve the textual description of the application.  This
1855      * will call back on the given PackageManager to load the description from
1856      * the application.
1857      *
1858      * @param pm A PackageManager from which the label can be loaded; usually
1859      * the PackageManager from which you originally retrieved this item.
1860      *
1861      * @return Returns a CharSequence containing the application's description.
1862      * If there is no description, null is returned.
1863      */
loadDescription(PackageManager pm)1864     public CharSequence loadDescription(PackageManager pm) {
1865         if (descriptionRes != 0) {
1866             CharSequence label = pm.getText(packageName, descriptionRes, this);
1867             if (label != null) {
1868                 return label;
1869             }
1870         }
1871         return null;
1872     }
1873 
1874     /**
1875      * Disable compatibility mode
1876      *
1877      * @hide
1878      */
1879     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
disableCompatibilityMode()1880     public void disableCompatibilityMode() {
1881         flags |= (FLAG_SUPPORTS_LARGE_SCREENS | FLAG_SUPPORTS_NORMAL_SCREENS |
1882                 FLAG_SUPPORTS_SMALL_SCREENS | FLAG_RESIZEABLE_FOR_SCREENS |
1883                 FLAG_SUPPORTS_SCREEN_DENSITIES | FLAG_SUPPORTS_XLARGE_SCREENS);
1884     }
1885 
1886     /**
1887      * Is using compatibility mode for non densty aware legacy applications.
1888      *
1889      * @hide
1890      */
usesCompatibilityMode()1891     public boolean usesCompatibilityMode() {
1892         return targetSdkVersion < DONUT ||
1893                 (flags & (FLAG_SUPPORTS_LARGE_SCREENS | FLAG_SUPPORTS_NORMAL_SCREENS |
1894                  FLAG_SUPPORTS_SMALL_SCREENS | FLAG_RESIZEABLE_FOR_SCREENS |
1895                  FLAG_SUPPORTS_SCREEN_DENSITIES | FLAG_SUPPORTS_XLARGE_SCREENS)) == 0;
1896     }
1897 
1898     /** {@hide} */
initForUser(int userId)1899     public void initForUser(int userId) {
1900         uid = UserHandle.getUid(userId, UserHandle.getAppId(uid));
1901 
1902         if ("android".equals(packageName)) {
1903             dataDir = Environment.getDataSystemDirectory().getAbsolutePath();
1904             return;
1905         }
1906 
1907         deviceProtectedDataDir = Environment
1908                 .getDataUserDePackageDirectory(volumeUuid, userId, packageName)
1909                 .getAbsolutePath();
1910         credentialProtectedDataDir = Environment
1911                 .getDataUserCePackageDirectory(volumeUuid, userId, packageName)
1912                 .getAbsolutePath();
1913 
1914         if ((privateFlags & PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) != 0
1915                 && PackageManager.APPLY_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) {
1916             dataDir = deviceProtectedDataDir;
1917         } else {
1918             dataDir = credentialProtectedDataDir;
1919         }
1920     }
1921 
isPackageWhitelistedForHiddenApis()1922     private boolean isPackageWhitelistedForHiddenApis() {
1923         return SystemConfig.getInstance().getHiddenApiWhitelistedApps().contains(packageName);
1924     }
1925 
1926     /**
1927      * @hide
1928      */
usesNonSdkApi()1929     public boolean usesNonSdkApi() {
1930         return (privateFlags & PRIVATE_FLAG_USES_NON_SDK_API) != 0;
1931     }
1932 
1933     /**
1934      * Whether an app needs to keep the app data on uninstall.
1935      *
1936      * @return {@code true} if the app indicates that it needs to keep the app data
1937      *
1938      * @hide
1939      */
hasFragileUserData()1940     public boolean hasFragileUserData() {
1941         return (privateFlags & PRIVATE_FLAG_HAS_FRAGILE_USER_DATA) != 0;
1942     }
1943 
1944     /**
1945      * Whether an app allows its playback audio to be captured by other apps.
1946      *
1947      * @return {@code true} if the app indicates that its audio can be captured by other apps.
1948      *
1949      * @hide
1950      */
isAudioPlaybackCaptureAllowed()1951     public boolean isAudioPlaybackCaptureAllowed() {
1952         return (privateFlags & PRIVATE_FLAG_ALLOW_AUDIO_PLAYBACK_CAPTURE) != 0;
1953     }
1954 
1955     /**
1956      * If {@code true} this app requested to run in the legacy storage mode.
1957      *
1958      * @hide
1959      */
hasRequestedLegacyExternalStorage()1960     public boolean hasRequestedLegacyExternalStorage() {
1961         return (privateFlags & PRIVATE_FLAG_REQUEST_LEGACY_EXTERNAL_STORAGE) != 0;
1962     }
1963 
1964     /**
1965      * If {@code true} this app allows heap pointer tagging.
1966      *
1967      * @hide
1968      */
allowsNativeHeapPointerTagging()1969     public boolean allowsNativeHeapPointerTagging() {
1970         return (privateFlags & PRIVATE_FLAG_ALLOW_NATIVE_HEAP_POINTER_TAGGING) != 0;
1971     }
1972 
isAllowedToUseHiddenApis()1973     private boolean isAllowedToUseHiddenApis() {
1974         if (isSignedWithPlatformKey()) {
1975             return true;
1976         } else if (isSystemApp() || isUpdatedSystemApp()) {
1977             return usesNonSdkApi() || isPackageWhitelistedForHiddenApis();
1978         } else {
1979             return false;
1980         }
1981     }
1982 
1983     /**
1984      * @hide
1985      */
getHiddenApiEnforcementPolicy()1986     public @HiddenApiEnforcementPolicy int getHiddenApiEnforcementPolicy() {
1987         if (isAllowedToUseHiddenApis()) {
1988             return HIDDEN_API_ENFORCEMENT_DISABLED;
1989         }
1990         if (mHiddenApiPolicy != HIDDEN_API_ENFORCEMENT_DEFAULT) {
1991             return mHiddenApiPolicy;
1992         }
1993         return HIDDEN_API_ENFORCEMENT_ENABLED;
1994     }
1995 
1996     /**
1997      * @hide
1998      */
setHiddenApiEnforcementPolicy(@iddenApiEnforcementPolicy int policy)1999     public void setHiddenApiEnforcementPolicy(@HiddenApiEnforcementPolicy int policy) {
2000         if (!isValidHiddenApiEnforcementPolicy(policy)) {
2001             throw new IllegalArgumentException("Invalid API enforcement policy: " + policy);
2002         }
2003         mHiddenApiPolicy = policy;
2004     }
2005 
2006     /**
2007      * Updates the hidden API enforcement policy for this app from the given values, if appropriate.
2008      *
2009      * This will have no effect if this app is not subject to hidden API enforcement, i.e. if it
2010      * is on the package whitelist.
2011      *
2012      * @param policy configured policy for this app, or {@link #HIDDEN_API_ENFORCEMENT_DEFAULT}
2013      *        if nothing configured.
2014      * @hide
2015      */
maybeUpdateHiddenApiEnforcementPolicy(@iddenApiEnforcementPolicy int policy)2016     public void maybeUpdateHiddenApiEnforcementPolicy(@HiddenApiEnforcementPolicy int policy) {
2017         if (isPackageWhitelistedForHiddenApis()) {
2018             return;
2019         }
2020         setHiddenApiEnforcementPolicy(policy);
2021     }
2022 
2023     /**
2024      * @hide
2025      */
setVersionCode(long newVersionCode)2026     public void setVersionCode(long newVersionCode) {
2027         longVersionCode = newVersionCode;
2028         versionCode = (int) newVersionCode;
2029     }
2030 
2031     /**
2032      * @hide
2033      */
2034     @Override
loadDefaultIcon(PackageManager pm)2035     public Drawable loadDefaultIcon(PackageManager pm) {
2036         if ((flags & FLAG_EXTERNAL_STORAGE) != 0
2037                 && isPackageUnavailable(pm)) {
2038             return Resources.getSystem().getDrawable(
2039                     com.android.internal.R.drawable.sym_app_on_sd_unavailable_icon);
2040         }
2041         return pm.getDefaultActivityIcon();
2042     }
2043 
2044     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
isPackageUnavailable(PackageManager pm)2045     private boolean isPackageUnavailable(PackageManager pm) {
2046         try {
2047             return pm.getPackageInfo(packageName, 0) == null;
2048         } catch (NameNotFoundException ex) {
2049             return true;
2050         }
2051     }
2052 
2053     /** @hide */
isDefaultToDeviceProtectedStorage()2054     public boolean isDefaultToDeviceProtectedStorage() {
2055         return (privateFlags
2056                 & ApplicationInfo.PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) != 0;
2057     }
2058 
2059     /** @hide */
isDirectBootAware()2060     public boolean isDirectBootAware() {
2061         return (privateFlags & ApplicationInfo.PRIVATE_FLAG_DIRECT_BOOT_AWARE) != 0;
2062     }
2063 
2064     /**
2065      * Check whether the application is encryption aware.
2066      *
2067      * @see #isDirectBootAware()
2068      * @see #isPartiallyDirectBootAware()
2069      *
2070      * @hide
2071      */
2072     @SystemApi
isEncryptionAware()2073     public boolean isEncryptionAware() {
2074         return isDirectBootAware() || isPartiallyDirectBootAware();
2075     }
2076 
2077     /** @hide */
isExternal()2078     public boolean isExternal() {
2079         return (flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0;
2080     }
2081 
2082     /**
2083      * True if the application is installed as an instant app.
2084      * @hide
2085      */
2086     @SystemApi
isInstantApp()2087     public boolean isInstantApp() {
2088         return (privateFlags & ApplicationInfo.PRIVATE_FLAG_INSTANT) != 0;
2089     }
2090 
2091     /** @hide */
isInternal()2092     public boolean isInternal() {
2093         return (flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) == 0;
2094     }
2095 
2096     /** @hide */
isOem()2097     public boolean isOem() {
2098         return (privateFlags & ApplicationInfo.PRIVATE_FLAG_OEM) != 0;
2099     }
2100 
2101     /** @hide */
isOdm()2102     public boolean isOdm() {
2103         return (privateFlags & ApplicationInfo.PRIVATE_FLAG_ODM) != 0;
2104     }
2105 
2106     /** @hide */
isPartiallyDirectBootAware()2107     public boolean isPartiallyDirectBootAware() {
2108         return (privateFlags & ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE) != 0;
2109     }
2110 
2111     /** @hide */
isSignedWithPlatformKey()2112     public boolean isSignedWithPlatformKey() {
2113         return (privateFlags & ApplicationInfo.PRIVATE_FLAG_SIGNED_WITH_PLATFORM_KEY) != 0;
2114     }
2115 
2116     /** @hide */
2117     @TestApi
isPrivilegedApp()2118     public boolean isPrivilegedApp() {
2119         return (privateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0;
2120     }
2121 
2122     /** @hide */
isRequiredForSystemUser()2123     public boolean isRequiredForSystemUser() {
2124         return (privateFlags & ApplicationInfo.PRIVATE_FLAG_REQUIRED_FOR_SYSTEM_USER) != 0;
2125     }
2126 
2127     /** @hide */
isStaticSharedLibrary()2128     public boolean isStaticSharedLibrary() {
2129         return (privateFlags & ApplicationInfo.PRIVATE_FLAG_STATIC_SHARED_LIBRARY) != 0;
2130     }
2131 
2132     /** @hide */
2133     @TestApi
isSystemApp()2134     public boolean isSystemApp() {
2135         return (flags & ApplicationInfo.FLAG_SYSTEM) != 0;
2136     }
2137 
2138     /** @hide */
isUpdatedSystemApp()2139     public boolean isUpdatedSystemApp() {
2140         return (flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0;
2141     }
2142 
2143     /** @hide */
isVendor()2144     public boolean isVendor() {
2145         return (privateFlags & ApplicationInfo.PRIVATE_FLAG_VENDOR) != 0;
2146     }
2147 
2148     /** @hide */
isProduct()2149     public boolean isProduct() {
2150         return (privateFlags & ApplicationInfo.PRIVATE_FLAG_PRODUCT) != 0;
2151     }
2152 
2153     /** @hide */
isSystemExt()2154     public boolean isSystemExt() {
2155         return (privateFlags & ApplicationInfo.PRIVATE_FLAG_SYSTEM_EXT) != 0;
2156     }
2157 
2158     /** @hide */
isEmbeddedDexUsed()2159     public boolean isEmbeddedDexUsed() {
2160         return (privateFlags & PRIVATE_FLAG_USE_EMBEDDED_DEX) != 0;
2161     }
2162 
2163     /**
2164      * Returns whether or not this application was installed as a virtual preload.
2165      */
isVirtualPreload()2166     public boolean isVirtualPreload() {
2167         return (privateFlags & PRIVATE_FLAG_VIRTUAL_PRELOAD) != 0;
2168     }
2169 
2170     /**
2171      * Returns whether or not this application can be profiled by the shell user,
2172      * even when running on a device that is running in user mode.
2173      */
isProfileableByShell()2174     public boolean isProfileableByShell() {
2175         return (privateFlags & PRIVATE_FLAG_PROFILEABLE_BY_SHELL) != 0;
2176     }
2177 
2178     /**
2179      * Returns true if the app has declared in its manifest that it wants its split APKs to be
2180      * loaded into isolated Contexts, with their own ClassLoaders and Resources objects.
2181      * @hide
2182      */
requestsIsolatedSplitLoading()2183     public boolean requestsIsolatedSplitLoading() {
2184         return (privateFlags & ApplicationInfo.PRIVATE_FLAG_ISOLATED_SPLIT_LOADING) != 0;
2185     }
2186 
2187     /**
2188      * Returns true if the package has declared in its manifest that it is a
2189      * runtime resource overlay.
2190      */
isResourceOverlay()2191     public boolean isResourceOverlay() {
2192         return (privateFlags & ApplicationInfo.PRIVATE_FLAG_IS_RESOURCE_OVERLAY) != 0;
2193     }
2194 
2195     /**
2196      * @hide
2197      */
getApplicationInfo()2198     @Override protected ApplicationInfo getApplicationInfo() {
2199         return this;
2200     }
2201 
2202     /**
2203      * Return all the APK paths that may be required to load this application, including all
2204      * splits, shared libraries, and resource overlays.
2205      * @hide
2206      */
getAllApkPaths()2207     public String[] getAllApkPaths() {
2208         final String[][] inputLists = { splitSourceDirs, sharedLibraryFiles, resourceDirs };
2209         final List<String> output = new ArrayList<>(10);
2210         if (sourceDir != null) {
2211             output.add(sourceDir);
2212         }
2213         for (String[] inputList : inputLists) {
2214             if (inputList != null) {
2215                 for (String input : inputList) {
2216                     output.add(input);
2217                 }
2218             }
2219         }
2220         return output.toArray(new String[output.size()]);
2221     }
2222 
setCodePath(String codePath)2223     /** {@hide} */ public void setCodePath(String codePath) { scanSourceDir = codePath; }
setBaseCodePath(String baseCodePath)2224     /** {@hide} */ public void setBaseCodePath(String baseCodePath) { sourceDir = baseCodePath; }
setSplitCodePaths(String[] splitCodePaths)2225     /** {@hide} */ public void setSplitCodePaths(String[] splitCodePaths) { splitSourceDirs = splitCodePaths; }
setResourcePath(String resourcePath)2226     /** {@hide} */ public void setResourcePath(String resourcePath) { scanPublicSourceDir = resourcePath; }
setBaseResourcePath(String baseResourcePath)2227     /** {@hide} */ public void setBaseResourcePath(String baseResourcePath) { publicSourceDir = baseResourcePath; }
setSplitResourcePaths(String[] splitResourcePaths)2228     /** {@hide} */ public void setSplitResourcePaths(String[] splitResourcePaths) { splitPublicSourceDirs = splitResourcePaths; }
setGwpAsanMode(@wpAsanMode int value)2229     /** {@hide} */ public void setGwpAsanMode(@GwpAsanMode int value) { gwpAsanMode = value; }
2230 
2231     /** {@hide} */
2232     @UnsupportedAppUsage
getCodePath()2233     public String getCodePath() { return scanSourceDir; }
getBaseCodePath()2234     /** {@hide} */ public String getBaseCodePath() { return sourceDir; }
getSplitCodePaths()2235     /** {@hide} */ public String[] getSplitCodePaths() { return splitSourceDirs; }
getResourcePath()2236     /** {@hide} */ public String getResourcePath() { return scanPublicSourceDir; }
2237     /** {@hide} */
2238     @UnsupportedAppUsage
getBaseResourcePath()2239     public String getBaseResourcePath() { return publicSourceDir; }
getSplitResourcePaths()2240     /** {@hide} */ public String[] getSplitResourcePaths() { return splitPublicSourceDirs; }
2241     @GwpAsanMode
getGwpAsanMode()2242     public int getGwpAsanMode() { return gwpAsanMode; }
2243 }
2244