From 5eb368c630cf5cddfa2eb9ff48778aa07b7beb62 Mon Sep 17 00:00:00 2001 From: Simon Redman Date: Wed, 12 Dec 2018 19:02:28 -0700 Subject: [PATCH] Add incremental notifications plugin settings database upgrade Summary: When upgrading the app to the version with the new privacy options (D17126), the app will crash with some error about missing a table in the Notifications Plugin database. This patch adds the table in onUpgrade in a proper way. Test Plan: - Build current app from master - Disable some apps in the Notifications plugin - Apply this patch (as well as its dependency, D17126) - The app should work, with your old settings, and now able to toggle privacy options! Reviewers: #kde_connect, albertvaka Reviewed By: #kde_connect, albertvaka Differential Revision: https://phabricator.kde.org/D17521 --- .../NotificationsPlugin/AppDatabase.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/AppDatabase.java b/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/AppDatabase.java index 52563397..351b82d9 100644 --- a/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/AppDatabase.java +++ b/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/AppDatabase.java @@ -40,7 +40,7 @@ class AppDatabase { private static final String SETTINGS_NAME = "app_database"; private static final String SETTINGS_KEY_ALL_ENABLED = "all_enabled"; - private static final int DATABASE_VERSION = 4; + private static final int DATABASE_VERSION = 5; private static final String DATABASE_NAME = "Applications"; private static final String TABLE_ENABLED = "Applications"; private static final String TABLE_PRIVACY = "PrivacyOpts"; @@ -49,6 +49,14 @@ class AppDatabase { private static final String KEY_PRIVACY_OPTIONS = "privacyOptions"; + private static final String DATABASE_CREATE_ENABLED = "CREATE TABLE " + + TABLE_ENABLED + "(" + KEY_PACKAGE_NAME + " TEXT PRIMARY KEY NOT NULL, " + + KEY_IS_ENABLED + " INTEGER NOT NULL ); "; + private static final String DATABASE_CREATE_PRIVACY_OPTS = "CREATE TABLE " + + TABLE_PRIVACY + "(" + KEY_PACKAGE_NAME + " TEXT PRIMARY KEY NOT NULL, " + + KEY_PRIVACY_OPTIONS + " INTEGER NOT NULL); "; + + private SQLiteDatabase ourDatabase; private DbHelper ourHelper; private SharedPreferences prefs; @@ -77,18 +85,15 @@ class AppDatabase { @Override public void onCreate(SQLiteDatabase db) { - db.execSQL("CREATE TABLE " + TABLE_ENABLED + - "(" + KEY_PACKAGE_NAME + " TEXT PRIMARY KEY NOT NULL, " + - KEY_IS_ENABLED + " INTEGER NOT NULL ); "); - db.execSQL("CREATE TABLE " + TABLE_PRIVACY + - "(" + KEY_PACKAGE_NAME + " TEXT PRIMARY KEY NOT NULL, " + - KEY_PRIVACY_OPTIONS + " INTEGER NOT NULL); "); + db.execSQL(DATABASE_CREATE_ENABLED); + db.execSQL(DATABASE_CREATE_PRIVACY_OPTS); } @Override - public void onUpgrade(SQLiteDatabase db, int i, int i2) { - db.execSQL("DROP TABLE IF EXISTS " + TABLE_ENABLED); - onCreate(db); + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + if (oldVersion < 5) { + db.execSQL(DATABASE_CREATE_PRIVACY_OPTS); + } } }