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