Fixed #1076: Refactored RealtimeService using WorkManager #1161
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Refactor
RealtimeServices for OTP Trip Results hasn't been functioning since Android 8.0 (API level 26) due to the background execution limits it introduces. This was fixed by refactoring Intent Service using Work Manager, swapping out WakefulBroadcastReceiver & Alarm Manager with WorkManager & Workers for all persistent work.
RealTimeService
RealTimeService was refactored to handle all the checks the old service was doing, it then converts and simplifies the bundle into a Data object which is passed into PeriodicWorkRequest which runs the RealTimeWorker class every 15 minutes. PeriodicWorkRequest is also started with an initial delay, it is only started an hour before the scheduled trip time which is the same as the old RealtimeService.
RealTimeWorker
RealTimeWorker is the new Worker class that only checks for any changes in the itineraries and responds to it accordingly, this logic was not changed and functions the same as the old RealtimeService. It returns the result as success if it was not canceled and failure if it was.
Empty Bundle
The old RealtimeService checked if the function receives an empty Bundle, and disables RealtimeServices if it's empty. The refactor includes this but it should be removed when issues #790 and #791 are resolved.
Core Functionality Change
The only major difference change in the refactor was the number of times the service polls, the old RealtimeService polls the OTP server every minute while the new one polls it every 15 minutes. This is due to a limitation on PeriodicWorkRequest whose minimum repeat interval is 15 minutes. WorkManager was used as it was recommended by the issue(#1076) and Android to schedule deferrable, asynchronous tasks that must be run reliably.
Issues Affected
Closes #1076
Could affect / close #977
Pull Request Requirements
Please make sure these boxes are checked before submitting your pull request - thanks!
Apply the
AndroidStyle.xml
style template to your code in Android Studio.Run the unit tests with
gradlew connectedObaGoogleDebugAndroidTest
to make sure you didn't break anythingIf you have multiple commits please combine them into one commit by squashing them for the initial submission of the pull request. When addressing comments on a pull request, please push a new commit per comment when possible (reviewers will squash and merge using GitHub merge tool)