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