From 19675e8bd7e0a43ba3e253a6f618e080067abd2a Mon Sep 17 00:00:00 2001 From: Yu Ping Hu Date: Mon, 7 Oct 2013 17:54:14 -0700 Subject: [PATCH] Add a mailbox type filter for syncing. Bug: 11081520 Change-Id: I76bcc0db08d2def3418849b9536b2e7ac1769f34 --- .../android/emailcommon/provider/Mailbox.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/emailcommon/src/com/android/emailcommon/provider/Mailbox.java b/emailcommon/src/com/android/emailcommon/provider/Mailbox.java index ae686e429..48a95ddde 100644 --- a/emailcommon/src/com/android/emailcommon/provider/Mailbox.java +++ b/emailcommon/src/com/android/emailcommon/provider/Mailbox.java @@ -55,6 +55,10 @@ public class Mailbox extends EmailContent implements MailboxColumns, Parcelable * Value for {@link #SYNC_EXTRA_MAILBOX_ID} when (re)starting push. */ public static final long SYNC_EXTRA_MAILBOX_ID_PUSH_ONLY = -3; + /** + * Sync extras key to specify that only a specific mailbox type should be synced. + */ + public static final String SYNC_EXTRA_MAILBOX_TYPE = "__mailboxType__"; /** * Sync extras key when syncing a mailbox to specify how many additional messages to sync. */ @@ -202,6 +206,11 @@ public class Mailbox extends EmailContent implements MailboxColumns, Parcelable + MailboxColumns.TYPE + "=" + Mailbox.TYPE_OUTBOX + " or " + MailboxColumns.SYNC_INTERVAL + "=1) and " + MailboxColumns.ACCOUNT_KEY + "=?"; + /** Selection for mailboxes that are configured for sync of a certain type for an account. */ + private static final String SYNCING_AND_TYPE_FOR_ACCOUNT_SELECTION = + MailboxColumns.SYNC_INTERVAL + "=1 and " + MailboxColumns.TYPE + "=? and " + + MailboxColumns.ACCOUNT_KEY + "=?"; + // Types of mailboxes. The list is ordered to match a typical UI presentation, e.g. // placing the inbox at the top. // Arrays of "special_mailbox_display_names" and "special_mailbox_icons" are depends on @@ -818,6 +827,19 @@ public class Mailbox extends EmailContent implements MailboxColumns, Parcelable new String[] { Long.toString(accountId) }, MailboxColumns.TYPE + " ASC"); } + /** + * Get the mailbox ids for an account that are configured for sync and have a specific type. + * @param accountId The id for the account that is syncing. + * @param mailboxType The type of the mailbox we're interested in. + * @return A cursor (with one column, containing ids) with all mailbox ids that match. + */ + public static Cursor getMailboxIdsForSyncByType(final ContentResolver cr, final long accountId, + final int mailboxType) { + return cr.query(Mailbox.CONTENT_URI, Mailbox.ID_PROJECTION, + SYNCING_AND_TYPE_FOR_ACCOUNT_SELECTION, + new String[] { Integer.toString(mailboxType), Long.toString(accountId) }, null); + } + /** * Get the account id for a mailbox. * @param context The {@link Context}.