赞
踩
引入HIDL的一个重要原因是Android团队想要将Android Framework和Android vendor之间的代码进行解耦,即franmework不依赖于vendor的代码,如此Android团队在开发franework的时候就可以屏蔽底层的硬件差异了。在面向对象编程中提倡基于接口编程其实也是这个思想,调用者并不直接调用实现类提供的接口,而是通过事先定义好的接口进行调用/实现。为了实现framework和vendor解耦,Android引入了VINTF object(Vendor Interface Object)。接下来要讲的DM(device manifest)和FCM(Framework Compatibility Matrixes)则属于VINTF object的一部分。
VINTF object则是用于framework告知vendor其想要什么,以及vendor告知framework它有什么。下面看下它们的关系图。
VINTF object 的涉及主要涉及的功能如下:
对于vendor
a) Defines a schema for the static component.(the device manifest file).
b) Adds build time support for defining the device manifest file for a given device.
c) Defines the queryable API at runtime that retrieves the device manifest file (along with the other runtime-collectible information) and packages them into the query result.
对于framework
a) Defines a schema for the static component (the framework manifest file).
b) Defines the queryable API at runtime that retrieves the framework manifest file and packages it into the query result.
一个VINTF object数据由来自device manifest 和 framework manifest files 的所匹配的信息组成,例如DM中提供的和FCM所要求的组件成功匹配上的一例。
Device Manifests由厂商维护,其中包含vendor Manifests 和 ODM Manifests两个部分。
Device Manifests
The vendor manifest specifies HALs, SELinux policy versions, etc. common to an SoC. It is recommended to be placed in the Android source tree at device/VENDOR/DEVICE/manifest.xml, but multiple fragment files can be used.
ODM Manifests
The ODM manifest lists HALs specific to the product in the ODM partition.
FCM 用于描述 framework 在运行时所需要的组件。FCM又分为SCM(system compatibilty matrix),PCM(product compatibility matrix)和 SECM(system_ext compatibility matrix)。 被列出在FCM的组件则静态的写入xml文件中,并且Android在编译、运行以及做VTS测试的时候都会检测设备能否满足FCM的要求。
//file:test/flagstaffTest/hardware/interfaces/custom_hardware/1.0/default/Android.bp
cc_binary {
name: "flagstaff.hardware.custom_hardware@1.0-service",
...
vintf_fragments: ["flagstaff.hardware.custom_hardware@1.0.xml"],
}
//file:test/flagstaffTest/hardware/interfaces/custom_hardware/1.0/default/flagstaff.hardware.custom_hardware@1.0.xml
<manifest version="1.0" type="device">
<hal format="hidl">
<name>flagstaff.hardware.custom_hardware</name>
<transport>hwbinder</transport>
<version>1.0</version>
<interface>
<name>ICustomHardware</name>
<instance>default</instance>
<instance>custom</instance>
</interface>
</hal>
</manifest>
此处的DM信息说明,vendor侧提供了2个版本1.0接口ICustomHardware的实现,其分别是default和custom。在使用时可以使用如下方法选择获取对应实例
//获取default实例
android::sp<ICustomHardware> instance = ICustomHardware::getService();
//获取custom实例
android::sp<ICustomHardware> custom = ICustomHardware::getService("custom");
//file:test/flagstaffTest/device.mk
DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE += \
test/flagstaffTest/compatibility_matrix/framework_compatibility_matrix.xml
//file:test/flagstaffTest/compatibility_matrix/framework_compatibility_matrix.xml
<compatibility-matrix version="2.0" type="framework">
<hal format="hidl" optional="true">
<name>flagstaff.hardware.custom_hardware</name>
<version>1.0</version>
<interface>
<name>ICustomHardware</name>
<instance>default</instance>
<instance>custom</instance>
</interface>
</hal>
</compatibility-matrix>
此处的FCM信息说明,framework需要版本为1.0接口ICustomHardware的两个实现,其分别是default和custom。但是此处的optional为true意味着该组件为可选,所以即使不提供对应的DM的话也不影响系统编译运行测试的。
另外如果有问题,欢迎留言或者email(836190520@qq.com)我,技术升级在于交流~~
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。