IContexthub.hal 生成的是个abstract class: interface还没有具体的实现
public static abstract class Stub extends android.os.HwBinder implements IContexthub{}
system/chre/Android.bp 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"], }
cc_library_static { name: "chre_client", vendor: true, export_include_dirs: [ "host/common/include", "platform/shared/include", "util/include", ], srcs: [ "host/common/fragmented_load_transaction.cc", "host/common/host_protocol_host.cc", "host/common/socket_client.cc", "platform/shared/host_protocol_common.cc", ], header_libs: ["chre_flatbuffers"], export_header_lib_headers: ["chre_flatbuffers"], shared_libs: [ "libcutils", "liblog", "libutils", ], cflags: ["-Wall", "-Werror"], }
generic_context_hub.cc
Return<void> GenericContextHub::getHubs(getHubs_cb _hidl_cb) { std::vector<ContextHub> hubs; ALOGV("%s", __func__); if (!mClient.isConnected()) { ALOGE("Couldn't connect to hub daemon"); } { // We haven't cached the hub details yet, so send a request and block // waiting on a response std::unique_lock<std::mutex> lock(mHubInfoMutex); FlatBufferBuilder builder; HostProtocolHost::encodeHubInfoRequest(builder); ALOGD("Sending hub info request"); if (!mClient.sendMessage(builder.GetBufferPointer(), builder.GetSize())) { ALOGE("Couldn't send hub info request"); } } _hidl_cb(hubs); return Void(); }
这里的mClient是什么?和谁连接?
GenericContextHub实现了IContecthub 并且通过SocketClient (chre): mClient 和 chre通信。
IContexthub的具体实现
创建FlatBufferBuilder, 使用具体的协议如HubInfo对Buffer编码(encode), 最后通过socket: chre 发送数据.
IContexthubCallback