@Test public void schedule_whenExtrasEvailable_transmitsExtras() { String extras = "e1"; TransportContext transportContext = TransportContext.builder() .setBackendName("backend1") .setExtras(extras.getBytes(Charset.defaultCharset())) .build(); store.recordNextCallTime(transportContext, 1000000); scheduler.schedule(transportContext, 1); JobInfo jobInfo = jobScheduler.getAllPendingJobs().get(0); PersistableBundle bundle = jobInfo.getExtras(); assertThat(bundle.get(JobInfoScheduler.EXTRAS)) .isEqualTo( Base64.encodeToString(extras.getBytes(Charset.defaultCharset()), Base64.DEFAULT)); }
@Override public void schedule(TransportContext transportContext, int attemptNumber) { ComponentName serviceComponent = new ComponentName(context, JobInfoSchedulerService.class); JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); int jobId = getJobId(transportContext); if (isJobServiceOn(jobScheduler, jobId, attemptNumber)) { Logging.d( LOG_TAG, "Upload for context %s is already scheduled. Returning...", transportContext); return; } long nextCallTime = eventStore.getNextCallTime(transportContext); JobInfo.Builder builder = config.configureJob( new JobInfo.Builder(jobId, serviceComponent), transportContext.getPriority(), nextCallTime, attemptNumber); PersistableBundle bundle = new PersistableBundle(); bundle.putInt(ATTEMPT_NUMBER, attemptNumber); bundle.putString(BACKEND_NAME, transportContext.getBackendName()); bundle.putInt(EVENT_PRIORITY, PriorityMapping.toInt(transportContext.getPriority())); if (transportContext.getExtras() != null) { bundle.putString(EXTRAS, encodeToString(transportContext.getExtras(), DEFAULT)); } builder.setExtras(bundle); Logging.d( LOG_TAG, "Scheduling upload for context %s with jobId=%d in %dms(Backend next call timestamp %d). Attempt %d", transportContext, jobId, config.getScheduleDelay(transportContext.getPriority(), nextCallTime, attemptNumber), nextCallTime, attemptNumber); jobScheduler.schedule(builder.build()); }
JobInfoScheduler implements WorkScheduler { @Override public void schedule(TransportContext transportContext, int attemptNumber) { ComponentName serviceComponent = new ComponentName(context, JobInfoSchedulerService.class); JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); int jobId = getJobId(transportContext); if (isJobServiceOn(jobScheduler, jobId, attemptNumber)) { Logging.d( LOG_TAG, "Upload for context %s is already scheduled. Returning...", transportContext); return; } long nextCallTime = eventStore.getNextCallTime(transportContext); JobInfo.Builder builder = config.configureJob( new JobInfo.Builder(jobId, serviceComponent), transportContext.getPriority(), nextCallTime, attemptNumber); PersistableBundle bundle = new PersistableBundle(); bundle.putInt(ATTEMPT_NUMBER, attemptNumber); bundle.putString(BACKEND_NAME, transportContext.getBackendName()); bundle.putInt(EVENT_PRIORITY, PriorityMapping.toInt(transportContext.getPriority())); if (transportContext.getExtras() != null) { bundle.putString(EXTRAS, encodeToString(transportContext.getExtras(), DEFAULT)); } builder.setExtras(bundle); Logging.d( LOG_TAG, "Scheduling upload for context %s with jobId=%d in %dms(Backend next call timestamp %d). Attempt %d", transportContext, jobId, config.getScheduleDelay(transportContext.getPriority(), nextCallTime, attemptNumber), nextCallTime, attemptNumber); jobScheduler.schedule(builder.build()); } }
JobInfoScheduler implements WorkScheduler { @Override public void schedule(TransportContext transportContext, int attemptNumber) { ComponentName serviceComponent = new ComponentName(context, JobInfoSchedulerService.class); JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); int jobId = getJobId(transportContext); if (isJobServiceOn(jobScheduler, jobId, attemptNumber)) { Logging.d( LOG_TAG, "Upload for context %s is already scheduled. Returning...", transportContext); return; } long nextCallTime = eventStore.getNextCallTime(transportContext); JobInfo.Builder builder = config.configureJob( new JobInfo.Builder(jobId, serviceComponent), transportContext.getPriority(), nextCallTime, attemptNumber); PersistableBundle bundle = new PersistableBundle(); bundle.putInt(ATTEMPT_NUMBER, attemptNumber); bundle.putString(BACKEND_NAME, transportContext.getBackendName()); bundle.putInt(EVENT_PRIORITY, PriorityMapping.toInt(transportContext.getPriority())); if (transportContext.getExtras() != null) { bundle.putString(EXTRAS, encodeToString(transportContext.getExtras(), DEFAULT)); } builder.setExtras(bundle); Logging.d( LOG_TAG, "Scheduling upload for context %s with jobId=%d in %dms(Backend next call timestamp %d). Attempt %d", transportContext, jobId, config.getScheduleDelay(transportContext.getPriority(), nextCallTime, attemptNumber), nextCallTime, attemptNumber); jobScheduler.schedule(builder.build()); } JobInfoScheduler(
      Context applicationContext, EventStore eventStore, SchedulerConfig config); }
JobInfoScheduler implements WorkScheduler { @Override public void schedule(TransportContext transportContext, int attemptNumber) { ComponentName serviceComponent = new ComponentName(context, JobInfoSchedulerService.class); JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); int jobId = getJobId(transportContext); if (isJobServiceOn(jobScheduler, jobId, attemptNumber)) { Logging.d( LOG_TAG, "Upload for context %s is already scheduled. Returning...", transportContext); return; } long nextCallTime = eventStore.getNextCallTime(transportContext); JobInfo.Builder builder = config.configureJob( new JobInfo.Builder(jobId, serviceComponent), transportContext.getPriority(), nextCallTime, attemptNumber); PersistableBundle bundle = new PersistableBundle(); bundle.putInt(ATTEMPT_NUMBER, attemptNumber); bundle.putString(BACKEND_NAME, transportContext.getBackendName()); bundle.putInt(EVENT_PRIORITY, PriorityMapping.toInt(transportContext.getPriority())); if (transportContext.getExtras() != null) { bundle.putString(EXTRAS, encodeToString(transportContext.getExtras(), DEFAULT)); } builder.setExtras(bundle); Logging.d( LOG_TAG, "Scheduling upload for context %s with jobId=%d in %dms(Backend next call timestamp %d). Attempt %d", transportContext, jobId, config.getScheduleDelay(transportContext.getPriority(), nextCallTime, attemptNumber), nextCallTime, attemptNumber); jobScheduler.schedule(builder.build()); } JobInfoScheduler(
      Context applicationContext, EventStore eventStore, SchedulerConfig config); @Override void schedule(TransportContext transportContext, int attemptNumber); }
JobInfoScheduler implements WorkScheduler { @Override public void schedule(TransportContext transportContext, int attemptNumber) { ComponentName serviceComponent = new ComponentName(context, JobInfoSchedulerService.class); JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); int jobId = getJobId(transportContext); if (isJobServiceOn(jobScheduler, jobId, attemptNumber)) { Logging.d( LOG_TAG, "Upload for context %s is already scheduled. Returning...", transportContext); return; } long nextCallTime = eventStore.getNextCallTime(transportContext); JobInfo.Builder builder = config.configureJob( new JobInfo.Builder(jobId, serviceComponent), transportContext.getPriority(), nextCallTime, attemptNumber); PersistableBundle bundle = new PersistableBundle(); bundle.putInt(ATTEMPT_NUMBER, attemptNumber); bundle.putString(BACKEND_NAME, transportContext.getBackendName()); bundle.putInt(EVENT_PRIORITY, PriorityMapping.toInt(transportContext.getPriority())); if (transportContext.getExtras() != null) { bundle.putString(EXTRAS, encodeToString(transportContext.getExtras(), DEFAULT)); } builder.setExtras(bundle); Logging.d( LOG_TAG, "Scheduling upload for context %s with jobId=%d in %dms(Backend next call timestamp %d). Attempt %d", transportContext, jobId, config.getScheduleDelay(transportContext.getPriority(), nextCallTime, attemptNumber), nextCallTime, attemptNumber); jobScheduler.schedule(builder.build()); } JobInfoScheduler(
      Context applicationContext, EventStore eventStore, SchedulerConfig config); @Override void schedule(TransportContext transportContext, int attemptNumber);  }