feat: Long-running workers on Android devices #573
+288
−90
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.
This pull request introduces foreground service support on Android devices as per Android workmanager docs Support for long-running workers.
Foreground service support:
createForegroundInfo
andcreateNotificationChannel
inBackgroundWorker.kt
to handle the creation of foreground notifications and channels.SetForeground
data class andparseSetForegroundCall
method inExtractor.kt
to parse method calls related to setting foreground options. [1] [2]setForeground
method andSetForegroundOptions
class inworkmanager.dart
to set foreground options from Dart code. [1] [2]Code refactoring and improvements:
onMethodCall
method inBackgroundWorker.kt
to handle the newSET_FOREGROUND
method call.BackgroundWorker.kt
andExtractor.kt
. [1] [2]These changes allows tasks to run as foreground services.
This PR addresses issue #236, but goes against the recomendation on #511 of using
Workmanager.registerProcessingTask
to implement long-running wokers on android.Since the implementation of long-running workers on Android tightly depends on specific requirements such as handling notifications and activating a foreground service on the run, a decision was made to create a dedicated API which laverages ListenableWorker.serForegroundAsync and minimally handles notification management in order to implement long-running workers while following android guidelines.