From 3d54182e2bc668f9c26fdf2f5b4b00cc349a3f1f Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 5 Jan 2024 20:24:05 +0100 Subject: [PATCH] DNS: backward compatibility --- .../java/eu/faircode/email/DnsHelper.java | 3 +- .../email/FragmentOptionsConnection.java | 28 +++++++++--------- .../layout/fragment_options_connection.xml | 29 ++++++++++--------- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DnsHelper.java b/app/src/main/java/eu/faircode/email/DnsHelper.java index e75fcc953f..093cafeed8 100644 --- a/app/src/main/java/eu/faircode/email/DnsHelper.java +++ b/app/src/main/java/eu/faircode/email/DnsHelper.java @@ -104,6 +104,7 @@ public class DnsHelper { @NonNull private static DnsRecord[] _lookup(Context context, String name, String type, int timeout) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean dns_custom = prefs.getBoolean("dns_custom", false); boolean dns_secure = prefs.getBoolean("dns_secure", false); String filter = null; @@ -141,7 +142,7 @@ public class DnsHelper { ResolverApi resolver = DnssecResolverApi.INSTANCE; AbstractDnsClient client = resolver.getClient(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && !dns_custom) client.setDataSource(new AbstractDnsDataSource() { private IOException ex; private DnsQueryResult result; diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java b/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java index 9e60614aa0..a02249272f 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java @@ -94,8 +94,8 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre private SwitchCompat swPreferIp4; private SwitchCompat swBindSocket; private SwitchCompat swStandaloneVpn; - private EditText etDns; private SwitchCompat swDnsCustom; + private EditText etDnsExtra; private SwitchCompat swDnsSecure; private SwitchCompat swTcpKeepAlive; private SwitchCompat swSslUpdate; @@ -162,8 +162,8 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre swPreferIp4 = view.findViewById(R.id.swPreferIp4); swBindSocket = view.findViewById(R.id.swBindSocket); swStandaloneVpn = view.findViewById(R.id.swStandaloneVpn); - etDns = view.findViewById(R.id.etDns); swDnsCustom = view.findViewById(R.id.swDnsCustom); + etDnsExtra = view.findViewById(R.id.etDnsExtra); swDnsSecure = view.findViewById(R.id.swDnsSecure); swTcpKeepAlive = view.findViewById(R.id.swTcpKeepAlive); swSslUpdate = view.findViewById(R.id.swSslUpdate); @@ -343,7 +343,17 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre } }); - etDns.addTextChangedListener(new TextWatcher() { + swDnsCustom.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean checked) { + DnsHelper.clear(buttonView.getContext()); + prefs.edit().putBoolean("dns_custom", checked).apply(); + etDnsExtra.setEnabled(checked || Build.VERSION.SDK_INT < Build.VERSION_CODES.Q); + swDnsSecure.setEnabled(checked); + } + }); + + etDnsExtra.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // Do nothing @@ -360,15 +370,6 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre } }); - swDnsCustom.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean checked) { - DnsHelper.clear(buttonView.getContext()); - prefs.edit().putBoolean("dns_custom", checked).apply(); - swDnsSecure.setEnabled(checked); - } - }); - swDnsSecure.setVisibility(debug || BuildConfig.DEBUG ? View.VISIBLE : View.GONE); swDnsSecure.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override @@ -759,8 +760,9 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre swPreferIp4.setChecked(prefs.getBoolean("prefer_ip4", true)); swBindSocket.setChecked(prefs.getBoolean("bind_socket", false)); swStandaloneVpn.setChecked(prefs.getBoolean("standalone_vpn", false)); - etDns.setText(prefs.getString("dns_extra", null)); swDnsCustom.setChecked(prefs.getBoolean("dns_custom", false)); + etDnsExtra.setText(prefs.getString("dns_extra", null)); + etDnsExtra.setEnabled(swDnsCustom.isEnabled() || Build.VERSION.SDK_INT < Build.VERSION_CODES.Q); swDnsSecure.setChecked(prefs.getBoolean("dns_secure", false)); swDnsSecure.setEnabled(swDnsCustom.isChecked()); swTcpKeepAlive.setChecked(prefs.getBoolean("tcp_keep_alive", false)); diff --git a/app/src/main/res/layout/fragment_options_connection.xml b/app/src/main/res/layout/fragment_options_connection.xml index a97fe9a6f3..9af0047db5 100644 --- a/app/src/main/res/layout/fragment_options_connection.xml +++ b/app/src/main/res/layout/fragment_options_connection.xml @@ -423,10 +423,22 @@ app:layout_constraintTop_toBottomOf="@id/swBindSocket" app:switchPadding="12dp" /> + + + app:layout_constraintTop_toBottomOf="@id/swDnsCustom" /> - -