Java Code Examples for android.app.job.JobInfo#getExtras()
The following examples show how to use
android.app.job.JobInfo#getExtras() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobInfoSchedulerTest.java From firebase-android-sdk with Apache License 2.0 | 6 votes |
@Test public void schedule_twoJobs() { store.recordNextCallTime(TRANSPORT_CONTEXT, 5); int jobId = scheduler.getJobId(TRANSPORT_CONTEXT); // Schedule first job scheduler.schedule(TRANSPORT_CONTEXT, 1); assertThat(jobScheduler.getAllPendingJobs()).isNotEmpty(); assertThat(jobScheduler.getAllPendingJobs().size()).isEqualTo(1); // Schedule another job scheduler.schedule(TRANSPORT_CONTEXT, 2); assertThat(jobScheduler.getAllPendingJobs()).isNotEmpty(); assertThat(jobScheduler.getAllPendingJobs().size()).isEqualTo(1); // The job should be the second job. JobInfo jobInfo = jobScheduler.getAllPendingJobs().get(0); PersistableBundle bundle = jobInfo.getExtras(); assertThat(jobInfo.getId()).isEqualTo(jobId); assertThat(bundle.get(JobInfoScheduler.ATTEMPT_NUMBER)).isEqualTo(2); assertThat(bundle.get(JobInfoScheduler.BACKEND_NAME)) .isEqualTo(TRANSPORT_CONTEXT.getBackendName()); }
Example 2
Source File: JobInfoSchedulerTest.java From firebase-android-sdk with Apache License 2.0 | 6 votes |
@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)); }
Example 3
Source File: VJobSchedulerService.java From container with GNU General Public License v3.0 | 6 votes |
@Override public int schedule(JobInfo job) throws RemoteException { int vuid = VBinder.getCallingUid(); int id = job.getId(); ComponentName service = job.getService(); JobId jobId = new JobId(vuid, service.getPackageName(), id); JobConfig config = mJobStore.get(jobId); if (config == null) { config = new JobConfig(mGlobalJobId++, service.getClassName(), job.getExtras()); mJobStore.put(jobId, config); } else { config.serviceName = service.getClassName(); config.extras = job.getExtras(); } saveJobs(); mirror.android.app.job.JobInfo.jobId.set(job, config.virtualJobId); mirror.android.app.job.JobInfo.service.set(job, mJobProxyComponent); return mScheduler.schedule(job); }
Example 4
Source File: JobInfoSchedulerTest.java From firebase-android-sdk with Apache License 2.0 | 5 votes |
@Test public void schedule_longWaitTimeFirstAttempt() { store.recordNextCallTime(TRANSPORT_CONTEXT, 1000000); scheduler.schedule(TRANSPORT_CONTEXT, 1); int jobId = scheduler.getJobId(TRANSPORT_CONTEXT); assertThat(jobScheduler.getAllPendingJobs()).isNotEmpty(); assertThat(jobScheduler.getAllPendingJobs().size()).isEqualTo(1); JobInfo jobInfo = jobScheduler.getAllPendingJobs().get(0); PersistableBundle bundle = jobInfo.getExtras(); assertThat(jobInfo.getId()).isEqualTo(jobId); assertThat(bundle.get(JobInfoScheduler.BACKEND_NAME)) .isEqualTo(TRANSPORT_CONTEXT.getBackendName()); assertThat(bundle.get(JobInfoScheduler.ATTEMPT_NUMBER)).isEqualTo(1); assertThat(jobInfo.getMinLatencyMillis()).isEqualTo(999999); }
Example 5
Source File: JobInfoSchedulerTest.java From firebase-android-sdk with Apache License 2.0 | 5 votes |
@Test public void schedule_noTimeRecordedForBackend() { scheduler.schedule(TRANSPORT_CONTEXT, 1); int jobId = scheduler.getJobId(TRANSPORT_CONTEXT); assertThat(jobScheduler.getAllPendingJobs()).isNotEmpty(); assertThat(jobScheduler.getAllPendingJobs().size()).isEqualTo(1); JobInfo jobInfo = jobScheduler.getAllPendingJobs().get(0); PersistableBundle bundle = jobInfo.getExtras(); assertThat(jobInfo.getId()).isEqualTo(jobId); assertThat(bundle.get(JobInfoScheduler.BACKEND_NAME)) .isEqualTo(TRANSPORT_CONTEXT.getBackendName()); assertThat(bundle.get(JobInfoScheduler.ATTEMPT_NUMBER)).isEqualTo(1); assertThat(jobInfo.getMinLatencyMillis()).isEqualTo(THIRTY_SECONDS); // 2^0*DELTA }
Example 6
Source File: JobInfoSchedulerTest.java From firebase-android-sdk with Apache License 2.0 | 5 votes |
@Test public void schedule_smallWaitTImeFirstAttempt() { store.recordNextCallTime(TRANSPORT_CONTEXT, 5); scheduler.schedule(TRANSPORT_CONTEXT, 1); int jobId = scheduler.getJobId(TRANSPORT_CONTEXT); assertThat(jobScheduler.getAllPendingJobs()).isNotEmpty(); assertThat(jobScheduler.getAllPendingJobs().size()).isEqualTo(1); JobInfo jobInfo = jobScheduler.getAllPendingJobs().get(0); PersistableBundle bundle = jobInfo.getExtras(); assertThat(jobInfo.getId()).isEqualTo(jobId); assertThat(bundle.get(JobInfoScheduler.BACKEND_NAME)) .isEqualTo(TRANSPORT_CONTEXT.getBackendName()); assertThat(bundle.get(JobInfoScheduler.ATTEMPT_NUMBER)).isEqualTo(1); assertThat(jobInfo.getMinLatencyMillis()).isEqualTo(THIRTY_SECONDS); // 2^0*DELTA }
Example 7
Source File: JobInfoSchedulerTest.java From firebase-android-sdk with Apache License 2.0 | 5 votes |
@Test public void schedule_longWaitTimeTenthAttempt() { store.recordNextCallTime(TRANSPORT_CONTEXT, 1000000); scheduler.schedule(TRANSPORT_CONTEXT, 10); int jobId = scheduler.getJobId(TRANSPORT_CONTEXT); assertThat(jobScheduler.getAllPendingJobs()).isNotEmpty(); assertThat(jobScheduler.getAllPendingJobs().size()).isEqualTo(1); JobInfo jobInfo = jobScheduler.getAllPendingJobs().get(0); PersistableBundle bundle = jobInfo.getExtras(); assertThat(jobInfo.getId()).isEqualTo(jobId); assertThat(bundle.get(JobInfoScheduler.BACKEND_NAME)) .isEqualTo(TRANSPORT_CONTEXT.getBackendName()); assertThat(bundle.get(JobInfoScheduler.ATTEMPT_NUMBER)).isEqualTo(10); assertThat(jobInfo.getMinLatencyMillis()).isGreaterThan((long) 1000000); }
Example 8
Source File: JobInfoSchedulerTest.java From firebase-android-sdk with Apache License 2.0 | 5 votes |
@Test public void schedule_withMultipleContexts_whenExtrasAvailable_schedulesForBothContexts() { String extras1 = "e1"; String extras2 = "e2"; TransportContext ctx1 = TransportContext.builder() .setBackendName("backend1") .setExtras(extras1.getBytes(Charset.defaultCharset())) .build(); TransportContext ctx2 = TransportContext.builder() .setBackendName("backend1") .setExtras(extras2.getBytes(Charset.defaultCharset())) .build(); store.recordNextCallTime(ctx1, 1000000); store.recordNextCallTime(ctx2, 1000000); scheduler.schedule(ctx1, 1); scheduler.schedule(ctx2, 1); assertThat(jobScheduler.getAllPendingJobs()).hasSize(2); JobInfo jobInfo = jobScheduler.getAllPendingJobs().get(0); PersistableBundle bundle = jobInfo.getExtras(); assertThat(bundle.get(JobInfoScheduler.EXTRAS)) .isEqualTo( Base64.encodeToString(extras1.getBytes(Charset.defaultCharset()), Base64.DEFAULT)); jobInfo = jobScheduler.getAllPendingJobs().get(1); bundle = jobInfo.getExtras(); assertThat(bundle.get(JobInfoScheduler.EXTRAS)) .isEqualTo( Base64.encodeToString(extras2.getBytes(Charset.defaultCharset()), Base64.DEFAULT)); }
Example 9
Source File: JobInfoSchedulerTest.java From firebase-android-sdk with Apache License 2.0 | 5 votes |
@Test public void schedule_smallWaitTImeFirstAttempt_multiplePriorities() { store.recordNextCallTime(TRANSPORT_CONTEXT, 5); scheduler.schedule(TRANSPORT_CONTEXT, 1); scheduler.schedule(UNMETERED_TRANSPORT_CONTEXT, 1); int jobId1 = scheduler.getJobId(TRANSPORT_CONTEXT); int jobId2 = scheduler.getJobId(UNMETERED_TRANSPORT_CONTEXT); assertThat(jobScheduler.getAllPendingJobs()).isNotEmpty(); assertThat(jobScheduler.getAllPendingJobs().size()).isEqualTo(2); JobInfo jobInfo1 = jobScheduler.getAllPendingJobs().get(0); assertThat(jobInfo1.getId()).isEqualTo(jobId1); assertThat(jobInfo1.getMinLatencyMillis()).isEqualTo(THIRTY_SECONDS); // 2^0*DELTA PersistableBundle bundle1 = jobInfo1.getExtras(); assertThat(bundle1.get(JobInfoScheduler.BACKEND_NAME)) .isEqualTo(TRANSPORT_CONTEXT.getBackendName()); assertThat(bundle1.get(JobInfoScheduler.EVENT_PRIORITY)) .isEqualTo(PriorityMapping.toInt(Priority.DEFAULT)); assertThat(bundle1.get(JobInfoScheduler.ATTEMPT_NUMBER)).isEqualTo(1); JobInfo jobInfo2 = jobScheduler.getAllPendingJobs().get(1); assertThat(jobInfo2.getId()).isEqualTo(jobId2); assertThat(jobInfo2.getMinLatencyMillis()).isEqualTo(TWENTY_FOUR_HOURS); // 2^0*DELTA PersistableBundle bundle2 = jobInfo2.getExtras(); assertThat(bundle2.get(JobInfoScheduler.BACKEND_NAME)) .isEqualTo(UNMETERED_TRANSPORT_CONTEXT.getBackendName()); assertThat(bundle2.get(JobInfoScheduler.EVENT_PRIORITY)) .isEqualTo(PriorityMapping.toInt(Priority.VERY_LOW)); assertThat(bundle2.get(JobInfoScheduler.ATTEMPT_NUMBER)).isEqualTo(1); }