DivestOS/Patches/LineageOS-18.1/android_packages_apps_Settings/0004-Private_DNS.patch
Tad fe8e8201a9 Add more 'Private DNS' options
Based off of patches from CalyxOS as noted in each included patch.

Tested and verified working on klte and mata 18.1

Signed-off-by: Tad <tad@spotco.us>
2021-10-21 23:39:46 -04:00

149 lines
8.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tad <tad@spotco.us>
Date: Thu, 21 Oct 2021 21:09:38 -0400
Subject: [PATCH] Add more 'Private DNS' options
This adds: Quad9, Cloudflare, and AdGuard
Credit: CalyxOS
- Chirayu Desai <chirayudesai1@gmail.com>
https://review.calyxos.org/c/CalyxOS/platform_packages_apps_Settings/+/458
- Pavel Shirshov <pshirshov@eml.cc>
https://review.calyxos.org/c/CalyxOS/platform_packages_apps_Settings/+/5357
Signed-off-by: Tad <tad@spotco.us>
Change-Id: I423ad5a3c360a687a226e61df3f75b5550f851c0
---
res/layout/private_dns_mode_dialog.xml | 12 +++++++++++
res/values/cm_strings.xml | 5 +++++
.../PrivateDnsModeDialogPreference.java | 21 +++++++++++++++++++
.../PrivateDnsPreferenceController.java | 15 +++++++++++++
4 files changed, 53 insertions(+)
diff --git a/res/layout/private_dns_mode_dialog.xml b/res/layout/private_dns_mode_dialog.xml
index 0b4f4db6c4..8b1d28450c 100644
--- a/res/layout/private_dns_mode_dialog.xml
+++ b/res/layout/private_dns_mode_dialog.xml
@@ -35,6 +35,18 @@
android:id="@+id/private_dns_mode_off"
layout="@layout/preference_widget_dialog_radiobutton"/>
+ <include
+ android:id="@+id/private_dns_mode_quadnine"
+ layout="@layout/preference_widget_dialog_radiobutton"/>
+
+ <include
+ android:id="@+id/private_dns_mode_cloudflare"
+ layout="@layout/preference_widget_dialog_radiobutton"/>
+
+ <include
+ android:id="@+id/private_dns_mode_adguard"
+ layout="@layout/preference_widget_dialog_radiobutton"/>
+
<include
android:id="@+id/private_dns_mode_opportunistic"
layout="@layout/preference_widget_dialog_radiobutton"/>
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
index c35c696b16..d18f0af87f 100644
--- a/res/values/cm_strings.xml
+++ b/res/values/cm_strings.xml
@@ -177,4 +177,9 @@
<string name="captive_portal_switch_title">Captive portal mode</string>
<string name="captive_portal_switch_summary">Enable or disable the captive portal probing for connection attempts (default ON).</string>
<string name="captive_portal_switch_warning">If you switch off the captive portal, you will not receive connectivity informations any longer. Really switch off?</string>
+
+ <!-- Private DNS -->
+ <string name="private_dns_mode_quadnine" translatable="false">Quad9</string>
+ <string name="private_dns_mode_cloudflare" translatable="false">Cloudflare</string>
+ <string name="private_dns_mode_adguard" translatable="false">AdGuard</string>
</resources>
diff --git a/src/com/android/settings/network/PrivateDnsModeDialogPreference.java b/src/com/android/settings/network/PrivateDnsModeDialogPreference.java
index 3fc5086cd6..af4b08f3a7 100644
--- a/src/com/android/settings/network/PrivateDnsModeDialogPreference.java
+++ b/src/com/android/settings/network/PrivateDnsModeDialogPreference.java
@@ -17,6 +17,9 @@ package com.android.settings.network;
import static android.net.ConnectivityManager.PRIVATE_DNS_DEFAULT_MODE_FALLBACK;
import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_OFF;
+import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_QUADNINE;
+import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_CLOUDFLARE;
+import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_ADGUARD;
import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_OPPORTUNISTIC;
import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
@@ -74,6 +77,9 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
static {
PRIVATE_DNS_MAP = new HashMap<>();
PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_OFF, R.id.private_dns_mode_off);
+ PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_QUADNINE, R.id.private_dns_mode_quadnine);
+ PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_CLOUDFLARE, R.id.private_dns_mode_cloudflare);
+ PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_ADGUARD, R.id.private_dns_mode_adguard);
PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_OPPORTUNISTIC, R.id.private_dns_mode_opportunistic);
PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_PROVIDER_HOSTNAME, R.id.private_dns_mode_provider);
}
@@ -180,6 +186,15 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
// Initial radio button text
final RadioButton offRadioButton = view.findViewById(R.id.private_dns_mode_off);
offRadioButton.setText(R.string.private_dns_mode_off);
+ final RadioButton quadnineRadioButton =
+ view.findViewById(R.id.private_dns_mode_quadnine);
+ quadnineRadioButton.setText(R.string.private_dns_mode_quadnine);
+ final RadioButton cloudflareRadioButton =
+ view.findViewById(R.id.private_dns_mode_cloudflare);
+ cloudflareRadioButton.setText(R.string.private_dns_mode_cloudflare);
+ final RadioButton adguardRadioButton =
+ view.findViewById(R.id.private_dns_mode_adguard);
+ adguardRadioButton.setText(R.string.private_dns_mode_adguard);
final RadioButton opportunisticRadioButton =
view.findViewById(R.id.private_dns_mode_opportunistic);
opportunisticRadioButton.setText(R.string.private_dns_mode_opportunistic);
@@ -221,6 +236,12 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.private_dns_mode_off) {
mMode = PRIVATE_DNS_MODE_OFF;
+ } else if (checkedId == R.id.private_dns_mode_quadnine) {
+ mMode = PRIVATE_DNS_MODE_QUADNINE;
+ } else if (checkedId == R.id.private_dns_mode_cloudflare) {
+ mMode = PRIVATE_DNS_MODE_CLOUDFLARE;
+ } else if (checkedId == R.id.private_dns_mode_adguard) {
+ mMode = PRIVATE_DNS_MODE_ADGUARD;
} else if (checkedId == R.id.private_dns_mode_opportunistic) {
mMode = PRIVATE_DNS_MODE_OPPORTUNISTIC;
} else if (checkedId == R.id.private_dns_mode_provider) {
diff --git a/src/com/android/settings/network/PrivateDnsPreferenceController.java b/src/com/android/settings/network/PrivateDnsPreferenceController.java
index 84cae88f85..e0d416e412 100644
--- a/src/com/android/settings/network/PrivateDnsPreferenceController.java
+++ b/src/com/android/settings/network/PrivateDnsPreferenceController.java
@@ -17,6 +17,9 @@
package com.android.settings.network;
import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_OFF;
+import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_QUADNINE;
+import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_CLOUDFLARE;
+import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_ADGUARD;
import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_OPPORTUNISTIC;
import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
import static android.provider.Settings.Global.PRIVATE_DNS_DEFAULT_MODE;
@@ -125,6 +128,18 @@ public class PrivateDnsPreferenceController extends BasePreferenceController
switch (mode) {
case PRIVATE_DNS_MODE_OFF:
return res.getString(R.string.private_dns_mode_off);
+ case PRIVATE_DNS_MODE_QUADNINE:
+ return dnsesResolved
+ ? res.getString(R.string.private_dns_mode_quadnine)
+ : res.getString(R.string.private_dns_mode_provider_failure);
+ case PRIVATE_DNS_MODE_CLOUDFLARE:
+ return dnsesResolved
+ ? res.getString(R.string.private_dns_mode_cloudflare)
+ : res.getString(R.string.private_dns_mode_provider_failure);
+ case PRIVATE_DNS_MODE_ADGUARD:
+ return dnsesResolved
+ ? res.getString(R.string.private_dns_mode_adguard)
+ : res.getString(R.string.private_dns_mode_provider_failure);
case PRIVATE_DNS_MODE_OPPORTUNISTIC:
return dnsesResolved ? res.getString(R.string.private_dns_mode_on)
: res.getString(R.string.private_dns_mode_opportunistic);
--
2.31.1