diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-10-04 00:34:51 +0000 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2019-10-07 16:24:41 +0200 |
| commit | 644a3336a05fab71d4ee04fa456f7770c035fff6 (patch) | |
| tree | a39f11a3bdb18a88d4237c06c17c67a739fc882e | |
| parent | 35e9f4028719c010a3d9551acb8b0049d7228184 (diff) | |
| download | mullvadvpn-644a3336a05fab71d4ee04fa456f7770c035fff6.tar.xz mullvadvpn-644a3336a05fab71d4ee04fa456f7770c035fff6.zip | |
Remove `AppVersionInfoFetcher`
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadVpnService.kt | 4 | ||||
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/AppVersionInfoFetcher.kt | 69 |
2 files changed, 0 insertions, 73 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadVpnService.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadVpnService.kt index e36c184bfe..388e4c0a5d 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadVpnService.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadVpnService.kt @@ -10,7 +10,6 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.async import kotlinx.coroutines.runBlocking -import net.mullvad.mullvadvpn.dataproxy.AppVersionInfoFetcher import net.mullvad.mullvadvpn.dataproxy.ConnectionProxy import net.mullvad.mullvadvpn.model.TunConfig @@ -23,7 +22,6 @@ class MullvadVpnService : VpnService() { private lateinit var daemon: Deferred<MullvadDaemon> private lateinit var connectionProxy: ConnectionProxy private lateinit var notificationManager: ForegroundNotificationManager - private lateinit var versionInfoFetcher: AppVersionInfoFetcher override fun onCreate() { setUp() @@ -95,7 +93,6 @@ class MullvadVpnService : VpnService() { daemon = startDaemon() connectionProxy = ConnectionProxy(this, daemon) notificationManager = startNotificationManager() - versionInfoFetcher = AppVersionInfoFetcher(daemon, this) } private fun startDaemon() = GlobalScope.async(Dispatchers.Default) { @@ -130,6 +127,5 @@ class MullvadVpnService : VpnService() { private fun tearDown() { connectionProxy.onDestroy() notificationManager.onDestroy() - versionInfoFetcher.stop() } } diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/AppVersionInfoFetcher.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/AppVersionInfoFetcher.kt deleted file mode 100644 index f067660ee5..0000000000 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/AppVersionInfoFetcher.kt +++ /dev/null @@ -1,69 +0,0 @@ -package net.mullvad.mullvadvpn.dataproxy - -import android.content.Context -import java.util.Calendar -import kotlinx.coroutines.Deferred -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.delay -import kotlinx.coroutines.launch -import net.mullvad.mullvadvpn.MullvadDaemon - -val ONE_DAY_IN_MILLISECONDS = 24L * 60L * 60L * 1000L -val ONE_MINUTE_IN_MILLISECONDS = 60L * 1000L - -class AppVersionInfoFetcher(val daemon: Deferred<MullvadDaemon>, val context: Context) { - private val preferences = - context.getSharedPreferences(AppVersionInfoCache.SHARED_PREFERENCES, Context.MODE_PRIVATE) - - private val mainLoop = run() - - fun stop() { - mainLoop.cancel() - } - - private fun run() = GlobalScope.launch(Dispatchers.Default) { - while (true) { - delay(calculateDelay()) - fetch() - } - } - - private fun calculateDelay(): Long { - val now = Calendar.getInstance().timeInMillis - val lastUpdated = preferences.getLong(AppVersionInfoCache.KEY_LAST_UPDATED, 0) - val delta = now - lastUpdated - - if (delta < 0 || delta >= ONE_DAY_IN_MILLISECONDS) { - return 0 - } else { - return ONE_DAY_IN_MILLISECONDS - delta - } - } - - private suspend fun fetch() { - var now = Calendar.getInstance().timeInMillis - var versionInfo = daemon.await().getVersionInfo() - var attempt = 0 - - while (attempt < 5 && versionInfo == null) { - delay(ONE_MINUTE_IN_MILLISECONDS) - now = Calendar.getInstance().timeInMillis - versionInfo = daemon.await().getVersionInfo() - attempt += 1 - } - - if (versionInfo != null) { - preferences.edit().apply { - with(AppVersionInfoCache) { - putLong(KEY_LAST_UPDATED, now) - putBoolean(KEY_CURRENT_IS_SUPPORTED, versionInfo.currentIsSupported) - putBoolean(KEY_CURRENT_IS_OUTDATED, versionInfo.currentIsOutdated) - putString(KEY_LATEST_STABLE, versionInfo.latestStable) - putString(KEY_LATEST, versionInfo.latest) - commit() - } - } - } - } -} |
