AIDL and HIDL core concepts

Table of contents

I. Overview

2. Core understanding of the core process

3. Some terminology

4. Reference example


I. Overview

Both AIDL and HIDL are mainly used for cross-process communication, and the essence is Binder communication.

The overall process is to write the .aidl file or .hal file first. This file only has the interface definition but not the implementation. Then use the tool to automatically generate code, and then use the generated code to write the implementation and call of the specific interface.

2. Core understanding of the core process

There are a lot of things on the Internet that are not clear, so don’t talk too much about it, let me talk about the core process:

  1. First, .aidl generates code, such as IMyAidlInterface.aidl generates code, both server side and client side must have the same package name.
  2. Server side: Inherit the IMyAidlInterface.Stub class in the generated code to implement the interface, such as class MyBinder extends IMyAidlInterface.Stub, because you need to call the interface when the service communicates, so return this class in onBind().
  3. Client side: Get the MyBinder class just prepared in onServiceConnected(), iMyAidlInterface = IMyAidlInterface.Stub.asInterface(service), the way to call the interface is directly iMyAidlInterface.[interface].

Look at the actual example against the process I said, and you will understand it thoroughly! In the final section I provide examples of good blogs.

The process of .hal is the same, but instead of Proxy and Stub, they are called Bp and Bn.

3. Some terminology

For AIDL to generate java code, the client (client) corresponds to Proxy, and the server (server) corresponds to Stub. Note that c++ code can also be generated, which is often used for framework and native communication nowadays.

For HIDL to generate c++ code, the client (client) corresponds to Bp (Binder Proxy), and the server (server) corresponds to Bn (Binder Native).

Essentially the same.

It can be understood in this way, you go to the bank to deposit money, you find an agent to deposit it, and store it in the ATM. You are the client, the bank is the server, the agent is the proxy, and the ATM is the stub. Money needs to be a Parcel of serialized data.

The communication is done by the kernel for you, and you can go deeper if you are interested.

4. Reference example

You can refer to excellent blogs for writing AIDL process:

AIDL - Short Book (jianshu.com)


---------------------
Author: alibli
Source: CSDN
Original: https://blog.csdn.net/weixin_36389889/article/details/125949031#%E6% A6%82%E8%BF%B0Copyright
statement: This article is the author's original article, please attach the blog post link for reprint!
Content analysis By: CSDN, CNBLOG blog post one-click reprint plug-in

Guess you like

Origin blog.csdn.net/xiaowang_lj/article/details/132127320
Recommended