Skip to content

Commit

Permalink
Settings: Add AdGuard DNS as a private DNS Provider
Browse files Browse the repository at this point in the history
Change-Id: Ieeff83515a273dd5ec06c853bcd0d5e4b51e0bc3
  • Loading branch information
goshawk22 authored and SirRGB committed Nov 16, 2023
1 parent 0b02622 commit 6e86deb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions res/layout/private_dns_mode_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
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"/>
Expand Down
6 changes: 6 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13645,4 +13645,10 @@
<string name="bluetooth_connect_access_dialog_negative">Don\u2019t connect</string>
<!-- Strings for Dialog connect button -->
<string name="bluetooth_connect_access_dialog_positive">Connect</string>

<!-- Cloudflare DNS Option -->
<string name="private_dns_mode_cloudflare" translatable="false">Cloudflare DNS</string>

<!-- AdGuard DNS Option -->
<string name="private_dns_mode_adguard" translatable="false">AdGuard DNS</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat

// Must match ConnectivitySettingsUtils
private static final int PRIVATE_DNS_MODE_CLOUDFLARE = 4;
private static final int PRIVATE_DNS_MODE_ADGUARD = 5;

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_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);
}
Expand Down Expand Up @@ -180,6 +182,9 @@ protected void onBindDialogView(View view) {
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);
Expand Down Expand Up @@ -221,6 +226,8 @@ public void onCheckedChanged(RadioGroup group, int checkedId) {
mMode = PRIVATE_DNS_MODE_OFF;
} 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class PrivateDnsPreferenceController extends BasePreferenceController

// Must match ConnectivitySettingsUtils
private static final int PRIVATE_DNS_MODE_CLOUDFLARE = 4;
private static final int PRIVATE_DNS_MODE_ADGUARD = 5;

private final Handler mHandler;
private final ContentObserver mSettingsObserver;
Expand Down Expand Up @@ -136,6 +137,10 @@ public CharSequence getSummary() {
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);
Expand Down

0 comments on commit 6e86deb

Please sign in to comment.