@Test @SmallTest public void testGetStatusesSync() { OneTimeWorkRequest aWork = createTestWorker(); OneTimeWorkRequest bWork = createTestWorker(); OneTimeWorkRequest cWork = createTestWorker(); OneTimeWorkRequest dWork = createTestWorker(); WorkContinuation firstChain = mWorkManagerImpl.beginWith(aWork).then(bWork); WorkContinuation secondChain = mWorkManagerImpl.beginWith(cWork); WorkContinuation combined = WorkContinuation.combine(dWork, firstChain, secondChain); combined.synchronous().enqueueSync(); List<WorkStatus> statuses = combined.synchronous().getStatusesSync(); assertThat(statuses, is(notNullValue())); List<UUID> ids = new ArrayList<>(statuses.size()); for (WorkStatus status : statuses) { ids.add(status.getId()); } assertThat(ids, containsInAnyOrder( aWork.getId(), bWork.getId(), cWork.getId(), dWork.getId())); }
@Override public List<WorkStatus> getStatusesSync() { if (Looper.getMainLooper().getThread() == Thread.currentThread()) { throw new IllegalStateException("Cannot getStatusesSync on main thread!"); } return mWorkManagerImpl.getStatusesByIdSync(mAllIds); }
WorkContinuationImpl extends WorkContinuation implements SynchronousWorkContinuation { @Override public List<WorkStatus> getStatusesSync() { if (Looper.getMainLooper().getThread() == Thread.currentThread()) { throw new IllegalStateException("Cannot getStatusesSync on main thread!"); } return mWorkManagerImpl.getStatusesByIdSync(mAllIds); } }
WorkContinuationImpl extends WorkContinuation implements SynchronousWorkContinuation { @Override public List<WorkStatus> getStatusesSync() { if (Looper.getMainLooper().getThread() == Thread.currentThread()) { throw new IllegalStateException("Cannot getStatusesSync on main thread!"); } return mWorkManagerImpl.getStatusesByIdSync(mAllIds); } WorkContinuationImpl(
            @NonNull WorkManagerImpl workManagerImpl,
            @NonNull List<? extends WorkRequest> work);   WorkContinuationImpl(
            @NonNull WorkManagerImpl workManagerImpl,
            String name,
            ExistingWorkPolicy existingWorkPolicy,
            @NonNull List<? extends WorkRequest> work);   WorkContinuationImpl(@NonNull WorkManagerImpl workManagerImpl,
            String name,
            ExistingWorkPolicy existingWorkPolicy,
            @NonNull List<? extends WorkRequest> work,
            @Nullable List<WorkContinuationImpl> parents); }
WorkContinuationImpl extends WorkContinuation implements SynchronousWorkContinuation { @Override public List<WorkStatus> getStatusesSync() { if (Looper.getMainLooper().getThread() == Thread.currentThread()) { throw new IllegalStateException("Cannot getStatusesSync on main thread!"); } return mWorkManagerImpl.getStatusesByIdSync(mAllIds); } WorkContinuationImpl(
            @NonNull WorkManagerImpl workManagerImpl,
            @NonNull List<? extends WorkRequest> work);   WorkContinuationImpl(
            @NonNull WorkManagerImpl workManagerImpl,
            String name,
            ExistingWorkPolicy existingWorkPolicy,
            @NonNull List<? extends WorkRequest> work);   WorkContinuationImpl(@NonNull WorkManagerImpl workManagerImpl,
            String name,
            ExistingWorkPolicy existingWorkPolicy,
            @NonNull List<? extends WorkRequest> work,
            @Nullable List<WorkContinuationImpl> parents); @NonNull WorkManagerImpl getWorkManagerImpl(); @Nullable String getName(); ExistingWorkPolicy getExistingWorkPolicy(); @NonNull List<? extends WorkRequest> getWork(); @NonNull List<String> getIds(); List<String> getAllIds(); boolean isEnqueued(); void markEnqueued(); List<WorkContinuationImpl> getParents(); @Override WorkContinuation then(List<OneTimeWorkRequest> work); @Override LiveData<List<WorkStatus>> getStatuses(); @Override List<WorkStatus> getStatusesSync(); @Override void enqueue(); @Override @WorkerThread void enqueueSync(); @Override SynchronousWorkContinuation synchronous(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) boolean hasCycles(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) static Set<String> prerequisitesFor(WorkContinuationImpl continuation); }
WorkContinuationImpl extends WorkContinuation implements SynchronousWorkContinuation { @Override public List<WorkStatus> getStatusesSync() { if (Looper.getMainLooper().getThread() == Thread.currentThread()) { throw new IllegalStateException("Cannot getStatusesSync on main thread!"); } return mWorkManagerImpl.getStatusesByIdSync(mAllIds); } WorkContinuationImpl(
            @NonNull WorkManagerImpl workManagerImpl,
            @NonNull List<? extends WorkRequest> work);   WorkContinuationImpl(
            @NonNull WorkManagerImpl workManagerImpl,
            String name,
            ExistingWorkPolicy existingWorkPolicy,
            @NonNull List<? extends WorkRequest> work);   WorkContinuationImpl(@NonNull WorkManagerImpl workManagerImpl,
            String name,
            ExistingWorkPolicy existingWorkPolicy,
            @NonNull List<? extends WorkRequest> work,
            @Nullable List<WorkContinuationImpl> parents); @NonNull WorkManagerImpl getWorkManagerImpl(); @Nullable String getName(); ExistingWorkPolicy getExistingWorkPolicy(); @NonNull List<? extends WorkRequest> getWork(); @NonNull List<String> getIds(); List<String> getAllIds(); boolean isEnqueued(); void markEnqueued(); List<WorkContinuationImpl> getParents(); @Override WorkContinuation then(List<OneTimeWorkRequest> work); @Override LiveData<List<WorkStatus>> getStatuses(); @Override List<WorkStatus> getStatusesSync(); @Override void enqueue(); @Override @WorkerThread void enqueueSync(); @Override SynchronousWorkContinuation synchronous(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) boolean hasCycles(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) static Set<String> prerequisitesFor(WorkContinuationImpl continuation);  }