Android学习14 -- VINF和兼容性矩阵

周末搞这玩意欲仙欲死,没办法只有看看。VINTF是供应商接口对象(VINTF 对象),准确的说,这个是属于兼容性矩阵概念。。。有点想起了以前看过的一个电影,异次元杀阵。。。

1 基础

这个是谷歌官方的图。

本质上其实就是两部分,设备提供什么能力,系统需要什么能力。然后看两者能否兼容匹配上。这两者都是使用xml进行描述。主要是Android8之后,system和vendor分离,为了确保两者的兼容性搞出来的。举例如下:

设备侧是Manifest描述:

device/VENDOR/DEVICE/manifest.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- Comments, Legal notices, etc. here -->
<manifest version="1.0" type="device" target-level="1">
    <!-- hals ommited -->
    <kernel version="4.4.176">
        <config>
            <key>CONFIG_ANDROID</key>
            <value>y</value>
        </config>
        <config>
            <key>CONFIG_ARM64</key>
            <value>y</value>
        </config>
    <!-- other configs ommited -->
    </kernel>
</manifest>

系统侧是Matrix描述:

/system/libhidl/manifest.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- Comments, Legal notices, etc. here -->
<manifest version="1.0" type="framework">
    <hal>
        <name>android.hidl.allocator</name>
        <transport>hwbinder</transport>
        <version>1.0</version>
        <interface>
            <name>IAllocator</name>
            <instance>ashmem</instance>
        </interface>
    </hal>
    <vendor-ndk>
        <version>27</version>
    </vendor-ndk>
    <system-sdk>
        <version>27</version>
    </system-sdk>
</manifest>

详细图如下(来自VINTF: manifest.xml | Cool Fish In Glacier):

Manifest类型Makefile Target生成文件..input files (源文件)
System Manifestmake system_manifest.xml/system/etc/vintf/manifest.xmlDEVICE_FRAMEWORK_MANIFEST_FILE + system/libhidl/vintfdata/manifest.xml
Product Manifestmake product_manifest.xml/product/etc/vintf/manifest.xmlPRODUCT_MANIFEST_FILES
Device Manifestmake device_manifest.xml/vendor/etc/vintf/manifest.xmlDEVICE_MANIFEST_FILE
ODM Manifestmake odm_manifest.xml/odm/etc/vintf/manifest.xmlODM_MANIFEST_FILES

我看说的一般是在/vendor/etc/vintf下面增加。一般是device_manifest和device_framework_compatibility_matrix这两个xml文件。

2 服务构建

就实践来说,要增加一个AIDL服务,大的有两个步骤。

1 服务编写

首先是在BP文件中增加对应的XML。vintf_fragments: ["android.hardware.xxx-service.xml"],

在代码中增加该xml,内容如下:

<manifest version="1.0" type="device">
    <hal format="aidl">
        <name>android.hardware.xxx</name>
        <version>1</version>
        <fqname>Ixxx/default</fqname>
    </hal>
</manifest>

之后正常编译。

2 运行环境搭建

主要是三个文件。

增加系统需要的能力和设备提供的能力。

adb push compatibility_matrix.device.xml /system/etc/vintf/compatibility_matrix.device.xml
adb push compatibility_matrix.xml /vendor/etc/vintf/compatibility_matrix.xml

内容和上面的xml稍微有点区别:

<hal format="aidl" optional="true">
    <name>android.hardware.xxx</name>
    <version>1</version>
    <interface>
        <name>Ixxx</name>
        <instance>default</instance>
    </interface>
</hal>

然后拷贝之前构造服务时候的xml到板子上/vendor/etc/vintf/manifest/中

adb push android.hardware.xxx.xml /vendor/etc/vintf/manifest/android.hardware.xxx.xml

运行服务如果报错的话会说Android servicemanager.cpp: servicemanager: Could not find <service> in the VINTF manifest。

一般就是xml没有拷贝对。

3 验证

在设备端查看提供的能力(HAL):

/system/bin/lshal --init-vintf

在设备端查看提供的能力(AIDL)

service list

4 参考资料

VINTF: manifest.xml | Cool Fish In Glacier

https://source.android.com/docs/core/architecture/vintf/resources?hl=zh-cn

VINTF简介-CSDN博客

清单  |  Android 开源项目  |  Android Open Source Project

  • 5
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值