'Confused about application area of Android bundled tool "aidl-cpp"

I am a novice in Android IPC (actually I used Unix domain sockets for communication long ago circa, 2014) and now it would seem that I need to learn AIDL/HIDL to understand the "recommended" IPC mechanisms.

Now, coming to my doubt, I have a simple requirement (more like a pet project, an academic one, so to say) to teach myself how IPC works in Android 10 and up.

I want to build a native service (c++) which will be started from say, adb shell. [SELinux and other security implications can be ruled out]

Next, I want to Make a simple Java App which will have a Native library (via JNI).

This native lib, when signaled from App, will spawn a new thread, which will then attempt to communicate with Native service and fetch some data to be displayed on the App.

In a nutshell, the following is what I want to make to teach myself

  • Android App dev
  • Android JNI, Native interface
  • POSIX threading in Android native code
  • Android IPC [binder]
  • Developing an Android native service as well.

A rough sketch would be something like:

App <--> JNI <--> Native lib <--spawns-thread--> Native Client <--IPC--> Native service

The IPC would be via binder and for which I want to learn and understand the basics of AIDL.

I have gone through the link: https://android.googlesource.com/platform/system/tools/aidl/+/refs/heads/android11-dev/docs/aidl-cpp.md

However I am confused in multiple areas such as:

  1. When to use "aidl-cpp" to generate the Bn/Bp interfaces? Can I simply allow soong build system to generate the required files?

  2. If #1 is not necessary then how am I supposed to write the Native service code without Bn interface generated in first hand?

  3. How can I tell "aidl-cpp" to compile multiple .aidl files?

I have also gone through another link: https://github.com/airgreen/nativeservice-app-aidl It is very well written but does not exactly answer my questions

Any help on the above topics would be very helpful.

Thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source