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

Commit 88fecd39 authored by p4r4n01d's avatar p4r4n01d Committed by Gerrit Code Review
Browse files

Wipe and re-create database on downgrade.

Not a very common situation but should fix some errors that could
 arise from flashing an old ROM over a new one, without wiping data.

Change-Id: I27f2a00396761105987830921bb3f8cb339d2171
parent 7d5b16e3
Loading
Loading
Loading
Loading
+31 −19
Original line number Diff line number Diff line
@@ -1566,6 +1566,12 @@ public class DatabaseHelper extends SQLiteOpenHelper {
        if (upgradeVersion != currentVersion) {
            Log.w(TAG, "Got stuck trying to upgrade from version " + upgradeVersion
                    + ", must wipe the settings provider");
            wipeDB(db, oldVersion, upgradeVersion, currentVersion);
        }
    }

    private void wipeDB(SQLiteDatabase db, int oldVersion, int upgradeVersion,
     int currentVersion) {
        db.execSQL("DROP TABLE IF EXISTS global");
        db.execSQL("DROP TABLE IF EXISTS globalIndex1");
        db.execSQL("DROP TABLE IF EXISTS system");
@@ -1586,6 +1592,12 @@ public class DatabaseHelper extends SQLiteOpenHelper {
        db.execSQL("INSERT INTO secure(name,value) values('" +
                "wiped_db_reason" + "','" + wipeReason + "');");
    }

    @Override
    public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // Not much can be done here - wipe database completely and create anew
        // otherwise an exception will be thrown on boot preventing startup.
        wipeDB(db, oldVersion, newVersion, oldVersion);
    }

    private String[] hashsetToStringArray(HashSet<String> set) {