VINTF简介

2023年 10月 13日 29.8k 0

VINTF简介

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

关于Treble

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)匹配的框架如下:

VINTF框架

  • 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 添加到任意模块

image-20231009175356886

具体可查看:

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位于:

system/libvintf/VintfObject.cpp
android::vintf::VintfObject

Java 查询API位于:

frameworks/base/core/java/android/os/VintfObject.java
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更好的版本控制系统。

AIDL演变

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

例如,

原来的hidl的接口为:



    

        vendorabcd.hardware.sensorscalibrate

        hwbinder

        1.0

        

            ISensorsCalibrate

            default

        

    


后面改为了如下:



    

        vendorabcd.hardware.sensorscalibrate

        hwbinder

        1

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

        

            ISensorsCalibrate

            default

        

      [或者使用fqname:]

      ISensorsCalibrate/default

        [两种任选一个即可]

    


相关工具

细节可参考:

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

LSHAL

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

/system/bin/lshal --init-vintf

ASSEMBLE_VINTF

主机端的工具,功能:

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

    #./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 [:[...]] [-o ] [-m]
                   [-c []]
                   Fill in build-time flags into the given file.
        -i [:[...]]
                   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  defined;
                   other entries are ignored. Argument may also be specified
                   multiple times.
        -o 
                   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 []
                   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=:[:[...]]
                   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.
                    has format: 3.18.0
                    is the location of android-base.config
                    is the location of an optional
                   arch-specific config fragment, more than one may be specified
        -l, --hals-only
                   Output has only  entries. Cannot be used with -n.
        -n, --no-hals
                   Output has no  entries (but all other entries).
                   Cannot be used with -l.
        --no-kernel-requirements
                   Output has no  entries in , and kernel minor
                   version is set to zero. (For example, 3.18.0).
    

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

    相关文章

    服务器端口转发,带你了解服务器端口转发
    服务器开放端口,服务器开放端口的步骤
    产品推荐:7月受欢迎AI容器镜像来了,有Qwen系列大模型镜像
    如何使用 WinGet 下载 Microsoft Store 应用
    百度搜索:蓝易云 – 熟悉ubuntu apt-get命令详解
    百度搜索:蓝易云 – 域名解析成功但ping不通解决方案

    发布评论