From 54f1948886062fbcbddba6ef1285f9b3c889d7a3 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 24 Jan 2020 08:52:04 +0100 Subject: [PATCH] Service boot transaction --- .../eu/faircode/email/ServiceSynchronize.java | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index a2afa8542c..33b768d14c 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -1566,24 +1566,31 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences public void run() { try { DB db = DB.getInstance(context); + try { + db.beginTransaction(); - // Reset accounts - for (EntityAccount account : db.account().getAccounts()) - db.account().setAccountState(account.id, null); + // Reset accounts + for (EntityAccount account : db.account().getAccounts()) + db.account().setAccountState(account.id, null); - // reset folders - for (EntityFolder folder : db.folder().getFolders()) { - db.folder().setFolderState(folder.id, null); - db.folder().setFolderSyncState(folder.id, null); + // reset folders + for (EntityFolder folder : db.folder().getFolders()) { + db.folder().setFolderState(folder.id, null); + db.folder().setFolderSyncState(folder.id, null); + } + + // Restore notifications + db.message().clearNotifyingMessages(); + + // Restore snooze timers + for (EntityMessage message : db.message().getSnoozed()) + EntityMessage.snooze(context, message.id, message.ui_snoozed); + + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); } - // Restore notifications - db.message().clearNotifyingMessages(); - - // Restore snooze timers - for (EntityMessage message : db.message().getSnoozed()) - EntityMessage.snooze(context, message.id, message.ui_snoozed); - // Restore schedule schedule(context);