10.10 android输入系统_APP获得并处理输入事件流程
APP对fd/InputChannel的注册过程:
new WindowInputEventReceiver extends InputEventReceiver//InputEventReceiver类的dispatchInputEvent函数会调用onInputEvent
onInputEvent函数在收到事件后被调用//被父类的dispatchInputEvent调用
在InputEventReceiver的构造函数中调用nativeInit
nativeInit//从java进入C++
new NativeInputEventReceiver
consumeEvents//调用Java层的函数dispatchInputEvent
dispatchInputEvent
最后会把fd加入epoll去监控
APP获得并处理输入事件流程
pollOnce
polInner
epoll_wait//等待各种事件的发生
pushResponse(events,mRequests.valueAt(requestIndex))构造response放入某个缓冲区
Response& response = mResponses.editItemAt(i)//从缓冲取出response
int callbackResult = response.request.callback->handleEvent(fd,events,data)
consumeEvents(env,false,-1,NULL)
mInputConsumer.consume(...,&seq,&inputEvent)
mChannel->receiveMessage(&mMsg)
nRead = ::recv(mFD,msg,sizeof(InputMessage),MSG_DONTWAIT)
initializeKeyEvent(keyEvent,&mMsg)
*outSeq = mMsg.body.key.seq
*outEvent = keyEvent
inputEventObj = android_view_KeyEvent_fromNative(env,static_cast<KeyEvent*>(inputEvent))
env->CallVoidMethod(receiverObj.get(),gInputEventReceivrrClassInfo.dispatchInputEvent,seq,inputEventObj)
onInputEvent(event)
enqueueInputEvent(event,this,0,true)
mPendingInputEventTail =q
doProcessInputEvents//处理众多的输入事件
QueueInputEvent q = mPendingInputEventHead;
mPendingInputEventHead = q.mNext
deliverInputEvent(q)
stage = q.shouldSkipIme()?mFirstPostImeInputStage:mFirstInputStage;//如果应用程序使用输入法,就从mFirstInputStage开始处理,如果不使用输入法,就从mFirstPostImeInputStage开始处理
stage.deliver(q)
InputStage stage的分析见下图
如果应用程序使用输入法,就从mFirstInputStage开始处理,如果不使用输入法,就从mFirstPostImeInputStage开始处理