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
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) {
if (current.accountState.shouldRun())
running = true;
if (enabled && current.accountState.shouldRun())
runService = true;
int index = accountStates.indexOf(current);
if (index < 0) {
if (current.shouldRun())
if (enabled && current.shouldRun())
start(current);
} else {
TupleAccountNetworkState prev = accountStates.get(index);
accountStates.remove(index);
if (current.reload ||
!prev.accountState.equals(current.accountState) ||
prev.shouldRun() != current.shouldRun()) {
Log.i("XXX account=" + current +
" reload=" + current.reload + " change=" + !prev.accountState.equals(current.accountState));
if (enabled) {
if (current.reload ||
!prev.accountState.equals(current.accountState) ||
prev.shouldRun() != current.shouldRun()) {
Log.i("XXX account=" + current +
" reload=" + current.reload + " change=" + !prev.accountState.equals(current.accountState));
if (prev.shouldRun())
stop(prev);
if (current.shouldRun())
start(prev);
}
} else {
if (prev.shouldRun())
stop(prev);
if (current.shouldRun())
start(prev);
}
}
accountStates.add(current);
}
if (!running)
if (!runService)
stopSelf();
}
@ -428,14 +434,16 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
}
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 =
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
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if (POST_EVAL.contains(key))
liveAccountNetworkState.post(true);
liveAccountNetworkState.post(false);
else if (POST_RELOAD.contains(key))
liveAccountNetworkState.post(true);
}