use of android.app.job.JobInfo in project android-job by evernote.
the class JobProxy21 method isPlatformJobScheduled.
@Override
public boolean isPlatformJobScheduled(JobRequest request) {
List<JobInfo> pendingJobs;
try {
pendingJobs = getJobScheduler().getAllPendingJobs();
} catch (Exception e) {
// it's possible that this throws an exception, see https://gist.github.com/vRallev/a59947dd3932d2642641
mCat.e(e);
return false;
}
//noinspection ConstantConditions
if (pendingJobs == null || pendingJobs.isEmpty()) {
return false;
}
int requestId = request.getJobId();
for (JobInfo info : pendingJobs) {
if (info.getId() == requestId) {
return true;
}
}
return false;
}
use of android.app.job.JobInfo in project materialistic by hidroh.
the class ItemSyncJobServiceTest method testScheduledJob.
@Test
public void testScheduledJob() {
PreferenceManager.getDefaultSharedPreferences(RuntimeEnvironment.application).edit().putBoolean(RuntimeEnvironment.application.getString(R.string.pref_saved_item_sync), true).apply();
shadowOf((ConnectivityManager) RuntimeEnvironment.application.getSystemService(Context.CONNECTIVITY_SERVICE)).setActiveNetworkInfo(ShadowNetworkInfo.newInstance(null, ConnectivityManager.TYPE_WIFI, 0, true, true));
SyncDelegate.scheduleSync(RuntimeEnvironment.application, new SyncDelegate.JobBuilder(RuntimeEnvironment.application, "1").build());
List<JobInfo> pendingJobs = shadowOf((JobScheduler) RuntimeEnvironment.application.getSystemService(Context.JOB_SCHEDULER_SERVICE)).getAllPendingJobs();
assertThat(pendingJobs).isNotEmpty();
JobInfo actual = pendingJobs.get(0);
assertThat(actual.getService().getClassName()).isEqualTo(ItemSyncJobService.class.getName());
}
use of android.app.job.JobInfo in project robolectric by robolectric.
the class ShadowJobSchedulerTest method getAllPendingJobs.
@Test
public void getAllPendingJobs() {
JobInfo jobInfo = new JobInfo.Builder(99, new ComponentName(RuntimeEnvironment.application, "component_class_name")).setPeriodic(1000).build();
jobScheduler.schedule(jobInfo);
assertThat(jobScheduler.getAllPendingJobs()).contains(jobInfo);
}
use of android.app.job.JobInfo in project platform_frameworks_base by android.
the class SyncManager method verifyJobScheduler.
private synchronized void verifyJobScheduler() {
if (mJobScheduler != null) {
return;
}
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.d(TAG, "initializing JobScheduler object.");
}
mJobScheduler = (JobScheduler) mContext.getSystemService(Context.JOB_SCHEDULER_SERVICE);
mJobSchedulerInternal = LocalServices.getService(JobSchedulerInternal.class);
// Get all persisted syncs from JobScheduler
List<JobInfo> pendingJobs = mJobScheduler.getAllPendingJobs();
for (JobInfo job : pendingJobs) {
SyncOperation op = SyncOperation.maybeCreateFromJobExtras(job.getExtras());
if (op != null) {
if (!op.isPeriodic) {
// Set the pending status of this EndPoint to true. Pending icon is
// shown on the settings activity.
mSyncStorageEngine.markPending(op.target, true);
}
}
}
cleanupJobs();
}
use of android.app.job.JobInfo in project platform_frameworks_base by android.
the class JobStoreTest method testWritingTaskWithExtras.
public void testWritingTaskWithExtras() throws Exception {
JobInfo.Builder b = new Builder(8, mComponent).setRequiresDeviceIdle(true).setPeriodic(10000L).setRequiresCharging(true).setPersisted(true);
PersistableBundle extras = new PersistableBundle();
extras.putDouble("hello", 3.2);
extras.putString("hi", "there");
extras.putInt("into", 3);
b.setExtras(extras);
final JobInfo task = b.build();
JobStatus taskStatus = JobStatus.createFromJobInfo(task, SOME_UID, null, -1, null);
mTaskStoreUnderTest.add(taskStatus);
Thread.sleep(IO_WAIT);
final JobSet jobStatusSet = new JobSet();
mTaskStoreUnderTest.readJobMapFromDisk(jobStatusSet);
assertEquals("Incorrect # of persisted tasks.", 1, jobStatusSet.size());
JobStatus loaded = jobStatusSet.getAllJobs().iterator().next();
assertTasksEqual(task, loaded.getJob());
}
Aggregations