diff --git a/app/src/main/java/eu/faircode/email/ConnectionHelper.java b/app/src/main/java/eu/faircode/email/ConnectionHelper.java index 3e20c40228..57f0bb6a09 100644 --- a/app/src/main/java/eu/faircode/email/ConnectionHelper.java +++ b/app/src/main/java/eu/faircode/email/ConnectionHelper.java @@ -43,6 +43,10 @@ import java.util.Locale; import java.util.Objects; public class ConnectionHelper { + static final List PREF_NETWORK = Collections.unmodifiableList(Arrays.asList( + "metered", "roaming", "rlah" // update network state + )); + // Roam like at home // https://en.wikipedia.org/wiki/European_Union_roaming_regulations private static final List RLAH_COUNTRY_CODES = Collections.unmodifiableList(Arrays.asList( diff --git a/app/src/main/java/eu/faircode/email/ServiceSend.java b/app/src/main/java/eu/faircode/email/ServiceSend.java index 486e15a2d5..1a3b9bfca1 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSend.java +++ b/app/src/main/java/eu/faircode/email/ServiceSend.java @@ -63,7 +63,7 @@ import javax.mail.internet.MimeMessage; import static android.os.Process.THREAD_PRIORITY_BACKGROUND; -public class ServiceSend extends ServiceBase { +public class ServiceSend extends ServiceBase implements SharedPreferences.OnSharedPreferenceChangeListener { private TupleUnsent lastUnsent = null; private boolean lastSuitable = false; @@ -150,12 +150,16 @@ public class ServiceSend extends ServiceBase { iif.addAction(ConnectivityManager.CONNECTIVITY_ACTION); iif.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED); registerReceiver(connectionChangedReceiver, iif); + + PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this); } @Override public void onDestroy() { EntityLog.log(this, "Service send destroy"); + PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this); + unregisterReceiver(connectionChangedReceiver); ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); @@ -172,6 +176,12 @@ public class ServiceSend extends ServiceBase { super.onDestroy(); } + @Override + public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { + if (ConnectionHelper.PREF_NETWORK.contains(key)) + checkConnectivity(); + } + @Override public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 316ecdb7de..9037c3a502 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -131,10 +131,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences "enabled", "poll_interval" // restart account(s) )); - private static final List PREF_NETWORK = Collections.unmodifiableList(Arrays.asList( - "metered", "roaming", "rlah" // update network state - )); - private static final List PREF_RELOAD = Collections.unmodifiableList(Arrays.asList( "ssl_harden", // force reconnect "badge", "unseen_ignored", // force update badge/widget @@ -616,8 +612,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { - if (PREF_EVAL.contains(key) || PREF_NETWORK.contains(key)) { - if (PREF_NETWORK.contains(key)) + if (PREF_EVAL.contains(key) || ConnectionHelper.PREF_NETWORK.contains(key)) { + if (ConnectionHelper.PREF_NETWORK.contains(key)) updateNetworkState(null, null); Bundle command = new Bundle();