(1) What is Binder
With the development of the Android mobile device platform system, more and more people are paying attention to the Binder Mechanism. What is Binder? In general, binder is a lightweight IPC component framework, and binder is a distributed component architecture, which is similar to com and CORBA. An open-binder open-source project, after implementation on the Android operating system, is now seen on Android.
Therefore, binder is not a new technology and new idea. It existed before android. It was most developed on BEOs and later productized on Palm OS cobalt. The binder in andorid is basically implemented by the author of the binder based on the initial design idea of the binder by referring to the open-source project openbinder opened by palmsource in Android.
(2) features of the Binder Mechanism
Although Android is built on Linux, it does not use Linux to provide the IPC Mechanism, but implements a lightweight IPC Mechanism-The Binder Mechanism. The following binder features make it an indispensable part of Android:
(1) distributed architecture.
(2) system-level development.
Oriented to the system layer rather than the application layer. Openbinder targets processes and IPC, rather than cross-network communication.
(3) It is implemented in C ++.
(4) multi-threaded programming.
Various thread models that support multi-threaded programming. The specified thread model is not mandatory.
(5) supports multiple operating system platforms.
From BEOs to Windows and Palm OS cobalt to Android. Binder can be implemented and used on different platforms. The binder uses components and objects to present some basic system services, such as processes and shared memory. Instead of trying to replace and hide the traditional concepts in the operating system, it embraces and surpasses them. This enables the binder to support most traditional operating system platforms.
(6) good hardware scalability.
Very low hardware requirements. From 50 MHz ARM 7 CPU (without memory protection) to 400 MHz ARM 9 CPU, and more powerful CPU.
(7). High user customization.
As the mechanism of IPC, most components in the system are connected and the coupling lines between components are minimized. Each component can be freely modified and replaced, improving user customization.
(8) The binder has very low hardware requirements, which is in line with the actual situation of Android. The Android product line is extensive and the chip clock speed is available at all levels. It must run smoothly on low-end machines, the performance requirements of the software are still very important.
(3) Binder Application Model
For an IPC communication, we can simply understand it as a client-server mode. The client requests the service. After receiving the client request, the server may return the result to the client. The inter-process communication model of the Binder Mechanism in the Android system is summarized as follows:
(1) The client obtains the proxy object of the server in some way. From the client perspective, there is no difference between the proxy object and its local object. It can call its method and access its variables like other local objects.
(2) the client sends request information to the server by calling the proxy object.
(3) The proxy object sends user request information to the Linux kernel space (actually Memory Sharing) through the binder device node (/dev/binder), which is obtained by the binder driver and sent to the service process.
(4) The service process processes user requests and returns the processing result to the agent object on the client through the binder driver of the Linux kernel.
(5) The client receives the results returned by the server.
The entire process is roughly as described above. You can imagine what benefits the introduction of the bingder Mechanism brings to inter-process communication? Yes, it is "thread migration". It is like a thread carrying a parameter to execute another process, and then returns the result, which is the same effect as calling its own function.
This document does not describe the details of the Binder Mechanism for the time being. In the subsequent articles, we will analyze the Binder Mechanism in detail. Here we will first look at the composition of the binder mechanism framework.
(4) Composition of the Binder Mechanism
(1) Binder driver
The binder is a character driver in the kernel located in/dev/binder. This device is the core part of the Android system IPC. The client's Service proxy is used to send requests to the server. The server also returns the processing results to the client's Service proxy object. In Android, an ipcthreadstate object encapsulates operations on the binder driver.
(2) Service Manager
This is mainly used to manage services. All system services provided by android must register themselves through service manager and add themselves to the service management linked list to provide services for the client. To communicate with a specific system server, the client needs to query and obtain the required services from the Service Manager. Service Manager is the Management Center of system service objects.
(3) Server)
It should be emphasized that the service here refers to the system server, rather than the SDK server, to provide services to the client.
(4) Client
Generally, it refers to applications on the Android system. It can request services in the server.
(5) proxy object
Obtain the generated proxy class object in the client application. From the application perspective, there is no difference between the proxy object and the local object. You can call its method. The methods are both synchronous and the corresponding results are returned.
The implementation of the binder mechanism is implemented using C/C ++, but Java content is also available in Android applications. The following describes the Service Manager in the binder mechanism.