The device /dev/invstr is created at boot with root permission.
The HAL Library is loaded when JNI Wrapper for Invcase Service is run, therefore, HAL code will run with system permission which attaches to the system_server process.
The Android Init Language uses init*.rc files to automatically do some actions when a condition is met. For the target hardware, Android Init will use init.<hardware>.rc file. On Emulator, it is init.ranchu.rc.
Add below lines to change the owner and permission on the /dev/invcase at boot:
device/generic/goldfish/init.ranchu.rc
on boot chown system system /dev/invcasechmod 0600 /dev/invstr
Build and Run
The Invstr Manager exports new Service APIs, therefore, need to rebuild the list of system APIs.
m all -j$(nproc)Run the Emulator and run Invstr app:
Third party App take String input from User and pass it to Android Kernel module to get the reverse of String.
Kernel Module
We need to create a kernel module named as "invstr" and add our logic to reverse the string that coming from User App. I am assuming that you guys know how to add a new module in kernel and build it.
If you guys are not familiar to add new module in kernel and build. I will add a separate post on it.
This guide assumes that invstr module is loaded as below:
device/generic/goldfish/init.ranchu.rc
+ on boot + insmod /system/lib/modules/invstr.ko + chown system system /dev/invstr + chmod 0600 /dev/invstr
logd("IInvstr service starts to join service pool");
ABinderProcess_joinThreadPool();
return EXIT_FAILURE; // should not reached
}
Build Service
Similar to the HIDL module, we will create a cc_binary module in theAndroid.bp.
AIDL has three different backends: Java, NDK, CPP. To use Stable AIDL, you must always use the system copy of libbinder at system/lib*/libbinder.so and talk on /dev/binder. For code on the vendor image, this means that libbinder (from the VNDK) cannot be used: this library has an unstable C++ API and unstable internals. Instead, native vendor code must use the NDK backend of AIDL, link against libbinder_ndk (which is backed by system libbinder.so), and link against the -ndk_platform libraries created by aidl_interface entries.
We need to define the service with the init process, so it can start whenever the hal class is started. To do this, we will create a new android.hardware.invstr-service.rc:
If this is a new package, add it to the latest framework compatibility matrix. If no interface should be added to the framework compatibility matrix (e.g. types-only package), add it to the exempt list in libvintf_fcm_exclude.
The User App will be very simple to test the hardware. It contains an EditText to get user input, a Button to execute commands, and a TextView to display the result.
I will Add user App details as separate blog . Current post itself become too long.
Thanks you guys for bearing with me to read this long post. Hope it help you guys as one stop solution to Use AIDL as HIDL.