Status Update
Comments
su...@google.com <su...@google.com> #2
If you are using location, you should be using the permissions API to ensure that you have the permissions you need to track background location before any attempts to use APIs that require that permission.
SystemForegroundService
just provides a convenient entry point for the ListenableWorker
. If you require additional permissions, its the app's responsibility to ask for permissions and check that those permissions are granted.
ch...@gmail.com <ch...@gmail.com> #3
We are performing location checks before submitting the WorkManager job. However, the problem exists if the location permission is removed by the User after the job has been submitted. The OS is force killing the app (when the location permission is removed), and the OS is trying to restart the SystemForegroundService which then crashes our app immediately on launch. We are not interacting with the WorkManager in this scenario other than initialising it which is necessary on app start, e.g.
val workManagerConfig = Configuration.Builder()
.setWorkerFactory(entryPoints.getWorkerFactory())
.build()
// Initialize WorkManager with the custom configuration.
WorkManager.initialize(context, workManagerConfig)
return WorkManager.getInstance(context)
[Deleted User] <[Deleted User]> #4
I think it might be best for now if your foreground worker does not declare that it is a location foreground service and instead it is either a 'short' service or a 'special use' service such that WorkManager's SystemForegroundService
redeliver intent restarts your foreground worker and in it you can check for location permission and then start a real foreground location service.
Meanwhile we have to adapt WorkManager's SystemForegroundService
to Android 14 requirements to have a foreground service type along with its permission runtime check as otherwise many of the types have runtime permissions pre-requisites.
ro...@gmail.com <ro...@gmail.com> #5
Sorry, I just re-read the changes for Android 14, and for this to work elegantly, we will need to change the implementation of SystemForegroundService
to do the right thing.
Will try to land this in the next WorkManager release.
Description
Version used: 1.0.0-alpha12
After upgrading to alpha12, all of my Workers written in Kotlin (and CoroutineWorkers, FWIW), complain about the 'Result' return value with an error that says: "One type argument expected for class Result<out T>"
It appears that the Kotlin standard library contains a public inline Result class already:
The Kotlin Result class is automatically available in every file, so Android Studio (3.2.1) doesn't offer to import the androidx.work.Result class, causing the error since it assumes you want to use the already available kotlin Result.
There were two workarounds, neither very friendly:
1) Use the fully qualified androidx.work.Result
2) Manually adding the androidx.work.Result import statement
Note that:
- Using the fully qualified name, then using the Android Studio option to add import did not work
- Removing the doWork method entirely and using Android Studio's quick fix to implement the method did add an import to androidx.work.Result, so new classes would avoid running into this issue.