Eval enabled

This commit is contained in:
M66B 2019-12-06 21:42:56 +01:00
parent 30c58b8e22
commit 71bc0bcefb
1 changed files with 24 additions and 16 deletions

View File

@ -196,36 +196,42 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
@Override @Override
public void onChanged(List<TupleAccountNetworkState> accountNetworkStates) { public void onChanged(List<TupleAccountNetworkState> accountNetworkStates) {
boolean running = false; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ServiceSynchronize.this);
boolean enabled = prefs.getBoolean("enabled", true);
boolean runService = false;
for (TupleAccountNetworkState current : accountNetworkStates) { for (TupleAccountNetworkState current : accountNetworkStates) {
if (current.accountState.shouldRun()) if (enabled && current.accountState.shouldRun())
running = true; runService = true;
int index = accountStates.indexOf(current); int index = accountStates.indexOf(current);
if (index < 0) { if (index < 0) {
if (current.shouldRun()) if (enabled && current.shouldRun())
start(current); start(current);
} else { } else {
TupleAccountNetworkState prev = accountStates.get(index); TupleAccountNetworkState prev = accountStates.get(index);
accountStates.remove(index); accountStates.remove(index);
if (enabled) {
if (current.reload || if (current.reload ||
!prev.accountState.equals(current.accountState) || !prev.accountState.equals(current.accountState) ||
prev.shouldRun() != current.shouldRun()) { prev.shouldRun() != current.shouldRun()) {
Log.i("XXX account=" + current + Log.i("XXX account=" + current +
" reload=" + current.reload + " change=" + !prev.accountState.equals(current.accountState)); " reload=" + current.reload + " change=" + !prev.accountState.equals(current.accountState));
if (prev.shouldRun())
stop(prev);
if (current.shouldRun())
start(prev);
}
} else {
if (prev.shouldRun()) if (prev.shouldRun())
stop(prev); stop(prev);
if (current.shouldRun())
start(prev);
} }
} }
accountStates.add(current); accountStates.add(current);
} }
if (!running) if (!runService)
stopSelf(); stopSelf();
} }
@ -428,14 +434,16 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
} }
private static final List<String> POST_EVAL = private static final List<String> POST_EVAL =
Collections.unmodifiableList(Arrays.asList("metered", "roaming", "rlah")); Collections.unmodifiableList(Arrays.asList("enabled"));
private static final List<String> POST_RELOAD = private static final List<String> POST_RELOAD =
Collections.unmodifiableList(Arrays.asList("socks_enabled", "socks_proxy", "subscribed_only", "debug")); Collections.unmodifiableList(Arrays.asList(
"metered", "roaming", "rlah",
"socks_enabled", "socks_proxy", "subscribed_only", "debug"));
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if (POST_EVAL.contains(key)) if (POST_EVAL.contains(key))
liveAccountNetworkState.post(true); liveAccountNetworkState.post(false);
else if (POST_RELOAD.contains(key)) else if (POST_RELOAD.contains(key))
liveAccountNetworkState.post(true); liveAccountNetworkState.post(true);
} }