Loading Android.bp +15 −1 Original line number Diff line number Diff line Loading @@ -643,8 +643,10 @@ java_library { ], }, // See comment on framework-oahl-backward-compatibility module below exclude_srcs: [ // See comment on framework-atb-backward-compatibility module below "core/java/android/content/pm/AndroidTestBaseUpdater.java", // See comment on framework-oahl-backward-compatibility module below "core/java/android/content/pm/OrgApacheHttpLegacyUpdater.java", ], Loading Loading @@ -697,6 +699,18 @@ java_library { ], } // A temporary build target that is conditionally included on the bootclasspath if // android.test.base library has been removed and which provides support for // maintaining backwards compatibility for APKs that target pre-P and depend on // android.test.base classes. This is used iff REMOVE_ATB_FROM_BCP=true is // specified on the build command line. java_library { name: "framework-atb-backward-compatibility", srcs: [ "core/java/android/content/pm/AndroidTestBaseUpdater.java", ], } genrule { name: "framework-statslog-gen", tools: ["stats-log-api-gen"], Loading core/java/android/content/pm/AndroidTestBaseUpdater.java 0 → 100644 +54 −0 Original line number Diff line number Diff line /* * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.content.pm; 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 com.android.internal.annotations.VisibleForTesting; /** * 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 * whether android.test.base is on the bootclasspath or not. In order to include this at * build time, and remove android.test.base from the bootclasspath pass * REMOVE_ATB_FROM_BCP=true on the build command line, otherwise this class will not be included * and the * * @hide */ @VisibleForTesting public class AndroidTestBaseUpdater extends PackageSharedLibraryUpdater { @Override public void updatePackage(Package pkg) { // Packages targeted at <= O_MR1 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)) { prefixRequiredLibrary(pkg, ANDROID_TEST_BASE); } else { // If a package already depends on android.test.runner then add a dependency on // android.test.base because android.test.runner depends on classes from the // android.test.base library. prefixImplicitDependency(pkg, ANDROID_TEST_RUNNER, ANDROID_TEST_BASE); } } } core/java/android/content/pm/PackageBackwardCompatibility.java +38 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.content.pm; import static android.content.pm.SharedLibraryNames.ANDROID_TEST_BASE; import static android.content.pm.SharedLibraryNames.ANDROID_TEST_MOCK; import static android.content.pm.SharedLibraryNames.ANDROID_TEST_RUNNER; import static android.content.pm.SharedLibraryNames.ORG_APACHE_HTTP_LEGACY; Loading Loading @@ -52,12 +53,22 @@ public class PackageBackwardCompatibility extends PackageSharedLibraryUpdater { "android.content.pm.OrgApacheHttpLegacyUpdater", RemoveUnnecessaryOrgApacheHttpLegacyLibrary::new); // Add this before adding AndroidTestBaseUpdater so that android.test.base comes before // android.test.mock. packageUpdaters.add(new AndroidTestRunnerSplitUpdater()); // Attempt to load and add the optional updater that will only be available when // REMOVE_ATB_FROM_BCP=true. If that could not be found then add the default updater that // will remove any references to org.apache.http.library from the package so that it does // not try and load the library when it is on the bootclasspath. boolean bootClassPathContainsATB = !addOptionalUpdater(packageUpdaters, "android.content.pm.AndroidTestBaseUpdater", RemoveUnnecessaryAndroidTestBaseLibrary::new); PackageSharedLibraryUpdater[] updaterArray = packageUpdaters .toArray(new PackageSharedLibraryUpdater[0]); INSTANCE = new PackageBackwardCompatibility( bootClassPathContainsOAHL, updaterArray); bootClassPathContainsOAHL, bootClassPathContainsATB, updaterArray); } /** Loading Loading @@ -105,11 +116,14 @@ public class PackageBackwardCompatibility extends PackageSharedLibraryUpdater { private final boolean mBootClassPathContainsOAHL; private final boolean mBootClassPathContainsATB; private final PackageSharedLibraryUpdater[] mPackageUpdaters; public PackageBackwardCompatibility(boolean bootClassPathContainsOAHL, PackageSharedLibraryUpdater[] packageUpdaters) { boolean bootClassPathContainsATB, PackageSharedLibraryUpdater[] packageUpdaters) { this.mBootClassPathContainsOAHL = bootClassPathContainsOAHL; this.mBootClassPathContainsATB = bootClassPathContainsATB; this.mPackageUpdaters = packageUpdaters; } Loading Loading @@ -139,6 +153,14 @@ public class PackageBackwardCompatibility extends PackageSharedLibraryUpdater { return INSTANCE.mBootClassPathContainsOAHL; } /** * True if the android.test.base is on the bootclasspath, false otherwise. */ @VisibleForTesting public static boolean bootClassPathContainsATB() { return INSTANCE.mBootClassPathContainsATB; } /** * Add android.test.mock dependency for any APK that depends on android.test.runner. * Loading Loading @@ -173,4 +195,18 @@ public class PackageBackwardCompatibility extends PackageSharedLibraryUpdater { } } /** * Remove any usages of android.test.base from the shared library as the library is on the * bootclasspath. */ @VisibleForTesting public static class RemoveUnnecessaryAndroidTestBaseLibrary extends PackageSharedLibraryUpdater { @Override public void updatePackage(Package pkg) { removeLibrary(pkg, ANDROID_TEST_BASE); } } } core/java/android/content/pm/SharedLibraryNames.java +2 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,8 @@ package android.content.pm; */ public class SharedLibraryNames { static final String ANDROID_TEST_BASE = "android.test.base"; static final String ANDROID_TEST_MOCK = "android.test.mock"; static final String ANDROID_TEST_RUNNER = "android.test.runner"; Loading core/tests/coretests/Android.mk +1 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ LOCAL_JAVA_LIBRARIES := \ android.test.base \ android.test.mock \ framework-oahl-backward-compatibility \ framework-atb-backward-compatibility \ LOCAL_PACKAGE_NAME := FrameworksCoreTests LOCAL_COMPATIBILITY_SUITE := device-tests Loading Loading
Android.bp +15 −1 Original line number Diff line number Diff line Loading @@ -643,8 +643,10 @@ java_library { ], }, // See comment on framework-oahl-backward-compatibility module below exclude_srcs: [ // See comment on framework-atb-backward-compatibility module below "core/java/android/content/pm/AndroidTestBaseUpdater.java", // See comment on framework-oahl-backward-compatibility module below "core/java/android/content/pm/OrgApacheHttpLegacyUpdater.java", ], Loading Loading @@ -697,6 +699,18 @@ java_library { ], } // A temporary build target that is conditionally included on the bootclasspath if // android.test.base library has been removed and which provides support for // maintaining backwards compatibility for APKs that target pre-P and depend on // android.test.base classes. This is used iff REMOVE_ATB_FROM_BCP=true is // specified on the build command line. java_library { name: "framework-atb-backward-compatibility", srcs: [ "core/java/android/content/pm/AndroidTestBaseUpdater.java", ], } genrule { name: "framework-statslog-gen", tools: ["stats-log-api-gen"], Loading
core/java/android/content/pm/AndroidTestBaseUpdater.java 0 → 100644 +54 −0 Original line number Diff line number Diff line /* * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.content.pm; 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 com.android.internal.annotations.VisibleForTesting; /** * 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 * whether android.test.base is on the bootclasspath or not. In order to include this at * build time, and remove android.test.base from the bootclasspath pass * REMOVE_ATB_FROM_BCP=true on the build command line, otherwise this class will not be included * and the * * @hide */ @VisibleForTesting public class AndroidTestBaseUpdater extends PackageSharedLibraryUpdater { @Override public void updatePackage(Package pkg) { // Packages targeted at <= O_MR1 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)) { prefixRequiredLibrary(pkg, ANDROID_TEST_BASE); } else { // If a package already depends on android.test.runner then add a dependency on // android.test.base because android.test.runner depends on classes from the // android.test.base library. prefixImplicitDependency(pkg, ANDROID_TEST_RUNNER, ANDROID_TEST_BASE); } } }
core/java/android/content/pm/PackageBackwardCompatibility.java +38 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.content.pm; import static android.content.pm.SharedLibraryNames.ANDROID_TEST_BASE; import static android.content.pm.SharedLibraryNames.ANDROID_TEST_MOCK; import static android.content.pm.SharedLibraryNames.ANDROID_TEST_RUNNER; import static android.content.pm.SharedLibraryNames.ORG_APACHE_HTTP_LEGACY; Loading Loading @@ -52,12 +53,22 @@ public class PackageBackwardCompatibility extends PackageSharedLibraryUpdater { "android.content.pm.OrgApacheHttpLegacyUpdater", RemoveUnnecessaryOrgApacheHttpLegacyLibrary::new); // Add this before adding AndroidTestBaseUpdater so that android.test.base comes before // android.test.mock. packageUpdaters.add(new AndroidTestRunnerSplitUpdater()); // Attempt to load and add the optional updater that will only be available when // REMOVE_ATB_FROM_BCP=true. If that could not be found then add the default updater that // will remove any references to org.apache.http.library from the package so that it does // not try and load the library when it is on the bootclasspath. boolean bootClassPathContainsATB = !addOptionalUpdater(packageUpdaters, "android.content.pm.AndroidTestBaseUpdater", RemoveUnnecessaryAndroidTestBaseLibrary::new); PackageSharedLibraryUpdater[] updaterArray = packageUpdaters .toArray(new PackageSharedLibraryUpdater[0]); INSTANCE = new PackageBackwardCompatibility( bootClassPathContainsOAHL, updaterArray); bootClassPathContainsOAHL, bootClassPathContainsATB, updaterArray); } /** Loading Loading @@ -105,11 +116,14 @@ public class PackageBackwardCompatibility extends PackageSharedLibraryUpdater { private final boolean mBootClassPathContainsOAHL; private final boolean mBootClassPathContainsATB; private final PackageSharedLibraryUpdater[] mPackageUpdaters; public PackageBackwardCompatibility(boolean bootClassPathContainsOAHL, PackageSharedLibraryUpdater[] packageUpdaters) { boolean bootClassPathContainsATB, PackageSharedLibraryUpdater[] packageUpdaters) { this.mBootClassPathContainsOAHL = bootClassPathContainsOAHL; this.mBootClassPathContainsATB = bootClassPathContainsATB; this.mPackageUpdaters = packageUpdaters; } Loading Loading @@ -139,6 +153,14 @@ public class PackageBackwardCompatibility extends PackageSharedLibraryUpdater { return INSTANCE.mBootClassPathContainsOAHL; } /** * True if the android.test.base is on the bootclasspath, false otherwise. */ @VisibleForTesting public static boolean bootClassPathContainsATB() { return INSTANCE.mBootClassPathContainsATB; } /** * Add android.test.mock dependency for any APK that depends on android.test.runner. * Loading Loading @@ -173,4 +195,18 @@ public class PackageBackwardCompatibility extends PackageSharedLibraryUpdater { } } /** * Remove any usages of android.test.base from the shared library as the library is on the * bootclasspath. */ @VisibleForTesting public static class RemoveUnnecessaryAndroidTestBaseLibrary extends PackageSharedLibraryUpdater { @Override public void updatePackage(Package pkg) { removeLibrary(pkg, ANDROID_TEST_BASE); } } }
core/java/android/content/pm/SharedLibraryNames.java +2 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,8 @@ package android.content.pm; */ public class SharedLibraryNames { static final String ANDROID_TEST_BASE = "android.test.base"; static final String ANDROID_TEST_MOCK = "android.test.mock"; static final String ANDROID_TEST_RUNNER = "android.test.runner"; Loading
core/tests/coretests/Android.mk +1 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ LOCAL_JAVA_LIBRARIES := \ android.test.base \ android.test.mock \ framework-oahl-backward-compatibility \ framework-atb-backward-compatibility \ LOCAL_PACKAGE_NAME := FrameworksCoreTests LOCAL_COMPATIBILITY_SUITE := device-tests Loading