From 1b6623b09265218c360a2a27d94e387d0d70f6b6 Mon Sep 17 00:00:00 2001 From: Marc Blank Date: Mon, 29 Nov 2010 10:21:14 -0800 Subject: [PATCH] Make sure we send callbacks for UI requested syncs * In the case in which a sync was requested during an already-running sync, we weren't passing the request information into the service Bug: 3143544 Change-Id: I098161830844f604e4aa5b9c067491d2777d78c3 --- src/com/android/exchange/EasSyncService.java | 6 ++-- src/com/android/exchange/ExchangeService.java | 28 ++++++++++++------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/com/android/exchange/EasSyncService.java b/src/com/android/exchange/EasSyncService.java index 6a388be97..56a2ec699 100644 --- a/src/com/android/exchange/EasSyncService.java +++ b/src/com/android/exchange/EasSyncService.java @@ -2357,8 +2357,7 @@ public class EasSyncService extends AbstractSyncService { public void run() { if (!setupService()) return; - if (mSyncReason == ExchangeService.SYNC_SERVICE_START_SYNC || - mSyncReason == ExchangeService.SYNC_SERVICE_PART_REQUEST) { + if (mSyncReason >= ExchangeService.SYNC_UI_REQUEST) { try { ExchangeService.callback().syncMailboxStatus(mMailboxId, EmailServiceStatus.IN_PROGRESS, 0); @@ -2441,8 +2440,7 @@ public class EasSyncService extends AbstractSyncService { } // Send a callback if this run was initiated by a service call - if (mSyncReason == ExchangeService.SYNC_SERVICE_START_SYNC || - mSyncReason == ExchangeService.SYNC_SERVICE_PART_REQUEST) { + if (mSyncReason >= ExchangeService.SYNC_UI_REQUEST) { try { ExchangeService.callback().syncMailboxStatus(mMailboxId, status, 0); } catch (RemoteException e1) { diff --git a/src/com/android/exchange/ExchangeService.java b/src/com/android/exchange/ExchangeService.java index 47894a2cd..8450aa001 100644 --- a/src/com/android/exchange/ExchangeService.java +++ b/src/com/android/exchange/ExchangeService.java @@ -134,12 +134,15 @@ public class ExchangeService extends Service implements Runnable { public static final int SYNC_PUSH = 2; // A ping (EAS push signal) was received public static final int SYNC_PING = 3; - // startSync was requested of ExchangeService - public static final int SYNC_SERVICE_START_SYNC = 4; - // A part request (attachment load, for now) was sent to ExchangeService - public static final int SYNC_SERVICE_PART_REQUEST = 5; // Misc. - public static final int SYNC_KICK = 6; + public static final int SYNC_KICK = 4; + + // Requests >= SYNC_UI_REQUEST generate callbacks to the UI + public static final int SYNC_UI_REQUEST = 5; + // startSync was requested of ExchangeService + public static final int SYNC_SERVICE_START_SYNC = SYNC_UI_REQUEST + 0; + // A part request (attachment load, for now) was sent to ExchangeService + public static final int SYNC_SERVICE_PART_REQUEST = SYNC_UI_REQUEST + 1; private static final String WHERE_PUSH_OR_PING_NOT_ACCOUNT_MAILBOX = MailboxColumns.ACCOUNT_KEY + "=? and " + MailboxColumns.TYPE + "!=" + @@ -2273,7 +2276,7 @@ public class ExchangeService extends Service implements Runnable { AbstractSyncService service = exchangeService.mServiceMap.get(mailboxId); if (service == null) { - service = startManualSync(mailboxId, SYNC_SERVICE_PART_REQUEST, req); + startManualSync(mailboxId, SYNC_SERVICE_PART_REQUEST, req); kick("part request"); } else { service.addRequest(req); @@ -2306,20 +2309,25 @@ public class ExchangeService extends Service implements Runnable { return PING_STATUS_OK; } - static public AbstractSyncService startManualSync(long mailboxId, int reason, Request req) { + static public void startManualSync(long mailboxId, int reason, Request req) { ExchangeService exchangeService = INSTANCE; - if (exchangeService == null) return null; + if (exchangeService == null) return; synchronized (sSyncLock) { - if (exchangeService.mServiceMap.get(mailboxId) == null) { + AbstractSyncService svc = exchangeService.mServiceMap.get(mailboxId); + if (svc == null) { exchangeService.mSyncErrorMap.remove(mailboxId); Mailbox m = Mailbox.restoreMailboxWithId(exchangeService, mailboxId); if (m != null) { log("Starting sync for " + m.mDisplayName); exchangeService.requestSync(m, reason, req); } + } else { + // If this is a ui request, set the sync reason for the service + if (svc.mSyncReason >= SYNC_UI_REQUEST) { + svc.mSyncReason = reason; + } } } - return exchangeService.mServiceMap.get(mailboxId); } // DO NOT CALL THIS IN A LOOP ON THE SERVICEMAP