FileUploader.java 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  1. /**
  2. * ownCloud Android client application
  3. *
  4. * @author Bartek Przybylski
  5. * @author masensio
  6. * @author LukeOwnCloud
  7. * @author David A. Velasco
  8. *
  9. * Copyright (C) 2012 Bartek Przybylski
  10. * Copyright (C) 2012-2016 ownCloud Inc.
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. package com.owncloud.android.files.services;
  25. import android.accounts.Account;
  26. import android.accounts.AccountManager;
  27. import android.accounts.OnAccountsUpdateListener;
  28. import android.app.NotificationManager;
  29. import android.app.PendingIntent;
  30. import android.app.Service;
  31. import android.content.Context;
  32. import android.content.Intent;
  33. import android.os.Binder;
  34. import android.os.Handler;
  35. import android.os.HandlerThread;
  36. import android.os.IBinder;
  37. import android.os.Looper;
  38. import android.os.Message;
  39. import android.os.Parcelable;
  40. import android.os.Process;
  41. import android.support.v4.app.NotificationCompat;
  42. import android.util.Pair;
  43. import com.owncloud.android.R;
  44. import com.owncloud.android.authentication.AccountUtils;
  45. import com.owncloud.android.authentication.AuthenticatorActivity;
  46. import com.owncloud.android.datamodel.FileDataStorageManager;
  47. import com.owncloud.android.datamodel.OCFile;
  48. import com.owncloud.android.datamodel.ThumbnailsCacheManager;
  49. import com.owncloud.android.datamodel.UploadsStorageManager;
  50. import com.owncloud.android.datamodel.UploadsStorageManager.UploadStatus;
  51. import com.owncloud.android.db.OCUpload;
  52. import com.owncloud.android.db.UploadResult;
  53. import com.owncloud.android.datamodel.ThumbnailsCacheManager;
  54. import com.owncloud.android.lib.common.OwnCloudAccount;
  55. import com.owncloud.android.lib.common.OwnCloudClient;
  56. import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
  57. import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
  58. import com.owncloud.android.lib.common.operations.RemoteOperationResult;
  59. import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
  60. import com.owncloud.android.lib.common.utils.Log_OC;
  61. import com.owncloud.android.lib.resources.files.FileUtils;
  62. import com.owncloud.android.lib.resources.status.OwnCloudVersion;
  63. import com.owncloud.android.ui.notifications.NotificationUtils;
  64. import com.owncloud.android.operations.UploadFileOperation;
  65. import com.owncloud.android.ui.activity.FileActivity;
  66. import com.owncloud.android.ui.activity.UploadListActivity;
  67. import com.owncloud.android.utils.ErrorMessageAdapter;
  68. import java.io.File;
  69. import java.util.AbstractList;
  70. import java.util.HashMap;
  71. import java.util.Iterator;
  72. import java.util.Map;
  73. import java.util.Vector;
  74. /**
  75. * Service for uploading files. Invoke using context.startService(...).
  76. *
  77. * Files to be uploaded are stored persistently using {@link UploadsStorageManager}.
  78. *
  79. * On next invocation of {@link FileUploader} uploaded files which
  80. * previously failed will be uploaded again until either upload succeeded or a
  81. * fatal error occured.
  82. *
  83. * Every file passed to this service is uploaded. No filtering is performed.
  84. * However, Intent keys (e.g., KEY_WIFI_ONLY) are obeyed.
  85. */
  86. public class FileUploader extends Service
  87. implements OnDatatransferProgressListener, OnAccountsUpdateListener, UploadFileOperation.OnRenameListener {
  88. private static final String TAG = FileUploader.class.getSimpleName();
  89. private static final String UPLOADS_ADDED_MESSAGE = "UPLOADS_ADDED";
  90. private static final String UPLOAD_START_MESSAGE = "UPLOAD_START";
  91. private static final String UPLOAD_FINISH_MESSAGE = "UPLOAD_FINISH";
  92. public static final String EXTRA_UPLOAD_RESULT = "RESULT";
  93. public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH";
  94. public static final String EXTRA_OLD_REMOTE_PATH = "OLD_REMOTE_PATH";
  95. public static final String EXTRA_OLD_FILE_PATH = "OLD_FILE_PATH";
  96. public static final String EXTRA_LINKED_TO_PATH = "LINKED_TO";
  97. public static final String ACCOUNT_NAME = "ACCOUNT_NAME";
  98. public static final String KEY_FILE = "FILE";
  99. public static final String KEY_LOCAL_FILE = "LOCAL_FILE";
  100. public static final String KEY_REMOTE_FILE = "REMOTE_FILE";
  101. public static final String KEY_MIME_TYPE = "MIME_TYPE";
  102. /**
  103. * Call this Service with only this Intent key if all pending uploads are to be retried.
  104. */
  105. private static final String KEY_RETRY = "KEY_RETRY";
  106. // /**
  107. // * Call this Service with KEY_RETRY and KEY_RETRY_REMOTE_PATH to retry
  108. // * upload of file identified by KEY_RETRY_REMOTE_PATH.
  109. // */
  110. // private static final String KEY_RETRY_REMOTE_PATH = "KEY_RETRY_REMOTE_PATH";
  111. /**
  112. * Call this Service with KEY_RETRY and KEY_RETRY_UPLOAD to retry
  113. * upload of file identified by KEY_RETRY_UPLOAD.
  114. */
  115. private static final String KEY_RETRY_UPLOAD = "KEY_RETRY_UPLOAD";
  116. /**
  117. * {@link Account} to which file is to be uploaded.
  118. */
  119. public static final String KEY_ACCOUNT = "ACCOUNT";
  120. /**
  121. * Set to true if remote file is to be overwritten. Default action is to upload with different name.
  122. */
  123. public static final String KEY_FORCE_OVERWRITE = "KEY_FORCE_OVERWRITE";
  124. /**
  125. * Set to true if remote folder is to be created if it does not exist.
  126. */
  127. public static final String KEY_CREATE_REMOTE_FOLDER = "CREATE_REMOTE_FOLDER";
  128. /**
  129. * Key to signal what is the origin of the upload request
  130. */
  131. public static final String KEY_CREATED_BY = "CREATED_BY";
  132. /**
  133. * Set to true if upload is to performed only when phone is being charged.
  134. */
  135. public static final String KEY_WHILE_CHARGING_ONLY = "KEY_WHILE_CHARGING_ONLY";
  136. public static final String KEY_LOCAL_BEHAVIOUR = "BEHAVIOUR";
  137. public static final int LOCAL_BEHAVIOUR_COPY = 0;
  138. public static final int LOCAL_BEHAVIOUR_MOVE = 1;
  139. public static final int LOCAL_BEHAVIOUR_FORGET = 2;
  140. private Looper mServiceLooper;
  141. private ServiceHandler mServiceHandler;
  142. private IBinder mBinder;
  143. private OwnCloudClient mUploadClient = null;
  144. private Account mCurrentAccount = null;
  145. private FileDataStorageManager mStorageManager;
  146. //since there can be only one instance of an Android service, there also just one db connection.
  147. private UploadsStorageManager mUploadsStorageManager = null;
  148. private IndexedForest<UploadFileOperation> mPendingUploads = new IndexedForest<UploadFileOperation>();
  149. /**
  150. * {@link UploadFileOperation} object of ongoing upload. Can be null. Note: There can only be one concurrent upload!
  151. */
  152. private UploadFileOperation mCurrentUpload = null;
  153. private NotificationManager mNotificationManager;
  154. private NotificationCompat.Builder mNotificationBuilder;
  155. private int mLastPercent;
  156. public static String getUploadsAddedMessage() {
  157. return FileUploader.class.getName() + UPLOADS_ADDED_MESSAGE;
  158. }
  159. public static String getUploadStartMessage() {
  160. return FileUploader.class.getName() + UPLOAD_START_MESSAGE;
  161. }
  162. public static String getUploadFinishMessage() {
  163. return FileUploader.class.getName() + UPLOAD_FINISH_MESSAGE;
  164. }
  165. @Override
  166. public void onRenameUpload() {
  167. mUploadsStorageManager.updateDatabaseUploadStart(mCurrentUpload);
  168. sendBroadcastUploadStarted(mCurrentUpload);
  169. }
  170. /**
  171. * Helper class providing methods to ease requesting commands to {@link FileUploader} .
  172. *
  173. * Avoids the need of checking once and again what extras are needed or optional
  174. * in the {@link Intent} to pass to {@link Context#startService(Intent)}.
  175. */
  176. public static class UploadRequester {
  177. /**
  178. * Call to upload several new files
  179. */
  180. public void uploadNewFile(
  181. Context context,
  182. Account account,
  183. String[] localPaths,
  184. String[] remotePaths,
  185. String[] mimeTypes,
  186. Integer behaviour,
  187. Boolean createRemoteFolder,
  188. int createdBy
  189. ) {
  190. Intent intent = new Intent(context, FileUploader.class);
  191. intent.putExtra(FileUploader.KEY_ACCOUNT, account);
  192. intent.putExtra(FileUploader.KEY_LOCAL_FILE, localPaths);
  193. intent.putExtra(FileUploader.KEY_REMOTE_FILE, remotePaths);
  194. intent.putExtra(FileUploader.KEY_MIME_TYPE, mimeTypes);
  195. intent.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, behaviour);
  196. intent.putExtra(FileUploader.KEY_CREATE_REMOTE_FOLDER, createRemoteFolder);
  197. intent.putExtra(FileUploader.KEY_CREATED_BY, createdBy);
  198. context.startService(intent);
  199. }
  200. /**
  201. * Call to upload a new single file
  202. */
  203. public void uploadNewFile(Context context, Account account, String localPath, String remotePath, int
  204. behaviour, String mimeType, boolean createRemoteFile, int createdBy) {
  205. uploadNewFile(
  206. context,
  207. account,
  208. new String[]{localPath},
  209. new String[]{remotePath},
  210. new String[]{mimeType},
  211. behaviour,
  212. createRemoteFile,
  213. createdBy
  214. );
  215. }
  216. /**
  217. * Call to update multiple files already uploaded
  218. */
  219. public void uploadUpdate(Context context, Account account, OCFile[] existingFiles, Integer behaviour,
  220. Boolean forceOverwrite) {
  221. Intent intent = new Intent(context, FileUploader.class);
  222. intent.putExtra(FileUploader.KEY_ACCOUNT, account);
  223. intent.putExtra(FileUploader.KEY_FILE, existingFiles);
  224. intent.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, behaviour);
  225. intent.putExtra(FileUploader.KEY_FORCE_OVERWRITE, forceOverwrite);
  226. context.startService(intent);
  227. }
  228. /**
  229. * Call to update a dingle file already uploaded
  230. */
  231. public void uploadUpdate(Context context, Account account, OCFile existingFile, Integer behaviour,
  232. Boolean forceOverwrite) {
  233. uploadUpdate(context, account, new OCFile[]{existingFile}, behaviour, forceOverwrite);
  234. }
  235. /**
  236. * Call to retry upload identified by remotePath
  237. */
  238. public void retry (Context context, OCUpload upload) {
  239. if (upload != null && context != null) {
  240. Account account = AccountUtils.getOwnCloudAccountByName(
  241. context,
  242. upload.getAccountName()
  243. );
  244. retry(context, account, upload);
  245. } else {
  246. throw new IllegalArgumentException("Null parameter!");
  247. }
  248. }
  249. /**
  250. * Retry a subset of all the stored failed uploads.
  251. *
  252. * @param context Caller {@link Context}
  253. * @param account If not null, only failed uploads to this OC account will be retried; otherwise,
  254. * uploads of all accounts will be retried.
  255. * @param uploadResult If not null, only failed uploads with the result specified will be retried;
  256. * otherwise, failed uploads due to any result will be retried.
  257. */
  258. public void retryFailedUploads(Context context, Account account, UploadResult uploadResult) {
  259. UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(context.getContentResolver());
  260. OCUpload[] failedUploads = uploadsStorageManager.getFailedUploads();
  261. Account currentAccount = null;
  262. boolean resultMatch, accountMatch;
  263. for ( OCUpload failedUpload: failedUploads) {
  264. accountMatch = (account == null || account.name.equals(failedUpload.getAccountName()));
  265. resultMatch = (uploadResult == null || uploadResult.equals(failedUpload.getLastResult()));
  266. if (accountMatch && resultMatch) {
  267. if (currentAccount == null ||
  268. !currentAccount.name.equals(failedUpload.getAccountName())) {
  269. currentAccount = failedUpload.getAccount(context);
  270. }
  271. retry(context, currentAccount, failedUpload);
  272. }
  273. }
  274. }
  275. /**
  276. * Private implementation of retry.
  277. *
  278. * @param context
  279. * @param account
  280. * @param upload
  281. */
  282. private void retry(Context context, Account account, OCUpload upload) {
  283. if (upload != null) {
  284. Intent i = new Intent(context, FileUploader.class);
  285. i.putExtra(FileUploader.KEY_RETRY, true);
  286. i.putExtra(FileUploader.KEY_ACCOUNT, account);
  287. i.putExtra(FileUploader.KEY_RETRY_UPLOAD, upload);
  288. context.startService(i);
  289. }
  290. }
  291. }
  292. /**
  293. * Service initialization
  294. */
  295. @Override
  296. public void onCreate() {
  297. super.onCreate();
  298. Log_OC.d(TAG, "Creating service");
  299. mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
  300. HandlerThread thread = new HandlerThread("FileUploaderThread",
  301. Process.THREAD_PRIORITY_BACKGROUND);
  302. thread.start();
  303. mServiceLooper = thread.getLooper();
  304. mServiceHandler = new ServiceHandler(mServiceLooper, this);
  305. mBinder = new FileUploaderBinder();
  306. mUploadsStorageManager = new UploadsStorageManager(getContentResolver());
  307. int failedCounter = mUploadsStorageManager.failInProgressUploads(
  308. UploadResult.SERVICE_INTERRUPTED // Add UploadResult.KILLED?
  309. );
  310. if (failedCounter > 0) {
  311. resurrection();
  312. }
  313. // add AccountsUpdatedListener
  314. AccountManager am = AccountManager.get(getApplicationContext());
  315. am.addOnAccountsUpdatedListener(this, null, false);
  316. }
  317. /**
  318. * Service clean-up when restarted after being killed
  319. */
  320. private void resurrection() {
  321. // remove stucked notification
  322. mNotificationManager.cancel(R.string.uploader_upload_in_progress_ticker);
  323. }
  324. /**
  325. * Service clean up
  326. */
  327. @Override
  328. public void onDestroy() {
  329. Log_OC.v(TAG, "Destroying service");
  330. mBinder = null;
  331. mServiceHandler = null;
  332. mServiceLooper.quit();
  333. mServiceLooper = null;
  334. mNotificationManager = null;
  335. // remove AccountsUpdatedListener
  336. AccountManager am = AccountManager.get(getApplicationContext());
  337. am.removeOnAccountsUpdatedListener(this);
  338. super.onDestroy();
  339. }
  340. /**
  341. * Entry point to add one or several files to the queue of uploads.
  342. *
  343. * New uploads are added calling to startService(), resulting in a call to
  344. * this method. This ensures the service will keep on working although the
  345. * caller activity goes away.
  346. */
  347. @Override
  348. public int onStartCommand(Intent intent, int flags, int startId) {
  349. Log_OC.d(TAG, "Starting command with id " + startId);
  350. boolean retry = intent.getBooleanExtra(KEY_RETRY, false);
  351. AbstractList<String> requestedUploads = new Vector<String>();
  352. if (!intent.hasExtra(KEY_ACCOUNT)) {
  353. Log_OC.e(TAG, "Not enough information provided in intent");
  354. return Service.START_NOT_STICKY;
  355. }
  356. Account account = intent.getParcelableExtra(KEY_ACCOUNT);
  357. if (!AccountUtils.exists(account, getApplicationContext())) {
  358. return Service.START_NOT_STICKY;
  359. }
  360. OwnCloudVersion ocv = AccountUtils.getServerVersion(account);
  361. boolean chunked = ocv.isChunkedUploadSupported();
  362. if (!retry) {
  363. if (!(intent.hasExtra(KEY_LOCAL_FILE) ||
  364. intent.hasExtra(KEY_FILE))) {
  365. Log_OC.e(TAG, "Not enough information provided in intent");
  366. return Service.START_NOT_STICKY;
  367. }
  368. String[] localPaths = null, remotePaths = null, mimeTypes = null;
  369. OCFile[] files = null;
  370. if (intent.hasExtra(KEY_FILE)) {
  371. Parcelable[] files_temp = intent.getParcelableArrayExtra(KEY_FILE);
  372. files = new OCFile[files_temp.length];
  373. System.arraycopy(files_temp, 0, files, 0, files_temp.length);
  374. } else {
  375. localPaths = intent.getStringArrayExtra(KEY_LOCAL_FILE);
  376. remotePaths = intent.getStringArrayExtra(KEY_REMOTE_FILE);
  377. mimeTypes = intent.getStringArrayExtra(KEY_MIME_TYPE);
  378. }
  379. boolean forceOverwrite = intent.getBooleanExtra(KEY_FORCE_OVERWRITE, false);
  380. int localAction = intent.getIntExtra(KEY_LOCAL_BEHAVIOUR, LOCAL_BEHAVIOUR_FORGET);
  381. boolean isCreateRemoteFolder = intent.getBooleanExtra(KEY_CREATE_REMOTE_FOLDER, false);
  382. int createdBy = intent.getIntExtra(KEY_CREATED_BY, UploadFileOperation.CREATED_BY_USER);
  383. if (intent.hasExtra(KEY_FILE) && files == null) {
  384. Log_OC.e(TAG, "Incorrect array for OCFiles provided in upload intent");
  385. return Service.START_NOT_STICKY;
  386. } else if (!intent.hasExtra(KEY_FILE)) {
  387. if (localPaths == null) {
  388. Log_OC.e(TAG, "Incorrect array for local paths provided in upload intent");
  389. return Service.START_NOT_STICKY;
  390. }
  391. if (remotePaths == null) {
  392. Log_OC.e(TAG, "Incorrect array for remote paths provided in upload intent");
  393. return Service.START_NOT_STICKY;
  394. }
  395. if (localPaths.length != remotePaths.length) {
  396. Log_OC.e(TAG, "Different number of remote paths and local paths!");
  397. return Service.START_NOT_STICKY;
  398. }
  399. files = new OCFile[localPaths.length];
  400. for (int i = 0; i < localPaths.length; i++) {
  401. files[i] = UploadFileOperation.obtainNewOCFileToUpload(
  402. remotePaths[i],
  403. localPaths[i],
  404. ((mimeTypes != null) ? mimeTypes[i] : null)
  405. );
  406. if (files[i] == null) {
  407. Log_OC.e(TAG, "obtainNewOCFileToUpload() returned null for remotePaths[i]:" + remotePaths[i]
  408. + " and localPaths[i]:" + localPaths[i]);
  409. return Service.START_NOT_STICKY;
  410. }
  411. }
  412. }
  413. // at this point variable "OCFile[] files" is loaded correctly.
  414. String uploadKey = null;
  415. UploadFileOperation newUpload = null;
  416. try {
  417. for (int i = 0; i < files.length; i++) {
  418. OCUpload ocUpload = new OCUpload(files[i], account);
  419. ocUpload.setFileSize(files[i].getFileLength());
  420. ocUpload.setForceOverwrite(forceOverwrite);
  421. ocUpload.setCreateRemoteFolder(isCreateRemoteFolder);
  422. ocUpload.setCreatedBy(createdBy);
  423. ocUpload.setLocalAction(localAction);
  424. /*ocUpload.setUseWifiOnly(isUseWifiOnly);
  425. ocUpload.setWhileChargingOnly(isWhileChargingOnly);*/
  426. ocUpload.setUploadStatus(UploadStatus.UPLOAD_IN_PROGRESS);
  427. newUpload = new UploadFileOperation(
  428. account,
  429. files[i],
  430. ocUpload,
  431. chunked,
  432. forceOverwrite,
  433. localAction,
  434. this
  435. );
  436. newUpload.setCreatedBy(createdBy);
  437. if (isCreateRemoteFolder) {
  438. newUpload.setRemoteFolderToBeCreated();
  439. }
  440. newUpload.addDatatransferProgressListener(this);
  441. newUpload.addDatatransferProgressListener((FileUploaderBinder) mBinder);
  442. newUpload.addRenameUploadListener(this);
  443. Pair<String, String> putResult = mPendingUploads.putIfAbsent(
  444. account.name,
  445. files[i].getRemotePath(),
  446. newUpload
  447. );
  448. if (putResult != null) {
  449. uploadKey = putResult.first;
  450. requestedUploads.add(uploadKey);
  451. // Save upload in database
  452. long id = mUploadsStorageManager.storeUpload(ocUpload);
  453. newUpload.setOCUploadId(id);
  454. }
  455. }
  456. } catch (IllegalArgumentException e) {
  457. Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage());
  458. return START_NOT_STICKY;
  459. } catch (IllegalStateException e) {
  460. Log_OC.e(TAG, "Bad information provided in intent: " + e.getMessage());
  461. return START_NOT_STICKY;
  462. } catch (Exception e) {
  463. Log_OC.e(TAG, "Unexpected exception while processing upload intent", e);
  464. return START_NOT_STICKY;
  465. }
  466. // *** TODO REWRITE: block inserted to request A retry; too many code copied, no control exception ***/
  467. } else {
  468. if (!intent.hasExtra(KEY_ACCOUNT) || !intent.hasExtra(KEY_RETRY_UPLOAD)) {
  469. Log_OC.e(TAG, "Not enough information provided in intent: no KEY_RETRY_UPLOAD_KEY");
  470. return START_NOT_STICKY;
  471. }
  472. OCUpload upload = intent.getParcelableExtra(KEY_RETRY_UPLOAD);
  473. UploadFileOperation newUpload = new UploadFileOperation(
  474. account,
  475. null,
  476. upload,
  477. chunked,
  478. upload.isForceOverwrite(), // TODO should be read from DB?
  479. upload.getLocalAction(), // TODO should be read from DB?
  480. this
  481. );
  482. newUpload.addDatatransferProgressListener(this);
  483. newUpload.addDatatransferProgressListener((FileUploaderBinder) mBinder);
  484. newUpload.addRenameUploadListener(this);
  485. Pair<String, String> putResult = mPendingUploads.putIfAbsent(
  486. account.name,
  487. upload.getRemotePath(),
  488. newUpload
  489. );
  490. if (putResult != null) {
  491. String uploadKey = putResult.first;
  492. requestedUploads.add(uploadKey);
  493. // Update upload in database
  494. upload.setUploadStatus(UploadStatus.UPLOAD_IN_PROGRESS);
  495. mUploadsStorageManager.updateUpload(upload);
  496. }
  497. }
  498. // *** TODO REWRITE END ***/
  499. if (requestedUploads.size() > 0) {
  500. Message msg = mServiceHandler.obtainMessage();
  501. msg.arg1 = startId;
  502. msg.obj = requestedUploads;
  503. mServiceHandler.sendMessage(msg);
  504. sendBroadcastUploadsAdded();
  505. }
  506. return Service.START_NOT_STICKY;
  507. }
  508. /**
  509. * Provides a binder object that clients can use to perform operations on
  510. * the queue of uploads, excepting the addition of new files.
  511. *
  512. * Implemented to perform cancellation, pause and resume of existing
  513. * uploads.
  514. */
  515. @Override
  516. public IBinder onBind(Intent arg0) {
  517. return mBinder;
  518. }
  519. /**
  520. * Called when ALL the bound clients were onbound.
  521. */
  522. @Override
  523. public boolean onUnbind(Intent intent) {
  524. ((FileUploaderBinder) mBinder).clearListeners();
  525. return false; // not accepting rebinding (default behaviour)
  526. }
  527. @Override
  528. public void onAccountsUpdated(Account[] accounts) {
  529. // Review current upload, and cancel it if its account doen't exist
  530. if (mCurrentUpload != null &&
  531. !AccountUtils.exists(mCurrentUpload.getAccount(), getApplicationContext())) {
  532. mCurrentUpload.cancel();
  533. }
  534. // The rest of uploads are cancelled when they try to start
  535. }
  536. /**
  537. * Binder to let client components to perform operations on the queue of
  538. * uploads.
  539. * <p/>
  540. * It provides by itself the available operations.
  541. */
  542. public class FileUploaderBinder extends Binder implements OnDatatransferProgressListener {
  543. /**
  544. * Map of listeners that will be reported about progress of uploads from a
  545. * {@link FileUploaderBinder} instance
  546. */
  547. private Map<String, OnDatatransferProgressListener> mBoundListeners =
  548. new HashMap<String, OnDatatransferProgressListener>();
  549. /**
  550. * Cancels a pending or current upload of a remote file.
  551. *
  552. * @param account ownCloud account where the remote file will be stored.
  553. * @param file A file in the queue of pending uploads
  554. */
  555. public void cancel(Account account, OCFile file) {
  556. cancel(account.name, file.getRemotePath());
  557. }
  558. /**
  559. * Cancels a pending or current upload that was persisted.
  560. *
  561. * @param storedUpload Upload operation persisted
  562. */
  563. public void cancel(OCUpload storedUpload) {
  564. cancel(storedUpload.getAccountName(), storedUpload.getRemotePath());
  565. }
  566. /**
  567. * Cancels a pending or current upload of a remote file.
  568. *
  569. * @param accountName Local name of an ownCloud account where the remote file will be stored.
  570. * @param remotePath Remote target of the upload
  571. */
  572. private void cancel(String accountName, String remotePath) {
  573. Pair<UploadFileOperation, String> removeResult =
  574. mPendingUploads.remove(accountName, remotePath);
  575. UploadFileOperation upload = removeResult.first;
  576. if (upload == null &&
  577. mCurrentUpload != null && mCurrentAccount != null &&
  578. mCurrentUpload.getRemotePath().startsWith(remotePath) &&
  579. accountName.equals(mCurrentAccount.name)) {
  580. upload = mCurrentUpload;
  581. }
  582. if (upload != null) {
  583. boolean pending = !upload.isUploadInProgress();
  584. upload.cancel();
  585. // need to update now table in mUploadsStorageManager,
  586. // since the operation will not get to be run by FileUploader#uploadFile
  587. mUploadsStorageManager.removeUpload(
  588. accountName,
  589. remotePath
  590. );
  591. }
  592. }
  593. /**
  594. * Cancels all the uploads for an account
  595. *
  596. * @param account ownCloud account.
  597. */
  598. public void cancel(Account account) {
  599. Log_OC.d(TAG, "Account= " + account.name);
  600. if (mCurrentUpload != null) {
  601. Log_OC.d(TAG, "Current Upload Account= " + mCurrentUpload.getAccount().name);
  602. if (mCurrentUpload.getAccount().name.equals(account.name)) {
  603. mCurrentUpload.cancel();
  604. }
  605. }
  606. // Cancel pending uploads
  607. cancelUploadsForAccount(account);
  608. }
  609. public void clearListeners() {
  610. mBoundListeners.clear();
  611. }
  612. /**
  613. * Returns True when the file described by 'file' is being uploaded to
  614. * the ownCloud account 'account' or waiting for it
  615. *
  616. * If 'file' is a directory, returns 'true' if some of its descendant files
  617. * is uploading or waiting to upload.
  618. *
  619. * Warning: If remote file exists and !forceOverwrite the original file
  620. * is being returned here. That is, it seems as if the original file is
  621. * being updated when actually a new file is being uploaded.
  622. *
  623. * @param account Owncloud account where the remote file will be stored.
  624. * @param file A file that could be in the queue of pending uploads
  625. */
  626. public boolean isUploading(Account account, OCFile file) {
  627. if (account == null || file == null)
  628. return false;
  629. return (mPendingUploads.contains(account.name, file.getRemotePath()));
  630. }
  631. public boolean isUploadingNow(OCUpload upload) {
  632. return (
  633. upload != null &&
  634. mCurrentAccount != null &&
  635. mCurrentUpload != null &&
  636. upload.getAccountName().equals(mCurrentAccount.name) &&
  637. upload.getRemotePath().equals(mCurrentUpload.getRemotePath())
  638. );
  639. }
  640. /**
  641. * Adds a listener interested in the progress of the upload for a concrete file.
  642. *
  643. * @param listener Object to notify about progress of transfer.
  644. * @param account ownCloud account holding the file of interest.
  645. * @param file {@link OCFile} of interest for listener.
  646. */
  647. public void addDatatransferProgressListener(
  648. OnDatatransferProgressListener listener,
  649. Account account,
  650. OCFile file
  651. ) {
  652. if (account == null || file == null || listener == null) return;
  653. String targetKey = buildRemoteName(account.name, file.getRemotePath());
  654. mBoundListeners.put(targetKey, listener);
  655. }
  656. /**
  657. * Adds a listener interested in the progress of the upload for a concrete file.
  658. *
  659. * @param listener Object to notify about progress of transfer.
  660. * @param ocUpload {@link OCUpload} of interest for listener.
  661. */
  662. public void addDatatransferProgressListener(
  663. OnDatatransferProgressListener listener,
  664. OCUpload ocUpload
  665. ) {
  666. if (ocUpload == null || listener == null) return;
  667. String targetKey = buildRemoteName(ocUpload.getAccountName(), ocUpload.getRemotePath());
  668. mBoundListeners.put(targetKey, listener);
  669. }
  670. /**
  671. * Removes a listener interested in the progress of the upload for a concrete file.
  672. *
  673. * @param listener Object to notify about progress of transfer.
  674. * @param account ownCloud account holding the file of interest.
  675. * @param file {@link OCFile} of interest for listener.
  676. */
  677. public void removeDatatransferProgressListener(
  678. OnDatatransferProgressListener listener,
  679. Account account,
  680. OCFile file
  681. ) {
  682. if (account == null || file == null || listener == null) return;
  683. String targetKey = buildRemoteName(account.name, file.getRemotePath());
  684. if (mBoundListeners.get(targetKey) == listener) {
  685. mBoundListeners.remove(targetKey);
  686. }
  687. }
  688. /**
  689. * Removes a listener interested in the progress of the upload for a concrete file.
  690. *
  691. * @param listener Object to notify about progress of transfer.
  692. * @param ocUpload Stored upload of interest
  693. */
  694. public void removeDatatransferProgressListener(
  695. OnDatatransferProgressListener listener,
  696. OCUpload ocUpload
  697. ) {
  698. if (ocUpload == null || listener == null) return;
  699. String targetKey = buildRemoteName(ocUpload.getAccountName(), ocUpload.getRemotePath());
  700. if (mBoundListeners.get(targetKey) == listener) {
  701. mBoundListeners.remove(targetKey);
  702. }
  703. }
  704. @Override
  705. public void onTransferProgress(long progressRate, long totalTransferredSoFar,
  706. long totalToTransfer, String fileName) {
  707. String key = buildRemoteName(mCurrentUpload.getAccount().name, mCurrentUpload.getFile().getRemotePath());
  708. OnDatatransferProgressListener boundListener = mBoundListeners.get(key);
  709. if (boundListener != null) {
  710. boundListener.onTransferProgress(progressRate, totalTransferredSoFar,
  711. totalToTransfer, fileName);
  712. }
  713. }
  714. /**
  715. * Builds a key for the map of listeners.
  716. * <p/>
  717. * TODO use method in IndexedForest, or refactor both to a common place
  718. * add to local database) to better policy (add to local database, then upload)
  719. *
  720. * @param accountName Local name of the ownCloud account where the file to upload belongs.
  721. * @param remotePath Remote path to upload the file to.
  722. * @return Key
  723. */
  724. private String buildRemoteName(String accountName, String remotePath) {
  725. return accountName + remotePath;
  726. }
  727. }
  728. /**
  729. * Upload worker. Performs the pending uploads in the order they were
  730. * requested.
  731. * <p/>
  732. * Created with the Looper of a new thread, started in
  733. * {@link FileUploader#onCreate()}.
  734. */
  735. private static class ServiceHandler extends Handler {
  736. // don't make it a final class, and don't remove the static ; lint will
  737. // warn about a possible memory leak
  738. FileUploader mService;
  739. public ServiceHandler(Looper looper, FileUploader service) {
  740. super(looper);
  741. if (service == null)
  742. throw new IllegalArgumentException("Received invalid NULL in parameter 'service'");
  743. mService = service;
  744. }
  745. @Override
  746. public void handleMessage(Message msg) {
  747. @SuppressWarnings("unchecked")
  748. AbstractList<String> requestedUploads = (AbstractList<String>) msg.obj;
  749. if (msg.obj != null) {
  750. Iterator<String> it = requestedUploads.iterator();
  751. while (it.hasNext()) {
  752. mService.uploadFile(it.next());
  753. }
  754. }
  755. Log_OC.d(TAG, "Stopping command after id " + msg.arg1);
  756. mService.stopSelf(msg.arg1);
  757. }
  758. }
  759. /**
  760. * Core upload method: sends the file(s) to upload
  761. *
  762. * @param uploadKey Key to access the upload to perform, contained in mPendingUploads
  763. */
  764. public void uploadFile(String uploadKey) {
  765. mCurrentUpload = mPendingUploads.get(uploadKey);
  766. if (mCurrentUpload != null) {
  767. /// Check account existence
  768. if (!AccountUtils.exists(mCurrentUpload.getAccount(), this)) {
  769. Log_OC.w(TAG, "Account " + mCurrentUpload.getAccount().name +
  770. " does not exist anymore -> cancelling all its uploads");
  771. cancelUploadsForAccount(mCurrentUpload.getAccount());
  772. return;
  773. }
  774. /// OK, let's upload
  775. mUploadsStorageManager.updateDatabaseUploadStart(mCurrentUpload);
  776. notifyUploadStart(mCurrentUpload);
  777. sendBroadcastUploadStarted(mCurrentUpload);
  778. RemoteOperationResult uploadResult = null;
  779. try {
  780. /// prepare client object to send the request to the ownCloud server
  781. if (mCurrentAccount == null || !mCurrentAccount.equals(mCurrentUpload.getAccount())) {
  782. mCurrentAccount = mCurrentUpload.getAccount();
  783. mStorageManager = new FileDataStorageManager(
  784. mCurrentAccount,
  785. getContentResolver()
  786. );
  787. } // else, reuse storage manager from previous operation
  788. // always get client from client manager, to get fresh credentials in case of update
  789. OwnCloudAccount ocAccount = new OwnCloudAccount(
  790. mCurrentAccount,
  791. this
  792. );
  793. mUploadClient = OwnCloudClientManagerFactory.getDefaultSingleton().
  794. getClientFor(ocAccount, this);
  795. /// perform the upload
  796. uploadResult = mCurrentUpload.execute(mUploadClient, mStorageManager);
  797. } catch (Exception e) {
  798. Log_OC.e(TAG, "Error uploading", e);
  799. uploadResult = new RemoteOperationResult(e);
  800. } finally {
  801. Pair<UploadFileOperation, String> removeResult;
  802. if (mCurrentUpload.wasRenamed()) {
  803. removeResult = mPendingUploads.removePayload(
  804. mCurrentAccount.name,
  805. mCurrentUpload.getOldFile().getRemotePath()
  806. );
  807. /** TODO: grant that name is also updated for mCurrentUpload.getOCUploadId */
  808. } else {
  809. removeResult = mPendingUploads.removePayload(
  810. mCurrentAccount.name,
  811. mCurrentUpload.getRemotePath()
  812. );
  813. }
  814. mUploadsStorageManager.updateDatabaseUploadResult(uploadResult, mCurrentUpload);
  815. /// notify result
  816. notifyUploadResult(mCurrentUpload, uploadResult);
  817. sendBroadcastUploadFinished(mCurrentUpload, uploadResult, removeResult.second);
  818. }
  819. }
  820. // generate new Thumbnail
  821. final ThumbnailsCacheManager.ThumbnailGenerationTask task =
  822. new ThumbnailsCacheManager.ThumbnailGenerationTask(mStorageManager, mCurrentAccount);
  823. Object[] params = new Object[2];
  824. params[0] = new File(mCurrentUpload.getOriginalStoragePath());
  825. params[1] = mCurrentUpload.getFile().getRemoteId();
  826. task.execute(params);
  827. }
  828. /**
  829. * Creates a status notification to show the upload progress
  830. *
  831. * @param upload Upload operation starting.
  832. */
  833. private void notifyUploadStart(UploadFileOperation upload) {
  834. // / create status notification with a progress bar
  835. mLastPercent = 0;
  836. mNotificationBuilder =
  837. NotificationUtils.newNotificationBuilder(this);
  838. mNotificationBuilder
  839. .setOngoing(true)
  840. .setSmallIcon(R.drawable.notification_icon)
  841. .setTicker(getString(R.string.uploader_upload_in_progress_ticker))
  842. .setContentTitle(getString(R.string.uploader_upload_in_progress_ticker))
  843. .setProgress(100, 0, false)
  844. .setContentText(
  845. String.format(getString(R.string.uploader_upload_in_progress_content), 0, upload.getFileName())
  846. );
  847. /// includes a pending intent in the notification showing the details
  848. Intent showUploadListIntent = new Intent(this, UploadListActivity.class);
  849. showUploadListIntent.putExtra(FileActivity.EXTRA_FILE, upload.getFile());
  850. showUploadListIntent.putExtra(FileActivity.EXTRA_ACCOUNT, upload.getAccount());
  851. showUploadListIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  852. mNotificationBuilder.setContentIntent(PendingIntent.getActivity(this, (int) System.currentTimeMillis(),
  853. showUploadListIntent, 0));
  854. if (!upload.isInstantPicture() && !upload.isInstantVideo()) {
  855. mNotificationManager.notify(R.string.uploader_upload_in_progress_ticker, mNotificationBuilder.build());
  856. } // else wait until the upload really start (onTransferProgress is called), so that if it's discarded
  857. // due to lack of Wifi, no notification is shown
  858. // TODO generalize for automated uploads
  859. }
  860. /**
  861. * Callback method to update the progress bar in the status notification
  862. */
  863. @Override
  864. public void onTransferProgress(long progressRate, long totalTransferredSoFar,
  865. long totalToTransfer, String filePath) {
  866. int percent = (int) (100.0 * ((double) totalTransferredSoFar) / ((double) totalToTransfer));
  867. if (percent != mLastPercent) {
  868. mNotificationBuilder.setProgress(100, percent, false);
  869. String fileName = filePath.substring(filePath.lastIndexOf(FileUtils.PATH_SEPARATOR) + 1);
  870. String text = String.format(getString(R.string.uploader_upload_in_progress_content), percent, fileName);
  871. mNotificationBuilder.setContentText(text);
  872. mNotificationManager.notify(R.string.uploader_upload_in_progress_ticker, mNotificationBuilder.build());
  873. }
  874. mLastPercent = percent;
  875. }
  876. /**
  877. * Updates the status notification with the result of an upload operation.
  878. *
  879. * @param uploadResult Result of the upload operation.
  880. * @param upload Finished upload operation
  881. */
  882. private void notifyUploadResult(UploadFileOperation upload,
  883. RemoteOperationResult uploadResult) {
  884. Log_OC.d(TAG, "NotifyUploadResult with resultCode: " + uploadResult.getCode());
  885. // / cancelled operation or success -> silent removal of progress notification
  886. mNotificationManager.cancel(R.string.uploader_upload_in_progress_ticker);
  887. // Show the result: success or fail notification
  888. if (!uploadResult.isCancelled() &&
  889. !uploadResult.getCode().equals(ResultCode.DELAYED_FOR_WIFI)) {
  890. int tickerId = (uploadResult.isSuccess()) ? R.string.uploader_upload_succeeded_ticker :
  891. R.string.uploader_upload_failed_ticker;
  892. String content;
  893. // check credentials error
  894. boolean needsToUpdateCredentials = (ResultCode.UNAUTHORIZED.equals(uploadResult.getCode()));
  895. tickerId = (needsToUpdateCredentials) ?
  896. R.string.uploader_upload_failed_credentials_error : tickerId;
  897. mNotificationBuilder
  898. .setTicker(getString(tickerId))
  899. .setContentTitle(getString(tickerId))
  900. .setAutoCancel(true)
  901. .setOngoing(false)
  902. .setProgress(0, 0, false);
  903. content = ErrorMessageAdapter.getErrorCauseMessage(
  904. uploadResult, upload, getResources()
  905. );
  906. if (needsToUpdateCredentials) {
  907. // let the user update credentials with one click
  908. Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
  909. updateAccountCredentials.putExtra(
  910. AuthenticatorActivity.EXTRA_ACCOUNT, upload.getAccount()
  911. );
  912. updateAccountCredentials.putExtra(
  913. AuthenticatorActivity.EXTRA_ACTION,
  914. AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN
  915. );
  916. updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  917. updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
  918. updateAccountCredentials.addFlags(Intent.FLAG_FROM_BACKGROUND);
  919. mNotificationBuilder.setContentIntent(PendingIntent.getActivity(
  920. this,
  921. (int) System.currentTimeMillis(),
  922. updateAccountCredentials,
  923. PendingIntent.FLAG_ONE_SHOT
  924. ));
  925. } else {
  926. mNotificationBuilder.setContentText(content);
  927. }
  928. if (!uploadResult.isSuccess() && !needsToUpdateCredentials ) {
  929. //in case of failure, do not show details file view (because there is no file!)
  930. Intent showUploadListIntent = new Intent(this, UploadListActivity.class);
  931. showUploadListIntent.putExtra(FileActivity.EXTRA_FILE, upload.getFile());
  932. showUploadListIntent.putExtra(FileActivity.EXTRA_ACCOUNT, upload.getAccount());
  933. showUploadListIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  934. mNotificationBuilder.setContentIntent(PendingIntent.getActivity(this, (int) System.currentTimeMillis(),
  935. showUploadListIntent, 0));
  936. }
  937. mNotificationBuilder.setContentText(content);
  938. mNotificationManager.notify(tickerId, mNotificationBuilder.build());
  939. if (uploadResult.isSuccess()) {
  940. mPendingUploads.remove(upload.getAccount().name, upload.getFile().getRemotePath());
  941. // remove success notification, with a delay of 2 seconds
  942. NotificationUtils.cancelWithDelay(
  943. mNotificationManager,
  944. R.string.uploader_upload_succeeded_ticker,
  945. 2000);
  946. }
  947. }
  948. }
  949. /**
  950. * Sends a broadcast in order to the interested activities can update their
  951. * view
  952. *
  953. * TODO - no more broadcasts, replace with a callback to subscribed listeners
  954. */
  955. private void sendBroadcastUploadsAdded() {
  956. Intent start = new Intent(getUploadsAddedMessage());
  957. // nothing else needed right now
  958. sendStickyBroadcast(start);
  959. }
  960. /**
  961. * Sends a broadcast in order to the interested activities can update their
  962. * view
  963. *
  964. * TODO - no more broadcasts, replace with a callback to subscribed listeners
  965. *
  966. * @param upload Finished upload operation
  967. */
  968. private void sendBroadcastUploadStarted(
  969. UploadFileOperation upload) {
  970. Intent start = new Intent(getUploadStartMessage());
  971. start.putExtra(EXTRA_REMOTE_PATH, upload.getRemotePath()); // real remote
  972. start.putExtra(EXTRA_OLD_FILE_PATH, upload.getOriginalStoragePath());
  973. start.putExtra(ACCOUNT_NAME, upload.getAccount().name);
  974. sendStickyBroadcast(start);
  975. }
  976. /**
  977. * Sends a broadcast in order to the interested activities can update their
  978. * view
  979. *
  980. * TODO - no more broadcasts, replace with a callback to subscribed listeners
  981. *
  982. * @param upload Finished upload operation
  983. * @param uploadResult Result of the upload operation
  984. * @param unlinkedFromRemotePath Path in the uploads tree where the upload was unlinked from
  985. */
  986. private void sendBroadcastUploadFinished(
  987. UploadFileOperation upload,
  988. RemoteOperationResult uploadResult,
  989. String unlinkedFromRemotePath) {
  990. Intent end = new Intent(getUploadFinishMessage());
  991. end.putExtra(EXTRA_REMOTE_PATH, upload.getRemotePath()); // real remote
  992. // path, after
  993. // possible
  994. // automatic
  995. // renaming
  996. if (upload.wasRenamed()) {
  997. end.putExtra(EXTRA_OLD_REMOTE_PATH, upload.getOldFile().getRemotePath());
  998. }
  999. end.putExtra(EXTRA_OLD_FILE_PATH, upload.getOriginalStoragePath());
  1000. end.putExtra(ACCOUNT_NAME, upload.getAccount().name);
  1001. end.putExtra(EXTRA_UPLOAD_RESULT, uploadResult.isSuccess());
  1002. if (unlinkedFromRemotePath != null) {
  1003. end.putExtra(EXTRA_LINKED_TO_PATH, unlinkedFromRemotePath);
  1004. }
  1005. sendStickyBroadcast(end);
  1006. }
  1007. /**
  1008. * Remove and 'forgets' pending uploads of an account.
  1009. *
  1010. * @param account Account which uploads will be cancelled
  1011. */
  1012. private void cancelUploadsForAccount(Account account) {
  1013. mPendingUploads.remove(account.name);
  1014. mUploadsStorageManager.removeUploads(account.name);
  1015. }
  1016. }