Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2117253
  • 博文数量: 438
  • 博客积分: 3871
  • 博客等级: 中校
  • 技术积分: 6075
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-10 00:11
个人简介

邮箱: wangcong02345@163.com

文章分类

全部博文(438)

文章存档

2017年(15)

2016年(119)

2015年(91)

2014年(62)

2013年(56)

2012年(79)

2011年(16)

分类: Android平台

2014-06-26 16:13:09

一. 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 clazz, jobject 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 contextObj, jobject 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. }






阅读(874) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~