Home | History | Annotate | Download | only in pm
      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.SystemApi;
     23 import android.annotation.TestApi;
     24 import android.content.Context;
     25 import android.content.pm.PackageManager.NameNotFoundException;
     26 import android.content.res.Resources;
     27 import android.graphics.drawable.Drawable;
     28 import android.os.Environment;
     29 import android.os.Parcel;
     30 import android.os.Parcelable;
     31 import android.os.UserHandle;
     32 import android.os.storage.StorageManager;
     33 import android.text.TextUtils;
     34 import android.util.Printer;
     35 import android.util.SparseArray;
     36 
     37 import com.android.internal.util.ArrayUtils;
     38 
     39 import java.lang.annotation.Retention;
     40 import java.lang.annotation.RetentionPolicy;
     41 import java.text.Collator;
     42 import java.util.Arrays;
     43 import java.util.Comparator;
     44 import java.util.Objects;
     45 import java.util.UUID;
     46 
     47 /**
     48  * Information you can retrieve about a particular application.  This
     49  * corresponds to information collected from the AndroidManifest.xml's
     50  * <application> tag.
     51  */
     52 public class ApplicationInfo extends PackageItemInfo implements Parcelable {
     53 
     54     /**
     55      * Default task affinity of all activities in this application. See
     56      * {@link ActivityInfo#taskAffinity} for more information.  This comes
     57      * from the "taskAffinity" attribute.
     58      */
     59     public String taskAffinity;
     60 
     61     /**
     62      * Optional name of a permission required to be able to access this
     63      * application's components.  From the "permission" attribute.
     64      */
     65     public String permission;
     66 
     67     /**
     68      * The name of the process this application should run in.  From the
     69      * "process" attribute or, if not set, the same as
     70      * <var>packageName</var>.
     71      */
     72     public String processName;
     73 
     74     /**
     75      * Class implementing the Application object.  From the "class"
     76      * attribute.
     77      */
     78     public String className;
     79 
     80     /**
     81      * A style resource identifier (in the package's resources) of the
     82      * description of an application.  From the "description" attribute
     83      * or, if not set, 0.
     84      */
     85     public int descriptionRes;
     86 
     87     /**
     88      * A style resource identifier (in the package's resources) of the
     89      * default visual theme of the application.  From the "theme" attribute
     90      * or, if not set, 0.
     91      */
     92     public int theme;
     93 
     94     /**
     95      * Class implementing the Application's manage space
     96      * functionality.  From the "manageSpaceActivity"
     97      * attribute. This is an optional attribute and will be null if
     98      * applications don't specify it in their manifest
     99      */
    100     public String manageSpaceActivityName;
    101 
    102     /**
    103      * Class implementing the Application's backup functionality.  From
    104      * the "backupAgent" attribute.  This is an optional attribute and
    105      * will be null if the application does not specify it in its manifest.
    106      *
    107      * <p>If android:allowBackup is set to false, this attribute is ignored.
    108      */
    109     public String backupAgentName;
    110 
    111     /**
    112      * An optional attribute that indicates the app supports automatic backup of app data.
    113      * <p>0 is the default and means the app's entire data folder + managed external storage will
    114      * be backed up;
    115      * Any negative value indicates the app does not support full-data backup, though it may still
    116      * want to participate via the traditional key/value backup API;
    117      * A positive number specifies an xml resource in which the application has defined its backup
    118      * include/exclude criteria.
    119      * <p>If android:allowBackup is set to false, this attribute is ignored.
    120      *
    121      * @see android.content.Context#getNoBackupFilesDir()
    122      * @see #FLAG_ALLOW_BACKUP
    123      *
    124      * @hide
    125      */
    126     public int fullBackupContent = 0;
    127 
    128     /**
    129      * The default extra UI options for activities in this application.
    130      * Set from the {@link android.R.attr#uiOptions} attribute in the
    131      * activity's manifest.
    132      */
    133     public int uiOptions = 0;
    134 
    135     /**
    136      * Value for {@link #flags}: if set, this application is installed in the
    137      * device's system image.
    138      */
    139     public static final int FLAG_SYSTEM = 1<<0;
    140 
    141     /**
    142      * Value for {@link #flags}: set to true if this application would like to
    143      * allow debugging of its
    144      * code, even when installed on a non-development system.  Comes
    145      * from {@link android.R.styleable#AndroidManifestApplication_debuggable
    146      * android:debuggable} of the &lt;application&gt; tag.
    147      */
    148     public static final int FLAG_DEBUGGABLE = 1<<1;
    149 
    150     /**
    151      * Value for {@link #flags}: set to true if this application has code
    152      * associated with it.  Comes
    153      * from {@link android.R.styleable#AndroidManifestApplication_hasCode
    154      * android:hasCode} of the &lt;application&gt; tag.
    155      */
    156     public static final int FLAG_HAS_CODE = 1<<2;
    157 
    158     /**
    159      * Value for {@link #flags}: set to true if this application is persistent.
    160      * Comes from {@link android.R.styleable#AndroidManifestApplication_persistent
    161      * android:persistent} of the &lt;application&gt; tag.
    162      */
    163     public static final int FLAG_PERSISTENT = 1<<3;
    164 
    165     /**
    166      * Value for {@link #flags}: set to true if this application holds the
    167      * {@link android.Manifest.permission#FACTORY_TEST} permission and the
    168      * device is running in factory test mode.
    169      */
    170     public static final int FLAG_FACTORY_TEST = 1<<4;
    171 
    172     /**
    173      * Value for {@link #flags}: default value for the corresponding ActivityInfo flag.
    174      * Comes from {@link android.R.styleable#AndroidManifestApplication_allowTaskReparenting
    175      * android:allowTaskReparenting} of the &lt;application&gt; tag.
    176      */
    177     public static final int FLAG_ALLOW_TASK_REPARENTING = 1<<5;
    178 
    179     /**
    180      * Value for {@link #flags}: default value for the corresponding ActivityInfo flag.
    181      * Comes from {@link android.R.styleable#AndroidManifestApplication_allowClearUserData
    182      * android:allowClearUserData} of the &lt;application&gt; tag.
    183      */
    184     public static final int FLAG_ALLOW_CLEAR_USER_DATA = 1<<6;
    185 
    186     /**
    187      * Value for {@link #flags}: this is set if this application has been
    188      * installed as an update to a built-in system application.
    189      */
    190     public static final int FLAG_UPDATED_SYSTEM_APP = 1<<7;
    191 
    192     /**
    193      * Value for {@link #flags}: this is set if the application has specified
    194      * {@link android.R.styleable#AndroidManifestApplication_testOnly
    195      * android:testOnly} to be true.
    196      */
    197     public static final int FLAG_TEST_ONLY = 1<<8;
    198 
    199     /**
    200      * Value for {@link #flags}: true when the application's window can be
    201      * reduced in size for smaller screens.  Corresponds to
    202      * {@link android.R.styleable#AndroidManifestSupportsScreens_smallScreens
    203      * android:smallScreens}.
    204      */
    205     public static final int FLAG_SUPPORTS_SMALL_SCREENS = 1<<9;
    206 
    207     /**
    208      * Value for {@link #flags}: true when the application's window can be
    209      * displayed on normal screens.  Corresponds to
    210      * {@link android.R.styleable#AndroidManifestSupportsScreens_normalScreens
    211      * android:normalScreens}.
    212      */
    213     public static final int FLAG_SUPPORTS_NORMAL_SCREENS = 1<<10;
    214 
    215     /**
    216      * Value for {@link #flags}: true when the application's window can be
    217      * increased in size for larger screens.  Corresponds to
    218      * {@link android.R.styleable#AndroidManifestSupportsScreens_largeScreens
    219      * android:largeScreens}.
    220      */
    221     public static final int FLAG_SUPPORTS_LARGE_SCREENS = 1<<11;
    222 
    223     /**
    224      * Value for {@link #flags}: true when the application knows how to adjust
    225      * its UI for different screen sizes.  Corresponds to
    226      * {@link android.R.styleable#AndroidManifestSupportsScreens_resizeable
    227      * android:resizeable}.
    228      */
    229     public static final int FLAG_RESIZEABLE_FOR_SCREENS = 1<<12;
    230 
    231     /**
    232      * Value for {@link #flags}: true when the application knows how to
    233      * accomodate different screen densities.  Corresponds to
    234      * {@link android.R.styleable#AndroidManifestSupportsScreens_anyDensity
    235      * android:anyDensity}.
    236      */
    237     public static final int FLAG_SUPPORTS_SCREEN_DENSITIES = 1<<13;
    238 
    239     /**
    240      * Value for {@link #flags}: set to true if this application would like to
    241      * request the VM to operate under the safe mode. Comes from
    242      * {@link android.R.styleable#AndroidManifestApplication_vmSafeMode
    243      * android:vmSafeMode} of the &lt;application&gt; tag.
    244      */
    245     public static final int FLAG_VM_SAFE_MODE = 1<<14;
    246 
    247     /**
    248      * Value for {@link #flags}: set to <code>false</code> if the application does not wish
    249      * to permit any OS-driven backups of its data; <code>true</code> otherwise.
    250      *
    251      * <p>Comes from the
    252      * {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup}
    253      * attribute of the &lt;application&gt; tag.
    254      */
    255     public static final int FLAG_ALLOW_BACKUP = 1<<15;
    256 
    257     /**
    258      * Value for {@link #flags}: set to <code>false</code> if the application must be kept
    259      * in memory following a full-system restore operation; <code>true</code> otherwise.
    260      * Ordinarily, during a full system restore operation each application is shut down
    261      * following execution of its agent's onRestore() method.  Setting this attribute to
    262      * <code>false</code> prevents this.  Most applications will not need to set this attribute.
    263      *
    264      * <p>If
    265      * {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup}
    266      * is set to <code>false</code> or no
    267      * {@link android.R.styleable#AndroidManifestApplication_backupAgent android:backupAgent}
    268      * is specified, this flag will be ignored.
    269      *
    270      * <p>Comes from the
    271      * {@link android.R.styleable#AndroidManifestApplication_killAfterRestore android:killAfterRestore}
    272      * attribute of the &lt;application&gt; tag.
    273      */
    274     public static final int FLAG_KILL_AFTER_RESTORE = 1<<16;
    275 
    276     /**
    277      * Value for {@link #flags}: Set to <code>true</code> if the application's backup
    278      * agent claims to be able to handle restore data even "from the future,"
    279      * i.e. from versions of the application with a versionCode greater than
    280      * the one currently installed on the device.  <i>Use with caution!</i>  By default
    281      * this attribute is <code>false</code> and the Backup Manager will ensure that data
    282      * from "future" versions of the application are never supplied during a restore operation.
    283      *
    284      * <p>If
    285      * {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup}
    286      * is set to <code>false</code> or no
    287      * {@link android.R.styleable#AndroidManifestApplication_backupAgent android:backupAgent}
    288      * is specified, this flag will be ignored.
    289      *
    290      * <p>Comes from the
    291      * {@link android.R.styleable#AndroidManifestApplication_restoreAnyVersion android:restoreAnyVersion}
    292      * attribute of the &lt;application&gt; tag.
    293      */
    294     public static final int FLAG_RESTORE_ANY_VERSION = 1<<17;
    295 
    296     /**
    297      * Value for {@link #flags}: Set to true if the application is
    298      * currently installed on external/removable/unprotected storage.  Such
    299      * applications may not be available if their storage is not currently
    300      * mounted.  When the storage it is on is not available, it will look like
    301      * the application has been uninstalled (its .apk is no longer available)
    302      * but its persistent data is not removed.
    303      */
    304     public static final int FLAG_EXTERNAL_STORAGE = 1<<18;
    305 
    306     /**
    307      * Value for {@link #flags}: true when the application's window can be
    308      * increased in size for extra large screens.  Corresponds to
    309      * {@link android.R.styleable#AndroidManifestSupportsScreens_xlargeScreens
    310      * android:xlargeScreens}.
    311      */
    312     public static final int FLAG_SUPPORTS_XLARGE_SCREENS = 1<<19;
    313 
    314     /**
    315      * Value for {@link #flags}: true when the application has requested a
    316      * large heap for its processes.  Corresponds to
    317      * {@link android.R.styleable#AndroidManifestApplication_largeHeap
    318      * android:largeHeap}.
    319      */
    320     public static final int FLAG_LARGE_HEAP = 1<<20;
    321 
    322     /**
    323      * Value for {@link #flags}: true if this application's package is in
    324      * the stopped state.
    325      */
    326     public static final int FLAG_STOPPED = 1<<21;
    327 
    328     /**
    329      * Value for {@link #flags}: true  when the application is willing to support
    330      * RTL (right to left). All activities will inherit this value.
    331      *
    332      * Set from the {@link android.R.attr#supportsRtl} attribute in the
    333      * activity's manifest.
    334      *
    335      * Default value is false (no support for RTL).
    336      */
    337     public static final int FLAG_SUPPORTS_RTL = 1<<22;
    338 
    339     /**
    340      * Value for {@link #flags}: true if the application is currently
    341      * installed for the calling user.
    342      */
    343     public static final int FLAG_INSTALLED = 1<<23;
    344 
    345     /**
    346      * Value for {@link #flags}: true if the application only has its
    347      * data installed; the application package itself does not currently
    348      * exist on the device.
    349      */
    350     public static final int FLAG_IS_DATA_ONLY = 1<<24;
    351 
    352     /**
    353      * Value for {@link #flags}: true if the application was declared to be a
    354      * game, or false if it is a non-game application.
    355      *
    356      * @deprecated use {@link #CATEGORY_GAME} instead.
    357      */
    358     @Deprecated
    359     public static final int FLAG_IS_GAME = 1<<25;
    360 
    361     /**
    362      * Value for {@link #flags}: {@code true} if the application asks that only
    363      * full-data streaming backups of its data be performed even though it defines
    364      * a {@link android.app.backup.BackupAgent BackupAgent}, which normally
    365      * indicates that the app will manage its backed-up data via incremental
    366      * key/value updates.
    367      */
    368     public static final int FLAG_FULL_BACKUP_ONLY = 1<<26;
    369 
    370     /**
    371      * Value for {@link #flags}: {@code true} if the application may use cleartext network traffic
    372      * (e.g., HTTP rather than HTTPS; WebSockets rather than WebSockets Secure; XMPP, IMAP, STMP
    373      * without STARTTLS or TLS). If {@code false}, the app declares that it does not intend to use
    374      * cleartext network traffic, in which case platform components (e.g., HTTP stacks,
    375      * {@code DownloadManager}, {@code MediaPlayer}) will refuse app's requests to use cleartext
    376      * traffic. Third-party libraries are encouraged to honor this flag as well.
    377      *
    378      * <p>NOTE: {@code WebView} does not honor this flag.
    379      *
    380      * <p>This flag is ignored on Android N and above if an Android Network Security Config is
    381      * present.
    382      *
    383      * <p>This flag comes from
    384      * {@link android.R.styleable#AndroidManifestApplication_usesCleartextTraffic
    385      * android:usesCleartextTraffic} of the &lt;application&gt; tag.
    386      */
    387     public static final int FLAG_USES_CLEARTEXT_TRAFFIC = 1<<27;
    388 
    389     /**
    390      * When set installer extracts native libs from .apk files.
    391      */
    392     public static final int FLAG_EXTRACT_NATIVE_LIBS = 1<<28;
    393 
    394     /**
    395      * Value for {@link #flags}: {@code true} when the application's rendering
    396      * should be hardware accelerated.
    397      */
    398     public static final int FLAG_HARDWARE_ACCELERATED = 1<<29;
    399 
    400     /**
    401      * Value for {@link #flags}: true if this application's package is in
    402      * the suspended state.
    403      */
    404     public static final int FLAG_SUSPENDED = 1<<30;
    405 
    406     /**
    407      * Value for {@link #flags}: true if code from this application will need to be
    408      * loaded into other applications' processes. On devices that support multiple
    409      * instruction sets, this implies the code might be loaded into a process that's
    410      * using any of the devices supported instruction sets.
    411      *
    412      * <p> The system might treat such applications specially, for eg., by
    413      * extracting the application's native libraries for all supported instruction
    414      * sets or by compiling the application's dex code for all supported instruction
    415      * sets.
    416      */
    417     public static final int FLAG_MULTIARCH  = 1 << 31;
    418 
    419     /**
    420      * Flags associated with the application.  Any combination of
    421      * {@link #FLAG_SYSTEM}, {@link #FLAG_DEBUGGABLE}, {@link #FLAG_HAS_CODE},
    422      * {@link #FLAG_PERSISTENT}, {@link #FLAG_FACTORY_TEST}, and
    423      * {@link #FLAG_ALLOW_TASK_REPARENTING}
    424      * {@link #FLAG_ALLOW_CLEAR_USER_DATA}, {@link #FLAG_UPDATED_SYSTEM_APP},
    425      * {@link #FLAG_TEST_ONLY}, {@link #FLAG_SUPPORTS_SMALL_SCREENS},
    426      * {@link #FLAG_SUPPORTS_NORMAL_SCREENS},
    427      * {@link #FLAG_SUPPORTS_LARGE_SCREENS}, {@link #FLAG_SUPPORTS_XLARGE_SCREENS},
    428      * {@link #FLAG_RESIZEABLE_FOR_SCREENS},
    429      * {@link #FLAG_SUPPORTS_SCREEN_DENSITIES}, {@link #FLAG_VM_SAFE_MODE},
    430      * {@link #FLAG_ALLOW_BACKUP}, {@link #FLAG_KILL_AFTER_RESTORE},
    431      * {@link #FLAG_RESTORE_ANY_VERSION}, {@link #FLAG_EXTERNAL_STORAGE},
    432      * {@link #FLAG_LARGE_HEAP}, {@link #FLAG_STOPPED},
    433      * {@link #FLAG_SUPPORTS_RTL}, {@link #FLAG_INSTALLED},
    434      * {@link #FLAG_IS_DATA_ONLY}, {@link #FLAG_IS_GAME},
    435      * {@link #FLAG_FULL_BACKUP_ONLY}, {@link #FLAG_USES_CLEARTEXT_TRAFFIC},
    436      * {@link #FLAG_MULTIARCH}.
    437      */
    438     public int flags = 0;
    439 
    440     /**
    441      * Value for {@link #privateFlags}: true if the application is hidden via restrictions and for
    442      * most purposes is considered as not installed.
    443      * {@hide}
    444      */
    445     public static final int PRIVATE_FLAG_HIDDEN = 1<<0;
    446 
    447     /**
    448      * Value for {@link #privateFlags}: set to <code>true</code> if the application
    449      * has reported that it is heavy-weight, and thus can not participate in
    450      * the normal application lifecycle.
    451      *
    452      * <p>Comes from the
    453      * android.R.styleable#AndroidManifestApplication_cantSaveState
    454      * attribute of the &lt;application&gt; tag.
    455      *
    456      * {@hide}
    457      */
    458     public static final int PRIVATE_FLAG_CANT_SAVE_STATE = 1<<1;
    459 
    460     /**
    461      * Value for {@link #privateFlags}: Set to true if the application has been
    462      * installed using the forward lock option.
    463      *
    464      * NOTE: DO NOT CHANGE THIS VALUE!  It is saved in packages.xml.
    465      *
    466      * {@hide}
    467      */
    468     public static final int PRIVATE_FLAG_FORWARD_LOCK = 1<<2;
    469 
    470     /**
    471      * Value for {@link #privateFlags}: set to {@code true} if the application
    472      * is permitted to hold privileged permissions.
    473      *
    474      * {@hide}
    475      */
    476     public static final int PRIVATE_FLAG_PRIVILEGED = 1<<3;
    477 
    478     /**
    479      * Value for {@link #privateFlags}: {@code true} if the application has any IntentFiler
    480      * with some data URI using HTTP or HTTPS with an associated VIEW action.
    481      *
    482      * {@hide}
    483      */
    484     public static final int PRIVATE_FLAG_HAS_DOMAIN_URLS = 1<<4;
    485 
    486     /**
    487      * When set, the default data storage directory for this app is pointed at
    488      * the device-protected location.
    489      *
    490      * @hide
    491      */
    492     public static final int PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE = 1 << 5;
    493 
    494     /**
    495      * When set, assume that all components under the given app are direct boot
    496      * aware, unless otherwise specified.
    497      *
    498      * @hide
    499      */
    500     public static final int PRIVATE_FLAG_DIRECT_BOOT_AWARE = 1 << 6;
    501 
    502     /**
    503      * Value for {@link #privateFlags}: {@code true} if the application is installed
    504      * as instant app.
    505      *
    506      * @hide
    507      */
    508     public static final int PRIVATE_FLAG_INSTANT = 1 << 7;
    509 
    510     /**
    511      * When set, at least one component inside this application is direct boot
    512      * aware.
    513      *
    514      * @hide
    515      */
    516     public static final int PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE = 1 << 8;
    517 
    518 
    519     /**
    520      * When set, signals that the application is required for the system user and should not be
    521      * uninstalled.
    522      *
    523      * @hide
    524      */
    525     public static final int PRIVATE_FLAG_REQUIRED_FOR_SYSTEM_USER = 1 << 9;
    526 
    527     /**
    528      * When set, the application explicitly requested that its activities be resizeable by default.
    529      * @see android.R.styleable#AndroidManifestActivity_resizeableActivity
    530      *
    531      * @hide
    532      */
    533     public static final int PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE = 1 << 10;
    534 
    535     /**
    536      * When set, the application explicitly requested that its activities *not* be resizeable by
    537      * default.
    538      * @see android.R.styleable#AndroidManifestActivity_resizeableActivity
    539      *
    540      * @hide
    541      */
    542     public static final int PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_UNRESIZEABLE = 1 << 11;
    543 
    544     /**
    545      * The application isn't requesting explicitly requesting for its activities to be resizeable or
    546      * non-resizeable by default. So, we are making it activities resizeable by default based on the
    547      * target SDK version of the app.
    548      * @see android.R.styleable#AndroidManifestActivity_resizeableActivity
    549      *
    550      * NOTE: This only affects apps with target SDK >= N where the resizeableActivity attribute was
    551      * introduced. It shouldn't be confused with {@link ActivityInfo#RESIZE_MODE_FORCE_RESIZEABLE}
    552      * where certain pre-N apps are forced to the resizeable.
    553      *
    554      * @hide
    555      */
    556     public static final int PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION =
    557             1 << 12;
    558 
    559     /**
    560      * Value for {@link #privateFlags}: {@code true} means the OS should go ahead and
    561      * run full-data backup operations for the app even when it is in a
    562      * foreground-equivalent run state.  Defaults to {@code false} if unspecified.
    563      * @hide
    564      */
    565     public static final int PRIVATE_FLAG_BACKUP_IN_FOREGROUND = 1 << 13;
    566 
    567     /**
    568      * Value for {@link #privateFlags}: {@code true} means this application
    569      * contains a static shared library. Defaults to {@code false} if unspecified.
    570      * @hide
    571      */
    572     public static final int PRIVATE_FLAG_STATIC_SHARED_LIBRARY = 1 << 14;
    573 
    574     /**
    575      * Value for {@link #privateFlags}: When set, the application will only have its splits loaded
    576      * if they are required to load a component. Splits can be loaded on demand using the
    577      * {@link Context#createContextForSplit(String)} API.
    578      * @hide
    579      */
    580     public static final int PRIVATE_FLAG_ISOLATED_SPLIT_LOADING = 1 << 15;
    581 
    582     /**
    583      * Value for {@link #privateFlags}: When set, the application was installed as
    584      * a virtual preload.
    585      * @hide
    586      */
    587     public static final int PRIVATE_FLAG_VIRTUAL_PRELOAD = 1 << 16;
    588 
    589     /** @hide */
    590     @IntDef(flag = true, prefix = { "PRIVATE_FLAG_" }, value = {
    591             PRIVATE_FLAG_HIDDEN,
    592             PRIVATE_FLAG_CANT_SAVE_STATE,
    593             PRIVATE_FLAG_FORWARD_LOCK,
    594             PRIVATE_FLAG_PRIVILEGED,
    595             PRIVATE_FLAG_HAS_DOMAIN_URLS,
    596             PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE,
    597             PRIVATE_FLAG_DIRECT_BOOT_AWARE,
    598             PRIVATE_FLAG_INSTANT,
    599             PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE,
    600             PRIVATE_FLAG_REQUIRED_FOR_SYSTEM_USER,
    601             PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE,
    602             PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_UNRESIZEABLE,
    603             PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION,
    604             PRIVATE_FLAG_BACKUP_IN_FOREGROUND,
    605             PRIVATE_FLAG_STATIC_SHARED_LIBRARY,
    606             PRIVATE_FLAG_ISOLATED_SPLIT_LOADING,
    607             PRIVATE_FLAG_VIRTUAL_PRELOAD,
    608     })
    609     @Retention(RetentionPolicy.SOURCE)
    610     public @interface ApplicationInfoPrivateFlags {}
    611 
    612     /**
    613      * Private/hidden flags. See {@code PRIVATE_FLAG_...} constants.
    614      * @hide
    615      */
    616     public @ApplicationInfoPrivateFlags int privateFlags;
    617 
    618     /**
    619      * @hide
    620      */
    621     public static final String METADATA_PRELOADED_FONTS = "preloaded_fonts";
    622 
    623     /**
    624      * The required smallest screen width the application can run on.  If 0,
    625      * nothing has been specified.  Comes from
    626      * {@link android.R.styleable#AndroidManifestSupportsScreens_requiresSmallestWidthDp
    627      * android:requiresSmallestWidthDp} attribute of the &lt;supports-screens&gt; tag.
    628      */
    629     public int requiresSmallestWidthDp = 0;
    630 
    631     /**
    632      * The maximum smallest screen width the application is designed for.  If 0,
    633      * nothing has been specified.  Comes from
    634      * {@link android.R.styleable#AndroidManifestSupportsScreens_compatibleWidthLimitDp
    635      * android:compatibleWidthLimitDp} attribute of the &lt;supports-screens&gt; tag.
    636      */
    637     public int compatibleWidthLimitDp = 0;
    638 
    639     /**
    640      * The maximum smallest screen width the application will work on.  If 0,
    641      * nothing has been specified.  Comes from
    642      * {@link android.R.styleable#AndroidManifestSupportsScreens_largestWidthLimitDp
    643      * android:largestWidthLimitDp} attribute of the &lt;supports-screens&gt; tag.
    644      */
    645     public int largestWidthLimitDp = 0;
    646 
    647     /**
    648      * Value indicating the maximum aspect ratio the application supports.
    649      * <p>
    650      * 0 means unset.
    651      * @See {@link android.R.attr#maxAspectRatio}.
    652      * @hide
    653      */
    654     public float maxAspectRatio;
    655 
    656     /** @removed */
    657     @Deprecated
    658     public String volumeUuid;
    659 
    660     /**
    661      * UUID of the storage volume on which this application is being hosted. For
    662      * apps hosted on the default internal storage at
    663      * {@link Environment#getDataDirectory()}, the UUID value is
    664      * {@link StorageManager#UUID_DEFAULT}.
    665      */
    666     public UUID storageUuid;
    667 
    668     /** {@hide} */
    669     public String scanSourceDir;
    670     /** {@hide} */
    671     public String scanPublicSourceDir;
    672 
    673     /**
    674      * Full path to the base APK for this application.
    675      */
    676     public String sourceDir;
    677 
    678     /**
    679      * Full path to the publicly available parts of {@link #sourceDir},
    680      * including resources and manifest. This may be different from
    681      * {@link #sourceDir} if an application is forward locked.
    682      */
    683     public String publicSourceDir;
    684 
    685     /**
    686      * The names of all installed split APKs, ordered lexicographically.
    687      */
    688     public String[] splitNames;
    689 
    690     /**
    691      * Full paths to zero or more split APKs, indexed by the same order as {@link #splitNames}.
    692      */
    693     public String[] splitSourceDirs;
    694 
    695     /**
    696      * Full path to the publicly available parts of {@link #splitSourceDirs},
    697      * including resources and manifest. This may be different from
    698      * {@link #splitSourceDirs} if an application is forward locked.
    699      *
    700      * @see #splitSourceDirs
    701      */
    702     public String[] splitPublicSourceDirs;
    703 
    704     /**
    705      * Maps the dependencies between split APKs. All splits implicitly depend on the base APK.
    706      *
    707      * Available since platform version O.
    708      *
    709      * Only populated if the application opts in to isolated split loading via the
    710      * {@link android.R.attr.isolatedSplits} attribute in the &lt;manifest&gt; tag of the app's
    711      * AndroidManifest.xml.
    712      *
    713      * The keys and values are all indices into the {@link #splitNames}, {@link #splitSourceDirs},
    714      * and {@link #splitPublicSourceDirs} arrays.
    715      * Each key represents a split and its value is an array of splits. The first element of this
    716      * array is the parent split, and the rest are configuration splits. These configuration splits
    717      * have no dependencies themselves.
    718      * Cycles do not exist because they are illegal and screened for during installation.
    719      *
    720      * May be null if no splits are installed, or if no dependencies exist between them.
    721      *
    722      * NOTE: Any change to the way split dependencies are stored must update the logic that
    723      *       creates the class loader context for dexopt (DexoptUtils#getClassLoaderContexts).
    724      *
    725      * @hide
    726      */
    727     public SparseArray<int[]> splitDependencies;
    728 
    729     /**
    730      * Full paths to the locations of extra resource packages (runtime overlays)
    731      * this application uses. This field is only used if there are extra resource
    732      * packages, otherwise it is null.
    733      *
    734      * {@hide}
    735      */
    736     public String[] resourceDirs;
    737 
    738     /**
    739      * String retrieved from the seinfo tag found in selinux policy. This value
    740      * can be overridden with a value set through the mac_permissions.xml policy
    741      * construct. This value is useful in setting an SELinux security context on
    742      * the process as well as its data directory. The String default is being used
    743      * here to represent a catchall label when no policy matches.
    744      *
    745      * {@hide}
    746      */
    747     public String seInfo = "default";
    748 
    749     /**
    750      * The seinfo tag generated per-user. This value may change based upon the
    751      * user's configuration. For example, when an instant app is installed for
    752      * a user. It is an error if this field is ever {@code null} when trying to
    753      * start a new process.
    754      * <p>NOTE: We need to separate this out because we modify per-user values
    755      * multiple times. This needs to be refactored since we're performing more
    756      * work than necessary and these values should only be set once. When that
    757      * happens, we can merge the per-user value with the seInfo state above.
    758      *
    759      * {@hide}
    760      */
    761     public String seInfoUser;
    762 
    763     /**
    764      * Paths to all shared libraries this application is linked against.  This
    765      * field is only set if the {@link PackageManager#GET_SHARED_LIBRARY_FILES
    766      * PackageManager.GET_SHARED_LIBRARY_FILES} flag was used when retrieving
    767      * the structure.
    768      */
    769     public String[] sharedLibraryFiles;
    770 
    771     /**
    772      * Full path to the default directory assigned to the package for its
    773      * persistent data.
    774      */
    775     public String dataDir;
    776 
    777     /**
    778      * Full path to the device-protected directory assigned to the package for
    779      * its persistent data.
    780      *
    781      * @see Context#createDeviceProtectedStorageContext()
    782      */
    783     public String deviceProtectedDataDir;
    784 
    785     /**
    786      * Full path to the credential-protected directory assigned to the package
    787      * for its persistent data.
    788      *
    789      * @hide
    790      */
    791     @SystemApi
    792     public String credentialProtectedDataDir;
    793 
    794     /**
    795      * Full path to the directory where native JNI libraries are stored.
    796      */
    797     public String nativeLibraryDir;
    798 
    799     /**
    800      * Full path where unpacked native libraries for {@link #secondaryCpuAbi}
    801      * are stored, if present.
    802      *
    803      * The main reason this exists is for bundled multi-arch apps, where
    804      * it's not trivial to calculate the location of libs for the secondary abi
    805      * given the location of the primary.
    806      *
    807      * TODO: Change the layout of bundled installs so that we can use
    808      * nativeLibraryRootDir & nativeLibraryRootRequiresIsa there as well.
    809      * (e.g {@code [ "/system/app-lib/Foo/arm", "/system/app-lib/Foo/arm64" ]}
    810      * instead of {@code [ "/system/lib/Foo", "/system/lib64/Foo" ]}.
    811      *
    812      * @hide
    813      */
    814     public String secondaryNativeLibraryDir;
    815 
    816     /**
    817      * The root path where unpacked native libraries are stored.
    818      * <p>
    819      * When {@link #nativeLibraryRootRequiresIsa} is set, the libraries are
    820      * placed in ISA-specific subdirectories under this path, otherwise the
    821      * libraries are placed directly at this path.
    822      *
    823      * @hide
    824      */
    825     public String nativeLibraryRootDir;
    826 
    827     /**
    828      * Flag indicating that ISA must be appended to
    829      * {@link #nativeLibraryRootDir} to be useful.
    830      *
    831      * @hide
    832      */
    833     public boolean nativeLibraryRootRequiresIsa;
    834 
    835     /**
    836      * The primary ABI that this application requires, This is inferred from the ABIs
    837      * of the native JNI libraries the application bundles. Will be {@code null}
    838      * if this application does not require any particular ABI.
    839      *
    840      * If non-null, the application will always be launched with this ABI.
    841      *
    842      * {@hide}
    843      */
    844     public String primaryCpuAbi;
    845 
    846     /**
    847      * The secondary ABI for this application. Might be non-null for multi-arch
    848      * installs. The application itself never uses this ABI, but other applications that
    849      * use its code might.
    850      *
    851      * {@hide}
    852      */
    853     public String secondaryCpuAbi;
    854 
    855     /**
    856      * The kernel user-ID that has been assigned to this application;
    857      * currently this is not a unique ID (multiple applications can have
    858      * the same uid).
    859      */
    860     public int uid;
    861 
    862     /**
    863      * The minimum SDK version this application can run on. It will not run
    864      * on earlier versions.
    865      */
    866     public int minSdkVersion;
    867 
    868     /**
    869      * The minimum SDK version this application targets.  It may run on earlier
    870      * versions, but it knows how to work with any new behavior added at this
    871      * version.  Will be {@link android.os.Build.VERSION_CODES#CUR_DEVELOPMENT}
    872      * if this is a development build and the app is targeting that.  You should
    873      * compare that this number is >= the SDK version number at which your
    874      * behavior was introduced.
    875      */
    876     public int targetSdkVersion;
    877 
    878     /**
    879      * The app's declared version code.
    880      * @hide
    881      */
    882     public int versionCode;
    883 
    884     /**
    885      * When false, indicates that all components within this application are
    886      * considered disabled, regardless of their individually set enabled status.
    887      */
    888     public boolean enabled = true;
    889 
    890     /**
    891      * For convenient access to the current enabled setting of this app.
    892      * @hide
    893      */
    894     public int enabledSetting = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
    895 
    896     /**
    897      * For convenient access to package's install location.
    898      * @hide
    899      */
    900     public int installLocation = PackageInfo.INSTALL_LOCATION_UNSPECIFIED;
    901 
    902     /**
    903      * Resource file providing the application's Network Security Config.
    904      * @hide
    905      */
    906     public int networkSecurityConfigRes;
    907 
    908     /**
    909      * Version of the sandbox the application wants to run in.
    910      * @hide
    911      */
    912     public int targetSandboxVersion;
    913 
    914     /**
    915      * The category of this app. Categories are used to cluster multiple apps
    916      * together into meaningful groups, such as when summarizing battery,
    917      * network, or disk usage. Apps should only define this value when they fit
    918      * well into one of the specific categories.
    919      * <p>
    920      * Set from the {@link android.R.attr#appCategory} attribute in the
    921      * manifest. If the manifest doesn't define a category, this value may have
    922      * been provided by the installer via
    923      * {@link PackageManager#setApplicationCategoryHint(String, int)}.
    924      */
    925     public @Category int category = CATEGORY_UNDEFINED;
    926 
    927     /** {@hide} */
    928     @IntDef(prefix = { "CATEGORY_" }, value = {
    929             CATEGORY_UNDEFINED,
    930             CATEGORY_GAME,
    931             CATEGORY_AUDIO,
    932             CATEGORY_VIDEO,
    933             CATEGORY_IMAGE,
    934             CATEGORY_SOCIAL,
    935             CATEGORY_NEWS,
    936             CATEGORY_MAPS,
    937             CATEGORY_PRODUCTIVITY
    938     })
    939     @Retention(RetentionPolicy.SOURCE)
    940     public @interface Category {
    941     }
    942 
    943     /**
    944      * Value when category is undefined.
    945      *
    946      * @see #category
    947      */
    948     public static final int CATEGORY_UNDEFINED = -1;
    949 
    950     /**
    951      * Category for apps which are primarily games.
    952      *
    953      * @see #category
    954      */
    955     public static final int CATEGORY_GAME = 0;
    956 
    957     /**
    958      * Category for apps which primarily work with audio or music, such as music
    959      * players.
    960      *
    961      * @see #category
    962      */
    963     public static final int CATEGORY_AUDIO = 1;
    964 
    965     /**
    966      * Category for apps which primarily work with video or movies, such as
    967      * streaming video apps.
    968      *
    969      * @see #category
    970      */
    971     public static final int CATEGORY_VIDEO = 2;
    972 
    973     /**
    974      * Category for apps which primarily work with images or photos, such as
    975      * camera or gallery apps.
    976      *
    977      * @see #category
    978      */
    979     public static final int CATEGORY_IMAGE = 3;
    980 
    981     /**
    982      * Category for apps which are primarily social apps, such as messaging,
    983      * communication, email, or social network apps.
    984      *
    985      * @see #category
    986      */
    987     public static final int CATEGORY_SOCIAL = 4;
    988 
    989     /**
    990      * Category for apps which are primarily news apps, such as newspapers,
    991      * magazines, or sports apps.
    992      *
    993      * @see #category
    994      */
    995     public static final int CATEGORY_NEWS = 5;
    996 
    997     /**
    998      * Category for apps which are primarily maps apps, such as navigation apps.
    999      *
   1000      * @see #category
   1001      */
   1002     public static final int CATEGORY_MAPS = 6;
   1003 
   1004     /**
   1005      * Category for apps which are primarily productivity apps, such as cloud
   1006      * storage or workplace apps.
   1007      *
   1008      * @see #category
   1009      */
   1010     public static final int CATEGORY_PRODUCTIVITY = 7;
   1011 
   1012     /**
   1013      * Return a concise, localized title for the given
   1014      * {@link ApplicationInfo#category} value, or {@code null} for unknown
   1015      * values such as {@link #CATEGORY_UNDEFINED}.
   1016      *
   1017      * @see #category
   1018      */
   1019     public static CharSequence getCategoryTitle(Context context, @Category int category) {
   1020         switch (category) {
   1021             case ApplicationInfo.CATEGORY_GAME:
   1022                 return context.getText(com.android.internal.R.string.app_category_game);
   1023             case ApplicationInfo.CATEGORY_AUDIO:
   1024                 return context.getText(com.android.internal.R.string.app_category_audio);
   1025             case ApplicationInfo.CATEGORY_VIDEO:
   1026                 return context.getText(com.android.internal.R.string.app_category_video);
   1027             case ApplicationInfo.CATEGORY_IMAGE:
   1028                 return context.getText(com.android.internal.R.string.app_category_image);
   1029             case ApplicationInfo.CATEGORY_SOCIAL:
   1030                 return context.getText(com.android.internal.R.string.app_category_social);
   1031             case ApplicationInfo.CATEGORY_NEWS:
   1032                 return context.getText(com.android.internal.R.string.app_category_news);
   1033             case ApplicationInfo.CATEGORY_MAPS:
   1034                 return context.getText(com.android.internal.R.string.app_category_maps);
   1035             case ApplicationInfo.CATEGORY_PRODUCTIVITY:
   1036                 return context.getText(com.android.internal.R.string.app_category_productivity);
   1037             default:
   1038                 return null;
   1039         }
   1040     }
   1041 
   1042     /** @hide */
   1043     public String classLoaderName;
   1044 
   1045     /** @hide */
   1046     public String[] splitClassLoaderNames;
   1047 
   1048     public void dump(Printer pw, String prefix) {
   1049         dump(pw, prefix, DUMP_FLAG_ALL);
   1050     }
   1051 
   1052     /** @hide */
   1053     public void dump(Printer pw, String prefix, int dumpFlags) {
   1054         super.dumpFront(pw, prefix);
   1055         if ((dumpFlags & DUMP_FLAG_DETAILS) != 0 && className != null) {
   1056             pw.println(prefix + "className=" + className);
   1057         }
   1058         if (permission != null) {
   1059             pw.println(prefix + "permission=" + permission);
   1060         }
   1061         pw.println(prefix + "processName=" + processName);
   1062         if ((dumpFlags & DUMP_FLAG_DETAILS) != 0) {
   1063             pw.println(prefix + "taskAffinity=" + taskAffinity);
   1064         }
   1065         pw.println(prefix + "uid=" + uid + " flags=0x" + Integer.toHexString(flags)
   1066                 + " privateFlags=0x" + Integer.toHexString(privateFlags)
   1067                 + " theme=0x" + Integer.toHexString(theme));
   1068         if ((dumpFlags & DUMP_FLAG_DETAILS) != 0) {
   1069             pw.println(prefix + "requiresSmallestWidthDp=" + requiresSmallestWidthDp
   1070                     + " compatibleWidthLimitDp=" + compatibleWidthLimitDp
   1071                     + " largestWidthLimitDp=" + largestWidthLimitDp);
   1072         }
   1073         pw.println(prefix + "sourceDir=" + sourceDir);
   1074         if (!Objects.equals(sourceDir, publicSourceDir)) {
   1075             pw.println(prefix + "publicSourceDir=" + publicSourceDir);
   1076         }
   1077         if (!ArrayUtils.isEmpty(splitSourceDirs)) {
   1078             pw.println(prefix + "splitSourceDirs=" + Arrays.toString(splitSourceDirs));
   1079         }
   1080         if (!ArrayUtils.isEmpty(splitPublicSourceDirs)
   1081                 && !Arrays.equals(splitSourceDirs, splitPublicSourceDirs)) {
   1082             pw.println(prefix + "splitPublicSourceDirs=" + Arrays.toString(splitPublicSourceDirs));
   1083         }
   1084         if (resourceDirs != null) {
   1085             pw.println(prefix + "resourceDirs=" + Arrays.toString(resourceDirs));
   1086         }
   1087         if ((dumpFlags & DUMP_FLAG_DETAILS) != 0 && seInfo != null) {
   1088             pw.println(prefix + "seinfo=" + seInfo);
   1089             pw.println(prefix + "seinfoUser=" + seInfoUser);
   1090         }
   1091         pw.println(prefix + "dataDir=" + dataDir);
   1092         if ((dumpFlags & DUMP_FLAG_DETAILS) != 0) {
   1093             pw.println(prefix + "deviceProtectedDataDir=" + deviceProtectedDataDir);
   1094             pw.println(prefix + "credentialProtectedDataDir=" + credentialProtectedDataDir);
   1095             if (sharedLibraryFiles != null) {
   1096                 pw.println(prefix + "sharedLibraryFiles=" + Arrays.toString(sharedLibraryFiles));
   1097             }
   1098         }
   1099         if (classLoaderName != null) {
   1100             pw.println(prefix + "classLoaderName=" + classLoaderName);
   1101         }
   1102         if (!ArrayUtils.isEmpty(splitClassLoaderNames)) {
   1103             pw.println(prefix + "splitClassLoaderNames=" + Arrays.toString(splitClassLoaderNames));
   1104         }
   1105 
   1106         pw.println(prefix + "enabled=" + enabled
   1107                 + " minSdkVersion=" + minSdkVersion
   1108                 + " targetSdkVersion=" + targetSdkVersion
   1109                 + " versionCode=" + versionCode
   1110                 + " targetSandboxVersion=" + targetSandboxVersion);
   1111         if ((dumpFlags & DUMP_FLAG_DETAILS) != 0) {
   1112             if (manageSpaceActivityName != null) {
   1113                 pw.println(prefix + "manageSpaceActivityName=" + manageSpaceActivityName);
   1114             }
   1115             if (descriptionRes != 0) {
   1116                 pw.println(prefix + "description=0x" + Integer.toHexString(descriptionRes));
   1117             }
   1118             if (uiOptions != 0) {
   1119                 pw.println(prefix + "uiOptions=0x" + Integer.toHexString(uiOptions));
   1120             }
   1121             pw.println(prefix + "supportsRtl=" + (hasRtlSupport() ? "true" : "false"));
   1122             if (fullBackupContent > 0) {
   1123                 pw.println(prefix + "fullBackupContent=@xml/" + fullBackupContent);
   1124             } else {
   1125                 pw.println(prefix + "fullBackupContent="
   1126                         + (fullBackupContent < 0 ? "false" : "true"));
   1127             }
   1128             if (networkSecurityConfigRes != 0) {
   1129                 pw.println(prefix + "networkSecurityConfigRes=0x"
   1130                         + Integer.toHexString(networkSecurityConfigRes));
   1131             }
   1132             if (category != CATEGORY_UNDEFINED) {
   1133                 pw.println(prefix + "category=" + category);
   1134             }
   1135         }
   1136         super.dumpBack(pw, prefix);
   1137     }
   1138 
   1139     /**
   1140      * @return true if "supportsRtl" has been set to true in the AndroidManifest
   1141      * @hide
   1142      */
   1143     public boolean hasRtlSupport() {
   1144         return (flags & FLAG_SUPPORTS_RTL) == FLAG_SUPPORTS_RTL;
   1145     }
   1146 
   1147     /** {@hide} */
   1148     public boolean hasCode() {
   1149         return (flags & FLAG_HAS_CODE) != 0;
   1150     }
   1151 
   1152     public static class DisplayNameComparator
   1153             implements Comparator<ApplicationInfo> {
   1154         public DisplayNameComparator(PackageManager pm) {
   1155             mPM = pm;
   1156         }
   1157 
   1158         public final int compare(ApplicationInfo aa, ApplicationInfo ab) {
   1159             CharSequence  sa = mPM.getApplicationLabel(aa);
   1160             if (sa == null) {
   1161                 sa = aa.packageName;
   1162             }
   1163             CharSequence  sb = mPM.getApplicationLabel(ab);
   1164             if (sb == null) {
   1165                 sb = ab.packageName;
   1166             }
   1167 
   1168             return sCollator.compare(sa.toString(), sb.toString());
   1169         }
   1170 
   1171         private final Collator   sCollator = Collator.getInstance();
   1172         private PackageManager   mPM;
   1173     }
   1174 
   1175     public ApplicationInfo() {
   1176     }
   1177 
   1178     public ApplicationInfo(ApplicationInfo orig) {
   1179         super(orig);
   1180         taskAffinity = orig.taskAffinity;
   1181         permission = orig.permission;
   1182         processName = orig.processName;
   1183         className = orig.className;
   1184         theme = orig.theme;
   1185         flags = orig.flags;
   1186         privateFlags = orig.privateFlags;
   1187         requiresSmallestWidthDp = orig.requiresSmallestWidthDp;
   1188         compatibleWidthLimitDp = orig.compatibleWidthLimitDp;
   1189         largestWidthLimitDp = orig.largestWidthLimitDp;
   1190         volumeUuid = orig.volumeUuid;
   1191         storageUuid = orig.storageUuid;
   1192         scanSourceDir = orig.scanSourceDir;
   1193         scanPublicSourceDir = orig.scanPublicSourceDir;
   1194         sourceDir = orig.sourceDir;
   1195         publicSourceDir = orig.publicSourceDir;
   1196         splitNames = orig.splitNames;
   1197         splitSourceDirs = orig.splitSourceDirs;
   1198         splitPublicSourceDirs = orig.splitPublicSourceDirs;
   1199         splitDependencies = orig.splitDependencies;
   1200         nativeLibraryDir = orig.nativeLibraryDir;
   1201         secondaryNativeLibraryDir = orig.secondaryNativeLibraryDir;
   1202         nativeLibraryRootDir = orig.nativeLibraryRootDir;
   1203         nativeLibraryRootRequiresIsa = orig.nativeLibraryRootRequiresIsa;
   1204         primaryCpuAbi = orig.primaryCpuAbi;
   1205         secondaryCpuAbi = orig.secondaryCpuAbi;
   1206         resourceDirs = orig.resourceDirs;
   1207         seInfo = orig.seInfo;
   1208         seInfoUser = orig.seInfoUser;
   1209         sharedLibraryFiles = orig.sharedLibraryFiles;
   1210         dataDir = orig.dataDir;
   1211         deviceProtectedDataDir = orig.deviceProtectedDataDir;
   1212         credentialProtectedDataDir = orig.credentialProtectedDataDir;
   1213         uid = orig.uid;
   1214         minSdkVersion = orig.minSdkVersion;
   1215         targetSdkVersion = orig.targetSdkVersion;
   1216         versionCode = orig.versionCode;
   1217         enabled = orig.enabled;
   1218         enabledSetting = orig.enabledSetting;
   1219         installLocation = orig.installLocation;
   1220         manageSpaceActivityName = orig.manageSpaceActivityName;
   1221         descriptionRes = orig.descriptionRes;
   1222         uiOptions = orig.uiOptions;
   1223         backupAgentName = orig.backupAgentName;
   1224         fullBackupContent = orig.fullBackupContent;
   1225         networkSecurityConfigRes = orig.networkSecurityConfigRes;
   1226         category = orig.category;
   1227         targetSandboxVersion = orig.targetSandboxVersion;
   1228         classLoaderName = orig.classLoaderName;
   1229         splitClassLoaderNames = orig.splitClassLoaderNames;
   1230     }
   1231 
   1232     public String toString() {
   1233         return "ApplicationInfo{"
   1234             + Integer.toHexString(System.identityHashCode(this))
   1235             + " " + packageName + "}";
   1236     }
   1237 
   1238     public int describeContents() {
   1239         return 0;
   1240     }
   1241 
   1242     @SuppressWarnings("unchecked")
   1243     public void writeToParcel(Parcel dest, int parcelableFlags) {
   1244         super.writeToParcel(dest, parcelableFlags);
   1245         dest.writeString(taskAffinity);
   1246         dest.writeString(permission);
   1247         dest.writeString(processName);
   1248         dest.writeString(className);
   1249         dest.writeInt(theme);
   1250         dest.writeInt(flags);
   1251         dest.writeInt(privateFlags);
   1252         dest.writeInt(requiresSmallestWidthDp);
   1253         dest.writeInt(compatibleWidthLimitDp);
   1254         dest.writeInt(largestWidthLimitDp);
   1255         if (storageUuid != null) {
   1256             dest.writeInt(1);
   1257             dest.writeLong(storageUuid.getMostSignificantBits());
   1258             dest.writeLong(storageUuid.getLeastSignificantBits());
   1259         } else {
   1260             dest.writeInt(0);
   1261         }
   1262         dest.writeString(scanSourceDir);
   1263         dest.writeString(scanPublicSourceDir);
   1264         dest.writeString(sourceDir);
   1265         dest.writeString(publicSourceDir);
   1266         dest.writeStringArray(splitNames);
   1267         dest.writeStringArray(splitSourceDirs);
   1268         dest.writeStringArray(splitPublicSourceDirs);
   1269         dest.writeSparseArray((SparseArray) splitDependencies);
   1270         dest.writeString(nativeLibraryDir);
   1271         dest.writeString(secondaryNativeLibraryDir);
   1272         dest.writeString(nativeLibraryRootDir);
   1273         dest.writeInt(nativeLibraryRootRequiresIsa ? 1 : 0);
   1274         dest.writeString(primaryCpuAbi);
   1275         dest.writeString(secondaryCpuAbi);
   1276         dest.writeStringArray(resourceDirs);
   1277         dest.writeString(seInfo);
   1278         dest.writeString(seInfoUser);
   1279         dest.writeStringArray(sharedLibraryFiles);
   1280         dest.writeString(dataDir);
   1281         dest.writeString(deviceProtectedDataDir);
   1282         dest.writeString(credentialProtectedDataDir);
   1283         dest.writeInt(uid);
   1284         dest.writeInt(minSdkVersion);
   1285         dest.writeInt(targetSdkVersion);
   1286         dest.writeInt(versionCode);
   1287         dest.writeInt(enabled ? 1 : 0);
   1288         dest.writeInt(enabledSetting);
   1289         dest.writeInt(installLocation);
   1290         dest.writeString(manageSpaceActivityName);
   1291         dest.writeString(backupAgentName);
   1292         dest.writeInt(descriptionRes);
   1293         dest.writeInt(uiOptions);
   1294         dest.writeInt(fullBackupContent);
   1295         dest.writeInt(networkSecurityConfigRes);
   1296         dest.writeInt(category);
   1297         dest.writeInt(targetSandboxVersion);
   1298         dest.writeString(classLoaderName);
   1299         dest.writeStringArray(splitClassLoaderNames);
   1300     }
   1301 
   1302     public static final Parcelable.Creator<ApplicationInfo> CREATOR
   1303             = new Parcelable.Creator<ApplicationInfo>() {
   1304         public ApplicationInfo createFromParcel(Parcel source) {
   1305             return new ApplicationInfo(source);
   1306         }
   1307         public ApplicationInfo[] newArray(int size) {
   1308             return new ApplicationInfo[size];
   1309         }
   1310     };
   1311 
   1312     @SuppressWarnings("unchecked")
   1313     private ApplicationInfo(Parcel source) {
   1314         super(source);
   1315         taskAffinity = source.readString();
   1316         permission = source.readString();
   1317         processName = source.readString();
   1318         className = source.readString();
   1319         theme = source.readInt();
   1320         flags = source.readInt();
   1321         privateFlags = source.readInt();
   1322         requiresSmallestWidthDp = source.readInt();
   1323         compatibleWidthLimitDp = source.readInt();
   1324         largestWidthLimitDp = source.readInt();
   1325         if (source.readInt() != 0) {
   1326             storageUuid = new UUID(source.readLong(), source.readLong());
   1327             volumeUuid = StorageManager.convert(storageUuid);
   1328         }
   1329         scanSourceDir = source.readString();
   1330         scanPublicSourceDir = source.readString();
   1331         sourceDir = source.readString();
   1332         publicSourceDir = source.readString();
   1333         splitNames = source.readStringArray();
   1334         splitSourceDirs = source.readStringArray();
   1335         splitPublicSourceDirs = source.readStringArray();
   1336         splitDependencies = source.readSparseArray(null);
   1337         nativeLibraryDir = source.readString();
   1338         secondaryNativeLibraryDir = source.readString();
   1339         nativeLibraryRootDir = source.readString();
   1340         nativeLibraryRootRequiresIsa = source.readInt() != 0;
   1341         primaryCpuAbi = source.readString();
   1342         secondaryCpuAbi = source.readString();
   1343         resourceDirs = source.readStringArray();
   1344         seInfo = source.readString();
   1345         seInfoUser = source.readString();
   1346         sharedLibraryFiles = source.readStringArray();
   1347         dataDir = source.readString();
   1348         deviceProtectedDataDir = source.readString();
   1349         credentialProtectedDataDir = source.readString();
   1350         uid = source.readInt();
   1351         minSdkVersion = source.readInt();
   1352         targetSdkVersion = source.readInt();
   1353         versionCode = source.readInt();
   1354         enabled = source.readInt() != 0;
   1355         enabledSetting = source.readInt();
   1356         installLocation = source.readInt();
   1357         manageSpaceActivityName = source.readString();
   1358         backupAgentName = source.readString();
   1359         descriptionRes = source.readInt();
   1360         uiOptions = source.readInt();
   1361         fullBackupContent = source.readInt();
   1362         networkSecurityConfigRes = source.readInt();
   1363         category = source.readInt();
   1364         targetSandboxVersion = source.readInt();
   1365         classLoaderName = source.readString();
   1366         splitClassLoaderNames = source.readStringArray();
   1367     }
   1368 
   1369     /**
   1370      * Retrieve the textual description of the application.  This
   1371      * will call back on the given PackageManager to load the description from
   1372      * the application.
   1373      *
   1374      * @param pm A PackageManager from which the label can be loaded; usually
   1375      * the PackageManager from which you originally retrieved this item.
   1376      *
   1377      * @return Returns a CharSequence containing the application's description.
   1378      * If there is no description, null is returned.
   1379      */
   1380     public CharSequence loadDescription(PackageManager pm) {
   1381         if (descriptionRes != 0) {
   1382             CharSequence label = pm.getText(packageName, descriptionRes, this);
   1383             if (label != null) {
   1384                 return label;
   1385             }
   1386         }
   1387         return null;
   1388     }
   1389 
   1390     /**
   1391      * Disable compatibility mode
   1392      *
   1393      * @hide
   1394      */
   1395     public void disableCompatibilityMode() {
   1396         flags |= (FLAG_SUPPORTS_LARGE_SCREENS | FLAG_SUPPORTS_NORMAL_SCREENS |
   1397                 FLAG_SUPPORTS_SMALL_SCREENS | FLAG_RESIZEABLE_FOR_SCREENS |
   1398                 FLAG_SUPPORTS_SCREEN_DENSITIES | FLAG_SUPPORTS_XLARGE_SCREENS);
   1399     }
   1400 
   1401     /**
   1402      * Is using compatibility mode for non densty aware legacy applications.
   1403      *
   1404      * @hide
   1405      */
   1406     public boolean usesCompatibilityMode() {
   1407         return targetSdkVersion < DONUT ||
   1408                 (flags & (FLAG_SUPPORTS_LARGE_SCREENS | FLAG_SUPPORTS_NORMAL_SCREENS |
   1409                  FLAG_SUPPORTS_SMALL_SCREENS | FLAG_RESIZEABLE_FOR_SCREENS |
   1410                  FLAG_SUPPORTS_SCREEN_DENSITIES | FLAG_SUPPORTS_XLARGE_SCREENS)) == 0;
   1411     }
   1412 
   1413     /** {@hide} */
   1414     public void initForUser(int userId) {
   1415         uid = UserHandle.getUid(userId, UserHandle.getAppId(uid));
   1416 
   1417         if ("android".equals(packageName)) {
   1418             dataDir = Environment.getDataSystemDirectory().getAbsolutePath();
   1419             return;
   1420         }
   1421 
   1422         deviceProtectedDataDir = Environment
   1423                 .getDataUserDePackageDirectory(volumeUuid, userId, packageName)
   1424                 .getAbsolutePath();
   1425         credentialProtectedDataDir = Environment
   1426                 .getDataUserCePackageDirectory(volumeUuid, userId, packageName)
   1427                 .getAbsolutePath();
   1428 
   1429         if ((privateFlags & PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) != 0
   1430                 && PackageManager.APPLY_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) {
   1431             dataDir = deviceProtectedDataDir;
   1432         } else {
   1433             dataDir = credentialProtectedDataDir;
   1434         }
   1435     }
   1436 
   1437     /**
   1438      * @hide
   1439      */
   1440     @Override
   1441     public Drawable loadDefaultIcon(PackageManager pm) {
   1442         if ((flags & FLAG_EXTERNAL_STORAGE) != 0
   1443                 && isPackageUnavailable(pm)) {
   1444             return Resources.getSystem().getDrawable(
   1445                     com.android.internal.R.drawable.sym_app_on_sd_unavailable_icon);
   1446         }
   1447         return pm.getDefaultActivityIcon();
   1448     }
   1449 
   1450     private boolean isPackageUnavailable(PackageManager pm) {
   1451         try {
   1452             return pm.getPackageInfo(packageName, 0) == null;
   1453         } catch (NameNotFoundException ex) {
   1454             return true;
   1455         }
   1456     }
   1457 
   1458     /**
   1459      * @hide
   1460      */
   1461     public boolean isForwardLocked() {
   1462         return (privateFlags & ApplicationInfo.PRIVATE_FLAG_FORWARD_LOCK) != 0;
   1463     }
   1464 
   1465     /**
   1466      * @hide
   1467      */
   1468     @TestApi
   1469     public boolean isSystemApp() {
   1470         return (flags & ApplicationInfo.FLAG_SYSTEM) != 0;
   1471     }
   1472 
   1473     /**
   1474      * @hide
   1475      */
   1476     @TestApi
   1477     public boolean isPrivilegedApp() {
   1478         return (privateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0;
   1479     }
   1480 
   1481     /**
   1482      * @hide
   1483      */
   1484     public boolean isUpdatedSystemApp() {
   1485         return (flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0;
   1486     }
   1487 
   1488     /** @hide */
   1489     public boolean isInternal() {
   1490         return (flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) == 0;
   1491     }
   1492 
   1493     /** @hide */
   1494     public boolean isExternalAsec() {
   1495         return TextUtils.isEmpty(volumeUuid)
   1496                 && (flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0;
   1497     }
   1498 
   1499     /** @hide */
   1500     public boolean isDefaultToDeviceProtectedStorage() {
   1501         return (privateFlags
   1502                 & ApplicationInfo.PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) != 0;
   1503     }
   1504 
   1505     /** @hide */
   1506     public boolean isDirectBootAware() {
   1507         return (privateFlags & ApplicationInfo.PRIVATE_FLAG_DIRECT_BOOT_AWARE) != 0;
   1508     }
   1509 
   1510     /** @hide */
   1511     public boolean isPartiallyDirectBootAware() {
   1512         return (privateFlags & ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE) != 0;
   1513     }
   1514 
   1515     /** @hide */
   1516     public boolean isEncryptionAware() {
   1517         return isDirectBootAware() || isPartiallyDirectBootAware();
   1518     }
   1519 
   1520     /**
   1521      * @hide
   1522      */
   1523     public boolean isInstantApp() {
   1524         return (privateFlags & ApplicationInfo.PRIVATE_FLAG_INSTANT) != 0;
   1525     }
   1526 
   1527     /**
   1528      * @hide
   1529      */
   1530     public boolean isRequiredForSystemUser() {
   1531         return (privateFlags & ApplicationInfo.PRIVATE_FLAG_REQUIRED_FOR_SYSTEM_USER) != 0;
   1532     }
   1533 
   1534     /**
   1535      * Returns true if the app has declared in its manifest that it wants its split APKs to be
   1536      * loaded into isolated Contexts, with their own ClassLoaders and Resources objects.
   1537      * @hide
   1538      */
   1539     public boolean requestsIsolatedSplitLoading() {
   1540         return (privateFlags & ApplicationInfo.PRIVATE_FLAG_ISOLATED_SPLIT_LOADING) != 0;
   1541     }
   1542 
   1543     /**
   1544      * @hide
   1545      */
   1546     public boolean isStaticSharedLibrary() {
   1547         return (privateFlags & ApplicationInfo.PRIVATE_FLAG_STATIC_SHARED_LIBRARY) != 0;
   1548     }
   1549 
   1550     /**
   1551      * Returns whether or not this application was installed as a virtual preload.
   1552      */
   1553     public boolean isVirtualPreload() {
   1554         return (privateFlags & PRIVATE_FLAG_VIRTUAL_PRELOAD) != 0;
   1555     }
   1556 
   1557     /**
   1558      * @hide
   1559      */
   1560     @Override protected ApplicationInfo getApplicationInfo() {
   1561         return this;
   1562     }
   1563 
   1564     /** {@hide} */ public void setCodePath(String codePath) { scanSourceDir = codePath; }
   1565     /** {@hide} */ public void setBaseCodePath(String baseCodePath) { sourceDir = baseCodePath; }
   1566     /** {@hide} */ public void setSplitCodePaths(String[] splitCodePaths) { splitSourceDirs = splitCodePaths; }
   1567     /** {@hide} */ public void setResourcePath(String resourcePath) { scanPublicSourceDir = resourcePath; }
   1568     /** {@hide} */ public void setBaseResourcePath(String baseResourcePath) { publicSourceDir = baseResourcePath; }
   1569     /** {@hide} */ public void setSplitResourcePaths(String[] splitResourcePaths) { splitPublicSourceDirs = splitResourcePaths; }
   1570 
   1571     /** {@hide} */ public String getCodePath() { return scanSourceDir; }
   1572     /** {@hide} */ public String getBaseCodePath() { return sourceDir; }
   1573     /** {@hide} */ public String[] getSplitCodePaths() { return splitSourceDirs; }
   1574     /** {@hide} */ public String getResourcePath() { return scanPublicSourceDir; }
   1575     /** {@hide} */ public String getBaseResourcePath() { return publicSourceDir; }
   1576     /** {@hide} */ public String[] getSplitResourcePaths() { return splitPublicSourceDirs; }
   1577 }
   1578