Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4fa3577b authored by Song Chun Fan's avatar Song Chun Fan Committed by Android (Google) Code Review
Browse files

Merge "[SettingsProvider] minor refactor: use a separate lock for GenerationRegistry" into main

parents 0f0a9504 dbf9f65f
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -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;
+1 −1
Original line number Diff line number Diff line
@@ -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());
        }

+8 −8
Original line number Diff line number Diff line
@@ -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);