Fix periodic job scheduling.
If a periodic job was run outside of its expected window (eg: because of
Doze mode or its constraints were unmet for a long time), then
JobSchedulerService would schedule the next one with a window starting
right now, which could cause the job to run again immediately.
This change addresses the issue by:
1. Switching to having consistent windows based on when the job was
scheduled. This also helps developers know when to expect jobs to run.
2. If a job runs in a different window, its run counts toward that
window instead.
3. For jobs with a custom flex setting, the next window is skipped if
the job is run to close to the next window.
Bug: 123248627
Test: atest com.android.server.job.JobSchedulerServiceTest
Test: atest CtsJobSchedulerTestCases
Change-Id: Ic18929e9d03e704ec43aa50fe37c64cd6807cf68
3 files changed