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

Commit bf2ef617 authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Reorder migration of settings from db to xml

Make sure we commit the Global table last, so that if the
runtime was restarted before the others were written, we don't
get into an inconsistent state of migration.

Not sure if this fixes the following bug, but it's one thing
that stood out as a possibility.

Bug: 27335488
Change-Id: I4166a157e9ff542b1d5e32797693417375e40581
parent 19df1284
Loading
Loading
Loading
Loading
+18 −14
Original line number Original line Diff line number Diff line
@@ -1671,16 +1671,16 @@ public class SettingsProvider extends ContentProvider {


        private void migrateLegacySettingsForUserLocked(DatabaseHelper dbHelper,
        private void migrateLegacySettingsForUserLocked(DatabaseHelper dbHelper,
                SQLiteDatabase database, int userId) {
                SQLiteDatabase database, int userId) {
            // Move over the global settings if owner.
            // Move over the system settings.
            if (userId == UserHandle.USER_SYSTEM) {
            final int systemKey = makeKey(SETTINGS_TYPE_SYSTEM, userId);
                final int globalKey = makeKey(SETTINGS_TYPE_GLOBAL, userId);
            ensureSettingsStateLocked(systemKey);
                ensureSettingsStateLocked(globalKey);
            SettingsState systemSettings = mSettingsStates.get(systemKey);
                SettingsState globalSettings = mSettingsStates.get(globalKey);
            migrateLegacySettingsLocked(systemSettings, database, TABLE_SYSTEM);
                migrateLegacySettingsLocked(globalSettings, database, TABLE_GLOBAL);
            systemSettings.persistSyncLocked();
                globalSettings.persistSyncLocked();
            }


            // Move over the secure settings.
            // Move over the secure settings.
            // Do this after System settings, since this is the first thing we check when deciding
            // to skip over migration from db to xml for a secondary user.
            final int secureKey = makeKey(SETTINGS_TYPE_SECURE, userId);
            final int secureKey = makeKey(SETTINGS_TYPE_SECURE, userId);
            ensureSettingsStateLocked(secureKey);
            ensureSettingsStateLocked(secureKey);
            SettingsState secureSettings = mSettingsStates.get(secureKey);
            SettingsState secureSettings = mSettingsStates.get(secureKey);
@@ -1688,12 +1688,16 @@ public class SettingsProvider extends ContentProvider {
            ensureSecureSettingAndroidIdSetLocked(secureSettings);
            ensureSecureSettingAndroidIdSetLocked(secureSettings);
            secureSettings.persistSyncLocked();
            secureSettings.persistSyncLocked();


            // Move over the system settings.
            // Move over the global settings if owner.
            final int systemKey = makeKey(SETTINGS_TYPE_SYSTEM, userId);
            // Do this last, since this is the first thing we check when deciding
            ensureSettingsStateLocked(systemKey);
            // to skip over migration from db to xml for owner user.
            SettingsState systemSettings = mSettingsStates.get(systemKey);
            if (userId == UserHandle.USER_SYSTEM) {
            migrateLegacySettingsLocked(systemSettings, database, TABLE_SYSTEM);
                final int globalKey = makeKey(SETTINGS_TYPE_GLOBAL, userId);
            systemSettings.persistSyncLocked();
                ensureSettingsStateLocked(globalKey);
                SettingsState globalSettings = mSettingsStates.get(globalKey);
                migrateLegacySettingsLocked(globalSettings, database, TABLE_GLOBAL);
                globalSettings.persistSyncLocked();
            }


            // Drop the database as now all is moved and persisted.
            // Drop the database as now all is moved and persisted.
            if (DROP_DATABASE_ON_MIGRATION) {
            if (DROP_DATABASE_ON_MIGRATION) {