diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-12-02 18:33:58 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2021-03-25 18:19:58 +0000 |
| commit | 64bb5ee9cb77ffcbc14cf6ceae0654b1fca55a0d (patch) | |
| tree | e8a13e3f6adec486e9790d6438e7b1d3f40abdd6 | |
| parent | 9fcc829c2b8a278979e88073c83c88856be49d6a (diff) | |
| download | mullvadvpn-64bb5ee9cb77ffcbc14cf6ceae0654b1fca55a0d.tar.xz mullvadvpn-64bb5ee9cb77ffcbc14cf6ceae0654b1fca55a0d.zip | |
Allow changing source of tunnel state events
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/service/LocationInfoCache.kt | 12 | ||||
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/service/ServiceInstance.kt | 4 |
2 files changed, 9 insertions, 7 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/LocationInfoCache.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/LocationInfoCache.kt index cc325d3231..c0116e9ef7 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/LocationInfoCache.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/LocationInfoCache.kt @@ -20,9 +20,9 @@ import net.mullvad.mullvadvpn.util.ExponentialBackoff import net.mullvad.mullvadvpn.util.Intermittent import net.mullvad.talpid.ConnectivityListener import net.mullvad.talpid.tunnel.ActionAfterDisconnect +import net.mullvad.talpid.util.autoSubscribable class LocationInfoCache( - val connectionProxy: ConnectionProxy, val connectivityListener: ConnectivityListener, val daemon: Intermittent<MullvadDaemon> ) { @@ -68,6 +68,10 @@ class LocationInfoCache( } } + var stateEvents by autoSubscribable<TunnelState>(this, TunnelState.Disconnected) { newState -> + state = newState + } + var selectedRelay by observable<RelayItem?>(null) { _, oldRelay, newRelay -> if (newRelay != oldRelay) { updateSelectedRelayLocation(newRelay) @@ -80,15 +84,11 @@ class LocationInfoCache( fetchRequestChannel.sendBlocking(RequestFetch.ForRealLocation) } } - - connectionProxy.onStateChange.subscribe(this) { realState -> - state = realState - } } fun onDestroy() { connectivityListener.connectivityNotifier.unsubscribe(this) - connectionProxy.onStateChange.unsubscribe(this) + stateEvents = null fetchRequestChannel.close() onNewLocation = null diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ServiceInstance.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ServiceInstance.kt index f65cc3ecb2..3bd6e479fb 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ServiceInstance.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ServiceInstance.kt @@ -19,7 +19,9 @@ class ServiceInstance( val keyStatusListener = KeyStatusListener(daemon) val locationInfoCache = - LocationInfoCache(connectionProxy, connectivityListener, intermittentDaemon) + LocationInfoCache(connectivityListener, intermittentDaemon).apply { + stateEvents = connectionProxy.onStateChange + } fun onDestroy() { accountCache.onDestroy() |
