android Native相关知识点

1)添加到loop循环中==》epoll_ctl

1.1)native code中的input(1.2中的)向java或jni层发消息,要求处理input相关事件。

code->messageQueue->getLooper()->addFd( code->mainWorkRead, 0, ALOOPER_EVENT_INPUT, mainWorkCallback, code);

1.2)input事件查询的2个fd

1.2.1)来自input dispatch

mLooper->addFd(mConsumer.getChannel()->getFd(), ident, ALOOPER_EVENT_INPUT, callback, data);

1.2.2)此处key事件是来自IME,需要发送到消息队列中。
mLooper->addFd(mDispatchKeyRead, ident, ALOOPER_EVENT_INPUT, callback, data);

1.2中的事件若需要jni或java层处理则通过mainWorkWrie/mainWorkRead管道发消息给mainWorkCallback处理。(为了input快速返回?)


2)mainWorkCallback在主线程,inputqueue在子线程,dev写的native code也在子线程。

主线程调用natiecode的也是通过pipe

 ALooper_addFd(looper, android_app->msgread, LOOPER_ID_MAIN, ALOOPER_EVENT_INPUT, NULL, &android_app->cmdPollSource);
java/jni主线程-->dev_native
static void android_app_write_cmd(struct android_app* android_app, int8_t cmd) {
    if (write(android_app->msgwrite, &cmd, sizeof(cmd)) != sizeof(cmd)) {
        LOGE("Failure writing android_app cmd: %s\n", strerror(errno));
    }
}

nt8_t android_app_read_cmd(struct android_app* android_app) {
    int8_t cmd;
    if (read(android_app->msgread, &cmd, sizeof(cmd)) == sizeof(cmd)) {xx}

}

3)public abstract void takeSurface (SurfaceHolder.Callback2 callback)

Added in API level 9

Take ownership of this window's surface. The window's view hierarchy will no longer draw into the surface, though it will otherwise continue to operate (such as for receiving input events). The given SurfaceHolder callback will be used to tell you about state changes to the surface.

public abstract void takeInputQueue (InputQueue.Callback callback)
Added in API level 9

Take ownership of this window's InputQueue. The window will no longer read and dispatch input events from the queue; it is your responsibility to do so.




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值