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