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