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

Commit 845f8486 authored by Tobias Thierer's avatar Tobias Thierer
Browse files

Reintroduce android.test.base for Android R apps targeting Android Q.

The change http://r.android.com/909093 to remove android.test.base
is currently only included for Android R builds. This means that
apps running on Android Q get android.test.base regardless of their
targetSdkVersion (including Q).

It is inconsistent to remove it for those same apps when running
on Android R. Therefore, this CL changes the conditional removal
code only remove android.test.base for apps targeting an SDK
version > Q.

Test: atest FrameworksCoreTests:android.content.pm.AndroidTestBaseUpdaterTest
Test: Manually checked that I was able to reproduce the issue before
      this CL but not afterwards
Fixes: 133396946

Change-Id: I2861035c51cbc1d843a3371828f7902bea83c7cc
parent 5d6e635c
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ 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 <= Q 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
@@ -38,17 +38,17 @@ import com.android.internal.annotations.VisibleForTesting;
@VisibleForTesting
public class AndroidTestBaseUpdater extends PackageSharedLibraryUpdater {

    private static boolean apkTargetsApiLevelLessThanOrEqualToP(Package pkg) {
    private static boolean apkTargetsApiLevelLessThanOrEqualToQ(Package pkg) {
        int targetSdkVersion = pkg.applicationInfo.targetSdkVersion;
        return targetSdkVersion <= Build.VERSION_CODES.P;
        return targetSdkVersion <= Build.VERSION_CODES.Q;
    }

    @Override
    public void updatePackage(Package pkg) {
        // Packages targeted at <= P expect the classes in the android.test.base library
        // Packages targeted at <= Q 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 (apkTargetsApiLevelLessThanOrEqualToP(pkg)) {
        if (apkTargetsApiLevelLessThanOrEqualToQ(pkg)) {
            prefixRequiredLibrary(pkg, ANDROID_TEST_BASE);
        } else {
            // If a package already depends on android.test.runner then add a dependency on
+11 −11
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_P() {
    public void targeted_at_Q() {
        PackageBuilder before = builder()
                .targetSdkVersion(Build.VERSION_CODES.P);
                .targetSdkVersion(Build.VERSION_CODES.Q);

        // Should add org.apache.http.legacy.
        PackageBuilder after = builder()
                .targetSdkVersion(Build.VERSION_CODES.P)
                .targetSdkVersion(Build.VERSION_CODES.Q)
                .requiredLibraries(ANDROID_TEST_BASE);

        checkBackwardsCompatibility(before, after);
    }

    @Test
    public void targeted_at_P_not_empty_usesLibraries() {
    public void targeted_at_Q_not_empty_usesLibraries() {
        PackageBuilder before = builder()
                .targetSdkVersion(Build.VERSION_CODES.P)
                .targetSdkVersion(Build.VERSION_CODES.Q)
                .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.
        // is not on the bootclasspath and the package targets pre-Q.
        PackageBuilder after = builder()
                .targetSdkVersion(Build.VERSION_CODES.P)
                .targetSdkVersion(Build.VERSION_CODES.Q)
                .requiredLibraries(ANDROID_TEST_BASE, OTHER_LIBRARY);

        checkBackwardsCompatibility(before, after);
    }

    @Test
    public void targeted_at_P_in_usesLibraries() {
    public void targeted_at_Q_in_usesLibraries() {
        PackageBuilder before = builder()
                .targetSdkVersion(Build.VERSION_CODES.P)
                .targetSdkVersion(Build.VERSION_CODES.Q)
                .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_P_in_usesOptionalLibraries() {
    public void targeted_at_Q_in_usesOptionalLibraries() {
        PackageBuilder before = builder()
                .targetSdkVersion(Build.VERSION_CODES.P)
                .targetSdkVersion(Build.VERSION_CODES.Q)
                .optionalLibraries(ANDROID_TEST_BASE);

        // No change is required because although org.apache.http.legacy has been removed from