This week I have proceeded in working on the second part of the project proposal. Scheduling the downloads in Downloadable-Content Project. Now the requirement for this project is, when a person installs the Firefox, the code is designed and developed in such a way that both Fonts and Hyphenation Dictionaries are downloaded during the application start. The implementation is rudimentary that Synchronization and Verification of catalog will be performed during every application start. During verification if the catalog is found to have files that are to be downloaded then the downloads are started. We need a better scheduling for the above mentioned process instead of executing the process during every app start.
There are few solutions provided by Android OS for scheduling the jobs. Scheduling jobs are historically performed using the AlarmManager. It is available as a part of operating system from API Level 1. It is the most primitive way of scheduling the jobs in Android platform. When the alarm goes off at the specified time, the intent that was registered for that will be broadcast by the system. This automatically starts the application and does the job.
In Android OS they have released a newer API for scheduling the jobs - JobScheduler. It is available from API Level 21. It has a JobService class which is the entry point for the JobScheduler. This class will handle the requests asnychronously. We have to override the method onStartJob where we have to implement the logic for the job.
There is one more option available in Android OS to schedule a networking task. It is GcmNetworkManager. Since our tasks are to download the files during runtime, the GCMNetworkManager will be a perfect candidate to implement scheduler that is required for our purpose. This API has advanced options to check for network connectivity, implements various backoff strategies and retries. It lets the Google Play Services to batch the network operations across the entire system. But Since Google has started advicing the developers to migrate from the Google Cloud Messaging to Firebase Cloud Messaging. The existing GCM related implementations may be deprecated soon in the future. Google has also released a high level wrapper around the existing job scheduling mechanisms in android using Firebase Cloud Messaging - Firebase JobDispatcher. This will be replacing the existing GCMNetworkManager in the future.
So we have four different solutions provided by Google as a part of Google Play Services or as a part of Android OS.
Now the problem in choosing the a particular scheduling solution is there are various advantages and disadvantages in these solutions. Firefox for Android is available for the API Level 15 of Android. The AlarmManager is too primitive. But the JobScheduler is available for API Level 21. GcmNetworkManager seems to be a better choice for the task but the problem is it needs Google Play Services in the Android Device. Without the Google Play Services there wont be GCMNetworkManager. Firefox can be installed in any android devices and does not require Google Play or Google Play Services to run. Anyone with official download link for Firefox provided by Mozilla can install and run it in any android device. Introducing the dependancy of Google Play Services is not recommended.
There are also some libraries developed by some other organizations for scheduling tasks in android like evernote’s android-job that we can consider. This week I spent time on researching the various available solutions and choosing which is best for the Fennec.