evant/JobSchedulerCompat — pull request #13 by mironov-nsk (2014-12-26 19:04:07+00:00)
Title: Fix IllegalArgumentException

Hello.

The following code produces an `IllegalArgumentException` on Lollipop devices.

```java
JobScheduler.getInstance(context).schedule(new JobInfo.Builder(JOB_SYNC, new ComponentName(context, SyncService.class))
.setPeriodic(TimeUnit.DAYS.toMillis(1))
.setRequiresDeviceIdle(true)
.setRequiresCharging(false)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.setPersisted(true)
.build()
);
```

Stack trace:
```
java.lang.IllegalArgumentException: An idle mode job will not respect any back-off policy, so calling setBackoffCriteria with setRequiresDeviceIdle is an error.
at android.app.job.JobInfo$Builder.build(JobInfo.java:465)
at me.tatarka.support.internal.JobSchedulerLollipopDelegate.convertJobInfo(JobSchedulerLollipopDelegate.java:79)
at me.tatarka.support.internal.JobSchedulerLollipopDelegate.schedule(JobSchedulerLollipopDelegate.java:53)
```

The reason is that `JobInfo.Builder` documentation [explicitly prohibits](https://developer.android.com/reference/android/app/job/JobInfo.Builder.html#setBackoffCriteria(long, int)) to use `setRequiresDeviceIdle(true)` and `setBackoffCriteria ` at the same time.
```
Note that trying to set a backoff criteria for a job with setRequiresDeviceIdle(boolean) will throw an exception when you call build().
```

The code above uses only `setRequiresDeviceIdle(true)` so it's totaly correct, but `JobSchedulerLollipopDelegate. convertJobInfo` and `JobSchedulerLollipopDelegate. convertFromJobInfo` fail to follow the restrictions.