Update send network state on settings changes

This commit is contained in:
M66B 2020-07-27 16:33:24 +02:00
parent 0fd36955ec
commit c7d476354b
3 changed files with 17 additions and 7 deletions

View File

@ -43,6 +43,10 @@ import java.util.Locale;
import java.util.Objects;
public class ConnectionHelper {
static final List<String> 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<String> RLAH_COUNTRY_CODES = Collections.unmodifiableList(Arrays.asList(

View File

@ -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);

View File

@ -131,10 +131,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
"enabled", "poll_interval" // restart account(s)
));
private static final List<String> PREF_NETWORK = Collections.unmodifiableList(Arrays.asList(
"metered", "roaming", "rlah" // update network state
));
private static final List<String> 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();