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!
How did the ship appear? What did the earliest sh...
There are many examples of making money in the wo...
A lot of big news comes from patents. From 2009 t...
96 days after injecting US$409 million into Coolp...
Dear, do you know what cache is? In fact, caching...
This article is based on a question from netizens...
On Weibo, there is a classic question with a play...
First, let me ask you a question: Assuming the pr...
Today I continue to share 9 human marketing cases...
BYD issued an announcement that its sales of new ...
Landing page quality and user matching are two ke...
Those who often go to the cinema to watch movies ...
At the "2017 China OTT Large Screen Marketin...
Nowadays, the cost of acquiring customers for onl...
People who eat grains and cereals are bound to ge...