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