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