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 b24cda921340..bfad798e08eb 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 @@ -1,83 +1,13 @@ package net.mullvad.mullvadvpn.ui.serviceconnection import android.os.Messenger -import java.net.InetAddress import net.mullvad.mullvadvpn.lib.ipc.Request import net.mullvad.mullvadvpn.lib.ipc.extensions.trySendRequest import net.mullvad.mullvadvpn.model.DnsOptions -import net.mullvad.mullvadvpn.model.DnsState -import net.mullvad.talpid.util.EventNotifier -class CustomDns(private val connection: Messenger, private val settingsListener: SettingsListener) { - @Deprecated( - message = "Will soon be removed in favor of onDnsOptionsChanged.", - replaceWith = ReplaceWith("onDnsOptionsChanged") - ) - val onEnabledChanged = EventNotifier(false) - @Deprecated( - message = "Will soon be removed in favor of onDnsOptionsChanged.", - replaceWith = ReplaceWith("onDnsOptionsChanged") - ) - val onDnsServersChanged = EventNotifier>(emptyList()) - val onDnsOptionsChanged = EventNotifier(null) - - init { - settingsListener.dnsOptionsNotifier.subscribe(this) { maybeDnsOptions -> - maybeDnsOptions?.let { dnsOptions -> - synchronized(this) { - onEnabledChanged.notifyIfChanged(dnsOptions.state == DnsState.Custom) - onDnsServersChanged.notifyIfChanged(dnsOptions.customOptions.addresses) - onDnsOptionsChanged.notifyIfChanged(dnsOptions) - } - } - } - } - - fun enable() { - connection.send(Request.SetEnableCustomDns(true).message) - } - - fun disable() { - connection.send(Request.SetEnableCustomDns(false).message) - } - - fun isCustomDnsEnabled(): Boolean { - return onEnabledChanged.latestEvent ?: false - } - - fun addDnsServer(server: InetAddress): Boolean { - val didntAlreadyHaveServer = !onDnsServersChanged.latestEvent.contains(server) - - connection.send(Request.AddCustomDnsServer(server).message) - - return didntAlreadyHaveServer - } - - 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) - } +class CustomDns(private val connection: Messenger) { fun setDnsOptions(dnsOptions: DnsOptions) { connection.trySendRequest(Request.SetDnsOptions(dnsOptions), false) } - - fun onDestroy() { - onEnabledChanged.unsubscribeAll() - onDnsServersChanged.unsubscribeAll() - onDnsOptionsChanged.unsubscribeAll() - - settingsListener.dnsOptionsNotifier.unsubscribe(this) - } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnectionContainer.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnectionContainer.kt index 1ca0d6642c58..6dbea7a51708 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnectionContainer.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnectionContainer.kt @@ -8,7 +8,6 @@ import net.mullvad.mullvadvpn.lib.ipc.DispatchingHandler import net.mullvad.mullvadvpn.lib.ipc.Event import net.mullvad.mullvadvpn.lib.ipc.Request import org.koin.core.component.KoinComponent -import org.koin.core.component.get // Container of classes that communicate with the service through an active connection // @@ -34,7 +33,7 @@ class ServiceConnectionContainer( val vpnPermission = VpnPermission(connection, dispatcher) val appVersionInfoCache = AppVersionInfoCache(dispatcher, settingsListener) - val customDns = CustomDns(connection, settingsListener) + val customDns = CustomDns(connection) var relayListListener = RelayListListener(connection, dispatcher, settingsListener) private var listenerId: Int? = null @@ -62,7 +61,6 @@ class ServiceConnectionContainer( voucherRedeemer.onDestroy() appVersionInfoCache.onDestroy() - customDns.onDestroy() relayListListener.onDestroy() } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/SettingsListener.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/SettingsListener.kt index 039b293d6915..d996c432ad3c 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/SettingsListener.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/SettingsListener.kt @@ -4,7 +4,6 @@ import android.os.Messenger import net.mullvad.mullvadvpn.lib.ipc.Event import net.mullvad.mullvadvpn.lib.ipc.EventDispatcher import net.mullvad.mullvadvpn.lib.ipc.Request -import net.mullvad.mullvadvpn.model.DnsOptions import net.mullvad.mullvadvpn.model.ObfuscationSettings import net.mullvad.mullvadvpn.model.QuantumResistantState import net.mullvad.mullvadvpn.model.RelaySettings @@ -12,7 +11,6 @@ import net.mullvad.mullvadvpn.model.Settings import net.mullvad.talpid.util.EventNotifier class SettingsListener(private val connection: Messenger, eventDispatcher: EventDispatcher) { - val dnsOptionsNotifier = EventNotifier(null) val relaySettingsNotifier = EventNotifier(null) val settingsNotifier = EventNotifier(null) @@ -55,7 +53,6 @@ class SettingsListener(private val connection: Messenger, eventDispatcher: Event } fun onDestroy() { - dnsOptionsNotifier.unsubscribeAll() relaySettingsNotifier.unsubscribeAll() settingsNotifier.unsubscribeAll() } @@ -65,10 +62,6 @@ class SettingsListener(private val connection: Messenger, eventDispatcher: Event } private fun handleNewSettings(newSettings: Settings) { - if (settings?.tunnelOptions?.dnsOptions != newSettings.tunnelOptions.dnsOptions) { - dnsOptionsNotifier.notify(newSettings.tunnelOptions.dnsOptions) - } - if (settings?.relaySettings != newSettings.relaySettings) { relaySettingsNotifier.notify(newSettings.relaySettings) }