Эх сурвалжийг харах

Improve upload errors

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 7 жил өмнө
parent
commit
1931baa761

+ 10 - 5
src/main/java/com/owncloud/android/files/services/FileUploader.java

@@ -472,7 +472,11 @@ public class FileUploader extends Service
             chunked = false;
         }
 
+        boolean onWifiOnly = intent.getBooleanExtra(KEY_WHILE_ON_WIFI_ONLY, false);
+        boolean whileChargingOnly = intent.getBooleanExtra(KEY_WHILE_CHARGING_ONLY, false);
+
         if (!retry) {
+
             if (!(intent.hasExtra(KEY_LOCAL_FILE) ||
                     intent.hasExtra(KEY_FILE))) {
                 Log_OC.e(TAG, "Not enough information provided in intent");
@@ -502,9 +506,6 @@ public class FileUploader extends Service
             boolean isCreateRemoteFolder = intent.getBooleanExtra(KEY_CREATE_REMOTE_FOLDER, false);
             int createdBy = intent.getIntExtra(KEY_CREATED_BY, UploadFileOperation.CREATED_BY_USER);
 
-            boolean onWifiOnly = intent.getBooleanExtra(KEY_WHILE_ON_WIFI_ONLY, false);
-            boolean whileChargingOnly = intent.getBooleanExtra(KEY_WHILE_CHARGING_ONLY, false);
-
             if (intent.hasExtra(KEY_FILE) && files == null) {
                 Log_OC.e(TAG, "Incorrect array for OCFiles provided in upload intent");
                 return Service.START_NOT_STICKY;
@@ -563,7 +564,9 @@ public class FileUploader extends Service
                             chunked,
                             forceOverwrite,
                             localAction,
-                            this
+                            this,
+                            onWifiOnly,
+                            whileChargingOnly
                     );
                     newUpload.setCreatedBy(createdBy);
                     if (isCreateRemoteFolder) {
@@ -617,7 +620,9 @@ public class FileUploader extends Service
                     chunked,
                     upload.isForceOverwrite(),  // TODO should be read from DB?
                     upload.getLocalAction(),    // TODO should be read from DB?
-                    this
+                    this,
+                    onWifiOnly,
+                    whileChargingOnly
             );
 
             newUpload.addDatatransferProgressListener(this);

+ 11 - 40
src/main/java/com/owncloud/android/operations/UploadFileOperation.java

@@ -24,11 +24,12 @@ import android.accounts.Account;
 import android.content.Context;
 import android.net.Uri;
 
+import com.evernote.android.job.JobRequest;
+import com.evernote.android.job.util.Device;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.datamodel.ThumbnailsCacheManager;
 import com.owncloud.android.db.OCUpload;
-import com.owncloud.android.db.PreferenceManager;
 import com.owncloud.android.files.services.FileUploader;
 import com.owncloud.android.lib.common.OwnCloudClient;
 import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
@@ -44,7 +45,6 @@ import com.owncloud.android.lib.resources.files.ReadRemoteFileOperation;
 import com.owncloud.android.lib.resources.files.RemoteFile;
 import com.owncloud.android.lib.resources.files.UploadRemoteFileOperation;
 import com.owncloud.android.operations.common.SyncOperation;
-import com.owncloud.android.utils.ConnectivityUtils;
 import com.owncloud.android.utils.FileStorageUtils;
 import com.owncloud.android.utils.MimeType;
 import com.owncloud.android.utils.MimeTypeUtil;
@@ -94,6 +94,8 @@ public class UploadFileOperation extends SyncOperation {
     private boolean mForceOverwrite = false;
     private int mLocalBehaviour = FileUploader.LOCAL_BEHAVIOUR_COPY;
     private int mCreatedBy = CREATED_BY_USER;
+    private boolean mOnWifiOnly = false;
+    private boolean mWhileChargingOnly = false;
 
     private boolean mWasRenamed = false;
     private long mOCUploadId = -1;
@@ -147,7 +149,9 @@ public class UploadFileOperation extends SyncOperation {
                                boolean chunked,
                                boolean forceOverwrite,
                                int localBehaviour,
-                               Context context
+                               Context context,
+                               boolean onWifiOnly,
+                               boolean whileChargingOnly
     ) {
         if (account == null) {
             throw new IllegalArgumentException("Illegal NULL account in UploadFileOperation " + "creation");
@@ -171,6 +175,8 @@ public class UploadFileOperation extends SyncOperation {
         } else {
             mFile = file;
         }
+        mOnWifiOnly = onWifiOnly;
+        mWhileChargingOnly = whileChargingOnly;
         mRemotePath = upload.getRemotePath();
         mChunked = chunked;
         mForceOverwrite = forceOverwrite;
@@ -301,13 +307,13 @@ public class UploadFileOperation extends SyncOperation {
         try {
 
             /// Check that connectivity conditions are met and delays the upload otherwise
-            if (delayForWifi()) {
+            if (mOnWifiOnly && !Device.getNetworkType(mContext).equals(JobRequest.NetworkType.UNMETERED)){
                 Log_OC.d(TAG, "Upload delayed until WiFi is available: " + getRemotePath());
                 return new RemoteOperationResult(ResultCode.DELAYED_FOR_WIFI);
             }
 
             // Check if charging conditions are met and delays the upload otherwise
-            if (delayForCharging()){
+            if (mWhileChargingOnly && !Device.isCharging(mContext)){
                 Log_OC.d(TAG, "Upload delayed until the device is charging: " + getRemotePath());
                 return new RemoteOperationResult(ResultCode.DELAYED_FOR_CHARGING);
             }
@@ -478,41 +484,6 @@ public class UploadFileOperation extends SyncOperation {
         return result;
     }
 
-
-    /**
-     * Checks origin of current upload and network type to decide if should be delayed, according to
-     * current user preferences.
-     *
-     * @return      'True' if the upload was delayed until WiFi connectivity is available, 'false' otherwise.
-     */
-    private boolean delayForWifi() {
-        boolean delayInstantPicture = (
-            isInstantPicture() &&  PreferenceManager.instantPictureUploadViaWiFiOnly(mContext)
-        );
-        boolean delayInstantVideo = (
-            isInstantVideo() && PreferenceManager.instantVideoUploadViaWiFiOnly(mContext)
-        );
-        return (
-            (delayInstantPicture || delayInstantVideo) &&
-            !ConnectivityUtils.isAppConnectedViaUnmeteredWiFi(mContext)
-        );
-    }
-
-    /**
-     * Check if upload should be delayed due to not charging
-     *
-     * @return      'True' if the upload was delayed until device is charging, 'false' otherwise.
-     */
-    private boolean delayForCharging() {
-        boolean delayInstantPicture = isInstantPicture() &&
-                PreferenceManager.instantPictureUploadWhenChargingOnly(mContext);
-
-        boolean delayInstantVideo = isInstantVideo() && PreferenceManager.instantVideoUploadWhenChargingOnly(mContext);
-
-        return ((delayInstantPicture || delayInstantVideo) && !ConnectivityUtils.isCharging(mContext));
-    }
-
-
     /**
      * Checks the existence of the folder where the current file will be uploaded both
      * in the remote server and in the local database.