summaryrefslogtreecommitdiff
path: root/ravenwood/runtime-common-src
diff options
context:
space:
mode:
author John Wu <topjohnwu@google.com> 2024-09-26 22:59:40 +0000
committer John Wu <topjohnwu@google.com> 2024-09-26 22:59:40 +0000
commit983461633b96db0bc58205a657edeffad3ce4080 (patch)
tree8df76979756f92a675ea35ac852917a2369d152f /ravenwood/runtime-common-src
parent6f7665370b368b3f4164cdce501ae224b3351c9b (diff)
Cherry-pick Ravenwood "core" code
- Copied f/b/r and f/b/t/h - Ported files under f/b/core, only what needed to for run-ravenwood-tests.sh to pass - Local changes because of missing resoucres support - Added @DisabledOnRavenwood(reason="AOSP is missing resources support") to tests under f/b/r that depends on resources bivalentinst and servicestest - Added try-catch around ResourcesManager.setInstance() Flag: EXEMPT host test change only Bug: 292141694 Test: $ANDROID_BUILD_TOP/frameworks/base/ravenwood/scripts/run-ravenwood-tests.sh Merged-in: I8a9b8374be3ae052ba4f152eb43af20d0871597f Change-Id: Iefd574dbded8c4ab2e244c4918c26641364a3432
Diffstat (limited to 'ravenwood/runtime-common-src')
-rw-r--r--ravenwood/runtime-common-src/com/android/ravenwood/common/JvmWorkaround.java15
-rw-r--r--ravenwood/runtime-common-src/com/android/ravenwood/common/OpenJdkWorkaround.java32
-rw-r--r--ravenwood/runtime-common-src/com/android/ravenwood/common/RavenwoodCommonUtils.java74
3 files changed, 118 insertions, 3 deletions
diff --git a/ravenwood/runtime-common-src/com/android/ravenwood/common/JvmWorkaround.java b/ravenwood/runtime-common-src/com/android/ravenwood/common/JvmWorkaround.java
index 0238baa2dcbf..02153a757cd8 100644
--- a/ravenwood/runtime-common-src/com/android/ravenwood/common/JvmWorkaround.java
+++ b/ravenwood/runtime-common-src/com/android/ravenwood/common/JvmWorkaround.java
@@ -38,7 +38,6 @@ public abstract class JvmWorkaround {
*/
public abstract void setFdInt(FileDescriptor fd, int fdInt);
-
/**
* Equivalent to Android's FileDescriptor.getInt$().
*/
@@ -49,6 +48,10 @@ public abstract class JvmWorkaround {
*/
public abstract void closeFd(FileDescriptor fd) throws IOException;
+ public abstract long addressOf(Object o);
+
+ public abstract <T> T fromAddress(long address);
+
/**
* Placeholder implementation for the host side.
*
@@ -75,5 +78,15 @@ public abstract class JvmWorkaround {
public void closeFd(FileDescriptor fd) {
throw calledOnHostside();
}
+
+ @Override
+ public long addressOf(Object o) {
+ throw calledOnHostside();
+ }
+
+ @Override
+ public <T> T fromAddress(long address) {
+ throw calledOnHostside();
+ }
}
}
diff --git a/ravenwood/runtime-common-src/com/android/ravenwood/common/OpenJdkWorkaround.java b/ravenwood/runtime-common-src/com/android/ravenwood/common/OpenJdkWorkaround.java
index a260147654cd..2323c65de5cf 100644
--- a/ravenwood/runtime-common-src/com/android/ravenwood/common/OpenJdkWorkaround.java
+++ b/ravenwood/runtime-common-src/com/android/ravenwood/common/OpenJdkWorkaround.java
@@ -18,8 +18,16 @@ package com.android.ravenwood.common;
import java.io.FileDescriptor;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
+import java.util.Map;
+import java.util.WeakHashMap;
class OpenJdkWorkaround extends JvmWorkaround {
+
+ // @GuardedBy("sAddressMap")
+ private static final Map<Object, Long> sAddressMap = new WeakHashMap<>();
+ // @GuardedBy("sAddressMap")
+ private static long sCurrentAddress = 1;
+
@Override
public void setFdInt(FileDescriptor fd, int fdInt) {
try {
@@ -60,4 +68,28 @@ class OpenJdkWorkaround extends JvmWorkaround {
+ " perhaps JRE has changed?", e);
}
}
+
+ @Override
+ public long addressOf(Object o) {
+ synchronized (sAddressMap) {
+ Long address = sAddressMap.get(o);
+ if (address == null) {
+ address = sCurrentAddress++;
+ sAddressMap.put(o, address);
+ }
+ return address;
+ }
+ }
+
+ @Override
+ public <T> T fromAddress(long address) {
+ synchronized (sAddressMap) {
+ for (var e : sAddressMap.entrySet()) {
+ if (e.getValue() == address) {
+ return (T) e.getKey();
+ }
+ }
+ }
+ return null;
+ }
}
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 c8cc8d9fe273..989bb6be1782 100644
--- a/ravenwood/runtime-common-src/com/android/ravenwood/common/RavenwoodCommonUtils.java
+++ b/ravenwood/runtime-common-src/com/android/ravenwood/common/RavenwoodCommonUtils.java
@@ -15,12 +15,20 @@
*/
package com.android.ravenwood.common;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+
import com.android.ravenwood.common.divergence.RavenwoodDivergence;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import java.util.Arrays;
public class RavenwoodCommonUtils {
@@ -31,6 +39,14 @@ public class RavenwoodCommonUtils {
private static final Object sLock = new Object();
+ /**
+ * If set to "1", we enable the verbose logging.
+ *
+ * (See also InitLogging() in http://ac/system/libbase/logging.cpp)
+ */
+ 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";
@@ -42,10 +58,19 @@ public class RavenwoodCommonUtils {
private static final boolean IS_ON_RAVENWOOD = RavenwoodDivergence.isOnRavenwood();
- private static final String RAVEWOOD_RUNTIME_PATH = getRavenwoodRuntimePathInternal();
+ private static final String RAVENWOOD_RUNTIME_PATH = getRavenwoodRuntimePathInternal();
public static final String RAVENWOOD_SYSPROP = "ro.is_on_ravenwood";
+ public static final String RAVENWOOD_RESOURCE_APK = "ravenwood-res-apks/ravenwood-res.apk";
+ public static final String RAVENWOOD_INST_RESOURCE_APK =
+ "ravenwood-res-apks/ravenwood-inst-res.apk";
+
+ public static final String RAVENWOOD_EMPTY_RESOURCES_APK =
+ RAVENWOOD_RUNTIME_PATH + "ravenwood-data/ravenwood-empty-res.apk";
+
+ public static final String RAVENWOOD_VERSION_JAVA_SYSPROP = "android.ravenwood.version";
+
// @GuardedBy("sLock")
private static boolean sIntegrityChecked = false;
@@ -72,6 +97,18 @@ public class RavenwoodCommonUtils {
return sEnableExtraRuntimeCheck;
}
+ /** Simple logging method. */
+ public static void log(String tag, String message) {
+ // Avoid using Android's Log class, which could be broken for various reasons.
+ // (e.g. the JNI file doesn't exist for whatever reason)
+ System.out.print(tag + ": " + message + "\n");
+ }
+
+ /** Simple logging method. */
+ private void log(String tag, String format, Object... args) {
+ log(tag, String.format(format, args));
+ }
+
/**
* Load the main runtime JNI library.
*/
@@ -176,7 +213,7 @@ public class RavenwoodCommonUtils {
*/
public static String getRavenwoodRuntimePath() {
ensureOnRavenwood();
- return RAVEWOOD_RUNTIME_PATH;
+ return RAVENWOOD_RUNTIME_PATH;
}
private static String getRavenwoodRuntimePathInternal() {
@@ -231,4 +268,37 @@ public class RavenwoodCommonUtils {
var is = new FileInputStream(fd);
RavenwoodCommonUtils.closeQuietly(is);
}
+
+ public static void ensureIsPublicVoidMethod(Method method, boolean isStatic) {
+ var ok = Modifier.isPublic(method.getModifiers())
+ && (Modifier.isStatic(method.getModifiers()) == isStatic)
+ && (method.getReturnType() == void.class);
+ if (ok) {
+ return; // okay
+ }
+ throw new AssertionError(String.format(
+ "Method %s.%s() expected to be public %svoid",
+ method.getDeclaringClass().getName(), method.getName(),
+ (isStatic ? "static " : "")));
+ }
+
+ public static void ensureIsPublicMember(Member member, boolean isStatic) {
+ var ok = Modifier.isPublic(member.getModifiers())
+ && (Modifier.isStatic(member.getModifiers()) == isStatic);
+ if (ok) {
+ return; // okay
+ }
+ throw new AssertionError(String.format(
+ "%s.%s expected to be public %s",
+ member.getDeclaringClass().getName(), member.getName(),
+ (isStatic ? "static" : "")));
+ }
+
+ @NonNull
+ public static String getStackTraceString(@Nullable Throwable th) {
+ StringWriter stringWriter = new StringWriter();
+ PrintWriter writer = new PrintWriter(stringWriter);
+ th.printStackTrace(writer);
+ return stringWriter.toString();
+ }
}