Update send network state on settings changes

pull/184/head
M66B 4 years ago
parent 0fd36955ec
commit c7d476354b

@ -43,6 +43,10 @@ import java.util.Locale;
import java.util.Objects; import java.util.Objects;
public class ConnectionHelper { public class ConnectionHelper {
static final List<String> PREF_NETWORK = Collections.unmodifiableList(Arrays.asList(
"metered", "roaming", "rlah" // update network state
));
// Roam like at home // Roam like at home
// https://en.wikipedia.org/wiki/European_Union_roaming_regulations // https://en.wikipedia.org/wiki/European_Union_roaming_regulations
private static final List<String> RLAH_COUNTRY_CODES = Collections.unmodifiableList(Arrays.asList( private static final List<String> RLAH_COUNTRY_CODES = Collections.unmodifiableList(Arrays.asList(

@ -63,7 +63,7 @@ import javax.mail.internet.MimeMessage;
import static android.os.Process.THREAD_PRIORITY_BACKGROUND; 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 TupleUnsent lastUnsent = null;
private boolean lastSuitable = false; private boolean lastSuitable = false;
@ -150,12 +150,16 @@ public class ServiceSend extends ServiceBase {
iif.addAction(ConnectivityManager.CONNECTIVITY_ACTION); iif.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
iif.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED); iif.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
registerReceiver(connectionChangedReceiver, iif); registerReceiver(connectionChangedReceiver, iif);
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
} }
@Override @Override
public void onDestroy() { public void onDestroy() {
EntityLog.log(this, "Service send destroy"); EntityLog.log(this, "Service send destroy");
PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);
unregisterReceiver(connectionChangedReceiver); unregisterReceiver(connectionChangedReceiver);
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
@ -172,6 +176,12 @@ public class ServiceSend extends ServiceBase {
super.onDestroy(); super.onDestroy();
} }
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if (ConnectionHelper.PREF_NETWORK.contains(key))
checkConnectivity();
}
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId); super.onStartCommand(intent, flags, startId);

@ -131,10 +131,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
"enabled", "poll_interval" // restart account(s) "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( private static final List<String> PREF_RELOAD = Collections.unmodifiableList(Arrays.asList(
"ssl_harden", // force reconnect "ssl_harden", // force reconnect
"badge", "unseen_ignored", // force update badge/widget "badge", "unseen_ignored", // force update badge/widget
@ -616,8 +612,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if (PREF_EVAL.contains(key) || PREF_NETWORK.contains(key)) { if (PREF_EVAL.contains(key) || ConnectionHelper.PREF_NETWORK.contains(key)) {
if (PREF_NETWORK.contains(key)) if (ConnectionHelper.PREF_NETWORK.contains(key))
updateNetworkState(null, null); updateNetworkState(null, null);
Bundle command = new Bundle(); Bundle command = new Bundle();

Loading…
Cancel
Save