Android HAL Service开发总结

Android HAL Service开发总结:

1.需要针对自己的hwservice编写init.rc启动脚本 vendor.device.xxx_hwfunservice-1.1.rc

复制代码
service vendor.device.xxx_hwfunservice-1.1 /vendor/bin/hw/vendor.device.xxx_hwfun@1.1-service
        class hal
    user system
    group system
    setenv FUNC_CONFIGURATION /vendor/etc/hwfun/xxssyy.json

2.在自己service代码仓库的Android.bp中,添加自己hwservice的编译目标

复制代码
cc_binary {
    name: "vendor.device.hardware.hwfun@1.1-service",
    init_rc: ["vendor.device.xxx_hwfunservice-1.1.rc"],
    relative_install_path: "hw",   // 安装的相对路径(绝对路径是/vendor/bin/), /vendor/bin/hw/
    vendor: true,
    override:[
        "android.device.xxx_hwfunc@1.1-service",
        "android.device.xxx_hwfunc@1.0-service",   // 如果希望vendor的hwservice取代android自己原生的hwservice,则需要配置该项目
    ],
    srcs: [
        //用于编译该hwservice的源代码    
        "src/xxx.cpp",
        "src/yyy.cpp",
    ],
    include_dirs: [
        "include",
        "vendor/inc",
    ],
    static_libs: [
        "libexternal",
    ],
    }

3.为了让HWServiceManager知晓有我们创建的这么一个hwservice(vendor.device.xxx_hwfunservice-1.1),需要将我们HWService的信息注册到供应商清单文件中(manifests.xml)

清单文件一般放在Android项目根目录的device/{VENDOR}/{DEVICE}/目录下的manifests.xml文件中,添加的格式如下:

复制代码
 </hal>
    <hal format="hidl">
    <name>vendor.device.hardware.hwfun</name>
    <transport>hwbinder</transport>
    <version>1.1</version>
    <interface>
        <name>IHWFun</name>
        <instance>default</instance>
    </interface>
    <fqname>@1.0::IHWFun/default</fqname>
  </hal>

如果清单文件中没有我们HWService的信息,那么我们的HWSerice代码中向HWServcieManager注册我们的IHWFun这个HIDL接口会失败

注:HWService的信息可以放在evice/{VENDOR}/{DEVICE}/目录下的manifests.xml文件中,也可以在放在工程目录中单独的某个xml文件中,例如:vendor.device.xxx_hwfunservice-1.1.xml,里面的内容为

复制代码
<manifest version="1.0" type="device">
 </hal>
    <hal format="hidl">
    <name>vendor.device.hardware.hwfun</name>
    <transport>hwbinder</transport>
    <version>1.1</version>
    <interface>
        <name>IHWFun</name>
        <instance>default</instance>
    </interface>
    <fqname>@1.0::IHWFun/default</fqname>
  </hal>
</manifest>

然后在Android.bp中增加编译条目

vintf_fragments: ["vendor.device.xxx_hwfunservice-1.1.xml"],

4.Android9之后的版本,增加了FCM(Framework Compability Matrix),如果Android系统(例如Framework)用到了我们HWService的HIDL接口

那么我们的HWSerice信息也需要添加到 system FCM矩阵中(还有product FCM,如果product中的app用到了我们的HWService,那么Product的FCM文件中需要添加我们的HWService)

在编译期间,会检查供应商清单文件(manifests.xml)中的HIDL服务是否在FCM中,如果不存在,编译的时候会报错:

files are incompatible: The following instances are in the device manifest but not specified in framework compatibility matrix:

2024-05-22T10:46:07.164Z\] checkvintf E 05-22 10:46:00 3171190 3171190 check_vintf.cpp:620\] vendor.device.hardware.hwfun@1.0::IHWFun/default 如果我们的HWService是给Android的Framework使用,那么需要添加到framework_manifest.xml文件中 ,添加方式和供应商清单文件一样。 5.由于我们的HWService是自启动,并且也添加了init.rc,那么需要对应设置SELinux策略,一般是在vendor/目录下的某个file_contexts文件中添加 Android Selinux策略处理:[构建 SELinux 政策 \| Android Open Source Project](https://source.android.google.cn/docs/security/features/selinux/build?hl=zh-cn "构建 SELinux 政策  |  Android Open Source Project") Android FCM:[兼容性矩阵 \| Android Open Source Project](https://source.android.google.cn/docs/core/architecture/vintf/comp-matrices?hl=zh-cn "兼容性矩阵  |  Android Open Source Project")

相关推荐
Cao_Shixin攻城狮3 小时前
Flutter运行Android项目时显示java版本不兼容(Unsupported class file major version 65)的处理
android·java·flutter
呼啦啦呼啦啦啦啦啦啦6 小时前
利用pdfjs实现的pdf预览简单demo(包含翻页功能)
android·javascript·pdf
idjl8 小时前
Mysql测试题
android·adb
游戏开发爱好者810 小时前
iOS App 电池消耗管理与优化 提升用户体验的完整指南
android·ios·小程序·https·uni-app·iphone·webview
人生游戏牛马NPC1号11 小时前
学习 Flutter (四):玩安卓项目实战 - 中
android·学习·flutter
星辰也为你祝福h12 小时前
Android原生Dialog
android
梁同学与Android13 小时前
Android ---【CPU优化】需要优化的原因及优化的地方
android
Misha韩14 小时前
React Native 基础tabBar和自定义tabBar - bottom-tabs
android·react native
iHero14 小时前
【Nextcloud】在 Ubuntu 22.04.3 LTS 上的 Nextcloud Hub 10 (31.0.2) 后台任务cron 的优化
android·linux·ubuntu·nextcloud
yuanlaile18 小时前
Flutter Android打包学习指南
android·flutter·flutter打包·flutter android