Fixed
Status Update
Comments
ra...@google.com <ra...@google.com>
ra...@google.com <ra...@google.com> #2
Will investigate.
ap...@google.com <ap...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-master-dev
commit fb7c36f21b71b2cfa4efd2af2a27c31dce8976d8
Author: Rahul Ravikumar <rahulrav@google.com>
Date: Mon May 04 12:22:00 2020
Delegate the call to isRunInForeground().
* ConstraintTrackingWorker now correctly delegates the call to isRunInForeground().
* This is necessary because the call to `setForegroundAsync()` assumes the identity of the delegated worker,
and NOT `ConstraintTrackingWorker`.
Test: Added unit tests.
Fixes: b/155579898
Change-Id: I87a661cf5d7007f440860aa282dcb9d7f630d964
M work/workmanager/src/androidTest/java/androidx/work/impl/workers/ConstraintTrackingWorkerTest.java
M work/workmanager/src/main/java/androidx/work/ListenableWorker.java
M work/workmanager/src/main/java/androidx/work/impl/workers/ConstraintTrackingWorker.java
https://android-review.googlesource.com/1302153
Branch: androidx-master-dev
commit fb7c36f21b71b2cfa4efd2af2a27c31dce8976d8
Author: Rahul Ravikumar <rahulrav@google.com>
Date: Mon May 04 12:22:00 2020
Delegate the call to isRunInForeground().
* ConstraintTrackingWorker now correctly delegates the call to isRunInForeground().
* This is necessary because the call to `setForegroundAsync()` assumes the identity of the delegated worker,
and NOT `ConstraintTrackingWorker`.
Test: Added unit tests.
Fixes:
Change-Id: I87a661cf5d7007f440860aa282dcb9d7f630d964
M work/workmanager/src/androidTest/java/androidx/work/impl/workers/ConstraintTrackingWorkerTest.java
M work/workmanager/src/main/java/androidx/work/ListenableWorker.java
M work/workmanager/src/main/java/androidx/work/impl/workers/ConstraintTrackingWorker.java
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()
.