The knowledge point of the article basically comes from this connection, and then incorporates some of its own understanding: http://gityuan.com/2015/10/31/binder-prepare/
1. Background knowledge
Android four-tier structure, the bottom is the Linux Kenel layer, that is, Android is actually based on Linux implementation, the basic implementation code is C language, and C is a structure-oriented language, rather than object-oriented language
So, there are many IPC communication mechanisms in Linux for interprocess communication, why does Android also create its own interprocess communication mechanism binder? Next, look at the different communication mechanisms under Linux
The process communication methods under Linux are basically inherited from Unix platforms, and the original UNIX IPC has
Pipelines and well-known pipelines: pipelines are created with a page-size memory, with a limited buffer size and a two copy of the pipeline as the data is copied
Message Queuing : A FIFO message queue, which also requires two copies of the data, and because of the need to maintain this message queue, it is required for additional CPU consumption, is not suitable for communication with a large amount of information
signal : The signal essentially notifies a process that something has happened, so that a process knows what it needs to do next, and the process can control itself by signaling itself. So the signal is more suitable for the interrupt control of the process and so on, and not for the exchange of information
Semaphore : More as a mechanism for locking, it guarantees the synchronization of data between processes and between threads.
Socket Interface : More general inter-process communication mechanism, mainly used for different operating systems, different devices, different networks between inter-process communication. Originally developed by the BSD branch of the UNIX system, it was later widely used with other systems. However, because of its more general, transmission efficiency is relatively low, but also need to copy two times the data
Shared memory : Multiple processes can access the same memory space, are the most efficient interprocess communication in all IPC, and do not require any copy of the data at all, and are shared directly.
2. The appearance of binder
In general, the signal and signal volume is basically excluded, not suitable for the use of Android four components between the transmission of information, and then left the other three
(1) In language, the IPC of Linux is implemented using C language, and the entire Android framework layer and application layer are implemented using Java.
(2) from the agreement, the creator of Android is not like Open source his code, this is the business nature of their own decision. and the main line of Linux is open source.
The above two may be the most essential reason for binder appearance, and the following is from the developer's point of view
(3) Performance, binder only need one copy of data, and pipeline, socket interface, message queue all need two copies of data.
(4) Shared memory Although no data copy is required. But in terms of stability, the use of C/s bander is more stable than shared memory.
(5) In safety, the IPC of Linux cannot get the reliable uid/pid of the process, while Android assigns its UID to the application, and the C/S mode ensures that the Android system exposes only the client and protects the server side.
3. Bbinder,bpbinder,ibinder
Bbinder: For Serveice, they inherit Bbinder (Bninterface). Bbinder.ontransact () receives the appropriate transaction request
Bpbinder: For the client, it inherits Bpbinder (Bpinterface). Bpbinder.transact () Distributing transaction requests
IBinder: Equivalent to a pointer, just like the ID of a socket, IBinder is the unique identifier of a process that is passed in as a parameter when refactoring the two binders. Bbinder and Bpbinder are all inherited from IBinder.
4. Structure of binder
The picture also comes from: http://gityuan.com/2015/10/31/binder-prepare/
(1) Service Manager is the equivalent of a manager, referring to native ServiceManager (c + +), is the binder daemon
(2) Client and server communication needs to obtain the Service Manager interface before the communication can begin
Source analysis will slowly fill up ...
Android--binder