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