https://deepinout.com/android-camera-native-framework/camera-java-fw-aidl-icameraservicelistener-aidl-details.html
1 ICameraServiceListener类图
黑色部分为对应的程序代码,
调用流程
C++
BpCameraServiceListener – ICameraServiceListener
AIDL
Java
ICameraServiceListener.Stub – OnTransact()
2 Android AIDL oneway修饰符
在 Android AIDL中,oneway 是一种修饰符,用于声明一个方法是单向的(one-way)。
使用 oneway 修饰符声明的方法不会阻塞调用线程,而是立即返回并在后台运行,因此不需要等待方法执行完成。
这种方式适用于客户端和服务端之间不需要进行同步通信的情况,例如通知服务端某项任务已经完成。
需要注意的是,在客户端调用带有 oneway 修饰符的方法时,无法得知方法是否返回成功或失败,因为该方法会立即返回,而不会等待服务端响应。
因此,建议将 oneway 修饰符仅用于不需要接收服务端响应的方法。
3 ICameraServiceListener.aidl接口详解
/** @hide */
interface ICameraServiceListener
{
/**
* Initial status will be transmitted with onStatusChange immediately
* after this listener is added to the service listener list.
*
* Allowed transitions:
*
* (Any) -> NOT_PRESENT
* NOT_PRESENT -> PRESENT
* NOT_PRESENT -> ENUMERATING
* ENUMERATING -> PRESENT
* PRESENT -> NOT_AVAILABLE
* NOT_AVAILABLE -> PRESENT
*
* A state will never immediately transition back to itself.
*
* The enums must match the values in
* include/hardware/camera_common.h when applicable
*/
// Device physically unplugged
const int STATUS_NOT_PRESENT = 0;
// Device physically has been plugged in and the camera can be used exclusively
const int STATUS_PRESENT = 1;
// Device physically has been plugged in but it will not be connect-able until enumeration is
// complete
const int STATUS_ENUMERATING = 2;
// Camera is in use by another app and cannot be used exclusively
const int STATUS_NOT_AVAILABLE = -2;
// Use to initialize variables only
const int STATUS_UNKNOWN = -1;
oneway void onStatusChanged(int status, String cameraId);
/**
* Notify registered client about status changes for a physical camera backing
* a logical camera.
*/
oneway void onPhysicalCameraStatusChanged(int status, String cameraId, String physicalCameraId);
/**
* The torch mode status of a camera.
*
* Initial status will be transmitted with onTorchStatusChanged immediately
* after this listener is added to the service listener list.
*
* The enums must match the values in
* include/hardware/camera_common.h
*/
// The camera's torch mode has become not available to use via
// setTorchMode().
const int TORCH_STATUS_NOT_AVAILABLE = 0;
// The camera's torch mode is off and available to be turned on via
// setTorchMode().
const int TORCH_STATUS_AVAILABLE_OFF = 1;
// The camera's torch mode is on and available to be turned off via
// setTorchMode().
const int TORCH_STATUS_AVAILABLE_ON = 2;
// Use to initialize variables only
const int TORCH_STATUS_UNKNOWN = -1;
oneway void onTorchStatusChanged(int status, String cameraId);
oneway void onTorchStrengthLevelChanged(String cameraId, int newTorchStrength);
/**
* Notify registered clients about camera access priority changes.
* Clients which were previously unable to open a certain camera device
* can retry after receiving this callback.
*/
oneway void onCameraAccessPrioritiesChanged();
/**
* Notify registered clients about cameras being opened/closed.
* Only clients with android.permission.CAMERA_OPEN_CLOSE_LISTENER permission
* will receive such callbacks.
*/
oneway void onCameraOpened(String cameraId, String clientPackageId);
oneway void onCameraClosed(String cameraId);
}