@Override protected boolean isJobInfoScheduled(@Nullable JobInfo info, @NonNull JobRequest request) { return info != null && info.getId() == request.getJobId(); }
@SuppressWarnings("SimplifiableIfStatement") protected boolean isJobInfoScheduled(@Nullable JobInfo info, @NonNull JobRequest request) { boolean correctInfo = info != null && info.getId() == request.getJobId(); if (!correctInfo) { return false; } return !request.isTransient() || TransientBundleCompat.isScheduled(mContext, request.getJobId()); }
@Override public List<JobInfo> getAllPendingJobs() throws RemoteException { int vuid = VBinder.getCallingUid(); List<JobInfo> jobs = mScheduler.getAllPendingJobs(); synchronized (mJobStore) { Iterator<JobInfo> iterator = jobs.listIterator(); while (iterator.hasNext()) { JobInfo job = iterator.next(); if (!VASettings.STUB_JOB.equals(job.getService().getClassName())) { // Schedule by Host, invisible in VA. iterator.remove(); continue; } Map.Entry<JobId, JobConfig> jobEntry = findJobByVirtualJobId(job.getId()); if (jobEntry == null) { iterator.remove(); continue; } JobId jobId = jobEntry.getKey(); JobConfig config = jobEntry.getValue(); if (jobId.vuid != vuid) { iterator.remove(); continue; } mirror.android.app.job.JobInfo.jobId.set(job, jobId.clientJobId); mirror.android.app.job.JobInfo.service.set(job, new ComponentName(jobId.packageName, config.serviceName)); } } return jobs; }
public List<JobInfo> getAllPendingJobsFromScheduler() { JobScheduler jobScheduler = getJobScheduler(); ArrayList<JobInfo> jobs = new ArrayList<>(jobScheduler.getAllPendingJobs()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { Iterator<JobInfo> iterator = jobs.iterator(); while (iterator.hasNext()) { if (iterator.next().getId() == JobIdsInternal.JOB_ID_JOB_RESCHEDULE_SERVICE) { iterator.remove(); } } } return jobs; } }
@NonNull private JobParameters prepareJobParameters(SchedulerConstraint constraint) { JobInfo info = schedule(constraint); JobParameters params = mock(JobParameters.class); when(params.getExtras()).thenReturn(info.getExtras()); when(params.getJobId()).thenReturn(info.getId()); return params; }
private void networkTest(@NetworkUtil.NetworkStatus int networkType, int expected) { SchedulerConstraint constraint = mock(SchedulerConstraint.class); when(constraint.getNetworkStatus()).thenReturn(networkType); JobInfo jobInfo = schedule(constraint); assertThat(jobInfo.isPersisted(), is(true)); assertThat(jobInfo.getId(), is(1)); assertThat(jobInfo.getMinLatencyMillis(), is(0L)); assertThat(jobInfo.getMaxExecutionDelayMillis(), is(0L)); assertThat(jobInfo.getNetworkType(), is(expected)); }
@Test public void delay() { SchedulerConstraint constraint = mock(SchedulerConstraint.class); when(constraint.getNetworkStatus()).thenReturn(NetworkUtil.DISCONNECTED); when(constraint.getDelayInMs()).thenReturn(133L); JobInfo jobInfo = schedule(constraint); assertThat(jobInfo.isPersisted(), is(true)); assertThat(jobInfo.getId(), is(1)); assertThat(jobInfo.getMinLatencyMillis(), is(133L)); assertThat(jobInfo.getMaxExecutionDelayMillis(), is(0L)); }
@Test public void deadline() { SchedulerConstraint constraint = mock(SchedulerConstraint.class); when(constraint.getNetworkStatus()).thenReturn(NetworkUtil.DISCONNECTED); when(constraint.getOverrideDeadlineInMs()).thenReturn(255L); JobInfo jobInfo = schedule(constraint); assertThat(jobInfo.isPersisted(), is(true)); assertThat(jobInfo.getId(), is(1)); assertThat(jobInfo.getMinLatencyMillis(), is(0L)); assertThat(jobInfo.getMaxExecutionDelayMillis(), is(255L)); }
@Test public void deadlineAndDelay() { SchedulerConstraint constraint = mock(SchedulerConstraint.class); when(constraint.getNetworkStatus()).thenReturn(NetworkUtil.DISCONNECTED); when(constraint.getOverrideDeadlineInMs()).thenReturn(255L); when(constraint.getDelayInMs()).thenReturn(133L); JobInfo jobInfo = schedule(constraint); assertThat(jobInfo.isPersisted(), is(true)); assertThat(jobInfo.getId(), is(1)); assertThat(jobInfo.getMinLatencyMillis(), is(133L)); assertThat(jobInfo.getMaxExecutionDelayMillis(), is(255L)); }
@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); }
@Override public void writeResult(PrintWriter out) { out.println(String.format("Pending job %d %s", j.getId(), j.toString())); } });
private static boolean isJobPollServiceOn(Context context) { JobScheduler scheduler = (JobScheduler) context .getSystemService(Context.JOB_SCHEDULER_SERVICE); for (JobInfo jobInfo : scheduler.getAllPendingJobs()) { if (jobInfo.getId() == UPDATE_WIDGET_JOB_ID) { return true; } } return false; }
@Override protected boolean isJobInfoScheduled(@Nullable JobInfo info, @NonNull JobRequest request) { return info != null && info.getId() == request.getJobId(); }
@SuppressWarnings("SimplifiableIfStatement") protected boolean isJobInfoScheduled(@Nullable JobInfo info, @NonNull JobRequest request) { boolean correctInfo = info != null && info.getId() == request.getJobId(); if (!correctInfo) { return false; } return !request.isTransient() || TransientBundleCompat.isScheduled(mContext, request.getJobId()); }
private android.app.job.JobInfo getPendingJob(int jobId) { List<android.app.job.JobInfo> jobs = jobScheduler.getAllPendingJobs(); for (android.app.job.JobInfo job : jobs) { if (job.getId() == jobId) { return job; } } return null; }