Merge "Update backwards compatibility support for android.test.base"

am: 617e556477

Change-Id: I05a06bfc724f204e28f995912e31c4ebd3135cac
This commit is contained in:
Paul Duffin
2019-02-21 05:34:51 -08:00
committed by android-build-merger
5 changed files with 26 additions and 20 deletions

View File

@@ -19,11 +19,12 @@ import static android.content.pm.SharedLibraryNames.ANDROID_TEST_BASE;
import static android.content.pm.SharedLibraryNames.ANDROID_TEST_RUNNER;
import android.content.pm.PackageParser.Package;
import android.os.Build;
import com.android.internal.annotations.VisibleForTesting;
/**
* Updates a package to ensure that if it targets < P that the android.test.base library is
* Updates a package to ensure that if it targets <= P that the android.test.base library is
* included by default.
*
* <p>This is separated out so that it can be conditionally included at build time depending on
@@ -37,12 +38,17 @@ import com.android.internal.annotations.VisibleForTesting;
@VisibleForTesting
public class AndroidTestBaseUpdater extends PackageSharedLibraryUpdater {
private static boolean apkTargetsApiLevelLessThanOrEqualToP(Package pkg) {
int targetSdkVersion = pkg.applicationInfo.targetSdkVersion;
return targetSdkVersion <= Build.VERSION_CODES.P;
}
@Override
public void updatePackage(Package pkg) {
// Packages targeted at <= O_MR1 expect the classes in the android.test.base library
// Packages targeted at <= P expect the classes in the android.test.base library
// to be accessible so this maintains backward compatibility by adding the
// android.test.base library to those packages.
if (apkTargetsApiLevelLessThanOrEqualToOMR1(pkg)) {
if (apkTargetsApiLevelLessThanOrEqualToP(pkg)) {
prefixRequiredLibrary(pkg, ANDROID_TEST_BASE);
} else {
// If a package already depends on android.test.runner then add a dependency on

View File

@@ -18,6 +18,7 @@ package android.content.pm;
import static android.content.pm.SharedLibraryNames.ORG_APACHE_HTTP_LEGACY;
import android.content.pm.PackageParser.Package;
import android.os.Build;
import com.android.internal.annotations.VisibleForTesting;
@@ -30,6 +31,11 @@ import com.android.internal.annotations.VisibleForTesting;
@VisibleForTesting
public class OrgApacheHttpLegacyUpdater extends PackageSharedLibraryUpdater {
private static boolean apkTargetsApiLevelLessThanOrEqualToOMR1(Package pkg) {
int targetSdkVersion = pkg.applicationInfo.targetSdkVersion;
return targetSdkVersion < Build.VERSION_CODES.P;
}
@Override
public void updatePackage(Package pkg) {
// Packages targeted at <= O_MR1 expect the classes in the org.apache.http.legacy library

View File

@@ -116,7 +116,7 @@ public class PackageBackwardCompatibility extends PackageSharedLibraryUpdater {
private final PackageSharedLibraryUpdater[] mPackageUpdaters;
public PackageBackwardCompatibility(
private PackageBackwardCompatibility(
boolean bootClassPathContainsATB, PackageSharedLibraryUpdater[] packageUpdaters) {
this.mBootClassPathContainsATB = bootClassPathContainsATB;
this.mPackageUpdaters = packageUpdaters;

View File

@@ -17,7 +17,6 @@ package android.content.pm;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Build;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ArrayUtils;
@@ -60,11 +59,6 @@ public abstract class PackageSharedLibraryUpdater {
|| ArrayUtils.contains(usesOptionalLibraries, apacheHttpLegacy);
}
static boolean apkTargetsApiLevelLessThanOrEqualToOMR1(PackageParser.Package pkg) {
int targetSdkVersion = pkg.applicationInfo.targetSdkVersion;
return targetSdkVersion < Build.VERSION_CODES.P;
}
/**
* Add an implicit dependency.
*

View File

@@ -35,37 +35,37 @@ public class AndroidTestBaseUpdaterTest extends PackageSharedLibraryUpdaterTest
private static final String OTHER_LIBRARY = "other.library";
@Test
public void targeted_at_O() {
public void targeted_at_P() {
PackageBuilder before = builder()
.targetSdkVersion(Build.VERSION_CODES.O);
.targetSdkVersion(Build.VERSION_CODES.P);
// Should add org.apache.http.legacy.
PackageBuilder after = builder()
.targetSdkVersion(Build.VERSION_CODES.O)
.targetSdkVersion(Build.VERSION_CODES.P)
.requiredLibraries(ANDROID_TEST_BASE);
checkBackwardsCompatibility(before, after);
}
@Test
public void targeted_at_O_not_empty_usesLibraries() {
public void targeted_at_P_not_empty_usesLibraries() {
PackageBuilder before = builder()
.targetSdkVersion(Build.VERSION_CODES.O)
.targetSdkVersion(Build.VERSION_CODES.P)
.requiredLibraries(OTHER_LIBRARY);
// The org.apache.http.legacy jar should be added at the start of the list because it
// is not on the bootclasspath and the package targets pre-P.
PackageBuilder after = builder()
.targetSdkVersion(Build.VERSION_CODES.O)
.targetSdkVersion(Build.VERSION_CODES.P)
.requiredLibraries(ANDROID_TEST_BASE, OTHER_LIBRARY);
checkBackwardsCompatibility(before, after);
}
@Test
public void targeted_at_O_in_usesLibraries() {
public void targeted_at_P_in_usesLibraries() {
PackageBuilder before = builder()
.targetSdkVersion(Build.VERSION_CODES.O)
.targetSdkVersion(Build.VERSION_CODES.P)
.requiredLibraries(ANDROID_TEST_BASE);
// No change is required because although org.apache.http.legacy has been removed from
@@ -74,9 +74,9 @@ public class AndroidTestBaseUpdaterTest extends PackageSharedLibraryUpdaterTest
}
@Test
public void targeted_at_O_in_usesOptionalLibraries() {
public void targeted_at_P_in_usesOptionalLibraries() {
PackageBuilder before = builder()
.targetSdkVersion(Build.VERSION_CODES.O)
.targetSdkVersion(Build.VERSION_CODES.P)
.optionalLibraries(ANDROID_TEST_BASE);
// No change is required because although org.apache.http.legacy has been removed from