自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
手电筒强度控制
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
对于搭载 Android 13 或更高版本的设备,Android 框架针对手电筒强度提供了多级控制。在 Android 12 及更低版本中,Android 框架仅允许开启或关闭手电筒模式。通过支持对手电筒的多级强度控制,设备可以实现一些用例,例如根据光照条件控制手电筒的亮度,以及利用频闪效果连续发送快速闪动的光束以发送求救信号。此功能的另一个好处是,它可以延长电池续航时间并提升性能,因为手电筒模式并不总是需要以最大强度开启,以最大强度开启可能会导致热节流状况。
公共 API
应用可以通过以下公共 API 和相机特征键使用手电筒强度控制功能。这些 API 不需要相机权限,因为它们不访问相机。
CameraManager API
CameraCharacteristics 键
实现
如需在设备上支持手电筒强度控制功能,请使用以下相机 AIDL HAL 接口:
位置:/camera/device/aidl/android/hardware/camera/device/ICameraDevice.aidl
确保您的 HAL 实现通告以下相机特征键,以支持手电筒亮度控制功能:
如需查看支持手电筒强度控制的相机 HAL 参考实现,请参阅 EmulatedCameraDeviceHWLImpl.cpp
。
验证
如需验证手电筒强度控制功能的实现情况,请运行以下 VTS 和 CTS 测试:
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[null,null,["最后更新时间 (UTC):2025-03-26。"],[],[],null,["# Torch strength control\n\nFor devices running Android 13 or higher, the Android\nframework provides a multilevel control for torch strength. In\nAndroid 12 and lower, the framework allows only for\nturning the torch mode on or off. By supporting multilevel torch strength\ncontrol, devices can enable use cases such as controlling the brightness of the\nflashlight based on lighting conditions and sending signals for assistance\nusing a strobe effect by sending quick pulses of light in a row. Another\nbenefit of this feature is that it can improve battery life and performance as\nthe torch mode doesn't always need to be turned on at the maximum strength,\nwhich can lead to thermal throttling conditions.\n\nPublic APIs\n-----------\n\nApps can use the torch strength control feature through the following public\nAPIs and camera characteristics keys. No camera permissions are required for\nthese APIs because the camera isn't accessed.\n\n#### CameraManager APIs\n\n- [`public void turnOnTorchWithStrengthLevel (String cameraId, int torchStrength)`](https://developer.android.com/reference/android/hardware/camera2/CameraManager#turnOnTorchWithStrengthLevel(java.lang.String,%20int)): Sets the brightness level of the flashlight associated with the given `cameraId` value in torch mode. If torch mode is off and `torchStrength` is greater than or equal to `1`, the torch turns on with the strength level specified in `torchStrength`.\n- [`public int getTorchStrengthLevel (String cameraId)`](https://developer.android.com/reference/android/hardware/camera2/CameraManager#getTorchStrengthLevel(java.lang.String)): Returns the brightness level of the flash unit associated with `cameraId`.\n\n#### CameraCharacteristics keys\n\n- [`FLASH_INFO_STRENGTH_MAXIMUM_LEVEL`](https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#FLASH_INFO_STRENGTH_MAXIMUM_LEVEL): Maximum brightness level. The camera HAL advertises this feature by setting a value greater than `1`.\n- [`FLASH_INFO_STRENGTH_DEFAULT_LEVEL`](https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#FLASH_INFO_STRENGTH_DEFAULT_LEVEL): Default flashlight brightness level.\n\nImplementation\n--------------\n\nTo support the torch strength control feature on your device, use the following\ncamera AIDL HAL interfaces:\n\nLocation: `/camera/device/aidl/android/hardware/camera/device/ICameraDevice.aidl`\n\n- [`void turnOnTorchWithStrengthLevel(int torchStrength)`](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces/camera/device/aidl/android/hardware/camera/device/ICameraDevice.aidl?q=turnOnTorchWithStrengthLevel)\n- [`int getTorchStrengthLevel()`](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces/camera/device/aidl/android/hardware/camera/device/ICameraDevice.aidl?q=getTorchStrengthLevel)\n\nEnsure your HAL implementation advertises the following camera characteristics\nkeys to support the torch brightness control feature:\n\n- [`FLASH_INFO_STRENGTH_MAXIMUM_LEVEL`](https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#FLASH_INFO_STRENGTH_MAXIMUM_LEVEL)\n- [`FLASH_INFO_STRENGTH_DEFAULT_LEVEL`](https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#FLASH_INFO_STRENGTH_DEFAULT_LEVEL)\n\nFor a reference Camera HAL implementation supporting torch strength control,\nsee\n[`EmulatedCameraDeviceHWLImpl.cpp`](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/google/camera/devices/EmulatedCamera/hwl/EmulatedCameraDeviceHWLImpl.cpp).\n\nValidation\n----------\n\nTo validate your implementation of the torch strength control feature, run the\nfollowing VTS and CTS tests:\n\n- VTS: [`/camera/provider/aidl/vts/VtsAidlHalCameraProvider\\_TargetTest.cpp`](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces/camera/provider/aidl/vts/VtsAidlHalCameraProvider_TargetTest.cpp)\n- CTS: [`/platform/cts/tests/camera/src/android/hardware/camera2/cts/FlashlightTest.java`](https://cs.android.com/android/platform/superproject/+/android-latest-release:cts/tests/camera/src/android/hardware/camera2/cts/FlashlightTest.java)"]]