diff --git a/app/src/main/java/eu/faircode/netguard/ActivityMain.java b/app/src/main/java/eu/faircode/netguard/ActivityMain.java index a3517414..ba2ff4f6 100644 --- a/app/src/main/java/eu/faircode/netguard/ActivityMain.java +++ b/app/src/main/java/eu/faircode/netguard/ActivityMain.java @@ -212,11 +212,6 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences return; } - if (hasPrivateDns()) { - swEnabled.setChecked(false); - return; - } - try { final Intent prepare = VpnService.prepare(ActivityMain.this); if (prepare == null) { @@ -264,12 +259,8 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences ServiceSinkhole.stop("switch off", ActivityMain.this, false); } }); - if (enabled) { + if (enabled) checkDoze(); - if (hasPrivateDns()) { - swEnabled.setChecked(false); - } - } // Network is metered ivMetered.setOnLongClickListener(new View.OnLongClickListener() { @@ -1115,22 +1106,6 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences } } - private boolean hasPrivateDns() { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - boolean filter = prefs.getBoolean("filter", false); - if (filter) { - String dns_mode = Settings.Global.getString(getContentResolver(), "private_dns_mode"); - Log.i(TAG, "Private DNS mode=" + dns_mode); - if (dns_mode == null) - dns_mode = "off"; - if (!"off".equals(dns_mode)) { - Toast.makeText(ActivityMain.this, R.string.msg_private_dns, Toast.LENGTH_LONG).show(); - return true; - } - } - return false; - } - private void menu_legend() { TypedValue tv = new TypedValue(); getTheme().resolveAttribute(R.attr.colorOn, tv, true); diff --git a/app/src/main/java/eu/faircode/netguard/ServiceSinkhole.java b/app/src/main/java/eu/faircode/netguard/ServiceSinkhole.java index e79044de..648dd8c3 100644 --- a/app/src/main/java/eu/faircode/netguard/ServiceSinkhole.java +++ b/app/src/main/java/eu/faircode/netguard/ServiceSinkhole.java @@ -1068,8 +1068,10 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS // Get custom DNS servers SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean ip6 = prefs.getBoolean("ip6", true); - String vpnDns1 = prefs.getString("dns", null); - String vpnDns2 = prefs.getString("dns2", null); + boolean pdns = Util.isPrivateDns(context); + // Make sure normal DNS servers are used when private DNS is enabled + String vpnDns1 = prefs.getString("dns", pdns ? "8.8.8.8" : null); + String vpnDns2 = prefs.getString("dns2", pdns ? "8.8.4.4" : null); Log.i(TAG, "DNS system=" + TextUtils.join(",", sysDns) + " VPN1=" + vpnDns1 + " VPN2=" + vpnDns2); if (vpnDns1 != null) @@ -1092,7 +1094,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS } // Use system DNS servers only when no two custom DNS servers specified - if (listDns.size() <= 1) + if (listDns.size() < 2) for (String def_dns : sysDns) try { InetAddress ddns = InetAddress.getByName(def_dns); diff --git a/app/src/main/java/eu/faircode/netguard/Util.java b/app/src/main/java/eu/faircode/netguard/Util.java index d7a978ce..6d166aa5 100644 --- a/app/src/main/java/eu/faircode/netguard/Util.java +++ b/app/src/main/java/eu/faircode/netguard/Util.java @@ -47,6 +47,7 @@ import android.os.Build; import android.os.Bundle; import android.os.PowerManager; import android.preference.PreferenceManager; +import android.provider.Settings; import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.Log; @@ -221,6 +222,14 @@ public class Util { return (country != null && listEU.contains(country.toUpperCase())); } + public static boolean isPrivateDns(Context context) { + String dns_mode = Settings.Global.getString(context.getContentResolver(), "private_dns_mode"); + Log.i(TAG, "Private DNS mode=" + dns_mode); + if (dns_mode == null) + dns_mode = "off"; + return (!"off".equals(dns_mode)); + } + public static String getNetworkGeneration(int networkType) { switch (networkType) { case TelephonyManager.NETWORK_TYPE_1xRTT: