diff options
author | 2024-09-25 00:43:28 +0000 | |
---|---|---|
committer | 2024-09-26 22:59:51 +0000 | |
commit | 5e13e25d51685f4cf1ae4c9188ae19577538c6f7 (patch) | |
tree | bc8bf33dad91ab85b2dbe311a1dedea7542ac4f6 /ravenwood/runtime-common-src | |
parent | 983461633b96db0bc58205a657edeffad3ce4080 (diff) |
[Ravenwood] Use native system property implementation
System properties are not only used by Java code, but also native code.
To make the property values consistent across Java and native code, make
the "source of truth" of property values on the native side.
In order to achieve this, we have to introduce a new native library
"libravenwood_sysprops" that does NOT link against libbase, and load
that library first. By doing so, we can override the low-level sysprop
function symbols with our own implementation.
Once that is done, all existing native code accessing system properties,
regardless whether they use the libbase/libcutils wrappers or the raw
sysprop functions will go through Ravenwood's implementation.
Other than improving system properties, this provides the infrastructure
to override/implement C functions that is used in native code.
Bug: 292141694
Flag: EXEMPT host test change only
Test: $ANDROID_BUILD_TOP/frameworks/base/ravenwood/scripts/run-ravenwood-tests.sh
Merged-in: I14678e2ac52ace0b23bd53df7b6092a1cbb881b3
Change-Id: I14678e2ac52ace0b23bd53df7b6092a1cbb881b3
Diffstat (limited to 'ravenwood/runtime-common-src')
-rw-r--r-- | ravenwood/runtime-common-src/com/android/ravenwood/common/RavenwoodCommonUtils.java | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/ravenwood/runtime-common-src/com/android/ravenwood/common/RavenwoodCommonUtils.java b/ravenwood/runtime-common-src/com/android/ravenwood/common/RavenwoodCommonUtils.java index 989bb6be1782..ef795c63880e 100644 --- a/ravenwood/runtime-common-src/com/android/ravenwood/common/RavenwoodCommonUtils.java +++ b/ravenwood/runtime-common-src/com/android/ravenwood/common/RavenwoodCommonUtils.java @@ -47,9 +47,6 @@ public class RavenwoodCommonUtils { public static final boolean RAVENWOOD_VERBOSE_LOGGING = "1".equals(System.getenv( "RAVENWOOD_VERBOSE")); - /** Name of `libravenwood_runtime` */ - private static final String RAVENWOOD_NATIVE_RUNTIME_NAME = "ravenwood_runtime"; - /** Directory name of `out/host/linux-x86/testcases/ravenwood-runtime` */ private static final String RAVENWOOD_RUNTIME_DIR_NAME = "ravenwood-runtime"; @@ -110,29 +107,21 @@ public class RavenwoodCommonUtils { } /** - * Load the main runtime JNI library. - */ - public static void loadRavenwoodNativeRuntime() { - ensureOnRavenwood(); - loadJniLibrary(RAVENWOOD_NATIVE_RUNTIME_NAME); - } - - /** * Internal implementation of * {@link android.platform.test.ravenwood.RavenwoodUtils#loadJniLibrary(String)} */ public static void loadJniLibrary(String libname) { if (RavenwoodCommonUtils.isOnRavenwood()) { - loadJniLibraryInternal(libname); + System.load(getJniLibraryPath(libname)); } else { System.loadLibrary(libname); } } /** - * Function equivalent to ART's System.loadLibrary. See RavenwoodUtils for why we need it. + * Find the shared library path from java.library.path. */ - private static void loadJniLibraryInternal(String libname) { + public static String getJniLibraryPath(String libname) { var path = System.getProperty("java.library.path"); var filename = "lib" + libname + ".so"; @@ -140,22 +129,21 @@ public class RavenwoodCommonUtils { try { if (path == null) { - throw new UnsatisfiedLinkError("Cannot load library " + libname + "." + throw new UnsatisfiedLinkError("Cannot find library " + libname + "." + " Property java.library.path not set!"); } for (var dir : path.split(":")) { var file = new File(dir + "/" + filename); if (file.exists()) { - System.load(file.getAbsolutePath()); - return; + return file.getAbsolutePath(); } } - throw new UnsatisfiedLinkError("Library " + libname + " not found in " - + "java.library.path: " + path); } catch (Throwable e) { dumpFiles(System.out); throw e; } + throw new UnsatisfiedLinkError("Library " + libname + " not found in " + + "java.library.path: " + path); } private static void dumpFiles(PrintStream out) { |