diff --git a/res/layout/private_dns_mode_dialog.xml b/res/layout/private_dns_mode_dialog.xml
index 83b01daa2ed..12f7ccd8a8a 100644
--- a/res/layout/private_dns_mode_dialog.xml
+++ b/res/layout/private_dns_mode_dialog.xml
@@ -41,6 +41,10 @@
android:id="@+id/private_dns_mode_opportunistic"
layout="@layout/preference_widget_dialog_radiobutton"/>
+
+
diff --git a/res/values/maos_private_dns_strings.xml b/res/values/maos_private_dns_strings.xml
new file mode 100644
index 00000000000..044461753b9
--- /dev/null
+++ b/res/values/maos_private_dns_strings.xml
@@ -0,0 +1,9 @@
+
+
+
+ MA DNS
+
diff --git a/src/com/android/settings/network/PrivateDnsModeDialogPreference.java b/src/com/android/settings/network/PrivateDnsModeDialogPreference.java
index b9836f1b86d..ab4b6a0750c 100644
--- a/src/com/android/settings/network/PrivateDnsModeDialogPreference.java
+++ b/src/com/android/settings/network/PrivateDnsModeDialogPreference.java
@@ -69,6 +69,16 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
public static final String ANNOTATION_URL = "url";
private static final String TAG = "PrivateDnsModeDialog";
+ // MAOS: the "MA DNS" radio is a preset for our DNS-over-TLS resolver
+ // (RFC 7858, TCP :853). It is not a fourth Private DNS mode: selecting
+ // it persists PRIVATE_DNS_MODE_PROVIDER_HOSTNAME with this specifier,
+ // exactly as if the user had typed it into the hostname field, so
+ // connectivity, PrivateDnsPreferenceController's summary and every
+ // other reader of Settings.Global PRIVATE_DNS_MODE /
+ // PRIVATE_DNS_SPECIFIER see an ordinary provider-hostname setup.
+ // doh.maproj.org is the separate DNS-over-HTTPS endpoint for browsers
+ // and must NOT be used here.
+ private static final String MAOS_PRIVATE_DNS_HOSTNAME = "dot.maproj.org";
// DNS_MODE -> RadioButton id
private static final Map PRIVATE_DNS_MAP;
@@ -87,6 +97,13 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
RadioGroup mRadioGroup;
@VisibleForTesting
int mMode;
+ // True while the "MA DNS" radio is the selected one. Kept separate
+ // from mMode (which is already PROVIDER_HOSTNAME in that case) so the
+ // dialog can tell the preset apart from the free-form provider radio:
+ // on Save the preset writes MAOS_PRIVATE_DNS_HOSTNAME instead of the
+ // hostname text, and the hostname field stays disabled under it.
+ @VisibleForTesting
+ boolean mMaDnsSelected;
public PrivateDnsModeDialogPreference(Context context) {
super(context);
@@ -137,8 +154,17 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
protected void onBindDialogView(View view) {
final Context context = getContext();
mMode = ConnectivitySettingsManager.getPrivateDnsMode(context);
+ final String currentHostname =
+ ConnectivitySettingsManager.getPrivateDnsHostname(context);
+ // The persisted state has no separate MA DNS mode, so reflect an
+ // existing dot.maproj.org provider setup on the MA DNS radio.
+ // Anything else with PROVIDER_HOSTNAME keeps the provider radio.
+ mMaDnsSelected = mMode == PRIVATE_DNS_MODE_PROVIDER_HOSTNAME
+ && MAOS_PRIVATE_DNS_HOSTNAME.equals(currentHostname);
mRadioGroup = view.findViewById(R.id.private_dns_radio_group);
- mRadioGroup.check(PRIVATE_DNS_MAP.getOrDefault(mMode, R.id.private_dns_mode_opportunistic));
+ mRadioGroup.check(mMaDnsSelected
+ ? R.id.private_dns_mode_ma_dns
+ : PRIVATE_DNS_MAP.getOrDefault(mMode, R.id.private_dns_mode_opportunistic));
mRadioGroup.setOnCheckedChangeListener(this);
// Initial radio button text
@@ -148,13 +174,19 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
view.findViewById(R.id.private_dns_mode_opportunistic);
opportunisticRadioButton.setText(
com.android.settingslib.R.string.private_dns_mode_opportunistic);
+ final RadioButton maDnsRadioButton = view.findViewById(R.id.private_dns_mode_ma_dns);
+ maDnsRadioButton.setText(R.string.private_dns_mode_ma_dns);
final RadioButton providerRadioButton = view.findViewById(R.id.private_dns_mode_provider);
providerRadioButton.setText(com.android.settingslib.R.string.private_dns_mode_provider);
mHostnameLayout = view.findViewById(R.id.private_dns_mode_provider_hostname_layout);
mHostnameText = view.findViewById(R.id.private_dns_mode_provider_hostname);
if (mHostnameText != null) {
- mHostnameText.setText(ConnectivitySettingsManager.getPrivateDnsHostname(context));
+ // No pre-fill: the field always shows only the hostname the
+ // user (or the MA DNS radio) actually persisted. Choosing MA
+ // DNS and then switching back to the provider radio therefore
+ // honestly shows dot.maproj.org as the current specifier.
+ mHostnameText.setText(currentHostname);
mHostnameText.addTextChangedListener(this);
}
@@ -179,10 +211,16 @@ 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;
+ mMaDnsSelected = false;
} else if (checkedId == R.id.private_dns_mode_opportunistic) {
mMode = PRIVATE_DNS_MODE_OPPORTUNISTIC;
+ mMaDnsSelected = false;
+ } else if (checkedId == R.id.private_dns_mode_ma_dns) {
+ mMode = PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
+ mMaDnsSelected = true;
} else if (checkedId == R.id.private_dns_mode_provider) {
mMode = PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
+ mMaDnsSelected = false;
}
updateDialogInfo();
}
@@ -223,7 +261,11 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
}
private void updateDialogInfo() {
- final boolean modeProvider = PRIVATE_DNS_MODE_PROVIDER_HOSTNAME == mMode;
+ // The hostname field belongs to the free-form provider radio only:
+ // under MA DNS the specifier is the fixed preset, and under Off /
+ // Automatic there is no specifier to edit at all.
+ final boolean modeProvider =
+ PRIVATE_DNS_MODE_PROVIDER_HOSTNAME == mMode && !mMaDnsSelected;
if (mHostnameLayout != null) {
mHostnameLayout.setEnabled(modeProvider);
mHostnameLayout.setErrorEnabled(false);
@@ -251,23 +293,34 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
void doSaveButton() {
Context context = getContext();
if (mMode == PRIVATE_DNS_MODE_PROVIDER_HOSTNAME) {
- if (mHostnameLayout == null || mHostnameText == null) {
- Log.e(TAG, "Can't find hostname resources!");
- return;
- }
- if (mHostnameText.getText().isEmpty()) {
- mHostnameLayout.setError(context.getString(R.string.private_dns_field_require));
- Log.w(TAG, "The hostname is empty!");
- return;
- }
- if (!InternetDomainName.isValid(mHostnameText.getText().toString())) {
- mHostnameLayout.setError(context.getString(R.string.private_dns_hostname_invalid));
- Log.w(TAG, "The hostname is invalid!");
- return;
+ if (mMaDnsSelected) {
+ // Persist the preset exactly as a typed hostname. The
+ // hostname text is deliberately neither read nor validated
+ // here: nothing the user previously typed is consulted,
+ // and the fixed hostname needs no validation.
+ ConnectivitySettingsManager.setPrivateDnsHostname(context,
+ MAOS_PRIVATE_DNS_HOSTNAME);
+ } else {
+ if (mHostnameLayout == null || mHostnameText == null) {
+ Log.e(TAG, "Can't find hostname resources!");
+ return;
+ }
+ if (mHostnameText.getText().isEmpty()) {
+ mHostnameLayout.setError(
+ context.getString(R.string.private_dns_field_require));
+ Log.w(TAG, "The hostname is empty!");
+ return;
+ }
+ if (!InternetDomainName.isValid(mHostnameText.getText().toString())) {
+ mHostnameLayout.setError(
+ context.getString(R.string.private_dns_hostname_invalid));
+ Log.w(TAG, "The hostname is invalid!");
+ return;
+ }
+
+ ConnectivitySettingsManager.setPrivateDnsHostname(context,
+ mHostnameText.getText().toString());
}
-
- ConnectivitySettingsManager.setPrivateDnsHostname(context,
- mHostnameText.getText().toString());
}
ConnectivitySettingsManager.setPrivateDnsMode(context, mMode);