Reload is synchroneous

pull/146/head
M66B 6 years ago
parent ec3c746f93
commit 1c523f1d63

@ -2436,61 +2436,59 @@ public class ServiceSynchronize extends LifecycleService {
} }
private void queue_reload(final boolean start, final String reason) { private void queue_reload(final boolean start, final String reason) {
synchronized (queue) { final boolean doStop = started;
final boolean doStop = started; final boolean doStart = (start && isEnabled() && suitableNetwork());
final boolean doStart = (start && isEnabled() && suitableNetwork());
if (!doStop && !doStart) if (!doStop && !doStart)
return; return;
EntityLog.log(ServiceSynchronize.this, "Queue reload " + EntityLog.log(ServiceSynchronize.this, "Queue reload " +
" doStop=" + doStop + " doStart=" + doStart + " queued=" + queued + " " + reason); " doStop=" + doStop + " doStart=" + doStart + " queued=" + queued + " " + reason);
queued++; queued++;
queue.submit(new Runnable() { queue.submit(new Runnable() {
PowerManager pm = getSystemService(PowerManager.class); PowerManager pm = getSystemService(PowerManager.class);
PowerManager.WakeLock wl = pm.newWakeLock( PowerManager.WakeLock wl = pm.newWakeLock(
PowerManager.PARTIAL_WAKE_LOCK, PowerManager.PARTIAL_WAKE_LOCK,
BuildConfig.APPLICATION_ID + ":reload"); BuildConfig.APPLICATION_ID + ":reload");
@Override @Override
public void run() { public void run() {
EntityLog.log(ServiceSynchronize.this, "Reload " + EntityLog.log(ServiceSynchronize.this, "Reload " +
" doStop=" + doStop + " doStart=" + doStart + " queued=" + queued + " " + reason); " stop=" + doStop + " start=" + doStart + " queued=" + queued + " " + reason);
try { try {
wl.acquire(); wl.acquire();
if (doStop) if (doStop)
stop(); stop();
if (doStart) if (doStart)
start(); start();
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
} finally { } finally {
wl.release(); wl.release();
queued--; queued--;
EntityLog.log(ServiceSynchronize.this, "Reload done queued=" + queued); EntityLog.log(ServiceSynchronize.this, "Reload done queued=" + queued);
if (queued == 0 && !isEnabled()) {
try {
Thread.sleep(STOP_DELAY);
} catch (InterruptedException ignored) {
}
if (queued == 0 && !isEnabled()) { if (queued == 0 && !isEnabled()) {
try { EntityLog.log(ServiceSynchronize.this, "Service stop");
Thread.sleep(STOP_DELAY); stopSelf();
} catch (InterruptedException ignored) {
}
if (queued == 0 && !isEnabled()) {
EntityLog.log(ServiceSynchronize.this, "Service stop");
stopSelf();
}
} }
} }
} }
}); }
});
started = doStart; started = doStart;
}
} }
private BroadcastReceiver outboxReceiver = new BroadcastReceiver() { private BroadcastReceiver outboxReceiver = new BroadcastReceiver() {

Loading…
Cancel
Save