Synchronize access to storedUntaggedResponses
This commit is contained in:
parent
41ca6b7899
commit
01a14b9f1f
1 changed files with 33 additions and 13 deletions
|
@ -38,7 +38,7 @@ class ImapFolderPusher extends ImapFolder {
|
|||
private final Object threadLock = new Object();
|
||||
private final IdleStopper idleStopper = new IdleStopper();
|
||||
private final TracingWakeLock wakeLock;
|
||||
private List<ImapResponse> storedUntaggedResponses = new ArrayList<ImapResponse>();
|
||||
private final List<ImapResponse> storedUntaggedResponses = new ArrayList<ImapResponse>();
|
||||
private Thread listeningThread;
|
||||
private volatile boolean stop = false;
|
||||
private volatile boolean idling = false;
|
||||
|
@ -105,7 +105,9 @@ class ImapFolderPusher extends ImapFolder {
|
|||
Log.d(LOG_TAG, "Storing response " + response + " for later processing");
|
||||
}
|
||||
|
||||
storedUntaggedResponses.add(response);
|
||||
synchronized (storedUntaggedResponses) {
|
||||
storedUntaggedResponses.add(response);
|
||||
}
|
||||
}
|
||||
|
||||
handlePossibleUidNext(response);
|
||||
|
@ -192,7 +194,7 @@ class ImapFolderPusher extends ImapFolder {
|
|||
} catch (Exception e) {
|
||||
wakeLock.acquire(PUSH_WAKE_LOCK_TIMEOUT);
|
||||
|
||||
storedUntaggedResponses.clear();
|
||||
clearStoredUntaggedResponses();
|
||||
idling = false;
|
||||
pushReceiver.setPushActive(getName(), false);
|
||||
|
||||
|
@ -373,21 +375,41 @@ class ImapFolderPusher extends ImapFolder {
|
|||
}
|
||||
}
|
||||
|
||||
private void clearStoredUntaggedResponses() {
|
||||
synchronized (storedUntaggedResponses) {
|
||||
storedUntaggedResponses.clear();
|
||||
}
|
||||
}
|
||||
|
||||
private void processStoredUntaggedResponses() throws MessagingException {
|
||||
List<ImapResponse> untaggedResponses;
|
||||
while (!storedUntaggedResponses.isEmpty()) {
|
||||
if (K9MailLib.isDebug()) {
|
||||
Log.i(LOG_TAG, "Processing " + storedUntaggedResponses.size() +
|
||||
" untagged responses from previous commands for " + getLogId());
|
||||
while (true) {
|
||||
List<ImapResponse> untaggedResponses = getAndClearStoredUntaggedResponses();
|
||||
if (untaggedResponses.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (K9MailLib.isDebug()) {
|
||||
Log.i(LOG_TAG, "Processing " + untaggedResponses.size() + " untagged responses from previous " +
|
||||
"commands for " + getLogId());
|
||||
}
|
||||
|
||||
untaggedResponses = new ArrayList<ImapResponse>(storedUntaggedResponses);
|
||||
storedUntaggedResponses.clear();
|
||||
processUntaggedResponses(untaggedResponses);
|
||||
}
|
||||
}
|
||||
|
||||
private List<ImapResponse> getAndClearStoredUntaggedResponses() {
|
||||
synchronized (storedUntaggedResponses) {
|
||||
if (storedUntaggedResponses.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<ImapResponse> untaggedResponses = new ArrayList<ImapResponse>(storedUntaggedResponses);
|
||||
storedUntaggedResponses.clear();
|
||||
|
||||
return untaggedResponses;
|
||||
}
|
||||
}
|
||||
|
||||
private void processUntaggedResponses(List<ImapResponse> responses) throws MessagingException {
|
||||
boolean skipSync = false;
|
||||
|
||||
|
@ -596,9 +618,7 @@ class ImapFolderPusher extends ImapFolder {
|
|||
}
|
||||
|
||||
private void syncFolderOnConnect() throws MessagingException {
|
||||
List<ImapResponse> untaggedResponses = new ArrayList<ImapResponse>(storedUntaggedResponses);
|
||||
storedUntaggedResponses.clear();
|
||||
processUntaggedResponses(untaggedResponses);
|
||||
processStoredUntaggedResponses();
|
||||
|
||||
if (messageCount == -1) {
|
||||
throw new MessagingException("Message count = -1 for idling");
|
||||
|
|
Loading…
Reference in a new issue