转载

Android input 系统初始化和启动流程

Input 系统核心线程之初始化和启动流程

一. 背景:

做Android touch 驱动时,设备在开机的时加载动画(kernel 层已load OK),若用手连续点击屏幕,待完全设备开机后UI 没有反应,但是touch依然正常报点,多点触摸时会临时恢复,但finger release 后依然恢复原样(UI没反应),初入行做驱动,借助前人的智慧,追了一下touch事件上报处理流程。

二 .Input 系统核心线程

InputReader and InputDisapatcher
  1. 该两个线程在IMS(InputManagerService)服务中伴随着system_server进程的启动而启动,整个调用过程:
InputManagerService(IMS初始化)
    nativeInit
        NativeInputManager
            EventHub
            InputManager
                InputDispatcher
                    Looper
                InputReader
                    QueuedInputListener
                InputReaderThread
                InputDispatcherThread
IMS.start(启动)
    nativeStart
        InputManager.start
            InputReaderThread->run
            InputDispatcherThread->run

1.1初始化过程

private void startOtherServices();                        framworks/base/services/java/com/android/server/SystemServer.java
    inputManager = new InputManagerService(context);                
    public InputManagerService(Context context)                    framworks/base/services/core/java/com/android/server/input/InputManagerService.java              
    mPtr = nativeInit(this, mContext, mHandler.getLooper().getQueue());    
        static jlong nativeInit                            framworks/base/services/core/jni/com_android_server_input_InputManagerService.cpp
            NativeInputManager* im = new NativeInputManager(contextObj, serviceObj,messageQueue->getLooper()) ;  framworks/base/services/core/jni/com_android_server_input_InputManagerService.cpp
            NativeInputManager::NativeInputManager                framworks/base/services/core/jni/com_android_server_input_InputManagerService.cpp
                (1)sp<EventHub> eventHub = new EventHub();            
                EventHub::EventHub(void);                    frameworks/native/services/inputflinger/EventHub.cpp
                (2)mInputManager = new InputManager(eventHub, this, this);
                InputManager::InputManager                    frameworks/native/services/inputflinger/InputManager.cpp
                    
                    (1)mDispatcher = new InputDispatcher(dispatcherPolicy);  
                       InputDispatcher::InputDispatcher                frameworks/native/services/inputflinger/InputDispatcher.cpp           
                    (2)mReader = new InputReader(eventHub, readerPolicy, mDispatcher);                   
                       InputReader::InputReader                    frameworks/native/services/inputflinger/InputReader.cpp  
                    (3)initialize();
                       mReaderThread = new InputReaderThread(mReader);  
                       InputReaderThread::InputReaderThread
                                           
                       mDispatcherThread = new InputDispatcherThread(mDispatcher); 
                       InputDispatcherThread::InputDispatcherThread

1.2启动过程:

public void start()                                frameworks/base/services/core/java/com/android/server/input/InputManagerService.java
    nativeStart(mPtr);                                framworks/base/services/core/jni/com_android_server_input_InputManagerService.cpp
    static void nativeStart(JNIEnv* env, jclass /* clazz */, jlong ptr)
        status_t result = im->getInputManager()->start();
        status_t InputManager::start()                +        frameworks/native/services/inputflinger/InputManager.cpp
            result = mDispatcherThread->run("InputDispatcher", PRIORITY_URGENT_DISPLAY);
            result = mReaderThread->run("InputReader", PRIORITY_URGENT_DISPLAY);

    Java层InputManagerService:采用android.display线程处理Message.
    JNI的NativeInputManager:采用android.display线程处理Message,以及创建EventHub。
    Native的InputManager:创建InputReaderThread和InputDispatcherThread两个线程
原文  https://segmentfault.com/a/1190000021298515
正文到此结束
Loading...