HAL Service, AIDL Interface, Application Layer

How to communicate through AIDL to a HAL service – Part 1

Let’s have some practical activities in the AOSP development domain. We are going to implement communication between the application layer and a HAL service through an AIDL interface. To do that, we should take some steps. In fact, we should implement a service in the HAL layer, an application or service in the application layer, and develop an AIDL interface as well. But it’s all of that because we will have something to do with SELinux as well.

I will try to break it into some steps. Then we can follow them to reach the communication. It is going to be fun. We will implement the HAL service with C++, the AIDL interface has its own simple language; and the application layer will be developed with Kotlin.

The steps that should be taken

  1. Implement an AIDL interface
  2. Implement a HAL service with the AIDL interface
  3. Add required SELinux policies
  4. Implement an application and communicate through AIDL
Android Structure

All the steps will be done as part of AOSP. So, that can be supposed a journey among AOSP. But before the next step, you should clone and build AOSP locally. You can read another post through the link below to set it up:

How to start AOSP development

How to build AOSP

I need to prepare a separate post for each step; otherwise, it will be a long post that you cannot walk over and will also be boring and confusing. In each step, I will prepare a brief of what we’re going to do and how it works. Then it will be followed by the code and a GitHub link where you can find the code. Finally, we will test them in the emulator and see the result.

The next posts will come soon!

5 thoughts on “How to communicate through AIDL to a HAL service – Part 1”

  1. hai bro, if i am following your steps then my service is not registering in android 12 version so do we need to add in systemserviceregistry.java and systemserver.java to register our service.

    1. Mohammad Hossein Heydarchi

      No, the registration is taking place in main() function for the HAL service. But to make it available it should be added to PRODUCT_PACKAGES and the se-policies should be configured correctly.
      But to find the problem if it relates to SELinux you can run the emulator in Permissive mode.

Leave a Comment

Your email address will not be published. Required fields are marked *