1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-02-27 00:13:13 +00:00

Cancel quit on operations pending

This commit is contained in:
M66B 2020-01-19 15:28:04 +01:00
parent a894e615b5
commit f93fed20a3

View file

@ -358,12 +358,15 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
return; return;
lastQuitId = startId; lastQuitId = startId;
EntityLog.log(ServiceSynchronize.this, "Service quit startId=" + startId); EntityLog.log(ServiceSynchronize.this,
"Service quit startId=" + startId + " ops=" + lastOperations);
queue.submit(new Runnable() { queue.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
Log.i("### quit"); Log.i("### quit startId=" + startId + "/" + lastQuitId + " ops=" + lastOperations);
if (lastOperations == 0)
return;
if (startId == null) { if (startId == null) {
// Service destroy // Service destroy
@ -372,7 +375,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
for (EntityOperation op : ops) for (EntityOperation op : ops)
db.folder().setFolderSyncState(op.folder, null); db.folder().setFolderSyncState(op.folder, null);
} else { } else {
// Delay for widget updates // Yield update notifications/widgets
try { try {
Thread.sleep(QUIT_DELAY); Thread.sleep(QUIT_DELAY);
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
@ -380,8 +383,9 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
} }
// Stop service // Stop service
boolean stopped = stopSelfResult(startId); boolean stopped = (lastOperations == 0 && stopSelfResult(startId));
EntityLog.log(ServiceSynchronize.this, "Service quited=" + stopped + " startId=" + startId); EntityLog.log(ServiceSynchronize.this, "Service quited=" + stopped +
" startId=" + startId + "/" + lastQuitId + " ops=" + lastOperations);
} }
} }
}); });
@ -1192,7 +1196,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
}); });
} }
// Keep alive // Keep alive
boolean first = true; boolean first = true;
while (state.isRunning()) { while (state.isRunning()) {
@ -1206,6 +1209,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
if (!ServiceSynchronize.this.getMainLooper().getThread().isAlive()) { if (!ServiceSynchronize.this.getMainLooper().getThread().isAlive()) {
Log.e("App died"); Log.e("App died");
EntityLog.log(ServiceSynchronize.this, account.name + " app died");
state.stop(); state.stop();
throw new StoreClosedException(iservice.getStore(), "App died"); throw new StoreClosedException(iservice.getStore(), "App died");
} }