Android Binder机制(一) ------- 整体框架

1. Binder基本介绍

Binder主要用于android系统进程间的通讯。数据在进程间传递只需要拷贝一次数据。由Binder内核层、Native核心层、C++/JAVA应用层组成。

2. Binder框架图

graph BT A(Linux Binder Driver) --> B(ProcessState IPCThreadState) B --> A B --> C(Binder Client) C --> B B --> D(Binder Server) D --> B
  • Binder驱动属于内核层,进程与内核打交道,最终实现进程间通信
  • ProcessState/IPCThreadState属于Native核心层,操作Binder设备文件,对上提供内核层Binder接口的封装
  • 客户端、服务端属于应用层,主要是具体服务的实现及调用,进程间通讯体现在这一层次。

3. Binder类图

binder

@startuml interface IBinder { virtual sp queryLocalInterface(const String16& descriptor); virtual const String16& getInterfaceDescriptor() const = 0; virtual status_t dump(int fd, const Vector& args) = 0; virtual status_t transact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags = 0) = 0; virtual status_t linkToDeath(const sp& recipient, void* cookie = NULL, uint32_t flags = 0) = 0; }

class BBinder {
virtual status_t onTransact( uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags = 0);
}
IBinder <|.. BBinder

class BpRefBase {
IBinder* const mRemote;
}
IBinder <|.. BpRefBase

class BpBinder {
const int32_t mHandle;
}
IBinder <|.. BpBinder

class ISurfaceComposer {

}

class BnInterface {

}
BBinder <|-- BnInterface
ISurfaceComposer <|-- BnInterface

class BpInterface {

}
BpRefBase <|-- BpInterface
ISurfaceComposer <|-- BpInterface

@enduml

posted @ 2018-03-24 16:48  qzhang1535  阅读(202)  评论(0编辑  收藏  举报