/* package */ synchronized ExecutionDelegator getExecutionDelegator() { if (executionDelegator == null) { executionDelegator = new ExecutionDelegator(this, this, new ConstraintChecker(getApplicationContext())); } return executionDelegator; }
/** * Returns true iff all the specified job constraints are satisfied. Note: At the moment this * method only checks for network constraints and nothing more. * * @param job the job whose constraints are to be checked. */ public boolean areConstraintsSatisfied(JobInvocation job) { int jobConstraints = Constraint.compact(job.getConstraints()); return areNetworkConstraintsSatisfied(jobConstraints); }
private void reschedule(JobInvocation jobInvocation) { Job job = new Builder(getValidationEnforcer(), jobInvocation).setReplaceCurrent(true).build(); getGooglePlayDriver().schedule(job); }
private static Builder initializeDefaultBuilder() { return TestUtil.getBuilderWithNoopValidator() .setConstraints(Constraint.DEVICE_CHARGING) .setExtras(null) .setLifetime(Lifetime.FOREVER) .setRecurring(false) .setReplaceCurrent(false) .setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL) .setService(TestJobService.class) .setTag("tag") .setTrigger(Trigger.NOW); }
@Test public void onReschedule_notRunningWrongTag_noException() { Bundle bundle = TestUtil.getBundleForContentJobExecution(); Job job = TestUtil.getBuilderWithNoopValidator() .setService(TestJobService.class) .setTrigger(Trigger.NOW) .setTag("TAG") .build(); receiver.prepareJob(jobCallbackMock, bundle); GooglePlayReceiver.onSchedule(job); }
@Test public void onReschedule_notRunning_noException() { Job job = TestUtil.getBuilderWithNoopValidator() .setService(TestJobService.class) .setTrigger(Trigger.NOW) .setTag("TAG") .build(); GooglePlayReceiver.onSchedule(job); }
@Test public void testCodingForExtras() { Bundle extras = new Bundle(); extras.putString("foo", "bar"); builder.setExtras(extras); Bundle deserializedExtras = coder .decode(coder.encode(setValidBuilderDefaults(builder).build(), new Bundle())) .build() .getExtras(); assertBundlesEqual(extras, deserializedExtras); }
@Test public void onJobFinished_notRecurringContentJob_sendResult() { jobInvocationBuilder.setTrigger( Trigger.contentUriTrigger(Arrays.asList(new ObservedUri(Contacts.CONTENT_URI, 0)))); JobInvocation jobInvocation = receiver.prepareJob(callbackMock, TestUtil.getBundleForContentJobExecution()); receiver.onJobFinished(jobInvocation, JobService.RESULT_SUCCESS); verify(callbackMock).jobFinished(JobService.RESULT_SUCCESS); verifyZeroInteractions(driverMock); }
@Test public void decode_contentUriTrigger() { ContentUriTrigger contentUriTrigger = TestUtil.getContentUriTrigger(); Bundle bundle = TestUtil.encodeContentUriJob(contentUriTrigger, coder); JobInvocation decode = coder.decode(bundle).build(); ContentUriTrigger trigger = (ContentUriTrigger) decode.getTrigger(); assertEquals(contentUriTrigger.getUris(), trigger.getUris()); }
@Override public void jobFinished(Bundle invocationData, @JobService.JobResult int result) { JobInvocation.Builder invocation = getJobCoder().decode(invocationData); if (invocation == null) { Log.wtf(TAG, "jobFinished: unknown invocation provided"); return; } ExecutionDelegator.this.onJobFinishedMessage(invocation.build(), result); } };
private static void writeRetryStrategyToBundle(JobParameters job, Bundle b) { RetryStrategy strategy = job.getRetryStrategy(); Bundle rb = new Bundle(); rb.putInt( REQUEST_PARAM_RETRY_STRATEGY_POLICY, convertRetryPolicyToLegacyVersion(strategy.getPolicy())); rb.putInt(REQUEST_PARAM_RETRY_STRATEGY_INITIAL_BACKOFF_SECONDS, strategy.getInitialBackoff()); rb.putInt(REQUEST_PARAM_RETRY_STRATEGY_MAXIMUM_BACKOFF_SECONDS, strategy.getMaximumBackoff()); b.putBundle(REQUEST_PARAM_RETRY_STRATEGY, rb); }
private void handleStopMessage(Message message) { Builder builder = GooglePlayReceiver.getJobCoder().decode(message.getData()); if (builder == null) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Invalid stop execution message."); } return; } JobInvocation job = builder.build(); ExecutionDelegator.stopJob(job, true); } }
@NonNull private synchronized ValidationEnforcer getValidationEnforcer() { if (validationEnforcer == null) { validationEnforcer = new ValidationEnforcer(getGooglePlayDriver().getValidator()); } return validationEnforcer; }
/** Instantiates a new FirebaseJobDispatcher using the provided Driver. */ public FirebaseJobDispatcher(@NonNull Driver driver) { this.driver = driver; validator = new ValidationEnforcer(driver.getValidator()); retryStrategyBuilder = new RetryStrategy.Builder(validator); }
@Override public void start(Bundle invocationData, IJobCallback callback) { jobParametersAtomicReference.set( GooglePlayReceiver.getJobCoder().decode(invocationData).build()); }
@Test public void prepareJob_messenger_noExtras() { Bundle bundle = TestUtil.getBundleForContentJobExecution(); JobInvocation jobInvocation = receiver.prepareJob(callbackMock, bundle); assertEquals(jobInvocation.getTriggerReason().getTriggeredContentUris(), TestUtil.URIS); }
private void requestRetryForJob(JobInvocation job) { try { callback.jobFinished(encodeJob(job), JobService.RESULT_FAIL_RETRY); } catch (RemoteException e) { Log.e(TAG, "Error sending result for job " + job.getTag() + ": " + e); } } }
private static void writeConstraintsToBundle(JobParameters job, Bundle b) { int c = Constraint.compact(job.getConstraints()); b.putBoolean( REQUEST_PARAM_REQUIRES_CHARGING, (c & Constraint.DEVICE_CHARGING) == Constraint.DEVICE_CHARGING); b.putBoolean( REQUEST_PARAM_REQUIRES_IDLE, (c & Constraint.DEVICE_IDLE) == Constraint.DEVICE_IDLE); b.putInt(REQUEST_PARAM_REQUIRED_NETWORK, convertConstraintsToLegacyNetConstant(c)); }
/** Returns true if any of the given {@code jobConstraints} require a network. */ private static boolean wantsNetwork(@JobConstraint int jobConstraints) { return wantsAnyNetwork(jobConstraints) || wantsUnmeteredNetwork(jobConstraints); }
static List<Job> getJobCombinations(Builder builder) { return getCombination(new JobBuilder(builder)); }