-
Notifications
You must be signed in to change notification settings - Fork 76
Bug fix: Rescheduling has problem (refers to issues #25 and #18) #28
Description
The problem is occurred when you've recently scheduled an unmetered network triggered periodic job and after a while you want to schedule another job(e.g. an unmetered network triggered periodic job as the second job).
Issue : When the 2'nd job is going to add, the job scheduler stops the first job and in the following needs to reschedule it again. The scheduler probably has missed some operations within rescheduling process.
Solution : If you review the "scheduleJob(JobStatus job) { ... }" method in the "me.tatarka.support.internal.job.JobServiceCompat" class, you can find out there is a bug in the "me.tatarka.support.internal.job.JobSchedulerService" class exactly the "rescheduleJob(JobStatus job, boolean wasFailure) { ... }" method and you must change it. In the following there is a new implementation of the mentioned method.
In the JobSchedulerService class ==>
private void rescheduleJob(JobStatus job, boolean wasFailure) {
JobStatus newJob;
if (wasFailure) {
newJob = rescheduleFailedJob(job);
} else {
newJob = reschedulePeriodicJob(job);
}
JobStore jobStore = JobStore.initAndGet(this);
synchronized (jobStore) {
jobStore.remove(job);
jobStore.add(newJob);
}
TimeReceiver.setAlarmsForJob(this, newJob);
if (job.hasIdleConstraint()) {
IdleReceiver.setIdleForJob(this, newJob);
}
/**
* The following constraints must be set and it is clear that those probably were forgotten
*/
if (newJob.hasConnectivityConstraint() || newJob.hasUnmeteredConstraint()) {
NetworkReceiver.setNetworkForJob(this, newJob);
ReceiverUtils.enable(this, NetworkReceiver.class);
}
if (job.hasChargingConstraint()) {
PowerReceiver.setPowerForJob(this, job);
ReceiverUtils.enable(this, PowerReceiver.class);
}
if (job.isPersisted()) {
ReceiverUtils.enable(this, BootReceiver.class);
}
}
It is tested for 10 unmetered network triggered periodic job ( every job had a period of 500ms) and their worked without any error nonstop at least for 30 minutes.