introduction:
It is mainly to sort out the Android camera system for the architecture of CameraAPI v2 + HAL3.
camera architecture
App and FrameWork
Camera API v2 is located at:
packages/apps/Camer2
frameworks/ex/camera2
At the application framework level, use the Camera2 API to interact with the camera's hardware. Access and camera native layer code by calling Binder interface
AIDL
The binder interface associated with CameraService is located at:
frameworks/av/camera/aidl/android/hardware
The Java code generated by AIDL accesses the natvie layer, obtains the access permission of the physical device camera, and returns to the application framework layer to create a CameraDevice and finally create a CameraCaptureSession.
Native framework
The native classes of the CameraDevice and CameraCaptureSession classes are located at:
frameworks/av/camera
CameraDevice:
CameraCaptureSession:
binder IPC interface
Implement cross-process communication. The binder class that calls the camera service is located in the following path:
frameworks/av/camera/aidl/android/hardware
ICameraService: the interface of the camera service
ICameraDeviceUser: an open specific camera device
ICameraServiceListener: Callback for the CameraService of the application framework layer
ICameraDeviceCallbacks: the callback of the CameraDevice used to apply the framework layer
camera service
The implementation class of CameraService is located at:
frameworks/av/services/camera/libcameraservice/CameraService.cpp
The code that actually interacts with the HAL
HAL
Provides the implementation of the camera hardware operation standard interface called by CameraService
FILTER
The HIDL interface definition of the camera HAL is located at:
hardware/interfaces/camera
The HAL (hardware abstract layer) layer standard interface of the camera service that needs to be implemented
Implement HAL
The HAL layer is located between the camera driver and the Android Frameworks.
The HAL defines the interfaces that must be implemented so that the application can properly operate the camera hardware
A typical HAL binder must implement the following HIDL interface:
ICameraProvider: Used to enumerate individual camera devices and manage their state.
ICameraDevice: the interface of the camera device
ICameraDeviceSession: Active camera device session interface
input validation
Since the HAL can access different resources than the camera service, the boundary between the two is considered a security boundary.
Therefore, the camera HAL must validate the parameters passed from the camera service to the HAL layer. This includes: checking that buffer length values are within the allowed range, and sanitizing parameters before they are used and passed to hardware or kernel drivers.