opentok / opentok-android-sdk-samples

Sample applications illustrating best practices using OpenTok Android SDK.
https://tokbox.com/developer/sdks/android/
MIT License
210 stars 170 forks source link

Android app crashing when photo gallery is accessed from app to send photo during videocall #485

Open tusharsharma718 opened 9 months ago

tusharsharma718 commented 9 months ago

Describe the bug

Android app crashing when photo gallery is accessed from app to send photo during videocall

To Reproduce

During the videocall the user gives permission to access gallery to select and send the photo but app gets crashed and session gets disconnected and following error gets logged in logcat :-

Fatal Exception: java.lang.RuntimeException Camera is being used after Camera.release() was called

Expected behavior

The app should not crashed when selecting photo as it is working fine on opentok version prior to 2.24.0

Device :

Additional context

This issue exist on the latest opentok version 2.26.1. as well.

goncalocostamendes commented 8 months ago

@tusharsharma718 there was an issue with the SDK related with camera releasing when not needed. It seems to be exactly what is causing your crash. The issue was solved on "opentok-android-sdk', version: '2.26.1'. Please upgrade the lib version and try it out.

tusharsharma718 commented 8 months ago

@tusharsharma718 there was an issue with the SDK related with camera releasing when not needed. It seems to be exactly what is causing your crash. The issue was solved on "opentok-android-sdk', version: '2.26.1'. Please upgrade the lib version and try it out.

@goncalocostamendes I have already mentioned in the Additional context that this issue exist in latest version 2.26.1 as well.

goncalocostamendes commented 8 months ago

@tusharsharma718 you are right. I missed that. I will validate if the issue is reproducible by configuring our test app to select a photo from the gallery.

It would be very useful if you could provide any insights or code snippets of your code so that we could have a better understanding of the root cause of the error

goncalocostamendes commented 8 months ago

@tusharsharma718 I was not able to reproduce the error. Can you provide the code you are using to get the photo from the gallery and the code you use to send the photo? I assume you send the photo to the peer? How are you doing it?

tusharsharma718 commented 8 months ago

@tusharsharma718 I was not able to reproduce the error. Can you provide the code you are using to get the photo from the gallery and the code you use to send the photo? I assume you send the photo to the peer? How are you doing it?

@goncalocostamendes will share the code soon.

tusharsharma718 commented 8 months ago

@goncalocostamendes pls find the following steps to reproduce the issue :-

Step-1 : User Clicks the button and the permission popup appears to access the gallery

This code is executed :-

{ val aboveApi32 = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU var mediaPermission : String = Manifest.permission.READ_EXTERNAL_STORAGE if(aboveApi32){ mediaPermission = Manifest.permission.READ_MEDIA_IMAGES } if (!EasyPermissions.hasPermissions(activity, mediaPermission)) { EasyPermissions.requestPermissions(this@VideoCallFragment, getString(R.string.access_local_image), PERMISSION_REQUEST_CODE, mediaPermission) } else { startImagePicker() } } then Pause method() is called

@CallSuper override fun onPause() { publisher?.onPause() super.onPause() }

Step-2 : User gives permision to access gallery

then this code is executed

private fun startImagePicker() { val intent = Intent() intent.type = "image/*" intent.action = Intent.ACTION_GET_CONTENT startActivityForResult(Intent.createChooser(intent, getString(R.string.select_picture)), Activity.SELECT_IMAGE_REQUEST_CODE) }

Step-3: Resume Method() is called

if (mSession == null) { createSession() } else { publisher?.onResume() }

Step-4 : Pause Method() is called

@CallSuper override fun onPause() { publisher?.onPause() super.onPause() }

Step-5 : Start Capture() method is called

if (camera != null) {

Camera.Parameters parameters = camera.getParameters(); parameters.setPreviewSize(-1, -1); parameters.setPreviewFormat(ImageFormat.NV21); camera.setParameters(parameters); }

then App gets crashed with the following error in logcat :-

java.lang.RuntimeException: Camera is being used after Camera.release() was called at android.hardware.Camera.native_getParameters(Native Method) at android.hardware.Camera.getParameters(Camera.java:2153) at com.videosample.consultation.custom.VideoCapturer.startCapture(VideoCapturer.java:133) at com.opentok.android.PublisherKit.c(Unknown Source:14) at com.opentok.android.PublisherKit.$r8$lambda$uxAi0JWLDFGCk8olGpDhu5RomTA(Unknown Source:0) at com.opentok.android.PublisherKit$$ExternalSyntheticLambda1.run(Unknown Source:2) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:246) at android.app.ActivityThread.main(ActivityThread.java:8633) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

v-kpheng commented 4 months ago

@goncalocostamendes, any updates?