From 850e9fdda99a444fbaf1c0e68e76a472d5484ccd Mon Sep 17 00:00:00 2001 From: Marc Blank Date: Sat, 6 Mar 2010 12:16:37 -0800 Subject: [PATCH] Use watchdog alarms with mailbox syncs * There are cases in which an HTTP POST can hang indefinitely; this will eventually be caught, but it could be a long time until this happens (I've seen hours) * Set a watchdog alarm for all HTTP POSTs (rather than just PING) Bug: 2492860 Change-Id: Ifccbb54c191c4164bb3188e0291490276bce25fb --- src/com/android/exchange/EasSyncService.java | 13 +++++++++---- src/com/android/exchange/SyncManager.java | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/com/android/exchange/EasSyncService.java b/src/com/android/exchange/EasSyncService.java index 004b45131..6c1f039e2 100644 --- a/src/com/android/exchange/EasSyncService.java +++ b/src/com/android/exchange/EasSyncService.java @@ -965,7 +965,7 @@ public class EasSyncService extends AbstractSyncService { protected HttpResponse sendHttpClientPost(String cmd, HttpEntity entity, int timeout) throws IOException { HttpClient client = getHttpClient(timeout); - boolean sleepAllowed = cmd.equals(PING_COMMAND); + boolean isPingCommand = cmd.equals(PING_COMMAND); // Split the mail sending commands String extra = null; @@ -992,16 +992,21 @@ public class EasSyncService extends AbstractSyncService { method.setEntity(entity); synchronized(getSynchronizer()) { mPendingPost = method; - if (sleepAllowed) { - SyncManager.runAsleep(mMailboxId, timeout+(10*SECONDS)); + long alarmTime = timeout+(10*SECONDS); + if (isPingCommand) { + SyncManager.runAsleep(mMailboxId, alarmTime); + } else { + SyncManager.setWatchdogAlarm(mMailboxId, alarmTime); } } try { return client.execute(method); } finally { synchronized(getSynchronizer()) { - if (sleepAllowed) { + if (isPingCommand) { SyncManager.runAwake(mMailboxId); + } else { + SyncManager.clearWatchdogAlarm(mMailboxId); } mPendingPost = null; } diff --git a/src/com/android/exchange/SyncManager.java b/src/com/android/exchange/SyncManager.java index 824a37629..d8d071cba 100644 --- a/src/com/android/exchange/SyncManager.java +++ b/src/com/android/exchange/SyncManager.java @@ -1286,6 +1286,20 @@ public class SyncManager extends Service implements Runnable { } } + static public void clearWatchdogAlarm(long id) { + SyncManager syncManager = INSTANCE; + if (syncManager != null) { + syncManager.clearAlarm(id); + } + } + + static public void setWatchdogAlarm(long id, long millis) { + SyncManager syncManager = INSTANCE; + if (syncManager != null) { + syncManager.setAlarm(id, millis); + } + } + static public void alert(Context context, long id) { SyncManager syncManager = INSTANCE; checkSyncManagerServiceRunning();