The information below comes from a number of sources, including my own experiments with the Android IPC and some disparate internet sources.
The overall architecture of the Android IPC system is shown in the diagram below. It consists of four major blocks; one in kernel space, and the other three in user space. The dashed lines represent the logical RPC calls. The solid lines represent the actual data flow.
BinderDriver: This is the core of IPC system. It passes data between a
ServiceProvider(s) and a
ServiceUser(s). This kernel component is provided by Android.
ServiceProvider: Provides some kind of service. It parses the received RPC data from the
BinderDriverand does the real work. Application developers will either make use of existing service providers (such as the
AudioFlinger), or in some cases will write their own.
ServiceManager: This is a special singleton ServiceProvider that provides service manager services for other service providers. This component is provided by Android.
ServiceUser: This is the client. It remote calls the
ServiceProviderby generating an RPC and sending it to the
BinderDriver. Application developers typically write their own
ServiceUseras part of their application.
Here is a typical flow of events for a fictitious
MultServiceProvider (a service provider that multiplies two numbers for a client) and a
MultServiceUser client which doesn’t know how to do multiplication (maybe because the numbers are quaternions) and needs to use the
ServiceManagerruns first (at power-up) and registers a special node (node O) with the
IServiceManagerproxy object for the special node O by calling the global
defaultServiceManager()->addService("Multiplier", new MultServiceProvider())to add itself as a service provider and then waits in an infinite loop for someone to request its services. The
addServiceRPC call is routed to the
BinderDrivernotices that the RPC is for the
ServiceManagerto add a new service, so besides routing the RPC to the
ServiceManagerit generates another node (let’s call it node M), for the new
ServiceManagerreads the data from the
BinderDriverand processes the
MultServiceUserclient process gets an
IServiceManagerproxy object for the special node O (again by using
- The client does an
IServiceManager::getService("Multiplier")RPC call to get the
MultServiceProvider. This call is routed to the
ServiceManagerreads the RPC data from the
BinderDriver, processes the
IServiceManager::getServicerequest and returns back the node representing the
MultServiceProvider::multiply(a, b). This call is routed to the
MultServiceProvider::multiplyRPC call and sends the product of the 2 numbers in a reply to the
BinderDriverroutes the reply back to the client.
- The client reads the data from the
BinderDriverwhich contains the result of “a * b”.
In a future post I hope to discuss the whole architecture in more detail, with concrete code examples for how to use
BnInterface, etc… to create a
ServiceProvider and a
ServiceUser all in native C++ code on Android.