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.
pull/5/head
Tom Hacohen 7 years ago
parent 784070c27c
commit 1d87de2e7a

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

Loading…
Cancel
Save