File tree Expand file tree Collapse file tree 1 file changed +5
-23
lines changed
app/src/main/java/io/github/sds100/keymapper/system/camera Expand file tree Collapse file tree 1 file changed +5
-23
lines changed Original file line number Diff line number Diff line change @@ -209,39 +209,21 @@ class AndroidCameraAdapter(context: Context) : CameraAdapter {
209209
210210 try {
211211 val cameraId = getFlashlightCameraIdForLens(lens)
212+ val flashInfo = getFlashInfo(lens)
212213
213- if (cameraId == null ) {
214+ if (cameraId == null || flashInfo == null ) {
214215 return when (lens) {
215216 CameraLens .FRONT -> Error .FrontFlashNotFound
216217 CameraLens .BACK -> Error .BackFlashNotFound
217218 }
218219 }
219220
220- val maxStrength = if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
221- getCharacteristicForLens(
222- lens,
223- CameraCharacteristics .FLASH_INFO_STRENGTH_MAXIMUM_LEVEL ,
224- )
225- } else {
226- null
227- }
228-
229- val defaultStrength =
230- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
231- getCharacteristicForLens(
232- lens,
233- CameraCharacteristics .FLASH_INFO_STRENGTH_DEFAULT_LEVEL ,
234- )
235- } else {
236- null
237- }
238-
239221 // try to find a camera with a flash
240- if (enabled && maxStrength != null && defaultStrength != null && Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
222+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU && enabled && flashInfo.supportsVariableStrength ) {
241223 val strength = if (strengthPercent == null ) {
242- defaultStrength
224+ flashInfo. defaultStrength
243225 } else {
244- (strengthPercent * maxStrength).toInt().coerceAtLeast(1 )
226+ (strengthPercent * flashInfo. maxStrength).toInt().coerceAtLeast(1 )
245227 }
246228 cameraManager.turnOnTorchWithStrengthLevel(cameraId, strength)
247229 } else {
You can’t perform that action at this time.
0 commit comments