Modern Apps git

MAOS.git

Public
git clone https://git.maproj.org/MAOS.git
main ▾

MAOS.git / patches / packages_apps_Settings_private_dns_ma_dns.patch

packages_apps_Settings_private_dns_ma_dns.patch186 lines · 9.8 KiBRaw
1diff --git a/res/layout/private_dns_mode_dialog.xml b/res/layout/private_dns_mode_dialog.xml
2index 83b01daa2ed..12f7ccd8a8a 100644
3--- a/res/layout/private_dns_mode_dialog.xml
4+++ b/res/layout/private_dns_mode_dialog.xml
5@@ -41,6 +41,10 @@
6 android:id="@+id/private_dns_mode_opportunistic"
7 layout="@layout/preference_widget_dialog_radiobutton"/>
8
9+ <include
10+ android:id="@+id/private_dns_mode_ma_dns"
11+ layout="@layout/preference_widget_dialog_radiobutton"/>
12+
13 <include
14 android:id="@+id/private_dns_mode_provider"
15 layout="@layout/preference_widget_dialog_radiobutton"/>
16diff --git a/res/values/maos_private_dns_strings.xml b/res/values/maos_private_dns_strings.xml
17new file mode 100644
18index 00000000000..044461753b9
19--- /dev/null
20+++ b/res/values/maos_private_dns_strings.xml
21@@ -0,0 +1,9 @@
22+<?xml version="1.0" encoding="utf-8"?>
23+<!--
24+ MAOS Private DNS preset. Kept in its own values file so the MA DNS patch
25+ does not have to share strings.xml / strings_ext.xml hunks with the other
26+ Settings patches applied before it.
27+ -->
28+<resources>
29+ <string name="private_dns_mode_ma_dns">MA DNS</string>
30+</resources>
31diff --git a/src/com/android/settings/network/PrivateDnsModeDialogPreference.java b/src/com/android/settings/network/PrivateDnsModeDialogPreference.java
32index b9836f1b86d..ab4b6a0750c 100644
33--- a/src/com/android/settings/network/PrivateDnsModeDialogPreference.java
34+++ b/src/com/android/settings/network/PrivateDnsModeDialogPreference.java
35@@ -69,6 +69,16 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
36 public static final String ANNOTATION_URL = "url";
37
38 private static final String TAG = "PrivateDnsModeDialog";
39+ // MAOS: the "MA DNS" radio is a preset for our DNS-over-TLS resolver
40+ // (RFC 7858, TCP :853). It is not a fourth Private DNS mode: selecting
41+ // it persists PRIVATE_DNS_MODE_PROVIDER_HOSTNAME with this specifier,
42+ // exactly as if the user had typed it into the hostname field, so
43+ // connectivity, PrivateDnsPreferenceController's summary and every
44+ // other reader of Settings.Global PRIVATE_DNS_MODE /
45+ // PRIVATE_DNS_SPECIFIER see an ordinary provider-hostname setup.
46+ // doh.maproj.org is the separate DNS-over-HTTPS endpoint for browsers
47+ // and must NOT be used here.
48+ private static final String MAOS_PRIVATE_DNS_HOSTNAME = "dot.maproj.org";
49 // DNS_MODE -> RadioButton id
50 private static final Map<Integer, Integer> PRIVATE_DNS_MAP;
51
52@@ -87,6 +97,13 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
53 RadioGroup mRadioGroup;
54 @VisibleForTesting
55 int mMode;
56+ // True while the "MA DNS" radio is the selected one. Kept separate
57+ // from mMode (which is already PROVIDER_HOSTNAME in that case) so the
58+ // dialog can tell the preset apart from the free-form provider radio:
59+ // on Save the preset writes MAOS_PRIVATE_DNS_HOSTNAME instead of the
60+ // hostname text, and the hostname field stays disabled under it.
61+ @VisibleForTesting
62+ boolean mMaDnsSelected;
63
64 public PrivateDnsModeDialogPreference(Context context) {
65 super(context);
66@@ -137,8 +154,17 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
67 protected void onBindDialogView(View view) {
68 final Context context = getContext();
69 mMode = ConnectivitySettingsManager.getPrivateDnsMode(context);
70+ final String currentHostname =
71+ ConnectivitySettingsManager.getPrivateDnsHostname(context);
72+ // The persisted state has no separate MA DNS mode, so reflect an
73+ // existing dot.maproj.org provider setup on the MA DNS radio.
74+ // Anything else with PROVIDER_HOSTNAME keeps the provider radio.
75+ mMaDnsSelected = mMode == PRIVATE_DNS_MODE_PROVIDER_HOSTNAME
76+ && MAOS_PRIVATE_DNS_HOSTNAME.equals(currentHostname);
77 mRadioGroup = view.findViewById(R.id.private_dns_radio_group);
78- mRadioGroup.check(PRIVATE_DNS_MAP.getOrDefault(mMode, R.id.private_dns_mode_opportunistic));
79+ mRadioGroup.check(mMaDnsSelected
80+ ? R.id.private_dns_mode_ma_dns
81+ : PRIVATE_DNS_MAP.getOrDefault(mMode, R.id.private_dns_mode_opportunistic));
82 mRadioGroup.setOnCheckedChangeListener(this);
83
84 // Initial radio button text
85@@ -148,13 +174,19 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
86 view.findViewById(R.id.private_dns_mode_opportunistic);
87 opportunisticRadioButton.setText(
88 com.android.settingslib.R.string.private_dns_mode_opportunistic);
89+ final RadioButton maDnsRadioButton = view.findViewById(R.id.private_dns_mode_ma_dns);
90+ maDnsRadioButton.setText(R.string.private_dns_mode_ma_dns);
91 final RadioButton providerRadioButton = view.findViewById(R.id.private_dns_mode_provider);
92 providerRadioButton.setText(com.android.settingslib.R.string.private_dns_mode_provider);
93
94 mHostnameLayout = view.findViewById(R.id.private_dns_mode_provider_hostname_layout);
95 mHostnameText = view.findViewById(R.id.private_dns_mode_provider_hostname);
96 if (mHostnameText != null) {
97- mHostnameText.setText(ConnectivitySettingsManager.getPrivateDnsHostname(context));
98+ // No pre-fill: the field always shows only the hostname the
99+ // user (or the MA DNS radio) actually persisted. Choosing MA
100+ // DNS and then switching back to the provider radio therefore
101+ // honestly shows dot.maproj.org as the current specifier.
102+ mHostnameText.setText(currentHostname);
103 mHostnameText.addTextChangedListener(this);
104 }
105
106@@ -179,10 +211,16 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
107 public void onCheckedChanged(RadioGroup group, int checkedId) {
108 if (checkedId == R.id.private_dns_mode_off) {
109 mMode = PRIVATE_DNS_MODE_OFF;
110+ mMaDnsSelected = false;
111 } else if (checkedId == R.id.private_dns_mode_opportunistic) {
112 mMode = PRIVATE_DNS_MODE_OPPORTUNISTIC;
113+ mMaDnsSelected = false;
114+ } else if (checkedId == R.id.private_dns_mode_ma_dns) {
115+ mMode = PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
116+ mMaDnsSelected = true;
117 } else if (checkedId == R.id.private_dns_mode_provider) {
118 mMode = PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
119+ mMaDnsSelected = false;
120 }
121 updateDialogInfo();
122 }
123@@ -223,7 +261,11 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
124 }
125
126 private void updateDialogInfo() {
127- final boolean modeProvider = PRIVATE_DNS_MODE_PROVIDER_HOSTNAME == mMode;
128+ // The hostname field belongs to the free-form provider radio only:
129+ // under MA DNS the specifier is the fixed preset, and under Off /
130+ // Automatic there is no specifier to edit at all.
131+ final boolean modeProvider =
132+ PRIVATE_DNS_MODE_PROVIDER_HOSTNAME == mMode && !mMaDnsSelected;
133 if (mHostnameLayout != null) {
134 mHostnameLayout.setEnabled(modeProvider);
135 mHostnameLayout.setErrorEnabled(false);
136@@ -251,23 +293,34 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
137 void doSaveButton() {
138 Context context = getContext();
139 if (mMode == PRIVATE_DNS_MODE_PROVIDER_HOSTNAME) {
140- if (mHostnameLayout == null || mHostnameText == null) {
141- Log.e(TAG, "Can't find hostname resources!");
142- return;
143- }
144- if (mHostnameText.getText().isEmpty()) {
145- mHostnameLayout.setError(context.getString(R.string.private_dns_field_require));
146- Log.w(TAG, "The hostname is empty!");
147- return;
148- }
149- if (!InternetDomainName.isValid(mHostnameText.getText().toString())) {
150- mHostnameLayout.setError(context.getString(R.string.private_dns_hostname_invalid));
151- Log.w(TAG, "The hostname is invalid!");
152- return;
153+ if (mMaDnsSelected) {
154+ // Persist the preset exactly as a typed hostname. The
155+ // hostname text is deliberately neither read nor validated
156+ // here: nothing the user previously typed is consulted,
157+ // and the fixed hostname needs no validation.
158+ ConnectivitySettingsManager.setPrivateDnsHostname(context,
159+ MAOS_PRIVATE_DNS_HOSTNAME);
160+ } else {
161+ if (mHostnameLayout == null || mHostnameText == null) {
162+ Log.e(TAG, "Can't find hostname resources!");
163+ return;
164+ }
165+ if (mHostnameText.getText().isEmpty()) {
166+ mHostnameLayout.setError(
167+ context.getString(R.string.private_dns_field_require));
168+ Log.w(TAG, "The hostname is empty!");
169+ return;
170+ }
171+ if (!InternetDomainName.isValid(mHostnameText.getText().toString())) {
172+ mHostnameLayout.setError(
173+ context.getString(R.string.private_dns_hostname_invalid));
174+ Log.w(TAG, "The hostname is invalid!");
175+ return;
176+ }
177+
178+ ConnectivitySettingsManager.setPrivateDnsHostname(context,
179+ mHostnameText.getText().toString());
180 }
181-
182- ConnectivitySettingsManager.setPrivateDnsHostname(context,
183- mHostnameText.getText().toString());
184 }
185
186 ConnectivitySettingsManager.setPrivateDnsMode(context, mMode);