From b051aaf41ef82b67e9d780e8de1378993b906ee1 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 27 Oct 2020 13:22:23 +0100 Subject: [PATCH] Added option to prefer IPv4 --- .../main/java/eu/faircode/email/EmailService.java | 12 ++++++++++++ .../faircode/email/FragmentOptionsConnection.java | 12 +++++++++++- .../java/eu/faircode/email/ServiceSynchronize.java | 2 +- .../main/res/layout/fragment_options_connection.xml | 13 ++++++++++++- app/src/main/res/values/strings.xml | 1 + 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/EmailService.java b/app/src/main/java/eu/faircode/email/EmailService.java index 6b34ce7e3c..0d5c1af9d4 100644 --- a/app/src/main/java/eu/faircode/email/EmailService.java +++ b/app/src/main/java/eu/faircode/email/EmailService.java @@ -431,6 +431,18 @@ public class EmailService implements AutoCloseable { // new SocketConnectException("Debug", new IOException("Test"), host, port, 0)); main = InetAddress.getByName(host); + + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean prefer_ip4 = prefs.getBoolean("prefer_ip4", false); + if (prefer_ip4 && main instanceof Inet6Address) { + for (InetAddress iaddr : InetAddress.getAllByName(host)) + if (iaddr instanceof Inet4Address) { + main = iaddr; + EntityLog.log(context, "Preferring=" + main); + break; + } + } + EntityLog.log(context, "Connecting to " + main); _connect(main, port, require_id, user, authenticator, factory); } catch (UnknownHostException ex) { diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java b/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java index 3255cf4482..fe764a4b02 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java @@ -58,13 +58,14 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre private SwitchCompat swRoaming; private SwitchCompat swRlah; private EditText etTimeout; + private SwitchCompat swPreferIp4; private SwitchCompat swSslHarden; private Button btnManage; private TextView tvConnectionType; private TextView tvConnectionRoaming; private final static String[] RESET_OPTIONS = new String[]{ - "metered", "download", "roaming", "rlah", "timeout", "ssl_harden" + "metered", "download", "roaming", "rlah", "timeout", "prefer_ip4", "ssl_harden" }; @Override @@ -82,6 +83,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre swRoaming = view.findViewById(R.id.swRoaming); swRlah = view.findViewById(R.id.swRlah); etTimeout = view.findViewById(R.id.etTimeout); + swPreferIp4 = view.findViewById(R.id.swPreferIp4); swSslHarden = view.findViewById(R.id.swSslHarden); btnManage = view.findViewById(R.id.btnManage); @@ -153,6 +155,13 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre } }); + swPreferIp4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("prefer_ip4", checked).apply(); + } + }); + swSslHarden.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -266,6 +275,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre etTimeout.setText(timeout == 0 ? null : Integer.toString(timeout)); etTimeout.setHint(Integer.toString(EmailService.DEFAULT_CONNECT_TIMEOUT)); + swPreferIp4.setChecked(prefs.getBoolean("prefer_ip4", false)); swSslHarden.setChecked(prefs.getBoolean("ssl_harden", false)); } diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 465e1ac0e9..376de379f6 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -134,7 +134,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences "sync_kept", "sync_folders", "sync_shared_folders", - "ssl_harden", // force reconnect + "prefer_ip4", "ssl_harden", // force reconnect "badge", "unseen_ignored", // force update badge/widget "protocol", "debug", // force reconnect "auth_plain", diff --git a/app/src/main/res/layout/fragment_options_connection.xml b/app/src/main/res/layout/fragment_options_connection.xml index 9c2bcfe9bd..686fec2359 100644 --- a/app/src/main/res/layout/fragment_options_connection.xml +++ b/app/src/main/res/layout/fragment_options_connection.xml @@ -184,6 +184,17 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvTimeoutHint" /> + + Download messages and attachments while roaming Roam like at home Connection timeout (seconds) + Prefer IPv4 over IPv6 Harden SSL connections Manage connectivity