Android system-process-Binder2-Java layer

introduction:

For the Android system, a complete software architecture is generally formed from the java layer to the native layer, and then to the kernel driver layer. What is the overall architecture and principle of the Binder IPC communication mechanism in the Android system, from the java layer to the underlying driver layer?

concept and understanding

Binder overall architecture

The red in the figure represents the related components of the binder architecture of the entire Java layer:
the Binder class represents the Server side, and the BinderProxy class codes the Client side; the
blue in the figure represents the components related to the Binder architecture of the Native layer;
the Binder logic of the upper Java layer is based on the foundation of the Native layer architecture In the above, the core logic is handed over to the Native layer method for processing.
The ServiceManager class of the framework layer in the Java layer does not completely correspond to the functions of the Native layer. The implementation of the ServiceManager class of the framework layer is finally completed by passing it to the Native layer through BinderProxy

Binder class diagram

The light blue in the picture is Interface, and the rest are Class:

ServiceManager : The ServiceManagerProxy object is obtained through the getIServiceManager method; the actual work of ServiceManager’s addService and getService is handled by the corresponding method of ServiceManagerProxy;
ServiceManagerProxy : its member variable mRemote points to the BinderProxy object, and the addService and getService methods of ServiceManagerProxy are finally handed over to mRemote Finish.
ServiceManagerNative : its method asInterface() returns the ServiceManagerProxy object, and ServiceManager uses the ServiceManagerNative class to find the ServiceManagerProxy;
Binder : its member variable mObject and method execTransact() are used for the native method
BinderInternal : there is a GcWatcher class inside for processing and Debug Binder related garbage collection.
IBinder : constant in the interface FLAG_ONEWAY: The client uses the binder to communicate with the server in a blocking manner, but if FLAG_ONEWAY is set, this becomes a non-blocking calling method, the client can return immediately, and the server uses a callback method to notify the client to complete Condition. In addition, the IBinder interface has an internal interface DeathDecipient (death notice).

Binder class hierarchy

All classes involved in the whole Binder from kernel to native, JNI, Framework layer

Source code walking:

 Registration service:

Get service:

Guess you like

Origin blog.csdn.net/haigand/article/details/132252101