diff --git a/app/src/main/java/eu/faircode/netguard/ActivityMain.java b/app/src/main/java/eu/faircode/netguard/ActivityMain.java index be6206e2..a3517414 100644 --- a/app/src/main/java/eu/faircode/netguard/ActivityMain.java +++ b/app/src/main/java/eu/faircode/netguard/ActivityMain.java @@ -193,7 +193,6 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences prefs.edit().putBoolean("enabled", isChecked).apply(); if (isChecked) { - String alwaysOn = Settings.Secure.getString(getContentResolver(), "always_on_vpn_app"); Log.i(TAG, "Always-on=" + alwaysOn); if (!TextUtils.isEmpty(alwaysOn)) @@ -213,13 +212,8 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences return; } - 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)) { + if (hasPrivateDns()) { swEnabled.setChecked(false); - Toast.makeText(ActivityMain.this, R.string.msg_private_dns, Toast.LENGTH_LONG).show(); return; } @@ -270,8 +264,12 @@ 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() { @@ -1117,6 +1115,22 @@ 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);