Cubietruck---18.input子系统启动流程分析

一. Input 系统的初始化
1. InputManagerService 是由SystemServer建立的
在frameworks/base/services/java/com/android/server/SystemServer.java中
  1. class ServerThread extends Thread {
  2.  @Override
  3.     public void run() {
  4.       HandlerThread wmHandlerThread = new HandlerThread("WindowManager");
  5.       wmHandlerThread.start();
  6.       Handler wmHandler = new Handler(wmHandlerThread.getLooper());
  7.       context = ActivityManagerService.main(factoryTest);
  8.      
  9.       InputManagerService inputManager = null;
  10.       //1.1 new的过程创建InputReader InputDispatcher和EventHub  
  11.       inputManager = new InputManagerService(context, wmHandler);  
  12.       inputManager.setWindowManagerCallbacks(wm.getInputMonitor());
  13.       //1.2 start的过程:将InputReader与InputDispatcher的线程跑起来
  14.       inputManager.start();                  
  15.      
  16.       display.setInputManager(inputManager);
  17.      }
  18. }
1.1 new的调用过程
SystemServer:: new InputManagerService
  -->  InputManagerService 构造函数
在frameworks/base/services/java/com/android/server/input/InputManagerService.java中
  1. public InputManagerService(Context context, Handler handler) 
  2. {
  3.     this.mContext = context;
  4.     this.mHandler = new InputManagerHandler(handler.getLooper());    
  5.     mPtr = nativeInit(this, mContext, mHandler.getLooper().getQueue());
  6. }
SystemServer:: new InputManagerService
  -->  InputManagerService 构造函数
    --> nativeInit     ;;通过jni调用
在frameworks/base/services/jni/com_android_server_input_InputManagerService.cpp 中
  1. static jint nativeInit(JNIEnv* env, jclass clazzjobject serviceObj, jobject contextObj, jobject messageQueueObj) 
  2. {
  3.     sp<MessageQueue> messageQueue = android_os_MessageQueue_getMessageQueue(env, messageQueueObj);
  4.     NativeInputManager* im = new NativeInputManager(contextObj, serviceObj, messageQueue->getLooper());
  5.     im->incStrong(serviceObj);
  6.     return reinterpret_cast<jint>(im);
  7. }
SystemServer:: new InputManagerService
  -->  InputManagerService 构造函数
    --> nativeInit     ;;通过jni调用 NativeInputManager 的构造
        -->  NativeInputManager  ;;new一个EventHub和InputManager
在frameworks/base/services/jni/com_android_server_input_InputManagerService.cpp中
  1. NativeInputManager::NativeInputManager(jobject contextObjjobject serviceObj, const sp<Looper>& looper) : mLooper(looper) 
  2. {
  3.     JNIEnv* env = jniEnv();
  4.     mContextObj = env->NewGlobalRef(contextObj);
  5.     mServiceObj = env->NewGlobalRef(serviceObj);
  6.     AutoMutex _l(mLock);
  7.     mLocked.systemUiVisibility = ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE;
  8.     mLocked.pointerSpeed = 0; 
  9.     mLocked.pointerGesturesEnabled = true;
  10.     mLocked.showTouches = false;

  11.     sp<EventHub> eventHub = new EventHub();
  12.     mInputManager = new InputManager(eventHub, this, this);
  13. }
SystemServer:: new InputManagerService
  -->  InputManagerService 构造函数
    --> nativeInit         ;;通过jni调用 NativeInputManager 的构造
        -->  NativeInputManager构造  ;;new一个EventHub和InputManager
          -->  InputManager 构造       ;;new InputDispatcher和InputReader及其线程
在frameworks/base/services/input/InputManager.cpp中
InputManager 的构造函数中,又建立了InputDispatcher和InputReader
  1. InputManager::InputManager(const sp<EventHubInterface>& eventHub,
  2.         const sp<InputReaderPolicyInterface>& readerPolicy,
  3.         const sp<InputDispatcherPolicyInterface>& dispatcherPolicy) {
  4.     mDispatcher = new InputDispatcher(dispatcherPolicy);
  5.     mReader = new InputReader(eventHub, readerPolicy, mDispatcher);
  6.     initialize();
  7. }
同时又建立了InputDispatcher和InputReader各自的线程
  1. void InputManager::initialize() {
  2.     mReaderThread = new InputReaderThread(mReader);
  3.     mDispatcherThread = new InputDispatcherThread(mDispatcher);
  4. }
1.2 start的调用过程
SystemServer:: InputManagerService .start
  -->  InputManagerService ::start   ;;调用jni
在frameworks/base/services/java/com/android/server/input/InputManagerService.java中
  1. public void start() {
  2.     nativeStart(mPtr);
  3. }
SystemServer:: InputManagerService .start
  -->  InputManagerService ::start   ;;调用jni
    --> nativeStart          ;;通过jni调用 NativeInputManager 的start
在frameworks/base/services/jni/com_android_server_input_InputManagerService.cpp 中
  1. public void start() {
  2.     nativeStart(mPtr);
  3. }
SystemServer:: InputManagerService .start
  -->  InputManagerService ::start   ;;调用jni
    --> nativeStart          ;;通过jni调用 NativeInputManager 的start
        -->  NativeInputManager::nativeStart  ;;调用InputManager的start
在frameworks/base/services/jni/com_android_server_input_InputManagerService.cpp中
  1. static void nativeStart(JNIEnv* env, jclass clazz, jint ptr) {
  2.     NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
  3.     status_t result = im->getInputManager()->start();
  4. }
SystemServer:: InputManagerService .start
  -->  InputManagerService ::start   ;;调用jni
    --> nativeStart          ;;通过jni调用 NativeInputManager 的start
        -->  NativeInputManager::nativeStart  ;;调用InputManager的start
          -->  InputManager ::start       ;;让InputDispatcher和InputReader的线程跑起来
在frameworks/base/services/input/InputManager.cpp中
  1. status_t InputManager::start() {
  2.     mDispatcherThread->run("InputDispatcher", PRIORITY_URGENT_DISPLAY);
  3.     mReaderThread->run("InputReader", PRIORITY_URGENT_DISPLAY);
  4.     return OK;
  5. }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值