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");
|
queue_reload(false, "service destroy");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _start() {
|
private void start() {
|
||||||
EntityLog.log(ServiceSynchronize.this, "Main start queued=" + queued);
|
EntityLog.log(ServiceSynchronize.this, "Main start queued=" + queued);
|
||||||
|
|
||||||
state = new ServiceState();
|
state = new ServiceState();
|
||||||
|
@ -2431,47 +2431,48 @@ public class ServiceSynchronize extends LifecycleService {
|
||||||
yieldWakelock();
|
yieldWakelock();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _stop() {
|
private void stop() {
|
||||||
PowerManager pm = getSystemService(PowerManager.class);
|
EntityLog.log(ServiceSynchronize.this, "Main stop");
|
||||||
PowerManager.WakeLock wl = pm.newWakeLock(
|
|
||||||
PowerManager.PARTIAL_WAKE_LOCK,
|
|
||||||
BuildConfig.APPLICATION_ID + ":stop");
|
|
||||||
try {
|
|
||||||
wl.acquire();
|
|
||||||
EntityLog.log(ServiceSynchronize.this, "Main stop");
|
|
||||||
|
|
||||||
state.running = false;
|
state.running = false;
|
||||||
state.semaphore.release();
|
state.semaphore.release();
|
||||||
join(state.thread);
|
join(state.thread);
|
||||||
|
|
||||||
EntityLog.log(ServiceSynchronize.this, "Main stopped queued=" + queued);
|
EntityLog.log(ServiceSynchronize.this, "Main stopped queued=" + queued);
|
||||||
|
|
||||||
state = null;
|
state = null;
|
||||||
} finally {
|
|
||||||
wl.release();
|
|
||||||
EntityLog.log(ServiceSynchronize.this, "Stop wake lock=" + wl.isHeld());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void queue_reload(final boolean start, String reason) {
|
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 doStop = started;
|
||||||
final boolean doStart = (start && isEnabled() && suitableNetwork());
|
final boolean doStart = (start && isEnabled() && suitableNetwork());
|
||||||
|
|
||||||
|
EntityLog.log(ServiceSynchronize.this, "Reload start=" + start +
|
||||||
|
" doStop=" + doStop + " doStart=" + doStart + " queued=" + queued + " " + reason);
|
||||||
|
|
||||||
queued++;
|
queued++;
|
||||||
lifecycle.submit(new Runnable() {
|
lifecycle.submit(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
PowerManager pm = getSystemService(PowerManager.class);
|
||||||
|
PowerManager.WakeLock wl = pm.newWakeLock(
|
||||||
|
PowerManager.PARTIAL_WAKE_LOCK,
|
||||||
|
BuildConfig.APPLICATION_ID + ":reload");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
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();
|
||||||
|
|
||||||
queued--;
|
queued--;
|
||||||
if (queued == 0 && !isEnabled()) {
|
if (queued == 0 && !isEnabled()) {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue