Build `ravenwood-junit` against `test_current`.
Some CTS tests desire to link against `test_current` to prove to
themselves that they're not touching hidden APIs. This means if they
also want to use our `ravenwood-junit` rules, that dependency also
needs to link against `test_current`.
Since we're reaching down into plenty of hidden details when we're
actually running on a Ravenwood runtime, we split into a `stub` and
an `impl` library, so that we give a cleanly compiling library to
to clients, which is then replaced under the Ravenwood runtime.
Bug: 292141694
Test: atest-dev CtsTextTestCasesRavenwood CtsTextTestCases
Change-Id: I96dbc9643324a7853a992e97b51a88f70eb721f3
diff --git a/Ravenwood.bp b/Ravenwood.bp
index b497871..03a23ba 100644
--- a/Ravenwood.bp
+++ b/Ravenwood.bp
@@ -81,7 +81,7 @@
"hoststubgen-helper-framework-runtime.ravenwood",
"junit",
"truth",
- "ravenwood-junit",
+ "ravenwood-junit-impl",
"android.test.mock",
],
}
diff --git a/ravenwood/Android.bp b/ravenwood/Android.bp
index b9e34ee..3f46ab8 100644
--- a/ravenwood/Android.bp
+++ b/ravenwood/Android.bp
@@ -25,12 +25,32 @@
}
java_library {
- name: "ravenwood-junit",
- srcs: ["junit-src/**/*.java"],
+ name: "ravenwood-junit-impl",
+ srcs: [
+ "junit-src/**/*.java",
+ "junit-impl-src/**/*.java",
+ ],
libs: [
"framework-minus-apex.ravenwood",
"junit",
],
+ visibility: ["//frameworks/base"],
+}
+
+// Carefully compiles against only test_current to support tests that
+// want to verify they're unbundled. The "impl" library above is what
+// ships inside the Ravenwood environment to actually drive any API
+// access to implementation details.
+java_library {
+ name: "ravenwood-junit",
+ srcs: [
+ "junit-src/**/*.java",
+ "junit-stub-src/**/*.java",
+ ],
+ sdk_version: "test_current",
+ libs: [
+ "junit",
+ ],
visibility: ["//visibility:public"],
}
diff --git a/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuleImpl.java b/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuleImpl.java
new file mode 100644
index 0000000..1caef26
--- /dev/null
+++ b/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuleImpl.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2023 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.platform.test.ravenwood;
+
+public class RavenwoodRuleImpl {
+ public static void init(RavenwoodRule rule) {
+ android.os.Process.init$ravenwood(rule.mUid, rule.mPid);
+ android.os.Binder.init$ravenwood();
+ }
+
+ public static void reset(RavenwoodRule rule) {
+ android.os.Process.reset$ravenwood();
+ android.os.Binder.reset$ravenwood();
+ }
+}
diff --git a/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java b/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java
index bffd0cd..79f9e58 100644
--- a/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java
+++ b/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java
@@ -16,7 +16,6 @@
package android.platform.test.ravenwood;
-import android.os.Process;
import android.platform.test.annotations.IgnoreUnderRavenwood;
import org.junit.Assume;
@@ -35,12 +34,16 @@
public class RavenwoodRule implements TestRule {
private static AtomicInteger sNextPid = new AtomicInteger(100);
+ private static final int SYSTEM_UID = 1000;
+ private static final int NOBODY_UID = 9999;
+ private static final int FIRST_APPLICATION_UID = 10000;
+
/**
* Unless the test author requests differently, run as "nobody", and give each collection of
* tests its own unique PID.
*/
- private int mUid = android.os.Process.NOBODY_UID;
- private int mPid = sNextPid.getAndIncrement();
+ int mUid = NOBODY_UID;
+ int mPid = sNextPid.getAndIncrement();
public RavenwoodRule() {
}
@@ -56,7 +59,7 @@
* test. Has no effect under non-Ravenwood environments.
*/
public Builder setProcessSystem() {
- mRule.mUid = android.os.Process.SYSTEM_UID;
+ mRule.mUid = SYSTEM_UID;
return this;
}
@@ -65,7 +68,7 @@
* test. Has no effect under non-Ravenwood environments.
*/
public Builder setProcessApp() {
- mRule.mUid = android.os.Process.FIRST_APPLICATION_UID;
+ mRule.mUid = FIRST_APPLICATION_UID;
return this;
}
@@ -82,16 +85,6 @@
return System.getProperty("java.class.path").contains("ravenwood");
}
- private void init() {
- android.os.Process.init$ravenwood(mUid, mPid);
- android.os.Binder.init$ravenwood();
- }
-
- private void reset() {
- android.os.Process.reset$ravenwood();
- android.os.Binder.reset$ravenwood();
- }
-
@Override
public Statement apply(Statement base, Description description) {
return new Statement() {
@@ -102,13 +95,13 @@
Assume.assumeFalse(isUnderRavenwood);
}
if (isUnderRavenwood) {
- init();
+ RavenwoodRuleImpl.init(RavenwoodRule.this);
}
try {
base.evaluate();
} finally {
if (isUnderRavenwood) {
- reset();
+ RavenwoodRuleImpl.reset(RavenwoodRule.this);
}
}
}
diff --git a/ravenwood/junit-stub-src/android/platform/test/ravenwood/RavenwoodRuleImpl.java b/ravenwood/junit-stub-src/android/platform/test/ravenwood/RavenwoodRuleImpl.java
new file mode 100644
index 0000000..ecaff80
--- /dev/null
+++ b/ravenwood/junit-stub-src/android/platform/test/ravenwood/RavenwoodRuleImpl.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2023 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.platform.test.ravenwood;
+
+public class RavenwoodRuleImpl {
+ public static void init(RavenwoodRule rule) {
+ // Must be provided by impl to reference runtime internals
+ throw new UnsupportedOperationException();
+ }
+
+ public static void reset(RavenwoodRule rule) {
+ // Must be provided by impl to reference runtime internals
+ throw new UnsupportedOperationException();
+ }
+}