Android 源码分析 - 硬件适配层 - 通用定义

        硬件适配层通用接口定义在hardware/libhardware/include/hardware/hardware.h。

typedef struct hw_module_t {

    /** tag must be initialized to HARDWARE_MODULE_TAG */

    uint32_t tag;

    uint16_t module_api_version;

#define version_major module_api_version

    uint16_t hal_api_version;

#define version_minor hal_api_version

    /** Identifier of module */

    const char *id;

    /** Name of this module */

    const char *name;

    /** Author/owner/implementor of the module */

    const char *author;

    /** Modules methods */

    struct hw_module_methods_t* methods;

    /** module's dso */

    void* dso;

    /** padding to 128 bytes, reserved for future use */

    uint32_t reserved[32-7];

} hw_module_t;

        模块通用方法open,用来打开一个设备。

typedef struct hw_module_methods_t {

    /** Open a specific device */

    int (*open)(const struct hw_module_t* module, const char* id,

            struct hw_device_t** device);

} hw_module_methods_t;

        设备通用方法close,用来关闭该设备。

typedef struct hw_device_t {

    /** tag must be initialized to HARDWARE_DEVICE_TAG */

    uint32_t tag;

    uint32_t version;

    /** reference to the module this device belongs to */

    struct hw_module_t* module;

    /** padding reserved for future use */

    uint32_t reserved[12];

    /** Close this device */

    int (*close)(struct hw_device_t* device);

} hw_device_t;

搜索模块

int hw_get_module(const char *id, const struct hw_module_t **module);

int hw_get_module_by_class(const char *class_id, const char *inst,

                           const struct hw_module_t **module);

int hw_get_module(const char *id, const struct hw_module_t **module)

{

    return hw_get_module_by_class(id, NULL, module);

}

  1. 搜索目录
    1. /vendor/lib/hw
    2. /system/lib/hw
  2. 搜索文件名称
    1. <class_id>.<inst>.<subname>.so (没有lib前缀)
  3. subname
    1. property_get "ro.hardware.<class_id>.<inst>"
    2. property_get "ro.hardware"
    3. property_get "ro.product.board"
    4. property_get "ro.board.platform"
    5. property_get "ro.arch"
    6. "default"

举例:

/vendor/lib/hw/lights.[ro.hardware.lights].so

/system/lib/hw/lights.[ro.hardware.lights].so

/vendor/lib/hw/lights.[ro.hardware].so

/system/lib/hw/lights.[ro.hardware].so

/vendor/lib/hw/lights.[ro.product.board].so

/system/lib/hw/lights.[ro.product.board].so

/vendor/lib/hw/lights.[ro.board.platform].so

/system/lib/hw/lights.[ro.board.platform].so

/vendor/lib/hw/lights.[ro.arch].so

/system/lib/hw/lights.[ro.arch].so

/system/lib/hw/lights.default.so

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Fighting Horse

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值