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