diff options
Diffstat (limited to 'android/src/main')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/MainActivity.kt | 7 | ||||
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadDaemon.kt | 2 | ||||
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadVpnService.kt | 2 | ||||
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/ConnectionProxy.kt | 2 | ||||
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/LocationInfoCache.kt | 16 | ||||
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/talpid/ConnectivityListener.kt | 5 | ||||
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/talpid/util/EventNotifier.kt (renamed from android/src/main/kotlin/net/mullvad/mullvadvpn/util/EventNotifier.kt) | 2 |
7 files changed, 29 insertions, 7 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/MainActivity.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/MainActivity.kt index cfa4f99000..da313c27c1 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/MainActivity.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/MainActivity.kt @@ -22,12 +22,15 @@ import net.mullvad.mullvadvpn.dataproxy.RelayListListener import net.mullvad.mullvadvpn.dataproxy.SettingsListener import net.mullvad.mullvadvpn.dataproxy.WwwAuthTokenRetriever import net.mullvad.mullvadvpn.util.SmartDeferred +import net.mullvad.talpid.ConnectivityListener class MainActivity : FragmentActivity() { companion object { val KEY_SHOULD_CONNECT = "should_connect" } + var connectivityListener = CompletableDeferred<ConnectivityListener>() + private set var daemon = CompletableDeferred<MullvadDaemon>() private set var service = CompletableDeferred<MullvadVpnService.LocalBinder>() @@ -39,7 +42,7 @@ class MainActivity : FragmentActivity() { val problemReport = MullvadProblemReport() var settingsListener = SettingsListener(this) var relayListListener = RelayListListener(this) - val locationInfoCache = LocationInfoCache(daemon, relayListListener) + val locationInfoCache = LocationInfoCache(daemon, connectivityListener, relayListListener) val accountCache = AccountCache(settingsListener, daemon) val wwwAuthTokenRetriever = WwwAuthTokenRetriever(daemon) @@ -55,6 +58,7 @@ class MainActivity : FragmentActivity() { localBinder.resetComplete?.await() service.complete(localBinder) daemon.complete(localBinder.daemon.await()) + connectivityListener.complete(localBinder.connectivityListener) } } @@ -67,6 +71,7 @@ class MainActivity : FragmentActivity() { service = CompletableDeferred<MullvadVpnService.LocalBinder>() daemon = CompletableDeferred<MullvadDaemon>() + connectivityListener = CompletableDeferred<ConnectivityListener>() } } diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadDaemon.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadDaemon.kt index a641b6a940..33e37f278a 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadDaemon.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadDaemon.kt @@ -9,7 +9,7 @@ import net.mullvad.mullvadvpn.model.RelayList import net.mullvad.mullvadvpn.model.RelaySettingsUpdate import net.mullvad.mullvadvpn.model.Settings import net.mullvad.mullvadvpn.model.TunnelState -import net.mullvad.mullvadvpn.util.EventNotifier +import net.mullvad.talpid.util.EventNotifier class MullvadDaemon(val vpnService: MullvadVpnService) { val onSettingsChange = EventNotifier<Settings?>(null) diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadVpnService.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadVpnService.kt index 91bc269ba2..dcbb7f83c5 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadVpnService.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadVpnService.kt @@ -56,6 +56,8 @@ class MullvadVpnService : TalpidVpnService() { get() = this@MullvadVpnService.daemon val connectionProxy get() = this@MullvadVpnService.connectionProxy + val connectivityListener + get() = this@MullvadVpnService.connectivityListener val resetComplete get() = this@MullvadVpnService.resetComplete diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/ConnectionProxy.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/ConnectionProxy.kt index ee429ca18d..04ab9f96ba 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/ConnectionProxy.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/ConnectionProxy.kt @@ -13,8 +13,8 @@ import kotlinx.coroutines.launch import net.mullvad.mullvadvpn.MainActivity import net.mullvad.mullvadvpn.MullvadDaemon import net.mullvad.mullvadvpn.model.TunnelState -import net.mullvad.mullvadvpn.util.EventNotifier import net.mullvad.talpid.tunnel.ActionAfterDisconnect +import net.mullvad.talpid.util.EventNotifier val ANTICIPATED_STATE_TIMEOUT_MS = 1500L diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/LocationInfoCache.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/LocationInfoCache.kt index 0057f034d8..9c9e339541 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/LocationInfoCache.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/LocationInfoCache.kt @@ -12,15 +12,25 @@ import net.mullvad.mullvadvpn.model.TunnelState import net.mullvad.mullvadvpn.relaylist.Relay import net.mullvad.mullvadvpn.relaylist.RelayCity import net.mullvad.mullvadvpn.relaylist.RelayCountry +import net.mullvad.talpid.ConnectivityListener import net.mullvad.talpid.tunnel.ActionAfterDisconnect class LocationInfoCache( val daemon: Deferred<MullvadDaemon>, + val connectivityListener: Deferred<ConnectivityListener>, val relayListListener: RelayListListener ) { private var lastKnownRealLocation: GeoIpLocation? = null private var activeFetch: Job? = null + private val connectivityListenerId = GlobalScope.async(Dispatchers.Default) { + connectivityListener.await().connectivityNotifier.subscribe { isConnected -> + if (isConnected) { + fetchLocation() + } + } + } + var onNewLocation: ((GeoIpLocation?) -> Unit)? = null set(value) { field = value @@ -112,10 +122,10 @@ class LocationInfoCache( daemon.await().getCurrentLocation() } - private fun shouldRetryFetch(): Boolean { + private suspend fun shouldRetryFetch(): Boolean { val state = this.state - return state is TunnelState.Disconnected || - state is TunnelState.Connected + return connectivityListener.await().isConnected && + (state is TunnelState.Disconnected || state is TunnelState.Connected) } } diff --git a/android/src/main/kotlin/net/mullvad/talpid/ConnectivityListener.kt b/android/src/main/kotlin/net/mullvad/talpid/ConnectivityListener.kt index f0b6e2e923..44f511f22a 100644 --- a/android/src/main/kotlin/net/mullvad/talpid/ConnectivityListener.kt +++ b/android/src/main/kotlin/net/mullvad/talpid/ConnectivityListener.kt @@ -7,8 +7,11 @@ import android.content.IntentFilter import android.net.ConnectivityManager import android.net.NetworkInfo import android.net.NetworkInfo.DetailedState +import net.mullvad.talpid.util.EventNotifier class ConnectivityListener : BroadcastReceiver() { + val connectivityNotifier = EventNotifier(true) + var isConnected = true private set(value) { field = value @@ -16,6 +19,8 @@ class ConnectivityListener : BroadcastReceiver() { if (senderAddress != 0L) { notifyConnectivityChange(value, senderAddress) } + + connectivityNotifier.notify(value) } var senderAddress = 0L diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/util/EventNotifier.kt b/android/src/main/kotlin/net/mullvad/talpid/util/EventNotifier.kt index ca45ca96e6..41cf1a7b3e 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/util/EventNotifier.kt +++ b/android/src/main/kotlin/net/mullvad/talpid/util/EventNotifier.kt @@ -1,4 +1,4 @@ -package net.mullvad.mullvadvpn.util +package net.mullvad.talpid.util class EventNotifier<T>(private val initialValue: T) { private val listeners = HashMap<Int, (T) -> Unit>() |
