+ /**
+ * Returns True when the file described by 'file' is being uploaded to the ownCloud account 'account' or waiting for it
+ *
+ * @param account Owncloud account where the remote file will be stored.
+ * @param file A file that could be in the queue of pending uploads
+ */
+ public boolean isUploading(Account account, OCFile file) {
+ synchronized (mPendingUploads) {
+ return (mPendingUploads.containsKey(buildRemoteName(account, file)));
+ }
+ }
+ }
+
+
+
+
+ /**
+ * Upload worker. Performs the pending uploads in the order they were requested.
+ *
+ * Created with the Looper of a new thread, started in {@link FileUploader#onCreate()}.
+ */
+ private static class ServiceHandler extends Handler {
+ // don't make it a final class, and don't remove the static ; lint will warn about a possible memory leak
+ FileUploader mService;
+ public ServiceHandler(Looper looper, FileUploader service) {
+ super(looper);
+ if (service == null)
+ throw new IllegalArgumentException("Received invalid NULL in parameter 'service'");
+ mService = service;
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ @SuppressWarnings("unchecked")
+ AbstractList<String> requestedUploads = (AbstractList<String>) msg.obj;
+ if (msg.obj != null) {
+ Iterator<String> it = requestedUploads.iterator();
+ while (it.hasNext()) {
+ mService.uploadFile(it.next());
+ }
+ }
+ mService.stopSelf(msg.arg1);
+ }
+ }
+
+
+
+
+ /**
+ * Core upload method: sends the file(s) to upload
+ *
+ * @param uploadKey Key to access the upload to perform, contained in mPendingUploads
+ */
+ public void uploadFile(String uploadKey) {
+
+ synchronized(mPendingUploads) {
+ mCurrentUpload = mPendingUploads.get(uploadKey);
+ }
+
+ if (mCurrentUpload != null) {