For synchronizing the catalog of downloadable content (bug 1201059) and content notifications (bug 1241810) we need to schedule repeating background tasks. Android has various APIs for that depending on version and device configuration: * AlarmManager http://developer.android.com/reference/android/app/AlarmManager.html The AlarmManager is available on all Android devices and versions. However it is very simple and we need to handle things like reboots or network availability ourselves. * JobScheduler http://developer.android.com/reference/android/app/job/JobScheduler.html JobScheduler has a fine-grained configuration and handles most problems of scheduling background tasks. However it has been introduced in Android 5 and there's no official backported version available. * GcmNetworkManager https://developers.google.com/android/reference/com/google/android/gms/gcm/GcmNetworkManager An API to schedule network-oriented tasks. It does almost all the heavy lifting for you but it's tied to GCM / Google Play Services and therefore not available on all devices. It would be nice to have a generic - maybe JobScheduler-like - helper class that you can use to configure a background task and in the background this class uses the best available API (For example AlarmManager on Gingerbread - or GcmNetworkManager if available, but JobScheduler on 5.0).
nalexander: Before considering implementing something like that for bug 1201059 and bug 1241810 I was wondering if we might have some other background "tick" that I could use to start other tasks. To piggyback on another, already existing, background task might be a simple workaround.
(In reply to Sebastian Kaspari (:sebastian) from comment #1) > nalexander: Before considering implementing something like that for bug > 1201059 and bug 1241810 I was wondering if we might have some other > background "tick" that I could use to start other tasks. To piggyback on > another, already existing, background task might be a simple workaround. I was not aware of JobScheduler or GcmNetworkManager. rnewman built a scheduler based on AlarmManager and reboot intents for Product Announcements (now deceased) and I used that model for our FHR uploader (also deceased). jchen and snorp (I think?) wrote a service to let Gecko schedule things like this, but I don't think it tries to address reboots, etc: https://dxr.mozilla.org/mozilla-central/source/mobile/android/base/java/org/mozilla/gecko/GeckoService.java. I wish JobScheduler had a support library version :( But failing that, perhaps we can dust off one of the existing solutions and try to generalize it for more tasks.
rnewman: do you have an opinion here?
(In reply to Nick Alexander :nalexander from comment #2) > I wish JobScheduler had a support library version :( Yeah, me too. Someone started this on Github a while ago but the library is already deprecated: https://github.com/evant/JobSchedulerCompat However maybe it's a good source of Dos and Donts if we are going to build our own.
Nope, no opinion. There were almost certainly comments in the code to the effect of "we should have one place that schedules all of these things" -- we'd like to respond to network state changes, timers, Gecko events, etc. -- so perhaps that's now this bug.
Created attachment 8727499 [details] [diff] [review] Basic patch
Comment on attachment 8727499 [details] [diff] [review] Basic patch Review of attachment 8727499 [details] [diff] [review]: ----------------------------------------------------------------- This bug is about creating this very generic helper for scheduling all kinds of background tasks. Periodically running DownloadContentService is something that gets more interesting after the sync client is in the tree (bug 1201059). After that we can think of running this service more often in the background (For this specific action).
Attachment #8727499 - Attachment is obsolete: true
I got a larger list of JobScheduler compats: https://android-arsenal.com/search?q=jobscheduler The two popular ones are: * Trigger (331 stars): https://github.com/airk000/Trigger * android-job (780 stars): https://github.com/evernote/android-job The latter schedules over GcmNetworkManager, JobScheduler, and AlarmManager and is maintained by a company (Evernote), so is probably more reliable. I think it'd be better to try to re-use one of these than rolling our own.
(In reply to Michael Comella (:mcomella) from comment #8) > I think it'd be better to try to re-use one of these than rolling our own. Definitely! Let's evaluate them before writing any code. I still have hopes that we can move from API 15 to 16 soon and just use JobScheduler. That's why I would prefer something that is very close to JobScheduler (and can have a "shitty" AlarmManager implementation on API 15) so that we can move to the platform API easily.
Unfortunately, JobScheduler is API 21. :(
Oh, sorry, for the confusion. I felt certain that this had been introduced with Jelly Bean. Okay, this makes the other libraries even more interesting. :)
The Firebase team released a new library that does exactly this and replaces GcmNetworkManager: https://github.com/firebase/firebase-jobdispatcher-android
Assigning to krish. He is currently looking at the various options we have.
Assignee: nobody → k.krish
Status: NEW → ASSIGNED
After a brief analysis, We have decided to move forward to use this library - https://github.com/evernote/android-job to schedule the tasks.
The Android team implemented this for us in the Android support library: https://developer.android.com/reference/androidx/work/WorkManager
Status: ASSIGNED → RESOLVED
Last Resolved: 9 months ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.