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.LongDef; 22 import android.annotation.NonNull; 23 import android.annotation.Nullable; 24 import android.annotation.SystemApi; 25 import android.annotation.UserIdInt; 26 import android.annotation.WorkerThread; 27 import android.content.ComponentName; 28 import android.content.ContentResolver; 29 import android.content.Intent; 30 import android.content.IntentSender; 31 import android.content.pm.SigningDetails.CertCapabilities; 32 import android.content.pm.overlay.OverlayPaths; 33 import android.os.Bundle; 34 import android.os.Handler; 35 import android.os.HandlerExecutor; 36 import android.os.IBinder; 37 import android.os.Looper; 38 import android.os.PersistableBundle; 39 import android.os.Process; 40 import android.os.storage.StorageManager; 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.KnownPackages; 47 import com.android.server.pm.PackageList; 48 import com.android.server.pm.PackageSetting; 49 import com.android.server.pm.dex.DynamicCodeLogger; 50 import com.android.server.pm.parsing.pkg.AndroidPackage; 51 import com.android.server.pm.pkg.AndroidPackageApi; 52 import com.android.server.pm.pkg.PackageStateInternal; 53 import com.android.server.pm.pkg.SharedUserApi; 54 import com.android.server.pm.pkg.component.ParsedMainComponent; 55 import com.android.server.pm.pkg.mutate.PackageStateMutator; 56 import com.android.server.pm.snapshot.PackageDataSnapshot; 57 58 import java.io.IOException; 59 import java.lang.annotation.Retention; 60 import java.lang.annotation.RetentionPolicy; 61 import java.util.List; 62 import java.util.Set; 63 import java.util.concurrent.Executor; 64 import java.util.function.Consumer; 65 66 /** 67 * Package manager local system service interface. 68 * 69 * @hide Only for use within the system server. 70 */ 71 public abstract class PackageManagerInternal { 72 @LongDef(flag = true, prefix = "RESOLVE_", value = { 73 RESOLVE_NON_BROWSER_ONLY, 74 RESOLVE_NON_RESOLVER_ONLY 75 }) 76 @Retention(RetentionPolicy.SOURCE) 77 public @interface PrivateResolveFlags {} 78 79 /** 80 * Internal {@link #resolveIntent(Intent, String, int, int, int, boolean, int)} flag: 81 * only match components that contain a generic web intent filter. 82 */ 83 public static final int RESOLVE_NON_BROWSER_ONLY = 0x00000001; 84 85 /** 86 * Internal {@link #resolveIntent(Intent, String, int, int, int, boolean, int)} flag: do not 87 * match to the resolver. 88 */ 89 public static final int RESOLVE_NON_RESOLVER_ONLY = 0x00000002; 90 91 @IntDef(value = { 92 INTEGRITY_VERIFICATION_ALLOW, 93 INTEGRITY_VERIFICATION_REJECT, 94 }) 95 @Retention(RetentionPolicy.SOURCE) 96 public @interface IntegrityVerificationResult {} 97 98 /** 99 * Used as the {@code verificationCode} argument for 100 * {@link PackageManagerInternal#setIntegrityVerificationResult(int, int)} to indicate that the 101 * integrity component allows the install to proceed. 102 */ 103 public static final int INTEGRITY_VERIFICATION_ALLOW = 1; 104 105 /** 106 * Used as the {@code verificationCode} argument for 107 * {@link PackageManagerInternal#setIntegrityVerificationResult(int, int)} to indicate that the 108 * integrity component does not allow install to proceed. 109 */ 110 public static final int INTEGRITY_VERIFICATION_REJECT = 0; 111 112 /** Observer called whenever the list of packages changes */ 113 public interface PackageListObserver { 114 /** A package was added to the system. */ onPackageAdded(@onNull String packageName, int uid)115 void onPackageAdded(@NonNull String packageName, int uid); 116 /** A package was changed - either installed for a specific user or updated. */ onPackageChanged(@onNull String packageName, int uid)117 default void onPackageChanged(@NonNull String packageName, int uid) {} 118 /** A package was removed from the system. */ onPackageRemoved(@onNull String packageName, int uid)119 void onPackageRemoved(@NonNull String packageName, int uid); 120 } 121 122 /** 123 * Called when the package for the default SMS handler changed 124 * 125 * @param packageName the new sms package 126 * @param userId user for which the change was made 127 */ onDefaultSmsAppChanged(String packageName, int userId)128 public void onDefaultSmsAppChanged(String packageName, int userId) {} 129 130 /** 131 * Called when the package for the default sim call manager changed 132 * 133 * @param packageName the new sms package 134 * @param userId user for which the change was made 135 */ onDefaultSimCallManagerAppChanged(String packageName, int userId)136 public void onDefaultSimCallManagerAppChanged(String packageName, int userId) {} 137 138 /** 139 * Sets a list of apps to keep in PM's internal data structures and as APKs even if no user has 140 * currently installed it. The apps are not preloaded. 141 * @param packageList List of package names to keep cached. 142 */ setKeepUninstalledPackages(List<String> packageList)143 public abstract void setKeepUninstalledPackages(List<String> packageList); 144 145 /** 146 * Gets whether some of the permissions used by this package require a user 147 * review before any of the app components can run. 148 * @param packageName The package name for which to check. 149 * @param userId The user under which to check. 150 * @return True a permissions review is required. 151 */ isPermissionsReviewRequired(String packageName, int userId)152 public abstract boolean isPermissionsReviewRequired(String packageName, int userId); 153 154 155 /** 156 * Gets whether a given package name belongs to the calling uid. If the calling uid is an 157 * {@link Process#isSdkSandboxUid(int) sdk sandbox uid}, checks whether the package name is 158 * equal to {@link PackageManager#getSdkSandboxPackageName()}. 159 * 160 * @param packageName The package name to check. 161 * @param callingUid The calling uid. 162 * @param userId The user under which to check. 163 * @return True if the package name belongs to the calling uid. 164 */ isSameApp(String packageName, int callingUid, int userId)165 public abstract boolean isSameApp(String packageName, int callingUid, int userId); 166 167 /** 168 * Retrieve all of the information we know about a particular package/application. 169 * @param filterCallingUid The results will be filtered in the context of this UID instead 170 * of the calling UID. 171 * @see PackageManager#getPackageInfo(String, int) 172 */ getPackageInfo(String packageName, @PackageManager.PackageInfoFlagsBits long flags, int filterCallingUid, int userId)173 public abstract PackageInfo getPackageInfo(String packageName, 174 @PackageManager.PackageInfoFlagsBits long flags, int filterCallingUid, int userId); 175 176 /** 177 * Retrieve CE data directory inode number of an application. 178 * Return 0 if there's error. 179 */ getCeDataInode(String packageName, int userId)180 public abstract long getCeDataInode(String packageName, int userId); 181 182 /** 183 * Return a List of all application packages that are installed on the 184 * device, for a specific user. If flag GET_UNINSTALLED_PACKAGES has been 185 * set, a list of all applications including those deleted with 186 * {@code DELETE_KEEP_DATA} (partially installed apps with data directory) 187 * will be returned. 188 * 189 * @param flags Additional option flags to modify the data returned. 190 * @param userId The user for whom the installed applications are to be 191 * listed 192 * @param callingUid The uid of the original caller app 193 * @return A List of ApplicationInfo objects, one for each installed 194 * application. In the unlikely case there are no installed 195 * packages, an empty list is returned. If flag 196 * {@code MATCH_UNINSTALLED_PACKAGES} is set, the application 197 * information is retrieved from the list of uninstalled 198 * applications (which includes installed applications as well as 199 * applications with data directory i.e. applications which had been 200 * deleted with {@code DELETE_KEEP_DATA} flag set). 201 */ getInstalledApplications( @ackageManager.ApplicationInfoFlagsBits long flags, @UserIdInt int userId, int callingUid)202 public abstract List<ApplicationInfo> getInstalledApplications( 203 @PackageManager.ApplicationInfoFlagsBits long flags, @UserIdInt int userId, 204 int callingUid); 205 206 /** 207 * Retrieve launcher extras for a suspended package provided to the system in 208 * {@link PackageManager#setPackagesSuspended(String[], boolean, PersistableBundle, 209 * PersistableBundle, String)}. 210 * 211 * @param packageName The package for which to return launcher extras. 212 * @param userId The user for which to check. 213 * @return The launcher extras. 214 * 215 * @see PackageManager#setPackagesSuspended(String[], boolean, PersistableBundle, 216 * PersistableBundle, String) 217 * @see PackageManager#isPackageSuspended() 218 */ getSuspendedPackageLauncherExtras(String packageName, int userId)219 public abstract Bundle getSuspendedPackageLauncherExtras(String packageName, 220 int userId); 221 222 /** 223 * Internal api to query the suspended state of a package. 224 * @param packageName The package to check. 225 * @param userId The user id to check for. 226 * @return {@code true} if the package is suspended, {@code false} otherwise. 227 * @see PackageManager#isPackageSuspended(String) 228 */ isPackageSuspended(String packageName, int userId)229 public abstract boolean isPackageSuspended(String packageName, int userId); 230 231 /** 232 * Removes all package suspensions imposed by any non-system packages. 233 */ removeAllNonSystemPackageSuspensions(int userId)234 public abstract void removeAllNonSystemPackageSuspensions(int userId); 235 236 /** 237 * Removes all suspensions imposed on the given package by non-system packages. 238 */ removeNonSystemPackageSuspensions(String packageName, int userId)239 public abstract void removeNonSystemPackageSuspensions(String packageName, int userId); 240 241 /** 242 * Removes all {@link PackageManager.DistractionRestriction restrictions} set on the given 243 * package 244 */ removeDistractingPackageRestrictions(String packageName, int userId)245 public abstract void removeDistractingPackageRestrictions(String packageName, int userId); 246 247 /** 248 * Removes all {@link PackageManager.DistractionRestriction restrictions} set on all the 249 * packages. 250 */ removeAllDistractingPackageRestrictions(int userId)251 public abstract void removeAllDistractingPackageRestrictions(int userId); 252 253 /** 254 * Flushes package restrictions for the given user immediately to disk. 255 */ 256 @WorkerThread flushPackageRestrictions(int userId)257 public abstract void flushPackageRestrictions(int userId); 258 259 /** 260 * Get the name of the package that suspended the given package. Packages can be suspended by 261 * device administrators or apps holding {@link android.Manifest.permission#MANAGE_USERS} or 262 * {@link android.Manifest.permission#SUSPEND_APPS}. 263 * 264 * @param suspendedPackage The package that has been suspended. 265 * @param userId The user for which to check. 266 * @return Name of the package that suspended the given package. Returns {@code null} if the 267 * given package is not currently suspended and the platform package name - i.e. 268 * {@code "android"} - if the package was suspended by a device admin. 269 */ getSuspendingPackage(String suspendedPackage, int userId)270 public abstract String getSuspendingPackage(String suspendedPackage, int userId); 271 272 /** 273 * Get the information describing the dialog to be shown to the user when they try to launch a 274 * suspended application. 275 * 276 * @param suspendedPackage The package that has been suspended. 277 * @param suspendingPackage 278 * @param userId The user for which to check. 279 * @return A {@link SuspendDialogInfo} object describing the dialog to be shown. 280 */ 281 @Nullable getSuspendedDialogInfo(String suspendedPackage, String suspendingPackage, int userId)282 public abstract SuspendDialogInfo getSuspendedDialogInfo(String suspendedPackage, 283 String suspendingPackage, int userId); 284 285 /** 286 * Gets any distraction flags set via 287 * {@link PackageManager#setDistractingPackageRestrictions(String[], int)} 288 * 289 * @param packageName 290 * @param userId 291 * @return A bitwise OR of any of the {@link PackageManager.DistractionRestriction} 292 */ getDistractingPackageRestrictions( String packageName, int userId)293 public abstract @PackageManager.DistractionRestriction int getDistractingPackageRestrictions( 294 String packageName, int userId); 295 296 /** 297 * Do a straight uid lookup for the given package/application in the given user. 298 * @see PackageManager#getPackageUidAsUser(String, int, int) 299 * @return The app's uid, or < 0 if the package was not found in that user 300 */ getPackageUid(String packageName, @PackageManager.PackageInfoFlagsBits long flags, int userId)301 public abstract int getPackageUid(String packageName, 302 @PackageManager.PackageInfoFlagsBits long flags, int userId); 303 304 /** 305 * Retrieve all of the information we know about a particular package/application. 306 * @param filterCallingUid The results will be filtered in the context of this UID instead 307 * of the calling UID. 308 * @see PackageManager#getApplicationInfo(String, int) 309 */ getApplicationInfo(String packageName, @PackageManager.ApplicationInfoFlagsBits long flags, int filterCallingUid, int userId)310 public abstract ApplicationInfo getApplicationInfo(String packageName, 311 @PackageManager.ApplicationInfoFlagsBits long flags, int filterCallingUid, int userId); 312 313 /** 314 * Retrieve all of the information we know about a particular activity class. 315 * @param filterCallingUid The results will be filtered in the context of this UID instead 316 * of the calling UID. 317 * @see PackageManager#getActivityInfo(ComponentName, int) 318 */ getActivityInfo(ComponentName component, @PackageManager.ComponentInfoFlagsBits long flags, int filterCallingUid, int userId)319 public abstract ActivityInfo getActivityInfo(ComponentName component, 320 @PackageManager.ComponentInfoFlagsBits long flags, int filterCallingUid, int userId); 321 322 /** 323 * Retrieve all activities that can be performed for the given intent. 324 * @param resolvedType the resolved type of the intent, which should be resolved via 325 * {@link Intent#resolveTypeIfNeeded(ContentResolver)} before passing to {@link PackageManager} 326 * @param filterCallingUid The results will be filtered in the context of this UID instead 327 * of the calling UID. 328 * @see PackageManager#queryIntentActivities(Intent, int) 329 */ queryIntentActivities( Intent intent, @Nullable String resolvedType, @PackageManager.ResolveInfoFlagsBits long flags, int filterCallingUid, int userId)330 public abstract List<ResolveInfo> queryIntentActivities( 331 Intent intent, @Nullable String resolvedType, 332 @PackageManager.ResolveInfoFlagsBits long flags, int filterCallingUid, int userId); 333 334 335 /** 336 * Retrieve all receivers that can handle a broadcast of the given intent. 337 * @param filterCallingUid The results will be filtered in the context of this UID instead 338 * of the calling UID. 339 * @param forSend true if the invocation is intended for sending broadcasts. The value 340 * of this parameter affects how packages are filtered. 341 */ queryIntentReceivers(Intent intent, String resolvedType, @PackageManager.ResolveInfoFlagsBits long flags, int filterCallingUid, int userId, boolean forSend)342 public abstract List<ResolveInfo> queryIntentReceivers(Intent intent, 343 String resolvedType, @PackageManager.ResolveInfoFlagsBits long flags, 344 int filterCallingUid, int userId, boolean forSend); 345 346 /** 347 * Retrieve all services that can be performed for the given intent. 348 * @see PackageManager#queryIntentServices(Intent, int) 349 */ queryIntentServices( Intent intent, @PackageManager.ResolveInfoFlagsBits long flags, int callingUid, int userId)350 public abstract List<ResolveInfo> queryIntentServices( 351 Intent intent, @PackageManager.ResolveInfoFlagsBits long flags, int callingUid, 352 int userId); 353 354 /** 355 * Interface to {@link com.android.server.pm.PackageManagerService#getHomeActivitiesAsUser}. 356 */ getHomeActivitiesAsUser(List<ResolveInfo> allHomeCandidates, int userId)357 public abstract ComponentName getHomeActivitiesAsUser(List<ResolveInfo> allHomeCandidates, 358 int userId); 359 360 /** 361 * @return The default home activity component name. 362 */ getDefaultHomeActivity(int userId)363 public abstract ComponentName getDefaultHomeActivity(int userId); 364 365 /** 366 * @return The SystemUI service component name. 367 */ getSystemUiServiceComponent()368 public abstract ComponentName getSystemUiServiceComponent(); 369 370 /** 371 * Called by DeviceOwnerManagerService to set the package names of device owner and profile 372 * owners. 373 */ setDeviceAndProfileOwnerPackages( int deviceOwnerUserId, String deviceOwner, SparseArray<String> profileOwners)374 public abstract void setDeviceAndProfileOwnerPackages( 375 int deviceOwnerUserId, String deviceOwner, SparseArray<String> profileOwners); 376 377 /** 378 * Marks packages as protected for a given user or all users in case of USER_ALL. 379 */ setOwnerProtectedPackages( @serIdInt int userId, @NonNull List<String> packageNames)380 public abstract void setOwnerProtectedPackages( 381 @UserIdInt int userId, @NonNull List<String> packageNames); 382 383 /** 384 * Returns {@code true} if a given package can't be wiped. Otherwise, returns {@code false}. 385 */ isPackageDataProtected(int userId, String packageName)386 public abstract boolean isPackageDataProtected(int userId, String packageName); 387 388 /** 389 * Returns {@code true} if a given package's state is protected, e.g. it cannot be force 390 * stopped, suspended, disabled or hidden. Otherwise, returns {@code false}. 391 */ isPackageStateProtected(String packageName, int userId)392 public abstract boolean isPackageStateProtected(String packageName, int userId); 393 394 /** 395 * Returns {@code true} if a given package is installed as ephemeral. Otherwise, returns 396 * {@code false}. 397 */ isPackageEphemeral(int userId, String packageName)398 public abstract boolean isPackageEphemeral(int userId, String packageName); 399 400 /** 401 * Gets whether the package was ever launched. 402 * @param packageName The package name. 403 * @param userId The user for which to check. 404 * @return Whether was launched. 405 * @throws IllegalArgumentException if the package is not found 406 */ wasPackageEverLaunched(String packageName, int userId)407 public abstract boolean wasPackageEverLaunched(String packageName, int userId); 408 409 /** 410 * Retrieve the official name associated with a uid. This name is 411 * guaranteed to never change, though it is possible for the underlying 412 * uid to be changed. That is, if you are storing information about 413 * uids in persistent storage, you should use the string returned 414 * by this function instead of the raw uid. 415 * 416 * @param uid The uid for which you would like to retrieve a name. 417 * @return Returns a unique name for the given uid, or null if the 418 * uid is not currently assigned. 419 */ getNameForUid(int uid)420 public abstract String getNameForUid(int uid); 421 422 /** 423 * Request to perform the second phase of ephemeral resolution. 424 * @param responseObj The response of the first phase of ephemeral resolution 425 * @param origIntent The original intent that triggered ephemeral resolution 426 * @param resolvedType The resolved type of the intent 427 * @param callingPkg The app requesting the ephemeral application 428 * @param callingFeatureId The feature in the package 429 * @param isRequesterInstantApp Whether or not the app requesting the ephemeral application 430 * is an instant app 431 * @param verificationBundle Optional bundle to pass to the installer for additional 432 * verification 433 * @param userId The ID of the user that triggered ephemeral resolution 434 */ requestInstantAppResolutionPhaseTwo(AuxiliaryResolveInfo responseObj, Intent origIntent, String resolvedType, String callingPkg, @Nullable String callingFeatureId, boolean isRequesterInstantApp, Bundle verificationBundle, int userId)435 public abstract void requestInstantAppResolutionPhaseTwo(AuxiliaryResolveInfo responseObj, 436 Intent origIntent, String resolvedType, String callingPkg, 437 @Nullable String callingFeatureId, boolean isRequesterInstantApp, 438 Bundle verificationBundle, int userId); 439 440 /** 441 * Grants implicit access based on an interaction between two apps. This grants access to the 442 * from one application to the other's package metadata. 443 * <p> 444 * When an application explicitly tries to interact with another application [via an 445 * activity, service or provider that is either declared in the caller's 446 * manifest via the {@code <queries>} tag or has been exposed via the target apps manifest using 447 * the {@code visibleToInstantApp} attribute], the target application must be able to see 448 * metadata about the calling app. If the calling application uses an implicit intent [ie 449 * action VIEW, category BROWSABLE], it remains hidden from the launched app. 450 * <p> 451 * If an interaction is not explicit, the {@code direct} argument should be set to false as 452 * visibility should not be granted in some cases. This method handles that logic. 453 * <p> 454 * @param userId the user 455 * @param intent the intent that triggered the grant 456 * @param recipientAppId The app ID of the application that is being given access to {@code 457 * visibleUid} 458 * @param visibleUid The uid of the application that is becoming accessible to {@code 459 * recipientAppId} 460 * @param direct true if the access is being made due to direct interaction between visibleUid 461 * and recipientAppId. 462 */ grantImplicitAccess( @serIdInt int userId, Intent intent, @AppIdInt int recipientAppId, int visibleUid, boolean direct)463 public abstract void grantImplicitAccess( 464 @UserIdInt int userId, Intent intent, 465 @AppIdInt int recipientAppId, int visibleUid, 466 boolean direct); 467 468 /** 469 * Grants implicit access based on an interaction between two apps. This grants access to the 470 * from one application to the other's package metadata. 471 * <p> 472 * When an application explicitly tries to interact with another application [via an 473 * activity, service or provider that is either declared in the caller's 474 * manifest via the {@code <queries>} tag or has been exposed via the target apps manifest using 475 * the {@code visibleToInstantApp} attribute], the target application must be able to see 476 * metadata about the calling app. If the calling application uses an implicit intent [ie 477 * action VIEW, category BROWSABLE], it remains hidden from the launched app. 478 * <p> 479 * If an interaction is not explicit, the {@code direct} argument should be set to false as 480 * visibility should not be granted in some cases. This method handles that logic. 481 * <p> 482 * @param userId the user 483 * @param intent the intent that triggered the grant 484 * @param recipientAppId The app ID of the application that is being given access to {@code 485 * visibleUid} 486 * @param visibleUid The uid of the application that is becoming accessible to {@code 487 * recipientAppId} 488 * @param direct true if the access is being made due to direct interaction between visibleUid 489 * and recipientAppId. 490 * @param retainOnUpdate true if the implicit access is retained across package update. 491 */ grantImplicitAccess( @serIdInt int userId, Intent intent, @AppIdInt int recipientAppId, int visibleUid, boolean direct, boolean retainOnUpdate)492 public abstract void grantImplicitAccess( 493 @UserIdInt int userId, Intent intent, 494 @AppIdInt int recipientAppId, int visibleUid, 495 boolean direct, boolean retainOnUpdate); 496 isInstantAppInstallerComponent(ComponentName component)497 public abstract boolean isInstantAppInstallerComponent(ComponentName component); 498 /** 499 * Prunes instant apps and state associated with uninstalled 500 * instant apps according to the current platform policy. 501 */ pruneInstantApps()502 public abstract void pruneInstantApps(); 503 504 /** 505 * Prunes the cache of the APKs in the given APEXes. 506 * @param apexPackages The list of APEX packages that may contain APK-in-APEX. 507 */ pruneCachedApksInApex(@onNull List<PackageInfo> apexPackages)508 public abstract void pruneCachedApksInApex(@NonNull List<PackageInfo> apexPackages); 509 510 /** 511 * @return The SetupWizard package name. 512 */ getSetupWizardPackageName()513 public abstract String getSetupWizardPackageName(); 514 515 public interface ExternalSourcesPolicy { 516 517 int USER_TRUSTED = 0; // User has trusted the package to install apps 518 int USER_BLOCKED = 1; // User has blocked the package to install apps 519 int USER_DEFAULT = 2; // Default code to use when user response is unavailable 520 521 /** 522 * Checks the user preference for whether a package is trusted to request installs through 523 * package installer 524 * 525 * @param packageName The package to check for 526 * @param uid the uid in which the package is running 527 * @return {@link #USER_TRUSTED} if the user has trusted the package, {@link #USER_BLOCKED} 528 * if user has blocked requests from the package, {@link #USER_DEFAULT} if the user response 529 * is not yet available 530 */ getPackageTrustedToInstallApps(String packageName, int uid)531 int getPackageTrustedToInstallApps(String packageName, int uid); 532 } 533 setExternalSourcesPolicy(ExternalSourcesPolicy policy)534 public abstract void setExternalSourcesPolicy(ExternalSourcesPolicy policy); 535 536 /** 537 * Return true if the given package is a persistent app process. 538 */ isPackagePersistent(String packageName)539 public abstract boolean isPackagePersistent(String packageName); 540 541 /** 542 * Get all overlay packages for a user. 543 * @param userId The user for which to get the overlays. 544 * @return A list of overlay packages. An empty list is returned if the 545 * user has no installed overlay packages. 546 */ getOverlayPackages(int userId)547 public abstract List<PackageInfo> getOverlayPackages(int userId); 548 549 /** 550 * Get the names of all target packages for a user. 551 * @param userId The user for which to get the package names. 552 * @return A list of target package names. This list includes the "android" package. 553 */ getTargetPackageNames(int userId)554 public abstract List<String> getTargetPackageNames(int userId); 555 556 /** 557 * Set which overlay to use for a package. 558 * @param userId The user for which to update the overlays. 559 * @param targetPackageName The package name of the package for which to update the overlays. 560 * @param overlayPaths The complete list of overlay paths that should be enabled for 561 * the target. Previously enabled overlays not specified in the list 562 * will be disabled. Pass in null or empty paths to disable all overlays. 563 * The order of the items is significant if several overlays modify the 564 * same resource. 565 * @param outUpdatedPackageNames An output list that contains the package names of packages 566 * affected by the update of enabled overlays. 567 * @return true if all packages names were known by the package manager, false otherwise 568 */ setEnabledOverlayPackages(int userId, String targetPackageName, @Nullable OverlayPaths overlayPaths, Set<String> outUpdatedPackageNames)569 public abstract boolean setEnabledOverlayPackages(int userId, String targetPackageName, 570 @Nullable OverlayPaths overlayPaths, Set<String> outUpdatedPackageNames); 571 572 /** 573 * Resolves an activity intent, allowing instant apps to be resolved. 574 */ resolveIntent(Intent intent, String resolvedType, @PackageManager.ResolveInfoFlagsBits long flags, @PrivateResolveFlags long privateResolveFlags, int userId, boolean resolveForStart, int filterCallingUid)575 public abstract ResolveInfo resolveIntent(Intent intent, String resolvedType, 576 @PackageManager.ResolveInfoFlagsBits long flags, 577 @PrivateResolveFlags long privateResolveFlags, int userId, boolean resolveForStart, 578 int filterCallingUid); 579 580 /** 581 * Resolves a service intent, allowing instant apps to be resolved. 582 */ resolveService(Intent intent, String resolvedType, @PackageManager.ResolveInfoFlagsBits long flags, int userId, int callingUid)583 public abstract ResolveInfo resolveService(Intent intent, String resolvedType, 584 @PackageManager.ResolveInfoFlagsBits long flags, int userId, int callingUid); 585 586 /** 587 * Resolves a content provider intent. 588 */ resolveContentProvider(String name, @PackageManager.ComponentInfoFlagsBits long flags, int userId, int callingUid)589 public abstract ProviderInfo resolveContentProvider(String name, 590 @PackageManager.ComponentInfoFlagsBits long flags, int userId, int callingUid); 591 592 /** 593 * Track the creator of a new isolated uid. 594 * @param isolatedUid The newly created isolated uid. 595 * @param ownerUid The uid of the app that created the isolated process. 596 */ addIsolatedUid(int isolatedUid, int ownerUid)597 public abstract void addIsolatedUid(int isolatedUid, int ownerUid); 598 599 /** 600 * Track removal of an isolated uid. 601 * @param isolatedUid isolated uid that is no longer being used. 602 */ removeIsolatedUid(int isolatedUid)603 public abstract void removeIsolatedUid(int isolatedUid); 604 605 /** 606 * Return the taget SDK version for the app with the given UID. 607 */ getUidTargetSdkVersion(int uid)608 public abstract int getUidTargetSdkVersion(int uid); 609 610 /** 611 * Return the taget SDK version for the app with the given package name. 612 */ getPackageTargetSdkVersion(String packageName)613 public abstract int getPackageTargetSdkVersion(String packageName); 614 615 /** Whether the binder caller can access instant apps. */ canAccessInstantApps(int callingUid, int userId)616 public abstract boolean canAccessInstantApps(int callingUid, int userId); 617 618 /** Whether the binder caller can access the given component. */ canAccessComponent(int callingUid, ComponentName component, int userId)619 public abstract boolean canAccessComponent(int callingUid, ComponentName component, int userId); 620 621 /** 622 * Returns {@code true} if a given package has instant application meta-data. 623 * Otherwise, returns {@code false}. Meta-data is state (eg. cookie, app icon, etc) 624 * associated with an instant app. It may be kept after the instant app has been uninstalled. 625 */ hasInstantApplicationMetadata(String packageName, int userId)626 public abstract boolean hasInstantApplicationMetadata(String packageName, int userId); 627 628 /** 629 * Updates a package last used time. 630 */ notifyPackageUse(String packageName, int reason)631 public abstract void notifyPackageUse(String packageName, int reason); 632 633 /** 634 * Notify the package is force stopped. 635 */ onPackageProcessKilledForUninstall(String packageName)636 public abstract void onPackageProcessKilledForUninstall(String packageName); 637 638 /** 639 * Returns a package object for the given package name. 640 */ getPackage(@onNull String packageName)641 public abstract @Nullable AndroidPackage getPackage(@NonNull String packageName); 642 643 /** 644 * Returns the {@link SystemApi} variant of a package for use with mainline. 645 */ 646 @Nullable getAndroidPackage(@onNull String packageName)647 public abstract AndroidPackageApi getAndroidPackage(@NonNull String packageName); 648 649 @Nullable getPackageStateInternal(@onNull String packageName)650 public abstract PackageStateInternal getPackageStateInternal(@NonNull String packageName); 651 652 @NonNull getPackageStates()653 public abstract ArrayMap<String, ? extends PackageStateInternal> getPackageStates(); 654 655 /** 656 * Returns a package for the given UID. If the UID is part of a shared user ID, one 657 * of the packages will be chosen to be returned. 658 */ getPackage(int uid)659 public abstract @Nullable AndroidPackage getPackage(int uid); 660 661 662 /** 663 * Returns all packages for the given app ID. 664 */ getPackagesForAppId(int appId)665 public abstract @NonNull List<AndroidPackage> getPackagesForAppId(int appId); 666 667 /** 668 * Returns a list without a change observer. 669 * 670 * @see #getPackageList(PackageListObserver) 671 */ getPackageList()672 public @NonNull PackageList getPackageList() { 673 return getPackageList(null); 674 } 675 676 /** 677 * Returns the list of packages installed at the time of the method call. 678 * <p>The given observer is notified when the list of installed packages 679 * changes [eg. a package was installed or uninstalled]. It will not be 680 * notified if a package is updated. 681 * <p>The package list will not be updated automatically as packages are 682 * installed / uninstalled. Any changes must be handled within the observer. 683 */ getPackageList(@ullable PackageListObserver observer)684 public abstract @NonNull PackageList getPackageList(@Nullable PackageListObserver observer); 685 686 /** 687 * Removes the observer. 688 * <p>Generally not needed. {@link #getPackageList(PackageListObserver)} will automatically 689 * remove the observer. 690 * <p>Does nothing if the observer isn't currently registered. 691 * <p>Observers are notified asynchronously and it's possible for an observer to be 692 * invoked after its been removed. 693 */ removePackageListObserver(@onNull PackageListObserver observer)694 public abstract void removePackageListObserver(@NonNull PackageListObserver observer); 695 696 /** 697 * Returns a package object for the disabled system package name. 698 */ getDisabledSystemPackage( @onNull String packageName)699 public abstract @Nullable PackageStateInternal getDisabledSystemPackage( 700 @NonNull String packageName); 701 702 /** 703 * Returns the package name for the disabled system package. 704 * 705 * This is equivalent to 706 * {@link #getDisabledSystemPackage(String)} 707 * .{@link PackageSetting#pkg} 708 * .{@link AndroidPackage#getPackageName()} 709 */ getDisabledSystemPackageName(@onNull String packageName)710 public abstract @Nullable String getDisabledSystemPackageName(@NonNull String packageName); 711 712 /** 713 * Returns whether or not the component is the resolver activity. 714 */ isResolveActivityComponent(@onNull ComponentInfo component)715 public abstract boolean isResolveActivityComponent(@NonNull ComponentInfo component); 716 717 /** 718 * Returns a list of package names for a known package 719 */ getKnownPackageNames( @nownPackages.KnownPackage int knownPackage, int userId)720 public abstract @NonNull String[] getKnownPackageNames( 721 @KnownPackages.KnownPackage int knownPackage, int userId); 722 723 /** 724 * Returns whether the package is an instant app. 725 */ isInstantApp(String packageName, int userId)726 public abstract boolean isInstantApp(String packageName, int userId); 727 728 /** 729 * Returns whether the package is an instant app. 730 */ getInstantAppPackageName(int uid)731 public abstract @Nullable String getInstantAppPackageName(int uid); 732 733 /** 734 * Returns whether or not access to the application should be filtered. 735 * <p> 736 * Access may be limited based upon whether the calling or target applications 737 * are instant applications. 738 * 739 * @see #canAccessInstantApps 740 */ filterAppAccess( @onNull AndroidPackage pkg, int callingUid, int userId)741 public abstract boolean filterAppAccess( 742 @NonNull AndroidPackage pkg, int callingUid, int userId); 743 744 /** 745 * Returns whether or not access to the application should be filtered. 746 * 747 * @see #filterAppAccess(AndroidPackage, int, int) 748 */ filterAppAccess( @onNull String packageName, int callingUid, int userId)749 public abstract boolean filterAppAccess( 750 @NonNull String packageName, int callingUid, int userId); 751 752 /** 753 * Returns whether or not access to the application which belongs to the given UID should be 754 * filtered. If the UID is part of a shared user ID, return {@code true} if all applications 755 * belong to the shared user ID should be filtered. 756 * 757 * @see #filterAppAccess(AndroidPackage, int, int) 758 */ filterAppAccess(int uid, int callingUid)759 public abstract boolean filterAppAccess(int uid, int callingUid); 760 761 /** 762 * Fetches all app Ids that a given application is currently visible to the provided user. 763 * 764 * <p> 765 * <strong>Note: </strong>This only includes UIDs >= {@link Process#FIRST_APPLICATION_UID} 766 * as all other UIDs can already see all applications. 767 * </p> 768 * 769 * If the app is visible to all UIDs, null is returned. If the app is not visible to any 770 * applications, the int array will be empty. 771 */ 772 @Nullable getVisibilityAllowList(@onNull String packageName, int userId)773 public abstract int[] getVisibilityAllowList(@NonNull String packageName, int userId); 774 775 /** 776 * Returns whether the given UID either declares <queries> element with the given package 777 * name in its app's manifest, has {@link android.Manifest.permission.QUERY_ALL_PACKAGES}, or 778 * package visibility filtering is enabled on it. If the UID is part of a shared user ID, 779 * return {@code true} if any one application belongs to the shared user ID meets the criteria. 780 */ canQueryPackage(int callingUid, @Nullable String packageName)781 public abstract boolean canQueryPackage(int callingUid, @Nullable String packageName); 782 783 /** Returns whether the given package was signed by the platform */ isPlatformSigned(String pkg)784 public abstract boolean isPlatformSigned(String pkg); 785 786 /** 787 * Returns true if it's still safe to restore data backed up from this app's version 788 * that was signed with restoringFromSigHash. 789 */ isDataRestoreSafe(@onNull byte[] restoringFromSigHash, @NonNull String packageName)790 public abstract boolean isDataRestoreSafe(@NonNull byte[] restoringFromSigHash, 791 @NonNull String packageName); 792 793 /** 794 * Returns true if it's still safe to restore data backed up from this app's version 795 * that was signed with restoringFromSig. 796 */ isDataRestoreSafe(@onNull Signature restoringFromSig, @NonNull String packageName)797 public abstract boolean isDataRestoreSafe(@NonNull Signature restoringFromSig, 798 @NonNull String packageName); 799 800 /** 801 * Returns {@code true} if the the signing information for {@code clientUid} is sufficient 802 * to gain access gated by {@code capability}. This can happen if the two UIDs have the 803 * same signing information, if the signing information {@code clientUid} indicates that 804 * it has the signing certificate for {@code serverUid} in its signing history (if it was 805 * previously signed by it), or if the signing certificate for {@code clientUid} is in the 806 * signing history for {@code serverUid} and with the {@code capability} specified. 807 */ hasSignatureCapability(int serverUid, int clientUid, @CertCapabilities int capability)808 public abstract boolean hasSignatureCapability(int serverUid, int clientUid, 809 @CertCapabilities int capability); 810 811 /** 812 * Get appIds of all available apps which specified android:sharedUserId in the manifest. 813 * 814 * @return a SparseArray mapping from appId to it's sharedUserId. 815 */ getAppsWithSharedUserIds()816 public abstract SparseArray<String> getAppsWithSharedUserIds(); 817 818 /** 819 * Get all packages which share the same userId as the specified package, or an empty array 820 * if the package does not have a shared userId. 821 */ 822 @NonNull getSharedUserPackagesForPackage(@onNull String packageName, int userId)823 public abstract String[] getSharedUserPackagesForPackage(@NonNull String packageName, 824 int userId); 825 826 /** 827 * Return the processes that have been declared for a uid. 828 * 829 * @param uid The uid to query. 830 * 831 * @return Returns null if there are no declared processes for the uid; otherwise, 832 * returns the set of processes it declared. 833 */ getProcessesForUid(int uid)834 public abstract ArrayMap<String, ProcessInfo> getProcessesForUid(int uid); 835 836 /** 837 * Return the gids associated with a particular permission. 838 * 839 * @param permissionName The name of the permission to query. 840 * @param userId The user id the gids will be associated with. 841 * 842 * @return Returns null if there are no gids associated with the permission, otherwise an 843 * array if the gid ints. 844 */ getPermissionGids(String permissionName, int userId)845 public abstract int[] getPermissionGids(String permissionName, int userId); 846 847 /** 848 * Return if device is currently in a "core" boot environment, typically 849 * used to support full-disk encryption. Only apps marked with 850 * {@code coreApp} attribute are available. 851 */ isOnlyCoreApps()852 public abstract boolean isOnlyCoreApps(); 853 854 /** 855 * Make a best-effort attempt to provide the requested free disk space by 856 * deleting cached files. 857 * 858 * @throws IOException if the request was unable to be fulfilled. 859 */ freeStorage(String volumeUuid, long bytes, @StorageManager.AllocateFlags int flags)860 public abstract void freeStorage(String volumeUuid, long bytes, 861 @StorageManager.AllocateFlags int flags) throws IOException; 862 863 /** 864 * Blocking call to clear all cached app data above quota. 865 */ freeAllAppCacheAboveQuota(@onNull String volumeUuid)866 public abstract void freeAllAppCacheAboveQuota(@NonNull String volumeUuid) throws IOException; 867 868 /** Returns {@code true} if the specified component is enabled and matches the given flags. */ isEnabledAndMatches(@onNull ParsedMainComponent component, @PackageManager.ComponentInfoFlagsBits long flags, int userId)869 public abstract boolean isEnabledAndMatches(@NonNull ParsedMainComponent component, 870 @PackageManager.ComponentInfoFlagsBits long flags, int userId); 871 872 /** Returns {@code true} if the given user requires extra badging for icons. */ userNeedsBadging(int userId)873 public abstract boolean userNeedsBadging(int userId); 874 875 /** 876 * Perform the given action for each {@link PackageSetting}. 877 * Note that packages lock will be held while performing the actions. 878 * 879 * If the caller does not need all packages, prefer the potentially non-locking 880 * {@link #withPackageSettingsSnapshot(Consumer)}. 881 * 882 * @param actionLocked action to be performed 883 */ forEachPackageSetting(Consumer<PackageSetting> actionLocked)884 public abstract void forEachPackageSetting(Consumer<PackageSetting> actionLocked); 885 886 /** 887 * Perform the given action for each package. 888 * @param action action to be performed 889 */ forEachPackageState(Consumer<PackageStateInternal> action)890 public abstract void forEachPackageState(Consumer<PackageStateInternal> action); 891 892 /** 893 * {@link #forEachPackageState(Consumer)} but filtered to only states with packages 894 * on device where {@link PackageStateInternal#getPkg()} is not null. 895 */ forEachPackage(Consumer<AndroidPackage> action)896 public abstract void forEachPackage(Consumer<AndroidPackage> action); 897 898 /** 899 * Perform the given action for each installed package for a user. 900 */ forEachInstalledPackage( @onNull Consumer<AndroidPackage> action, @UserIdInt int userId)901 public abstract void forEachInstalledPackage( 902 @NonNull Consumer<AndroidPackage> action, @UserIdInt int userId); 903 904 /** Returns the list of enabled components */ getEnabledComponents(String packageName, int userId)905 public abstract ArraySet<String> getEnabledComponents(String packageName, int userId); 906 907 /** Returns the list of disabled components */ getDisabledComponents(String packageName, int userId)908 public abstract ArraySet<String> getDisabledComponents(String packageName, int userId); 909 910 /** Returns whether the given package is enabled for the given user */ getApplicationEnabledState( String packageName, int userId)911 public abstract @PackageManager.EnabledState int getApplicationEnabledState( 912 String packageName, int userId); 913 914 /** 915 * Return the enabled setting for a package component (activity, receiver, service, provider). 916 */ getComponentEnabledSetting( @onNull ComponentName componentName, int callingUid, int userId)917 public abstract @PackageManager.EnabledState int getComponentEnabledSetting( 918 @NonNull ComponentName componentName, int callingUid, int userId); 919 920 /** 921 * Extra field name for the token of a request to enable rollback for a 922 * package. 923 */ 924 public static final String EXTRA_ENABLE_ROLLBACK_TOKEN = 925 "android.content.pm.extra.ENABLE_ROLLBACK_TOKEN"; 926 927 /** 928 * Extra field name for the session id of a request to enable rollback 929 * for a package. 930 */ 931 public static final String EXTRA_ENABLE_ROLLBACK_SESSION_ID = 932 "android.content.pm.extra.ENABLE_ROLLBACK_SESSION_ID"; 933 934 /** 935 * Used as the {@code enableRollbackCode} argument for 936 * {@link PackageManagerInternal#setEnableRollbackCode} to indicate that 937 * enabling rollback succeeded. 938 */ 939 public static final int ENABLE_ROLLBACK_SUCCEEDED = 1; 940 941 /** 942 * Used as the {@code enableRollbackCode} argument for 943 * {@link PackageManagerInternal#setEnableRollbackCode} to indicate that 944 * enabling rollback failed. 945 */ 946 public static final int ENABLE_ROLLBACK_FAILED = -1; 947 948 /** 949 * Allows the rollback manager listening to the 950 * {@link Intent#ACTION_PACKAGE_ENABLE_ROLLBACK enable rollback broadcast} 951 * to respond to the package manager. The response must include the 952 * {@code enableRollbackCode} which is one of 953 * {@link PackageManager#ENABLE_ROLLBACK_SUCCEEDED} or 954 * {@link PackageManager#ENABLE_ROLLBACK_FAILED}. 955 * 956 * @param token pending package identifier as passed via the 957 * {@link PackageManager#EXTRA_ENABLE_ROLLBACK_TOKEN} Intent extra. 958 * @param enableRollbackCode the status code result of enabling rollback 959 * @throws SecurityException if the caller does not have the 960 * PACKAGE_ROLLBACK_AGENT permission. 961 */ setEnableRollbackCode(int token, int enableRollbackCode)962 public abstract void setEnableRollbackCode(int token, int enableRollbackCode); 963 964 /** 965 * Ask the package manager to compile layouts in the given package. 966 */ compileLayouts(String packageName)967 public abstract boolean compileLayouts(String packageName); 968 969 /* 970 * Inform the package manager that the pending package install identified by 971 * {@code token} can be completed. 972 */ finishPackageInstall(int token, boolean didLaunch)973 public abstract void finishPackageInstall(int token, boolean didLaunch); 974 975 /** 976 * Remove the default browser stored in the legacy package settings. 977 * 978 * @param userId the user id 979 * 980 * @return the package name of the default browser, or {@code null} if none 981 */ 982 @Nullable removeLegacyDefaultBrowserPackageName(int userId)983 public abstract String removeLegacyDefaultBrowserPackageName(int userId); 984 985 /** 986 * Returns {@code true} if given {@code packageName} is an apex package. 987 */ isApexPackage(String packageName)988 public abstract boolean isApexPackage(String packageName); 989 990 /** 991 * Returns list of {@code packageName} of apks inside the given apex. 992 * @param apexPackageName Package name of the apk container of apex 993 */ getApksInApex(String apexPackageName)994 public abstract List<String> getApksInApex(String apexPackageName); 995 996 /** 997 * Uninstalls given {@code packageName}. 998 * 999 * @param packageName apex package to uninstall. 1000 * @param versionCode version of a package to uninstall. 1001 * @param userId user to uninstall apex package for. Must be 1002 * {@link android.os.UserHandle#USER_ALL}, otherwise failure will be reported. 1003 * @param intentSender a {@link IntentSender} to send result of an uninstall to. 1004 * @param flags flags about the uninstall. 1005 */ uninstallApex(String packageName, long versionCode, int userId, IntentSender intentSender, @PackageManager.InstallFlags int installFlags)1006 public abstract void uninstallApex(String packageName, long versionCode, int userId, 1007 IntentSender intentSender, @PackageManager.InstallFlags int installFlags); 1008 1009 /** 1010 * Update fingerprint of build that updated the runtime permissions for a user. 1011 * 1012 * @param userId The user to update 1013 */ updateRuntimePermissionsFingerprint(@serIdInt int userId)1014 public abstract void updateRuntimePermissionsFingerprint(@UserIdInt int userId); 1015 1016 /** 1017 * Migrates legacy obb data to its new location. 1018 */ migrateLegacyObbData()1019 public abstract void migrateLegacyObbData(); 1020 1021 /** 1022 * Writes all package manager settings to disk. If {@code async} is {@code true}, the 1023 * settings are written at some point in the future. Otherwise, the call blocks until 1024 * the settings have been written. 1025 */ writeSettings(boolean async)1026 public abstract void writeSettings(boolean async); 1027 1028 /** 1029 * Writes all permission settings for the given set of users to disk. If {@code async} 1030 * is {@code true}, the settings are written at some point in the future. Otherwise, 1031 * the call blocks until the settings have been written. 1032 */ writePermissionSettings(@onNull @serIdInt int[] userIds, boolean async)1033 public abstract void writePermissionSettings(@NonNull @UserIdInt int[] userIds, boolean async); 1034 1035 /** 1036 * Returns {@code true} if the caller is the installer of record for the given package. 1037 * Otherwise, {@code false}. 1038 */ isCallerInstallerOfRecord( @onNull AndroidPackage pkg, int callingUid)1039 public abstract boolean isCallerInstallerOfRecord( 1040 @NonNull AndroidPackage pkg, int callingUid); 1041 1042 /** Returns whether or not permissions need to be upgraded for the given user */ isPermissionUpgradeNeeded(@serIdInt int userId)1043 public abstract boolean isPermissionUpgradeNeeded(@UserIdInt int userId); 1044 1045 /** 1046 * Allows the integrity component to respond to the 1047 * {@link Intent#ACTION_PACKAGE_NEEDS_INTEGRITY_VERIFICATION package verification 1048 * broadcast} to respond to the package manager. The response must include 1049 * the {@code verificationCode} which is one of 1050 * {@link #INTEGRITY_VERIFICATION_ALLOW} and {@link #INTEGRITY_VERIFICATION_REJECT}. 1051 * 1052 * @param verificationId pending package identifier as passed via the 1053 * {@link PackageManager#EXTRA_VERIFICATION_ID} Intent extra. 1054 * @param verificationResult either {@link #INTEGRITY_VERIFICATION_ALLOW} 1055 * or {@link #INTEGRITY_VERIFICATION_REJECT}. 1056 */ setIntegrityVerificationResult(int verificationId, @IntegrityVerificationResult int verificationResult)1057 public abstract void setIntegrityVerificationResult(int verificationId, 1058 @IntegrityVerificationResult int verificationResult); 1059 1060 /** 1061 * Returns MIME types contained in {@code mimeGroup} from {@code packageName} package 1062 */ getMimeGroup(String packageName, String mimeGroup)1063 public abstract List<String> getMimeGroup(String packageName, String mimeGroup); 1064 1065 /** 1066 * Toggles visibility logging to help in debugging the app enumeration feature. 1067 * @param packageName the package name that should begin logging 1068 * @param enabled true if visibility blocks should be logged 1069 */ setVisibilityLogging(String packageName, boolean enabled)1070 public abstract void setVisibilityLogging(String packageName, boolean enabled); 1071 1072 /** 1073 * Returns if a package name is a valid system package. 1074 */ isSystemPackage(@onNull String packageName)1075 public abstract boolean isSystemPackage(@NonNull String packageName); 1076 1077 /** 1078 * Unblocks uninstall for all packages for the user. 1079 */ clearBlockUninstallForUser(@serIdInt int userId)1080 public abstract void clearBlockUninstallForUser(@UserIdInt int userId); 1081 1082 /** 1083 * Unsuspends all packages suspended by the given package for the user. 1084 */ unsuspendForSuspendingPackage(String suspendingPackage, int userId)1085 public abstract void unsuspendForSuspendingPackage(String suspendingPackage, int userId); 1086 1087 /** 1088 * Returns {@code true} if the package is suspending any packages for the user. 1089 */ isSuspendingAnyPackages(String suspendingPackage, int userId)1090 public abstract boolean isSuspendingAnyPackages(String suspendingPackage, int userId); 1091 1092 /** 1093 * Register to listen for loading progress of an installed package. 1094 * The listener is automatically unregistered when the app is fully loaded. 1095 * @param packageName The name of the installed package 1096 * @param callback To loading reporting progress 1097 * @param userId The user under which to check. 1098 * @return Whether the registration was successful. It can fail if the package has not been 1099 * installed yet. 1100 */ registerInstalledLoadingProgressCallback(@onNull String packageName, @NonNull InstalledLoadingProgressCallback callback, int userId)1101 public abstract boolean registerInstalledLoadingProgressCallback(@NonNull String packageName, 1102 @NonNull InstalledLoadingProgressCallback callback, int userId); 1103 1104 /** 1105 * Callback to listen for loading progress of a package installed on Incremental File System. 1106 */ 1107 public abstract static class InstalledLoadingProgressCallback { 1108 final LoadingProgressCallbackBinder mBinder = new LoadingProgressCallbackBinder(); 1109 final Executor mExecutor; 1110 /** 1111 * Default constructor that should always be called on subclass instantiation 1112 * @param handler To dispatch callback events through. If null, the main thread 1113 * handler will be used. 1114 */ InstalledLoadingProgressCallback(@ullable Handler handler)1115 public InstalledLoadingProgressCallback(@Nullable Handler handler) { 1116 if (handler == null) { 1117 handler = new Handler(Looper.getMainLooper()); 1118 } 1119 mExecutor = new HandlerExecutor(handler); 1120 } 1121 1122 /** 1123 * Binder used by Package Manager Service to register as a callback 1124 * @return the binder object of IPackageLoadingProgressCallback 1125 */ getBinder()1126 public final @NonNull IBinder getBinder() { 1127 return mBinder; 1128 } 1129 1130 /** 1131 * Report loading progress of an installed package. 1132 * 1133 * @param progress Loading progress between [0, 1] for the registered package. 1134 */ onLoadingProgressChanged(float progress)1135 public abstract void onLoadingProgressChanged(float progress); 1136 1137 private class LoadingProgressCallbackBinder extends 1138 android.content.pm.IPackageLoadingProgressCallback.Stub { 1139 @Override onPackageLoadingProgressChanged(float progress)1140 public void onPackageLoadingProgressChanged(float progress) { 1141 mExecutor.execute(PooledLambda.obtainRunnable( 1142 InstalledLoadingProgressCallback::onLoadingProgressChanged, 1143 InstalledLoadingProgressCallback.this, 1144 progress).recycleOnUse()); 1145 } 1146 } 1147 } 1148 1149 /** 1150 * Retrieve all of the information we know about a particular activity class including its 1151 * package states. 1152 * 1153 * @param packageName a specific package 1154 * @param filterCallingUid The results will be filtered in the context of this UID instead 1155 * of the calling UID. 1156 * @param userId The user for whom the package is installed 1157 * @return IncrementalStatesInfo that contains information about package states. 1158 */ getIncrementalStatesInfo(String packageName, int filterCallingUid, int userId)1159 public abstract IncrementalStatesInfo getIncrementalStatesInfo(String packageName, 1160 int filterCallingUid, int userId); 1161 1162 /** 1163 * Requesting the checksums for APKs within a package. 1164 * See {@link PackageManager#requestChecksums} for details. 1165 * 1166 * @param executor to use for digest calculations. 1167 * @param handler to use for postponed calculations. 1168 */ 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)1169 public abstract void requestChecksums(@NonNull String packageName, boolean includeSplits, 1170 @Checksum.TypeMask int optional, @Checksum.TypeMask int required, 1171 @Nullable List trustedInstallers, 1172 @NonNull IOnChecksumsReadyListener onChecksumsReadyListener, int userId, 1173 @NonNull Executor executor, @NonNull Handler handler); 1174 1175 /** 1176 * Returns true if the given {@code packageName} and {@code userId} is frozen. 1177 * 1178 * @param packageName a specific package 1179 * @param callingUid The uid of the caller 1180 * @param userId The user for whom the package is installed 1181 * @return {@code true} If the package is current frozen (due to install/update etc.) 1182 */ isPackageFrozen( @onNull String packageName, int callingUid, int userId)1183 public abstract boolean isPackageFrozen( 1184 @NonNull String packageName, int callingUid, int userId); 1185 1186 /** 1187 * Deletes the OAT artifacts of a package. 1188 * @param packageName a specific package 1189 * @return the number of freed bytes or -1 if there was an error in the process. 1190 */ deleteOatArtifactsOfPackage(String packageName)1191 public abstract long deleteOatArtifactsOfPackage(String packageName); 1192 1193 /** 1194 * Reconcile all app data for the given user. 1195 */ reconcileAppsData(int userId, @StorageManager.StorageFlags int flags, boolean migrateAppsData)1196 public abstract void reconcileAppsData(int userId, @StorageManager.StorageFlags int flags, 1197 boolean migrateAppsData); 1198 1199 /** 1200 * Returns an array of PackageStateInternal that are all part of a shared user setting which is 1201 * denoted by the app ID. Returns an empty set if the shared user setting doesn't exist or does 1202 * not contain any package. 1203 */ 1204 @NonNull getSharedUserPackages(int sharedUserAppId)1205 public abstract ArraySet<PackageStateInternal> getSharedUserPackages(int sharedUserAppId); 1206 1207 /** 1208 * Returns the SharedUserApi denoted by the app ID of the shared user setting. Returns null if 1209 * the corresponding shared user setting doesn't exist. 1210 */ 1211 @Nullable getSharedUserApi(int sharedUserAppId)1212 public abstract SharedUserApi getSharedUserApi(int sharedUserAppId); 1213 1214 /** 1215 * Returns if the given uid is privileged or not. 1216 */ isUidPrivileged(int uid)1217 public abstract boolean isUidPrivileged(int uid); 1218 1219 /** 1220 * Initiates a package state mutation request, returning the current state as known by 1221 * PackageManager. This allows the later commit request to compare the initial values and 1222 * determine if any state was changed or any packages were updated since the whole request 1223 * was initiated. 1224 * 1225 * As a concrete example, consider the following steps: 1226 * <ol> 1227 * <li>Read a package state without taking a lock</li> 1228 * <li>Check some values in that state, determine that a mutation needs to occur</li> 1229 * <li>Call to commit the change with the new value, takes lock</li> 1230 * </ol> 1231 * 1232 * Between steps 1 and 3, because the lock was not taken for the entire flow, it's possible 1233 * a package state was changed by another consumer or a package was updated/installed. 1234 * 1235 * If anything has changed, 1236 * {@link #commitPackageStateMutation(PackageStateMutator.InitialState, Consumer)} will return 1237 * a {@link PackageStateMutator.Result} indicating so. If the caller has not indicated it can 1238 * ignore changes, it can opt to re-run the commit logic from the top with a true write lock 1239 * around all of its read-logic-commit loop. 1240 * 1241 * Note that if the caller does not care about potential race conditions or package/state 1242 * changes between steps 1 and 3, it can simply opt to not call this method and pass in null 1243 * for the initial state. This is useful to avoid long running data structure locks when the 1244 * caller is changing a value as part of a one-off request. Perhaps from an app side API which 1245 * mutates only a single package, where it doesn't care what the state of that package is or 1246 * any other packages on the devices. 1247 * 1248 * Important to note is that if no locking is enforced, callers themselves will not be 1249 * synchronized with themselves. The caller may be relying on the PackageManager lock to 1250 * enforce ordering within their own code path, and that has to be adjusted if migrated off 1251 * the lock. 1252 */ 1253 @NonNull recordInitialState()1254 public abstract PackageStateMutator.InitialState recordInitialState(); 1255 1256 /** 1257 * Some questions to ask when designing a mutation: 1258 * <ol> 1259 * <li>What external system state is required and is it synchronized properly?</li> 1260 * <li>Are there any package/state changes that could happen to the target (or another) 1261 * package that could result in the commit being invalid?</li> 1262 * <li>Is the caller synchronized with itself and can handle multiple mutations being 1263 * requested from different threads?</li> 1264 * <li>What should be done in case of a conflict and the commit can't be finished?</li> 1265 * </ol> 1266 * 1267 * @param state See {@link #recordInitialState()}. If null, no result is returned. 1268 * @param consumer Lean wrapper around just the logic that changes state values 1269 * @return result if anything changed since initial state, or null if nothing changed and 1270 * commit was successful 1271 */ 1272 @Nullable commitPackageStateMutation( @ullable PackageStateMutator.InitialState state, @NonNull Consumer<PackageStateMutator> consumer)1273 public abstract PackageStateMutator.Result commitPackageStateMutation( 1274 @Nullable PackageStateMutator.InitialState state, 1275 @NonNull Consumer<PackageStateMutator> consumer); 1276 1277 /** 1278 * @return package data snapshot for use with other PackageManager infrastructure. This should 1279 * only be used as a parameter passed to another PM related class. Do not call methods on this 1280 * directly. 1281 */ 1282 @NonNull snapshot()1283 public abstract PackageDataSnapshot snapshot(); 1284 shutdown()1285 public abstract void shutdown(); 1286 getDynamicCodeLogger()1287 public abstract DynamicCodeLogger getDynamicCodeLogger(); 1288 } 1289