Camera sometimes not closing

473 views
Skip to first unread message

re.le...@gmail.com

unread,
May 31, 2021, 5:09:52 AM5/31/21
to Android CameraX Discussion Group
Hello!

I am having issue of Camera lens not closing sometimes. It does not happen always. It happens randomly. I have application that uses Navigation and closing/opening Camera is happening more then once per application lifecycle. 

I noticed this in my logcat: 2021-05-31 10:56:02.172 23887-24170/com.ahss.mbid D/CameraStateRegistry: Recalculating open cameras:
    Camera                                       State                 
    -------------------------------------------------------------------
    Camera@f0c87e7[id=0]                         UNKNOWN               
    Camera@f0fbb83[id=1]                         CLOSING               
    -------------------------------------------------------------------
    Open count: 1 (Max allowed: 1)

Above is example of Camera got stuck. One lens is working but other just outputs black screen.
What is to note is that it does not always get stuck in this state. Sometimes it gets stuck in PENDING state. 
I call unbindAll() method in onDestroyView() callback before I close fragment that hosts camera stream. This method should close all cameras but I have this issue sometimes regardless. 

My question is is there a method that can force close camera. This way I could force close camera lens before using Camera again.

Thanks in advance
Igor


Wenhung Teng

unread,
May 31, 2021, 5:49:21 AM5/31/21
to Android CameraX Discussion Group, re.le...@gmail.com
Hi, 
We also notice this kind of issue happen on specific device some, the CameraHAL fail at the closing step. 
At this moment, CameraX didn't have a public API to force clean the state of the camera device. But we are working on a solution to close the camera internally for this case.
Can you share us the CameraX library version, device model name and android OS version? We will inform you if we have a update for this issue.

re.le...@gmail.com 在 2021年5月31日 星期一下午5:09:52 [UTC+8] 的信中寫道:

re.le...@gmail.com

unread,
Jun 1, 2021, 5:20:42 AM6/1/21
to Android CameraX Discussion Group, wenhu...@google.com, re.le...@gmail.com
Hi,
Current CameraX version is 1.0.0-rc02

It happened on most of devices. As for my testing devices its Samsung s8+ Android OS 9, also Motorola One Action Android OS 10. 
As for my colleges one of them has Samsung s8+ but kept on Android OS 7, he did not stress test is as much and has not yet had this issue. 

It seems that this issue is happening quite often. Could it be that some resources are keeping camera opened? I do close all ImageProxy images on analyzer so I dont think its that. Since I am bidning and unbiding to swtich camera lens, it never failed there.

re.le...@gmail.com

unread,
Jun 1, 2021, 7:49:37 AM6/1/21
to Android CameraX Discussion Group, re.le...@gmail.com, wenhu...@google.com
Edid: Samsung s9+ Android 9 has also the same issue.

Wenhung Teng

unread,
Jun 1, 2021, 8:35:11 AM6/1/21
to Android CameraX Discussion Group, re.le...@gmail.com, Wenhung Teng
Thanks for the information, we will also keep track of these models.
In our experiences, the camera closing flow might be stuck if the ImageProxy is not closed in API 21 and 22 devices, but rarely happens in the recent models. 
 
The reason for this (camera cannot be closed) problem could be different between devices, mostly might be that the cameraHAL layer doesn't finish or is still waiting for some tasks in the pipeline, and that would cause the closed callback doesn't be called. 
We are now internally testing a fix for this kind of error to close the camera. Will inform you if the update is ready in the new version.
re.le...@gmail.com 在 2021年6月1日 星期二下午5:20:42 [UTC+8] 的信中寫道:

Android CameraX Discussion Group

unread,
Jun 2, 2021, 8:55:13 PM6/2/21
to Android CameraX Discussion Group, Wenhung Teng, re.le...@gmail.com
Create https://issuetracker.google.com/189994064 to track this issue.

Wenhung Teng

unread,
Jun 7, 2021, 10:42:37 PM6/7/21
to Android CameraX Discussion Group, Android CameraX Discussion Group, Wenhung Teng, re.le...@gmail.com
Hi, we have an update in the alpha05. The change can help the camera go to the close state.
Could you use the alpha05 to have a try? Hope this can help the issue you experienced.

Android CameraX Discussion Group 在 2021年6月3日 星期四上午8:55:13 [UTC+8] 的信中寫道:

re.le...@gmail.com

unread,
Jun 9, 2021, 3:42:51 AM6/9/21
to Android CameraX Discussion Group, wenhu...@google.com, Android CameraX Discussion Group, re.le...@gmail.com
Hi, I saw the update and updated CameraX as soon as I saw a fix. I tested it now for around 2 days and the issue did not happen. I hope it stays this way :) 
Thanks for the help, and if the issue arise again I will post here.

Igor

Wenhung Teng

unread,
Jun 9, 2021, 4:04:53 AM6/9/21
to Android CameraX Discussion Group, re.le...@gmail.com, Wenhung Teng, Android CameraX Discussion Group

Cool! Please feel free to inform us if you have any further investigation.
We are also keeping track of this issue and consider cherry-pick this update into the stable line if it works as expected.

re.le...@gmail.com 在 2021年6月9日 星期三下午3:42:51 [UTC+8] 的信中寫道:

Jay Patel

unread,
Aug 10, 2022, 2:23:30 AM8/10/22
to Android CameraX Discussion Group, wenhu...@google.com, re.le...@gmail.com, Android CameraX Discussion Group
Hi Guys,

This issue is still happening for me regardless of new version. Updated to the latest version 1.1.0 but still happening on GalaxyS9 and other devices. It seems it takes time to go into CLOSING state. I could see the logs printing after few seconds. And meanwhile If I open the camera again, it's getting stuck sometimes getting into deadlock and showing black screen then I had to restart my device to make it work again.

Check the time I close my activity and then getting log of camera state closing:

2022-08-10 10:07:18.209 5543-7378/I /mali_winsys: delete_surface() [1080x2220] return ------------------->Closed Activity with executor.shutdown()
2022-08-10 10:07:27.684 5543-12355/D/Camera2CameraImpl: {Camera@3879634[id=0]} Closing camera. ----------------> After few seconds initiated closing process from cameraX lib
2022-08-10 10:07:27.685 5543-12355/D/Camera2CameraImpl: {Camera@3879634[id=0]} Transitioning camera internal state: OPENED --> CLOSING
2022-08-10 10:07:27.685 5543-12355/D/CameraStateRegistry: Recalculating open cameras:
    Camera                                       State                
    -------------------------------------------------------------------
    Camera@3879634[id=0]                         CLOSING              
    Camera@5bbe11e[id=1]                         UNKNOWN              
    Camera@f2644b8[id=2]                         UNKNOWN              
    -------------------------------------------------------------------
Could you please update if anyone else got the clear solution on any specific version?

Thanks,

Scott Nien

unread,
Aug 10, 2022, 2:49:23 AM8/10/22
to Jay Patel, Android CameraX Discussion Group, wenhu...@google.com, re.le...@gmail.com
Hi Jay, 

How do you reproduce the issue ?  is it 100% reproducible ?


--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/d6400069-5e83-4b7c-8fdb-6bb5a8d5bf53n%40android.com.

Jay Patel

unread,
Aug 10, 2022, 3:13:21 AM8/10/22
to Android CameraX Discussion Group, scot...@google.com, Android CameraX Discussion Group, wenhu...@google.com, re.le...@gmail.com, Jay Patel
Hi Scott, 

Actually yes its 100% reproducible, though its rare game! It's like I keep playing with opening and closing camera activity for number of times. So before getting CLOSED state log, I opened again to capture something else and if I keep doing this, at one point It's conflicting with the previous state as It hasn't been closed and getting into deadlock situation where I could only see black screen while opening the preview and then even if I go to default camera app it doesn't work and I had to restart my device to make it work. 

Scott Nien

unread,
Aug 10, 2022, 3:57:44 AM8/10/22
to Jay Patel, Android CameraX Discussion Group, wenhu...@google.com, re.le...@gmail.com
This seems to be a known Samsung issue that Camera service or HAL is stuck at some state and cannot recover unless rebooted. 
BTW, when this issue happens,  do you wait a little longer like 10 seconds and try again ?  we did find that sometimes camera service will restart and it takes some time to be ready again. 




Jay Patel

unread,
Aug 10, 2022, 4:06:16 AM8/10/22
to Android CameraX Discussion Group, scot...@google.com, Android CameraX Discussion Group, wenhu...@google.com, re.le...@gmail.com, Jay Patel
Yes, I tried to wait for few minutes but it didn't come back to the original state without rebooting. Well Samsung is still better, It's happening so quickly with devices like Huawei P30, couldn't open camera within few seconds unless it comes to CLOSED state. Is there any way to close camera forcefully or release something? M I missing something or the delay of coming to CLOSED state is the normal behavior with CameraX? I tried with almost 3 4 devices like Galaxy s9, galaxy s10, huawei P30 all same.

Scott Nien

unread,
Aug 12, 2022, 4:12:33 AM8/12/22
to Jay Patel, Android CameraX Discussion Group, wenhu...@google.com, re.le...@gmail.com
Thanks Jay,  I'd like to clarify further, 
Then the issue happens in the Huawei P30,  were you able to open the camera in native camera app ?  
This is important, because,  if native camera app cannot open the camera either,  it means the camera service or HAL was stuck at something.  But if CameraX cannot see camera output but native camera app works fine,  then this is likely an issue in CameraX.  

Jay Patel

unread,
Aug 12, 2022, 4:17:38 AM8/12/22
to Scott Nien, Android CameraX Discussion Group, wenhu...@google.com, re.le...@gmail.com
Hi Scott,

Yes native camera app works fine! It's getting messed up once we go through the scenario I suggested! The only reason is, keep opening the cameraX again and again before it reaches CLOSED state as it takes a few seconds time even though you destroy the activity. 

Scott Nien

unread,
Aug 12, 2022, 4:56:48 AM8/12/22
to Jay Patel, Android CameraX Discussion Group, wenhu...@google.com, re.le...@gmail.com
>  The only reason is, keep opening the cameraX again and again before it reaches CLOSED state as it takes a few seconds time even though you destroy the activity. 

It is likely caused by the camera service being dead and restarted (or maybe too many actions beine queued in the camera service or HAL).  It may take a few seconds to recover.  We have added more stress tests than before and are now analyzing the failure. Hopefully we can improve this soon. 

BTW I wonder,  are you also doing the stress test or just some manual tests ?

Jay Patel

unread,
Aug 18, 2022, 1:21:58 AM8/18/22
to Scott Nien, Android CameraX Discussion Group, re.le...@gmail.com, wenhu...@google.com
Well glad to know that you’re about to reach the error!

Regarding test type, we can consider based on following:

Galaxy s9 and s10 : Stress test
Huawei P30 : Manual test (It happens within the first attempt when you open the camera again before the first instance gets into CLOSED state.
Reply all
Reply to author
Forward
0 new messages