summaryrefslogtreecommitdiffhomepage
path: root/android/src
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-01-04 18:19:49 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-04-12 13:19:37 +0000
commitec8118b9a1dc6a112f1142e6e81b6bbe668dfc24 (patch)
treeae262e751d8c73c3322ed78fc15a2a6f40814e4a /android/src
parent772f9580de1d486db3e547fa459c88610c32a137 (diff)
downloadmullvadvpn-ec8118b9a1dc6a112f1142e6e81b6bbe668dfc24.tar.xz
mullvadvpn-ec8118b9a1dc6a112f1142e6e81b6bbe668dfc24.zip
Use an intermittent daemon in `ConnectionProxy`
Diffstat (limited to 'android/src')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/ConnectionProxy.kt28
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt2
2 files changed, 17 insertions, 13 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ConnectionProxy.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ConnectionProxy.kt
index fc5e6c9366..adbe991673 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ConnectionProxy.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ConnectionProxy.kt
@@ -20,7 +20,7 @@ import net.mullvad.talpid.util.EventNotifier
val ANTICIPATED_STATE_TIMEOUT_MS = 1500L
-class ConnectionProxy(val context: Context, val daemon: MullvadDaemon) {
+class ConnectionProxy(val context: Context, val daemon: Intermittent<MullvadDaemon>) {
private enum class Command {
CONNECT,
RECONNECT,
@@ -48,12 +48,8 @@ class ConnectionProxy(val context: Context, val daemon: MullvadDaemon) {
private val fetchInitialStateJob = fetchInitialState()
init {
- daemon.onTunnelStateChange = { newState ->
- synchronized(this) {
- resetAnticipatedStateJob?.cancel()
- state = newState
- uiState = newState
- }
+ daemon.registerListener(this) { newDaemon ->
+ newDaemon?.onTunnelStateChange = { newState -> handleNewState(newState) }
}
}
@@ -77,12 +73,12 @@ class ConnectionProxy(val context: Context, val daemon: MullvadDaemon) {
fun onDestroy() {
commandChannel.close()
- daemon.onTunnelStateChange = null
onUiStateChange.unsubscribeAll()
onStateChange.unsubscribeAll()
fetchInitialStateJob.cancel()
+ daemon.unregisterListener(this)
}
private fun spawnActor() = GlobalScope.actor<Command>(Dispatchers.Default, Channel.UNLIMITED) {
@@ -94,10 +90,10 @@ class ConnectionProxy(val context: Context, val daemon: MullvadDaemon) {
Command.CONNECT -> {
requestVpnPermission()
vpnPermission.await()
- daemon.connect()
+ daemon.await().connect()
}
- Command.RECONNECT -> daemon.reconnect()
- Command.DISCONNECT -> daemon.disconnect()
+ Command.RECONNECT -> daemon.await().reconnect()
+ Command.DISCONNECT -> daemon.await().disconnect()
}
}
} catch (exception: ClosedReceiveChannelException) {
@@ -105,6 +101,14 @@ class ConnectionProxy(val context: Context, val daemon: MullvadDaemon) {
}
}
+ private fun handleNewState(newState: TunnelState) {
+ synchronized(this) {
+ resetAnticipatedStateJob?.cancel()
+ state = newState
+ uiState = newState
+ }
+ }
+
private fun anticipateConnectingState(): Boolean {
synchronized(this) {
val currentState = uiState
@@ -206,7 +210,7 @@ class ConnectionProxy(val context: Context, val daemon: MullvadDaemon) {
}
private fun fetchInitialState() = GlobalScope.launch(Dispatchers.Default) {
- val currentState = daemon.getState()
+ val currentState = daemon.await().getState()
synchronized(this) {
if (state === initialState && currentState != null) {
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt
index bca3f4956d..132b998156 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt
@@ -230,7 +230,7 @@ class MullvadVpnService : TalpidVpnService() {
}
private suspend fun setUpInstance(daemon: MullvadDaemon, settings: Settings) {
- val connectionProxy = ConnectionProxy(this, daemon)
+ val connectionProxy = ConnectionProxy(this, daemonInstance.intermittentDaemon)
val customDns = CustomDns(daemon, endpoint.settingsListener)
endpoint.splitTunneling.onChange.subscribe(this@MullvadVpnService) { excludedApps ->