switch between system dns/custom dns from settings (#42)
This commit is contained in:
1 parent
029b536250
commit
15b836e75c
9 files changed
+185
-6
No files matched your search
@@ -13,6 +13,7 @@ import android.util.Log
|
||||
import bypass.whitelist.MainActivity
|
||||
import bypass.whitelist.R
|
||||
import bypass.whitelist.util.Callback
|
||||
import bypass.whitelist.util.DnsMode
|
||||
import bypass.whitelist.util.Prefs
|
||||
import bypass.whitelist.util.SocksAuth
|
||||
import bypass.whitelist.util.Vpn
|
||||
@@ -86,12 +87,26 @@ class TunnelVpnService : VpnService() {
|
||||
.addRoute(Vpn.ROUTE, 0)
|
||||
.setMtu(Vpn.MTU)
|
||||
|
||||
val systemDns = getSystemDnsServers()
|
||||
if (systemDns.isNotEmpty()) {
|
||||
for (dns in systemDns) builder.addDnsServer(dns)
|
||||
} else {
|
||||
builder.addDnsServer(Vpn.DNS_PRIMARY)
|
||||
builder.addDnsServer(Vpn.DNS_SECONDARY)
|
||||
when (Prefs.dnsMode) {
|
||||
DnsMode.SYSTEM -> {
|
||||
val systemDns = getSystemDnsServers()
|
||||
if (systemDns.isNotEmpty()) {
|
||||
for (dns in systemDns) builder.addDnsServer(dns)
|
||||
} else {
|
||||
builder.addDnsServer(Vpn.DNS_PRIMARY)
|
||||
builder.addDnsServer(Vpn.DNS_SECONDARY)
|
||||
}
|
||||
}
|
||||
DnsMode.CUSTOM -> {
|
||||
val primary = Prefs.dnsPrimary.trim()
|
||||
val secondary = Prefs.dnsSecondary.trim()
|
||||
if (primary.isNotEmpty()) builder.addDnsServer(primary)
|
||||
if (secondary.isNotEmpty()) builder.addDnsServer(secondary)
|
||||
if (primary.isEmpty() && secondary.isEmpty()) {
|
||||
builder.addDnsServer(Vpn.DNS_PRIMARY)
|
||||
builder.addDnsServer(Vpn.DNS_SECONDARY)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package bypass.whitelist.ui
|
||||
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.EditText
|
||||
import android.widget.RadioButton
|
||||
import android.widget.RadioGroup
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import bypass.whitelist.R
|
||||
import bypass.whitelist.util.DnsMode
|
||||
import bypass.whitelist.util.Prefs
|
||||
|
||||
class DnsSettingsDialogFragment : DialogFragment() {
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val view = layoutInflater.inflate(R.layout.dialog_dns_settings, null)
|
||||
|
||||
val dnsModeGroup = view.findViewById<RadioGroup>(R.id.dnsModeGroup)
|
||||
val dnsModeSystem = view.findViewById<RadioButton>(R.id.dnsModeSystem)
|
||||
val dnsModeCustom = view.findViewById<RadioButton>(R.id.dnsModeCustom)
|
||||
val customDnsContainer = view.findViewById<View>(R.id.customDnsContainer)
|
||||
val primaryInput = view.findViewById<EditText>(R.id.dnsPrimaryInput)
|
||||
val secondaryInput = view.findViewById<EditText>(R.id.dnsSecondaryInput)
|
||||
|
||||
when (Prefs.dnsMode) {
|
||||
DnsMode.SYSTEM -> dnsModeSystem.isChecked = true
|
||||
DnsMode.CUSTOM -> dnsModeCustom.isChecked = true
|
||||
}
|
||||
customDnsContainer.visibility = if (Prefs.dnsMode == DnsMode.CUSTOM) View.VISIBLE else View.GONE
|
||||
primaryInput.setText(Prefs.dnsPrimary)
|
||||
secondaryInput.setText(Prefs.dnsSecondary)
|
||||
|
||||
dnsModeGroup.setOnCheckedChangeListener { _, checkedId ->
|
||||
customDnsContainer.visibility = if (checkedId == R.id.dnsModeCustom) View.VISIBLE else View.GONE
|
||||
}
|
||||
|
||||
return AlertDialog.Builder(requireContext())
|
||||
.setTitle(R.string.dns_settings_title)
|
||||
.setView(view)
|
||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
Prefs.dnsMode = if (dnsModeCustom.isChecked) DnsMode.CUSTOM else DnsMode.SYSTEM
|
||||
if (dnsModeCustom.isChecked) {
|
||||
Prefs.dnsPrimary = primaryInput.text.toString()
|
||||
Prefs.dnsSecondary = secondaryInput.text.toString()
|
||||
}
|
||||
}
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.create()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAG = "DnsSettingsDialog"
|
||||
}
|
||||
}
|
||||
@@ -59,6 +59,7 @@ class SettingsDialogFragment : DialogFragment() {
|
||||
val splitTunnelingItem = view.findViewById<TextView>(R.id.splitTunnelingItem)
|
||||
val splitTunnelingAppsItem = view.findViewById<TextView>(R.id.splitTunnelingAppsItem)
|
||||
val proxyItem = view.findViewById<TextView>(R.id.proxyItem)
|
||||
val dnsItem = view.findViewById<TextView>(R.id.dnsItem)
|
||||
val autoclickItem = view.findViewById<TextView>(R.id.autoclickItem)
|
||||
val headlessCheckbox = view.findViewById<CheckBox>(R.id.headlessCheckbox)
|
||||
val reconnectCheckbox = view.findViewById<CheckBox>(R.id.reconnectOnStartCheckbox)
|
||||
@@ -96,6 +97,10 @@ class SettingsDialogFragment : DialogFragment() {
|
||||
}.show(childFragmentManager, ProxySettingsDialogFragment.TAG)
|
||||
}
|
||||
|
||||
dnsItem.setOnClickListener {
|
||||
DnsSettingsDialogFragment().show(childFragmentManager, DnsSettingsDialogFragment.TAG)
|
||||
}
|
||||
|
||||
autoclickItem.setOnClickListener {
|
||||
showAutoclickSettingsDialog()
|
||||
}
|
||||
|
||||
@@ -106,6 +106,7 @@ class VkCaptchaWebView(
|
||||
|
||||
@JavascriptInterface
|
||||
fun setStatus(message: String) {
|
||||
if (message.startsWith("ortc ERROR")) return
|
||||
Log.d("CAPTCHA", "status: $message")
|
||||
activity.runOnUiThread { onStatus(message) }
|
||||
}
|
||||
|
||||
@@ -31,6 +31,11 @@ object SocksAuth {
|
||||
get() = if (Prefs.socksAuthMode == SocksAuthMode.MANUAL) Prefs.socksPass else autoPass
|
||||
}
|
||||
|
||||
enum class DnsMode(val label: String) {
|
||||
SYSTEM("System"),
|
||||
CUSTOM("Custom"),
|
||||
}
|
||||
|
||||
object PrefsKeys {
|
||||
const val CONNECT_ON_START = "connect_on_start"
|
||||
const val URL = "url"
|
||||
@@ -46,6 +51,9 @@ object PrefsKeys {
|
||||
const val SOCKS_USER = "socks_user"
|
||||
const val SOCKS_PASS = "socks_pass"
|
||||
const val PROXY_ONLY = "proxy_only"
|
||||
const val DNS_MODE = "dns_mode"
|
||||
const val DNS_PRIMARY = "dns_primary"
|
||||
const val DNS_SECONDARY = "dns_secondary"
|
||||
}
|
||||
|
||||
const val BLANK_URL = "about:blank"
|
||||
|
||||
@@ -90,4 +90,23 @@ object Prefs {
|
||||
var proxyOnly: Boolean
|
||||
get() = prefs.getBoolean(PrefsKeys.PROXY_ONLY, false)
|
||||
set(value) = prefs.edit { putBoolean(PrefsKeys.PROXY_ONLY, value) }
|
||||
|
||||
var dnsMode: DnsMode
|
||||
get() {
|
||||
val name = prefs.getString(PrefsKeys.DNS_MODE, DnsMode.SYSTEM.name)!!
|
||||
return try {
|
||||
DnsMode.valueOf(name)
|
||||
} catch (_: IllegalArgumentException) {
|
||||
DnsMode.SYSTEM
|
||||
}
|
||||
}
|
||||
set(value) = prefs.edit { putString(PrefsKeys.DNS_MODE, value.name) }
|
||||
|
||||
var dnsPrimary: String
|
||||
get() = prefs.getString(PrefsKeys.DNS_PRIMARY, Vpn.DNS_PRIMARY)!!
|
||||
set(value) = prefs.edit { putString(PrefsKeys.DNS_PRIMARY, value) }
|
||||
|
||||
var dnsSecondary: String
|
||||
get() = prefs.getString(PrefsKeys.DNS_SECONDARY, Vpn.DNS_SECONDARY)!!
|
||||
set(value) = prefs.edit { putString(PrefsKeys.DNS_SECONDARY, value) }
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="12dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/dns_mode_label"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/dnsModeGroup"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/dnsModeSystem"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/dns_mode_system" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/dnsModeCustom"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:text="@string/dns_mode_custom" />
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/customDnsContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/dnsPrimaryInput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/dns_primary_hint"
|
||||
android:inputType="text" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/dnsSecondaryInput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/dns_secondary_hint"
|
||||
android:inputType="text" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -52,6 +52,16 @@
|
||||
android:text="@string/menu_proxy_settings"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dnsItem"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:paddingHorizontal="24dp"
|
||||
android:paddingVertical="14dp"
|
||||
android:text="@string/menu_dns_settings"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/autoclickItem"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -50,6 +50,13 @@
|
||||
<string name="proxy_copy">Copy proxy URL</string>
|
||||
<string name="proxy_copied">Copied to clipboard</string>
|
||||
<string name="proxy_only_label">Proxy only (no VPN)</string>
|
||||
<string name="menu_dns_settings">DNS settings</string>
|
||||
<string name="dns_settings_title">DNS</string>
|
||||
<string name="dns_mode_label">DNS mode</string>
|
||||
<string name="dns_mode_system">System</string>
|
||||
<string name="dns_mode_custom">Custom</string>
|
||||
<string name="dns_primary_hint">Primary DNS</string>
|
||||
<string name="dns_secondary_hint">Secondary DNS</string>
|
||||
<string name="notification_vpn_title">VPN active</string>
|
||||
<string name="notification_proxy_title">Proxy active</string>
|
||||
<string name="notification_disconnect">Disconnect</string>
|
||||
|
||||
Reference in new issue
Block a user