-
Notifications
You must be signed in to change notification settings - Fork 331
feat: Long-running workers on Android devices #573
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
base: main
Are you sure you want to change the base?
Conversation
To view this pull requests documentation preview, visit the following URL: docs.page/fluttercommunity/flutter_workmanager~573 Documentation is deployed and generated using docs.page. |
@ened I Kindly ask for your input on this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for building these features. I have left some comments
@@ -179,31 +178,32 @@ class Workmanager { | |||
/// The [taskName] is the value that will be returned in the [BackgroundTaskHandler] | |||
/// The [inputData] is the input data for task. Valid value types are: int, bool, double, String and their list | |||
Future<void> registerOneOffTask( | |||
/// Only supported on Android. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably use default dart formatting 2-space indenting
, so that it does not change the code which is not modified
required this.notificationChannelDescription, | ||
required this.notificationChannelImportance, | ||
required this.notificationTitle, | ||
required this.notificationDescription}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a trailing-comma and reformat, to be consistent
@@ -1,6 +1,7 @@ | |||
package dev.fluttercommunity.workmanager | |||
|
|||
import android.content.Context | |||
import android.content.pm.ServiceInfo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the import used?
@@ -213,13 +255,14 @@ object Extractor { | |||
constraintsConfig = extractConstraintConfigFromCall(call), | |||
outOfQuotaPolicy = extractOutOfQuotaPolicyFromCall(call), | |||
backoffPolicyConfig = | |||
extractBackoffPolicyConfigFromCall( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ened is this formatting ok, or it should be reverted. To not add unncessary changed lines and simplify reviews single formatting should be used
@@ -2,3 +2,6 @@ library workmanager; | |||
|
|||
export 'src/options.dart'; | |||
export 'src/workmanager.dart' show Workmanager; | |||
export 'src/workmanager.dart' show SetForegroundOptions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead do: export 'src/workmanager.dart' show Workmanager, SetForegroundOptions, etc;
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.