summaryrefslogtreecommitdiff
path: root/ravenwood/junit-impl-src
diff options
context:
space:
mode:
author John Wu <topjohnwu@google.com> 2024-09-25 00:43:28 +0000
committer John Wu <topjohnwu@google.com> 2024-09-26 22:59:51 +0000
commit5e13e25d51685f4cf1ae4c9188ae19577538c6f7 (patch)
treebc8bf33dad91ab85b2dbe311a1dedea7542ac4f6 /ravenwood/junit-impl-src
parent983461633b96db0bc58205a657edeffad3ce4080 (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/junit-impl-src')
-rw-r--r--ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodNativeLoader.java1
-rw-r--r--ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java34
2 files changed, 29 insertions, 6 deletions
diff --git a/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodNativeLoader.java b/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodNativeLoader.java
index e5486117e7f2..d29b93c0c171 100644
--- a/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodNativeLoader.java
+++ b/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodNativeLoader.java
@@ -43,6 +43,7 @@ public final class RavenwoodNativeLoader {
android.util.Log.class,
android.os.Parcel.class,
android.os.Binder.class,
+ android.os.SystemProperties.class,
android.content.res.ApkAssets.class,
android.content.res.AssetManager.class,
android.content.res.StringBlock.class,
diff --git a/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java b/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java
index 40b14dbe6bfd..805b0c161cb3 100644
--- a/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java
+++ b/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java
@@ -31,6 +31,7 @@ import android.os.Bundle;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.ServiceManager;
+import android.os.SystemProperties;
import android.system.ErrnoException;
import android.system.Os;
import android.util.Log;
@@ -38,6 +39,7 @@ import android.util.Log;
import androidx.test.platform.app.InstrumentationRegistry;
import com.android.internal.os.RuntimeInit;
+import com.android.ravenwood.RavenwoodRuntimeNative;
import com.android.ravenwood.common.RavenwoodCommonUtils;
import com.android.ravenwood.common.RavenwoodRuntimeException;
import com.android.ravenwood.common.SneakyThrow;
@@ -68,6 +70,8 @@ public class RavenwoodRuntimeEnvironmentController {
}
private static final String MAIN_THREAD_NAME = "RavenwoodMain";
+ private static final String RAVENWOOD_NATIVE_SYSPROP_NAME = "ravenwood_sysprop";
+ private static final String RAVENWOOD_NATIVE_RUNTIME_NAME = "ravenwood_runtime";
/**
* When enabled, attempt to dump all thread stacks just before we hit the
@@ -118,6 +122,7 @@ public class RavenwoodRuntimeEnvironmentController {
}
private static RavenwoodConfig sConfig;
+ private static RavenwoodSystemProperties sProps;
private static boolean sInitialized = false;
/**
@@ -132,6 +137,14 @@ public class RavenwoodRuntimeEnvironmentController {
// We haven't initialized liblog yet, so directly write to System.out here.
RavenwoodCommonUtils.log(TAG, "globalInit()");
+ // Load libravenwood_sysprop first
+ var libProp = RavenwoodCommonUtils.getJniLibraryPath(RAVENWOOD_NATIVE_SYSPROP_NAME);
+ System.load(libProp);
+ RavenwoodRuntimeNative.reloadNativeLibrary(libProp);
+
+ // Make sure libravenwood_runtime is loaded.
+ System.load(RavenwoodCommonUtils.getJniLibraryPath(RAVENWOOD_NATIVE_RUNTIME_NAME));
+
// Do the basic set up for the android sysprops.
setSystemProperties(RavenwoodSystemProperties.DEFAULT_VALUES);
@@ -359,12 +372,21 @@ public class RavenwoodRuntimeEnvironmentController {
/**
* Set the current configuration to the actual SystemProperties.
*/
- public static void setSystemProperties(RavenwoodSystemProperties ravenwoodSystemProperties) {
- var clone = new RavenwoodSystemProperties(ravenwoodSystemProperties, true);
+ private static void setSystemProperties(RavenwoodSystemProperties systemProperties) {
+ SystemProperties.clearChangeCallbacksForTest();
+ RavenwoodRuntimeNative.clearSystemProperties();
+ sProps = new RavenwoodSystemProperties(systemProperties, true);
+ for (var entry : systemProperties.getValues().entrySet()) {
+ RavenwoodRuntimeNative.setSystemProperty(entry.getKey(), entry.getValue());
+ }
+ }
- android.os.SystemProperties.init$ravenwood(
- clone.getValues(),
- clone.getKeyReadablePredicate(),
- clone.getKeyWritablePredicate());
+ @SuppressWarnings("unused") // Called from native code (ravenwood_sysprop.cpp)
+ private static void checkSystemPropertyAccess(String key, boolean write) {
+ boolean result = write ? sProps.isKeyWritable(key) : sProps.isKeyReadable(key);
+ if (!result) {
+ throw new IllegalArgumentException((write ? "Write" : "Read")
+ + " access to system property '" + key + "' denied via RavenwoodConfig");
+ }
}
}