FileUploader.java 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. /* ownCloud Android client application
  2. * Copyright (C) 2012 Bartek Przybylski
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  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. package com.owncloud.android.files.services;
  19. import java.io.File;
  20. import java.util.AbstractList;
  21. import java.util.Iterator;
  22. import java.util.Vector;
  23. import java.util.concurrent.ConcurrentHashMap;
  24. import java.util.concurrent.ConcurrentMap;
  25. import com.owncloud.android.authenticator.AccountAuthenticator;
  26. import com.owncloud.android.datamodel.FileDataStorageManager;
  27. import com.owncloud.android.datamodel.OCFile;
  28. import com.owncloud.android.files.InstantUploadBroadcastReceiver;
  29. import com.owncloud.android.operations.ChunkedUploadFileOperation;
  30. import com.owncloud.android.operations.RemoteOperationResult;
  31. import com.owncloud.android.operations.UploadFileOperation;
  32. import com.owncloud.android.ui.activity.FileDetailActivity;
  33. import com.owncloud.android.ui.fragment.FileDetailFragment;
  34. import com.owncloud.android.utils.OwnCloudVersion;
  35. import eu.alefzero.webdav.OnDatatransferProgressListener;
  36. import com.owncloud.android.network.OwnCloudClientUtils;
  37. import android.accounts.Account;
  38. import android.accounts.AccountManager;
  39. import android.app.Notification;
  40. import android.app.NotificationManager;
  41. import android.app.PendingIntent;
  42. import android.app.Service;
  43. import android.content.Intent;
  44. import android.os.Binder;
  45. import android.os.Handler;
  46. import android.os.HandlerThread;
  47. import android.os.IBinder;
  48. import android.os.Looper;
  49. import android.os.Message;
  50. import android.os.Process;
  51. import android.util.Log;
  52. import android.webkit.MimeTypeMap;
  53. import android.widget.RemoteViews;
  54. import com.owncloud.android.R;
  55. import eu.alefzero.webdav.WebdavClient;
  56. public class FileUploader extends Service implements OnDatatransferProgressListener {
  57. public static final String UPLOAD_FINISH_MESSAGE = "UPLOAD_FINISH";
  58. public static final String EXTRA_PARENT_DIR_ID = "PARENT_DIR_ID";
  59. public static final String EXTRA_UPLOAD_RESULT = "RESULT";
  60. public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH";
  61. public static final String EXTRA_FILE_PATH = "FILE_PATH";
  62. public static final String KEY_LOCAL_FILE = "LOCAL_FILE";
  63. public static final String KEY_REMOTE_FILE = "REMOTE_FILE";
  64. public static final String KEY_ACCOUNT = "ACCOUNT";
  65. public static final String KEY_UPLOAD_TYPE = "UPLOAD_TYPE";
  66. public static final String KEY_FORCE_OVERWRITE = "KEY_FORCE_OVERWRITE";
  67. public static final String ACCOUNT_NAME = "ACCOUNT_NAME";
  68. public static final String KEY_MIME_TYPE = "MIME_TYPE";
  69. public static final String KEY_INSTANT_UPLOAD = "INSTANT_UPLOAD";
  70. public static final int UPLOAD_SINGLE_FILE = 0;
  71. public static final int UPLOAD_MULTIPLE_FILES = 1;
  72. private static final String TAG = FileUploader.class.getSimpleName();
  73. private Looper mServiceLooper;
  74. private ServiceHandler mServiceHandler;
  75. private IBinder mBinder;
  76. private WebdavClient mUploadClient = null;
  77. private Account mLastAccount = null;
  78. private FileDataStorageManager mStorageManager;
  79. private ConcurrentMap<String, UploadFileOperation> mPendingUploads = new ConcurrentHashMap<String, UploadFileOperation>();
  80. private UploadFileOperation mCurrentUpload = null;
  81. private NotificationManager mNotificationManager;
  82. private Notification mNotification;
  83. private int mLastPercent;
  84. private RemoteViews mDefaultNotificationContentView;
  85. /**
  86. * Builds a key for mPendingUploads from the account and file to upload
  87. *
  88. * @param account Account where the file to download is stored
  89. * @param file File to download
  90. */
  91. private String buildRemoteName(Account account, OCFile file) {
  92. return account.name + file.getRemotePath();
  93. }
  94. private String buildRemoteName(Account account, String remotePath) {
  95. return account.name + remotePath;
  96. }
  97. /**
  98. * Checks if an ownCloud server version should support chunked uploads.
  99. *
  100. * @param version OwnCloud version instance corresponding to an ownCloud server.
  101. * @return 'True' if the ownCloud server with version supports chunked uploads.
  102. */
  103. private static boolean chunkedUploadIsSupported(OwnCloudVersion version) {
  104. return (version != null && version.compareTo(OwnCloudVersion.owncloud_v4_5) >= 0);
  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("FileUploaderThread",
  114. Process.THREAD_PRIORITY_BACKGROUND);
  115. thread.start();
  116. mServiceLooper = thread.getLooper();
  117. mServiceHandler = new ServiceHandler(mServiceLooper, this);
  118. mBinder = new FileUploaderBinder();
  119. }
  120. /**
  121. * Entry point to add one or several files to the queue of uploads.
  122. *
  123. * New uploads are added calling to startService(), resulting in a call to this method. This ensures the service will keep on working
  124. * although the caller activity goes away.
  125. */
  126. @Override
  127. public int onStartCommand(Intent intent, int flags, int startId) {
  128. if (!intent.hasExtra(KEY_ACCOUNT) || !intent.hasExtra(KEY_UPLOAD_TYPE)) {
  129. Log.e(TAG, "Not enough information provided in intent");
  130. return Service.START_NOT_STICKY;
  131. }
  132. int uploadType = intent.getIntExtra(KEY_UPLOAD_TYPE, -1);
  133. if (uploadType == -1) {
  134. Log.e(TAG, "Incorrect upload type provided");
  135. return Service.START_NOT_STICKY;
  136. }
  137. Account account = intent.getParcelableExtra(KEY_ACCOUNT);
  138. String[] localPaths, remotePaths, mimeTypes;
  139. if (uploadType == UPLOAD_SINGLE_FILE) {
  140. localPaths = new String[] { intent.getStringExtra(KEY_LOCAL_FILE) };
  141. remotePaths = new String[] { intent
  142. .getStringExtra(KEY_REMOTE_FILE) };
  143. mimeTypes = new String[] { intent.getStringExtra(KEY_MIME_TYPE) };
  144. } else { // mUploadType == UPLOAD_MULTIPLE_FILES
  145. localPaths = intent.getStringArrayExtra(KEY_LOCAL_FILE);
  146. remotePaths = intent.getStringArrayExtra(KEY_REMOTE_FILE);
  147. mimeTypes = intent.getStringArrayExtra(KEY_MIME_TYPE);
  148. }
  149. if (localPaths == null) {
  150. Log.e(TAG, "Incorrect array for local paths provided in upload intent");
  151. return Service.START_NOT_STICKY;
  152. }
  153. if (remotePaths == null) {
  154. Log.e(TAG, "Incorrect array for remote paths provided in upload intent");
  155. return Service.START_NOT_STICKY;
  156. }
  157. if (localPaths.length != remotePaths.length) {
  158. Log.e(TAG, "Different number of remote paths and local paths!");
  159. return Service.START_NOT_STICKY;
  160. }
  161. boolean isInstant = intent.getBooleanExtra(KEY_INSTANT_UPLOAD, false);
  162. boolean forceOverwrite = intent.getBooleanExtra(KEY_FORCE_OVERWRITE, false);
  163. OwnCloudVersion ocv = new OwnCloudVersion(AccountManager.get(this).getUserData(account, AccountAuthenticator.KEY_OC_VERSION));
  164. boolean chunked = FileUploader.chunkedUploadIsSupported(ocv);
  165. AbstractList<String> requestedUploads = new Vector<String>();
  166. String uploadKey = null;
  167. UploadFileOperation newUpload = null;
  168. OCFile file = null;
  169. FileDataStorageManager storageManager = new FileDataStorageManager(account, getContentResolver());
  170. boolean fixed = false;
  171. if (isInstant) {
  172. fixed = checkAndFixInstantUploadDirectory(storageManager);
  173. }
  174. try {
  175. for (int i=0; i < localPaths.length; i++) {
  176. uploadKey = buildRemoteName(account, remotePaths[i]);
  177. file = obtainNewOCFileToUpload(remotePaths[i], localPaths[i], ((mimeTypes!=null)?mimeTypes[i]:(String)null), isInstant, forceOverwrite, storageManager);
  178. if (chunked) {
  179. newUpload = new ChunkedUploadFileOperation(account, file, isInstant, forceOverwrite);
  180. } else {
  181. newUpload = new UploadFileOperation(account, file, isInstant, forceOverwrite);
  182. }
  183. if (fixed && i==0) {
  184. newUpload.setRemoteFolderToBeCreated();
  185. }
  186. mPendingUploads.putIfAbsent(uploadKey, newUpload);
  187. newUpload.addDatatransferProgressListener(this);
  188. requestedUploads.add(uploadKey);
  189. }
  190. } catch (IllegalArgumentException e) {
  191. Log.e(TAG, "Not enough information provided in intent: " + e.getMessage());
  192. return START_NOT_STICKY;
  193. } catch (IllegalStateException e) {
  194. Log.e(TAG, "Bad information provided in intent: " + e.getMessage());
  195. return START_NOT_STICKY;
  196. } catch (Exception e) {
  197. Log.e(TAG, "Unexpected exception while processing upload intent", e);
  198. return START_NOT_STICKY;
  199. }
  200. if (requestedUploads.size() > 0) {
  201. Message msg = mServiceHandler.obtainMessage();
  202. msg.arg1 = startId;
  203. msg.obj = requestedUploads;
  204. mServiceHandler.sendMessage(msg);
  205. }
  206. return Service.START_NOT_STICKY;
  207. }
  208. /**
  209. * Provides a binder object that clients can use to perform operations on the queue of uploads, excepting the addition of new files.
  210. *
  211. * Implemented to perform cancellation, pause and resume of existing uploads.
  212. */
  213. @Override
  214. public IBinder onBind(Intent arg0) {
  215. return mBinder;
  216. }
  217. /**
  218. * Binder to let client components to perform operations on the queue of uploads.
  219. *
  220. * It provides by itself the available operations.
  221. */
  222. public class FileUploaderBinder extends Binder {
  223. /**
  224. * Cancels a pending or current upload of a remote file.
  225. *
  226. * @param account Owncloud account where the remote file will be stored.
  227. * @param file A file in the queue of pending uploads
  228. */
  229. public void cancel(Account account, OCFile file) {
  230. UploadFileOperation upload = null;
  231. synchronized (mPendingUploads) {
  232. upload = mPendingUploads.remove(buildRemoteName(account, file));
  233. }
  234. if (upload != null) {
  235. upload.cancel();
  236. }
  237. }
  238. /**
  239. * Returns True when the file described by 'file' is being uploaded to the ownCloud account 'account' or waiting for it
  240. *
  241. * @param account Owncloud account where the remote file will be stored.
  242. * @param file A file that could be in the queue of pending uploads
  243. */
  244. public boolean isUploading(Account account, OCFile file) {
  245. synchronized (mPendingUploads) {
  246. return (mPendingUploads.containsKey(buildRemoteName(account, file)));
  247. }
  248. }
  249. }
  250. /**
  251. * Upload worker. Performs the pending uploads in the order they were requested.
  252. *
  253. * Created with the Looper of a new thread, started in {@link FileUploader#onCreate()}.
  254. */
  255. private static class ServiceHandler extends Handler {
  256. // don't make it a final class, and don't remove the static ; lint will warn about a possible memory leak
  257. FileUploader mService;
  258. public ServiceHandler(Looper looper, FileUploader service) {
  259. super(looper);
  260. if (service == null)
  261. throw new IllegalArgumentException("Received invalid NULL in parameter 'service'");
  262. mService = service;
  263. }
  264. @Override
  265. public void handleMessage(Message msg) {
  266. @SuppressWarnings("unchecked")
  267. AbstractList<String> requestedUploads = (AbstractList<String>) msg.obj;
  268. if (msg.obj != null) {
  269. Iterator<String> it = requestedUploads.iterator();
  270. while (it.hasNext()) {
  271. mService.uploadFile(it.next());
  272. }
  273. }
  274. mService.stopSelf(msg.arg1);
  275. }
  276. }
  277. /**
  278. * Core upload method: sends the file(s) to upload
  279. *
  280. * @param uploadKey Key to access the upload to perform, contained in mPendingUploads
  281. */
  282. public void uploadFile(String uploadKey) {
  283. synchronized(mPendingUploads) {
  284. mCurrentUpload = mPendingUploads.get(uploadKey);
  285. }
  286. if (mCurrentUpload != null) {
  287. notifyUploadStart(mCurrentUpload);
  288. /// prepare client object to send requests to the ownCloud server
  289. if (mUploadClient == null || !mLastAccount.equals(mCurrentUpload.getAccount())) {
  290. mLastAccount = mCurrentUpload.getAccount();
  291. mStorageManager = new FileDataStorageManager(mLastAccount, getContentResolver());
  292. mUploadClient = OwnCloudClientUtils.createOwnCloudClient(mLastAccount, getApplicationContext());
  293. }
  294. /// create remote folder for instant uploads
  295. if (mCurrentUpload.isRemoteFolderToBeCreated()) {
  296. mUploadClient.createDirectory(InstantUploadBroadcastReceiver.INSTANT_UPLOAD_DIR); // ignoring result; fail could just mean that it already exists, but local database is not synchronized; the upload will be tried anyway
  297. }
  298. /// perform the upload
  299. RemoteOperationResult uploadResult = null;
  300. try {
  301. uploadResult = mCurrentUpload.execute(mUploadClient);
  302. if (uploadResult.isSuccess()) {
  303. saveUploadedFile(mCurrentUpload.getFile(), mStorageManager);
  304. }
  305. } finally {
  306. synchronized(mPendingUploads) {
  307. mPendingUploads.remove(uploadKey);
  308. }
  309. }
  310. /// notify result
  311. notifyUploadResult(uploadResult, mCurrentUpload);
  312. sendFinalBroadcast(mCurrentUpload, uploadResult);
  313. }
  314. }
  315. /**
  316. * Saves a new OC File after a successful upload.
  317. *
  318. * @param file OCFile describing the uploaded file
  319. * @param storageManager Interface to the database where the new OCFile has to be stored.
  320. * @param parentDirId Id of the parent OCFile.
  321. */
  322. private void saveUploadedFile(OCFile file, FileDataStorageManager storageManager) {
  323. file.setModificationTimestamp(System.currentTimeMillis());
  324. storageManager.saveFile(file);
  325. }
  326. private boolean checkAndFixInstantUploadDirectory(FileDataStorageManager storageManager) {
  327. OCFile instantUploadDir = storageManager.getFileByPath(InstantUploadBroadcastReceiver.INSTANT_UPLOAD_DIR);
  328. if (instantUploadDir == null) {
  329. // first instant upload in the account, or never account not synchronized after the remote InstantUpload folder was created
  330. OCFile newDir = new OCFile(InstantUploadBroadcastReceiver.INSTANT_UPLOAD_DIR);
  331. newDir.setMimetype("DIR");
  332. newDir.setParentId(storageManager.getFileByPath(OCFile.PATH_SEPARATOR).getFileId());
  333. storageManager.saveFile(newDir);
  334. return true;
  335. }
  336. return false;
  337. }
  338. private OCFile obtainNewOCFileToUpload(String remotePath, String localPath, String mimeType, boolean isInstant, boolean forceOverwrite, FileDataStorageManager storageManager) {
  339. OCFile newFile = new OCFile(remotePath);
  340. newFile.setStoragePath(localPath);
  341. newFile.setLastSyncDate(0);
  342. newFile.setKeepInSync(forceOverwrite);
  343. // size
  344. if (localPath != null && localPath.length() > 0) {
  345. File localFile = new File(localPath);
  346. newFile.setFileLength(localFile.length());
  347. } // don't worry about not assigning size, the problems with localPath are checked when the UploadFileOperation instance is created
  348. // MIME type
  349. if (mimeType == null || mimeType.length() <= 0) {
  350. try {
  351. mimeType = MimeTypeMap.getSingleton()
  352. .getMimeTypeFromExtension(
  353. remotePath.substring(remotePath.lastIndexOf('.') + 1));
  354. } catch (IndexOutOfBoundsException e) {
  355. Log.e(TAG, "Trying to find out MIME type of a file without extension: " + remotePath);
  356. }
  357. }
  358. if (mimeType == null) {
  359. mimeType = "application/octet-stream";
  360. }
  361. newFile.setMimetype(mimeType);
  362. // parent dir
  363. String parentPath = new File(remotePath).getParent();
  364. parentPath = parentPath.endsWith("/")?parentPath:parentPath+"/" ;
  365. OCFile parentDir = storageManager.getFileByPath(parentPath);
  366. if (parentDir == null) {
  367. throw new IllegalStateException("Can not upload a file to a non existing remote location: " + parentPath);
  368. }
  369. long parentDirId = parentDir.getFileId();
  370. newFile.setParentId(parentDirId);
  371. return newFile;
  372. }
  373. /**
  374. * Creates a status notification to show the upload progress
  375. *
  376. * @param upload Upload operation starting.
  377. */
  378. private void notifyUploadStart(UploadFileOperation upload) {
  379. /// create status notification with a progress bar
  380. mLastPercent = 0;
  381. mNotification = new Notification(R.drawable.icon, getString(R.string.uploader_upload_in_progress_ticker), System.currentTimeMillis());
  382. mNotification.flags |= Notification.FLAG_ONGOING_EVENT;
  383. mDefaultNotificationContentView = mNotification.contentView;
  384. mNotification.contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.progressbar_layout);
  385. mNotification.contentView.setProgressBar(R.id.status_progress, 100, 0, false);
  386. mNotification.contentView.setTextViewText(R.id.status_text, String.format(getString(R.string.uploader_upload_in_progress_content), 0, new File(upload.getStoragePath()).getName()));
  387. mNotification.contentView.setImageViewResource(R.id.status_icon, R.drawable.icon);
  388. /// includes a pending intent in the notification showing the details view of the file
  389. Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
  390. showDetailsIntent.putExtra(FileDetailFragment.EXTRA_FILE, upload.getFile());
  391. showDetailsIntent.putExtra(FileDetailFragment.EXTRA_ACCOUNT, upload.getAccount());
  392. showDetailsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  393. mNotification.contentIntent = PendingIntent.getActivity(getApplicationContext(), (int)System.currentTimeMillis(), showDetailsIntent, 0);
  394. mNotificationManager.notify(R.string.uploader_upload_in_progress_ticker, mNotification);
  395. }
  396. /**
  397. * Callback method to update the progress bar in the status notification
  398. */
  399. @Override
  400. public void onTransferProgress(long progressRate, long totalTransferredSoFar, long totalToTransfer, String fileName) {
  401. int percent = (int)(100.0*((double)totalTransferredSoFar)/((double)totalToTransfer));
  402. if (percent != mLastPercent) {
  403. mNotification.contentView.setProgressBar(R.id.status_progress, 100, percent, false);
  404. String text = String.format(getString(R.string.uploader_upload_in_progress_content), percent, fileName);
  405. mNotification.contentView.setTextViewText(R.id.status_text, text);
  406. mNotificationManager.notify(R.string.uploader_upload_in_progress_ticker, mNotification);
  407. }
  408. mLastPercent = percent;
  409. }
  410. /**
  411. * Callback method to update the progress bar in the status notification (old version)
  412. */
  413. @Override
  414. public void onTransferProgress(long progressRate) {
  415. // NOTHING TO DO HERE ANYMORE
  416. }
  417. /**
  418. * Updates the status notification with the result of an upload operation.
  419. *
  420. * @param uploadResult Result of the upload operation.
  421. * @param upload Finished upload operation
  422. */
  423. private void notifyUploadResult(RemoteOperationResult uploadResult, UploadFileOperation upload) {
  424. if (uploadResult.isCancelled()) {
  425. /// cancelled operation -> silent removal of progress notification
  426. mNotificationManager.cancel(R.string.uploader_upload_in_progress_ticker);
  427. } else if (uploadResult.isSuccess()) {
  428. /// success -> silent update of progress notification to success message
  429. mNotification.flags ^= Notification.FLAG_ONGOING_EVENT; // remove the ongoing flag
  430. mNotification.flags |= Notification.FLAG_AUTO_CANCEL;
  431. mNotification.contentView = mDefaultNotificationContentView;
  432. /// includes a pending intent in the notification showing the details view of the file
  433. Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
  434. showDetailsIntent.putExtra(FileDetailFragment.EXTRA_FILE, upload.getFile());
  435. showDetailsIntent.putExtra(FileDetailFragment.EXTRA_ACCOUNT, upload.getAccount());
  436. showDetailsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  437. mNotification.contentIntent = PendingIntent.getActivity(getApplicationContext(), (int)System.currentTimeMillis(), showDetailsIntent, 0);
  438. mNotification.setLatestEventInfo( getApplicationContext(),
  439. getString(R.string.uploader_upload_succeeded_ticker),
  440. String.format(getString(R.string.uploader_upload_succeeded_content_single), (new File(upload.getStoragePath())).getName()),
  441. mNotification.contentIntent);
  442. mNotificationManager.notify(R.string.uploader_upload_in_progress_ticker, mNotification); // NOT AN ERROR; uploader_upload_in_progress_ticker is the target, not a new notification
  443. /* Notification about multiple uploads: pending of update
  444. mNotification.setLatestEventInfo( getApplicationContext(),
  445. getString(R.string.uploader_upload_succeeded_ticker),
  446. String.format(getString(R.string.uploader_upload_succeeded_content_multiple), mSuccessCounter),
  447. mNotification.contentIntent);
  448. */
  449. } else {
  450. /// fail -> explicit failure notification
  451. mNotificationManager.cancel(R.string.uploader_upload_in_progress_ticker);
  452. Notification finalNotification = new Notification(R.drawable.icon, getString(R.string.uploader_upload_failed_ticker), System.currentTimeMillis());
  453. finalNotification.flags |= Notification.FLAG_AUTO_CANCEL;
  454. // TODO put something smart in the contentIntent below
  455. finalNotification.contentIntent = PendingIntent.getActivity(getApplicationContext(), (int)System.currentTimeMillis(), new Intent(), 0);
  456. finalNotification.setLatestEventInfo( getApplicationContext(),
  457. getString(R.string.uploader_upload_failed_ticker),
  458. String.format(getString(R.string.uploader_upload_failed_content_single), (new File(upload.getStoragePath())).getName()),
  459. finalNotification.contentIntent);
  460. mNotificationManager.notify(R.string.uploader_upload_failed_ticker, finalNotification);
  461. /* Notification about multiple uploads failure: pending of update
  462. finalNotification.setLatestEventInfo( getApplicationContext(),
  463. getString(R.string.uploader_upload_failed_ticker),
  464. String.format(getString(R.string.uploader_upload_failed_content_multiple), mSuccessCounter, mTotalFilesToSend),
  465. finalNotification.contentIntent);
  466. } */
  467. }
  468. }
  469. /**
  470. * Sends a broadcast in order to the interested activities can update their view
  471. *
  472. * @param upload Finished upload operation
  473. * @param uploadResult Result of the upload operation
  474. */
  475. private void sendFinalBroadcast(UploadFileOperation upload, RemoteOperationResult uploadResult) {
  476. Intent end = new Intent(UPLOAD_FINISH_MESSAGE);
  477. end.putExtra(EXTRA_REMOTE_PATH, upload.getRemotePath()); // real remote path, after possible automatic renaming
  478. end.putExtra(EXTRA_FILE_PATH, upload.getStoragePath());
  479. end.putExtra(ACCOUNT_NAME, upload.getAccount().name);
  480. end.putExtra(EXTRA_UPLOAD_RESULT, uploadResult.isSuccess());
  481. end.putExtra(EXTRA_PARENT_DIR_ID, upload.getFile().getParentId());
  482. sendBroadcast(end);
  483. }
  484. }