Android 框架层AIDL 添加接口

因此,为进行通信,进程需将其对象分解成可供操作系统理解的原语,并将其编组为可供您操作的对象。如果未设置,则对应于在此编译上下文中具有稳定性的接口(因此此处加载的接口只能与一起编译的东西一起使用,例如在 system.img 上)。总结: 在冻结的AIDL接口上面加新的接口 需要做的步骤。AIDL 可以理解成是一个范式, 通过这个范式编写接口文件, 然后利用Android的AIDL工具 会生成继承binder所需要能力的头文件。然后通过服务调用其接口。编译会在下面的目录生成实现binder通信的接口文件。
摘要由CSDN通过智能技术生成

AIDL的原理

可以利用ALDL定义客户端与服务均认可的编程接口,以便二者使用进程间通信 (IPC) 进行相互通信。在 Android 中,一个进程通常无法访问另一个进程的内存。因此,为进行通信,进程需将其对象分解成可供操作系统理解的原语,并将其编组为可供您操作的对象。编写执行该编组操作的代码较为繁琐,因此 Android 会使用 AIDL 为您处理此问题。

AIDL 可以理解成是一个范式, 通过这个范式编写接口文件, 然后利用Android的AIDL工具 会生成继承binder所需要能力的头文件。

构建AIDL的流程

以automotive的audiocontrol模块为例

  1. 编写AIDL接口文件,编写Android.bp, 通过AIDL 生成头文件
    其aidl的文件位于下面的目录
hardware/interfaces/automotive/audiocontrol/aidl/android/hardware/automotive/audiocontrol/

编译会在下面的目录生成实现binder通信的接口文件。
接口文件有java cpp ndk三种类型。 使得能够被不同的客户端和服务端的代码引用到。

out/soong/.intermediates/hardware/interfaces/automotive/audiocontrol/aidl/android.hardware.automotive.audiocontrol-V2-cpp-source/gen/include/android/hardware/automotive/audiocontrol$ ls
AudioFocusChange.h    BnFocusListener.h     BpDuckingInfo.h    IAudioControl.h
BnAudioControl.h      BnMutingInfo.h        BpFocusListener.h  IFocusListener.h
BnAudioFocusChange.h  BpAudioControl.h      BpMutingInfo.h     MutingInfo.h
BnDuckingInfo.h       BpAudioFocusChange.h  DuckingInfo.h
  1. 实现service,实现service对应的bin,以及rc,注册服务到servicemananger
    AudioContro 实现的demo bin位于hardware/interfaces/automotive/audiocontrol/aidl/default
    目录下,编译会生成
    android.hardware.automotive.audiocontrol-service.example这样的bin 这个bin在 audiocontrol-default.rc 中启动。
    当然服务端的是 就是把audiocontrol的服务注册到servicemanger中。
    std::shared_ptr<AudioControl> audioControl = ::ndk::SharedRefBase::make<AudioControl>();
    const std::string instance = std::string() + AudioControl::descriptor + "/default";
    binder_status_t status =
            AServiceManager_addService(audioControl->asBinder().get(), instance.c_str());
    CHECK_EQ(status, STATUS_OK);

服务的名字在audiocontrol-default.xml中定义为
android.hardware.automotive.audiocontrol.IAu

  • 22
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值