Merge "Do alert work in background thread"

This commit is contained in:
Marc Blank 2010-03-19 10:19:46 -07:00 committed by Android (Google) Code Review
commit a4049ccbdb

View File

@ -1321,31 +1321,38 @@ public class SyncManager extends Service implements Runnable {
} }
} }
static public void alert(Context context, long id) { static public void alert(Context context, final long id) {
SyncManager syncManager = INSTANCE; final SyncManager syncManager = INSTANCE;
checkSyncManagerServiceRunning(); checkSyncManagerServiceRunning();
if (id < 0) { if (id < 0) {
kick("ping SyncManager"); kick("ping SyncManager");
} else if (syncManager == null) { } else if (syncManager == null) {
context.startService(new Intent(context, SyncManager.class)); context.startService(new Intent(context, SyncManager.class));
} else { } else {
AbstractSyncService service = syncManager.mServiceMap.get(id); final AbstractSyncService service = syncManager.mServiceMap.get(id);
if (service != null) { if (service != null) {
// Handle alerts in a background thread, as we are typically called from a
// broadcast receiver, and are therefore running in the UI thread
new Thread(new Runnable() {
public void run() {
Mailbox m = Mailbox.restoreMailboxWithId(syncManager, id); Mailbox m = Mailbox.restoreMailboxWithId(syncManager, id);
if (m != null) { if (m != null) {
// We ignore drafts completely (doesn't sync). Changes in Outbox are handled // We ignore drafts completely (doesn't sync). Changes in Outbox are
// in the checkMailboxes loop, so we can ignore these pings. // handled in the checkMailboxes loop, so we can ignore these pings.
if (m.mType == Mailbox.TYPE_DRAFTS || m.mType == Mailbox.TYPE_OUTBOX) { if (m.mType == Mailbox.TYPE_DRAFTS || m.mType == Mailbox.TYPE_OUTBOX) {
String[] args = new String[] {Long.toString(m.mId)}; String[] args = new String[] {Long.toString(m.mId)};
ContentResolver resolver = INSTANCE.mResolver; ContentResolver resolver = INSTANCE.mResolver;
resolver.delete(Message.DELETED_CONTENT_URI, WHERE_MAILBOX_KEY, args); resolver.delete(Message.DELETED_CONTENT_URI, WHERE_MAILBOX_KEY,
resolver.delete(Message.UPDATED_CONTENT_URI, WHERE_MAILBOX_KEY, args); args);
resolver.delete(Message.UPDATED_CONTENT_URI, WHERE_MAILBOX_KEY,
args);
return; return;
} }
service.mAccount = Account.restoreAccountWithId(INSTANCE, m.mAccountKey); service.mAccount = Account.restoreAccountWithId(INSTANCE, m.mAccountKey);
service.mMailbox = m; service.mMailbox = m;
service.alarm(); service.alarm();
} }
}}).start();
} }
} }
} }