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

This commit is contained in:
Paul Duffin
2019-02-21 13:22:15 +00:00
committed by Gerrit Code Review
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 static android.content.pm.SharedLibraryNames.ANDROID_TEST_RUNNER;
import android.content.pm.PackageParser.Package; import android.content.pm.PackageParser.Package;
import android.os.Build;
import com.android.internal.annotations.VisibleForTesting; 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. * included by default.
* *
* <p>This is separated out so that it can be conditionally included at build time depending on * <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 @VisibleForTesting
public class AndroidTestBaseUpdater extends PackageSharedLibraryUpdater { public class AndroidTestBaseUpdater extends PackageSharedLibraryUpdater {
private static boolean apkTargetsApiLevelLessThanOrEqualToP(Package pkg) {
int targetSdkVersion = pkg.applicationInfo.targetSdkVersion;
return targetSdkVersion <= Build.VERSION_CODES.P;
}
@Override @Override
public void updatePackage(Package pkg) { 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 // to be accessible so this maintains backward compatibility by adding the
// android.test.base library to those packages. // android.test.base library to those packages.
if (apkTargetsApiLevelLessThanOrEqualToOMR1(pkg)) { if (apkTargetsApiLevelLessThanOrEqualToP(pkg)) {
prefixRequiredLibrary(pkg, ANDROID_TEST_BASE); prefixRequiredLibrary(pkg, ANDROID_TEST_BASE);
} else { } else {
// If a package already depends on android.test.runner then add a dependency on // 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 static android.content.pm.SharedLibraryNames.ORG_APACHE_HTTP_LEGACY;
import android.content.pm.PackageParser.Package; import android.content.pm.PackageParser.Package;
import android.os.Build;
import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting;
@@ -30,6 +31,11 @@ import com.android.internal.annotations.VisibleForTesting;
@VisibleForTesting @VisibleForTesting
public class OrgApacheHttpLegacyUpdater extends PackageSharedLibraryUpdater { public class OrgApacheHttpLegacyUpdater extends PackageSharedLibraryUpdater {
private static boolean apkTargetsApiLevelLessThanOrEqualToOMR1(Package pkg) {
int targetSdkVersion = pkg.applicationInfo.targetSdkVersion;
return targetSdkVersion < Build.VERSION_CODES.P;
}
@Override @Override
public void updatePackage(Package pkg) { public void updatePackage(Package pkg) {
// Packages targeted at <= O_MR1 expect the classes in the org.apache.http.legacy library // 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; private final PackageSharedLibraryUpdater[] mPackageUpdaters;
public PackageBackwardCompatibility( private PackageBackwardCompatibility(
boolean bootClassPathContainsATB, PackageSharedLibraryUpdater[] packageUpdaters) { boolean bootClassPathContainsATB, PackageSharedLibraryUpdater[] packageUpdaters) {
this.mBootClassPathContainsATB = bootClassPathContainsATB; this.mBootClassPathContainsATB = bootClassPathContainsATB;
this.mPackageUpdaters = packageUpdaters; this.mPackageUpdaters = packageUpdaters;

View File

@@ -17,7 +17,6 @@ package android.content.pm;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.os.Build;
import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ArrayUtils; import com.android.internal.util.ArrayUtils;
@@ -60,11 +59,6 @@ public abstract class PackageSharedLibraryUpdater {
|| ArrayUtils.contains(usesOptionalLibraries, apacheHttpLegacy); || 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. * Add an implicit dependency.
* *

View File

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