Android12之HIDL转AIDL通信(一百三十七)

本文介绍了如何使用hidl2aidl工具将HIDL接口转换为AIDL,包括创建HIDL文件,执行转换命令,以及对比转换前后的接口内容差异。转换过程涉及编译工具,指定包路径和选项,以及转换后的目录结构。

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

1.编译hidl2aidl bin
# make hidl2aidl
# ls out/soong/host/linux-x86/bin/hidl2aidl
out/soong/host/linux-x86/bin/hidl2aidl

# hidl2aidl --help
hidl2aidl: invalid option -- '-'
Usage: hidl2aidl [-fh] [-o <output path>] [-l <header file>] [-p <root path>] (-r <interface root>)+ [-R] [-F] [-v] [-d <depfile>] FQNAME

Converts FQNAME, PACKAGE(.SUBPACKAGE)*@[0-9]+.[0-9]+(::TYPE)? to an aidl equivalent.

        -f: Force hidl2aidl to convert older packages
        -e: Used for expanding extensions and types from other packages
        -h: Prints this menu.
        -o <output path>: Location to output files.
        -l <header file>: File containing a header to prepend to generated files.
        -p <root path>: Android build root, defaults to $ANDROID_BUILD_TOP or pwd.
        -R: Do not add default package roots if not specified in -r.
        -F: Require all referenced ASTs to be frozen.
        -r <package:path root>: E.g., android.hardware:hardware/interfaces.
        -v: verbose output.
        -d <depfile>: location of depfile to write to.
2.创建HIDL文件
# mkdir -p hardware/interfaces/open/1.0
# emacs IOpen.hal
package android.hardware.open@1.0;

interface IOpen {
    putChars(string msg);
    getChars() generates (string msg);
};

注意:interface IOpen接口中的IOpen,必须是I开头;如果定义为interface Open,则错误报错。
3.HIDL到AIDL转换
# cd hardware/interfaces/open
# mkdir aidl
# hidl2aidl -o hardware/interfaces/open/aidl -r android.hardware:hardware/interfaces android.hardware.open@1.0

# tree 
.
├── 1.0
│   └── IOpen.hal
└── aidl
    ├── Android.bp
    ├── android
    │   └── hardware
    │       └── open
    │           └── IOpen.aidl
    └── conversion.log

注意:以上均为转换后自动生成的目录和文件.
4.对比IOpen.hal与IOpen.aidl内容
<1>.IOpen.hal
package android.hardware.open@1.0;

interface IOpen {
    putChars(string msg);
    getChars() generates (string msg);
};
<2>.IOpen.aidl
// FIXME: license file, or use the -l option to generate the files with the header.

package android.hardware.open;

@VintfStability
interface IOpen {
    // Adding return type to method instead of out param String msg since there is only one return value.
    String getChars();

    void putChars(in String msg);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Android系统攻城狮

你的鼓励将是我创作的最大动力!

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

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

打赏作者

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

抵扣说明:

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

余额充值