Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 869f5c42 authored by Paul Duffin's avatar Paul Duffin Committed by android-build-merger
Browse files

Merge "Update backwards compatibility support for android.test.base" am: 617e5564 am: f4dfe505

am: 70828b49

Change-Id: Ic8b18c2e4fc86717e0fe5c3090c5e7cbaf9b05d6
parents 48d53521 70828b49
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -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
+6 −0
Original line number Diff line number Diff line
@@ -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
+1 −1
Original line number Diff line number Diff line
@@ -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;
+0 −6
Original line number Diff line number Diff line
@@ -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.
     *
+10 −10
Original line number Diff line number Diff line
@@ -37,37 +37,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
@@ -76,9 +76,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