summaryrefslogtreecommitdiffhomepage
path: root/android/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'android/src/main')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/DaemonInstance.kt14
1 files changed, 11 insertions, 3 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/DaemonInstance.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/DaemonInstance.kt
index 0e81b87276..6f89462bbe 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/DaemonInstance.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/DaemonInstance.kt
@@ -9,6 +9,7 @@ import kotlinx.coroutines.channels.ClosedReceiveChannelException
import kotlinx.coroutines.channels.ReceiveChannel
import kotlinx.coroutines.channels.actor
import kotlinx.coroutines.channels.sendBlocking
+import net.mullvad.mullvadvpn.util.Intermittent
private const val API_IP_ADDRESS_FILE = "api-ip-address.txt"
private const val RELAYS_FILE = "relays.json"
@@ -21,11 +22,13 @@ class DaemonInstance(val vpnService: MullvadVpnService, val listener: (MullvadDa
private val commandChannel = spawnActor()
- private var daemon by observable<MullvadDaemon?>(null) { _, oldInstance, newInstance ->
+ private var daemon by observable<MullvadDaemon?>(null) { _, oldInstance, _ ->
oldInstance?.onDestroy()
listener(newInstance)
}
+ val intermittentDaemon = Intermittent<MullvadDaemon>()
+
fun start() {
commandChannel.sendBlocking(Command.START)
}
@@ -36,6 +39,7 @@ class DaemonInstance(val vpnService: MullvadVpnService, val listener: (MullvadDa
fun onDestroy() {
commandChannel.close()
+ intermittentDaemon.onDestroy()
}
private fun spawnActor() = GlobalScope.actor<Command>(Dispatchers.Default, Channel.UNLIMITED) {
@@ -91,12 +95,16 @@ class DaemonInstance(val vpnService: MullvadVpnService, val listener: (MullvadDa
}
}
- private fun startDaemon() {
- daemon = MullvadDaemon(vpnService).apply {
+ private suspend fun startDaemon() {
+ val newDaemon = MullvadDaemon(vpnService).apply {
onDaemonStopped = {
+ intermittentDaemon.spawnUpdate(null)
daemon = null
}
}
+
+ daemon = newDaemon
+ intermittentDaemon.update(newDaemon)
}
private fun stopDaemon() {