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