This article is reprinted from the WeChat public account "Embedded Linux System Development", written by asonangel. Please contact the WeChat public account "Embedded Linux System Development" to reprint this article. Recently the blogger is studying the binder of the Android system. What is binder? It can be understood as a method of inter-process communication in the Android system. Although the Android system is based on Linux, it does not use the inter-process communication method that comes with Linux, but uses a more efficient binder. Understanding binder is crucial to understanding the Android system. The binder principle diagram is as follows: Binder communication uses a client/server architecture, which is the same as Socket, but slightly more complicated. The binder component includes Client, Server, ServiceManager, and binder driver, among which ServiceManager is used to manage various services in the system. Specific communication process: Server first registers a service with ServiceManager, which is actually just a string. Then Client obtains the service from ServiceManager, and the keyword is the registered string. In this way, Client and Server can communicate. The real data flow goes through the binder driver in the underlying Linux kernel space, but this is encapsulated, so you don’t need to care about the real binder driver, just call functions between Client and Server to send and receive data. It is the onTransact function on the server and remote()->transact(TEST, data, &reply) on the client. The sent data is stored in data, and the returned data is stored in reply. Both Client and Server can send and receive data. Android system architecture diagram: After understanding binder, let's analyze it in detail: the binder driver must be in the bottom Linux kernel, so the binder client and server can exist anywhere. For example: 1. The binder server is in the app layer, and the client is in the app layer. 2. The binder server is in the native layer, and the client is in the app layer. 3. The binder server is in the app layer, and the client is in the native layer. 4. The binder server is in the native layer, and the client is in the native layer. All four situations are possible. This is a bit abstract, so I will post two articles to link. I have verified the codes of these two articles and they can be used. It should be noted that the binder of the APP layer is written in Java, and the binder of the native layer is written in C++. But in fact, the interfaces are very similar. But to understand the code, you need to understand several classes first: The real inheritance relationship of native layer binder is as follows: A little more symmetry may make it easier to understand: We mainly inherit from BnInterface and BpInterface to implement our own server and client. bp: binder proxy bn:binder native sm:ServiceManager |
<<: Goodbye WeChat! My WeChat chat history is not worth 180 yuan
>>: Five UI styles for the second half of 2021, there must be one you like!
With the rapid development of mobile devices, use...
Recently, although the temperature has repeatedly...
Market research firm IHS iSuppli released a disas...
Every year end Various festivals have also become...
For an advertisement, the importance of copywriti...
In the advertising industry, copywriting is the l...
[[170825]] The so-called AR (augmented reality) i...
Hello everyone, this is the first issue of the En...
Recently, the Italian website macitynet.it release...
(Li Xiubao, Professor of the College of Oceanogra...
Android 5.0 is the latest version released by Goo...
This is the 73rd issue of the Nature Trumpet colu...
Image source: Weibo screenshot gossip Recently, t...
In today's Internet age, if you have fans, yo...
How to define seed users ? Three conditions for d...