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

Commit 119285e7 authored by Adam Cohen's avatar Adam Cohen
Browse files

Cleanup orphaned workspace items on db upgrade

-> Any workspace item whose screen id is not present in the
   screens table is removed from the database. This is
   intended to restore database consistency.

issue 13741729

Change-Id: I9a04b4165f1d85541025fcf48ddf2ad9e39ae94e
parent cc95d18d
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ public class LauncherProvider extends ContentProvider {

    private static final String DATABASE_NAME = "launcher.db";

    private static final int DATABASE_VERSION = 17;
    private static final int DATABASE_VERSION = 18;

    static final String OLD_AUTHORITY = "com.android.launcher2.settings";
    static final String AUTHORITY = ProviderConfig.AUTHORITY;
@@ -492,6 +492,13 @@ public class LauncherProvider extends ContentProvider {
                    ");");
        }

        private void removeOrphanedItems(SQLiteDatabase db) {
            db.execSQL("DELETE FROM " + TABLE_FAVORITES + " WHERE " +
                    LauncherSettings.Favorites.SCREEN + " NOT IN (SELECT " +
                    LauncherSettings.WorkspaceScreens._ID + " FROM " + TABLE_WORKSPACE_SCREENS +
                    ")");
        }

        private void setFlagJustLoadedOldDb() {
            String spKey = LauncherAppState.getSharedPreferencesKey();
            SharedPreferences sp = mContext.getSharedPreferences(spKey, Context.MODE_PRIVATE);
@@ -792,6 +799,15 @@ public class LauncherProvider extends ContentProvider {
                version = 17;
            }

            if (version < 18) {
                // Due to a data loss bug, some users may have items associated with screen ids
                // which no longer exist. Since this can cause other problems, and since the user
                // will never see these items anyway, we use database upgrade as an opportunity to
                // clean things up.
                removeOrphanedItems(db);
                version = 18;
            }

            if (version != DATABASE_VERSION) {
                Log.w(TAG, "Destroying all old data.");
                db.execSQL("DROP TABLE IF EXISTS " + TABLE_FAVORITES);