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