From 02d5951f8bc7146d1580a1e30f52dbb877e036b9 Mon Sep 17 00:00:00 2001 From: Mygod Date: Wed, 14 Sep 2016 22:37:26 +0800 Subject: [PATCH] Auto reset when downgrading While it's theoretically impossible to downgrade without reinstalling the app, there are ways to bypass this mechanism. And don't forget users can restore their app data as well. --- .../com/github/shadowsocks/Shadowsocks.scala | 4 ++-- .../github/shadowsocks/ShadowsocksSettings.scala | 15 ++++++--------- .../com/github/shadowsocks/utils/Constants.scala | 1 + 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala index 61efd0eb..90abd27b 100644 --- a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala +++ b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala @@ -186,8 +186,8 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext { snackbar.show } - if (!app.settings.getBoolean(BuildConfig.VERSION_NAME, false)) { - app.editor.putBoolean(BuildConfig.VERSION_NAME, true).apply() + if (app.settings.getInt(Key.currentVersionCode, -1) != BuildConfig.VERSION_CODE) { + app.editor.putInt(Key.currentVersionCode, BuildConfig.VERSION_CODE).apply() recovery() diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala index 394d5a3f..054a6869 100644 --- a/src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala @@ -208,20 +208,17 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan def refreshProfile() { profile = app.currentProfile match { - case Some(profile) => profile - case None => { + case Some(p) => p + case None => app.profileManager.getFirstProfile match { - case Some(profile) => { - app.profileId(profile.id) - profile - } - case None => { + case Some(p) => + app.profileId(p.id) + p + case None => val default = app.profileManager.createDefault() app.profileId(default.id) default - } } - } } isProxyApps.setChecked(profile.proxyApps) } diff --git a/src/main/scala/com/github/shadowsocks/utils/Constants.scala b/src/main/scala/com/github/shadowsocks/utils/Constants.scala index 038b8d46..1b68ed5d 100644 --- a/src/main/scala/com/github/shadowsocks/utils/Constants.scala +++ b/src/main/scala/com/github/shadowsocks/utils/Constants.scala @@ -173,6 +173,7 @@ object Key { val kcpcli = "kcpcli" val tfo = "tcp_fastopen" + val currentVersionCode = "currentVersionCode" } object State {