JulianAssmann / flutter_background

A flutter plugin to keep apps running in the background via foreground services. Android only.
https://pub.dev/packages/flutter_background
MIT License
85 stars 44 forks source link

[BUG] Android 14 (API 34+): Foreground service types are required #85

Open kNoAPP opened 1 month ago

kNoAPP commented 1 month ago

https://developer.android.com/about/versions/14/changes/fgs-types-required https://developer.android.com/about/versions/14/changes/fgs-types-required#media-projection https://developer.android.com/reference/android/content/pm/ServiceInfo#FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION

E/AndroidRuntime(16537): java.lang.RuntimeException: Unable to start service de.julianassmann.flutter_background.IsolateHolderService@ceb8b4b with Intent { act=START cmp=com.remotelegal.astra/de.julianassmann.flutter_background.IsolateHolderService }: java.lang.SecurityException: Starting FGS with type mediaProjection callerApp=ProcessRecord{5ba1ad5 16537:com.remotelegal.astra/u0a549} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION] any of the permissions allOf=false [android.permission.CAPTURE_VIDEO_OUTPUT, android:project_media] 
E/AndroidRuntime(16537):    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5053)
E/AndroidRuntime(16537):    at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0)
E/AndroidRuntime(16537):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2390)
E/AndroidRuntime(16537):    at android.os.Handler.dispatchMessage(Handler.java:107)
E/AndroidRuntime(16537):    at android.os.Looper.loopOnce(Looper.java:232)
E/AndroidRuntime(16537):    at android.os.Looper.loop(Looper.java:317)
E/AndroidRuntime(16537):    at android.app.ActivityThread.main(ActivityThread.java:8501)
E/AndroidRuntime(16537):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(16537):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
E/AndroidRuntime(16537):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)
E/AndroidRuntime(16537): Caused by: java.lang.SecurityException: Starting FGS with type mediaProjection callerApp=ProcessRecord{5ba1ad5 16537:com.remotelegal.astra/u0a549} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION] any of the permissions allOf=false [android.permission.CAPTURE_VIDEO_OUTPUT, android:project_media] 
ma-vai commented 1 month ago

We are also experiencing the same issue. There is a pending merge request for this by someone else, however it is hardcoding FGS type of "specialUse" which requires many hoops to explain when publishing to the Play Store.

It would be ideal if we can set the FGS type string in the manifest for this package, and have the package detect and send the appropriate FGS const to the android start service call.

kNoAPP commented 1 week ago

@steveseguin Question, were you trying to fix this issue with your fork? Did you succeed? https://github.com/steveseguin/flutter_background

steveseguin commented 1 week ago

@steveseguin Question, were you trying to fix this issue with your fork? Did you succeed? https://github.com/steveseguin/flutter_background

I hacked at it until it worked. Part of the issue in my case was that I needed to explicitly request permission for display capture, and that also had to be approved by the Google reviewers.

I then had conflicts between Flutter plugins, as different ones needed different versions of other dependencies, and so that took further hacking to cut out the bits of the flutter_background plugin that were causing me grief.

Do a lot of testing if moving to Android 14, across a lot of devices, including Samsung.

https://github.com/steveseguin/vdon_flutter - final product.

The funny thing is, I have a new version written in react-native that I'm moving instead to, as I'm giving up on Flutter. This was meant to be quick hold over update, and it ended up being a big headache.

kNoAPP commented 1 week ago

@steveseguin Question, were you trying to fix this issue with your fork? Did you succeed? https://github.com/steveseguin/flutter_background

I hacked at it until it worked. Part of the issue in my case was that I needed to explicitly request permission for display capture, and that also had to be approved by the Google reviewers.

I then had conflicts between Flutter plugins, as different ones needed different versions of other dependencies, and so that took further hacking to cut out the bits of the flutter_background plugin that were causing me grief.

Do a lot of testing if moving to Android 14, across a lot of devices, including Samsung.

https://github.com/steveseguin/vdon_flutter - final product.

The funny thing is, I have a new version written in react-native that I'm moving instead to, as I'm giving up on Flutter. This was meant to be quick hold over update, and it ended up being a big headache.

Thanks, this is good information. I'm running from LiveKit's videoconferencing SDK and my app breaks the moment I throw Android SDK 34 at it. Haven't been able to fix it yet before the upcoming August deadline.

ma-vai commented 1 week ago

We also experienced a lot of Flutter plugin breakage when updating to Android 14/SDK 34. This background things was the most pressing issue. There is a package that supposedly handles it (https://pub.dev/packages/flutter_background_service) but it's not exactly the same as flutter_background, which I prefer as it's been great for us so far. I was hoping the way flutter_background_service implemented the FGS stuff could be done for flutter_background.