Skip to content
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

FOREGROUND_SERVICE_MEDIA_PROJECTION not found in io.agora.rtc2.extensions.MediaProjectionMgr$LocalScreenCaptureAssistantActivity on Android 14 #1733

Closed
1 of 5 tasks
bhavinb98 opened this issue Apr 30, 2024 · 22 comments
Labels
waiting for customer response waiting for customer response, or closed by no-reponse bot

Comments

@bhavinb98
Copy link

Version of the agora_rtc_engine

6.3.0

Platforms affected

  • Android
  • iOS
  • macOS
  • Windows
  • Web

Steps to reproduce

Flutter Version - 3.19.4
Android 14

These permissions have been specified in AndroidManifest

<uses-permission android:name="android.permission.CAPTURE_VIDEO_OUTPUT" />
<uses-permission android:name="android.permission.CAPTURE_AUDIO_OUTPUT" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
<service
    android:name="com.pravera.flutter_foreground_task.service.ForegroundService"
    android:foregroundServiceType="mediaPlayback|camera|microphone|mediaProjection"
    android:stopWithTask="true"/>

I get this error when starting screen share

Java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1001, result=-1, data=Intent { (has extras) }} to activity {com.sprintstudio.conversations/io.agora.rtc2.extensions.MediaProjectionMgr$LocalScreenCaptureAssistantActivity}: java.lang.SecurityException: Media projections require a foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION

Expected results

Screen share starts properly

Actual results

Get the above error

Code sample

Code sample
[Paste your code here]

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.19.4, on Microsoft Windows [Version 10.0.22631.3447], locale en-IN)
[✓] Windows Version (Installed version of Windows is version 10 or higher)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Chrome - develop for the web
[✗] Visual Studio - develop Windows apps
    ✗ Visual Studio not installed; this is necessary to develop Windows apps.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components
[!] Android Studio (version 2021.3)
    ✗ Unable to determine bundled Java version.
[✓] Android Studio (version 2023.2)
[✓] VS Code (version 1.88.1)
[✓] Connected device (3 available)
[✓] Network resources
@littleGnAl
Copy link
Contributor

I'm so sorry that we're in holiday until May 06, I will take a look this issue after holiday.

@littleGnAl
Copy link
Contributor

I try our example and it works fine, can you check the configurations for reference?
https://github.com/AgoraIO-Extensions/Agora-Flutter-SDK/blob/main/example/android/app/src/main/AndroidManifest.xml

I think you can also try removing the mediaProjection from the com.pravera.flutter_foreground_task.service.ForegroundService in your project to see if it works or not.

<service
    android:name="com.pravera.flutter_foreground_task.service.ForegroundService"
-   android:foregroundServiceType="mediaPlayback|camera|microphone|mediaProjection"
+   android:foregroundServiceType="mediaPlayback|camera|microphone"
    android:stopWithTask="true"/>

@littleGnAl littleGnAl added waiting for customer response waiting for customer response, or closed by no-reponse bot and removed keep track labels May 6, 2024
@bhavinb98
Copy link
Author

I did the changes and get this error when starting screen share -

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1001, result=-1, data=Intent { (has extras) }} to activity {com.sprintstudio.conversations/io.agora.rtc2.extensions.MediaProjectionMgr$LocalScreenCaptureAssistantActivity}: java.lang.SecurityException: Media projections require a foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION

@github-actions github-actions bot removed the waiting for customer response waiting for customer response, or closed by no-reponse bot label May 6, 2024
@bhavinb98
Copy link
Author

It seems that I've ran into a weird problem. So I added the mediaProjection service back. I did a flutter clean and ran it again. It always gives me the above error during the first run, where it also crashes after the error. From 2nd run onwards, it runs fine.

I'm using this this plugin to enable foreground service in my app - https://pub.dev/packages/flutter_foreground_task, m not sure if this is the source of the issue. Also created an issue there - Dev-hwang/flutter_foreground_task#212

Another doubt I have -

I try our example and it works fine, can you check the configurations for reference?
https://github.com/AgoraIO-Extensions/Agora-Flutter-SDK/blob/main/example/android/app/src/main/AndroidManifest.xml

Android 14 needs foreground service permissions to be explicitly specified, but in your example, I don't see any declared, isn't the mediaProjection service is required for screen sharing?

@littleGnAl
Copy link
Contributor

The permissions are declared inside the SDK

api 'io.agora.rtc:full-screen-sharing:4.3.0'
, so you do not need to config any permissions for the screen sharing feature on Android by default.

I'm not very sure if it is affected by the flutter_foreground_task package, but I think you can first try running our example on your phone and see if it works or not, if yes, you can try removing the configurations or codes related to the flutter_foreground_task package in your project and try again.

@littleGnAl littleGnAl added the waiting for customer response waiting for customer response, or closed by no-reponse bot label May 7, 2024
@bhavinb98
Copy link
Author

I ran the example and it ran fine.

Updated Agora plugin to version 6.3.1

I removed the flutter_foreground_task code from my app as well.

This is the error I get when I start screen share on the first run.

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1001, result=-1, data=Intent { (has extras) }} to activity {com.sprintstudio.conversations/io.agora.rtc2.extensions.MediaProjectionMgr$LocalScreenCaptureAssistantActivity}: java.lang.SecurityException: Media projections require a foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION
E/AndroidRuntime(16677): 	at android.app.ActivityThread.deliverResults(ActivityThread.java:5527)
E/AndroidRuntime(16677): 	at android.app.ActivityThread.handleSendResult(ActivityThread.java:5566)
E/AndroidRuntime(16677): 	at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:67)
E/AndroidRuntime(16677): 	at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
E/AndroidRuntime(16677): 	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139)
E/AndroidRuntime(16677): 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96)
E/AndroidRuntime(16677): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443)
E/AndroidRuntime(16677): 	at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(16677): 	at android.os.Looper.loopOnce(Looper.java:205)
E/AndroidRuntime(16677): 	at android.os.Looper.loop(Looper.java:294)
E/AndroidRuntime(16677): 	at android.app.ActivityThread.main(ActivityThread.java:8177)
E/AndroidRuntime(16677): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(16677): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
E/AndroidRuntime(16677): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
E/AndroidRuntime(16677): Caused by: java.lang.SecurityException: Media projections require a foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION
E/AndroidRuntime(16677): 	at android.os.Parcel.createExceptionOrNull(Parcel.java:3057)
E/AndroidRuntime(16677): 	at android.os.Parcel.createException(Parcel.java:3041)
E/AndroidRuntime(16677): 	at android.os.Parcel.readException(Parcel.java:3024)
E/AndroidRuntime(16677): 	at android.os.Parcel.readException(Parcel.java:2966)
E/AndroidRuntime(16677): 	at android.media.projection.IMediaProjection$Stub$Proxy.start(IMediaProjection.java:313)
E/AndroidRuntime(16677): 	at android.media.projection.MediaProjection.<init>(MediaProjection.java:84)
E/AndroidRuntime(16677): 	at android.media.projection.MediaProjection.<init>(MediaProjection.java:75)
E/AndroidRuntime(16677): 	at android.media.projection.MediaProjectionManager.getMediaProjection(MediaProjectionManager.java:236)
E/AndroidRuntime(16677): 	at io.agora.rtc2.extensions.MediaProjectionMgr.onRequestResult(MediaProjectionMgr.java:172)
E/AndroidRuntime(16677): 	at io.agora.rtc2.extensions.MediaProjectionMgr$LocalScreenCaptureAssistantActivity.onActivityResult(MediaProjectionMgr.java:257)
E/AndroidRuntime(16677): 	at android.app.Activity.dispatchActivityResult(Activity.java:8943)
E/AndroidRuntime(16677): 	at android.app.ActivityThread.deliverResults(ActivityThread.java:5520)
E/AndroidRuntime(16677): 	... 13 more
E/AndroidRuntime(16677): Caused by: android.os.RemoteException: Remote stack trace:
E/AndroidRuntime(16677): 	at com.android.server.media.projection.MediaProjectionManagerService$MediaProjection.start(MediaProjectionManagerService.java:940)
E/AndroidRuntime(16677): 	at android.media.projection.IMediaProjection$Stub.onTransact(IMediaProjection.java:192)
E/AndroidRuntime(16677): 	at android.os.Binder.execTransactInternal(Binder.java:1339)
E/AndroidRuntime(16677): 	at android.os.Binder.execTransact(Binder.java:1275)
E/AndroidRuntime(16677): 

The subsequent runs after the first run work fine.

I also tried adding these permissions to my manifest to fix the first run issue but the problems remains

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />

@github-actions github-actions bot removed the waiting for customer response waiting for customer response, or closed by no-reponse bot label May 14, 2024
@littleGnAl
Copy link
Contributor

Is it possible to provide a mini reproducible demo for this issue which should be useful for us to investigate it?

@littleGnAl littleGnAl added the waiting for customer response waiting for customer response, or closed by no-reponse bot label May 16, 2024
costaaaaaa added a commit to costaaaaaa/Agora-Flutter-SDK that referenced this issue May 16, 2024
Fix for: AgoraIO-Extensions#1733 (Foreground Service bug)
@costaaaaaa
Copy link

Ignore this update. I'm doing some tests. Sorry about it

@costaaaaaa
Copy link

@UnluckyY1 Comment how relevant is your link, please.

@UnluckyY1
Copy link

@costaaaaaa Sorry, I made a mistake. I was supposed to post my comment on another issue.

@bhavinb98
Copy link
Author

bhavinb98 commented May 17, 2024

Is it possible to provide a mini reproducible demo for this issue which should be useful for us to investigate it?

@littleGnAl Here

Steps to reproduce -

  1. Run first time, start screen share. (results in a crash).
  2. Run again, works fine.
  3. Do a flutter clean and also uninstall the app from emulator/device.

@github-actions github-actions bot removed the waiting for customer response waiting for customer response, or closed by no-reponse bot label May 17, 2024
@costaaaaaa
Copy link

Guys, I made this changes to build and send to play console: Link to fork

Basically I added tools:node="remove" param in two permissions on AndroidManifest (from example folder) and set the replacement on Service tag.

I removed permissions because it I do not need this behavior at this moment.

Hope this workaround help someone.

@bhavinb98
Copy link
Author

@costaaaaaa Not sure if it works. I tried your forked branch on my demo project-

agora_rtc_engine:
    git:
      url: https://github.com/costaaaaaa/Agora-Flutter-SDK.git
      ref: fix_foreground_media_service

The issue persists.

@littleGnAl Did you get the chance to look at my demo project?

@littleGnAl
Copy link
Contributor

@bhavinb98 I'm so sorry that I just got back from vacation, I will investigate the demo in the next few days.

@littleGnAl
Copy link
Contributor

@bhavinb98 I found that it's related to the targetSdk, I changed the targetSdk it works fine
image

I'm so sorry that I'm a little busy this week, it still needs more time for me to investigate this issue next week. For a workaround you can set the targetSdk to 33 at this time.

@littleGnAl
Copy link
Contributor

Okay, I finally found that it's a bug of our native SDK, it will be fixed on the next version, still, for a workaround you can set the targetSdk to 33 at this time.

@bhavinb98
Copy link
Author

Any timeline for the next version release?

@littleGnAl
Copy link
Contributor

@bhavinb98 Probably in early July.

@littleGnAl
Copy link
Contributor

The new version agora_rtc_engine: ^6.3.2 is out, please try upgrading it to see if it works.

@littleGnAl littleGnAl added the waiting for customer response waiting for customer response, or closed by no-reponse bot label Jun 6, 2024
@bhavinb98
Copy link
Author

It's working. Thanks

@github-actions github-actions bot removed the waiting for customer response waiting for customer response, or closed by no-reponse bot label Jun 7, 2024
@littleGnAl littleGnAl added waiting for customer response waiting for customer response, or closed by no-reponse bot and removed keep track labels Jun 13, 2024
Copy link
Contributor

Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now. If you find this problem please file a new issue with the same description, what happens, logs and the output. All system setups can be slightly different so it's always better to open new issues and reference the related ones. Thanks for your contribution.

Copy link
Contributor

github-actions bot commented Jul 4, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please raise a new issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
waiting for customer response waiting for customer response, or closed by no-reponse bot
Projects
None yet
Development

No branches or pull requests

4 participants