Always synchronize folders on force sync

pull/183/head
M66B 5 years ago
parent 67a6802b83
commit 8ea4753056

@ -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); DB db = DB.getInstance(context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(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); boolean sync_shared_folders = prefs.getBoolean("sync_shared_folders", false);
// Get folder names // Get folder names

@ -223,7 +223,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
if (index < 0) { if (index < 0) {
if (current.canRun()) { if (current.canRun()) {
EntityLog.log(ServiceSynchronize.this, "### new " + current); EntityLog.log(ServiceSynchronize.this, "### new " + current);
start(current, current.accountState.isEnabled(current.enabled)); start(current, current.accountState.isEnabled(current.enabled), false);
} }
} else { } else {
TupleAccountNetworkState prev = accountStates.get(index); TupleAccountNetworkState prev = accountStates.get(index);
@ -233,6 +233,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
boolean reload = false; boolean reload = false;
boolean sync = current.command.getBoolean("sync", false); boolean sync = current.command.getBoolean("sync", false);
boolean force = current.command.getBoolean("force", false);
switch (current.command.getString("name")) { switch (current.command.getString("name")) {
case "reload": case "reload":
reload = true; reload = true;
@ -251,6 +252,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
if (prev.canRun() || current.canRun()) if (prev.canRun() || current.canRun())
EntityLog.log(ServiceSynchronize.this, "### changed " + current + EntityLog.log(ServiceSynchronize.this, "### changed " + current +
" reload=" + reload + " reload=" + reload +
" force=" + force +
" stop=" + prev.canRun() + " stop=" + prev.canRun() +
" start=" + current.canRun() + " start=" + current.canRun() +
" sync=" + current.accountState.isEnabled(current.enabled) + "/" + sync + " sync=" + current.accountState.isEnabled(current.enabled) + "/" + sync +
@ -265,7 +267,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
if (prev.canRun()) if (prev.canRun())
stop(prev); stop(prev);
if (current.canRun()) 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) { private void start(final TupleAccountNetworkState accountNetworkState, boolean sync, boolean force) {
EntityLog.log(ServiceSynchronize.this, "Service start=" + accountNetworkState); EntityLog.log(ServiceSynchronize.this,
"Service start=" + accountNetworkState + " sync=" + sync + " force=" + force);
final Core.State astate = new Core.State(accountNetworkState.networkState); final Core.State astate = new Core.State(accountNetworkState.networkState);
astate.runnable(new Runnable() { astate.runnable(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
monitorAccount(accountNetworkState.accountState, astate, sync); monitorAccount(accountNetworkState.accountState, astate, sync, force);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(accountNetworkState.accountState.name, ex); Log.e(accountNetworkState.accountState.name, ex);
} }
@ -724,11 +727,14 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
} }
private void onReload(Intent intent) { private void onReload(Intent intent) {
if (intent.getBooleanExtra("force", false)) boolean force = intent.getBooleanExtra("force", false);
if (force)
lastLost = 0; lastLost = 0;
Bundle command = new Bundle(); Bundle command = new Bundle();
command.putString("name", "reload"); command.putString("name", "reload");
command.putLong("account", intent.getLongExtra("account", -1)); command.putLong("account", intent.getLongExtra("account", -1));
command.putBoolean("force", force);
liveAccountNetworkState.post(command); liveAccountNetworkState.post(command);
} }
@ -825,7 +831,9 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
return builder; 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 pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
final PowerManager.WakeLock wlAccount = pm.newWakeLock( final PowerManager.WakeLock wlAccount = pm.newWakeLock(
PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":account." + account.id); PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":account." + account.id);
@ -1014,7 +1022,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
// Update folder list // Update folder list
if (account.protocol == EntityAccount.TYPE_IMAP) if (account.protocol == EntityAccount.TYPE_IMAP)
Core.onSynchronizeFolders(this, account, iservice.getStore(), state); Core.onSynchronizeFolders(this, account, iservice.getStore(), state, force);
// Open synchronizing folders // Open synchronizing folders
List<EntityFolder> folders = db.folder().getFolders(account.id, false, true); List<EntityFolder> folders = db.folder().getFolders(account.id, false, true);

Loading…
Cancel
Save