-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove unused parts of legacy CustomDns
- Loading branch information
Showing
3 changed files
with
2 additions
and
81 deletions.
There are no files selected for viewing
72 changes: 1 addition & 71 deletions
72
android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/CustomDns.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<List<InetAddress>>(emptyList()) | ||
val onDnsOptionsChanged = EventNotifier<DnsOptions?>(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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters