CHRE: /vendor/bin/chre

从上文知道IContexthub service最终通过socket和chre通信,暂且不关注chre通过 fastrpc和dsp的通信。

system/chre/host/msm/Android.mk

LOCAL_MODULE := chre
LOCAL_VENDOR_MODULE := true
LOCAL_CPP_EXTENSION := .cc
FASTRPC_INC := $(TARGET_OUT_INTERMEDIATES)/include/fastrpc/inc
LOCAL_ADDITIONAL_DEPENDENCIES ::= $(FASTRPC_INC)
LOCAL_SRC_FILES := \
    ../../platform/shared/host_protocol_common.cc \
    ../common/host_protocol_host.cc \
    ../common/socket_server.cc \
    daemon/chre_daemon.cc \
    daemon/generated/chre_slpi_stub.c
LOCAL_C_INCLUDES := \
    $(FASTRPC_INC) \
    system/chre/platform/slpi/include \
LOCAL_HEADER_LIBRARIES := chre_flatbuffers
LOCAL_SHARED_LIBRARIES := \
    libbase \
    libutils \
    libcutils \
    liblog \
LOCAL_SHARED_LIBRARIES += libadsprpc

# ps -A | grep chre


system        2050     1   19300   4888 do_sys_poll         0 S chre

ps -A | grep context


system       18927     1 2126252   5104 binder_ioctl_write_read 0 S android.hardware.contexthub@1.0-service

 

kill contexthu-service场景

CHRE server收到断开信息

chre/host/common/socket_server.cc -> handleClientData -> LOGI("Client %" PRIu16 " disconnected", clientId)

CHRE    : Client 3 disconnected

ontexthub@1.0-service自动启动(init.rc不是one-shot), 再次注册service

ALOGI("Registration complete for %s/%s.",Interface::descriptor, name.c_str()); 


android.hardware.contexthub@1.0-service: Registration complete for android.hardware.contexthub@1.0::IContexthub/default.

重新和chre建立socket连接

SocketClient::reconnect() -> LOGD("Successfully (re)connected")
CHRE    : Successfully (re)connected

SocketServer::acceptClientConnection()

03-27 15:18:27.290 18996 18996 I CHRE    : Accepted new client connection (count 1), assigned client ID 1

 

kill chre

CHRE    : Caught signal 15
CHRE    : Exiting poll loop: Interrupted system call
CHRE    : Socket disconnected on remote end
ContextHubHal: Lost connection to CHRE daemon

CHRE    : Shutdown complete
/vendor/bin/chre: vendor/qcom/proprietary/commonsys-intf/adsprpc/src/fastrpc_apps_user.c:1006: remote_handle_open: Successfully opened handle 0x37260a70 for chre_slpi on domain 2
/vendor/bin/chre: vendor/qcom/proprietary/commonsys-intf/adsprpc/src/fastrpc_apps_user.c:1006: remote_handle_open: Successfully opened handle 0x372609f0 for chre_slpi on domain 2


CHRE    : CHRE on SLPI started
CHRE    : Ready to accept connections
CHRE    : Successfully (re)connected
ContextHubHal: Reconnected to CHRE daemon
CHRE    : Accepted new client connection (count 1), assigned client ID 1

main函数分析

分为3部分:

1. 在slpi侧建立thread运行chre处理来着host的 Events,

对events的处理分两步a. 放入队列 b.处理每个nanoApp上的event 

2. 处理来着chre的message

3. 通过socket:chre处理来着client的message, 调用slpi/chre处理

 

NanoApp是个什么

组成

nanoappStart/HandleEvent/End : entry points from the system into the nanoapp 也就是实现这3个函数,其中主要是HandleEvent

NanoApp的创建

实现entryPoints: start/end/handleEvent

DLL_EXPORT const struct chreNslNanoappInfo _chreNslDsoNanoappInfo = {
  .magic = CHRE_NSL_NANOAPP_INFO_MAGIC,
  .structMinorVersion = CHRE_NSL_NANOAPP_INFO_STRUCT_MINOR_VERSION,
  .targetApiVersion = CHRE_API_VERSION,

  // These values are supplied by the build environment
  .vendor = NANOAPP_VENDOR_STRING,
  .name = NANOAPP_NAME_STRING,
  .isSystemNanoapp = 0,
  .appId = NANOAPP_ID,
  .appVersion = NANOAPP_VERSION,

  .entryPoints = {
    .start = nanoappStart,
    .handleEvent = nanoappHandleEvent,
    .end = nanoappEnd,
  },
};

编译成什么

是个共享库 so文件

target_so = '${BUILDPATH}/'+LIBNAME+'.so'

BUILD_DLLS += chre_app_sensor_cfg

入口点的调用

start

当通过socket: chre收到loadNanoapp时,创建nanoApp, 调用start函数

handleEvent

当收到client发来的message时

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值