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