Added custom DNS resolver option

pull/214/head
M66B 8 months ago
parent 68792a9859
commit 6b90d0e166

@ -20,6 +20,7 @@ package eu.faircode.email;
*/
import android.content.Context;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.DnsResolver;
import android.net.LinkProperties;
@ -29,6 +30,7 @@ import android.os.Build;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;
import org.minidns.DnsClient;
import org.minidns.dnsmessage.DnsMessage;
@ -310,10 +312,20 @@ public class DnsHelper {
}
static InetAddress getByName(Context context, String host) throws UnknownHostException {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean custom_dns = prefs.getBoolean("custom_dns", false);
if (!custom_dns)
return InetAddress.getByName(host);
return getAllByName(context, host)[0];
}
static InetAddress[] getAllByName(Context context, String host) throws UnknownHostException {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean custom_dns = prefs.getBoolean("custom_dns", false);
if (!custom_dns)
return InetAddress.getAllByName(host);
List<InetAddress> result = new ArrayList<>();
boolean[] has46 = ConnectionHelper.has46(context);

@ -95,6 +95,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
private SwitchCompat swBindSocket;
private SwitchCompat swStandaloneVpn;
private SwitchCompat swTcpKeepAlive;
private SwitchCompat swCustomDns;
private SwitchCompat swSslUpdate;
private SwitchCompat swSslHarden;
private SwitchCompat swSslHardenStrict;
@ -125,7 +126,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
"metered", "download", "download_limited", "roaming", "rlah",
"download_headers", "download_eml", "download_plain",
"require_validated", "require_validated_captive", "vpn_only",
"timeout", "prefer_ip4", "bind_socket", "standalone_vpn", "tcp_keep_alive",
"timeout", "prefer_ip4", "bind_socket", "standalone_vpn", "tcp_keep_alive", "custom_dns",
"ssl_update", "ssl_harden", "ssl_harden_strict", "cert_strict", "cert_transparency", "check_names",
"open_safe", "http_redirect",
"bouncy_castle", "bc_fips"
@ -158,6 +159,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
swBindSocket = view.findViewById(R.id.swBindSocket);
swStandaloneVpn = view.findViewById(R.id.swStandaloneVpn);
swTcpKeepAlive = view.findViewById(R.id.swTcpKeepAlive);
swCustomDns = view.findViewById(R.id.swCustomDns);
swSslUpdate = view.findViewById(R.id.swSslUpdate);
swSslHarden = view.findViewById(R.id.swSslHarden);
swSslHardenStrict = view.findViewById(R.id.swSslHardenStrict);
@ -350,6 +352,13 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
}
});
swCustomDns.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton v, boolean checked) {
prefs.edit().putBoolean("custom_dns", checked).apply();
}
});
swSslUpdate.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton v, boolean checked) {
@ -715,6 +724,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
swBindSocket.setChecked(prefs.getBoolean("bind_socket", false));
swStandaloneVpn.setChecked(prefs.getBoolean("standalone_vpn", false));
swTcpKeepAlive.setChecked(prefs.getBoolean("tcp_keep_alive", false));
swCustomDns.setChecked(prefs.getBoolean("custom_dns", false));
swSslUpdate.setChecked(prefs.getBoolean("ssl_update", true));
swSslHarden.setChecked(prefs.getBoolean("ssl_harden", false));
swSslHardenStrict.setChecked(prefs.getBoolean("ssl_harden_strict", false));

@ -171,7 +171,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
"sync_folders",
"sync_shared_folders",
"download_headers", "download_eml",
"prefer_ip4", "bind_socket", "standalone_vpn", "tcp_keep_alive", // force reconnect
"prefer_ip4", "bind_socket", "standalone_vpn", "tcp_keep_alive", "custom_dns", // force reconnect
"ssl_harden", "ssl_harden_strict", "cert_strict", "cert_transparency", "check_names", "bouncy_castle", "bc_fips", // force reconnect
"experiments", "debug", "protocol", // force reconnect
"auth_plain", "auth_login", "auth_ntlm", "auth_sasl", "auth_apop", // force reconnect

@ -448,6 +448,18 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swTcpKeepAlive" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swCustomDns"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:tag="nosuggest"
android:text="@string/title_advanced_custom_dns"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvTcpKeepAliveHint"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swSslUpdate"
android:layout_width="0dp"
@ -457,7 +469,7 @@
android:text="@string/title_advanced_ssl_update"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvTcpKeepAliveHint"
app:layout_constraintTop_toBottomOf="@id/swCustomDns"
app:switchPadding="12dp" />
<TextView

@ -518,6 +518,7 @@
<string name="title_advanced_bind_socket" translatable="false">Bind sockets to the active network</string>
<string name="title_advanced_standalone_vpn" translatable="false">Standalone VPN</string>
<string name="title_advanced_tcp_keep_alive" translatable="false">TCP keep alive</string>
<string name="title_advanced_custom_dns">Use custom DNS resolver</string>
<string name="title_advanced_ssl_update">Use updated SSL provider</string>
<string name="title_advanced_ssl_harden">Harden SSL connections</string>
<string name="title_advanced_ssl_harden_strict">Require TLS 1.3</string>

Loading…
Cancel
Save