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

Commit e05b08f7 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Using transaction when dropping tables, so that the DB never enters

an inconsistant state

Bug: 34720697
Change-Id: I55a26d63be6c06622da6ee3395bf1990f1a58a11
parent ea53ca3a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -815,7 +815,7 @@ public class LauncherModel extends BroadcastReceiver
            if (clearDb) {
                Log.d(TAG, "loadWorkspace: resetting launcher database");
                LauncherSettings.Settings.call(contentResolver,
                        LauncherSettings.Settings.METHOD_DELETE_DB);
                        LauncherSettings.Settings.METHOD_CREATE_EMPTY_DB);
            }

            Log.d(TAG, "loadWorkspace: loading default favorites");
+12 −18
Original line number Diff line number Diff line
@@ -406,18 +406,13 @@ public class LauncherProvider extends ContentProvider {
                return result;
            }
            case LauncherSettings.Settings.METHOD_CREATE_EMPTY_DB: {
                createEmptyDB();
                mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
                return null;
            }
            case LauncherSettings.Settings.METHOD_LOAD_DEFAULT_FAVORITES: {
                loadDefaultFavoritesIfNecessary();
                return null;
            }
            case LauncherSettings.Settings.METHOD_DELETE_DB: {
                // Are you sure? (y/n)
                mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
                return null;
            }
        }
        return null;
    }
@@ -469,13 +464,6 @@ public class LauncherProvider extends ContentProvider {
        values.put(LauncherSettings.ChangeLogColumns.MODIFIED, System.currentTimeMillis());
    }

    /**
     * Clears all the data for a fresh start.
     */
    synchronized private void createEmptyDB() {
        mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
    }

    private void clearFlagEmptyDbCreated() {
        Utilities.getPrefs(getContext()).edit().remove(EMPTY_DATABASE_CREATED).commit();
    }
@@ -518,12 +506,12 @@ public class LauncherProvider extends ContentProvider {

            // There might be some partially restored DB items, due to buggy restore logic in
            // previous versions of launcher.
            createEmptyDB();
            mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
            // Populate favorites table with initial favorites
            if ((mOpenHelper.loadFavorites(mOpenHelper.getWritableDatabase(), loader) <= 0)
                    && usingExternallyProvidedLayout) {
                // Unable to load external layout. Cleanup and load the internal layout.
                createEmptyDB();
                mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
                mOpenHelper.loadFavorites(mOpenHelper.getWritableDatabase(),
                        getDefaultLayoutParser(widgetHost));
            }
@@ -825,9 +813,15 @@ public class LauncherProvider extends ContentProvider {
         * Clears all the data for a fresh start.
         */
        public void createEmptyDB(SQLiteDatabase db) {
            db.beginTransaction();
            try {
                db.execSQL("DROP TABLE IF EXISTS " + Favorites.TABLE_NAME);
                db.execSQL("DROP TABLE IF EXISTS " + WorkspaceScreens.TABLE_NAME);
                onCreate(db);
                db.setTransactionSuccessful();
            } finally {
                db.endTransaction();
            }
        }

        /**
+0 −1
Original line number Diff line number Diff line
@@ -291,7 +291,6 @@ public class LauncherSettings {
        public static final String METHOD_NEW_SCREEN_ID = "generate_new_screen_id";

        public static final String METHOD_CREATE_EMPTY_DB = "create_empty_db";
        public static final String METHOD_DELETE_DB = "delete_db";

        public static final String METHOD_LOAD_DEFAULT_FAVORITES = "load_default_favorites";