还是以SurfaceFlinger为例论述。SurfaceFlinger的init方法会调用MessageQueue的setEventThread方法创建Connection对象,并且还会调用Looper的addFd方法将BitTube对象的文件描述符添加到Looper中进行监听,
mEventThread = eventThread;
mEvents = eventThread->createEventConnection();
mEvents->stealReceiveChannel(&mEventTube);
mLooper->addFd(mEventTube.getFd(), 0, Looper::EVENT_INPUT,
MessageQueue::cb_eventReceiver, this);
也就是说,一旦BitTube对象的文件描述符发生变化,就会回调MessageQueue的cb_eventReceiver方法。
Looper的addFd方法调用流程图如下,