From 1d87de2e7a9f42677d5f2427a259cccae84ce0b0 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Tue, 28 Mar 2017 16:20:42 +0100 Subject: [PATCH] App update: set the app version on first launch if not already set. The app update broadcast receiver is only called on the first update, not install, which was causing EteSync to think it was updating from version 1 on the first update, doesn't matter which version one was updating from. This fixes it by saving the version on the first run. --- app/src/main/java/com/etesync/syncadapter/App.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/src/main/java/com/etesync/syncadapter/App.java b/app/src/main/java/com/etesync/syncadapter/App.java index 299ab0df..b03c8d62 100644 --- a/app/src/main/java/com/etesync/syncadapter/App.java +++ b/app/src/main/java/com/etesync/syncadapter/App.java @@ -103,6 +103,7 @@ public class App extends Application { reinitCertManager(); reinitLogger(); StrictMode.enableDefaults(); + initPrefVersion(); } public void reinitCertManager() { @@ -230,6 +231,15 @@ public class App extends Application { private final static String PREF_VERSION = "version"; + /** Init the preferences version of the app. + * This is used to initialise the first version if not alrady set. */ + private void initPrefVersion() { + SharedPreferences prefs = getSharedPreferences("app", Context.MODE_PRIVATE); + if (prefs.getInt(PREF_VERSION, 0) == 0) { + prefs.edit().putInt(PREF_VERSION, BuildConfig.VERSION_CODE).apply(); + } + } + private void update(int fromVersion) { App.log.info("Updating from version " + fromVersion + " to " + BuildConfig.VERSION_CODE);