Simplify logic.
Make sure that either messages are fetched or a sync is initiated, and there can be no situation where neither happens. Change-Id: I73ec2482a5a86c54309634f434b7d8fd77d7c079
This commit is contained in:
parent
c59103c933
commit
b9532055e2
@ -2770,9 +2770,9 @@ public class ImapService extends Service {
|
|||||||
// the changes just perform a full sync
|
// the changes just perform a full sync
|
||||||
final long timeSinceLastFullSync = SystemClock.elapsedRealtime() -
|
final long timeSinceLastFullSync = SystemClock.elapsedRealtime() -
|
||||||
mailbox.mLastFullSyncTime;
|
mailbox.mLastFullSyncTime;
|
||||||
final boolean fullSync = timeSinceLastFullSync >= FULL_SYNC_INTERVAL_MILLIS
|
final boolean forceSync = timeSinceLastFullSync >= FULL_SYNC_INTERVAL_MILLIS
|
||||||
|| timeSinceLastFullSync < 0;
|
|| timeSinceLastFullSync < 0;
|
||||||
if (fullSync) {
|
if (forceSync) {
|
||||||
needSync = true;
|
needSync = true;
|
||||||
fetchMessages.clear();
|
fetchMessages.clear();
|
||||||
|
|
||||||
@ -2788,25 +2788,26 @@ public class ImapService extends Service {
|
|||||||
+ ": need sync " + needSync + ", " + msgToFetchSize + " fetch messages");
|
+ ": need sync " + needSync + ", " + msgToFetchSize + " fetch messages");
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean syncRequested = false;
|
if (msgToFetchSize > 0) {
|
||||||
|
if (!needSync && msgToFetchSize <= MAX_MESSAGES_TO_FETCH) {
|
||||||
try {
|
try {
|
||||||
// Sync fetch messages only if we are not going to perform a full sync
|
|
||||||
if (msgToFetchSize > 0 && msgToFetchSize < MAX_MESSAGES_TO_FETCH && !needSync) {
|
|
||||||
processImapFetchChanges(context, account, mailbox, fetchMessages);
|
processImapFetchChanges(context, account, mailbox, fetchMessages);
|
||||||
}
|
|
||||||
if (needSync || msgToFetchSize > MAX_MESSAGES_TO_FETCH) {
|
|
||||||
// With idle we fetched as much as possible. If as resync is required, then
|
|
||||||
// if should be a full sync
|
|
||||||
requestSync(context, account, mailbox.mId, true);
|
|
||||||
syncRequested = true;
|
|
||||||
}
|
|
||||||
} catch (MessagingException ex) {
|
} catch (MessagingException ex) {
|
||||||
LogUtils.w(LOG_TAG, "Failed to process imap idle changes for mailbox " + mailbox.mId);
|
LogUtils.w(LOG_TAG,
|
||||||
|
"Failed to process imap idle changes for mailbox " + mailbox.mId);
|
||||||
|
needSync = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
needSync = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (needSync) {
|
||||||
|
requestSync(context, account, mailbox.mId, true);
|
||||||
|
} else {
|
||||||
// In case no sync happens, re-add idle status
|
// In case no sync happens, re-add idle status
|
||||||
try {
|
try {
|
||||||
if (!syncRequested && account.getSyncInterval() == Account.CHECK_INTERVAL_PUSH) {
|
if (account.getSyncInterval() == Account.CHECK_INTERVAL_PUSH) {
|
||||||
final ImapIdleFolderHolder holder = ImapIdleFolderHolder.getInstance();
|
final ImapIdleFolderHolder holder = ImapIdleFolderHolder.getInstance();
|
||||||
holder.registerMailboxForIdle(context, account, mailbox);
|
holder.registerMailboxForIdle(context, account, mailbox);
|
||||||
}
|
}
|
||||||
@ -2816,3 +2817,4 @@ public class ImapService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user