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

try/catch getCameraInfo() on Camera1Engine.java #1244

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

EzequielAdrianM
Copy link
Contributor

Please merge, this is a small try/catch that helps to prevent the apps using the library from crashing on devices using the old Camera1 API.

Fix Runtime Exception on devices trying to use Camera1

Fatal Exception: java.lang.RuntimeException: Fail to get camera info
at android.hardware.Camera.getCameraInfo(Camera.java:332)
at com.otaliastudios.cameraview.engine.Camera1Engine.collectCameraInfo(Camera1Engine.java:144)

Fix Runtime Exception on devices trying to use Camera1

Fatal Exception: java.lang.RuntimeException: Fail to get camera info
       at android.hardware.Camera.getCameraInfo(Camera.java:332)
       at com.otaliastudios.cameraview.engine.Camera1Engine.collectCameraInfo(Camera1Engine.java:144)
@natario1
Copy link
Owner

Wouldn't it be better to just continue the for loop? Maybe the next camera info succeeds.

Fatal Exception: java.lang.RuntimeException: Fail to get camera info
       at android.hardware.Camera.getCameraInfo(Camera.java:332)
       at com.otaliastudios.cameraview.engine.Camera1Engine.collectCameraInfo(Camera1Engine.java:144)
@EzequielAdrianM
Copy link
Contributor Author

I just modified the commit so that the loop can continue looking for other Camera info's.

Every time getParameters() is called, it can fail with RuntimeException: "getParameters failed (empty parameters)"

So the fix is to try/catch and Log.e the failure. Please tell me if you need to throw REASON_UNLNOWN exception or let the app continue.

LOGCAT CRASH:

Exception java.lang.RuntimeException: getParameters failed (empty parameters)
  at android.hardware.Camera.native_getParameters
  at android.hardware.Camera.getParameters (Camera.java:3088)
  at com.otaliastudios.cameraview.engine.Camera1Engine$3.run (Camera1Engine.java:579)
  at com.otaliastudios.cameraview.engine.orchestrator.CameraStateOrchestrator$3.run (CameraStateOrchestrator.java:100)
  at com.otaliastudios.cameraview.engine.orchestrator.CameraOrchestrator$1.call (CameraOrchestrator.java:84)
  at com.otaliastudios.cameraview.engine.orchestrator.CameraOrchestrator$1.call (CameraOrchestrator.java:81)
  at com.otaliastudios.cameraview.engine.orchestrator.CameraOrchestrator$3.run (CameraOrchestrator.java:152)
  at com.otaliastudios.cameraview.internal.WorkerHandler.run (WorkerHandler.java:137)
  at com.otaliastudios.cameraview.engine.orchestrator.CameraOrchestrator.execute (CameraOrchestrator.java:147)
  at com.otaliastudios.cameraview.engine.orchestrator.CameraOrchestrator.access$100 (CameraOrchestrator.java:34)
  at com.otaliastudios.cameraview.engine.orchestrator.CameraOrchestrator$2.run (CameraOrchestrator.java:137)
  at android.os.Handler.handleCallback (Handler.java:836)
  at android.os.Handler.dispatchMessage (Handler.java:103)
  at android.os.Looper.loop (Looper.java:203)
  at android.os.HandlerThread.run (HandlerThread.java:61)
Copy link

codecov bot commented Jan 7, 2024

Codecov Report

Merging #1244 (84a32b8) into main (6aa2d3a) will decrease coverage by 0.7%.
Report is 16 commits behind head on main.
The diff coverage is 59.1%.

❗ Current head 84a32b8 differs from pull request most recent head 0470e35. Consider uploading reports for the commit 0470e35 to get more accurate results

Additional details and impacted files
Files Coverage Δ
...a/com/otaliastudios/cameraview/CameraListener.java 85.7% <100.0%> (+1.1%) ⬆️
...java/com/otaliastudios/cameraview/CameraUtils.java 69.5% <ø> (ø)
.../otaliastudios/cameraview/engine/CameraEngine.java 90.3% <ø> (ø)
...taliastudios/cameraview/gesture/GestureAction.java 88.0% <100.0%> (+0.5%) ⬆️
...studios/cameraview/internal/FpsRangeValidator.java 71.4% <100.0%> (+4.8%) ⬆️
.../com/otaliastudios/cameraview/overlay/Overlay.java 100.0% <ø> (ø)
...taliastudios/cameraview/overlay/OverlayLayout.java 89.6% <100.0%> (+0.7%) ⬆️
...udios/cameraview/preview/SurfaceCameraPreview.java 90.0% <100.0%> (+0.3%) ⬆️
...tudios/cameraview/video/SnapshotVideoRecorder.java 78.7% <100.0%> (-1.1%) ⬇️
...tudios/cameraview/video/encoding/MediaEncoder.java 82.3% <100.0%> (+0.6%) ⬆️
... and 9 more

... and 15 files with indirect coverage changes

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

Successfully merging this pull request may close these issues.

None yet

2 participants