1 /* 2 * Copyright (C) 2015 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 17 package android.content.pm; 18 19 import android.annotation.AppIdInt; 20 import android.annotation.IntDef; 21 import android.annotation.NonNull; 22 import android.annotation.Nullable; 23 import android.annotation.UserIdInt; 24 import android.annotation.WorkerThread; 25 import android.content.ComponentName; 26 import android.content.ContentResolver; 27 import android.content.Intent; 28 import android.content.IntentSender; 29 import android.content.pm.PackageManager.ApplicationInfoFlags; 30 import android.content.pm.PackageManager.ComponentInfoFlags; 31 import android.content.pm.PackageManager.PackageInfoFlags; 32 import android.content.pm.PackageManager.ResolveInfoFlags; 33 import android.content.pm.parsing.component.ParsedMainComponent; 34 import android.os.Bundle; 35 import android.os.PersistableBundle; 36 import android.util.ArrayMap; 37 import android.util.ArraySet; 38 import android.util.SparseArray; 39 40 import com.android.server.pm.PackageList; 41 import com.android.server.pm.PackageSetting; 42 import com.android.server.pm.parsing.pkg.AndroidPackage; 43 44 import java.io.IOException; 45 import java.lang.annotation.Retention; 46 import java.lang.annotation.RetentionPolicy; 47 import java.util.Collection; 48 import java.util.List; 49 import java.util.function.Consumer; 50 51 /** 52 * Package manager local system service interface. 53 * 54 * @hide Only for use within the system server. 55 */ 56 public abstract class PackageManagerInternal { 57 public static final int PACKAGE_SYSTEM = 0; 58 public static final int PACKAGE_SETUP_WIZARD = 1; 59 public static final int PACKAGE_INSTALLER = 2; 60 public static final int PACKAGE_VERIFIER = 3; 61 public static final int PACKAGE_BROWSER = 4; 62 public static final int PACKAGE_SYSTEM_TEXT_CLASSIFIER = 5; 63 public static final int PACKAGE_PERMISSION_CONTROLLER = 6; 64 public static final int PACKAGE_WELLBEING = 7; 65 public static final int PACKAGE_DOCUMENTER = 8; 66 public static final int PACKAGE_CONFIGURATOR = 9; 67 public static final int PACKAGE_INCIDENT_REPORT_APPROVER = 10; 68 public static final int PACKAGE_APP_PREDICTOR = 11; 69 public static final int PACKAGE_WIFI = 13; 70 public static final int PACKAGE_COMPANION = 14; 71 public static final int PACKAGE_RETAIL_DEMO = 15; 72 73 @IntDef(flag = true, prefix = "RESOLVE_", value = { 74 RESOLVE_NON_BROWSER_ONLY, 75 RESOLVE_NON_RESOLVER_ONLY 76 }) 77 @Retention(RetentionPolicy.SOURCE) 78 public @interface PrivateResolveFlags {} 79 80 /** 81 * Internal {@link #resolveIntent(Intent, String, int, int, int, boolean, int)} flag: 82 * only match components that contain a generic web intent filter. 83 */ 84 public static final int RESOLVE_NON_BROWSER_ONLY = 0x00000001; 85 86 /** 87 * Internal {@link #resolveIntent(Intent, String, int, int, int, boolean, int)} flag: do not 88 * match to the resolver. 89 */ 90 public static final int RESOLVE_NON_RESOLVER_ONLY = 0x00000002; 91 92 @IntDef(value = { 93 INTEGRITY_VERIFICATION_ALLOW, 94 INTEGRITY_VERIFICATION_REJECT, 95 }) 96 @Retention(RetentionPolicy.SOURCE) 97 public @interface IntegrityVerificationResult {} 98 99 /** 100 * Used as the {@code verificationCode} argument for 101 * {@link PackageManagerInternal#setIntegrityVerificationResult(int, int)} to indicate that the 102 * integrity component allows the install to proceed. 103 */ 104 public static final int INTEGRITY_VERIFICATION_ALLOW = 1; 105 106 /** 107 * Used as the {@code verificationCode} argument for 108 * {@link PackageManagerInternal#setIntegrityVerificationResult(int, int)} to indicate that the 109 * integrity component does not allow install to proceed. 110 */ 111 public static final int INTEGRITY_VERIFICATION_REJECT = 0; 112 113 @IntDef(value = { 114 PACKAGE_SYSTEM, 115 PACKAGE_SETUP_WIZARD, 116 PACKAGE_INSTALLER, 117 PACKAGE_VERIFIER, 118 PACKAGE_BROWSER, 119 PACKAGE_SYSTEM_TEXT_CLASSIFIER, 120 PACKAGE_PERMISSION_CONTROLLER, 121 PACKAGE_WELLBEING, 122 PACKAGE_DOCUMENTER, 123 PACKAGE_CONFIGURATOR, 124 PACKAGE_INCIDENT_REPORT_APPROVER, 125 PACKAGE_APP_PREDICTOR, 126 PACKAGE_WIFI, 127 PACKAGE_COMPANION, 128 PACKAGE_RETAIL_DEMO, 129 }) 130 @Retention(RetentionPolicy.SOURCE) 131 public @interface KnownPackage {} 132 133 /** Observer called whenever the list of packages changes */ 134 public interface PackageListObserver { 135 /** A package was added to the system. */ onPackageAdded(@onNull String packageName, int uid)136 void onPackageAdded(@NonNull String packageName, int uid); 137 /** A package was changed - either installed for a specific user or updated. */ onPackageChanged(@onNull String packageName, int uid)138 default void onPackageChanged(@NonNull String packageName, int uid) {} 139 /** A package was removed from the system. */ onPackageRemoved(@onNull String packageName, int uid)140 void onPackageRemoved(@NonNull String packageName, int uid); 141 } 142 143 /** 144 * Called when the package for the default SMS handler changed 145 * 146 * @param packageName the new sms package 147 * @param userId user for which the change was made 148 */ onDefaultSmsAppChanged(String packageName, int userId)149 public void onDefaultSmsAppChanged(String packageName, int userId) {} 150 151 /** 152 * Called when the package for the default sim call manager changed 153 * 154 * @param packageName the new sms package 155 * @param userId user for which the change was made 156 */ onDefaultSimCallManagerAppChanged(String packageName, int userId)157 public void onDefaultSimCallManagerAppChanged(String packageName, int userId) {} 158 159 /** 160 * Sets a list of apps to keep in PM's internal data structures and as APKs even if no user has 161 * currently installed it. The apps are not preloaded. 162 * @param packageList List of package names to keep cached. 163 */ setKeepUninstalledPackages(List<String> packageList)164 public abstract void setKeepUninstalledPackages(List<String> packageList); 165 166 /** 167 * Gets whether some of the permissions used by this package require a user 168 * review before any of the app components can run. 169 * @param packageName The package name for which to check. 170 * @param userId The user under which to check. 171 * @return True a permissions review is required. 172 */ isPermissionsReviewRequired(String packageName, int userId)173 public abstract boolean isPermissionsReviewRequired(String packageName, int userId); 174 175 /** 176 * Retrieve all of the information we know about a particular package/application. 177 * @param filterCallingUid The results will be filtered in the context of this UID instead 178 * of the calling UID. 179 * @see PackageManager#getPackageInfo(String, int) 180 */ getPackageInfo(String packageName, @PackageInfoFlags int flags, int filterCallingUid, int userId)181 public abstract PackageInfo getPackageInfo(String packageName, 182 @PackageInfoFlags int flags, int filterCallingUid, int userId); 183 184 /** 185 * Retrieve CE data directory inode number of an application. 186 * Return 0 if there's error. 187 */ getCeDataInode(String packageName, int userId)188 public abstract long getCeDataInode(String packageName, int userId); 189 190 /** 191 * Return a List of all application packages that are installed on the 192 * device, for a specific user. If flag GET_UNINSTALLED_PACKAGES has been 193 * set, a list of all applications including those deleted with 194 * {@code DELETE_KEEP_DATA} (partially installed apps with data directory) 195 * will be returned. 196 * 197 * @param flags Additional option flags to modify the data returned. 198 * @param userId The user for whom the installed applications are to be 199 * listed 200 * @param callingUid The uid of the original caller app 201 * @return A List of ApplicationInfo objects, one for each installed 202 * application. In the unlikely case there are no installed 203 * packages, an empty list is returned. If flag 204 * {@code MATCH_UNINSTALLED_PACKAGES} is set, the application 205 * information is retrieved from the list of uninstalled 206 * applications (which includes installed applications as well as 207 * applications with data directory i.e. applications which had been 208 * deleted with {@code DELETE_KEEP_DATA} flag set). 209 */ getInstalledApplications( @pplicationInfoFlags int flags, @UserIdInt int userId, int callingUid)210 public abstract List<ApplicationInfo> getInstalledApplications( 211 @ApplicationInfoFlags int flags, @UserIdInt int userId, int callingUid); 212 213 /** 214 * Retrieve launcher extras for a suspended package provided to the system in 215 * {@link PackageManager#setPackagesSuspended(String[], boolean, PersistableBundle, 216 * PersistableBundle, String)}. 217 * 218 * @param packageName The package for which to return launcher extras. 219 * @param userId The user for which to check. 220 * @return The launcher extras. 221 * 222 * @see PackageManager#setPackagesSuspended(String[], boolean, PersistableBundle, 223 * PersistableBundle, String) 224 * @see PackageManager#isPackageSuspended() 225 */ getSuspendedPackageLauncherExtras(String packageName, int userId)226 public abstract Bundle getSuspendedPackageLauncherExtras(String packageName, 227 int userId); 228 229 /** 230 * Internal api to query the suspended state of a package. 231 * @param packageName The package to check. 232 * @param userId The user id to check for. 233 * @return {@code true} if the package is suspended, {@code false} otherwise. 234 * @see PackageManager#isPackageSuspended(String) 235 */ isPackageSuspended(String packageName, int userId)236 public abstract boolean isPackageSuspended(String packageName, int userId); 237 238 /** 239 * Removes all package suspensions imposed by any non-system packages. 240 */ removeAllNonSystemPackageSuspensions(int userId)241 public abstract void removeAllNonSystemPackageSuspensions(int userId); 242 243 /** 244 * Removes all suspensions imposed on the given package by non-system packages. 245 */ removeNonSystemPackageSuspensions(String packageName, int userId)246 public abstract void removeNonSystemPackageSuspensions(String packageName, int userId); 247 248 /** 249 * Removes all {@link PackageManager.DistractionRestriction restrictions} set on the given 250 * package 251 */ removeDistractingPackageRestrictions(String packageName, int userId)252 public abstract void removeDistractingPackageRestrictions(String packageName, int userId); 253 254 /** 255 * Removes all {@link PackageManager.DistractionRestriction restrictions} set on all the 256 * packages. 257 */ removeAllDistractingPackageRestrictions(int userId)258 public abstract void removeAllDistractingPackageRestrictions(int userId); 259 260 /** 261 * Flushes package restrictions for the given user immediately to disk. 262 */ 263 @WorkerThread flushPackageRestrictions(int userId)264 public abstract void flushPackageRestrictions(int userId); 265 266 /** 267 * Get the name of the package that suspended the given package. Packages can be suspended by 268 * device administrators or apps holding {@link android.Manifest.permission#MANAGE_USERS} or 269 * {@link android.Manifest.permission#SUSPEND_APPS}. 270 * 271 * @param suspendedPackage The package that has been suspended. 272 * @param userId The user for which to check. 273 * @return Name of the package that suspended the given package. Returns {@code null} if the 274 * given package is not currently suspended and the platform package name - i.e. 275 * {@code "android"} - if the package was suspended by a device admin. 276 */ getSuspendingPackage(String suspendedPackage, int userId)277 public abstract String getSuspendingPackage(String suspendedPackage, int userId); 278 279 /** 280 * Get the information describing the dialog to be shown to the user when they try to launch a 281 * suspended application. 282 * 283 * @param suspendedPackage The package that has been suspended. 284 * @param suspendingPackage 285 * @param userId The user for which to check. 286 * @return A {@link SuspendDialogInfo} object describing the dialog to be shown. 287 */ 288 @Nullable getSuspendedDialogInfo(String suspendedPackage, String suspendingPackage, int userId)289 public abstract SuspendDialogInfo getSuspendedDialogInfo(String suspendedPackage, 290 String suspendingPackage, int userId); 291 292 /** 293 * Gets any distraction flags set via 294 * {@link PackageManager#setDistractingPackageRestrictions(String[], int)} 295 * 296 * @param packageName 297 * @param userId 298 * @return A bitwise OR of any of the {@link PackageManager.DistractionRestriction} 299 */ getDistractingPackageRestrictions( String packageName, int userId)300 public abstract @PackageManager.DistractionRestriction int getDistractingPackageRestrictions( 301 String packageName, int userId); 302 303 /** 304 * Do a straight uid lookup for the given package/application in the given user. This enforces 305 * app visibility rules and permissions. Call {@link #getPackageUidInternal} for the internal 306 * implementation. 307 * @deprecated Use {@link PackageManager#getPackageUid(String, int)} 308 * @return The app's uid, or < 0 if the package was not found in that user 309 */ 310 @Deprecated getPackageUid(String packageName, @PackageInfoFlags int flags, int userId)311 public abstract int getPackageUid(String packageName, 312 @PackageInfoFlags int flags, int userId); 313 314 /** 315 * Do a straight uid lookup for the given package/application in the given user. 316 * @see PackageManager#getPackageUidAsUser(String, int, int) 317 * @return The app's uid, or < 0 if the package was not found in that user 318 * TODO(b/148235092): rename this to getPackageUid 319 */ getPackageUidInternal(String packageName, @PackageInfoFlags int flags, int userId)320 public abstract int getPackageUidInternal(String packageName, 321 @PackageInfoFlags int flags, int userId); 322 323 /** 324 * Retrieve all of the information we know about a particular package/application. 325 * @param filterCallingUid The results will be filtered in the context of this UID instead 326 * of the calling UID. 327 * @see PackageManager#getApplicationInfo(String, int) 328 */ getApplicationInfo(String packageName, @ApplicationInfoFlags int flags, int filterCallingUid, int userId)329 public abstract ApplicationInfo getApplicationInfo(String packageName, 330 @ApplicationInfoFlags int flags, int filterCallingUid, int userId); 331 332 /** 333 * Retrieve all of the information we know about a particular activity class. 334 * @param filterCallingUid The results will be filtered in the context of this UID instead 335 * of the calling UID. 336 * @see PackageManager#getActivityInfo(ComponentName, int) 337 */ getActivityInfo(ComponentName component, @ComponentInfoFlags int flags, int filterCallingUid, int userId)338 public abstract ActivityInfo getActivityInfo(ComponentName component, 339 @ComponentInfoFlags int flags, int filterCallingUid, int userId); 340 341 /** 342 * Retrieve all activities that can be performed for the given intent. 343 * @param resolvedType the resolved type of the intent, which should be resolved via 344 * {@link Intent#resolveTypeIfNeeded(ContentResolver)} before passing to {@link PackageManager} 345 * @param filterCallingUid The results will be filtered in the context of this UID instead 346 * of the calling UID. 347 * @see PackageManager#queryIntentActivities(Intent, int) 348 */ queryIntentActivities( Intent intent, @Nullable String resolvedType, @ResolveInfoFlags int flags, int filterCallingUid, int userId)349 public abstract List<ResolveInfo> queryIntentActivities( 350 Intent intent, @Nullable String resolvedType, @ResolveInfoFlags int flags, 351 int filterCallingUid, int userId); 352 353 354 /** 355 * Retrieve all services that can be performed for the given intent. 356 * @see PackageManager#queryIntentServices(Intent, int) 357 */ queryIntentServices( Intent intent, int flags, int callingUid, int userId)358 public abstract List<ResolveInfo> queryIntentServices( 359 Intent intent, int flags, int callingUid, int userId); 360 361 /** 362 * Interface to {@link com.android.server.pm.PackageManagerService#getHomeActivitiesAsUser}. 363 */ getHomeActivitiesAsUser(List<ResolveInfo> allHomeCandidates, int userId)364 public abstract ComponentName getHomeActivitiesAsUser(List<ResolveInfo> allHomeCandidates, 365 int userId); 366 367 /** 368 * @return The default home activity component name. 369 */ getDefaultHomeActivity(int userId)370 public abstract ComponentName getDefaultHomeActivity(int userId); 371 372 /** 373 * @return The SystemUI service component name. 374 */ getSystemUiServiceComponent()375 public abstract ComponentName getSystemUiServiceComponent(); 376 377 /** 378 * Called by DeviceOwnerManagerService to set the package names of device owner and profile 379 * owners. 380 */ setDeviceAndProfileOwnerPackages( int deviceOwnerUserId, String deviceOwner, SparseArray<String> profileOwners)381 public abstract void setDeviceAndProfileOwnerPackages( 382 int deviceOwnerUserId, String deviceOwner, SparseArray<String> profileOwners); 383 384 /** 385 * Called by DevicePolicyManagerService to set the package names protected by the device 386 * owner. 387 */ setDeviceOwnerProtectedPackages(List<String> packageNames)388 public abstract void setDeviceOwnerProtectedPackages(List<String> packageNames); 389 390 /** 391 * Returns {@code true} if a given package can't be wiped. Otherwise, returns {@code false}. 392 */ isPackageDataProtected(int userId, String packageName)393 public abstract boolean isPackageDataProtected(int userId, String packageName); 394 395 /** 396 * Returns {@code true} if a given package's state is protected, e.g. it cannot be force 397 * stopped, suspended, disabled or hidden. Otherwise, returns {@code false}. 398 */ isPackageStateProtected(String packageName, int userId)399 public abstract boolean isPackageStateProtected(String packageName, int userId); 400 401 /** 402 * Returns {@code true} if a given package is installed as ephemeral. Otherwise, returns 403 * {@code false}. 404 */ isPackageEphemeral(int userId, String packageName)405 public abstract boolean isPackageEphemeral(int userId, String packageName); 406 407 /** 408 * Gets whether the package was ever launched. 409 * @param packageName The package name. 410 * @param userId The user for which to check. 411 * @return Whether was launched. 412 * @throws IllegalArgumentException if the package is not found 413 */ wasPackageEverLaunched(String packageName, int userId)414 public abstract boolean wasPackageEverLaunched(String packageName, int userId); 415 416 /** 417 * Retrieve the official name associated with a uid. This name is 418 * guaranteed to never change, though it is possible for the underlying 419 * uid to be changed. That is, if you are storing information about 420 * uids in persistent storage, you should use the string returned 421 * by this function instead of the raw uid. 422 * 423 * @param uid The uid for which you would like to retrieve a name. 424 * @return Returns a unique name for the given uid, or null if the 425 * uid is not currently assigned. 426 */ getNameForUid(int uid)427 public abstract String getNameForUid(int uid); 428 429 /** 430 * Request to perform the second phase of ephemeral resolution. 431 * @param responseObj The response of the first phase of ephemeral resolution 432 * @param origIntent The original intent that triggered ephemeral resolution 433 * @param resolvedType The resolved type of the intent 434 * @param callingPkg The app requesting the ephemeral application 435 * @param callingFeatureId The feature in the package 436 * @param isRequesterInstantApp Whether or not the app requesting the ephemeral application 437 * is an instant app 438 * @param verificationBundle Optional bundle to pass to the installer for additional 439 * verification 440 * @param userId The ID of the user that triggered ephemeral resolution 441 */ requestInstantAppResolutionPhaseTwo(AuxiliaryResolveInfo responseObj, Intent origIntent, String resolvedType, String callingPkg, @Nullable String callingFeatureId, boolean isRequesterInstantApp, Bundle verificationBundle, int userId)442 public abstract void requestInstantAppResolutionPhaseTwo(AuxiliaryResolveInfo responseObj, 443 Intent origIntent, String resolvedType, String callingPkg, 444 @Nullable String callingFeatureId, boolean isRequesterInstantApp, 445 Bundle verificationBundle, int userId); 446 447 /** 448 * Grants implicit access based on an interaction between two apps. This grants access to the 449 * from one application to the other's package metadata. 450 * <p> 451 * When an application explicitly tries to interact with another application [via an 452 * activity, service or provider that is either declared in the caller's 453 * manifest via the {@code <queries>} tag or has been exposed via the target apps manifest using 454 * the {@code visibleToInstantApp} attribute], the target application must be able to see 455 * metadata about the calling app. If the calling application uses an implicit intent [ie 456 * action VIEW, category BROWSABLE], it remains hidden from the launched app. 457 * <p> 458 * If an interaction is not explicit, the {@code direct} argument should be set to false as 459 * visibility should not be granted in some cases. This method handles that logic. 460 * <p> 461 * @param userId the user 462 * @param intent the intent that triggered the grant 463 * @param recipientAppId The app ID of the application that is being given access to {@code 464 * visibleUid} 465 * @param visibleUid The uid of the application that is becoming accessible to {@code 466 * recipientAppId} 467 * @param direct true if the access is being made due to direct interaction between visibleUid 468 * and recipientAppId. 469 */ grantImplicitAccess( @serIdInt int userId, Intent intent, @AppIdInt int recipientAppId, int visibleUid, boolean direct)470 public abstract void grantImplicitAccess( 471 @UserIdInt int userId, Intent intent, 472 @AppIdInt int recipientAppId, int visibleUid, 473 boolean direct); 474 isInstantAppInstallerComponent(ComponentName component)475 public abstract boolean isInstantAppInstallerComponent(ComponentName component); 476 /** 477 * Prunes instant apps and state associated with uninstalled 478 * instant apps according to the current platform policy. 479 */ pruneInstantApps()480 public abstract void pruneInstantApps(); 481 482 /** 483 * Prunes the cache of the APKs in the given APEXes. 484 * @param apexPackages The list of APEX packages that may contain APK-in-APEX. 485 */ pruneCachedApksInApex(@onNull List<PackageInfo> apexPackages)486 public abstract void pruneCachedApksInApex(@NonNull List<PackageInfo> apexPackages); 487 488 /** 489 * @return The SetupWizard package name. 490 */ getSetupWizardPackageName()491 public abstract String getSetupWizardPackageName(); 492 493 public interface ExternalSourcesPolicy { 494 495 int USER_TRUSTED = 0; // User has trusted the package to install apps 496 int USER_BLOCKED = 1; // User has blocked the package to install apps 497 int USER_DEFAULT = 2; // Default code to use when user response is unavailable 498 499 /** 500 * Checks the user preference for whether a package is trusted to request installs through 501 * package installer 502 * 503 * @param packageName The package to check for 504 * @param uid the uid in which the package is running 505 * @return {@link #USER_TRUSTED} if the user has trusted the package, {@link #USER_BLOCKED} 506 * if user has blocked requests from the package, {@link #USER_DEFAULT} if the user response 507 * is not yet available 508 */ getPackageTrustedToInstallApps(String packageName, int uid)509 int getPackageTrustedToInstallApps(String packageName, int uid); 510 } 511 setExternalSourcesPolicy(ExternalSourcesPolicy policy)512 public abstract void setExternalSourcesPolicy(ExternalSourcesPolicy policy); 513 514 /** 515 * Return true if the given package is a persistent app process. 516 */ isPackagePersistent(String packageName)517 public abstract boolean isPackagePersistent(String packageName); 518 519 /** 520 * Get all overlay packages for a user. 521 * @param userId The user for which to get the overlays. 522 * @return A list of overlay packages. An empty list is returned if the 523 * user has no installed overlay packages. 524 */ getOverlayPackages(int userId)525 public abstract List<PackageInfo> getOverlayPackages(int userId); 526 527 /** 528 * Get the names of all target packages for a user. 529 * @param userId The user for which to get the package names. 530 * @return A list of target package names. This list includes the "android" package. 531 */ getTargetPackageNames(int userId)532 public abstract List<String> getTargetPackageNames(int userId); 533 534 /** 535 * Set which overlay to use for a package. 536 * @param userId The user for which to update the overlays. 537 * @param targetPackageName The package name of the package for which to update the overlays. 538 * @param overlayPackageNames The complete list of overlay packages that should be enabled for 539 * the target. Previously enabled overlays not specified in the list 540 * will be disabled. Pass in null or an empty list to disable 541 * all overlays. The order of the items is significant if several 542 * overlays modify the same resource. 543 * @param outUpdatedPackageNames An output list that contains the package names of packages 544 * affected by the update of enabled overlays. 545 * @return true if all packages names were known by the package manager, false otherwise 546 */ setEnabledOverlayPackages(int userId, String targetPackageName, List<String> overlayPackageNames, Collection<String> outUpdatedPackageNames)547 public abstract boolean setEnabledOverlayPackages(int userId, String targetPackageName, 548 List<String> overlayPackageNames, Collection<String> outUpdatedPackageNames); 549 550 /** 551 * Resolves an activity intent, allowing instant apps to be resolved. 552 */ resolveIntent(Intent intent, String resolvedType, int flags, @PrivateResolveFlags int privateResolveFlags, int userId, boolean resolveForStart, int filterCallingUid)553 public abstract ResolveInfo resolveIntent(Intent intent, String resolvedType, 554 int flags, @PrivateResolveFlags int privateResolveFlags, int userId, 555 boolean resolveForStart, int filterCallingUid); 556 557 /** 558 * Resolves a service intent, allowing instant apps to be resolved. 559 */ resolveService(Intent intent, String resolvedType, int flags, int userId, int callingUid)560 public abstract ResolveInfo resolveService(Intent intent, String resolvedType, 561 int flags, int userId, int callingUid); 562 563 /** 564 * Resolves a content provider intent. 565 */ resolveContentProvider(String name, int flags, int userId)566 public abstract ProviderInfo resolveContentProvider(String name, int flags, int userId); 567 568 /** 569 * Track the creator of a new isolated uid. 570 * @param isolatedUid The newly created isolated uid. 571 * @param ownerUid The uid of the app that created the isolated process. 572 */ addIsolatedUid(int isolatedUid, int ownerUid)573 public abstract void addIsolatedUid(int isolatedUid, int ownerUid); 574 575 /** 576 * Track removal of an isolated uid. 577 * @param isolatedUid isolated uid that is no longer being used. 578 */ removeIsolatedUid(int isolatedUid)579 public abstract void removeIsolatedUid(int isolatedUid); 580 581 /** 582 * Return the taget SDK version for the app with the given UID. 583 */ getUidTargetSdkVersion(int uid)584 public abstract int getUidTargetSdkVersion(int uid); 585 586 /** 587 * Return the taget SDK version for the app with the given package name. 588 */ getPackageTargetSdkVersion(String packageName)589 public abstract int getPackageTargetSdkVersion(String packageName); 590 591 /** Whether the binder caller can access instant apps. */ canAccessInstantApps(int callingUid, int userId)592 public abstract boolean canAccessInstantApps(int callingUid, int userId); 593 594 /** Whether the binder caller can access the given component. */ canAccessComponent(int callingUid, ComponentName component, int userId)595 public abstract boolean canAccessComponent(int callingUid, ComponentName component, int userId); 596 597 /** 598 * Returns {@code true} if a given package has instant application meta-data. 599 * Otherwise, returns {@code false}. Meta-data is state (eg. cookie, app icon, etc) 600 * associated with an instant app. It may be kept after the instant app has been uninstalled. 601 */ hasInstantApplicationMetadata(String packageName, int userId)602 public abstract boolean hasInstantApplicationMetadata(String packageName, int userId); 603 604 /** 605 * Updates a package last used time. 606 */ notifyPackageUse(String packageName, int reason)607 public abstract void notifyPackageUse(String packageName, int reason); 608 609 /** 610 * Returns a package object for the given package name. 611 */ getPackage(@onNull String packageName)612 public abstract @Nullable AndroidPackage getPackage(@NonNull String packageName); 613 getPackageSetting(String packageName)614 public abstract @Nullable PackageSetting getPackageSetting(String packageName); 615 616 /** 617 * Returns a package for the given UID. If the UID is part of a shared user ID, one 618 * of the packages will be chosen to be returned. 619 */ getPackage(int uid)620 public abstract @Nullable AndroidPackage getPackage(int uid); 621 622 /** 623 * Returns a list without a change observer. 624 * 625 * @see #getPackageList(PackageListObserver) 626 */ getPackageList()627 public @NonNull PackageList getPackageList() { 628 return getPackageList(null); 629 } 630 631 /** 632 * Returns the list of packages installed at the time of the method call. 633 * <p>The given observer is notified when the list of installed packages 634 * changes [eg. a package was installed or uninstalled]. It will not be 635 * notified if a package is updated. 636 * <p>The package list will not be updated automatically as packages are 637 * installed / uninstalled. Any changes must be handled within the observer. 638 */ getPackageList(@ullable PackageListObserver observer)639 public abstract @NonNull PackageList getPackageList(@Nullable PackageListObserver observer); 640 641 /** 642 * Removes the observer. 643 * <p>Generally not needed. {@link #getPackageList(PackageListObserver)} will automatically 644 * remove the observer. 645 * <p>Does nothing if the observer isn't currently registered. 646 * <p>Observers are notified asynchronously and it's possible for an observer to be 647 * invoked after its been removed. 648 */ removePackageListObserver(@onNull PackageListObserver observer)649 public abstract void removePackageListObserver(@NonNull PackageListObserver observer); 650 651 /** 652 * Returns a package object for the disabled system package name. 653 */ getDisabledSystemPackage(@onNull String packageName)654 public abstract @Nullable PackageSetting getDisabledSystemPackage(@NonNull String packageName); 655 656 /** 657 * Returns the package name for the disabled system package. 658 * 659 * This is equivalent to 660 * {@link #getDisabledSystemPackage(String)} 661 * .{@link PackageSetting#pkg} 662 * .{@link AndroidPackage#getPackageName()} 663 */ getDisabledSystemPackageName(@onNull String packageName)664 public abstract @Nullable String getDisabledSystemPackageName(@NonNull String packageName); 665 666 /** 667 * Returns whether or not the component is the resolver activity. 668 */ isResolveActivityComponent(@onNull ComponentInfo component)669 public abstract boolean isResolveActivityComponent(@NonNull ComponentInfo component); 670 671 672 /** 673 * Returns a list of package names for a known package 674 */ getKnownPackageNames( @nownPackage int knownPackage, int userId)675 public abstract @NonNull String[] getKnownPackageNames( 676 @KnownPackage int knownPackage, int userId); 677 678 /** 679 * Returns whether the package is an instant app. 680 */ isInstantApp(String packageName, int userId)681 public abstract boolean isInstantApp(String packageName, int userId); 682 683 /** 684 * Returns whether the package is an instant app. 685 */ getInstantAppPackageName(int uid)686 public abstract @Nullable String getInstantAppPackageName(int uid); 687 688 /** 689 * Returns whether or not access to the application should be filtered. 690 * <p> 691 * Access may be limited based upon whether the calling or target applications 692 * are instant applications. 693 * 694 * @see #canAccessInstantApps 695 */ filterAppAccess( @onNull AndroidPackage pkg, int callingUid, int userId)696 public abstract boolean filterAppAccess( 697 @NonNull AndroidPackage pkg, int callingUid, int userId); 698 699 /** 700 * Returns whether or not access to the application should be filtered. 701 * 702 * @see #filterAppAccess(AndroidPackage, int, int) 703 */ filterAppAccess( @onNull String packageName, int callingUid, int userId)704 public abstract boolean filterAppAccess( 705 @NonNull String packageName, int callingUid, int userId); 706 707 /** Returns whether the given package was signed by the platform */ isPlatformSigned(String pkg)708 public abstract boolean isPlatformSigned(String pkg); 709 710 /** 711 * Returns true if it's still safe to restore data backed up from this app's version 712 * that was signed with restoringFromSigHash. 713 */ isDataRestoreSafe(@onNull byte[] restoringFromSigHash, @NonNull String packageName)714 public abstract boolean isDataRestoreSafe(@NonNull byte[] restoringFromSigHash, 715 @NonNull String packageName); 716 717 /** 718 * Returns true if it's still safe to restore data backed up from this app's version 719 * that was signed with restoringFromSig. 720 */ isDataRestoreSafe(@onNull Signature restoringFromSig, @NonNull String packageName)721 public abstract boolean isDataRestoreSafe(@NonNull Signature restoringFromSig, 722 @NonNull String packageName); 723 724 /** 725 * Returns {@code true} if the the signing information for {@code clientUid} is sufficient 726 * to gain access gated by {@code capability}. This can happen if the two UIDs have the 727 * same signing information, if the signing information {@code clientUid} indicates that 728 * it has the signing certificate for {@code serverUid} in its signing history (if it was 729 * previously signed by it), or if the signing certificate for {@code clientUid} is in the 730 * signing history for {@code serverUid} and with the {@code capability} specified. 731 */ hasSignatureCapability(int serverUid, int clientUid, @PackageParser.SigningDetails.CertCapabilities int capability)732 public abstract boolean hasSignatureCapability(int serverUid, int clientUid, 733 @PackageParser.SigningDetails.CertCapabilities int capability); 734 735 /** 736 * Get appIds of all available apps which specified android:sharedUserId in the manifest. 737 * 738 * @return a SparseArray mapping from appId to it's sharedUserId. 739 */ getAppsWithSharedUserIds()740 public abstract SparseArray<String> getAppsWithSharedUserIds(); 741 742 /** 743 * Get all packages which share the same userId as the specified package, or an empty array 744 * if the package does not have a shared userId. 745 */ 746 @NonNull getSharedUserPackagesForPackage(@onNull String packageName, int userId)747 public abstract String[] getSharedUserPackagesForPackage(@NonNull String packageName, 748 int userId); 749 750 /** 751 * Return the processes that have been declared for a uid. 752 * 753 * @param uid The uid to query. 754 * 755 * @return Returns null if there are no declared processes for the uid; otherwise, 756 * returns the set of processes it declared. 757 */ getProcessesForUid(int uid)758 public abstract ArrayMap<String, ProcessInfo> getProcessesForUid(int uid); 759 760 /** 761 * Return the gids associated with a particular permission. 762 * 763 * @param permissionName The name of the permission to query. 764 * @param userId The user id the gids will be associated with. 765 * 766 * @return Returns null if there are no gids associated with the permission, otherwise an 767 * array if the gid ints. 768 */ getPermissionGids(String permissionName, int userId)769 public abstract int[] getPermissionGids(String permissionName, int userId); 770 771 /** 772 * Return if device is currently in a "core" boot environment, typically 773 * used to support full-disk encryption. Only apps marked with 774 * {@code coreApp} attribute are available. 775 */ isOnlyCoreApps()776 public abstract boolean isOnlyCoreApps(); 777 778 /** 779 * Make a best-effort attempt to provide the requested free disk space by 780 * deleting cached files. 781 * 782 * @throws IOException if the request was unable to be fulfilled. 783 */ freeStorage(String volumeUuid, long bytes, int storageFlags)784 public abstract void freeStorage(String volumeUuid, long bytes, int storageFlags) 785 throws IOException; 786 787 /** Returns {@code true} if the specified component is enabled and matches the given flags. */ isEnabledAndMatches(@onNull ParsedMainComponent component, int flags, int userId)788 public abstract boolean isEnabledAndMatches(@NonNull ParsedMainComponent component, int flags, 789 int userId); 790 791 /** Returns {@code true} if the given user requires extra badging for icons. */ userNeedsBadging(int userId)792 public abstract boolean userNeedsBadging(int userId); 793 794 /** 795 * Perform the given action for each package. 796 * Note that packages lock will be held while performing the actions. 797 * 798 * @param actionLocked action to be performed 799 */ forEachPackage(Consumer<AndroidPackage> actionLocked)800 public abstract void forEachPackage(Consumer<AndroidPackage> actionLocked); 801 802 /** 803 * Perform the given action for each {@link PackageSetting}. 804 * Note that packages lock will be held while performing the actions. 805 * 806 * @param actionLocked action to be performed 807 */ forEachPackageSetting(Consumer<PackageSetting> actionLocked)808 public abstract void forEachPackageSetting(Consumer<PackageSetting> actionLocked); 809 810 /** 811 * Perform the given action for each installed package for a user. 812 * Note that packages lock will be held while performin the actions. 813 */ forEachInstalledPackage( @onNull Consumer<AndroidPackage> actionLocked, @UserIdInt int userId)814 public abstract void forEachInstalledPackage( 815 @NonNull Consumer<AndroidPackage> actionLocked, @UserIdInt int userId); 816 817 /** Returns the list of enabled components */ getEnabledComponents(String packageName, int userId)818 public abstract ArraySet<String> getEnabledComponents(String packageName, int userId); 819 820 /** Returns the list of disabled components */ getDisabledComponents(String packageName, int userId)821 public abstract ArraySet<String> getDisabledComponents(String packageName, int userId); 822 823 /** Returns whether the given package is enabled for the given user */ getApplicationEnabledState( String packageName, int userId)824 public abstract @PackageManager.EnabledState int getApplicationEnabledState( 825 String packageName, int userId); 826 827 /** 828 * Extra field name for the token of a request to enable rollback for a 829 * package. 830 */ 831 public static final String EXTRA_ENABLE_ROLLBACK_TOKEN = 832 "android.content.pm.extra.ENABLE_ROLLBACK_TOKEN"; 833 834 /** 835 * Extra field name for the session id of a request to enable rollback 836 * for a package. 837 */ 838 public static final String EXTRA_ENABLE_ROLLBACK_SESSION_ID = 839 "android.content.pm.extra.ENABLE_ROLLBACK_SESSION_ID"; 840 841 /** 842 * Used as the {@code enableRollbackCode} argument for 843 * {@link PackageManagerInternal#setEnableRollbackCode} to indicate that 844 * enabling rollback succeeded. 845 */ 846 public static final int ENABLE_ROLLBACK_SUCCEEDED = 1; 847 848 /** 849 * Used as the {@code enableRollbackCode} argument for 850 * {@link PackageManagerInternal#setEnableRollbackCode} to indicate that 851 * enabling rollback failed. 852 */ 853 public static final int ENABLE_ROLLBACK_FAILED = -1; 854 855 /** 856 * Allows the rollback manager listening to the 857 * {@link Intent#ACTION_PACKAGE_ENABLE_ROLLBACK enable rollback broadcast} 858 * to respond to the package manager. The response must include the 859 * {@code enableRollbackCode} which is one of 860 * {@link PackageManager#ENABLE_ROLLBACK_SUCCEEDED} or 861 * {@link PackageManager#ENABLE_ROLLBACK_FAILED}. 862 * 863 * @param token pending package identifier as passed via the 864 * {@link PackageManager#EXTRA_ENABLE_ROLLBACK_TOKEN} Intent extra. 865 * @param enableRollbackCode the status code result of enabling rollback 866 * @throws SecurityException if the caller does not have the 867 * PACKAGE_ROLLBACK_AGENT permission. 868 */ setEnableRollbackCode(int token, int enableRollbackCode)869 public abstract void setEnableRollbackCode(int token, int enableRollbackCode); 870 871 /** 872 * Ask the package manager to compile layouts in the given package. 873 */ compileLayouts(String packageName)874 public abstract boolean compileLayouts(String packageName); 875 876 /* 877 * Inform the package manager that the pending package install identified by 878 * {@code token} can be completed. 879 */ finishPackageInstall(int token, boolean didLaunch)880 public abstract void finishPackageInstall(int token, boolean didLaunch); 881 882 /** 883 * Remove the default browser stored in the legacy package settings. 884 * 885 * @param userId the user id 886 * 887 * @return the package name of the default browser, or {@code null} if none 888 */ 889 @Nullable removeLegacyDefaultBrowserPackageName(int userId)890 public abstract String removeLegacyDefaultBrowserPackageName(int userId); 891 892 /** 893 * Returns {@code true} if given {@code packageName} is an apex package. 894 */ isApexPackage(String packageName)895 public abstract boolean isApexPackage(String packageName); 896 897 /** 898 * Returns list of {@code packageName} of apks inside the given apex. 899 * @param apexPackageName Package name of the apk container of apex 900 */ getApksInApex(String apexPackageName)901 public abstract List<String> getApksInApex(String apexPackageName); 902 903 /** 904 * Uninstalls given {@code packageName}. 905 * 906 * @param packageName apex package to uninstall. 907 * @param versionCode version of a package to uninstall. 908 * @param userId user to uninstall apex package for. Must be 909 * {@link android.os.UserHandle#USER_ALL}, otherwise failure will be reported. 910 * @param intentSender a {@link IntentSender} to send result of an uninstall to. 911 * @param flags flags about the uninstall. 912 */ uninstallApex(String packageName, long versionCode, int userId, IntentSender intentSender, int flags)913 public abstract void uninstallApex(String packageName, long versionCode, int userId, 914 IntentSender intentSender, int flags); 915 916 /** 917 * Update fingerprint of build that updated the runtime permissions for a user. 918 * 919 * @param userId The user to update 920 */ updateRuntimePermissionsFingerprint(@serIdInt int userId)921 public abstract void updateRuntimePermissionsFingerprint(@UserIdInt int userId); 922 923 /** 924 * Migrates legacy obb data to its new location. 925 */ migrateLegacyObbData()926 public abstract void migrateLegacyObbData(); 927 928 /** 929 * Writes all package manager settings to disk. If {@code async} is {@code true}, the 930 * settings are written at some point in the future. Otherwise, the call blocks until 931 * the settings have been written. 932 */ writeSettings(boolean async)933 public abstract void writeSettings(boolean async); 934 935 /** 936 * Writes all permission settings for the given set of users to disk. If {@code async} 937 * is {@code true}, the settings are written at some point in the future. Otherwise, 938 * the call blocks until the settings have been written. 939 */ writePermissionSettings(@onNull @serIdInt int[] userIds, boolean async)940 public abstract void writePermissionSettings(@NonNull @UserIdInt int[] userIds, boolean async); 941 942 /** 943 * Returns {@code true} if the caller is the installer of record for the given package. 944 * Otherwise, {@code false}. 945 */ isCallerInstallerOfRecord( @onNull AndroidPackage pkg, int callingUid)946 public abstract boolean isCallerInstallerOfRecord( 947 @NonNull AndroidPackage pkg, int callingUid); 948 949 /** Returns whether or not permissions need to be upgraded for the given user */ isPermissionUpgradeNeeded(@serIdInt int userId)950 public abstract boolean isPermissionUpgradeNeeded(@UserIdInt int userId); 951 952 /** Sets the enforcement of reading external storage */ setReadExternalStorageEnforced(boolean enforced)953 public abstract void setReadExternalStorageEnforced(boolean enforced); 954 955 /** 956 * Allows the integrity component to respond to the 957 * {@link Intent#ACTION_PACKAGE_NEEDS_INTEGRITY_VERIFICATION package verification 958 * broadcast} to respond to the package manager. The response must include 959 * the {@code verificationCode} which is one of 960 * {@link #INTEGRITY_VERIFICATION_ALLOW} and {@link #INTEGRITY_VERIFICATION_REJECT}. 961 * 962 * @param verificationId pending package identifier as passed via the 963 * {@link PackageManager#EXTRA_VERIFICATION_ID} Intent extra. 964 * @param verificationResult either {@link #INTEGRITY_VERIFICATION_ALLOW} 965 * or {@link #INTEGRITY_VERIFICATION_REJECT}. 966 */ setIntegrityVerificationResult(int verificationId, @IntegrityVerificationResult int verificationResult)967 public abstract void setIntegrityVerificationResult(int verificationId, 968 @IntegrityVerificationResult int verificationResult); 969 970 /** 971 * Returns MIME types contained in {@code mimeGroup} from {@code packageName} package 972 */ getMimeGroup(String packageName, String mimeGroup)973 public abstract List<String> getMimeGroup(String packageName, String mimeGroup); 974 975 /** 976 * Toggles visibility logging to help in debugging the app enumeration feature. 977 * @param packageName the package name that should begin logging 978 * @param enabled true if visibility blocks should be logged 979 */ setVisibilityLogging(String packageName, boolean enabled)980 public abstract void setVisibilityLogging(String packageName, boolean enabled); 981 982 /** 983 * Returns if a package name is a valid system package. 984 */ isSystemPackage(@onNull String packageName)985 public abstract boolean isSystemPackage(@NonNull String packageName); 986 987 /** 988 * Unblocks uninstall for all packages for the user. 989 */ clearBlockUninstallForUser(@serIdInt int userId)990 public abstract void clearBlockUninstallForUser(@UserIdInt int userId); 991 992 /** 993 * Unsuspends all packages suspended by the given package for the user. 994 */ unsuspendForSuspendingPackage(String suspendingPackage, int userId)995 public abstract void unsuspendForSuspendingPackage(String suspendingPackage, int userId); 996 997 /** 998 * Returns {@code true} if the package is suspending any packages for the user. 999 */ isSuspendingAnyPackages(String suspendingPackage, int userId)1000 public abstract boolean isSuspendingAnyPackages(String suspendingPackage, int userId); 1001 } 1002