WorkManager 2.3.4 - new lint rule

Viewed 1144

I increased the version of my WorkManager to 2.3.4 and there is new lint rule called SpecifyJobSchedulerIdRange with description: "Warn when an app uses JobService but does not specify jobIds for WorkManager." and explanation:

When using JobScheduler APIs directly, WorkManager requires that developers specify a range of JobScheduler ids that are safe for WorkManager to use so the ids do not collide. For more information look at androidx.work.Configuration.Builder.setJobSchedulerJobIdRange(int, int).

I specified the range of ids WorkManager can use by function setJobSchedulerJobIdRange as I should but I still get that lint warning. It's weird that a get that lint warning by my custom JobService and not by the Configuration.Builder.

In my Application class:

override fun getWorkManagerConfiguration(): Configuration {
    return Configuration.Builder()
       .setWorkerFactory(workerFactory)
       .setJobSchedulerJobIdRange(100000, 101000)
       .build()
}
1 Answers

I came across this issue as well and spent some time looking at the code for the lint issue here, https://android.googlesource.com/platform/frameworks/support/+/androidx-master-dev/work/workmanager-lint/src/main/java/androidx/work/lint/SpecifyJobSchedulerIdRangeIssueDetector.kt

If Im not mistaken, the lint check looks for all classes which extend JobService, then makes sure that at least 1 of those classes calls androidx.work.Configuration.Builder.setJobSchedulerJobIdRange

I updated my 1 extension of JobService to provide the config as a static method to my application class and this solved the lint issue.

I am not really sure if its really a lint issue or not - it seems weird to have to declare the config for work manager in a JobService class, especially when its the Application class which needs it, but maybe that was their point? Make sure that the class using Job Ids sets it for everyone?

Related