Why does Android choose binder?

Source: Internet
Author: User

Why does Android choose binder?

Binder (Android technology insider ):

Among the available options above, the most widely used and recognized Binder Mechanism for Android is the Binder Mechanism.

Why does binder be used as the communication mechanism between processes? Does the binder consume less memory resources because it is more concise and fast?

Yes, these are also the advantages of the binder.

Of course, there are also many other reasons, such as the traditional inter-process communication may increase the overhead of processes, and there are risks such as process overload and security vulnerabilities, the binder can solve and avoid these problems.

Binder provides the following functions:

DriverProgramTo promote inter-process communication.

Improve performance through shared memory.

Allocate the thread pool of each process to process requests.

Reference counting and cross-process object reference ing are introduced for objects in the system.

Synchronous call between processes.

 

Android BinderDesign and Implementation-design:

Currently, Linux supports IPC including traditional pipelines, System v ipc, message queue, shared memory, and semaphores, and socket only supports client-server communication.

Of course, you can also set up a set of protocols on these underlying mechanisms to implement client-server communication, but this increases the complexity of the system and the complexity of the mobile phone, it is difficult to guarantee the reliability of resources in a scarce environment.

On the other handTransmission Performance:

As a common interface, socket has low transmission efficiency and high overhead. It is mainly used for inter-network process Communication and low-speed communication between processes on the machine.

Message queues and pipelines adopt the storage-forwarding method, that is, data is first copied from the sender's cache area to the cache area opened by the kernel, and then copied from the kernel cache area to the receiver's cache area,

There must be at least two copies. Although the shared memory does not need to be copied, the control is complex and difficult to use.

Table 1 Number of data copies in various IPC Modes

IPC

Number of data copies

Shared Memory

0

Binder

1

Socket/pipeline/Message Queue

2

 

Another reason is thatSecurity considerations:

Android, as an open platform with many developers, has a wide range of application sources and ensures the security of smart terminals.

End users do not want apps downloaded from the Internet to peek at private data without knowledge, connect to wireless networks, and operate the underlying device for a long time, resulting in rapid depletion of battery and so on. Traditional IPC does not have any

Security measures are completely dependent on upper-layer protocols. First, the receiver of the traditional IPC cannot obtain the reliable UID/PID (User ID/process ID) of the other process, and thus cannot identify the other process.

Android assigns its UID to each installed application. Therefore, the UID of the process is an important identifier for identifying the Process Identity. Traditional IPC can only be filled with UID/PID in data packets,

However, this is not reliable and can be easily exploited by malicious programs. Reliable identity tags are only added to the kernel by the IPC Mechanism itself. Second, traditional IPC access points are open and private channels cannot be established.

For example, the name of the named pipe, the System V key value, the socket IP address, or the file name are all open, as long as the program that knows these access points can establish a connection with the peer end, no matter what the situation can be

Prevent malicious programs from obtaining connections by guessing the recipient address.

For the above reasons, Android needs to establish a new IPC mechanism to meet the system's requirements for communication methods, transmission performance and security. This is the binder.

The binder is based on the client-server communication mode. Only one copy is required during the transmission process. The UID/PID identity is added to the sender. It supports both real-name binder and anonymous binder, which is highly secure.

Object-oriented binder IPC:

The introduction of Object-oriented Thinking converts inter-process communication into calling the method of this object by referencing a binder object. Its unique feature is that the binder object is

An object that can be referenced across processes. Its entity is located in a process, and its reference is distributed across various processes of the system. The most attractive thing is that this reference and the reference in Java

It can be either a strong type or a weak type, and can be passed from a process to other processes so that everyone can access the same server, just like assigning an object or reference

The value is the same as that of another reference. The binder blurs the process boundary and fades out the communication process between processes. The entire system seems to be running in the same object-oriented program.

Object-oriented is only for applications. Similar to other modules in the kernel, the binder driver is implemented in C language without the concept of classes and objects.

The binder Driver provides underlying support for Object-Oriented inter-process communication.

From: http://wenku.baidu.com/view/4186490690c69ec3d5bb753a.html

 

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.