[Bug]: Flashlight brightness control crashes camerahalserver on Mediatek devices (SIGABRT)
Bug Description
Using the Flashlight QS tile from Essentials causes a fatal crash (SIGABRT) in camerahalserver on Mediatek devices. The crash originates from a state machine violation in the Mediatek Camera HAL:
Abort message: [onGetTorchStrengthLevelLocked] Cannot setTorchLevel after setTorchOff
The HAL asserts that setTorchLevel must not be called after setTorchOff. Essentials appears to call setTorchLevel (for brightness/fade effect) without ensuring the torch is in an active state first. This causes the camera provider to crash and restart in a loop (observed 14 consecutive crashes), making ALL cameras (IDs 0–6) unavailable until the HAL eventually self-recovers.
Steps to Reproduce
- Enable Flashlight qs tile in Essentials
- Toggle the flashlight on/off from qs tile Essentials provide
- No flashlight, camera becomes completely unavailable
- Check logcat for camerahalserver SIGABRT
Expected Behavior
Flashlight brightness control should work without crashing camerahalserver. The app should ensure torch is in an active/on state before calling setTorchLevel.
Screenshots
No response
Android Version
Android 16 (HyperOS 3.1)
Device
Xiaomi POCO X7 Pro (nezha, Dimensity 9300+)
App Version
15.2
Additional Context
Logcat abort message:
[onGetTorchStrengthLevelLocked] Cannot setTorchLevel after setTorchOff - 0:0 (onGetTorchStrengthLevelLocked){#618:vendor/mediatek/proprietary/hardware/mtkcam+android/main/hal/devicemgr/depend/CameraDeviceManagerImpl.cpp}
Possible fix: guard setTorchLevel calls with a check that the torch is currently enabled/on before adjusting brightness level.
Note: This issue is specific to Mediatek HAL. Pixel (Qualcomm/Google HAL) likely does not enforce this state assertion strictly.
Hope someone with hardware can look into this and test a solution :)
Given the clue from the other Mediatek issue (#465) about state machine violations (Cannot setTorchLevel after setTorchOff)—here are a few actionable technical ideas or contributions the developer could try to resolve it: State Guard Implementation: Suggest implementing a boolean state check or guard in the app's flashlight/brightness control logic. The app needs to explicitly verify that the torch is currently registered as "on" before sending any setTorchLevel commands, ensuring it never attempts to adjust brightness levels after a setTorchOff signal has been dispatched. Debounce Brightness/Toggle Calls: If the app is using a fade effect, brightness slider, or rapid toggling (like via a Quick Settings tile or a shortcut button), introduce a debounce or lock mechanism. This prevents conflicting asynchronous calls from hitting the MediaTek Camera HAL faster than its state machine can process them. Fallback to Basic Toggle: For MediaTek devices specifically, offer an option or automatic fallback that strips out advanced brightness/fade commands entirely, reverting the app's flashlight integration to a basic, safe on/off boolean state toggle to prevent triggering the SIGABRT crash.
BTW. If anyone can fix, I have a TCL Nxtpaper 11 Plus and happy to test any fixes.
Temporarily disabled brightness intensity control