summaryrefslogtreecommitdiffhomepage
path: root/android/src/main
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-01-25 17:53:07 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-02-11 14:36:18 +0000
commitecc775e5bd9e6289315137e36a93ee5a382bcff7 (patch)
tree365f772344245e5133be693deec5cd9cf5882b1f /android/src/main
parent75f10ce304c949bbd18850f8b474e39c57278618 (diff)
downloadmullvadvpn-ecc775e5bd9e6289315137e36a93ee5a382bcff7.tar.xz
mullvadvpn-ecc775e5bd9e6289315137e36a93ee5a382bcff7.zip
Provide intermittent daemon from `DaemonInstance`
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() {