diff --git a/src/com/android/email/service/AttachmentDownloadService.java b/src/com/android/email/service/AttachmentDownloadService.java index 38a7f224c..550931746 100644 --- a/src/com/android/email/service/AttachmentDownloadService.java +++ b/src/com/android/email/service/AttachmentDownloadService.java @@ -468,16 +468,18 @@ public class AttachmentDownloadService extends Service implements Runnable { .toString(), req.priority != PRIORITY_FOREGROUND); // Lazily initialize our (reusable) pending intent if (mWatchdogPendingIntent == null) { - Intent alarmIntent = new Intent(mContext, Watchdog.class); - mWatchdogPendingIntent = PendingIntent.getBroadcast(mContext, 0, alarmIntent, 0); - mAlarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE); + createWatchdogPendingIntent(mContext); } // Set the alarm mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + WATCHDOG_CHECK_INTERVAL, WATCHDOG_CHECK_INTERVAL, mWatchdogPendingIntent); } - + /*package*/ void createWatchdogPendingIntent(Context context) { + Intent alarmIntent = new Intent(context, Watchdog.class); + mWatchdogPendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0); + mAlarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); + } private void cancelDownload(DownloadRequest req) { mDownloadsInProgress.remove(req.attachmentId); req.inProgress = false; diff --git a/tests/src/com/android/email/service/AttachmentDownloadServiceTests.java b/tests/src/com/android/email/service/AttachmentDownloadServiceTests.java index 5ab6ca5e5..cd9766de4 100644 --- a/tests/src/com/android/email/service/AttachmentDownloadServiceTests.java +++ b/tests/src/com/android/email/service/AttachmentDownloadServiceTests.java @@ -70,11 +70,11 @@ public class AttachmentDownloadServiceTests extends AccountTestCase { // Use the NullEmailService so that the loadAttachment calls become no-ops mService = new AttachmentDownloadService(); mService.mContext = mMockContext; - mService.addServiceIntentForTest(mAccountId, new Intent(mMockContext, + mService.addServiceIntentForTest(mAccountId, new Intent(mContext, NullEmailService.class)); mAccountManagerStub = new AttachmentDownloadService.AccountManagerStub(null); mService.mAccountManagerStub = mAccountManagerStub; - mService.mConnectivityManager = new MockConnectivityManager(getContext(), "mock"); + mService.mConnectivityManager = new MockConnectivityManager(mContext, "mock"); mDownloadSet = mService.mDownloadSet; mMockDirectory = new MockDirectory(mService.mContext.getCacheDir().getAbsolutePath()); @@ -119,6 +119,7 @@ public class AttachmentDownloadServiceTests extends AccountTestCase { // Process the queue; attachment 1 should be marked "in progress", and should be in // the in-progress map + mDownloadSet.createWatchdogPendingIntent(mContext); mDownloadSet.processQueue(); DownloadRequest req = mDownloadSet.findDownloadRequest(att1.mId); assertNotNull(req);