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

Commit 5ea4ae77 authored by Abhishek Aggarwal's avatar Abhishek Aggarwal Committed by Bharath
Browse files

sdk: Account for lineage modification while downgrading as well

parent d3fce9f5
Loading
Loading
Loading
Loading
+24 −19
Original line number Diff line number Diff line
@@ -390,25 +390,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;
        }
@@ -446,6 +428,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,
@@ -478,6 +461,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) {