diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-03-13 14:31:11 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-03-13 14:31:11 -0300 |
| commit | d5184944bd375db027eef599e3eeadea479c00fd (patch) | |
| tree | a8f6b84d2e6a86cfea6edc13f43055cebc89d805 | |
| parent | 545462a3638212bad048e01ccfc9ece9914a0195 (diff) | |
| parent | 74cde104bf9799a6c5a26a1ae9059dc37d99a9db (diff) | |
| download | mullvadvpn-d5184944bd375db027eef599e3eeadea479c00fd.tar.xz mullvadvpn-d5184944bd375db027eef599e3eeadea479c00fd.zip | |
Merge branch 'fix-version-info'
4 files changed, 50 insertions, 30 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/AppVersionInfoCache.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/AppVersionInfoCache.kt index a192fb0f75..dab1b0b7ae 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/AppVersionInfoCache.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/AppVersionInfoCache.kt @@ -7,32 +7,59 @@ import kotlinx.coroutines.launch import net.mullvad.mullvadvpn.model.AppVersionInfo import net.mullvad.mullvadvpn.service.MullvadDaemon -class AppVersionInfoCache(val context: Context, val daemon: MullvadDaemon) { +class AppVersionInfoCache( + val context: Context, + val daemon: MullvadDaemon, + val settingsListener: SettingsListener +) { companion object { val LEGACY_SHARED_PREFERENCES = "app_version_info_cache" } private val setUpJob = setUp() + private val settingsListenerId = settingsListener.subscribe { settings -> + showBetaReleases = settings.showBetaReleases ?: false + } + private var appVersionInfo: AppVersionInfo? = null set(value) { synchronized(this) { - upgradeVersion = if (isStable) value?.latestStable else value?.latest + field = value + onUpdate?.invoke() + } + } - if (value != null && upgradeVersion == version) { - upgradeVersion = null + val latestStable + get() = appVersionInfo?.latestStable + val latest + get() = appVersionInfo?.latest + val isSupported + get() = appVersionInfo?.currentIsSupported ?: true - field = AppVersionInfo( - value.currentIsSupported, - /* currentIsOutdated = */ false, - value.latestStable, - value.latest - ) + val isOutdated: Boolean + get() { + if (showBetaReleases) { + return version != null && latest != null && latest != version + } else { + return version != null && latestStable != null && latestStable != version + } + } + + val upgradeVersion: String? + get() { + if (showBetaReleases) { + if (version == latest) { + return null } else { - field = value + return latest + } + } else { + if (version == latestStable) { + return null + } else { + return latestStable } - - onUpdate?.invoke() } } @@ -42,22 +69,16 @@ class AppVersionInfoCache(val context: Context, val daemon: MullvadDaemon) { value?.invoke() } - val latestStable - get() = appVersionInfo?.latestStable - val latest - get() = appVersionInfo?.latest - val isSupported - get() = appVersionInfo?.currentIsSupported ?: true - var isOutdated = false - get() = appVersionInfo?.currentIsOutdated ?: false + var showBetaReleases = false + private set(value) { + if (field != value) { + field = value + onUpdate?.invoke() + } + } var version: String? = null private set - var isStable = true - private set - - var upgradeVersion: String? = null - private set fun onCreate() { context.getSharedPreferences(LEGACY_SHARED_PREFERENCES, Context.MODE_PRIVATE) @@ -68,6 +89,7 @@ class AppVersionInfoCache(val context: Context, val daemon: MullvadDaemon) { fun onDestroy() { setUpJob.cancel() + settingsListener.unsubscribe(settingsListenerId) daemon.onAppVersionInfoChange = null } @@ -75,7 +97,6 @@ class AppVersionInfoCache(val context: Context, val daemon: MullvadDaemon) { val currentVersion = daemon.getCurrentVersion() version = currentVersion - isStable = !currentVersion.contains("-") daemon.onAppVersionInfoChange = { newAppVersionInfo -> appVersionInfo = newAppVersionInfo diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/model/AppVersionInfo.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/model/AppVersionInfo.kt index 5bbdee7589..0c41090f3f 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/model/AppVersionInfo.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/model/AppVersionInfo.kt @@ -2,7 +2,6 @@ package net.mullvad.mullvadvpn.model data class AppVersionInfo( val currentIsSupported: Boolean, - val currentIsOutdated: Boolean, val latestStable: String, val latest: String ) diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ServiceConnection.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ServiceConnection.kt index af4f49efda..5250f5d42e 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ServiceConnection.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ServiceConnection.kt @@ -13,9 +13,9 @@ class ServiceConnection(private val service: ServiceInstance, val mainActivity: val connectionProxy = service.connectionProxy val connectivityListener = service.connectivityListener - val appVersionInfoCache = AppVersionInfoCache(mainActivity, daemon) val keyStatusListener = KeyStatusListener(daemon) val settingsListener = SettingsListener(daemon) + val appVersionInfoCache = AppVersionInfoCache(mainActivity, daemon, settingsListener) val accountCache = AccountCache(settingsListener, daemon) var relayListListener = RelayListListener(daemon, settingsListener) val locationInfoCache = LocationInfoCache(daemon, connectivityListener, relayListListener) diff --git a/mullvad-jni/Cargo.toml b/mullvad-jni/Cargo.toml index 1d5cf6d13b..222268076f 100644 --- a/mullvad-jni/Cargo.toml +++ b/mullvad-jni/Cargo.toml @@ -10,7 +10,7 @@ publish = false [lib] crate_type = ["cdylib"] -[dependencies] +[target.'cfg(target_os = "android")'.dependencies] err-derive = "0.2.1" futures = "0.1" ipnetwork = "0.15" |
