From b60bd6cf0eb8679fb1aa95ec860bc5c92f560e42 Mon Sep 17 00:00:00 2001 From: Michael Bestas Date: Fri, 9 Oct 2020 18:56:29 +0300 Subject: Dialer: handle database downgrade from lineage-16.0 Change-Id: I67a84d8f709d97d66c76cbac30f5bc997ef69c54 --- .../dialer/database/DialerDatabaseHelper.java | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'java') 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); -- cgit v1.2.3