diff --git a/provider_src/com/android/email/mail/Store.java b/provider_src/com/android/email/mail/Store.java index 377b59448..310238fdd 100644 --- a/provider_src/com/android/email/mail/Store.java +++ b/provider_src/com/android/email/mail/Store.java @@ -156,6 +156,16 @@ public abstract class Store { return true; } + /** + * Some protocols allow for syncing of folder types other than inbox. The store for any such + * protocol should override this to return what types can be synced. + * @param type The type of mailbox + * @return true if the given type of mailbox can be synced. + */ + public boolean canSyncFolderType(final int type) { + return (type == Mailbox.TYPE_INBOX); + } + public Folder getFolder(String name) throws MessagingException { return null; } diff --git a/provider_src/com/android/email/mail/store/ImapStore.java b/provider_src/com/android/email/mail/store/ImapStore.java index 89667eb7f..0aee551f7 100644 --- a/provider_src/com/android/email/mail/store/ImapStore.java +++ b/provider_src/com/android/email/mail/store/ImapStore.java @@ -40,6 +40,7 @@ import com.android.emailcommon.mail.Message; import com.android.emailcommon.mail.MessagingException; import com.android.emailcommon.provider.Account; import com.android.emailcommon.provider.Credential; +import com.android.emailcommon.provider.EmailContent; import com.android.emailcommon.provider.HostAuth; import com.android.emailcommon.provider.Mailbox; import com.android.emailcommon.service.EmailServiceProxy; @@ -133,6 +134,26 @@ public class ImapStore extends Store { return mPassword; } + public boolean canSyncFolderType(final int type) { + switch (type) { + case Mailbox.TYPE_INBOX: + case Mailbox.TYPE_MAIL: + case Mailbox.TYPE_SENT: + case Mailbox.TYPE_TRASH: + case Mailbox.TYPE_JUNK: + return true; + case Mailbox.TYPE_NONE: + case Mailbox.TYPE_PARENT: + case Mailbox.TYPE_DRAFTS: + case Mailbox.TYPE_OUTBOX: + case Mailbox.TYPE_SEARCH: + case Mailbox.TYPE_STARRED: + case Mailbox.TYPE_UNREAD: + default: + return false; + } + } + @VisibleForTesting Collection getConnectionPoolForTest() { return mConnectionPool; @@ -373,6 +394,11 @@ public class ImapStore extends Store { // outside of #saveMailboxList() folder.mHash = mailbox.getHashes(); // We must save this here to make sure we have a valid ID for later + + // This is a newly created folder from the server. By definition, if it came from + // the server, it can be synched. We need to set the uiSyncStatus so that the UI + // will not try to display the empty state until the sync completes. + mailbox.mUiSyncStatus = EmailContent.SYNC_STATUS_INITIAL_SYNC_NEEDED; mailbox.save(mContext); } folder.mMailbox = mailbox; diff --git a/provider_src/com/android/email/service/EmailServiceStub.java b/provider_src/com/android/email/service/EmailServiceStub.java index aa73d29dc..055c36004 100644 --- a/provider_src/com/android/email/service/EmailServiceStub.java +++ b/provider_src/com/android/email/service/EmailServiceStub.java @@ -293,10 +293,18 @@ public abstract class EmailServiceStub extends IEmailService.Stub implements IEm Cursor localFolderCursor = null; Store store = null; try { + store = Store.getInstance(account, mContext); + // Step 0: Make sure the default system mailboxes exist. for (final int type : Mailbox.REQUIRED_FOLDER_TYPES) { if (Mailbox.findMailboxOfType(mContext, accountId, type) == Mailbox.NO_MAILBOX) { final Mailbox mailbox = Mailbox.newSystemMailbox(mContext, accountId, type); + if (store.canSyncFolderType(type)) { + // If this folder is syncable, then we should set its UISyncStatus. + // Otherwise the UI could show the empty state until the sync + // actually occurs. + mailbox.mUiSyncStatus = Mailbox.SYNC_STATUS_INITIAL_SYNC_NEEDED; + } mailbox.save(mContext); if (type == Mailbox.TYPE_INBOX) { inboxId = mailbox.mId; @@ -305,7 +313,6 @@ public abstract class EmailServiceStub extends IEmailService.Stub implements IEm } // Step 1: Get remote mailboxes - store = Store.getInstance(account, mContext); final Folder[] remoteFolders = store.updateFolders(); final HashSet remoteFolderNames = new HashSet(); for (final Folder remoteFolder : remoteFolders) {