summaryrefslogtreecommitdiff
path: root/ravenwood/runtime-helper-src
diff options
context:
space:
mode:
author Makoto Onuki <omakoto@google.com> 2024-05-21 11:20:08 -0700
committer Makoto Onuki <omakoto@google.com> 2024-05-21 14:32:12 -0700
commit8775923a18f5cc155857dac7bdafccb46d0599e9 (patch)
treea17da28d21b44e8b5253b6d4ee906b766fe58b4e /ravenwood/runtime-helper-src
parentc939aaa3a9813e9999ca15708e79cec21dba5a18 (diff)
Ensure Build is always usable on Ravenwood ...
... even without a RavenwoodRule. There are situation where android APIs are called outside of a RavenwoodRule, but some of the APIs require a RavenwoodRule to initialize them. Since Build and SystemProperties are critical and often used by the test infra code (e.g. test runner or other junit rules), make sure they're always accessible. Fix: 341735388 Test: atest CtsOsTestCases Test: $ANDROID_BUILD_TOP/frameworks/base/ravenwood/scripts/run-ravenwood-tests.sh Change-Id: Iedcfae7e75c5ee9f2c7fb87c61262c2b33450d04
Diffstat (limited to 'ravenwood/runtime-helper-src')
-rw-r--r--ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/nativesubstitution/RavenwoodEnvironment_host.java57
-rw-r--r--ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/nativesubstitution/SystemProperties_host.java15
2 files changed, 72 insertions, 0 deletions
diff --git a/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/nativesubstitution/RavenwoodEnvironment_host.java b/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/nativesubstitution/RavenwoodEnvironment_host.java
new file mode 100644
index 000000000000..68bf92273022
--- /dev/null
+++ b/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/nativesubstitution/RavenwoodEnvironment_host.java
@@ -0,0 +1,57 @@
+/*
+ * 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.platform.test.ravenwood.nativesubstitution;
+
+import android.platform.test.ravenwood.RavenwoodSystemProperties;
+import android.util.Log;
+
+import com.android.internal.ravenwood.RavenwoodEnvironment;
+
+public class RavenwoodEnvironment_host {
+ private static final String TAG = RavenwoodEnvironment.TAG;
+
+ private static final Object sInitializeLock = new Object();
+
+ // @GuardedBy("sInitializeLock")
+ private static boolean sInitialized;
+
+ private RavenwoodEnvironment_host() {
+ }
+
+ /**
+ * Called from {@link RavenwoodEnvironment#ensureRavenwoodInitialized()}.
+ */
+ public static void ensureRavenwoodInitializedInternal() {
+ synchronized (sInitializeLock) {
+ if (sInitialized) {
+ return;
+ }
+ Log.w(TAG, "Initializing Ravenwood environment");
+
+ // Set the default values.
+ var sysProps = RavenwoodSystemProperties.DEFAULT_VALUES;
+
+ // We have a method that does it in RavenwoodRuleImpl, but we can't use that class
+ // here, So just inline it.
+ SystemProperties_host.initializeIfNeeded(
+ sysProps.getValues(),
+ sysProps.getKeyReadablePredicate(),
+ sysProps.getKeyWritablePredicate());
+
+ sInitialized = true;
+ }
+ }
+}
diff --git a/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/nativesubstitution/SystemProperties_host.java b/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/nativesubstitution/SystemProperties_host.java
index eba6c8b2db64..e7479d313918 100644
--- a/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/nativesubstitution/SystemProperties_host.java
+++ b/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/nativesubstitution/SystemProperties_host.java
@@ -47,6 +47,21 @@ public class SystemProperties_host {
@GuardedBy("sLock")
private static SparseArray<String> sKeyHandles = new SparseArray<>();
+ /**
+ * Basically the same as {@link #native_init$ravenwood}, but it'll only run if no values are
+ * set yet.
+ */
+ public static void initializeIfNeeded(Map<String, String> values,
+ Predicate<String> keyReadablePredicate, Predicate<String> keyWritablePredicate) {
+ synchronized (sLock) {
+ if (sValues != null) {
+ return; // Already initialized.
+ }
+ native_init$ravenwood(values, keyReadablePredicate, keyWritablePredicate,
+ () -> {});
+ }
+ }
+
public static void native_init$ravenwood(Map<String, String> values,
Predicate<String> keyReadablePredicate, Predicate<String> keyWritablePredicate,
Runnable changeCallback) {