summaryrefslogtreecommitdiffhomepage
path: root/android/src/main
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2019-07-25 21:26:13 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2019-07-29 18:42:42 +0000
commit296d0b777a89c5ef72560f4e909f2a6ad612a274 (patch)
tree3e881c3dc90a27e78e7ee47b113535856c066c73 /android/src/main
parentb3696e1cc20430a1f8c640c025fad5511eb6fff0 (diff)
downloadmullvadvpn-296d0b777a89c5ef72560f4e909f2a6ad612a274.tar.xz
mullvadvpn-296d0b777a89c5ef72560f4e909f2a6ad612a274.zip
Use selected relay information when reconnecting
Diffstat (limited to 'android/src/main')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/MainActivity.kt2
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/LocationInfoCache.kt26
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