From 88fb7f7cd032ec0d838bdddf40a6f5a73442f422 Mon Sep 17 00:00:00 2001 From: Andrew Stadler Date: Fri, 23 Apr 2010 12:17:43 -0700 Subject: [PATCH] Fix uncommanded exit from MessageList with 2+ accounts * When you have 2 or more accounts configured, MessageList gets confused. * If you are viewing a mailbox from account A, and account B does a background sync, MessageList gets confused by the reports coming back from the Controller. It gives up and returns to the Accounts list. * This change adds a check for the current account and ignores the MessageList updates if we weren't actually waiting for them. * To test the positive case for this code (make sure we didn't break it), verify that the inbox on an IMAP account is displayed properly immediately after you add it. Bug: 2619513 Change-Id: Ib31254b4099ba6b7922b06d42e2b7928551e4fb2 --- .../android/email/activity/MessageList.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/com/android/email/activity/MessageList.java b/src/com/android/email/activity/MessageList.java index 2ece07bf3..5856b64fa 100644 --- a/src/com/android/email/activity/MessageList.java +++ b/src/com/android/email/activity/MessageList.java @@ -1102,7 +1102,7 @@ public class MessageList extends ListActivity implements OnItemClickListener, On final boolean accountExists = Account.isValidId(MessageList.this, mAccountId); if (accountExists && mOkToRecurse) { // launch network lookup - mControllerCallback.mWaitForMailboxType = mMailboxType; + mControllerCallback.presetMailboxListCallback(mMailboxType, mAccountId); mController.updateMailboxList(mAccountId, mControllerCallback); } else { // We don't want to do the network lookup, or the account doesn't exist in the @@ -1436,19 +1436,26 @@ public class MessageList extends ListActivity implements OnItemClickListener, On // This is used to alter the connection banner operation for sending messages MessagingException mSendMessageException; - // This is preset for use by updateMailboxListCallback - int mWaitForMailboxType = -1; + // These values are set by FindMailboxTask, and used by updateMailboxListCallback + // Access to these must be synchronized because of various threads dealing with them + private int mWaitForMailboxType = -1; + private long mWaitForMailboxAccount = -1; - // TODO check accountKey and only react to relevant notifications - public void updateMailboxListCallback(MessagingException result, long accountKey, - int progress) { + public synchronized void presetMailboxListCallback(int mailboxType, long accountId) { + mWaitForMailboxType = mailboxType; + mWaitForMailboxAccount = accountId; + } + + public synchronized void updateMailboxListCallback(MessagingException result, + long accountKey, int progress) { // updateMailboxList is never the end goal in MessageList, so we don't show // these errors. There are a couple of corner cases that we miss reporting, but // this is better than reporting a number of non-problem intermediate states. // updateBanner(result, progress, mMailboxId); updateProgress(result, progress); - if (progress == 100) { + if (progress == 100 && accountKey == mWaitForMailboxAccount) { + mWaitForMailboxAccount = -1; mHandler.lookupMailboxType(accountKey, mWaitForMailboxType); } }