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

Commit 1ccdd12f authored by Rohit Sekhar's avatar Rohit Sekhar
Browse files

Merge branch '3712-q-downgradeDB' into 'v1-q'

LineageDatabaseHelper: Downgrade DB_VERSION to 13

See merge request !70
parents 689e7a74 7c75a4b0
Loading
Loading
Loading
Loading
+40 −49
Original line number Diff line number Diff line
@@ -49,8 +49,6 @@ public class LineageDatabaseHelper extends SQLiteOpenHelper{

    private static final String DATABASE_NAME = "lineagesettings.db";
    private static final int DATABASE_VERSION = 13;
    private static final int E_DB_INCREMENT = 2;
    private static final int E_DATABASE_VERSION = DATABASE_VERSION+E_DB_INCREMENT;

    private static final String DATABASE_NAME_OLD = "cmsettings.db";

@@ -141,7 +139,7 @@ public class LineageDatabaseHelper extends SQLiteOpenHelper{
     * @param userId
     */
    public LineageDatabaseHelper(Context context, int userId) {
        super(context, dbNameForUser(context, userId, DATABASE_NAME), null, E_DATABASE_VERSION);
        super(context, dbNameForUser(context, userId, DATABASE_NAME), null, DATABASE_VERSION);
        mContext = context;
        mUserHandle = userId;

@@ -198,12 +196,9 @@ public class LineageDatabaseHelper extends SQLiteOpenHelper{

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.d(TAG, "Upgrading from version: " + oldVersion + " to " + newVersion);
        if (LOCAL_LOGV) Log.d(TAG, "Upgrading from version: " + oldVersion + " to " + newVersion);
        int upgradeVersion = oldVersion;
        int eUpgradeVersion = oldVersion;
        if(upgradeVersion>13){
            upgradeVersion = upgradeVersion - E_DB_INCREMENT; //to respect lineage version
	}

        if (upgradeVersion < 2) {
            db.beginTransaction();
            try {
@@ -337,7 +332,7 @@ public class LineageDatabaseHelper extends SQLiteOpenHelper{

                    if (value == 0) {
                        stmt = db.compileStatement("UPDATE system SET value=? WHERE name=?");
                        stmt.bindLong(1, 1);
                        stmt.bindLong(1, 2);
                        stmt.bindString(2, LineageSettings.System.STATUS_BAR_CLOCK);
                        stmt.execute();
                    }
@@ -451,49 +446,45 @@ public class LineageDatabaseHelper extends SQLiteOpenHelper{
            }
            upgradeVersion = 13;
        }
        if(upgradeVersion > eUpgradeVersion)
            eUpgradeVersion = upgradeVersion;
        if (eUpgradeVersion < 14) {
            // not doing anything anymore 
            eUpgradeVersion = 14;
        // *** Remember to update DATABASE_VERSION above!
    }
        if (eUpgradeVersion < 15) {

    @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) {
                // Update STATUS_BAR_CLOCK because was centered by db 14 before (not in code anymore)
                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, LineageSettings.System.STATUS_BAR_CLOCK);
                    stmt.execute();
                    db.setTransactionSuccessful();
                } catch (SQLiteDoneException ex) {
                    // LineageSettings.System.STATUS_BAR_CLOCK is not set
                } finally {
                    if (stmt != null) stmt.close();
                    db.endTransaction();
                }
                
                // Update STATUS_BAR_BATTERY_STYLE because was displayed as text by db 14 before (not in code anymore)
                db.beginTransaction();
                stmt = null;
                try {
                    stmt = db.compileStatement("UPDATE system SET value=? WHERE name=?");
                            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, LineageSettings.System.STATUS_BAR_BATTERY_STYLE);
                            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();
                    }
                }
            eUpgradeVersion = 15;
            }
        // *** Remember to update DATABASE_VERSION above!
        }
    }

    private void moveSettingsToNewTable(SQLiteDatabase db,