从 Ixxx.hal得到 service 但service是怎样注册、启动的?
哪里生成了cc_binary: android.hardware.contexthub@1.0-service
hardware/interfaces/contexthub/1.0/default/Android.bp
cc_binary {
name: "android.hardware.contexthub@1.0-service",
relative_install_path: "hw",
proprietary: true,
init_rc: ["android.hardware.contexthub@1.0-service.rc"],
srcs: ["service.cpp"],
cflags: ["-Wall", "-Werror"],
shared_libs: [
"libutils",
"android.hardware.contexthub@1.0",
],
}
android.hardware.contexthub@1.0.so哪里生成的?
这里生成了可执行文件cc_binary: android.hardware.contexthub@1.0-service,其中依赖android.hardware.contexthub@1.0.so
库,但这个库是怎样生成的?下面的bp文件并没有说生成 cc_library_shared, 这个问题先放下
hidl_interface {
name: "android.hardware.contexthub@1.0",
root: "android.hardware",
vndk: {
enabled: true, // "android.hardware.contexthub@1.0.vndk.27.arm64.vendor", 可能是VSDK中的实现
},
srcs: [
"types.hal",
"IContexthub.hal",
"IContexthubCallback.hal",
],
interfaces: [
"android.hidl.base@1.0",
],
types: [
"AsyncEventType",
],
gen_java: true,
}
android.hardware.contexthub@1.0-servic的实现
main() { return defaultPassthroughServiceImplementation<IContexthub>(); }
status_t defaultPassthroughServiceImplementation(size_t maxThreads = 1) {
return defaultPassthroughServiceImplementation<Interface>("default", maxThreads);
}
status_t defaultPassthroughServiceImplementation(std::string name,
size_t maxThreads = 1) {
configureRpcThreadpool(maxThreads, true);
//注册
1] status_t result = registerPassthroughServiceImplementation<Interface>(name);
//运行等待请求
2] joinRpcThreadpool();
return UNKNOWN_ERROR;
}
注册service,IContexthub的getService获得要注册service的name
status_t registerPassthroughServiceImplementation(
std::string name = "default") {
sp<Interface> service = Interface::getService(name, true /* getStub */);
status_t status = service->registerAsService(name);
if (status == OK) {
ALOGI("Registration complete for %s/%s.",
Interface::descriptor, name.c_str());
}
return status;
}
public static IContexthub getService(String serviceName, boolean retry) {
IContexthub.asInterface(android.os.HwBinder.getService("android.hardware.contexthub@1.0::IContexthub", serviceName, retry));
}
android.hardware.contexthub@1.0-servic的启动
init_rc: ["android.hardware.contexthub@1.0-service.rc"],
service vendor.contexthub-hal-1-0 /vendor/bin/hw/android.hardware.contexthub@1.0-service
class hal
user system
group system
# ps -A | grep contexthub
system 11837 1 2126252 4380 binder_ioctl_write_read 0 S android.hardware.contexthub@1.0-service
Android HAL模块的加载过程
https://juejin.im/post/5c0fbb3a6fb9a049f23c9b13
HAL模块的存放路径是有规范的。HAL规定了2个硬件模块动态共享库的存放路径,定义在/hardware/libhardware/hardware.c:
/** Base path of the hal modules */
#if defined(__LP64__)
#define HAL_LIBRARY_PATH1 "/system/lib64/hw"
#define HAL_LIBRARY_PATH2 "/vendor/lib64/hw"
#else
#define HAL_LIBRARY_PATH1 "/system/lib/hw"
#define HAL_LIBRARY_PATH2 "/vendor/lib/hw"
#endif
所以,硬件模块的共享库必须放在/system/lib/hw 或者 /vendor/lib/hw 这2个路径下的其中一个
/vendor/lib/hw # cd /system//lib/hw/ /system/lib/hw # ls -al | grep context 没有hal模块
/vendor/lib/hw # ls -al | grep context [加载的是1.0-impl.generic是毫无疑问的,问题是怎么加载的还要研究下]
android.hardware.contexthub@1.0-impl.generic.so
cc_library_shared { name: "android.hardware.contexthub@1.0-impl.generic", vendor: true, relative_install_path: "hw", srcs: [ "host/hal_generic/generic_context_hub.cc", ], cflags: ["-Wall", "-Werror"], cpp_std: "c++17", shared_libs: [ "libcutils", "liblog", "libhidlbase", "libhidltransport", "libutils", "android.hardware.contexthub@1.0", ], static_libs: ["chre_client"], tags: ["optional"], }