AgoraIO / API-Examples

Play with AgoraSDK and have fun! Everything you need to start learning Agora.
304 stars 218 forks source link

Application get crash in Android -14 #401

Open rahul-kumawat-vts opened 1 month ago

rahul-kumawat-vts commented 1 month ago

In our application we have targeted the SDK 34 and we are using screen sharing SDK.

implementation "io.agora.rtc:full-sdk:4.3.1"
implementation "io.agora.rtc:full-screen-sharing:4.3.1"

We have already using a foreground service in app manifest as per the doc https://docs.agora.io/en/video-calling/core-functionality/screen-sharing?platform=web

Do we need to do anything at our end to fix this crash.

Stack trace: 
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1001, result=-1, data=Intent { (has extras) }} to activity {[com.travelme.app/io.agora.rtc2.extensions.MediaProjectionMgr$LocalScreenCaptureAssistantActivity](http://com.travelme.app/io.agora.rtc2.extensions.MediaProjectionMgr$LocalScreenCaptureAssistantActivity)}: java.lang.SecurityException: Media projections require a foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION
at android.app.ActivityThread.deliverResults(ActivityThread.java:5844)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:5888)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:70)
at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:99)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2620)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:222)
at android.os.Looper.loop(Looper.java:314)
at android.app.ActivityThread.main(ActivityThread.java:8732)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:565)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1090)
Caused by: java.lang.SecurityException: Media projections require a foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION
at android.os.Parcel.createExceptionOrNull(Parcel.java:3057)
at android.os.Parcel.createException(Parcel.java:3041)
at android.os.Parcel.readException(Parcel.java:3024)
at android.os.Parcel.readException(Parcel.java:2966)
at android.media.projection.IMediaProjection$Stub$Proxy.start(IMediaProjection.java:313)
at android.media.projection.MediaProjection.<init>(MediaProjection.java:84)
at android.media.projection.MediaProjection.<init>(MediaProjection.java:75)
at android.media.projection.MediaProjectionManager.getMediaProjection(MediaProjectionManager.java:236)
at io.agora.rtc2.extensions.MediaProjectionMgr.onRequestResult(MediaProjectionMgr.java:172)
at io.agora.rtc2.extensions.MediaProjectionMgr$LocalScreenCaptureAssistantActivity.onActivityResult(MediaProjectionMgr.java:257)
at android.app.Activity.dispatchActivityResult(Activity.java:9278)
at android.app.ActivityThread.deliverResults(ActivityThread.java:5837)
... 13 more
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.media.projection.MediaProjectionManagerService$MediaProjection.start(MediaProjectionManagerService.java:1048)
at android.media.projection.IMediaProjection$Stub.onTransact(IMediaProjection.java:192)
at android.os.Binder.execTransactInternal(Binder.java:1346)
at android.os.Binder.execTransact(Binder.java:1282)
weileifrank commented 1 month ago

The bug has been fixed. You can upgrade the version to 4.4.1 and then try again.

rahul-kumawat-vts commented 1 month ago

Thanks, it's working with version 4.4.1.

One more thing why onUserJoined callback executed again once any user left the channel in version 4.4.1. It was properly working fine with version 4.3.1

override fun onUserJoined(uid: Int, elapsed: Int) {
            super.onUserJoined(uid, elapsed)
            Log.d(TAG, "onUser-Joined: $uid")
            try {
                runOnUiThread {
                    viewModel.visitDetailsLiveData.value?.data?.data?.let { visitDetailsData ->
                        val hostUserId = visitDetailsData.host_user_id
                        val residenceUserId = visitDetailsData.residence_user_id
                        val isHostUser = uid.toString() == hostUserId
                        val isResidenceUser = uid.toString() == residenceUserId

                        if (isMultiVisit) {
                            handleMultiVisitUserJoined(uid, visitDetailsData, isHostUser)
                        } else {
                            handleSingleVisitUserJoined(uid, visitDetailsData, isHostUser, isResidenceUser)
                        }
                    }
                }
            } catch (e: Exception) {
                e.printStackTrace()
            }
        }

override fun onUserOffline(uid: Int, reason: Int) {
            Log.d(TAG, "onUser-Offline: $uid")
            CoroutineScope(Dispatchers.Main).launch {
                try {
                    if (isMultiVisit) {
                        handleMultiVisitUserOffline(uid)
                    } else if (mapHost["host1"] == uid) {
                        handleSingleVisitHostOffline(uid)
                    }
                } catch (e: Exception) {
                    e.printStackTrace()
                }
            }
        }
Screenshot 2024-09-20 at 11 42 59 PM
rahul-kumawat-bigstep commented 1 month ago

Can anyone please help update on above issue with latest Agora SDK version 4.4.1

https://github.com/AgoraIO/API-Examples/issues/401#issuecomment-2364282507

@weileifrank

weileifrank commented 1 month ago

I have tested it. there is no problem for onUserJoined callback with agora version 4.4.1, can you share your demo with me?

By the way, you can also run our demo first to see if the callback is normal

weileifrank commented 1 month ago

@rahul-kumawat-bigstep

rahul-kumawat-bigstep commented 1 month ago

@weileifrank Just checked in your demo as well when any user left the channel (Suppose UID - 452061665) onUserOffline callback executed. In next second for UID-452061665 onUserJoined callback executed.

Please check the logs of your demo App.

Screenshot 2024-09-30 at 6 21 23 PM
rahul6924 commented 1 month ago

@weileifrank Can you please check on priority as our client is facing issue https://github.com/AgoraIO/API-Examples/issues/401#issuecomment-2383099563.

weileifrank commented 1 month ago

i have tested our JoinChannelVideoByToken demo case with agora version 4.4.1 and the logs is as below:

截屏2024-10-03 14 02 52

anyway,can you share your demo with me for checking?

weileifrank commented 1 month ago

@rahul6924

rahul-kumawat-vts commented 1 month ago

Hi @weileifrank I have checked with your webdemo and app but still having same issue. Please check the video

https://drive.google.com/file/d/10tRGVG0b7JL5-TgGIr2S9mn-hxC9akhM/view?usp=sharing

weileifrank commented 1 month ago

@rahul6924 it's a pity,we did not reproduce it. you can test the case with two android device and then export the sdk log for us ,the sdk path is sdcard/Android/data/io.agora.api.example/files/

sdk_log_path
rahul-kumawat-vts commented 1 month ago

@weileifrank I will check in two different phone but over use case is mobile and web video streaming. Can you please check the similar case at your end https://github.com/AgoraIO/API-Examples/issues/401#issuecomment-2391280798

rahul-kumawat-bigstep commented 1 month ago

@weileifrank I have tried with two mobile but the behaviour is still same also i didn't get any logs in storage. There is no application folder with package name inside storage directory

Do i need to add the below code in sample application.

val logConfig = LogConfig() logConfig.level = Constants.LogLevel.getValue(Constants.LogLevel.LOG_LEVEL_INFO) val ts: String = SimpleDateFormat("yyyyMMdd").format(Date()) logConfig.filePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORYDOWNLOADS).absolutePath + "/agora/agora"+ts+".log"

val config = RtcEngineConfig() config.mLogConfig = logConfig