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