This is a simple example for native service and app communcation via aidl on android platform. Native service server will add service nativeservice in service manager and app will connect nativeservice via ServiceManager.
When click start button, app will send start command to native service and native service will continues to return timestamps to app. Native service will stop sending data when click stop button.
- Download AOSP code. I built the server on Oreo 8.1.0 version.
- Make a full build
- Put native-service to the root path of AOSP code.
- In the root path of AOSP code execute command source ./build/envsetup.sh
- Enter the directory native-service and execute build command mm to build native-service and generate bin native_server.
- adb root
- adb remount
- adb push native_server /system/bin/
- adb shell setenforce 0
- adb shell
- cd /system/bin and execute chmod 777 native_server
- execute ./native_server to start native service
Sometimes app can not connect to native service due to selinux permission problem. The step 6 setenforce 0 above used to put selinux in permissive mode and close selinux temporarily.
When native_server is running you can install and start app to connect it.