PackageManager.java revision cf4550c3198d6b3d92cdc52707fe70d7cc0caa9f
1/* 2 * Copyright (C) 2006 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 17package android.content.pm; 18 19import android.content.ComponentName; 20import android.content.Context; 21import android.content.Intent; 22import android.content.IntentFilter; 23import android.content.IntentSender; 24import android.content.res.Resources; 25import android.content.res.XmlResourceParser; 26import android.graphics.drawable.Drawable; 27import android.net.Uri; 28import android.util.AndroidException; 29import android.util.DisplayMetrics; 30 31import java.io.File; 32import java.util.List; 33 34/** 35 * Class for retrieving various kinds of information related to the application 36 * packages that are currently installed on the device. 37 * 38 * You can find this class through {@link Context#getPackageManager}. 39 */ 40public abstract class PackageManager { 41 42 /** 43 * This exception is thrown when a given package, application, or component 44 * name can not be found. 45 */ 46 public static class NameNotFoundException extends AndroidException { 47 public NameNotFoundException() { 48 } 49 50 public NameNotFoundException(String name) { 51 super(name); 52 } 53 } 54 55 /** 56 * {@link PackageInfo} flag: return information about 57 * activities in the package in {@link PackageInfo#activities}. 58 */ 59 public static final int GET_ACTIVITIES = 0x00000001; 60 61 /** 62 * {@link PackageInfo} flag: return information about 63 * intent receivers in the package in 64 * {@link PackageInfo#receivers}. 65 */ 66 public static final int GET_RECEIVERS = 0x00000002; 67 68 /** 69 * {@link PackageInfo} flag: return information about 70 * services in the package in {@link PackageInfo#services}. 71 */ 72 public static final int GET_SERVICES = 0x00000004; 73 74 /** 75 * {@link PackageInfo} flag: return information about 76 * content providers in the package in 77 * {@link PackageInfo#providers}. 78 */ 79 public static final int GET_PROVIDERS = 0x00000008; 80 81 /** 82 * {@link PackageInfo} flag: return information about 83 * instrumentation in the package in 84 * {@link PackageInfo#instrumentation}. 85 */ 86 public static final int GET_INSTRUMENTATION = 0x00000010; 87 88 /** 89 * {@link PackageInfo} flag: return information about the 90 * intent filters supported by the activity. 91 */ 92 public static final int GET_INTENT_FILTERS = 0x00000020; 93 94 /** 95 * {@link PackageInfo} flag: return information about the 96 * signatures included in the package. 97 */ 98 public static final int GET_SIGNATURES = 0x00000040; 99 100 /** 101 * {@link ResolveInfo} flag: return the IntentFilter that 102 * was matched for a particular ResolveInfo in 103 * {@link ResolveInfo#filter}. 104 */ 105 public static final int GET_RESOLVED_FILTER = 0x00000040; 106 107 /** 108 * {@link ComponentInfo} flag: return the {@link ComponentInfo#metaData} 109 * data {@link android.os.Bundle}s that are associated with a component. 110 * This applies for any API returning a ComponentInfo subclass. 111 */ 112 public static final int GET_META_DATA = 0x00000080; 113 114 /** 115 * {@link PackageInfo} flag: return the 116 * {@link PackageInfo#gids group ids} that are associated with an 117 * application. 118 * This applies for any API returning an PackageInfo class, either 119 * directly or nested inside of another. 120 */ 121 public static final int GET_GIDS = 0x00000100; 122 123 /** 124 * {@link PackageInfo} flag: include disabled components in the returned info. 125 */ 126 public static final int GET_DISABLED_COMPONENTS = 0x00000200; 127 128 /** 129 * {@link ApplicationInfo} flag: return the 130 * {@link ApplicationInfo#sharedLibraryFiles paths to the shared libraries} 131 * that are associated with an application. 132 * This applies for any API returning an ApplicationInfo class, either 133 * directly or nested inside of another. 134 */ 135 public static final int GET_SHARED_LIBRARY_FILES = 0x00000400; 136 137 /** 138 * {@link ProviderInfo} flag: return the 139 * {@link ProviderInfo#uriPermissionPatterns URI permission patterns} 140 * that are associated with a content provider. 141 * This applies for any API returning an ProviderInfo class, either 142 * directly or nested inside of another. 143 */ 144 public static final int GET_URI_PERMISSION_PATTERNS = 0x00000800; 145 /** 146 * {@link PackageInfo} flag: return information about 147 * permissions in the package in 148 * {@link PackageInfo#permissions}. 149 */ 150 public static final int GET_PERMISSIONS = 0x00001000; 151 152 /** 153 * Flag parameter to retrieve all applications(even uninstalled ones) with data directories. 154 * This state could have resulted if applications have been deleted with flag 155 * DONT_DELETE_DATA 156 * with a possibility of being replaced or reinstalled in future 157 */ 158 public static final int GET_UNINSTALLED_PACKAGES = 0x00002000; 159 160 /** 161 * {@link PackageInfo} flag: return information about 162 * hardware preferences 163 * {@link PackageInfo#configPreferences} 164 */ 165 public static final int GET_CONFIGURATIONS = 0x00004000; 166 167 /** 168 * {@link ApplicationInfo} flag: return the 169 * {@link ApplicationInfo#supportsDensities} that the package supports. 170 */ 171 public static final int GET_SUPPORTS_DENSITIES = 0x00008000; 172 173 /** 174 * Resolution and querying flag: if set, only filters that support the 175 * {@link android.content.Intent#CATEGORY_DEFAULT} will be considered for 176 * matching. This is a synonym for including the CATEGORY_DEFAULT in your 177 * supplied Intent. 178 */ 179 public static final int MATCH_DEFAULT_ONLY = 0x00010000; 180 181 /** 182 * Permission check result: this is returned by {@link #checkPermission} 183 * if the permission has been granted to the given package. 184 */ 185 public static final int PERMISSION_GRANTED = 0; 186 187 /** 188 * Permission check result: this is returned by {@link #checkPermission} 189 * if the permission has not been granted to the given package. 190 */ 191 public static final int PERMISSION_DENIED = -1; 192 193 /** 194 * Signature check result: this is returned by {@link #checkSignatures} 195 * if the two packages have a matching signature. 196 */ 197 public static final int SIGNATURE_MATCH = 0; 198 199 /** 200 * Signature check result: this is returned by {@link #checkSignatures} 201 * if neither of the two packages is signed. 202 */ 203 public static final int SIGNATURE_NEITHER_SIGNED = 1; 204 205 /** 206 * Signature check result: this is returned by {@link #checkSignatures} 207 * if the first package is not signed, but the second is. 208 */ 209 public static final int SIGNATURE_FIRST_NOT_SIGNED = -1; 210 211 /** 212 * Signature check result: this is returned by {@link #checkSignatures} 213 * if the second package is not signed, but the first is. 214 */ 215 public static final int SIGNATURE_SECOND_NOT_SIGNED = -2; 216 217 /** 218 * Signature check result: this is returned by {@link #checkSignatures} 219 * if both packages are signed but there is no matching signature. 220 */ 221 public static final int SIGNATURE_NO_MATCH = -3; 222 223 /** 224 * Signature check result: this is returned by {@link #checkSignatures} 225 * if either of the given package names are not valid. 226 */ 227 public static final int SIGNATURE_UNKNOWN_PACKAGE = -4; 228 229 public static final int COMPONENT_ENABLED_STATE_DEFAULT = 0; 230 public static final int COMPONENT_ENABLED_STATE_ENABLED = 1; 231 public static final int COMPONENT_ENABLED_STATE_DISABLED = 2; 232 233 /** 234 * Flag parameter for {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} to 235 * indicate that this package should be installed as forward locked, i.e. only the app itself 236 * should have access to it's code and non-resource assets. 237 * @hide 238 */ 239 public static final int INSTALL_FORWARD_LOCK = 0x00000001; 240 241 /** 242 * Flag parameter for {@link #installPackage} to indicate that you want to replace an already 243 * installed package, if one exists. 244 * @hide 245 */ 246 public static final int INSTALL_REPLACE_EXISTING = 0x00000002; 247 248 /** 249 * Flag parameter for {@link #installPackage} to indicate that you want to 250 * allow test packages (those that have set android:testOnly in their 251 * manifest) to be installed. 252 * @hide 253 */ 254 public static final int INSTALL_ALLOW_TEST = 0x00000004; 255 256 /** 257 * Flag parameter for 258 * {@link #setComponentEnabledSetting(android.content.ComponentName, int, int)} to indicate 259 * that you don't want to kill the app containing the component. Be careful when you set this 260 * since changing component states can make the containing application's behavior unpredictable. 261 */ 262 public static final int DONT_KILL_APP = 0x00000001; 263 264 /** 265 * Installation return code: this is passed to the {@link IPackageInstallObserver} by 266 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} on success. 267 * @hide 268 */ 269 public static final int INSTALL_SUCCEEDED = 1; 270 271 /** 272 * Installation return code: this is passed to the {@link IPackageInstallObserver} by 273 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if the package is 274 * already installed. 275 * @hide 276 */ 277 public static final int INSTALL_FAILED_ALREADY_EXISTS = -1; 278 279 /** 280 * Installation return code: this is passed to the {@link IPackageInstallObserver} by 281 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if the package archive 282 * file is invalid. 283 * @hide 284 */ 285 public static final int INSTALL_FAILED_INVALID_APK = -2; 286 287 /** 288 * Installation return code: this is passed to the {@link IPackageInstallObserver} by 289 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if the URI passed in 290 * is invalid. 291 * @hide 292 */ 293 public static final int INSTALL_FAILED_INVALID_URI = -3; 294 295 /** 296 * Installation return code: this is passed to the {@link IPackageInstallObserver} by 297 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if the package manager 298 * service found that the device didn't have enough storage space to install the app. 299 * @hide 300 */ 301 public static final int INSTALL_FAILED_INSUFFICIENT_STORAGE = -4; 302 303 /** 304 * Installation return code: this is passed to the {@link IPackageInstallObserver} by 305 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if a 306 * package is already installed with the same name. 307 * @hide 308 */ 309 public static final int INSTALL_FAILED_DUPLICATE_PACKAGE = -5; 310 311 /** 312 * Installation return code: this is passed to the {@link IPackageInstallObserver} by 313 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if 314 * the requested shared user does not exist. 315 * @hide 316 */ 317 public static final int INSTALL_FAILED_NO_SHARED_USER = -6; 318 319 /** 320 * Installation return code: this is passed to the {@link IPackageInstallObserver} by 321 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if 322 * a previously installed package of the same name has a different signature 323 * than the new package (and the old package's data was not removed). 324 * @hide 325 */ 326 public static final int INSTALL_FAILED_UPDATE_INCOMPATIBLE = -7; 327 328 /** 329 * Installation return code: this is passed to the {@link IPackageInstallObserver} by 330 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if 331 * the new package is requested a shared user which is already installed on the 332 * device and does not have matching signature. 333 * @hide 334 */ 335 public static final int INSTALL_FAILED_SHARED_USER_INCOMPATIBLE = -8; 336 337 /** 338 * Installation return code: this is passed to the {@link IPackageInstallObserver} by 339 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if 340 * the new package uses a shared library that is not available. 341 * @hide 342 */ 343 public static final int INSTALL_FAILED_MISSING_SHARED_LIBRARY = -9; 344 345 /** 346 * Installation return code: this is passed to the {@link IPackageInstallObserver} by 347 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if 348 * the new package uses a shared library that is not available. 349 * @hide 350 */ 351 public static final int INSTALL_FAILED_REPLACE_COULDNT_DELETE = -10; 352 353 /** 354 * Installation return code: this is passed to the {@link IPackageInstallObserver} by 355 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if 356 * the new package failed while optimizing and validating its dex files, 357 * either because there was not enough storage or the validation failed. 358 * @hide 359 */ 360 public static final int INSTALL_FAILED_DEXOPT = -11; 361 362 /** 363 * Installation return code: this is passed to the {@link IPackageInstallObserver} by 364 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if 365 * the new package failed because the current SDK version is older than 366 * that required by the package. 367 * @hide 368 */ 369 public static final int INSTALL_FAILED_OLDER_SDK = -12; 370 371 /** 372 * Installation return code: this is passed to the {@link IPackageInstallObserver} by 373 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if 374 * the new package failed because it contains a content provider with the 375 * same authority as a provider already installed in the system. 376 * @hide 377 */ 378 public static final int INSTALL_FAILED_CONFLICTING_PROVIDER = -13; 379 380 /** 381 * Installation return code: this is passed to the {@link IPackageInstallObserver} by 382 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if 383 * the new package failed because the current SDK version is newer than 384 * that required by the package. 385 * @hide 386 */ 387 public static final int INSTALL_FAILED_NEWER_SDK = -14; 388 389 /** 390 * Installation return code: this is passed to the {@link IPackageInstallObserver} by 391 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if 392 * the new package failed because it has specified that it is a test-only 393 * package and the caller has not supplied the {@link #INSTALL_ALLOW_TEST} 394 * flag. 395 * @hide 396 */ 397 public static final int INSTALL_FAILED_TEST_ONLY = -15; 398 399 /** 400 * Installation return code: this is passed to the {@link IPackageInstallObserver} by 401 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if 402 * the package being installed contains native code, but none that is 403 * compatible with the the device's CPU_ABI. 404 * @hide 405 */ 406 public static final int INSTALL_FAILED_CPU_ABI_INCOMPATIBLE = -16; 407 408 /** 409 * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by 410 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} 411 * if the parser was given a path that is not a file, or does not end with the expected 412 * '.apk' extension. 413 * @hide 414 */ 415 public static final int INSTALL_PARSE_FAILED_NOT_APK = -100; 416 417 /** 418 * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by 419 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} 420 * if the parser was unable to retrieve the AndroidManifest.xml file. 421 * @hide 422 */ 423 public static final int INSTALL_PARSE_FAILED_BAD_MANIFEST = -101; 424 425 /** 426 * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by 427 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} 428 * if the parser encountered an unexpected exception. 429 * @hide 430 */ 431 public static final int INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION = -102; 432 433 /** 434 * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by 435 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} 436 * if the parser did not find any certificates in the .apk. 437 * @hide 438 */ 439 public static final int INSTALL_PARSE_FAILED_NO_CERTIFICATES = -103; 440 441 /** 442 * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by 443 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} 444 * if the parser found inconsistent certificates on the files in the .apk. 445 * @hide 446 */ 447 public static final int INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES = -104; 448 449 /** 450 * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by 451 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} 452 * if the parser encountered a CertificateEncodingException in one of the 453 * files in the .apk. 454 * @hide 455 */ 456 public static final int INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING = -105; 457 458 /** 459 * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by 460 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} 461 * if the parser encountered a bad or missing package name in the manifest. 462 * @hide 463 */ 464 public static final int INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME = -106; 465 466 /** 467 * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by 468 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} 469 * if the parser encountered a bad shared user id name in the manifest. 470 * @hide 471 */ 472 public static final int INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID = -107; 473 474 /** 475 * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by 476 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} 477 * if the parser encountered some structural problem in the manifest. 478 * @hide 479 */ 480 public static final int INSTALL_PARSE_FAILED_MANIFEST_MALFORMED = -108; 481 482 /** 483 * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by 484 * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} 485 * if the parser did not find any actionable tags (instrumentation or application) 486 * in the manifest. 487 * @hide 488 */ 489 public static final int INSTALL_PARSE_FAILED_MANIFEST_EMPTY = -109; 490 491 /** 492 * Indicates the state of installation. Used by PackageManager to 493 * figure out incomplete installations. Say a package is being installed 494 * (the state is set to PKG_INSTALL_INCOMPLETE) and remains so till 495 * the package installation is successful or unsuccesful lin which case 496 * the PackageManager will no longer maintain state information associated 497 * with the package. If some exception(like device freeze or battery being 498 * pulled out) occurs during installation of a package, the PackageManager 499 * needs this information to clean up the previously failed installation. 500 */ 501 public static final int PKG_INSTALL_INCOMPLETE = 0; 502 public static final int PKG_INSTALL_COMPLETE = 1; 503 504 /** 505 * Flag parameter for {@link #deletePackage} to indicate that you don't want to delete the 506 * package's data directory. 507 * 508 * @hide 509 */ 510 public static final int DONT_DELETE_DATA = 0x00000001; 511 512 /** 513 * Retrieve overall information about an application package that is 514 * installed on the system. 515 * 516 * <p>Throws {@link NameNotFoundException} if a package with the given 517 * name can not be found on the system. 518 * 519 * @param packageName The full name (i.e. com.google.apps.contacts) of the 520 * desired package. 521 522 * @param flags Additional option flags. Use any combination of 523 * {@link #GET_ACTIVITIES}, 524 * {@link #GET_GIDS}, 525 * {@link #GET_CONFIGURATIONS}, 526 * {@link #GET_INSTRUMENTATION}, 527 * {@link #GET_PERMISSIONS}, 528 * {@link #GET_PROVIDERS}, 529 * {@link #GET_RECEIVERS}, 530 * {@link #GET_SERVICES}, 531 * {@link #GET_SIGNATURES}, 532 * {@link #GET_UNINSTALLED_PACKAGES} to modify the data returned. 533 * 534 * @return Returns a PackageInfo object containing information about the package. 535 * If flag GET_UNINSTALLED_PACKAGES is set and if the package is not 536 * found in the list of installed applications, the package information is 537 * retrieved from the list of uninstalled applications(which includes 538 * installed applications as well as applications 539 * with data directory ie applications which had been 540 * deleted with DONT_DELTE_DATA flag set). 541 * 542 * @see #GET_ACTIVITIES 543 * @see #GET_GIDS 544 * @see #GET_CONFIGURATIONS 545 * @see #GET_INSTRUMENTATION 546 * @see #GET_PERMISSIONS 547 * @see #GET_PROVIDERS 548 * @see #GET_RECEIVERS 549 * @see #GET_SERVICES 550 * @see #GET_SIGNATURES 551 * @see #GET_UNINSTALLED_PACKAGES 552 * 553 */ 554 public abstract PackageInfo getPackageInfo(String packageName, int flags) 555 throws NameNotFoundException; 556 557 /** 558 * Return a "good" intent to launch a front-door activity in a package, 559 * for use for example to implement an "open" button when browsing through 560 * packages. The current implementation will look first for a main 561 * activity in the category {@link Intent#CATEGORY_INFO}, next for a 562 * main activity in the category {@link Intent#CATEGORY_LAUNCHER}, or return 563 * null if neither are found. 564 * 565 * <p>Throws {@link NameNotFoundException} if a package with the given 566 * name can not be found on the system. 567 * 568 * @param packageName The name of the package to inspect. 569 * 570 * @return Returns either a fully-qualified Intent that can be used to 571 * launch the main activity in the package, or null if the package does 572 * not contain such an activity. 573 */ 574 public abstract Intent getLaunchIntentForPackage(String packageName); 575 576 /** 577 * Return an array of all of the secondary group-ids that have been 578 * assigned to a package. 579 * 580 * <p>Throws {@link NameNotFoundException} if a package with the given 581 * name can not be found on the system. 582 * 583 * @param packageName The full name (i.e. com.google.apps.contacts) of the 584 * desired package. 585 * 586 * @return Returns an int array of the assigned gids, or null if there 587 * are none. 588 */ 589 public abstract int[] getPackageGids(String packageName) 590 throws NameNotFoundException; 591 592 /** 593 * Retrieve all of the information we know about a particular permission. 594 * 595 * <p>Throws {@link NameNotFoundException} if a permission with the given 596 * name can not be found on the system. 597 * 598 * @param name The fully qualified name (i.e. com.google.permission.LOGIN) 599 * of the permission you are interested in. 600 * @param flags Additional option flags. Use {@link #GET_META_DATA} to 601 * retrieve any meta-data associated with the permission. 602 * 603 * @return Returns a {@link PermissionInfo} containing information about the 604 * permission. 605 */ 606 public abstract PermissionInfo getPermissionInfo(String name, int flags) 607 throws NameNotFoundException; 608 609 /** 610 * Query for all of the permissions associated with a particular group. 611 * 612 * <p>Throws {@link NameNotFoundException} if the given group does not 613 * exist. 614 * 615 * @param group The fully qualified name (i.e. com.google.permission.LOGIN) 616 * of the permission group you are interested in. Use null to 617 * find all of the permissions not associated with a group. 618 * @param flags Additional option flags. Use {@link #GET_META_DATA} to 619 * retrieve any meta-data associated with the permissions. 620 * 621 * @return Returns a list of {@link PermissionInfo} containing information 622 * about all of the permissions in the given group. 623 */ 624 public abstract List<PermissionInfo> queryPermissionsByGroup(String group, 625 int flags) throws NameNotFoundException; 626 627 /** 628 * Retrieve all of the information we know about a particular group of 629 * permissions. 630 * 631 * <p>Throws {@link NameNotFoundException} if a permission group with the given 632 * name can not be found on the system. 633 * 634 * @param name The fully qualified name (i.e. com.google.permission_group.APPS) 635 * of the permission you are interested in. 636 * @param flags Additional option flags. Use {@link #GET_META_DATA} to 637 * retrieve any meta-data associated with the permission group. 638 * 639 * @return Returns a {@link PermissionGroupInfo} containing information 640 * about the permission. 641 */ 642 public abstract PermissionGroupInfo getPermissionGroupInfo(String name, 643 int flags) throws NameNotFoundException; 644 645 /** 646 * Retrieve all of the known permission groups in the system. 647 * 648 * @param flags Additional option flags. Use {@link #GET_META_DATA} to 649 * retrieve any meta-data associated with the permission group. 650 * 651 * @return Returns a list of {@link PermissionGroupInfo} containing 652 * information about all of the known permission groups. 653 */ 654 public abstract List<PermissionGroupInfo> getAllPermissionGroups(int flags); 655 656 /** 657 * Retrieve all of the information we know about a particular 658 * package/application. 659 * 660 * <p>Throws {@link NameNotFoundException} if an application with the given 661 * package name can not be found on the system. 662 * 663 * @param packageName The full name (i.e. com.google.apps.contacts) of an 664 * application. 665 * @param flags Additional option flags. Use any combination of 666 * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES}, 667 * {@link #GET_UNINSTALLED_PACKAGES} to modify the data returned. 668 * 669 * @return {@link ApplicationInfo} Returns ApplicationInfo object containing 670 * information about the package. 671 * If flag GET_UNINSTALLED_PACKAGES is set and if the package is not 672 * found in the list of installed applications, 673 * the application information is retrieved from the 674 * list of uninstalled applications(which includes 675 * installed applications as well as applications 676 * with data directory ie applications which had been 677 * deleted with DONT_DELTE_DATA flag set). 678 * 679 * @see #GET_META_DATA 680 * @see #GET_SHARED_LIBRARY_FILES 681 * @see #GET_UNINSTALLED_PACKAGES 682 */ 683 public abstract ApplicationInfo getApplicationInfo(String packageName, 684 int flags) throws NameNotFoundException; 685 686 /** 687 * Retrieve all of the information we know about a particular activity 688 * class. 689 * 690 * <p>Throws {@link NameNotFoundException} if an activity with the given 691 * class name can not be found on the system. 692 * 693 * @param className The full name (i.e. 694 * com.google.apps.contacts.ContactsList) of an Activity 695 * class. 696 * @param flags Additional option flags. Use any combination of 697 * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES}, 698 * to modify the data (in ApplicationInfo) returned. 699 * 700 * @return {@link ActivityInfo} containing information about the activity. 701 * 702 * @see #GET_INTENT_FILTERS 703 * @see #GET_META_DATA 704 * @see #GET_SHARED_LIBRARY_FILES 705 */ 706 public abstract ActivityInfo getActivityInfo(ComponentName className, 707 int flags) throws NameNotFoundException; 708 709 /** 710 * Retrieve all of the information we know about a particular receiver 711 * class. 712 * 713 * <p>Throws {@link NameNotFoundException} if a receiver with the given 714 * class name can not be found on the system. 715 * 716 * @param className The full name (i.e. 717 * com.google.apps.contacts.CalendarAlarm) of a Receiver 718 * class. 719 * @param flags Additional option flags. Use any combination of 720 * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES}, 721 * to modify the data returned. 722 * 723 * @return {@link ActivityInfo} containing information about the receiver. 724 * 725 * @see #GET_INTENT_FILTERS 726 * @see #GET_META_DATA 727 * @see #GET_SHARED_LIBRARY_FILES 728 */ 729 public abstract ActivityInfo getReceiverInfo(ComponentName className, 730 int flags) throws NameNotFoundException; 731 732 /** 733 * Retrieve all of the information we know about a particular service 734 * class. 735 * 736 * <p>Throws {@link NameNotFoundException} if a service with the given 737 * class name can not be found on the system. 738 * 739 * @param className The full name (i.e. 740 * com.google.apps.media.BackgroundPlayback) of a Service 741 * class. 742 * @param flags Additional option flags. Use any combination of 743 * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES}, 744 * to modify the data returned. 745 * 746 * @return ServiceInfo containing information about the service. 747 * 748 * @see #GET_META_DATA 749 * @see #GET_SHARED_LIBRARY_FILES 750 */ 751 public abstract ServiceInfo getServiceInfo(ComponentName className, 752 int flags) throws NameNotFoundException; 753 754 /** 755 * Return a List of all packages that are installed 756 * on the device. 757 * 758 * @param flags Additional option flags. Use any combination of 759 * {@link #GET_ACTIVITIES}, 760 * {@link #GET_GIDS}, 761 * {@link #GET_CONFIGURATIONS}, 762 * {@link #GET_INSTRUMENTATION}, 763 * {@link #GET_PERMISSIONS}, 764 * {@link #GET_PROVIDERS}, 765 * {@link #GET_RECEIVERS}, 766 * {@link #GET_SERVICES}, 767 * {@link #GET_SIGNATURES}, 768 * {@link #GET_UNINSTALLED_PACKAGES} to modify the data returned. 769 * 770 * @return A List of PackageInfo objects, one for each package that is 771 * installed on the device. In the unlikely case of there being no 772 * installed packages, an empty list is returned. 773 * If flag GET_UNINSTALLED_PACKAGES is set, a list of all 774 * applications including those deleted with DONT_DELETE_DATA 775 * (partially installed apps with data directory) will be returned. 776 * 777 * @see #GET_ACTIVITIES 778 * @see #GET_GIDS 779 * @see #GET_CONFIGURATIONS 780 * @see #GET_INSTRUMENTATION 781 * @see #GET_PERMISSIONS 782 * @see #GET_PROVIDERS 783 * @see #GET_RECEIVERS 784 * @see #GET_SERVICES 785 * @see #GET_SIGNATURES 786 * @see #GET_UNINSTALLED_PACKAGES 787 * 788 */ 789 public abstract List<PackageInfo> getInstalledPackages(int flags); 790 791 /** 792 * Check whether a particular package has been granted a particular 793 * permission. 794 * 795 * @param permName The name of the permission you are checking for, 796 * @param pkgName The name of the package you are checking against. 797 * 798 * @return If the package has the permission, PERMISSION_GRANTED is 799 * returned. If it does not have the permission, PERMISSION_DENIED 800 * is returned. 801 * 802 * @see #PERMISSION_GRANTED 803 * @see #PERMISSION_DENIED 804 */ 805 public abstract int checkPermission(String permName, String pkgName); 806 807 /** 808 * Add a new dynamic permission to the system. For this to work, your 809 * package must have defined a permission tree through the 810 * {@link android.R.styleable#AndroidManifestPermissionTree 811 * <permission-tree>} tag in its manifest. A package can only add 812 * permissions to trees that were defined by either its own package or 813 * another with the same user id; a permission is in a tree if it 814 * matches the name of the permission tree + ".": for example, 815 * "com.foo.bar" is a member of the permission tree "com.foo". 816 * 817 * <p>It is good to make your permission tree name descriptive, because you 818 * are taking possession of that entire set of permission names. Thus, it 819 * must be under a domain you control, with a suffix that will not match 820 * any normal permissions that may be declared in any applications that 821 * are part of that domain. 822 * 823 * <p>New permissions must be added before 824 * any .apks are installed that use those permissions. Permissions you 825 * add through this method are remembered across reboots of the device. 826 * If the given permission already exists, the info you supply here 827 * will be used to update it. 828 * 829 * @param info Description of the permission to be added. 830 * 831 * @return Returns true if a new permission was created, false if an 832 * existing one was updated. 833 * 834 * @throws SecurityException if you are not allowed to add the 835 * given permission name. 836 * 837 * @see #removePermission(String) 838 */ 839 public abstract boolean addPermission(PermissionInfo info); 840 841 /** 842 * Removes a permission that was previously added with 843 * {@link #addPermission(PermissionInfo)}. The same ownership rules apply 844 * -- you are only allowed to remove permissions that you are allowed 845 * to add. 846 * 847 * @param name The name of the permission to remove. 848 * 849 * @throws SecurityException if you are not allowed to remove the 850 * given permission name. 851 * 852 * @see #addPermission(PermissionInfo) 853 */ 854 public abstract void removePermission(String name); 855 856 /** 857 * Compare the signatures of two packages to determine if the same 858 * signature appears in both of them. If they do contain the same 859 * signature, then they are allowed special privileges when working 860 * with each other: they can share the same user-id, run instrumentation 861 * against each other, etc. 862 * 863 * @param pkg1 First package name whose signature will be compared. 864 * @param pkg2 Second package name whose signature will be compared. 865 * @return Returns an integer indicating whether there is a matching 866 * signature: the value is >= 0 if there is a match (or neither package 867 * is signed), or < 0 if there is not a match. The match result can be 868 * further distinguished with the success (>= 0) constants 869 * {@link #SIGNATURE_MATCH}, {@link #SIGNATURE_NEITHER_SIGNED}; or 870 * failure (< 0) constants {@link #SIGNATURE_FIRST_NOT_SIGNED}, 871 * {@link #SIGNATURE_SECOND_NOT_SIGNED}, {@link #SIGNATURE_NO_MATCH}, 872 * or {@link #SIGNATURE_UNKNOWN_PACKAGE}. 873 * 874 * @see #SIGNATURE_MATCH 875 * @see #SIGNATURE_NEITHER_SIGNED 876 * @see #SIGNATURE_FIRST_NOT_SIGNED 877 * @see #SIGNATURE_SECOND_NOT_SIGNED 878 * @see #SIGNATURE_NO_MATCH 879 * @see #SIGNATURE_UNKNOWN_PACKAGE 880 */ 881 public abstract int checkSignatures(String pkg1, String pkg2); 882 883 /** 884 * Retrieve the names of all packages that are associated with a particular 885 * user id. In most cases, this will be a single package name, the package 886 * that has been assigned that user id. Where there are multiple packages 887 * sharing the same user id through the "sharedUserId" mechanism, all 888 * packages with that id will be returned. 889 * 890 * @param uid The user id for which you would like to retrieve the 891 * associated packages. 892 * 893 * @return Returns an array of one or more packages assigned to the user 894 * id, or null if there are no known packages with the given id. 895 */ 896 public abstract String[] getPackagesForUid(int uid); 897 898 /** 899 * Retrieve the official name associated with a user id. This name is 900 * guaranteed to never change, though it is possibly for the underlying 901 * user id to be changed. That is, if you are storing information about 902 * user ids in persistent storage, you should use the string returned 903 * by this function instead of the raw user-id. 904 * 905 * @param uid The user id for which you would like to retrieve a name. 906 * @return Returns a unique name for the given user id, or null if the 907 * user id is not currently assigned. 908 */ 909 public abstract String getNameForUid(int uid); 910 911 /** 912 * Return the user id associated with a shared user name. Multiple 913 * applications can specify a shared user name in their manifest and thus 914 * end up using a common uid. This might be used for new applications 915 * that use an existing shared user name and need to know the uid of the 916 * shared user. 917 * 918 * @param sharedUserName The shared user name whose uid is to be retrieved. 919 * @return Returns the uid associated with the shared user, or NameNotFoundException 920 * if the shared user name is not being used by any installed packages 921 * @hide 922 */ 923 public abstract int getUidForSharedUser(String sharedUserName) 924 throws NameNotFoundException; 925 926 /** 927 * Return a List of all application packages that are installed on the 928 * device. If flag GET_UNINSTALLED_PACKAGES has been set, a list of all 929 * applications including those deleted with DONT_DELETE_DATA(partially 930 * installed apps with data directory) will be returned. 931 * 932 * @param flags Additional option flags. Use any combination of 933 * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES}, 934 * {link #GET_UNINSTALLED_PACKAGES} to modify the data returned. 935 * 936 * @return A List of ApplicationInfo objects, one for each application that 937 * is installed on the device. In the unlikely case of there being 938 * no installed applications, an empty list is returned. 939 * If flag GET_UNINSTALLED_PACKAGES is set, a list of all 940 * applications including those deleted with DONT_DELETE_DATA 941 * (partially installed apps with data directory) will be returned. 942 * 943 * @see #GET_META_DATA 944 * @see #GET_SHARED_LIBRARY_FILES 945 * @see #GET_UNINSTALLED_PACKAGES 946 */ 947 public abstract List<ApplicationInfo> getInstalledApplications(int flags); 948 949 /** 950 * Get a list of shared libraries that are available on the 951 * system. 952 * 953 * @return An array of shared library names that are 954 * available on the system, or null if none are installed. 955 * 956 */ 957 public abstract String[] getSystemSharedLibraryNames(); 958 959 /** 960 * Determine the best action to perform for a given Intent. This is how 961 * {@link Intent#resolveActivity} finds an activity if a class has not 962 * been explicitly specified. 963 * 964 * @param intent An intent containing all of the desired specification 965 * (action, data, type, category, and/or component). 966 * @param flags Additional option flags. The most important is 967 * MATCH_DEFAULT_ONLY, to limit the resolution to only 968 * those activities that support the CATEGORY_DEFAULT. 969 * 970 * @return Returns a ResolveInfo containing the final activity intent that 971 * was determined to be the best action. Returns null if no 972 * matching activity was found. 973 * 974 * @see #MATCH_DEFAULT_ONLY 975 * @see #GET_INTENT_FILTERS 976 * @see #GET_RESOLVED_FILTER 977 */ 978 public abstract ResolveInfo resolveActivity(Intent intent, int flags); 979 980 /** 981 * Retrieve all activities that can be performed for the given intent. 982 * 983 * @param intent The desired intent as per resolveActivity(). 984 * @param flags Additional option flags. The most important is 985 * MATCH_DEFAULT_ONLY, to limit the resolution to only 986 * those activities that support the CATEGORY_DEFAULT. 987 * 988 * @return A List<ResolveInfo> containing one entry for each matching 989 * Activity. These are ordered from best to worst match -- that 990 * is, the first item in the list is what is returned by 991 * resolveActivity(). If there are no matching activities, an empty 992 * list is returned. 993 * 994 * @see #MATCH_DEFAULT_ONLY 995 * @see #GET_INTENT_FILTERS 996 * @see #GET_RESOLVED_FILTER 997 */ 998 public abstract List<ResolveInfo> queryIntentActivities(Intent intent, 999 int flags); 1000 1001 /** 1002 * Retrieve a set of activities that should be presented to the user as 1003 * similar options. This is like {@link #queryIntentActivities}, except it 1004 * also allows you to supply a list of more explicit Intents that you would 1005 * like to resolve to particular options, and takes care of returning the 1006 * final ResolveInfo list in a reasonable order, with no duplicates, based 1007 * on those inputs. 1008 * 1009 * @param caller The class name of the activity that is making the 1010 * request. This activity will never appear in the output 1011 * list. Can be null. 1012 * @param specifics An array of Intents that should be resolved to the 1013 * first specific results. Can be null. 1014 * @param intent The desired intent as per resolveActivity(). 1015 * @param flags Additional option flags. The most important is 1016 * MATCH_DEFAULT_ONLY, to limit the resolution to only 1017 * those activities that support the CATEGORY_DEFAULT. 1018 * 1019 * @return A List<ResolveInfo> containing one entry for each matching 1020 * Activity. These are ordered first by all of the intents resolved 1021 * in <var>specifics</var> and then any additional activities that 1022 * can handle <var>intent</var> but did not get included by one of 1023 * the <var>specifics</var> intents. If there are no matching 1024 * activities, an empty list is returned. 1025 * 1026 * @see #MATCH_DEFAULT_ONLY 1027 * @see #GET_INTENT_FILTERS 1028 * @see #GET_RESOLVED_FILTER 1029 */ 1030 public abstract List<ResolveInfo> queryIntentActivityOptions( 1031 ComponentName caller, Intent[] specifics, Intent intent, int flags); 1032 1033 /** 1034 * Retrieve all receivers that can handle a broadcast of the given intent. 1035 * 1036 * @param intent The desired intent as per resolveActivity(). 1037 * @param flags Additional option flags. The most important is 1038 * MATCH_DEFAULT_ONLY, to limit the resolution to only 1039 * those activities that support the CATEGORY_DEFAULT. 1040 * 1041 * @return A List<ResolveInfo> containing one entry for each matching 1042 * Receiver. These are ordered from first to last in priority. If 1043 * there are no matching receivers, an empty list is returned. 1044 * 1045 * @see #MATCH_DEFAULT_ONLY 1046 * @see #GET_INTENT_FILTERS 1047 * @see #GET_RESOLVED_FILTER 1048 */ 1049 public abstract List<ResolveInfo> queryBroadcastReceivers(Intent intent, 1050 int flags); 1051 1052 /** 1053 * Determine the best service to handle for a given Intent. 1054 * 1055 * @param intent An intent containing all of the desired specification 1056 * (action, data, type, category, and/or component). 1057 * @param flags Additional option flags. 1058 * 1059 * @return Returns a ResolveInfo containing the final service intent that 1060 * was determined to be the best action. Returns null if no 1061 * matching service was found. 1062 * 1063 * @see #GET_INTENT_FILTERS 1064 * @see #GET_RESOLVED_FILTER 1065 */ 1066 public abstract ResolveInfo resolveService(Intent intent, int flags); 1067 1068 /** 1069 * Retrieve all services that can match the given intent. 1070 * 1071 * @param intent The desired intent as per resolveService(). 1072 * @param flags Additional option flags. 1073 * 1074 * @return A List<ResolveInfo> containing one entry for each matching 1075 * ServiceInfo. These are ordered from best to worst match -- that 1076 * is, the first item in the list is what is returned by 1077 * resolveService(). If there are no matching services, an empty 1078 * list is returned. 1079 * 1080 * @see #GET_INTENT_FILTERS 1081 * @see #GET_RESOLVED_FILTER 1082 */ 1083 public abstract List<ResolveInfo> queryIntentServices(Intent intent, 1084 int flags); 1085 1086 /** 1087 * Find a single content provider by its base path name. 1088 * 1089 * @param name The name of the provider to find. 1090 * @param flags Additional option flags. Currently should always be 0. 1091 * 1092 * @return ContentProviderInfo Information about the provider, if found, 1093 * else null. 1094 */ 1095 public abstract ProviderInfo resolveContentProvider(String name, 1096 int flags); 1097 1098 /** 1099 * Retrieve content provider information. 1100 * 1101 * <p><em>Note: unlike most other methods, an empty result set is indicated 1102 * by a null return instead of an empty list.</em> 1103 * 1104 * @param processName If non-null, limits the returned providers to only 1105 * those that are hosted by the given process. If null, 1106 * all content providers are returned. 1107 * @param uid If <var>processName</var> is non-null, this is the required 1108 * uid owning the requested content providers. 1109 * @param flags Additional option flags. Currently should always be 0. 1110 * 1111 * @return A List<ContentProviderInfo> containing one entry for each 1112 * content provider either patching <var>processName</var> or, if 1113 * <var>processName</var> is null, all known content providers. 1114 * <em>If there are no matching providers, null is returned.</em> 1115 */ 1116 public abstract List<ProviderInfo> queryContentProviders( 1117 String processName, int uid, int flags); 1118 1119 /** 1120 * Retrieve all of the information we know about a particular 1121 * instrumentation class. 1122 * 1123 * <p>Throws {@link NameNotFoundException} if instrumentation with the 1124 * given class name can not be found on the system. 1125 * 1126 * @param className The full name (i.e. 1127 * com.google.apps.contacts.InstrumentList) of an 1128 * Instrumentation class. 1129 * @param flags Additional option flags. Currently should always be 0. 1130 * 1131 * @return InstrumentationInfo containing information about the 1132 * instrumentation. 1133 */ 1134 public abstract InstrumentationInfo getInstrumentationInfo( 1135 ComponentName className, int flags) throws NameNotFoundException; 1136 1137 /** 1138 * Retrieve information about available instrumentation code. May be used 1139 * to retrieve either all instrumentation code, or only the code targeting 1140 * a particular package. 1141 * 1142 * @param targetPackage If null, all instrumentation is returned; only the 1143 * instrumentation targeting this package name is 1144 * returned. 1145 * @param flags Additional option flags. Currently should always be 0. 1146 * 1147 * @return A List<InstrumentationInfo> containing one entry for each 1148 * matching available Instrumentation. Returns an empty list if 1149 * there is no instrumentation available for the given package. 1150 */ 1151 public abstract List<InstrumentationInfo> queryInstrumentation( 1152 String targetPackage, int flags); 1153 1154 /** 1155 * Retrieve an image from a package. This is a low-level API used by 1156 * the various package manager info structures (such as 1157 * {@link ComponentInfo} to implement retrieval of their associated 1158 * icon. 1159 * 1160 * @param packageName The name of the package that this icon is coming from. 1161 * Can not be null. 1162 * @param resid The resource identifier of the desired image. Can not be 0. 1163 * @param appInfo Overall information about <var>packageName</var>. This 1164 * may be null, in which case the application information will be retrieved 1165 * for you if needed; if you already have this information around, it can 1166 * be much more efficient to supply it here. 1167 * 1168 * @return Returns a Drawable holding the requested image. Returns null if 1169 * an image could not be found for any reason. 1170 */ 1171 public abstract Drawable getDrawable(String packageName, int resid, 1172 ApplicationInfo appInfo); 1173 1174 /** 1175 * Retrieve the icon associated with an activity. Given the full name of 1176 * an activity, retrieves the information about it and calls 1177 * {@link ComponentInfo#loadIcon ComponentInfo.loadIcon()} to return its icon. 1178 * If the activity can not be found, NameNotFoundException is thrown. 1179 * 1180 * @param activityName Name of the activity whose icon is to be retrieved. 1181 * 1182 * @return Returns the image of the icon, or the default activity icon if 1183 * it could not be found. Does not return null. 1184 * @throws NameNotFoundException Thrown if the resources for the given 1185 * activity could not be loaded. 1186 * 1187 * @see #getActivityIcon(Intent) 1188 */ 1189 public abstract Drawable getActivityIcon(ComponentName activityName) 1190 throws NameNotFoundException; 1191 1192 /** 1193 * Retrieve the icon associated with an Intent. If intent.getClassName() is 1194 * set, this simply returns the result of 1195 * getActivityIcon(intent.getClassName()). Otherwise it resolves the intent's 1196 * component and returns the icon associated with the resolved component. 1197 * If intent.getClassName() can not be found or the Intent can not be resolved 1198 * to a component, NameNotFoundException is thrown. 1199 * 1200 * @param intent The intent for which you would like to retrieve an icon. 1201 * 1202 * @return Returns the image of the icon, or the default activity icon if 1203 * it could not be found. Does not return null. 1204 * @throws NameNotFoundException Thrown if the resources for application 1205 * matching the given intent could not be loaded. 1206 * 1207 * @see #getActivityIcon(ComponentName) 1208 */ 1209 public abstract Drawable getActivityIcon(Intent intent) 1210 throws NameNotFoundException; 1211 1212 /** 1213 * Return the generic icon for an activity that is used when no specific 1214 * icon is defined. 1215 * 1216 * @return Drawable Image of the icon. 1217 */ 1218 public abstract Drawable getDefaultActivityIcon(); 1219 1220 /** 1221 * Retrieve the icon associated with an application. If it has not defined 1222 * an icon, the default app icon is returned. Does not return null. 1223 * 1224 * @param info Information about application being queried. 1225 * 1226 * @return Returns the image of the icon, or the default application icon 1227 * if it could not be found. 1228 * 1229 * @see #getApplicationIcon(String) 1230 */ 1231 public abstract Drawable getApplicationIcon(ApplicationInfo info); 1232 1233 /** 1234 * Retrieve the icon associated with an application. Given the name of the 1235 * application's package, retrieves the information about it and calls 1236 * getApplicationIcon() to return its icon. If the application can not be 1237 * found, NameNotFoundException is thrown. 1238 * 1239 * @param packageName Name of the package whose application icon is to be 1240 * retrieved. 1241 * 1242 * @return Returns the image of the icon, or the default application icon 1243 * if it could not be found. Does not return null. 1244 * @throws NameNotFoundException Thrown if the resources for the given 1245 * application could not be loaded. 1246 * 1247 * @see #getApplicationIcon(ApplicationInfo) 1248 */ 1249 public abstract Drawable getApplicationIcon(String packageName) 1250 throws NameNotFoundException; 1251 1252 /** 1253 * Retrieve text from a package. This is a low-level API used by 1254 * the various package manager info structures (such as 1255 * {@link ComponentInfo} to implement retrieval of their associated 1256 * labels and other text. 1257 * 1258 * @param packageName The name of the package that this text is coming from. 1259 * Can not be null. 1260 * @param resid The resource identifier of the desired text. Can not be 0. 1261 * @param appInfo Overall information about <var>packageName</var>. This 1262 * may be null, in which case the application information will be retrieved 1263 * for you if needed; if you already have this information around, it can 1264 * be much more efficient to supply it here. 1265 * 1266 * @return Returns a CharSequence holding the requested text. Returns null 1267 * if the text could not be found for any reason. 1268 */ 1269 public abstract CharSequence getText(String packageName, int resid, 1270 ApplicationInfo appInfo); 1271 1272 /** 1273 * Retrieve an XML file from a package. This is a low-level API used to 1274 * retrieve XML meta data. 1275 * 1276 * @param packageName The name of the package that this xml is coming from. 1277 * Can not be null. 1278 * @param resid The resource identifier of the desired xml. Can not be 0. 1279 * @param appInfo Overall information about <var>packageName</var>. This 1280 * may be null, in which case the application information will be retrieved 1281 * for you if needed; if you already have this information around, it can 1282 * be much more efficient to supply it here. 1283 * 1284 * @return Returns an XmlPullParser allowing you to parse out the XML 1285 * data. Returns null if the xml resource could not be found for any 1286 * reason. 1287 */ 1288 public abstract XmlResourceParser getXml(String packageName, int resid, 1289 ApplicationInfo appInfo); 1290 1291 /** 1292 * Return the label to use for this application. 1293 * 1294 * @return Returns the label associated with this application, or null if 1295 * it could not be found for any reason. 1296 * @param info The application to get the label of 1297 */ 1298 public abstract CharSequence getApplicationLabel(ApplicationInfo info); 1299 1300 /** 1301 * Retrieve the resources associated with an activity. Given the full 1302 * name of an activity, retrieves the information about it and calls 1303 * getResources() to return its application's resources. If the activity 1304 * can not be found, NameNotFoundException is thrown. 1305 * 1306 * @param activityName Name of the activity whose resources are to be 1307 * retrieved. 1308 * 1309 * @return Returns the application's Resources. 1310 * @throws NameNotFoundException Thrown if the resources for the given 1311 * application could not be loaded. 1312 * 1313 * @see #getResourcesForApplication(ApplicationInfo) 1314 */ 1315 public abstract Resources getResourcesForActivity(ComponentName activityName) 1316 throws NameNotFoundException; 1317 1318 /** 1319 * Retrieve the resources for an application. Throws NameNotFoundException 1320 * if the package is no longer installed. 1321 * 1322 * @param app Information about the desired application. 1323 * 1324 * @return Returns the application's Resources. 1325 * @throws NameNotFoundException Thrown if the resources for the given 1326 * application could not be loaded (most likely because it was uninstalled). 1327 */ 1328 public abstract Resources getResourcesForApplication(ApplicationInfo app) 1329 throws NameNotFoundException; 1330 1331 /** 1332 * Retrieve the resources associated with an application. Given the full 1333 * package name of an application, retrieves the information about it and 1334 * calls getResources() to return its application's resources. If the 1335 * appPackageName can not be found, NameNotFoundException is thrown. 1336 * 1337 * @param appPackageName Package name of the application whose resources 1338 * are to be retrieved. 1339 * 1340 * @return Returns the application's Resources. 1341 * @throws NameNotFoundException Thrown if the resources for the given 1342 * application could not be loaded. 1343 * 1344 * @see #getResourcesForApplication(ApplicationInfo) 1345 */ 1346 public abstract Resources getResourcesForApplication(String appPackageName) 1347 throws NameNotFoundException; 1348 1349 /** 1350 * Retrieve overall information about an application package defined 1351 * in a package archive file 1352 * 1353 * @param archiveFilePath The path to the archive file 1354 * @param flags Additional option flags. Use any combination of 1355 * {@link #GET_ACTIVITIES}, 1356 * {@link #GET_GIDS}, 1357 * {@link #GET_CONFIGURATIONS}, 1358 * {@link #GET_INSTRUMENTATION}, 1359 * {@link #GET_PERMISSIONS}, 1360 * {@link #GET_PROVIDERS}, 1361 * {@link #GET_RECEIVERS}, 1362 * {@link #GET_SERVICES}, 1363 * {@link #GET_SIGNATURES}, to modify the data returned. 1364 * 1365 * @return Returns the information about the package. Returns 1366 * null if the package could not be successfully parsed. 1367 * 1368 * @see #GET_ACTIVITIES 1369 * @see #GET_GIDS 1370 * @see #GET_CONFIGURATIONS 1371 * @see #GET_INSTRUMENTATION 1372 * @see #GET_PERMISSIONS 1373 * @see #GET_PROVIDERS 1374 * @see #GET_RECEIVERS 1375 * @see #GET_SERVICES 1376 * @see #GET_SIGNATURES 1377 * 1378 */ 1379 public PackageInfo getPackageArchiveInfo(String archiveFilePath, int flags) { 1380 PackageParser packageParser = new PackageParser(archiveFilePath); 1381 DisplayMetrics metrics = new DisplayMetrics(); 1382 metrics.setToDefaults(); 1383 final File sourceFile = new File(archiveFilePath); 1384 PackageParser.Package pkg = packageParser.parsePackage( 1385 sourceFile, archiveFilePath, metrics, 0); 1386 if (pkg == null) { 1387 return null; 1388 } 1389 return PackageParser.generatePackageInfo(pkg, null, flags); 1390 } 1391 1392 /** 1393 * @hide 1394 * 1395 * Install a package. Since this may take a little while, the result will 1396 * be posted back to the given observer. An installation will fail if the calling context 1397 * lacks the {@link android.Manifest.permission#INSTALL_PACKAGES} permission, if the 1398 * package named in the package file's manifest is already installed, or if there's no space 1399 * available on the device. 1400 * 1401 * @param packageURI The location of the package file to install. This can be a 'file:' or a 1402 * 'content:' URI. 1403 * @param observer An observer callback to get notified when the package installation is 1404 * complete. {@link IPackageInstallObserver#packageInstalled(String, int)} will be 1405 * called when that happens. observer may be null to indicate that no callback is desired. 1406 * @param flags - possible values: {@link #INSTALL_FORWARD_LOCK}, 1407 * {@link #INSTALL_REPLACE_EXISTING}, {@link #INSTALL_ALLOW_TEST}. 1408 * @param installerPackageName Optional package name of the application that is performing the 1409 * installation. This identifies which market the package came from. 1410 */ 1411 public abstract void installPackage( 1412 Uri packageURI, IPackageInstallObserver observer, int flags, 1413 String installerPackageName); 1414 1415 /** 1416 * Attempts to delete a package. Since this may take a little while, the result will 1417 * be posted back to the given observer. A deletion will fail if the calling context 1418 * lacks the {@link android.Manifest.permission#DELETE_PACKAGES} permission, if the 1419 * named package cannot be found, or if the named package is a "system package". 1420 * (TODO: include pointer to documentation on "system packages") 1421 * 1422 * @param packageName The name of the package to delete 1423 * @param observer An observer callback to get notified when the package deletion is 1424 * complete. {@link android.content.pm.IPackageDeleteObserver#packageDeleted(boolean)} will be 1425 * called when that happens. observer may be null to indicate that no callback is desired. 1426 * @param flags - possible values: {@link #DONT_DELETE_DATA} 1427 * 1428 * @hide 1429 */ 1430 public abstract void deletePackage( 1431 String packageName, IPackageDeleteObserver observer, int flags); 1432 1433 /** 1434 * Retrieve the package name of the application that installed a package. This identifies 1435 * which market the package came from. 1436 * 1437 * @param packageName The name of the package to query 1438 * 1439 * @hide 1440 */ 1441 public abstract String getInstallerPackageName(String packageName); 1442 1443 /** 1444 * Attempts to clear the user data directory of an application. 1445 * Since this may take a little while, the result will 1446 * be posted back to the given observer. A deletion will fail if the 1447 * named package cannot be found, or if the named package is a "system package". 1448 * 1449 * @param packageName The name of the package 1450 * @param observer An observer callback to get notified when the operation is finished 1451 * {@link android.content.pm.IPackageDataObserver#onRemoveCompleted(String, boolean)} 1452 * will be called when that happens. observer may be null to indicate that 1453 * no callback is desired. 1454 * 1455 * @hide 1456 */ 1457 public abstract void clearApplicationUserData(String packageName, 1458 IPackageDataObserver observer); 1459 /** 1460 * Attempts to delete the cache files associated with an application. 1461 * Since this may take a little while, the result will 1462 * be posted back to the given observer. A deletion will fail if the calling context 1463 * lacks the {@link android.Manifest.permission#DELETE_CACHE_FILES} permission, if the 1464 * named package cannot be found, or if the named package is a "system package". 1465 * 1466 * @param packageName The name of the package to delete 1467 * @param observer An observer callback to get notified when the cache file deletion 1468 * is complete. 1469 * {@link android.content.pm.IPackageDataObserver#onRemoveCompleted(String, boolean)} 1470 * will be called when that happens. observer may be null to indicate that 1471 * no callback is desired. 1472 * 1473 * @hide 1474 */ 1475 public abstract void deleteApplicationCacheFiles(String packageName, 1476 IPackageDataObserver observer); 1477 1478 /** 1479 * Free storage by deleting LRU sorted list of cache files across 1480 * all applications. If the currently available free storage 1481 * on the device is greater than or equal to the requested 1482 * free storage, no cache files are cleared. If the currently 1483 * available storage on the device is less than the requested 1484 * free storage, some or all of the cache files across 1485 * all applications are deleted (based on last accessed time) 1486 * to increase the free storage space on the device to 1487 * the requested value. There is no guarantee that clearing all 1488 * the cache files from all applications will clear up 1489 * enough storage to achieve the desired value. 1490 * @param freeStorageSize The number of bytes of storage to be 1491 * freed by the system. Say if freeStorageSize is XX, 1492 * and the current free storage is YY, 1493 * if XX is less than YY, just return. if not free XX-YY number 1494 * of bytes if possible. 1495 * @param observer call back used to notify when 1496 * the operation is completed 1497 * 1498 * @hide 1499 */ 1500 public abstract void freeStorageAndNotify(long freeStorageSize, IPackageDataObserver observer); 1501 1502 /** 1503 * Free storage by deleting LRU sorted list of cache files across 1504 * all applications. If the currently available free storage 1505 * on the device is greater than or equal to the requested 1506 * free storage, no cache files are cleared. If the currently 1507 * available storage on the device is less than the requested 1508 * free storage, some or all of the cache files across 1509 * all applications are deleted (based on last accessed time) 1510 * to increase the free storage space on the device to 1511 * the requested value. There is no guarantee that clearing all 1512 * the cache files from all applications will clear up 1513 * enough storage to achieve the desired value. 1514 * @param freeStorageSize The number of bytes of storage to be 1515 * freed by the system. Say if freeStorageSize is XX, 1516 * and the current free storage is YY, 1517 * if XX is less than YY, just return. if not free XX-YY number 1518 * of bytes if possible. 1519 * @param pi IntentSender call back used to 1520 * notify when the operation is completed.May be null 1521 * to indicate that no call back is desired. 1522 * 1523 * @hide 1524 */ 1525 public abstract void freeStorage(long freeStorageSize, IntentSender pi); 1526 1527 /** 1528 * Retrieve the size information for a package. 1529 * Since this may take a little while, the result will 1530 * be posted back to the given observer. The calling context 1531 * should have the {@link android.Manifest.permission#GET_PACKAGE_SIZE} permission. 1532 * 1533 * @param packageName The name of the package whose size information is to be retrieved 1534 * @param observer An observer callback to get notified when the operation 1535 * is complete. 1536 * {@link android.content.pm.IPackageStatsObserver#onGetStatsCompleted(PackageStats, boolean)} 1537 * The observer's callback is invoked with a PackageStats object(containing the 1538 * code, data and cache sizes of the package) and a boolean value representing 1539 * the status of the operation. observer may be null to indicate that 1540 * no callback is desired. 1541 * 1542 * @hide 1543 */ 1544 public abstract void getPackageSizeInfo(String packageName, 1545 IPackageStatsObserver observer); 1546 1547 /** 1548 * Add a new package to the list of preferred packages. This new package 1549 * will be added to the front of the list (removed from its current location 1550 * if already listed), meaning it will now be preferred over all other 1551 * packages when resolving conflicts. 1552 * 1553 * @param packageName The package name of the new package to make preferred. 1554 */ 1555 public abstract void addPackageToPreferred(String packageName); 1556 1557 /** 1558 * Remove a package from the list of preferred packages. If it was on 1559 * the list, it will no longer be preferred over other packages. 1560 * 1561 * @param packageName The package name to remove. 1562 */ 1563 public abstract void removePackageFromPreferred(String packageName); 1564 1565 /** 1566 * Retrieve the list of all currently configured preferred packages. The 1567 * first package on the list is the most preferred, the last is the 1568 * least preferred. 1569 * 1570 * @param flags Additional option flags. Use any combination of 1571 * {@link #GET_ACTIVITIES}, 1572 * {@link #GET_GIDS}, 1573 * {@link #GET_CONFIGURATIONS}, 1574 * {@link #GET_INSTRUMENTATION}, 1575 * {@link #GET_PERMISSIONS}, 1576 * {@link #GET_PROVIDERS}, 1577 * {@link #GET_RECEIVERS}, 1578 * {@link #GET_SERVICES}, 1579 * {@link #GET_SIGNATURES}, to modify the data returned. 1580 * 1581 * @return Returns a list of PackageInfo objects describing each 1582 * preferred application, in order of preference. 1583 * 1584 * @see #GET_ACTIVITIES 1585 * @see #GET_GIDS 1586 * @see #GET_CONFIGURATIONS 1587 * @see #GET_INSTRUMENTATION 1588 * @see #GET_PERMISSIONS 1589 * @see #GET_PROVIDERS 1590 * @see #GET_RECEIVERS 1591 * @see #GET_SERVICES 1592 * @see #GET_SIGNATURES 1593 */ 1594 public abstract List<PackageInfo> getPreferredPackages(int flags); 1595 1596 /** 1597 * Add a new preferred activity mapping to the system. This will be used 1598 * to automatically select the given activity component when 1599 * {@link Context#startActivity(Intent) Context.startActivity()} finds 1600 * multiple matching activities and also matches the given filter. 1601 * 1602 * @param filter The set of intents under which this activity will be 1603 * made preferred. 1604 * @param match The IntentFilter match category that this preference 1605 * applies to. 1606 * @param set The set of activities that the user was picking from when 1607 * this preference was made. 1608 * @param activity The component name of the activity that is to be 1609 * preferred. 1610 */ 1611 public abstract void addPreferredActivity(IntentFilter filter, int match, 1612 ComponentName[] set, ComponentName activity); 1613 1614 /** 1615 * Replaces an existing preferred activity mapping to the system, and if that were not present 1616 * adds a new preferred activity. This will be used 1617 * to automatically select the given activity component when 1618 * {@link Context#startActivity(Intent) Context.startActivity()} finds 1619 * multiple matching activities and also matches the given filter. 1620 * 1621 * @param filter The set of intents under which this activity will be 1622 * made preferred. 1623 * @param match The IntentFilter match category that this preference 1624 * applies to. 1625 * @param set The set of activities that the user was picking from when 1626 * this preference was made. 1627 * @param activity The component name of the activity that is to be 1628 * preferred. 1629 * @hide 1630 */ 1631 public abstract void replacePreferredActivity(IntentFilter filter, int match, 1632 ComponentName[] set, ComponentName activity); 1633 1634 /** 1635 * Remove all preferred activity mappings, previously added with 1636 * {@link #addPreferredActivity}, from the 1637 * system whose activities are implemented in the given package name. 1638 * 1639 * @param packageName The name of the package whose preferred activity 1640 * mappings are to be removed. 1641 */ 1642 public abstract void clearPackagePreferredActivities(String packageName); 1643 1644 /** 1645 * Retrieve all preferred activities, previously added with 1646 * {@link #addPreferredActivity}, that are 1647 * currently registered with the system. 1648 * 1649 * @param outFilters A list in which to place the filters of all of the 1650 * preferred activities, or null for none. 1651 * @param outActivities A list in which to place the component names of 1652 * all of the preferred activities, or null for none. 1653 * @param packageName An option package in which you would like to limit 1654 * the list. If null, all activities will be returned; if non-null, only 1655 * those activities in the given package are returned. 1656 * 1657 * @return Returns the total number of registered preferred activities 1658 * (the number of distinct IntentFilter records, not the number of unique 1659 * activity components) that were found. 1660 */ 1661 public abstract int getPreferredActivities(List<IntentFilter> outFilters, 1662 List<ComponentName> outActivities, String packageName); 1663 1664 /** 1665 * Set the enabled setting for a package component (activity, receiver, service, provider). 1666 * This setting will override any enabled state which may have been set by the component in its 1667 * manifest. 1668 * 1669 * @param componentName The component to enable 1670 * @param newState The new enabled state for the component. The legal values for this state 1671 * are: 1672 * {@link #COMPONENT_ENABLED_STATE_ENABLED}, 1673 * {@link #COMPONENT_ENABLED_STATE_DISABLED} 1674 * and 1675 * {@link #COMPONENT_ENABLED_STATE_DEFAULT} 1676 * The last one removes the setting, thereby restoring the component's state to 1677 * whatever was set in it's manifest (or enabled, by default). 1678 * @param flags Optional behavior flags: {@link #DONT_KILL_APP} or 0. 1679 */ 1680 public abstract void setComponentEnabledSetting(ComponentName componentName, 1681 int newState, int flags); 1682 1683 1684 /** 1685 * Return the the enabled setting for a package component (activity, 1686 * receiver, service, provider). This returns the last value set by 1687 * {@link #setComponentEnabledSetting(ComponentName, int, int)}; in most 1688 * cases this value will be {@link #COMPONENT_ENABLED_STATE_DEFAULT} since 1689 * the value originally specified in the manifest has not been modified. 1690 * 1691 * @param componentName The component to retrieve. 1692 * @return Returns the current enabled state for the component. May 1693 * be one of {@link #COMPONENT_ENABLED_STATE_ENABLED}, 1694 * {@link #COMPONENT_ENABLED_STATE_DISABLED}, or 1695 * {@link #COMPONENT_ENABLED_STATE_DEFAULT}. The last one means the 1696 * component's enabled state is based on the original information in 1697 * the manifest as found in {@link ComponentInfo}. 1698 */ 1699 public abstract int getComponentEnabledSetting(ComponentName componentName); 1700 1701 /** 1702 * Set the enabled setting for an application 1703 * This setting will override any enabled state which may have been set by the application in 1704 * its manifest. It also overrides the enabled state set in the manifest for any of the 1705 * application's components. It does not override any enabled state set by 1706 * {@link #setComponentEnabledSetting} for any of the application's components. 1707 * 1708 * @param packageName The package name of the application to enable 1709 * @param newState The new enabled state for the component. The legal values for this state 1710 * are: 1711 * {@link #COMPONENT_ENABLED_STATE_ENABLED}, 1712 * {@link #COMPONENT_ENABLED_STATE_DISABLED} 1713 * and 1714 * {@link #COMPONENT_ENABLED_STATE_DEFAULT} 1715 * The last one removes the setting, thereby restoring the applications's state to 1716 * whatever was set in its manifest (or enabled, by default). 1717 * @param flags Optional behavior flags: {@link #DONT_KILL_APP} or 0. 1718 */ 1719 public abstract void setApplicationEnabledSetting(String packageName, 1720 int newState, int flags); 1721 1722 /** 1723 * Return the the enabled setting for an application. This returns 1724 * the last value set by 1725 * {@link #setApplicationEnabledSetting(String, int, int)}; in most 1726 * cases this value will be {@link #COMPONENT_ENABLED_STATE_DEFAULT} since 1727 * the value originally specified in the manifest has not been modified. 1728 * 1729 * @param packageName The component to retrieve. 1730 * @return Returns the current enabled state for the component. May 1731 * be one of {@link #COMPONENT_ENABLED_STATE_ENABLED}, 1732 * {@link #COMPONENT_ENABLED_STATE_DISABLED}, or 1733 * {@link #COMPONENT_ENABLED_STATE_DEFAULT}. The last one means the 1734 * application's enabled state is based on the original information in 1735 * the manifest as found in {@link ComponentInfo}. 1736 */ 1737 public abstract int getApplicationEnabledSetting(String packageName); 1738 1739 /** 1740 * Return whether the device has been booted into safe mode. 1741 */ 1742 public abstract boolean isSafeMode(); 1743} 1744