Skip to content

Commit d2d7b55

Browse files
authored
Allow custom DNS on opportunistic DoT (#4703)
Task/Issue URL: https://app.asana.com/0/1202552961248957/1207692081807518/f ### Description Remove the warning on custom DNS screen when private DNS is set to automatic ### Steps to test this PR _Test automatic mode_ - [x] install from this branch - [x] ensure private DNS is set to off - [x] enable VPN and set VPN custom DNS to 1.1.1.1 - [x] verify custom DNS is correctly enabled - [x] go android settings -> private DNS and set to `dns.google` - [x] back to DDG app -> VPN custom DNS screen - [x] verify warning "private DNS is already specified...turn off private DNS..." shows - [x] verify internet connection works - [x] verify DNS traffic is routed through Google (dnsleaktest.com) - [x] go android settings -> private DNS and set to automatic - [x] back to DDG app, VPN custom DNS screen - [x] verify warning "private DNS is already specified...turn off private DNS..." does NOT show - [x] verify internet connection works - [x] verify DNS traffic is routed through Cloudflare (dnsleaktest.com)
1 parent df917e2 commit d2d7b55

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

common/common-utils/src/main/java/com/duckduckgo/common/utils/extensions/ContextExtensions.kt

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,36 @@ import android.provider.Settings
2424
import androidx.core.content.ContextCompat
2525
import timber.log.Timber
2626

27+
/**
28+
* Constants for PrivateDnsMode
29+
*
30+
* "off" return when private DNS is off
31+
* "opportunistic" return when private DNS is set to "automatic" aka opportunistic
32+
* "hostname" return when private DNS is set to strict mode, aka user set a DNS
33+
*/
34+
private const val PRIVATE_DNS_MODE_OFF = "off"
35+
private const val PRIVATE_DNS_MODE_OPPORTUNISTIC = "opportunistic"
36+
private const val PRIVATE_DNS_MODE_STRICT = "hostname"
37+
2738
fun Context.isPrivateDnsActive(): Boolean {
2839
var dnsMode = Settings.Global.getString(contentResolver, "private_dns_mode")
29-
if (dnsMode == null) dnsMode = "off"
30-
return "off" != dnsMode
40+
if (dnsMode == null) dnsMode = PRIVATE_DNS_MODE_OFF
41+
return PRIVATE_DNS_MODE_OFF != dnsMode
42+
}
43+
44+
fun Context.isPrivateDnsAutomatic(): Boolean {
45+
var dnsMode = Settings.Global.getString(contentResolver, "private_dns_mode")
46+
return dnsMode == PRIVATE_DNS_MODE_OPPORTUNISTIC
47+
}
48+
49+
fun Context.isPrivateDnsStrict(): Boolean {
50+
var dnsMode = Settings.Global.getString(contentResolver, "private_dns_mode")
51+
return dnsMode == PRIVATE_DNS_MODE_STRICT
3152
}
3253

3354
fun Context.getPrivateDnsServerName(): String? {
3455
val dnsMode = Settings.Global.getString(contentResolver, "private_dns_mode")
35-
return if ("hostname" == dnsMode) Settings.Global.getString(contentResolver, "private_dns_specifier") else null
56+
return if (PRIVATE_DNS_MODE_STRICT == dnsMode) Settings.Global.getString(contentResolver, "private_dns_specifier") else null
3657
}
3758

3859
fun Context.isAirplaneModeOn(): Boolean {

network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/settings/custom_dns/VpnCustomDnsActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import com.duckduckgo.common.ui.view.setEnabledOpacity
3131
import com.duckduckgo.common.ui.view.show
3232
import com.duckduckgo.common.ui.viewbinding.viewBinding
3333
import com.duckduckgo.common.utils.DispatcherProvider
34-
import com.duckduckgo.common.utils.extensions.isPrivateDnsActive
34+
import com.duckduckgo.common.utils.extensions.isPrivateDnsStrict
3535
import com.duckduckgo.common.utils.extensions.launchSettings
3636
import com.duckduckgo.di.scopes.ActivityScope
3737
import com.duckduckgo.navigation.api.GlobalActivityStarter.ActivityParams
@@ -125,7 +125,7 @@ class VpnCustomDnsActivity : DuckDuckGoActivity() {
125125
events
126126
.flatMapLatest { viewModel.reduce(it) }
127127
.flowOn(dispatcherProvider.io())
128-
.onStart { events.emit(Init(this@VpnCustomDnsActivity.isPrivateDnsActive())) }
128+
.onStart { events.emit(Init(this@VpnCustomDnsActivity.isPrivateDnsStrict())) }
129129
.collect(::render)
130130
}
131131
binding.defaultDnsOption.setOnCheckedChangeListener(defaultDnsListener)

network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/settings/custom_dns/VpnCustomDnsViewModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ class VpnCustomDnsViewModel @Inject constructor(
5353
CustomDnsSelected -> handleCustomDnsSelected()
5454
is CustomDnsEntered -> handleCustomDnsEntered(event)
5555
OnApply -> handleOnApply()
56-
ForceApplyIfReset -> handleforceApply()
56+
ForceApplyIfReset -> handleForceApply()
5757
}
5858
}
5959

60-
private fun handleforceApply() = flow {
60+
private fun handleForceApply() = flow {
6161
if (netpVpnSettingsDataStore.customDns != null && currentState == DefaultDns) {
6262
netpVpnSettingsDataStore.customDns = null
6363
networkProtectionPixels.reportDefaultDnsSet()

0 commit comments

Comments
 (0)