am ecaa9774
: If we\'re stopped, make sure watchdog alarm is also stopped
* commit 'ecaa97741332e506afade647402896993ba64fba': If we're stopped, make sure watchdog alarm is also stopped
This commit is contained in:
commit
f304b9b98d
@ -405,13 +405,22 @@ public class AttachmentDownloadService extends Service implements Runnable {
|
|||||||
return count;
|
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
|
* Watchdog for downloads; we use this in case we are hanging on a download, which might
|
||||||
* have failed silently (the connection dropped, for example)
|
* have failed silently (the connection dropped, for example)
|
||||||
*/
|
*/
|
||||||
private void onWatchdogAlarm() {
|
private void onWatchdogAlarm() {
|
||||||
// If our service instance is gone, just leave...
|
// If our service instance is gone, just leave (but cancel alarm first!)
|
||||||
if (mStop) return;
|
if (mStop) {
|
||||||
|
cancelWatchdogAlarm();
|
||||||
|
return;
|
||||||
|
}
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
for (DownloadRequest req: mDownloadsInProgress.values()) {
|
for (DownloadRequest req: mDownloadsInProgress.values()) {
|
||||||
// Check how long it's been since receiving a callback
|
// 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 there are downloads in progress, reset alarm
|
||||||
if (mDownloadsInProgress.isEmpty()) {
|
if (mDownloadsInProgress.isEmpty()) {
|
||||||
if (mAlarmManager != null && mWatchdogPendingIntent != null) {
|
cancelWatchdogAlarm();
|
||||||
mAlarmManager.cancel(mWatchdogPendingIntent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Check whether we can start new downloads...
|
// Check whether we can start new downloads...
|
||||||
if (mConnectivityManager != null && mConnectivityManager.hasConnectivity()) {
|
if (mConnectivityManager != null && mConnectivityManager.hasConnectivity()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user