Fixed orphan sync threads

pull/200/head
M66B 4 years ago
parent 0a417725eb
commit 2e85b3bc0d

@ -263,14 +263,17 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
boolean sync = current.command.getBoolean("sync", false); boolean sync = current.command.getBoolean("sync", false);
boolean force = current.command.getBoolean("force", false); boolean force = current.command.getBoolean("force", false);
if (force) if (force) {
sync = true; sync = true;
current.accountState.operations++;
}
int index = accountStates.indexOf(current); int index = accountStates.indexOf(current);
if (index < 0) { if (index < 0) {
if (current.canRun(force)) { if (current.canRun()) {
EntityLog.log(ServiceSynchronize.this, "### new " + current + EntityLog.log(ServiceSynchronize.this, "### new " + current +
" start=" + current.canRun(force) + " force=" + force +
" start=" + current.canRun() +
" sync=" + current.accountState.isEnabled(current.enabled) + " sync=" + current.accountState.isEnabled(current.enabled) +
" enabled=" + current.accountState.synchronize + " enabled=" + current.accountState.synchronize +
" ondemand=" + current.accountState.ondemand + " ondemand=" + current.accountState.ondemand +
@ -300,14 +303,14 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
// Some networks disallow email server connections: // Some networks disallow email server connections:
// - reload on network type change when disconnected // - reload on network type change when disconnected
if (reload || if (reload ||
prev.canRun(force) != current.canRun(force) || prev.canRun() != current.canRun() ||
!prev.accountState.equals(current.accountState)) { !prev.accountState.equals(current.accountState)) {
if (prev.canRun(force) || current.canRun(force)) if (prev.canRun() || current.canRun())
EntityLog.log(ServiceSynchronize.this, "### changed " + current + EntityLog.log(ServiceSynchronize.this, "### changed " + current +
" reload=" + reload + " reload=" + reload +
" force=" + force + " force=" + force +
" stop=" + prev.canRun(force) + " stop=" + prev.canRun() +
" start=" + current.canRun(force) + " start=" + current.canRun() +
" sync=" + sync + " sync=" + sync +
" enabled=" + current.accountState.isEnabled(current.enabled) + " enabled=" + current.accountState.isEnabled(current.enabled) +
" should=" + current.accountState.shouldRun(current.enabled) + " should=" + current.accountState.shouldRun(current.enabled) +
@ -319,11 +322,11 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
" tbd=" + current.accountState.tbd + " tbd=" + current.accountState.tbd +
" state=" + current.accountState.state + " state=" + current.accountState.state +
" active=" + prev.networkState.getActive() + "/" + current.networkState.getActive()); " active=" + prev.networkState.getActive() + "/" + current.networkState.getActive());
if (prev.canRun(force)) { if (prev.canRun()) {
event = true; event = true;
stop(prev); stop(prev);
} }
if (current.canRun(force)) { if (current.canRun()) {
event = true; event = true;
start(current, current.accountState.isEnabled(current.enabled) || sync, force); start(current, current.accountState.isEnabled(current.enabled) || sync, force);
} }

@ -44,8 +44,8 @@ public class TupleAccountNetworkState {
this.accountState = accountState; this.accountState = accountState;
} }
public boolean canRun(boolean force) { public boolean canRun() {
return (this.networkState.isSuitable() && this.accountState.shouldRun(enabled || force)); return (this.networkState.isSuitable() && this.accountState.shouldRun(enabled));
} }
@Override @Override

Loading…
Cancel
Save