Search in sources :

Example 1 with JobInfo

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;
}
Also used : JobInfo(android.app.job.JobInfo)

Example 2 with JobInfo

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());
}
Also used : JobScheduler(android.app.job.JobScheduler) JobInfo(android.app.job.JobInfo) ConnectivityManager(android.net.ConnectivityManager) Test(org.junit.Test)

Example 3 with JobInfo

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);
}
Also used : JobInfo(android.app.job.JobInfo) ComponentName(android.content.ComponentName) Test(org.junit.Test)

Example 4 with 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();
}
Also used : JobSchedulerInternal(com.android.server.job.JobSchedulerInternal) JobInfo(android.app.job.JobInfo)

Example 5 with JobInfo

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());
}
Also used : JobStatus(com.android.server.job.controllers.JobStatus) PersistableBundle(android.os.PersistableBundle) JobInfo(android.app.job.JobInfo) JobSet(com.android.server.job.JobStore.JobSet) Builder(android.app.job.JobInfo.Builder) Builder(android.app.job.JobInfo.Builder)

Aggregations

JobInfo (android.app.job.JobInfo)66 JobStatus (com.android.server.job.controllers.JobStatus)22 JobScheduler (android.app.job.JobScheduler)13 Builder (android.app.job.JobInfo.Builder)12 JobSet (com.android.server.job.JobStore.JobSet)12 ArrayList (java.util.ArrayList)10 ComponentName (android.content.ComponentName)8 Event (com.android.server.job.MockPriorityJobService.TestEnvironment.Event)8 Test (org.junit.Test)7 PersistableBundle (android.os.PersistableBundle)6 NotificationManager (android.app.NotificationManager)5 JobSchedulerInternal (com.android.server.job.JobSchedulerInternal)5 StateController (com.android.server.job.controllers.StateController)5 JobParameters (android.app.job.JobParameters)1 ConnectivityManager (android.net.ConnectivityManager)1 NonNull (android.support.annotation.NonNull)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1