I was getting the context from the main activity and it was working with Foreground service until I press to home button. After I implemented LifecycleOwner to the service, I cannot get the Camera frames even the app is open.
D/CameraRepository: Added camera: 0
I/Camera2CameraInfo: Device Level: INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED
I/CameraManagerGlobal: postSingleUpdate device: camera id 0 status STATUS_PRESENT
I/CameraManagerGlobal: postSingleUpdate device: camera id 1 status STATUS_PRESENT
D/UseCaseAttachState: Active and attached use case: [] for camera: 0
I/CameraManagerGlobal: postSingleUpdate device: camera id 2 status STATUS_PRESENT
D/CameraRepository: Added camera: 1
I/Camera2CameraInfo: Device Level: INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED
I/CameraManagerGlobal: postSingleUpdate device: camera id 0 status STATUS_PRESENT
I/CameraManagerGlobal: postSingleUpdate device: camera id 1 status STATUS_PRESENT
I/CameraManagerGlobal: postSingleUpdate device: camera id 2 status STATUS_PRESENT
D/CameraRepository: Added camera: 2
D/UseCaseAttachState: Active and attached use case: [] for camera: 1
I/Camera2CameraInfo: Device Level: INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED
I/CameraManagerGlobal: postSingleUpdate device: camera id 0 status STATUS_PRESENT
I/CameraManagerGlobal: postSingleUpdate device: camera id 1 status STATUS_PRESENT
I/CameraManagerGlobal: postSingleUpdate device: camera id 2 status STATUS_PRESENT
D/UseCaseAttachState: Active and attached use case: [] for camera: 2
D/CameraOrientationUtil: getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=270, isOppositeFacing=false, result=270
D/DeferrableSurface: Surface created[total_surfaces=1, used_surfaces=0](androidx.camera.core.impl.ImmediateSurface@2797ba5}
D/Camera2CameraImpl: {Camera@50536c5[id=1]} Use case ImageAnalysis:androidx.camera.core.ImageAnalysis-bea87099-87f4-434d-9ba7-90571f6c862f ACTIVE