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

Commit d3fce9f5 authored by Rohit Sekhar's avatar Rohit Sekhar Committed by Bharath
Browse files

LineageDatabaseHelper: Override onDowngrade()

* We had previously bumped the DB_VERSION to:
  - 14 (which set STATUS_BAR_CLOCK to 1 and STATUS_BAR_BATTERY_STYLE to 2)
  - 15 (which set STATUS_BAR_CLOCK to 2 and STATUS_BAR_BATTERY_STYLE to 0)
    DB_VERSION 15 is essentially reverting to version 13, and undoing the changes that version 14 did.

* Our R based builds follow upstream (which bumped the DB_VERSION to 14, from 13 on lineage-17.1)
  This breaks boot, for a user trying to transition with a Q userdata to R.

* At this point in time, it makes sense for us to force downgrade the DB_VERSION to 13, so that our upgrade path is left intact and we can follow upstream from R as well.
parent 7e5642ae
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
@@ -440,6 +440,44 @@ public class LineageDatabaseHelper extends SQLiteOpenHelper{
        }
    }

    @Override
    public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion){
        if (LOCAL_LOGV) Log.d(TAG, "Downgrading from version: " + oldVersion + " to " + newVersion);

        if(oldVersion == 14) {
            if (mUserHandle == UserHandle.USER_OWNER) {
                for (String key : new String[] {
                    LineageSettings.System.STATUS_BAR_CLOCK,
                    LineageSettings.System.STATUS_BAR_BATTERY_STYLE,
                }) {
                    db.beginTransaction();
                    SQLiteStatement stmt = null;
                    try {
                        stmt = db.compileStatement("UPDATE system SET value=? WHERE name=?");
                        if(key == LineageSettings.System.STATUS_BAR_CLOCK){
                        // Update STATUS_BAR_CLOCK because was centered by db 14 before (not in code anymore)
                            stmt.bindLong(1, 2);
                            stmt.bindString(2, key);
			} else {
                        // Update STATUS_BAR_BATTERY_STYLE because was centered by db 14 before (not in code anymore)
                            stmt.bindLong(1, 0);
                            stmt.bindString(2, key);
                        }
                        stmt.execute();
                        db.setTransactionSuccessful();
                    } catch (SQLiteDoneException ex) {
                        // LineageSettings.System.STATUS_BAR_CLOCK is not set
			//                       OR
                        // LineageSettings.System.STATUS_BAR_BATTERY_STYLE is not set
                    } finally {
                        if (stmt != null) stmt.close();
                        db.endTransaction();
                    }
                }
            }
        }
    }

    private void moveSettingsToNewTable(SQLiteDatabase db,
                                        String sourceTable, String destTable,
                                        String[] settingsToMove, boolean doIgnore) {