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.overlay.OverlayPaths; 34 import android.content.pm.parsing.component.ParsedMainComponent; 35 import android.os.Bundle; 36 import android.os.Handler; 37 import android.os.HandlerExecutor; 38 import android.os.IBinder; 39 import android.os.Looper; 40 import android.os.PersistableBundle; 41 import android.util.ArrayMap; 42 import android.util.ArraySet; 43 import android.util.SparseArray; 44 45 import com.android.internal.util.function.pooled.PooledLambda; 46 import com.android.server.pm.PackageList; 47 import com.android.server.pm.PackageSetting; 48 import com.android.server.pm.parsing.pkg.AndroidPackage; 49 50 import java.io.IOException; 51 import java.lang.annotation.Retention; 52 import java.lang.annotation.RetentionPolicy; 53 import java.util.List; 54 import java.util.Set; 55 import java.util.concurrent.Executor; 56 import java.util.function.Consumer; 57 58 /** 59 * Package manager local system service interface. 60 * 61 * @hide Only for use within the system server. 62 */ 63 public abstract class PackageManagerInternal implements PackageSettingsSnapshotProvider { 64 @IntDef(prefix = "PACKAGE_", value = { 65 PACKAGE_SYSTEM, 66 PACKAGE_SETUP_WIZARD, 67 PACKAGE_INSTALLER, 68 PACKAGE_VERIFIER, 69 PACKAGE_BROWSER, 70 PACKAGE_SYSTEM_TEXT_CLASSIFIER, 71 PACKAGE_PERMISSION_CONTROLLER, 72 PACKAGE_DOCUMENTER, 73 PACKAGE_CONFIGURATOR, 74 PACKAGE_INCIDENT_REPORT_APPROVER, 75 PACKAGE_APP_PREDICTOR, 76 PACKAGE_OVERLAY_CONFIG_SIGNATURE, 77 PACKAGE_WIFI, 78 PACKAGE_COMPANION, 79 PACKAGE_RETAIL_DEMO, 80 PACKAGE_RECENTS, 81 }) 82 @Retention(RetentionPolicy.SOURCE) 83 public @interface KnownPackage {} 84 85 public static final int PACKAGE_SYSTEM = 0; 86 public static final int PACKAGE_SETUP_WIZARD = 1; 87 public static final int PACKAGE_INSTALLER = 2; 88 public static final int PACKAGE_VERIFIER = 3; 89 public static final int PACKAGE_BROWSER = 4; 90 public static final int PACKAGE_SYSTEM_TEXT_CLASSIFIER = 5; 91 public static final int PACKAGE_PERMISSION_CONTROLLER = 6; 92 public static final int PACKAGE_WELLBEING = 7; 93 public static final int PACKAGE_DOCUMENTER = 8; 94 public static final int PACKAGE_CONFIGURATOR = 9; 95 public static final int PACKAGE_INCIDENT_REPORT_APPROVER = 10; 96 public static final int PACKAGE_APP_PREDICTOR = 11; 97 public static final int PACKAGE_OVERLAY_CONFIG_SIGNATURE = 12; 98 public static final int PACKAGE_WIFI = 13; 99 public static final int PACKAGE_COMPANION = 14; 100 public static final int PACKAGE_RETAIL_DEMO = 15; 101 public static final int PACKAGE_RECENTS = 16; 102 // Integer value of the last known package ID. Increases as new ID is added to KnownPackage. 103 // Please note the numbers should be continuous. 104 public static final int LAST_KNOWN_PACKAGE = PACKAGE_RECENTS; 105 106 @IntDef(flag = true, prefix = "RESOLVE_", value = { 107 RESOLVE_NON_BROWSER_ONLY, 108 RESOLVE_NON_RESOLVER_ONLY 109 }) 110 @Retention(RetentionPolicy.SOURCE) 111 public @interface PrivateResolveFlags {} 112 113 /** 114 * Internal {@link #resolveIntent(Intent, String, int, int, int, boolean, int)} flag: 115 * only match components that contain a generic web intent filter. 116 */ 117 public static final int RESOLVE_NON_BROWSER_ONLY = 0x00000001; 118 119 /** 120 * Internal {@link #resolveIntent(Intent, String, int, int, int, boolean, int)} flag: do not 121 * match to the resolver. 122 */ 123 public static final int RESOLVE_NON_RESOLVER_ONLY = 0x00000002; 124 125 @IntDef(value = { 126 INTEGRITY_VERIFICATION_ALLOW, 127 INTEGRITY_VERIFICATION_REJECT, 128 }) 129 @Retention(RetentionPolicy.SOURCE) 130 public @interface IntegrityVerificationResult {} 131 132 /** 133 * Used as the {@code verificationCode} argument for 134 * {@link PackageManagerInternal#setIntegrityVerificationResult(int, int)} to indicate that the 135 * integrity component allows the install to proceed. 136 */ 137 public static final int INTEGRITY_VERIFICATION_ALLOW = 1; 138 139 /** 140 * Used as the {@code verificationCode} argument for 141 * {@link PackageManagerInternal#setIntegrityVerificationResult(int, int)} to indicate that the 142 * integrity component does not allow install to proceed. 143 */ 144 public static final int INTEGRITY_VERIFICATION_REJECT = 0; 145 146 /** Observer called whenever the list of packages changes */ 147 public interface PackageListObserver { 148 /** A package was added to the system. */ onPackageAdded(@onNull String packageName, int uid)149 void onPackageAdded(@NonNull String packageName, int uid); 150 /** A package was changed - either installed for a specific user or updated. */ onPackageChanged(@onNull String packageName, int uid)151 default void onPackageChanged(@NonNull String packageName, int uid) {} 152 /** A package was removed from the system. */ onPackageRemoved(@onNull String packageName, int uid)153 void onPackageRemoved(@NonNull String packageName, int uid); 154 } 155 156 /** 157 * Called when the package for the default SMS handler changed 158 * 159 * @param packageName the new sms package 160 * @param userId user for which the change was made 161 */ onDefaultSmsAppChanged(String packageName, int userId)162 public void onDefaultSmsAppChanged(String packageName, int userId) {} 163 164 /** 165 * Called when the package for the default sim call manager changed 166 * 167 * @param packageName the new sms package 168 * @param userId user for which the change was made 169 */ onDefaultSimCallManagerAppChanged(String packageName, int userId)170 public void onDefaultSimCallManagerAppChanged(String packageName, int userId) {} 171 172 /** 173 * Sets a list of apps to keep in PM's internal data structures and as APKs even if no user has 174 * currently installed it. The apps are not preloaded. 175 * @param packageList List of package names to keep cached. 176 */ setKeepUninstalledPackages(List<String> packageList)177 public abstract void setKeepUninstalledPackages(List<String> packageList); 178 179 /** 180 * Gets whether some of the permissions used by this package require a user 181 * review before any of the app components can run. 182 * @param packageName The package name for which to check. 183 * @param userId The user under which to check. 184 * @return True a permissions review is required. 185 */ isPermissionsReviewRequired(String packageName, int userId)186 public abstract boolean isPermissionsReviewRequired(String packageName, int userId); 187 188 /** 189 * Retrieve all of the information we know about a particular package/application. 190 * @param filterCallingUid The results will be filtered in the context of this UID instead 191 * of the calling UID. 192 * @see PackageManager#getPackageInfo(String, int) 193 */ getPackageInfo(String packageName, @PackageInfoFlags int flags, int filterCallingUid, int userId)194 public abstract PackageInfo getPackageInfo(String packageName, 195 @PackageInfoFlags int flags, int filterCallingUid, int userId); 196 197 /** 198 * Retrieve CE data directory inode number of an application. 199 * Return 0 if there's error. 200 */ getCeDataInode(String packageName, int userId)201 public abstract long getCeDataInode(String packageName, int userId); 202 203 /** 204 * Return a List of all application packages that are installed on the 205 * device, for a specific user. If flag GET_UNINSTALLED_PACKAGES has been 206 * set, a list of all applications including those deleted with 207 * {@code DELETE_KEEP_DATA} (partially installed apps with data directory) 208 * will be returned. 209 * 210 * @param flags Additional option flags to modify the data returned. 211 * @param userId The user for whom the installed applications are to be 212 * listed 213 * @param callingUid The uid of the original caller app 214 * @return A List of ApplicationInfo objects, one for each installed 215 * application. In the unlikely case there are no installed 216 * packages, an empty list is returned. If flag 217 * {@code MATCH_UNINSTALLED_PACKAGES} is set, the application 218 * information is retrieved from the list of uninstalled 219 * applications (which includes installed applications as well as 220 * applications with data directory i.e. applications which had been 221 * deleted with {@code DELETE_KEEP_DATA} flag set). 222 */ getInstalledApplications( @pplicationInfoFlags int flags, @UserIdInt int userId, int callingUid)223 public abstract List<ApplicationInfo> getInstalledApplications( 224 @ApplicationInfoFlags int flags, @UserIdInt int userId, int callingUid); 225 226 /** 227 * Retrieve launcher extras for a suspended package provided to the system in 228 * {@link PackageManager#setPackagesSuspended(String[], boolean, PersistableBundle, 229 * PersistableBundle, String)}. 230 * 231 * @param packageName The package for which to return launcher extras. 232 * @param userId The user for which to check. 233 * @return The launcher extras. 234 * 235 * @see PackageManager#setPackagesSuspended(String[], boolean, PersistableBundle, 236 * PersistableBundle, String) 237 * @see PackageManager#isPackageSuspended() 238 */ getSuspendedPackageLauncherExtras(String packageName, int userId)239 public abstract Bundle getSuspendedPackageLauncherExtras(String packageName, 240 int userId); 241 242 /** 243 * Internal api to query the suspended state of a package. 244 * @param packageName The package to check. 245 * @param userId The user id to check for. 246 * @return {@code true} if the package is suspended, {@code false} otherwise. 247 * @see PackageManager#isPackageSuspended(String) 248 */ isPackageSuspended(String packageName, int userId)249 public abstract boolean isPackageSuspended(String packageName, int userId); 250 251 /** 252 * Removes all package suspensions imposed by any non-system packages. 253 */ removeAllNonSystemPackageSuspensions(int userId)254 public abstract void removeAllNonSystemPackageSuspensions(int userId); 255 256 /** 257 * Removes all suspensions imposed on the given package by non-system packages. 258 */ removeNonSystemPackageSuspensions(String packageName, int userId)259 public abstract void removeNonSystemPackageSuspensions(String packageName, int userId); 260 261 /** 262 * Removes all {@link PackageManager.DistractionRestriction restrictions} set on the given 263 * package 264 */ removeDistractingPackageRestrictions(String packageName, int userId)265 public abstract void removeDistractingPackageRestrictions(String packageName, int userId); 266 267 /** 268 * Removes all {@link PackageManager.DistractionRestriction restrictions} set on all the 269 * packages. 270 */ removeAllDistractingPackageRestrictions(int userId)271 public abstract void removeAllDistractingPackageRestrictions(int userId); 272 273 /** 274 * Flushes package restrictions for the given user immediately to disk. 275 */ 276 @WorkerThread flushPackageRestrictions(int userId)277 public abstract void flushPackageRestrictions(int userId); 278 279 /** 280 * Get the name of the package that suspended the given package. Packages can be suspended by 281 * device administrators or apps holding {@link android.Manifest.permission#MANAGE_USERS} or 282 * {@link android.Manifest.permission#SUSPEND_APPS}. 283 * 284 * @param suspendedPackage The package that has been suspended. 285 * @param userId The user for which to check. 286 * @return Name of the package that suspended the given package. Returns {@code null} if the 287 * given package is not currently suspended and the platform package name - i.e. 288 * {@code "android"} - if the package was suspended by a device admin. 289 */ getSuspendingPackage(String suspendedPackage, int userId)290 public abstract String getSuspendingPackage(String suspendedPackage, int userId); 291 292 /** 293 * Get the information describing the dialog to be shown to the user when they try to launch a 294 * suspended application. 295 * 296 * @param suspendedPackage The package that has been suspended. 297 * @param suspendingPackage 298 * @param userId The user for which to check. 299 * @return A {@link SuspendDialogInfo} object describing the dialog to be shown. 300 */ 301 @Nullable getSuspendedDialogInfo(String suspendedPackage, String suspendingPackage, int userId)302 public abstract SuspendDialogInfo getSuspendedDialogInfo(String suspendedPackage, 303 String suspendingPackage, int userId); 304 305 /** 306 * Gets any distraction flags set via 307 * {@link PackageManager#setDistractingPackageRestrictions(String[], int)} 308 * 309 * @param packageName 310 * @param userId 311 * @return A bitwise OR of any of the {@link PackageManager.DistractionRestriction} 312 */ getDistractingPackageRestrictions( String packageName, int userId)313 public abstract @PackageManager.DistractionRestriction int getDistractingPackageRestrictions( 314 String packageName, int userId); 315 316 /** 317 * Do a straight uid lookup for the given package/application in the given user. 318 * @see PackageManager#getPackageUidAsUser(String, int, int) 319 * @return The app's uid, or < 0 if the package was not found in that user 320 */ getPackageUid(String packageName, @PackageInfoFlags int flags, int userId)321 public abstract int getPackageUid(String packageName, @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 Owners to set the package names protected by the device owner. 386 */ setDeviceOwnerProtectedPackages( String deviceOwnerPackageName, List<String> packageNames)387 public abstract void setDeviceOwnerProtectedPackages( 388 String deviceOwnerPackageName, 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 overlayPaths The complete list of overlay paths that should be enabled for 539 * the target. Previously enabled overlays not specified in the list 540 * will be disabled. Pass in null or empty paths to disable all overlays. 541 * The order of the items is significant if several overlays modify the 542 * 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, @Nullable OverlayPaths overlayPaths, Set<String> outUpdatedPackageNames)547 public abstract boolean setEnabledOverlayPackages(int userId, String targetPackageName, 548 @Nullable OverlayPaths overlayPaths, Set<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 * Resolves a content provider intent. 570 */ resolveContentProvider(String name, int flags, int userId, int callingUid)571 public abstract ProviderInfo resolveContentProvider(String name, int flags, int userId, 572 int callingUid); 573 574 /** 575 * Track the creator of a new isolated uid. 576 * @param isolatedUid The newly created isolated uid. 577 * @param ownerUid The uid of the app that created the isolated process. 578 */ addIsolatedUid(int isolatedUid, int ownerUid)579 public abstract void addIsolatedUid(int isolatedUid, int ownerUid); 580 581 /** 582 * Track removal of an isolated uid. 583 * @param isolatedUid isolated uid that is no longer being used. 584 */ removeIsolatedUid(int isolatedUid)585 public abstract void removeIsolatedUid(int isolatedUid); 586 587 /** 588 * Return the taget SDK version for the app with the given UID. 589 */ getUidTargetSdkVersion(int uid)590 public abstract int getUidTargetSdkVersion(int uid); 591 592 /** 593 * Return the taget SDK version for the app with the given package name. 594 */ getPackageTargetSdkVersion(String packageName)595 public abstract int getPackageTargetSdkVersion(String packageName); 596 597 /** Whether the binder caller can access instant apps. */ canAccessInstantApps(int callingUid, int userId)598 public abstract boolean canAccessInstantApps(int callingUid, int userId); 599 600 /** Whether the binder caller can access the given component. */ canAccessComponent(int callingUid, ComponentName component, int userId)601 public abstract boolean canAccessComponent(int callingUid, ComponentName component, int userId); 602 603 /** 604 * Returns {@code true} if a given package has instant application meta-data. 605 * Otherwise, returns {@code false}. Meta-data is state (eg. cookie, app icon, etc) 606 * associated with an instant app. It may be kept after the instant app has been uninstalled. 607 */ hasInstantApplicationMetadata(String packageName, int userId)608 public abstract boolean hasInstantApplicationMetadata(String packageName, int userId); 609 610 /** 611 * Updates a package last used time. 612 */ notifyPackageUse(String packageName, int reason)613 public abstract void notifyPackageUse(String packageName, int reason); 614 615 /** 616 * Returns a package object for the given package name. 617 */ getPackage(@onNull String packageName)618 public abstract @Nullable AndroidPackage getPackage(@NonNull String packageName); 619 getPackageSetting(String packageName)620 public abstract @Nullable PackageSetting getPackageSetting(String packageName); 621 622 /** 623 * Returns a package for the given UID. If the UID is part of a shared user ID, one 624 * of the packages will be chosen to be returned. 625 */ getPackage(int uid)626 public abstract @Nullable AndroidPackage getPackage(int uid); 627 628 /** 629 * Returns a list without a change observer. 630 * 631 * @see #getPackageList(PackageListObserver) 632 */ getPackageList()633 public @NonNull PackageList getPackageList() { 634 return getPackageList(null); 635 } 636 637 /** 638 * Returns the list of packages installed at the time of the method call. 639 * <p>The given observer is notified when the list of installed packages 640 * changes [eg. a package was installed or uninstalled]. It will not be 641 * notified if a package is updated. 642 * <p>The package list will not be updated automatically as packages are 643 * installed / uninstalled. Any changes must be handled within the observer. 644 */ getPackageList(@ullable PackageListObserver observer)645 public abstract @NonNull PackageList getPackageList(@Nullable PackageListObserver observer); 646 647 /** 648 * Removes the observer. 649 * <p>Generally not needed. {@link #getPackageList(PackageListObserver)} will automatically 650 * remove the observer. 651 * <p>Does nothing if the observer isn't currently registered. 652 * <p>Observers are notified asynchronously and it's possible for an observer to be 653 * invoked after its been removed. 654 */ removePackageListObserver(@onNull PackageListObserver observer)655 public abstract void removePackageListObserver(@NonNull PackageListObserver observer); 656 657 /** 658 * Returns a package object for the disabled system package name. 659 */ getDisabledSystemPackage(@onNull String packageName)660 public abstract @Nullable PackageSetting getDisabledSystemPackage(@NonNull String packageName); 661 662 /** 663 * Returns the package name for the disabled system package. 664 * 665 * This is equivalent to 666 * {@link #getDisabledSystemPackage(String)} 667 * .{@link PackageSetting#pkg} 668 * .{@link AndroidPackage#getPackageName()} 669 */ getDisabledSystemPackageName(@onNull String packageName)670 public abstract @Nullable String getDisabledSystemPackageName(@NonNull String packageName); 671 672 /** 673 * Returns whether or not the component is the resolver activity. 674 */ isResolveActivityComponent(@onNull ComponentInfo component)675 public abstract boolean isResolveActivityComponent(@NonNull ComponentInfo component); 676 677 678 /** 679 * Returns a list of package names for a known package 680 */ getKnownPackageNames( @nownPackage int knownPackage, int userId)681 public abstract @NonNull String[] getKnownPackageNames( 682 @KnownPackage int knownPackage, int userId); 683 684 /** 685 * Returns whether the package is an instant app. 686 */ isInstantApp(String packageName, int userId)687 public abstract boolean isInstantApp(String packageName, int userId); 688 689 /** 690 * Returns whether the package is an instant app. 691 */ getInstantAppPackageName(int uid)692 public abstract @Nullable String getInstantAppPackageName(int uid); 693 694 /** 695 * Returns whether or not access to the application should be filtered. 696 * <p> 697 * Access may be limited based upon whether the calling or target applications 698 * are instant applications. 699 * 700 * @see #canAccessInstantApps 701 */ filterAppAccess( @onNull AndroidPackage pkg, int callingUid, int userId)702 public abstract boolean filterAppAccess( 703 @NonNull AndroidPackage pkg, int callingUid, int userId); 704 705 /** 706 * Returns whether or not access to the application should be filtered. 707 * 708 * @see #filterAppAccess(AndroidPackage, int, int) 709 */ filterAppAccess( @onNull String packageName, int callingUid, int userId)710 public abstract boolean filterAppAccess( 711 @NonNull String packageName, int callingUid, int userId); 712 713 /** Returns whether the given package was signed by the platform */ isPlatformSigned(String pkg)714 public abstract boolean isPlatformSigned(String pkg); 715 716 /** 717 * Returns true if it's still safe to restore data backed up from this app's version 718 * that was signed with restoringFromSigHash. 719 */ isDataRestoreSafe(@onNull byte[] restoringFromSigHash, @NonNull String packageName)720 public abstract boolean isDataRestoreSafe(@NonNull byte[] restoringFromSigHash, 721 @NonNull String packageName); 722 723 /** 724 * Returns true if it's still safe to restore data backed up from this app's version 725 * that was signed with restoringFromSig. 726 */ isDataRestoreSafe(@onNull Signature restoringFromSig, @NonNull String packageName)727 public abstract boolean isDataRestoreSafe(@NonNull Signature restoringFromSig, 728 @NonNull String packageName); 729 730 /** 731 * Returns {@code true} if the the signing information for {@code clientUid} is sufficient 732 * to gain access gated by {@code capability}. This can happen if the two UIDs have the 733 * same signing information, if the signing information {@code clientUid} indicates that 734 * it has the signing certificate for {@code serverUid} in its signing history (if it was 735 * previously signed by it), or if the signing certificate for {@code clientUid} is in the 736 * signing history for {@code serverUid} and with the {@code capability} specified. 737 */ hasSignatureCapability(int serverUid, int clientUid, @PackageParser.SigningDetails.CertCapabilities int capability)738 public abstract boolean hasSignatureCapability(int serverUid, int clientUid, 739 @PackageParser.SigningDetails.CertCapabilities int capability); 740 741 /** 742 * Get appIds of all available apps which specified android:sharedUserId in the manifest. 743 * 744 * @return a SparseArray mapping from appId to it's sharedUserId. 745 */ getAppsWithSharedUserIds()746 public abstract SparseArray<String> getAppsWithSharedUserIds(); 747 748 /** 749 * Get all packages which share the same userId as the specified package, or an empty array 750 * if the package does not have a shared userId. 751 */ 752 @NonNull getSharedUserPackagesForPackage(@onNull String packageName, int userId)753 public abstract String[] getSharedUserPackagesForPackage(@NonNull String packageName, 754 int userId); 755 756 /** 757 * Return the processes that have been declared for a uid. 758 * 759 * @param uid The uid to query. 760 * 761 * @return Returns null if there are no declared processes for the uid; otherwise, 762 * returns the set of processes it declared. 763 */ getProcessesForUid(int uid)764 public abstract ArrayMap<String, ProcessInfo> getProcessesForUid(int uid); 765 766 /** 767 * Return the gids associated with a particular permission. 768 * 769 * @param permissionName The name of the permission to query. 770 * @param userId The user id the gids will be associated with. 771 * 772 * @return Returns null if there are no gids associated with the permission, otherwise an 773 * array if the gid ints. 774 */ getPermissionGids(String permissionName, int userId)775 public abstract int[] getPermissionGids(String permissionName, int userId); 776 777 /** 778 * Return if device is currently in a "core" boot environment, typically 779 * used to support full-disk encryption. Only apps marked with 780 * {@code coreApp} attribute are available. 781 */ isOnlyCoreApps()782 public abstract boolean isOnlyCoreApps(); 783 784 /** 785 * Make a best-effort attempt to provide the requested free disk space by 786 * deleting cached files. 787 * 788 * @throws IOException if the request was unable to be fulfilled. 789 */ freeStorage(String volumeUuid, long bytes, int storageFlags)790 public abstract void freeStorage(String volumeUuid, long bytes, int storageFlags) 791 throws IOException; 792 793 /** Returns {@code true} if the specified component is enabled and matches the given flags. */ isEnabledAndMatches(@onNull ParsedMainComponent component, int flags, int userId)794 public abstract boolean isEnabledAndMatches(@NonNull ParsedMainComponent component, int flags, 795 int userId); 796 797 /** Returns {@code true} if the given user requires extra badging for icons. */ userNeedsBadging(int userId)798 public abstract boolean userNeedsBadging(int userId); 799 800 /** 801 * Perform the given action for each package. 802 * Note that packages lock will be held while performing the actions. 803 * 804 * If the caller does not need all packages, prefer the potentially non-locking 805 * {@link #withPackageSettingsSnapshot(Consumer)}. 806 * 807 * @param actionLocked action to be performed 808 */ forEachPackage(Consumer<AndroidPackage> actionLocked)809 public abstract void forEachPackage(Consumer<AndroidPackage> actionLocked); 810 811 /** 812 * Perform the given action for each {@link PackageSetting}. 813 * Note that packages lock will be held while performing the actions. 814 * 815 * If the caller does not need all packages, prefer the potentially non-locking 816 * {@link #withPackageSettingsSnapshot(Consumer)}. 817 * 818 * @param actionLocked action to be performed 819 */ forEachPackageSetting(Consumer<PackageSetting> actionLocked)820 public abstract void forEachPackageSetting(Consumer<PackageSetting> actionLocked); 821 822 /** 823 * Perform the given action for each installed package for a user. 824 * Note that packages lock will be held while performin the actions. 825 */ forEachInstalledPackage( @onNull Consumer<AndroidPackage> actionLocked, @UserIdInt int userId)826 public abstract void forEachInstalledPackage( 827 @NonNull Consumer<AndroidPackage> actionLocked, @UserIdInt int userId); 828 829 /** Returns the list of enabled components */ getEnabledComponents(String packageName, int userId)830 public abstract ArraySet<String> getEnabledComponents(String packageName, int userId); 831 832 /** Returns the list of disabled components */ getDisabledComponents(String packageName, int userId)833 public abstract ArraySet<String> getDisabledComponents(String packageName, int userId); 834 835 /** Returns whether the given package is enabled for the given user */ getApplicationEnabledState( String packageName, int userId)836 public abstract @PackageManager.EnabledState int getApplicationEnabledState( 837 String packageName, int userId); 838 839 /** 840 * Return the enabled setting for a package component (activity, receiver, service, provider). 841 */ getComponentEnabledSetting( @onNull ComponentName componentName, int callingUid, int userId)842 public abstract @PackageManager.EnabledState int getComponentEnabledSetting( 843 @NonNull ComponentName componentName, int callingUid, int userId); 844 845 /** 846 * Extra field name for the token of a request to enable rollback for a 847 * package. 848 */ 849 public static final String EXTRA_ENABLE_ROLLBACK_TOKEN = 850 "android.content.pm.extra.ENABLE_ROLLBACK_TOKEN"; 851 852 /** 853 * Extra field name for the session id of a request to enable rollback 854 * for a package. 855 */ 856 public static final String EXTRA_ENABLE_ROLLBACK_SESSION_ID = 857 "android.content.pm.extra.ENABLE_ROLLBACK_SESSION_ID"; 858 859 /** 860 * Used as the {@code enableRollbackCode} argument for 861 * {@link PackageManagerInternal#setEnableRollbackCode} to indicate that 862 * enabling rollback succeeded. 863 */ 864 public static final int ENABLE_ROLLBACK_SUCCEEDED = 1; 865 866 /** 867 * Used as the {@code enableRollbackCode} argument for 868 * {@link PackageManagerInternal#setEnableRollbackCode} to indicate that 869 * enabling rollback failed. 870 */ 871 public static final int ENABLE_ROLLBACK_FAILED = -1; 872 873 /** 874 * Allows the rollback manager listening to the 875 * {@link Intent#ACTION_PACKAGE_ENABLE_ROLLBACK enable rollback broadcast} 876 * to respond to the package manager. The response must include the 877 * {@code enableRollbackCode} which is one of 878 * {@link PackageManager#ENABLE_ROLLBACK_SUCCEEDED} or 879 * {@link PackageManager#ENABLE_ROLLBACK_FAILED}. 880 * 881 * @param token pending package identifier as passed via the 882 * {@link PackageManager#EXTRA_ENABLE_ROLLBACK_TOKEN} Intent extra. 883 * @param enableRollbackCode the status code result of enabling rollback 884 * @throws SecurityException if the caller does not have the 885 * PACKAGE_ROLLBACK_AGENT permission. 886 */ setEnableRollbackCode(int token, int enableRollbackCode)887 public abstract void setEnableRollbackCode(int token, int enableRollbackCode); 888 889 /** 890 * Ask the package manager to compile layouts in the given package. 891 */ compileLayouts(String packageName)892 public abstract boolean compileLayouts(String packageName); 893 894 /* 895 * Inform the package manager that the pending package install identified by 896 * {@code token} can be completed. 897 */ finishPackageInstall(int token, boolean didLaunch)898 public abstract void finishPackageInstall(int token, boolean didLaunch); 899 900 /** 901 * Remove the default browser stored in the legacy package settings. 902 * 903 * @param userId the user id 904 * 905 * @return the package name of the default browser, or {@code null} if none 906 */ 907 @Nullable removeLegacyDefaultBrowserPackageName(int userId)908 public abstract String removeLegacyDefaultBrowserPackageName(int userId); 909 910 /** 911 * Returns {@code true} if given {@code packageName} is an apex package. 912 */ isApexPackage(String packageName)913 public abstract boolean isApexPackage(String packageName); 914 915 /** 916 * Returns list of {@code packageName} of apks inside the given apex. 917 * @param apexPackageName Package name of the apk container of apex 918 */ getApksInApex(String apexPackageName)919 public abstract List<String> getApksInApex(String apexPackageName); 920 921 /** 922 * Uninstalls given {@code packageName}. 923 * 924 * @param packageName apex package to uninstall. 925 * @param versionCode version of a package to uninstall. 926 * @param userId user to uninstall apex package for. Must be 927 * {@link android.os.UserHandle#USER_ALL}, otherwise failure will be reported. 928 * @param intentSender a {@link IntentSender} to send result of an uninstall to. 929 * @param flags flags about the uninstall. 930 */ uninstallApex(String packageName, long versionCode, int userId, IntentSender intentSender, int flags)931 public abstract void uninstallApex(String packageName, long versionCode, int userId, 932 IntentSender intentSender, int flags); 933 934 /** 935 * Update fingerprint of build that updated the runtime permissions for a user. 936 * 937 * @param userId The user to update 938 */ updateRuntimePermissionsFingerprint(@serIdInt int userId)939 public abstract void updateRuntimePermissionsFingerprint(@UserIdInt int userId); 940 941 /** 942 * Migrates legacy obb data to its new location. 943 */ migrateLegacyObbData()944 public abstract void migrateLegacyObbData(); 945 946 /** 947 * Writes all package manager settings to disk. If {@code async} is {@code true}, the 948 * settings are written at some point in the future. Otherwise, the call blocks until 949 * the settings have been written. 950 */ writeSettings(boolean async)951 public abstract void writeSettings(boolean async); 952 953 /** 954 * Writes all permission settings for the given set of users to disk. If {@code async} 955 * is {@code true}, the settings are written at some point in the future. Otherwise, 956 * the call blocks until the settings have been written. 957 */ writePermissionSettings(@onNull @serIdInt int[] userIds, boolean async)958 public abstract void writePermissionSettings(@NonNull @UserIdInt int[] userIds, boolean async); 959 960 /** 961 * Returns {@code true} if the caller is the installer of record for the given package. 962 * Otherwise, {@code false}. 963 */ isCallerInstallerOfRecord( @onNull AndroidPackage pkg, int callingUid)964 public abstract boolean isCallerInstallerOfRecord( 965 @NonNull AndroidPackage pkg, int callingUid); 966 967 /** Returns whether or not permissions need to be upgraded for the given user */ isPermissionUpgradeNeeded(@serIdInt int userId)968 public abstract boolean isPermissionUpgradeNeeded(@UserIdInt int userId); 969 970 /** 971 * Allows the integrity component to respond to the 972 * {@link Intent#ACTION_PACKAGE_NEEDS_INTEGRITY_VERIFICATION package verification 973 * broadcast} to respond to the package manager. The response must include 974 * the {@code verificationCode} which is one of 975 * {@link #INTEGRITY_VERIFICATION_ALLOW} and {@link #INTEGRITY_VERIFICATION_REJECT}. 976 * 977 * @param verificationId pending package identifier as passed via the 978 * {@link PackageManager#EXTRA_VERIFICATION_ID} Intent extra. 979 * @param verificationResult either {@link #INTEGRITY_VERIFICATION_ALLOW} 980 * or {@link #INTEGRITY_VERIFICATION_REJECT}. 981 */ setIntegrityVerificationResult(int verificationId, @IntegrityVerificationResult int verificationResult)982 public abstract void setIntegrityVerificationResult(int verificationId, 983 @IntegrityVerificationResult int verificationResult); 984 985 /** 986 * Returns MIME types contained in {@code mimeGroup} from {@code packageName} package 987 */ getMimeGroup(String packageName, String mimeGroup)988 public abstract List<String> getMimeGroup(String packageName, String mimeGroup); 989 990 /** 991 * Toggles visibility logging to help in debugging the app enumeration feature. 992 * @param packageName the package name that should begin logging 993 * @param enabled true if visibility blocks should be logged 994 */ setVisibilityLogging(String packageName, boolean enabled)995 public abstract void setVisibilityLogging(String packageName, boolean enabled); 996 997 /** 998 * Returns if a package name is a valid system package. 999 */ isSystemPackage(@onNull String packageName)1000 public abstract boolean isSystemPackage(@NonNull String packageName); 1001 1002 /** 1003 * Unblocks uninstall for all packages for the user. 1004 */ clearBlockUninstallForUser(@serIdInt int userId)1005 public abstract void clearBlockUninstallForUser(@UserIdInt int userId); 1006 1007 /** 1008 * Unsuspends all packages suspended by the given package for the user. 1009 */ unsuspendForSuspendingPackage(String suspendingPackage, int userId)1010 public abstract void unsuspendForSuspendingPackage(String suspendingPackage, int userId); 1011 1012 /** 1013 * Returns {@code true} if the package is suspending any packages for the user. 1014 */ isSuspendingAnyPackages(String suspendingPackage, int userId)1015 public abstract boolean isSuspendingAnyPackages(String suspendingPackage, int userId); 1016 1017 /** 1018 * Register to listen for loading progress of an installed package. 1019 * The listener is automatically unregistered when the app is fully loaded. 1020 * @param packageName The name of the installed package 1021 * @param callback To loading reporting progress 1022 * @param userId The user under which to check. 1023 * @return Whether the registration was successful. It can fail if the package has not been 1024 * installed yet. 1025 */ registerInstalledLoadingProgressCallback(@onNull String packageName, @NonNull InstalledLoadingProgressCallback callback, int userId)1026 public abstract boolean registerInstalledLoadingProgressCallback(@NonNull String packageName, 1027 @NonNull InstalledLoadingProgressCallback callback, int userId); 1028 1029 /** 1030 * Returns the string representation of a known package. For example, 1031 * {@link #PACKAGE_SETUP_WIZARD} is represented by the string Setup Wizard. 1032 * 1033 * @param knownPackage The known package. 1034 * @return The string representation. 1035 */ knownPackageToString(@nownPackage int knownPackage)1036 public static @NonNull String knownPackageToString(@KnownPackage int knownPackage) { 1037 switch (knownPackage) { 1038 case PACKAGE_SYSTEM: 1039 return "System"; 1040 case PACKAGE_SETUP_WIZARD: 1041 return "Setup Wizard"; 1042 case PACKAGE_INSTALLER: 1043 return "Installer"; 1044 case PACKAGE_VERIFIER: 1045 return "Verifier"; 1046 case PACKAGE_BROWSER: 1047 return "Browser"; 1048 case PACKAGE_SYSTEM_TEXT_CLASSIFIER: 1049 return "System Text Classifier"; 1050 case PACKAGE_PERMISSION_CONTROLLER: 1051 return "Permission Controller"; 1052 case PACKAGE_WELLBEING: 1053 return "Wellbeing"; 1054 case PACKAGE_DOCUMENTER: 1055 return "Documenter"; 1056 case PACKAGE_CONFIGURATOR: 1057 return "Configurator"; 1058 case PACKAGE_INCIDENT_REPORT_APPROVER: 1059 return "Incident Report Approver"; 1060 case PACKAGE_APP_PREDICTOR: 1061 return "App Predictor"; 1062 case PACKAGE_WIFI: 1063 return "Wi-Fi"; 1064 case PACKAGE_COMPANION: 1065 return "Companion"; 1066 case PACKAGE_RETAIL_DEMO: 1067 return "Retail Demo"; 1068 case PACKAGE_OVERLAY_CONFIG_SIGNATURE: 1069 return "Overlay Config Signature"; 1070 case PACKAGE_RECENTS: 1071 return "Recents"; 1072 } 1073 return "Unknown"; 1074 } 1075 1076 /** 1077 * Callback to listen for loading progress of a package installed on Incremental File System. 1078 */ 1079 public abstract static class InstalledLoadingProgressCallback { 1080 final LoadingProgressCallbackBinder mBinder = new LoadingProgressCallbackBinder(); 1081 final Executor mExecutor; 1082 /** 1083 * Default constructor that should always be called on subclass instantiation 1084 * @param handler To dispatch callback events through. If null, the main thread 1085 * handler will be used. 1086 */ InstalledLoadingProgressCallback(@ullable Handler handler)1087 public InstalledLoadingProgressCallback(@Nullable Handler handler) { 1088 if (handler == null) { 1089 handler = new Handler(Looper.getMainLooper()); 1090 } 1091 mExecutor = new HandlerExecutor(handler); 1092 } 1093 1094 /** 1095 * Binder used by Package Manager Service to register as a callback 1096 * @return the binder object of IPackageLoadingProgressCallback 1097 */ getBinder()1098 public final @NonNull IBinder getBinder() { 1099 return mBinder; 1100 } 1101 1102 /** 1103 * Report loading progress of an installed package. 1104 * 1105 * @param progress Loading progress between [0, 1] for the registered package. 1106 */ onLoadingProgressChanged(float progress)1107 public abstract void onLoadingProgressChanged(float progress); 1108 1109 private class LoadingProgressCallbackBinder extends 1110 android.content.pm.IPackageLoadingProgressCallback.Stub { 1111 @Override onPackageLoadingProgressChanged(float progress)1112 public void onPackageLoadingProgressChanged(float progress) { 1113 mExecutor.execute(PooledLambda.obtainRunnable( 1114 InstalledLoadingProgressCallback::onLoadingProgressChanged, 1115 InstalledLoadingProgressCallback.this, 1116 progress).recycleOnUse()); 1117 } 1118 } 1119 } 1120 1121 /** 1122 * Retrieve all of the information we know about a particular activity class including its 1123 * package states. 1124 * 1125 * @param packageName a specific package 1126 * @param filterCallingUid The results will be filtered in the context of this UID instead 1127 * of the calling UID. 1128 * @param userId The user for whom the package is installed 1129 * @return IncrementalStatesInfo that contains information about package states. 1130 */ getIncrementalStatesInfo(String packageName, int filterCallingUid, int userId)1131 public abstract IncrementalStatesInfo getIncrementalStatesInfo(String packageName, 1132 int filterCallingUid, int userId); 1133 1134 /** 1135 * Requesting the checksums for APKs within a package. 1136 * See {@link PackageManager#requestChecksums} for details. 1137 * 1138 * @param executor to use for digest calculations. 1139 * @param handler to use for postponed calculations. 1140 */ requestChecksums(@onNull String packageName, boolean includeSplits, @Checksum.TypeMask int optional, @Checksum.TypeMask int required, @Nullable List trustedInstallers, @NonNull IOnChecksumsReadyListener onChecksumsReadyListener, int userId, @NonNull Executor executor, @NonNull Handler handler)1141 public abstract void requestChecksums(@NonNull String packageName, boolean includeSplits, 1142 @Checksum.TypeMask int optional, @Checksum.TypeMask int required, 1143 @Nullable List trustedInstallers, 1144 @NonNull IOnChecksumsReadyListener onChecksumsReadyListener, int userId, 1145 @NonNull Executor executor, @NonNull Handler handler); 1146 1147 /** 1148 * Returns true if the given {@code packageName} and {@code userId} is frozen. 1149 * 1150 * @param packageName a specific package 1151 * @param callingUid The uid of the caller 1152 * @param userId The user for whom the package is installed 1153 * @return {@code true} If the package is current frozen (due to install/update etc.) 1154 */ isPackageFrozen( @onNull String packageName, int callingUid, int userId)1155 public abstract boolean isPackageFrozen( 1156 @NonNull String packageName, int callingUid, int userId); 1157 1158 /** 1159 * Deletes the OAT artifacts of a package. 1160 * @param packageName a specific package 1161 * @return the number of freed bytes or -1 if there was an error in the process. 1162 */ deleteOatArtifactsOfPackage(String packageName)1163 public abstract long deleteOatArtifactsOfPackage(String packageName); 1164 } 1165