summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Martin Stjernholm <mast@google.com> 2022-12-23 21:51:13 +0000
committer Treehugger Robot <treehugger-gerrit@google.com> 2023-01-07 21:11:46 +0000
commit453b9fe909c22eb0f01b3072a5213dd46aed6f45 (patch)
tree4a8ba7821d1a4eaaeeacc9cde7a103fe3a303e47
parentdfbed3af514c47e72fdf9efc556c751dea9487eb (diff)
Undo giving full access to system libs from other system libs.
Directly extending the search path to /system/${LIB} for system APKs may result in system libs being loaded in an app classloader namespace rather than the system namespace. If those libs then depend on other non-public libraries, e.g. in APEXes, that are only accessible through links from the system namespace, then those dependencies will fail to load because the app classloader namespace doesn't have the same links. This CL functionally undoes https://r.android.com/2211602, but only disables tests that break, and adds some tests to exercise the situation above. Also change native libs in the test to use `min_sdk_version` rather than `sdk_version`, because now when they contain code they need an NDK, and one with exactly version 31 is normally not available in the build. (Otoh, the java libraries with `product_specific: true` or `vendor: true` aren't allowed to use `min_sdk_version`.) Test: atest -a libnativeloader_test libnativeloader_lazy_test \ libnativeloader_e2e_tests Bug: 258340826 Bug: 237577392 Change-Id: I95a3fbc6c8021c037fffda1423aa90c62973ec89
-rw-r--r--libnativeloader/library_namespaces.cpp20
-rw-r--r--libnativeloader/test/Android.bp33
-rw-r--r--libnativeloader/test/libsystem_testlib.cc31
-rw-r--r--libnativeloader/test/loadlibrarytest_data_app_manifest.xml2
-rw-r--r--libnativeloader/test/loadlibrarytest_product_app_manifest.xml2
-rw-r--r--libnativeloader/test/loadlibrarytest_system_app_manifest.xml1
-rw-r--r--libnativeloader/test/loadlibrarytest_system_ext_app_manifest.xml1
-rw-r--r--libnativeloader/test/loadlibrarytest_system_priv_app_manifest.xml1
-rw-r--r--libnativeloader/test/loadlibrarytest_vendor_app_manifest.xml2
-rw-r--r--libnativeloader/test/src/android/test/app/DataAppTest.java22
-rw-r--r--libnativeloader/test/src/android/test/app/ProductAppTest.java22
-rw-r--r--libnativeloader/test/src/android/test/app/SystemAppTest.java10
-rw-r--r--libnativeloader/test/src/android/test/app/VendorAppTest.java22
-rw-r--r--libnativeloader/test/src/android/test/hostside/LibnativeloaderTest.java52
14 files changed, 156 insertions, 65 deletions
diff --git a/libnativeloader/library_namespaces.cpp b/libnativeloader/library_namespaces.cpp
index 2a6febdd80..9aeebf38ad 100644
--- a/libnativeloader/library_namespaces.cpp
+++ b/libnativeloader/library_namespaces.cpp
@@ -88,18 +88,15 @@ constexpr const char* kVendorLibPath = "/vendor/" LIB;
// below, because they can't be two separate directories - either one has to be
// a symlink to the other.
constexpr const char* kProductLibPath = "/product/" LIB ":/system/product/" LIB;
-constexpr const char* kSystemLibPath = "/system/" LIB ":/system_ext/" LIB;
const std::regex kVendorDexPathRegex("(^|:)(/system)?/vendor/");
const std::regex kProductDexPathRegex("(^|:)(/system)?/product/");
-const std::regex kSystemDexPathRegex("(^|:)/system(_ext)?/"); // MUST be tested last.
// Define origin partition of APK
using ApkOrigin = enum {
APK_ORIGIN_DEFAULT = 0,
APK_ORIGIN_VENDOR = 1, // Includes both /vendor and /system/vendor
APK_ORIGIN_PRODUCT = 2, // Includes both /product and /system/product
- APK_ORIGIN_SYSTEM = 3, // Includes both /system and /system_ext but not /system/{vendor,product}
};
jobject GetParentClassLoader(JNIEnv* env, jobject class_loader) {
@@ -122,9 +119,6 @@ ApkOrigin GetApkOriginFromDexPath(const std::string& dex_path) {
apk_origin = APK_ORIGIN_PRODUCT;
}
- if (apk_origin == APK_ORIGIN_DEFAULT && std::regex_search(dex_path, kSystemDexPathRegex)) {
- apk_origin = APK_ORIGIN_SYSTEM;
- }
return apk_origin;
}
@@ -246,19 +240,7 @@ Result<NativeLoaderNamespace*> LibraryNamespaces::Create(JNIEnv* env, uint32_t t
const char* apk_origin_msg = "other apk"; // Only for debug logging.
if (!is_shared) {
- if (apk_origin == APK_ORIGIN_SYSTEM) {
- // System apps commonly get access to system libs from the system
- // namespace through shared namespaces (i.e. is_shared is true) and hence
- // don't need this. In practice it's necessary for shared system libraries
- // (i.e. JARs rather than actual APKs) that are loaded by ordinary apps
- // which don't get shared namespaces.
- apk_origin_msg = "system apk";
-
- // Give access to all libraries in the system and system_ext partitions
- // (they can freely access each other's private APIs).
- library_path = library_path + ":" + kSystemLibPath;
- permitted_path = permitted_path + ":" + kSystemLibPath;
- } else if (apk_origin == APK_ORIGIN_VENDOR) {
+ if (apk_origin == APK_ORIGIN_VENDOR) {
unbundled_app_origin = APK_ORIGIN_VENDOR;
apk_origin_msg = "unbundled vendor apk";
diff --git a/libnativeloader/test/Android.bp b/libnativeloader/test/Android.bp
index 839397acd2..95b9b886dd 100644
--- a/libnativeloader/test/Android.bp
+++ b/libnativeloader/test/Android.bp
@@ -23,11 +23,32 @@ package {
default_applicable_licenses: ["art_license"],
}
+// A native library that goes into /system or /system_ext and that depends on
+// a non-public library that is linked from the system namespace.
cc_library {
- name: "libnativeloader_testlib",
- sdk_version: "31",
+ name: "libsystem_testlib",
+ min_sdk_version: "31",
+ stl: "libc++_static",
+ shared_libs: ["liblog"],
+ // It's difficult to add a shared_lib dependency on a non-public library
+ // here, so it dlopens one instead.
+ srcs: ["libsystem_testlib.cc"],
+}
+
+// A native library that goes into /product.
+cc_library {
+ name: "libproduct_testlib",
+ min_sdk_version: "31",
+ stl: "none",
srcs: [],
+}
+
+// A native library that goes into /vendor.
+cc_library {
+ name: "libvendor_testlib",
+ min_sdk_version: "31",
stl: "none",
+ srcs: [],
}
// This app is just an intermediate container to be able to include the .so
@@ -35,10 +56,14 @@ cc_library {
android_test_helper_app {
name: "library_container_app",
defaults: ["art_module_source_build_java_defaults"],
- sdk_version: "31",
+ min_sdk_version: "31",
manifest: "library_container_app_manifest.xml",
compile_multilib: "both",
- jni_libs: ["libnativeloader_testlib"],
+ jni_libs: [
+ "libsystem_testlib",
+ "libproduct_testlib",
+ "libvendor_testlib",
+ ],
}
java_library {
diff --git a/libnativeloader/test/libsystem_testlib.cc b/libnativeloader/test/libsystem_testlib.cc
new file mode 100644
index 0000000000..97d32237b4
--- /dev/null
+++ b/libnativeloader/test/libsystem_testlib.cc
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+
+#include <dlfcn.h>
+
+#include "log/log.h"
+
+static void __attribute__((constructor)) ctor() {
+ // Load a library that should be available to system libraries through a
+ // linked namespace (i.e. is not directly in /system/${LIB}), and that is not
+ // in public.libraries.txt. We use a real one to avoid having to set up an
+ // APEX test fixture and rerun linkerconfig.
+ void* h = dlopen("libandroidicu.so", RTLD_NOW);
+ if (h == nullptr) {
+ LOG_ALWAYS_FATAL("Failed to load dependency: %s", dlerror());
+ }
+ dlclose(h);
+}
diff --git a/libnativeloader/test/loadlibrarytest_data_app_manifest.xml b/libnativeloader/test/loadlibrarytest_data_app_manifest.xml
index f265ef5715..4be78f84f9 100644
--- a/libnativeloader/test/loadlibrarytest_data_app_manifest.xml
+++ b/libnativeloader/test/loadlibrarytest_data_app_manifest.xml
@@ -28,9 +28,11 @@
<uses-native-library android:required="false" android:name="libsystem_extpub.oem2.so" />
<uses-native-library android:required="false" android:name="libsystem_extpub1.oem1.so" />
<uses-native-library android:required="false" android:name="libsystem_extpub2.oem1.so" />
+ <uses-native-library android:required="false" android:name="libsystem_extpub3.oem1.so" />
<uses-native-library android:required="false" android:name="libproduct_extpub.product1.so" />
<uses-native-library android:required="false" android:name="libproduct_extpub1.product1.so" />
<uses-native-library android:required="false" android:name="libproduct_extpub2.product1.so" />
+ <uses-native-library android:required="false" android:name="libproduct_extpub3.product1.so" />
</application>
</manifest>
diff --git a/libnativeloader/test/loadlibrarytest_product_app_manifest.xml b/libnativeloader/test/loadlibrarytest_product_app_manifest.xml
index 4c019a2690..9061c396e1 100644
--- a/libnativeloader/test/loadlibrarytest_product_app_manifest.xml
+++ b/libnativeloader/test/loadlibrarytest_product_app_manifest.xml
@@ -28,9 +28,11 @@
<uses-native-library android:required="false" android:name="libsystem_extpub.oem2.so" />
<uses-native-library android:required="false" android:name="libsystem_extpub1.oem1.so" />
<uses-native-library android:required="false" android:name="libsystem_extpub2.oem1.so" />
+ <uses-native-library android:required="false" android:name="libsystem_extpub3.oem1.so" />
<uses-native-library android:required="false" android:name="libproduct_extpub.product1.so" />
<uses-native-library android:required="false" android:name="libproduct_extpub1.product1.so" />
<uses-native-library android:required="false" android:name="libproduct_extpub2.product1.so" />
+ <uses-native-library android:required="false" android:name="libproduct_extpub3.product1.so" />
</application>
</manifest>
diff --git a/libnativeloader/test/loadlibrarytest_system_app_manifest.xml b/libnativeloader/test/loadlibrarytest_system_app_manifest.xml
index 2a8518bdc4..7ee7532d1c 100644
--- a/libnativeloader/test/loadlibrarytest_system_app_manifest.xml
+++ b/libnativeloader/test/loadlibrarytest_system_app_manifest.xml
@@ -29,6 +29,7 @@
<uses-native-library android:required="false" android:name="libproduct_extpub.product1.so" />
<uses-native-library android:required="false" android:name="libproduct_extpub1.product1.so" />
<uses-native-library android:required="false" android:name="libproduct_extpub2.product1.so" />
+ <uses-native-library android:required="false" android:name="libproduct_extpub3.product1.so" />
</application>
</manifest>
diff --git a/libnativeloader/test/loadlibrarytest_system_ext_app_manifest.xml b/libnativeloader/test/loadlibrarytest_system_ext_app_manifest.xml
index c16372e33a..a2c1a2c8db 100644
--- a/libnativeloader/test/loadlibrarytest_system_ext_app_manifest.xml
+++ b/libnativeloader/test/loadlibrarytest_system_ext_app_manifest.xml
@@ -29,6 +29,7 @@
<uses-native-library android:required="false" android:name="libproduct_extpub.product1.so" />
<uses-native-library android:required="false" android:name="libproduct_extpub1.product1.so" />
<uses-native-library android:required="false" android:name="libproduct_extpub2.product1.so" />
+ <uses-native-library android:required="false" android:name="libproduct_extpub3.product1.so" />
</application>
</manifest>
diff --git a/libnativeloader/test/loadlibrarytest_system_priv_app_manifest.xml b/libnativeloader/test/loadlibrarytest_system_priv_app_manifest.xml
index 11ca8f6182..87a30cec12 100644
--- a/libnativeloader/test/loadlibrarytest_system_priv_app_manifest.xml
+++ b/libnativeloader/test/loadlibrarytest_system_priv_app_manifest.xml
@@ -29,6 +29,7 @@
<uses-native-library android:required="false" android:name="libproduct_extpub.product1.so" />
<uses-native-library android:required="false" android:name="libproduct_extpub1.product1.so" />
<uses-native-library android:required="false" android:name="libproduct_extpub2.product1.so" />
+ <uses-native-library android:required="false" android:name="libproduct_extpub3.product1.so" />
</application>
</manifest>
diff --git a/libnativeloader/test/loadlibrarytest_vendor_app_manifest.xml b/libnativeloader/test/loadlibrarytest_vendor_app_manifest.xml
index 4908d0b0e2..b3434fb930 100644
--- a/libnativeloader/test/loadlibrarytest_vendor_app_manifest.xml
+++ b/libnativeloader/test/loadlibrarytest_vendor_app_manifest.xml
@@ -28,9 +28,11 @@
<uses-native-library android:required="false" android:name="libsystem_extpub.oem2.so" />
<uses-native-library android:required="false" android:name="libsystem_extpub1.oem1.so" />
<uses-native-library android:required="false" android:name="libsystem_extpub2.oem1.so" />
+ <uses-native-library android:required="false" android:name="libsystem_extpub3.oem1.so" />
<uses-native-library android:required="false" android:name="libproduct_extpub.product1.so" />
<uses-native-library android:required="false" android:name="libproduct_extpub1.product1.so" />
<uses-native-library android:required="false" android:name="libproduct_extpub2.product1.so" />
+ <uses-native-library android:required="false" android:name="libproduct_extpub3.product1.so" />
</application>
</manifest>
diff --git a/libnativeloader/test/src/android/test/app/DataAppTest.java b/libnativeloader/test/src/android/test/app/DataAppTest.java
index a8e31bfb41..9403494df6 100644
--- a/libnativeloader/test/src/android/test/app/DataAppTest.java
+++ b/libnativeloader/test/src/android/test/app/DataAppTest.java
@@ -49,17 +49,27 @@ public class DataAppTest {
}
@Test
+ public void testLoadExtendedPublicLibrariesViaSystemSharedLib() {
+ SystemSharedLib.loadLibrary("system_extpub2.oem1");
+ SystemSharedLib.loadLibrary("product_extpub2.product1");
+ }
+
+ @Test
public void testLoadPrivateLibrariesViaSystemSharedLib() {
- SystemSharedLib.loadLibrary("system_private2");
- SystemSharedLib.loadLibrary("systemext_private2");
+ // TODO(b/237577392): Loading a private native system library via a shared system library
+ // ought to work.
+ // SystemSharedLib.loadLibrary("system_private2");
+ // SystemSharedLib.loadLibrary("systemext_private2");
TestUtils.assertLibraryNotFound(() -> SystemSharedLib.loadLibrary("product_private2"));
TestUtils.assertLibraryNotFound(() -> SystemSharedLib.loadLibrary("vendor_private2"));
}
@Test
public void testLoadPrivateLibrariesViaSystemExtSharedLib() {
- SystemExtSharedLib.loadLibrary("system_private3");
- SystemExtSharedLib.loadLibrary("systemext_private3");
+ // TODO(b/237577392): Loading a private native system library via a shared system library
+ // ought to work.
+ // SystemExtSharedLib.loadLibrary("system_private3");
+ // SystemExtSharedLib.loadLibrary("systemext_private3");
TestUtils.assertLibraryNotFound(() -> SystemExtSharedLib.loadLibrary("product_private3"));
TestUtils.assertLibraryNotFound(() -> SystemExtSharedLib.loadLibrary("vendor_private3"));
}
@@ -84,8 +94,8 @@ public class DataAppTest {
@Test
public void testLoadExtendedPublicLibrariesWithAbsolutePaths() {
- System.load(TestUtils.libPath("/system", "system_extpub2.oem1"));
- System.load(TestUtils.libPath("/product", "product_extpub2.product1"));
+ System.load(TestUtils.libPath("/system", "system_extpub3.oem1"));
+ System.load(TestUtils.libPath("/product", "product_extpub3.product1"));
}
@Test
diff --git a/libnativeloader/test/src/android/test/app/ProductAppTest.java b/libnativeloader/test/src/android/test/app/ProductAppTest.java
index d48a46cf92..7ec817b642 100644
--- a/libnativeloader/test/src/android/test/app/ProductAppTest.java
+++ b/libnativeloader/test/src/android/test/app/ProductAppTest.java
@@ -49,17 +49,27 @@ public class ProductAppTest {
}
@Test
+ public void testLoadExtendedPublicLibrariesViaSystemSharedLib() {
+ SystemSharedLib.loadLibrary("system_extpub2.oem1");
+ SystemSharedLib.loadLibrary("product_extpub2.product1");
+ }
+
+ @Test
public void testLoadPrivateLibrariesViaSystemSharedLib() {
- SystemSharedLib.loadLibrary("system_private2");
- SystemSharedLib.loadLibrary("systemext_private2");
+ // TODO(b/237577392): Loading a private native system library via a shared system library
+ // ought to work.
+ // SystemSharedLib.loadLibrary("system_private2");
+ // SystemSharedLib.loadLibrary("systemext_private2");
TestUtils.assertLibraryNotFound(() -> SystemSharedLib.loadLibrary("product_private2"));
TestUtils.assertLibraryNotFound(() -> SystemSharedLib.loadLibrary("vendor_private2"));
}
@Test
public void testLoadPrivateLibrariesViaSystemExtSharedLib() {
- SystemExtSharedLib.loadLibrary("system_private3");
- SystemExtSharedLib.loadLibrary("systemext_private3");
+ // TODO(b/237577392): Loading a private native system library via a shared system library
+ // ought to work.
+ // SystemExtSharedLib.loadLibrary("system_private3");
+ // SystemExtSharedLib.loadLibrary("systemext_private3");
TestUtils.assertLibraryNotFound(() -> SystemExtSharedLib.loadLibrary("product_private3"));
TestUtils.assertLibraryNotFound(() -> SystemExtSharedLib.loadLibrary("vendor_private3"));
}
@@ -84,8 +94,8 @@ public class ProductAppTest {
@Test
public void testLoadExtendedPublicLibrariesWithAbsolutePaths() {
- System.load(TestUtils.libPath("/system", "system_extpub2.oem1"));
- System.load(TestUtils.libPath("/product", "product_extpub2.product1"));
+ System.load(TestUtils.libPath("/system", "system_extpub3.oem1"));
+ System.load(TestUtils.libPath("/product", "product_extpub3.product1"));
}
@Test
diff --git a/libnativeloader/test/src/android/test/app/SystemAppTest.java b/libnativeloader/test/src/android/test/app/SystemAppTest.java
index 9a3e09ce8d..cabdfb7e75 100644
--- a/libnativeloader/test/src/android/test/app/SystemAppTest.java
+++ b/libnativeloader/test/src/android/test/app/SystemAppTest.java
@@ -51,6 +51,12 @@ public class SystemAppTest {
}
@Test
+ public void testLoadExtendedPublicLibrariesViaSystemSharedLib() {
+ SystemSharedLib.loadLibrary("system_extpub2.oem1");
+ SystemSharedLib.loadLibrary("product_extpub2.product1");
+ }
+
+ @Test
public void testLoadPrivateLibrariesViaSystemSharedLib() {
SystemSharedLib.loadLibrary("system_private2");
SystemSharedLib.loadLibrary("systemext_private2");
@@ -84,8 +90,8 @@ public class SystemAppTest {
@Test
public void testLoadExtendedPublicLibrariesWithAbsolutePaths() {
- System.load(TestUtils.libPath("/system", "system_extpub2.oem1"));
- System.load(TestUtils.libPath("/product", "product_extpub2.product1"));
+ System.load(TestUtils.libPath("/system", "system_extpub3.oem1"));
+ System.load(TestUtils.libPath("/product", "product_extpub3.product1"));
}
@Test
diff --git a/libnativeloader/test/src/android/test/app/VendorAppTest.java b/libnativeloader/test/src/android/test/app/VendorAppTest.java
index 380ab218f7..10d0ea04ee 100644
--- a/libnativeloader/test/src/android/test/app/VendorAppTest.java
+++ b/libnativeloader/test/src/android/test/app/VendorAppTest.java
@@ -48,17 +48,27 @@ public class VendorAppTest {
}
@Test
+ public void testLoadExtendedPublicLibrariesViaSystemSharedLib() {
+ SystemSharedLib.loadLibrary("system_extpub2.oem1");
+ SystemSharedLib.loadLibrary("product_extpub2.product1");
+ }
+
+ @Test
public void testLoadPrivateLibrariesViaSystemSharedLib() {
- SystemSharedLib.loadLibrary("system_private2");
- SystemSharedLib.loadLibrary("systemext_private2");
+ // TODO(b/237577392): Loading a private native system library via a shared system library
+ // ought to work.
+ // SystemSharedLib.loadLibrary("system_private2");
+ // SystemSharedLib.loadLibrary("systemext_private2");
TestUtils.assertLibraryNotFound(() -> SystemSharedLib.loadLibrary("product_private2"));
TestUtils.assertLibraryNotFound(() -> SystemSharedLib.loadLibrary("vendor_private2"));
}
@Test
public void testLoadPrivateLibrariesViaSystemExtSharedLib() {
- SystemExtSharedLib.loadLibrary("system_private3");
- SystemExtSharedLib.loadLibrary("systemext_private3");
+ // TODO(b/237577392): Loading a private native system library via a shared system library
+ // ought to work.
+ // SystemExtSharedLib.loadLibrary("system_private3");
+ // SystemExtSharedLib.loadLibrary("systemext_private3");
TestUtils.assertLibraryNotFound(() -> SystemExtSharedLib.loadLibrary("product_private3"));
TestUtils.assertLibraryNotFound(() -> SystemExtSharedLib.loadLibrary("vendor_private3"));
}
@@ -84,8 +94,8 @@ public class VendorAppTest {
@Test
public void testLoadExtendedPublicLibrariesWithAbsolutePaths() {
TestUtils.assertLinkerNamespaceError(
- () -> System.load(TestUtils.libPath("/system", "system_extpub2.oem1")));
- System.load(TestUtils.libPath("/product", "product_extpub2.product1"));
+ () -> System.load(TestUtils.libPath("/system", "system_extpub3.oem1")));
+ System.load(TestUtils.libPath("/product", "product_extpub3.product1"));
}
@Test
diff --git a/libnativeloader/test/src/android/test/hostside/LibnativeloaderTest.java b/libnativeloader/test/src/android/test/hostside/LibnativeloaderTest.java
index 78d8b82340..55a6dd27b3 100644
--- a/libnativeloader/test/src/android/test/hostside/LibnativeloaderTest.java
+++ b/libnativeloader/test/src/android/test/hostside/LibnativeloaderTest.java
@@ -232,9 +232,9 @@ public class LibnativeloaderTest extends BaseHostJUnit4Test {
mLibApk = libApk;
}
- void addLib(String dir, String name) throws Exception {
- pushNativeTestLib(mLibApk, dir + "/" + name);
- mPublicLibs.add(name);
+ void addLib(String libName, String destDir, String destName) throws Exception {
+ pushNativeTestLib(mLibApk, libName, destDir + "/" + destName);
+ mPublicLibs.add(destName);
}
void pushPublicLibrariesFile(String path) throws DeviceNotAvailableException {
@@ -244,30 +244,34 @@ public class LibnativeloaderTest extends BaseHostJUnit4Test {
void pushExtendedPublicSystemOemLibs(ZipFile libApk) throws Exception {
var oem1Libs = new PublicLibs(libApk);
- // Push libextpub<n>.oem1.so for each test. Since we cannot unload them, we need a fresh
- // never-before-loaded library in each loadLibrary call.
- for (int i = 1; i <= 2; ++i) {
- oem1Libs.addLib("/system/${LIB}", "libsystem_extpub" + i + ".oem1.so");
+ // Push libsystem_extpub<n>.oem1.so for each test. Since we cannot unload them, we need
+ // a fresh never-before-loaded library in each loadLibrary call.
+ for (int i = 1; i <= 3; ++i) {
+ oem1Libs.addLib("libsystem_testlib.so", "/system/${LIB}",
+ "libsystem_extpub" + i + ".oem1.so");
}
- oem1Libs.addLib("/system/${LIB}", "libsystem_extpub.oem1.so");
+ oem1Libs.addLib("libsystem_testlib.so", "/system/${LIB}", "libsystem_extpub.oem1.so");
oem1Libs.pushPublicLibrariesFile("/system/etc/public.libraries-oem1.txt");
var oem2Libs = new PublicLibs(libApk);
- oem2Libs.addLib("/system/${LIB}", "libsystem_extpub.oem2.so");
+ oem2Libs.addLib("libsystem_testlib.so", "/system/${LIB}", "libsystem_extpub.oem2.so");
// libextpub_nouses.oem2.so is a library that the test apps don't have
// <uses-native-library> dependencies for.
- oem2Libs.addLib("/system/${LIB}", "libsystem_extpub_nouses.oem2.so");
+ oem2Libs.addLib(
+ "libsystem_testlib.so", "/system/${LIB}", "libsystem_extpub_nouses.oem2.so");
oem2Libs.pushPublicLibrariesFile("/system/etc/public.libraries-oem2.txt");
}
void pushExtendedPublicProductLibs(ZipFile libApk) throws Exception {
var product1Libs = new PublicLibs(libApk);
- // Push libfoo<n>.product1.so for each test. Since we cannot unload them, we need a
- // fresh never-before-loaded library in each loadLibrary call.
- for (int i = 1; i <= 2; ++i) {
- product1Libs.addLib("/product/${LIB}", "libproduct_extpub" + i + ".product1.so");
+ // Push libproduct_extpub<n>.product1.so for each test. Since we cannot unload them, we
+ // need a fresh never-before-loaded library in each loadLibrary call.
+ for (int i = 1; i <= 3; ++i) {
+ product1Libs.addLib("libproduct_testlib.so", "/product/${LIB}",
+ "libproduct_extpub" + i + ".product1.so");
}
- product1Libs.addLib("/product/${LIB}", "libproduct_extpub.product1.so");
+ product1Libs.addLib(
+ "libproduct_testlib.so", "/product/${LIB}", "libproduct_extpub.product1.so");
product1Libs.pushPublicLibrariesFile("/product/etc/public.libraries-product1.txt");
}
@@ -275,10 +279,14 @@ public class LibnativeloaderTest extends BaseHostJUnit4Test {
// Push the libraries once for each test. Since we cannot unload them, we need a fresh
// never-before-loaded library in each loadLibrary call.
for (int i = 1; i <= 6; ++i) {
- pushNativeTestLib(libApk, "/system/${LIB}/libsystem_private" + i + ".so");
- pushNativeTestLib(libApk, "/system_ext/${LIB}/libsystemext_private" + i + ".so");
- pushNativeTestLib(libApk, "/product/${LIB}/libproduct_private" + i + ".so");
- pushNativeTestLib(libApk, "/vendor/${LIB}/libvendor_private" + i + ".so");
+ pushNativeTestLib(libApk, "libsystem_testlib.so",
+ "/system/${LIB}/libsystem_private" + i + ".so");
+ pushNativeTestLib(libApk, "libsystem_testlib.so",
+ "/system_ext/${LIB}/libsystemext_private" + i + ".so");
+ pushNativeTestLib(libApk, "libproduct_testlib.so",
+ "/product/${LIB}/libproduct_private" + i + ".so");
+ pushNativeTestLib(libApk, "libvendor_testlib.so",
+ "/vendor/${LIB}/libvendor_private" + i + ".so");
}
}
@@ -337,8 +345,8 @@ public class LibnativeloaderTest extends BaseHostJUnit4Test {
// Like pushString, but extracts libnativeloader_testlib.so from the library_container_app
// APK and pushes it to destPath. "${LIB}" is replaced with "lib" or "lib64" as appropriate.
- void pushNativeTestLib(ZipFile libApk, String destPath) throws Exception {
- String libApkPath = "lib/" + getTestArch() + "/libnativeloader_testlib.so";
+ void pushNativeTestLib(ZipFile libApk, String libName, String destPath) throws Exception {
+ String libApkPath = "lib/" + getTestArch() + "/" + libName;
ZipEntry entry = libApk.getEntry(libApkPath);
assertWithMessage("Failed to find " + libApkPath + " in library_container_app.apk")
.that(entry)
@@ -346,7 +354,7 @@ public class LibnativeloaderTest extends BaseHostJUnit4Test {
File libraryTempFile;
try (InputStream inStream = libApk.getInputStream(entry)) {
- libraryTempFile = writeStreamToTempFile("libnativeloader_testlib.so", inStream);
+ libraryTempFile = writeStreamToTempFile(libName, inStream);
}
destPath = destPath.replace("${LIB}", libDirName());