mirror of https://github.com/M66B/FairEmail.git
Reload wakelock
This commit is contained in:
parent
98f97139a5
commit
6917c0e9dc
|
@ -2320,7 +2320,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
queue_reload(false, "service destroy");
|
||||
}
|
||||
|
||||
private void _start() {
|
||||
private void start() {
|
||||
EntityLog.log(ServiceSynchronize.this, "Main start queued=" + queued);
|
||||
|
||||
state = new ServiceState();
|
||||
|
@ -2431,13 +2431,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
yieldWakelock();
|
||||
}
|
||||
|
||||
private void _stop() {
|
||||
PowerManager pm = getSystemService(PowerManager.class);
|
||||
PowerManager.WakeLock wl = pm.newWakeLock(
|
||||
PowerManager.PARTIAL_WAKE_LOCK,
|
||||
BuildConfig.APPLICATION_ID + ":stop");
|
||||
try {
|
||||
wl.acquire();
|
||||
private void stop() {
|
||||
EntityLog.log(ServiceSynchronize.this, "Main stop");
|
||||
|
||||
state.running = false;
|
||||
|
@ -2447,31 +2441,38 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
EntityLog.log(ServiceSynchronize.this, "Main stopped queued=" + queued);
|
||||
|
||||
state = null;
|
||||
} finally {
|
||||
wl.release();
|
||||
EntityLog.log(ServiceSynchronize.this, "Stop wake lock=" + wl.isHeld());
|
||||
}
|
||||
}
|
||||
|
||||
private void queue_reload(final boolean start, String reason) {
|
||||
EntityLog.log(ServiceSynchronize.this, "Reload start=" + start +
|
||||
" started=" + started + " queued=" + queued + " " + reason);
|
||||
|
||||
final boolean doStop = started;
|
||||
final boolean doStart = (start && isEnabled() && suitableNetwork());
|
||||
|
||||
EntityLog.log(ServiceSynchronize.this, "Reload start=" + start +
|
||||
" doStop=" + doStop + " doStart=" + doStart + " queued=" + queued + " " + reason);
|
||||
|
||||
queued++;
|
||||
lifecycle.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PowerManager pm = getSystemService(PowerManager.class);
|
||||
PowerManager.WakeLock wl = pm.newWakeLock(
|
||||
PowerManager.PARTIAL_WAKE_LOCK,
|
||||
BuildConfig.APPLICATION_ID + ":reload");
|
||||
|
||||
try {
|
||||
wl.acquire();
|
||||
|
||||
if (doStop)
|
||||
_stop();
|
||||
stop();
|
||||
|
||||
if (doStart)
|
||||
_start();
|
||||
start();
|
||||
|
||||
} catch (Throwable ex) {
|
||||
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
|
||||
} finally {
|
||||
wl.release();
|
||||
|
||||
queued--;
|
||||
if (queued == 0 && !isEnabled()) {
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue