From 8ea4753056c9c3b1b9e3cbfeff96bdd4163658c8 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 12 Jul 2020 08:44:50 +0200 Subject: [PATCH] Always synchronize folders on force sync --- app/src/main/java/eu/faircode/email/Core.java | 6 +++-- .../eu/faircode/email/ServiceSynchronize.java | 24 ++++++++++++------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index dd8eb79a1b..34f479e6b4 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -1427,11 +1427,13 @@ class Core { } } - static void onSynchronizeFolders(Context context, EntityAccount account, Store istore, State state) throws MessagingException { + static void onSynchronizeFolders( + Context context, EntityAccount account, Store istore, + State state, boolean force) throws MessagingException { DB db = DB.getInstance(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - boolean sync_folders = prefs.getBoolean("sync_folders", true); + boolean sync_folders = (prefs.getBoolean("sync_folders", true) || force); boolean sync_shared_folders = prefs.getBoolean("sync_shared_folders", false); // Get folder names diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 8d5b467767..2ebcef1deb 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -223,7 +223,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences if (index < 0) { if (current.canRun()) { EntityLog.log(ServiceSynchronize.this, "### new " + current); - start(current, current.accountState.isEnabled(current.enabled)); + start(current, current.accountState.isEnabled(current.enabled), false); } } else { TupleAccountNetworkState prev = accountStates.get(index); @@ -233,6 +233,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences boolean reload = false; boolean sync = current.command.getBoolean("sync", false); + boolean force = current.command.getBoolean("force", false); switch (current.command.getString("name")) { case "reload": reload = true; @@ -251,6 +252,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences if (prev.canRun() || current.canRun()) EntityLog.log(ServiceSynchronize.this, "### changed " + current + " reload=" + reload + + " force=" + force + " stop=" + prev.canRun() + " start=" + current.canRun() + " sync=" + current.accountState.isEnabled(current.enabled) + "/" + sync + @@ -265,7 +267,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences if (prev.canRun()) stop(prev); if (current.canRun()) - start(current, current.accountState.isEnabled(current.enabled) || sync); + start(current, current.accountState.isEnabled(current.enabled) || sync, force); } } @@ -313,15 +315,16 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences } } - private void start(final TupleAccountNetworkState accountNetworkState, boolean sync) { - EntityLog.log(ServiceSynchronize.this, "Service start=" + accountNetworkState); + private void start(final TupleAccountNetworkState accountNetworkState, boolean sync, boolean force) { + EntityLog.log(ServiceSynchronize.this, + "Service start=" + accountNetworkState + " sync=" + sync + " force=" + force); final Core.State astate = new Core.State(accountNetworkState.networkState); astate.runnable(new Runnable() { @Override public void run() { try { - monitorAccount(accountNetworkState.accountState, astate, sync); + monitorAccount(accountNetworkState.accountState, astate, sync, force); } catch (Throwable ex) { Log.e(accountNetworkState.accountState.name, ex); } @@ -724,11 +727,14 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences } private void onReload(Intent intent) { - if (intent.getBooleanExtra("force", false)) + boolean force = intent.getBooleanExtra("force", false); + if (force) lastLost = 0; + Bundle command = new Bundle(); command.putString("name", "reload"); command.putLong("account", intent.getLongExtra("account", -1)); + command.putBoolean("force", force); liveAccountNetworkState.post(command); } @@ -825,7 +831,9 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences return builder; } - private void monitorAccount(final EntityAccount account, final Core.State state, final boolean sync) throws NoSuchProviderException { + private void monitorAccount( + final EntityAccount account, final Core.State state, + final boolean sync, final boolean force) throws NoSuchProviderException { final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wlAccount = pm.newWakeLock( PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":account." + account.id); @@ -1014,7 +1022,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences // Update folder list if (account.protocol == EntityAccount.TYPE_IMAP) - Core.onSynchronizeFolders(this, account, iservice.getStore(), state); + Core.onSynchronizeFolders(this, account, iservice.getStore(), state, force); // Open synchronizing folders List folders = db.folder().getFolders(account.id, false, true);