恒美微站 Logo 恒美微站
  • 首页
  • 关于我们
  • 建站服务
  • 主题模板
  • 案例展示
  • 资讯中心
  • 联系我们

Android 12 S Binder原理之BpBinder,BnBinder以及IInterface介绍

  • 首页
  • 资讯中心
  • /
  • Android 12 S Binder原理之BpBinder,BnBinder以及IInterface介绍

相关资讯

基于SpringBoot的闲置资产管理系统(毕业设计项目源码+文档) 2026/8/16 13:49:35
中国行政区划矢量地图数据免费下载:省市县4级Shapefile,10分钟在QGIS出一张图 2026/8/16 13:49:35
Steam创意工坊下载器WorkshopDL:3步搞定Epic与GOG游戏的模组下载 2026/8/16 13:49:35

最新资讯

Windows Server防火墙IP拦截实战:从原理到四种配置方法详解
企业知识库 AI 助手(RAG 为主)产品与技术实现方案
Overleaf Git同步认证失败排查指南:从HTTPS令牌到SSH密钥的解决方案
Spring AI(12) :ChatPDF-实现ChatPDF应用
LlamaIndex结构化输出实战:从RAG到智能体工作流的数据自动化
Windows硬件信息查询批处理脚本:WMIC与PowerShell实战指南

今日推荐

【文章复现】非线性值迭代自适应动态规划(ADP):离散时间非线性系统的策略迭代自适应动态规划算法研究附Matlab代码
【双层规划,节点出清价,绿证交易,CVaR方法】两级电力市场环境下计及风险的省间交易商最优购电模型附Matlab代码
隐式mpc+自适应mpc+时变mpc,线性时变模型预测控制附Simulink仿真

本周热门

【文章复现】非线性值迭代自适应动态规划(ADP):离散时间非线性系统的策略迭代自适应动态规划算法研究附Matlab代码
【双层规划,节点出清价,绿证交易,CVaR方法】两级电力市场环境下计及风险的省间交易商最优购电模型附Matlab代码
隐式mpc+自适应mpc+时变mpc,线性时变模型预测控制附Simulink仿真

本月精选

如何用DamaiHelper实现演唱会门票的智能自动化抢购:完整技术解决方案指南
第4篇:59 倍性能差距的索引瓶颈定位——一次教科书级的全表扫描调优
终极歌词批量下载神器:5分钟解决离线音乐库歌词同步难题

Android 12 S Binder原理之BpBinder,BnBinder以及IInterface介绍

发布时间:2026/8/16 13:54:36
Android 12 S Binder原理之BpBinder,BnBinder以及IInterface介绍 系列文章Android 12 S ServiceManager原理Android 12 S Native Service的创建流程Android 12 S Binder原理之BpBinderBnBinder以及IInterface介绍Android 12 S HIDL Service创建流程Android 12 S 自定义Hal服务selinux权限添加Android 12 S 自定义Native服务selinux权限添加Android 12 S java服务调用native服务Android 12 S 自定义native服务访问java服务​一Binder机制介绍Binder机制是Android系统提供的跨进程通讯机制。Client进程希望可以与Server进程沟通但由于是跨进程所以需要借助Binder驱动进程通信。Binder由以下模块组成* Binder驱动* Binder Server端 - Server进程* Binder Client端 - Client进程* ServiceManager - 管理者Binder的通信模型如下所示二创建Service模型如果要创建一个Service需要Server端继承BnInterface, Client端继承BpInterface。具体可用下图表示可在如下文件中找到关于Bn, Bp相关的声明frameworks/native/libs/binder/include/binder/IInterface.hframeworks/native/libs/binder/include/binder/IBinder.h具体代码如下frameworks/native/libs/binder/include/binder/IInterface.h class IInterface : public virtual RefBase { public: IInterface(); static spIBinder asBinder(const IInterface*); static spIBinder asBinder(const spIInterface); protected: virtual ~IInterface(); virtual IBinder* onAsBinder() 0; }; ----------------------------------------------------------- class BnInterface : public INTERFACE, public BBinder { public: virtual spIInterface queryLocalInterface(const String16 _descriptor); virtual const String16 getInterfaceDescriptor() const; protected: typedef INTERFACE BaseInterface; virtual IBinder* onAsBinder(); }; frameworks/native/libs/binder/include/binder/Binder.h class BBinder : public IBinder { public: BBinder(); virtual const String16 getInterfaceDescriptor() const; virtual bool isBinderAlive() const; virtual status_t pingBinder(); ... }; frameworks/native/libs/binder/include/binder/IBinder.h class [[clang::lto_visibility_public]] IBinder : public virtual RefBase { public: enum { FIRST_CALL_TRANSACTION 0x00000001, LAST_CALL_TRANSACTION 0x00ffffff, ... }; ------------------------------------------------------------------- class BpInterface : public INTERFACE, public BpRefBase { public: explicit BpInterface(const spIBinder remote); protected: typedef INTERFACE BaseInterface; virtual IBinder* onAsBinder(); }; frameworks/native/libs/binder/include/binder/Binder.h class BpRefBase : public virtual RefBase { protected: explicit BpRefBase(const spIBinder o); virtual ~BpRefBase(); virtual void onFirstRef(); virtual void onLastStrongRef(const void* id); virtual bool onIncStrongAttempted(uint32_t flags, const void* id); inline IBinder* remote() const { return mRemote; }//返回的是BpBinder inline spIBinder remoteStrong() const { return spIBinder::fromExisting(mRemote); ...三进程间传递数据的载体 - ParcelParcel代码位于如下目录Parcel用于传递进程间的数据。不管是Client发送数据给Server还是Server发送数据给Client都是通过Parcel进行传递。frameworks/native/include/binder/Parcel.hframeworks/native/include/binder/Parcel.cppwrite相关接口:status_t write(const void* data, size_t len); status_t writeInt32(int32_t val); status_t writeUint32(uint32_t val); status_t writeInt64(int64_t val); status_t writeUint64(uint64_t val); status_t writeFloat(float val); status_t writeDouble(double val); status_t writeStrongBinder(const spIBinder val); status_t writeInt32Array(size_t len, const int32_t *val); status_t writeByteArray(size_t len, const uint8_t *val); status_t writeBool(bool val); status_t writeChar(char16_t val); status_t writeByte(int8_t val); ......read相关接口:status_t read(void* outData, size_t len) const; const void* readInplace(size_t len) const; int32_t readInt32() const; status_t readInt32(int32_t *pArg) const; uint32_t readUint32() const; status_t readUint32(uint32_t *pArg) const; int64_t readInt64() const; status_t readInt64(int64_t *pArg) const; uint64_t readUint64() const; status_t readUint64(uint64_t *pArg) const; float readFloat() const; status_t readFloat(float *pArg) const; double readDouble() const; status_t readDouble(double *pArg) const; bool readBool() const; status_t readBool(bool *pArg) const; char16_t readChar() const; status_t readChar(char16_t *pArg) const; int8_t readByte() const; status_t readByte(int8_t *pArg) const; ......举个例子在native service中是如何通过Parcel传递数据的如下所示都是通过Parcel进行传递。class BpCustomizeManagerService : public BpInterfaceICustomizeManagerService { public: explicit BpCustomizeManagerService (const spIBinder impl) : BpInterface ICustomizeManagerService(impl) { ALOGD(create Service \n); } int customeize(int size){ Parcel data, reply; data.writeInterfaceToken(ICustomizeManagerService::getInterfaceDescriptor()); data.writeInt32(size); remote()-transact(CUSTOMIZE, data, reply); return reply.readInt32(); } }; status_t BnCustomizeManagerService ::onTransact(uint32_t code, const Parcel data, Parcel *reply, uint32_t flags){ switch (code) { case CUSTOMIZE: { CHECK_INTERFACE(ICustomizeManagerService, data, reply); int size data.readInt32(); int ret customeize(size); //函数返回值从Server传递给Client reply-writeInt32(); return NO_ERROR; } ... };

关于恒美微站

恒美微站专注于为个体商户、工作室提供极简自助建站服务,让每个人都能轻松拥有专业网站。

快速链接

  • 关于我们
  • 建站服务
  • 主题模板
  • 案例展示
  • 资讯中心

服务项目

  • 可视化建站
  • 拖拽编辑
  • 主题定制
  • SEO 优化
  • 网站托管

联系方式

  • 📍 地址:北京市朝阳区建国路 88 号
  • 📞 电话:400-888-8888
  • ✉️ 邮箱:info@hmyw.cn
  • 🕐 时间:周一至周日 9:00-18:00

© 2024 恒美微站 hmyw.cn 版权所有 | 京 ICP 备 12345678 号