summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Bestas <mkbestas@lineageos.org>2020-10-09 18:56:29 +0300
committerMichael Bestas <mkbestas@lineageos.org>2020-12-12 01:23:35 +0200
commitb60bd6cf0eb8679fb1aa95ec860bc5c92f560e42 (patch)
tree67e5cc30a24d72895158d804a1b11fe53d705917
parentc4d7fbe452c347e3801d77c084175ee209884ac5 (diff)
Dialer: handle database downgrade from lineage-16.0
Change-Id: I67a84d8f709d97d66c76cbac30f5bc997ef69c54
-rw-r--r--java/com/android/dialer/database/DialerDatabaseHelper.java28
1 files changed, 28 insertions, 0 deletions
diff --git a/java/com/android/dialer/database/DialerDatabaseHelper.java b/java/com/android/dialer/database/DialerDatabaseHelper.java
index 719492e69..9d2639806 100644
--- a/java/com/android/dialer/database/DialerDatabaseHelper.java
+++ b/java/com/android/dialer/database/DialerDatabaseHelper.java
@@ -280,6 +280,34 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
db.execSQL("ALTER TABLE smartdial_table ADD carrier_presence INTEGER NOT NULL DEFAULT 0");
}
+ @Override
+ public void onDowngrade(SQLiteDatabase db, int oldNumber, int newNumber) {
+ // Disregard the old version and new versions provided by SQLiteOpenHelper, we will read
+ // our own from the database.
+
+ int oldVersion;
+
+ oldVersion = getPropertyAsInt(db, DATABASE_VERSION_PROPERTY, 0);
+
+ if (oldVersion == 0) {
+ LogUtil.e(
+ "DialerDatabaseHelper.onDowngrade", "malformed database version..recreating database");
+ setupTables(db);
+ return;
+ }
+
+ if (oldVersion == 70011) {
+ oldVersion = 10;
+ }
+
+ if (oldVersion != DATABASE_VERSION) {
+ throw new IllegalStateException(
+ "error downgrading the database to version " + DATABASE_VERSION);
+ }
+
+ setProperty(db, DATABASE_VERSION_PROPERTY, String.valueOf(DATABASE_VERSION));
+ }
+
/** Stores a key-value pair in the {@link Tables#PROPERTIES} table. */
public void setProperty(String key, String value) {
setProperty(getWritableDatabase(), key, value);