diff options
| author | Albin <albin@mullvad.net> | 2023-02-08 11:18:37 +0100 |
|---|---|---|
| committer | Albin <albin@mullvad.net> | 2023-02-08 11:18:37 +0100 |
| commit | 0a570d1348eae02474953fababe30d856f323512 (patch) | |
| tree | d6878b972e58b0ac816b31058f89169c9ecd1269 /android | |
| parent | 490570a2a382e18b1999cd01811860a727ddae69 (diff) | |
| parent | 202c1185ba055440987350472cafe905fc7a0a5f (diff) | |
| download | mullvadvpn-0a570d1348eae02474953fababe30d856f323512.tar.xz mullvadvpn-0a570d1348eae02474953fababe30d856f323512.zip | |
Merge branch 'simplify-setting-dns-options'
Diffstat (limited to 'android')
4 files changed, 42 insertions, 0 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Request.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Request.kt index 9584aee506..57dcd1bc98 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Request.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Request.kt @@ -4,6 +4,7 @@ import android.os.Message as RawMessage import android.os.Messenger import java.net.InetAddress import kotlinx.parcelize.Parcelize +import net.mullvad.mullvadvpn.model.DnsOptions import net.mullvad.mullvadvpn.model.LocationConstraint // Requests that the service can handle @@ -11,6 +12,7 @@ sealed class Request : Message.RequestMessage() { protected override val messageKey = MESSAGE_KEY @Parcelize + @Deprecated("Use SetDnsOptions") data class AddCustomDnsServer(val address: InetAddress) : Request() @Parcelize @@ -68,9 +70,11 @@ sealed class Request : Message.RequestMessage() { object ClearAccountHistory : Request() @Parcelize + @Deprecated("Use SetDnsOptions") data class RemoveCustomDnsServer(val address: InetAddress) : Request() @Parcelize + @Deprecated("Use SetDnsOptions") data class ReplaceCustomDnsServer( val oldAddress: InetAddress, val newAddress: InetAddress @@ -83,6 +87,7 @@ sealed class Request : Message.RequestMessage() { data class SetAutoConnect(val autoConnect: Boolean) : Request() @Parcelize + @Deprecated("Use SetDnsOptions") data class SetEnableCustomDns(val enable: Boolean) : Request() @Parcelize @@ -103,6 +108,9 @@ sealed class Request : Message.RequestMessage() { @Parcelize data class VpnPermissionResponse(val isGranted: Boolean) : Request() + @Parcelize + data class SetDnsOptions(val dnsOptions: DnsOptions) : Request() + companion object { private const val MESSAGE_KEY = "request" diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/SettingsRepository.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/SettingsRepository.kt new file mode 100644 index 0000000000..926c3543d3 --- /dev/null +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/SettingsRepository.kt @@ -0,0 +1,13 @@ +package net.mullvad.mullvadvpn.repository + +import net.mullvad.mullvadvpn.model.DnsOptions +import net.mullvad.mullvadvpn.ui.serviceconnection.ServiceConnectionManager +import net.mullvad.mullvadvpn.ui.serviceconnection.customDns + +class SettingsRepository( + private val serviceConnectionManager: ServiceConnectionManager +) { + fun setDnsOptions(dnsOptions: DnsOptions) { + serviceConnectionManager.customDns()?.setDnsOptions(dnsOptions) + } +} diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/CustomDns.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/CustomDns.kt index b2ae560450..62943ee0cb 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/CustomDns.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/CustomDns.kt @@ -15,10 +15,16 @@ import net.mullvad.mullvadvpn.model.DnsState class CustomDns(private val endpoint: ServiceEndpoint) { private sealed class Command { + @Deprecated("Use SetDnsOptions") class AddDnsServer(val server: InetAddress) : Command() + @Deprecated("Use SetDnsOptions") class RemoveDnsServer(val server: InetAddress) : Command() + @Deprecated("Use SetDnsOptions") class ReplaceDnsServer(val oldServer: InetAddress, val newServer: InetAddress) : Command() + @Deprecated("Use SetDnsOptions") class SetEnabled(val enabled: Boolean) : Command() + + class SetDnsOptions(val dnsOptions: DnsOptions) : Command() } private val commandChannel = spawnActor() @@ -56,6 +62,10 @@ class CustomDns(private val endpoint: ServiceEndpoint) { registerHandler(Request.SetEnableCustomDns::class) { request -> commandChannel.trySendBlocking(Command.SetEnabled(request.enable)) } + + registerHandler(Request.SetDnsOptions::class) { request -> + commandChannel.trySendBlocking(Command.SetDnsOptions(request.dnsOptions)) + } } } @@ -76,6 +86,7 @@ class CustomDns(private val endpoint: ServiceEndpoint) { doReplaceDnsServer(command.oldServer, command.newServer) } is Command.SetEnabled -> changeDnsOptions(command.enabled) + is Command.SetDnsOptions -> setDnsOptions(command.dnsOptions) } } } catch (exception: ClosedReceiveChannelException) { @@ -116,4 +127,8 @@ class CustomDns(private val endpoint: ServiceEndpoint) { ) daemon.await().setDnsOptions(options) } + + private suspend fun setDnsOptions(dnsOptions: DnsOptions) { + daemon.await().setDnsOptions(dnsOptions) + } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/CustomDns.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/CustomDns.kt index 8bfc53f226..9d9e235007 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/CustomDns.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/CustomDns.kt @@ -3,7 +3,9 @@ package net.mullvad.mullvadvpn.ui.serviceconnection import android.os.Messenger import java.net.InetAddress import net.mullvad.mullvadvpn.ipc.Request +import net.mullvad.mullvadvpn.model.DnsOptions import net.mullvad.mullvadvpn.model.DnsState +import net.mullvad.mullvadvpn.util.trySendRequest import net.mullvad.talpid.util.EventNotifier class CustomDns(private val connection: Messenger, private val settingsListener: SettingsListener) { @@ -57,6 +59,10 @@ class CustomDns(private val connection: Messenger, private val settingsListener: connection.send(Request.RemoveCustomDnsServer(server).message) } + fun setDnsOptions(dnsOptions: DnsOptions) { + connection.trySendRequest(Request.SetDnsOptions(dnsOptions), false) + } + fun onDestroy() { onEnabledChanged.unsubscribeAll() onDnsServersChanged.unsubscribeAll() |
