summaryrefslogtreecommitdiff
path: root/ravenwood/junit-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/junit-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/junit-src')
-rw-r--r--ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodSystemProperties.java40
1 files changed, 35 insertions, 5 deletions
diff --git a/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodSystemProperties.java b/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodSystemProperties.java
index 85ad4e444f24..c3786ee0041d 100644
--- a/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodSystemProperties.java
+++ b/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodSystemProperties.java
@@ -22,7 +22,9 @@ import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
-class RavenwoodSystemProperties {
+public class RavenwoodSystemProperties {
+ private volatile boolean mIsImmutable;
+
private final Map<String, String> mValues = new HashMap<>();
/** Set of additional keys that should be considered readable */
@@ -101,15 +103,23 @@ class RavenwoodSystemProperties {
setValue("ro.debuggable", "1");
}
- Map<String, String> getValues() {
+ /** Copy constructor */
+ public RavenwoodSystemProperties(RavenwoodSystemProperties source, boolean immutable) {
+ this.mKeyReadable.addAll(source.mKeyReadable);
+ this.mKeyWritable.addAll(source.mKeyWritable);
+ this.mValues.putAll(source.mValues);
+ this.mIsImmutable = immutable;
+ }
+
+ public Map<String, String> getValues() {
return new HashMap<>(mValues);
}
- Predicate<String> getKeyReadablePredicate() {
+ public Predicate<String> getKeyReadablePredicate() {
return mKeyReadablePredicate;
}
- Predicate<String> getKeyWritablePredicate() {
+ public Predicate<String> getKeyWritablePredicate() {
return mKeyWritablePredicate;
}
@@ -123,12 +133,20 @@ class RavenwoodSystemProperties {
"vendor_dlkm",
};
+ private void ensureNotImmutable() {
+ if (mIsImmutable) {
+ throw new RuntimeException("Unable to update immutable instance");
+ }
+ }
+
/**
* Set the given property for all possible partitions where it could be defined. For
* example, the value of {@code ro.build.type} is typically also mirrored under
* {@code ro.system.build.type}, etc.
*/
private void setValueForPartitions(String key, String value) {
+ ensureNotImmutable();
+
setValue("ro." + key, value);
for (String partition : PARTITIONS) {
setValue("ro." + partition + "." + key, value);
@@ -136,6 +154,8 @@ class RavenwoodSystemProperties {
}
public void setValue(String key, Object value) {
+ ensureNotImmutable();
+
final String valueString = (value == null) ? null : String.valueOf(value);
if ((valueString == null) || valueString.isEmpty()) {
mValues.remove(key);
@@ -145,16 +165,19 @@ class RavenwoodSystemProperties {
}
public void setAccessNone(String key) {
+ ensureNotImmutable();
mKeyReadable.remove(key);
mKeyWritable.remove(key);
}
public void setAccessReadOnly(String key) {
+ ensureNotImmutable();
mKeyReadable.add(key);
mKeyWritable.remove(key);
}
public void setAccessReadWrite(String key) {
+ ensureNotImmutable();
mKeyReadable.add(key);
mKeyWritable.add(key);
}
@@ -172,4 +195,11 @@ class RavenwoodSystemProperties {
return key;
}
}
-}
+
+ /**
+ * Return an immutable, default instance.
+ */
+ // Create a default instance, and make an immutable copy of it.
+ public static final RavenwoodSystemProperties DEFAULT_VALUES =
+ new RavenwoodSystemProperties(new RavenwoodSystemProperties(), true);
+} \ No newline at end of file