Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

[BUG] App crash when returning to it #10

Closed
hsson opened this issue Apr 4, 2019 · 14 comments
Closed

[BUG] App crash when returning to it #10

hsson opened this issue Apr 4, 2019 · 14 comments
Labels
bug Something isn't working

Comments

@hsson
Copy link

hsson commented Apr 4, 2019

Describe the bug
After just having used the scanning functionality, then closing the app, and the re-opening the app, I encountered the following exception:

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:503)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.reflect.InvocationTargetException        at java.lang.reflect.Method.invoke(Method.java:-2)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.hardware.camera2.CameraAccessException: CAMERA_DISCONNECTED (2): checkPidStatus:1708: The camera device has been disconnected
        at android.hardware.camera2.CameraManager.throwAsPublicException(CameraManager.java:728)
        at android.hardware.camera2.impl.ICameraDeviceUserWrapper.waitUntilIdle(ICameraDeviceUserWrapper.java:179)
        at android.hardware.camera2.impl.CameraDeviceImpl.waitUntilIdle(CameraDeviceImpl.java:1135)
        at android.hardware.camera2.impl.CameraDeviceImpl.configureStreamsChecked(CameraDeviceImpl.java:436)
        at android.hardware.camera2.impl.CameraDeviceImpl.createCaptureSessionInternal(CameraDeviceImpl.java:662)
        at android.hardware.camera2.impl.CameraDeviceImpl.createCaptureSession(CameraDeviceImpl.java:510)
        at uk.co.brightec.kbarcode.camera.Camera2Source.createCaptureSession$kbarcode_release(Camera2Source.kt:121)
        at uk.co.brightec.kbarcode.camera.Camera2Source$start$1.onOpened(Camera2Source.kt:55)
        at android.hardware.camera2.impl.CameraDeviceImpl$1.run(CameraDeviceImpl.java:143)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6718)
        at java.lang.reflect.Method.invoke(Method.java:-2)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.os.ServiceSpecificException: checkPidStatus:1708: The camera device has been disconnected
        at android.os.Parcel.createException(Parcel.java:1964)
        at android.os.Parcel.readException(Parcel.java:1918)
        at android.os.Parcel.readException(Parcel.java:1868)
        at android.hardware.camera2.ICameraDeviceUser$Stub$Proxy.waitUntilIdle(ICameraDeviceUser.java:599)
        at android.hardware.camera2.impl.ICameraDeviceUserWrapper.waitUntilIdle(ICameraDeviceUserWrapper.java:177)
        at android.hardware.camera2.impl.CameraDeviceImpl.waitUntilIdle(CameraDeviceImpl.java:1135)
        at android.hardware.camera2.impl.CameraDeviceImpl.configureStreamsChecked(CameraDeviceImpl.java:436)
        at android.hardware.camera2.impl.CameraDeviceImpl.createCaptureSessionInternal(CameraDeviceImpl.java:662)
        at android.hardware.camera2.impl.CameraDeviceImpl.createCaptureSession(CameraDeviceImpl.java:510)
        at uk.co.brightec.kbarcode.camera.Camera2Source.createCaptureSession$kbarcode_release(Camera2Source.kt:121)
        at uk.co.brightec.kbarcode.camera.Camera2Source$start$1.onOpened(Camera2Source.kt:55)
        at android.hardware.camera2.impl.CameraDeviceImpl$1.run(CameraDeviceImpl.java:143)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6718)
        at java.lang.reflect.Method.invoke(Method.java:-2)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

I believe this is rather rare though, but it might be good if you handled this some better way that doesn't cause the app to crash.

To Reproduce
Steps to reproduce the behavior:
Close app, and then re-open it. Doesn't happen all the time though.

Expected behavior
I expected the app to re-open with the camera view and the scanning started as normal. This is what happens most of the time, except this one time when I got the exception.

Screenshots
N/A

Smartphone (please complete the following information):

  • Device: Google Pixel 2 XL
  • OS: Android 9, API 28

Additional context
None

@hsson hsson added the bug Something isn't working label Apr 4, 2019
@hsson
Copy link
Author

hsson commented Apr 4, 2019

Actually, this happens quite often. If I simply leave the scanner running, lock my phone and leave it locked for a few seconds, then unlock it, this happens.

@alistairsykes alistairsykes self-assigned this Apr 8, 2019
@alistairsykes
Copy link
Contributor

Thanks for reporting @hsson. Have you found this on any other devices too? My aim would certainly be for this to be reported through the OnCameraErrorListener

@hsson
Copy link
Author

hsson commented Apr 8, 2019

I can reproduce this in the emulator as well! Simply by leaving the scanner running, locking the phone (the emulators power button), leaving it locked for a few seconds, then unlocking again. Are you saying it's possible for me to catch this error and handle it myself through the OncameraErrorListener? :)

@hsson
Copy link
Author

hsson commented Apr 8, 2019

I tried setting the OnCameraErrorListener on my BarcodeView in my fragment's onResume method, but this didn't catch the error.

@alistairsykes
Copy link
Contributor

Sorry, I mean my intention for fixing this issue would be to make it return in the OnCameraErrorListener. I will take a look this.

@hsson
Copy link
Author

hsson commented Apr 8, 2019

Okay, sounds great! :)

@alistairsykes
Copy link
Contributor

I haven't been able to create this, but if I create PR for what I think the changes should be @hsson would you be able to see if they are suitable for your needs?

@hsson
Copy link
Author

hsson commented Apr 8, 2019

Hm okay! Well that would be great, I can test it out. I could also try and create an example app that recreates the issue.

@hsson
Copy link
Author

hsson commented Apr 8, 2019

I did some more digging, and I'm starting to suspect that this is caused by the fact that I'm calling start() on my BarcodeView unconditionally in my fragments onResume(), I did this as the camera for some reason sometimes wouldn't start automatically either on resuming to the fragment or after having granted permissions.

alistairsykes added a commit that referenced this issue Apr 8, 2019
…a is released properly and report the error through the listener.
@alistairsykes
Copy link
Contributor

Oh ok interesting. We have just merged in a pull request which should catch the CameraAccessException and return it in the OnCameraErrorListener. If you wouldn't mind checking it reports the exception rather than crashing that would be great, even if there is another issue somewhere, it would be good to see if this resolves that.

Are you able to provide your implementation to show the camera not starting? How have you chosen to implement the library: lifecycle aware or manual; xml or programmatic? Did you follow a particular sample?

@alistairsykes
Copy link
Contributor

@hsson

@hsson
Copy link
Author

hsson commented Apr 8, 2019

Okay I've solved the issue on my end now! I accidentally and incorrectly called ActivityCompat.requestPermissions instead of calling requestPermissions directly on my fragment. This meant that my callback never got called, so my view_barcode.start() was never called. What a silly thing... I implemented the library lifecycle aware using XML. And like I said in my last comment, it appears that my calls to start() in my onResume() is what caused the crashes, but this is not needed anymore.

@hsson
Copy link
Author

hsson commented Apr 8, 2019

Sorry for the headache! :)

I'll see if I can get around to verifying that your pull request fixes the original issue as well!

@alistairsykes
Copy link
Contributor

@hsson Ahh yes that is a silly gotcha. I'm glad you found the issue.

Interestingly, even adding start() in onResume() doesn't cause that crash for me.

@alistairsykes alistairsykes removed their assignment May 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants