8000 Bug Report: Foreground Service Crash on Android 14+ (API 34+) with mediaProjection due to Missing Permissions · Issue #1813 · flutter-webrtc/flutter-webrtc · GitHub
[go: up one dir, main page]

Skip to content

Bug Report: Foreground Service Crash on Android 14+ (API 34+) with mediaProjection due to Missing Permissions #1813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Sam15b opened this issue Apr 8, 2025 · 0 comments

Comments

@Sam15b
Copy link
Sam15b commented Apr 8, 2025

When attempting screen sharing using flutter_webrtc on Android 14 (API 34) or higher, the app crashes with a SecurityException because the required foreground service permissions for mediaProjection are not properly handled.

Critical Issue with targetSdkVersion Workaround
Temporary Fix: Forcing targetSdkVersion 28 (Android 9) avoids the crash, but Google Play Console rejects apps with targetSdkVersion < 31 (since August 2022).

Production Impact: This makes the workaround unusable for published apps, requiring a proper fix for API 34+ compliance.

get this E/AndroidRuntime(12034): FATAL EXCEPTION: main E/AndroidRuntime(12034): Process: com.it.mediastream, PID: 12034 E/AndroidRuntime(12034): java.lang.RuntimeException: Unable to start service de.julianassmann.flutter_background.IsolateHolderService@f05fc9a with Intent { act=START cmp=com.it.mediastream/de.julianassmann.flutter_background.IsolateHolderService }: java.lang.SecurityException: Starting FGS with type mediaProjection callerApp=ProcessRecord{ee6725f 12034:com.it.mediastream/u0a386} 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(12034): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5295) E/AndroidRuntime(12034): at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0) E/AndroidRuntime(12034): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2580) E/AndroidRuntime(12034): at android.os.Handler.dispatchMessage(Handler.java:112) E/AndroidRuntime(12034): at android.os.Looper.loopOnce(Looper.java:268) E/AndroidRuntime(12034): at android.os.Looper.loop(Looper.java:384) E/AndroidRuntime(12034): at android.app.ActivityThread.main(ActivityThread.java:8921) E/AndroidRuntime(12034): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(12034): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580) E/AndroidRuntime(12034): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:907) E/AndroidRuntime(12034): Caused by: java.lang.SecurityException: Starting FGS with type mediaProjection callerApp=ProcessRecord{ee6725f 12034:com.it.mediastream/u0a386} 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(12034): at android.os.Parcel.createExceptionOrNull(Parcel.java:3242) E/AndroidRuntime(12034): at android.os.Parcel.createException(Parcel.java:3226) E/AndroidRuntime(12034): at android.os.Parcel.readException(Parcel.java:3209) E/AndroidRuntime(12034): at android.os.Parcel.readException(Parcel.java:3151) E/AndroidRuntime(12034): at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:7326) E/AndroidRuntime(12034): at android.app.Service.startForeground(Service.java:776) E/AndroidRuntime(12034): at de.julianassmann.flutter_background.IsolateHolderService.startService(IsolateHolderService.kt:128) E/AndroidRuntime(12034): at de.julianassmann.flutter_background.IsolateHolderService.onStartCommand(IsolateHolderService.kt:53) E/AndroidRuntime(12034): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5277) E/AndroidRuntime(12034): ... 9 more E/AndroidRuntime(12034): Caused by: android.os.RemoteException: Remote stack trace: E/AndroidRuntime(12034): at com.android.server.am.ActiveServices.validateForegroundServiceType(ActiveServices.java:2921) E/AndroidRuntime(12034): at com.android.server.am.ActiveServices.setServiceForegroundInnerLocked(ActiveServices.java:2605) E/AndroidRuntime(12034): at com.android.server.am.ActiveServices.setServiceForegroundLocked(ActiveServices.java:1859) E/AndroidRuntime(12034): at com.android.server.am.ActivityManagerService.setServiceForeground(ActivityManagerService.java:14552) E/AndroidRuntime(12034): at android.app.IActivityManager$Stub.onTransact$setServiceForeground$(IActivityManager.java:12183) E/AndroidRuntime(12034):
Steps to Reproduce
Set targetSdkVersion = 34 (Android 14) in app/build.gradle.

Use flutter_webrtc to start screen sharing.

App crashes on Android 14+ devices with SecurityException.

Workaround Attempt:

Setting targetSdkVersion = 28 prevents the crash, but Google Play blocks submission.

Root Cause
Android 14+ enforces stricter foreground service (FGS) permissions for mediaProjection:

Mandatory: FOREGROUND_SERVICE_MEDIA_PROJECTION

One of these: CAPTURE_VIDEO_OUTPUT or android:project_media

The IsolateHolderService in flutter_background (used by flutter_webrtc) does not declare these permissions.

Why This Needs to Be Fixed in flutter_webrtc
Play Store Compliance: Apps must target SDK 34+ by 2024.

Security: Proper permission handling is mandatory for screen capture.

User Experience: Crashes on newer Android versions degrade reliability.

Temporary Workarounds (Not Ideal for Production)
Downgrade targetSdkVersion to 28 (only for testing, not Play Store compliant).

Manually patch the plugin (not sustainable for updates).

Environment
Plugin: flutter_webrtc: ^0.6.10

Flutter: 3.16.9

Android: SDK 34+

Device: Motorola edge 50 fusion

@cloudwebrtc please check this issue of Foreground Service Crash on Android 14](#1813 (comment))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0