PackageManager.java revision 076357b8567458d4b6dfdcf839ef751634cd2bfb
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 * Get a list of shared libraries that are available on the 857 * system. 858 * 859 * @return An array of shared library names that are 860 * available on the system, or null if none are installed. 861 * 862 */ 863 public abstract String[] getSystemSharedLibraryNames(); 864 865 /** 866 * Determine the best action to perform for a given Intent. This is how 867 * {@link Intent#resolveActivity} finds an activity if a class has not 868 * been explicitly specified. 869 * 870 * @param intent An intent containing all of the desired specification 871 * (action, data, type, category, and/or component). 872 * @param flags Additional option flags. The most important is 873 * MATCH_DEFAULT_ONLY, to limit the resolution to only 874 * those activities that support the CATEGORY_DEFAULT. 875 * 876 * @return Returns a ResolveInfo containing the final activity intent that 877 * was determined to be the best action. Returns null if no 878 * matching activity was found. 879 * 880 * @see #MATCH_DEFAULT_ONLY 881 * @see #GET_INTENT_FILTERS 882 * @see #GET_RESOLVED_FILTER 883 */ 884 public abstract ResolveInfo resolveActivity(Intent intent, int flags); 885 886 /** 887 * Retrieve all activities that can be performed for the given intent. 888 * 889 * @param intent The desired intent as per resolveActivity(). 890 * @param flags Additional option flags. The most important is 891 * MATCH_DEFAULT_ONLY, to limit the resolution to only 892 * those activities that support the CATEGORY_DEFAULT. 893 * 894 * @return A List<ResolveInfo> containing one entry for each matching 895 * Activity. These are ordered from best to worst match -- that 896 * is, the first item in the list is what is returned by 897 * resolveActivity(). If there are no matching activities, an empty 898 * list is returned. 899 * 900 * @see #MATCH_DEFAULT_ONLY 901 * @see #GET_INTENT_FILTERS 902 * @see #GET_RESOLVED_FILTER 903 */ 904 public abstract List<ResolveInfo> queryIntentActivities(Intent intent, 905 int flags); 906 907 /** 908 * Retrieve a set of activities that should be presented to the user as 909 * similar options. This is like {@link #queryIntentActivities}, except it 910 * also allows you to supply a list of more explicit Intents that you would 911 * like to resolve to particular options, and takes care of returning the 912 * final ResolveInfo list in a reasonable order, with no duplicates, based 913 * on those inputs. 914 * 915 * @param caller The class name of the activity that is making the 916 * request. This activity will never appear in the output 917 * list. Can be null. 918 * @param specifics An array of Intents that should be resolved to the 919 * first specific results. Can be null. 920 * @param intent The desired intent as per resolveActivity(). 921 * @param flags Additional option flags. The most important is 922 * MATCH_DEFAULT_ONLY, to limit the resolution to only 923 * those activities that support the CATEGORY_DEFAULT. 924 * 925 * @return A List<ResolveInfo> containing one entry for each matching 926 * Activity. These are ordered first by all of the intents resolved 927 * in <var>specifics</var> and then any additional activities that 928 * can handle <var>intent</var> but did not get included by one of 929 * the <var>specifics</var> intents. If there are no matching 930 * activities, an empty list is returned. 931 * 932 * @see #MATCH_DEFAULT_ONLY 933 * @see #GET_INTENT_FILTERS 934 * @see #GET_RESOLVED_FILTER 935 */ 936 public abstract List<ResolveInfo> queryIntentActivityOptions( 937 ComponentName caller, Intent[] specifics, Intent intent, int flags); 938 939 /** 940 * Retrieve all receivers that can handle a broadcast of the given intent. 941 * 942 * @param intent The desired intent as per resolveActivity(). 943 * @param flags Additional option flags. The most important is 944 * MATCH_DEFAULT_ONLY, to limit the resolution to only 945 * those activities that support the CATEGORY_DEFAULT. 946 * 947 * @return A List<ResolveInfo> containing one entry for each matching 948 * Receiver. These are ordered from first to last in priority. If 949 * there are no matching receivers, an empty list is returned. 950 * 951 * @see #MATCH_DEFAULT_ONLY 952 * @see #GET_INTENT_FILTERS 953 * @see #GET_RESOLVED_FILTER 954 */ 955 public abstract List<ResolveInfo> queryBroadcastReceivers(Intent intent, 956 int flags); 957 958 /** 959 * Determine the best service to handle for a given Intent. 960 * 961 * @param intent An intent containing all of the desired specification 962 * (action, data, type, category, and/or component). 963 * @param flags Additional option flags. 964 * 965 * @return Returns a ResolveInfo containing the final service intent that 966 * was determined to be the best action. Returns null if no 967 * matching service was found. 968 * 969 * @see #GET_INTENT_FILTERS 970 * @see #GET_RESOLVED_FILTER 971 */ 972 public abstract ResolveInfo resolveService(Intent intent, int flags); 973 974 /** 975 * Retrieve all services that can match the given intent. 976 * 977 * @param intent The desired intent as per resolveService(). 978 * @param flags Additional option flags. 979 * 980 * @return A List<ResolveInfo> containing one entry for each matching 981 * ServiceInfo. These are ordered from best to worst match -- that 982 * is, the first item in the list is what is returned by 983 * resolveService(). If there are no matching services, an empty 984 * list is returned. 985 * 986 * @see #GET_INTENT_FILTERS 987 * @see #GET_RESOLVED_FILTER 988 */ 989 public abstract List<ResolveInfo> queryIntentServices(Intent intent, 990 int flags); 991 992 /** 993 * Find a single content provider by its base path name. 994 * 995 * @param name The name of the provider to find. 996 * @param flags Additional option flags. Currently should always be 0. 997 * 998 * @return ContentProviderInfo Information about the provider, if found, 999 * else null. 1000 */ 1001 public abstract ProviderInfo resolveContentProvider(String name, 1002 int flags); 1003 1004 /** 1005 * Retrieve content provider information. 1006 * 1007 * <p><em>Note: unlike most other methods, an empty result set is indicated 1008 * by a null return instead of an empty list.</em> 1009 * 1010 * @param processName If non-null, limits the returned providers to only 1011 * those that are hosted by the given process. If null, 1012 * all content providers are returned. 1013 * @param uid If <var>processName</var> is non-null, this is the required 1014 * uid owning the requested content providers. 1015 * @param flags Additional option flags. Currently should always be 0. 1016 * 1017 * @return A List<ContentProviderInfo> containing one entry for each 1018 * content provider either patching <var>processName</var> or, if 1019 * <var>processName</var> is null, all known content providers. 1020 * <em>If there are no matching providers, null is returned.</em> 1021 */ 1022 public abstract List<ProviderInfo> queryContentProviders( 1023 String processName, int uid, int flags); 1024 1025 /** 1026 * Retrieve all of the information we know about a particular 1027 * instrumentation class. 1028 * 1029 * <p>Throws {@link NameNotFoundException} if instrumentation with the 1030 * given class name can not be found on the system. 1031 * 1032 * @param className The full name (i.e. 1033 * com.google.apps.contacts.InstrumentList) of an 1034 * Instrumentation class. 1035 * @param flags Additional option flags. Currently should always be 0. 1036 * 1037 * @return InstrumentationInfo containing information about the 1038 * instrumentation. 1039 */ 1040 public abstract InstrumentationInfo getInstrumentationInfo( 1041 ComponentName className, int flags) throws NameNotFoundException; 1042 1043 /** 1044 * Retrieve information about available instrumentation code. May be used 1045 * to retrieve either all instrumentation code, or only the code targeting 1046 * a particular package. 1047 * 1048 * @param targetPackage If null, all instrumentation is returned; only the 1049 * instrumentation targeting this package name is 1050 * returned. 1051 * @param flags Additional option flags. Currently should always be 0. 1052 * 1053 * @return A List<InstrumentationInfo> containing one entry for each 1054 * matching available Instrumentation. Returns an empty list if 1055 * there is no instrumentation available for the given package. 1056 */ 1057 public abstract List<InstrumentationInfo> queryInstrumentation( 1058 String targetPackage, int flags); 1059 1060 /** 1061 * Retrieve an image from a package. This is a low-level API used by 1062 * the various package manager info structures (such as 1063 * {@link ComponentInfo} to implement retrieval of their associated 1064 * icon. 1065 * 1066 * @param packageName The name of the package that this icon is coming from. 1067 * Can not be null. 1068 * @param resid The resource identifier of the desired image. Can not be 0. 1069 * @param appInfo Overall information about <var>packageName</var>. This 1070 * may be null, in which case the application information will be retrieved 1071 * for you if needed; if you already have this information around, it can 1072 * be much more efficient to supply it here. 1073 * 1074 * @return Returns a Drawable holding the requested image. Returns null if 1075 * an image could not be found for any reason. 1076 */ 1077 public abstract Drawable getDrawable(String packageName, int resid, 1078 ApplicationInfo appInfo); 1079 1080 /** 1081 * Retrieve the icon associated with an activity. Given the full name of 1082 * an activity, retrieves the information about it and calls 1083 * {@link ComponentInfo#loadIcon ComponentInfo.loadIcon()} to return its icon. 1084 * If the activity can not be found, NameNotFoundException is thrown. 1085 * 1086 * @param activityName Name of the activity whose icon is to be retrieved. 1087 * 1088 * @return Returns the image of the icon, or the default activity icon if 1089 * it could not be found. Does not return null. 1090 * @throws NameNotFoundException Thrown if the resources for the given 1091 * activity could not be loaded. 1092 * 1093 * @see #getActivityIcon(Intent) 1094 */ 1095 public abstract Drawable getActivityIcon(ComponentName activityName) 1096 throws NameNotFoundException; 1097 1098 /** 1099 * Retrieve the icon associated with an Intent. If intent.getClassName() is 1100 * set, this simply returns the result of 1101 * getActivityIcon(intent.getClassName()). Otherwise it resolves the intent's 1102 * component and returns the icon associated with the resolved component. 1103 * If intent.getClassName() can not be found or the Intent can not be resolved 1104 * to a component, NameNotFoundException is thrown. 1105 * 1106 * @param intent The intent for which you would like to retrieve an icon. 1107 * 1108 * @return Returns the image of the icon, or the default activity icon if 1109 * it could not be found. Does not return null. 1110 * @throws NameNotFoundException Thrown if the resources for application 1111 * matching the given intent could not be loaded. 1112 * 1113 * @see #getActivityIcon(ComponentName) 1114 */ 1115 public abstract Drawable getActivityIcon(Intent intent) 1116 throws NameNotFoundException; 1117 1118 /** 1119 * Return the generic icon for an activity that is used when no specific 1120 * icon is defined. 1121 * 1122 * @return Drawable Image of the icon. 1123 */ 1124 public abstract Drawable getDefaultActivityIcon(); 1125 1126 /** 1127 * Retrieve the icon associated with an application. If it has not defined 1128 * an icon, the default app icon is returned. Does not return null. 1129 * 1130 * @param info Information about application being queried. 1131 * 1132 * @return Returns the image of the icon, or the default application icon 1133 * if it could not be found. 1134 * 1135 * @see #getApplicationIcon(String) 1136 */ 1137 public abstract Drawable getApplicationIcon(ApplicationInfo info); 1138 1139 /** 1140 * Retrieve the icon associated with an application. Given the name of the 1141 * application's package, retrieves the information about it and calls 1142 * getApplicationIcon() to return its icon. If the application can not be 1143 * found, NameNotFoundException is thrown. 1144 * 1145 * @param packageName Name of the package whose application icon is to be 1146 * retrieved. 1147 * 1148 * @return Returns the image of the icon, or the default application icon 1149 * if it could not be found. Does not return null. 1150 * @throws NameNotFoundException Thrown if the resources for the given 1151 * application could not be loaded. 1152 * 1153 * @see #getApplicationIcon(ApplicationInfo) 1154 */ 1155 public abstract Drawable getApplicationIcon(String packageName) 1156 throws NameNotFoundException; 1157 1158 /** 1159 * Retrieve text from a package. This is a low-level API used by 1160 * the various package manager info structures (such as 1161 * {@link ComponentInfo} to implement retrieval of their associated 1162 * labels and other text. 1163 * 1164 * @param packageName The name of the package that this text is coming from. 1165 * Can not be null. 1166 * @param resid The resource identifier of the desired text. Can not be 0. 1167 * @param appInfo Overall information about <var>packageName</var>. This 1168 * may be null, in which case the application information will be retrieved 1169 * for you if needed; if you already have this information around, it can 1170 * be much more efficient to supply it here. 1171 * 1172 * @return Returns a CharSequence holding the requested text. Returns null 1173 * if the text could not be found for any reason. 1174 */ 1175 public abstract CharSequence getText(String packageName, int resid, 1176 ApplicationInfo appInfo); 1177 1178 /** 1179 * Retrieve an XML file from a package. This is a low-level API used to 1180 * retrieve XML meta data. 1181 * 1182 * @param packageName The name of the package that this xml is coming from. 1183 * Can not be null. 1184 * @param resid The resource identifier of the desired xml. Can not be 0. 1185 * @param appInfo Overall information about <var>packageName</var>. This 1186 * may be null, in which case the application information will be retrieved 1187 * for you if needed; if you already have this information around, it can 1188 * be much more efficient to supply it here. 1189 * 1190 * @return Returns an XmlPullParser allowing you to parse out the XML 1191 * data. Returns null if the xml resource could not be found for any 1192 * reason. 1193 */ 1194 public abstract XmlResourceParser getXml(String packageName, int resid, 1195 ApplicationInfo appInfo); 1196 1197 /** 1198 * Return the label to use for this application. 1199 * 1200 * @return Returns the label associated with this application, or null if 1201 * it could not be found for any reason. 1202 * @param info The application to get the label of 1203 */ 1204 public abstract CharSequence getApplicationLabel(ApplicationInfo info); 1205 1206 /** 1207 * Retrieve the resources associated with an activity. Given the full 1208 * name of an activity, retrieves the information about it and calls 1209 * getResources() to return its application's resources. If the activity 1210 * can not be found, NameNotFoundException is thrown. 1211 * 1212 * @param activityName Name of the activity whose resources are to be 1213 * retrieved. 1214 * 1215 * @return Returns the application's Resources. 1216 * @throws NameNotFoundException Thrown if the resources for the given 1217 * application could not be loaded. 1218 * 1219 * @see #getResourcesForApplication(ApplicationInfo) 1220 */ 1221 public abstract Resources getResourcesForActivity(ComponentName activityName) 1222 throws NameNotFoundException; 1223 1224 /** 1225 * Retrieve the resources for an application. Throws NameNotFoundException 1226 * if the package is no longer installed. 1227 * 1228 * @param app Information about the desired application. 1229 * 1230 * @return Returns the application's Resources. 1231 * @throws NameNotFoundException Thrown if the resources for the given 1232 * application could not be loaded (most likely because it was uninstalled). 1233 */ 1234 public abstract Resources getResourcesForApplication(ApplicationInfo app) 1235 throws NameNotFoundException; 1236 1237 /** 1238 * Retrieve the resources associated with an application. Given the full 1239 * package name of an application, retrieves the information about it and 1240 * calls getResources() to return its application's resources. If the 1241 * appPackageName can not be found, NameNotFoundException is thrown. 1242 * 1243 * @param appPackageName Package name of the application whose resources 1244 * are to be retrieved. 1245 * 1246 * @return Returns the application's Resources. 1247 * @throws NameNotFoundException Thrown if the resources for the given 1248 * application could not be loaded. 1249 * 1250 * @see #getResourcesForApplication(ApplicationInfo) 1251 */ 1252 public abstract Resources getResourcesForApplication(String appPackageName) 1253 throws NameNotFoundException; 1254 1255 /** 1256 * Retrieve overall information about an application package defined 1257 * in a package archive file 1258 * 1259 * @param archiveFilePath The path to the archive file 1260 * @param flags Additional option flags. Use any combination of 1261 * {@link #GET_ACTIVITIES}, 1262 * {@link #GET_GIDS}, 1263 * {@link #GET_CONFIGURATIONS}, 1264 * {@link #GET_INSTRUMENTATION}, 1265 * {@link #GET_PERMISSIONS}, 1266 * {@link #GET_PROVIDERS}, 1267 * {@link #GET_RECEIVERS}, 1268 * {@link #GET_SERVICES}, 1269 * {@link #GET_SIGNATURES}, to modify the data returned. 1270 * 1271 * @return Returns the information about the package. Returns 1272 * null if the package could not be successfully parsed. 1273 * 1274 * @see #GET_ACTIVITIES 1275 * @see #GET_GIDS 1276 * @see #GET_CONFIGURATIONS 1277 * @see #GET_INSTRUMENTATION 1278 * @see #GET_PERMISSIONS 1279 * @see #GET_PROVIDERS 1280 * @see #GET_RECEIVERS 1281 * @see #GET_SERVICES 1282 * @see #GET_SIGNATURES 1283 * 1284 */ 1285 public PackageInfo getPackageArchiveInfo(String archiveFilePath, int flags) { 1286 PackageParser packageParser = new PackageParser(archiveFilePath); 1287 DisplayMetrics metrics = new DisplayMetrics(); 1288 metrics.setToDefaults(); 1289 final File sourceFile = new File(archiveFilePath); 1290 PackageParser.Package pkg = packageParser.parsePackage( 1291 sourceFile, archiveFilePath, metrics, 0); 1292 if (pkg == null) { 1293 return null; 1294 } 1295 return PackageParser.generatePackageInfo(pkg, null, flags); 1296 } 1297 1298 /** 1299 * Install a package. Since this may take a little while, the result will 1300 * be posted back to the given observer. An installation will fail if the calling context 1301 * lacks the {@link android.Manifest.permission#INSTALL_PACKAGES} permission, if the 1302 * package named in the package file's manifest is already installed, or if there's no space 1303 * available on the device. 1304 * 1305 * @param packageURI The location of the package file to install. This can be a 'file:' or a 1306 * 'content:' URI. 1307 * @param observer An observer callback to get notified when the package installation is 1308 * complete. {@link IPackageInstallObserver#packageInstalled(String, int)} will be 1309 * called when that happens. observer may be null to indicate that no callback is desired. 1310 * @param flags - possible values: {@link #FORWARD_LOCK_PACKAGE}, 1311 * {@link #REPLACE_EXISTING_PACKAGE} 1312 * 1313 * @see #installPackage(android.net.Uri) 1314 */ 1315 public abstract void installPackage( 1316 Uri packageURI, IPackageInstallObserver observer, int flags); 1317 1318 /** 1319 * Attempts to delete a package. Since this may take a little while, the result will 1320 * be posted back to the given observer. A deletion will fail if the calling context 1321 * lacks the {@link android.Manifest.permission#DELETE_PACKAGES} permission, if the 1322 * named package cannot be found, or if the named package is a "system package". 1323 * (TODO: include pointer to documentation on "system packages") 1324 * 1325 * @param packageName The name of the package to delete 1326 * @param observer An observer callback to get notified when the package deletion is 1327 * complete. {@link android.content.pm.IPackageDeleteObserver#packageDeleted(boolean)} will be 1328 * called when that happens. observer may be null to indicate that no callback is desired. 1329 * @param flags - possible values: {@link #DONT_DELETE_DATA} 1330 * 1331 * @hide 1332 */ 1333 public abstract void deletePackage( 1334 String packageName, IPackageDeleteObserver observer, int flags); 1335 /** 1336 * Attempts to clear the user data directory of an application. 1337 * Since this may take a little while, the result will 1338 * be posted back to the given observer. A deletion will fail if the 1339 * named package cannot be found, or if the named package is a "system package". 1340 * 1341 * @param packageName The name of the package 1342 * @param observer An observer callback to get notified when the operation is finished 1343 * {@link android.content.pm.IPackageDataObserver#onRemoveCompleted(String, boolean)} 1344 * will be called when that happens. observer may be null to indicate that 1345 * no callback is desired. 1346 * 1347 * @hide 1348 */ 1349 public abstract void clearApplicationUserData(String packageName, 1350 IPackageDataObserver observer); 1351 /** 1352 * Attempts to delete the cache files associated with an application. 1353 * Since this may take a little while, the result will 1354 * be posted back to the given observer. A deletion will fail if the calling context 1355 * lacks the {@link android.Manifest.permission#DELETE_CACHE_FILES} permission, if the 1356 * named package cannot be found, or if the named package is a "system package". 1357 * 1358 * @param packageName The name of the package to delete 1359 * @param observer An observer callback to get notified when the cache file deletion 1360 * is complete. 1361 * {@link android.content.pm.IPackageDataObserver#onRemoveCompleted(String, boolean)} 1362 * will be called when that happens. observer may be null to indicate that 1363 * no callback is desired. 1364 * 1365 * @hide 1366 */ 1367 public abstract void deleteApplicationCacheFiles(String packageName, 1368 IPackageDataObserver observer); 1369 1370 /** 1371 * Free storage by deleting LRU sorted list of cache files across 1372 * all applications. If the currently available free storage 1373 * on the device is greater than or equal to the requested 1374 * free storage, no cache files are cleared. If the currently 1375 * available storage on the device is less than the requested 1376 * free storage, some or all of the cache files across 1377 * all applications are deleted (based on last accessed time) 1378 * to increase the free storage space on the device to 1379 * the requested value. There is no guarantee that clearing all 1380 * the cache files from all applications will clear up 1381 * enough storage to achieve the desired value. 1382 * @param freeStorageSize The number of bytes of storage to be 1383 * freed by the system. Say if freeStorageSize is XX, 1384 * and the current free storage is YY, 1385 * if XX is less than YY, just return. if not free XX-YY number 1386 * of bytes if possible. 1387 * @param observer call back used to notify when 1388 * the operation is completed 1389 * 1390 * @hide 1391 */ 1392 public abstract void freeStorageAndNotify(long freeStorageSize, IPackageDataObserver observer); 1393 1394 /** 1395 * Free storage by deleting LRU sorted list of cache files across 1396 * all applications. If the currently available free storage 1397 * on the device is greater than or equal to the requested 1398 * free storage, no cache files are cleared. If the currently 1399 * available storage on the device is less than the requested 1400 * free storage, some or all of the cache files across 1401 * all applications are deleted (based on last accessed time) 1402 * to increase the free storage space on the device to 1403 * the requested value. There is no guarantee that clearing all 1404 * the cache files from all applications will clear up 1405 * enough storage to achieve the desired value. 1406 * @param freeStorageSize The number of bytes of storage to be 1407 * freed by the system. Say if freeStorageSize is XX, 1408 * and the current free storage is YY, 1409 * if XX is less than YY, just return. if not free XX-YY number 1410 * of bytes if possible. 1411 * @param opFinishedIntent PendingIntent call back used to 1412 * notify when the operation is completed.May be null 1413 * to indicate that no call back is desired. 1414 * 1415 * @hide 1416 */ 1417 public abstract void freeStorage(long freeStorageSize, PendingIntent opFinishedIntent); 1418 1419 /** 1420 * Retrieve the size information for a package. 1421 * Since this may take a little while, the result will 1422 * be posted back to the given observer. The calling context 1423 * should have the {@link android.Manifest.permission#GET_PACKAGE_SIZE} permission. 1424 * 1425 * @param packageName The name of the package whose size information is to be retrieved 1426 * @param observer An observer callback to get notified when the operation 1427 * is complete. 1428 * {@link android.content.pm.IPackageStatsObserver#onGetStatsCompleted(PackageStats, boolean)} 1429 * The observer's callback is invoked with a PackageStats object(containing the 1430 * code, data and cache sizes of the package) and a boolean value representing 1431 * the status of the operation. observer may be null to indicate that 1432 * no callback is desired. 1433 * 1434 * @hide 1435 */ 1436 public abstract void getPackageSizeInfo(String packageName, 1437 IPackageStatsObserver observer); 1438 1439 /** 1440 * Install a package. 1441 * 1442 * @param packageURI The location of the package file to install 1443 * 1444 * @see #installPackage(android.net.Uri, IPackageInstallObserver, int) 1445 */ 1446 public void installPackage(Uri packageURI) { 1447 installPackage(packageURI, null, 0); 1448 } 1449 1450 /** 1451 * Add a new package to the list of preferred packages. This new package 1452 * will be added to the front of the list (removed from its current location 1453 * if already listed), meaning it will now be preferred over all other 1454 * packages when resolving conflicts. 1455 * 1456 * @param packageName The package name of the new package to make preferred. 1457 */ 1458 public abstract void addPackageToPreferred(String packageName); 1459 1460 /** 1461 * Remove a package from the list of preferred packages. If it was on 1462 * the list, it will no longer be preferred over other packages. 1463 * 1464 * @param packageName The package name to remove. 1465 */ 1466 public abstract void removePackageFromPreferred(String packageName); 1467 1468 /** 1469 * Retrieve the list of all currently configured preferred packages. The 1470 * first package on the list is the most preferred, the last is the 1471 * least preferred. 1472 * 1473 * @param flags Additional option flags. Use any combination of 1474 * {@link #GET_ACTIVITIES}, 1475 * {@link #GET_GIDS}, 1476 * {@link #GET_CONFIGURATIONS}, 1477 * {@link #GET_INSTRUMENTATION}, 1478 * {@link #GET_PERMISSIONS}, 1479 * {@link #GET_PROVIDERS}, 1480 * {@link #GET_RECEIVERS}, 1481 * {@link #GET_SERVICES}, 1482 * {@link #GET_SIGNATURES}, to modify the data returned. 1483 * 1484 * @return Returns a list of PackageInfo objects describing each 1485 * preferred application, in order of preference. 1486 * 1487 * @see #GET_ACTIVITIES 1488 * @see #GET_GIDS 1489 * @see #GET_CONFIGURATIONS 1490 * @see #GET_INSTRUMENTATION 1491 * @see #GET_PERMISSIONS 1492 * @see #GET_PROVIDERS 1493 * @see #GET_RECEIVERS 1494 * @see #GET_SERVICES 1495 * @see #GET_SIGNATURES 1496 */ 1497 public abstract List<PackageInfo> getPreferredPackages(int flags); 1498 1499 /** 1500 * Add a new preferred activity mapping to the system. This will be used 1501 * to automatically select the given activity component when 1502 * {@link Context#startActivity(Intent) Context.startActivity()} finds 1503 * multiple matching activities and also matches the given filter. 1504 * 1505 * @param filter The set of intents under which this activity will be 1506 * made preferred. 1507 * @param match The IntentFilter match category that this preference 1508 * applies to. 1509 * @param set The set of activities that the user was picking from when 1510 * this preference was made. 1511 * @param activity The component name of the activity that is to be 1512 * preferred. 1513 */ 1514 public abstract void addPreferredActivity(IntentFilter filter, int match, 1515 ComponentName[] set, ComponentName activity); 1516 1517 /** 1518 * Remove all preferred activity mappings, previously added with 1519 * {@link #addPreferredActivity}, from the 1520 * system whose activities are implemented in the given package name. 1521 * 1522 * @param packageName The name of the package whose preferred activity 1523 * mappings are to be removed. 1524 */ 1525 public abstract void clearPackagePreferredActivities(String packageName); 1526 1527 /** 1528 * Retrieve all preferred activities, previously added with 1529 * {@link #addPreferredActivity}, that are 1530 * currently registered with the system. 1531 * 1532 * @param outFilters A list in which to place the filters of all of the 1533 * preferred activities, or null for none. 1534 * @param outActivities A list in which to place the component names of 1535 * all of the preferred activities, or null for none. 1536 * @param packageName An option package in which you would like to limit 1537 * the list. If null, all activities will be returned; if non-null, only 1538 * those activities in the given package are returned. 1539 * 1540 * @return Returns the total number of registered preferred activities 1541 * (the number of distinct IntentFilter records, not the number of unique 1542 * activity components) that were found. 1543 */ 1544 public abstract int getPreferredActivities(List<IntentFilter> outFilters, 1545 List<ComponentName> outActivities, String packageName); 1546 1547 /** 1548 * Set the enabled setting for a package component (activity, receiver, service, provider). 1549 * This setting will override any enabled state which may have been set by the component in its 1550 * manifest. 1551 * 1552 * @param componentName The component to enable 1553 * @param newState The new enabled state for the component. The legal values for this state 1554 * are: 1555 * {@link #COMPONENT_ENABLED_STATE_ENABLED}, 1556 * {@link #COMPONENT_ENABLED_STATE_DISABLED} 1557 * and 1558 * {@link #COMPONENT_ENABLED_STATE_DEFAULT} 1559 * The last one removes the setting, thereby restoring the component's state to 1560 * whatever was set in it's manifest (or enabled, by default). 1561 * @param flags Optional behavior flags: {@link #DONT_KILL_APP} or 0. 1562 */ 1563 public abstract void setComponentEnabledSetting(ComponentName componentName, 1564 int newState, int flags); 1565 1566 1567 /** 1568 * Return the the enabled setting for a package component (activity, 1569 * receiver, service, provider). This returns the last value set by 1570 * {@link #setComponentEnabledSetting(ComponentName, int, int)}; in most 1571 * cases this value will be {@link #COMPONENT_ENABLED_STATE_DEFAULT} since 1572 * the value originally specified in the manifest has not been modified. 1573 * 1574 * @param componentName The component to retrieve. 1575 * @return Returns the current enabled state for the component. May 1576 * be one of {@link #COMPONENT_ENABLED_STATE_ENABLED}, 1577 * {@link #COMPONENT_ENABLED_STATE_DISABLED}, or 1578 * {@link #COMPONENT_ENABLED_STATE_DEFAULT}. The last one means the 1579 * component's enabled state is based on the original information in 1580 * the manifest as found in {@link ComponentInfo}. 1581 */ 1582 public abstract int getComponentEnabledSetting(ComponentName componentName); 1583 1584 /** 1585 * Set the enabled setting for an application 1586 * This setting will override any enabled state which may have been set by the application in 1587 * its manifest. It also overrides the enabled state set in the manifest for any of the 1588 * application's components. It does not override any enabled state set by 1589 * {@link #setComponentEnabledSetting} for any of the application's components. 1590 * 1591 * @param packageName The package name of the application to enable 1592 * @param newState The new enabled state for the component. The legal values for this state 1593 * are: 1594 * {@link #COMPONENT_ENABLED_STATE_ENABLED}, 1595 * {@link #COMPONENT_ENABLED_STATE_DISABLED} 1596 * and 1597 * {@link #COMPONENT_ENABLED_STATE_DEFAULT} 1598 * The last one removes the setting, thereby restoring the applications's state to 1599 * whatever was set in its manifest (or enabled, by default). 1600 * @param flags Optional behavior flags: {@link #DONT_KILL_APP} or 0. 1601 */ 1602 public abstract void setApplicationEnabledSetting(String packageName, 1603 int newState, int flags); 1604 1605 /** 1606 * Return the the enabled setting for an application. This returns 1607 * the last value set by 1608 * {@link #setApplicationEnabledSetting(String, int, int)}; in most 1609 * cases this value will be {@link #COMPONENT_ENABLED_STATE_DEFAULT} since 1610 * the value originally specified in the manifest has not been modified. 1611 * 1612 * @param packageName The component to retrieve. 1613 * @return Returns the current enabled state for the component. May 1614 * be one of {@link #COMPONENT_ENABLED_STATE_ENABLED}, 1615 * {@link #COMPONENT_ENABLED_STATE_DISABLED}, or 1616 * {@link #COMPONENT_ENABLED_STATE_DEFAULT}. The last one means the 1617 * application's enabled state is based on the original information in 1618 * the manifest as found in {@link ComponentInfo}. 1619 */ 1620 public abstract int getApplicationEnabledSetting(String packageName); 1621 1622 /** 1623 * Return whether the device has been booted into safe mode. 1624 */ 1625 public abstract boolean isSafeMode(); 1626} 1627