DNS: backward compatibility

pull/214/head
M66B 12 months ago
parent 788b02f104
commit 3d54182e2b

@ -104,6 +104,7 @@ public class DnsHelper {
@NonNull @NonNull
private static DnsRecord[] _lookup(Context context, String name, String type, int timeout) { private static DnsRecord[] _lookup(Context context, String name, String type, int timeout) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean dns_custom = prefs.getBoolean("dns_custom", false);
boolean dns_secure = prefs.getBoolean("dns_secure", false); boolean dns_secure = prefs.getBoolean("dns_secure", false);
String filter = null; String filter = null;
@ -141,7 +142,7 @@ public class DnsHelper {
ResolverApi resolver = DnssecResolverApi.INSTANCE; ResolverApi resolver = DnssecResolverApi.INSTANCE;
AbstractDnsClient client = resolver.getClient(); 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() { client.setDataSource(new AbstractDnsDataSource() {
private IOException ex; private IOException ex;
private DnsQueryResult result; private DnsQueryResult result;

@ -94,8 +94,8 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
private SwitchCompat swPreferIp4; private SwitchCompat swPreferIp4;
private SwitchCompat swBindSocket; private SwitchCompat swBindSocket;
private SwitchCompat swStandaloneVpn; private SwitchCompat swStandaloneVpn;
private EditText etDns;
private SwitchCompat swDnsCustom; private SwitchCompat swDnsCustom;
private EditText etDnsExtra;
private SwitchCompat swDnsSecure; private SwitchCompat swDnsSecure;
private SwitchCompat swTcpKeepAlive; private SwitchCompat swTcpKeepAlive;
private SwitchCompat swSslUpdate; private SwitchCompat swSslUpdate;
@ -162,8 +162,8 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
swPreferIp4 = view.findViewById(R.id.swPreferIp4); swPreferIp4 = view.findViewById(R.id.swPreferIp4);
swBindSocket = view.findViewById(R.id.swBindSocket); swBindSocket = view.findViewById(R.id.swBindSocket);
swStandaloneVpn = view.findViewById(R.id.swStandaloneVpn); swStandaloneVpn = view.findViewById(R.id.swStandaloneVpn);
etDns = view.findViewById(R.id.etDns);
swDnsCustom = view.findViewById(R.id.swDnsCustom); swDnsCustom = view.findViewById(R.id.swDnsCustom);
etDnsExtra = view.findViewById(R.id.etDnsExtra);
swDnsSecure = view.findViewById(R.id.swDnsSecure); swDnsSecure = view.findViewById(R.id.swDnsSecure);
swTcpKeepAlive = view.findViewById(R.id.swTcpKeepAlive); swTcpKeepAlive = view.findViewById(R.id.swTcpKeepAlive);
swSslUpdate = view.findViewById(R.id.swSslUpdate); 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 @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// Do nothing // 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.setVisibility(debug || BuildConfig.DEBUG ? View.VISIBLE : View.GONE);
swDnsSecure.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swDnsSecure.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
@ -759,8 +760,9 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
swPreferIp4.setChecked(prefs.getBoolean("prefer_ip4", true)); swPreferIp4.setChecked(prefs.getBoolean("prefer_ip4", true));
swBindSocket.setChecked(prefs.getBoolean("bind_socket", false)); swBindSocket.setChecked(prefs.getBoolean("bind_socket", false));
swStandaloneVpn.setChecked(prefs.getBoolean("standalone_vpn", false)); swStandaloneVpn.setChecked(prefs.getBoolean("standalone_vpn", false));
etDns.setText(prefs.getString("dns_extra", null));
swDnsCustom.setChecked(prefs.getBoolean("dns_custom", false)); 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.setChecked(prefs.getBoolean("dns_secure", false));
swDnsSecure.setEnabled(swDnsCustom.isChecked()); swDnsSecure.setEnabled(swDnsCustom.isChecked());
swTcpKeepAlive.setChecked(prefs.getBoolean("tcp_keep_alive", false)); swTcpKeepAlive.setChecked(prefs.getBoolean("tcp_keep_alive", false));

@ -423,10 +423,22 @@
app:layout_constraintTop_toBottomOf="@id/swBindSocket" app:layout_constraintTop_toBottomOf="@id/swBindSocket"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swDnsCustom"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_dns_custom"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swStandaloneVpn"
app:switchPadding="12dp" />
<TextView <TextView
android:id="@+id/tvDns" android:id="@+id/tvDns"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:layout_marginEnd="48dp" android:layout_marginEnd="48dp"
android:text="@string/title_advanced_dns" android:text="@string/title_advanced_dns"
@ -434,10 +446,10 @@
android:textColor="?android:attr/textColorPrimary" android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swStandaloneVpn" /> app:layout_constraintTop_toBottomOf="@id/swDnsCustom" />
<eu.faircode.email.EditTextPlain <eu.faircode.email.EditTextPlain
android:id="@+id/etDns" android:id="@+id/etDnsExtra"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="48dp" android:layout_marginEnd="48dp"
@ -448,17 +460,6 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDns" /> app:layout_constraintTop_toBottomOf="@id/tvDns" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swDnsCustom"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_dns_custom"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etDns"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
android:id="@+id/swDnsSecure" android:id="@+id/swDnsSecure"
android:layout_width="0dp" android:layout_width="0dp"
@ -468,7 +469,7 @@
android:text="@string/title_advanced_dns_secure" android:text="@string/title_advanced_dns_secure"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swDnsCustom" app:layout_constraintTop_toBottomOf="@id/etDnsExtra"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat

Loading…
Cancel
Save