+ /**
+ * Binder to let client components to perform operations on the queue of uploads.
+ *
+ * It provides by itself the available operations.
+ */
+ public class FileUploaderBinder extends Binder {
+
+ /**
+ * Cancels a pending or current upload of a remote file.
+ *
+ * @param account Owncloud account where the remote file will be stored.
+ * @param file A file in the queue of pending uploads
+ */
+ public void cancel(Account account, OCFile file) {
+ UploadFileOperation upload = null;
+ synchronized (mPendingUploads) {
+ upload = mPendingUploads.remove(buildRemoteName(account, file));
+ }
+ if (upload != null) {
+ // TODO upload.cancel();
+ }
+ }
+
+
+ /**
+ * 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);