瀏覽代碼

Remove locks

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 7 年之前
父節點
當前提交
65cc28e79f
共有 1 個文件被更改,包括 10 次插入5 次删除
  1. 10 5
      src/main/java/com/owncloud/android/jobs/OfflineSyncJob.java

+ 10 - 5
src/main/java/com/owncloud/android/jobs/OfflineSyncJob.java

@@ -23,6 +23,7 @@ import android.accounts.Account;
 import android.content.Context;
 import android.content.Intent;
 import android.database.Cursor;
+import android.os.Build;
 import android.os.PowerManager;
 import android.support.annotation.NonNull;
 
@@ -53,6 +54,7 @@ public class OfflineSyncJob extends Job {
     protected Result onRunJob(@NonNull Params params) {
         final Context context = MainApp.getAppContext();
 
+        PowerManager.WakeLock wakeLock = null;
         if (!PowerUtils.isPowerSaveMode(context) && !ConnectivityUtils.isInternetWalled(context)) {
             Set<Job> jobs = JobManager.instance().getAllJobsForTag(TAG);
             for (Job job : jobs) {
@@ -61,10 +63,11 @@ public class OfflineSyncJob extends Job {
                 }
             }
 
-            PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
-            PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
-                    TAG);
-            wakeLock.acquire();
+            if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
+                PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
+                wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
+                wakeLock.acquire();
+            }
 
             Cursor cursorOnKeptInSync = context.getContentResolver().query(
                     ProviderMeta.ProviderTableMeta.CONTENT_URI,
@@ -115,7 +118,9 @@ public class OfflineSyncJob extends Job {
                 }
             }
 
-            wakeLock.release();
+            if (wakeLock != null) {
+                wakeLock.release();
+            }
         }
 
         return Result.SUCCESS;