mirror of https://github.com/M66B/FairEmail.git
Synchronize reload
This commit is contained in:
parent
2224ed8ee9
commit
6f49e81c0c
|
@ -2251,7 +2251,7 @@ public class ServiceSynchronize extends LifecycleService {
|
||||||
private int queued = 0;
|
private int queued = 0;
|
||||||
private long lastLost = 0;
|
private long lastLost = 0;
|
||||||
private EntityFolder outbox = null;
|
private EntityFolder outbox = null;
|
||||||
private ExecutorService lifecycle = Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory);
|
private ExecutorService queue = Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory);
|
||||||
private ExecutorService executor = Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory);
|
private ExecutorService executor = Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2435,52 +2435,59 @@ public class ServiceSynchronize extends LifecycleService {
|
||||||
state = null;
|
state = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void queue_reload(final boolean start, String reason) {
|
private void queue_reload(final boolean start, final String reason) {
|
||||||
final boolean doStop = started;
|
synchronized (queue) {
|
||||||
final boolean doStart = (start && isEnabled() && suitableNetwork());
|
final boolean doStop = started;
|
||||||
|
final boolean doStart = (start && isEnabled() && suitableNetwork());
|
||||||
|
|
||||||
EntityLog.log(ServiceSynchronize.this, "Reload start=" + start +
|
EntityLog.log(ServiceSynchronize.this, "Queue reload " +
|
||||||
" doStop=" + doStop + " doStart=" + doStart + " queued=" + queued + " " + reason);
|
" doStop=" + doStop + " doStart=" + doStart + " queued=" + queued + " " + reason);
|
||||||
|
|
||||||
queued++;
|
queued++;
|
||||||
lifecycle.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() {
|
||||||
try {
|
EntityLog.log(ServiceSynchronize.this, "Reload " +
|
||||||
wl.acquire();
|
" doStop=" + doStop + " doStart=" + doStart + " queued=" + queued + " " + reason);
|
||||||
|
|
||||||
if (doStop)
|
try {
|
||||||
stop();
|
wl.acquire();
|
||||||
|
|
||||||
if (doStart)
|
if (doStop)
|
||||||
start();
|
stop();
|
||||||
|
|
||||||
} catch (Throwable ex) {
|
if (doStart)
|
||||||
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
|
start();
|
||||||
} finally {
|
|
||||||
wl.release();
|
} catch (Throwable ex) {
|
||||||
|
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
|
||||||
|
} finally {
|
||||||
|
wl.release();
|
||||||
|
|
||||||
|
queued--;
|
||||||
|
EntityLog.log(ServiceSynchronize.this, "Reload done queued=" + queued);
|
||||||
|
|
||||||
queued--;
|
|
||||||
if (queued == 0 && !isEnabled()) {
|
|
||||||
try {
|
|
||||||
Thread.sleep(STOP_DELAY);
|
|
||||||
} catch (InterruptedException ignored) {
|
|
||||||
}
|
|
||||||
if (queued == 0 && !isEnabled()) {
|
if (queued == 0 && !isEnabled()) {
|
||||||
EntityLog.log(ServiceSynchronize.this, "Service stop");
|
try {
|
||||||
stopSelf();
|
Thread.sleep(STOP_DELAY);
|
||||||
|
} 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…
Reference in New Issue