How can write an app that calls the service through the hal?

706 Views Asked by At

I have 1 project using aidl for hal,after creating selinux and .aidl . files

I built a service.cpp code and it was loaded into the system

I want to deploy my app to be able to test my service but when I download android studio I really don't know how to link with aosp

Can anyone give me an answer?

2

There are 2 best solutions below

1
On BEST ANSWER

Well I actually made it pretty simple with aosp andrdoid 13's support work After a few hours studying the structure of applications I have created the following structure diagram and call the service in Invcase.java Finally just enter the command mmm packages/apps/invcase/ it will automatically generate for me 1 .apk file and now I will install with adb tree apps

0
On

Your HAL will generate a service that can be used in the upper layer. You can check it by running the command adb shell service list | grep 'SERVICE_NAME'.

You need to create an HAL Manager to facilitate communication between the service and your app. Here is an example I created for a Timer HAL:

https://github.com/alvenan/AOSPbenchmark/tree/main/timer_manager

In the Java file, you can see how to create a service instance and make function calls:

https://github.com/alvenan/AOSPbenchmark/blob/main/timer_manager/src/vendor/alvenan/timermanager/TimerManager.java

After compiling the manager, it will create a .jar library in the "out" folder. For example: /your/path/aosp/out/target/common/obj/JAVA_LIBRARIES/your.package.yourservicemanager_intermediates/classes.jar

Then, you can add this path in Android Studio by going to Build > Edit Libraries and Dependencies > Dependencies. Under "Declared Dependencies," click on '+' and choose "JAR/AAR Dependency." Enter the path of the .jar file in step 1 and apply the changes.

After this, you will be able to instantiate the manager and access the service in your app:

https://github.com/alvenan/AOSPbenchmark/blob/main/bench_test_jni/JavaNativeTestApp/app/src/main/java/vendor/alvenan/javanativetestapp/MainActivity.java#L18

Finally, add your manager to your app's manifest:

https://github.com/alvenan/AOSPbenchmark/blob/main/bench_test_jni/JavaNativeTestApp/app/src/main/AndroidManifest.xml#L17

This is the approach I typically use for my HAL projects. For a more comprehensive overview, you can take a look at my repository:

https://github.com/alvenan/AOSPbenchmark/tree/main

I hope this helps.