@Test @SmallTest public void testGreedyScheduler_ignoresPeriodicWork() { PeriodicWorkRequest periodicWork = new PeriodicWorkRequest.Builder(TestWorker.class, 0L, TimeUnit.MILLISECONDS) .build(); mGreedyScheduler.schedule(getWorkSpec(periodicWork)); verify(mMockWorkConstraintsTracker, never()).replace(ArgumentMatchers.<WorkSpec>anyList()); }
@Override public synchronized void schedule(WorkSpec... workSpecs) { int originalSize = mConstrainedWorkSpecs.size(); for (WorkSpec workSpec : workSpecs) { if (workSpec.state == State.ENQUEUED && !workSpec.isPeriodic() && workSpec.initialDelay == 0L) { if (workSpec.hasConstraints()) { if (Build.VERSION.SDK_INT < 24 || !workSpec.constraints.hasContentUriTriggers()) { Log.d(TAG, String.format("Starting tracking for %s", workSpec.id)); mConstrainedWorkSpecs.add(workSpec); } } else { mWorkManagerImpl.startWork(workSpec.id); } } } if (originalSize != mConstrainedWorkSpecs.size()) { mWorkConstraintsTracker.replace(mConstrainedWorkSpecs); } }
GreedyScheduler implements Scheduler, WorkConstraintsCallback, ExecutionListener { @Override public synchronized void schedule(WorkSpec... workSpecs) { int originalSize = mConstrainedWorkSpecs.size(); for (WorkSpec workSpec : workSpecs) { if (workSpec.state == State.ENQUEUED && !workSpec.isPeriodic() && workSpec.initialDelay == 0L) { if (workSpec.hasConstraints()) { if (Build.VERSION.SDK_INT < 24 || !workSpec.constraints.hasContentUriTriggers()) { Log.d(TAG, String.format("Starting tracking for %s", workSpec.id)); mConstrainedWorkSpecs.add(workSpec); } } else { mWorkManagerImpl.startWork(workSpec.id); } } } if (originalSize != mConstrainedWorkSpecs.size()) { mWorkConstraintsTracker.replace(mConstrainedWorkSpecs); } } }
GreedyScheduler implements Scheduler, WorkConstraintsCallback, ExecutionListener { @Override public synchronized void schedule(WorkSpec... workSpecs) { int originalSize = mConstrainedWorkSpecs.size(); for (WorkSpec workSpec : workSpecs) { if (workSpec.state == State.ENQUEUED && !workSpec.isPeriodic() && workSpec.initialDelay == 0L) { if (workSpec.hasConstraints()) { if (Build.VERSION.SDK_INT < 24 || !workSpec.constraints.hasContentUriTriggers()) { Log.d(TAG, String.format("Starting tracking for %s", workSpec.id)); mConstrainedWorkSpecs.add(workSpec); } } else { mWorkManagerImpl.startWork(workSpec.id); } } } if (originalSize != mConstrainedWorkSpecs.size()) { mWorkConstraintsTracker.replace(mConstrainedWorkSpecs); } } GreedyScheduler(Context context, WorkManagerImpl workManagerImpl); @VisibleForTesting  GreedyScheduler(WorkManagerImpl workManagerImpl,
            WorkConstraintsTracker workConstraintsTracker); }
GreedyScheduler implements Scheduler, WorkConstraintsCallback, ExecutionListener { @Override public synchronized void schedule(WorkSpec... workSpecs) { int originalSize = mConstrainedWorkSpecs.size(); for (WorkSpec workSpec : workSpecs) { if (workSpec.state == State.ENQUEUED && !workSpec.isPeriodic() && workSpec.initialDelay == 0L) { if (workSpec.hasConstraints()) { if (Build.VERSION.SDK_INT < 24 || !workSpec.constraints.hasContentUriTriggers()) { Log.d(TAG, String.format("Starting tracking for %s", workSpec.id)); mConstrainedWorkSpecs.add(workSpec); } } else { mWorkManagerImpl.startWork(workSpec.id); } } } if (originalSize != mConstrainedWorkSpecs.size()) { mWorkConstraintsTracker.replace(mConstrainedWorkSpecs); } } GreedyScheduler(Context context, WorkManagerImpl workManagerImpl); @VisibleForTesting  GreedyScheduler(WorkManagerImpl workManagerImpl,
            WorkConstraintsTracker workConstraintsTracker); @Override synchronized void schedule(WorkSpec... workSpecs); @Override synchronized void cancel(@NonNull String workSpecId); @Override synchronized void onAllConstraintsMet(@NonNull List<String> workSpecIds); @Override synchronized void onAllConstraintsNotMet(@NonNull List<String> workSpecIds); @Override synchronized void onExecuted(@NonNull String workSpecId,
            boolean isSuccessful,
            boolean needsReschedule); }
GreedyScheduler implements Scheduler, WorkConstraintsCallback, ExecutionListener { @Override public synchronized void schedule(WorkSpec... workSpecs) { int originalSize = mConstrainedWorkSpecs.size(); for (WorkSpec workSpec : workSpecs) { if (workSpec.state == State.ENQUEUED && !workSpec.isPeriodic() && workSpec.initialDelay == 0L) { if (workSpec.hasConstraints()) { if (Build.VERSION.SDK_INT < 24 || !workSpec.constraints.hasContentUriTriggers()) { Log.d(TAG, String.format("Starting tracking for %s", workSpec.id)); mConstrainedWorkSpecs.add(workSpec); } } else { mWorkManagerImpl.startWork(workSpec.id); } } } if (originalSize != mConstrainedWorkSpecs.size()) { mWorkConstraintsTracker.replace(mConstrainedWorkSpecs); } } GreedyScheduler(Context context, WorkManagerImpl workManagerImpl); @VisibleForTesting  GreedyScheduler(WorkManagerImpl workManagerImpl,
            WorkConstraintsTracker workConstraintsTracker); @Override synchronized void schedule(WorkSpec... workSpecs); @Override synchronized void cancel(@NonNull String workSpecId); @Override synchronized void onAllConstraintsMet(@NonNull List<String> workSpecIds); @Override synchronized void onAllConstraintsNotMet(@NonNull List<String> workSpecIds); @Override synchronized void onExecuted(@NonNull String workSpecId,
            boolean isSuccessful,
            boolean needsReschedule);  }