Binder mechanism is An important means of cross-process communication in Android system. the interaction betweenService and Activity is used in this mechanism. To this end, I have written a small service case, in order to facilitate a better understanding of binder communication mechanism. Service Code: Public classMyServiceextendsService { Public Booleanflag=tr
In this article, we will thoroughly analyze how to register a service with the system.
In the example in the first article, exampleservice registers a service with the system using the following statement.
// File: exampleservice. cpp
In the previous article, we know that the reference of the servicemanager proxy object of the current process can be obtained by calling the defaultservicemanager () global function. Before in-depth analysis of the addservice () method, let's take a look at how s
1. What is binder?
Intuitively, Binder is a class in Android that inherits the IBinder interface
From the perspective of IPC (inter-process communication, interprocess communication), Binder is a cross-process communication in Android, and
5.3 Statement of Binder in Driver
Driver is the core of Binder communication. All Binder entities in the system and references of each entity in each process are registered in the driver; the driver must record the many-to-one relationship between the Binder references-> entities; find the corresponding entities for th
We know that the android program architecture is designed in accordance with the MVC pattern, and the display and logic operations are well separated. The XML file is used to add and layout views. The activity is used to display various views, while the Service implements to display data in the view according to certain logic. Based on this principle, when designing a program, we need to let them perform their respective duties and make reasonable com
Analysis of the Binder-based IPC process framework in Android, androidbinder
Preface:
Activity, Service, BroadcastReceiver, and Content Provider are four application components of Android. These components that constitute a complete application can be in the same process or not in the same process, when these components are not in the same Process and data in
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 knowledgeAndroid 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, rathe
Android-binder (a) Learn fromExplore the art of Android developmentHttps://www.jianshu.com/p/bdef9e3178c972765136Discussion on binderBinder is an implementation class for the IBinder interface, and Inder is a bridge between the various managers and their service providers that connect the system, and binders are used primarily in service.Layering of
4 Binder Protocol
The basic format of the Binder protocol is (command + data). The ioctl (fd, cmd, arg) function is used for interaction. The command is carried by the cmd parameter, and the data is carried by the arg parameter, which varies with the cmd parameter. The following table lists all commands and their corresponding data:
Table 2 Binder communication c
The binder mechanism is the inter-process access mechanism throughout the Android system and is often used to access the service. Let's take a look at how the binder is used to access the service in combination with the code.
You can understand the service as a non-interface activity. It is a program running in the background. The so-called background is relativ
The binder system can run in the android native environment, but cannot run in the Java Virtual Machine. Therefore, to use binder communication in the Java environment, you need to call some JNI native functions (/android_runtime/android_util_binder.cpp)
Get iservicemanager
The servicemanager. Java file manages all services at the Java layer. To call any functio
Android is based on the Linux kernel, but it does not have rich UNIX-based inter-process communication, but is implemented based on openbinder.
The Binder Mechanism is driven by client, server, Service Manager, and binder.ProgramIt consists of four components: client, server, and service manager running in the user space, and the binder driver running in the ker
Tags: server fetch fill occurs based on the default cross-process communication compilation implementationThe binder mechanism of AIDL on the application layer for beginners to knowFirst you have to understand several concepts:Ipc:inter-process communication, inter-process communication or cross-process communication. It is simple to understand that an application can have multiple processes, but the need for data exchange requires IPC, or data exchan
the service end with WHO does not matter, as long as is with Isenderbinder is a pair of OK. Binderproxy should be called Senderbinder.So what does he need for the application? He needs a function call, not transact such things. If you care about these bottom-up packaging solutions all day long, then it's a big head. Iactivitymanager This is the user needs of the interface, the previous Transact interface is obviously inappropriate for the user to use. The disgusting Transact function is adapted
the service end with WHO does not matter, as long as is with Isenderbinder is a pair of OK. Binderproxy should be called Senderbinder.So what does he need for the application? He needs a function call, not transact such things. If you care about these bottom-up packaging solutions all day long, then it's a big head. Iactivitymanager This is the user needs of the interface, the previous Transact interface is obviously inappropriate for the user to use. The disgusting Transact function is adapted
4.3 struct binder_transaction_data: send and receive data packet structure
This structure is the standard format for Binder to receive/send data packets. Each member is defined as follows:
Table 5 structure of Binder send and receive data packets: binder_transaction_data
Member
Description
Union {Size_t handle;Void * ptr;} Target;
This Member specifies the destination of the sent da
node and look at the following code:status_t bnmediaplayerservice::ontransact ( uint32_t Code, const parcel data, parcel* reply, uint32_t flags) { C1/>switch (code) {case CREATE: { check_interface (imediaplayerservice, data, reply); spThe answer is in this sentence: Reply->writestrongbinder (Player->asbinder ());When this reply is written to the binder driver, the driver specifically handles such ibinder type of data,
); Bindservice (Intent, Mserviceconn, context.bind_auto_create); BreakAt the same time we need to overwrite the method of interface Serviceconnection, at the beginning of the link, IBinder is the IBinder class variable returned by Onbind, so we convert it to Localbinder, Then call the method in Localbinder to get the object of the Bound Service, put it in the global variable, and then call his method. The note here is that onservicedisconnected will not normally be
6 Binder memory ing and receiving cache zone management
For the time being, let's take a look at how data arrives at the receiving end from the sending end in the traditional IPC method? Generally, the sender stores the prepared data in the cache and calls the API to enter the kernel through system calls. The kernel service program allocates memory in the kernel space and copies data from the sender's cache to the kernel cache. When the receiver reads
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:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.