From 40236a89316ab2151a8c93de0e286c2f1a9a8d37 Mon Sep 17 00:00:00 2001 From: James Lemieux Date: Mon, 29 Sep 2014 17:51:27 -0700 Subject: [PATCH] Display sync errors using snackbar and not as a TL footer b/16463253 The FAB compose button overlaps the action button found in the TL footer when network errors occur during sync. To avoid this overlap, the snackbar is used to display these errors and they no longer appear as a TL footer. In order to signal the sync error to AAC for display in the snackbar, the Folder.lastSyncResult needed to be encoded in the manner that AAC reads. This was not happening for POP/IMAP/Exchange accounts, so a large portion of this change is encoding that value properly every place it is written. To ensure the value is read/written properly everywhere, common methods were introduced in UIProvider that do this work. UIProviderTest was also added to ensure the read/write methods agree with each other. Finally, the display of the "Load More" TL footer was updated to match the latest spec. Change-Id: I9d3ae1157f288f05b0fed4d1385858f6c9ebfbf9 --- .../emailcommon/provider/EmailContent.java | 5 ++- .../service/EmailServiceStatus.java | 1 + .../provider/EmailConversationCursor.java | 4 -- .../android/email/provider/EmailProvider.java | 14 +++---- .../service/PopImapSyncAdapterService.java | 38 ++++++++++++------- 5 files changed, 36 insertions(+), 26 deletions(-) diff --git a/emailcommon/src/com/android/emailcommon/provider/EmailContent.java b/emailcommon/src/com/android/emailcommon/provider/EmailContent.java index f6766ae2b..0dc87c735 100755 --- a/emailcommon/src/com/android/emailcommon/provider/EmailContent.java +++ b/emailcommon/src/com/android/emailcommon/provider/EmailContent.java @@ -35,10 +35,10 @@ import android.os.Parcelable; import android.os.RemoteException; import android.provider.BaseColumns; -import com.android.emailcommon.utility.TextUtilities; -import com.android.emailcommon.utility.Utility; import com.android.emailcommon.Logging; import com.android.emailcommon.R; +import com.android.emailcommon.utility.TextUtilities; +import com.android.emailcommon.utility.Utility; import com.android.mail.providers.UIProvider; import com.android.mail.utils.LogUtils; import com.google.common.annotations.VisibleForTesting; @@ -101,6 +101,7 @@ public abstract class EmailContent { public static final int LAST_SYNC_RESULT_SUCCESS = UIProvider.LastSyncResult.SUCCESS; public static final int LAST_SYNC_RESULT_AUTH_ERROR = UIProvider.LastSyncResult.AUTH_ERROR; + public static final int LAST_SYNC_RESULT_SERVER_ERROR = UIProvider.LastSyncResult.SERVER_ERROR; public static final int LAST_SYNC_RESULT_SECURITY_ERROR = UIProvider.LastSyncResult.SECURITY_ERROR; public static final int LAST_SYNC_RESULT_CONNECTION_ERROR = diff --git a/emailcommon/src/com/android/emailcommon/service/EmailServiceStatus.java b/emailcommon/src/com/android/emailcommon/service/EmailServiceStatus.java index 44922221b..88e5dd29a 100644 --- a/emailcommon/src/com/android/emailcommon/service/EmailServiceStatus.java +++ b/emailcommon/src/com/android/emailcommon/service/EmailServiceStatus.java @@ -33,6 +33,7 @@ import android.os.Bundle; public abstract class EmailServiceStatus { public static final int SUCCESS = 0; public static final int IN_PROGRESS = 1; + public static final int FAILURE = 2; public static final int MESSAGE_NOT_FOUND = 0x10; public static final int ATTACHMENT_NOT_FOUND = 0x11; diff --git a/provider_src/com/android/email/provider/EmailConversationCursor.java b/provider_src/com/android/email/provider/EmailConversationCursor.java index f6a17e37f..f2c481b41 100644 --- a/provider_src/com/android/email/provider/EmailConversationCursor.java +++ b/provider_src/com/android/email/provider/EmailConversationCursor.java @@ -72,8 +72,6 @@ public class EmailConversationCursor extends CursorWrapper implements if (mailbox != null) { mMailboxTypeId = mailbox.mType; - mExtras.putInt(UIProvider.CursorExtraKeys.EXTRA_ERROR, - mailbox.mUiLastSyncResult); mExtras.putInt(UIProvider.CursorExtraKeys.EXTRA_TOTAL_COUNT, mailbox.mTotalCount); if (mailbox.mUiSyncStatus == EmailContent.SYNC_STATUS_BACKGROUND || mailbox.mUiSyncStatus == EmailContent.SYNC_STATUS_USER @@ -106,8 +104,6 @@ public class EmailConversationCursor extends CursorWrapper implements } else { mMailboxTypeId = -1; // TODO for virtual mailboxes, we may want to do something besides just fake it - mExtras.putInt(UIProvider.CursorExtraKeys.EXTRA_ERROR, - UIProvider.LastSyncResult.SUCCESS); mExtras.putInt(UIProvider.CursorExtraKeys.EXTRA_TOTAL_COUNT, cursor != null ? cursor.getCount() : 0); mExtras.putInt(UIProvider.CursorExtraKeys.EXTRA_STATUS, diff --git a/provider_src/com/android/email/provider/EmailProvider.java b/provider_src/com/android/email/provider/EmailProvider.java index 52e796b3a..e4d052081 100644 --- a/provider_src/com/android/email/provider/EmailProvider.java +++ b/provider_src/com/android/email/provider/EmailProvider.java @@ -65,10 +65,10 @@ import android.util.SparseArray; import com.android.common.content.ProjectionMap; import com.android.email.DebugUtils; +import com.android.email.NotificationController; +import com.android.email.NotificationControllerCreatorHolder; import com.android.email.Preferences; import com.android.email.R; -import com.android.email.NotificationControllerCreatorHolder; -import com.android.email.NotificationController; import com.android.email.SecurityPolicy; import com.android.email.activity.setup.AccountSecurity; import com.android.email.activity.setup.AccountSettingsUtils; @@ -5751,13 +5751,13 @@ public class EmailProvider extends ContentProvider .monitorRefreshStatus(mailbox.mId, new RefreshStatusMonitor.Callback() { @Override public void onRefreshCompleted(long mailboxId, int result) { + // all calls to this method assumed to be started by a user action + final int syncValue = UIProvider.createSyncValue(EmailContent.SYNC_STATUS_USER, + result); final ContentValues values = new ContentValues(); values.put(Mailbox.UI_SYNC_STATUS, UIProvider.SyncStatus.NO_SYNC); - values.put(Mailbox.UI_LAST_SYNC_RESULT, result); - mDatabase.update( - Mailbox.TABLE_NAME, - values, - WHERE_ID, + values.put(Mailbox.UI_LAST_SYNC_RESULT, syncValue); + mDatabase.update(Mailbox.TABLE_NAME, values, WHERE_ID, new String[] { String.valueOf(mailboxId) }); notifyUIFolder(mailbox.mId, mailbox.mAccountKey); } diff --git a/provider_src/com/android/email/service/PopImapSyncAdapterService.java b/provider_src/com/android/email/service/PopImapSyncAdapterService.java index 4fae4d0a9..08a6f3adb 100644 --- a/provider_src/com/android/email/service/PopImapSyncAdapterService.java +++ b/provider_src/com/android/email/service/PopImapSyncAdapterService.java @@ -122,17 +122,21 @@ public class PopImapSyncAdapterService extends Service { Uri mailboxUri = ContentUris.withAppendedId(Mailbox.CONTENT_URI, mailboxId); ContentValues values = new ContentValues(); // Set mailbox sync state - values.put(Mailbox.UI_SYNC_STATUS, - uiRefresh ? EmailContent.SYNC_STATUS_USER : EmailContent.SYNC_STATUS_BACKGROUND); + final int syncStatus = uiRefresh ? EmailContent.SYNC_STATUS_USER : + EmailContent.SYNC_STATUS_BACKGROUND; + values.put(Mailbox.UI_SYNC_STATUS, syncStatus); resolver.update(mailboxUri, values, null, null); try { + int lastSyncResult; try { String legacyImapProtocol = context.getString(R.string.protocol_legacy_imap); if (mailbox.mType == Mailbox.TYPE_OUTBOX) { EmailServiceStub.sendMailImpl(context, account.mId); } else { + lastSyncResult = UIProvider.createSyncValue(syncStatus, + EmailContent.LAST_SYNC_RESULT_SUCCESS); EmailServiceStatus.syncMailboxStatus(resolver, extras, mailboxId, - EmailServiceStatus.IN_PROGRESS, 0, UIProvider.LastSyncResult.SUCCESS); + EmailServiceStatus.IN_PROGRESS, 0, lastSyncResult); final int status; if (protocol.equals(legacyImapProtocol)) { status = ImapService.synchronizeMailboxSynchronous(context, account, @@ -142,30 +146,38 @@ public class PopImapSyncAdapterService extends Service { mailbox, deltaMessageCount); } EmailServiceStatus.syncMailboxStatus(resolver, extras, mailboxId, status, 0, - UIProvider.LastSyncResult.SUCCESS); + lastSyncResult); } } catch (MessagingException e) { final int type = e.getExceptionType(); // type must be translated into the domain of values used by EmailServiceStatus - switch(type) { + switch (type) { case MessagingException.IOERROR: - EmailServiceStatus.syncMailboxStatus(resolver, extras, mailboxId, type, 0, - UIProvider.LastSyncResult.CONNECTION_ERROR); + lastSyncResult = UIProvider.createSyncValue(syncStatus, + EmailContent.LAST_SYNC_RESULT_CONNECTION_ERROR); + EmailServiceStatus.syncMailboxStatus(resolver, extras, mailboxId, + EmailServiceStatus.FAILURE, 0, lastSyncResult); syncResult.stats.numIoExceptions++; break; case MessagingException.AUTHENTICATION_FAILED: - EmailServiceStatus.syncMailboxStatus(resolver, extras, mailboxId, type, 0, - UIProvider.LastSyncResult.AUTH_ERROR); + lastSyncResult = UIProvider.createSyncValue(syncStatus, + EmailContent.LAST_SYNC_RESULT_AUTH_ERROR); + EmailServiceStatus.syncMailboxStatus(resolver, extras, mailboxId, + EmailServiceStatus.FAILURE, 0, lastSyncResult); syncResult.stats.numAuthExceptions++; break; case MessagingException.SERVER_ERROR: - EmailServiceStatus.syncMailboxStatus(resolver, extras, mailboxId, type, 0, - UIProvider.LastSyncResult.SERVER_ERROR); + lastSyncResult = UIProvider.createSyncValue(syncStatus, + EmailContent.LAST_SYNC_RESULT_SERVER_ERROR); + EmailServiceStatus.syncMailboxStatus(resolver, extras, mailboxId, + EmailServiceStatus.FAILURE, 0, lastSyncResult); break; default: - EmailServiceStatus.syncMailboxStatus(resolver, extras, mailboxId, type, 0, - UIProvider.LastSyncResult.INTERNAL_ERROR); + lastSyncResult = UIProvider.createSyncValue(syncStatus, + EmailContent.LAST_SYNC_RESULT_INTERNAL_ERROR); + EmailServiceStatus.syncMailboxStatus(resolver, extras, mailboxId, + EmailServiceStatus.FAILURE, 0, lastSyncResult); } } } finally {