1
0
mirror of https://github.com/etesync/android synced 2024-11-16 04:49:06 +00:00

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.
This commit is contained in:
Tom Hacohen 2017-03-28 16:20:42 +01:00
parent 784070c27c
commit 1d87de2e7a

View File

@ -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);