Fixed
Status Update
Comments
ra...@google.com <ra...@google.com>
ap...@google.com <ap...@google.com> #3
Thank you for the quick fix.
Is there an ETA for the next release?
Is there an ETA for the next release?
Description
Context
Component used: work-runtime
Version used: 2.4.0 Alpha 3
Devices/Android versions reproduced on: Android 7
Description
When running a Worker with constraints that calls setForegroundAsync() on Android 7 (and potentially earlier) the foreground service is started but not stopped after the worker has completed execution.
On Android 8, 9, and 10, the foreground service is stopped as expected when the worker completes and the notification is removed.
The bug only occurs for workers that have constraints. If no constraints are set, the behavior on Android 7 is correct as well.
Sample project
Github projecthttps://github.com/otbinary/workmanager-foreground-worker contains a small sample app.
A foreground worker with a constraint (
setRequiresBatteryNotLow
) that sleeps for five seconds can be started by a broadcast intent:adb shell am broadcast -n com.github.otbinary.fgworker/.StartSleepingWorkerBroadcastReceiver
Observations
On Android 7,
WorkerWrapper.resolve()
is called only for aConstraintTrackingWorker
instance that is wrapped around the actualSleepingWorker
instance.ConstraintTrackingWorker.isRunInForeground()
isfalse
.resolve()
therefore does not callmForegroundProcessor.stopForeground()
.On Android 8+,
resolve()
is called for the actualSleepingWorker
instance whoseisRunInForeground()
returnstrue
.resolve()
callsmForegroundProcessor.stopForeground()
.