Modern Apps git

← MAOS.git

maos: replace Private DNS prefill with an MA DNS radio option

Commit
88e9e994eda67b8cff35b66faee8ed53fd7cf2c3
Author
Vayun Mathur <[email protected]>
When
2026-11-17 15:40 UTC (18 days ago)
Parents
00ed539
Undo the Private DNS hostname prefill entirely and replace it with a
dedicated MA DNS choice in the Private DNS mode dialog.

The previous packages_apps_Settings_private_dns_prefill.patch seeded
dot.maproj.org into the hostname field of
PrivateDnsModeDialogPreference whenever the persisted hostname was
empty. That made an unchosen suggestion look like the current
specifier and conflated merely opening the dialog with having picked
our resolver. The new packages_apps_Settings_private_dns_ma_dns.patch
removes that behaviour: the hostname field now always shows only the
hostname that is actually persisted, with no seeding of any kind.

The patch adds a fourth radio button, labelled "MA DNS"
(R.string.private_dns_mode_ma_dns, @id/private_dns_mode_ma_dns),
alongside Off, Automatic and Private DNS provider hostname in
private_dns_mode_dialog.xml, between Automatic and the provider
hostname option. It is a preset, not a fourth Private DNS mode.
PrivateDnsModeDialogPreference tracks it with mMaDnsSelected while
keeping mMode at PRIVATE_DNS_MODE_PROVIDER_HOSTNAME, and on Save it
persists dot.maproj.org through
ConnectivitySettingsManager.setPrivateDnsHostname() followed by the
existing setPrivateDnsMode(PROVIDER_HOSTNAME) call. The persisted
Settings.Global PRIVATE_DNS_MODE / PRIVATE_DNS_SPECIFIER pair is
therefore exactly the pair a user typing dot.maproj.org would have
produced, so connectivity handling, PrivateDnsPreferenceController's
summary text and every other Private DNS reader behave consistently
with no special cases. dot.maproj.org remains the DNS-over-TLS
resolver (RFC 7858, TCP :853); doh.maproj.org remains the separate
DNS-over-HTTPS endpoint for browsers and is not used here.

Radio state reflects the persisted state honestly: when the dialog
opens with mode PROVIDER_HOSTNAME and specifier dot.maproj.org, MA
DNS is the checked radio; a provider setup with any other hostname
checks the provider hostname radio as before, and Off / Automatic
are unaffected. Switching away behaves with the standard mode
semantics. Off and Automatic clear mMaDnsSelected and write no
specifier, the hostname field is enabled only under the free-form
provider radio (it stays disabled under MA DNS, whose specifier is
fixed, as well as under Off / Automatic), and no code path rewrites
the hostname text in the dialog. Choosing MA DNS and saving does
overwrite the specifier with dot.maproj.org, as selecting that
preset means; choosing the provider hostname radio afterwards then
honestly shows dot.maproj.org in the field as the current specifier,
ready to edit or replace. Previously typed hostnames are otherwise
not clobbered: toggling between radios before Save leaves the text
untouched, and it is consulted and validated (non-empty,
InternetDomainName.isValid) only when saving under the provider
hostname radio.

The MA DNS label lives in a new res/values/maos_private_dns_strings.xml
rather than strings.xml or strings_ext.xml, so this patch shares no
hunks with the Settings patches applied before it in build-maos.sh.
build-maos.sh now registers
packages/apps/Settings:packages_apps_Settings_private_dns_ma_dns.patch
in place of the removed prefill patch, and the old
packages_apps_Settings_private_dns_prefill.patch file is deleted.

The patch was regenerated with git diff against the pristine
~/maos packages/apps/Settings files (the touched Java and layout
files were clean in that tree; the strings file is new), scoped to
exactly the three files it changes, so its hunk headers and blob
indexes are exact.

Verification: git apply --check of the new patch on the pristine
PrivateDnsModeDialogPreference.java, private_dns_mode_dialog.xml and
absent maos_private_dns_strings.xml passes, git apply followed by
git apply --reverse --check and a full reverse apply passes, both
XML files parse, the Settings tree was restored clean for the
touched paths afterwards, no reference to private_dns_prefill
remains in the repo, and bash -n build-maos.sh passes.

Not verified: an on-device open of Settings > Network & internet >
Private DNS showing and using the MA DNS radio, the resulting
summary text, or an actual DNS-over-TLS connection to
dot.maproj.org. There is no device to flash here, so that still
needs a flashed MAOS build containing this patch.

Diff

build-maos.sh
diff --git a/build-maos.sh b/build-maos.shindex d4ce0c0..8124908 100755--- a/build-maos.sh+++ b/build-maos.sh@@ -285,7 +285,7 @@ apply_maos_patches() {                 "packages/apps/Settings:settings.patch" \                 "packages/apps/Settings:packages_apps_Settings_ct_rkp_servers.patch" \                 "packages/apps/Settings:packages_apps_Settings_widevine_servers.patch" \-                "packages/apps/Settings:packages_apps_Settings_private_dns_prefill.patch" \+                "packages/apps/Settings:packages_apps_Settings_private_dns_ma_dns.patch" \                 "packages/apps/Settings:packages_apps_Settings_maos_attestation.patch" \                 "packages/apps/SetupWizard2:setupwizard2.patch" \                 "external/roboto-fonts:roboto_fonts.patch" \
patches/packages_apps_Settings_private_dns_ma_dns.patch
diff --git a/patches/packages_apps_Settings_private_dns_ma_dns.patch b/patches/packages_apps_Settings_private_dns_ma_dns.patchnew file mode 100644index 0000000..832876f--- /dev/null+++ b/patches/packages_apps_Settings_private_dns_ma_dns.patch@@ -0,0 +1,186 @@+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"/>+ ++            <include++                android:id="@+id/private_dns_mode_ma_dns"++                layout="@layout/preference_widget_dialog_radiobutton"/>+++             <include+                 android:id="@+id/private_dns_mode_provider"+                 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 @@++<?xml version="1.0" encoding="utf-8"?>++<!--++  MAOS Private DNS preset. Kept in its own values file so the MA DNS patch++  does not have to share strings.xml / strings_ext.xml hunks with the other++  Settings patches applied before it.++  -->++<resources>++    <string name="private_dns_mode_ma_dns">MA DNS</string>++</resources>+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<Integer, Integer> 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);
patches/packages_apps_Settings_private_dns_prefill.patch
diff --git a/patches/packages_apps_Settings_private_dns_prefill.patch b/patches/packages_apps_Settings_private_dns_prefill.patchdeleted file mode 100644index 189f9d5..0000000--- a/patches/packages_apps_Settings_private_dns_prefill.patch+++ /dev/null@@ -1,32 +0,0 @@-diff --git a/src/com/android/settings/network/PrivateDnsModeDialogPreference.java b/src/com/android/settings/network/PrivateDnsModeDialogPreference.java-index b9836f1b86d..75c4e10e185 100644---- a/src/com/android/settings/network/PrivateDnsModeDialogPreference.java-+++ b/src/com/android/settings/network/PrivateDnsModeDialogPreference.java-@@ -31,6 +31,7 @@ import android.net.ConnectivitySettingsManager;- import android.os.UserHandle;- import android.os.UserManager;- import android.text.Editable;-+import android.text.TextUtils;- import android.text.TextWatcher;- import android.text.method.LinkMovementMethod;- import android.util.AttributeSet;-@@ -154,7 +155,18 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat-         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));-+            final String currentHostname =-+                    ConnectivitySettingsManager.getPrivateDnsHostname(context);-+            // MAOS: pre-fill our DoT resolver (dot.maproj.org, RFC 7858-+            // DNS-over-TLS on :853) so choosing "Private DNS provider-+            // hostname" needs no typing. Android Private DNS is DoT, not-+            // DoH: doh.maproj.org stays for browsers/DoH clients and must-+            // NOT be used here. This is only a suggestion in the text-+            // field: it is persisted solely when the user keeps that mode-+            // and taps Save (see doSaveButton), and a hostname the user-+            // already set is never overwritten.-+            mHostnameText.setText(-+                    TextUtils.isEmpty(currentHostname) ? "dot.maproj.org" : currentHostname);-             mHostnameText.addTextChangedListener(this);-         }-