mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-28 02:37:16 +00:00
Prevent race condition on quit
This commit is contained in:
parent
df59723f08
commit
a77f73ea71
1 changed files with 16 additions and 9 deletions
|
@ -90,6 +90,7 @@ import me.leolin.shortcutbadger.ShortcutBadger;
|
|||
import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
|
||||
|
||||
public class ServiceSynchronize extends ServiceBase implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private Integer lastStartId = null;
|
||||
private Boolean lastSuitable = null;
|
||||
private long lastLost = 0;
|
||||
private int lastAccounts = 0;
|
||||
|
@ -179,7 +180,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
for (TupleAccountNetworkState prev : accountStates)
|
||||
stop(prev);
|
||||
|
||||
quit();
|
||||
quit(null);
|
||||
|
||||
accountStates.clear();
|
||||
coreStates.clear();
|
||||
|
@ -261,7 +262,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
nm.notify(Helper.NOTIFICATION_SYNCHRONIZE, getNotificationService(lastAccounts, lastOperations).build());
|
||||
}
|
||||
} else
|
||||
quit();
|
||||
quit(lastStartId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -343,7 +344,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
});
|
||||
}
|
||||
|
||||
private void quit() {
|
||||
private void quit(final Integer startId) {
|
||||
EntityLog.log(ServiceSynchronize.this, "Service quit");
|
||||
|
||||
queue.submit(new Runnable() {
|
||||
|
@ -357,13 +358,18 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
Log.w(ex);
|
||||
}
|
||||
|
||||
DB db = DB.getInstance(ServiceSynchronize.this);
|
||||
List<EntityOperation> ops = db.operation().getOperations(EntityOperation.SYNC);
|
||||
for (EntityOperation op : ops)
|
||||
db.folder().setFolderSyncState(op.folder, null);
|
||||
if (startId != null) {
|
||||
stopSelf(startId);
|
||||
|
||||
stopSelf();
|
||||
EntityLog.log(ServiceSynchronize.this, "### quited");
|
||||
if (startId.equals(lastStartId)) {
|
||||
DB db = DB.getInstance(ServiceSynchronize.this);
|
||||
List<EntityOperation> ops = db.operation().getOperations(EntityOperation.SYNC);
|
||||
for (EntityOperation op : ops)
|
||||
db.folder().setFolderSyncState(op.folder, null);
|
||||
}
|
||||
|
||||
EntityLog.log(ServiceSynchronize.this, "### quit requested");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -577,6 +583,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
lastStartId = startId;
|
||||
String action = (intent == null ? null : intent.getAction());
|
||||
String reason = (intent == null ? null : intent.getStringExtra("reason"));
|
||||
EntityLog.log(ServiceSynchronize.this, "### Service command " + intent +
|
||||
|
|
Loading…
Reference in a new issue