diff options
Diffstat (limited to 'android/src')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/MainActivity.kt | 2 | ||||
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/LocationInfoCache.kt | 26 |
2 files changed, 25 insertions, 3 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/MainActivity.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/MainActivity.kt index d16e36a1b6..f5d4d6bd60 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/MainActivity.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/MainActivity.kt @@ -38,10 +38,10 @@ class MainActivity : FragmentActivity() { val connectionProxy = ConnectionProxy(this) val keyStatusListener = KeyStatusListener(daemon) - val locationInfoCache = LocationInfoCache(daemon) val problemReport = MullvadProblemReport() var settingsListener = SettingsListener(this) var relayListListener = RelayListListener(this) + val locationInfoCache = LocationInfoCache(daemon, relayListListener) val accountCache = AccountCache(settingsListener, daemon) private var waitForDaemonJob: Job? = null 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 74745118d3..3884490bcc 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/LocationInfoCache.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/LocationInfoCache.kt @@ -11,8 +11,14 @@ import net.mullvad.mullvadvpn.model.ActionAfterDisconnect import net.mullvad.mullvadvpn.model.GeoIpLocation import net.mullvad.mullvadvpn.model.TunnelState import net.mullvad.mullvadvpn.MullvadDaemon +import net.mullvad.mullvadvpn.relaylist.RelayCity +import net.mullvad.mullvadvpn.relaylist.RelayCountry +import net.mullvad.mullvadvpn.relaylist.Relay -class LocationInfoCache(val daemon: Deferred<MullvadDaemon>) { +class LocationInfoCache( + val daemon: Deferred<MullvadDaemon>, + val relayListListener: RelayListListener +) { private var lastKnownRealLocation: GeoIpLocation? = null private var activeFetch: Job? = null @@ -43,7 +49,7 @@ class LocationInfoCache(val daemon: Deferred<MullvadDaemon>) { when (value.actionAfterDisconnect) { is ActionAfterDisconnect.Nothing -> location = lastKnownRealLocation is ActionAfterDisconnect.Block -> location = null - is ActionAfterDisconnect.Reconnect -> {} // Leave location unchanged + is ActionAfterDisconnect.Reconnect -> location = locationFromSelectedRelay() } } is TunnelState.Blocked -> location = null @@ -59,6 +65,22 @@ class LocationInfoCache(val daemon: Deferred<MullvadDaemon>) { onNewLocation?.invoke(country, city, hostname) } + private fun locationFromSelectedRelay(): GeoIpLocation? { + val relayItem = relayListListener.selectedRelayItem + + when (relayItem) { + is RelayCountry -> return GeoIpLocation(relayItem.name, null, null) + is RelayCity -> return GeoIpLocation(relayItem.country.name, relayItem.name, null) + is Relay -> return GeoIpLocation( + relayItem.city.country.name, + relayItem.city.name, + relayItem.name + ) + } + + return null + } + private fun fetchLocation() { val previousFetch = activeFetch val initialState = state |
