Loading core/java/android/os/Build.java +6 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,8 @@ import android.util.ArraySet; import android.util.Slog; import android.view.View; import com.android.internal.ravenwood.RavenwoodEnvironment; import dalvik.system.VMRuntime; import java.util.ArrayList; Loading @@ -49,6 +51,10 @@ import java.util.stream.Collectors; */ @RavenwoodKeepWholeClass public class Build { static { // Set up the default system properties. RavenwoodEnvironment.ensureRavenwoodInitialized(); } private static final String TAG = "Build"; /** Value used for when a build property is unknown. */ Loading core/java/com/android/internal/ravenwood/RavenwoodEnvironment.java +25 −1 Original line number Diff line number Diff line Loading @@ -15,14 +15,23 @@ */ package com.android.internal.ravenwood; import android.ravenwood.annotation.RavenwoodNativeSubstitutionClass; /** * Class to interact with the Ravenwood environment. */ @android.ravenwood.annotation.RavenwoodKeepWholeClass public class RavenwoodEnvironment { @RavenwoodNativeSubstitutionClass( "com.android.platform.test.ravenwood.nativesubstitution.RavenwoodEnvironment_host") public final class RavenwoodEnvironment { public static final String TAG = "RavenwoodEnvironment"; private static RavenwoodEnvironment sInstance = new RavenwoodEnvironment(); private RavenwoodEnvironment() { if (isRunningOnRavenwood()) { ensureRavenwoodInitializedInternal(); } } /** Loading @@ -32,6 +41,21 @@ public class RavenwoodEnvironment { return sInstance; } /** * Initialize the ravenwood environment if it hasn't happened already, if running on Ravenwood. * * No-op if called on the device side. */ public static void ensureRavenwoodInitialized() { } private static void ensureRavenwoodInitialized$ravenwood() { getInstance(); // This is enough to initialize the environment. } /** Initialize the ravenwood environment */ private static native void ensureRavenwoodInitializedInternal(); /** * USE IT SPARINGLY! Returns true if it's running on Ravenwood, hostside test environment. * Loading ravenwood/bivalenttest/test/com/android/ravenwoodtest/bivalenttest/RavenwoodRuleTest.java +9 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.ravenwoodtest.bivalenttest; import android.platform.test.annotations.DisabledOnNonRavenwood; import android.platform.test.annotations.DisabledOnRavenwood; import android.platform.test.ravenwood.RavenwoodRule; import android.util.Log; import androidx.test.ext.junit.runners.AndroidJUnit4; Loading @@ -43,5 +44,13 @@ public class RavenwoodRuleTest { Assert.assertTrue(RavenwoodRule.isOnRavenwood()); } @Test public void testDumpSystemProperties() { Log.w("XXX", "System properties"); for (var sp : System.getProperties().entrySet()) { Log.w("XXX", "" + sp.getKey() + "=" + sp.getValue()); } } // TODO: Add more tests } ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuleImpl.java +18 −5 Original line number Diff line number Diff line Loading @@ -100,10 +100,11 @@ public class RavenwoodRuleImpl { android.os.Process.init$ravenwood(rule.mUid, rule.mPid); android.os.Binder.init$ravenwood(); android.os.SystemProperties.init$ravenwood( rule.mSystemProperties.getValues(), rule.mSystemProperties.getKeyReadablePredicate(), rule.mSystemProperties.getKeyWritablePredicate()); // android.os.SystemProperties.init$ravenwood( // rule.mSystemProperties.getValues(), // rule.mSystemProperties.getKeyReadablePredicate(), // rule.mSystemProperties.getKeyWritablePredicate()); setSystemProperties(rule.mSystemProperties); ServiceManager.init$ravenwood(); LocalServices.removeAllServicesForTest(); Loading Loading @@ -157,7 +158,7 @@ public class RavenwoodRuleImpl { LocalServices.removeAllServicesForTest(); ServiceManager.reset$ravenwood(); android.os.SystemProperties.reset$ravenwood(); setSystemProperties(RavenwoodSystemProperties.DEFAULT_VALUES); android.os.Binder.reset$ravenwood(); android.os.Process.reset$ravenwood(); Loading Loading @@ -291,4 +292,16 @@ public class RavenwoodRuleImpl { collectMethods(clazz.getSuperclass(), result); } } /** * Set the current configuration to the actual SystemProperties. */ public static void setSystemProperties(RavenwoodSystemProperties ravenwoodSystemProperties) { var clone = new RavenwoodSystemProperties(ravenwoodSystemProperties, true); android.os.SystemProperties.init$ravenwood( clone.getValues(), clone.getKeyReadablePredicate(), clone.getKeyWritablePredicate()); } } ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodSystemProperties.java +35 −5 Original line number Diff line number Diff line Loading @@ -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 */ Loading Loading @@ -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; } Loading @@ -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); Loading @@ -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); Loading @@ -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); } Loading @@ -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 Loading
core/java/android/os/Build.java +6 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,8 @@ import android.util.ArraySet; import android.util.Slog; import android.view.View; import com.android.internal.ravenwood.RavenwoodEnvironment; import dalvik.system.VMRuntime; import java.util.ArrayList; Loading @@ -49,6 +51,10 @@ import java.util.stream.Collectors; */ @RavenwoodKeepWholeClass public class Build { static { // Set up the default system properties. RavenwoodEnvironment.ensureRavenwoodInitialized(); } private static final String TAG = "Build"; /** Value used for when a build property is unknown. */ Loading
core/java/com/android/internal/ravenwood/RavenwoodEnvironment.java +25 −1 Original line number Diff line number Diff line Loading @@ -15,14 +15,23 @@ */ package com.android.internal.ravenwood; import android.ravenwood.annotation.RavenwoodNativeSubstitutionClass; /** * Class to interact with the Ravenwood environment. */ @android.ravenwood.annotation.RavenwoodKeepWholeClass public class RavenwoodEnvironment { @RavenwoodNativeSubstitutionClass( "com.android.platform.test.ravenwood.nativesubstitution.RavenwoodEnvironment_host") public final class RavenwoodEnvironment { public static final String TAG = "RavenwoodEnvironment"; private static RavenwoodEnvironment sInstance = new RavenwoodEnvironment(); private RavenwoodEnvironment() { if (isRunningOnRavenwood()) { ensureRavenwoodInitializedInternal(); } } /** Loading @@ -32,6 +41,21 @@ public class RavenwoodEnvironment { return sInstance; } /** * Initialize the ravenwood environment if it hasn't happened already, if running on Ravenwood. * * No-op if called on the device side. */ public static void ensureRavenwoodInitialized() { } private static void ensureRavenwoodInitialized$ravenwood() { getInstance(); // This is enough to initialize the environment. } /** Initialize the ravenwood environment */ private static native void ensureRavenwoodInitializedInternal(); /** * USE IT SPARINGLY! Returns true if it's running on Ravenwood, hostside test environment. * Loading
ravenwood/bivalenttest/test/com/android/ravenwoodtest/bivalenttest/RavenwoodRuleTest.java +9 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.ravenwoodtest.bivalenttest; import android.platform.test.annotations.DisabledOnNonRavenwood; import android.platform.test.annotations.DisabledOnRavenwood; import android.platform.test.ravenwood.RavenwoodRule; import android.util.Log; import androidx.test.ext.junit.runners.AndroidJUnit4; Loading @@ -43,5 +44,13 @@ public class RavenwoodRuleTest { Assert.assertTrue(RavenwoodRule.isOnRavenwood()); } @Test public void testDumpSystemProperties() { Log.w("XXX", "System properties"); for (var sp : System.getProperties().entrySet()) { Log.w("XXX", "" + sp.getKey() + "=" + sp.getValue()); } } // TODO: Add more tests }
ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuleImpl.java +18 −5 Original line number Diff line number Diff line Loading @@ -100,10 +100,11 @@ public class RavenwoodRuleImpl { android.os.Process.init$ravenwood(rule.mUid, rule.mPid); android.os.Binder.init$ravenwood(); android.os.SystemProperties.init$ravenwood( rule.mSystemProperties.getValues(), rule.mSystemProperties.getKeyReadablePredicate(), rule.mSystemProperties.getKeyWritablePredicate()); // android.os.SystemProperties.init$ravenwood( // rule.mSystemProperties.getValues(), // rule.mSystemProperties.getKeyReadablePredicate(), // rule.mSystemProperties.getKeyWritablePredicate()); setSystemProperties(rule.mSystemProperties); ServiceManager.init$ravenwood(); LocalServices.removeAllServicesForTest(); Loading Loading @@ -157,7 +158,7 @@ public class RavenwoodRuleImpl { LocalServices.removeAllServicesForTest(); ServiceManager.reset$ravenwood(); android.os.SystemProperties.reset$ravenwood(); setSystemProperties(RavenwoodSystemProperties.DEFAULT_VALUES); android.os.Binder.reset$ravenwood(); android.os.Process.reset$ravenwood(); Loading Loading @@ -291,4 +292,16 @@ public class RavenwoodRuleImpl { collectMethods(clazz.getSuperclass(), result); } } /** * Set the current configuration to the actual SystemProperties. */ public static void setSystemProperties(RavenwoodSystemProperties ravenwoodSystemProperties) { var clone = new RavenwoodSystemProperties(ravenwoodSystemProperties, true); android.os.SystemProperties.init$ravenwood( clone.getValues(), clone.getKeyReadablePredicate(), clone.getKeyWritablePredicate()); } }
ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodSystemProperties.java +35 −5 Original line number Diff line number Diff line Loading @@ -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 */ Loading Loading @@ -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; } Loading @@ -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); Loading @@ -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); Loading @@ -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); } Loading @@ -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