diff --git a/src/com/android/email/Controller.java b/src/com/android/email/Controller.java index a4db02369..4ac040cda 100644 --- a/src/com/android/email/Controller.java +++ b/src/com/android/email/Controller.java @@ -343,13 +343,13 @@ public class Controller { * a simple message list. We should also at this point queue up a background task of * downloading some/all of the messages in this mailbox, but that should be interruptable. */ - public void updateMailbox(final long accountId, final long mailboxId) { + public void updateMailbox(final long accountId, final long mailboxId, boolean userRequest) { IEmailService service = getServiceForAccount(accountId); if (service != null) { // Service implementation try { - service.startSync(mailboxId); + service.startSync(mailboxId, userRequest); } catch (RemoteException e) { // TODO Change exception handling to be consistent with however this method // is implemented for other protocols @@ -558,7 +558,7 @@ public class Controller { if (service != null) { // Service implementation try { - service.startSync(outboxId); + service.startSync(outboxId, false); } catch (RemoteException e) { // TODO Change exception handling to be consistent with however this method // is implemented for other protocols @@ -1580,7 +1580,7 @@ public class Controller { return null; } - public void startSync(long mailboxId) throws RemoteException { + public void startSync(long mailboxId, boolean userRequest) throws RemoteException { } public void stopSync(long mailboxId) throws RemoteException { diff --git a/src/com/android/email/ExchangeUtils.java b/src/com/android/email/ExchangeUtils.java index a7fad587b..219ade3ac 100644 --- a/src/com/android/email/ExchangeUtils.java +++ b/src/com/android/email/ExchangeUtils.java @@ -118,7 +118,7 @@ public class ExchangeUtils { public void setLogging(int on) throws RemoteException { } - public void startSync(long mailboxId) throws RemoteException { + public void startSync(long mailboxId, boolean userRequest) throws RemoteException { } public void stopSync(long mailboxId) throws RemoteException { diff --git a/src/com/android/email/RefreshManager.java b/src/com/android/email/RefreshManager.java index 38d8095e7..977464ae3 100644 --- a/src/com/android/email/RefreshManager.java +++ b/src/com/android/email/RefreshManager.java @@ -231,8 +231,8 @@ public class RefreshManager { /** * Refresh messages in a mailbox. */ - public boolean refreshMessageList(long accountId, long mailboxId) { - return refreshMessageList(accountId, mailboxId, false); + public boolean refreshMessageList(long accountId, long mailboxId, boolean userRequest) { + return refreshMessageList(accountId, mailboxId, false, userRequest); } /** @@ -242,7 +242,8 @@ public class RefreshManager { return refreshMessageList(accountId, mailboxId, true); } - private boolean refreshMessageList(long accountId, long mailboxId, boolean loadMoreMessages) { + private boolean refreshMessageList(long accountId, long mailboxId, boolean loadMoreMessages, + boolean userRequest) { final Status status = mMessageListStatus.get(mailboxId); if (!status.canRefresh()) return false; @@ -253,7 +254,7 @@ public class RefreshManager { if (loadMoreMessages) { mController.loadMoreMessages(mailboxId); } else { - mController.updateMailbox(accountId, mailboxId); + mController.updateMailbox(accountId, mailboxId, userRequest); } return true; } diff --git a/src/com/android/email/activity/MessageList.java b/src/com/android/email/activity/MessageList.java index 79e736460..5611839c5 100644 --- a/src/com/android/email/activity/MessageList.java +++ b/src/com/android/email/activity/MessageList.java @@ -349,7 +349,7 @@ public class MessageList extends Activity implements OnClickListener, public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.refresh: - mListFragment.onRefresh(); + mListFragment.onRefresh(true); return true; case R.id.folders: onFolders(); diff --git a/src/com/android/email/activity/MessageListFragment.java b/src/com/android/email/activity/MessageListFragment.java index dfe22bfef..4c56e0720 100644 --- a/src/com/android/email/activity/MessageListFragment.java +++ b/src/com/android/email/activity/MessageListFragment.java @@ -24,10 +24,10 @@ import com.android.email.Utility; import com.android.email.Utility.ListStateSaver; import com.android.email.data.MailboxAccountLoader; import com.android.email.provider.EmailContent; -import com.android.email.provider.EmailProvider; import com.android.email.provider.EmailContent.Account; import com.android.email.provider.EmailContent.Mailbox; import com.android.email.provider.EmailContent.Message; +import com.android.email.provider.EmailProvider; import com.android.email.service.MailService; import android.app.Activity; @@ -56,15 +56,15 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; -import android.view.ViewGroup; import android.view.View.DragThumbnailBuilder; import android.view.View.OnDragListener; +import android.view.ViewGroup; import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; +import android.widget.AdapterView.OnItemLongClickListener; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; -import android.widget.AdapterView.OnItemClickListener; -import android.widget.AdapterView.OnItemLongClickListener; import java.security.InvalidParameterException; import java.util.HashSet; @@ -637,13 +637,13 @@ public class MessageListFragment extends ListFragment * * Note: Manual refresh is enabled even for push accounts. */ - public void onRefresh() { + public void onRefresh(boolean userRequest) { if (!mIsRefreshable) { return; } long accountId = getAccountId(); if (accountId != -1) { - mRefreshManager.refreshMessageList(accountId, mMailboxId); + mRefreshManager.refreshMessageList(accountId, mMailboxId, userRequest); } } @@ -888,7 +888,7 @@ public class MessageListFragment extends ListFragment if (!mRefreshManager.isMailboxStale(mMailboxId)) { return; } - onRefresh(); + onRefresh(false); } /** Implements {@link MessagesAdapter.Callback} */ diff --git a/src/com/android/email/activity/MessageListXL.java b/src/com/android/email/activity/MessageListXL.java index a81ac7f7a..24bd25e7c 100644 --- a/src/com/android/email/activity/MessageListXL.java +++ b/src/com/android/email/activity/MessageListXL.java @@ -780,7 +780,7 @@ public class MessageListXL extends Activity implements return; } if (isCurrentMailboxRefreshable) { - mRefreshManager.refreshMessageList(mAccountId, mMailboxId); + mRefreshManager.refreshMessageList(mAccountId, mMailboxId, false); } // Refresh mailbox list if (mAccountId != -1) { @@ -790,7 +790,7 @@ public class MessageListXL extends Activity implements } // Refresh inbox if (shouldAutoRefreshInbox()) { - mRefreshManager.refreshMessageList(mAccountId, mInboxId); + mRefreshManager.refreshMessageList(mAccountId, mInboxId, false); } } diff --git a/src/com/android/email/service/EmailServiceProxy.java b/src/com/android/email/service/EmailServiceProxy.java index 91eff5040..6b3502c9b 100644 --- a/src/com/android/email/service/EmailServiceProxy.java +++ b/src/com/android/email/service/EmailServiceProxy.java @@ -180,12 +180,12 @@ public class EmailServiceProxy implements IEmailService { }); } - public void startSync(final long mailboxId) throws RemoteException { + public void startSync(final long mailboxId, final boolean userRequest) throws RemoteException { setTask(new Runnable () { public void run() { try { if (mCallback != null) mService.setCallback(mCallback); - mService.startSync(mailboxId); + mService.startSync(mailboxId, userRequest); } catch (RemoteException e) { } } diff --git a/src/com/android/email/service/IEmailService.aidl b/src/com/android/email/service/IEmailService.aidl index 663b346bb..02164746f 100644 --- a/src/com/android/email/service/IEmailService.aidl +++ b/src/com/android/email/service/IEmailService.aidl @@ -23,7 +23,7 @@ interface IEmailService { Bundle validate(in String protocol, in String host, in String userName, in String password, int port, boolean ssl, boolean trustCertificates) ; - void startSync(long mailboxId); + void startSync(long mailboxId, boolean userRequest); void stopSync(long mailboxId); void loadMore(long messageId); diff --git a/src/com/android/email/service/PopImapSyncAdapterService.java b/src/com/android/email/service/PopImapSyncAdapterService.java index 74a5ba4e4..2fa876749 100644 --- a/src/com/android/email/service/PopImapSyncAdapterService.java +++ b/src/com/android/email/service/PopImapSyncAdapterService.java @@ -96,7 +96,7 @@ public class PopImapSyncAdapterService extends Service { Mailbox.TYPE_INBOX); if (mailboxId > 0) { Log.d(TAG, "Starting manual sync for account " + emailAddress); - Controller.getInstance(context).updateMailbox(accountId, mailboxId); + Controller.getInstance(context).updateMailbox(accountId, mailboxId, false); } } } diff --git a/src/com/android/exchange/EasSyncService.java b/src/com/android/exchange/EasSyncService.java index 6ad000fe1..70fd2d704 100644 --- a/src/com/android/exchange/EasSyncService.java +++ b/src/com/android/exchange/EasSyncService.java @@ -2364,8 +2364,8 @@ public class EasSyncService extends AbstractSyncService { */ public void run() { if (!setupService()) return; - - if (mSyncReason >= ExchangeService.SYNC_UI_REQUEST) { + final boolean callbackRequired = (mSyncReason >= ExchangeService.SYNC_CALLBACK_START); + if (callbackRequired) { try { ExchangeService.callback().syncMailboxStatus(mMailboxId, EmailServiceStatus.IN_PROGRESS, 0); @@ -2448,8 +2448,16 @@ public class EasSyncService extends AbstractSyncService { } // Send a callback if this run was initiated by a service call - if (mSyncReason >= ExchangeService.SYNC_UI_REQUEST) { + if (callbackRequired) { try { + // Unless the user specifically asked for a sync, we really don't want to report + // connection issues, as they are likely to be transient. In this case, we + // simply report success, so that the progress indicator terminates without + // putting up an error banner + if (mSyncReason != ExchangeService.SYNC_UI_REQUEST && + status == EXIT_IO_ERROR) { + status = EmailServiceStatus.SUCCESS; + } ExchangeService.callback().syncMailboxStatus(mMailboxId, status, 0); } catch (RemoteException e1) { // Don't care if this fails diff --git a/src/com/android/exchange/ExchangeService.java b/src/com/android/exchange/ExchangeService.java index 6279b2749..9b9ed5803 100644 --- a/src/com/android/exchange/ExchangeService.java +++ b/src/com/android/exchange/ExchangeService.java @@ -137,12 +137,14 @@ public class ExchangeService extends Service implements Runnable { // Misc. public static final int SYNC_KICK = 4; - // Requests >= SYNC_UI_REQUEST generate callbacks to the UI - public static final int SYNC_UI_REQUEST = 5; - // startSync was requested of ExchangeService - public static final int SYNC_SERVICE_START_SYNC = SYNC_UI_REQUEST + 0; + // Requests >= SYNC_CALLBACK_START generate callbacks to the UI + public static final int SYNC_CALLBACK_START = 5; + // startSync was requested of ExchangeService (other than due to user request) + public static final int SYNC_SERVICE_START_SYNC = SYNC_CALLBACK_START + 0; + // startSync was requested of ExchangeService (due to user request) + public static final int SYNC_UI_REQUEST = SYNC_CALLBACK_START + 1; // A part request (attachment load, for now) was sent to ExchangeService - public static final int SYNC_SERVICE_PART_REQUEST = SYNC_UI_REQUEST + 1; + public static final int SYNC_SERVICE_PART_REQUEST = SYNC_CALLBACK_START + 2; private static final String WHERE_PUSH_OR_PING_NOT_ACCOUNT_MAILBOX = MailboxColumns.ACCOUNT_KEY + "=? and " + MailboxColumns.TYPE + "!=" + @@ -340,7 +342,7 @@ public class ExchangeService extends Service implements Runnable { return new EasSyncService().tryAutodiscover(userName, password); } - public void startSync(long mailboxId) throws RemoteException { + public void startSync(long mailboxId, boolean userRequest) throws RemoteException { ExchangeService exchangeService = INSTANCE; if (exchangeService == null) return; checkExchangeServiceServiceRunning(); @@ -369,7 +371,8 @@ public class ExchangeService extends Service implements Runnable { } return; } - startManualSync(mailboxId, ExchangeService.SYNC_SERVICE_START_SYNC, null); + startManualSync(mailboxId, userRequest ? ExchangeService.SYNC_UI_REQUEST : + ExchangeService.SYNC_SERVICE_START_SYNC, null); } public void stopSync(long mailboxId) throws RemoteException { @@ -2328,7 +2331,7 @@ public class ExchangeService extends Service implements Runnable { } } else { // If this is a ui request, set the sync reason for the service - if (reason >= SYNC_UI_REQUEST) { + if (reason >= SYNC_CALLBACK_START) { svc.mSyncReason = reason; } } diff --git a/tests/src/com/android/email/RefreshManagerTest.java b/tests/src/com/android/email/RefreshManagerTest.java index 3f447fdf1..4badfc42f 100644 --- a/tests/src/com/android/email/RefreshManagerTest.java +++ b/tests/src/com/android/email/RefreshManagerTest.java @@ -219,7 +219,7 @@ public class RefreshManagerTest extends InstrumentationTestCase { public void testRefreshMessageList() { // request refresh mailbox 1 - assertTrue(mTarget.refreshMessageList(ACCOUNT_1, MAILBOX_1)); + assertTrue(mTarget.refreshMessageList(ACCOUNT_1, MAILBOX_1, false)); assertTrue(mListener.mCalledOnRefreshStatusChanged); assertFalse(mListener.mCalledOnConnectionError); @@ -234,7 +234,7 @@ public class RefreshManagerTest extends InstrumentationTestCase { assertTrue(mTarget.isRefreshingAnyMessageListForTest()); // Request again -- shouldn't be accepted. - assertFalse(mTarget.refreshMessageList(ACCOUNT_1, MAILBOX_1)); + assertFalse(mTarget.refreshMessageList(ACCOUNT_1, MAILBOX_1, false)); assertFalse(mListener.mCalledOnRefreshStatusChanged); assertFalse(mListener.mCalledOnConnectionError); @@ -243,7 +243,7 @@ public class RefreshManagerTest extends InstrumentationTestCase { mController.reset(); // request refresh mailbox 2 - assertTrue(mTarget.refreshMessageList(ACCOUNT_2, MAILBOX_2)); + assertTrue(mTarget.refreshMessageList(ACCOUNT_2, MAILBOX_2, false)); assertTrue(mListener.mCalledOnRefreshStatusChanged); assertFalse(mListener.mCalledOnConnectionError); @@ -431,7 +431,7 @@ public class RefreshManagerTest extends InstrumentationTestCase { } @Override - public void updateMailbox(long accountId, long mailboxId) { + public void updateMailbox(long accountId, long mailboxId, boolean userRequest) { mCalledUpdateMailbox = true; mAccountId = accountId; mMailboxId = mailboxId;