summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt7
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ConnectionProxy.kt18
2 files changed, 7 insertions, 18 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt
index 3f85bd58e0..bab7bcf3ce 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt
@@ -17,11 +17,11 @@ class MullvadDaemon(val vpnService: MullvadVpnService) {
protected var daemonInterfaceAddress = 0L
val onSettingsChange = EventNotifier<Settings?>(null)
+ var onTunnelStateChange = EventNotifier<TunnelState>(TunnelState.Disconnected)
var onAppVersionInfoChange: ((AppVersionInfo) -> Unit)? = null
var onKeygenEvent: ((KeygenEvent) -> Unit)? = null
var onRelayListChange: ((RelayList) -> Unit)? = null
- var onTunnelStateChange: ((TunnelState) -> Unit)? = null
var onDaemonStopped: (() -> Unit)? = null
init {
@@ -29,6 +29,7 @@ class MullvadDaemon(val vpnService: MullvadVpnService) {
initialize(vpnService, vpnService.cacheDir.absolutePath, vpnService.filesDir.absolutePath)
onSettingsChange.notify(getSettings())
+ onTunnelStateChange.notify(getState() ?: TunnelState.Disconnected)
}
fun connect() {
@@ -133,11 +134,11 @@ class MullvadDaemon(val vpnService: MullvadVpnService) {
fun onDestroy() {
onSettingsChange.unsubscribeAll()
+ onTunnelStateChange.unsubscribeAll()
onAppVersionInfoChange = null
onKeygenEvent = null
onRelayListChange = null
- onTunnelStateChange = null
onDaemonStopped = null
deinitialize()
@@ -205,7 +206,7 @@ class MullvadDaemon(val vpnService: MullvadVpnService) {
}
private fun notifyTunnelStateEvent(event: TunnelState) {
- onTunnelStateChange?.invoke(event)
+ onTunnelStateChange.notify(event)
}
private fun notifyDaemonStopped() {
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ConnectionProxy.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ConnectionProxy.kt
index a625531c63..94cc9f05b8 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ConnectionProxy.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ConnectionProxy.kt
@@ -6,7 +6,6 @@ import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.ClosedReceiveChannelException
import kotlinx.coroutines.channels.actor
import kotlinx.coroutines.channels.sendBlocking
-import kotlinx.coroutines.launch
import net.mullvad.mullvadvpn.ipc.Event
import net.mullvad.mullvadvpn.ipc.Request
import net.mullvad.mullvadvpn.model.TunnelState
@@ -23,8 +22,6 @@ class ConnectionProxy(val vpnPermission: VpnPermission, endpoint: ServiceEndpoin
private val daemon = endpoint.intermittentDaemon
private val initialState = TunnelState.Disconnected
- private val fetchInitialStateJob = fetchInitialState()
-
var onStateChange = EventNotifier<TunnelState>(initialState)
var state by onStateChange.notifiable()
@@ -32,7 +29,9 @@ class ConnectionProxy(val vpnPermission: VpnPermission, endpoint: ServiceEndpoin
init {
daemon.registerListener(this) { newDaemon ->
- newDaemon?.onTunnelStateChange = { newState -> state = newState }
+ newDaemon?.onTunnelStateChange?.subscribe(this@ConnectionProxy) { newState ->
+ state = newState
+ }
}
onStateChange.subscribe(this) { tunnelState ->
@@ -60,7 +59,6 @@ class ConnectionProxy(val vpnPermission: VpnPermission, endpoint: ServiceEndpoin
fun onDestroy() {
commandChannel.close()
- fetchInitialStateJob.cancel()
onStateChange.unsubscribeAll()
daemon.unregisterListener(this)
}
@@ -83,14 +81,4 @@ class ConnectionProxy(val vpnPermission: VpnPermission, endpoint: ServiceEndpoin
// Closed sender, so stop the actor
}
}
-
- private fun fetchInitialState() = GlobalScope.launch(Dispatchers.Default) {
- val currentState = daemon.await().getState()
-
- synchronized(this) {
- if (state === initialState && currentState != null) {
- state = currentState
- }
- }
- }
}