use of com.evernote.android.job.JobRequest in project android-job by evernote.
the class PlatformAlarmService method onHandleIntent.
@Override
protected void onHandleIntent(final Intent intent) {
if (intent == null) {
Cat.i("Delivered intent is null");
return;
}
int jobId = intent.getIntExtra(PlatformAlarmReceiver.EXTRA_JOB_ID, -1);
final JobProxy.Common common = new JobProxy.Common(this, jobId);
// create the JobManager. Seeing sometimes exceptions, that it wasn't created, yet.
final JobRequest request = common.getPendingRequest(true);
if (request == null) {
return;
}
// parallel execution
EXECUTOR_SERVICE.execute(new Runnable() {
@Override
public void run() {
common.executeJobRequest(request);
// call here, our own wake lock could be acquired too late
try {
PlatformAlarmReceiver.completeWakefulIntent(intent);
} catch (Exception e) {
// could end in a NPE if the intent has no wake lock
}
}
});
}
use of com.evernote.android.job.JobRequest in project android by nextcloud.
the class ContactsPreferenceActivity method cancelContactBackupJobForAccount.
public static void cancelContactBackupJobForAccount(Context context, Account account) {
Log_OC.d(TAG, "disabling contacts backup job for account: " + account.name);
JobManager jobManager = JobManager.create(context);
Set<JobRequest> jobs = jobManager.getAllJobRequestsForTag(ContactsBackupJob.TAG);
for (JobRequest jobRequest : jobs) {
PersistableBundleCompat extras = jobRequest.getExtras();
if (extras.getString(ContactsBackupJob.ACCOUNT, "").equalsIgnoreCase(account.name)) {
jobManager.cancel(jobRequest.getJobId());
}
}
}
use of com.evernote.android.job.JobRequest in project android-job by evernote.
the class PlatformWorkManagerTest method testCancel.
@Test
@SuppressWarnings("ConstantConditions")
public void testCancel() {
int jobId = new JobRequest.Builder(TAG).setExecutionWindow(TimeUnit.HOURS.toMillis(4), TimeUnit.HOURS.toMillis(5)).build().schedule();
JobRequest request = mWorkManagerRule.getManager().getJobRequest(jobId);
JobProxyWorkManager jobProxyWorkManager = new JobProxyWorkManager(ApplicationProvider.getApplicationContext());
assertThat(jobProxyWorkManager.isPlatformJobScheduled(request)).isTrue();
String tag = JobProxyWorkManager.createTag(jobId);
List<WorkInfo> statuses = mWorkManagerRule.getWorkStatus(tag);
assertThat(statuses).isNotNull().hasSize(1);
assertThat(statuses.get(0).getState()).isEqualTo(WorkInfo.State.ENQUEUED);
mWorkManagerRule.getManager().cancel(jobId);
assertThat(mWorkManagerRule.getWorkStatus(tag).get(0).getState()).isEqualTo(WorkInfo.State.CANCELLED);
assertThat(jobProxyWorkManager.isPlatformJobScheduled(request)).isFalse();
}
use of com.evernote.android.job.JobRequest in project android-job by evernote.
the class PlatformWorker method doWork.
@NonNull
@Override
public Result doWork() {
final int jobId = getJobId();
if (jobId < 0) {
return Result.failure();
}
try {
JobProxy.Common common = new JobProxy.Common(getApplicationContext(), CAT, jobId);
JobRequest request = common.getPendingRequest(true, true);
if (request == null) {
return Result.failure();
}
Bundle transientBundle = null;
if (request.isTransient()) {
transientBundle = TransientBundleHolder.getBundle(jobId);
if (transientBundle == null) {
CAT.d("Transient bundle is gone for request %s", request);
return Result.failure();
}
}
Job.Result result = common.executeJobRequest(request, transientBundle);
if (Job.Result.SUCCESS == result) {
return Result.success();
} else {
return Result.failure();
}
} finally {
TransientBundleHolder.cleanUpBundle(jobId);
}
}
use of com.evernote.android.job.JobRequest in project android-job by evernote.
the class PlatformJobService method onStartJob.
@Override
public boolean onStartJob(final JobParameters params) {
final int jobId = params.getJobId();
final JobProxy.Common common = new JobProxy.Common(this, jobId);
final JobRequest request = common.getPendingRequest(true);
if (request == null) {
return false;
}
EXECUTOR_SERVICE.execute(new Runnable() {
@Override
public void run() {
try {
common.executeJobRequest(request);
} finally {
// do not reschedule
jobFinished(params, false);
}
}
});
// yes, we have a job running in the background
return true;
}
Aggregations