Loading core/java/android/app/PropertyInvalidatedCache.java +330 −395 File changed.Preview size limit exceeded, changes collapsed. Show changes core/tests/coretests/src/android/app/PropertyInvalidatedCacheTests.java +12 −18 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ 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 @@ -27,7 +26,6 @@ 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,10 +90,11 @@ public class PropertyInvalidatedCacheTests { } } // Ensure all test nonces are cleared after the test ends. // Clear the test mode after every test, in case this process is used for other // tests. This also resets the test property map. @After public void tearDown() throws Exception { PropertyInvalidatedCache.resetAfterTest(); PropertyInvalidatedCache.setTestMode(false); } // This test is disabled pending an sepolicy change that allows any app to set the Loading @@ -112,6 +111,9 @@ 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 @@ -221,16 +223,22 @@ 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 @@ -367,18 +375,4 @@ 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 +16 −19 Original line number Diff line number Diff line Loading @@ -17,7 +17,6 @@ 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 @@ -27,7 +26,6 @@ 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 @@ -94,17 +92,17 @@ public class IpcDataCacheTest { public Boolean apply(Integer x) { return mServer.query(x); } @Override public boolean shouldBypassCache(Integer x) { return x % 13 == 0; } } // Ensure all test nonces are cleared after the test ends. // Clear the test mode after every test, in case this process is used for other // tests. This also resets the test property map. @After public void tearDown() throws Exception { IpcDataCache.resetAfterTest(); IpcDataCache.setTestMode(false); } // This test is disabled pending an sepolicy change that allows any app to set the Loading @@ -121,6 +119,9 @@ 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 @@ -164,6 +165,9 @@ 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 @@ -201,6 +205,9 @@ 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 @@ -306,6 +313,8 @@ 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 @@ -315,6 +324,8 @@ public class IpcDataCacheTest { TestCache(IpcDataCache.Config c, TestQuery query) { super(c, query); mQuery = query; setTestMode(true); testPropertyName(); } int getRecomputeCount() { Loading Loading @@ -445,18 +456,4 @@ 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 +330 −395 File changed.Preview size limit exceeded, changes collapsed. Show changes
core/tests/coretests/src/android/app/PropertyInvalidatedCacheTests.java +12 −18 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ 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 @@ -27,7 +26,6 @@ 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,10 +90,11 @@ public class PropertyInvalidatedCacheTests { } } // Ensure all test nonces are cleared after the test ends. // Clear the test mode after every test, in case this process is used for other // tests. This also resets the test property map. @After public void tearDown() throws Exception { PropertyInvalidatedCache.resetAfterTest(); PropertyInvalidatedCache.setTestMode(false); } // This test is disabled pending an sepolicy change that allows any app to set the Loading @@ -112,6 +111,9 @@ 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 @@ -221,16 +223,22 @@ 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 @@ -367,18 +375,4 @@ 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 +16 −19 Original line number Diff line number Diff line Loading @@ -17,7 +17,6 @@ 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 @@ -27,7 +26,6 @@ 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 @@ -94,17 +92,17 @@ public class IpcDataCacheTest { public Boolean apply(Integer x) { return mServer.query(x); } @Override public boolean shouldBypassCache(Integer x) { return x % 13 == 0; } } // Ensure all test nonces are cleared after the test ends. // Clear the test mode after every test, in case this process is used for other // tests. This also resets the test property map. @After public void tearDown() throws Exception { IpcDataCache.resetAfterTest(); IpcDataCache.setTestMode(false); } // This test is disabled pending an sepolicy change that allows any app to set the Loading @@ -121,6 +119,9 @@ 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 @@ -164,6 +165,9 @@ 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 @@ -201,6 +205,9 @@ 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 @@ -306,6 +313,8 @@ 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 @@ -315,6 +324,8 @@ public class IpcDataCacheTest { TestCache(IpcDataCache.Config c, TestQuery query) { super(c, query); mQuery = query; setTestMode(true); testPropertyName(); } int getRecomputeCount() { Loading Loading @@ -445,18 +456,4 @@ 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) { } } }