VINTF简介

VINTF简介

是Vendor Interface Object的缩写,即厂商接口对象。

关于Treble

各分区较合理的规划方式:

  • Product: OEM相关定制,主要包括Apps,SDK,产品sysprops等
  • System: Android系统的Framework和Daemons
  • Treble Interface: Treble接口
  • Vendor: 硬件相关驱动/Daemons
  • ODM: ODM相关定制,包括ODM相关的Apps,SDK等,还有VINTF支持

Treble Interface组成成分,

在Android O添加的接口:

  • C++依赖(使用VNDK),
  • IPC调用(使用HIDL),
  • SELinux,
  • 通用Kernel接口,
  • Android Verified Boot(AVB);

到Android P新增接口:

  • Java依赖(使用System SDK),

  • 系统Properties。

概述

VINTF指的是Vendor Interface object,是android 8.0分离system和vendor分区的机制之一,用来检查system和vendor依赖是否匹配。

Framework(system)和Device(vendor)匹配的框架如下:

  • Manifest 描述了提供给对方的feature(Provider)

  • Matrix 描述了需要对方提供的feature(Requirement)

Manifest 和 Matrix 在OTA升级前会进行匹配检查,以确保framework和device是兼容的。总的来说,manifest是提供端,matrix是需求端。

Manifest

Framework manifest文件是由Google手动生成的。

  • 在aosp源码的路径: system/libhidl/manifest.xml
  • 在设备上的路径: /system/manifest.xml

Device manifest文件是和设备,硬件相关的。

  • 在aosp源码路径: device/${VENDOR}/${DEVICE}/manifest.xml
  • 在设备的路径: /vendor/manifest.xml

具体清单描述如下:

source.android.google.cn/docs/core/a...

Manifest Fragment

在您的 Android.bpAndroid.mk 文件中,将 vintf_fragments 添加到任意模块

具体可查看:

source.android.google.cn/docs/core/a...

本质上就是在汇总manifest的时候,除了常规路径,还会将各个子仓库的VINTF碎片汇总进来。

Compatibility Matrices

Framework compatibility matrix描述的是framework对 device的需求。

这个matrix文件是和Android Framework Image(system.img)关联的。

Framework compatibility matrix的这些需要被device manifest支持。

Device compatibility matrix描述了device对framework的需求。

具体兼容性矩阵描述如下:

source.android.google.cn/docs/core/a...

运行时数据

有些需求的信息是在运行时搜集的。通过接口

::android::vintf::VintfObject::GetRuntimeInfo(),信息包括以下:

Kernel信息

/proc/config.gz. 压缩过的kernel配置,需要在运行时被转化成一个可查询的对象

/proc/version. 系统调用uname()的到的信息

/proc/cpuinfo. 格式可能根据32位和64位而有所不同

policydb version

/sys/fs/selinux/policyvers (假设selinuxfs加载在/sys/fs/selinux).

Libselinux的security_policyvers() 接口返回结果是一样的

Static Lib AVB version

bootloader system property:ro.boot.vbmeta.avb_version

init/fs_mgr system property:ro.boot.avb_version

查询接口

VINTF Object也是系统API,提供给hwservicemanager、OTA升级服务、CTS DeviceInfo等模块调用以便获取信息用以匹配。

可查询的供应商接口对象的代码位于system/libvintf

C++ 查询API位于:

bash 复制代码
system/libvintf/VintfObject.cpp
arduino 复制代码
android::vintf::VintfObject

Java 查询API位于:

bash 复制代码
frameworks/base/core/java/android/os/VintfObject.java
lua 复制代码
android.os.VintfObject

vendor和system检查不通过会弹窗:

关于feature

不同工程提供的feature不同,需要差异化配置。

可以在各自feature的mk中通过 DEVICE_MANIFEST_FILE 来申明和该feature相关的 manifest.xml,

编译时候会收集所有mk中的DEVICE_MANIFEST_FILE组合成一个完整的manifest.xml。

Stable AIDL

source.android.com/devices/arc...

Google 在Android 11引入了AIDL for HALs,旨在代替HIDL原先的作用。在之后的Android版本推荐使用AIDL 实现Hal层的访问。 这样做的原因,应该有以下几点:

  • AIDL比HIDL存在的时间更长(仅从Android 8到Android 10),并在许多其他地方使用,如Android框架组件之间或应用程序中。既然AIDL具有稳定性支持,就可以用单一的IPC方式从HAL到框架进程或者应用进程。
  • AIDL还有一个比HIDL更好的版本控制系统。

也就是说,VINTF接口后面会演变成aidl接口为主,而不是hidl。

例如,

原来的hidl的接口为:

xml 复制代码
<manifest version="1.0" type="device">

    <hal format="hidl">

        <name>vendorabcd.hardware.sensorscalibrate</name>

        <transport>hwbinder</transport>

        <version>1.0</version>

        <interface>

            <name>ISensorsCalibrate</name>

            <instance>default</instance>

        </interface>

    </hal>

</manifest>

后面改为了如下:

xml 复制代码
<manifest version="1.0" type="device">

    <hal format="aidl">

        <name>vendorabcd.hardware.sensorscalibrate</name>

        <transport>hwbinder</transport>

        <version>1</version>

        [可以保留原本的写法:]

        <interface>

            <name>ISensorsCalibrate</name>

            <instance>default</instance>

        </interface>

      [或者使用fqname:]

      <fqname>ISensorsCalibrate/default</fqname>

        [两种任选一个即可]

    </hal>

</manifest>

相关工具

细节可参考:

source.android.google.cn/docs/core/a...

LSHAL

在设备端查看设备清单文件:

sql 复制代码
/system/bin/lshal --init-vintf

ASSEMBLE_VINTF

主机端的工具,功能:

  1. 验证兼容性矩阵或清单文件是否有效。
  2. 将变量注入到构建时可用的清单/兼容性矩阵,并生成应该安装到设备上的新文件。
  3. 检查生成的文件与其双重文件之间的兼容性。
  4. 如果给出了清单文件,则可以视需要生成与该清单文件兼容的样板兼容性矩阵。

帮助文档

shell 复制代码
#./assemble_vintf --help

assemble_vintf: Checks if a given manifest / matrix file is valid and 
    fill in build-time flags into the given file.
assemble_vintf -h
               Display this help text.
assemble_vintf -i <input file>[:<input file>[...]] [-o <output file>] [-m]
               [-c [<check file>]]
               Fill in build-time flags into the given file.
    -i <input file>[:<input file>[...]]
               A list of input files. Format is automatically detected for the
               first file, and the remaining files must have the same format.
               Files other than the first file should only have <hal> defined;
               other entries are ignored. Argument may also be specified
               multiple times.
    -o <output file>
               Optional output file. If not specified, write to stdout.
    -m
               a compatible compatibility matrix is
               generated instead; for example, given a device manifest,
               a framework compatibility matrix is generated. This flag
               is ignored when input is a compatibility matrix.
    -c [<check file>]
               The path of the "check file"; for example, this is the path
               of the device manifest for framework compatibility matrix.
               After writing the output file, the program checks against
               the "check file", depending on environment variables.
               - PRODUCT_ENFORCE_VINTF_MANIFEST=true: check compatibility
               If any check fails, an error message is written to stderr.
               Return 1.
    --kernel=<version>:<android-base.config>[:<android-base-arch.config>[...]]
               Add a kernel entry to framework compatibility matrix or device
               manifest. Ignored for other input format.
               There can be any number of --kernel for framework compatibility
               matrix, but at most one --kernel and at most one config file for
               device manifest.
               <version> has format: 3.18.0
               <android-base.config> is the location of android-base.config
               <android-base-arch.config> is the location of an optional
               arch-specific config fragment, more than one may be specified
    -l, --hals-only
               Output has only <hal> entries. Cannot be used with -n.
    -n, --no-hals
               Output has no <hal> entries (but all other entries).
               Cannot be used with -l.
    --no-kernel-requirements
               Output has no <config> entries in <kernel>, and kernel minor
               version is set to zero. (For example, 3.18.0).

计划写一篇VINTF匹配原理和使用,以及stable AIDL调用的文章。

相关推荐
万能的小裴同学8 分钟前
Android M3U8视频播放器
android·音视频
q***577437 分钟前
MySql的慢查询(慢日志)
android·mysql·adb
JavaNoober1 小时前
Android 前台服务 "Bad Notification" 崩溃机制分析文档
android
城东米粉儿2 小时前
关于ObjectAnimator
android
zhangphil3 小时前
Android渲染线程Render Thread的RenderNode与DisplayList,引用Bitmap及Open GL纹理上传GPU
android
火柴就是我4 小时前
从头写一个自己的app
android·前端·flutter
lichong9515 小时前
XLog debug 开启打印日志,release 关闭打印日志
android·java·前端
用户69371750013845 小时前
14.Kotlin 类:类的形态(一):抽象类 (Abstract Class)
android·后端·kotlin
火柴就是我5 小时前
NekoBoxForAndroid 编译libcore.aar
android
Kaede66 小时前
MySQL中如何使用命令行修改root密码
android·mysql·adb