RedApparat / Fotoapparat

Making Camera for Android more friendly. 📸
Apache License 2.0
3.82k stars 405 forks source link

Start / stop do not propagate IllegalStateException #179

Open Diolor opened 6 years ago

Diolor commented 6 years ago

FA#start() / FA#stop() function don't propagate the exceptions correctly but they throw them inside the thread

Context:

michaelschwinges commented 5 years ago

I'm also fairly certain that there's a problem propagating exceptions within start().

I am developing for an obscure, customised Android phone in use by law enforcement in my country. Therefore it is not a recognisable brand/model.

When opening FA with front camera, I get this exception in the debug console, however very importantly, the cameraErrorCallback's onError() is never called.

The output is:

W/System.err: at libcore.io.IoBridge.open(IoBridge.java:487) at java.io.FileOutputStream.(FileOutputStream.java:87) at java.io.FileOutputStream.(FileOutputStream.java:72) at android.util.SystemUtil.writeCameraState(SystemUtil.java:386) at android.hardware.Camera.open(Camera.java:507) at io.fotoapparat.hardware.CameraDevice.open(CameraDevice.kt:69) W/System.err: at io.fotoapparat.routine.camera.StartRoutineKt.start(StartRoutine.kt:42) at io.fotoapparat.routine.camera.StartRoutineKt.bootStart(StartRoutine.kt:26) D/SettingsInterface: from settings cache , name = show_keyboard_state , value = null W/System.err: at io.fotoapparat.Fotoapparat$start$1.invoke(Fotoapparat.kt:84) at io.fotoapparat.Fotoapparat$start$1.invoke(Fotoapparat.kt:34) at io.fotoapparat.concurrent.CameraExecutor$execute$future$1.call(CameraExecutor.kt:26) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818) W/System.err: Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied) at libcore.io.Posix.open(Native Method) at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186) at libcore.io.IoBridge.open(IoBridge.java:473) ... 14 more

Some further info on this weird Android device is that fotoapparat.isAvailable(front()) returns true, however the above error happens if you try and use it, and the preview surface remains black. Also interesting is that the built in camera app only shows preview for the back camera and will not show the flip front/back icon, so I am sure that the camera app knows that the front camera, which appears on the hardware info, throws errors when it is used and the camera app adjusts its behaviour accordingly.

What I am struggling with is therefore how to get FotoApparat to detect a janky device such as this so that I can not use the front camera (default for my app) and disable the flip camera button.