camera hw_get_module

本文探讨了Android中硬件抽象层(HAL)的加载机制,特别是如何通过hw_get_module函数实现对不同硬件模块的通用性调用。详细解析了hw_get_module及其内部的hw_get_module_by_class,展示其通过查找设备属性、遍历配置变体来找到对应的硬件模块动态链接库,并加载执行的过程。
摘要由CSDN通过智能技术生成

google为了保护硬件厂商的信息,在Android中添加了一层,也就是大名鼎鼎的HAL层。
HAL的编写方法的过程中,会发现整个模块貌似没有一个入口。一般说来模块都要有个入口,比
如应用程序有main函数,可以为加载器进行加载执行,dll文件有dllmain,而对于我们自己写的动态
链接库,我们可以对库中导出的任何符号进行调用。
问题来了,Android中的HAL是比较具有通用性的,需要上层的函数对其进行加载调用,Android的

HAL加载器是如何实现对不同的Hardware Module进行通用性的调用的呢?
带着这个疑问查看Android源码,会发现Android中实现调用HAL是通过hw_get_module实现的

int hw_get_module(const char *id, const struct hw_module_t **module)
{
    return hw_get_module_by_class(id, NULL, module); //id:camera
}

int hw_get_module_by_class(const char *class_id, const char *inst,
                           const struct hw_module_t **module)
{
    int i = 0;
    char prop[PATH_MAX] = {0};
    char path[PATH_MAX] = {0};
    char name[PATH_MAX] = {0};
    char prop_name[PATH_MAX] = {0};
    if (inst)
        snprintf(name, PATH_MAX, "%s.%s", class_id, inst);
    else
        strlcpy(name, class_id, PATH_MAX);

    /*
     * Here we rely on the fact that calling dlopen multiple times on
     * the same .so will simply increment a refcount (and not load
     * a new copy of the library).
     * We also assume that dlopen() is thread-safe.
     */

    /* First try a property specific to the class and possibly instance */
    snprintf(prop_name, sizeof(prop_name), "ro.hardware.%s", name);//ro.hardware.camera
    if (property_get(prop_name, prop, NULL) > 0) { //prop:sp9832e
        if (hw_module_ex

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值