diff options
author | 2024-11-01 17:32:42 +0000 | |
---|---|---|
committer | 2024-11-01 21:17:30 +0000 | |
commit | 41adec2334d6610ba1127cad335a3f29791e4920 (patch) | |
tree | 00da533ccc641912624bc96796f7221f81840fbf /ravenwood/runtime-helper-src | |
parent | 0a6265b30157dea118ca0145535ac0ee3145ba09 (diff) |
[Ravenwood] Cleanup and update RavenwoodEnvironment
- Move the UID/PID/targetSdk injection into RavenwoodRuntimeState
- Update VMRuntime to return the configured target SDK level
- Remove the Workaround class in RavenwoodEnvironment
- Implement Os.gettid to make Process.myTid return a real value
Flag: EXEMPT host test change only
Bug: 292141694
Test: $ANDROID_BUILD_TOP/frameworks/base/ravenwood/scripts/run-ravenwood-tests.sh
Change-Id: I611a6cde7c7fb53f71a7a25e93143f4884af734b
Diffstat (limited to 'ravenwood/runtime-helper-src')
6 files changed, 125 insertions, 8 deletions
diff --git a/ravenwood/runtime-helper-src/framework/android/os/Process_ravenwood.java b/ravenwood/runtime-helper-src/framework/android/os/Process_ravenwood.java new file mode 100644 index 000000000000..3c6a4d78d1d9 --- /dev/null +++ b/ravenwood/runtime-helper-src/framework/android/os/Process_ravenwood.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2024 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.os; + +import android.util.Pair; + +public class Process_ravenwood { + + private static volatile ThreadLocal<Pair<Integer, Boolean>> sThreadPriority; + + static { + reset(); + } + + public static void reset() { + // Reset the thread local variable + sThreadPriority = ThreadLocal.withInitial( + () -> Pair.create(Process.THREAD_PRIORITY_DEFAULT, true)); + } + + /** + * Called by {@link Process#setThreadPriority(int, int)} + */ + public static void setThreadPriority(int tid, int priority) { + if (Process.myTid() == tid) { + boolean backgroundOk = sThreadPriority.get().second; + if (priority >= Process.THREAD_PRIORITY_BACKGROUND && !backgroundOk) { + throw new IllegalArgumentException( + "Priority " + priority + " blocked by setCanSelfBackground()"); + } + sThreadPriority.set(Pair.create(priority, backgroundOk)); + } else { + throw new UnsupportedOperationException( + "Cross-thread priority management not yet available in Ravenwood"); + } + } + + /** + * Called by {@link Process#setCanSelfBackground(boolean)} + */ + public static void setCanSelfBackground(boolean backgroundOk) { + int priority = sThreadPriority.get().first; + sThreadPriority.set(Pair.create(priority, backgroundOk)); + } + + /** + * Called by {@link Process#getThreadPriority(int)} + */ + public static int getThreadPriority(int tid) { + if (Process.myTid() == tid) { + return sThreadPriority.get().first; + } else { + throw new UnsupportedOperationException( + "Cross-thread priority management not yet available in Ravenwood"); + } + } +} diff --git a/ravenwood/runtime-helper-src/framework/com/android/internal/ravenwood/RavenwoodEnvironment_host.java b/ravenwood/runtime-helper-src/framework/com/android/internal/ravenwood/RavenwoodEnvironment_host.java index e12ff240c4d9..b65668b67e03 100644 --- a/ravenwood/runtime-helper-src/framework/com/android/internal/ravenwood/RavenwoodEnvironment_host.java +++ b/ravenwood/runtime-helper-src/framework/com/android/internal/ravenwood/RavenwoodEnvironment_host.java @@ -23,14 +23,6 @@ public class RavenwoodEnvironment_host { } /** - * Called from {@link RavenwoodEnvironment#ensureRavenwoodInitialized()}. - */ - public static void ensureRavenwoodInitialized() { - // Initialization is now done by RavenwoodAwareTestRunner. - // Should we remove it? - } - - /** * Called from {@link RavenwoodEnvironment#getRavenwoodRuntimePath()}. */ public static String getRavenwoodRuntimePath(RavenwoodEnvironment env) { diff --git a/ravenwood/runtime-helper-src/libcore-fake/android/system/Os.java b/ravenwood/runtime-helper-src/libcore-fake/android/system/Os.java index c94ef31a5e5e..02981713674d 100644 --- a/ravenwood/runtime-helper-src/libcore-fake/android/system/Os.java +++ b/ravenwood/runtime-helper-src/libcore-fake/android/system/Os.java @@ -16,6 +16,7 @@ package android.system; import com.android.ravenwood.RavenwoodRuntimeNative; +import com.android.ravenwood.RavenwoodRuntimeState; import com.android.ravenwood.common.JvmWorkaround; import java.io.FileDescriptor; @@ -97,4 +98,16 @@ public final class Os { public static void setenv(String name, String value, boolean overwrite) throws ErrnoException { RavenwoodRuntimeNative.setenv(name, value, overwrite); } + + public static int getpid() { + return RavenwoodRuntimeState.sPid; + } + + public static int getuid() { + return RavenwoodRuntimeState.sUid; + } + + public static int gettid() { + return RavenwoodRuntimeNative.gettid(); + } } diff --git a/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/RavenwoodRuntimeNative.java b/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/RavenwoodRuntimeNative.java index f13189f6f8be..7b940b423b69 100644 --- a/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/RavenwoodRuntimeNative.java +++ b/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/RavenwoodRuntimeNative.java @@ -58,6 +58,8 @@ public class RavenwoodRuntimeNative { public static native void clearSystemProperties(); + public static native int gettid(); + public static long lseek(FileDescriptor fd, long offset, int whence) throws ErrnoException { return nLseek(JvmWorkaround.getInstance().getFdInt(fd), offset, whence); } diff --git a/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/RavenwoodRuntimeState.java b/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/RavenwoodRuntimeState.java new file mode 100644 index 000000000000..175e020d61d6 --- /dev/null +++ b/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/RavenwoodRuntimeState.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2024 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 com.android.ravenwood; + +public class RavenwoodRuntimeState { + // This must match VMRuntime.SDK_VERSION_CUR_DEVELOPMENT. + public static final int CUR_DEVELOPMENT = 10000; + + public static volatile int sUid; + public static volatile int sPid; + public static volatile int sTargetSdkLevel; + + static { + reset(); + } + + public static void reset() { + sUid = -1; + sPid = -1; + sTargetSdkLevel = CUR_DEVELOPMENT; + } +} diff --git a/ravenwood/runtime-helper-src/libcore-fake/dalvik/system/VMRuntime.java b/ravenwood/runtime-helper-src/libcore-fake/dalvik/system/VMRuntime.java index ba89f71dde8a..eaadac6a8b92 100644 --- a/ravenwood/runtime-helper-src/libcore-fake/dalvik/system/VMRuntime.java +++ b/ravenwood/runtime-helper-src/libcore-fake/dalvik/system/VMRuntime.java @@ -19,6 +19,7 @@ package dalvik.system; // The original is here: // $ANDROID_BUILD_TOP/libcore/libart/src/main/java/dalvik/system/VMRuntime.java +import com.android.ravenwood.RavenwoodRuntimeState; import com.android.ravenwood.common.JvmWorkaround; import java.lang.reflect.Array; @@ -52,4 +53,8 @@ public class VMRuntime { public long addressOf(Object obj) { return JvmWorkaround.getInstance().addressOf(obj); } + + public int getTargetSdkVersion() { + return RavenwoodRuntimeState.sTargetSdkLevel; + } } |