Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
View issue level access limits(Press Alt + Right arrow for more information)
Unintended behavior
View staffing
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()
.