@SuppressWarnings("ConstantConditions") private void testConstraints(JobRequest.Builder builder) { int jobId = builder .setRequiredNetworkType(JobRequest.NetworkType.METERED) .setRequiresBatteryNotLow(true) .setRequiresCharging(true) .setRequiresDeviceIdle(true) .setRequiresStorageNotLow(true) .build() .schedule(); String tag = JobProxyWorkManager.createTag(jobId); List<WorkInfo> statuses = mWorkManagerRule.getWorkStatus(tag); assertThat(statuses).isNotNull().hasSize(1); assertThat(statuses.get(0).getState()).isEqualTo(WorkInfo.State.ENQUEUED); mWorkManagerRule.getManager().cancelAllForTag(TAG); assertThat(mWorkManagerRule.getWorkStatus(tag).get(0).getState()).isEqualTo(WorkInfo.State.CANCELLED); } }
cancelAllForTag(request.getTag());
/** * All new Job classes need to be included in the factory method below */ @Override @Nullable public Job create(@NonNull final String tag) { if (D) UserError.Log.ueh("JobCreator", JoH.dateTimeText(JoH.tsl()) + " Passed: " + tag); switch (tag) { /* case CloudSyncJob.TAG: return new CloudSyncJob(); case DailyJob.TAG: return new DailyJob(); */ default: UserError.Log.wtf(TAG, "Failed to match Job: " + tag + " requesting cancellation"); try { JobManager.instance().cancelAllForTag(tag); } catch (Exception e) { // } return null; } } }
/** * All new Job classes need to be included in the factory method below */ @Override @Nullable public Job create(@NonNull final String tag) { if (D) UserError.Log.ueh("JobCreator", JoH.dateTimeText(JoH.tsl()) + " Passed: " + tag); switch (tag) { /* case CloudSyncJob.TAG: return new CloudSyncJob(); case DailyJob.TAG: return new DailyJob(); */ default: UserError.Log.wtf(TAG, "Failed to match Job: " + tag + " requesting cancellation"); try { JobManager.instance().cancelAllForTag(tag); } catch (Exception e) { // } return null; } } }
@Override public void onCreate() { super.onCreate(); JobManager.create(this).addJobCreator(new HookFetchJobCreator()); int noOfJobRequests = JobManager.instance().getAllJobRequestsForTag(HookFetchJob.TAG).size(); // No of Job Requests for HookFetchJob would be greater than 1 for older version of // application because of rescheduling of job again and again, causing large no. of wakelocks if (noOfJobRequests > 1) { JobManager.instance().cancelAllForTag(HookFetchJob.TAG); noOfJobRequests = 0; } if (noOfJobRequests == 0) { HookFetchJob.scheduleJob(); } }
cancelAllForTag(request.getTag());