Basics of Binder in Android

Source: Internet
Author: User

Android Binder Basics Point

A comparison of traditional IPC and binder mechanisms

Traditional IPC:

1) receiver pays can not obtain the other party process reliable uid/pid, so that the identity of the other person can not be identified.

2) The access point is open and the private channel cannot be established.

3) socket, pipeline and message queue require two copies of data, transmission efficiency is poor.

4) The way the memory is shared is complex and difficult to use.

Binder mechanism:

1) Add Uid/pid identity to sender.

2) supports both real-name binders and anonymous binders.

3) The transfer process requires only one copy.

Object-oriented thinking in two binders

A Binder object is an object that can be referenced across processes, its entities are in a process, and its references are all over the processes of the system. This reference, like a reference in Java, enables a strong type to be weakly typed, and can be passed from one process to another.

Communication model of three binders

User space: Server,client,servicemanager; kernel space: Binder driver.

Binder driver: Not related to hardware, but the implementation of the same way as the device driver, working in the kernel state, the user access it through/dev/binder.

ServiceManager: Similar to DNS, converts the binder name in the form of a character into a reference to the binder in the client.

The Server:server to ServiceManager communication is also a binder implementation, and the server obtains a binder reference for ServiceManager by a fixed 0 reference.

Client:client gets the binder reference for the server registration by name. These references to binders are strongly typed, ensuring that any referenced binder entities are not freed. The client and server can also send anonymous binders directly through the real name binder, and other processes cannot get references to anonymous binders by means of exhaustive or guessing.

Four uses binder through Aidl

Android will convert the Aidl file into a IInterface interface with a stub stub class that implements this interface and inherits the binder, and the server provides a series of business operations through the stub implementation class.

Within the stub, there is a proxy class that inherits the stub, and the client obtains an instance of the proxy through the stub's Asinterface method to remotely access the method provided by the server.

This is a typical stub-proxy pattern that allows the upper-level code to take no account of the IPC's underlying implementation details.

In addition, the Aidl interface can pass any complex type that implements the Parcelable interface in addition to the Java base type. Aidl interface can also pass another Aidl interface, note that this is essentially an anonymous binder,server can be passed through the client's Aidl interface back to the method in the client, here to pay attention to the problem of memory overflow.

Basics of Binder in Android

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.