|
|
@ -145,6 +145,10 @@ class Core {
|
|
|
|
private static final long SCREEN_ON_DURATION = 3000L; // milliseconds
|
|
|
|
private static final long SCREEN_ON_DURATION = 3000L; // milliseconds
|
|
|
|
private static final int SYNC_BATCH_SIZE = 20;
|
|
|
|
private static final int SYNC_BATCH_SIZE = 20;
|
|
|
|
private static final int DOWNLOAD_BATCH_SIZE = 20;
|
|
|
|
private static final int DOWNLOAD_BATCH_SIZE = 20;
|
|
|
|
|
|
|
|
private static final int SYNC_YIELD_COUNT = 100;
|
|
|
|
|
|
|
|
private static final long SYNC_YIELD_DURATION = 1000; // milliseconds
|
|
|
|
|
|
|
|
private static final int DOWNLOAD_YIELD_COUNT = 25;
|
|
|
|
|
|
|
|
private static final long DOWNLOAD_YIELD_DURATION = 1000; // milliseconds
|
|
|
|
private static final long YIELD_DURATION = 200L; // milliseconds
|
|
|
|
private static final long YIELD_DURATION = 200L; // milliseconds
|
|
|
|
private static final long JOIN_WAIT_ALIVE = 5 * 60 * 1000L; // milliseconds
|
|
|
|
private static final long JOIN_WAIT_ALIVE = 5 * 60 * 1000L; // milliseconds
|
|
|
|
private static final long JOIN_WAIT_INTERRUPT = 1 * 60 * 1000L; // milliseconds
|
|
|
|
private static final long JOIN_WAIT_INTERRUPT = 1 * 60 * 1000L; // milliseconds
|
|
|
@ -156,8 +160,6 @@ class Core {
|
|
|
|
private static final long EXISTS_RETRY_DELAY = 20 * 1000L; // milliseconds
|
|
|
|
private static final long EXISTS_RETRY_DELAY = 20 * 1000L; // milliseconds
|
|
|
|
private static final int FIND_RETRY_COUNT = 3; // times
|
|
|
|
private static final int FIND_RETRY_COUNT = 3; // times
|
|
|
|
private static final long FIND_RETRY_DELAY = 5 * 1000L; // milliseconds
|
|
|
|
private static final long FIND_RETRY_DELAY = 5 * 1000L; // milliseconds
|
|
|
|
private static final long OPS_YIELD_INTERVAL = 15 * 1000L; // milliseconds
|
|
|
|
|
|
|
|
private static final long OPS_YIELD_DURATION = 500L; // milliseconds
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final Map<Long, List<EntityIdentity>> accountIdentities = new HashMap<>();
|
|
|
|
private static final Map<Long, List<EntityIdentity>> accountIdentities = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
@ -3481,6 +3483,7 @@ class Core {
|
|
|
|
fp.add(GmailFolder.FetchProfileItem.THRID);
|
|
|
|
fp.add(GmailFolder.FetchProfileItem.THRID);
|
|
|
|
|
|
|
|
|
|
|
|
// Add/update local messages
|
|
|
|
// Add/update local messages
|
|
|
|
|
|
|
|
int synced = 0;
|
|
|
|
Log.i(folder.name + " add=" + imessages.length);
|
|
|
|
Log.i(folder.name + " add=" + imessages.length);
|
|
|
|
for (int i = imessages.length - 1; i >= 0; i -= SYNC_BATCH_SIZE) {
|
|
|
|
for (int i = imessages.length - 1; i >= 0; i -= SYNC_BATCH_SIZE) {
|
|
|
|
state.ensureRunning("Sync/IMAP/sync/fetch");
|
|
|
|
state.ensureRunning("Sync/IMAP/sync/fetch");
|
|
|
@ -3519,7 +3522,6 @@ class Core {
|
|
|
|
state.ensureRunning("Sync/IMAP/sync");
|
|
|
|
state.ensureRunning("Sync/IMAP/sync");
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
state.dutyCycle(true, account.name);
|
|
|
|
|
|
|
|
// Some providers erroneously return old messages
|
|
|
|
// Some providers erroneously return old messages
|
|
|
|
if (full.contains(isub[j]))
|
|
|
|
if (full.contains(isub[j]))
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -3543,6 +3545,15 @@ class Core {
|
|
|
|
false, download && initialize == 0,
|
|
|
|
false, download && initialize == 0,
|
|
|
|
rules, state, stats);
|
|
|
|
rules, state, stats);
|
|
|
|
ids[from + j] = (message == null || message.ui_hide ? null : message.id);
|
|
|
|
ids[from + j] = (message == null || message.ui_hide ? null : message.id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (message != null && full.contains(isub[j]))
|
|
|
|
|
|
|
|
if ((++synced % SYNC_YIELD_COUNT) == 0)
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Log.i(folder.name + " yield synced=" + synced);
|
|
|
|
|
|
|
|
Thread.sleep(SYNC_YIELD_DURATION);
|
|
|
|
|
|
|
|
} catch (InterruptedException ex) {
|
|
|
|
|
|
|
|
Log.w(ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (MessageRemovedException ex) {
|
|
|
|
} catch (MessageRemovedException ex) {
|
|
|
|
Log.w(folder.name, ex);
|
|
|
|
Log.w(folder.name, ex);
|
|
|
|
} catch (FolderClosedException ex) {
|
|
|
|
} catch (FolderClosedException ex) {
|
|
|
@ -3559,7 +3570,6 @@ class Core {
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
// Free memory
|
|
|
|
// Free memory
|
|
|
|
isub[j] = null;
|
|
|
|
isub[j] = null;
|
|
|
|
state.dutyCycle(false, account.name);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -3607,6 +3617,7 @@ class Core {
|
|
|
|
db.folder().setFolderSyncState(folder.id, "downloading");
|
|
|
|
db.folder().setFolderSyncState(folder.id, "downloading");
|
|
|
|
|
|
|
|
|
|
|
|
// Download messages/attachments
|
|
|
|
// Download messages/attachments
|
|
|
|
|
|
|
|
int downloaded = 0;
|
|
|
|
Log.i(folder.name + " download=" + imessages.length);
|
|
|
|
Log.i(folder.name + " download=" + imessages.length);
|
|
|
|
for (int i = imessages.length - 1; i >= 0; i -= DOWNLOAD_BATCH_SIZE) {
|
|
|
|
for (int i = imessages.length - 1; i >= 0; i -= DOWNLOAD_BATCH_SIZE) {
|
|
|
|
state.ensureRunning("Sync/IMAP/download/fetch");
|
|
|
|
state.ensureRunning("Sync/IMAP/download/fetch");
|
|
|
@ -3631,14 +3642,22 @@ class Core {
|
|
|
|
state.ensureRunning("Sync/IMAP/download");
|
|
|
|
state.ensureRunning("Sync/IMAP/download");
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
state.dutyCycle(true, account.name);
|
|
|
|
if (ids[from + j] != null) {
|
|
|
|
if (ids[from + j] != null)
|
|
|
|
boolean fetched = downloadMessage(
|
|
|
|
downloadMessage(
|
|
|
|
|
|
|
|
context,
|
|
|
|
context,
|
|
|
|
account, folder,
|
|
|
|
account, folder,
|
|
|
|
istore, ifolder,
|
|
|
|
istore, ifolder,
|
|
|
|
(MimeMessage) isub[j], ids[from + j],
|
|
|
|
(MimeMessage) isub[j], ids[from + j],
|
|
|
|
state, stats);
|
|
|
|
state, stats);
|
|
|
|
|
|
|
|
if (fetched)
|
|
|
|
|
|
|
|
if ((++downloaded % DOWNLOAD_YIELD_COUNT) == 0)
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Log.i(folder.name + " yield downloaded=" + downloaded);
|
|
|
|
|
|
|
|
Thread.sleep(DOWNLOAD_YIELD_DURATION);
|
|
|
|
|
|
|
|
} catch (InterruptedException ex) {
|
|
|
|
|
|
|
|
Log.w(ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (FolderClosedException ex) {
|
|
|
|
} catch (FolderClosedException ex) {
|
|
|
|
throw ex;
|
|
|
|
throw ex;
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
} catch (Throwable ex) {
|
|
|
@ -3646,7 +3665,6 @@ class Core {
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
// Free memory
|
|
|
|
// Free memory
|
|
|
|
isub[j] = null;
|
|
|
|
isub[j] = null;
|
|
|
|
state.dutyCycle(false, account.name);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -5817,31 +5835,27 @@ class Core {
|
|
|
|
",serial=" + serial + "]";
|
|
|
|
",serial=" + serial + "]";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Long last = null;
|
|
|
|
private static class FolderPriority {
|
|
|
|
private long idle = 0, busy = 0;
|
|
|
|
private long folder;
|
|
|
|
private long started = 0;
|
|
|
|
private int priority;
|
|
|
|
|
|
|
|
|
|
|
|
void dutyCycle(boolean start, String name) {
|
|
|
|
FolderPriority(long folder, int priority) {
|
|
|
|
if (start)
|
|
|
|
this.folder = folder;
|
|
|
|
started = new Date().getTime();
|
|
|
|
this.priority = priority;
|
|
|
|
else {
|
|
|
|
}
|
|
|
|
long end = new Date().getTime();
|
|
|
|
|
|
|
|
if (last != null)
|
|
|
|
@Override
|
|
|
|
idle += (started - last);
|
|
|
|
public int hashCode() {
|
|
|
|
last = end;
|
|
|
|
return (int) (this.folder * 37 + priority);
|
|
|
|
busy += (end - started);
|
|
|
|
}
|
|
|
|
if (busy + idle > OPS_YIELD_INTERVAL) {
|
|
|
|
|
|
|
|
long wait = (OPS_YIELD_DURATION - idle);
|
|
|
|
@Override
|
|
|
|
Log.i(name + " idle wait=" + wait);
|
|
|
|
public boolean equals(@Nullable Object obj) {
|
|
|
|
if (wait > 0)
|
|
|
|
if (obj instanceof FolderPriority) {
|
|
|
|
try {
|
|
|
|
FolderPriority other = (FolderPriority) obj;
|
|
|
|
Thread.sleep(wait);
|
|
|
|
return (this.folder == other.folder && this.priority == other.priority);
|
|
|
|
} catch (InterruptedException ex) {
|
|
|
|
} else
|
|
|
|
Log.w(ex);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
idle = 0;
|
|
|
|
|
|
|
|
busy = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|