Add "account only" periodic sync for push accounts.
EAS push only gets changes to the contents of collections, but not for changes to accounts or folder structure. This adds a new sync type to fetch only accounts, and adds a periodic sync of this type for push accounts. Change-Id: I1e9337252dbb5e53db3f7c5953e089de2c69d18c
This commit is contained in:
parent
ef3fe5727f
commit
6f2beeb59a
@ -36,6 +36,10 @@ public class Mailbox extends EmailContent implements MailboxColumns, Parcelable
|
|||||||
* Sync extras key when syncing a mailbox to specify which mailbox to sync.
|
* Sync extras key when syncing a mailbox to specify which mailbox to sync.
|
||||||
*/
|
*/
|
||||||
public static final String SYNC_EXTRA_MAILBOX_ID = "__mailboxId__";
|
public static final String SYNC_EXTRA_MAILBOX_ID = "__mailboxId__";
|
||||||
|
/**
|
||||||
|
* Value for {@link #SYNC_EXTRA_MAILBOX_ID} when requesting an account only sync
|
||||||
|
*/
|
||||||
|
public static final long SYNC_EXTRA_MAILBOX_ID_ACCOUNT_ONLY = -2;
|
||||||
/**
|
/**
|
||||||
* Sync extras key when syncing a mailbox to specify how many additional messages to sync.
|
* Sync extras key when syncing a mailbox to specify how many additional messages to sync.
|
||||||
*/
|
*/
|
||||||
|
@ -257,6 +257,14 @@ public class EmailProvider extends ContentProvider {
|
|||||||
Body.TABLE_NAME,
|
Body.TABLE_NAME,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accounts that are receiving push notifications schedule a periodic sync to fetch account
|
||||||
|
* changes that aren't included in push (e.g. account settings, folder structure). This value
|
||||||
|
* specifies the poll frequency, in seconds. Currently set to one day.
|
||||||
|
*/
|
||||||
|
private static final long ACCOUNT_ONLY_SYNC_INTERVAL =
|
||||||
|
DateUtils.DAY_IN_MILLIS / DateUtils.SECOND_IN_MILLIS;
|
||||||
|
|
||||||
private static UriMatcher sURIMatcher = null;
|
private static UriMatcher sURIMatcher = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -4241,21 +4249,6 @@ public class EmailProvider extends ContentProvider {
|
|||||||
return new android.accounts.Account(account.mEmailAddress, info.accountType);
|
return new android.accounts.Account(account.mEmailAddress, info.accountType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The old sync code used to add periodic syncs for a mailbox when it was manually synced.
|
|
||||||
* This function removes all such non-default periodic syncs.
|
|
||||||
* @param account The account for which to remove unnecessary periodic syncs.
|
|
||||||
*/
|
|
||||||
private void removeExtraPeriodicSyncs(final android.accounts.Account account) {
|
|
||||||
final List<PeriodicSync> syncs =
|
|
||||||
ContentResolver.getPeriodicSyncs(account, EmailContent.AUTHORITY);
|
|
||||||
for (PeriodicSync sync : syncs) {
|
|
||||||
if (!sync.extras.isEmpty()) {
|
|
||||||
ContentResolver.removePeriodicSync(account, EmailContent.AUTHORITY, sync.extras);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update an account's periodic sync if the sync interval has changed.
|
* Update an account's periodic sync if the sync interval has changed.
|
||||||
* @param accountId id for the account to update.
|
* @param accountId id for the account to update.
|
||||||
@ -4276,16 +4269,27 @@ public class EmailProvider extends ContentProvider {
|
|||||||
LogUtils.d(TAG, "Setting sync interval for account " + accountId + " to " + syncInterval +
|
LogUtils.d(TAG, "Setting sync interval for account " + accountId + " to " + syncInterval +
|
||||||
" minutes");
|
" minutes");
|
||||||
|
|
||||||
// TODO: Ideally we don't need to do this every time we change the sync interval.
|
// First remove all existing periodic syncs.
|
||||||
// Either do this on upgrade, or perhaps on startup.
|
final List<PeriodicSync> syncs =
|
||||||
removeExtraPeriodicSyncs(account);
|
ContentResolver.getPeriodicSyncs(account, EmailContent.AUTHORITY);
|
||||||
|
for (final PeriodicSync sync : syncs) {
|
||||||
|
ContentResolver.removePeriodicSync(account, EmailContent.AUTHORITY, sync.extras);
|
||||||
|
}
|
||||||
|
|
||||||
final Bundle extras = new Bundle();
|
// Now add back the periodic sync we need, if there is one.
|
||||||
if (syncInterval > 0) {
|
if (syncInterval != Account.CHECK_INTERVAL_NEVER) {
|
||||||
ContentResolver.addPeriodicSync(account, EmailContent.AUTHORITY, extras,
|
final Bundle extras = new Bundle();
|
||||||
syncInterval * 60);
|
final long pollFrequency;
|
||||||
} else {
|
if (syncInterval == Account.CHECK_INTERVAL_PUSH) {
|
||||||
ContentResolver.removePeriodicSync(account, EmailContent.AUTHORITY, extras);
|
// For push accounts, we still need an account-only sync to update things that are
|
||||||
|
// not pushed.
|
||||||
|
extras.putLong(Mailbox.SYNC_EXTRA_MAILBOX_ID,
|
||||||
|
Mailbox.SYNC_EXTRA_MAILBOX_ID_ACCOUNT_ONLY);
|
||||||
|
pollFrequency = ACCOUNT_ONLY_SYNC_INTERVAL;
|
||||||
|
} else {
|
||||||
|
pollFrequency = syncInterval * 60;
|
||||||
|
}
|
||||||
|
ContentResolver.addPeriodicSync(account, EmailContent.AUTHORITY, extras, pollFrequency);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user