Reputation: 975
I have a custom setup where I need to interact with a custom HAL through IPC in an Android JNI service. The flow I am working on is:
HMI -> CustomSensorManager -> AIDL -> Custom System Service -> Binder IPC -> Custom JNI service -> AIDL -> Custom HAL service (Vendor/Framework).
I successfully created the custom HAL, which reads sensor data. Here is the Android.bp for the HAL service:
cc_binary {
name: "android.hardware.sensors-service",
vendor: true,
relative_install_path: "hw",
init_rc: ["android.hardware.sensors-service.rc"],
vintf_fragments: ["android.hardware.sensors-service.xml"],
srcs: [
"Sensors.cpp",
"service.cpp",
"ConvertUtils.cpp",
],
shared_libs: [
"libbase",
"liblog",
"libhardware",
"libbinder_ndk",
"libbinder",
"libutils",
"android.hardware.vsensors-V1-ndk",
],
}
Below is the folder structure for the custom HAL.
I also wrote the AIDL interface for the HAL as follows:
aidl_interface {
name: "android.hardware.vsensors",
vendor: true,
srcs: ["android/hardware/vsensors/*.aidl"],
stability: "vintf",
owner: "ABCD",
backend: {
cpp: {
enabled: false,
},
java: {
sdk_version: "module_current",
},
},
}
Below is the folder structure for aidl_interface
Problem: Now, I want to interact with this HAL service from the JNI layer. I am adding the JNI service code in:
frameworks/base/services/core/jni/Android.bp
frameworks/base/services/core/jni/com_android_server_CustomSensorService.cpp
frameworks/base/services/core/jni/onload.cpp
Below is the code where I try to get the HAL service using AIDL through IPC, but I cannot reference the ISensors AIDL interface properly.
JNI Code (com_android_server_CustomSensorService.cpp):
static sp<ISensors> getSensorService() {
if (gSensorService == nullptr) {
sp<IServiceManager> sm = defaultServiceManager();
sp<IBinder> binder = sm->getService(String16("android.hardware.vsensors.ISensor/default"));
if (binder != nullptr) {
gSensorService = android::interface_cast<ISensors>(binder);
LOGI("Successfully connected to ISensors service");
} else {
LOGE("Failed to connect to ISensors service");
}
}
return gSensorService;
}
Issue:
I am unsure how to properly reference or integrate the aidl_interface for HAL in the frameworks/base/services/core/jni/Android.bp file. What is the correct way to reference or add the AIDL interface so that the JNI layer can find it?
Any guidance or examples on how to correctly link the AIDL for HAL into the JNI layer would be appreciated.
Upvotes: 0
Views: 206