Merge "Clean up uses-native-library targetSdkVersion check" into sc-dev

This commit is contained in:
Rhed Jao
2021-05-03 03:27:31 +00:00
committed by Android (Google) Code Review
2 changed files with 30 additions and 7 deletions

View File

@@ -167,6 +167,28 @@ public class PlatformCompat extends IPlatformCompat.Stub {
return enabled;
}
/**
* Called by the package manager to check if a given change is enabled for a given package name
* and the target sdk version while the package is in the parsing state.
*
* <p>Does not perform costly permission check.
*
* @param changeId the ID of the change in question
* @param packageName package name to check for
* @param targetSdkVersion target sdk version to check for
* @return {@code true} if the change would be enabled for this package name.
*/
public boolean isChangeEnabledInternal(long changeId, String packageName,
int targetSdkVersion) {
if (mCompatConfig.willChangeBeEnabled(changeId, packageName)) {
final ApplicationInfo appInfo = new ApplicationInfo();
appInfo.packageName = packageName;
appInfo.targetSdkVersion = targetSdkVersion;
return isChangeEnabledInternalNoLogging(changeId, appInfo);
}
return false;
}
@Override
public void setOverrides(CompatibilityChangeConfig overrides, String packageName) {
checkCompatChangeOverridePermission();

View File

@@ -12711,7 +12711,8 @@ public class PackageManagerService extends IPackageManager.Stub
Map<String, AndroidPackage> availablePackages)
throws PackageManagerException {
final ArrayList<SharedLibraryInfo> sharedLibraryInfos = collectSharedLibraryInfos(
pkgSetting.pkg, availablePackages, mSharedLibraries, null);
pkgSetting.pkg, availablePackages, mSharedLibraries, null /* newLibraries */,
mInjector.getCompatibility());
executeSharedLibrariesUpdateLPr(pkg, pkgSetting, changingLib, changingLibSetting,
sharedLibraryInfos, mUserManager.getUserIds());
}
@@ -12719,8 +12720,8 @@ public class PackageManagerService extends IPackageManager.Stub
private static ArrayList<SharedLibraryInfo> collectSharedLibraryInfos(AndroidPackage pkg,
Map<String, AndroidPackage> availablePackages,
@NonNull final Map<String, WatchedLongSparseArray<SharedLibraryInfo>> existingLibraries,
@Nullable final Map<String, WatchedLongSparseArray<SharedLibraryInfo>> newLibraries)
throws PackageManagerException {
@Nullable final Map<String, WatchedLongSparseArray<SharedLibraryInfo>> newLibraries,
PlatformCompat platformCompat) throws PackageManagerException {
if (pkg == null) {
return null;
}
@@ -12744,9 +12745,9 @@ public class PackageManagerService extends IPackageManager.Stub
null, null, pkg.getPackageName(), false, pkg.getTargetSdkVersion(),
usesLibraryInfos, availablePackages, existingLibraries, newLibraries);
}
// TODO(b/160928779) gate this behavior using ENFORCE_NATIVE_SHARED_LIBRARY_DEPENDENCIES
if (pkg.getTargetSdkVersion() > 30) {
if (!pkg.getUsesNativeLibraries().isEmpty() && pkg.getTargetSdkVersion() > 30) {
if (platformCompat.isChangeEnabledInternal(ENFORCE_NATIVE_SHARED_LIBRARY_DEPENDENCIES,
pkg.getPackageName(), pkg.getTargetSdkVersion())) {
if (!pkg.getUsesNativeLibraries().isEmpty()) {
usesLibraryInfos = collectSharedLibraryInfos(pkg.getUsesNativeLibraries(), null,
null, pkg.getPackageName(), true, pkg.getTargetSdkVersion(),
usesLibraryInfos, availablePackages, existingLibraries, newLibraries);
@@ -18875,7 +18876,7 @@ public class PackageManagerService extends IPackageManager.Stub
result.get(installPackageName).collectedSharedLibraryInfos =
collectSharedLibraryInfos(scanResult.request.parsedPackage,
combinedPackages, request.sharedLibrarySource,
incomingSharedLibraries);
incomingSharedLibraries, injector.getCompatibility());
} catch (PackageManagerException e) {
throw new ReconcileFailure(e.error, e.getMessage());