android12/13/14上支持新加入Hidl的hal方法-No more HIDL interfaces can be added to Android. Please use AIDL

背景:

正常新版本比如aosp13,如果说新建一个Hidl想要进行运行,在编译开始时候就会报如下错误:

No more HIDL interfaces can be added to Android. Please use AIDL

即新版本让你不要再使用 HIDL interfaces而是使用AIDL方式

但是很多学员提出,公司和方案上就是要求做hidl,很多时候不是自己可以随意决定,所以那是否高版本就真的不可以进行hidl的开发么?如果这样为啥系统自带了很多hidl是怎么可以通过编译校验的呢?

修改掉编译报错:

先考虑让编译不报错:No more HIDL interfaces can be added to Android. Please use AIDL

那么得寻找哪里有这个报错,具体找到如下:
在这里插入图片描述可以看到具体是在如下目:
system/tools/hidl/build/hidl_interface.go:498

那么来看看这个代码部分
在这里插入图片描述

有一种暴力做法是直接把这个if判断都进行屏蔽

  if !canInterfaceExist(i.ModuleBase.Name()) {
            mctx.PropertyErrorf("name", "No more HIDL interfaces can be added to Android. Please use AIDL.")
            return
    }

但是这样可能会让系统整个版本任何人都可以添加hidl,这样确实不太合理波及范围太大。
那么有什么办法可以只让我们自己hidl通过么,类似白名单东西?

答案当然是有啦,比如android系统自带那些hidl可以编译通过都是因为有个白名单,白名单在哪就是要上面的canInterfaceExist方法:


func canInterfaceExist(name string) bool {
        if strings.HasPrefix(name, "android.") {
                return allAospHidlInterfaces[name]
        }

        return true
}
//最后就是靠这个allAospHidlInterfaces名单来过滤
var allAospHidlInterfaces = map[string]bool{
        "android.frameworks.automotive.display@1.0":         true,
        "android.frameworks.bufferhub@1.0":                  true,
        "android.frameworks.cameraservice.common@2.0":       true,
        "android.frameworks.cameraservice.device@2.0":       true,
        "android.frameworks.cameraservice.device@2.1":       true,
        "android.frameworks.cameraservice.service@2.0":      true,
        "android.frameworks.cameraservice.service@2.1":      true,
        "android.frameworks.cameraservice.service@2.2":      true,
        "android.frameworks.displayservice@1.0":             true,
        "android.frameworks.schedulerservice@1.0":           true,
        "android.frameworks.sensorservice@1.0":              true,
        "android.frameworks.stats@1.0":                      true,
        "android.frameworks.vr.composer@1.0":                true,
        "android.frameworks.vr.composer@2.0":                true,
        "android.hardware.atrace@1.0":                       true,
        "android.hardware.audio@2.0":                        true,

上面是不是就看到了白名单,把android自带的一些hidl都是放入白名单。

其实也可以通过git log方式看看google是怎么新版本添加hidl:
使用git log -p hidl_interface.go即只查看hidl_interface.go这一个文件的提交修改

test@test:~/aosp/system/tools/hidl/build$ git log -p hidl_interface.go
commit 4fa2b9ba79667837c3dbf607ba97d6c01aa31382
Merge: 4a66e183 97e276d4
Author: Roopa Sattiraju <sattiraju@google.com>
Date:   Wed Feb 2 01:22:03 2022 +0000

    Adding min_sdk_version to bluetooth_audio libs for bt apex deps am: e0977657a1 am: ae873b363e am: e50737ac99 am: 97e276d4d8
    
    Original change: https://android-review.googlesource.com/c/platform/system/tools/hidl/+/1932823
    
    Change-Id: I957abe24b2b90159b7bf67a636f0f63e98f1a5f0

commit 4a66e1833adbf7365a6da706f4140debb6b15eb1
Author: Mikhail Naganov <mnaganov@google.com>
Date:   Fri Jan 21 22:17:43 2022 +0000

    Add android.hardware.audio@7.1
    
    This is an exemption from the rule on no new HIDL
    interfaces in T.
    
    Ignore-AOSP-First: Part of an internal topic, will upstream
    Bug: 214426419
    Test: m
    Change-Id: I8615d8a5e1490d74c79ddb3c57594b36d26144d9

diff --git a/build/hidl_interface.go b/build/hidl_interface.go
index 0ea768af..8084c442 100644
--- a/build/hidl_interface.go
+++ b/build/hidl_interface.go
@@ -881,6 +881,7 @@ var allAospHidlInterfaces = map[string]bool{
        "android.hardware.audio@5.0":                        true,
        "android.hardware.audio@6.0":                        true,
        "android.hardware.audio@7.0":                        true,
+       "android.hardware.audio@7.1":                        true,
        "android.hardware.audio.common@2.0":                 true,
        "android.hardware.audio.common@4.0":                 true,
        "android.hardware.audio.common@5.0":                 true,



明显看到 "android.hardware.audio@7.1"也是这样添加的,所以我们也可以把自己hidl这样添加一下。

diff --git a/build/hidl_interface.go b/build/hidl_interface.go
index fa770d15..d73173cc 100644
--- a/build/hidl_interface.go
+++ b/build/hidl_interface.go
@@ -884,6 +884,7 @@ var allAospHidlInterfaces = map[string]bool{
        "android.hardware.audio@6.0":                        true,
        "android.hardware.audio@7.0":                        true,
        "android.hardware.audio@7.1":                        true,
+       "android.hardware.hidltest@1.0":                     true,
        "android.hardware.audio.common@2.0":                 true,
        "android.hardware.audio.common@4.0":                 true,
        "android.hardware.audio.common@5.0":                 true,

这样保存好既可以编译通过了。

其他hidl部分的代码:

代码部分操作建议先参考如下两个链接:
https://blog.csdn.net/learnframework/article/details/134621556
相关兼容性矩阵manifest等参考aidl的:
https://blog.csdn.net/learnframework/article/details/134945726

当然我这里也提供相关的直接demo资料哈(仅仅学员可以获取哈)
链接: https://pan.baidu.com/s/1UOrjn6F5r0j_N3gjBKASzA

运行结果

在这里插入图片描述

更多framework技术干货,请关注下面“千里马学框架”

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

千里马学框架

帮助你了,就请我喝杯咖啡

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值