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
This commit is contained in:
Marc Blank 2010-03-06 12:16:37 -08:00
parent 136d3b96bb
commit 850e9fdda9
2 changed files with 23 additions and 4 deletions

View File

@ -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;
}

View File

@ -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();