1. 程式人生 > >Android input 子系統

Android input 子系統

一.input 系統初始化
InputManagerService(java):
SystemService.run    --->    startOtherServices    ---->    new InputManagerService    ---->    NativeInit

(cpp)
new NativeInputManager: public virtual InputReaderPolicyInterface, public virtual InputDispatcherPolicyInterface, public virtual PointerControllerPolicyInterface 
    ---->
new EventHub : public EventHubInterface ----> epoll && inotify 監測 /dev/input 下檔案的建立與刪除 ----> 建立pipe並用epoll監聽其中的ReadPipe ----> new InputManager(eventHub) : public InputManagerInterface ----> new InputDispatcher : public InputDispatcherInterface ---->
new InputReader : public InputReaderInterface ----> new QueuedInputListener(InputDispatcher.InputListenerInterface) ----> initialize ----> new InputReaderThread(InputReader.InputReaderInterface) ----> new InputDispatcherThread(InputDispatcher.InputDispatcherInterface) (java) inputManager.setWindowManagerCallbacks(wm.getInputMonitor()) ---->
mWindowManagerCallbacks = callbacks inputManager.start() nativeStart (cpp) NativeInputManager->getInputManager()->start() ----> mDispatcherThread->run("InputDispatcher", PRIORITY_URGENT_DISPLAY) ----> threadLoop(){InputReaderInterface->loopOnce();return true;} ----> mReaderThread->run("InputReader", PRIORITY_URGENT_DISPLAY) ----> threadLoop(){InputDispatcherInterface->dispatchOnce();return true;} 二.讀取input events InputReaderInterface->loopOnce ----> EventHub->getEvents ----> scanDevicesLocked or readNotifyLocked ----> openDeviceLocked ----> new Device ----> processEventsLocked ---> addDeviceLocked ----> createDeviceLocked(InputDevice) ----> new InputDevice ----> addaddMapper ----> mDevices.add or--> processEventsForDeviceLocked ----> device->process ----> InputDevice::process ----> mapper->process ----> MultiTouchInputMapper::process ----> TouchInputMapper::process(rawEvent) ----> mCursorButtonAccumulator.process(rawEvent); ----> mCursorScrollAccumulator.process(rawEvent); ----> mTouchButtonAccumulator.process(rawEvent) ----> TouchInputMapper::sync ----> processRawTouches ----> cookAndDispatch ----> dispatchTouches ----> TouchInputMapper::dispatchMotion ----> getListener()->notifyMotion ----> InputDispatcherInterface.notifyMotion ----> InputDispatcherPolicyInterface->interceptMotionBeforeQueueing ----> mPolicy->filterInputEvent(&event, policyFlags) //可能會根據java中的policy過濾改event ----> enqueueInboundEventLocked(newEntry) //判斷是否需要喚起dispatchOnce ----> mMultiTouchMotionAccumulator.process(rawEvent) 三.分發events InputDispatcherInterface.dispatchOnce ----> dispatchOnceInnerLocked ----> mPendingEvent = mInboundQueue.dequeueAtHead() //取出event ----> pokeUserActivityLocked(mPendingEvent) //封裝成系統讀取的時間 呼叫mPolicy ----> dispatchMotionLocked ----> findTouchedWindowTargetsLocked //得到要對應的UI視窗 ----> dispatchEventLocked ----> connectionIndex = getConnectionIndexLocked(inputTarget.inputChannel) ----> connection = mConnectionsByFd.valueAt(connectionIndex) ----> prepareDispatchCycleLocked ----> enqueueDispatchEntriesLocked ----> startDispatchCycleLocked ----> status = connection->inputPublisher.publishMotionEvent