summaryrefslogtreecommitdiffhomepage
path: root/android/src
diff options
context:
space:
mode:
Diffstat (limited to 'android/src')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Request.kt16
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/CustomDns.kt35
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt4
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt3
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/CustomDns.kt33
5 files changed, 86 insertions, 5 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Request.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Request.kt
index 1937ce424b..fc293e69a3 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Request.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Request.kt
@@ -2,6 +2,7 @@ package net.mullvad.mullvadvpn.ipc
import android.os.Message as RawMessage
import android.os.Messenger
+import java.net.InetAddress
import kotlinx.parcelize.Parcelize
import org.joda.time.DateTime
@@ -10,6 +11,9 @@ sealed class Request : Message.RequestMessage() {
protected override val messageKey = MESSAGE_KEY
@Parcelize
+ data class AddCustomDnsServer(val address: InetAddress) : Request()
+
+ @Parcelize
object Connect : Request()
@Parcelize
@@ -49,6 +53,18 @@ sealed class Request : Message.RequestMessage() {
data class RemoveAccountFromHistory(val account: String?) : Request()
@Parcelize
+ data class RemoveCustomDnsServer(val address: InetAddress) : Request()
+
+ @Parcelize
+ data class ReplaceCustomDnsServer(
+ val oldAddress: InetAddress,
+ val newAddress: InetAddress
+ ) : Request()
+
+ @Parcelize
+ data class SetEnableCustomDns(val enable: Boolean) : Request()
+
+ @Parcelize
data class SetEnableSplitTunneling(val enable: Boolean) : Request()
@Parcelize
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/CustomDns.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/CustomDns.kt
index 447c215e1c..b517d796dc 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/CustomDns.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/CustomDns.kt
@@ -3,17 +3,22 @@ package net.mullvad.mullvadvpn.service
import java.net.InetAddress
import java.util.ArrayList
import kotlin.properties.Delegates.observable
+import kotlinx.coroutines.runBlocking
+import net.mullvad.mullvadvpn.ipc.Request
import net.mullvad.mullvadvpn.model.DnsOptions
-import net.mullvad.mullvadvpn.service.endpoint.SettingsListener
+import net.mullvad.mullvadvpn.service.endpoint.ServiceEndpoint
import net.mullvad.talpid.util.EventNotifier
-class CustomDns(val daemon: MullvadDaemon, val settingsListener: SettingsListener) {
+class CustomDns(private val endpoint: ServiceEndpoint) {
private var enabled by observable(false) { _, oldValue, newValue ->
if (oldValue != newValue) {
onEnabledChanged.notify(newValue)
}
}
+ private val daemon
+ get() = runBlocking { endpoint.intermittentDaemon.await() }
+
private var dnsServers by observable<ArrayList<InetAddress>>(ArrayList()) { _, _, servers ->
onDnsServersChanged.notify(servers.toList())
}
@@ -22,16 +27,38 @@ class CustomDns(val daemon: MullvadDaemon, val settingsListener: SettingsListene
val onDnsServersChanged = EventNotifier<List<InetAddress>>(emptyList())
init {
- settingsListener.dnsOptionsNotifier.subscribe(this) { maybeDnsOptions ->
+ endpoint.settingsListener.dnsOptionsNotifier.subscribe(this) { maybeDnsOptions ->
maybeDnsOptions?.let { dnsOptions ->
enabled = dnsOptions.custom
dnsServers = dnsOptions.addresses
}
}
+
+ endpoint.dispatcher.apply {
+ registerHandler(Request.AddCustomDnsServer::class) { request ->
+ addDnsServer(request.address)
+ }
+
+ registerHandler(Request.RemoveCustomDnsServer::class) { request ->
+ removeDnsServer(request.address)
+ }
+
+ registerHandler(Request.ReplaceCustomDnsServer::class) { request ->
+ replaceDnsServer(request.oldAddress, request.newAddress)
+ }
+
+ registerHandler(Request.SetEnableCustomDns::class) { request ->
+ if (request.enable) {
+ enable()
+ } else {
+ disable()
+ }
+ }
+ }
}
fun onDestroy() {
- settingsListener.dnsOptionsNotifier.unsubscribe(this)
+ endpoint.settingsListener.dnsOptionsNotifier.unsubscribe(this)
}
fun enable() {
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 1d379c5775..64a31ca474 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt
@@ -237,7 +237,9 @@ class MullvadVpnService : TalpidVpnService() {
}
private suspend fun setUpInstance(daemon: MullvadDaemon, settings: Settings) {
- val customDns = CustomDns(daemon, endpoint.settingsListener)
+ val customDns = CustomDns(endpoint)
+
+ endpoint.customDns = customDns
handlePendingAction(settings)
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt
index 1d7ee77763..250d57dee5 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt
@@ -14,6 +14,7 @@ import kotlinx.coroutines.channels.sendBlocking
import net.mullvad.mullvadvpn.ipc.DispatchingHandler
import net.mullvad.mullvadvpn.ipc.Event
import net.mullvad.mullvadvpn.ipc.Request
+import net.mullvad.mullvadvpn.service.CustomDns
import net.mullvad.mullvadvpn.service.MullvadDaemon
import net.mullvad.mullvadvpn.service.persistence.SplitTunnelingPersistence
import net.mullvad.mullvadvpn.util.Intermittent
@@ -44,6 +45,8 @@ class ServiceEndpoint(
val locationInfoCache = LocationInfoCache(this)
val splitTunneling = SplitTunneling(SplitTunnelingPersistence(context), this)
+ var customDns: CustomDns? = null
+
init {
dispatcher.registerHandler(Request.RegisterListener::class) { request ->
registrationQueue.sendBlocking(request.listener)
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/CustomDns.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/CustomDns.kt
index 7b2b506f29..140d1135cd 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/CustomDns.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/CustomDns.kt
@@ -2,6 +2,7 @@ package net.mullvad.mullvadvpn.ui.serviceconnection
import android.os.Messenger
import java.net.InetAddress
+import net.mullvad.mullvadvpn.ipc.Request
import net.mullvad.talpid.util.EventNotifier
class CustomDns(val connection: Messenger, val settingsListener: SettingsListener) {
@@ -19,6 +20,38 @@ class CustomDns(val connection: Messenger, val settingsListener: SettingsListene
}
}
+ fun enable() {
+ connection.send(Request.SetEnableCustomDns(true).message)
+ }
+
+ fun disable() {
+ connection.send(Request.SetEnableCustomDns(false).message)
+ }
+
+ fun addDnsServer(server: InetAddress): Boolean {
+ val alreadyHadServer = onDnsServersChanged.latestEvent.contains(server)
+
+ connection.send(Request.AddCustomDnsServer(server).message)
+
+ return alreadyHadServer
+ }
+
+ fun replaceDnsServer(oldServer: InetAddress, newServer: InetAddress): Boolean {
+ synchronized(this) {
+ val dnsServers = onDnsServersChanged.latestEvent
+ val containsOldServer = dnsServers.contains(oldServer)
+ val replacementIsValid = oldServer == newServer || !dnsServers.contains(newServer)
+
+ connection.send(Request.ReplaceCustomDnsServer(oldServer, newServer).message)
+
+ return containsOldServer && replacementIsValid
+ }
+ }
+
+ fun removeDnsServer(server: InetAddress) {
+ connection.send(Request.RemoveCustomDnsServer(server).message)
+ }
+
fun onDestroy() {
onEnabledChanged.unsubscribeAll()
onDnsServersChanged.unsubscribeAll()