Acquire wakelocks to make sure all is good

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2017-05-10 21:37:43 +02:00 committed by AndyScherzinger
parent d18d618ac4
commit 441e5c7511
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
2 changed files with 19 additions and 0 deletions

View file

@ -24,6 +24,7 @@ package com.owncloud.android.jobs;
import android.accounts.Account;
import android.content.Context;
import android.os.PowerManager;
import android.support.annotation.NonNull;
import com.evernote.android.job.Job;
@ -47,7 +48,14 @@ public class AutoUploadJob extends Job {
@NonNull
@Override
protected Result onRunJob(Params params) {
final Context context = MainApp.getAppContext();
PowerManager powerManager = (PowerManager) context.getSystemService(context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
TAG);
wakeLock.acquire();
PersistableBundleCompat bundle = params.getExtras();
final String filePath = bundle.getString(LOCAL_PATH, "");
final String remotePath = bundle.getString(REMOTE_PATH, "");
@ -76,6 +84,7 @@ public class AutoUploadJob extends Job {
}
wakeLock.release();
return Result.SUCCESS;
}
}

View file

@ -23,6 +23,7 @@ package com.owncloud.android.jobs;
import android.content.ContentResolver;
import android.content.Context;
import android.os.PowerManager;
import android.support.annotation.NonNull;
import android.util.Log;
@ -62,9 +63,16 @@ public class NewAutoUploadJob extends Job {
@NonNull
@Override
protected Result onRunJob(Params params) {
final Context context = MainApp.getAppContext();
final ContentResolver contentResolver = context.getContentResolver();
PowerManager powerManager = (PowerManager) context.getSystemService(context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
TAG);
wakeLock.acquire();
// Create all the providers we'll need
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(contentResolver);
final FilesystemDataProvider filesystemDataProvider = new FilesystemDataProvider(contentResolver);
@ -114,6 +122,8 @@ public class NewAutoUploadJob extends Job {
Log.d(TAG, "Something went wrong while indexing files for auto upload");
}
}
wakeLock.release();
return Result.SUCCESS;
}
}