Android interprocess communication (IPC) mechanism binder introduction and Learning Plan

Source: Internet
Author: User
Tags new set

In Android systems, each application is composed of multiple activity and service parts, and these activity and service are likely to be executed in the same processing, in addition, can also be performed in different processes.

And then. How does activity or service communicate in the same process? This is the binder interprocess communication mechanism to be described in this article.

We know that the Android system is based on the Linux kernel, while the Linux kernel inherits and is compatible with the rich Unix system interprocess communication (IPC) mechanism.

There are traditional pipes (pipe), signal (Signal) and Trace (trace). These three means of communication can only be used between the parent and child processes, or between sibling processes. A command pipeline (Named pipe) was added later. So that interprocess communication is no longer confined between parent-child processes or sibling processes, and in order to better support transactional processing in commercial applications, at/T's Unix System V. Also added three inter-process communication mechanisms called "System V IPC". Each is a message queue (message), a shared memory (Share), and a semaphore (Semaphore). Later, BSD Unix extended the "system V IPC" mechanism significantly. Provides an inter-process communication mechanism called a socket (socket). To learn more about these inter-process communication mechanisms, it is recommended that you refer to the "Linux kernel source Scenario analysis" article in the article on Android learning startup.

But. The Android system does not use the various inter-process communication mechanisms mentioned above. Instead of using the binder mechanism, is it due to the poor performance of the mobile device hardware and low memory characteristics? Unknown.

Binder is not actually a new set of interprocess communication mechanisms proposed by Android. It is implemented based on Openbinder. Openbinder was first developed by Be Inc., followed by Palm Inc.. Now Openbinder's author Dianne Hackborn is working for Google. Responsible for the development of Android platform.

As mentioned repeatedly, Binder is an inter-process communication mechanism that is similar to the COM and CORBA Distributed component architectures, in a more popular way, in fact providing remote procedure call (RPC) functionality. From the literal point of view, Binder has the meaning of binders, then what is it bonded together? In the binder mechanism of the Android system. Consists of a system component, each of which is client, server, Service Manager, and binder driver, in which client, server, and Service Manager execute in User space and binder driver executes kernel space. Binder is a binder that binds the four components together. The core component is the binder driver, and Service Manager provides the functionality of the auxiliary management. Client and server communicate between Client-server on the infrastructure provided by the binder driver and service Manager.

Service Manager and Binder drivers have been implemented on the Android platform, and developers simply need to implement their own client and server components in accordance with the specification. It's easy to say, it's hard to do, and the binder mechanism for Android is the hardest to understand for people who just started learning, and the binder mechanism is from the point of view of system development or application development. Are the most important components of the Android system. So. It is important to understand how binder works. To learn more about how Binder works, the best way is to read binder-related source code, the originator of Linux Linus Torvalds before said a famous rtfsc:read the fucking source Code.

Although reading Binder's source code is the best way to learn the binder mechanism. But also must not fight unprepared war, because binder source code is relatively dull and more difficult to understand, the hypothesis can be supplemented by some theoretical knowledge, it is better. Less gossip, online on the binder mechanism of information is still a lot of, here do not want to write it again. The following two articles are highly recommended:

Android in layman's binder mechanism

Android Binder Design and implementation – design article

Android's binder mechanism in layman's terms starts from the scene. In-depth introduction of binder in user space of the three components of the client, server and service manager of the interrelationship. Android Binder Design and implementation of the article is specifically introduced in the kernel space Binder driver data structure and design principles. We are very grateful to the two authors for bringing us such a good binder study material. Sum up. The relationship between the four components of the Android system binder mechanism, client, Server, Service Manager, and binder drivers, for example, is as seen in:

1. Client, server, and Service Manager real user space, binder drivers are now in kernel space

2. Binder drivers and Service Manager have been implemented in the Android platform. Developers only need to implement their own client and server in user space

3. Binder driver provides device file/dev/binder interaction with user space, Client, server, and service Manager communicate with binder driver through open and IOCTL file operation functions

4. interprocess communication between client and server is implemented indirectly through binder drivers

5. Service Manager is a daemon. The ability to administer the server and provide the client with a query server interface

So far. The binder mechanism finally has a perceptual understanding, but still feel not very well from top to bottom throughout the IPC communication process, so. The binder source is intended to be analyzed in the following four scenarios to further understand the binder mechanism:

1. How does Service manager become a daemon? That is, how Service Manager informs the binder driver that it is the context manager of the binder mechanism.

2. How does server and client get the Service Manager interface? That is, how the Defaultservicemanager interface is implemented.

3. How does the server start up its own services? How does Service Manager serve server in the course of server startup? That is, how the Iservicemanager::addservice interface is implemented.

4 How does Service Manager provide services to the client? That is, how the Iservicemanager::getservice interface is implemented.

In the next four articles, the binder source code will be analyzed according to these four scenarios. Will involve the binder-related source code of the user space to the kernel space.

Why isn't there a scenario where client and server are communicating between processes? This is because Service Manager also acts as the server role at the same time as the daemon.

So. Just so that we can understand the third and fourth scenarios, we also understand how the client and server in the binder mechanism communicate with each other through the binder driver for interprocess communication.

In order to describe the principle and implementation of the binder mechanism of inter-process communication in Android system. In the next four articles, we have introduced the implementation of the binder mechanism based on the C + + language, but when we developed the application on the Android system. are based on the Java language, so. We will be in the last post. Specifically describes the Android system interprocess communication Binder mechanism implemented in the Java interface of the application framework layer:

5. Android system interprocess communication Binder mechanism in the application framework Layer Java Interface Source code analysis.

Sina Micro-Boluo: Http://, welcome attention!

Android interprocess communication (IPC) mechanism binder introduction and Learning Plan

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.