Android开发Android技术知识Android开发

hw_get_module() 是如何获取到对应 hw_modu

2019-06-24  本文已影响3人  爱因私谈
image.png

hw_get_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);
}

hardware so 命名如下:

 name
 |  |
id.inst.subname.so
 |  |     |
 |  |     依次从下面属性中查找,以它们的值当做subname,如果都找不到就用“default”作为subname
 |  |     {ro.hardware.%s,(%s为id.inst组成的name)
 |  |     ro.hardware,
 |  |     ro.product.board,
 |  |     ro.board.platform,
 |  |     ro.arch}
 |  一般为空,与id组成name
 hw_get_module()传进来的第一个参数,比如sensor、power、audio对应不同模块

如:sensor模块hardware so为:

// id: sensors
// inst: null
// subname: rk30board
sensors.rk30board.so

hw_get_module_by_class() 按照上面so的命名规则组合出so库名,再到下面目录中去查找对应文件:

“/system/lib/hw”
“/vendor/lib/hw”

当找到压so文件,则调用dlopen()打开so并取得文件句柄,再调用dlsym()从中取得hw_module_t结构返回。

上一篇 下一篇

猜你喜欢

热点阅读