From 726c48c5a73fb5e0c2c49446f2e56cfc03f3cf08 Mon Sep 17 00:00:00 2001 From: Songchun Fan Date: Tue, 14 Mar 2023 18:09:14 -0700 Subject: [PATCH] [SettingsProvider] GenerationRegistry test for Global settings BUG: 228619157 Test: atest com.android.providers.settings.GenerationRegistryTest Change-Id: I5e050b4834d75ab9112efdcd25621ab88e16eb5c --- packages/SettingsProvider/test/AndroidTest.xml | 6 ++++++ .../settings/GenerationRegistryTest.java | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/packages/SettingsProvider/test/AndroidTest.xml b/packages/SettingsProvider/test/AndroidTest.xml index 9d2352670dddf..0bf53ccf81a6d 100644 --- a/packages/SettingsProvider/test/AndroidTest.xml +++ b/packages/SettingsProvider/test/AndroidTest.xml @@ -14,6 +14,12 @@ limitations under the License. --> + + + diff --git a/packages/SettingsProvider/test/src/com/android/providers/settings/GenerationRegistryTest.java b/packages/SettingsProvider/test/src/com/android/providers/settings/GenerationRegistryTest.java index 6ec8146baee0b..586d6f73baad6 100644 --- a/packages/SettingsProvider/test/src/com/android/providers/settings/GenerationRegistryTest.java +++ b/packages/SettingsProvider/test/src/com/android/providers/settings/GenerationRegistryTest.java @@ -170,6 +170,23 @@ public class GenerationRegistryTest { checkBundle(b, 1, 2, false); } + @Test + public void testGlobalSettings() throws IOException { + final GenerationRegistry generationRegistry = new GenerationRegistry(new Object()); + final int globalKey = SettingsState.makeKey(SettingsState.SETTINGS_TYPE_GLOBAL, 0); + final String testGlobalSetting = "test_global_setting"; + final Bundle b = new Bundle(); + generationRegistry.addGenerationData(b, globalKey, testGlobalSetting); + checkBundle(b, 0, 1, false); + final MemoryIntArray array = getArray(b); + final int globalKey2 = SettingsState.makeKey(SettingsState.SETTINGS_TYPE_GLOBAL, 10); + b.clear(); + generationRegistry.addGenerationData(b, globalKey2, testGlobalSetting); + checkBundle(b, 0, 1, false); + final MemoryIntArray array2 = getArray(b); + // Check that user10 and user0 use the same array to store global settings' generations + assertThat(array).isEqualTo(array2); + } private void checkBundle(Bundle b, int expectedIndex, int expectedGeneration, boolean isNull) throws IOException {