Java layer interface for process communication between binders, mainly using the Jni method to invoke the C + + interface of the Binder library
In the Java layer, the service component is called the Java Service, and the service component's proxy is called the Java Service Proxy.
The acquisition process of the ServiceManager Java Layer proxy object (servicemanagerproxy).
The ServiceManager Java service and Java Service Proxy implementation structure of the Java layer is still very similar, as follows:
Java Service class diagram:
Class diagram for the Java service Proxy:
The acquisition of ServiceManager proxy objects is achieved through the Getisservicemanager of the ServiceManager class, A binderproxy is packaged as a servicemanagerproxy implementation by Servicemanagernative's asinterface.
The acquisition of Binderproxy is obtained through the JNI invocation of Android_os_binderinternal_getcontextobject. The Java layer Binderproxy object is created by the function and is saved in the global variable gbinderproxyoffsets.
Second, the Java Service Interface definition and resolution.
The interface is defined in the. aidl file using the Aidl language, and the Java file that generates the corresponding interface name is compiled. which
I****service.stub describes a Java service that needs to be inherited to achieve a specific business.
Ontransact is used to implement interprocess communication.
Asinterface a Binderproxy package for i****service.stub.proxy.
I****service.stub.proxy describes a Java service proxy object
Third, the startup process of Java services
1, initialization, mainly in its parent Binder called Init, and then through Android_os_binder_init, in the C + + layer to create javabbinderholder, and save it in the Gbinderoffsets.mobject.
2, register the service to ServiceManager, call ServiceManager AddService can
Iv. access to Java Service proxy objects
GetService using the Servicemanagerjava service proxy
V. Calls to Java Services
By getting the service proxy, actually exposing the interface to the service, the corresponding function is called.
Comprehensive:
The binder communication mechanism in Android is broadly divided into three layers:
Binder in the Java layer wrapper: Using JNI calls, you are actually making a communication request to the binder local object through the Binder proxy object of the C + + layer.
==============================================================
Service implementations of the C + + layer: Binder proxy objects request specific operations to binder local objects via binder driver, binder local objects
It is also possible to invoke the Java layer's services to complete the functionality.
==============================================================
Binder driver, in fact, is a proxy process and service process communication tools, a microphone, not responsible for the specific business, its implementation is essentially
Writes the defined command protocol code to the kernel buffer and returns the protocol code to coordinate the server service for the C + + and Java tiers.
Android Binder interprocess communication mechanism 6-binder Java Interface for inter-process communication mechanism