Browse Source

Fixes

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 7 years ago
parent
commit
2d5d8cc1ca

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

@@ -48,7 +48,7 @@ import com.owncloud.android.operations.common.SyncOperation;
 import com.owncloud.android.utils.FileStorageUtils;
 import com.owncloud.android.utils.MimeType;
 import com.owncloud.android.utils.MimeTypeUtil;
-import com.owncloud.android.utils.UploadUtils;
+import com.owncloud.android.utils.PowerUtils;
 import com.owncloud.android.utils.UriUtils;
 
 import org.apache.commons.httpclient.HttpStatus;
@@ -354,7 +354,7 @@ public class UploadFileOperation extends SyncOperation {
             }
 
             // Check that device is not in power save mode
-            if (!mIgnoringPowerSaveMode && UploadUtils.isPowerSaveMode(mContext)) {
+            if (!mIgnoringPowerSaveMode && PowerUtils.isPowerSaveMode(mContext)) {
                 Log_OC.d(TAG, "Upload delayed because device is in power save mode: " + getRemotePath());
                 return new RemoteOperationResult(ResultCode.DELAYED_IN_POWER_SAVE_MODE);
             }

+ 24 - 0
src/main/java/com/owncloud/android/utils/PowerUtils.java

@@ -0,0 +1,24 @@
+package com.owncloud.android.utils;
+
+import android.annotation.TargetApi;
+import android.content.Context;
+import android.os.Build;
+import android.os.PowerManager;
+
+public class PowerUtils {
+
+    /**
+     * Checks if device is in power save mode. For older devices that do not support this API, returns false.
+     * @return true if it is, false otherwise.
+     */
+    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+    public static boolean isPowerSaveMode(Context context) {
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+            PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
+            return powerManager != null && powerManager.isPowerSaveMode();
+        }
+
+        // For older versions, we just say that device is not in power save mode
+        return false;
+    }
+}

+ 1 - 1
src/main/java/com/owncloud/android/utils/ReceiversHelper.java

@@ -81,7 +81,7 @@ public class ReceiversHelper {
         BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
             @Override
             public void onReceive(Context context, Intent intent) {
-                if (!UploadUtils.isPowerSaveMode(context)) {
+                if (!PowerUtils.isPowerSaveMode(context)) {
                     FilesSyncHelper.restartJobsIfNeeded();
                 }
             }