Android R(11)为自定义HIDL接口添加DM&&FCM(六)

本文介绍如何通过DM和FCM实现自定义HIDL接口,包括在Android.bp中添加DM信息及在设备清单和兼容矩阵中配置的过程。适用于Android Framework与Vendor间代码解耦。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

为自定义HIDL接口添加DM&&FCM(六)

1.概览

  引入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.

2.设备清单-Manifests

   一个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.

3.兼容矩阵-Compatibility Matrixes

  FCM 用于描述 framework 在运行时所需要的组件。FCM又分为SCM(system compatibilty matrix),PCM(product compatibility matrix)和 SECM(system_ext compatibility matrix)。 被列出在FCM的组件则静态的写入xml文件中,并且Android在编译、运行以及做VTS测试的时候都会检测设备能否满足FCM的要求。

4.ICustomHardware的 DM

4.1 在Android.bp中添加DM信息

//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"],
}

4.2 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");

5.ICustomHardware的FCM

5.1 将FCM添加到Android编译系统

//file:test/flagstaffTest/device.mk
DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE += \
        test/flagstaffTest/compatibility_matrix/framework_compatibility_matrix.xml

5.2 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)我,技术升级在于交流~~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值