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