@Test @LargeTest @SdkSuppress(minSdkVersion = 24) public void testStartJob_PassesContentUriTriggers() throws InterruptedException { if (Build.VERSION.SDK_INT < WorkManagerImpl.MIN_JOB_SCHEDULER_API_LEVEL) { return; } OneTimeWorkRequest work = new OneTimeWorkRequest.Builder(ContentUriTriggerLoggingWorker.class).build(); insertWork(work); final String[] testContentAuthorities = new String[] { work.getStringId(), "yet another " + work.getStringId() }; final Uri[] testContentUris = new Uri[] { Uri.parse("http: Uri.parse("http: }; JobParameters mockParams = createMockJobParameters(work.getStringId()); when(mockParams.getTriggeredContentAuthorities()).thenReturn(testContentAuthorities); when(mockParams.getTriggeredContentUris()).thenReturn(testContentUris); assertThat(ContentUriTriggerLoggingWorker.sTimesUpdated, is(0)); assertThat(mSystemJobServiceSpy.onStartJob(mockParams), is(true)); Thread.sleep(1000L); assertThat(ContentUriTriggerLoggingWorker.sTimesUpdated, is(1)); assertThat(ContentUriTriggerLoggingWorker.sTriggeredContentAuthorities, is(testContentAuthorities)); assertThat(ContentUriTriggerLoggingWorker.sTriggeredContentUris, is(testContentUris)); }
@Override public boolean onStartJob(JobParameters params) { PersistableBundle extras = params.getExtras(); String workSpecId = extras.getString(SystemJobInfoConverter.EXTRA_WORK_SPEC_ID); if (TextUtils.isEmpty(workSpecId)) { Log.e(TAG, "WorkSpec id not found!"); return false; } synchronized (mJobParameters) { if (mJobParameters.containsKey(workSpecId)) { Log.d(TAG, String.format( "Job is already being executed by SystemJobService: %s", workSpecId)); return false; } boolean isPeriodic = extras.getBoolean(SystemJobInfoConverter.EXTRA_IS_PERIODIC, false); if (isPeriodic && params.isOverrideDeadlineExpired()) { Log.d(TAG, String.format( "Override deadline expired for id %s. Retry requested", workSpecId)); jobFinished(params, true); return false; } Log.d(TAG, String.format("onStartJob for %s", workSpecId)); mJobParameters.put(workSpecId, params); } Extras.RuntimeExtras runtimeExtras = null; if (Build.VERSION.SDK_INT >= 24) { runtimeExtras = new Extras.RuntimeExtras(); if (params.getTriggeredContentUris() != null || params.getTriggeredContentAuthorities() != null) { runtimeExtras.triggeredContentUris = params.getTriggeredContentUris(); runtimeExtras.triggeredContentAuthorities = params.getTriggeredContentAuthorities(); } if (Build.VERSION.SDK_INT >= 28) { runtimeExtras.network = params.getNetwork(); } } mWorkManagerImpl.startWork(workSpecId, runtimeExtras); return true; }
SystemJobService extends JobService implements ExecutionListener { @Override public boolean onStartJob(JobParameters params) { PersistableBundle extras = params.getExtras(); String workSpecId = extras.getString(SystemJobInfoConverter.EXTRA_WORK_SPEC_ID); if (TextUtils.isEmpty(workSpecId)) { Log.e(TAG, "WorkSpec id not found!"); return false; } synchronized (mJobParameters) { if (mJobParameters.containsKey(workSpecId)) { Log.d(TAG, String.format( "Job is already being executed by SystemJobService: %s", workSpecId)); return false; } boolean isPeriodic = extras.getBoolean(SystemJobInfoConverter.EXTRA_IS_PERIODIC, false); if (isPeriodic && params.isOverrideDeadlineExpired()) { Log.d(TAG, String.format( "Override deadline expired for id %s. Retry requested", workSpecId)); jobFinished(params, true); return false; } Log.d(TAG, String.format("onStartJob for %s", workSpecId)); mJobParameters.put(workSpecId, params); } Extras.RuntimeExtras runtimeExtras = null; if (Build.VERSION.SDK_INT >= 24) { runtimeExtras = new Extras.RuntimeExtras(); if (params.getTriggeredContentUris() != null || params.getTriggeredContentAuthorities() != null) { runtimeExtras.triggeredContentUris = params.getTriggeredContentUris(); runtimeExtras.triggeredContentAuthorities = params.getTriggeredContentAuthorities(); } if (Build.VERSION.SDK_INT >= 28) { runtimeExtras.network = params.getNetwork(); } } mWorkManagerImpl.startWork(workSpecId, runtimeExtras); return true; } }
SystemJobService extends JobService implements ExecutionListener { @Override public boolean onStartJob(JobParameters params) { PersistableBundle extras = params.getExtras(); String workSpecId = extras.getString(SystemJobInfoConverter.EXTRA_WORK_SPEC_ID); if (TextUtils.isEmpty(workSpecId)) { Log.e(TAG, "WorkSpec id not found!"); return false; } synchronized (mJobParameters) { if (mJobParameters.containsKey(workSpecId)) { Log.d(TAG, String.format( "Job is already being executed by SystemJobService: %s", workSpecId)); return false; } boolean isPeriodic = extras.getBoolean(SystemJobInfoConverter.EXTRA_IS_PERIODIC, false); if (isPeriodic && params.isOverrideDeadlineExpired()) { Log.d(TAG, String.format( "Override deadline expired for id %s. Retry requested", workSpecId)); jobFinished(params, true); return false; } Log.d(TAG, String.format("onStartJob for %s", workSpecId)); mJobParameters.put(workSpecId, params); } Extras.RuntimeExtras runtimeExtras = null; if (Build.VERSION.SDK_INT >= 24) { runtimeExtras = new Extras.RuntimeExtras(); if (params.getTriggeredContentUris() != null || params.getTriggeredContentAuthorities() != null) { runtimeExtras.triggeredContentUris = params.getTriggeredContentUris(); runtimeExtras.triggeredContentAuthorities = params.getTriggeredContentAuthorities(); } if (Build.VERSION.SDK_INT >= 28) { runtimeExtras.network = params.getNetwork(); } } mWorkManagerImpl.startWork(workSpecId, runtimeExtras); return true; }  }
SystemJobService extends JobService implements ExecutionListener { @Override public boolean onStartJob(JobParameters params) { PersistableBundle extras = params.getExtras(); String workSpecId = extras.getString(SystemJobInfoConverter.EXTRA_WORK_SPEC_ID); if (TextUtils.isEmpty(workSpecId)) { Log.e(TAG, "WorkSpec id not found!"); return false; } synchronized (mJobParameters) { if (mJobParameters.containsKey(workSpecId)) { Log.d(TAG, String.format( "Job is already being executed by SystemJobService: %s", workSpecId)); return false; } boolean isPeriodic = extras.getBoolean(SystemJobInfoConverter.EXTRA_IS_PERIODIC, false); if (isPeriodic && params.isOverrideDeadlineExpired()) { Log.d(TAG, String.format( "Override deadline expired for id %s. Retry requested", workSpecId)); jobFinished(params, true); return false; } Log.d(TAG, String.format("onStartJob for %s", workSpecId)); mJobParameters.put(workSpecId, params); } Extras.RuntimeExtras runtimeExtras = null; if (Build.VERSION.SDK_INT >= 24) { runtimeExtras = new Extras.RuntimeExtras(); if (params.getTriggeredContentUris() != null || params.getTriggeredContentAuthorities() != null) { runtimeExtras.triggeredContentUris = params.getTriggeredContentUris(); runtimeExtras.triggeredContentAuthorities = params.getTriggeredContentAuthorities(); } if (Build.VERSION.SDK_INT >= 28) { runtimeExtras.network = params.getNetwork(); } } mWorkManagerImpl.startWork(workSpecId, runtimeExtras); return true; }  @Override void onCreate(); @Override void onDestroy(); @Override boolean onStartJob(JobParameters params); @Override boolean onStopJob(JobParameters params); @Override void onExecuted(
            @NonNull String workSpecId,
            boolean isSuccessful,
            boolean needsReschedule); }
SystemJobService extends JobService implements ExecutionListener { @Override public boolean onStartJob(JobParameters params) { PersistableBundle extras = params.getExtras(); String workSpecId = extras.getString(SystemJobInfoConverter.EXTRA_WORK_SPEC_ID); if (TextUtils.isEmpty(workSpecId)) { Log.e(TAG, "WorkSpec id not found!"); return false; } synchronized (mJobParameters) { if (mJobParameters.containsKey(workSpecId)) { Log.d(TAG, String.format( "Job is already being executed by SystemJobService: %s", workSpecId)); return false; } boolean isPeriodic = extras.getBoolean(SystemJobInfoConverter.EXTRA_IS_PERIODIC, false); if (isPeriodic && params.isOverrideDeadlineExpired()) { Log.d(TAG, String.format( "Override deadline expired for id %s. Retry requested", workSpecId)); jobFinished(params, true); return false; } Log.d(TAG, String.format("onStartJob for %s", workSpecId)); mJobParameters.put(workSpecId, params); } Extras.RuntimeExtras runtimeExtras = null; if (Build.VERSION.SDK_INT >= 24) { runtimeExtras = new Extras.RuntimeExtras(); if (params.getTriggeredContentUris() != null || params.getTriggeredContentAuthorities() != null) { runtimeExtras.triggeredContentUris = params.getTriggeredContentUris(); runtimeExtras.triggeredContentAuthorities = params.getTriggeredContentAuthorities(); } if (Build.VERSION.SDK_INT >= 28) { runtimeExtras.network = params.getNetwork(); } } mWorkManagerImpl.startWork(workSpecId, runtimeExtras); return true; }  @Override void onCreate(); @Override void onDestroy(); @Override boolean onStartJob(JobParameters params); @Override boolean onStopJob(JobParameters params); @Override void onExecuted(
            @NonNull String workSpecId,
            boolean isSuccessful,
            boolean needsReschedule);  }