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)); }
@NonNull Bundle encode(@NonNull JobParameters jobParameters, @NonNull Bundle data) { if (data == null) { throw new IllegalArgumentException("Unexpected null Bundle provided"); } Bundle userExtras = jobParameters.getExtras(); if (userExtras != null) { data.putAll(userExtras); } data.putInt(prefix + BundleProtocol.PACKED_PARAM_LIFETIME, jobParameters.getLifetime()); data.putBoolean(prefix + BundleProtocol.PACKED_PARAM_RECURRING, jobParameters.isRecurring()); data.putBoolean( prefix + BundleProtocol.PACKED_PARAM_REPLACE_CURRENT, jobParameters.shouldReplaceCurrent()); data.putString(prefix + BundleProtocol.PACKED_PARAM_TAG, jobParameters.getTag()); data.putString(prefix + BundleProtocol.PACKED_PARAM_SERVICE, jobParameters.getService()); data.putInt( prefix + BundleProtocol.PACKED_PARAM_CONSTRAINTS, compact(jobParameters.getConstraints())); encodeTrigger(jobParameters.getTrigger(), data); encodeRetryStrategy(jobParameters.getRetryStrategy(), data); return data; }
Builder(@NonNull ValidationEnforcer validator, JobParameters job) { this.validator = validator; tag = job.getTag(); serviceClassName = job.getService(); trigger = job.getTrigger(); recurring = job.isRecurring(); lifetime = job.getLifetime(); constraints = job.getConstraints(); extras = job.getExtras(); retryStrategy = job.getRetryStrategy(); }
static void assertJobsEqual(JobParameters input, JobParameters output) { assertNotNull("input", input); assertNotNull("output", output); assertEquals("isRecurring()", input.isRecurring(), output.isRecurring()); assertEquals( "shouldReplaceCurrent()", input.shouldReplaceCurrent(), output.shouldReplaceCurrent()); assertEquals("getLifetime()", input.getLifetime(), output.getLifetime()); assertEquals("getTag()", input.getTag(), output.getTag()); assertEquals("getService()", input.getService(), output.getService()); assertEquals( "getConstraints()", Constraint.compact(input.getConstraints()), Constraint.compact(output.getConstraints())); assertTriggersEqual(input.getTrigger(), output.getTrigger()); assertBundlesEqual(input.getExtras(), output.getExtras()); assertRetryStrategiesEqual(input.getRetryStrategy(), output.getRetryStrategy()); }