美文网首页
Android:Input系统总结

Android:Input系统总结

作者: 我在等你回复可你没回 | 来源:发表于2019-06-20 14:57 被阅读0次

InputDispatcher线程跑在什么进程?

跑在System_server


image.png

InputDispatcher线程是在哪里启动的?

在 /frameworks/native/services/inputflinger/InputManager.cpp

status_t InputManager::start() {
    status_t result = mDispatcherThread->run("InputDispatcher", PRIORITY_URGENT_DISPLAY);
    if (result) {
        ALOGE("Could not start InputDispatcher thread due to error %d.", result);
        return result;
    }

    result = mReaderThread->run("InputReader", PRIORITY_URGENT_DISPLAY);
    if (result) {
        ALOGE("Could not start InputReader thread due to error %d.", result);

        mDispatcherThread->requestExit();
        return result;
    }

    return OK;
}

InputDispatcher线程入口在做什么?

bool InputDispatcherThread::threadLoop() {
    mDispatcher->dispatchOnce();
    return true;
}

其中mDispatcher的初始化
mDispatcher = new InputDispatcher(dispatcherPolicy);

线程在哪里睡眠?

在mLooper->pollOnce(timeoutMillis)中


image.png

java层和native层通过什么联系在一起?

通过inputWindowHandle联系。
/frameworks/base/services/core/java/com/android/server/input/InputManagerService.java

    public void registerInputChannel(InputChannel inputChannel,
            InputWindowHandle inputWindowHandle) {
        if (inputChannel == null) {
            throw new IllegalArgumentException("inputChannel must not be null.");
        }

        nativeRegisterInputChannel(mPtr, inputChannel, inputWindowHandle, false);
    }

在wms添加窗口的时候,创建了这个input的通道

    public int addWindow(Session session, IWindow client, int seq,
            WindowManager.LayoutParams attrs, int viewVisibility, int displayId,
            Rect outContentInsets, Rect outStableInsets, Rect outOutsets,
            InputChannel outInputChannel) {
      ................
      win.openInputChannel(outInputChannel);
      ................
     }

如何确认是哪个窗口被点击了?

相关文章

网友评论

      本文标题:Android:Input系统总结

      本文链接:https://www.haomeiwen.com/subject/clwdqctx.html