一、什么是HIDL
HIDL 全称为HAL interface definition language(发音为“hide-l”)是用于指定 HAL 和其用户之间的接口的一种接口描述语言 (IDL),Android O开始引入了HIDL这个概念,HIDL和应用层AIDL差不多,AIDL常用于连接App和Framework,HIDL则是用来连接Framework和HAL,AIDL使用Binder通信,HIDL则使用HwBinder通信,他们都是通过Binder驱动完成通信,只不过两个Binder域不一样。
二、实例学习测试。
1、整个源码在https://download.csdn.net/download/qq_37858386/34862866路径下面,代码这里我是放在vendor/mediatek/proprietary/hardware/interfaces/hello_hidl这么目录。
2、执行下面的命令生成相应的Android.dp文件。
PACKAGE=vendor.mediatek.hardware.hello_hidl@1.0
LOC=vendor/mediatek/proprietary/hardware/interfaces/hello_hidl/1.0/default/
hidl-gen -o $LOC -Lc++-impl -rvendor.mediatek.hardware:vendor/mediatek/proprietary/hardware/interfaces -randroid.hidl:system/libhidl/transport $PACKAGE
hidl-gen -o $LOC -Landroidbp-impl -rvendor.mediatek.hardware:vendor/mediatek/proprietary/hardware/interfaces -randroid.hidl:system/libhidl/transport $PACKAGE
./vendor/mediatek/proprietary/hardware/interfaces/update-makefiles.sh
3、vendor/etc/vintf/manifest.xml里面添加
<hal format="hidl">
<name>vendor.mediatek.hardware.pq</name>
<transport>hwbinder</transport>
<version>2.6</version>
<interface>
<name>IPictureQuality</name>
<instance>default</instance>
</interface>
<fqname>@2.6::IPictureQuality/default</fqname>
</hal>
4、执行下面两个命令编译
mmm vendor/mediatek/proprietary/hardware/interfaces/hello_hidl/1.0/default
mmm vendor/mediatek/proprietary/hardware/interfaces/hello_hidl/1.0/default/app
5、会生成下面四个文件,adb push到设备的相应目录
out\target\product\xxx\vendor\lib64\vendor.mediatek.hardware.hello_hidl@1.0.so
out\target\product\xxx\vendor\lib64\hw\vendor.mediatek.hardware.hello_hidl@1.0-impl.so
out\target\product\xxx\vendor\bin\hw\vendor.mediatek.hardware.hello_hidl@1.0-service
out\target\product\xxx\vendor\bin\Hello_App
6、运行这个vendor.mediatek.hardware.hello_hidl@1.0-service二进制可执行文件,这个文件就会执行service.cpp的代码,调用defaultPassthroughServiceImplementation注册我们的HIDL服务。
7、测试程序代码Helloo_App,获取IHello的服务,然后调用addition_hidl函数.
三、参考文章
AndroidQ 打通应用层到HAL层---(HIDL服务实现)_DJLZPP的博客-CSDN博客
AndroidQ 打通应用层到HAL层---(HAL模块实现)_DJLZPP的博客-CSDN博客