Merge "Don't push things that haven't performed initial sync." into jb-ub-mail-ur10

This commit is contained in:
Yu Ping Hu 2013-10-04 21:41:13 +00:00 committed by Android (Google) Code Review
commit 1265011585
3 changed files with 22 additions and 21 deletions

View File

@ -162,6 +162,10 @@ public abstract class EmailContent {
}
}
public static boolean isInitialSyncKey(final String syncKey) {
return syncKey == null || syncKey.isEmpty() || syncKey.equals("0");
}
// The Uri is lazily initialized
public Uri getUri() {
if (mUri == null) {

View File

@ -188,9 +188,14 @@ 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 should receive push for an account. A mailbox should receive
* push if it has a valid, non-initial sync key and is opted in for sync.
*/
private static final String PUSH_MAILBOXES_FOR_ACCOUNT_SELECTION =
MailboxColumns.SYNC_KEY + "not null and " + MailboxColumns.SYNC_KEY + "!='' and " +
MailboxColumns.SYNC_KEY + "!='0'" + 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 = "("
@ -787,14 +792,15 @@ public class Mailbox extends EmailContent implements MailboxColumns, Parcelable
}
/**
* Get the mailboxes that want to receive push updates for an account.
* Get the mailboxes that should 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);
PUSH_MAILBOXES_FOR_ACCOUNT_SELECTION, new String[] { Long.toString(accountId) },
null);
}
/**

View File

@ -1506,12 +1506,14 @@ public class EmailProvider extends ContentProvider {
*/
private static final String GET_ACCOUNT_DETAILS = "SELECT"
+ " h." + HostAuthColumns.PROTOCOL + ","
+ " a." + AccountColumns.EMAIL_ADDRESS
+ " a." + AccountColumns.EMAIL_ADDRESS + ","
+ " a." + AccountColumns.SYNC_KEY
+ " FROM " + Account.TABLE_NAME + " AS a"
+ " INNER JOIN " + HostAuth.TABLE_NAME + " AS h"
+ " ON a." + AccountColumns.HOST_AUTH_KEY_RECV + "=h." + HostAuthColumns.ID
+ " WHERE a." + AccountColumns.ID + "=?";
private static final int INDEX_EMAIL_ADDRESS = 1;
private static final int INDEX_SYNC_KEY = 2;
/**
* Restart push if we need it (currently only for Exchange accounts).
@ -1527,8 +1529,10 @@ public class EmailProvider extends ContentProvider {
try {
if (c.moveToFirst()) {
final String protocol = c.getString(INDEX_PROTOCOL);
final String emailAddress = c.getString(INDEX_EMAIL_ADDRESS);
if (context.getString(R.string.protocol_eas).equals(protocol)) {
// Only restart push for EAS accounts that have completed initial sync.
if (context.getString(R.string.protocol_eas).equals(protocol) &&
!EmailContent.isInitialSyncKey(c.getString(INDEX_SYNC_KEY))) {
final String emailAddress = c.getString(INDEX_EMAIL_ADDRESS);
final android.accounts.Account account =
getAccountManagerAccount(context, emailAddress, protocol);
restartPush(account);
@ -4880,12 +4884,6 @@ public class EmailProvider extends ContentProvider {
return new android.accounts.Account(emailAddress, info.accountType);
}
/**
* The amount of time between periodic syncs intended to ensure that push hasn't died.
*/
private static final long KICK_SYNC_INTERVAL =
DateUtils.HOUR_IN_MILLIS / DateUtils.SECOND_IN_MILLIS;
/**
* Update an account's periodic sync if the sync interval has changed.
* @param accountId id for the account to update.
@ -4918,13 +4916,6 @@ public class EmailProvider extends ContentProvider {
if (syncInterval > 0) {
ContentResolver.addPeriodicSync(account, EmailContent.AUTHORITY, Bundle.EMPTY,
syncInterval * DateUtils.MINUTE_IN_MILLIS / DateUtils.SECOND_IN_MILLIS);
} else if (syncInterval == Account.CHECK_INTERVAL_PUSH) {
// Schedule a periodic sync to restart the push in case it fails.
// TODO: Make this unnecessary by having push not break.
final Bundle extras = new Bundle(1);
extras.putLong(Mailbox.SYNC_EXTRA_MAILBOX_ID, Mailbox.SYNC_EXTRA_MAILBOX_ID_PUSH_ONLY);
ContentResolver.addPeriodicSync(account, EmailContent.AUTHORITY, extras,
KICK_SYNC_INTERVAL);
}
}