第20讲 ICameraServiceListener.aidl详解

本讲是Android Camera Native Framework专题的第20讲,我们介绍ICameraServiceListener.aidl详解。

更多资源:

资源 描述
在线课程 极客笔记在线课程
知识星球 星球名称:深入浅出Android Camera 星球ID: 17296815
Wechat 极客笔记圈

ICameraServiceListener类图

ICameraServiceListener类图

Android AIDL oneway修饰符

在 Android AIDL中,oneway 是一种修饰符,用于声明一个方法是单向的(one-way)。

使用 oneway 修饰符声明的方法不会阻塞调用线程,而是立即返回并在后台运行,因此不需要等待方法执行完成。

这种方式适用于客户端和服务端之间不需要进行同步通信的情况,例如通知服务端某项任务已经完成。

需要注意的是,在客户端调用带有 oneway 修饰符的方法时,无法得知方法是否返回成功或失败,因为该方法会立即返回,而不会等待服务端响应。因此,建议将 oneway 修饰符仅用于不需要接收服务端响应的方法。

ICameraServiceListener.aidl接口详解

Function Description
oneway void onTorchStatusChanged(int status, String cameraId) 回调通知Flash Torch模式的状态变化
oneway void onTorchStrengthLevelChanged(String cameraId, int newTorchStrength) 回调通知Flash Torch的强度发生变化
oneway void onCameraAccessPrioritiesChanged() 当进程(CameraService的任何一个client)的adj或前后台状态发生变化时,会回调该方法。
oneway void onCameraOpened(String cameraId, String clientPackageId) 回调通知某个client(clientPackageId)打开了某颗(cameraId)Camera。 需要有android.permission.CAMERA_OPEN_CLOSE_LISTENER权限。
oneway void onCameraClosed(String cameraId) 回调通知某颗(cameraId)Camera被关闭了。 需要有android.permission.CAMERA_OPEN_CLOSE_LISTENER权限。

Android 13 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);
}

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程

Android Camera Native Framework