hidl与aidl的区别?
HIDL的全称是HAL interface definition language(硬件抽象层接口定义语言),在此之前Android 有AIDL,架构在Android binder 之上,用来定义Android 基于Binder通信的Client 与Service之间的接口。HIDL也是类似的作用,只不过定义的是Android Framework与Android HAL实现之间的接口
hidl跟以前的HAL有什么区别?
在Android O之前,HAL是一个个的.so库,通过dlopen来进行打开,库和framework位于同一个进程
在Android O之后,framework和hal运行于不同的进程,所有的HAL采用新的HIDL技术来完成
先从hardware这个目录开始研究下:
hidl节点文件 /dev/hwbinder
hardware/interfaces/xxx/1.0/default/
实现HAL接口端的共享库
[email protected] //binder client端
$(GEN): $(LOCAL_PATH)/Ixxx.hal
$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)
include $(BUILD_JAVA_LIBRARY)
实现HAL实现端的共享库
[email protected] //binder server端
LOCAL_MODULE := [email protected]
LOCAL_SRC_FILES := \
xxx_impl.cpp \
include $(BUILD_SHARED_LIBRARY)
Android native 进程入口
[email protected] //Android native 进程入口
启动binder server端进程的脚本
service xxx-hal-1-0 /vendor/bin/hw/[email protected]
class hal
user system
group system
binder server启动
LOCAL_MODULE := [email protected]
LOCAL_INIT_RC := [email protected]
LOCAL_SRC_FILES := \
service.cpp \
include $(BUILD_EXECUTABLE)
service.cpp
int main() {
return defaultPassthroughServiceImplementation<IDlpc3435>();
}
研究三种模式中的简单的直通(passthrough)模式
registerPassthroughServiceImplementation 函数是 HAL 服务的注册过程
将 Ixxx 服务注册到 hwservicemanager 中
service->registerAsService(name);//将Ixxx注册到hwservicemanager中
getPassthroughServiceManager()
创建一个new PassthroughServiceManager() 通过PassthroughServiceManager查询服务
拼接出后面需要查找的函数名HIDL_FETCH_Ixxx和库名字[email protected],然后查找"/system/lib64/hw/"、"/vendor/lib64/hw/"、"/odm/lib64/hw/"下是否有对应的so库。接着通过dlopen载入/vendor/lib/hw/[email protected],然后通过dlsym查找并调用HIDL_FETCH_Ixxx函数
HIDL_FETCH_Ixxx{
hw_get_module(xxx_HARDWARE_MODULE_ID, &hw_module);
hw_module->methods->open(hw_module
}
通过hw_get_module
就和Android O
以前的Hal模式一致
接下来的流程就跟之前HAL一样。。。
什么时候执行脚本?
开机时,init进程会读取并解析这个脚本
当然也可以自己手动执行这个bin文件[email protected]
达到同样效果!这样服务端就启动起来了!
如何调用客户端?
通过getService
getPassthroughServiceManager
获取binder对象,其他跟aidl一样!
有一点需要注意,就是我们可以通过app方式(Java)或者bin执行文件(cpp)方式调用客户端!
三种模式:
使用 passthrough 模式
Passthrough header files
Binderizing passthrough HALs