ServiceManager, in fact, is also a service, but its server-side implementation does not use the binder library structure implementation, but directly open Binder/dev for communication, not universal.
The following is an example of Mediaplayservice in MediaServer, which illustrates the more common implementation of a service using binder communication mechanisms.
First, service component start-up
The service component runs in the server process, and the server process typically starts with its main function, which typically does two things at startup:
1. First register the service component inside the ServiceManager
2. Start a binder thread pool to wait for and process communication requests from the client process.
Taking MediaServer and the mediaplayservice of them as an example, the entry position is: Frameworks\av\media\mediaserver\main_mediaserver.cpp.
Part of the structure of the Meidaplayservice is shown below:
Its complete structure is fully implemented according to the structure of the binder library.
The startup process is as follows:
In the Talkwithdriver call, using the IOCTL to interact with the binder driver, the communication data is encapsulated as a binder_write_read struct, which communicates using the Binder_write_read protocol.
Using Binder_ioctl within the binder driver to distribute the data to be processed, and ultimately through Binder_thread_read and Binder_thread_write, the registration request is told to ServiceManager, And the processing results are again driven back to the mediaserver process by binder.
Second, access to service proxy objects
The service proxy object acquisition process is a binder communication process with the client process standard with the ServiceManager process:
As follows:
Where GetService calls Checkservice,iservicemanager, the real implementation class for Bpservicemanager, which is the proxy object for ServiceManager. Through it, the client process communicates through the binder driver in connection with the process where the ServiceManager is located.
Android Binder interprocess communication mechanism 5-service registration and acquisition of proxy objects