use of com.evernote.android.job.Job in project android-job by evernote.
the class PlatformJobService method onStopJob.
@Override
public boolean onStopJob(JobParameters params) {
Job job = JobManager.instance().getJob(params.getJobId());
if (job != null) {
job.cancel();
CAT.d("Called onStopJob for %s", job);
} else {
CAT.d("Called onStopJob, job %d not found", params.getJobId());
}
// do not reschedule
return false;
}
use of com.evernote.android.job.Job in project android by nextcloud.
the class OfflineSyncJob method onRunJob.
@NonNull
@Override
protected Result onRunJob(@NonNull Params params) {
final Context context = MainApp.getAppContext();
PowerManager.WakeLock wakeLock = null;
if (!PowerUtils.isPowerSaveMode(context) && Device.getNetworkType(context).equals(JobRequest.NetworkType.UNMETERED) && !ConnectivityUtils.isInternetWalled(context)) {
Set<Job> jobs = JobManager.instance().getAllJobsForTag(TAG);
for (Job job : jobs) {
if (!job.isFinished() && !job.equals(this)) {
return Result.SUCCESS;
}
}
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, null, ProviderMeta.ProviderTableMeta.FILE_KEEP_IN_SYNC + " = ?", new String[] { String.valueOf(1) }, null);
if (cursorOnKeptInSync != null) {
if (cursorOnKeptInSync.moveToFirst()) {
String localPath = "";
String accountName = "";
Account account = null;
do {
localPath = cursorOnKeptInSync.getString(cursorOnKeptInSync.getColumnIndex(ProviderMeta.ProviderTableMeta.FILE_STORAGE_PATH));
accountName = cursorOnKeptInSync.getString(cursorOnKeptInSync.getColumnIndex(ProviderMeta.ProviderTableMeta.FILE_ACCOUNT_OWNER));
account = new Account(accountName, MainApp.getAccountType());
if (!AccountUtils.exists(account, context) || localPath == null || localPath.length() <= 0) {
continue;
}
offlineFileList.add(new OfflineFile(localPath, account));
} while (cursorOnKeptInSync.moveToNext());
}
cursorOnKeptInSync.close();
}
FileDataStorageManager storageManager;
for (OfflineFile offlineFile : offlineFileList) {
storageManager = new FileDataStorageManager(offlineFile.getAccount(), context.getContentResolver());
OCFile file = storageManager.getFileByLocalPath(offlineFile.getLocalPath());
SynchronizeFileOperation sfo = new SynchronizeFileOperation(file, null, offlineFile.getAccount(), true, context);
RemoteOperationResult result = sfo.execute(storageManager, context);
if (result.getCode() == RemoteOperationResult.ResultCode.SYNC_CONFLICT) {
Intent i = new Intent(context, ConflictsResolveActivity.class);
i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra(ConflictsResolveActivity.EXTRA_FILE, file);
i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, offlineFile.getAccount());
context.startActivity(i);
}
}
if (wakeLock != null) {
wakeLock.release();
}
}
return Result.SUCCESS;
}
Aggregations