一. Input 系统的初始化
1. InputManagerService 是由SystemServer建立的
在frameworks/base/services/java/com/android/server/SystemServer.java中
1.1 new的调用过程
SystemServer:: new InputManagerService
--> InputManagerService 构造函数
在frameworks/base/services/java/com/android/server/input/InputManagerService.java中
SystemServer:: new InputManagerService
--> InputManagerService 构造函数
--> nativeInit ;;通过jni调用
在frameworks/base/services/jni/com_android_server_input_InputManagerService.cpp 中
SystemServer:: new InputManagerService
--> InputManagerService 构造函数
--> nativeInit ;;通过jni调用 NativeInputManager 的构造
--> NativeInputManager ;;new一个EventHub和InputManager
在frameworks/base/services/jni/com_android_server_input_InputManagerService.cpp中
SystemServer:: new InputManagerService
--> InputManagerService 构造函数
--> nativeInit ;;通过jni调用 NativeInputManager 的构造
--> NativeInputManager构造 ;;new一个EventHub和InputManager
--> InputManager 构造 ;;new InputDispatcher和InputReader及其线程
在frameworks/base/services/input/InputManager.cpp中
在 InputManager 的构造函数中,又建立了InputDispatcher和InputReader
同时又建立了InputDispatcher和InputReader各自的线程
1.2 start的调用过程
SystemServer:: InputManagerService .start
--> InputManagerService ::start ;;调用jni
在frameworks/base/services/java/com/android/server/input/InputManagerService.java中
SystemServer:: InputManagerService
.start
--> InputManagerService ::start ;;调用jni
--> nativeStart ;;通过jni调用 NativeInputManager 的start
在frameworks/base/services/jni/com_android_server_input_InputManagerService.cpp 中
SystemServer:: InputManagerService
.start
--> InputManagerService ::start ;;调用jni
--> nativeStart ;;通过jni调用 NativeInputManager 的start
--> NativeInputManager::nativeStart ;;调用InputManager的start
在frameworks/base/services/jni/com_android_server_input_InputManagerService.cpp中
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. InputManagerService 是由SystemServer建立的
在frameworks/base/services/java/com/android/server/SystemServer.java中
- class ServerThread extends Thread {
- @Override
- public void run() {
- HandlerThread wmHandlerThread = new HandlerThread("WindowManager");
- wmHandlerThread.start();
- Handler wmHandler = new Handler(wmHandlerThread.getLooper());
- context = ActivityManagerService.main(factoryTest);
-
- InputManagerService inputManager = null;
- //1.1 new的过程创建InputReader InputDispatcher和EventHub
- inputManager = new InputManagerService(context, wmHandler);
- inputManager.setWindowManagerCallbacks(wm.getInputMonitor());
- //1.2 start的过程:将InputReader与InputDispatcher的线程跑起来
- inputManager.start();
-
- display.setInputManager(inputManager);
- }
- }
SystemServer:: new InputManagerService
--> InputManagerService 构造函数
在frameworks/base/services/java/com/android/server/input/InputManagerService.java中
- public InputManagerService(Context context, Handler handler)
- {
- this.mContext = context;
- this.mHandler = new InputManagerHandler(handler.getLooper());
- mPtr = nativeInit(this, mContext, mHandler.getLooper().getQueue());
- }
--> InputManagerService 构造函数
--> nativeInit ;;通过jni调用
在frameworks/base/services/jni/com_android_server_input_InputManagerService.cpp 中
- static jint nativeInit(JNIEnv* env, jclass clazz, jobject serviceObj, jobject contextObj, jobject messageQueueObj)
- {
- sp<MessageQueue> messageQueue = android_os_MessageQueue_getMessageQueue(env, messageQueueObj);
- NativeInputManager* im = new NativeInputManager(contextObj, serviceObj, messageQueue->getLooper());
- im->incStrong(serviceObj);
- return reinterpret_cast<jint>(im);
- }
--> InputManagerService 构造函数
--> nativeInit ;;通过jni调用 NativeInputManager 的构造
--> NativeInputManager ;;new一个EventHub和InputManager
在frameworks/base/services/jni/com_android_server_input_InputManagerService.cpp中
- NativeInputManager::NativeInputManager(jobject contextObj, jobject serviceObj, const sp<Looper>& looper) : mLooper(looper)
- {
- JNIEnv* env = jniEnv();
- mContextObj = env->NewGlobalRef(contextObj);
- mServiceObj = env->NewGlobalRef(serviceObj);
- AutoMutex _l(mLock);
- mLocked.systemUiVisibility = ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE;
- mLocked.pointerSpeed = 0;
- mLocked.pointerGesturesEnabled = true;
- mLocked.showTouches = false;
-
- sp<EventHub> eventHub = new EventHub();
- mInputManager = new InputManager(eventHub, this, this);
- }
--> InputManagerService 构造函数
--> nativeInit ;;通过jni调用 NativeInputManager 的构造
--> NativeInputManager构造 ;;new一个EventHub和InputManager
--> InputManager 构造 ;;new InputDispatcher和InputReader及其线程
在frameworks/base/services/input/InputManager.cpp中
在 InputManager 的构造函数中,又建立了InputDispatcher和InputReader
- InputManager::InputManager(const sp<EventHubInterface>& eventHub,
- const sp<InputReaderPolicyInterface>& readerPolicy,
- const sp<InputDispatcherPolicyInterface>& dispatcherPolicy) {
- mDispatcher = new InputDispatcher(dispatcherPolicy);
- mReader = new InputReader(eventHub, readerPolicy, mDispatcher);
- initialize();
- }
- void InputManager::initialize() {
- mReaderThread = new InputReaderThread(mReader);
- mDispatcherThread = new InputDispatcherThread(mDispatcher);
- }
SystemServer:: InputManagerService .start
--> InputManagerService ::start ;;调用jni
在frameworks/base/services/java/com/android/server/input/InputManagerService.java中
- public void start() {
- nativeStart(mPtr);
- }
--> InputManagerService ::start ;;调用jni
--> nativeStart ;;通过jni调用 NativeInputManager 的start
在frameworks/base/services/jni/com_android_server_input_InputManagerService.cpp 中
- public void start() {
- nativeStart(mPtr);
- }
--> InputManagerService ::start ;;调用jni
--> nativeStart ;;通过jni调用 NativeInputManager 的start
--> NativeInputManager::nativeStart ;;调用InputManager的start
在frameworks/base/services/jni/com_android_server_input_InputManagerService.cpp中
- static void nativeStart(JNIEnv* env, jclass clazz, jint ptr) {
- NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
- status_t result = im->getInputManager()->start();
- }
--> InputManagerService ::start ;;调用jni
--> nativeStart ;;通过jni调用 NativeInputManager 的start
--> NativeInputManager::nativeStart ;;调用InputManager的start
--> InputManager ::start ;;让InputDispatcher和InputReader的线程跑起来
在frameworks/base/services/input/InputManager.cpp中
- status_t InputManager::start() {
- mDispatcherThread->run("InputDispatcher", PRIORITY_URGENT_DISPLAY);
- mReaderThread->run("InputReader", PRIORITY_URGENT_DISPLAY);
- return OK;
- }