Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,36 @@ import android.provider.Settings
import androidx.core.content.ContextCompat
import timber.log.Timber

/**
* Constants for PrivateDnsMode
*
* "off" return when private DNS is off
* "opportunistic" return when private DNS is set to "automatic" aka opportunistic
* "hostname" return when private DNS is set to strict mode, aka user set a DNS
*/
private const val PRIVATE_DNS_MODE_OFF = "off"
private const val PRIVATE_DNS_MODE_OPPORTUNISTIC = "opportunistic"
private const val PRIVATE_DNS_MODE_STRICT = "hostname"

fun Context.isPrivateDnsActive(): Boolean {
var dnsMode = Settings.Global.getString(contentResolver, "private_dns_mode")
if (dnsMode == null) dnsMode = "off"
return "off" != dnsMode
if (dnsMode == null) dnsMode = PRIVATE_DNS_MODE_OFF
return PRIVATE_DNS_MODE_OFF != dnsMode
}

fun Context.isPrivateDnsAutomatic(): Boolean {
var dnsMode = Settings.Global.getString(contentResolver, "private_dns_mode")
return dnsMode == PRIVATE_DNS_MODE_OPPORTUNISTIC
}

fun Context.isPrivateDnsStrict(): Boolean {
var dnsMode = Settings.Global.getString(contentResolver, "private_dns_mode")
return dnsMode == PRIVATE_DNS_MODE_STRICT
}

fun Context.getPrivateDnsServerName(): String? {
val dnsMode = Settings.Global.getString(contentResolver, "private_dns_mode")
return if ("hostname" == dnsMode) Settings.Global.getString(contentResolver, "private_dns_specifier") else null
return if (PRIVATE_DNS_MODE_STRICT == dnsMode) Settings.Global.getString(contentResolver, "private_dns_specifier") else null
}

fun Context.isAirplaneModeOn(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import com.duckduckgo.common.ui.view.setEnabledOpacity
import com.duckduckgo.common.ui.view.show
import com.duckduckgo.common.ui.viewbinding.viewBinding
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.common.utils.extensions.isPrivateDnsActive
import com.duckduckgo.common.utils.extensions.isPrivateDnsStrict
import com.duckduckgo.common.utils.extensions.launchSettings
import com.duckduckgo.di.scopes.ActivityScope
import com.duckduckgo.navigation.api.GlobalActivityStarter.ActivityParams
Expand Down Expand Up @@ -125,7 +125,7 @@ class VpnCustomDnsActivity : DuckDuckGoActivity() {
events
.flatMapLatest { viewModel.reduce(it) }
.flowOn(dispatcherProvider.io())
.onStart { events.emit(Init(this@VpnCustomDnsActivity.isPrivateDnsActive())) }
.onStart { events.emit(Init(this@VpnCustomDnsActivity.isPrivateDnsStrict())) }
.collect(::render)
}
binding.defaultDnsOption.setOnCheckedChangeListener(defaultDnsListener)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ class VpnCustomDnsViewModel @Inject constructor(
CustomDnsSelected -> handleCustomDnsSelected()
is CustomDnsEntered -> handleCustomDnsEntered(event)
OnApply -> handleOnApply()
ForceApplyIfReset -> handleforceApply()
ForceApplyIfReset -> handleForceApply()
}
}

private fun handleforceApply() = flow {
private fun handleForceApply() = flow {
if (netpVpnSettingsDataStore.customDns != null && currentState == DefaultDns) {
netpVpnSettingsDataStore.customDns = null
networkProtectionPixels.reportDefaultDnsSet()
Expand Down