aidl for hal之Link to death Base

注意:以下代码,与前面的文章息息相关,这里只介绍关键代码,其余代码不展示

核心概念

当客户端拿到一个 HAL 的 AIDL 接口代理对象后,可以对这个远端 Binder 注册一个 death recipient

  • 如果 HAL 进程挂了
  • 或者承载该 Binder 的进程退出了
  • Binder driver 会通知客户端
  • 客户端注册的回调会被触发

这就是 linkToDeath


涉及到的关键方法与类

路径: frameworks/native/libs/binder/ndk/include_ndk/android/binder_ibinder.h

/**
 *  表示对死亡通知的处理句柄。参见 AIBinder_linkToDeath/AIBinder_unlinkToDeath。
 */
struct AIBinder_DeathRecipient;
typedef struct AIBinder_DeathRecipient AIBinder_DeathRecipient;
/**
 * 此函数在接收到死亡通知时执行。参见 AIBinder_linkToDeath/AIBinder_unlinkToDeath。
 *
 * 自 API 级别 29 起可用。
 *
 * \param cookie 传递给 AIBinder_linkToDeath 的 cookie。
 */
typedef void (*AIBinder_DeathRecipient_onBinderDied)(void* cookie) __INTRODUCED_IN(29);
/**
* 创建一个新的binder death recipient。该对象可以附加到多个不同的binder对象。
*
* 自 API 级别 29 起可用。
*
* 警告:请确保此 Cookie 的生命周期足够长。如果它是动态分配的,
* 则应使用 `AIBinder_DeathRecipient_setOnUnlinked` 将其删除。
* onBinderDied:调用此死亡接收者时要执行的回调函数。
* return`:新创建的对象(如果 `onBinderDied` 为 null,则返回 null)。
*/
__attribute__((warn_unused_result)) AIBinder_DeathRecipient* AIBinder_DeathRecipient_new(
        AIBinder_DeathRecipient_onBinderDied onBinderDied) __INTRODUCED_IN(29);
/**
* 注册以接收关联 Binder 已终止的通知。同一个终止接收者可以关联多个不同的 Binder。
* 如果 Binder 是本地 Binder,则不会指定终止接收者(因为如果本地进程终止,
* 则不存在接收者来接收事务)。如果 Binder 终止,则会将 cookie 传递给接收者,
* 该 cookie 可以为空。必须使用此 coo
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值