Loading core/java/android/os/Build.java +3 −1 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import android.app.ActivityThread; import android.app.Application; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; import android.ravenwood.annotation.RavenwoodKeepWholeClass; import android.sysprop.DeviceProperties; import android.sysprop.SocProperties; import android.sysprop.TelephonyProperties; Loading @@ -47,6 +48,7 @@ import java.util.stream.Collectors; /** * Information about the current build, extracted from system properties. */ @RavenwoodKeepWholeClass public class Build { private static final String TAG = "Build"; Loading Loading @@ -307,7 +309,7 @@ public class Build { * compatibility. */ final String[] abiList; if (VMRuntime.getRuntime().is64Bit()) { if (android.os.Process.is64Bit()) { abiList = SUPPORTED_64_BIT_ABIS; } else { abiList = SUPPORTED_32_BIT_ABIS; Loading core/java/android/os/SystemProperties.java +31 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemApi; import android.compat.annotation.UnsupportedAppUsage; import android.ravenwood.annotation.RavenwoodKeepWholeClass; import android.ravenwood.annotation.RavenwoodNativeSubstitutionClass; import android.util.Log; import android.util.MutableInt; Loading @@ -36,6 +38,8 @@ import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.function.Predicate; /** * Gives access to the system properties store. The system properties Loading @@ -51,6 +55,8 @@ import java.util.HashMap; * {@hide} */ @SystemApi @RavenwoodKeepWholeClass @RavenwoodNativeSubstitutionClass("com.android.hoststubgen.nativesubstitution.SystemProperties_host") public class SystemProperties { private static final String TAG = "SystemProperties"; private static final boolean TRACK_KEY_ACCESS = false; Loading Loading @@ -94,6 +100,31 @@ public class SystemProperties { } } /** @hide */ public static void init$ravenwood(Map<String, String> values, Predicate<String> keyReadablePredicate, Predicate<String> keyWritablePredicate) { native_init$ravenwood(values, keyReadablePredicate, keyWritablePredicate, SystemProperties::callChangeCallbacks); synchronized (sChangeCallbacks) { sChangeCallbacks.clear(); } } /** @hide */ public static void reset$ravenwood() { native_reset$ravenwood(); synchronized (sChangeCallbacks) { sChangeCallbacks.clear(); } } // These native methods are currently only implemented by Ravenwood, as it's the only // mechanism we have to jump to our RavenwoodNativeSubstitutionClass private static native void native_init$ravenwood(Map<String, String> values, Predicate<String> keyReadablePredicate, Predicate<String> keyWritablePredicate, Runnable changeCallback); private static native void native_reset$ravenwood(); // The one-argument version of native_get used to be a regular native function. Nowadays, // we use the two-argument form of native_get all the time, but we can't just delete the // one-argument overload: apps use it via reflection, as the UnsupportedAppUsage annotation Loading core/tests/coretests/src/android/os/BuildTest.java +0 −2 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import android.platform.test.annotations.IgnoreUnderRavenwood; import android.platform.test.flag.junit.SetFlagsRule; import android.platform.test.ravenwood.RavenwoodRule; Loading Loading @@ -71,7 +70,6 @@ public class BuildTest { */ @Test @SmallTest @IgnoreUnderRavenwood(blockedBy = Build.class) public void testBuildFields() throws Exception { assertNotEmpty("ID", Build.ID); assertNotEmpty("DISPLAY", Build.DISPLAY); Loading core/tests/systemproperties/Android.bp +22 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,9 @@ android_test { static_libs: [ "android-common", "frameworks-core-util-lib", "androidx.test.rules", "androidx.test.ext.junit", "ravenwood-junit", ], libs: [ "android.test.runner", Loading @@ -23,3 +26,22 @@ android_test { platform_apis: true, certificate: "platform", } android_ravenwood_test { name: "FrameworksCoreSystemPropertiesTestsRavenwood", static_libs: [ "android-common", "frameworks-core-util-lib", "androidx.test.rules", "androidx.test.ext.junit", "ravenwood-junit", ], libs: [ "android.test.runner", "android.test.base", ], srcs: [ "src/**/*.java", ], auto_gen_config: true, } core/tests/systemproperties/src/android/os/SystemPropertiesTest.java +27 −2 Original line number Diff line number Diff line Loading @@ -16,19 +16,36 @@ package android.os; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import android.platform.test.ravenwood.RavenwoodRule; import android.test.suitebuilder.annotation.SmallTest; import junit.framework.TestCase; import org.junit.Rule; import org.junit.Test; import java.util.Objects; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; public class SystemPropertiesTest extends TestCase { public class SystemPropertiesTest { @Rule public final RavenwoodRule mRavenwood = new RavenwoodRule.Builder() .setSystemPropertyMutable(KEY, null) .setSystemPropertyMutable(UNSET_KEY, null) .setSystemPropertyMutable(PERSIST_KEY, null) .build(); private static final String KEY = "sys.testkey"; private static final String UNSET_KEY = "Aiw7woh6ie4toh7W"; private static final String PERSIST_KEY = "persist.sys.testkey"; @Test @SmallTest public void testStressPersistPropertyConsistency() throws Exception { for (int i = 0; i < 100; ++i) { Loading @@ -38,6 +55,7 @@ public class SystemPropertiesTest extends TestCase { } } @Test @SmallTest public void testStressMemoryPropertyConsistency() throws Exception { for (int i = 0; i < 100; ++i) { Loading @@ -47,6 +65,7 @@ public class SystemPropertiesTest extends TestCase { } } @Test @SmallTest public void testProperties() throws Exception { String value; Loading Loading @@ -93,6 +112,7 @@ public class SystemPropertiesTest extends TestCase { assertEquals(expected, value); } @Test @SmallTest public void testHandle() throws Exception { String value; Loading @@ -114,6 +134,7 @@ public class SystemPropertiesTest extends TestCase { assertEquals(12345, handle.getInt(12345)); } @Test @SmallTest public void testIntegralProperties() throws Exception { testInt("", 123, 123); Loading @@ -133,6 +154,7 @@ public class SystemPropertiesTest extends TestCase { testLong("-3147483647", 124, -3147483647L); } @Test @SmallTest public void testUnset() throws Exception { assertEquals("abc", SystemProperties.get(UNSET_KEY, "abc")); Loading @@ -142,6 +164,7 @@ public class SystemPropertiesTest extends TestCase { assertEquals(-10, SystemProperties.getLong(UNSET_KEY, -10)); } @Test @SmallTest @SuppressWarnings("null") public void testNullKey() throws Exception { Loading Loading @@ -176,6 +199,7 @@ public class SystemPropertiesTest extends TestCase { } } @Test @SmallTest public void testCallbacks() { // Latches are not really necessary, but are easy to use. Loading Loading @@ -220,6 +244,7 @@ public class SystemPropertiesTest extends TestCase { } } @Test @SmallTest public void testDigestOf() { final String empty = SystemProperties.digestOf(); Loading Loading
core/java/android/os/Build.java +3 −1 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import android.app.ActivityThread; import android.app.Application; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; import android.ravenwood.annotation.RavenwoodKeepWholeClass; import android.sysprop.DeviceProperties; import android.sysprop.SocProperties; import android.sysprop.TelephonyProperties; Loading @@ -47,6 +48,7 @@ import java.util.stream.Collectors; /** * Information about the current build, extracted from system properties. */ @RavenwoodKeepWholeClass public class Build { private static final String TAG = "Build"; Loading Loading @@ -307,7 +309,7 @@ public class Build { * compatibility. */ final String[] abiList; if (VMRuntime.getRuntime().is64Bit()) { if (android.os.Process.is64Bit()) { abiList = SUPPORTED_64_BIT_ABIS; } else { abiList = SUPPORTED_32_BIT_ABIS; Loading
core/java/android/os/SystemProperties.java +31 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemApi; import android.compat.annotation.UnsupportedAppUsage; import android.ravenwood.annotation.RavenwoodKeepWholeClass; import android.ravenwood.annotation.RavenwoodNativeSubstitutionClass; import android.util.Log; import android.util.MutableInt; Loading @@ -36,6 +38,8 @@ import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.function.Predicate; /** * Gives access to the system properties store. The system properties Loading @@ -51,6 +55,8 @@ import java.util.HashMap; * {@hide} */ @SystemApi @RavenwoodKeepWholeClass @RavenwoodNativeSubstitutionClass("com.android.hoststubgen.nativesubstitution.SystemProperties_host") public class SystemProperties { private static final String TAG = "SystemProperties"; private static final boolean TRACK_KEY_ACCESS = false; Loading Loading @@ -94,6 +100,31 @@ public class SystemProperties { } } /** @hide */ public static void init$ravenwood(Map<String, String> values, Predicate<String> keyReadablePredicate, Predicate<String> keyWritablePredicate) { native_init$ravenwood(values, keyReadablePredicate, keyWritablePredicate, SystemProperties::callChangeCallbacks); synchronized (sChangeCallbacks) { sChangeCallbacks.clear(); } } /** @hide */ public static void reset$ravenwood() { native_reset$ravenwood(); synchronized (sChangeCallbacks) { sChangeCallbacks.clear(); } } // These native methods are currently only implemented by Ravenwood, as it's the only // mechanism we have to jump to our RavenwoodNativeSubstitutionClass private static native void native_init$ravenwood(Map<String, String> values, Predicate<String> keyReadablePredicate, Predicate<String> keyWritablePredicate, Runnable changeCallback); private static native void native_reset$ravenwood(); // The one-argument version of native_get used to be a regular native function. Nowadays, // we use the two-argument form of native_get all the time, but we can't just delete the // one-argument overload: apps use it via reflection, as the UnsupportedAppUsage annotation Loading
core/tests/coretests/src/android/os/BuildTest.java +0 −2 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import android.platform.test.annotations.IgnoreUnderRavenwood; import android.platform.test.flag.junit.SetFlagsRule; import android.platform.test.ravenwood.RavenwoodRule; Loading Loading @@ -71,7 +70,6 @@ public class BuildTest { */ @Test @SmallTest @IgnoreUnderRavenwood(blockedBy = Build.class) public void testBuildFields() throws Exception { assertNotEmpty("ID", Build.ID); assertNotEmpty("DISPLAY", Build.DISPLAY); Loading
core/tests/systemproperties/Android.bp +22 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,9 @@ android_test { static_libs: [ "android-common", "frameworks-core-util-lib", "androidx.test.rules", "androidx.test.ext.junit", "ravenwood-junit", ], libs: [ "android.test.runner", Loading @@ -23,3 +26,22 @@ android_test { platform_apis: true, certificate: "platform", } android_ravenwood_test { name: "FrameworksCoreSystemPropertiesTestsRavenwood", static_libs: [ "android-common", "frameworks-core-util-lib", "androidx.test.rules", "androidx.test.ext.junit", "ravenwood-junit", ], libs: [ "android.test.runner", "android.test.base", ], srcs: [ "src/**/*.java", ], auto_gen_config: true, }
core/tests/systemproperties/src/android/os/SystemPropertiesTest.java +27 −2 Original line number Diff line number Diff line Loading @@ -16,19 +16,36 @@ package android.os; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import android.platform.test.ravenwood.RavenwoodRule; import android.test.suitebuilder.annotation.SmallTest; import junit.framework.TestCase; import org.junit.Rule; import org.junit.Test; import java.util.Objects; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; public class SystemPropertiesTest extends TestCase { public class SystemPropertiesTest { @Rule public final RavenwoodRule mRavenwood = new RavenwoodRule.Builder() .setSystemPropertyMutable(KEY, null) .setSystemPropertyMutable(UNSET_KEY, null) .setSystemPropertyMutable(PERSIST_KEY, null) .build(); private static final String KEY = "sys.testkey"; private static final String UNSET_KEY = "Aiw7woh6ie4toh7W"; private static final String PERSIST_KEY = "persist.sys.testkey"; @Test @SmallTest public void testStressPersistPropertyConsistency() throws Exception { for (int i = 0; i < 100; ++i) { Loading @@ -38,6 +55,7 @@ public class SystemPropertiesTest extends TestCase { } } @Test @SmallTest public void testStressMemoryPropertyConsistency() throws Exception { for (int i = 0; i < 100; ++i) { Loading @@ -47,6 +65,7 @@ public class SystemPropertiesTest extends TestCase { } } @Test @SmallTest public void testProperties() throws Exception { String value; Loading Loading @@ -93,6 +112,7 @@ public class SystemPropertiesTest extends TestCase { assertEquals(expected, value); } @Test @SmallTest public void testHandle() throws Exception { String value; Loading @@ -114,6 +134,7 @@ public class SystemPropertiesTest extends TestCase { assertEquals(12345, handle.getInt(12345)); } @Test @SmallTest public void testIntegralProperties() throws Exception { testInt("", 123, 123); Loading @@ -133,6 +154,7 @@ public class SystemPropertiesTest extends TestCase { testLong("-3147483647", 124, -3147483647L); } @Test @SmallTest public void testUnset() throws Exception { assertEquals("abc", SystemProperties.get(UNSET_KEY, "abc")); Loading @@ -142,6 +164,7 @@ public class SystemPropertiesTest extends TestCase { assertEquals(-10, SystemProperties.getLong(UNSET_KEY, -10)); } @Test @SmallTest @SuppressWarnings("null") public void testNullKey() throws Exception { Loading Loading @@ -176,6 +199,7 @@ public class SystemPropertiesTest extends TestCase { } } @Test @SmallTest public void testCallbacks() { // Latches are not really necessary, but are easy to use. Loading Loading @@ -220,6 +244,7 @@ public class SystemPropertiesTest extends TestCase { } } @Test @SmallTest public void testDigestOf() { final String empty = SystemProperties.digestOf(); Loading