diff options
| author | Marc Blank <mblank@google.com> | 2012-08-18 14:03:45 -0700 |
|---|---|---|
| committer | Marc Blank <mblank@google.com> | 2012-08-18 14:03:45 -0700 |
| commit | 9d593aab1b5b4af6df4d9bbc3f4126da4ec2e2a0 (patch) | |
| tree | c05e79f5da175891328b3da626c15d6710308a81 /emailsync | |
| parent | 49f5c000a96c7af2e80ed3369d07c184159753ec (diff) | |
| download | android_packages_apps_Email-9d593aab1b5b4af6df4d9bbc3f4126da4ec2e2a0.tar.gz android_packages_apps_Email-9d593aab1b5b4af6df4d9bbc3f4126da4ec2e2a0.tar.bz2 android_packages_apps_Email-9d593aab1b5b4af6df4d9bbc3f4126da4ec2e2a0.zip | |
Make sure that all access to service map is lock-protected
Bug: 7013731
Change-Id: Ib5e1f2aa92fd448f0a4131393a34d93315bfa649
Diffstat (limited to 'emailsync')
| -rw-r--r-- | emailsync/src/com/android/emailsync/SyncManager.java | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/emailsync/src/com/android/emailsync/SyncManager.java b/emailsync/src/com/android/emailsync/SyncManager.java index b331501bb..965391167 100644 --- a/emailsync/src/com/android/emailsync/SyncManager.java +++ b/emailsync/src/com/android/emailsync/SyncManager.java @@ -1093,7 +1093,7 @@ public abstract class SyncManager extends Service implements Runnable { } else if (ssm == null) { context.startService(new Intent(context, SyncManager.class)); } else { - final AbstractSyncService service = ssm.mServiceMap.get(id); + final AbstractSyncService service = ssm.getRunningService(id); 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 @@ -1680,6 +1680,18 @@ public abstract class SyncManager extends Service implements Runnable { } /** + * Retrieve a running sync service for the passed-in mailbox id in a threadsafe manner + * + * @param mailboxId the id of the mailbox whose service is to be found + * @return the running service (a subclass of AbstractSyncService) or null if none + */ + public AbstractSyncService getRunningService(long mailboxId) { + synchronized(sSyncLock) { + return mServiceMap.get(mailboxId); + } + } + + /** * Check whether an Outbox (referenced by a Cursor) has any messages that can be sent * @param c the cursor to an Outbox * @return true if there is mail to be sent @@ -1865,10 +1877,7 @@ public abstract class SyncManager extends Service implements Runnable { try { while (c.moveToNext()) { long mailboxId = c.getLong(Mailbox.CONTENT_ID_COLUMN); - AbstractSyncService service = null; - synchronized (sSyncLock) { - service = mServiceMap.get(mailboxId); - } + AbstractSyncService service = getRunningService(mailboxId); if (service == null) { // Get the cached account Account account = getAccountById(c.getInt(Mailbox.CONTENT_ACCOUNT_KEY_COLUMN)); @@ -1990,7 +1999,7 @@ public abstract class SyncManager extends Service implements Runnable { Mailbox m = Mailbox.restoreMailboxWithId(ssm, mailboxId); if (m == null || !isSyncable(m)) return; try { - AbstractSyncService service = ssm.mServiceMap.get(mailboxId); + AbstractSyncService service = ssm.getRunningService(mailboxId); if (service != null) { service.mRequestTime = System.currentTimeMillis() + ms; kick("service request"); @@ -2005,7 +2014,7 @@ public abstract class SyncManager extends Service implements Runnable { static public void serviceRequestImmediate(long mailboxId) { SyncManager ssm = INSTANCE; if (ssm == null) return; - AbstractSyncService service = ssm.mServiceMap.get(mailboxId); + AbstractSyncService service = ssm.getRunningService(mailboxId); if (service != null) { service.mRequestTime = System.currentTimeMillis(); Mailbox m = Mailbox.restoreMailboxWithId(ssm, mailboxId); @@ -2047,7 +2056,7 @@ public abstract class SyncManager extends Service implements Runnable { static public void sendRequest(long mailboxId, Request req) { SyncManager ssm = INSTANCE; if (ssm == null) return; - AbstractSyncService service = ssm.mServiceMap.get(mailboxId); + AbstractSyncService service = ssm.getRunningService(mailboxId); if (service == null) { startManualSync(mailboxId, SYNC_SERVICE_PART_REQUEST, req); kick("part request"); @@ -2067,7 +2076,7 @@ public abstract class SyncManager extends Service implements Runnable { SyncManager ssm = INSTANCE; if (ssm == null) return PING_STATUS_OK; // Already syncing... - if (ssm.mServiceMap.get(mailboxId) != null) { + if (ssm.getRunningService(mailboxId) != null) { return PING_STATUS_RUNNING; } // No errors or a transient error, don't ping... @@ -2149,7 +2158,7 @@ public abstract class SyncManager extends Service implements Runnable { } private boolean isRunningInServiceThread(long mailboxId) { - AbstractSyncService syncService = mServiceMap.get(mailboxId); + AbstractSyncService syncService = getRunningService(mailboxId); Thread thisThread = Thread.currentThread(); return syncService != null && syncService.mThread != null && thisThread == syncService.mThread; |
