Android Binder interprocess communication mechanism 5-service registration and acquisition of proxy objects

Source: Internet
Author: User

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

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.