Loading core/java/android/app/PropertyInvalidatedCache.java +395 −330 File changed.Preview size limit exceeded, changes collapsed. Show changes core/tests/coretests/src/android/app/PropertyInvalidatedCacheTests.java +18 −12 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package android.app; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; import android.platform.test.annotations.IgnoreUnderRavenwood; import android.platform.test.ravenwood.RavenwoodRule; Loading @@ -26,6 +27,7 @@ import android.platform.test.ravenwood.RavenwoodRule; import androidx.test.filters.SmallTest; import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; Loading Loading @@ -90,11 +92,10 @@ public class PropertyInvalidatedCacheTests { } } // Clear the test mode after every test, in case this process is used for other // tests. This also resets the test property map. // Ensure all test nonces are cleared after the test ends. @After public void tearDown() throws Exception { PropertyInvalidatedCache.setTestMode(false); PropertyInvalidatedCache.resetAfterTest(); } // This test is disabled pending an sepolicy change that allows any app to set the Loading @@ -111,9 +112,6 @@ public class PropertyInvalidatedCacheTests { new PropertyInvalidatedCache<>(4, MODULE, API, "cache1", new ServerQuery(tester)); PropertyInvalidatedCache.setTestMode(true); testCache.testPropertyName(); tester.verify(0); assertEquals(tester.value(3), testCache.query(3)); tester.verify(1); Loading Loading @@ -223,22 +221,16 @@ public class PropertyInvalidatedCacheTests { TestCache(String module, String api) { this(module, api, new TestQuery()); setTestMode(true); testPropertyName(); } TestCache(String module, String api, TestQuery query) { super(4, module, api, api, query); mQuery = query; setTestMode(true); testPropertyName(); } public int getRecomputeCount() { return mQuery.getRecomputeCount(); } } @Test Loading Loading @@ -375,4 +367,18 @@ public class PropertyInvalidatedCacheTests { PropertyInvalidatedCache.MODULE_BLUETOOTH, "getState"); assertEquals(n1, "cache_key.bluetooth.get_state"); } // It is illegal to continue to use a cache with a test key after calling setTestMode(false). // This test verifies the code detects errors in calling setTestMode(). @Test public void testTestMode() { TestCache cache = new TestCache(); cache.invalidateCache(); PropertyInvalidatedCache.resetAfterTest(); try { cache.invalidateCache(); fail("expected an IllegalStateException"); } catch (IllegalStateException expected) { } } } core/tests/coretests/src/android/os/IpcDataCacheTest.java +19 −16 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.os; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import android.multiuser.Flags; import android.platform.test.annotations.IgnoreUnderRavenwood; Loading @@ -26,6 +27,7 @@ import android.platform.test.ravenwood.RavenwoodRule; import androidx.test.filters.SmallTest; import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; Loading Loading @@ -92,17 +94,17 @@ public class IpcDataCacheTest { public Boolean apply(Integer x) { return mServer.query(x); } @Override public boolean shouldBypassCache(Integer x) { return x % 13 == 0; } } // Clear the test mode after every test, in case this process is used for other // tests. This also resets the test property map. // Ensure all test nonces are cleared after the test ends. @After public void tearDown() throws Exception { IpcDataCache.setTestMode(false); IpcDataCache.resetAfterTest(); } // This test is disabled pending an sepolicy change that allows any app to set the Loading @@ -119,9 +121,6 @@ public class IpcDataCacheTest { new IpcDataCache<>(4, MODULE, API, "testCache1", new ServerQuery(tester)); IpcDataCache.setTestMode(true); testCache.testPropertyName(); tester.verify(0); assertEquals(tester.value(3), testCache.query(3)); tester.verify(1); Loading Loading @@ -165,9 +164,6 @@ public class IpcDataCacheTest { IpcDataCache<Integer, Boolean> testCache = new IpcDataCache<>(config, (x) -> tester.query(x, x % 10 == 9)); IpcDataCache.setTestMode(true); testCache.testPropertyName(); tester.verify(0); assertEquals(tester.value(3), testCache.query(3)); tester.verify(1); Loading Loading @@ -205,9 +201,6 @@ public class IpcDataCacheTest { IpcDataCache<Integer, Boolean> testCache = new IpcDataCache<>(config, (x) -> tester.query(x), (x) -> x % 9 == 0); IpcDataCache.setTestMode(true); testCache.testPropertyName(); tester.verify(0); assertEquals(tester.value(3), testCache.query(3)); tester.verify(1); Loading Loading @@ -313,8 +306,6 @@ public class IpcDataCacheTest { TestCache(String module, String api, TestQuery query) { super(4, module, api, "testCache7", query); mQuery = query; setTestMode(true); testPropertyName(); } TestCache(IpcDataCache.Config c) { Loading @@ -324,8 +315,6 @@ public class IpcDataCacheTest { TestCache(IpcDataCache.Config c, TestQuery query) { super(c, query); mQuery = query; setTestMode(true); testPropertyName(); } int getRecomputeCount() { Loading Loading @@ -456,4 +445,18 @@ public class IpcDataCacheTest { TestCache ec = new TestCache(e); assertEquals(ec.isDisabled(), true); } // It is illegal to continue to use a cache with a test key after calling setTestMode(false). // This test verifies the code detects errors in calling setTestMode(). @Test public void testTestMode() { TestCache cache = new TestCache(); cache.invalidateCache(); IpcDataCache.resetAfterTest(); try { cache.invalidateCache(); fail("expected an IllegalStateException"); } catch (IllegalStateException expected) { } } } Loading
core/java/android/app/PropertyInvalidatedCache.java +395 −330 File changed.Preview size limit exceeded, changes collapsed. Show changes
core/tests/coretests/src/android/app/PropertyInvalidatedCacheTests.java +18 −12 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package android.app; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; import android.platform.test.annotations.IgnoreUnderRavenwood; import android.platform.test.ravenwood.RavenwoodRule; Loading @@ -26,6 +27,7 @@ import android.platform.test.ravenwood.RavenwoodRule; import androidx.test.filters.SmallTest; import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; Loading Loading @@ -90,11 +92,10 @@ public class PropertyInvalidatedCacheTests { } } // Clear the test mode after every test, in case this process is used for other // tests. This also resets the test property map. // Ensure all test nonces are cleared after the test ends. @After public void tearDown() throws Exception { PropertyInvalidatedCache.setTestMode(false); PropertyInvalidatedCache.resetAfterTest(); } // This test is disabled pending an sepolicy change that allows any app to set the Loading @@ -111,9 +112,6 @@ public class PropertyInvalidatedCacheTests { new PropertyInvalidatedCache<>(4, MODULE, API, "cache1", new ServerQuery(tester)); PropertyInvalidatedCache.setTestMode(true); testCache.testPropertyName(); tester.verify(0); assertEquals(tester.value(3), testCache.query(3)); tester.verify(1); Loading Loading @@ -223,22 +221,16 @@ public class PropertyInvalidatedCacheTests { TestCache(String module, String api) { this(module, api, new TestQuery()); setTestMode(true); testPropertyName(); } TestCache(String module, String api, TestQuery query) { super(4, module, api, api, query); mQuery = query; setTestMode(true); testPropertyName(); } public int getRecomputeCount() { return mQuery.getRecomputeCount(); } } @Test Loading Loading @@ -375,4 +367,18 @@ public class PropertyInvalidatedCacheTests { PropertyInvalidatedCache.MODULE_BLUETOOTH, "getState"); assertEquals(n1, "cache_key.bluetooth.get_state"); } // It is illegal to continue to use a cache with a test key after calling setTestMode(false). // This test verifies the code detects errors in calling setTestMode(). @Test public void testTestMode() { TestCache cache = new TestCache(); cache.invalidateCache(); PropertyInvalidatedCache.resetAfterTest(); try { cache.invalidateCache(); fail("expected an IllegalStateException"); } catch (IllegalStateException expected) { } } }
core/tests/coretests/src/android/os/IpcDataCacheTest.java +19 −16 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.os; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import android.multiuser.Flags; import android.platform.test.annotations.IgnoreUnderRavenwood; Loading @@ -26,6 +27,7 @@ import android.platform.test.ravenwood.RavenwoodRule; import androidx.test.filters.SmallTest; import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; Loading Loading @@ -92,17 +94,17 @@ public class IpcDataCacheTest { public Boolean apply(Integer x) { return mServer.query(x); } @Override public boolean shouldBypassCache(Integer x) { return x % 13 == 0; } } // Clear the test mode after every test, in case this process is used for other // tests. This also resets the test property map. // Ensure all test nonces are cleared after the test ends. @After public void tearDown() throws Exception { IpcDataCache.setTestMode(false); IpcDataCache.resetAfterTest(); } // This test is disabled pending an sepolicy change that allows any app to set the Loading @@ -119,9 +121,6 @@ public class IpcDataCacheTest { new IpcDataCache<>(4, MODULE, API, "testCache1", new ServerQuery(tester)); IpcDataCache.setTestMode(true); testCache.testPropertyName(); tester.verify(0); assertEquals(tester.value(3), testCache.query(3)); tester.verify(1); Loading Loading @@ -165,9 +164,6 @@ public class IpcDataCacheTest { IpcDataCache<Integer, Boolean> testCache = new IpcDataCache<>(config, (x) -> tester.query(x, x % 10 == 9)); IpcDataCache.setTestMode(true); testCache.testPropertyName(); tester.verify(0); assertEquals(tester.value(3), testCache.query(3)); tester.verify(1); Loading Loading @@ -205,9 +201,6 @@ public class IpcDataCacheTest { IpcDataCache<Integer, Boolean> testCache = new IpcDataCache<>(config, (x) -> tester.query(x), (x) -> x % 9 == 0); IpcDataCache.setTestMode(true); testCache.testPropertyName(); tester.verify(0); assertEquals(tester.value(3), testCache.query(3)); tester.verify(1); Loading Loading @@ -313,8 +306,6 @@ public class IpcDataCacheTest { TestCache(String module, String api, TestQuery query) { super(4, module, api, "testCache7", query); mQuery = query; setTestMode(true); testPropertyName(); } TestCache(IpcDataCache.Config c) { Loading @@ -324,8 +315,6 @@ public class IpcDataCacheTest { TestCache(IpcDataCache.Config c, TestQuery query) { super(c, query); mQuery = query; setTestMode(true); testPropertyName(); } int getRecomputeCount() { Loading Loading @@ -456,4 +445,18 @@ public class IpcDataCacheTest { TestCache ec = new TestCache(e); assertEquals(ec.isDisabled(), true); } // It is illegal to continue to use a cache with a test key after calling setTestMode(false). // This test verifies the code detects errors in calling setTestMode(). @Test public void testTestMode() { TestCache cache = new TestCache(); cache.invalidateCache(); IpcDataCache.resetAfterTest(); try { cache.invalidateCache(); fail("expected an IllegalStateException"); } catch (IllegalStateException expected) { } } }