diff options
Diffstat (limited to 'android')
3 files changed, 21 insertions, 14 deletions
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 a521bcebfd..842a7bdf80 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/LocationInfoCache.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/LocationInfoCache.kt @@ -11,6 +11,7 @@ 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.mullvadvpn.relaylist.RelayItem import net.mullvad.mullvadvpn.service.MullvadDaemon import net.mullvad.talpid.ConnectivityListener import net.mullvad.talpid.tunnel.ActionAfterDisconnect @@ -21,11 +22,11 @@ const val MAX_RETRIES: Int = 17 // ceil(log2(MAX_DELAY / DELAY_SCALE) + 1) class LocationInfoCache( val daemon: MullvadDaemon, - val connectivityListener: ConnectivityListener, - val relayListListener: RelayListListener + val connectivityListener: ConnectivityListener ) { - private var lastKnownRealLocation: GeoIpLocation? = null private var activeFetch: Job? = null + private var lastKnownRealLocation: GeoIpLocation? = null + private var selectedRelayLocation: GeoIpLocation? = null private val connectivityListenerId = connectivityListener.connectivityNotifier.subscribe { isConnected -> @@ -64,40 +65,45 @@ class LocationInfoCache( when (value.actionAfterDisconnect) { ActionAfterDisconnect.Nothing -> location = lastKnownRealLocation ActionAfterDisconnect.Block -> location = null - ActionAfterDisconnect.Reconnect -> location = locationFromSelectedRelay() + ActionAfterDisconnect.Reconnect -> location = selectedRelayLocation } } is TunnelState.Error -> location = null } } + var selectedRelay: RelayItem? = null + set(value) { + if (field != value) { + field = value + updateSelectedRelayLocation(value) + } + } + fun onDestroy() { connectivityListener.connectivityNotifier.unsubscribe(connectivityListenerId) activeFetch?.cancel() } - private fun locationFromSelectedRelay(): GeoIpLocation? { - val relayItem = relayListListener.selectedRelayItem - - when (relayItem) { - is RelayCountry -> return GeoIpLocation(null, null, relayItem.name, null, null) - is RelayCity -> return GeoIpLocation( + private fun updateSelectedRelayLocation(relayItem: RelayItem?) { + selectedRelayLocation = when (relayItem) { + is RelayCountry -> GeoIpLocation(null, null, relayItem.name, null, null) + is RelayCity -> GeoIpLocation( null, null, relayItem.country.name, relayItem.name, null ) - is Relay -> return GeoIpLocation( + is Relay -> GeoIpLocation( null, null, relayItem.city.country.name, relayItem.city.name, relayItem.name ) + else -> null } - - return null } private fun fetchLocation() { diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt index 6c8bfc442d..7f296657a6 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt @@ -86,6 +86,7 @@ class ConnectFragment : ServiceDependentFragment(OnNoService.GoToLaunchScreen) { } relayListListener.onRelayListChange = { _, selectedRelayItem -> + locationInfoCache.selectedRelay = selectedRelayItem switchLocationButton.location = selectedRelayItem } 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 5250f5d42e..630e79dce2 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ServiceConnection.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ServiceConnection.kt @@ -18,7 +18,7 @@ class ServiceConnection(private val service: ServiceInstance, val mainActivity: val appVersionInfoCache = AppVersionInfoCache(mainActivity, daemon, settingsListener) val accountCache = AccountCache(settingsListener, daemon) var relayListListener = RelayListListener(daemon, settingsListener) - val locationInfoCache = LocationInfoCache(daemon, connectivityListener, relayListListener) + val locationInfoCache = LocationInfoCache(daemon, connectivityListener) init { appVersionInfoCache.onCreate() |
