61483af8b63a7a0b21dd4c32ddba901610ef9392
[pub/Android/ownCloud.git] / src / com / owncloud / android / files / services / FileDownloader.java
1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
3 * Copyright (C) 2012-2013 ownCloud Inc.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2,
7 * as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19 package com.owncloud.android.files.services;
20
21 import java.io.File;
22 import java.io.IOException;
23 import java.util.AbstractList;
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.Iterator;
27 import java.util.Map;
28 import java.util.Vector;
29 import java.util.concurrent.ConcurrentHashMap;
30 import java.util.concurrent.ConcurrentMap;
31
32 import com.owncloud.android.R;
33 import com.owncloud.android.authentication.AuthenticatorActivity;
34 import com.owncloud.android.datamodel.FileDataStorageManager;
35 import com.owncloud.android.datamodel.OCFile;
36
37 import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
38 import com.owncloud.android.lib.common.OwnCloudAccount;
39 import com.owncloud.android.lib.common.OwnCloudClient;
40 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
41 import com.owncloud.android.notifications.NotificationBuilderWithProgressBar;
42 import com.owncloud.android.notifications.NotificationDelayer;
43 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
44 import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
45 import com.owncloud.android.lib.common.utils.Log_OC;
46 import com.owncloud.android.lib.resources.files.FileUtils;
47 import com.owncloud.android.operations.DownloadFileOperation;
48 import com.owncloud.android.ui.activity.FileActivity;
49 import com.owncloud.android.ui.activity.FileDisplayActivity;
50 import com.owncloud.android.ui.preview.PreviewImageActivity;
51 import com.owncloud.android.ui.preview.PreviewImageFragment;
52 import com.owncloud.android.utils.ErrorMessageAdapter;
53
54 import android.accounts.Account;
55 import android.accounts.AccountsException;
56 import android.app.NotificationManager;
57 import android.app.PendingIntent;
58 import android.app.Service;
59 import android.content.Intent;
60 import android.os.Binder;
61 import android.os.Handler;
62 import android.os.HandlerThread;
63 import android.os.IBinder;
64 import android.os.Looper;
65 import android.os.Message;
66 import android.os.Process;
67 import android.support.v4.app.NotificationCompat;
68
69 public class FileDownloader extends Service implements OnDatatransferProgressListener {
70
71 public static final String EXTRA_ACCOUNT = "ACCOUNT";
72 public static final String EXTRA_FILE = "FILE";
73
74 public static final String ACTION_CANCEL_FILE_DOWNLOAD = "CANCEL_FILE_DOWNLOAD";
75
76 private static final String DOWNLOAD_ADDED_MESSAGE = "DOWNLOAD_ADDED";
77 private static final String DOWNLOAD_FINISH_MESSAGE = "DOWNLOAD_FINISH";
78 public static final String EXTRA_DOWNLOAD_RESULT = "RESULT";
79 public static final String EXTRA_FILE_PATH = "FILE_PATH";
80 public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH";
81 public static final String ACCOUNT_NAME = "ACCOUNT_NAME";
82
83 private static final String TAG = "FileDownloader";
84
85 private Looper mServiceLooper;
86 private ServiceHandler mServiceHandler;
87 private IBinder mBinder;
88 private OwnCloudClient mDownloadClient = null;
89 private Account mLastAccount = null;
90 private FileDataStorageManager mStorageManager;
91
92 private ConcurrentMap<String, DownloadFileOperation> mPendingDownloads = new ConcurrentHashMap<String, DownloadFileOperation>();
93 private DownloadFileOperation mCurrentDownload = null;
94
95 private NotificationManager mNotificationManager;
96 private NotificationCompat.Builder mNotificationBuilder;
97 private int mLastPercent;
98
99
100 public static String getDownloadAddedMessage() {
101 return FileDownloader.class.getName().toString() + DOWNLOAD_ADDED_MESSAGE;
102 }
103
104 public static String getDownloadFinishMessage() {
105 return FileDownloader.class.getName().toString() + DOWNLOAD_FINISH_MESSAGE;
106 }
107
108 /**
109 * Builds a key for mPendingDownloads from the account and file to download
110 *
111 * @param account Account where the file to download is stored
112 * @param file File to download
113 */
114 private String buildRemoteName(Account account, OCFile file) {
115 return account.name + file.getRemotePath();
116 }
117
118
119 /**
120 * Service initialization
121 */
122 @Override
123 public void onCreate() {
124 super.onCreate();
125 mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
126 HandlerThread thread = new HandlerThread("FileDownloaderThread",
127 Process.THREAD_PRIORITY_BACKGROUND);
128 thread.start();
129 mServiceLooper = thread.getLooper();
130 mServiceHandler = new ServiceHandler(mServiceLooper, this);
131 mBinder = new FileDownloaderBinder();
132 }
133
134 /**
135 * Entry point to add one or several files to the queue of downloads.
136 *
137 * New downloads are added calling to startService(), resulting in a call to this method. This ensures the service will keep on working
138 * although the caller activity goes away.
139 */
140 @Override
141 public int onStartCommand(Intent intent, int flags, int startId) {
142 if ( !intent.hasExtra(EXTRA_ACCOUNT) ||
143 !intent.hasExtra(EXTRA_FILE)
144 /*!intent.hasExtra(EXTRA_FILE_PATH) ||
145 !intent.hasExtra(EXTRA_REMOTE_PATH)*/
146 ) {
147 Log_OC.e(TAG, "Not enough information provided in intent");
148 return START_NOT_STICKY;
149 } else {
150 final Account account = intent.getParcelableExtra(EXTRA_ACCOUNT);
151 final OCFile file = intent.getParcelableExtra(EXTRA_FILE);
152
153 if (ACTION_CANCEL_FILE_DOWNLOAD.equals(intent.getAction())) {
154
155 new Thread(new Runnable() {
156 public void run() {
157 // Cancel the download
158 cancel(account, file);
159 }
160 }).start();
161
162 } else {
163
164 AbstractList<String> requestedDownloads = new Vector<String>(); // dvelasco: now this always contains just one element, but that can change in a near future (download of multiple selection)
165 String downloadKey = buildRemoteName(account, file);
166 try {
167 DownloadFileOperation newDownload = new DownloadFileOperation(account, file);
168 mPendingDownloads.putIfAbsent(downloadKey, newDownload);
169 newDownload.addDatatransferProgressListener(this);
170 newDownload.addDatatransferProgressListener((FileDownloaderBinder) mBinder);
171 requestedDownloads.add(downloadKey);
172
173 // Store file on db with state 'downloading'
174 FileDataStorageManager storageManager = new FileDataStorageManager(account, getContentResolver());
175 file.setDownloading(true);
176 storageManager.saveFile(file);
177
178 sendBroadcastNewDownload(newDownload);
179
180 } catch (IllegalArgumentException e) {
181 Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage());
182 return START_NOT_STICKY;
183 }
184
185 if (requestedDownloads.size() > 0) {
186 Message msg = mServiceHandler.obtainMessage();
187 msg.arg1 = startId;
188 msg.obj = requestedDownloads;
189 mServiceHandler.sendMessage(msg);
190 }
191 }
192 }
193
194 return START_NOT_STICKY;
195 }
196
197
198 /**
199 * Provides a binder object that clients can use to perform operations on the queue of downloads, excepting the addition of new files.
200 *
201 * Implemented to perform cancellation, pause and resume of existing downloads.
202 */
203 @Override
204 public IBinder onBind(Intent arg0) {
205 return mBinder;
206 }
207
208
209 /**
210 * Called when ALL the bound clients were onbound.
211 */
212 @Override
213 public boolean onUnbind(Intent intent) {
214 ((FileDownloaderBinder)mBinder).clearListeners();
215 return false; // not accepting rebinding (default behaviour)
216 }
217
218
219 /**
220 * Binder to let client components to perform operations on the queue of downloads.
221 *
222 * It provides by itself the available operations.
223 */
224 public class FileDownloaderBinder extends Binder implements OnDatatransferProgressListener {
225
226 /**
227 * Map of listeners that will be reported about progress of downloads from a {@link FileDownloaderBinder} instance
228 */
229 private Map<String, OnDatatransferProgressListener> mBoundListeners = new HashMap<String, OnDatatransferProgressListener>();
230
231
232 /**
233 * Cancels a pending or current download of a remote file.
234 *
235 * @param account Owncloud account where the remote file is stored.
236 * @param file A file in the queue of pending downloads
237 */
238 public void cancel(Account account, OCFile file) {
239 DownloadFileOperation download = null;
240 synchronized (mPendingDownloads) {
241 download = mPendingDownloads.remove(buildRemoteName(account, file));
242 }
243 if (download != null) {
244 download.cancel();
245 }
246 }
247
248
249 public void clearListeners() {
250 mBoundListeners.clear();
251 }
252
253
254 /**
255 * Returns True when the file described by 'file' in the ownCloud account 'account' is downloading or waiting to download.
256 *
257 * If 'file' is a directory, returns 'true' if some of its descendant files is downloading or waiting to download.
258 *
259 * @param account Owncloud account where the remote file is stored.
260 * @param file A file that could be in the queue of downloads.
261 */
262 /*
263 public boolean isDownloading(Account account, OCFile file) {
264 if (account == null || file == null) return false;
265 String targetKey = buildRemoteName(account, file);
266 synchronized (mPendingDownloads) {
267 if (file.isFolder()) {
268 // this can be slow if there are many downloads :(
269 Iterator<String> it = mPendingDownloads.keySet().iterator();
270 boolean found = false;
271 while (it.hasNext() && !found) {
272 found = it.next().startsWith(targetKey);
273 }
274 return found;
275 } else {
276 return (mPendingDownloads.containsKey(targetKey));
277 }
278 }
279 }
280 */
281
282
283 /**
284 * Adds a listener interested in the progress of the download for a concrete file.
285 *
286 * @param listener Object to notify about progress of transfer.
287 * @param account ownCloud account holding the file of interest.
288 * @param file {@link OCfile} of interest for listener.
289 */
290 public void addDatatransferProgressListener (OnDatatransferProgressListener listener, Account account, OCFile file) {
291 if (account == null || file == null || listener == null) return;
292 String targetKey = buildRemoteName(account, file);
293 mBoundListeners.put(targetKey, listener);
294 }
295
296
297 /**
298 * Removes a listener interested in the progress of the download for a concrete file.
299 *
300 * @param listener Object to notify about progress of transfer.
301 * @param account ownCloud account holding the file of interest.
302 * @param file {@link OCfile} of interest for listener.
303 */
304 public void removeDatatransferProgressListener (OnDatatransferProgressListener listener, Account account, OCFile file) {
305 if (account == null || file == null || listener == null) return;
306 String targetKey = buildRemoteName(account, file);
307 if (mBoundListeners.get(targetKey) == listener) {
308 mBoundListeners.remove(targetKey);
309 }
310 }
311
312 @Override
313 public void onTransferProgress(long progressRate, long totalTransferredSoFar, long totalToTransfer,
314 String fileName) {
315 String key = buildRemoteName(mCurrentDownload.getAccount(), mCurrentDownload.getFile());
316 OnDatatransferProgressListener boundListener = mBoundListeners.get(key);
317 if (boundListener != null) {
318 boundListener.onTransferProgress(progressRate, totalTransferredSoFar, totalToTransfer, fileName);
319 }
320 }
321
322 }
323
324
325 /**
326 * Download worker. Performs the pending downloads in the order they were requested.
327 *
328 * Created with the Looper of a new thread, started in {@link FileUploader#onCreate()}.
329 */
330 private static class ServiceHandler extends Handler {
331 // don't make it a final class, and don't remove the static ; lint will warn about a possible memory leak
332 FileDownloader mService;
333 public ServiceHandler(Looper looper, FileDownloader service) {
334 super(looper);
335 if (service == null)
336 throw new IllegalArgumentException("Received invalid NULL in parameter 'service'");
337 mService = service;
338 }
339
340 @Override
341 public void handleMessage(Message msg) {
342 @SuppressWarnings("unchecked")
343 AbstractList<String> requestedDownloads = (AbstractList<String>) msg.obj;
344 if (msg.obj != null) {
345 Iterator<String> it = requestedDownloads.iterator();
346 while (it.hasNext()) {
347 mService.downloadFile(it.next());
348 }
349 }
350 mService.stopSelf(msg.arg1);
351 }
352 }
353
354
355 /**
356 * Core download method: requests a file to download and stores it.
357 *
358 * @param downloadKey Key to access the download to perform, contained in mPendingDownloads
359 */
360 private void downloadFile(String downloadKey) {
361
362 synchronized(mPendingDownloads) {
363 mCurrentDownload = mPendingDownloads.get(downloadKey);
364 }
365
366 if (mCurrentDownload != null) {
367
368 notifyDownloadStart(mCurrentDownload);
369
370 RemoteOperationResult downloadResult = null;
371 try {
372 /// prepare client object to send the request to the ownCloud server
373 if (mDownloadClient == null || !mLastAccount.equals(mCurrentDownload.getAccount())) {
374 mLastAccount = mCurrentDownload.getAccount();
375 mStorageManager =
376 new FileDataStorageManager(mLastAccount, getContentResolver());
377 OwnCloudAccount ocAccount = new OwnCloudAccount(mLastAccount, this);
378 mDownloadClient = OwnCloudClientManagerFactory.getDefaultSingleton().
379 getClientFor(ocAccount, this);
380 }
381
382 /// perform the download
383 downloadResult = mCurrentDownload.execute(mDownloadClient);
384 if (downloadResult.isSuccess()) {
385 saveDownloadedFile();
386 } else {
387 updateUnsuccessfulDownloadedFile();
388 }
389
390 } catch (AccountsException e) {
391 Log_OC.e(TAG, "Error while trying to get autorization for " + mLastAccount.name, e);
392 downloadResult = new RemoteOperationResult(e);
393 } catch (IOException e) {
394 Log_OC.e(TAG, "Error while trying to get autorization for " + mLastAccount.name, e);
395 downloadResult = new RemoteOperationResult(e);
396
397 } finally {
398 synchronized(mPendingDownloads) {
399 mPendingDownloads.remove(downloadKey);
400 }
401 }
402
403
404 /// notify result
405 notifyDownloadResult(mCurrentDownload, downloadResult);
406
407 sendBroadcastDownloadFinished(mCurrentDownload, downloadResult);
408 }
409 }
410
411
412 /**
413 * Updates the OC File after a successful download.
414 */
415 private void saveDownloadedFile() {
416 OCFile file = mStorageManager.getFileById(mCurrentDownload.getFile().getFileId());
417 long syncDate = System.currentTimeMillis();
418 file.setLastSyncDateForProperties(syncDate);
419 file.setLastSyncDateForData(syncDate);
420 file.setNeedsUpdateThumbnail(true);
421 file.setModificationTimestamp(mCurrentDownload.getModificationTimestamp());
422 file.setModificationTimestampAtLastSyncForData(mCurrentDownload.getModificationTimestamp());
423 // file.setEtag(mCurrentDownload.getEtag()); // TODO Etag, where available
424 file.setMimetype(mCurrentDownload.getMimeType());
425 file.setStoragePath(mCurrentDownload.getSavePath());
426 file.setFileLength((new File(mCurrentDownload.getSavePath()).length()));
427 file.setRemoteId(mCurrentDownload.getFile().getRemoteId());
428 file.setDownloading(false);
429 mStorageManager.saveFile(file);
430 mStorageManager.triggerMediaScan(file.getStoragePath());
431 }
432
433 /**
434 * Update the OC File after a unsuccessful download
435 */
436 private void updateUnsuccessfulDownloadedFile() {
437 OCFile file = mStorageManager.getFileById(mCurrentDownload.getFile().getFileId());
438 file.setDownloading(false);
439 mStorageManager.saveFile(file);
440 }
441
442
443 /**
444 * Creates a status notification to show the download progress
445 *
446 * @param download Download operation starting.
447 */
448 private void notifyDownloadStart(DownloadFileOperation download) {
449 /// create status notification with a progress bar
450 mLastPercent = 0;
451 mNotificationBuilder =
452 NotificationBuilderWithProgressBar.newNotificationBuilderWithProgressBar(this);
453 mNotificationBuilder
454 .setSmallIcon(R.drawable.notification_icon)
455 .setTicker(getString(R.string.downloader_download_in_progress_ticker))
456 .setContentTitle(getString(R.string.downloader_download_in_progress_ticker))
457 .setOngoing(true)
458 .setProgress(100, 0, download.getSize() < 0)
459 .setContentText(
460 String.format(getString(R.string.downloader_download_in_progress_content), 0,
461 new File(download.getSavePath()).getName())
462 );
463
464 /// includes a pending intent in the notification showing the details view of the file
465 Intent showDetailsIntent = null;
466 if (PreviewImageFragment.canBePreviewed(download.getFile())) {
467 showDetailsIntent = new Intent(this, PreviewImageActivity.class);
468 } else {
469 showDetailsIntent = new Intent(this, FileDisplayActivity.class);
470 }
471 showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, download.getFile());
472 showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, download.getAccount());
473 showDetailsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
474
475 mNotificationBuilder.setContentIntent(PendingIntent.getActivity(
476 this, (int) System.currentTimeMillis(), showDetailsIntent, 0
477 ));
478
479 mNotificationManager.notify(R.string.downloader_download_in_progress_ticker, mNotificationBuilder.build());
480 }
481
482
483 /**
484 * Callback method to update the progress bar in the status notification.
485 */
486 @Override
487 public void onTransferProgress(long progressRate, long totalTransferredSoFar, long totalToTransfer, String filePath) {
488 int percent = (int)(100.0*((double)totalTransferredSoFar)/((double)totalToTransfer));
489 if (percent != mLastPercent) {
490 mNotificationBuilder.setProgress(100, percent, totalToTransfer < 0);
491 String fileName = filePath.substring(filePath.lastIndexOf(FileUtils.PATH_SEPARATOR) + 1);
492 String text = String.format(getString(R.string.downloader_download_in_progress_content), percent, fileName);
493 mNotificationBuilder.setContentText(text);
494 mNotificationManager.notify(R.string.downloader_download_in_progress_ticker, mNotificationBuilder.build());
495 }
496 mLastPercent = percent;
497 }
498
499
500 /**
501 * Updates the status notification with the result of a download operation.
502 *
503 * @param downloadResult Result of the download operation.
504 * @param download Finished download operation
505 */
506 private void notifyDownloadResult(DownloadFileOperation download, RemoteOperationResult downloadResult) {
507 mNotificationManager.cancel(R.string.downloader_download_in_progress_ticker);
508 if (!downloadResult.isCancelled()) {
509 int tickerId = (downloadResult.isSuccess()) ? R.string.downloader_download_succeeded_ticker :
510 R.string.downloader_download_failed_ticker;
511
512 boolean needsToUpdateCredentials = (
513 downloadResult.getCode() == ResultCode.UNAUTHORIZED ||
514 downloadResult.isIdPRedirection()
515 );
516 tickerId = (needsToUpdateCredentials) ?
517 R.string.downloader_download_failed_credentials_error : tickerId;
518
519 mNotificationBuilder
520 .setTicker(getString(tickerId))
521 .setContentTitle(getString(tickerId))
522 .setAutoCancel(true)
523 .setOngoing(false)
524 .setProgress(0, 0, false);
525
526 if (needsToUpdateCredentials) {
527
528 // let the user update credentials with one click
529 Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
530 updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, download.getAccount());
531 updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION, AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN);
532 updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
533 updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
534 updateAccountCredentials.addFlags(Intent.FLAG_FROM_BACKGROUND);
535 mNotificationBuilder
536 .setContentIntent(PendingIntent.getActivity(
537 this, (int) System.currentTimeMillis(), updateAccountCredentials, PendingIntent.FLAG_ONE_SHOT));
538
539 mDownloadClient = null; // grant that future retries on the same account will get the fresh credentials
540
541 } else {
542 // TODO put something smart in showDetailsIntent
543 Intent showDetailsIntent = new Intent();
544 mNotificationBuilder
545 .setContentIntent(PendingIntent.getActivity(
546 this, (int) System.currentTimeMillis(), showDetailsIntent, 0));
547 }
548
549 mNotificationBuilder.setContentText(ErrorMessageAdapter.getErrorCauseMessage(downloadResult, download, getResources()));
550 mNotificationManager.notify(tickerId, mNotificationBuilder.build());
551
552 // Remove success notification
553 if (downloadResult.isSuccess()) {
554 // Sleep 2 seconds, so show the notification before remove it
555 NotificationDelayer.cancelWithDelay(
556 mNotificationManager,
557 R.string.downloader_download_succeeded_ticker,
558 2000);
559 }
560
561 }
562 }
563
564
565 /**
566 * Sends a broadcast when a download finishes in order to the interested activities can update their view
567 *
568 * @param download Finished download operation
569 * @param downloadResult Result of the download operation
570 */
571 private void sendBroadcastDownloadFinished(DownloadFileOperation download, RemoteOperationResult downloadResult) {
572 Intent end = new Intent(getDownloadFinishMessage());
573 end.putExtra(EXTRA_DOWNLOAD_RESULT, downloadResult.isSuccess());
574 end.putExtra(ACCOUNT_NAME, download.getAccount().name);
575 end.putExtra(EXTRA_REMOTE_PATH, download.getRemotePath());
576 end.putExtra(EXTRA_FILE_PATH, download.getSavePath());
577 sendStickyBroadcast(end);
578 }
579
580
581 /**
582 * Sends a broadcast when a new download is added to the queue.
583 *
584 * @param download Added download operation
585 */
586 private void sendBroadcastNewDownload(DownloadFileOperation download) {
587 Intent added = new Intent(getDownloadAddedMessage());
588 added.putExtra(ACCOUNT_NAME, download.getAccount().name);
589 added.putExtra(EXTRA_REMOTE_PATH, download.getRemotePath());
590 added.putExtra(EXTRA_FILE_PATH, download.getSavePath());
591 sendStickyBroadcast(added);
592 }
593
594 /**
595 * Cancel operation
596 * @param account Owncloud account where the remote file is stored.
597 * @param file File OCFile
598 */
599 public void cancel(Account account, OCFile file){
600 DownloadFileOperation download = null;
601 String targetKey = buildRemoteName(account, file);
602 ArrayList<String> keyItems = new ArrayList<String>();
603 synchronized (mPendingDownloads) {
604 if (file.isFolder()) {
605 Log_OC.d(TAG, "Folder download. Canceling pending downloads (from folder)");
606 Iterator<String> it = mPendingDownloads.keySet().iterator();
607 boolean found = false;
608 while (it.hasNext()) {
609 String keyDownloadOperation = it.next();
610 found = keyDownloadOperation.startsWith(targetKey);
611 if (found) {
612 keyItems.add(keyDownloadOperation);
613 }
614 }
615 } else {
616 // this is not really expected...
617 Log_OC.d(TAG, "Canceling file download");
618 keyItems.add(buildRemoteName(account, file));
619 }
620 }
621 for (String item: keyItems) {
622 download = mPendingDownloads.remove(item);
623 Log_OC.d(TAG, "Key removed: " + item);
624
625 if (download != null) {
626 download.cancel();
627 }
628 }
629 }
630 }