summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYu Ping Hu <yph@google.com>2013-06-20 17:11:01 -0700
committerYu Ping Hu <yph@google.com>2013-06-20 18:38:48 -0700
commita54ee609cdb79ad3abdda2d7180a29617fa38610 (patch)
tree6c60ab5bfb818d66c234f53dcacac828e0537e03
parent6f2beeb59ae75ee26c78d99ded532acd87e1ff97 (diff)
downloadandroid_packages_apps_Email-a54ee609cdb79ad3abdda2d7180a29617fa38610.tar.gz
android_packages_apps_Email-a54ee609cdb79ad3abdda2d7180a29617fa38610.tar.bz2
android_packages_apps_Email-a54ee609cdb79ad3abdda2d7180a29617fa38610.zip
Convert Mailbox syncInterval column to boolean.
We are no longer doing per-mailbox sync intervals; instead, mailboxes opt in to syncing, and the account sync interval controls what happens. Change-Id: I8ae32ea25079abbb63bb6a6a282bf5c06de73fca
-rw-r--r--emailcommon/src/com/android/emailcommon/provider/Mailbox.java35
-rw-r--r--src/com/android/email/provider/DBHelper.java14
-rw-r--r--src/com/android/email/provider/EmailProvider.java6
3 files changed, 52 insertions, 3 deletions
diff --git a/emailcommon/src/com/android/emailcommon/provider/Mailbox.java b/emailcommon/src/com/android/emailcommon/provider/Mailbox.java
index 002a7a9d5..637dfc400 100644
--- a/emailcommon/src/com/android/emailcommon/provider/Mailbox.java
+++ b/emailcommon/src/com/android/emailcommon/provider/Mailbox.java
@@ -17,6 +17,7 @@
package com.android.emailcommon.provider;
+import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
@@ -128,7 +129,9 @@ public class Mailbox extends EmailContent implements MailboxColumns, Parcelable
public static final long NO_MAILBOX = -1;
// Sentinel values for the mSyncInterval field of both Mailbox records
+ @Deprecated
public static final int CHECK_INTERVAL_NEVER = -1;
+ @Deprecated
public static final int CHECK_INTERVAL_PUSH = -2;
// The following two sentinel values are used by EAS
// Ping indicates that the EAS mailbox is synced based on a "ping" from the server
@@ -151,6 +154,15 @@ public class Mailbox extends EmailContent implements MailboxColumns, Parcelable
MailboxColumns.TYPE + "<" + Mailbox.TYPE_NOT_EMAIL +
" AND " + MailboxColumns.FLAG_VISIBLE + "=1";
+ /** Selection for all mailboxes that explicitly say they want to sync for an account. */
+ private static final String SYNCING_AND_ACCOUNT_SELECTION =
+ MailboxColumns.SYNC_INTERVAL + "=1 and " + MailboxColumns.ACCOUNT_KEY + "=?";
+
+ /** Selection for mailboxes that say they want to sync, plus outbox, for an account. */
+ private static final String OUTBOX_PLUS_SYNCING_AND_ACCOUNT_SELECTION = "("
+ + MailboxColumns.TYPE + "=" + Mailbox.TYPE_OUTBOX + " or "
+ + MailboxColumns.SYNC_INTERVAL + "=1) 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
@@ -691,4 +703,27 @@ public class Mailbox extends EmailContent implements MailboxColumns, Parcelable
public String toString() {
return "[Mailbox " + mId + ": " + mDisplayName + "]";
}
+
+ /**
+ * Get the mailboxes that want to receive push updates for an account.
+ * @param cr The {@link ContentResolver}.
+ * @param accountId The id for the account that is pushing.
+ * @return A cursor (suitable for use with {@link #restore}) with all mailboxes we should sync.
+ */
+ public static Cursor getMailboxesForPush(final ContentResolver cr, final long accountId) {
+ return cr.query(Mailbox.CONTENT_URI, Mailbox.CONTENT_PROJECTION,
+ SYNCING_AND_ACCOUNT_SELECTION, new String[] { Long.toString(accountId) }, null);
+ }
+
+ /**
+ * Get the mailbox ids for an account that should sync when we do a full account sync.
+ * @param cr The {@link ContentResolver}.
+ * @param accountId The id for the account that is pushing.
+ * @return A cursor (with one column, containing ids) with all mailbox ids we should sync.
+ */
+ public static Cursor getMailboxIdsForSync(final ContentResolver cr, final long accountId) {
+ return cr.query(Mailbox.CONTENT_URI, Mailbox.ID_PROJECTION,
+ OUTBOX_PLUS_SYNCING_AND_ACCOUNT_SELECTION,
+ new String[] { Long.toString(accountId) }, null);
+ }
}
diff --git a/src/com/android/email/provider/DBHelper.java b/src/com/android/email/provider/DBHelper.java
index fb3128d23..626b55554 100644
--- a/src/com/android/email/provider/DBHelper.java
+++ b/src/com/android/email/provider/DBHelper.java
@@ -143,8 +143,10 @@ public final class DBHelper {
// Version 110: Stop updating message_count, don't use auto lookback, and don't use
// ping/push_hold sync states.
// Version 111: Delete Exchange account mailboxes.
+ // Version 112: Convert Mailbox syncInterval to a boolean (whether or not this mailbox
+ // syncs along with the account).
- public static final int DATABASE_VERSION = 111;
+ public static final int DATABASE_VERSION = 112;
// Any changes to the database format *must* include update-in-place code.
// Original version: 2
@@ -1047,8 +1049,18 @@ public final class DBHelper {
oldVersion = 110;
}
if (oldVersion == 110) {
+ // Delete account mailboxes.
db.execSQL("delete from " + Mailbox.TABLE_NAME + " where " + MailboxColumns.TYPE
+ "=" +Mailbox.TYPE_EAS_ACCOUNT_MAILBOX);
+ oldVersion = 111;
+ }
+ if (oldVersion == 111) {
+ // Mailbox sync interval now indicates whether this mailbox syncs with the rest
+ // of the account. Anyone who was syncing at all, plus outboxes, are set to 1,
+ // everyone else is 0.
+ db.execSQL("update " + Mailbox.TABLE_NAME + " set " + MailboxColumns.SYNC_INTERVAL
+ + "=case when " + MailboxColumns.SYNC_INTERVAL + "="
+ + Mailbox.CHECK_INTERVAL_NEVER + " then 0 else 1 end");
}
}
diff --git a/src/com/android/email/provider/EmailProvider.java b/src/com/android/email/provider/EmailProvider.java
index df6f1e78a..49e86874d 100644
--- a/src/com/android/email/provider/EmailProvider.java
+++ b/src/com/android/email/provider/EmailProvider.java
@@ -3208,7 +3208,9 @@ public class EmailProvider extends ContentProvider {
new String[] {String.valueOf(mailbox.mId)});
// For non-push mailboxes, if it's stale (i.e. last sync was a while
// ago), force a sync.
- if (mailbox.mSyncInterval > Mailbox.CHECK_INTERVAL_PUSH) {
+ // TODO: Fix the check for whether we're non-push? Right now it checks
+ // whether we are participating in account sync rules.
+ if (mailbox.mSyncInterval == 0) {
final long timeSinceLastSync =
System.currentTimeMillis() - mailbox.mSyncTime;
if (timeSinceLastSync > AUTO_REFRESH_INTERVAL_MS) {
@@ -4350,7 +4352,7 @@ public class EmailProvider extends ContentProvider {
m.mServerId = SEARCH_MAILBOX_SERVER_ID;
m.mFlagVisible = false;
m.mDisplayName = SEARCH_MAILBOX_SERVER_ID;
- m.mSyncInterval = Mailbox.CHECK_INTERVAL_NEVER;
+ m.mSyncInterval = 0;
m.mType = Mailbox.TYPE_SEARCH;
m.mFlags = Mailbox.FLAG_HOLDS_MAIL;
m.mParentKey = Mailbox.NO_MAILBOX;