diff options
| author | 2023-10-26 23:54:09 +0000 | |
|---|---|---|
| committer | 2023-10-26 23:54:09 +0000 | |
| commit | 4fa3577bedb1d5fc58d9a6abd6a80df2367d5c93 (patch) | |
| tree | 91ddfee2ddee23a39be73ae7874f4a33edce9964 | |
| parent | 0f0a9504c5bad4f6d57f53af3ec2ca018c3a4c1d (diff) | |
| parent | dbf9f65f5f20b2b9b786c66d00b8775c1c2d8236 (diff) | |
Merge "[SettingsProvider] minor refactor: use a separate lock for GenerationRegistry" into main
3 files changed, 12 insertions, 12 deletions
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/GenerationRegistry.java b/packages/SettingsProvider/src/com/android/providers/settings/GenerationRegistry.java index 02ec486a0205..cd35f67a1369 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/GenerationRegistry.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/GenerationRegistry.java @@ -45,7 +45,8 @@ final class GenerationRegistry { private static final boolean DEBUG = false; - private final Object mLock; + // This lock is not the same lock used in SettingsProvider and SettingsState + private final Object mLock = new Object(); // Key -> backingStore mapping @GuardedBy("mLock") @@ -74,8 +75,7 @@ final class GenerationRegistry { private final int mMaxNumBackingStore; - GenerationRegistry(Object lock, int maxNumUsers) { - mLock = lock; + GenerationRegistry(int maxNumUsers) { // Add some buffer to maxNumUsers to accommodate corner cases when the actual number of // users in the system exceeds the limit maxNumUsers = maxNumUsers + 2; diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java index 95d7039859b5..5acc1cad160a 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java @@ -2884,7 +2884,7 @@ public class SettingsProvider extends ContentProvider { public SettingsRegistry() { mHandler = new MyHandler(getContext().getMainLooper()); - mGenerationRegistry = new GenerationRegistry(mLock, UserManager.getMaxSupportedUsers()); + mGenerationRegistry = new GenerationRegistry(UserManager.getMaxSupportedUsers()); mBackupManager = new BackupManager(getContext()); } 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 12865f452e22..8029785ba78f 100644 --- a/packages/SettingsProvider/test/src/com/android/providers/settings/GenerationRegistryTest.java +++ b/packages/SettingsProvider/test/src/com/android/providers/settings/GenerationRegistryTest.java @@ -36,7 +36,7 @@ import java.io.IOException; public class GenerationRegistryTest { @Test public void testGenerationsWithRegularSetting() throws IOException { - final GenerationRegistry generationRegistry = new GenerationRegistry(new Object(), 2); + final GenerationRegistry generationRegistry = new GenerationRegistry(2); final int secureKey = SettingsState.makeKey(SettingsState.SETTINGS_TYPE_SECURE, 0); final String testSecureSetting = "test_secure_setting"; Bundle b = new Bundle(); @@ -93,7 +93,7 @@ public class GenerationRegistryTest { @Test public void testGenerationsWithConfigSetting() throws IOException { - final GenerationRegistry generationRegistry = new GenerationRegistry(new Object(), 1); + final GenerationRegistry generationRegistry = new GenerationRegistry(1); final String prefix = "test_namespace/"; final int configKey = SettingsState.makeKey(SettingsState.SETTINGS_TYPE_CONFIG, 0); @@ -110,7 +110,7 @@ public class GenerationRegistryTest { @Test public void testMaxNumBackingStores() throws IOException { - final GenerationRegistry generationRegistry = new GenerationRegistry(new Object(), 2); + final GenerationRegistry generationRegistry = new GenerationRegistry(2); final String testSecureSetting = "test_secure_setting"; Bundle b = new Bundle(); for (int i = 0; i < generationRegistry.getMaxNumBackingStores(); i++) { @@ -133,7 +133,7 @@ public class GenerationRegistryTest { @Test public void testMaxSizeBackingStore() throws IOException { - final GenerationRegistry generationRegistry = new GenerationRegistry(new Object(), 1); + final GenerationRegistry generationRegistry = new GenerationRegistry(1); final int secureKey = SettingsState.makeKey(SettingsState.SETTINGS_TYPE_SECURE, 0); final String testSecureSetting = "test_secure_setting"; Bundle b = new Bundle(); @@ -153,7 +153,7 @@ public class GenerationRegistryTest { @Test public void testUnsetSettings() throws IOException { - final GenerationRegistry generationRegistry = new GenerationRegistry(new Object(), 1); + final GenerationRegistry generationRegistry = new GenerationRegistry(1); final int secureKey = SettingsState.makeKey(SettingsState.SETTINGS_TYPE_SECURE, 0); final String testSecureSetting = "test_secure_setting"; Bundle b = new Bundle(); @@ -172,7 +172,7 @@ public class GenerationRegistryTest { @Test public void testGlobalSettings() throws IOException { - final GenerationRegistry generationRegistry = new GenerationRegistry(new Object(), 2); + final GenerationRegistry generationRegistry = new GenerationRegistry(2); final int globalKey = SettingsState.makeKey(SettingsState.SETTINGS_TYPE_GLOBAL, 0); final String testGlobalSetting = "test_global_setting"; final Bundle b = new Bundle(); @@ -190,11 +190,11 @@ public class GenerationRegistryTest { @Test public void testNumberOfBackingStores() { - GenerationRegistry generationRegistry = new GenerationRegistry(new Object(), 0); + GenerationRegistry generationRegistry = new GenerationRegistry(0); // Test that the capacity of the backing stores is always valid assertThat(generationRegistry.getMaxNumBackingStores()).isEqualTo( GenerationRegistry.MIN_NUM_BACKING_STORE); - generationRegistry = new GenerationRegistry(new Object(), 100); + generationRegistry = new GenerationRegistry(100); // Test that the capacity of the backing stores is always valid assertThat(generationRegistry.getMaxNumBackingStores()).isEqualTo( GenerationRegistry.MAX_NUM_BACKING_STORE); |