android Native相关知识点

来源:互联网 发布:linux设置ftp访问目录 编辑:程序博客网 时间:2024/06/05 18:46

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.