Greetings.
Maybe I can help. In CameraX beta04 was added Camera2Interop. It allow set some settings to use cases and in your case set focus.
Example below in Kotlin.
private fun initPreviewUseCase(): Preview {
val preview = Preview.Builder()
attachSettingsTo(preview, false)
return preview.build()
}
private fun attachSettingsTo(useCaseBuilder: Any, isAF:Boolean){
Camera2Interop.Extender(useCaseBuilder as ExtendableBuilder<*>).run {
if (isAF) setCaptureRequestOption(CaptureRequest.CONTROL_AF_MODE, CameraMetadata.CONTROL_AF_MODE_CONTINUOUS_VIDEO)
else {
setCaptureRequestOption(CaptureRequest.CONTROL_AF_MODE, CameraMetadata.CONTROL_AF_MODE_OFF)
setCaptureRequestOption(CaptureRequest.LENS_FOCUS_DISTANCE, 0F) // 0F - means infinity focus
}}}
Usefull links.