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