Torch is behaving weirdly when set to off

62 views
Skip to first unread message

Ranjan Malav

unread,
Jul 21, 2021, 12:35:46 PM7/21/21
to Android CameraX Discussion Group
Hi team,

I'm experiencing strange behavior from the torch. Just after launching the app, when I try to turn it off with `cam.cameraControl.enableTorch(false)` it switches off, then turns on and goes off again.
This happens 2-3 times and after that, it starts to behave normally.
I've created a small android app to test this behavior. 

Unfortunately, my open source project is completely dependent on the timings of the flashlight and this weird behavior is making it unusable. It's happening on all kinds of devices.
Reported devices:
Oneplus 7 Pro, Android 11
Redmi Note 4, Android 11
Huawei ANE LX1
Huawei HUAWEI P20 Lite, Android 9

Leo Huang

unread,
Jul 21, 2021, 11:51:15 PM7/21/21
to Android CameraX Discussion Group, ranja...@gmail.com
Hi,
Thanks for reporting it.
The symptom sounds indeed weird. The test app (https://github.com/ranjan-malav/camerax-torch) does very basic operations.
I test it by the provided test app on my local devices but do not observe it.
My test devices are
Pixel 5, android 11
Huawei ANE LX2, android 8.0
Nokia 1, android 10

Can the issue be reproduced by every device you test and 100%? 
Could you attach a video that show the symptom encountered?

Thanks

ranja...@gmail.com 在 2021年7月22日 星期四上午12:35:46 [UTC+8] 的信中寫道:

Ranjan Malav

unread,
Jul 22, 2021, 12:25:38 PM7/22/21
to Android CameraX Discussion Group, leoh...@google.com, Ranjan Malav
Strangely I've not been able to reproduce it since yesterday. But I've definitely experienced it myself.
This is the app in which I'm using cameraX libraries.
You can check the latest review by the user.
"But there seems to be a slight bug where a single tap produces two quick flashes."
Also, here is a report from another user on the github project.
"However, there seems to be a bug where if I tap the "tap & hold the icon to transmit manually" then it flashes twice instead of once (Huawei ANE LX1)"

Can you try the app and see if it's happening? Meanwhile, I'll try to reproduce at my end and share a video if possible.

Ranjan Malav

unread,
Jul 22, 2021, 12:45:29 PM7/22/21
to Android CameraX Discussion Group, Ranjan Malav, leoh...@google.com
Luckily I was able to capture it in the video once(Redmi Note 4, Android 11). This happened for the first time only and it was working normally after that.

Leo Huang

unread,
Jul 26, 2021, 4:44:30 AM7/26/21
to Android CameraX Discussion Group, ranja...@gmail.com, Leo Huang
Thank you for updating these information. They are very helpful.
We have found a possible cause and will update more information if any.

ranja...@gmail.com 在 2021年7月23日 星期五上午12:45:29 [UTC+8] 的信中寫道:

Leo Huang

unread,
Jul 28, 2021, 3:44:07 AM7/28/21
to Android CameraX Discussion Group, Leo Huang, ranja...@gmail.com
Hi
I was trying a solution on the Huawei P20 Lite but did not work.
I found the issue can be reproduced 100% on Huawei P20 Lite when quickly turn ON/OFF torch. The torch will flash twice while turn OFF.
But unfortunately it seems to be a device specific timing issue on Huawei P20 Lite because I cat get the same result by implementing a test app with camera2 API. (CameraX base on camera2 API.)
There is a workaround for this device, that is to wait for the completion of ListenableFuture of enableTorch() request and then issue next request.
For example by modifying the test project,

    // Create a single thread executor to execute the torch requests sequentially.
    private val executor = Executors.newSingleThreadExecutor()

    private fun switchFlash(cam: Camera, on: Boolean) {
        isFlashOn = on
        executor.execute {
            try {
                cam.cameraControl.enableTorch(on).get() // blocking until request complete.
            } catch (e: ExecutionException) {
                // log error
            }
        }
    }

Not sure if the workaround is feasible for your application since it may delay for a while if quickly switching torch.
I currently do not have Redmi Note 4 and other devices you pasted, so I am not able to confirm are they also device specific issue.
Would you mind to test if the workaround feasible on the device you test?


Leo Huang 在 2021年7月26日 星期一下午4:44:30 [UTC+8] 的信中寫道:
Reply all
Reply to author
Forward
0 new messages