Distinguish mailbox requests that are user requested

Bug: 3251757
Change-Id: Ie417ebf44c8b740db88e5854077782930359a958
This commit is contained in:
Marc Blank 2010-12-20 19:00:20 -08:00
parent e70c2e0543
commit cbdd9f78b2
12 changed files with 50 additions and 38 deletions

View File

@ -343,13 +343,13 @@ public class Controller {
* a simple message list. We should also at this point queue up a background task of * 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. * 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); IEmailService service = getServiceForAccount(accountId);
if (service != null) { if (service != null) {
// Service implementation // Service implementation
try { try {
service.startSync(mailboxId); service.startSync(mailboxId, userRequest);
} catch (RemoteException e) { } catch (RemoteException e) {
// TODO Change exception handling to be consistent with however this method // TODO Change exception handling to be consistent with however this method
// is implemented for other protocols // is implemented for other protocols
@ -558,7 +558,7 @@ public class Controller {
if (service != null) { if (service != null) {
// Service implementation // Service implementation
try { try {
service.startSync(outboxId); service.startSync(outboxId, false);
} catch (RemoteException e) { } catch (RemoteException e) {
// TODO Change exception handling to be consistent with however this method // TODO Change exception handling to be consistent with however this method
// is implemented for other protocols // is implemented for other protocols
@ -1580,7 +1580,7 @@ public class Controller {
return null; 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 { public void stopSync(long mailboxId) throws RemoteException {

View File

@ -118,7 +118,7 @@ public class ExchangeUtils {
public void setLogging(int on) throws RemoteException { 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 { public void stopSync(long mailboxId) throws RemoteException {

View File

@ -231,8 +231,8 @@ public class RefreshManager {
/** /**
* Refresh messages in a mailbox. * Refresh messages in a mailbox.
*/ */
public boolean refreshMessageList(long accountId, long mailboxId) { public boolean refreshMessageList(long accountId, long mailboxId, boolean userRequest) {
return refreshMessageList(accountId, mailboxId, false); return refreshMessageList(accountId, mailboxId, false, userRequest);
} }
/** /**
@ -242,7 +242,8 @@ public class RefreshManager {
return refreshMessageList(accountId, mailboxId, true); 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); final Status status = mMessageListStatus.get(mailboxId);
if (!status.canRefresh()) return false; if (!status.canRefresh()) return false;
@ -253,7 +254,7 @@ public class RefreshManager {
if (loadMoreMessages) { if (loadMoreMessages) {
mController.loadMoreMessages(mailboxId); mController.loadMoreMessages(mailboxId);
} else { } else {
mController.updateMailbox(accountId, mailboxId); mController.updateMailbox(accountId, mailboxId, userRequest);
} }
return true; return true;
} }

View File

@ -349,7 +349,7 @@ public class MessageList extends Activity implements OnClickListener,
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.refresh: case R.id.refresh:
mListFragment.onRefresh(); mListFragment.onRefresh(true);
return true; return true;
case R.id.folders: case R.id.folders:
onFolders(); onFolders();

View File

@ -24,10 +24,10 @@ import com.android.email.Utility;
import com.android.email.Utility.ListStateSaver; import com.android.email.Utility.ListStateSaver;
import com.android.email.data.MailboxAccountLoader; import com.android.email.data.MailboxAccountLoader;
import com.android.email.provider.EmailContent; 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.Account;
import com.android.email.provider.EmailContent.Mailbox; import com.android.email.provider.EmailContent.Mailbox;
import com.android.email.provider.EmailContent.Message; import com.android.email.provider.EmailContent.Message;
import com.android.email.provider.EmailProvider;
import com.android.email.service.MailService; import com.android.email.service.MailService;
import android.app.Activity; import android.app.Activity;
@ -56,15 +56,15 @@ import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.view.View.DragThumbnailBuilder; import android.view.View.DragThumbnailBuilder;
import android.view.View.OnDragListener; import android.view.View.OnDragListener;
import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import java.security.InvalidParameterException; import java.security.InvalidParameterException;
import java.util.HashSet; import java.util.HashSet;
@ -637,13 +637,13 @@ public class MessageListFragment extends ListFragment
* *
* Note: Manual refresh is enabled even for push accounts. * Note: Manual refresh is enabled even for push accounts.
*/ */
public void onRefresh() { public void onRefresh(boolean userRequest) {
if (!mIsRefreshable) { if (!mIsRefreshable) {
return; return;
} }
long accountId = getAccountId(); long accountId = getAccountId();
if (accountId != -1) { 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)) { if (!mRefreshManager.isMailboxStale(mMailboxId)) {
return; return;
} }
onRefresh(); onRefresh(false);
} }
/** Implements {@link MessagesAdapter.Callback} */ /** Implements {@link MessagesAdapter.Callback} */

View File

@ -780,7 +780,7 @@ public class MessageListXL extends Activity implements
return; return;
} }
if (isCurrentMailboxRefreshable) { if (isCurrentMailboxRefreshable) {
mRefreshManager.refreshMessageList(mAccountId, mMailboxId); mRefreshManager.refreshMessageList(mAccountId, mMailboxId, false);
} }
// Refresh mailbox list // Refresh mailbox list
if (mAccountId != -1) { if (mAccountId != -1) {
@ -790,7 +790,7 @@ public class MessageListXL extends Activity implements
} }
// Refresh inbox // Refresh inbox
if (shouldAutoRefreshInbox()) { if (shouldAutoRefreshInbox()) {
mRefreshManager.refreshMessageList(mAccountId, mInboxId); mRefreshManager.refreshMessageList(mAccountId, mInboxId, false);
} }
} }

View File

@ -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 () { setTask(new Runnable () {
public void run() { public void run() {
try { try {
if (mCallback != null) mService.setCallback(mCallback); if (mCallback != null) mService.setCallback(mCallback);
mService.startSync(mailboxId); mService.startSync(mailboxId, userRequest);
} catch (RemoteException e) { } catch (RemoteException e) {
} }
} }

View File

@ -23,7 +23,7 @@ interface IEmailService {
Bundle validate(in String protocol, in String host, in String userName, in String password, Bundle validate(in String protocol, in String host, in String userName, in String password,
int port, boolean ssl, boolean trustCertificates) ; int port, boolean ssl, boolean trustCertificates) ;
void startSync(long mailboxId); void startSync(long mailboxId, boolean userRequest);
void stopSync(long mailboxId); void stopSync(long mailboxId);
void loadMore(long messageId); void loadMore(long messageId);

View File

@ -96,7 +96,7 @@ public class PopImapSyncAdapterService extends Service {
Mailbox.TYPE_INBOX); Mailbox.TYPE_INBOX);
if (mailboxId > 0) { if (mailboxId > 0) {
Log.d(TAG, "Starting manual sync for account " + emailAddress); Log.d(TAG, "Starting manual sync for account " + emailAddress);
Controller.getInstance(context).updateMailbox(accountId, mailboxId); Controller.getInstance(context).updateMailbox(accountId, mailboxId, false);
} }
} }
} }

View File

@ -2364,8 +2364,8 @@ public class EasSyncService extends AbstractSyncService {
*/ */
public void run() { public void run() {
if (!setupService()) return; if (!setupService()) return;
final boolean callbackRequired = (mSyncReason >= ExchangeService.SYNC_CALLBACK_START);
if (mSyncReason >= ExchangeService.SYNC_UI_REQUEST) { if (callbackRequired) {
try { try {
ExchangeService.callback().syncMailboxStatus(mMailboxId, ExchangeService.callback().syncMailboxStatus(mMailboxId,
EmailServiceStatus.IN_PROGRESS, 0); 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 // Send a callback if this run was initiated by a service call
if (mSyncReason >= ExchangeService.SYNC_UI_REQUEST) { if (callbackRequired) {
try { 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); ExchangeService.callback().syncMailboxStatus(mMailboxId, status, 0);
} catch (RemoteException e1) { } catch (RemoteException e1) {
// Don't care if this fails // Don't care if this fails

View File

@ -137,12 +137,14 @@ public class ExchangeService extends Service implements Runnable {
// Misc. // Misc.
public static final int SYNC_KICK = 4; public static final int SYNC_KICK = 4;
// Requests >= SYNC_UI_REQUEST generate callbacks to the UI // Requests >= SYNC_CALLBACK_START generate callbacks to the UI
public static final int SYNC_UI_REQUEST = 5; public static final int SYNC_CALLBACK_START = 5;
// startSync was requested of ExchangeService // startSync was requested of ExchangeService (other than due to user request)
public static final int SYNC_SERVICE_START_SYNC = SYNC_UI_REQUEST + 0; 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 // 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 = private static final String WHERE_PUSH_OR_PING_NOT_ACCOUNT_MAILBOX =
MailboxColumns.ACCOUNT_KEY + "=? and " + MailboxColumns.TYPE + "!=" + MailboxColumns.ACCOUNT_KEY + "=? and " + MailboxColumns.TYPE + "!=" +
@ -340,7 +342,7 @@ public class ExchangeService extends Service implements Runnable {
return new EasSyncService().tryAutodiscover(userName, password); 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; ExchangeService exchangeService = INSTANCE;
if (exchangeService == null) return; if (exchangeService == null) return;
checkExchangeServiceServiceRunning(); checkExchangeServiceServiceRunning();
@ -369,7 +371,8 @@ public class ExchangeService extends Service implements Runnable {
} }
return; 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 { public void stopSync(long mailboxId) throws RemoteException {
@ -2328,7 +2331,7 @@ public class ExchangeService extends Service implements Runnable {
} }
} else { } else {
// If this is a ui request, set the sync reason for the service // 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; svc.mSyncReason = reason;
} }
} }

View File

@ -219,7 +219,7 @@ public class RefreshManagerTest extends InstrumentationTestCase {
public void testRefreshMessageList() { public void testRefreshMessageList() {
// request refresh mailbox 1 // request refresh mailbox 1
assertTrue(mTarget.refreshMessageList(ACCOUNT_1, MAILBOX_1)); assertTrue(mTarget.refreshMessageList(ACCOUNT_1, MAILBOX_1, false));
assertTrue(mListener.mCalledOnRefreshStatusChanged); assertTrue(mListener.mCalledOnRefreshStatusChanged);
assertFalse(mListener.mCalledOnConnectionError); assertFalse(mListener.mCalledOnConnectionError);
@ -234,7 +234,7 @@ public class RefreshManagerTest extends InstrumentationTestCase {
assertTrue(mTarget.isRefreshingAnyMessageListForTest()); assertTrue(mTarget.isRefreshingAnyMessageListForTest());
// Request again -- shouldn't be accepted. // 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.mCalledOnRefreshStatusChanged);
assertFalse(mListener.mCalledOnConnectionError); assertFalse(mListener.mCalledOnConnectionError);
@ -243,7 +243,7 @@ public class RefreshManagerTest extends InstrumentationTestCase {
mController.reset(); mController.reset();
// request refresh mailbox 2 // request refresh mailbox 2
assertTrue(mTarget.refreshMessageList(ACCOUNT_2, MAILBOX_2)); assertTrue(mTarget.refreshMessageList(ACCOUNT_2, MAILBOX_2, false));
assertTrue(mListener.mCalledOnRefreshStatusChanged); assertTrue(mListener.mCalledOnRefreshStatusChanged);
assertFalse(mListener.mCalledOnConnectionError); assertFalse(mListener.mCalledOnConnectionError);
@ -431,7 +431,7 @@ public class RefreshManagerTest extends InstrumentationTestCase {
} }
@Override @Override
public void updateMailbox(long accountId, long mailboxId) { public void updateMailbox(long accountId, long mailboxId, boolean userRequest) {
mCalledUpdateMailbox = true; mCalledUpdateMailbox = true;
mAccountId = accountId; mAccountId = accountId;
mMailboxId = mailboxId; mMailboxId = mailboxId;