- RemoteOperationResult downloadResult = null;
- try {
- /// prepare client object to send the request to the ownCloud server
- if (mCurrentAccount == null || !mCurrentAccount.equals(mCurrentDownload.getAccount())) {
- mCurrentAccount = mCurrentDownload.getAccount();
- mStorageManager = new FileDataStorageManager(
- mCurrentAccount,
- getContentResolver()
- );
- } // else, reuse storage manager from previous operation
-
- // always get client from client manager, to get fresh credentials in case of update
- OwnCloudAccount ocAccount = new OwnCloudAccount(mCurrentAccount, this);
- mDownloadClient = OwnCloudClientManagerFactory.getDefaultSingleton().
- getClientFor(ocAccount, this);
-
-
- /// perform the download
- /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
- "Executing download of " + mCurrentDownload.getRemotePath());*/
- downloadResult = mCurrentDownload.execute(mDownloadClient);
- if (downloadResult.isSuccess()) {
- saveDownloadedFile();
+ notifyDownloadStart(mCurrentDownload);
+
+ RemoteOperationResult downloadResult = null;
+ try {
+ /// prepare client object to send the request to the ownCloud server
+ if (mCurrentAccount == null ||
+ !mCurrentAccount.equals(mCurrentDownload.getAccount())) {
+ mCurrentAccount = mCurrentDownload.getAccount();
+ mStorageManager = new FileDataStorageManager(
+ mCurrentAccount,
+ getContentResolver()
+ );
+ } // else, reuse storage manager from previous operation
+
+ // always get client from client manager, to get fresh credentials in case
+ // of update
+ OwnCloudAccount ocAccount = new OwnCloudAccount(mCurrentAccount, this);
+ mDownloadClient = OwnCloudClientManagerFactory.getDefaultSingleton().
+ getClientFor(ocAccount, this);
+
+
+ /// perform the download
+ downloadResult = mCurrentDownload.execute(mDownloadClient);
+ if (downloadResult.isSuccess()) {
+ saveDownloadedFile();
+ }
+
+ } catch (Exception e) {
+ Log_OC.e(TAG, "Error downloading", e);
+ downloadResult = new RemoteOperationResult(e);
+
+ } finally {
+ Pair<DownloadFileOperation, String> removeResult =
+ mPendingDownloads.removePayload(mCurrentAccount,
+ mCurrentDownload.getRemotePath());
+
+ /// notify result
+ notifyDownloadResult(mCurrentDownload, downloadResult);
+
+ sendBroadcastDownloadFinished(mCurrentDownload, downloadResult, removeResult.second);