@Test @SmallTest public void testEnqueueUniquePeriodicWork_setsUniqueName() { final String uniqueName = "myname"; PeriodicWorkRequest periodicWork = new PeriodicWorkRequest.Builder( TestWorker.class, 15L, TimeUnit.MINUTES) .build(); mWorkManagerImpl.enqueueUniquePeriodicWorkSync( uniqueName, ExistingPeriodicWorkPolicy.REPLACE, periodicWork); List<String> workSpecIds = mDatabase.workNameDao().getWorkSpecIdsWithName(uniqueName); assertThat(periodicWork.getStringId(), isIn(workSpecIds)); }
@Override public void enqueueUniquePeriodicWorkSync( @NonNull String uniqueWorkName, @NonNull ExistingPeriodicWorkPolicy existingPeriodicWorkPolicy, @NonNull PeriodicWorkRequest periodicWork) { assertBackgroundThread("Cannot enqueueUniquePeriodicWorkSync on main thread!"); createWorkContinuationForUniquePeriodicWork( uniqueWorkName, existingPeriodicWorkPolicy, periodicWork) .enqueueSync(); }
WorkManagerImpl extends WorkManager implements SynchronousWorkManager { @Override public void enqueueUniquePeriodicWorkSync( @NonNull String uniqueWorkName, @NonNull ExistingPeriodicWorkPolicy existingPeriodicWorkPolicy, @NonNull PeriodicWorkRequest periodicWork) { assertBackgroundThread("Cannot enqueueUniquePeriodicWorkSync on main thread!"); createWorkContinuationForUniquePeriodicWork( uniqueWorkName, existingPeriodicWorkPolicy, periodicWork) .enqueueSync(); } }
WorkManagerImpl extends WorkManager implements SynchronousWorkManager { @Override public void enqueueUniquePeriodicWorkSync( @NonNull String uniqueWorkName, @NonNull ExistingPeriodicWorkPolicy existingPeriodicWorkPolicy, @NonNull PeriodicWorkRequest periodicWork) { assertBackgroundThread("Cannot enqueueUniquePeriodicWorkSync on main thread!"); createWorkContinuationForUniquePeriodicWork( uniqueWorkName, existingPeriodicWorkPolicy, periodicWork) .enqueueSync(); } @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)  WorkManagerImpl(
            @NonNull Context context,
            @NonNull Configuration configuration); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)  WorkManagerImpl(
            @NonNull Context context,
            @NonNull Configuration configuration,
            boolean useTestDatabase); }
WorkManagerImpl extends WorkManager implements SynchronousWorkManager { @Override public void enqueueUniquePeriodicWorkSync( @NonNull String uniqueWorkName, @NonNull ExistingPeriodicWorkPolicy existingPeriodicWorkPolicy, @NonNull PeriodicWorkRequest periodicWork) { assertBackgroundThread("Cannot enqueueUniquePeriodicWorkSync on main thread!"); createWorkContinuationForUniquePeriodicWork( uniqueWorkName, existingPeriodicWorkPolicy, periodicWork) .enqueueSync(); } @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)  WorkManagerImpl(
            @NonNull Context context,
            @NonNull Configuration configuration); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)  WorkManagerImpl(
            @NonNull Context context,
            @NonNull Configuration configuration,
            boolean useTestDatabase); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) static void setDelegate(WorkManagerImpl delegate); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) static WorkManagerImpl getInstance(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) static void initialize(@NonNull Context context, @NonNull Configuration configuration); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) Context getApplicationContext(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) WorkDatabase getWorkDatabase(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @NonNull Configuration getConfiguration(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @NonNull List<Scheduler> getSchedulers(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @NonNull Processor getProcessor(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @NonNull TaskExecutor getTaskExecutor(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @NonNull Preferences getPreferences(); @Override void enqueue(@NonNull List<? extends WorkRequest> workRequests); @Override void enqueueSync(@NonNull WorkRequest... workRequest); @Override void enqueueSync(@NonNull List<? extends WorkRequest> workRequest); @Override WorkContinuation beginWith(@NonNull List<OneTimeWorkRequest> work); @Override WorkContinuation beginUniqueWork(
            @NonNull String uniqueWorkName,
            @NonNull ExistingWorkPolicy existingWorkPolicy,
            @NonNull List<OneTimeWorkRequest> work); @Override void enqueueUniquePeriodicWork(
            @NonNull String uniqueWorkName,
            @NonNull ExistingPeriodicWorkPolicy existingPeriodicWorkPolicy,
            @NonNull PeriodicWorkRequest periodicWork); @Override void enqueueUniquePeriodicWorkSync(
            @NonNull String uniqueWorkName,
            @NonNull ExistingPeriodicWorkPolicy existingPeriodicWorkPolicy,
            @NonNull PeriodicWorkRequest periodicWork); @Override void cancelWorkById(@NonNull UUID id); @Override @WorkerThread void cancelWorkByIdSync(@NonNull UUID id); @Override void cancelAllWorkByTag(@NonNull final String tag); @Override @WorkerThread void cancelAllWorkByTagSync(@NonNull String tag); @Override void cancelUniqueWork(@NonNull String uniqueWorkName); @Override @WorkerThread void cancelUniqueWorkSync(@NonNull String uniqueWorkName); @Override void cancelAllWork(); @Override @WorkerThread void cancelAllWorkSync(); @Override LiveData<Long> getLastCancelAllTimeMillis(); @Override long getLastCancelAllTimeMillisSync(); @Override void pruneWork(); @Override @WorkerThread void pruneWorkSync(); @Override LiveData<WorkStatus> getStatusById(@NonNull UUID id); @Override @WorkerThread @Nullable WorkStatus getStatusByIdSync(@NonNull UUID id); @Override LiveData<List<WorkStatus>> getStatusesByTag(@NonNull String tag); @Override List<WorkStatus> getStatusesByTagSync(@NonNull String tag); @Override LiveData<List<WorkStatus>> getStatusesForUniqueWork(@NonNull String uniqueWorkName); @Override List<WorkStatus> getStatusesForUniqueWorkSync(@NonNull String uniqueWorkName); @Override SynchronousWorkManager synchronous(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) void startWork(String workSpecId); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) void startWork(String workSpecId, Extras.RuntimeExtras runtimeExtras); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) void stopWork(String workSpecId); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) void rescheduleEligibleWork(); }
WorkManagerImpl extends WorkManager implements SynchronousWorkManager { @Override public void enqueueUniquePeriodicWorkSync( @NonNull String uniqueWorkName, @NonNull ExistingPeriodicWorkPolicy existingPeriodicWorkPolicy, @NonNull PeriodicWorkRequest periodicWork) { assertBackgroundThread("Cannot enqueueUniquePeriodicWorkSync on main thread!"); createWorkContinuationForUniquePeriodicWork( uniqueWorkName, existingPeriodicWorkPolicy, periodicWork) .enqueueSync(); } @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)  WorkManagerImpl(
            @NonNull Context context,
            @NonNull Configuration configuration); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)  WorkManagerImpl(
            @NonNull Context context,
            @NonNull Configuration configuration,
            boolean useTestDatabase); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) static void setDelegate(WorkManagerImpl delegate); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) static WorkManagerImpl getInstance(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) static void initialize(@NonNull Context context, @NonNull Configuration configuration); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) Context getApplicationContext(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) WorkDatabase getWorkDatabase(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @NonNull Configuration getConfiguration(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @NonNull List<Scheduler> getSchedulers(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @NonNull Processor getProcessor(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @NonNull TaskExecutor getTaskExecutor(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @NonNull Preferences getPreferences(); @Override void enqueue(@NonNull List<? extends WorkRequest> workRequests); @Override void enqueueSync(@NonNull WorkRequest... workRequest); @Override void enqueueSync(@NonNull List<? extends WorkRequest> workRequest); @Override WorkContinuation beginWith(@NonNull List<OneTimeWorkRequest> work); @Override WorkContinuation beginUniqueWork(
            @NonNull String uniqueWorkName,
            @NonNull ExistingWorkPolicy existingWorkPolicy,
            @NonNull List<OneTimeWorkRequest> work); @Override void enqueueUniquePeriodicWork(
            @NonNull String uniqueWorkName,
            @NonNull ExistingPeriodicWorkPolicy existingPeriodicWorkPolicy,
            @NonNull PeriodicWorkRequest periodicWork); @Override void enqueueUniquePeriodicWorkSync(
            @NonNull String uniqueWorkName,
            @NonNull ExistingPeriodicWorkPolicy existingPeriodicWorkPolicy,
            @NonNull PeriodicWorkRequest periodicWork); @Override void cancelWorkById(@NonNull UUID id); @Override @WorkerThread void cancelWorkByIdSync(@NonNull UUID id); @Override void cancelAllWorkByTag(@NonNull final String tag); @Override @WorkerThread void cancelAllWorkByTagSync(@NonNull String tag); @Override void cancelUniqueWork(@NonNull String uniqueWorkName); @Override @WorkerThread void cancelUniqueWorkSync(@NonNull String uniqueWorkName); @Override void cancelAllWork(); @Override @WorkerThread void cancelAllWorkSync(); @Override LiveData<Long> getLastCancelAllTimeMillis(); @Override long getLastCancelAllTimeMillisSync(); @Override void pruneWork(); @Override @WorkerThread void pruneWorkSync(); @Override LiveData<WorkStatus> getStatusById(@NonNull UUID id); @Override @WorkerThread @Nullable WorkStatus getStatusByIdSync(@NonNull UUID id); @Override LiveData<List<WorkStatus>> getStatusesByTag(@NonNull String tag); @Override List<WorkStatus> getStatusesByTagSync(@NonNull String tag); @Override LiveData<List<WorkStatus>> getStatusesForUniqueWork(@NonNull String uniqueWorkName); @Override List<WorkStatus> getStatusesForUniqueWorkSync(@NonNull String uniqueWorkName); @Override SynchronousWorkManager synchronous(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) void startWork(String workSpecId); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) void startWork(String workSpecId, Extras.RuntimeExtras runtimeExtras); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) void stopWork(String workSpecId); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) void rescheduleEligibleWork(); static final int MAX_PRE_JOB_SCHEDULER_API_LEVEL; static final int MIN_JOB_SCHEDULER_API_LEVEL; }