diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-11-19 19:27:13 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-12-14 13:59:04 +0000 |
| commit | 9c414414dea2d90c48d0b1313afd8ab4fd9ff68c (patch) | |
| tree | 95bb6863c9849bf8c1ee754bb56ee7632e58d1b7 /android | |
| parent | de42d0ad3281bd7df987fd747a3a50688fc50251 (diff) | |
| download | mullvadvpn-9c414414dea2d90c48d0b1313afd8ab4fd9ff68c.tar.xz mullvadvpn-9c414414dea2d90c48d0b1313afd8ab4fd9ff68c.zip | |
Warn when trying to add public DNS address
Diffstat (limited to 'android')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/AdvancedFragment.kt | 6 | ||||
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsAdapter.kt | 17 |
2 files changed, 21 insertions, 2 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/AdvancedFragment.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/AdvancedFragment.kt index bdeb4a879c..f02f5cca91 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/AdvancedFragment.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/AdvancedFragment.kt @@ -36,7 +36,11 @@ class AdvancedFragment : ServiceDependentFragment(OnNoService.GoBack) { titleController = CollapsibleTitleController(view, R.id.contents) - customDnsAdapter = CustomDnsAdapter(customDns) + customDnsAdapter = CustomDnsAdapter(customDns).apply { + showPublicDnsAddressWarning = { confirmation -> + showConfirmPublicDnsServerDialog(confirmation) + } + } view.findViewById<CustomRecyclerView>(R.id.contents).apply { layoutManager = LinearLayoutManager(parentActivity) diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsAdapter.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsAdapter.kt index 5c3eeee3a5..44af15c1f7 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsAdapter.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsAdapter.kt @@ -5,6 +5,7 @@ import android.view.LayoutInflater import android.view.ViewGroup import java.net.InetAddress import kotlin.properties.Delegates.observable +import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import net.mullvad.mullvadvpn.R @@ -53,6 +54,8 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>( val isEditing get() = editingPosition != null + var showPublicDnsAddressWarning: ((CompletableDeferred<Boolean>) -> Unit)? = null + init { customDns.apply { onDnsServersChanged.subscribe(this) { dnsServers -> @@ -282,10 +285,22 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>( if (inetAddressValidator.isValid(addressText)) { val address = InetAddress.getByName(addressText) - if (!address.isLoopbackAddress()) { + if (!address.isLoopbackAddress() && confirmAddIfPublicAddress(address)) { handler(address) } } } } + + private suspend fun confirmAddIfPublicAddress(address: InetAddress): Boolean { + if (address.isLinkLocalAddress() || address.isSiteLocalAddress()) { + return true + } + + val confirmation = CompletableDeferred<Boolean>() + + showPublicDnsAddressWarning?.invoke(confirmation) + + return confirmation.await() + } } |
