Merge changes from topic "hidl-updater-system"

am: 5a490d4bb7

Change-Id: I1fe4f587bb5f7452752ea3c7fc23635fb4a8aee2
This commit is contained in:
Steven Moreland
2019-03-13 10:11:57 -07:00
committed by android-build-merger
5 changed files with 56 additions and 11 deletions

View File

@@ -34,8 +34,14 @@ public class AndroidHidlUpdater extends PackageSharedLibraryUpdater {
@Override @Override
public void updatePackage(Package pkg) { public void updatePackage(Package pkg) {
ApplicationInfo info = pkg.applicationInfo;
// This was the default <= P and is maintained for backwards compatibility. // This was the default <= P and is maintained for backwards compatibility.
if (pkg.applicationInfo.targetSdkVersion <= Build.VERSION_CODES.P) { boolean isLegacy = info.targetSdkVersion <= Build.VERSION_CODES.P;
// Only system apps use these libraries
boolean isSystem = info.isSystemApp() || info.isUpdatedSystemApp();
if (isLegacy && isSystem) {
prefixRequiredLibrary(pkg, ANDROID_HIDL_BASE); prefixRequiredLibrary(pkg, ANDROID_HIDL_BASE);
prefixRequiredLibrary(pkg, ANDROID_HIDL_MANAGER); prefixRequiredLibrary(pkg, ANDROID_HIDL_MANAGER);
} else { } else {

View File

@@ -3857,8 +3857,6 @@ public class PackageParser {
// every activity info has had a chance to set it from its attributes. // every activity info has had a chance to set it from its attributes.
setMaxAspectRatio(owner); setMaxAspectRatio(owner);
PackageBackwardCompatibility.modifySharedLibraries(owner);
if (hasDomainURLs(owner)) { if (hasDomainURLs(owner)) {
owner.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS; owner.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS;
} else { } else {

View File

@@ -40,8 +40,17 @@ public class AndroidHidlUpdaterTest extends PackageSharedLibraryUpdaterTest {
PackageBuilder before = builder() PackageBuilder before = builder()
.targetSdkVersion(Build.VERSION_CODES.P); .targetSdkVersion(Build.VERSION_CODES.P);
// no change, not system
checkBackwardsCompatibility(before, before);
}
@Test
public void targeted_at_P_system() {
PackageBuilder before = builder().asSystemApp()
.targetSdkVersion(Build.VERSION_CODES.P);
// Should add both HIDL libraries // Should add both HIDL libraries
PackageBuilder after = builder() PackageBuilder after = builder().asSystemApp()
.targetSdkVersion(Build.VERSION_CODES.P) .targetSdkVersion(Build.VERSION_CODES.P)
.requiredLibraries(ANDROID_HIDL_MANAGER, ANDROID_HIDL_BASE); .requiredLibraries(ANDROID_HIDL_MANAGER, ANDROID_HIDL_BASE);
@@ -54,9 +63,19 @@ public class AndroidHidlUpdaterTest extends PackageSharedLibraryUpdaterTest {
.targetSdkVersion(Build.VERSION_CODES.P) .targetSdkVersion(Build.VERSION_CODES.P)
.requiredLibraries(OTHER_LIBRARY); .requiredLibraries(OTHER_LIBRARY);
// no change, not system
checkBackwardsCompatibility(before, before);
}
@Test
public void targeted_at_P_not_empty_usesLibraries_system() {
PackageBuilder before = builder().asSystemApp()
.targetSdkVersion(Build.VERSION_CODES.P)
.requiredLibraries(OTHER_LIBRARY);
// The hidl jars should be added at the start of the list because it // The hidl jars should be added at the start of the list because it
// is not on the bootclasspath and the package targets pre-P. // is not on the bootclasspath and the package targets pre-P.
PackageBuilder after = builder() PackageBuilder after = builder().asSystemApp()
.targetSdkVersion(Build.VERSION_CODES.P) .targetSdkVersion(Build.VERSION_CODES.P)
.requiredLibraries(ANDROID_HIDL_MANAGER, ANDROID_HIDL_BASE, OTHER_LIBRARY); .requiredLibraries(ANDROID_HIDL_MANAGER, ANDROID_HIDL_BASE, OTHER_LIBRARY);
@@ -69,8 +88,21 @@ public class AndroidHidlUpdaterTest extends PackageSharedLibraryUpdaterTest {
.targetSdkVersion(Build.VERSION_CODES.P) .targetSdkVersion(Build.VERSION_CODES.P)
.requiredLibraries(ANDROID_HIDL_MANAGER, ANDROID_HIDL_BASE); .requiredLibraries(ANDROID_HIDL_MANAGER, ANDROID_HIDL_BASE);
// No change is required because although the HIDL libraries has been removed from PackageBuilder after = builder()
// the bootclasspath the package explicitly requests it. .targetSdkVersion(Build.VERSION_CODES.P);
// Libraries are removed because they are not available for non-system apps
checkBackwardsCompatibility(before, after);
}
@Test
public void targeted_at_P_in_usesLibraries_system() {
PackageBuilder before = builder().asSystemApp()
.targetSdkVersion(Build.VERSION_CODES.P)
.requiredLibraries(ANDROID_HIDL_MANAGER, ANDROID_HIDL_BASE);
// No change is required because the package explicitly requests the HIDL libraries
// and is targeted at the current version so does not need backwards compatibility.
checkBackwardsCompatibility(before, before); checkBackwardsCompatibility(before, before);
} }
@@ -81,8 +113,7 @@ public class AndroidHidlUpdaterTest extends PackageSharedLibraryUpdaterTest {
// Dependency is removed, it is not available. // Dependency is removed, it is not available.
PackageBuilder after = builder(); PackageBuilder after = builder();
// No change is required because the package explicitly requests the HIDL libraries // Libraries are removed because they are not available for apps targetting Q+
// and is targeted at the current version so does not need backwards compatibility.
checkBackwardsCompatibility(before, after); checkBackwardsCompatibility(before, after);
} }
@@ -93,8 +124,7 @@ public class AndroidHidlUpdaterTest extends PackageSharedLibraryUpdaterTest {
// Dependency is removed, it is not available. // Dependency is removed, it is not available.
PackageBuilder after = builder(); PackageBuilder after = builder();
// No change is required because the package explicitly requests the HIDL libraries // Libraries are removed because they are not available for apps targetting Q+
// and is targeted at the current version so does not need backwards compatibility.
checkBackwardsCompatibility(before, after); checkBackwardsCompatibility(before, after);
} }

View File

@@ -30,6 +30,8 @@ class PackageBuilder {
private int mTargetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT; private int mTargetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;
private int mFlags = 0;
private ArrayList<String> mRequiredLibraries; private ArrayList<String> mRequiredLibraries;
private ArrayList<String> mOptionalLibraries; private ArrayList<String> mOptionalLibraries;
@@ -41,6 +43,7 @@ class PackageBuilder {
public PackageParser.Package build() { public PackageParser.Package build() {
PackageParser.Package pkg = new PackageParser.Package("org.package.name"); PackageParser.Package pkg = new PackageParser.Package("org.package.name");
pkg.applicationInfo.targetSdkVersion = mTargetSdkVersion; pkg.applicationInfo.targetSdkVersion = mTargetSdkVersion;
pkg.applicationInfo.flags = mFlags;
pkg.usesLibraries = mRequiredLibraries; pkg.usesLibraries = mRequiredLibraries;
pkg.usesOptionalLibraries = mOptionalLibraries; pkg.usesOptionalLibraries = mOptionalLibraries;
return pkg; return pkg;
@@ -51,6 +54,11 @@ class PackageBuilder {
return this; return this;
} }
PackageBuilder asSystemApp() {
this.mFlags |= ApplicationInfo.FLAG_SYSTEM;
return this;
}
PackageBuilder requiredLibraries(String... names) { PackageBuilder requiredLibraries(String... names) {
this.mRequiredLibraries = arrayListOrNull(names); this.mRequiredLibraries = arrayListOrNull(names);
return this; return this;

View File

@@ -168,6 +168,7 @@ import android.content.pm.InstantAppRequest;
import android.content.pm.InstantAppResolveInfo; import android.content.pm.InstantAppResolveInfo;
import android.content.pm.InstrumentationInfo; import android.content.pm.InstrumentationInfo;
import android.content.pm.IntentFilterVerificationInfo; import android.content.pm.IntentFilterVerificationInfo;
import android.content.pm.PackageBackwardCompatibility;
import android.content.pm.KeySet; import android.content.pm.KeySet;
import android.content.pm.PackageCleanItem; import android.content.pm.PackageCleanItem;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
@@ -11043,6 +11044,8 @@ public class PackageManagerService extends IPackageManager.Stub
pkg.mRealPackage = null; pkg.mRealPackage = null;
pkg.mAdoptPermissions = null; pkg.mAdoptPermissions = null;
} }
PackageBackwardCompatibility.modifySharedLibraries(pkg);
} }
private static @NonNull <T> T assertNotNull(@Nullable T object, String message) private static @NonNull <T> T assertNotNull(@Nullable T object, String message)