From ecaa97741332e506afade647402896993ba64fba Mon Sep 17 00:00:00 2001 From: Marc Blank Date: Wed, 25 Jan 2012 14:59:54 -0800 Subject: [PATCH] If we're stopped, make sure watchdog alarm is also stopped Bug: 5647625 Change-Id: I33e94107f2d6e4a38a5a221df72ed83596ca7c54 --- .../service/AttachmentDownloadService.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/com/android/email/service/AttachmentDownloadService.java b/src/com/android/email/service/AttachmentDownloadService.java index b0db0bb01..18468fbb1 100644 --- a/src/com/android/email/service/AttachmentDownloadService.java +++ b/src/com/android/email/service/AttachmentDownloadService.java @@ -405,13 +405,22 @@ public class AttachmentDownloadService extends Service implements Runnable { return count; } + private void cancelWatchdogAlarm() { + if (mAlarmManager != null && mWatchdogPendingIntent != null) { + mAlarmManager.cancel(mWatchdogPendingIntent); + } + } + /** * Watchdog for downloads; we use this in case we are hanging on a download, which might * have failed silently (the connection dropped, for example) */ private void onWatchdogAlarm() { - // If our service instance is gone, just leave... - if (mStop) return; + // If our service instance is gone, just leave (but cancel alarm first!) + if (mStop) { + cancelWatchdogAlarm(); + return; + } long now = System.currentTimeMillis(); for (DownloadRequest req: mDownloadsInProgress.values()) { // Check how long it's been since receiving a callback @@ -425,9 +434,7 @@ public class AttachmentDownloadService extends Service implements Runnable { } // If there are downloads in progress, reset alarm if (mDownloadsInProgress.isEmpty()) { - if (mAlarmManager != null && mWatchdogPendingIntent != null) { - mAlarmManager.cancel(mWatchdogPendingIntent); - } + cancelWatchdogAlarm(); } // Check whether we can start new downloads... if (mConnectivityManager != null && mConnectivityManager.hasConnectivity()) {