@Test @LargeTest public void testInterruption() throws InterruptedException { OneTimeWorkRequest work = new OneTimeWorkRequest.Builder(TestWorker.class).build(); insertWork(work); WorkerWrapper workerWrapper = new WorkerWrapper.Builder(mContext, mConfiguration, mDatabase, work.getStringId()) .withSchedulers(Collections.singletonList(mMockScheduler)) .withListener(mMockListener) .build(); Executors.newSingleThreadExecutor().submit(workerWrapper); workerWrapper.interrupt(false); Thread.sleep(6000L); verify(mMockListener).onExecuted(work.getStringId(), false, true); }
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) public void interrupt(boolean cancelled) { mInterrupted = true; if (mWorker != null) { mWorker.stop(cancelled); } }
WorkerWrapper implements Runnable { @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) public void interrupt(boolean cancelled) { mInterrupted = true; if (mWorker != null) { mWorker.stop(cancelled); } } }
WorkerWrapper implements Runnable { @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) public void interrupt(boolean cancelled) { mInterrupted = true; if (mWorker != null) { mWorker.stop(cancelled); } } private  WorkerWrapper(Builder builder); }
WorkerWrapper implements Runnable { @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) public void interrupt(boolean cancelled) { mInterrupted = true; if (mWorker != null) { mWorker.stop(cancelled); } } private  WorkerWrapper(Builder builder); @WorkerThread @Override void run(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) void interrupt(boolean cancelled); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @SuppressWarnings("ClassNewInstance") static Worker workerFromClassName(
            @NonNull Context context,
            @NonNull String workerClassName,
            @NonNull UUID workSpecId,
            @NonNull Extras extras); }
WorkerWrapper implements Runnable { @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) public void interrupt(boolean cancelled) { mInterrupted = true; if (mWorker != null) { mWorker.stop(cancelled); } } private  WorkerWrapper(Builder builder); @WorkerThread @Override void run(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) void interrupt(boolean cancelled); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @SuppressWarnings("ClassNewInstance") static Worker workerFromClassName(
            @NonNull Context context,
            @NonNull String workerClassName,
            @NonNull UUID workSpecId,
            @NonNull Extras extras);  }