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

Commit 8bd1eee7 authored by Abhishek Aggarwal's avatar Abhishek Aggarwal
Browse files

sdk: Account for lineage modification while downgrading as well

parent 2c14f8e5
Loading
Loading
Loading
Loading
+24 −19
Original line number Diff line number Diff line
@@ -437,25 +437,7 @@ public class LineageDatabaseHelper extends SQLiteOpenHelper{
        if (upgradeVersion < 14) {
            // Update button/keyboard brightness range
            if (mUserHandle == UserHandle.USER_OWNER) {
                for (String key : new String[] {
                    LineageSettings.Secure.BUTTON_BRIGHTNESS,
                    LineageSettings.Secure.KEYBOARD_BRIGHTNESS,
                }) {
                    db.beginTransaction();
                    SQLiteStatement stmt = null;
                    try {
                        stmt = db.compileStatement(
                                "UPDATE secure SET value=round(value / 255.0, 2) WHERE name=?");
                        stmt.bindString(1, key);
                        stmt.execute();
                        db.setTransactionSuccessful();
                    } catch (SQLiteDoneException ex) {
                        // key is not set
                    } finally {
                        if (stmt != null) stmt.close();
                        db.endTransaction();
                    }
                }
                migrateDbTo14(db);
            }
            upgradeVersion = 14;
        }
@@ -468,6 +450,7 @@ public class LineageDatabaseHelper extends SQLiteOpenHelper{

        if(oldVersion == 14) {
            if (mUserHandle == UserHandle.USER_OWNER) {
                migrateDbTo14(db);
                for (String key : new String[] {
                    LineageSettings.System.STATUS_BAR_CLOCK,
                    LineageSettings.System.STATUS_BAR_BATTERY_STYLE,
@@ -500,6 +483,28 @@ public class LineageDatabaseHelper extends SQLiteOpenHelper{
        }
    }

    private void migrateDbTo14(SQLiteDatabase db) {
        for (String key : new String[] {
            LineageSettings.Secure.BUTTON_BRIGHTNESS,
            LineageSettings.Secure.KEYBOARD_BRIGHTNESS,
        }) {
            db.beginTransaction();
            SQLiteStatement stmt = null;
            try {
                stmt = db.compileStatement(
                        "UPDATE secure SET value=round(value / 255.0, 2) WHERE name=?");
                stmt.bindString(1, key);
                stmt.execute();
                db.setTransactionSuccessful();
            } catch (SQLiteDoneException ex) {
                // key is not set
            } finally {
                if (stmt != null) stmt.close();
                db.endTransaction();
            }
        }
    }

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