浏览代码

Merge pull request #1191 from owncloud/cancelUploadOnWlanExit

Cancel upload on wlan exit
Maria Asensio 9 年之前
父节点
当前提交
f88ab60a78

+ 20 - 2
src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java

@@ -92,7 +92,7 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
 
         Account account = AccountUtils.getCurrentOwnCloudAccount(context);
         if (account == null) {
-            Log_OC.w(TAG, "No ownCloud account found for instant upload, aborting");
+            Log_OC.w(TAG, "No account found for instant upload, aborting");
             return;
         }
 
@@ -170,7 +170,7 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
 
         Account account = AccountUtils.getCurrentOwnCloudAccount(context);
         if (account == null) {
-            Log_OC.w(TAG, "No owncloud account found for instant upload, aborting");
+            Log_OC.w(TAG, "No account found for instant upload, aborting");
             return;
         }
 
@@ -211,6 +211,19 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
             return;
         }
 
+        if (instantPictureUploadViaWiFiOnly(context) && !isConnectedViaWiFi(context)){
+            Account account = AccountUtils.getCurrentOwnCloudAccount(context);
+            if (account == null) {
+                Log_OC.w(TAG, "No account found for instant upload, aborting");
+                return;
+            }
+
+            Intent i = new Intent(context, FileUploader.class);
+            i.putExtra(FileUploader.KEY_ACCOUNT, account);
+            i.putExtra(FileUploader.KEY_CANCEL_ALL, true);
+            context.startService(i);
+        }
+
         if (!intent.hasExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY)
                 && isOnline(context)
                 && (!instantPictureUploadViaWiFiOnly(context) || (instantPictureUploadViaWiFiOnly(context) == isConnectedViaWiFi(context) == true))) {
@@ -218,6 +231,11 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
             Cursor c = db.getAwaitingFiles();
             if (c.moveToFirst()) {
                 do {
+                    if (instantPictureUploadViaWiFiOnly(context) &&
+                            !isConnectedViaWiFi(context)){
+                        break;
+                    }
+
                     String account_name = c.getString(c.getColumnIndex("account"));
                     String file_path = c.getString(c.getColumnIndex("path"));
                     File f = new File(file_path);

+ 12 - 0
src/com/owncloud/android/files/services/FileUploader.java

@@ -98,6 +98,8 @@ public class FileUploader extends Service
     public static final String KEY_INSTANT_UPLOAD = "INSTANT_UPLOAD";
     public static final String KEY_LOCAL_BEHAVIOUR = "BEHAVIOUR";
 
+    public static final String KEY_CANCEL_ALL = "CANCEL_ALL";
+
     public static final int LOCAL_BEHAVIOUR_COPY = 0;
     public static final int LOCAL_BEHAVIOUR_MOVE = 1;
     public static final int LOCAL_BEHAVIOUR_FORGET = 2;
@@ -194,6 +196,16 @@ public class FileUploader extends Service
     public int onStartCommand(Intent intent, int flags, int startId) {
         Log_OC.d(TAG, "Starting command with id " + startId);
 
+        if (intent.hasExtra(KEY_CANCEL_ALL) && intent.hasExtra(KEY_ACCOUNT)){
+            Account account = intent.getParcelableExtra(KEY_ACCOUNT);
+
+            if (mCurrentUpload != null) {
+                FileUploaderBinder fub = (FileUploaderBinder) mBinder;
+                fub.cancel(account);
+                return Service.START_NOT_STICKY;
+            }
+        }
+
         if (!intent.hasExtra(KEY_ACCOUNT) || !intent.hasExtra(KEY_UPLOAD_TYPE)
                 || !(intent.hasExtra(KEY_LOCAL_FILE) || intent.hasExtra(KEY_FILE))) {
             Log_OC.e(TAG, "Not enough information provided in intent");

+ 3 - 0
src/com/owncloud/android/operations/UploadFileOperation.java

@@ -393,6 +393,9 @@ public class UploadFileOperation extends RemoteOperation {
             if (temporalFile != null && !originalFile.equals(temporalFile)) {
                 temporalFile.delete();
             }
+            if (result == null){
+                result = new RemoteOperationResult(ResultCode.UNKNOWN_ERROR);
+            }
             if (result.isSuccess()) {
                 Log_OC.i(TAG, "Upload of " + mOriginalStoragePath + " to " + mRemotePath + ": " +
                         result.getLogMessage());