Merge "Remove ComputerTracker and fix consistency in PackageManagerService" into tm-dev
This commit is contained in:
commit
35fed17b0e
@ -48,7 +48,6 @@ import com.android.server.pm.PackageSetting;
|
||||
import com.android.server.pm.dex.DynamicCodeLogger;
|
||||
import com.android.server.pm.parsing.pkg.AndroidPackage;
|
||||
import com.android.server.pm.pkg.AndroidPackageApi;
|
||||
import com.android.server.pm.pkg.PackageState;
|
||||
import com.android.server.pm.pkg.PackageStateInternal;
|
||||
import com.android.server.pm.pkg.SharedUserApi;
|
||||
import com.android.server.pm.pkg.component.ParsedMainComponent;
|
||||
@ -690,8 +689,6 @@ public abstract class PackageManagerInternal {
|
||||
@Nullable
|
||||
public abstract PackageStateInternal getPackageStateInternal(@NonNull String packageName);
|
||||
|
||||
public abstract @Nullable PackageState getPackageState(@NonNull String packageName);
|
||||
|
||||
@NonNull
|
||||
public abstract ArrayMap<String, ? extends PackageStateInternal> getPackageStates();
|
||||
|
||||
|
@ -34,6 +34,7 @@ import android.content.Context;
|
||||
import android.content.pm.ApkChecksum;
|
||||
import android.content.pm.Checksum;
|
||||
import android.content.pm.IOnChecksumsReadyListener;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManagerInternal;
|
||||
import android.content.pm.Signature;
|
||||
import android.content.pm.SigningDetails.SignatureSchemeVersion;
|
||||
@ -62,6 +63,7 @@ import android.util.apk.VerityBuilder;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.security.VerityUtils;
|
||||
import com.android.server.LocalServices;
|
||||
import com.android.server.pm.parsing.pkg.AndroidPackage;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
@ -52,6 +52,7 @@ import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.internal.util.function.QuadFunction;
|
||||
import com.android.server.FgThread;
|
||||
import com.android.server.LocalServices;
|
||||
import com.android.server.compat.CompatChange;
|
||||
import com.android.server.om.OverlayReferenceMapper;
|
||||
import com.android.server.pm.parsing.pkg.AndroidPackage;
|
||||
@ -486,12 +487,12 @@ public class AppsFilter implements Watchable, Snappable {
|
||||
}
|
||||
|
||||
/** Builder method for an AppsFilter */
|
||||
public static AppsFilter create(
|
||||
PackageManagerInternal pms, PackageManagerServiceInjector injector) {
|
||||
public static AppsFilter create(@NonNull PackageManagerServiceInjector injector,
|
||||
@NonNull PackageManagerInternal pmInt) {
|
||||
final boolean forceSystemAppsQueryable =
|
||||
injector.getContext().getResources()
|
||||
.getBoolean(R.bool.config_forceSystemPackagesQueryable);
|
||||
final FeatureConfigImpl featureConfig = new FeatureConfigImpl(pms, injector);
|
||||
final FeatureConfigImpl featureConfig = new FeatureConfigImpl(pmInt, injector);
|
||||
final String[] forcedQueryablePackageNames;
|
||||
if (forceSystemAppsQueryable) {
|
||||
// all system apps already queryable, no need to read and parse individual exceptions
|
||||
@ -512,7 +513,7 @@ public class AppsFilter implements Watchable, Snappable {
|
||||
};
|
||||
AppsFilter appsFilter = new AppsFilter(stateProvider, featureConfig,
|
||||
forcedQueryablePackageNames, forceSystemAppsQueryable, null,
|
||||
injector.getBackgroundExecutor(), pms);
|
||||
injector.getBackgroundExecutor(), pmInt);
|
||||
featureConfig.setAppsFilter(appsFilter);
|
||||
return appsFilter;
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ package com.android.server.pm;
|
||||
import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.app.job.JobInfo;
|
||||
import android.app.job.JobParameters;
|
||||
@ -269,7 +270,7 @@ public final class BackgroundDexOptService {
|
||||
PackageManagerService pm = mInjector.getPackageManagerService();
|
||||
ArraySet<String> packagesToOptimize;
|
||||
if (packageNames == null) {
|
||||
packagesToOptimize = mDexOptHelper.getOptimizablePackages();
|
||||
packagesToOptimize = mDexOptHelper.getOptimizablePackages(pm.snapshotComputer());
|
||||
} else {
|
||||
packagesToOptimize = new ArraySet<>(packageNames);
|
||||
}
|
||||
@ -334,7 +335,7 @@ public final class BackgroundDexOptService {
|
||||
return false;
|
||||
}
|
||||
|
||||
ArraySet<String> pkgs = mDexOptHelper.getOptimizablePackages();
|
||||
ArraySet<String> pkgs = mDexOptHelper.getOptimizablePackages(pm.snapshotComputer());
|
||||
if (pkgs.isEmpty()) {
|
||||
Slog.i(TAG, "No packages to optimize");
|
||||
markPostBootUpdateCompleted(params);
|
||||
@ -556,8 +557,8 @@ public final class BackgroundDexOptService {
|
||||
}
|
||||
|
||||
/** Gets the size of a package. */
|
||||
private long getPackageSize(PackageManagerService pm, String pkg) {
|
||||
PackageInfo info = pm.snapshotComputer().getPackageInfo(pkg, 0, UserHandle.USER_SYSTEM);
|
||||
private long getPackageSize(@NonNull Computer snapshot, String pkg) {
|
||||
PackageInfo info = snapshot.getPackageInfo(pkg, 0, UserHandle.USER_SYSTEM);
|
||||
long size = 0;
|
||||
if (info != null && info.applicationInfo != null) {
|
||||
File path = Paths.get(info.applicationInfo.sourceDir).toFile();
|
||||
@ -605,8 +606,9 @@ public final class BackgroundDexOptService {
|
||||
Slog.d(TAG, "Should Downgrade " + shouldDowngrade);
|
||||
}
|
||||
if (shouldDowngrade) {
|
||||
final Computer snapshot = pm.snapshotComputer();
|
||||
Set<String> unusedPackages =
|
||||
pm.getUnusedPackages(mDowngradeUnusedAppsThresholdInMillis);
|
||||
snapshot.getUnusedPackages(mDowngradeUnusedAppsThresholdInMillis);
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "Unsused Packages " + String.join(",", unusedPackages));
|
||||
}
|
||||
@ -618,7 +620,7 @@ public final class BackgroundDexOptService {
|
||||
// Should be aborted by the scheduler.
|
||||
return abortCode;
|
||||
}
|
||||
@DexOptResult int downgradeResult = downgradePackage(pm, pkg,
|
||||
@DexOptResult int downgradeResult = downgradePackage(snapshot, pm, pkg,
|
||||
/* isForPrimaryDex= */ true, isPostBootUpdate);
|
||||
if (downgradeResult == PackageDexOptimizer.DEX_OPT_PERFORMED) {
|
||||
updatedPackages.add(pkg);
|
||||
@ -629,7 +631,7 @@ public final class BackgroundDexOptService {
|
||||
return status;
|
||||
}
|
||||
if (supportSecondaryDex) {
|
||||
downgradeResult = downgradePackage(pm, pkg,
|
||||
downgradeResult = downgradePackage(snapshot, pm, pkg,
|
||||
/* isForPrimaryDex= */false, isPostBootUpdate);
|
||||
status = convertPackageDexOptimizerStatusToInternal(downgradeResult);
|
||||
if (status != STATUS_OK) {
|
||||
@ -696,8 +698,8 @@ public final class BackgroundDexOptService {
|
||||
* @return PackageDexOptimizer.DEX_*
|
||||
*/
|
||||
@DexOptResult
|
||||
private int downgradePackage(PackageManagerService pm, String pkg, boolean isForPrimaryDex,
|
||||
boolean isPostBootUpdate) {
|
||||
private int downgradePackage(@NonNull Computer snapshot, PackageManagerService pm, String pkg,
|
||||
boolean isForPrimaryDex, boolean isPostBootUpdate) {
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "Downgrading " + pkg);
|
||||
}
|
||||
@ -709,15 +711,15 @@ public final class BackgroundDexOptService {
|
||||
if (!isPostBootUpdate) {
|
||||
dexoptFlags |= DexoptOptions.DEXOPT_IDLE_BACKGROUND_JOB;
|
||||
}
|
||||
long package_size_before = getPackageSize(pm, pkg);
|
||||
long package_size_before = getPackageSize(snapshot, pkg);
|
||||
int result = PackageDexOptimizer.DEX_OPT_SKIPPED;
|
||||
if (isForPrimaryDex || PLATFORM_PACKAGE_NAME.equals(pkg)) {
|
||||
// This applies for system apps or if packages location is not a directory, i.e.
|
||||
// monolithic install.
|
||||
if (!pm.canHaveOatDir(pkg)) {
|
||||
if (!pm.canHaveOatDir(snapshot, pkg)) {
|
||||
// For apps that don't have the oat directory, instead of downgrading,
|
||||
// remove their compiler artifacts from dalvik cache.
|
||||
pm.deleteOatArtifactsOfPackage(pkg);
|
||||
pm.deleteOatArtifactsOfPackage(snapshot, pkg);
|
||||
} else {
|
||||
result = performDexOptPrimary(pkg, reason, dexoptFlags);
|
||||
}
|
||||
@ -726,8 +728,9 @@ public final class BackgroundDexOptService {
|
||||
}
|
||||
|
||||
if (result == PackageDexOptimizer.DEX_OPT_PERFORMED) {
|
||||
final Computer newSnapshot = pm.snapshotComputer();
|
||||
FrameworkStatsLog.write(FrameworkStatsLog.APP_DOWNGRADED, pkg, package_size_before,
|
||||
getPackageSize(pm, pkg), /*aggressive=*/ false);
|
||||
getPackageSize(newSnapshot, pkg), /*aggressive=*/ false);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -58,10 +58,6 @@ import com.android.server.utils.WatchedLongSparseArray;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@ -92,92 +88,69 @@ import java.util.Set;
|
||||
* and other managers (like PermissionManager) mean deadlock is possible. On the
|
||||
* other hand, not overriding in {@link ComputerLocked} may leave a function walking
|
||||
* unstable data.
|
||||
*
|
||||
* To coax developers to consider such issues carefully, all methods in
|
||||
* {@link Computer} must be annotated with <code>@LiveImplementation(override =
|
||||
* MANDATORY)</code> or <code>LiveImplementation(locked = NOT_ALLOWED)</code>. A unit
|
||||
* test verifies the annotation and that the annotation corresponds to the code in
|
||||
* {@link ComputerEngine} and {@link ComputerLocked}.
|
||||
*/
|
||||
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
|
||||
public interface Computer extends PackageDataSnapshot {
|
||||
|
||||
/**
|
||||
* Every method must be annotated.
|
||||
*/
|
||||
@Target({ ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface LiveImplementation {
|
||||
// A Computer method must be annotated with one of the following values:
|
||||
// MANDATORY - the method must be overridden in ComputerEngineLive. The
|
||||
// format of the override is a call to the super method, wrapped in a
|
||||
// synchronization block.
|
||||
// NOT_ALLOWED - the method may not appear in the live computer. It must
|
||||
// be final in the ComputerEngine.
|
||||
int MANDATORY = 1;
|
||||
int NOT_ALLOWED = 2;
|
||||
int override() default MANDATORY;
|
||||
String rationale() default "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Administrative statistics: record that the snapshot has been used. Every call
|
||||
* to use() increments the usage counter.
|
||||
*/
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
default void use() {
|
||||
}
|
||||
/**
|
||||
* Fetch the snapshot usage counter.
|
||||
* @return The number of times this snapshot was used.
|
||||
*/
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
default int getUsed() {
|
||||
return 0;
|
||||
}
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
@NonNull List<ResolveInfo> queryIntentActivitiesInternal(Intent intent, String resolvedType,
|
||||
@PackageManager.ResolveInfoFlagsBits long flags,
|
||||
@PackageManagerInternal.PrivateResolveFlags long privateResolveFlags,
|
||||
int filterCallingUid, int userId, boolean resolveForStart, boolean allowDynamicSplits);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
@NonNull List<ResolveInfo> queryIntentActivitiesInternal(Intent intent, String resolvedType,
|
||||
long flags, int userId);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
@NonNull List<ResolveInfo> queryIntentServicesInternal(Intent intent, String resolvedType,
|
||||
long flags, int userId, int callingUid, boolean includeInstantApps);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.MANDATORY)
|
||||
@NonNull QueryIntentActivitiesResult queryIntentActivitiesInternalBody(Intent intent,
|
||||
String resolvedType, long flags, int filterCallingUid, int userId,
|
||||
boolean resolveForStart, boolean allowDynamicSplits, String pkgName,
|
||||
String instantAppPkgName);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
ActivityInfo getActivityInfo(ComponentName component, long flags, int userId);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
|
||||
/**
|
||||
* Important: The provided filterCallingUid is used exclusively to filter out activities
|
||||
* that can be seen based on user state. It's typically the original caller uid prior
|
||||
* to clearing. Because it can only be provided by trusted code, its value can be
|
||||
* trusted and will be used as-is; unlike userId which will be validated by this method.
|
||||
*/
|
||||
ActivityInfo getActivityInfoInternal(ComponentName component, long flags,
|
||||
int filterCallingUid, int userId);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.MANDATORY)
|
||||
AndroidPackage getPackage(String packageName);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.MANDATORY)
|
||||
AndroidPackage getPackage(int uid);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
ApplicationInfo generateApplicationInfoFromSettings(String packageName, long flags,
|
||||
int filterCallingUid, int userId);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
ApplicationInfo getApplicationInfo(String packageName, long flags, int userId);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
|
||||
/**
|
||||
* Important: The provided filterCallingUid is used exclusively to filter out applications
|
||||
* that can be seen based on user state. It's typically the original caller uid prior
|
||||
* to clearing. Because it can only be provided by trusted code, its value can be
|
||||
* trusted and will be used as-is; unlike userId which will be validated by this method.
|
||||
*/
|
||||
ApplicationInfo getApplicationInfoInternal(String packageName, long flags,
|
||||
int filterCallingUid, int userId);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
|
||||
/**
|
||||
* Report the 'Home' activity which is currently set as "always use this one". If non is set
|
||||
* then reports the most likely home activity or null if there are more than one.
|
||||
*/
|
||||
ComponentName getDefaultHomeActivity(int userId);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
ComponentName getHomeActivitiesAsUser(List<ResolveInfo> allHomeCandidates, int userId);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
CrossProfileDomainInfo getCrossProfileDomainPreferredLpr(Intent intent, String resolvedType,
|
||||
long flags, int sourceUserId, int parentUserId);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
Intent getHomeIntent();
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
List<CrossProfileIntentFilter> getMatchingCrossProfileIntentFilters(Intent intent,
|
||||
String resolvedType, int userId);
|
||||
|
||||
@ -192,15 +165,11 @@ public interface Computer extends PackageDataSnapshot {
|
||||
* @param intent
|
||||
* @return A filtered list of resolved activities.
|
||||
*/
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
List<ResolveInfo> applyPostResolutionFilter(@NonNull List<ResolveInfo> resolveInfos,
|
||||
String ephemeralPkgName, boolean allowDynamicSplits, int filterCallingUid,
|
||||
boolean resolveForStart, int userId, Intent intent);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
PackageInfo generatePackageInfo(PackageStateInternal ps, long flags, int userId);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
PackageInfo getPackageInfo(String packageName, long flags, int userId);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
PackageInfo getPackageInfoInternal(String packageName, long versionCode, long flags,
|
||||
int filterCallingUid, int userId);
|
||||
|
||||
@ -209,79 +178,69 @@ public interface Computer extends PackageDataSnapshot {
|
||||
* known {@link PackageState} instances without a {@link PackageState#getAndroidPackage()}
|
||||
* will not be represented.
|
||||
*/
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.MANDATORY)
|
||||
String[] getAllAvailablePackageNames();
|
||||
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
PackageStateInternal getPackageStateInternal(String packageName);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.MANDATORY)
|
||||
PackageStateInternal getPackageStateInternal(String packageName, int callingUid);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.MANDATORY)
|
||||
@Nullable PackageState getPackageStateCopied(@NonNull String packageName);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
ParceledListSlice<PackageInfo> getInstalledPackages(long flags, int userId);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
ResolveInfo createForwardingResolveInfoUnchecked(WatchedIntentFilter filter,
|
||||
int sourceUserId, int targetUserId);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
ServiceInfo getServiceInfo(ComponentName component, long flags, int userId);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
SharedLibraryInfo getSharedLibraryInfo(String name, long version);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.MANDATORY)
|
||||
String getInstantAppPackageName(int callingUid);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
String resolveExternalPackageName(AndroidPackage pkg);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
String resolveInternalPackageName(String packageName, long versionCode);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
String[] getPackagesForUid(int uid);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
UserInfo getProfileParent(int userId);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
boolean canViewInstantApps(int callingUid, int userId);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
boolean filterSharedLibPackage(@Nullable PackageStateInternal ps, int uid, int userId,
|
||||
long flags);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
boolean isCallerSameApp(String packageName, int uid);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
boolean isComponentVisibleToInstantApp(@Nullable ComponentName component);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
boolean isComponentVisibleToInstantApp(@Nullable ComponentName component,
|
||||
@PackageManager.ComponentType int type);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
boolean isImplicitImageCaptureIntentAndNotSetByDpcLocked(Intent intent, int userId,
|
||||
|
||||
/**
|
||||
* From Android R, camera intents have to match system apps. The only exception to this is if
|
||||
* the DPC has set the camera persistent preferred activity. This case was introduced
|
||||
* because it is important that the DPC has the ability to set both system and non-system
|
||||
* camera persistent preferred activities.
|
||||
*
|
||||
* @return {@code true} if the intent is a camera intent and the persistent preferred
|
||||
* activity was not set by the DPC.
|
||||
*/
|
||||
boolean isImplicitImageCaptureIntentAndNotSetByDpc(Intent intent, int userId,
|
||||
String resolvedType, long flags);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
boolean isInstantApp(String packageName, int userId);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
boolean isInstantAppInternal(String packageName, @UserIdInt int userId, int callingUid);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
boolean isSameProfileGroup(@UserIdInt int callerUserId, @UserIdInt int userId);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
boolean shouldFilterApplication(@Nullable PackageStateInternal ps, int callingUid,
|
||||
@Nullable ComponentName component, @PackageManager.ComponentType int componentType,
|
||||
int userId);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
boolean shouldFilterApplication(@Nullable PackageStateInternal ps, int callingUid,
|
||||
int userId);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
boolean shouldFilterApplication(@NonNull SharedUserSetting sus, int callingUid,
|
||||
int userId);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
int checkUidPermission(String permName, int uid);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.MANDATORY)
|
||||
int getPackageUidInternal(String packageName, long flags, int userId, int callingUid);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
long updateFlagsForApplication(long flags, int userId);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
long updateFlagsForComponent(long flags, int userId);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
long updateFlagsForPackage(long flags, int userId);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
|
||||
/**
|
||||
* Update given flags when being used to request {@link ResolveInfo}.
|
||||
* <p>Instant apps are resolved specially, depending upon context. Minimally,
|
||||
* {@code}flags{@code} must have the {@link PackageManager#MATCH_INSTANT}
|
||||
* flag set. However, this flag is only honoured in three circumstances:
|
||||
* <ul>
|
||||
* <li>when called from a system process</li>
|
||||
* <li>when the caller holds the permission {@code android.permission.ACCESS_INSTANT_APPS}</li>
|
||||
* <li>when resolution occurs to start an activity with a {@code android.intent.action.VIEW}
|
||||
* action and a {@code android.intent.category.BROWSABLE} category</li>
|
||||
* </ul>
|
||||
*/
|
||||
long updateFlagsForResolve(long flags, int userId, int callingUid, boolean wantInstantApps,
|
||||
boolean isImplicitImageCaptureIntentAndNotSetByDpc);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
long updateFlagsForResolve(long flags, int userId, int callingUid, boolean wantInstantApps,
|
||||
boolean onlyExposedExplicitly, boolean isImplicitImageCaptureIntentAndNotSetByDpc);
|
||||
|
||||
@ -299,117 +258,99 @@ public interface Computer extends PackageDataSnapshot {
|
||||
* @param checkShell whether to prevent shell from access if there's a debugging restriction
|
||||
* @param message the message to log on security exception
|
||||
*/
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
void enforceCrossUserOrProfilePermission(int callingUid, @UserIdInt int userId,
|
||||
boolean requireFullPermission, boolean checkShell, String message);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
|
||||
/**
|
||||
* Enforces the request is from the system or an app that has INTERACT_ACROSS_USERS
|
||||
* or INTERACT_ACROSS_USERS_FULL permissions, if the {@code userId} is not for the caller.
|
||||
*
|
||||
* @param checkShell whether to prevent shell from access if there's a debugging restriction
|
||||
* @param message the message to log on security exception
|
||||
*/
|
||||
void enforceCrossUserPermission(int callingUid, @UserIdInt int userId,
|
||||
boolean requireFullPermission, boolean checkShell, String message);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
void enforceCrossUserPermission(int callingUid, @UserIdInt int userId,
|
||||
boolean requireFullPermission, boolean checkShell,
|
||||
boolean requirePermissionWhenSameUser, String message);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.MANDATORY)
|
||||
SigningDetails getSigningDetails(@NonNull String packageName);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.MANDATORY)
|
||||
SigningDetails getSigningDetails(int uid);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.MANDATORY)
|
||||
boolean filterAppAccess(AndroidPackage pkg, int callingUid, int userId);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.MANDATORY)
|
||||
boolean filterAppAccess(String packageName, int callingUid, int userId);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.MANDATORY)
|
||||
boolean filterAppAccess(int uid, int callingUid);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.MANDATORY)
|
||||
void dump(int type, FileDescriptor fd, PrintWriter pw, DumpState dumpState);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
PackageManagerService.FindPreferredActivityBodyResult findPreferredActivityInternal(
|
||||
Intent intent, String resolvedType, long flags, List<ResolveInfo> query, boolean always,
|
||||
boolean removeMatches, boolean debug, int userId, boolean queryMayBeFiltered);
|
||||
@Computer.LiveImplementation(override = Computer.LiveImplementation.NOT_ALLOWED)
|
||||
ResolveInfo findPersistentPreferredActivityLP(Intent intent, String resolvedType, long flags,
|
||||
ResolveInfo findPersistentPreferredActivity(Intent intent, String resolvedType, long flags,
|
||||
List<ResolveInfo> query, boolean debug, int userId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
PreferredIntentResolver getPreferredActivities(@UserIdInt int userId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@NonNull
|
||||
ArrayMap<String, ? extends PackageStateInternal> getPackageStates();
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@Nullable
|
||||
String getRenamedPackage(@NonNull String packageName);
|
||||
|
||||
/**
|
||||
* @return set of packages to notify
|
||||
*/
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@NonNull
|
||||
ArraySet<String> getNotifyPackagesForReplacedReceived(@NonNull String[] packages);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@PackageManagerService.PackageStartability
|
||||
int getPackageStartability(boolean safeMode, @NonNull String packageName, int callingUid,
|
||||
@UserIdInt int userId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
boolean isPackageAvailable(String packageName, @UserIdInt int userId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@NonNull
|
||||
String[] currentToCanonicalPackageNames(@NonNull String[] names);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@NonNull
|
||||
String[] canonicalToCurrentPackageNames(@NonNull String[] names);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@NonNull
|
||||
int[] getPackageGids(@NonNull String packageName,
|
||||
@PackageManager.PackageInfoFlagsBits long flags, @UserIdInt int userId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
int getTargetSdkVersion(@NonNull String packageName);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
boolean activitySupportsIntent(@NonNull ComponentName resolveComponentName,
|
||||
@NonNull ComponentName component, @NonNull Intent intent, String resolvedType);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@Nullable
|
||||
ActivityInfo getReceiverInfo(@NonNull ComponentName component,
|
||||
@PackageManager.ComponentInfoFlagsBits long flags, @UserIdInt int userId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@Nullable
|
||||
ParceledListSlice<SharedLibraryInfo> getSharedLibraries(@NonNull String packageName,
|
||||
@PackageManager.PackageInfoFlagsBits long flags, @UserIdInt int userId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
boolean canRequestPackageInstalls(@NonNull String packageName, int callingUid,
|
||||
int userId, boolean throwIfPermNotDeclared);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.NOT_ALLOWED)
|
||||
/**
|
||||
* Returns true if the system or user is explicitly preventing an otherwise valid installer to
|
||||
* complete an install. This includes checks like unknown sources and user restrictions.
|
||||
*/
|
||||
boolean isInstallDisabledForPackage(@NonNull String packageName, int uid,
|
||||
@UserIdInt int userId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@Nullable
|
||||
List<VersionedPackage> getPackagesUsingSharedLibrary(@NonNull SharedLibraryInfo libInfo,
|
||||
@PackageManager.PackageInfoFlagsBits long flags, int callingUid, @UserIdInt int userId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@Nullable
|
||||
ParceledListSlice<SharedLibraryInfo> getDeclaredSharedLibraries(
|
||||
@NonNull String packageName, @PackageManager.PackageInfoFlagsBits long flags,
|
||||
@UserIdInt int userId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@Nullable
|
||||
ProviderInfo getProviderInfo(@NonNull ComponentName component,
|
||||
@PackageManager.ComponentInfoFlagsBits long flags, @UserIdInt int userId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@Nullable
|
||||
String[] getSystemSharedLibraryNames();
|
||||
|
||||
@ -417,136 +358,103 @@ public interface Computer extends PackageDataSnapshot {
|
||||
* @return the state if the given package has a state and isn't filtered by visibility.
|
||||
* Provides no guarantee that the package is in any usable state.
|
||||
*/
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@Nullable
|
||||
PackageStateInternal getPackageStateFiltered(@NonNull String packageName, int callingUid,
|
||||
@UserIdInt int userId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
int checkSignatures(@NonNull String pkg1, @NonNull String pkg2);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
int checkUidSignatures(int uid1, int uid2);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
boolean hasSigningCertificate(@NonNull String packageName, @NonNull byte[] certificate,
|
||||
@PackageManager.CertificateInputType int type);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
boolean hasUidSigningCertificate(int uid, @NonNull byte[] certificate,
|
||||
@PackageManager.CertificateInputType int type);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@NonNull
|
||||
List<String> getAllPackages();
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@Nullable
|
||||
String getNameForUid(int uid);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@Nullable
|
||||
String[] getNamesForUids(@NonNull int[] uids);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
int getUidForSharedUser(@NonNull String sharedUserName);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
int getFlagsForUid(int uid);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
int getPrivateFlagsForUid(int uid);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
boolean isUidPrivileged(int uid);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@NonNull
|
||||
String[] getAppOpPermissionPackages(@NonNull String permissionName);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@NonNull
|
||||
ParceledListSlice<PackageInfo> getPackagesHoldingPermissions(@NonNull String[] permissions,
|
||||
@PackageManager.PackageInfoFlagsBits long flags, @UserIdInt int userId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@NonNull
|
||||
List<ApplicationInfo> getInstalledApplications(
|
||||
@PackageManager.ApplicationInfoFlagsBits long flags, @UserIdInt int userId,
|
||||
int callingUid);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@Nullable
|
||||
ProviderInfo resolveContentProvider(@NonNull String name,
|
||||
@PackageManager.ResolveInfoFlagsBits long flags, @UserIdInt int userId, int callingUid);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@Nullable
|
||||
ProviderInfo getGrantImplicitAccessProviderInfo(int recipientUid,
|
||||
@NonNull String visibleAuthority);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
void querySyncProviders(boolean safeMode, @NonNull List<String> outNames,
|
||||
@NonNull List<ProviderInfo> outInfo);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@NonNull
|
||||
ParceledListSlice<ProviderInfo> queryContentProviders(@Nullable String processName, int uid,
|
||||
@PackageManager.ComponentInfoFlagsBits long flags, @Nullable String metaDataKey);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@Nullable
|
||||
InstrumentationInfo getInstrumentationInfo(@NonNull ComponentName component, int flags);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@NonNull
|
||||
ParceledListSlice<InstrumentationInfo> queryInstrumentation(
|
||||
@NonNull String targetPackage, int flags);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@NonNull
|
||||
List<PackageStateInternal> findSharedNonSystemLibraries(
|
||||
@NonNull PackageStateInternal pkgSetting);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
boolean getApplicationHiddenSettingAsUser(@NonNull String packageName, @UserIdInt int userId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
boolean isPackageSuspendedForUser(@NonNull String packageName, @UserIdInt int userId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
boolean isSuspendingAnyPackages(@NonNull String suspendingPackage, @UserIdInt int userId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@NonNull
|
||||
ParceledListSlice<IntentFilter> getAllIntentFilters(@NonNull String packageName);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
boolean getBlockUninstallForUser(@NonNull String packageName, @UserIdInt int userId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@Nullable
|
||||
SparseArray<int[]> getBroadcastAllowList(@NonNull String packageName, @UserIdInt int[] userIds,
|
||||
boolean isInstantApp);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@Nullable
|
||||
String getInstallerPackageName(@NonNull String packageName);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@Nullable
|
||||
InstallSourceInfo getInstallSourceInfo(@NonNull String packageName);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@PackageManager.EnabledState
|
||||
int getApplicationEnabledSetting(@NonNull String packageName, @UserIdInt int userId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@PackageManager.EnabledState
|
||||
int getComponentEnabledSetting(@NonNull ComponentName component, int callingUid,
|
||||
@UserIdInt int userId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@PackageManager.EnabledState
|
||||
int getComponentEnabledSettingInternal(@NonNull ComponentName component, int callingUid,
|
||||
@UserIdInt int userId);
|
||||
@ -557,25 +465,19 @@ public interface Computer extends PackageDataSnapshot {
|
||||
* are all effectively enabled for the given component. Or if the component cannot be found,
|
||||
* returns false.
|
||||
*/
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
boolean isComponentEffectivelyEnabled(@NonNull ComponentInfo componentInfo,
|
||||
@UserIdInt int userId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@Nullable
|
||||
KeySet getKeySetByAlias(@NonNull String packageName, @NonNull String alias);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@Nullable
|
||||
KeySet getSigningKeySet(@NonNull String packageName);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
boolean isPackageSignedByKeySet(@NonNull String packageName, @NonNull KeySet ks);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
boolean isPackageSignedByKeySetExactly(@NonNull String packageName, @NonNull KeySet ks);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@Nullable
|
||||
int[] getVisibilityAllowList(@NonNull String packageName, @UserIdInt int userId);
|
||||
|
||||
@ -585,49 +487,37 @@ public interface Computer extends PackageDataSnapshot {
|
||||
* package visibility filtering is enabled on it. If the UID is part of a shared user ID,
|
||||
* return {@code true} if any one application belongs to the shared user ID meets the criteria.
|
||||
*/
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
boolean canQueryPackage(int callingUid, @Nullable String targetPackageName);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
int getPackageUid(@NonNull String packageName, @PackageManager.PackageInfoFlagsBits long flags,
|
||||
@UserIdInt int userId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
boolean canAccessComponent(int callingUid, @NonNull ComponentName component,
|
||||
@UserIdInt int userId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
boolean isCallerInstallerOfRecord(@NonNull AndroidPackage pkg, int callingUid);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@PackageManager.InstallReason
|
||||
int getInstallReason(@NonNull String packageName, @UserIdInt int userId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
boolean canPackageQuery(@NonNull String sourcePackageName, @NonNull String targetPackageName,
|
||||
@UserIdInt int userId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
boolean canForwardTo(@NonNull Intent intent, @Nullable String resolvedType,
|
||||
@UserIdInt int sourceUserId, @UserIdInt int targetUserId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@NonNull
|
||||
List<ApplicationInfo> getPersistentApplications(boolean safeMode, int flags);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@NonNull
|
||||
SparseArray<String> getAppsWithSharedUserIds();
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@NonNull
|
||||
String[] getSharedUserPackagesForPackage(@NonNull String packageName, @UserIdInt int userId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@NonNull
|
||||
Set<String> getUnusedPackages(long downgradeTimeThresholdMillis);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@Nullable
|
||||
CharSequence getHarmfulAppWarning(@NonNull String packageName, @UserIdInt int userId);
|
||||
|
||||
@ -638,55 +528,49 @@ public interface Computer extends PackageDataSnapshot {
|
||||
*
|
||||
* @return The filtered packages
|
||||
*/
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@NonNull
|
||||
String[] filterOnlySystemPackages(@Nullable String... pkgNames);
|
||||
|
||||
// The methods in this block should be removed once SettingBase is interface snapshotted
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@NonNull
|
||||
List<AndroidPackage> getPackagesForAppId(int appId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
int getUidTargetSdkVersion(int uid);
|
||||
|
||||
/**
|
||||
* @see PackageManagerInternal#getProcessesForUid(int)
|
||||
*/
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@Nullable
|
||||
ArrayMap<String, ProcessInfo> getProcessesForUid(int uid);
|
||||
// End block
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
boolean getBlockUninstall(@UserIdInt int userId, @NonNull String packageName);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@NonNull
|
||||
WatchedArrayMap<String, WatchedLongSparseArray<SharedLibraryInfo>> getSharedLibraries();
|
||||
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@Nullable
|
||||
Pair<PackageStateInternal, SharedUserApi> getPackageOrSharedUser(int appId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@Nullable
|
||||
SharedUserApi getSharedUser(int sharedUserAppIde);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@NonNull
|
||||
ArraySet<PackageStateInternal> getSharedUserPackages(int sharedUserAppId);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@NonNull
|
||||
ComponentResolverApi getComponentResolver();
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@Nullable
|
||||
PackageStateInternal getDisabledSystemPackage(@NonNull String packageName);
|
||||
|
||||
@Computer.LiveImplementation(override = LiveImplementation.MANDATORY)
|
||||
@Nullable
|
||||
ResolveInfo getInstantAppInstallerInfo();
|
||||
|
||||
@NonNull
|
||||
WatchedArrayMap<String, Integer> getFrozenPackages();
|
||||
|
||||
@Nullable
|
||||
ComponentName getInstantAppInstallerComponent();
|
||||
}
|
||||
|
@ -466,7 +466,7 @@ public class ComputerEngine implements Computer {
|
||||
|
||||
flags = updateFlagsForResolve(flags, userId, filterCallingUid, resolveForStart,
|
||||
comp != null || pkgName != null /*onlyExposedExplicitly*/,
|
||||
isImplicitImageCaptureIntentAndNotSetByDpcLocked(intent, userId, resolvedType,
|
||||
isImplicitImageCaptureIntentAndNotSetByDpc(intent, userId, resolvedType,
|
||||
flags));
|
||||
List<ResolveInfo> list = Collections.emptyList();
|
||||
boolean skipPostResolution = false;
|
||||
@ -1722,15 +1722,6 @@ public class ComputerEngine implements Computer {
|
||||
return mSettings.getPackage(packageName);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PackageState getPackageStateCopied(@NonNull String packageName) {
|
||||
int callingUid = Binder.getCallingUid();
|
||||
packageName = resolveInternalPackageNameInternalLocked(
|
||||
packageName, PackageManager.VERSION_CODE_HIGHEST, callingUid);
|
||||
PackageStateInternal pkgSetting = mSettings.getPackage(packageName);
|
||||
return pkgSetting == null ? null : PackageStateImpl.copy(pkgSetting);
|
||||
}
|
||||
|
||||
public final ParceledListSlice<PackageInfo> getInstalledPackages(long flags, int userId) {
|
||||
final int callingUid = Binder.getCallingUid();
|
||||
if (getInstantAppPackageName(callingUid) != null) {
|
||||
@ -2468,7 +2459,7 @@ public class ComputerEngine implements Computer {
|
||||
* @return {@code true} if the intent is a camera intent and the persistent preferred
|
||||
* activity was not set by the DPC.
|
||||
*/
|
||||
public final boolean isImplicitImageCaptureIntentAndNotSetByDpcLocked(Intent intent,
|
||||
public final boolean isImplicitImageCaptureIntentAndNotSetByDpc(Intent intent,
|
||||
int userId, String resolvedType, @PackageManager.ResolveInfoFlagsBits long flags) {
|
||||
return intent.isImplicitImageCaptureIntent() && !isPersistentPreferredActivitySetByDpm(
|
||||
intent, userId, resolvedType, flags);
|
||||
@ -3228,12 +3219,12 @@ public class ComputerEngine implements Computer {
|
||||
|
||||
flags = updateFlagsForResolve(
|
||||
flags, userId, callingUid, false /*includeInstantApps*/,
|
||||
isImplicitImageCaptureIntentAndNotSetByDpcLocked(intent, userId,
|
||||
isImplicitImageCaptureIntentAndNotSetByDpc(intent, userId,
|
||||
resolvedType, flags));
|
||||
intent = PackageManagerServiceUtils.updateIntentForResolve(intent);
|
||||
|
||||
// Try to find a matching persistent preferred activity.
|
||||
result.mPreferredResolveInfo = findPersistentPreferredActivityLP(intent,
|
||||
result.mPreferredResolveInfo = findPersistentPreferredActivity(intent,
|
||||
resolvedType, flags, query, debug, userId);
|
||||
|
||||
// If a persistent preferred activity matched, use it.
|
||||
@ -3444,7 +3435,7 @@ public class ComputerEngine implements Computer {
|
||||
userId, queryMayBeFiltered, callingUid, isDeviceProvisioned);
|
||||
}
|
||||
|
||||
public final ResolveInfo findPersistentPreferredActivityLP(Intent intent,
|
||||
public final ResolveInfo findPersistentPreferredActivity(Intent intent,
|
||||
String resolvedType, @PackageManager.ResolveInfoFlagsBits long flags,
|
||||
List<ResolveInfo> query, boolean debug, int userId) {
|
||||
final int n = query.size();
|
||||
@ -5418,7 +5409,7 @@ public class ComputerEngine implements Computer {
|
||||
}
|
||||
long flags = updateFlagsForResolve(0, parent.id, callingUid,
|
||||
false /*includeInstantApps*/,
|
||||
isImplicitImageCaptureIntentAndNotSetByDpcLocked(intent, parent.id,
|
||||
isImplicitImageCaptureIntentAndNotSetByDpc(intent, parent.id,
|
||||
resolvedType, 0));
|
||||
flags |= PackageManager.MATCH_DEFAULT_ONLY;
|
||||
CrossProfileDomainInfo xpDomainInfo = getCrossProfileDomainPreferredLpr(
|
||||
@ -5694,4 +5685,17 @@ public class ComputerEngine implements Computer {
|
||||
public ResolveInfo getInstantAppInstallerInfo() {
|
||||
return mInstantAppInstallerInfo;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public WatchedArrayMap<String, Integer> getFrozenPackages() {
|
||||
return mFrozenPackages;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ComponentName getInstantAppInstallerComponent() {
|
||||
return mLocalInstantAppInstallerActivity == null
|
||||
? null : mLocalInstantAppInstallerActivity.getComponentName();
|
||||
}
|
||||
}
|
||||
|
@ -16,62 +16,21 @@
|
||||
|
||||
package com.android.server.pm;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.UserIdInt;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.ComponentInfo;
|
||||
import android.content.pm.InstallSourceInfo;
|
||||
import android.content.pm.InstrumentationInfo;
|
||||
import android.content.pm.KeySet;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ParceledListSlice;
|
||||
import android.content.pm.ProcessInfo;
|
||||
import android.content.pm.ProviderInfo;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.content.pm.SharedLibraryInfo;
|
||||
import android.content.pm.SigningDetails;
|
||||
import android.content.pm.VersionedPackage;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.ArraySet;
|
||||
import android.util.Pair;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.server.pm.parsing.pkg.AndroidPackage;
|
||||
import com.android.server.pm.pkg.PackageState;
|
||||
import com.android.server.pm.pkg.PackageStateInternal;
|
||||
import com.android.server.pm.pkg.SharedUserApi;
|
||||
import com.android.server.pm.resolution.ComponentResolverApi;
|
||||
import com.android.server.utils.WatchedArrayMap;
|
||||
import com.android.server.utils.WatchedLongSparseArray;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* This subclass is the external interface to the live computer. Some internal helper
|
||||
* methods are overridden to fetch live data instead of snapshot data. For each
|
||||
* Computer interface that is overridden in this class, the override takes the PM lock
|
||||
* and then delegates to the live computer engine. This is required because there are
|
||||
* no locks taken in the engine itself.
|
||||
* methods are overridden to fetch live data instead of snapshot data.
|
||||
*/
|
||||
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
|
||||
public final class ComputerLocked extends ComputerEngine {
|
||||
private final Object mLock;
|
||||
|
||||
ComputerLocked(PackageManagerService.Snapshot args) {
|
||||
super(args);
|
||||
mLock = mService.mLock;
|
||||
}
|
||||
|
||||
protected ComponentName resolveComponentName() {
|
||||
@ -83,814 +42,4 @@ public final class ComputerLocked extends ComputerEngine {
|
||||
protected ApplicationInfo androidApplication() {
|
||||
return mService.getCoreAndroidApplication();
|
||||
}
|
||||
|
||||
public @NonNull List<ResolveInfo> queryIntentServicesInternalBody(Intent intent,
|
||||
String resolvedType, int flags, int userId, int callingUid,
|
||||
String instantAppPkgName) {
|
||||
synchronized (mLock) {
|
||||
return super.queryIntentServicesInternalBody(intent, resolvedType, flags, userId,
|
||||
callingUid, instantAppPkgName);
|
||||
}
|
||||
}
|
||||
public @NonNull QueryIntentActivitiesResult queryIntentActivitiesInternalBody(
|
||||
Intent intent, String resolvedType, long flags, int filterCallingUid, int userId,
|
||||
boolean resolveForStart, boolean allowDynamicSplits, String pkgName,
|
||||
String instantAppPkgName) {
|
||||
synchronized (mLock) {
|
||||
return super.queryIntentActivitiesInternalBody(intent, resolvedType, flags,
|
||||
filterCallingUid, userId, resolveForStart, allowDynamicSplits, pkgName,
|
||||
instantAppPkgName);
|
||||
}
|
||||
}
|
||||
public ActivityInfo getActivityInfoInternalBody(ComponentName component, int flags,
|
||||
int filterCallingUid, int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.getActivityInfoInternalBody(component, flags, filterCallingUid,
|
||||
userId);
|
||||
}
|
||||
}
|
||||
public AndroidPackage getPackage(String packageName) {
|
||||
synchronized (mLock) {
|
||||
return super.getPackage(packageName);
|
||||
}
|
||||
}
|
||||
public AndroidPackage getPackage(int uid) {
|
||||
synchronized (mLock) {
|
||||
return super.getPackage(uid);
|
||||
}
|
||||
}
|
||||
public ApplicationInfo getApplicationInfoInternalBody(String packageName, int flags,
|
||||
int filterCallingUid, int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.getApplicationInfoInternalBody(packageName, flags, filterCallingUid,
|
||||
userId);
|
||||
}
|
||||
}
|
||||
public ArrayList<ResolveInfo> filterCandidatesWithDomainPreferredActivitiesLPrBody(
|
||||
Intent intent, int matchFlags, List<ResolveInfo> candidates,
|
||||
CrossProfileDomainInfo xpDomainInfo, int userId, boolean debug) {
|
||||
synchronized (mLock) {
|
||||
return super.filterCandidatesWithDomainPreferredActivitiesLPrBody(intent,
|
||||
matchFlags, candidates, xpDomainInfo, userId, debug);
|
||||
}
|
||||
}
|
||||
public PackageInfo getPackageInfoInternalBody(String packageName, long versionCode,
|
||||
int flags, int filterCallingUid, int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.getPackageInfoInternalBody(packageName, versionCode, flags,
|
||||
filterCallingUid, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getAllAvailablePackageNames() {
|
||||
synchronized (mLock) {
|
||||
return super.getAllAvailablePackageNames();
|
||||
}
|
||||
}
|
||||
|
||||
public PackageStateInternal getPackageStateInternal(String packageName, int callingUid) {
|
||||
synchronized (mLock) {
|
||||
return super.getPackageStateInternal(packageName, callingUid);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PackageState getPackageStateCopied(@NonNull String packageName) {
|
||||
synchronized (mLock) {
|
||||
return super.getPackageStateCopied(packageName);
|
||||
}
|
||||
}
|
||||
|
||||
public ParceledListSlice<PackageInfo> getInstalledPackagesBody(int flags, int userId,
|
||||
int callingUid) {
|
||||
synchronized (mLock) {
|
||||
return super.getInstalledPackagesBody(flags, userId, callingUid);
|
||||
}
|
||||
}
|
||||
public ServiceInfo getServiceInfoBody(ComponentName component, int flags, int userId,
|
||||
int callingUid) {
|
||||
synchronized (mLock) {
|
||||
return super.getServiceInfoBody(component, flags, userId, callingUid);
|
||||
}
|
||||
}
|
||||
public String getInstantAppPackageName(int callingUid) {
|
||||
synchronized (mLock) {
|
||||
return super.getInstantAppPackageName(callingUid);
|
||||
}
|
||||
}
|
||||
public String[] getPackagesForUidInternalBody(int callingUid, int userId, int appId,
|
||||
boolean isCallerInstantApp) {
|
||||
synchronized (mLock) {
|
||||
return super.getPackagesForUidInternalBody(callingUid, userId, appId,
|
||||
isCallerInstantApp);
|
||||
}
|
||||
}
|
||||
public boolean isInstantAppInternalBody(String packageName, @UserIdInt int userId,
|
||||
int callingUid) {
|
||||
synchronized (mLock) {
|
||||
return super.isInstantAppInternalBody(packageName, userId, callingUid);
|
||||
}
|
||||
}
|
||||
public boolean isInstantAppResolutionAllowedBody(Intent intent,
|
||||
List<ResolveInfo> resolvedActivities, int userId, boolean skipPackageCheck,
|
||||
int flags) {
|
||||
synchronized (mLock) {
|
||||
return super.isInstantAppResolutionAllowedBody(intent, resolvedActivities, userId,
|
||||
skipPackageCheck, flags);
|
||||
}
|
||||
}
|
||||
public int getPackageUidInternal(String packageName, int flags, int userId,
|
||||
int callingUid) {
|
||||
synchronized (mLock) {
|
||||
return super.getPackageUidInternal(packageName, flags, userId, callingUid);
|
||||
}
|
||||
}
|
||||
public SigningDetails getSigningDetails(@NonNull String packageName) {
|
||||
synchronized (mLock) {
|
||||
return super.getSigningDetails(packageName);
|
||||
}
|
||||
}
|
||||
public SigningDetails getSigningDetails(int uid) {
|
||||
synchronized (mLock) {
|
||||
return super.getSigningDetails(uid);
|
||||
}
|
||||
}
|
||||
public boolean filterAppAccess(AndroidPackage pkg, int callingUid, int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.filterAppAccess(pkg, callingUid, userId);
|
||||
}
|
||||
}
|
||||
public boolean filterAppAccess(String packageName, int callingUid, int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.filterAppAccess(packageName, callingUid, userId);
|
||||
}
|
||||
}
|
||||
public boolean filterAppAccess(int uid, int callingUid) {
|
||||
synchronized (mLock) {
|
||||
return super.filterAppAccess(uid, callingUid);
|
||||
}
|
||||
}
|
||||
public void dump(int type, FileDescriptor fd, PrintWriter pw, DumpState dumpState) {
|
||||
synchronized (mLock) {
|
||||
super.dump(type, fd, pw, dumpState);
|
||||
}
|
||||
}
|
||||
public PackageManagerService.FindPreferredActivityBodyResult findPreferredActivityBody(
|
||||
Intent intent, String resolvedType, int flags, List<ResolveInfo> query, boolean always,
|
||||
boolean removeMatches, boolean debug, int userId, boolean queryMayBeFiltered,
|
||||
int callingUid, boolean isDeviceProvisioned) {
|
||||
synchronized (mLock) {
|
||||
return super.findPreferredActivityBody(intent, resolvedType, flags, query, always,
|
||||
removeMatches, debug, userId, queryMayBeFiltered, callingUid,
|
||||
isDeviceProvisioned);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreferredIntentResolver getPreferredActivities(int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.getPreferredActivities(userId);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ArrayMap<String, ? extends PackageStateInternal> getPackageStates() {
|
||||
synchronized (mLock) {
|
||||
return super.getPackageStates();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getRenamedPackage(@NonNull String packageName) {
|
||||
synchronized (mLock) {
|
||||
return super.getRenamedPackage(packageName);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ArraySet<String> getNotifyPackagesForReplacedReceived(@NonNull String[] packages) {
|
||||
synchronized (mLock) {
|
||||
return super.getNotifyPackagesForReplacedReceived(packages);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPackageStartability(boolean safeMode, @NonNull String packageName, int callingUid,
|
||||
@UserIdInt int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.getPackageStartability(safeMode, packageName, callingUid, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPackageAvailable(String packageName, @UserIdInt int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.isPackageAvailable(packageName, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] currentToCanonicalPackageNames(String[] names) {
|
||||
synchronized (mLock) {
|
||||
return super.currentToCanonicalPackageNames(names);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] canonicalToCurrentPackageNames(String[] names) {
|
||||
synchronized (mLock) {
|
||||
return super.canonicalToCurrentPackageNames(names);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getPackageGids(@NonNull String packageName,
|
||||
@PackageManager.PackageInfoFlagsBits long flags, @UserIdInt int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.getPackageGids(packageName, flags, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTargetSdkVersion(@NonNull String packageName) {
|
||||
synchronized (mLock) {
|
||||
return super.getTargetSdkVersion(packageName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activitySupportsIntent(@NonNull ComponentName resolveComponentName,
|
||||
@NonNull ComponentName component, @NonNull Intent intent, String resolvedType) {
|
||||
synchronized (mLock) {
|
||||
return super.activitySupportsIntent(resolveComponentName, component, intent,
|
||||
resolvedType);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ActivityInfo getReceiverInfo(@NonNull ComponentName component,
|
||||
@PackageManager.ComponentInfoFlagsBits long flags, @UserIdInt int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.getReceiverInfo(component, flags, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ParceledListSlice<SharedLibraryInfo> getSharedLibraries(@NonNull String packageName,
|
||||
@PackageManager.PackageInfoFlagsBits long flags, @UserIdInt int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.getSharedLibraries(packageName, flags, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRequestPackageInstalls(@NonNull String packageName, int callingUid,
|
||||
@UserIdInt int userId, boolean throwIfPermNotDeclared) {
|
||||
synchronized (mLock) {
|
||||
return super.canRequestPackageInstalls(packageName, callingUid, userId,
|
||||
throwIfPermNotDeclared);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VersionedPackage> getPackagesUsingSharedLibrary(@NonNull SharedLibraryInfo libInfo,
|
||||
@PackageManager.PackageInfoFlagsBits long flags, int callingUid,
|
||||
@UserIdInt int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.getPackagesUsingSharedLibrary(libInfo, flags, callingUid, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ParceledListSlice<SharedLibraryInfo> getDeclaredSharedLibraries(
|
||||
@NonNull String packageName, @PackageManager.PackageInfoFlagsBits long flags,
|
||||
@UserIdInt int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.getDeclaredSharedLibraries(packageName, flags, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ProviderInfo getProviderInfo(@NonNull ComponentName component,
|
||||
@PackageManager.ComponentInfoFlagsBits long flags, @UserIdInt int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.getProviderInfo(component, flags, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String[] getSystemSharedLibraryNames() {
|
||||
synchronized (mLock) {
|
||||
return super.getSystemSharedLibraryNames();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int checkSignatures(@NonNull String pkg1,
|
||||
@NonNull String pkg2) {
|
||||
synchronized (mLock) {
|
||||
return super.checkSignatures(pkg1, pkg2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int checkUidSignatures(int uid1, int uid2) {
|
||||
synchronized (mLock) {
|
||||
return super.checkUidSignatures(uid1, uid2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSigningCertificate(@NonNull String packageName, @NonNull byte[] certificate,
|
||||
int type) {
|
||||
synchronized (mLock) {
|
||||
return super.hasSigningCertificate(packageName, certificate, type);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasUidSigningCertificate(int uid, @NonNull byte[] certificate, int type) {
|
||||
synchronized (mLock) {
|
||||
return super.hasUidSigningCertificate(uid, certificate, type);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAllPackages() {
|
||||
synchronized (mLock) {
|
||||
return super.getAllPackages();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNameForUid(int uid) {
|
||||
synchronized (mLock) {
|
||||
return super.getNameForUid(uid);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String[] getNamesForUids(int[] uids) {
|
||||
synchronized (mLock) {
|
||||
return super.getNamesForUids(uids);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUidForSharedUser(@NonNull String sharedUserName) {
|
||||
synchronized (mLock) {
|
||||
return super.getUidForSharedUser(sharedUserName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFlagsForUid(int uid) {
|
||||
synchronized (mLock) {
|
||||
return super.getFlagsForUid(uid);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPrivateFlagsForUid(int uid) {
|
||||
synchronized (mLock) {
|
||||
return super.getPrivateFlagsForUid(uid);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUidPrivileged(int uid) {
|
||||
synchronized (mLock) {
|
||||
return super.isUidPrivileged(uid);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String[] getAppOpPermissionPackages(@NonNull String permissionName) {
|
||||
synchronized (mLock) {
|
||||
return super.getAppOpPermissionPackages(permissionName);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ParceledListSlice<PackageInfo> getPackagesHoldingPermissions(
|
||||
@NonNull String[] permissions, @PackageManager.PackageInfoFlagsBits long flags,
|
||||
@UserIdInt int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.getPackagesHoldingPermissions(permissions, flags, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public List<ApplicationInfo> getInstalledApplications(
|
||||
@PackageManager.ApplicationInfoFlagsBits long flags, @UserIdInt int userId,
|
||||
int callingUid) {
|
||||
synchronized (mLock) {
|
||||
return super.getInstalledApplications(flags, userId, callingUid);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ProviderInfo resolveContentProvider(@NonNull String name,
|
||||
@PackageManager.ResolveInfoFlagsBits long flags, @UserIdInt int userId,
|
||||
int callingUid) {
|
||||
synchronized (mLock) {
|
||||
return super.resolveContentProvider(name, flags, userId, callingUid);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ProviderInfo getGrantImplicitAccessProviderInfo(int recipientUid,
|
||||
@NonNull String visibleAuthority) {
|
||||
synchronized (mLock) {
|
||||
return super.getGrantImplicitAccessProviderInfo(recipientUid, visibleAuthority);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void querySyncProviders(boolean safeMode, @NonNull List<String> outNames,
|
||||
@NonNull List<ProviderInfo> outInfo) {
|
||||
synchronized (mLock) {
|
||||
super.querySyncProviders(safeMode, outNames, outInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ParceledListSlice<ProviderInfo> queryContentProviders(@Nullable String processName,
|
||||
int uid, @PackageManager.ComponentInfoFlagsBits long flags,
|
||||
@Nullable String metaDataKey) {
|
||||
synchronized (mLock) {
|
||||
return super.queryContentProviders(processName, uid, flags, metaDataKey);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public InstrumentationInfo getInstrumentationInfo(@NonNull ComponentName component, int flags) {
|
||||
synchronized (mLock) {
|
||||
return super.getInstrumentationInfo(component, flags);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ParceledListSlice<InstrumentationInfo> queryInstrumentation(
|
||||
@NonNull String targetPackage, int flags) {
|
||||
synchronized (mLock) {
|
||||
return super.queryInstrumentation(targetPackage, flags);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public List<PackageStateInternal> findSharedNonSystemLibraries(
|
||||
@NonNull PackageStateInternal pkgSetting) {
|
||||
synchronized (mLock) {
|
||||
return super.findSharedNonSystemLibraries(pkgSetting);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getApplicationHiddenSettingAsUser(@NonNull String packageName,
|
||||
@UserIdInt int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.getApplicationHiddenSettingAsUser(packageName, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPackageSuspendedForUser(@NonNull String packageName, @UserIdInt int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.isPackageSuspendedForUser(packageName, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuspendingAnyPackages(@NonNull String suspendingPackage,
|
||||
@UserIdInt int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.isSuspendingAnyPackages(suspendingPackage, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ParceledListSlice<IntentFilter> getAllIntentFilters(@NonNull String packageName) {
|
||||
synchronized (mLock) {
|
||||
return super.getAllIntentFilters(packageName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBlockUninstallForUser(@NonNull String packageName, @UserIdInt int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.getBlockUninstallForUser(packageName, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public SparseArray<int[]> getBroadcastAllowList(@NonNull String packageName,
|
||||
@UserIdInt int[] userIds, boolean isInstantApp) {
|
||||
synchronized (mLock) {
|
||||
return super.getBroadcastAllowList(packageName, userIds, isInstantApp);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getInstallerPackageName(@NonNull String packageName) {
|
||||
synchronized (mLock) {
|
||||
return super.getInstallerPackageName(packageName);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public InstallSourceInfo getInstallSourceInfo(@NonNull String packageName) {
|
||||
synchronized (mLock) {
|
||||
return super.getInstallSourceInfo(packageName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getApplicationEnabledSetting(@NonNull String packageName, @UserIdInt int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.getApplicationEnabledSetting(packageName, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getComponentEnabledSetting(@NonNull ComponentName component, int callingUid,
|
||||
@UserIdInt int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.getComponentEnabledSetting(component, callingUid, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getComponentEnabledSettingInternal(@NonNull ComponentName component, int callingUid,
|
||||
@UserIdInt int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.getComponentEnabledSettingInternal(component, callingUid, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComponentEffectivelyEnabled(@NonNull ComponentInfo componentInfo,
|
||||
@UserIdInt int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.isComponentEffectivelyEnabled(componentInfo, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public KeySet getKeySetByAlias(@NonNull String packageName, @NonNull String alias) {
|
||||
synchronized (mLock) {
|
||||
return super.getKeySetByAlias(packageName, alias);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public KeySet getSigningKeySet(@NonNull String packageName) {
|
||||
synchronized (mLock) {
|
||||
return super.getSigningKeySet(packageName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPackageSignedByKeySet(@NonNull String packageName, @NonNull KeySet ks) {
|
||||
synchronized (mLock) {
|
||||
return super.isPackageSignedByKeySet(packageName, ks);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPackageSignedByKeySetExactly(@NonNull String packageName, @NonNull KeySet ks) {
|
||||
synchronized (mLock) {
|
||||
return super.isPackageSignedByKeySetExactly(packageName, ks);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public int[] getVisibilityAllowList(@NonNull String packageName, @UserIdInt int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.getVisibilityAllowList(packageName, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canQueryPackage(int callingUid, @Nullable String targetPackageName) {
|
||||
synchronized (mLock) {
|
||||
return super.canQueryPackage(callingUid, targetPackageName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPackageUid(@NonNull String packageName,
|
||||
@PackageManager.PackageInfoFlagsBits long flags, @UserIdInt int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.getPackageUid(packageName, flags, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAccessComponent(int callingUid, @NonNull ComponentName component,
|
||||
@UserIdInt int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.canAccessComponent(callingUid, component, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCallerInstallerOfRecord(@NonNull AndroidPackage pkg, int callingUid) {
|
||||
synchronized (mLock) {
|
||||
return super.isCallerInstallerOfRecord(pkg, callingUid);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInstallReason(@NonNull String packageName, @UserIdInt int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.getInstallReason(packageName, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPackageQuery(@NonNull String sourcePackageName,
|
||||
@NonNull String targetPackageName, @UserIdInt int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.canPackageQuery(sourcePackageName, targetPackageName, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canForwardTo(@NonNull Intent intent, @Nullable String resolvedType,
|
||||
@UserIdInt int sourceUserId, @UserIdInt int targetUserId) {
|
||||
synchronized (mLock) {
|
||||
return super.canForwardTo(intent, resolvedType, sourceUserId, targetUserId);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public List<ApplicationInfo> getPersistentApplications(boolean safeMode, int flags) {
|
||||
synchronized (mLock) {
|
||||
return super.getPersistentApplications(safeMode, flags);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public SparseArray<String> getAppsWithSharedUserIds() {
|
||||
synchronized (mLock) {
|
||||
return super.getAppsWithSharedUserIds();
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String[] getSharedUserPackagesForPackage(@NonNull String packageName,
|
||||
@UserIdInt int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.getSharedUserPackagesForPackage(packageName, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Set<String> getUnusedPackages(long downgradeTimeThresholdMillis) {
|
||||
synchronized (mLock) {
|
||||
return super.getUnusedPackages(downgradeTimeThresholdMillis);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public CharSequence getHarmfulAppWarning(@NonNull String packageName, @UserIdInt int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.getHarmfulAppWarning(packageName, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String[] filterOnlySystemPackages(@Nullable String... pkgNames) {
|
||||
synchronized (mLock) {
|
||||
return super.filterOnlySystemPackages(pkgNames);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public List<AndroidPackage> getPackagesForAppId(int appId) {
|
||||
synchronized (mLock) {
|
||||
return super.getPackagesForAppId(appId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUidTargetSdkVersion(int uid) {
|
||||
synchronized (mLock) {
|
||||
return super.getUidTargetSdkVersion(uid);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ArrayMap<String, ProcessInfo> getProcessesForUid(int uid) {
|
||||
synchronized (mLock) {
|
||||
return super.getProcessesForUid(uid);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackageStateInternal getPackageStateFiltered(@NonNull String packageName, int callingUid,
|
||||
@UserIdInt int userId) {
|
||||
synchronized (mLock) {
|
||||
return super.getPackageStateFiltered(packageName, callingUid, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBlockUninstall(@UserIdInt int userId, @NonNull String packageName) {
|
||||
synchronized (mLock) {
|
||||
return super.getBlockUninstall(userId, packageName);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public WatchedArrayMap<String, WatchedLongSparseArray<SharedLibraryInfo>> getSharedLibraries() {
|
||||
synchronized (mLock) {
|
||||
return super.getSharedLibraries();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Pair<PackageStateInternal, SharedUserApi> getPackageOrSharedUser(int appId) {
|
||||
synchronized (mLock) {
|
||||
return super.getPackageOrSharedUser(appId);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public SharedUserApi getSharedUser(int sharedUserAppId) {
|
||||
synchronized (mLock) {
|
||||
return super.getSharedUser(sharedUserAppId);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ArraySet<PackageStateInternal> getSharedUserPackages(int sharedUserAppId) {
|
||||
synchronized (mLock) {
|
||||
return super.getSharedUserPackages(sharedUserAppId);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ComponentResolverApi getComponentResolver() {
|
||||
synchronized (mLock) {
|
||||
return super.getComponentResolver();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PackageStateInternal getDisabledSystemPackage(@NonNull String packageName) {
|
||||
synchronized (mLock) {
|
||||
return super.getDisabledSystemPackage(packageName);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ResolveInfo getInstantAppInstallerInfo() {
|
||||
synchronized (mLock) {
|
||||
return super.getInstantAppInstallerInfo();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -147,6 +147,7 @@ final class DeletePackageHelper {
|
||||
final SparseArray<TempUserState> priorUserStates;
|
||||
/** enabled state of the uninstalled application */
|
||||
synchronized (mPm.mLock) {
|
||||
final Computer computer = mPm.snapshotComputer();
|
||||
uninstalledPs = mPm.mSettings.getPackageLPr(packageName);
|
||||
if (uninstalledPs == null) {
|
||||
Slog.w(TAG, "Not removing non-existent package " + packageName);
|
||||
@ -170,10 +171,10 @@ final class DeletePackageHelper {
|
||||
if (pkg != null) {
|
||||
SharedLibraryInfo libraryInfo = null;
|
||||
if (pkg.getStaticSharedLibName() != null) {
|
||||
libraryInfo = mPm.getSharedLibraryInfo(pkg.getStaticSharedLibName(),
|
||||
libraryInfo = computer.getSharedLibraryInfo(pkg.getStaticSharedLibName(),
|
||||
pkg.getStaticSharedLibVersion());
|
||||
} else if (pkg.getSdkLibName() != null) {
|
||||
libraryInfo = mPm.getSharedLibraryInfo(pkg.getSdkLibName(),
|
||||
libraryInfo = computer.getSharedLibraryInfo(pkg.getSdkLibName(),
|
||||
pkg.getSdkLibVersionMajor());
|
||||
}
|
||||
|
||||
@ -183,7 +184,7 @@ final class DeletePackageHelper {
|
||||
continue;
|
||||
}
|
||||
List<VersionedPackage> libClientPackages =
|
||||
mPm.getPackagesUsingSharedLibrary(libraryInfo,
|
||||
computer.getPackagesUsingSharedLibrary(libraryInfo,
|
||||
MATCH_KNOWN_PACKAGES, Process.SYSTEM_UID, currUserId);
|
||||
if (!ArrayUtils.isEmpty(libClientPackages)) {
|
||||
Slog.w(TAG, "Not removing package " + pkg.getManifestPackageName()
|
||||
@ -454,11 +455,11 @@ final class DeletePackageHelper {
|
||||
if (affectedUserIds == null) {
|
||||
affectedUserIds = mPm.resolveUserIds(userId);
|
||||
}
|
||||
final Computer snapshot = mPm.snapshotComputer();
|
||||
for (final int affectedUserId : affectedUserIds) {
|
||||
if (hadSuspendAppsPermission.get(affectedUserId)) {
|
||||
mPm.unsuspendForSuspendingPackage(mPm.snapshotComputer(), packageName,
|
||||
affectedUserId);
|
||||
mPm.removeAllDistractingPackageRestrictions(affectedUserId);
|
||||
mPm.unsuspendForSuspendingPackage(snapshot, packageName, affectedUserId);
|
||||
mPm.removeAllDistractingPackageRestrictions(snapshot, affectedUserId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -621,7 +622,8 @@ final class DeletePackageHelper {
|
||||
final int callingUid = Binder.getCallingUid();
|
||||
mPm.mContext.enforceCallingOrSelfPermission(
|
||||
android.Manifest.permission.DELETE_PACKAGES, null);
|
||||
final boolean canViewInstantApps = mPm.canViewInstantApps(callingUid, userId);
|
||||
final Computer snapshot = mPm.snapshotComputer();
|
||||
final boolean canViewInstantApps = snapshot.canViewInstantApps(callingUid, userId);
|
||||
Preconditions.checkNotNull(versionedPackage);
|
||||
Preconditions.checkNotNull(observer);
|
||||
Preconditions.checkArgumentInRange(versionedPackage.getLongVersionCode(),
|
||||
@ -644,12 +646,13 @@ final class DeletePackageHelper {
|
||||
}
|
||||
|
||||
// Normalize package name to handle renamed packages and static libs
|
||||
final String internalPackageName = mPm.resolveInternalPackageName(packageName, versionCode);
|
||||
final String internalPackageName =
|
||||
snapshot.resolveInternalPackageName(packageName, versionCode);
|
||||
|
||||
final int uid = Binder.getCallingUid();
|
||||
if (!isOrphaned(internalPackageName)
|
||||
if (!isOrphaned(snapshot, internalPackageName)
|
||||
&& !allowSilentUninstall
|
||||
&& !isCallerAllowedToSilentlyUninstall(uid, internalPackageName)) {
|
||||
&& !isCallerAllowedToSilentlyUninstall(snapshot, uid, internalPackageName)) {
|
||||
mPm.mHandler.post(() -> {
|
||||
try {
|
||||
final Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE);
|
||||
@ -680,8 +683,7 @@ final class DeletePackageHelper {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!deleteAllUsers && mPm.mIPackageManager
|
||||
.getBlockUninstallForUser(internalPackageName, userId)) {
|
||||
if (!deleteAllUsers && snapshot.getBlockUninstallForUser(internalPackageName, userId)) {
|
||||
mPm.mHandler.post(() -> {
|
||||
try {
|
||||
observer.onPackageDeleted(packageName,
|
||||
@ -756,44 +758,45 @@ final class DeletePackageHelper {
|
||||
});
|
||||
}
|
||||
|
||||
private boolean isOrphaned(String packageName) {
|
||||
final PackageStateInternal packageState = mPm.getPackageStateInternal(packageName);
|
||||
private boolean isOrphaned(@NonNull Computer snapshot, String packageName) {
|
||||
final PackageStateInternal packageState = snapshot.getPackageStateInternal(packageName);
|
||||
return packageState != null && packageState.getInstallSource().isOrphaned;
|
||||
}
|
||||
|
||||
private boolean isCallerAllowedToSilentlyUninstall(int callingUid, String pkgName) {
|
||||
private boolean isCallerAllowedToSilentlyUninstall(@NonNull Computer snapshot, int callingUid,
|
||||
String pkgName) {
|
||||
if (callingUid == Process.SHELL_UID || callingUid == Process.ROOT_UID
|
||||
|| UserHandle.getAppId(callingUid) == Process.SYSTEM_UID) {
|
||||
return true;
|
||||
}
|
||||
final int callingUserId = UserHandle.getUserId(callingUid);
|
||||
// If the caller installed the pkgName, then allow it to silently uninstall.
|
||||
if (callingUid == mPm.mIPackageManager.getPackageUid(
|
||||
mPm.mIPackageManager.getInstallerPackageName(pkgName), 0, callingUserId)) {
|
||||
if (callingUid == snapshot.getPackageUid(snapshot.getInstallerPackageName(pkgName), 0,
|
||||
callingUserId)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Allow package verifier to silently uninstall.
|
||||
if (mPm.mRequiredVerifierPackage != null && callingUid == mPm.mIPackageManager
|
||||
if (mPm.mRequiredVerifierPackage != null && callingUid == snapshot
|
||||
.getPackageUid(mPm.mRequiredVerifierPackage, 0, callingUserId)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Allow package uninstaller to silently uninstall.
|
||||
if (mPm.mRequiredUninstallerPackage != null && callingUid == mPm.mIPackageManager
|
||||
if (mPm.mRequiredUninstallerPackage != null && callingUid == snapshot
|
||||
.getPackageUid(mPm.mRequiredUninstallerPackage, 0, callingUserId)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Allow storage manager to silently uninstall.
|
||||
if (mPm.mStorageManagerPackage != null && callingUid == mPm.mIPackageManager.getPackageUid(
|
||||
if (mPm.mStorageManagerPackage != null && callingUid == snapshot.getPackageUid(
|
||||
mPm.mStorageManagerPackage, 0, callingUserId)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Allow caller having MANAGE_PROFILE_AND_DEVICE_OWNERS permission to silently
|
||||
// uninstall for device owner provisioning.
|
||||
return mPm.mIPackageManager.checkUidPermission(MANAGE_PROFILE_AND_DEVICE_OWNERS, callingUid)
|
||||
return snapshot.checkUidPermission(MANAGE_PROFILE_AND_DEVICE_OWNERS, callingUid)
|
||||
== PERMISSION_GRANTED;
|
||||
}
|
||||
|
||||
@ -899,8 +902,8 @@ final class DeletePackageHelper {
|
||||
int installedForUsersCount = 0;
|
||||
synchronized (mPm.mLock) {
|
||||
// Normalize package name to handle renamed packages and static libs
|
||||
final String internalPkgName = mPm.resolveInternalPackageName(packageName,
|
||||
versionCode);
|
||||
final String internalPkgName = mPm.snapshotComputer()
|
||||
.resolveInternalPackageName(packageName, versionCode);
|
||||
final PackageSetting ps = mPm.mSettings.getPackageLPr(internalPkgName);
|
||||
if (ps != null) {
|
||||
int[] installedUsers = ps.queryInstalledUsers(mUserManagerInternal.getUserIds(),
|
||||
|
@ -266,8 +266,9 @@ final class DexOptHelper {
|
||||
return;
|
||||
}
|
||||
|
||||
final Computer snapshot = mPm.snapshotComputer();
|
||||
List<PackageStateInternal> pkgSettings =
|
||||
getPackagesForDexopt(mPm.getPackageStates().values(), mPm);
|
||||
getPackagesForDexopt(snapshot.getPackageStates().values(), mPm);
|
||||
|
||||
List<AndroidPackage> pkgs = new ArrayList<>(pkgSettings.size());
|
||||
for (int index = 0; index < pkgSettings.size(); index++) {
|
||||
@ -282,17 +283,19 @@ final class DexOptHelper {
|
||||
final int elapsedTimeSeconds =
|
||||
(int) TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - startTime);
|
||||
|
||||
final Computer newSnapshot = mPm.snapshotComputer();
|
||||
|
||||
MetricsLogger.histogram(mPm.mContext, "opt_dialog_num_dexopted", stats[0]);
|
||||
MetricsLogger.histogram(mPm.mContext, "opt_dialog_num_skipped", stats[1]);
|
||||
MetricsLogger.histogram(mPm.mContext, "opt_dialog_num_failed", stats[2]);
|
||||
MetricsLogger.histogram(
|
||||
mPm.mContext, "opt_dialog_num_total", getOptimizablePackages().size());
|
||||
MetricsLogger.histogram(mPm.mContext, "opt_dialog_num_total",
|
||||
getOptimizablePackages(newSnapshot).size());
|
||||
MetricsLogger.histogram(mPm.mContext, "opt_dialog_time_s", elapsedTimeSeconds);
|
||||
}
|
||||
|
||||
public ArraySet<String> getOptimizablePackages() {
|
||||
public ArraySet<String> getOptimizablePackages(@NonNull Computer snapshot) {
|
||||
ArraySet<String> pkgs = new ArraySet<>();
|
||||
mPm.forEachPackageState(packageState -> {
|
||||
mPm.forEachPackageState(snapshot, packageState -> {
|
||||
final AndroidPackage pkg = packageState.getPkg();
|
||||
if (pkg != null && mPm.mPackageDexOptimizer.canOptimizePackage(pkg)) {
|
||||
pkgs.add(packageState.getPackageName());
|
||||
@ -302,10 +305,10 @@ final class DexOptHelper {
|
||||
}
|
||||
|
||||
/*package*/ boolean performDexOpt(DexoptOptions options) {
|
||||
if (mPm.getInstantAppPackageName(Binder.getCallingUid()) != null) {
|
||||
final Computer snapshot = mPm.snapshotComputer();
|
||||
if (snapshot.getInstantAppPackageName(Binder.getCallingUid()) != null) {
|
||||
return false;
|
||||
} else if (mPm.mIPackageManager.isInstantApp(options.getPackageName(),
|
||||
UserHandle.getCallingUserId())) {
|
||||
} else if (snapshot.isInstantApp(options.getPackageName(), UserHandle.getCallingUserId())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -417,10 +420,10 @@ final class DexOptHelper {
|
||||
mPm.getDexManager().getPackageUseInfoOrDefault(p.getPackageName()), options);
|
||||
}
|
||||
|
||||
public void forceDexOpt(String packageName) {
|
||||
public void forceDexOpt(@NonNull Computer snapshot, String packageName) {
|
||||
PackageManagerServiceUtils.enforceSystemOrRoot("forceDexOpt");
|
||||
|
||||
final PackageStateInternal packageState = mPm.getPackageStateInternal(packageName);
|
||||
final PackageStateInternal packageState = snapshot.getPackageStateInternal(packageName);
|
||||
final AndroidPackage pkg = packageState == null ? null : packageState.getPkg();
|
||||
if (packageState == null || pkg == null) {
|
||||
throw new IllegalArgumentException("Unknown package: " + packageName);
|
||||
@ -485,19 +488,21 @@ final class DexOptHelper {
|
||||
|
||||
ArrayList<PackageStateInternal> sortTemp = new ArrayList<>(remainingPkgSettings.size());
|
||||
|
||||
final Computer snapshot = packageManagerService.snapshotComputer();
|
||||
|
||||
// Give priority to core apps.
|
||||
applyPackageFilter(pkgSetting -> pkgSetting.getPkg().isCoreApp(), result,
|
||||
applyPackageFilter(snapshot, pkgSetting -> pkgSetting.getPkg().isCoreApp(), result,
|
||||
remainingPkgSettings, sortTemp, packageManagerService);
|
||||
|
||||
// Give priority to system apps that listen for pre boot complete.
|
||||
Intent intent = new Intent(Intent.ACTION_PRE_BOOT_COMPLETED);
|
||||
final ArraySet<String> pkgNames = getPackageNamesForIntent(intent, UserHandle.USER_SYSTEM);
|
||||
applyPackageFilter(pkgSetting -> pkgNames.contains(pkgSetting.getPackageName()), result,
|
||||
applyPackageFilter(snapshot, pkgSetting -> pkgNames.contains(pkgSetting.getPackageName()), result,
|
||||
remainingPkgSettings, sortTemp, packageManagerService);
|
||||
|
||||
// Give priority to apps used by other apps.
|
||||
DexManager dexManager = packageManagerService.getDexManager();
|
||||
applyPackageFilter(pkgSetting ->
|
||||
applyPackageFilter(snapshot, pkgSetting ->
|
||||
dexManager.getPackageUseInfoOrDefault(pkgSetting.getPackageName())
|
||||
.isAnyCodePathUsedByOtherApps(),
|
||||
result, remainingPkgSettings, sortTemp, packageManagerService);
|
||||
@ -535,7 +540,7 @@ final class DexOptHelper {
|
||||
// No historical info. Take all.
|
||||
remainingPredicate = pkgSetting -> true;
|
||||
}
|
||||
applyPackageFilter(remainingPredicate, result, remainingPkgSettings, sortTemp,
|
||||
applyPackageFilter(snapshot, remainingPredicate, result, remainingPkgSettings, sortTemp,
|
||||
packageManagerService);
|
||||
|
||||
if (debug) {
|
||||
@ -550,7 +555,7 @@ final class DexOptHelper {
|
||||
// package will be removed from {@code packages} and added to {@code result} with its
|
||||
// dependencies. If usage data is available, the positive packages will be sorted by usage
|
||||
// data (with {@code sortTemp} as temporary storage).
|
||||
private static void applyPackageFilter(
|
||||
private static void applyPackageFilter(@NonNull Computer snapshot,
|
||||
Predicate<PackageStateInternal> filter,
|
||||
Collection<PackageStateInternal> result,
|
||||
Collection<PackageStateInternal> packages,
|
||||
@ -568,8 +573,7 @@ final class DexOptHelper {
|
||||
for (PackageStateInternal pkgSetting : sortTemp) {
|
||||
result.add(pkgSetting);
|
||||
|
||||
List<PackageStateInternal> deps =
|
||||
packageManagerService.findSharedNonSystemLibraries(pkgSetting);
|
||||
List<PackageStateInternal> deps = snapshot.findSharedNonSystemLibraries(pkgSetting);
|
||||
if (!deps.isEmpty()) {
|
||||
deps.removeAll(result);
|
||||
result.addAll(deps);
|
||||
|
@ -21,7 +21,6 @@ import static com.android.server.pm.PackageManagerService.DOMAIN_VERIFICATION;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.UserIdInt;
|
||||
import android.content.pm.PackageManagerInternal;
|
||||
import android.os.Binder;
|
||||
import android.os.Message;
|
||||
import android.os.UserHandle;
|
||||
@ -35,13 +34,10 @@ import com.android.server.pm.verify.domain.proxy.DomainVerificationProxyV2;
|
||||
public final class DomainVerificationConnection implements DomainVerificationService.Connection,
|
||||
DomainVerificationProxyV1.Connection, DomainVerificationProxyV2.Connection {
|
||||
final PackageManagerService mPm;
|
||||
final PackageManagerInternal mPmInternal;
|
||||
final UserManagerInternal mUmInternal;
|
||||
|
||||
// TODO(b/198166813): remove PMS dependency
|
||||
DomainVerificationConnection(PackageManagerService pm) {
|
||||
mPm = pm;
|
||||
mPmInternal = mPm.mInjector.getLocalService(PackageManagerInternal.class);
|
||||
mUmInternal = mPm.mInjector.getLocalService(UserManagerInternal.class);
|
||||
}
|
||||
|
||||
@ -82,18 +78,18 @@ public final class DomainVerificationConnection implements DomainVerificationSer
|
||||
@Override
|
||||
public boolean isCallerPackage(int callingUid, @NonNull String packageName) {
|
||||
final int callingUserId = UserHandle.getUserId(callingUid);
|
||||
return callingUid == mPmInternal.getPackageUid(packageName, 0, callingUserId);
|
||||
return callingUid == mPm.snapshotComputer().getPackageUid(packageName, 0, callingUserId);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public AndroidPackage getPackage(@NonNull String packageName) {
|
||||
return mPmInternal.getPackage(packageName);
|
||||
return mPm.snapshotComputer().getPackage(packageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean filterAppAccess(String packageName, int callingUid, int userId) {
|
||||
return mPmInternal.filterAppAccess(packageName, callingUid, userId);
|
||||
return mPm.snapshotComputer().filterAppAccess(packageName, callingUid, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -108,6 +104,6 @@ public final class DomainVerificationConnection implements DomainVerificationSer
|
||||
|
||||
@NonNull
|
||||
public Computer snapshot() {
|
||||
return (Computer) mPmInternal.snapshot();
|
||||
return mPm.snapshotComputer();
|
||||
}
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ final class DumpHelper {
|
||||
|
||||
@NeverCompile // Avoid size overhead of debugging code.
|
||||
public void doDump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||
final Computer snapshot = mPm.snapshotComputer();
|
||||
DumpState dumpState = new DumpState();
|
||||
ArraySet<String> permissionNames = null;
|
||||
|
||||
@ -121,7 +122,7 @@ final class DumpHelper {
|
||||
}
|
||||
|
||||
// Normalize package name to handle renamed packages and static libs
|
||||
pkg = mPm.resolveInternalPackageName(pkg, PackageManager.VERSION_CODE_HIGHEST);
|
||||
pkg = snapshot.resolveInternalPackageName(pkg, PackageManager.VERSION_CODE_HIGHEST);
|
||||
|
||||
pw.println(mPm.checkPermission(perm, pkg, user));
|
||||
return;
|
||||
@ -243,7 +244,7 @@ final class DumpHelper {
|
||||
|
||||
// Return if the package doesn't exist.
|
||||
if (packageName != null
|
||||
&& mPm.getPackageStateInternal(packageName) == null
|
||||
&& snapshot.getPackageStateInternal(packageName) == null
|
||||
&& !mPm.mApexManager.isApexPackage(packageName)) {
|
||||
pw.println("Unable to find package: " + packageName);
|
||||
return;
|
||||
@ -257,7 +258,7 @@ final class DumpHelper {
|
||||
if (!checkin
|
||||
&& dumpState.isDumping(DumpState.DUMP_VERSION)
|
||||
&& packageName == null) {
|
||||
mPm.dumpComputer(DumpState.DUMP_VERSION, fd, pw, dumpState);
|
||||
snapshot.dump(DumpState.DUMP_VERSION, fd, pw, dumpState);
|
||||
}
|
||||
|
||||
if (!checkin
|
||||
@ -273,7 +274,7 @@ final class DumpHelper {
|
||||
final String knownPackage = PackageManagerInternal.knownPackageToString(i);
|
||||
ipw.print(knownPackage);
|
||||
ipw.println(":");
|
||||
final String[] pkgNames = mPm.getKnownPackageNamesInternal(i,
|
||||
final String[] pkgNames = mPm.getKnownPackageNamesInternal(snapshot, i,
|
||||
UserHandle.USER_SYSTEM);
|
||||
ipw.increaseIndent();
|
||||
if (ArrayUtils.isEmpty(pkgNames)) {
|
||||
@ -288,8 +289,6 @@ final class DumpHelper {
|
||||
ipw.decreaseIndent();
|
||||
}
|
||||
|
||||
final Computer snapshot = mPm.snapshotComputer();
|
||||
|
||||
if (dumpState.isDumping(DumpState.DUMP_VERIFIERS)
|
||||
&& packageName == null) {
|
||||
final String requiredVerifierPackage = mPm.mRequiredVerifierPackage;
|
||||
@ -343,7 +342,7 @@ final class DumpHelper {
|
||||
|
||||
if (dumpState.isDumping(DumpState.DUMP_LIBS)
|
||||
&& packageName == null) {
|
||||
mPm.dumpComputer(DumpState.DUMP_LIBS, fd, pw, dumpState);
|
||||
snapshot.dump(DumpState.DUMP_LIBS, fd, pw, dumpState);
|
||||
}
|
||||
|
||||
if (dumpState.isDumping(DumpState.DUMP_FEATURES)
|
||||
@ -389,17 +388,17 @@ final class DumpHelper {
|
||||
}
|
||||
|
||||
if (!checkin && dumpState.isDumping(DumpState.DUMP_PREFERRED)) {
|
||||
mPm.dumpComputer(DumpState.DUMP_PREFERRED, fd, pw, dumpState);
|
||||
snapshot.dump(DumpState.DUMP_PREFERRED, fd, pw, dumpState);
|
||||
}
|
||||
|
||||
if (!checkin
|
||||
&& dumpState.isDumping(DumpState.DUMP_PREFERRED_XML)
|
||||
&& packageName == null) {
|
||||
mPm.dumpComputer(DumpState.DUMP_PREFERRED_XML, fd, pw, dumpState);
|
||||
snapshot.dump(DumpState.DUMP_PREFERRED_XML, fd, pw, dumpState);
|
||||
}
|
||||
|
||||
if (!checkin && dumpState.isDumping(DumpState.DUMP_DOMAIN_PREFERRED)) {
|
||||
mPm.dumpComputer(DumpState.DUMP_DOMAIN_PREFERRED, fd, pw, dumpState);
|
||||
snapshot.dump(DumpState.DUMP_DOMAIN_PREFERRED, fd, pw, dumpState);
|
||||
}
|
||||
|
||||
if (!checkin && dumpState.isDumping(DumpState.DUMP_PERMISSIONS)) {
|
||||
@ -429,7 +428,7 @@ final class DumpHelper {
|
||||
|
||||
if (!checkin
|
||||
&& dumpState.isDumping(DumpState.DUMP_QUERIES)) {
|
||||
mPm.dumpComputer(DumpState.DUMP_QUERIES, fd, pw, dumpState);
|
||||
snapshot.dump(DumpState.DUMP_QUERIES, fd, pw, dumpState);
|
||||
}
|
||||
|
||||
if (dumpState.isDumping(DumpState.DUMP_SHARED_USERS)) {
|
||||
@ -529,12 +528,12 @@ final class DumpHelper {
|
||||
|
||||
if (!checkin
|
||||
&& dumpState.isDumping(DumpState.DUMP_DEXOPT)) {
|
||||
mPm.dumpComputer(DumpState.DUMP_DEXOPT, fd, pw, dumpState);
|
||||
snapshot.dump(DumpState.DUMP_DEXOPT, fd, pw, dumpState);
|
||||
}
|
||||
|
||||
if (!checkin
|
||||
&& dumpState.isDumping(DumpState.DUMP_COMPILER_STATS)) {
|
||||
mPm.dumpComputer(DumpState.DUMP_COMPILER_STATS, fd, pw, dumpState);
|
||||
snapshot.dump(DumpState.DUMP_COMPILER_STATS, fd, pw, dumpState);
|
||||
}
|
||||
|
||||
if (dumpState.isDumping(DumpState.DUMP_MESSAGES)
|
||||
@ -581,7 +580,7 @@ final class DumpHelper {
|
||||
pw.println(" Known digesters list flag: "
|
||||
+ PackageManagerService.getKnownDigestersList());
|
||||
|
||||
PerUidReadTimeouts[] items = mPm.getPerUidReadTimeouts();
|
||||
PerUidReadTimeouts[] items = mPm.getPerUidReadTimeouts(snapshot);
|
||||
pw.println(" Timeouts (" + items.length + "):");
|
||||
for (PerUidReadTimeouts item : items) {
|
||||
pw.print(" (");
|
||||
|
1189
services/core/java/com/android/server/pm/IPackageManagerBase.java
Normal file
1189
services/core/java/com/android/server/pm/IPackageManagerBase.java
Normal file
File diff suppressed because it is too large
Load Diff
@ -33,7 +33,8 @@ final class IncrementalProgressListener extends IPackageLoadingProgressCallback.
|
||||
|
||||
@Override
|
||||
public void onPackageLoadingProgressChanged(float progress) {
|
||||
PackageStateInternal packageState = mPm.getPackageStateInternal(mPackageName);
|
||||
PackageStateInternal packageState = mPm.snapshotComputer()
|
||||
.getPackageStateInternal(mPackageName);
|
||||
if (packageState == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ final class InitAndSystemPackageHelper {
|
||||
}
|
||||
}
|
||||
OverlayConfig overlayConfig = OverlayConfig.initializeSystemInstance(
|
||||
consumer -> mPm.forEachPackage(
|
||||
consumer -> mPm.forEachPackage(mPm.snapshotComputer(),
|
||||
pkg -> consumer.accept(pkg, pkg.isSystem(),
|
||||
apkInApexPreInstalledPaths.get(pkg.getPackageName()))));
|
||||
// Prune any system packages that no longer exist.
|
||||
|
@ -527,8 +527,10 @@ final class InstallPackageHelper {
|
||||
+ android.Manifest.permission.INSTALL_PACKAGES + ".");
|
||||
}
|
||||
PackageSetting pkgSetting;
|
||||
mPm.enforceCrossUserPermission(callingUid, userId, true /* requireFullPermission */,
|
||||
true /* checkShell */, "installExistingPackage for user " + userId);
|
||||
final Computer preLockSnapshot = mPm.snapshotComputer();
|
||||
preLockSnapshot.enforceCrossUserPermission(callingUid, userId,
|
||||
true /* requireFullPermission */, true /* checkShell */,
|
||||
"installExistingPackage for user " + userId);
|
||||
if (mPm.isUserRestricted(userId, UserManager.DISALLOW_INSTALL_APPS)) {
|
||||
return PackageManager.INSTALL_FAILED_USER_RESTRICTED;
|
||||
}
|
||||
@ -543,11 +545,12 @@ final class InstallPackageHelper {
|
||||
|
||||
// writer
|
||||
synchronized (mPm.mLock) {
|
||||
final Computer snapshot = mPm.snapshotComputer();
|
||||
pkgSetting = mPm.mSettings.getPackageLPr(packageName);
|
||||
if (pkgSetting == null) {
|
||||
return PackageManager.INSTALL_FAILED_INVALID_URI;
|
||||
}
|
||||
if (!mPm.canViewInstantApps(callingUid, UserHandle.getUserId(callingUid))) {
|
||||
if (!snapshot.canViewInstantApps(callingUid, UserHandle.getUserId(callingUid))) {
|
||||
// only allow the existing package to be used if it's installed as a full
|
||||
// application for at least one user
|
||||
boolean installAllowed = false;
|
||||
@ -597,7 +600,8 @@ final class InstallPackageHelper {
|
||||
mAppDataHelper.prepareAppDataAfterInstallLIF(pkgSetting.getPkg());
|
||||
}
|
||||
}
|
||||
mPm.sendPackageAddedForUser(packageName, pkgSetting, userId, DataLoaderType.NONE);
|
||||
mPm.sendPackageAddedForUser(mPm.snapshotComputer(), packageName, pkgSetting, userId,
|
||||
DataLoaderType.NONE);
|
||||
synchronized (mPm.mLock) {
|
||||
mPm.updateSequenceNumberLP(pkgSetting, new int[]{ userId });
|
||||
}
|
||||
@ -1902,8 +1906,8 @@ final class InstallPackageHelper {
|
||||
AndroidPackage oldPackage = mPm.mPackages.get(packageName);
|
||||
|
||||
// Set the update and install times
|
||||
PackageStateInternal deletedPkgSetting = mPm.getPackageStateInternal(
|
||||
oldPackage.getPackageName());
|
||||
PackageStateInternal deletedPkgSetting = mPm.snapshotComputer()
|
||||
.getPackageStateInternal(oldPackage.getPackageName());
|
||||
reconciledPkg.mPkgSetting
|
||||
.setFirstInstallTimeFromReplaced(deletedPkgSetting, request.mAllUsers)
|
||||
.setLastUpdateTime(System.currentTimeMillis());
|
||||
@ -2571,9 +2575,10 @@ final class InstallPackageHelper {
|
||||
size = i;
|
||||
mPm.mPendingBroadcasts.clear();
|
||||
}
|
||||
final Computer snapshot = mPm.snapshotComputer();
|
||||
// Send broadcasts
|
||||
for (int i = 0; i < size; i++) {
|
||||
mPm.sendPackageChangedBroadcast(packages[i], true /* dontKillApp */,
|
||||
mPm.sendPackageChangedBroadcast(snapshot, packages[i], true /* dontKillApp */,
|
||||
components[i], uids[i], null /* reason */);
|
||||
}
|
||||
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
|
||||
@ -2592,7 +2597,7 @@ final class InstallPackageHelper {
|
||||
final boolean update = res.mRemovedInfo != null && res.mRemovedInfo.mRemovedPackage != null;
|
||||
final String packageName = res.mName;
|
||||
final PackageStateInternal pkgSetting =
|
||||
succeeded ? mPm.getPackageStateInternal(packageName) : null;
|
||||
succeeded ? mPm.snapshotComputer().getPackageStateInternal(packageName) : null;
|
||||
final boolean removedBeforeUpdate = (pkgSetting == null)
|
||||
|| (pkgSetting.isSystem() && !pkgSetting.getPath().getPath().equals(
|
||||
res.mPkg.getPath()));
|
||||
@ -2690,9 +2695,9 @@ final class InstallPackageHelper {
|
||||
// sendPackageAddedForNewUsers also deals with system apps
|
||||
int appId = UserHandle.getAppId(res.mUid);
|
||||
boolean isSystem = res.mPkg.isSystem();
|
||||
mPm.sendPackageAddedForNewUsers(packageName, isSystem || virtualPreload,
|
||||
virtualPreload /*startReceiver*/, appId, firstUserIds, firstInstantUserIds,
|
||||
dataLoaderType);
|
||||
mPm.sendPackageAddedForNewUsers(mPm.snapshotComputer(), packageName,
|
||||
isSystem || virtualPreload, virtualPreload /*startReceiver*/, appId,
|
||||
firstUserIds, firstInstantUserIds, dataLoaderType);
|
||||
|
||||
// Send added for users that don't see the package for the first time
|
||||
Bundle extras = new Bundle();
|
||||
@ -2705,7 +2710,8 @@ final class InstallPackageHelper {
|
||||
final SparseArray<int[]> newBroadcastAllowList;
|
||||
synchronized (mPm.mLock) {
|
||||
newBroadcastAllowList = mPm.mAppsFilter.getVisibilityAllowList(
|
||||
mPm.getPackageStateInternal(packageName, Process.SYSTEM_UID),
|
||||
mPm.snapshotComputer()
|
||||
.getPackageStateInternal(packageName, Process.SYSTEM_UID),
|
||||
updateUserIds, mPm.mSettings.getPackagesLocked());
|
||||
}
|
||||
mPm.sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED, packageName,
|
||||
@ -2807,11 +2813,12 @@ final class InstallPackageHelper {
|
||||
}
|
||||
} else if (!ArrayUtils.isEmpty(res.mLibraryConsumers)) { // if static shared lib
|
||||
// No need to kill consumers if it's installation of new version static shared lib.
|
||||
final Computer snapshot = mPm.snapshotComputer();
|
||||
final boolean dontKillApp = !update && res.mPkg.getStaticSharedLibName() != null;
|
||||
for (int i = 0; i < res.mLibraryConsumers.size(); i++) {
|
||||
AndroidPackage pkg = res.mLibraryConsumers.get(i);
|
||||
// send broadcast that all consumers of the static shared library have changed
|
||||
mPm.sendPackageChangedBroadcast(pkg.getPackageName(), dontKillApp,
|
||||
mPm.sendPackageChangedBroadcast(snapshot, pkg.getPackageName(), dontKillApp,
|
||||
new ArrayList<>(Collections.singletonList(pkg.getPackageName())),
|
||||
pkg.getUid(), null);
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.server.pm;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.content.Context;
|
||||
import android.content.pm.IPackageManager;
|
||||
import android.content.pm.ModuleInfo;
|
||||
@ -25,6 +26,7 @@ import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.XmlResourceParser;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.UserHandle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
@ -58,7 +60,7 @@ public class ModuleInfoProvider {
|
||||
private static final String MODULE_METADATA_KEY = "android.content.pm.MODULE_METADATA";
|
||||
|
||||
private final Context mContext;
|
||||
private final IPackageManager mPackageManager;
|
||||
private IPackageManager mPackageManager;
|
||||
private final ApexManager mApexManager;
|
||||
private final Map<String, ModuleInfo> mModuleInfo;
|
||||
|
||||
@ -66,9 +68,8 @@ public class ModuleInfoProvider {
|
||||
private volatile boolean mMetadataLoaded;
|
||||
private volatile String mPackageName;
|
||||
|
||||
ModuleInfoProvider(Context context, IPackageManager packageManager) {
|
||||
ModuleInfoProvider(Context context) {
|
||||
mContext = context;
|
||||
mPackageManager = packageManager;
|
||||
mApexManager = ApexManager.getInstance();
|
||||
mModuleInfo = new ArrayMap<>();
|
||||
}
|
||||
@ -77,12 +78,20 @@ public class ModuleInfoProvider {
|
||||
public ModuleInfoProvider(
|
||||
XmlResourceParser metadata, Resources resources, ApexManager apexManager) {
|
||||
mContext = null;
|
||||
mPackageManager = null;
|
||||
mApexManager = apexManager;
|
||||
mModuleInfo = new ArrayMap<>();
|
||||
loadModuleMetadata(metadata, resources);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private IPackageManager getPackageManager() {
|
||||
if (mPackageManager == null) {
|
||||
mPackageManager = IPackageManager.Stub.asInterface(
|
||||
ServiceManager.getService("package"));
|
||||
}
|
||||
return mPackageManager;
|
||||
}
|
||||
|
||||
/** Called by the {@code PackageManager} when it has completed its boot sequence */
|
||||
public void systemReady() {
|
||||
mPackageName = mContext.getResources().getString(
|
||||
@ -95,7 +104,7 @@ public class ModuleInfoProvider {
|
||||
final Resources packageResources;
|
||||
final PackageInfo pi;
|
||||
try {
|
||||
pi = mPackageManager.getPackageInfo(mPackageName,
|
||||
pi = getPackageManager().getPackageInfo(mPackageName,
|
||||
PackageManager.GET_META_DATA, UserHandle.USER_SYSTEM);
|
||||
|
||||
Context packageContext = mContext.createPackageContext(mPackageName, 0);
|
||||
@ -183,7 +192,7 @@ public class ModuleInfoProvider {
|
||||
|
||||
List<PackageInfo> allPackages;
|
||||
try {
|
||||
allPackages = mPackageManager.getInstalledPackages(
|
||||
allPackages = getPackageManager().getInstalledPackages(
|
||||
flags | PackageManager.MATCH_APEX, UserHandle.getCallingUserId()).getList();
|
||||
} catch (RemoteException e) {
|
||||
Slog.w(TAG, "Unable to retrieve all package names", e);
|
||||
|
@ -57,6 +57,8 @@ import com.android.internal.os.SomeArgs;
|
||||
import com.android.internal.util.FrameworkStatsLog;
|
||||
import com.android.server.pm.parsing.pkg.AndroidPackage;
|
||||
import com.android.server.pm.parsing.pkg.AndroidPackageUtils;
|
||||
import com.android.server.pm.pkg.PackageStateInternal;
|
||||
import com.android.server.pm.pkg.PackageStateUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Objects;
|
||||
@ -77,81 +79,74 @@ public final class MovePackageHelper {
|
||||
final StorageManager storage = mPm.mInjector.getSystemService(StorageManager.class);
|
||||
final PackageManager pm = mPm.mContext.getPackageManager();
|
||||
|
||||
final String currentVolumeUuid;
|
||||
final File codeFile;
|
||||
final InstallSource installSource;
|
||||
final String packageAbiOverride;
|
||||
final int appId;
|
||||
final String seinfo;
|
||||
final String label;
|
||||
final int targetSdkVersion;
|
||||
final PackageFreezer freezer;
|
||||
final int[] installedUserIds;
|
||||
final boolean isCurrentLocationExternal;
|
||||
Computer snapshot = mPm.snapshotComputer();
|
||||
final PackageStateInternal packageState = snapshot.getPackageStateInternal(packageName);
|
||||
if (packageState == null
|
||||
|| packageState.getPkg() == null
|
||||
|| snapshot.shouldFilterApplication(packageState, callingUid, user.getIdentifier())) {
|
||||
throw new PackageManagerException(MOVE_FAILED_DOESNT_EXIST, "Missing package");
|
||||
}
|
||||
final AndroidPackage pkg = packageState.getPkg();
|
||||
if (pkg.isSystem()) {
|
||||
throw new PackageManagerException(MOVE_FAILED_SYSTEM_PACKAGE,
|
||||
"Cannot move system application");
|
||||
}
|
||||
|
||||
final boolean isInternalStorage = VolumeInfo.ID_PRIVATE_INTERNAL.equals(volumeUuid);
|
||||
final boolean allow3rdPartyOnInternal = mPm.mContext.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_allow3rdPartyAppOnInternal);
|
||||
if (isInternalStorage && !allow3rdPartyOnInternal) {
|
||||
throw new PackageManagerException(MOVE_FAILED_3RD_PARTY_NOT_ALLOWED_ON_INTERNAL,
|
||||
"3rd party apps are not allowed on internal storage");
|
||||
}
|
||||
|
||||
|
||||
final String currentVolumeUuid = packageState.getVolumeUuid();
|
||||
|
||||
final File probe = new File(pkg.getPath());
|
||||
final File probeOat = new File(probe, "oat");
|
||||
if (!probe.isDirectory() || !probeOat.isDirectory()) {
|
||||
throw new PackageManagerException(MOVE_FAILED_INTERNAL_ERROR,
|
||||
"Move only supported for modern cluster style installs");
|
||||
}
|
||||
|
||||
if (Objects.equals(currentVolumeUuid, volumeUuid)) {
|
||||
throw new PackageManagerException(MOVE_FAILED_INTERNAL_ERROR,
|
||||
"Package already moved to " + volumeUuid);
|
||||
}
|
||||
if (!pkg.isExternalStorage()
|
||||
&& mPm.isPackageDeviceAdminOnAnyUser(snapshot, packageName)) {
|
||||
throw new PackageManagerException(MOVE_FAILED_DEVICE_ADMIN,
|
||||
"Device admin cannot be moved");
|
||||
}
|
||||
|
||||
if (snapshot.getFrozenPackages().containsKey(packageName)) {
|
||||
throw new PackageManagerException(MOVE_FAILED_OPERATION_PENDING,
|
||||
"Failed to move already frozen package");
|
||||
}
|
||||
|
||||
final boolean isCurrentLocationExternal = pkg.isExternalStorage();
|
||||
final File codeFile = new File(pkg.getPath());
|
||||
final InstallSource installSource = packageState.getInstallSource();
|
||||
final String packageAbiOverride = packageState.getCpuAbiOverride();
|
||||
final int appId = UserHandle.getAppId(pkg.getUid());
|
||||
final String seinfo = AndroidPackageUtils.getSeInfo(pkg, packageState);
|
||||
final String label = String.valueOf(pm.getApplicationLabel(
|
||||
AndroidPackageUtils.generateAppInfoWithoutState(pkg)));
|
||||
final int targetSdkVersion = pkg.getTargetSdkVersion();
|
||||
final int[] installedUserIds = PackageStateUtils.queryInstalledUsers(packageState,
|
||||
mPm.mUserManager.getUserIds(), true);
|
||||
final String fromCodePath;
|
||||
if (codeFile.getParentFile().getName().startsWith(
|
||||
PackageManagerService.RANDOM_DIR_PREFIX)) {
|
||||
fromCodePath = codeFile.getParentFile().getAbsolutePath();
|
||||
} else {
|
||||
fromCodePath = codeFile.getAbsolutePath();
|
||||
}
|
||||
|
||||
// reader
|
||||
final PackageFreezer freezer;
|
||||
synchronized (mPm.mLock) {
|
||||
final AndroidPackage pkg = mPm.mPackages.get(packageName);
|
||||
final PackageSetting ps = mPm.mSettings.getPackageLPr(packageName);
|
||||
if (pkg == null
|
||||
|| ps == null
|
||||
|| mPm.shouldFilterApplication(ps, callingUid, user.getIdentifier())) {
|
||||
throw new PackageManagerException(MOVE_FAILED_DOESNT_EXIST, "Missing package");
|
||||
}
|
||||
if (pkg.isSystem()) {
|
||||
throw new PackageManagerException(MOVE_FAILED_SYSTEM_PACKAGE,
|
||||
"Cannot move system application");
|
||||
}
|
||||
|
||||
final boolean isInternalStorage = VolumeInfo.ID_PRIVATE_INTERNAL.equals(volumeUuid);
|
||||
final boolean allow3rdPartyOnInternal = mPm.mContext.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_allow3rdPartyAppOnInternal);
|
||||
if (isInternalStorage && !allow3rdPartyOnInternal) {
|
||||
throw new PackageManagerException(MOVE_FAILED_3RD_PARTY_NOT_ALLOWED_ON_INTERNAL,
|
||||
"3rd party apps are not allowed on internal storage");
|
||||
}
|
||||
|
||||
currentVolumeUuid = ps.getVolumeUuid();
|
||||
|
||||
final File probe = new File(pkg.getPath());
|
||||
final File probeOat = new File(probe, "oat");
|
||||
if (!probe.isDirectory() || !probeOat.isDirectory()) {
|
||||
throw new PackageManagerException(MOVE_FAILED_INTERNAL_ERROR,
|
||||
"Move only supported for modern cluster style installs");
|
||||
}
|
||||
|
||||
if (Objects.equals(currentVolumeUuid, volumeUuid)) {
|
||||
throw new PackageManagerException(MOVE_FAILED_INTERNAL_ERROR,
|
||||
"Package already moved to " + volumeUuid);
|
||||
}
|
||||
if (!pkg.isExternalStorage() && mPm.isPackageDeviceAdminOnAnyUser(packageName)) {
|
||||
throw new PackageManagerException(MOVE_FAILED_DEVICE_ADMIN,
|
||||
"Device admin cannot be moved");
|
||||
}
|
||||
|
||||
if (mPm.mFrozenPackages.containsKey(packageName)) {
|
||||
throw new PackageManagerException(MOVE_FAILED_OPERATION_PENDING,
|
||||
"Failed to move already frozen package");
|
||||
}
|
||||
|
||||
isCurrentLocationExternal = pkg.isExternalStorage();
|
||||
codeFile = new File(pkg.getPath());
|
||||
installSource = ps.getInstallSource();
|
||||
packageAbiOverride = ps.getCpuAbiOverride();
|
||||
appId = UserHandle.getAppId(pkg.getUid());
|
||||
seinfo = AndroidPackageUtils.getSeInfo(pkg, ps);
|
||||
label = String.valueOf(pm.getApplicationLabel(
|
||||
AndroidPackageUtils.generateAppInfoWithoutState(pkg)));
|
||||
targetSdkVersion = pkg.getTargetSdkVersion();
|
||||
freezer = mPm.freezePackage(packageName, "movePackageInternal");
|
||||
installedUserIds = ps.queryInstalledUsers(mPm.mUserManager.getUserIds(), true);
|
||||
if (codeFile.getParentFile().getName().startsWith(
|
||||
PackageManagerService.RANDOM_DIR_PREFIX)) {
|
||||
fromCodePath = codeFile.getParentFile().getAbsolutePath();
|
||||
} else {
|
||||
fromCodePath = codeFile.getAbsolutePath();
|
||||
}
|
||||
}
|
||||
|
||||
final Bundle extras = new Bundle();
|
||||
|
@ -131,8 +131,9 @@ public class OtaDexoptService extends IOtaDexopt.Stub {
|
||||
Predicate<PackageStateInternal> isPlatformPackage = pkgSetting ->
|
||||
PLATFORM_PACKAGE_NAME.equals(pkgSetting.getPkg().getPackageName());
|
||||
// Important: the packages we need to run with ab-ota compiler-reason.
|
||||
final Computer snapshot = mPackageManagerService.snapshotComputer();
|
||||
final Collection<? extends PackageStateInternal> allPackageStates =
|
||||
mPackageManagerService.getPackageStates().values();
|
||||
snapshot.getPackageStates().values();
|
||||
important = DexOptHelper.getPackagesForDexopt(allPackageStates,mPackageManagerService,
|
||||
DEBUG_DEXOPT);
|
||||
// Remove Platform Package from A/B OTA b/160735835.
|
||||
@ -165,7 +166,7 @@ public class OtaDexoptService extends IOtaDexopt.Stub {
|
||||
Log.i(TAG, "Low on space, deleting oat files in an attempt to free up space: "
|
||||
+ DexOptHelper.packagesToString(others));
|
||||
for (PackageStateInternal pkg : others) {
|
||||
mPackageManagerService.deleteOatArtifactsOfPackage(pkg.getPackageName());
|
||||
mPackageManagerService.deleteOatArtifactsOfPackage(snapshot, pkg.getPackageName());
|
||||
}
|
||||
}
|
||||
long spaceAvailableNow = getAvailableSpace();
|
||||
|
@ -597,8 +597,8 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
|
||||
String installerAttributionTag, int userId)
|
||||
throws IOException {
|
||||
final int callingUid = Binder.getCallingUid();
|
||||
mPm.enforceCrossUserPermission(
|
||||
callingUid, userId, true, true, "createSession");
|
||||
final Computer snapshot = mPm.snapshotComputer();
|
||||
snapshot.enforceCrossUserPermission(callingUid, userId, true, true, "createSession");
|
||||
|
||||
if (mPm.isUserRestricted(userId, UserManager.DISALLOW_INSTALL_APPS)) {
|
||||
throw new SecurityException("User restriction prevents installing");
|
||||
@ -663,7 +663,7 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
|
||||
params.installFlags &= ~PackageManager.INSTALL_ALL_USERS;
|
||||
params.installFlags |= PackageManager.INSTALL_REPLACE_EXISTING;
|
||||
if ((params.installFlags & PackageManager.INSTALL_VIRTUAL_PRELOAD) != 0
|
||||
&& !mPm.isCallerVerifier(callingUid)) {
|
||||
&& !mPm.isCallerVerifier(snapshot, callingUid)) {
|
||||
params.installFlags &= ~PackageManager.INSTALL_VIRTUAL_PRELOAD;
|
||||
}
|
||||
if (mContext.checkCallingOrSelfPermission(
|
||||
@ -676,7 +676,7 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
|
||||
String originatingPackageName = null;
|
||||
if (params.originatingUid != SessionParams.UID_UNKNOWN
|
||||
&& params.originatingUid != callingUid) {
|
||||
String[] packages = mPm.mIPackageManager.getPackagesForUid(params.originatingUid);
|
||||
String[] packages = snapshot.getPackagesForUid(params.originatingUid);
|
||||
if (packages != null && packages.length > 0) {
|
||||
// Choose an arbitrary representative package in the case of a shared UID.
|
||||
originatingPackageName = packages[0];
|
||||
@ -727,7 +727,7 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
|
||||
|
||||
if ((params.installFlags & PackageManager.INSTALL_INSTANT_APP) != 0
|
||||
&& !isCalledBySystemOrShell(callingUid)
|
||||
&& (mPm.mIPackageManager.getFlagsForUid(callingUid) & ApplicationInfo.FLAG_SYSTEM)
|
||||
&& (snapshot.getFlagsForUid(callingUid) & ApplicationInfo.FLAG_SYSTEM)
|
||||
== 0) {
|
||||
throw new SecurityException(
|
||||
"Only system apps could use the PackageManager.INSTALL_INSTANT_APP flag.");
|
||||
@ -1038,11 +1038,12 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
|
||||
return "smdl" + sessionId + ".tmp";
|
||||
}
|
||||
|
||||
private boolean shouldFilterSession(int uid, SessionInfo info) {
|
||||
private boolean shouldFilterSession(@NonNull Computer snapshot, int uid, SessionInfo info) {
|
||||
if (info == null) {
|
||||
return false;
|
||||
}
|
||||
return uid != info.getInstallerUid() && !mPm.canQueryPackage(uid, info.getAppPackageName());
|
||||
return uid != info.getInstallerUid()
|
||||
&& !snapshot.canQueryPackage(uid, info.getAppPackageName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1055,7 +1056,7 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
|
||||
? session.generateInfoForCaller(true /* includeIcon */, callingUid)
|
||||
: null;
|
||||
}
|
||||
return shouldFilterSession(callingUid, result) ? null : result;
|
||||
return shouldFilterSession(mPm.snapshotComputer(), callingUid, result) ? null : result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1070,15 +1071,16 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
|
||||
}
|
||||
}
|
||||
}
|
||||
result.removeIf(info -> shouldFilterSession(callingUid, info));
|
||||
final Computer snapshot = mPm.snapshotComputer();
|
||||
result.removeIf(info -> shouldFilterSession(snapshot, callingUid, info));
|
||||
return new ParceledListSlice<>(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParceledListSlice<SessionInfo> getAllSessions(int userId) {
|
||||
final int callingUid = Binder.getCallingUid();
|
||||
mPm.enforceCrossUserPermission(
|
||||
callingUid, userId, true, false, "getAllSessions");
|
||||
final Computer snapshot = mPm.snapshotComputer();
|
||||
snapshot.enforceCrossUserPermission(callingUid, userId, true, false, "getAllSessions");
|
||||
|
||||
final List<SessionInfo> result = new ArrayList<>();
|
||||
synchronized (mSessions) {
|
||||
@ -1090,15 +1092,16 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
|
||||
}
|
||||
}
|
||||
}
|
||||
result.removeIf(info -> shouldFilterSession(callingUid, info));
|
||||
result.removeIf(info -> shouldFilterSession(snapshot, callingUid, info));
|
||||
return new ParceledListSlice<>(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParceledListSlice<SessionInfo> getMySessions(String installerPackageName, int userId) {
|
||||
mPm.enforceCrossUserPermission(
|
||||
Binder.getCallingUid(), userId, true, false, "getMySessions");
|
||||
mAppOps.checkPackage(Binder.getCallingUid(), installerPackageName);
|
||||
final Computer snapshot = mPm.snapshotComputer();
|
||||
final int callingUid = Binder.getCallingUid();
|
||||
snapshot.enforceCrossUserPermission(callingUid, userId, true, false, "getMySessions");
|
||||
mAppOps.checkPackage(callingUid, installerPackageName);
|
||||
|
||||
final List<SessionInfo> result = new ArrayList<>();
|
||||
synchronized (mSessions) {
|
||||
@ -1120,8 +1123,9 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
|
||||
@Override
|
||||
public void uninstall(VersionedPackage versionedPackage, String callerPackageName, int flags,
|
||||
IntentSender statusReceiver, int userId) {
|
||||
final Computer snapshot = mPm.snapshotComputer();
|
||||
final int callingUid = Binder.getCallingUid();
|
||||
mPm.enforceCrossUserPermission(callingUid, userId, true, true, "uninstall");
|
||||
snapshot.enforceCrossUserPermission(callingUid, userId, true, true, "uninstall");
|
||||
if ((callingUid != Process.SHELL_UID) && (callingUid != Process.ROOT_UID)) {
|
||||
mAppOps.checkPackage(callingUid, callerPackageName);
|
||||
}
|
||||
@ -1154,8 +1158,7 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
|
||||
.setAdmin(callerPackageName)
|
||||
.write();
|
||||
} else {
|
||||
ApplicationInfo appInfo = mPm.mIPackageManager
|
||||
.getApplicationInfo(callerPackageName, 0, userId);
|
||||
ApplicationInfo appInfo = snapshot.getApplicationInfo(callerPackageName, 0, userId);
|
||||
if (appInfo.targetSdkVersion >= Build.VERSION_CODES.P) {
|
||||
mContext.enforceCallingOrSelfPermission(Manifest.permission.REQUEST_DELETE_PACKAGES,
|
||||
null);
|
||||
@ -1174,7 +1177,8 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
|
||||
String callerPackageName, IntentSender statusReceiver, int userId) {
|
||||
final int callingUid = Binder.getCallingUid();
|
||||
mContext.enforceCallingOrSelfPermission(Manifest.permission.DELETE_PACKAGES, null);
|
||||
mPm.enforceCrossUserPermission(callingUid, userId, true, true, "uninstall");
|
||||
final Computer snapshot = mPm.snapshotComputer();
|
||||
snapshot.enforceCrossUserPermission(callingUid, userId, true, true, "uninstall");
|
||||
if ((callingUid != Process.SHELL_UID) && (callingUid != Process.ROOT_UID)) {
|
||||
mAppOps.checkPackage(callingUid, callerPackageName);
|
||||
}
|
||||
@ -1206,8 +1210,9 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
|
||||
|
||||
@Override
|
||||
public void registerCallback(IPackageInstallerCallback callback, int userId) {
|
||||
mPm.enforceCrossUserPermission(
|
||||
Binder.getCallingUid(), userId, true, false, "registerCallback");
|
||||
final Computer snapshot = mPm.snapshotComputer();
|
||||
snapshot.enforceCrossUserPermission(Binder.getCallingUid(), userId, true, false,
|
||||
"registerCallback");
|
||||
registerCallback(callback, eventUserId -> userId == eventUserId);
|
||||
}
|
||||
|
||||
@ -1295,13 +1300,13 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shouldFilterSession(int uid, int sessionId) {
|
||||
private boolean shouldFilterSession(@NonNull Computer snapshot, int uid, int sessionId) {
|
||||
final PackageInstallerSession session = getSession(sessionId);
|
||||
if (session == null) {
|
||||
return false;
|
||||
}
|
||||
return uid != session.getInstallerUid()
|
||||
&& !mPm.canQueryPackage(uid, session.getPackageName());
|
||||
&& !snapshot.canQueryPackage(uid, session.getPackageName());
|
||||
}
|
||||
|
||||
static class PackageDeleteObserverAdapter extends PackageDeleteObserver {
|
||||
@ -1454,11 +1459,12 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
|
||||
final int sessionId = msg.arg1;
|
||||
final int userId = msg.arg2;
|
||||
final int n = mCallbacks.beginBroadcast();
|
||||
final Computer snapshot = mPm.snapshotComputer();
|
||||
for (int i = 0; i < n; i++) {
|
||||
final IPackageInstallerCallback callback = mCallbacks.getBroadcastItem(i);
|
||||
final BroadcastCookie cookie = (BroadcastCookie) mCallbacks.getBroadcastCookie(i);
|
||||
if (cookie.userCheck.test(userId)
|
||||
&& !shouldFilterSession(cookie.callingUid, sessionId)) {
|
||||
&& !shouldFilterSession(snapshot, cookie.callingUid, sessionId)) {
|
||||
try {
|
||||
invokeCallback(callback, msg);
|
||||
} catch (RemoteException ignored) {
|
||||
|
@ -860,7 +860,8 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
|
||||
return USER_ACTION_NOT_NEEDED;
|
||||
}
|
||||
|
||||
if (mPm.isInstallDisabledForPackage(getInstallerPackageName(), mInstallerUid, userId)) {
|
||||
if (snapshot.isInstallDisabledForPackage(getInstallerPackageName(), mInstallerUid,
|
||||
userId)) {
|
||||
// show the installer to account for device poslicy or unknown sources use cases
|
||||
return USER_ACTION_REQUIRED;
|
||||
}
|
||||
@ -3755,7 +3756,8 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
|
||||
};
|
||||
|
||||
if (!manualStartAndDestroy) {
|
||||
final PerUidReadTimeouts[] perUidReadTimeouts = mPm.getPerUidReadTimeouts();
|
||||
final PerUidReadTimeouts[] perUidReadTimeouts =
|
||||
mPm.getPerUidReadTimeouts(mPm.snapshotComputer());
|
||||
|
||||
final StorageHealthCheckParams healthCheckParams = new StorageHealthCheckParams();
|
||||
healthCheckParams.blockedTimeoutMs = INCREMENTAL_STORAGE_BLOCKED_TIMEOUT_MS;
|
||||
|
@ -0,0 +1,751 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.server.pm;
|
||||
|
||||
import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
|
||||
import static android.content.pm.PackageManager.RESTRICTION_NONE;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.UserIdInt;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.AuxiliaryResolveInfo;
|
||||
import android.content.pm.Checksum;
|
||||
import android.content.pm.IOnChecksumsReadyListener;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManagerInternal;
|
||||
import android.content.pm.ProcessInfo;
|
||||
import android.content.pm.ProviderInfo;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.SuspendDialogInfo;
|
||||
import android.os.Binder;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Process;
|
||||
import android.os.storage.StorageManager;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.ArraySet;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import com.android.server.pm.dex.DexManager;
|
||||
import com.android.server.pm.dex.DynamicCodeLogger;
|
||||
import com.android.server.pm.parsing.pkg.AndroidPackage;
|
||||
import com.android.server.pm.permission.PermissionManagerServiceInternal;
|
||||
import com.android.server.pm.pkg.AndroidPackageApi;
|
||||
import com.android.server.pm.pkg.PackageStateInternal;
|
||||
import com.android.server.pm.pkg.PackageStateUtils;
|
||||
import com.android.server.pm.pkg.SharedUserApi;
|
||||
import com.android.server.pm.pkg.component.ParsedMainComponent;
|
||||
import com.android.server.pm.pkg.mutate.PackageStateMutator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Internal manager variant of {@link IPackageManagerBase}. See that class for info.
|
||||
* {@link PackageManagerInternal} should eventually passing in a snapshot instance, deprecating
|
||||
* this class, but that requires much larger refactor.
|
||||
*/
|
||||
abstract class PackageManagerInternalBase extends PackageManagerInternal {
|
||||
|
||||
@NonNull
|
||||
private final PackageManagerService mService;
|
||||
|
||||
public PackageManagerInternalBase(@NonNull PackageManagerService service) {
|
||||
mService = service;
|
||||
}
|
||||
|
||||
@NonNull protected abstract Context getContext();
|
||||
@NonNull protected abstract PermissionManagerServiceInternal getPermissionManager();
|
||||
@NonNull protected abstract AppDataHelper getAppDataHelper();
|
||||
@NonNull protected abstract PackageObserverHelper getPackageObserverHelper();
|
||||
@NonNull protected abstract ResolveIntentHelper getResolveIntentHelper();
|
||||
@NonNull protected abstract SuspendPackageHelper getSuspendPackageHelper();
|
||||
@NonNull protected abstract ProtectedPackages getProtectedPackages();
|
||||
@NonNull protected abstract UserNeedsBadgingCache getUserNeedsBadging();
|
||||
@NonNull protected abstract InstantAppRegistry getInstantAppRegistry();
|
||||
@NonNull protected abstract ApexManager getApexManager();
|
||||
@NonNull protected abstract DexManager getDexManager();
|
||||
|
||||
@Override
|
||||
public final Computer snapshot() {
|
||||
return mService.snapshotComputer();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final List<ApplicationInfo> getInstalledApplications(
|
||||
@PackageManager.ApplicationInfoFlagsBits long flags, int userId, int callingUid) {
|
||||
return snapshot().getInstalledApplications(flags, userId, callingUid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean isInstantApp(String packageName, int userId) {
|
||||
return snapshot().isInstantApp(packageName, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final String getInstantAppPackageName(int uid) {
|
||||
return snapshot().getInstantAppPackageName(uid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean filterAppAccess(AndroidPackage pkg, int callingUid, int userId) {
|
||||
return snapshot().filterAppAccess(pkg, callingUid, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean filterAppAccess(String packageName, int callingUid, int userId) {
|
||||
return snapshot().filterAppAccess(packageName, callingUid, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean filterAppAccess(int uid, int callingUid) {
|
||||
return snapshot().filterAppAccess(uid, callingUid);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@Deprecated
|
||||
public final int[] getVisibilityAllowList(@NonNull String packageName, int userId) {
|
||||
return snapshot().getVisibilityAllowList(packageName, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean canQueryPackage(int callingUid, @Nullable String packageName) {
|
||||
return snapshot().canQueryPackage(callingUid, packageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final AndroidPackage getPackage(String packageName) {
|
||||
return snapshot().getPackage(packageName);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@Deprecated
|
||||
public final AndroidPackageApi getAndroidPackage(@NonNull String packageName) {
|
||||
return snapshot().getPackage(packageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final AndroidPackage getPackage(int uid) {
|
||||
return snapshot().getPackage(uid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final List<AndroidPackage> getPackagesForAppId(int appId) {
|
||||
return snapshot().getPackagesForAppId(appId);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@Deprecated
|
||||
public final PackageStateInternal getPackageStateInternal(String packageName) {
|
||||
return snapshot().getPackageStateInternal(packageName);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
@Deprecated
|
||||
public final ArrayMap<String, ? extends PackageStateInternal> getPackageStates() {
|
||||
return snapshot().getPackageStates();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void removePackageListObserver(PackageListObserver observer) {
|
||||
getPackageObserverHelper().removeObserver(observer);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final PackageStateInternal getDisabledSystemPackage(@NonNull String packageName) {
|
||||
return snapshot().getDisabledSystemPackage(packageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final @NonNull String[] getKnownPackageNames(int knownPackage, int userId) {
|
||||
return mService.getKnownPackageNamesInternal(snapshot(), knownPackage, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void setKeepUninstalledPackages(final List<String> packageList) {
|
||||
mService.setKeepUninstalledPackagesInternal(snapshot(), packageList);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean isPermissionsReviewRequired(String packageName, int userId) {
|
||||
return getPermissionManager().isPermissionsReviewRequired(packageName, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final PackageInfo getPackageInfo(String packageName,
|
||||
@PackageManager.PackageInfoFlagsBits long flags, int filterCallingUid, int userId) {
|
||||
return snapshot().getPackageInfoInternal(packageName,
|
||||
PackageManager.VERSION_CODE_HIGHEST, flags, filterCallingUid, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final Bundle getSuspendedPackageLauncherExtras(String packageName, int userId) {
|
||||
return getSuspendPackageHelper().getSuspendedPackageLauncherExtras(snapshot(), packageName,
|
||||
userId, Binder.getCallingUid());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean isPackageSuspended(String packageName, int userId) {
|
||||
return getSuspendPackageHelper().isPackageSuspended(snapshot(), packageName, userId,
|
||||
Binder.getCallingUid());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void removeNonSystemPackageSuspensions(String packageName, int userId) {
|
||||
getSuspendPackageHelper().removeSuspensionsBySuspendingPackage(snapshot(),
|
||||
new String[]{packageName},
|
||||
(suspendingPackage) -> !PackageManagerService.PLATFORM_PACKAGE_NAME.equals(
|
||||
suspendingPackage),
|
||||
userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void removeDistractingPackageRestrictions(String packageName, int userId) {
|
||||
mService.removeDistractingPackageRestrictions(snapshot(), new String[]{packageName},
|
||||
userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void removeAllDistractingPackageRestrictions(int userId) {
|
||||
mService.removeAllDistractingPackageRestrictions(snapshot(), userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final String getSuspendingPackage(String suspendedPackage, int userId) {
|
||||
return getSuspendPackageHelper().getSuspendingPackage(snapshot(), suspendedPackage, userId,
|
||||
Binder.getCallingUid());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final SuspendDialogInfo getSuspendedDialogInfo(String suspendedPackage,
|
||||
String suspendingPackage, int userId) {
|
||||
return getSuspendPackageHelper().getSuspendedDialogInfo(snapshot(), suspendedPackage,
|
||||
suspendingPackage, userId, Binder.getCallingUid());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final int getDistractingPackageRestrictions(String packageName, int userId) {
|
||||
final PackageStateInternal packageState = getPackageStateInternal(packageName);
|
||||
return (packageState == null) ? RESTRICTION_NONE
|
||||
: packageState.getUserStateOrDefault(userId).getDistractionFlags();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final int getPackageUid(String packageName,
|
||||
@PackageManager.PackageInfoFlagsBits long flags, int userId) {
|
||||
return snapshot().getPackageUidInternal(packageName, flags, userId, Process.SYSTEM_UID);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final ApplicationInfo getApplicationInfo(String packageName,
|
||||
@PackageManager.ApplicationInfoFlagsBits long flags, int filterCallingUid, int userId) {
|
||||
return snapshot().getApplicationInfoInternal(packageName, flags, filterCallingUid, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final ActivityInfo getActivityInfo(ComponentName component,
|
||||
@PackageManager.ComponentInfoFlagsBits long flags, int filterCallingUid, int userId) {
|
||||
return snapshot().getActivityInfoInternal(component, flags, filterCallingUid, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final List<ResolveInfo> queryIntentActivities(
|
||||
Intent intent, String resolvedType, @PackageManager.ResolveInfoFlagsBits long flags,
|
||||
int filterCallingUid, int userId) {
|
||||
return snapshot().queryIntentActivitiesInternal(intent, resolvedType, flags, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final List<ResolveInfo> queryIntentReceivers(Intent intent,
|
||||
String resolvedType, @PackageManager.ResolveInfoFlagsBits long flags,
|
||||
int filterCallingUid, int userId) {
|
||||
return getResolveIntentHelper().queryIntentReceiversInternal(
|
||||
snapshot(), intent, resolvedType, flags, userId, filterCallingUid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final List<ResolveInfo> queryIntentServices(
|
||||
Intent intent, @PackageManager.ResolveInfoFlagsBits long flags, int callingUid,
|
||||
int userId) {
|
||||
final String resolvedType = intent.resolveTypeIfNeeded(getContext().getContentResolver());
|
||||
return snapshot().queryIntentServicesInternal(intent, resolvedType, flags, userId,
|
||||
callingUid, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final ComponentName getHomeActivitiesAsUser(List<ResolveInfo> allHomeCandidates,
|
||||
int userId) {
|
||||
return snapshot().getHomeActivitiesAsUser(allHomeCandidates, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final ComponentName getDefaultHomeActivity(int userId) {
|
||||
return snapshot().getDefaultHomeActivity(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final ComponentName getSystemUiServiceComponent() {
|
||||
return ComponentName.unflattenFromString(getContext().getResources().getString(
|
||||
com.android.internal.R.string.config_systemUIServiceComponent));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void setDeviceOwnerProtectedPackages(
|
||||
String deviceOwnerPackageName, List<String> packageNames) {
|
||||
getProtectedPackages().setDeviceOwnerProtectedPackages(
|
||||
deviceOwnerPackageName, packageNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean isPackageDataProtected(int userId, String packageName) {
|
||||
return getProtectedPackages().isPackageDataProtected(userId, packageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean isPackageStateProtected(String packageName, int userId) {
|
||||
return getProtectedPackages().isPackageStateProtected(userId, packageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean isPackageEphemeral(int userId, String packageName) {
|
||||
final PackageStateInternal packageState = getPackageStateInternal(packageName);
|
||||
return packageState != null
|
||||
&& packageState.getUserStateOrDefault(userId).isInstantApp();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean wasPackageEverLaunched(String packageName, int userId) {
|
||||
final PackageStateInternal packageState = getPackageStateInternal(packageName);
|
||||
if (packageState == null) {
|
||||
throw new IllegalArgumentException("Unknown package: " + packageName);
|
||||
}
|
||||
return !packageState.getUserStateOrDefault(userId).isNotLaunched();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean isEnabledAndMatches(ParsedMainComponent component, long flags, int userId) {
|
||||
return PackageStateUtils.isEnabledAndMatches(
|
||||
getPackageStateInternal(component.getPackageName()), component, flags, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean userNeedsBadging(int userId) {
|
||||
return getUserNeedsBadging().get(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final String getNameForUid(int uid) {
|
||||
return snapshot().getNameForUid(uid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void requestInstantAppResolutionPhaseTwo(AuxiliaryResolveInfo responseObj,
|
||||
Intent origIntent, String resolvedType, String callingPackage,
|
||||
@Nullable String callingFeatureId, boolean isRequesterInstantApp,
|
||||
Bundle verificationBundle, int userId) {
|
||||
mService.requestInstantAppResolutionPhaseTwo(responseObj, origIntent,
|
||||
resolvedType, callingPackage, callingFeatureId, isRequesterInstantApp,
|
||||
verificationBundle, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void grantImplicitAccess(int userId, Intent intent,
|
||||
int recipientAppId, int visibleUid, boolean direct) {
|
||||
grantImplicitAccess(userId, intent, recipientAppId, visibleUid, direct,
|
||||
false /* retainOnUpdate */);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void grantImplicitAccess(int userId, Intent intent,
|
||||
int recipientAppId, int visibleUid, boolean direct, boolean retainOnUpdate) {
|
||||
mService.grantImplicitAccess(snapshot(), userId, intent,
|
||||
recipientAppId, visibleUid, direct, retainOnUpdate);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean isInstantAppInstallerComponent(ComponentName component) {
|
||||
final ActivityInfo instantAppInstallerActivity = mService.mInstantAppInstallerActivity;
|
||||
return instantAppInstallerActivity != null
|
||||
&& instantAppInstallerActivity.getComponentName().equals(component);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void pruneInstantApps() {
|
||||
getInstantAppRegistry().pruneInstantApps(snapshot());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final String getSetupWizardPackageName() {
|
||||
return mService.mSetupWizardPackage;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final ResolveInfo resolveIntent(Intent intent, String resolvedType,
|
||||
@PackageManager.ResolveInfoFlagsBits long flags,
|
||||
@PackageManagerInternal.PrivateResolveFlags long privateResolveFlags, int userId,
|
||||
boolean resolveForStart, int filterCallingUid) {
|
||||
return getResolveIntentHelper().resolveIntentInternal(snapshot(),
|
||||
intent, resolvedType, flags, privateResolveFlags, userId, resolveForStart,
|
||||
filterCallingUid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final ResolveInfo resolveService(Intent intent, String resolvedType,
|
||||
@PackageManager.ResolveInfoFlagsBits long flags, int userId, int callingUid) {
|
||||
return getResolveIntentHelper().resolveServiceInternal(snapshot(), intent,
|
||||
resolvedType, flags, userId, callingUid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final ProviderInfo resolveContentProvider(String name,
|
||||
@PackageManager.ResolveInfoFlagsBits long flags, int userId, int callingUid) {
|
||||
return snapshot().resolveContentProvider(name, flags, userId,callingUid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final int getUidTargetSdkVersion(int uid) {
|
||||
return snapshot().getUidTargetSdkVersion(uid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final int getPackageTargetSdkVersion(String packageName) {
|
||||
final PackageStateInternal packageState = getPackageStateInternal(packageName);
|
||||
if (packageState != null && packageState.getPkg() != null) {
|
||||
return packageState.getPkg().getTargetSdkVersion();
|
||||
}
|
||||
return Build.VERSION_CODES.CUR_DEVELOPMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean canAccessInstantApps(int callingUid, @UserIdInt int userId) {
|
||||
return snapshot().canViewInstantApps(callingUid, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean canAccessComponent(int callingUid, @NonNull ComponentName component,
|
||||
@UserIdInt int userId) {
|
||||
return snapshot().canAccessComponent(callingUid, component, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean hasInstantApplicationMetadata(String packageName, int userId) {
|
||||
return getInstantAppRegistry().hasInstantApplicationMetadata(packageName, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final SparseArray<String> getAppsWithSharedUserIds() {
|
||||
return snapshot().getAppsWithSharedUserIds();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
@Deprecated
|
||||
public final String[] getSharedUserPackagesForPackage(String packageName, int userId) {
|
||||
return snapshot().getSharedUserPackagesForPackage(packageName, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final ArrayMap<String, ProcessInfo> getProcessesForUid(int uid) {
|
||||
return snapshot().getProcessesForUid(uid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final int[] getPermissionGids(String permissionName, int userId) {
|
||||
return getPermissionManager().getPermissionGids(permissionName, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean isOnlyCoreApps() {
|
||||
return mService.isOnlyCoreApps();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void freeStorage(String volumeUuid, long bytes,
|
||||
@StorageManager.AllocateFlags int flags) throws IOException {
|
||||
mService.freeStorage(volumeUuid, bytes, flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void freeAllAppCacheAboveQuota(@NonNull String volumeUuid) throws IOException {
|
||||
mService.freeAllAppCacheAboveQuota(volumeUuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void forEachPackageSetting(Consumer<PackageSetting> actionLocked) {
|
||||
mService.forEachPackageSetting(actionLocked);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void forEachPackageState(Consumer<PackageStateInternal> action) {
|
||||
mService.forEachPackageState(snapshot(), action);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void forEachPackage(Consumer<AndroidPackage> action) {
|
||||
mService.forEachPackage(snapshot(), action);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void forEachInstalledPackage(@NonNull Consumer<AndroidPackage> action,
|
||||
@UserIdInt int userId) {
|
||||
mService.forEachInstalledPackage(snapshot(), action, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final ArraySet<String> getEnabledComponents(String packageName, int userId) {
|
||||
final PackageStateInternal packageState = getPackageStateInternal(packageName);
|
||||
if (packageState == null) {
|
||||
return new ArraySet<>();
|
||||
}
|
||||
return packageState.getUserStateOrDefault(userId).getEnabledComponents();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final ArraySet<String> getDisabledComponents(String packageName, int userId) {
|
||||
final PackageStateInternal packageState = getPackageStateInternal(packageName);
|
||||
if (packageState == null) {
|
||||
return new ArraySet<>();
|
||||
}
|
||||
return packageState.getUserStateOrDefault(userId).getDisabledComponents();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final @PackageManager.EnabledState int getApplicationEnabledState(
|
||||
String packageName, int userId) {
|
||||
final PackageStateInternal packageState = getPackageStateInternal(packageName);
|
||||
if (packageState == null) {
|
||||
return COMPONENT_ENABLED_STATE_DEFAULT;
|
||||
}
|
||||
return packageState.getUserStateOrDefault(userId).getEnabledState();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final @PackageManager.EnabledState int getComponentEnabledSetting(
|
||||
@NonNull ComponentName componentName, int callingUid, int userId) {
|
||||
return snapshot().getComponentEnabledSettingInternal(
|
||||
componentName, callingUid, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void setEnableRollbackCode(int token, int enableRollbackCode) {
|
||||
mService.setEnableRollbackCode(token, enableRollbackCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void finishPackageInstall(int token, boolean didLaunch) {
|
||||
mService.finishPackageInstall(token, didLaunch);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean isApexPackage(String packageName) {
|
||||
return getApexManager().isApexPackage(packageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final List<String> getApksInApex(String apexPackageName) {
|
||||
return getApexManager().getApksInApex(apexPackageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean isCallerInstallerOfRecord(@NonNull AndroidPackage pkg, int callingUid) {
|
||||
return snapshot().isCallerInstallerOfRecord(pkg, callingUid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final List<String> getMimeGroup(String packageName, String mimeGroup) {
|
||||
return mService.getMimeGroupInternal(snapshot(), packageName, mimeGroup);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean isSystemPackage(@NonNull String packageName) {
|
||||
return packageName.equals(mService.ensureSystemPackageName(snapshot(), packageName));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void unsuspendForSuspendingPackage(final String packageName, int affectedUser) {
|
||||
mService.unsuspendForSuspendingPackage(snapshot(), packageName, affectedUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean isSuspendingAnyPackages(String suspendingPackage, int userId) {
|
||||
return snapshot().isSuspendingAnyPackages(suspendingPackage, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void requestChecksums(@NonNull 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) {
|
||||
mService.requestChecksumsInternal(snapshot(), packageName, includeSplits, optional,
|
||||
required, trustedInstallers, onChecksumsReadyListener, userId, executor,
|
||||
handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean isPackageFrozen(@NonNull String packageName,
|
||||
int callingUid, int userId) {
|
||||
return snapshot().getPackageStartability(mService.getSafeMode(), packageName, callingUid, userId)
|
||||
== PackageManagerService.PACKAGE_STARTABILITY_FROZEN;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final long deleteOatArtifactsOfPackage(String packageName) {
|
||||
return mService.deleteOatArtifactsOfPackage(snapshot(), packageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void reconcileAppsData(int userId, @StorageManager.StorageFlags int flags,
|
||||
boolean migrateAppsData) {
|
||||
getAppDataHelper().reconcileAppsData(userId, flags, migrateAppsData);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public ArraySet<PackageStateInternal> getSharedUserPackages(int sharedUserAppId) {
|
||||
return snapshot().getSharedUserPackages(sharedUserAppId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public SharedUserApi getSharedUserApi(int sharedUserAppId) {
|
||||
return snapshot().getSharedUser(sharedUserAppId);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
@Deprecated
|
||||
public final PackageStateMutator.InitialState recordInitialState() {
|
||||
return mService.recordInitialState();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@Deprecated
|
||||
public final PackageStateMutator.Result commitPackageStateMutation(
|
||||
@Nullable PackageStateMutator.InitialState state,
|
||||
@NonNull Consumer<PackageStateMutator> consumer) {
|
||||
return mService.commitPackageStateMutation(state, consumer);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void shutdown() {
|
||||
mService.shutdown();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final DynamicCodeLogger getDynamicCodeLogger() {
|
||||
return getDexManager().getDynamicCodeLogger();
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.server.pm;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.content.IIntentReceiver;
|
||||
import android.os.Bundle;
|
||||
@ -30,9 +31,9 @@ interface PackageSender {
|
||||
Bundle extras, int flags, String targetPkg,
|
||||
IIntentReceiver finishedReceiver, int[] userIds, int[] instantUserIds,
|
||||
@Nullable SparseArray<int[]> broadcastAllowList, @Nullable Bundle bOptions);
|
||||
void sendPackageAddedForNewUsers(String packageName, boolean sendBootCompleted,
|
||||
boolean includeStopped, int appId, int[] userIds, int[] instantUserIds,
|
||||
int dataLoaderType);
|
||||
void sendPackageAddedForNewUsers(@NonNull Computer snapshot, String packageName,
|
||||
boolean sendBootCompleted, boolean includeStopped, int appId, int[] userIds,
|
||||
int[] instantUserIds, int dataLoaderType);
|
||||
void notifyPackageAdded(String packageName, int uid);
|
||||
void notifyPackageChanged(String packageName, int uid);
|
||||
void notifyPackageRemoved(String packageName, int uid);
|
||||
|
@ -25,6 +25,7 @@ import static com.android.server.pm.PackageManagerService.DEBUG_PREFERRED;
|
||||
import static com.android.server.pm.PackageManagerService.TAG;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.UserIdInt;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
@ -74,17 +75,18 @@ final class PreferredActivityHelper {
|
||||
mPm = pm;
|
||||
}
|
||||
|
||||
private ResolveInfo findPreferredActivityNotLocked(Intent intent, String resolvedType,
|
||||
@PackageManager.ResolveInfoFlagsBits long flags, List<ResolveInfo> query,
|
||||
boolean always, boolean removeMatches, boolean debug, int userId) {
|
||||
return findPreferredActivityNotLocked(
|
||||
intent, resolvedType, flags, query, always, removeMatches, debug, userId,
|
||||
private ResolveInfo findPreferredActivityNotLocked(@NonNull Computer snapshot, Intent intent,
|
||||
String resolvedType, @PackageManager.ResolveInfoFlagsBits long flags,
|
||||
List<ResolveInfo> query, boolean always, boolean removeMatches, boolean debug,
|
||||
@UserIdInt int userId) {
|
||||
return findPreferredActivityNotLocked(snapshot, intent, resolvedType, flags, query, always,
|
||||
removeMatches, debug, userId,
|
||||
UserHandle.getAppId(Binder.getCallingUid()) >= Process.FIRST_APPLICATION_UID);
|
||||
}
|
||||
|
||||
// TODO: handle preferred activities missing while user has amnesia
|
||||
/** <b>must not hold {@link PackageManagerService.mLock}</b> */
|
||||
public ResolveInfo findPreferredActivityNotLocked(
|
||||
public ResolveInfo findPreferredActivityNotLocked(@NonNull Computer snapshot,
|
||||
Intent intent, String resolvedType, @PackageManager.ResolveInfoFlagsBits long flags,
|
||||
List<ResolveInfo> query, boolean always, boolean removeMatches, boolean debug,
|
||||
int userId, boolean queryMayBeFiltered) {
|
||||
@ -95,7 +97,7 @@ final class PreferredActivityHelper {
|
||||
if (!mPm.mUserManager.exists(userId)) return null;
|
||||
|
||||
PackageManagerService.FindPreferredActivityBodyResult body =
|
||||
mPm.findPreferredActivityInternal(
|
||||
snapshot.findPreferredActivityInternal(
|
||||
intent, resolvedType, flags, query, always,
|
||||
removeMatches, debug, userId, queryMayBeFiltered);
|
||||
if (body.mChanged) {
|
||||
@ -117,7 +119,7 @@ final class PreferredActivityHelper {
|
||||
mPm.clearPackagePreferredActivitiesLPw(packageName, changedUsers, userId);
|
||||
}
|
||||
if (changedUsers.size() > 0) {
|
||||
updateDefaultHomeNotLocked(changedUsers);
|
||||
updateDefaultHomeNotLocked(mPm.snapshotComputer(), changedUsers);
|
||||
mPm.postPreferredActivityChangedBroadcast(userId);
|
||||
mPm.scheduleWritePackageRestrictions(userId);
|
||||
}
|
||||
@ -128,7 +130,7 @@ final class PreferredActivityHelper {
|
||||
*
|
||||
* @return Whether the ACTION_PREFERRED_ACTIVITY_CHANGED broadcast has been scheduled.
|
||||
*/
|
||||
public boolean updateDefaultHomeNotLocked(int userId) {
|
||||
public boolean updateDefaultHomeNotLocked(@NonNull Computer snapshot, @UserIdInt int userId) {
|
||||
if (Thread.holdsLock(mPm.mLock)) {
|
||||
Slog.wtf(TAG, "Calling thread " + Thread.currentThread().getName()
|
||||
+ " is holding mLock", new Throwable());
|
||||
@ -139,10 +141,10 @@ final class PreferredActivityHelper {
|
||||
// before that.
|
||||
return false;
|
||||
}
|
||||
final Intent intent = mPm.getHomeIntent();
|
||||
final List<ResolveInfo> resolveInfos = mPm.snapshotComputer().queryIntentActivitiesInternal(
|
||||
final Intent intent = snapshot.getHomeIntent();
|
||||
final List<ResolveInfo> resolveInfos = snapshot.queryIntentActivitiesInternal(
|
||||
intent, null, MATCH_DIRECT_BOOT_AWARE | MATCH_DIRECT_BOOT_UNAWARE, userId);
|
||||
final ResolveInfo preferredResolveInfo = findPreferredActivityNotLocked(
|
||||
final ResolveInfo preferredResolveInfo = findPreferredActivityNotLocked(snapshot,
|
||||
intent, null, 0, resolveInfos, true, false, false, userId);
|
||||
final String packageName = preferredResolveInfo != null
|
||||
&& preferredResolveInfo.activityInfo != null
|
||||
@ -151,8 +153,7 @@ final class PreferredActivityHelper {
|
||||
if (TextUtils.equals(currentPackageName, packageName)) {
|
||||
return false;
|
||||
}
|
||||
final String[] callingPackages = mPm.mIPackageManager
|
||||
.getPackagesForUid(Binder.getCallingUid());
|
||||
final String[] callingPackages = snapshot.getPackagesForUid(Binder.getCallingUid());
|
||||
if (callingPackages != null && ArrayUtils.contains(callingPackages,
|
||||
mPm.mRequiredPermissionControllerPackage)) {
|
||||
// PermissionController manages default home directly.
|
||||
@ -174,23 +175,21 @@ final class PreferredActivityHelper {
|
||||
/**
|
||||
* Variant that takes a {@link WatchedIntentFilter}
|
||||
*/
|
||||
public void addPreferredActivity(WatchedIntentFilter filter, int match,
|
||||
ComponentName[] set, ComponentName activity, boolean always, int userId,
|
||||
public void addPreferredActivity(@NonNull Computer snapshot, WatchedIntentFilter filter,
|
||||
int match, ComponentName[] set, ComponentName activity, boolean always, int userId,
|
||||
String opname, boolean removeExisting) {
|
||||
// writer
|
||||
int callingUid = Binder.getCallingUid();
|
||||
mPm.enforceCrossUserPermission(callingUid, userId, true /* requireFullPermission */,
|
||||
snapshot.enforceCrossUserPermission(callingUid, userId, true /* requireFullPermission */,
|
||||
false /* checkShell */, "add preferred activity");
|
||||
if (mPm.mContext.checkCallingOrSelfPermission(
|
||||
android.Manifest.permission.SET_PREFERRED_APPLICATIONS)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
synchronized (mPm.mLock) {
|
||||
if (mPm.getUidTargetSdkVersion(callingUid)
|
||||
< Build.VERSION_CODES.FROYO) {
|
||||
Slog.w(TAG, "Ignoring addPreferredActivity() from uid "
|
||||
+ callingUid);
|
||||
return;
|
||||
}
|
||||
if (snapshot.getUidTargetSdkVersion(callingUid)
|
||||
< Build.VERSION_CODES.FROYO) {
|
||||
Slog.w(TAG, "Ignoring addPreferredActivity() from uid "
|
||||
+ callingUid);
|
||||
return;
|
||||
}
|
||||
mPm.mContext.enforceCallingOrSelfPermission(
|
||||
android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null);
|
||||
@ -214,7 +213,8 @@ final class PreferredActivityHelper {
|
||||
new PreferredActivity(filter, match, set, activity, always));
|
||||
mPm.scheduleWritePackageRestrictions(userId);
|
||||
}
|
||||
if (!(isHomeFilter(filter) && updateDefaultHomeNotLocked(userId))) {
|
||||
// Re-snapshot after mLock
|
||||
if (!(isHomeFilter(filter) && updateDefaultHomeNotLocked(mPm.snapshotComputer(), userId))) {
|
||||
mPm.postPreferredActivityChangedBroadcast(userId);
|
||||
}
|
||||
}
|
||||
@ -222,8 +222,8 @@ final class PreferredActivityHelper {
|
||||
/**
|
||||
* Variant that takes a {@link WatchedIntentFilter}
|
||||
*/
|
||||
public void replacePreferredActivity(WatchedIntentFilter filter, int match,
|
||||
ComponentName[] set, ComponentName activity, int userId) {
|
||||
public void replacePreferredActivity(@NonNull Computer snapshot, WatchedIntentFilter filter,
|
||||
int match, ComponentName[] set, ComponentName activity, int userId) {
|
||||
if (filter.countActions() != 1) {
|
||||
throw new IllegalArgumentException(
|
||||
"replacePreferredActivity expects filter to have only 1 action.");
|
||||
@ -238,13 +238,14 @@ final class PreferredActivityHelper {
|
||||
}
|
||||
|
||||
final int callingUid = Binder.getCallingUid();
|
||||
mPm.enforceCrossUserPermission(callingUid, userId, true /* requireFullPermission */,
|
||||
snapshot.enforceCrossUserPermission(callingUid, userId, true /* requireFullPermission */,
|
||||
false /* checkShell */, "replace preferred activity");
|
||||
if (mPm.mContext.checkCallingOrSelfPermission(
|
||||
android.Manifest.permission.SET_PREFERRED_APPLICATIONS)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
synchronized (mPm.mLock) {
|
||||
if (mPm.getUidTargetSdkVersion(callingUid)
|
||||
// TODO: Remove lock?
|
||||
if (mPm.snapshotComputer().getUidTargetSdkVersion(callingUid)
|
||||
< Build.VERSION_CODES.FROYO) {
|
||||
Slog.w(TAG, "Ignoring replacePreferredActivity() from uid "
|
||||
+ Binder.getCallingUid());
|
||||
@ -296,21 +297,23 @@ final class PreferredActivityHelper {
|
||||
}
|
||||
}
|
||||
}
|
||||
addPreferredActivity(filter, match, set, activity, true, userId,
|
||||
|
||||
// Retake a snapshot after editing with lock held
|
||||
addPreferredActivity(mPm.snapshotComputer(), filter, match, set, activity, true, userId,
|
||||
"Replacing preferred", false);
|
||||
}
|
||||
|
||||
public void clearPackagePreferredActivities(String packageName) {
|
||||
public void clearPackagePreferredActivities(@NonNull Computer snapshot, String packageName) {
|
||||
final int callingUid = Binder.getCallingUid();
|
||||
if (mPm.getInstantAppPackageName(callingUid) != null) {
|
||||
if (snapshot.getInstantAppPackageName(callingUid) != null) {
|
||||
return;
|
||||
}
|
||||
final PackageStateInternal packageState = mPm.getPackageStateInternal(packageName);
|
||||
if (packageState == null || !mPm.isCallerSameApp(packageName, callingUid)) {
|
||||
final PackageStateInternal packageState = snapshot.getPackageStateInternal(packageName);
|
||||
if (packageState == null || !snapshot.isCallerSameApp(packageName, callingUid)) {
|
||||
if (mPm.mContext.checkCallingOrSelfPermission(
|
||||
android.Manifest.permission.SET_PREFERRED_APPLICATIONS)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
if (mPm.getUidTargetSdkVersion(callingUid)
|
||||
if (snapshot.getUidTargetSdkVersion(callingUid)
|
||||
< Build.VERSION_CODES.FROYO) {
|
||||
Slog.w(TAG, "Ignoring clearPackagePreferredActivities() from uid "
|
||||
+ callingUid);
|
||||
@ -320,7 +323,7 @@ final class PreferredActivityHelper {
|
||||
android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null);
|
||||
}
|
||||
}
|
||||
if (packageState != null && mPm.shouldFilterApplication(packageState, callingUid,
|
||||
if (packageState != null && snapshot.shouldFilterApplication(packageState, callingUid,
|
||||
UserHandle.getUserId(callingUid))) {
|
||||
return;
|
||||
}
|
||||
@ -329,23 +332,23 @@ final class PreferredActivityHelper {
|
||||
}
|
||||
|
||||
/** <b>must not hold {@link #PackageManagerService.mLock}</b> */
|
||||
void updateDefaultHomeNotLocked(SparseBooleanArray userIds) {
|
||||
void updateDefaultHomeNotLocked(@NonNull Computer snapshot, SparseBooleanArray userIds) {
|
||||
if (Thread.holdsLock(mPm.mLock)) {
|
||||
Slog.wtf(TAG, "Calling thread " + Thread.currentThread().getName()
|
||||
+ " is holding mLock", new Throwable());
|
||||
}
|
||||
for (int i = userIds.size() - 1; i >= 0; --i) {
|
||||
final int userId = userIds.keyAt(i);
|
||||
updateDefaultHomeNotLocked(userId);
|
||||
updateDefaultHomeNotLocked(snapshot, userId);
|
||||
}
|
||||
}
|
||||
|
||||
public void setHomeActivity(ComponentName comp, int userId) {
|
||||
if (mPm.getInstantAppPackageName(Binder.getCallingUid()) != null) {
|
||||
public void setHomeActivity(@NonNull Computer snapshot, ComponentName comp, int userId) {
|
||||
if (snapshot.getInstantAppPackageName(Binder.getCallingUid()) != null) {
|
||||
return;
|
||||
}
|
||||
ArrayList<ResolveInfo> homeActivities = new ArrayList<>();
|
||||
mPm.getHomeActivitiesAsUser(homeActivities, userId);
|
||||
snapshot.getHomeActivitiesAsUser(homeActivities, userId);
|
||||
|
||||
boolean found = false;
|
||||
|
||||
@ -364,7 +367,7 @@ final class PreferredActivityHelper {
|
||||
throw new IllegalArgumentException("Component " + comp + " cannot be home on user "
|
||||
+ userId);
|
||||
}
|
||||
replacePreferredActivity(getHomeFilter(), IntentFilter.MATCH_CATEGORY_EMPTY,
|
||||
replacePreferredActivity(snapshot, getHomeFilter(), IntentFilter.MATCH_CATEGORY_EMPTY,
|
||||
set, comp, userId);
|
||||
}
|
||||
|
||||
@ -401,7 +404,7 @@ final class PreferredActivityHelper {
|
||||
mPm.scheduleWritePackageRestrictions(userId);
|
||||
}
|
||||
if (isHomeFilter(filter)) {
|
||||
updateDefaultHomeNotLocked(userId);
|
||||
updateDefaultHomeNotLocked(mPm.snapshotComputer(), userId);
|
||||
}
|
||||
mPm.postPreferredActivityChangedBroadcast(userId);
|
||||
}
|
||||
@ -417,7 +420,7 @@ final class PreferredActivityHelper {
|
||||
changed = mPm.mSettings.clearPackagePersistentPreferredActivities(packageName, userId);
|
||||
}
|
||||
if (changed) {
|
||||
updateDefaultHomeNotLocked(userId);
|
||||
updateDefaultHomeNotLocked(mPm.snapshotComputer(), userId);
|
||||
mPm.postPreferredActivityChangedBroadcast(userId);
|
||||
mPm.scheduleWritePackageRestrictions(userId);
|
||||
}
|
||||
@ -506,7 +509,7 @@ final class PreferredActivityHelper {
|
||||
synchronized (mPm.mLock) {
|
||||
mPm.mSettings.readPreferredActivitiesLPw(readParser, readUserId);
|
||||
}
|
||||
updateDefaultHomeNotLocked(readUserId);
|
||||
updateDefaultHomeNotLocked(mPm.snapshotComputer(), readUserId);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
if (DEBUG_BACKUP) {
|
||||
@ -598,7 +601,7 @@ final class PreferredActivityHelper {
|
||||
mPm.mPermissionManager.resetRuntimePermissions(pkg, userId);
|
||||
}
|
||||
}
|
||||
updateDefaultHomeNotLocked(userId);
|
||||
updateDefaultHomeNotLocked(mPm.snapshotComputer(), userId);
|
||||
resetNetworkPolicies(userId);
|
||||
mPm.scheduleWritePackageRestrictions(userId);
|
||||
} finally {
|
||||
@ -610,12 +613,11 @@ final class PreferredActivityHelper {
|
||||
mPm.mInjector.getLocalService(NetworkPolicyManagerInternal.class).resetUserState(userId);
|
||||
}
|
||||
|
||||
// TODO: This method should not touch the Computer directly
|
||||
public int getPreferredActivities(List<IntentFilter> outFilters,
|
||||
List<ComponentName> outActivities, String packageName, Computer computer) {
|
||||
public int getPreferredActivities(@NonNull Computer snapshot, List<IntentFilter> outFilters,
|
||||
List<ComponentName> outActivities, String packageName) {
|
||||
List<WatchedIntentFilter> temp =
|
||||
WatchedIntentFilter.toWatchedIntentFilterList(outFilters);
|
||||
int result = getPreferredActivitiesInternal(temp, outActivities, packageName, computer);
|
||||
int result = getPreferredActivitiesInternal(snapshot, temp, outActivities, packageName);
|
||||
outFilters.clear();
|
||||
for (int i = 0; i < temp.size(); i++) {
|
||||
outFilters.add(temp.get(i).getIntentFilter());
|
||||
@ -626,16 +628,17 @@ final class PreferredActivityHelper {
|
||||
/**
|
||||
* Variant that takes a {@link WatchedIntentFilter}
|
||||
*/
|
||||
private int getPreferredActivitiesInternal(List<WatchedIntentFilter> outFilters,
|
||||
List<ComponentName> outActivities, String packageName, Computer computer) {
|
||||
private int getPreferredActivitiesInternal(@NonNull Computer snapshot,
|
||||
List<WatchedIntentFilter> outFilters, List<ComponentName> outActivities,
|
||||
String packageName) {
|
||||
final int callingUid = Binder.getCallingUid();
|
||||
if (mPm.getInstantAppPackageName(callingUid) != null) {
|
||||
if (snapshot.getInstantAppPackageName(callingUid) != null) {
|
||||
return 0;
|
||||
}
|
||||
int num = 0;
|
||||
final int userId = UserHandle.getCallingUserId();
|
||||
|
||||
PreferredIntentResolver pir = computer.getPreferredActivities(userId);
|
||||
PreferredIntentResolver pir = snapshot.getPreferredActivities(userId);
|
||||
if (pir != null) {
|
||||
final Iterator<PreferredActivity> it = pir.filterIterator();
|
||||
while (it.hasNext()) {
|
||||
@ -643,8 +646,9 @@ final class PreferredActivityHelper {
|
||||
final String prefPackageName = pa.mPref.mComponent.getPackageName();
|
||||
if (packageName == null
|
||||
|| (prefPackageName.equals(packageName) && pa.mPref.mAlways)) {
|
||||
if (mPm.shouldFilterApplication(
|
||||
mPm.getPackageStateInternal(prefPackageName), callingUid, userId)) {
|
||||
if (snapshot.shouldFilterApplication(
|
||||
snapshot.getPackageStateInternal(prefPackageName), callingUid,
|
||||
userId)) {
|
||||
continue;
|
||||
}
|
||||
if (outFilters != null) {
|
||||
@ -660,7 +664,8 @@ final class PreferredActivityHelper {
|
||||
return num;
|
||||
}
|
||||
|
||||
public ResolveInfo findPersistentPreferredActivity(Intent intent, int userId) {
|
||||
public ResolveInfo findPersistentPreferredActivity(@NonNull Computer snapshot, Intent intent,
|
||||
int userId) {
|
||||
if (!UserHandle.isSameApp(Binder.getCallingUid(), Process.SYSTEM_UID)) {
|
||||
throw new SecurityException(
|
||||
"findPersistentPreferredActivity can only be run by the system");
|
||||
@ -671,24 +676,23 @@ final class PreferredActivityHelper {
|
||||
final int callingUid = Binder.getCallingUid();
|
||||
intent = PackageManagerServiceUtils.updateIntentForResolve(intent);
|
||||
final String resolvedType = intent.resolveTypeIfNeeded(mPm.mContext.getContentResolver());
|
||||
final long flags = mPm.updateFlagsForResolve(
|
||||
final long flags = snapshot.updateFlagsForResolve(
|
||||
0, userId, callingUid, false /*includeInstantApps*/,
|
||||
mPm.isImplicitImageCaptureIntentAndNotSetByDpcLocked(intent, userId, resolvedType,
|
||||
snapshot.isImplicitImageCaptureIntentAndNotSetByDpc(intent, userId, resolvedType,
|
||||
0));
|
||||
final List<ResolveInfo> query = mPm.snapshotComputer().queryIntentActivitiesInternal(intent,
|
||||
final List<ResolveInfo> query = snapshot.queryIntentActivitiesInternal(intent,
|
||||
resolvedType, flags, userId);
|
||||
synchronized (mPm.mLock) {
|
||||
return mPm.findPersistentPreferredActivityLP(intent, resolvedType, flags, query, false,
|
||||
userId);
|
||||
}
|
||||
return snapshot.findPersistentPreferredActivity(intent, resolvedType, flags, query, false,
|
||||
userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Variant that takes a {@link WatchedIntentFilter}
|
||||
*/
|
||||
public void setLastChosenActivity(Intent intent, String resolvedType, int flags,
|
||||
WatchedIntentFilter filter, int match, ComponentName activity) {
|
||||
if (mPm.getInstantAppPackageName(Binder.getCallingUid()) != null) {
|
||||
public void setLastChosenActivity(@NonNull Computer snapshot, Intent intent,
|
||||
String resolvedType, int flags, WatchedIntentFilter filter, int match,
|
||||
ComponentName activity) {
|
||||
if (snapshot.getInstantAppPackageName(Binder.getCallingUid()) != null) {
|
||||
return;
|
||||
}
|
||||
final int userId = UserHandle.getCallingUserId();
|
||||
@ -702,25 +706,26 @@ final class PreferredActivityHelper {
|
||||
filter.dump(new PrintStreamPrinter(System.out), " ");
|
||||
}
|
||||
intent.setComponent(null);
|
||||
final List<ResolveInfo> query = mPm.snapshotComputer().queryIntentActivitiesInternal(intent,
|
||||
final List<ResolveInfo> query = snapshot.queryIntentActivitiesInternal(intent,
|
||||
resolvedType, flags, userId);
|
||||
// Find any earlier preferred or last chosen entries and nuke them
|
||||
findPreferredActivityNotLocked(
|
||||
intent, resolvedType, flags, query, false, true, false, userId);
|
||||
findPreferredActivityNotLocked(snapshot, intent, resolvedType, flags, query, false, true,
|
||||
false, userId);
|
||||
// Add the new activity as the last chosen for this filter
|
||||
addPreferredActivity(filter, match, null, activity, false, userId,
|
||||
addPreferredActivity(snapshot, filter, match, null, activity, false, userId,
|
||||
"Setting last chosen", false);
|
||||
}
|
||||
|
||||
public ResolveInfo getLastChosenActivity(Intent intent, String resolvedType, int flags) {
|
||||
if (mPm.getInstantAppPackageName(Binder.getCallingUid()) != null) {
|
||||
public ResolveInfo getLastChosenActivity(@NonNull Computer snapshot, Intent intent,
|
||||
String resolvedType, int flags) {
|
||||
if (snapshot.getInstantAppPackageName(Binder.getCallingUid()) != null) {
|
||||
return null;
|
||||
}
|
||||
final int userId = UserHandle.getCallingUserId();
|
||||
if (DEBUG_PREFERRED) Log.v(TAG, "Querying last chosen activity for " + intent);
|
||||
final List<ResolveInfo> query = mPm.snapshotComputer().queryIntentActivitiesInternal(intent,
|
||||
final List<ResolveInfo> query = snapshot.queryIntentActivitiesInternal(intent,
|
||||
resolvedType, flags, userId);
|
||||
return findPreferredActivityNotLocked(
|
||||
intent, resolvedType, flags, query, false, false, false, userId);
|
||||
return findPreferredActivityNotLocked(snapshot, intent, resolvedType, flags, query, false,
|
||||
false, false, userId);
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,6 @@ public class PreferredComponent {
|
||||
private String mParseError;
|
||||
|
||||
private final Callbacks mCallbacks;
|
||||
private final String mSetupWizardPackageName;
|
||||
|
||||
public interface Callbacks {
|
||||
public boolean onReadTag(String tagName, TypedXmlPullParser parser)
|
||||
@ -72,7 +71,6 @@ public class PreferredComponent {
|
||||
mAlways = always;
|
||||
mShortComponent = component.flattenToShortString();
|
||||
mParseError = null;
|
||||
mSetupWizardPackageName = null;
|
||||
if (set != null) {
|
||||
final int N = set.length;
|
||||
String[] myPackages = new String[N];
|
||||
@ -174,8 +172,6 @@ public class PreferredComponent {
|
||||
mSetPackages = myPackages;
|
||||
mSetClasses = myClasses;
|
||||
mSetComponents = myComponents;
|
||||
final PackageManagerInternal packageManagerInternal = LocalServices.getService(PackageManagerInternal.class);
|
||||
mSetupWizardPackageName = packageManagerInternal.getSetupWizardPackageName();
|
||||
}
|
||||
|
||||
public String getParseError() {
|
||||
@ -209,6 +205,7 @@ public class PreferredComponent {
|
||||
final int NQ = query.size();
|
||||
final int NS = mSetPackages.length;
|
||||
final PackageManagerInternal pmi = LocalServices.getService(PackageManagerInternal.class);
|
||||
String setupWizardPackageName = pmi.getSetupWizardPackageName();
|
||||
int numMatch = 0;
|
||||
for (int i=0; i<NQ; i++) {
|
||||
ResolveInfo ri = query.get(i);
|
||||
@ -217,7 +214,7 @@ public class PreferredComponent {
|
||||
|
||||
// ignore SetupWizard package's launcher capability because it is only existed
|
||||
// during SetupWizard is running
|
||||
if (excludeSetupWizardPackage && ai.packageName.equals(mSetupWizardPackageName)) {
|
||||
if (excludeSetupWizardPackage && ai.packageName.equals(setupWizardPackageName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -307,6 +304,8 @@ public class PreferredComponent {
|
||||
if (!excludeSetupWizardPackage && NS < NQ) {
|
||||
return false;
|
||||
}
|
||||
final PackageManagerInternal pmi = LocalServices.getService(PackageManagerInternal.class);
|
||||
String setupWizardPackageName = pmi.getSetupWizardPackageName();
|
||||
for (int i=0; i<NQ; i++) {
|
||||
ResolveInfo ri = query.get(i);
|
||||
ActivityInfo ai = ri.activityInfo;
|
||||
@ -314,7 +313,7 @@ public class PreferredComponent {
|
||||
|
||||
// ignore SetupWizard package's launcher capability because it is only existed
|
||||
// during SetupWizard is running
|
||||
if (excludeSetupWizardPackage && ai.packageName.equals(mSetupWizardPackageName)) {
|
||||
if (excludeSetupWizardPackage && ai.packageName.equals(setupWizardPackageName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,8 @@ final class RemovePackageHelper {
|
||||
|
||||
public void removePackageLI(AndroidPackage pkg, boolean chatty) {
|
||||
// Remove the parent package setting
|
||||
PackageStateInternal ps = mPm.getPackageStateInternal(pkg.getPackageName());
|
||||
PackageStateInternal ps = mPm.snapshotComputer()
|
||||
.getPackageStateInternal(pkg.getPackageName());
|
||||
if (ps != null) {
|
||||
removePackageLI(ps.getPackageName(), chatty);
|
||||
} else if (DEBUG_REMOVE && chatty) {
|
||||
@ -271,8 +272,8 @@ final class RemovePackageHelper {
|
||||
synchronized (mPm.mLock) {
|
||||
mPm.mDomainVerificationManager.clearPackage(deletedPs.getPackageName());
|
||||
mPm.mSettings.getKeySetManagerService().removeAppKeySetDataLPw(packageName);
|
||||
mPm.mAppsFilter.removePackage(mPm.getPackageStateInternal(packageName),
|
||||
false /* isReplace */);
|
||||
mPm.mAppsFilter.removePackage(mPm.snapshotComputer()
|
||||
.getPackageStateInternal(packageName), false /* isReplace */);
|
||||
removedAppId = mPm.mSettings.removePackageLPw(packageName);
|
||||
if (outInfo != null) {
|
||||
outInfo.mRemovedAppId = removedAppId;
|
||||
@ -298,7 +299,8 @@ final class RemovePackageHelper {
|
||||
if (changedUsers.size() > 0) {
|
||||
final PreferredActivityHelper preferredActivityHelper =
|
||||
new PreferredActivityHelper(mPm);
|
||||
preferredActivityHelper.updateDefaultHomeNotLocked(changedUsers);
|
||||
preferredActivityHelper.updateDefaultHomeNotLocked(mPm.snapshotComputer(),
|
||||
changedUsers);
|
||||
mPm.postPreferredActivityChangedBroadcast(UserHandle.USER_ALL);
|
||||
}
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ final class ResolveIntentHelper {
|
||||
if (!mUserManager.exists(userId)) return null;
|
||||
final int callingUid = Binder.getCallingUid();
|
||||
flags = computer.updateFlagsForResolve(flags, userId, filterCallingUid, resolveForStart,
|
||||
computer.isImplicitImageCaptureIntentAndNotSetByDpcLocked(intent, userId,
|
||||
computer.isImplicitImageCaptureIntentAndNotSetByDpc(intent, userId,
|
||||
resolvedType, flags));
|
||||
computer.enforceCrossUserPermission(callingUid, userId, false /*requireFullPermission*/,
|
||||
false /*checkShell*/, "resolve intent");
|
||||
@ -170,9 +170,9 @@ final class ResolveIntentHelper {
|
||||
}
|
||||
// If we have saved a preference for a preferred activity for
|
||||
// this Intent, use that.
|
||||
ResolveInfo ri = mPreferredActivityHelper.findPreferredActivityNotLocked(intent,
|
||||
resolvedType, flags, query, true, false, debug, userId,
|
||||
queryMayBeFiltered);
|
||||
ResolveInfo ri = mPreferredActivityHelper.findPreferredActivityNotLocked(computer,
|
||||
intent, resolvedType, flags, query, true, false, debug,
|
||||
userId, queryMayBeFiltered);
|
||||
if (ri != null) {
|
||||
return ri;
|
||||
}
|
||||
@ -317,7 +317,7 @@ final class ResolveIntentHelper {
|
||||
final String instantAppPkgName = computer.getInstantAppPackageName(filterCallingUid);
|
||||
flags = computer.updateFlagsForResolve(flags, userId, filterCallingUid,
|
||||
false /*includeInstantApps*/,
|
||||
computer.isImplicitImageCaptureIntentAndNotSetByDpcLocked(intent, userId,
|
||||
computer.isImplicitImageCaptureIntentAndNotSetByDpc(intent, userId,
|
||||
resolvedType, flags));
|
||||
Intent originalIntent = null;
|
||||
ComponentName comp = intent.getComponent();
|
||||
@ -562,7 +562,7 @@ final class ResolveIntentHelper {
|
||||
final int callingUid = Binder.getCallingUid();
|
||||
flags = computer.updateFlagsForResolve(flags, userId, callingUid,
|
||||
false /*includeInstantApps*/,
|
||||
computer.isImplicitImageCaptureIntentAndNotSetByDpcLocked(intent, userId,
|
||||
computer.isImplicitImageCaptureIntentAndNotSetByDpc(intent, userId,
|
||||
resolvedType, flags));
|
||||
computer.enforceCrossUserPermission(callingUid, userId, false /*requireFullPermission*/,
|
||||
false /*checkShell*/, "query intent activity options");
|
||||
|
@ -741,9 +741,11 @@ public final class SharedLibrariesImpl implements SharedLibrariesRead, Watchable
|
||||
}
|
||||
SharedLibraryInfo libraryInfo = versionedLib.valueAt(libIdx);
|
||||
|
||||
final Computer snapshot = mPm.snapshotComputer();
|
||||
|
||||
// Remove the shared library overlays from its dependent packages.
|
||||
for (int currentUserId : mPm.mUserManager.getUserIds()) {
|
||||
final List<VersionedPackage> dependents = mPm.getPackagesUsingSharedLibrary(
|
||||
final List<VersionedPackage> dependents = snapshot.getPackagesUsingSharedLibrary(
|
||||
libraryInfo, 0, Process.SYSTEM_UID, currentUserId);
|
||||
if (dependents == null) {
|
||||
continue;
|
||||
|
@ -26,13 +26,13 @@ import static com.android.server.pm.PackageManagerService.SCAN_INITIAL;
|
||||
import static com.android.server.pm.PackageManagerService.TAG;
|
||||
import static com.android.server.pm.PackageManagerServiceUtils.logCriticalInfo;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.app.ResourcesManager;
|
||||
import android.content.IIntentReceiver;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackagePartitions;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.content.pm.VersionedPackage;
|
||||
import com.android.server.pm.pkg.parsing.ParsingPackageUtils;
|
||||
import android.os.Environment;
|
||||
import android.os.FileUtils;
|
||||
import android.os.UserHandle;
|
||||
@ -48,6 +48,7 @@ import android.util.Slog;
|
||||
import com.android.internal.policy.AttributeCache;
|
||||
import com.android.server.pm.parsing.pkg.AndroidPackage;
|
||||
import com.android.server.pm.pkg.PackageStateInternal;
|
||||
import com.android.server.pm.pkg.parsing.ParsingPackageUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@ -78,7 +79,7 @@ public final class StorageEventHelper extends StorageEventListener {
|
||||
// Clean up any users or apps that were removed or recreated
|
||||
// while this volume was missing
|
||||
mPm.mUserManager.reconcileUsers(volumeUuid);
|
||||
reconcileApps(volumeUuid);
|
||||
reconcileApps(mPm.snapshotComputer(), volumeUuid);
|
||||
|
||||
// Clean up any install sessions that expired or were
|
||||
// cancelled while this volume was missing
|
||||
@ -299,8 +300,8 @@ public final class StorageEventHelper extends StorageEventListener {
|
||||
* aren't expected, either due to uninstallation or reinstallation on
|
||||
* another volume.
|
||||
*/
|
||||
public void reconcileApps(String volumeUuid) {
|
||||
List<String> absoluteCodePaths = collectAbsoluteCodePaths();
|
||||
public void reconcileApps(@NonNull Computer snapshot, String volumeUuid) {
|
||||
List<String> absoluteCodePaths = collectAbsoluteCodePaths(snapshot);
|
||||
List<File> filesToDelete = null;
|
||||
|
||||
final File[] files = FileUtils.listFilesOrEmpty(
|
||||
@ -345,10 +346,10 @@ public final class StorageEventHelper extends StorageEventListener {
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> collectAbsoluteCodePaths() {
|
||||
private List<String> collectAbsoluteCodePaths(@NonNull Computer snapshot) {
|
||||
List<String> codePaths = new ArrayList<>();
|
||||
final ArrayMap<String, ? extends PackageStateInternal> packageStates =
|
||||
mPm.getPackageStates();
|
||||
snapshot.getPackageStates();
|
||||
final int packageCount = packageStates.size();
|
||||
for (int i = 0; i < packageCount; i++) {
|
||||
final PackageStateInternal ps = packageStates.valueAt(i);
|
||||
|
@ -100,14 +100,14 @@ public final class SuspendPackageHelper {
|
||||
* @return The names of failed packages.
|
||||
*/
|
||||
@Nullable
|
||||
String[] setPackagesSuspended(@NonNull Computer computer, @Nullable String[] packageNames,
|
||||
String[] setPackagesSuspended(@NonNull Computer snapshot, @Nullable String[] packageNames,
|
||||
boolean suspended, @Nullable PersistableBundle appExtras,
|
||||
@Nullable PersistableBundle launcherExtras, @Nullable SuspendDialogInfo dialogInfo,
|
||||
@NonNull String callingPackage, @UserIdInt int userId, int callingUid) {
|
||||
if (ArrayUtils.isEmpty(packageNames)) {
|
||||
return packageNames;
|
||||
}
|
||||
if (suspended && !isSuspendAllowedForUser(userId, callingUid)) {
|
||||
if (suspended && !isSuspendAllowedForUser(snapshot, userId, callingUid)) {
|
||||
Slog.w(TAG, "Cannot suspend due to restrictions on user " + userId);
|
||||
return packageNames;
|
||||
}
|
||||
@ -123,7 +123,7 @@ public final class SuspendPackageHelper {
|
||||
ArraySet<String> modifiedPackages = new ArraySet<>();
|
||||
|
||||
final boolean[] canSuspend = suspended
|
||||
? canSuspendPackageForUser(computer, packageNames, userId, callingUid) : null;
|
||||
? canSuspendPackageForUser(snapshot, packageNames, userId, callingUid) : null;
|
||||
for (int i = 0; i < packageNames.length; i++) {
|
||||
final String packageName = packageNames[i];
|
||||
if (callingPackage.equals(packageName)) {
|
||||
@ -133,9 +133,9 @@ public final class SuspendPackageHelper {
|
||||
continue;
|
||||
}
|
||||
final PackageStateInternal packageState =
|
||||
computer.getPackageStateInternal(packageName);
|
||||
snapshot.getPackageStateInternal(packageName);
|
||||
if (packageState == null
|
||||
|| computer.shouldFilterApplication(packageState, callingUid, userId)) {
|
||||
|| snapshot.shouldFilterApplication(packageState, callingUid, userId)) {
|
||||
Slog.w(TAG, "Could not find package setting for package: " + packageName
|
||||
+ ". Skipping suspending/un-suspending.");
|
||||
unmodifiablePackages.add(packageName);
|
||||
@ -191,9 +191,11 @@ public final class SuspendPackageHelper {
|
||||
}
|
||||
});
|
||||
|
||||
final Computer newSnapshot = mPm.snapshotComputer();
|
||||
|
||||
if (!changedPackagesList.isEmpty()) {
|
||||
final String[] changedPackages = changedPackagesList.toArray(new String[0]);
|
||||
sendPackagesSuspendedForUser(
|
||||
sendPackagesSuspendedForUser(newSnapshot,
|
||||
suspended ? Intent.ACTION_PACKAGES_SUSPENDED
|
||||
: Intent.ACTION_PACKAGES_UNSUSPENDED,
|
||||
changedPackages, changedUids.toArray(), userId);
|
||||
@ -202,7 +204,7 @@ public final class SuspendPackageHelper {
|
||||
}
|
||||
// Send the suspension changed broadcast to ensure suspension state is not stale.
|
||||
if (!modifiedPackages.isEmpty()) {
|
||||
sendPackagesSuspendedForUser(Intent.ACTION_PACKAGES_SUSPENSION_CHANGED,
|
||||
sendPackagesSuspendedForUser(newSnapshot, Intent.ACTION_PACKAGES_SUSPENSION_CHANGED,
|
||||
modifiedPackages.toArray(new String[0]), modifiedUids.toArray(), userId);
|
||||
}
|
||||
return unmodifiablePackages.toArray(new String[0]);
|
||||
@ -217,14 +219,14 @@ public final class SuspendPackageHelper {
|
||||
* @return The names of packages which are Unsuspendable.
|
||||
*/
|
||||
@NonNull
|
||||
String[] getUnsuspendablePackagesForUser(@NonNull Computer computer,
|
||||
String[] getUnsuspendablePackagesForUser(@NonNull Computer snapshot,
|
||||
@NonNull String[] packageNames, @UserIdInt int userId, int callingUid) {
|
||||
if (!isSuspendAllowedForUser(userId, callingUid)) {
|
||||
if (!isSuspendAllowedForUser(snapshot, userId, callingUid)) {
|
||||
Slog.w(TAG, "Cannot suspend due to restrictions on user " + userId);
|
||||
return packageNames;
|
||||
}
|
||||
final ArraySet<String> unactionablePackages = new ArraySet<>();
|
||||
final boolean[] canSuspend = canSuspendPackageForUser(computer, packageNames, userId,
|
||||
final boolean[] canSuspend = canSuspendPackageForUser(snapshot, packageNames, userId,
|
||||
callingUid);
|
||||
for (int i = 0; i < packageNames.length; i++) {
|
||||
if (!canSuspend[i]) {
|
||||
@ -232,7 +234,7 @@ public final class SuspendPackageHelper {
|
||||
continue;
|
||||
}
|
||||
final PackageStateInternal packageState =
|
||||
computer.getPackageStateFiltered(packageNames[i], callingUid, userId);
|
||||
snapshot.getPackageStateFiltered(packageNames[i], callingUid, userId);
|
||||
if (packageState == null) {
|
||||
Slog.w(TAG, "Could not find package setting for package: " + packageNames[i]);
|
||||
unactionablePackages.add(packageNames[i]);
|
||||
@ -250,8 +252,9 @@ public final class SuspendPackageHelper {
|
||||
* @return The app extras of the suspended package.
|
||||
*/
|
||||
@Nullable
|
||||
Bundle getSuspendedPackageAppExtras(@NonNull String packageName, int userId, int callingUid) {
|
||||
final PackageStateInternal ps = mPm.getPackageStateInternal(packageName, callingUid);
|
||||
Bundle getSuspendedPackageAppExtras(@NonNull Computer snapshot, @NonNull String packageName,
|
||||
int userId, int callingUid) {
|
||||
final PackageStateInternal ps = snapshot.getPackageStateInternal(packageName, callingUid);
|
||||
if (ps == null) {
|
||||
return null;
|
||||
}
|
||||
@ -329,12 +332,14 @@ public final class SuspendPackageHelper {
|
||||
}
|
||||
});
|
||||
|
||||
final Computer newSnapshot = mPm.snapshotComputer();
|
||||
|
||||
mPm.scheduleWritePackageRestrictions(userId);
|
||||
if (!unsuspendedPackages.isEmpty()) {
|
||||
final String[] packageArray = unsuspendedPackages.toArray(
|
||||
new String[unsuspendedPackages.size()]);
|
||||
sendMyPackageSuspendedOrUnsuspended(packageArray, false, userId);
|
||||
sendPackagesSuspendedForUser(Intent.ACTION_PACKAGES_UNSUSPENDED,
|
||||
sendPackagesSuspendedForUser(newSnapshot, Intent.ACTION_PACKAGES_UNSUSPENDED,
|
||||
packageArray, unsuspendedUids.toArray(), userId);
|
||||
}
|
||||
}
|
||||
@ -348,10 +353,10 @@ public final class SuspendPackageHelper {
|
||||
* @return The launcher extras.
|
||||
*/
|
||||
@Nullable
|
||||
Bundle getSuspendedPackageLauncherExtras(@NonNull String packageName, int userId,
|
||||
int callingUid) {
|
||||
final PackageStateInternal packageState = mPm.getPackageStateInternal(
|
||||
packageName, callingUid);
|
||||
Bundle getSuspendedPackageLauncherExtras(@NonNull Computer snapshot,
|
||||
@NonNull String packageName, int userId, int callingUid) {
|
||||
final PackageStateInternal packageState =
|
||||
snapshot.getPackageStateInternal(packageName, callingUid);
|
||||
if (packageState == null) {
|
||||
return null;
|
||||
}
|
||||
@ -376,9 +381,10 @@ public final class SuspendPackageHelper {
|
||||
* @param callingUid The caller's uid.
|
||||
* @return {@code true}, if the given package is suspended.
|
||||
*/
|
||||
boolean isPackageSuspended(@NonNull String packageName, int userId, int callingUid) {
|
||||
final PackageStateInternal packageState = mPm.getPackageStateInternal(
|
||||
packageName, callingUid);
|
||||
boolean isPackageSuspended(@NonNull Computer snapshot, @NonNull String packageName, int userId,
|
||||
int callingUid) {
|
||||
final PackageStateInternal packageState =
|
||||
snapshot.getPackageStateInternal(packageName, callingUid);
|
||||
return packageState != null && packageState.getUserStateOrDefault(userId)
|
||||
.isSuspended();
|
||||
}
|
||||
@ -392,8 +398,9 @@ public final class SuspendPackageHelper {
|
||||
* @return The name of suspending package.
|
||||
*/
|
||||
@Nullable
|
||||
String getSuspendingPackage(@NonNull String suspendedPackage, int userId, int callingUid) {
|
||||
final PackageStateInternal packageState = mPm.getPackageStateInternal(
|
||||
String getSuspendingPackage(@NonNull Computer snapshot, @NonNull String suspendedPackage,
|
||||
int userId, int callingUid) {
|
||||
final PackageStateInternal packageState = snapshot.getPackageStateInternal(
|
||||
suspendedPackage, callingUid);
|
||||
if (packageState == null) {
|
||||
return null;
|
||||
@ -424,9 +431,10 @@ public final class SuspendPackageHelper {
|
||||
* @return The dialog info.
|
||||
*/
|
||||
@Nullable
|
||||
SuspendDialogInfo getSuspendedDialogInfo(@NonNull String suspendedPackage,
|
||||
@NonNull String suspendingPackage, int userId, int callingUid) {
|
||||
final PackageStateInternal packageState = mPm.getPackageStateInternal(
|
||||
SuspendDialogInfo getSuspendedDialogInfo(@NonNull Computer snapshot,
|
||||
@NonNull String suspendedPackage, @NonNull String suspendingPackage, int userId,
|
||||
int callingUid) {
|
||||
final PackageStateInternal packageState = snapshot.getPackageStateInternal(
|
||||
suspendedPackage, callingUid);
|
||||
if (packageState == null) {
|
||||
return null;
|
||||
@ -454,9 +462,9 @@ public final class SuspendPackageHelper {
|
||||
* @param callingUid The caller's uid.
|
||||
* @return {@code true} if the user is allowed to suspend packages by the caller.
|
||||
*/
|
||||
boolean isSuspendAllowedForUser(int userId, int callingUid) {
|
||||
boolean isSuspendAllowedForUser(@NonNull Computer snapshot, int userId, int callingUid) {
|
||||
final UserManagerService userManager = mInjector.getUserManagerService();
|
||||
return isCallerDeviceOrProfileOwner(userId, callingUid)
|
||||
return isCallerDeviceOrProfileOwner(snapshot, userId, callingUid)
|
||||
|| (!userManager.hasUserRestriction(UserManager.DISALLOW_APPS_CONTROL, userId)
|
||||
&& !userManager.hasUserRestriction(UserManager.DISALLOW_UNINSTALL_APPS, userId));
|
||||
}
|
||||
@ -471,21 +479,23 @@ public final class SuspendPackageHelper {
|
||||
* @return An array containing results of the checks
|
||||
*/
|
||||
@NonNull
|
||||
boolean[] canSuspendPackageForUser(@NonNull Computer computer, @NonNull String[] packageNames,
|
||||
boolean[] canSuspendPackageForUser(@NonNull Computer snapshot, @NonNull String[] packageNames,
|
||||
int userId, int callingUid) {
|
||||
final boolean[] canSuspend = new boolean[packageNames.length];
|
||||
final boolean isCallerOwner = isCallerDeviceOrProfileOwner(userId, callingUid);
|
||||
final boolean isCallerOwner = isCallerDeviceOrProfileOwner(snapshot, userId, callingUid);
|
||||
final long token = Binder.clearCallingIdentity();
|
||||
try {
|
||||
final DefaultAppProvider defaultAppProvider = mInjector.getDefaultAppProvider();
|
||||
final String activeLauncherPackageName = defaultAppProvider.getDefaultHome(userId);
|
||||
final String dialerPackageName = defaultAppProvider.getDefaultDialer(userId);
|
||||
final String requiredInstallerPackage = getKnownPackageName(PACKAGE_INSTALLER, userId);
|
||||
final String requiredInstallerPackage =
|
||||
getKnownPackageName(snapshot, PACKAGE_INSTALLER, userId);
|
||||
final String requiredUninstallerPackage =
|
||||
getKnownPackageName(PACKAGE_UNINSTALLER, userId);
|
||||
final String requiredVerifierPackage = getKnownPackageName(PACKAGE_VERIFIER, userId);
|
||||
getKnownPackageName(snapshot, PACKAGE_UNINSTALLER, userId);
|
||||
final String requiredVerifierPackage =
|
||||
getKnownPackageName(snapshot, PACKAGE_VERIFIER, userId);
|
||||
final String requiredPermissionControllerPackage =
|
||||
getKnownPackageName(PACKAGE_PERMISSION_CONTROLLER, userId);
|
||||
getKnownPackageName(snapshot, PACKAGE_PERMISSION_CONTROLLER, userId);
|
||||
for (int i = 0; i < packageNames.length; i++) {
|
||||
canSuspend[i] = false;
|
||||
final String packageName = packageNames[i];
|
||||
@ -530,7 +540,7 @@ public final class SuspendPackageHelper {
|
||||
+ "\": protected package");
|
||||
continue;
|
||||
}
|
||||
if (!isCallerOwner && computer.getBlockUninstall(userId, packageName)) {
|
||||
if (!isCallerOwner && snapshot.getBlockUninstall(userId, packageName)) {
|
||||
Slog.w(TAG, "Cannot suspend package \"" + packageName
|
||||
+ "\": blocked by admin");
|
||||
continue;
|
||||
@ -539,7 +549,7 @@ public final class SuspendPackageHelper {
|
||||
// Cannot suspend static shared libs as they are considered
|
||||
// a part of the using app (emulating static linking). Also
|
||||
// static libs are installed always on internal storage.
|
||||
PackageStateInternal packageState = computer.getPackageStateInternal(packageName);
|
||||
PackageStateInternal packageState = snapshot.getPackageStateInternal(packageName);
|
||||
AndroidPackage pkg = packageState == null ? null : packageState.getPkg();
|
||||
if (pkg != null) {
|
||||
// Cannot suspend SDK libs as they are controlled by SDK manager.
|
||||
@ -580,8 +590,8 @@ public final class SuspendPackageHelper {
|
||||
* @param userId The user where packages reside.
|
||||
*/
|
||||
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
|
||||
void sendPackagesSuspendedForUser(@NonNull String intent, @NonNull String[] pkgList,
|
||||
@NonNull int[] uidList, int userId) {
|
||||
void sendPackagesSuspendedForUser(@NonNull Computer snapshot, @NonNull String intent,
|
||||
@NonNull String[] pkgList, @NonNull int[] uidList, int userId) {
|
||||
final List<List<String>> pkgsToSend = new ArrayList(pkgList.length);
|
||||
final List<IntArray> uidsToSend = new ArrayList(pkgList.length);
|
||||
final List<SparseArray<int[]>> allowListsToSend = new ArrayList(pkgList.length);
|
||||
@ -592,8 +602,8 @@ public final class SuspendPackageHelper {
|
||||
final String pkgName = pkgList[i];
|
||||
final int uid = uidList[i];
|
||||
SparseArray<int[]> allowList = mInjector.getAppsFilter().getVisibilityAllowList(
|
||||
mPm.getPackageStateInternal(pkgName, SYSTEM_UID),
|
||||
userIds, mPm.getPackageStates());
|
||||
snapshot.getPackageStateInternal(pkgName, SYSTEM_UID),
|
||||
userIds, snapshot.getPackageStates());
|
||||
if (allowList == null) {
|
||||
allowList = new SparseArray<>(0);
|
||||
}
|
||||
@ -628,19 +638,22 @@ public final class SuspendPackageHelper {
|
||||
}
|
||||
}
|
||||
|
||||
private String getKnownPackageName(@KnownPackage int knownPackage, int userId) {
|
||||
final String[] knownPackages = mPm.getKnownPackageNamesInternal(knownPackage, userId);
|
||||
private String getKnownPackageName(@NonNull Computer snapshot, @KnownPackage int knownPackage,
|
||||
int userId) {
|
||||
final String[] knownPackages =
|
||||
mPm.getKnownPackageNamesInternal(snapshot, knownPackage, userId);
|
||||
return knownPackages.length > 0 ? knownPackages[0] : null;
|
||||
}
|
||||
|
||||
private boolean isCallerDeviceOrProfileOwner(int userId, int callingUid) {
|
||||
private boolean isCallerDeviceOrProfileOwner(@NonNull Computer snapshot, int userId,
|
||||
int callingUid) {
|
||||
if (callingUid == SYSTEM_UID) {
|
||||
return true;
|
||||
}
|
||||
final String ownerPackage = mProtectedPackages.getDeviceOwnerOrProfileOwnerPackage(userId);
|
||||
if (ownerPackage != null) {
|
||||
return callingUid == mPm.getPackageUidInternal(
|
||||
ownerPackage, 0, userId, callingUid);
|
||||
return callingUid == snapshot.getPackageUidInternal(ownerPackage, 0, userId,
|
||||
callingUid);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -659,9 +672,10 @@ public final class SuspendPackageHelper {
|
||||
return;
|
||||
}
|
||||
final int[] targetUserIds = new int[] {userId};
|
||||
final Computer snapshot = mPm.snapshotComputer();
|
||||
for (String packageName : affectedPackages) {
|
||||
final Bundle appExtras = suspended
|
||||
? getSuspendedPackageAppExtras(packageName, userId, SYSTEM_UID)
|
||||
? getSuspendedPackageAppExtras(snapshot, packageName, userId, SYSTEM_UID)
|
||||
: null;
|
||||
final Bundle intentExtras;
|
||||
if (appExtras != null) {
|
||||
|
@ -4148,11 +4148,11 @@ public class UserManagerService extends IUserManager.Stub {
|
||||
continue;
|
||||
}
|
||||
if (filter.direction == DefaultCrossProfileIntentFilter.Direction.TO_PARENT) {
|
||||
mPm.addCrossProfileIntentFilter(
|
||||
mPm.addCrossProfileIntentFilter(mPm.snapshotComputer(),
|
||||
filter.filter, mContext.getOpPackageName(), profileUserId, parentUserId,
|
||||
filter.flags);
|
||||
} else {
|
||||
mPm.addCrossProfileIntentFilter(
|
||||
mPm.addCrossProfileIntentFilter(mPm.snapshotComputer(),
|
||||
filter.filter, mContext.getOpPackageName(), parentUserId, profileUserId,
|
||||
filter.flags);
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ public class WatchedIntentFilter
|
||||
}
|
||||
|
||||
// Convert an {@link IntentFilter} to a {@link WatchedIntentFilter}
|
||||
protected WatchedIntentFilter(IntentFilter f) {
|
||||
public WatchedIntentFilter(IntentFilter f) {
|
||||
mFilter = new IntentFilter(f);
|
||||
}
|
||||
|
||||
|
@ -31,13 +31,13 @@ import android.content.pm.dex.ArtManagerInternal;
|
||||
import android.content.pm.dex.DexMetadataHelper;
|
||||
import android.content.pm.dex.ISnapshotRuntimeProfileCallback;
|
||||
import android.content.pm.dex.PackageOptimizationInfo;
|
||||
import com.android.server.pm.pkg.parsing.PackageInfoWithoutStateUtils;
|
||||
import android.os.Binder;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.Process;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.SystemProperties;
|
||||
import android.os.UserHandle;
|
||||
import android.system.Os;
|
||||
@ -55,6 +55,7 @@ import com.android.server.pm.Installer;
|
||||
import com.android.server.pm.Installer.InstallerException;
|
||||
import com.android.server.pm.PackageManagerServiceCompilerMapping;
|
||||
import com.android.server.pm.parsing.pkg.AndroidPackage;
|
||||
import com.android.server.pm.pkg.parsing.PackageInfoWithoutStateUtils;
|
||||
|
||||
import dalvik.system.DexFile;
|
||||
import dalvik.system.VMRuntime;
|
||||
@ -92,7 +93,7 @@ public class ArtManagerService extends android.content.pm.dex.IArtManager.Stub {
|
||||
private static final String BOOT_IMAGE_PROFILE_NAME = "android.prof";
|
||||
|
||||
private final Context mContext;
|
||||
private final IPackageManager mPackageManager;
|
||||
private IPackageManager mPackageManager;
|
||||
private final Object mInstallLock;
|
||||
@GuardedBy("mInstallLock")
|
||||
private final Installer mInstaller;
|
||||
@ -103,10 +104,9 @@ public class ArtManagerService extends android.content.pm.dex.IArtManager.Stub {
|
||||
verifyTronLoggingConstants();
|
||||
}
|
||||
|
||||
public ArtManagerService(Context context, IPackageManager pm, Installer installer,
|
||||
public ArtManagerService(Context context, Installer installer,
|
||||
Object installLock) {
|
||||
mContext = context;
|
||||
mPackageManager = pm;
|
||||
mInstaller = installer;
|
||||
mInstallLock = installLock;
|
||||
mHandler = new Handler(BackgroundThread.getHandler().getLooper());
|
||||
@ -114,6 +114,15 @@ public class ArtManagerService extends android.content.pm.dex.IArtManager.Stub {
|
||||
LocalServices.addService(ArtManagerInternal.class, new ArtManagerInternalImpl());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private IPackageManager getPackageManager() {
|
||||
if (mPackageManager == null) {
|
||||
mPackageManager = IPackageManager.Stub.asInterface(
|
||||
ServiceManager.getService("package"));
|
||||
}
|
||||
return mPackageManager;
|
||||
}
|
||||
|
||||
private boolean checkAndroidPermissions(int callingUid, String callingPackage) {
|
||||
// Callers always need this permission
|
||||
mContext.enforceCallingOrSelfPermission(
|
||||
@ -157,7 +166,7 @@ public class ArtManagerService extends android.content.pm.dex.IArtManager.Stub {
|
||||
}
|
||||
PackageInfo info = null;
|
||||
try {
|
||||
info = mPackageManager.getPackageInfo(packageName, /*flags*/ 0, /*userId*/ 0);
|
||||
info = getPackageManager().getPackageInfo(packageName, /*flags*/ 0, /*userId*/ 0);
|
||||
} catch (RemoteException ignored) {
|
||||
// Should not happen.
|
||||
}
|
||||
@ -221,7 +230,7 @@ public class ArtManagerService extends android.content.pm.dex.IArtManager.Stub {
|
||||
|
||||
// TODO(calin): consider adding an API to PMS which can retrieve the
|
||||
// PackageParser.Package.
|
||||
info = mPackageManager.getPackageInfo(packageName, /*flags*/ 0, /*userId*/ 0);
|
||||
info = getPackageManager().getPackageInfo(packageName, /*flags*/ 0, /*userId*/ 0);
|
||||
} catch (RemoteException ignored) {
|
||||
// Should not happen.
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ import static com.android.server.pm.dex.PackageDexUsage.PackageUseInfo;
|
||||
|
||||
import static java.util.function.Function.identity;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.IPackageManager;
|
||||
@ -33,6 +35,7 @@ import android.os.BatteryManager;
|
||||
import android.os.FileUtils;
|
||||
import android.os.PowerManager;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.SystemProperties;
|
||||
import android.os.UserHandle;
|
||||
import android.os.storage.StorageManager;
|
||||
@ -109,7 +112,7 @@ public class DexManager {
|
||||
// record class loaders or ISAs.)
|
||||
private final DynamicCodeLogger mDynamicCodeLogger;
|
||||
|
||||
private final IPackageManager mPackageManager;
|
||||
private IPackageManager mPackageManager;
|
||||
private final PackageDexOptimizer mPackageDexOptimizer;
|
||||
private final Object mInstallLock;
|
||||
@GuardedBy("mInstallLock")
|
||||
@ -128,16 +131,22 @@ public class DexManager {
|
||||
private static int DEX_SEARCH_FOUND_SPLIT = 2; // dex file is a split apk
|
||||
private static int DEX_SEARCH_FOUND_SECONDARY = 3; // dex file is a secondary dex
|
||||
|
||||
public DexManager(Context context, IPackageManager pms, PackageDexOptimizer pdo,
|
||||
Installer installer, Object installLock) {
|
||||
public DexManager(Context context, PackageDexOptimizer pdo, Installer installer,
|
||||
Object installLock) {
|
||||
this(context, pdo, installer, installLock, null);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public DexManager(Context context, PackageDexOptimizer pdo, Installer installer,
|
||||
Object installLock, @Nullable IPackageManager packageManager) {
|
||||
mContext = context;
|
||||
mPackageCodeLocationsCache = new HashMap<>();
|
||||
mPackageDexUsage = new PackageDexUsage();
|
||||
mPackageManager = pms;
|
||||
mPackageDexOptimizer = pdo;
|
||||
mInstaller = installer;
|
||||
mInstallLock = installLock;
|
||||
mDynamicCodeLogger = new DynamicCodeLogger(pms, installer);
|
||||
mDynamicCodeLogger = new DynamicCodeLogger(installer);
|
||||
mPackageManager = packageManager;
|
||||
|
||||
// This is currently checked to handle tests that pass in a null context.
|
||||
// TODO(b/174783329): Modify the tests to pass in a mocked Context, PowerManager,
|
||||
@ -157,6 +166,15 @@ public class DexManager {
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private IPackageManager getPackageManager() {
|
||||
if (mPackageManager == null) {
|
||||
mPackageManager = IPackageManager.Stub.asInterface(
|
||||
ServiceManager.getService("package"));
|
||||
}
|
||||
return mPackageManager;
|
||||
}
|
||||
|
||||
public DynamicCodeLogger getDynamicCodeLogger() {
|
||||
return mDynamicCodeLogger;
|
||||
}
|
||||
@ -529,7 +547,7 @@ public class DexManager {
|
||||
|
||||
PackageInfo pkg;
|
||||
try {
|
||||
pkg = mPackageManager.getPackageInfo(packageName, /*flags*/0,
|
||||
pkg = getPackageManager().getPackageInfo(packageName, /*flags*/0,
|
||||
dexUseInfo.getOwnerUserId());
|
||||
} catch (RemoteException e) {
|
||||
throw new AssertionError(e);
|
||||
@ -673,7 +691,7 @@ public class DexManager {
|
||||
// to get back the real app uid and its storage kind. These are only used
|
||||
// to perform extra validation in installd.
|
||||
// TODO(calin): maybe a bit overkill.
|
||||
pkg = mPackageManager.getPackageInfo(packageName, /*flags*/0,
|
||||
pkg = getPackageManager().getPackageInfo(packageName, /*flags*/0,
|
||||
dexUseInfo.getOwnerUserId());
|
||||
} catch (RemoteException ignore) {
|
||||
// Can't happen, DexManager is local.
|
||||
|
@ -19,11 +19,13 @@ package com.android.server.pm.dex;
|
||||
import static com.android.server.pm.dex.PackageDynamicCodeLoading.FILE_TYPE_DEX;
|
||||
import static com.android.server.pm.dex.PackageDynamicCodeLoading.FILE_TYPE_NATIVE;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.IPackageManager;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.os.FileUtils;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.UserHandle;
|
||||
import android.os.storage.StorageManager;
|
||||
import android.util.EventLog;
|
||||
@ -58,20 +60,30 @@ public class DynamicCodeLogger {
|
||||
private static final String DCL_DEX_SUBTAG = "dcl";
|
||||
private static final String DCL_NATIVE_SUBTAG = "dcln";
|
||||
|
||||
private final IPackageManager mPackageManager;
|
||||
private IPackageManager mPackageManager;
|
||||
private final PackageDynamicCodeLoading mPackageDynamicCodeLoading;
|
||||
private final Installer mInstaller;
|
||||
|
||||
DynamicCodeLogger(IPackageManager pms, Installer installer) {
|
||||
this(pms, installer, new PackageDynamicCodeLoading());
|
||||
DynamicCodeLogger(Installer installer) {
|
||||
mInstaller = installer;
|
||||
mPackageDynamicCodeLoading = new PackageDynamicCodeLoading();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
DynamicCodeLogger(IPackageManager pms, Installer installer,
|
||||
PackageDynamicCodeLoading packageDynamicCodeLoading) {
|
||||
mPackageManager = pms;
|
||||
mPackageDynamicCodeLoading = packageDynamicCodeLoading;
|
||||
DynamicCodeLogger(@NonNull IPackageManager packageManager, @NonNull Installer installer,
|
||||
@NonNull PackageDynamicCodeLoading packageDynamicCodeLoading) {
|
||||
mPackageManager = packageManager;
|
||||
mInstaller = installer;
|
||||
mPackageDynamicCodeLoading = packageDynamicCodeLoading;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private IPackageManager getPackageManager() {
|
||||
if (mPackageManager == null) {
|
||||
mPackageManager = IPackageManager.Stub.asInterface(
|
||||
ServiceManager.getService("package"));
|
||||
}
|
||||
return mPackageManager;
|
||||
}
|
||||
|
||||
public Set<String> getAllPackagesWithDynamicCodeLoading() {
|
||||
@ -104,7 +116,7 @@ public class DynamicCodeLogger {
|
||||
|
||||
try {
|
||||
PackageInfo ownerInfo =
|
||||
mPackageManager.getPackageInfo(packageName, /*flags*/ 0, userId);
|
||||
getPackageManager().getPackageInfo(packageName, /*flags*/ 0, userId);
|
||||
appInfo = ownerInfo == null ? null : ownerInfo.applicationInfo;
|
||||
} catch (RemoteException ignored) {
|
||||
// Can't happen, we're local.
|
||||
@ -167,7 +179,7 @@ public class DynamicCodeLogger {
|
||||
loadingUid = appInfo.uid;
|
||||
} else {
|
||||
try {
|
||||
loadingUid = mPackageManager.getPackageUid(loadingPackageName, /*flags*/ 0,
|
||||
loadingUid = getPackageManager().getPackageUid(loadingPackageName, /*flags*/ 0,
|
||||
userId);
|
||||
} catch (RemoteException ignored) {
|
||||
// Can't happen, we're local.
|
||||
@ -223,7 +235,7 @@ public class DynamicCodeLogger {
|
||||
public void recordNative(int loadingUid, String path) {
|
||||
String[] packages;
|
||||
try {
|
||||
packages = mPackageManager.getPackagesForUid(loadingUid);
|
||||
packages = getPackageManager().getPackagesForUid(loadingUid);
|
||||
if (packages == null || packages.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ public final class BackgroundDexOptServiceUnitTest {
|
||||
when(mInjector.getDataDirStorageLowBytes()).thenReturn(STORAGE_LOW_BYTES);
|
||||
when(mInjector.getDexOptThermalCutoff()).thenReturn(PowerManager.THERMAL_STATUS_CRITICAL);
|
||||
when(mInjector.getCurrentThermalStatus()).thenReturn(PowerManager.THERMAL_STATUS_NONE);
|
||||
when(mDexOptHelper.getOptimizablePackages()).thenReturn(DEFAULT_PACKAGE_LIST);
|
||||
when(mDexOptHelper.getOptimizablePackages(any())).thenReturn(DEFAULT_PACKAGE_LIST);
|
||||
when(mDexOptHelper.performDexOptWithStatus(any())).thenReturn(
|
||||
PackageDexOptimizer.DEX_OPT_PERFORMED);
|
||||
|
||||
@ -158,7 +158,7 @@ public final class BackgroundDexOptServiceUnitTest {
|
||||
@Test
|
||||
public void testNoExecutionForNoOptimizablePackages() {
|
||||
initUntilBootCompleted();
|
||||
when(mDexOptHelper.getOptimizablePackages()).thenReturn(EMPTY_PACKAGE_LIST);
|
||||
when(mDexOptHelper.getOptimizablePackages(any())).thenReturn(EMPTY_PACKAGE_LIST);
|
||||
|
||||
assertThat(mService.onStartJob(mJobServiceForPostBoot,
|
||||
mJobParametersForPostBoot)).isFalse();
|
||||
|
@ -157,7 +157,7 @@ class PackageManagerServiceHibernationTests {
|
||||
rule.system().validateFinalState()
|
||||
whenever(appHibernationManager.isHibernatingGlobally(TEST_PACKAGE_2_NAME)).thenReturn(true)
|
||||
|
||||
val optimizablePkgs = DexOptHelper(pm).optimizablePackages
|
||||
val optimizablePkgs = DexOptHelper(pm).getOptimizablePackages(pm.snapshotComputer())
|
||||
|
||||
assertTrue(optimizablePkgs.contains(TEST_PACKAGE_NAME))
|
||||
assertFalse(optimizablePkgs.contains(TEST_PACKAGE_2_NAME))
|
||||
|
@ -85,6 +85,7 @@ class SharedLibrariesImplTest {
|
||||
private lateinit var mSharedLibrariesImpl: SharedLibrariesImpl
|
||||
private lateinit var mPms: PackageManagerService
|
||||
private lateinit var mSettings: Settings
|
||||
private lateinit var mComputer: Computer
|
||||
|
||||
@Mock
|
||||
private lateinit var mDeletePackageHelper: DeletePackageHelper
|
||||
@ -114,22 +115,16 @@ class SharedLibrariesImplTest {
|
||||
mSharedLibrariesImpl.setDeletePackageHelper(mDeletePackageHelper)
|
||||
addExistingSharedLibraries()
|
||||
|
||||
mComputer = mock {
|
||||
whenever(sharedLibraries) { mSharedLibrariesImpl.sharedLibraries }
|
||||
whenever(resolveInternalPackageName(anyString(), anyLong())) { arguments[0] }
|
||||
}
|
||||
|
||||
whenever(mSettings.getPackageLPr(any())) { mExistingSettings[arguments[0]] }
|
||||
whenever(mRule.mocks().injector.getSystemService(StorageManager::class.java))
|
||||
.thenReturn(mStorageManager)
|
||||
whenever(mStorageManager.findPathForUuid(nullable())).thenReturn(mFile)
|
||||
doAnswer { it.arguments[0] }.`when`(mPms).resolveInternalPackageName(any(), any())
|
||||
doAnswer {
|
||||
mockThrowOnUnmocked<Computer> {
|
||||
whenever(sharedLibraries) { mSharedLibrariesImpl.sharedLibraries }
|
||||
whenever(resolveInternalPackageName(anyString(), anyLong())) {
|
||||
mPms.resolveInternalPackageName(getArgument(0), getArgument(1))
|
||||
}
|
||||
whenever(getPackageStateInternal(anyString())) {
|
||||
mPms.getPackageStateInternal(getArgument(0))
|
||||
}
|
||||
}
|
||||
}.`when`(mPms).snapshotComputer()
|
||||
doAnswer { mComputer }.`when`(mPms).snapshotComputer()
|
||||
whenever(mDeletePackageHelper.deletePackageX(any(), any(), any(), any(), any()))
|
||||
.thenReturn(PackageManager.DELETE_SUCCEEDED)
|
||||
whenever(mRule.mocks().injector.compatibility).thenReturn(mPlatformCompat)
|
||||
@ -189,7 +184,8 @@ class SharedLibrariesImplTest {
|
||||
|
||||
@Test
|
||||
fun removeSharedLibrary() {
|
||||
doAnswer { mutableListOf(VersionedPackage(CONSUMER_PACKAGE_NAME, 1L)) }.`when`(mPms)
|
||||
doAnswer { mutableListOf(VersionedPackage(CONSUMER_PACKAGE_NAME, 1L)) }
|
||||
.`when`(mComputer)
|
||||
.getPackagesUsingSharedLibrary(any(), any(), any(), any())
|
||||
val staticInfo = mSharedLibrariesImpl
|
||||
.getSharedLibraryInfo(STATIC_LIB_NAME, STATIC_LIB_VERSION)!!
|
||||
|
@ -104,9 +104,9 @@ class SuspendPackageHelperTest {
|
||||
pms, rule.mocks().injector, broadcastHelper, protectedPackages)
|
||||
defaultAppProvider = rule.mocks().defaultAppProvider
|
||||
testHandler = rule.mocks().handler
|
||||
packageSetting1 = pms.getPackageStateInternal(TEST_PACKAGE_1)!!
|
||||
packageSetting2 = pms.getPackageStateInternal(TEST_PACKAGE_2)!!
|
||||
ownerSetting = pms.getPackageStateInternal(DEVICE_OWNER_PACKAGE)!!
|
||||
packageSetting1 = pms.snapshotComputer().getPackageStateInternal(TEST_PACKAGE_1)!!
|
||||
packageSetting2 = pms.snapshotComputer().getPackageStateInternal(TEST_PACKAGE_2)!!
|
||||
ownerSetting = pms.snapshotComputer().getPackageStateInternal(DEVICE_OWNER_PACKAGE)!!
|
||||
deviceOwnerUid = UserHandle.getUid(TEST_USER_ID, ownerSetting.appId)
|
||||
packagesToSuspend = arrayOf(TEST_PACKAGE_1, TEST_PACKAGE_2)
|
||||
uidsToSuspend = intArrayOf(packageSetting1.appId, packageSetting2.appId)
|
||||
@ -270,7 +270,7 @@ class SuspendPackageHelperTest {
|
||||
testHandler.flush()
|
||||
assertThat(failedNames).isEmpty()
|
||||
|
||||
val result = suspendPackageHelper.getSuspendedPackageAppExtras(
|
||||
val result = suspendPackageHelper.getSuspendedPackageAppExtras(pms.snapshotComputer(),
|
||||
TEST_PACKAGE_1, TEST_USER_ID, deviceOwnerUid)!!
|
||||
|
||||
assertThat(result.getString(TEST_PACKAGE_1)).isEqualTo(TEST_PACKAGE_1)
|
||||
@ -286,13 +286,13 @@ class SuspendPackageHelperTest {
|
||||
null /* dialogInfo */, DEVICE_OWNER_PACKAGE, TEST_USER_ID, deviceOwnerUid)
|
||||
testHandler.flush()
|
||||
assertThat(failedNames).isEmpty()
|
||||
assertThat(suspendPackageHelper.getSuspendingPackage(
|
||||
assertThat(suspendPackageHelper.getSuspendingPackage(pms.snapshotComputer(),
|
||||
TEST_PACKAGE_1, TEST_USER_ID, deviceOwnerUid)).isEqualTo(DEVICE_OWNER_PACKAGE)
|
||||
assertThat(suspendPackageHelper.getSuspendingPackage(
|
||||
assertThat(suspendPackageHelper.getSuspendingPackage(pms.snapshotComputer(),
|
||||
TEST_PACKAGE_2, TEST_USER_ID, deviceOwnerUid)).isEqualTo(DEVICE_OWNER_PACKAGE)
|
||||
assertThat(suspendPackageHelper.getSuspendedPackageAppExtras(
|
||||
assertThat(suspendPackageHelper.getSuspendedPackageAppExtras(pms.snapshotComputer(),
|
||||
TEST_PACKAGE_1, TEST_USER_ID, deviceOwnerUid)).isNotNull()
|
||||
assertThat(suspendPackageHelper.getSuspendedPackageAppExtras(
|
||||
assertThat(suspendPackageHelper.getSuspendedPackageAppExtras(pms.snapshotComputer(),
|
||||
TEST_PACKAGE_2, TEST_USER_ID, deviceOwnerUid)).isNotNull()
|
||||
|
||||
suspendPackageHelper.removeSuspensionsBySuspendingPackage(pms.snapshotComputer(),
|
||||
@ -311,13 +311,13 @@ class SuspendPackageHelperTest {
|
||||
nullable(), nullable(), any(), eq(TEST_PACKAGE_2), nullable(), any(), any(),
|
||||
nullable(), nullable())
|
||||
|
||||
assertThat(suspendPackageHelper.getSuspendingPackage(
|
||||
assertThat(suspendPackageHelper.getSuspendingPackage(pms.snapshotComputer(),
|
||||
TEST_PACKAGE_1, TEST_USER_ID, deviceOwnerUid)).isNull()
|
||||
assertThat(suspendPackageHelper.getSuspendingPackage(
|
||||
assertThat(suspendPackageHelper.getSuspendingPackage(pms.snapshotComputer(),
|
||||
TEST_PACKAGE_2, TEST_USER_ID, deviceOwnerUid)).isNull()
|
||||
assertThat(suspendPackageHelper.getSuspendedPackageAppExtras(
|
||||
assertThat(suspendPackageHelper.getSuspendedPackageAppExtras(pms.snapshotComputer(),
|
||||
TEST_PACKAGE_1, TEST_USER_ID, deviceOwnerUid)).isNull()
|
||||
assertThat(suspendPackageHelper.getSuspendedPackageAppExtras(
|
||||
assertThat(suspendPackageHelper.getSuspendedPackageAppExtras(pms.snapshotComputer(),
|
||||
TEST_PACKAGE_2, TEST_USER_ID, deviceOwnerUid)).isNull()
|
||||
}
|
||||
|
||||
@ -331,7 +331,7 @@ class SuspendPackageHelperTest {
|
||||
testHandler.flush()
|
||||
assertThat(failedNames).isEmpty()
|
||||
|
||||
val result = suspendPackageHelper.getSuspendedPackageLauncherExtras(
|
||||
val result = suspendPackageHelper.getSuspendedPackageLauncherExtras(pms.snapshotComputer(),
|
||||
TEST_PACKAGE_2, TEST_USER_ID, deviceOwnerUid)!!
|
||||
|
||||
assertThat(result.getString(TEST_PACKAGE_2)).isEqualTo(TEST_PACKAGE_2)
|
||||
@ -346,7 +346,7 @@ class SuspendPackageHelperTest {
|
||||
testHandler.flush()
|
||||
assertThat(failedNames).isEmpty()
|
||||
|
||||
assertThat(suspendPackageHelper.isPackageSuspended(
|
||||
assertThat(suspendPackageHelper.isPackageSuspended(pms.snapshotComputer(),
|
||||
TEST_PACKAGE_1, TEST_USER_ID, deviceOwnerUid)).isTrue()
|
||||
}
|
||||
|
||||
@ -360,7 +360,7 @@ class SuspendPackageHelperTest {
|
||||
testHandler.flush()
|
||||
assertThat(failedNames).isEmpty()
|
||||
|
||||
assertThat(suspendPackageHelper.getSuspendingPackage(
|
||||
assertThat(suspendPackageHelper.getSuspendingPackage(pms.snapshotComputer(),
|
||||
TEST_PACKAGE_2, TEST_USER_ID, deviceOwnerUid)).isEqualTo(DEVICE_OWNER_PACKAGE)
|
||||
}
|
||||
|
||||
@ -375,7 +375,7 @@ class SuspendPackageHelperTest {
|
||||
testHandler.flush()
|
||||
assertThat(failedNames).isEmpty()
|
||||
|
||||
val result = suspendPackageHelper.getSuspendedDialogInfo(
|
||||
val result = suspendPackageHelper.getSuspendedDialogInfo(pms.snapshotComputer(),
|
||||
TEST_PACKAGE_1, DEVICE_OWNER_PACKAGE, TEST_USER_ID, deviceOwnerUid)!!
|
||||
|
||||
assertThat(result.title).isEqualTo(TEST_PACKAGE_1)
|
||||
@ -387,8 +387,8 @@ class SuspendPackageHelperTest {
|
||||
mockAllowList(packageSetting1, allowList(10001, 10002, 10003))
|
||||
mockAllowList(packageSetting2, allowList(10001, 10002, 10003))
|
||||
|
||||
suspendPackageHelper.sendPackagesSuspendedForUser(Intent.ACTION_PACKAGES_SUSPENDED,
|
||||
packagesToSuspend, uidsToSuspend, TEST_USER_ID)
|
||||
suspendPackageHelper.sendPackagesSuspendedForUser(pms.snapshotComputer(),
|
||||
Intent.ACTION_PACKAGES_SUSPENDED, packagesToSuspend, uidsToSuspend, TEST_USER_ID)
|
||||
testHandler.flush()
|
||||
verify(broadcastHelper).sendPackageBroadcast(any(), nullable(), bundleCaptor.capture(),
|
||||
anyInt(), nullable(), nullable(), any(), nullable(), any(), nullable())
|
||||
@ -406,8 +406,8 @@ class SuspendPackageHelperTest {
|
||||
mockAllowList(packageSetting1, allowList(10001, 10002, 10003))
|
||||
mockAllowList(packageSetting2, allowList(10001, 10002, 10007))
|
||||
|
||||
suspendPackageHelper.sendPackagesSuspendedForUser(Intent.ACTION_PACKAGES_SUSPENDED,
|
||||
packagesToSuspend, uidsToSuspend, TEST_USER_ID)
|
||||
suspendPackageHelper.sendPackagesSuspendedForUser(pms.snapshotComputer(),
|
||||
Intent.ACTION_PACKAGES_SUSPENDED, packagesToSuspend, uidsToSuspend, TEST_USER_ID)
|
||||
testHandler.flush()
|
||||
verify(broadcastHelper, times(2)).sendPackageBroadcast(
|
||||
any(), nullable(), bundleCaptor.capture(), anyInt(), nullable(), nullable(), any(),
|
||||
@ -429,8 +429,8 @@ class SuspendPackageHelperTest {
|
||||
mockAllowList(packageSetting1, allowList(10001, 10002, 10003))
|
||||
mockAllowList(packageSetting2, null)
|
||||
|
||||
suspendPackageHelper.sendPackagesSuspendedForUser(Intent.ACTION_PACKAGES_SUSPENDED,
|
||||
packagesToSuspend, uidsToSuspend, TEST_USER_ID)
|
||||
suspendPackageHelper.sendPackagesSuspendedForUser(pms.snapshotComputer(),
|
||||
Intent.ACTION_PACKAGES_SUSPENDED, packagesToSuspend, uidsToSuspend, TEST_USER_ID)
|
||||
testHandler.flush()
|
||||
verify(broadcastHelper, times(2)).sendPackageBroadcast(
|
||||
any(), nullable(), bundleCaptor.capture(), anyInt(), nullable(), nullable(), any(),
|
||||
@ -449,8 +449,9 @@ class SuspendPackageHelperTest {
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun sendPackagesSuspendModifiedForUser() {
|
||||
suspendPackageHelper.sendPackagesSuspendedForUser(Intent.ACTION_PACKAGES_SUSPENSION_CHANGED,
|
||||
packagesToSuspend, uidsToSuspend, TEST_USER_ID)
|
||||
suspendPackageHelper.sendPackagesSuspendedForUser(pms.snapshotComputer(),
|
||||
Intent.ACTION_PACKAGES_SUSPENSION_CHANGED, packagesToSuspend, uidsToSuspend,
|
||||
TEST_USER_ID)
|
||||
testHandler.flush()
|
||||
verify(broadcastHelper).sendPackageBroadcast(
|
||||
eq(Intent.ACTION_PACKAGES_SUSPENSION_CHANGED), nullable(), bundleCaptor.capture(),
|
||||
@ -483,13 +484,13 @@ class SuspendPackageHelperTest {
|
||||
Mockito.doReturn(DIALER_PACKAGE).`when`(defaultAppProvider)
|
||||
.getDefaultDialer(eq(TEST_USER_ID))
|
||||
Mockito.doReturn(arrayOf(INSTALLER_PACKAGE)).`when`(pms).getKnownPackageNamesInternal(
|
||||
eq(PackageManagerInternal.PACKAGE_INSTALLER), eq(TEST_USER_ID))
|
||||
any(), eq(PackageManagerInternal.PACKAGE_INSTALLER), eq(TEST_USER_ID))
|
||||
Mockito.doReturn(arrayOf(UNINSTALLER_PACKAGE)).`when`(pms).getKnownPackageNamesInternal(
|
||||
eq(PackageManagerInternal.PACKAGE_UNINSTALLER), eq(TEST_USER_ID))
|
||||
any(), eq(PackageManagerInternal.PACKAGE_UNINSTALLER), eq(TEST_USER_ID))
|
||||
Mockito.doReturn(arrayOf(VERIFIER_PACKAGE)).`when`(pms).getKnownPackageNamesInternal(
|
||||
eq(PackageManagerInternal.PACKAGE_VERIFIER), eq(TEST_USER_ID))
|
||||
any(), eq(PackageManagerInternal.PACKAGE_VERIFIER), eq(TEST_USER_ID))
|
||||
Mockito.doReturn(arrayOf(PERMISSION_CONTROLLER_PACKAGE)).`when`(pms)
|
||||
.getKnownPackageNamesInternal(
|
||||
.getKnownPackageNamesInternal(any(),
|
||||
eq(PackageManagerInternal.PACKAGE_PERMISSION_CONTROLLER), eq(TEST_USER_ID))
|
||||
}
|
||||
|
||||
|
@ -159,8 +159,8 @@ public class DexManagerTests {
|
||||
.when(mockContext)
|
||||
.getSystemService(PowerManager.class);
|
||||
|
||||
mDexManager = new DexManager(mockContext, mPM, /*PackageDexOptimizer*/ null,
|
||||
mInstaller, mInstallLock);
|
||||
mDexManager = new DexManager(mockContext, /*PackageDexOptimizer*/ null,
|
||||
mInstaller, mInstallLock, mPM);
|
||||
|
||||
// Foo and Bar are available to user0.
|
||||
// Only Bar is available to user1;
|
||||
|
@ -23,11 +23,10 @@ import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import static java.lang.reflect.Modifier.isFinal;
|
||||
import static java.lang.reflect.Modifier.isPrivate;
|
||||
import static java.lang.reflect.Modifier.isProtected;
|
||||
import static java.lang.reflect.Modifier.isPublic;
|
||||
import static java.lang.reflect.Modifier.isStatic;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.app.AppGlobals;
|
||||
import android.content.IIntentReceiver;
|
||||
@ -63,7 +62,6 @@ import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -101,7 +99,7 @@ public class PackageManagerServiceTest {
|
||||
@Nullable Bundle bOptions) {
|
||||
}
|
||||
|
||||
public void sendPackageAddedForNewUsers(String packageName,
|
||||
public void sendPackageAddedForNewUsers(@NonNull Computer snapshot, String packageName,
|
||||
boolean sendBootComplete, boolean includeStopped, int appId,
|
||||
int[] userIds, int[] instantUserIds, int dataLoaderType) {
|
||||
}
|
||||
@ -456,147 +454,6 @@ public class PackageManagerServiceTest {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return the boolean locked value. A null return means the annotation was not
|
||||
// found. This method will fail if the annotation is found but is not one of the
|
||||
// known constants.
|
||||
private Boolean getOverride(Method m) {
|
||||
final String name = "Computer." + displayName(m);
|
||||
final Computer.LiveImplementation annotation =
|
||||
m.getAnnotation(Computer.LiveImplementation.class);
|
||||
if (annotation == null) {
|
||||
return null;
|
||||
}
|
||||
final int override = annotation.override();
|
||||
if (override == Computer.LiveImplementation.MANDATORY) {
|
||||
return true;
|
||||
} else if (override == Computer.LiveImplementation.NOT_ALLOWED) {
|
||||
return false;
|
||||
} else {
|
||||
flag(name, "invalid Live value: " + override);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComputerStructure() {
|
||||
// Verify that Copmuter methods are properly annotated and that ComputerLocked is
|
||||
// properly populated per annotations.
|
||||
// Call PackageManagerService.validateComputer();
|
||||
Class base = Computer.class;
|
||||
|
||||
HashMap<Method, Boolean> methodType = new HashMap<>();
|
||||
|
||||
// Verify that all Computer methods are annotated and that the annotation
|
||||
// parameter locked() is valid.
|
||||
for (Method m : base.getDeclaredMethods()) {
|
||||
final String name = "Computer." + displayName(m);
|
||||
Boolean override = getOverride(m);
|
||||
if (override == null) {
|
||||
flag(name, "missing required Live annotation");
|
||||
}
|
||||
methodType.put(m, override);
|
||||
}
|
||||
|
||||
Class coreClass = ComputerEngine.class;
|
||||
final Method[] coreMethods = coreClass.getDeclaredMethods();
|
||||
|
||||
// Examine every method in the core. If it inherits from a base method it must be
|
||||
// "public final" if the base is NOT_ALLOWED or "public" if the base is MANDATORY.
|
||||
// If the core method does not inherit from the base then it must be either
|
||||
// private or protected.
|
||||
for (Method m : base.getDeclaredMethods()) {
|
||||
String name = "Computer." + displayName(m);
|
||||
final boolean locked = methodType.get(m);
|
||||
final Method core = matchMethod(m, coreMethods);
|
||||
if (core == null) {
|
||||
flag(name, "not overridden in ComputerEngine");
|
||||
continue;
|
||||
}
|
||||
name = "ComputerEngine." + displayName(m);
|
||||
final int modifiers = core.getModifiers();
|
||||
if (!locked) {
|
||||
if (!isPublic(modifiers)) {
|
||||
flag(name, "is not public");
|
||||
}
|
||||
if (!isFinal(modifiers)) {
|
||||
flag(name, "is not final");
|
||||
}
|
||||
}
|
||||
}
|
||||
// Any methods left in the coreMethods array must be private or protected.
|
||||
// Protected methods must be overridden (and final) in the live list.
|
||||
Method[] coreHelpers = new Method[coreMethods.length];
|
||||
int coreIndex = 0;
|
||||
for (Method m : coreMethods) {
|
||||
if (m != null) {
|
||||
final String name = "ComputerEngine." + displayName(m);
|
||||
if (name.contains(".lambda$static")) {
|
||||
// skip static lambda function
|
||||
continue;
|
||||
}
|
||||
|
||||
final int modifiers = m.getModifiers();
|
||||
if (isPrivate(modifiers)) {
|
||||
// Okay
|
||||
} else if (isProtected(modifiers)) {
|
||||
coreHelpers[coreIndex++] = m;
|
||||
} else {
|
||||
flag(name, "is neither private nor protected");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Class liveClass = ComputerLocked.class;
|
||||
final Method[] liveMethods = liveClass.getDeclaredMethods();
|
||||
|
||||
// Examine every method in the live list. Every method must be final and must
|
||||
// inherit either from base or core. If the method inherits from a base method
|
||||
// then the base must be MANDATORY.
|
||||
for (Method m : base.getDeclaredMethods()) {
|
||||
String name = "Computer." + displayName(m);
|
||||
final boolean locked = methodType.get(m);
|
||||
final Method live = matchMethod(m, liveMethods);
|
||||
if (live == null) {
|
||||
if (locked) {
|
||||
flag(name, "not overridden in ComputerLocked");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!locked) {
|
||||
flag(name, "improperly overridden in ComputerLocked");
|
||||
continue;
|
||||
}
|
||||
|
||||
name = "ComputerLocked." + displayName(m);
|
||||
final int modifiers = live.getModifiers();
|
||||
if (!locked) {
|
||||
if (!isPublic(modifiers)) {
|
||||
flag(name, "is not public");
|
||||
}
|
||||
if (!isFinal(modifiers)) {
|
||||
flag(name, "is not final");
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Method m : coreHelpers) {
|
||||
if (m == null) {
|
||||
continue;
|
||||
}
|
||||
String name = "ComputerLocked." + displayName(m);
|
||||
final Method live = matchMethod(m, liveMethods);
|
||||
if (live == null) {
|
||||
flag(name, "is not overridden in ComputerLocked");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
for (Method m : liveMethods) {
|
||||
if (m != null) {
|
||||
String name = "ComputerLocked." + displayName(m);
|
||||
flag(name, "illegal local method");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static PerPackageReadTimeouts[] getPerPackageReadTimeouts(String knownDigestersList) {
|
||||
final String defaultTimeouts = "3600000001:3600000002:3600000003";
|
||||
List<PerPackageReadTimeouts> result = PerPackageReadTimeouts.parseDigestersList(
|
||||
|
Loading…
x
Reference in New Issue
Block a user