From 20568c850a83dbbd63dd437974bcd95c8ffc0242 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Wed, 3 May 2017 18:28:35 +0100 Subject: [PATCH] SyncManager: Request for a full sync if interrupted. This doesn't work well, but I'm keeping it since it's still better than what was there before. We have a problem that on initial sync with long enough logs, Android kills the sync manager before completion. The reason for that is that due to the fact that EteSync first downloads the whole journal and only then processes it, the sync manager spends a minute without making any network traffic, which in turn makes Android kill the sync[1]. This should probably be fixed by paginating the initial download, that is, downloading and processing the journal in chunks, which is possibly a good idea regardless. 1: https://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter.html --- .../syncadapter/syncadapter/SyncManager.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.java b/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.java index 441730f5..01a57b0f 100644 --- a/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.java +++ b/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.java @@ -140,51 +140,51 @@ abstract public class SyncManager { } if (Thread.interrupted()) - return; + throw new InterruptedException(); syncPhase = R.string.sync_phase_query_capabilities; App.log.info("Sync phase: " + context.getString(syncPhase)); queryCapabilities(); if (Thread.interrupted()) - return; + throw new InterruptedException(); syncPhase = R.string.sync_phase_prepare_local; App.log.info("Sync phase: " + context.getString(syncPhase)); prepareLocal(); if (Thread.interrupted()) - return; + throw new InterruptedException(); syncPhase = R.string.sync_phase_fetch_entries; App.log.info("Sync phase: " + context.getString(syncPhase)); fetchEntries(); if (Thread.interrupted()) - return; + throw new InterruptedException(); syncPhase = R.string.sync_phase_apply_remote_entries; App.log.info("Sync phase: " + context.getString(syncPhase)); applyRemoteEntries(); /* Create journal entries out of local changes. */ if (Thread.interrupted()) - return; + throw new InterruptedException(); syncPhase = R.string.sync_phase_create_local_entries; App.log.info("Sync phase: " + context.getString(syncPhase)); createLocalEntries(); if (Thread.interrupted()) - return; + throw new InterruptedException(); syncPhase = R.string.sync_phase_apply_local_entries; App.log.info("Sync phase: " + context.getString(syncPhase)); applyLocalEntries(); if (Thread.interrupted()) - return; + throw new InterruptedException(); syncPhase = R.string.sync_phase_push_entries; App.log.info("Sync phase: " + context.getString(syncPhase)); pushEntries(); /* Cleanup and finalize changes */ if (Thread.interrupted()) - return; + throw new InterruptedException(); syncPhase = R.string.sync_phase_post_processing; App.log.info("Sync phase: " + context.getString(syncPhase)); postProcess(); @@ -197,7 +197,8 @@ abstract public class SyncManager { syncResult.stats.numIoExceptions++; syncResult.delayUntil = (e.retryAfter > 0) ? e.retryAfter : Constants.DEFAULT_RETRY_DELAY; } catch (InterruptedException e) { - + // Restart sync if interrupted + syncResult.fullSyncRequested = true; } catch (Exception | OutOfMemoryError e) { if (e instanceof Exceptions.UnauthorizedException) { syncResult.stats.numAuthExceptions++;