Merge change 26262 into eclair
* changes: Only handle mailbox alarms for EAS mailboxes
This commit is contained in:
commit
b2f71dac39
@ -55,9 +55,13 @@ public class EmailSyncAlarmReceiver extends BroadcastReceiver {
|
|||||||
ArrayList<Long> mailboxesToNotify = new ArrayList<Long>();
|
ArrayList<Long> mailboxesToNotify = new ArrayList<Long>();
|
||||||
ContentResolver cr = context.getContentResolver();
|
ContentResolver cr = context.getContentResolver();
|
||||||
int messageCount = 0;
|
int messageCount = 0;
|
||||||
|
|
||||||
|
// Get a selector for EAS accounts (we don't want to sync on changes to POP/IMAP messages)
|
||||||
|
String selector = SyncManager.getEasAccountSelector();
|
||||||
|
|
||||||
// Find all of the deletions
|
// Find all of the deletions
|
||||||
Cursor c = cr.query(Message.DELETED_CONTENT_URI, MAILBOX_DATA_PROJECTION,
|
Cursor c = cr.query(Message.DELETED_CONTENT_URI, MAILBOX_DATA_PROJECTION, selector,
|
||||||
null, null, null);
|
null, null);
|
||||||
try {
|
try {
|
||||||
// Keep track of which mailboxes to notify; we'll only notify each one once
|
// Keep track of which mailboxes to notify; we'll only notify each one once
|
||||||
while (c.moveToNext()) {
|
while (c.moveToNext()) {
|
||||||
@ -72,8 +76,8 @@ public class EmailSyncAlarmReceiver extends BroadcastReceiver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now, find changed messages
|
// Now, find changed messages
|
||||||
c = cr.query(Message.UPDATED_CONTENT_URI, MAILBOX_DATA_PROJECTION,
|
c = cr.query(Message.UPDATED_CONTENT_URI, MAILBOX_DATA_PROJECTION, selector,
|
||||||
null, null, null);
|
null, null);
|
||||||
try {
|
try {
|
||||||
// Keep track of which mailboxes to notify; we'll only notify each one once
|
// Keep track of which mailboxes to notify; we'll only notify each one once
|
||||||
while (c.moveToNext()) {
|
while (c.moveToNext()) {
|
||||||
|
@ -149,6 +149,7 @@ public class SyncManager extends Service implements Runnable {
|
|||||||
"(" + MailboxColumns.TYPE + '=' + Mailbox.TYPE_OUTBOX
|
"(" + MailboxColumns.TYPE + '=' + Mailbox.TYPE_OUTBOX
|
||||||
+ " or " + MailboxColumns.SYNC_INTERVAL + "!=" + Mailbox.CHECK_INTERVAL_NEVER + ')'
|
+ " or " + MailboxColumns.SYNC_INTERVAL + "!=" + Mailbox.CHECK_INTERVAL_NEVER + ')'
|
||||||
+ " and " + MailboxColumns.ACCOUNT_KEY + " in (";
|
+ " and " + MailboxColumns.ACCOUNT_KEY + " in (";
|
||||||
|
private static final String ACCOUNT_KEY_IN = MailboxColumns.ACCOUNT_KEY + " in (";
|
||||||
|
|
||||||
// Offsets into the syncStatus data for EAS that indicate type, exit status, and change count
|
// Offsets into the syncStatus data for EAS that indicate type, exit status, and change count
|
||||||
// The format is S<type_char>:<exit_char>:<change_count>
|
// The format is S<type_char>:<exit_char>:<change_count>
|
||||||
@ -372,7 +373,8 @@ public class SyncManager extends Service implements Runnable {
|
|||||||
class AccountObserver extends ContentObserver {
|
class AccountObserver extends ContentObserver {
|
||||||
// mAccounts keeps track of Accounts that we care about (EAS for now)
|
// mAccounts keeps track of Accounts that we care about (EAS for now)
|
||||||
AccountList mAccounts = new AccountList();
|
AccountList mAccounts = new AccountList();
|
||||||
String mAccountKeyList = null;
|
String mSyncableEasMailboxSelector = null;
|
||||||
|
String mEasAccountSelector = null;
|
||||||
|
|
||||||
public AccountObserver(Handler handler) {
|
public AccountObserver(Handler handler) {
|
||||||
super(handler);
|
super(handler);
|
||||||
@ -397,12 +399,12 @@ public class SyncManager extends Service implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a String suitable for appending to a where clause that selects for all eas
|
* Returns a String suitable for appending to a where clause that selects for all syncable
|
||||||
* accounts.
|
* mailboxes in all eas accounts
|
||||||
* @return a String in the form "and accountKey in (a, b, c...)"
|
* @return a complex selection string that is not to be cached
|
||||||
*/
|
*/
|
||||||
public String getMailboxWhere() {
|
public String getSyncableEasMailboxWhere() {
|
||||||
if (mAccountKeyList == null) {
|
if (mSyncableEasMailboxSelector == null) {
|
||||||
StringBuilder sb = new StringBuilder(WHERE_NOT_INTERVAL_NEVER_AND_ACCOUNT_KEY_IN);
|
StringBuilder sb = new StringBuilder(WHERE_NOT_INTERVAL_NEVER_AND_ACCOUNT_KEY_IN);
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (Account account: mAccounts) {
|
for (Account account: mAccounts) {
|
||||||
@ -414,9 +416,32 @@ public class SyncManager extends Service implements Runnable {
|
|||||||
sb.append(account.mId);
|
sb.append(account.mId);
|
||||||
}
|
}
|
||||||
sb.append(')');
|
sb.append(')');
|
||||||
mAccountKeyList = sb.toString();
|
mSyncableEasMailboxSelector = sb.toString();
|
||||||
}
|
}
|
||||||
return mAccountKeyList;
|
return mSyncableEasMailboxSelector;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a String suitable for appending to a where clause that selects for all eas
|
||||||
|
* accounts.
|
||||||
|
* @return a String in the form "accountKey in (a, b, c...)" that is not to be cached
|
||||||
|
*/
|
||||||
|
public String getAccountKeyWhere() {
|
||||||
|
if (mEasAccountSelector == null) {
|
||||||
|
StringBuilder sb = new StringBuilder(ACCOUNT_KEY_IN);
|
||||||
|
boolean first = true;
|
||||||
|
for (Account account: mAccounts) {
|
||||||
|
if (!first) {
|
||||||
|
sb.append(',');
|
||||||
|
} else {
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
sb.append(account.mId);
|
||||||
|
}
|
||||||
|
sb.append(')');
|
||||||
|
mEasAccountSelector = sb.toString();
|
||||||
|
}
|
||||||
|
return mEasAccountSelector;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean syncParametersChanged(Account account) {
|
private boolean syncParametersChanged(Account account) {
|
||||||
@ -453,7 +478,8 @@ public class SyncManager extends Service implements Runnable {
|
|||||||
new android.accounts.Account(account.mEmailAddress,
|
new android.accounts.Account(account.mEmailAddress,
|
||||||
Eas.ACCOUNT_MANAGER_TYPE);
|
Eas.ACCOUNT_MANAGER_TYPE);
|
||||||
AccountManager.get(SyncManager.this).removeAccount(acct, null, null);
|
AccountManager.get(SyncManager.this).removeAccount(acct, null, null);
|
||||||
mAccountKeyList = null;
|
mSyncableEasMailboxSelector = null;
|
||||||
|
mEasAccountSelector = null;
|
||||||
} else {
|
} else {
|
||||||
// See whether any of our accounts has changed sync interval or window
|
// See whether any of our accounts has changed sync interval or window
|
||||||
if (syncParametersChanged(account)) {
|
if (syncParametersChanged(account)) {
|
||||||
@ -483,7 +509,8 @@ public class SyncManager extends Service implements Runnable {
|
|||||||
HostAuth.restoreHostAuthWithId(getContext(), account.mHostAuthKeyRecv);
|
HostAuth.restoreHostAuthWithId(getContext(), account.mHostAuthKeyRecv);
|
||||||
account.mHostAuthRecv = ha;
|
account.mHostAuthRecv = ha;
|
||||||
mAccounts.add(account);
|
mAccounts.add(account);
|
||||||
mAccountKeyList = null;
|
mSyncableEasMailboxSelector = null;
|
||||||
|
mEasAccountSelector = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -617,6 +644,14 @@ public class SyncManager extends Service implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public String getEasAccountSelector() {
|
||||||
|
if (INSTANCE != null) {
|
||||||
|
return INSTANCE.mAccountObserver.getAccountKeyWhere();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Account getAccountById(long accountId) {
|
private Account getAccountById(long accountId) {
|
||||||
return mAccountObserver.mAccounts.getById(accountId);
|
return mAccountObserver.mAccounts.getById(accountId);
|
||||||
}
|
}
|
||||||
@ -1421,7 +1456,7 @@ public class SyncManager extends Service implements Runnable {
|
|||||||
// Start up threads that need it; use a query which finds eas mailboxes where the
|
// Start up threads that need it; use a query which finds eas mailboxes where the
|
||||||
// the sync interval is not "never". This is the set of mailboxes that we control
|
// the sync interval is not "never". This is the set of mailboxes that we control
|
||||||
Cursor c = getContentResolver().query(Mailbox.CONTENT_URI, Mailbox.CONTENT_PROJECTION,
|
Cursor c = getContentResolver().query(Mailbox.CONTENT_URI, Mailbox.CONTENT_PROJECTION,
|
||||||
mAccountObserver.getMailboxWhere(), null, null);
|
mAccountObserver.getSyncableEasMailboxWhere(), null, null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while (c.moveToNext()) {
|
while (c.moveToNext()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user