1.Android 4.0 用户输入子系统代码模块
frameworks/base/services/java/com/android/server/SystemServer.java
frameworks/base/services/java/com/android/server/wm/WindowManagerService.java
frameworks/base/services/java/com/android/server/wm/InputManager.java
frameworks/base/services/jni/com_android_server_InputManager.cpp
frameworks/base/services/input/Android.mk
frameworks/base/services/input/EventHub.cpp
frameworks/base/services/input/EventHub.h
frameworks/base/services/input/InputApplication.cpp
frameworks/base/services/input/InputDispatcher.cpp
frameworks/base/services/input/InputListener.cpp
frameworks/base/services/input/InputDispatcher.h
frameworks/base/services/input/InputListener.h
frameworks/base/services/input/InputManager.cpp
frameworks/base/services/input/InputManager.h
frameworks/base/services/input/InputReader.cpp
frameworks/base/services/input/InputReader.h
frameworks/base/services/input/InputWindow.cpp
frameworks/base/services/input/InputWindow.h
frameworks/base/services/input/PointerController.cpp
frameworks/base/services/input/PointerController.h
frameworks/base/services/input/SpriteController.cpp

frameworks/base/services/input/SpriteController.h


2.Service and WindowManagerService


[java] view plain copy
  1. Sourcecode:frameworks/base/services/java/com/android/server/SystemServer.java
  2. classServerThreadextendsThread{
  3. privatestaticfinalStringTAG="SystemServer";
  4. /*。。。。。。。。。。处略过若干行。。。。。。。。。*/
  5. Slog.i(TAG,"WindowManager");
  6. wm=WindowManagerService.main(context,power,
  7. factoryTest!=SystemServer.FACTORY_TEST_LOW_LEVEL,
  8. !firstBoot);
  9. ServiceManager.addService(Context.WINDOW_SERVICE,wm);
  10. ActivityManagerService.self().setWindowManager(wm);
  11. }
功能描述:系统启动过程通过SystemServer添加WindowManagerService到服务列表

--WindowManagerService的构造方法

[java] view plain copy
  1. Sourcecode:frameworks/base/services/java/com/android/server/wm/WindowManagerService.java
  2. privateWindowManagerService(Contextcontext,PowerManagerServicepm,
  3. booleanhaveInputMethods,booleanshowBootMsgs){
  4. mInputManager=newInputManager(context,this);/*构造InputManager*/
  5. PolicyThreadthr=newPolicyThread(mPolicy,this,context,pm);
  6. thr.start();
  7. /*debugbyJoyce*/
  8. synchronized(thr){
  9. while(!thr.mRunning){
  10. try{
  11. thr.wait();
  12. }catch(InterruptedExceptione){
  13. }
  14. }
  15. }
  16. mInputManager.start();/*启动InputManager*/
  17. }

功能描述:1)初始化并构造一个InputManager实例mInputManager
2)开启InputManager(由InputManager本身start()方法实现)

--InputManager构造方法以及start()方法的实现

[java] view plain copy
  1. Sourcecode:frameworks/base/services/java/com/android/server/wm/InputManager.java
  2. publicInputManager(Contextcontext,WindowManagerServicewindowManagerService){
  3. this.mContext=context;
  4. this.mWindowManagerService=windowManagerService;
  5. this.mCallbacks=newCallbacks();
  6. /*现在知道为何与WindowManagerService有关系了吧
  7. *因为InputManager的各种需求
  8. */
  9. /*获取Looper循环队列?说实话我已经忘记了,只不过还记得那一副经典的图*/
  10. Looperlooper=windowManagerService.mH.getLooper();
  11. Slog.i(TAG,"Initializinginputmanager");
  12. nativeInit(mContext,mCallbacks,looper.getQueue());/*初始化InputManager*/
  13. }
  14. /*debugbyJoyce*/
  15. publicvoidstart(){
  16. Slog.i(TAG,"HeyJoyceStartinginputmanager");
  17. nativeStart();/*启动InputManager的本地实现*/
  18. }
  19. }
功能描述:1)调用JNI本地框架中的nativeInit方法来初始化InputManager
2)调用JNI本地框架中的nativeStart方法来开启InputManager


3.JNI本地框架的实现
--com_android_server_InputManager中给上层InputManager所提供的两个本地AP的实现

------------------>A部分[java] view plain copy
  1. Sourcecode:frameworks/base/services/jni/com_android_server_InputManager.cpp
  2. /*方法映射表*/
  3. staticJNINativeMethodgInputManagerMethods[]={
  4. /*name,signature,funcPtr*/
  5. {"nativeInit","(Landroid/content/Context;"
  6. "Lcom/android/server/wm/InputManager$Callbacks;Landroid/os/MessageQueue;)V",
  7. (void*)android_server_InputManager_nativeInit},
  8. {"nativeStart","()V",
  9. (void*)android_server_InputManager_nativeStart},
  10. }
  11. staticvoidandroid_server_InputManager_nativeInit(JNIEnv*env,jclassclazz,
  12. jobjectcontextObj,jobjectcallbacksObj,jobjectmessageQueueObj){
  13. if(gNativeInputManager==NULL){/*首次调用肯定为NULL*/
  14. sp<Looper>looper=android_os_MessageQueue_getLooper(env,messageQueueObj);
  15. gNativeInputManager=newNativeInputManager(contextObj,callbacksObj,looper);
  16. }else{
  17. LOGE("Inputmanageralreadyinitialized.");
  18. jniThrowRuntimeException(env,"Inputmanageralreadyinitialized.");
  19. }
  20. }
  21. --NativeInputManager本地类的构造函数
  22. NativeInputManager::NativeInputManager(jobjectcontextObj,
  23. jobjectcallbacksObj,constsp<Looper>&looper):
  24. mLooper(looper){
  25. JNIEnv*env=jniEnv();
  26. /*程序到这里就已经为我们创建一个inputdeviceHAL的实例了*/
  27. sp<EventHub>eventHub=newEventHub();/*creattheEventHub一系列的memset*/
  28. /*并以eventHub为参数为我们创建了一个InputManager本地实例,注意这个InputManager
  29. 是上层InputManager的本地实现定义在InputManager.cpp中
  30. */
  31. mInputManager=newInputManager(eventHub,this,this);
  32. }
  33. --InputManager构造函数的实现
  34. Sourcecode:frameworks/base/services/input/InputManager.cpp
  35. InputManager::InputManager(
  36. constsp<EventHubInterface>&eventHub,
  37. constsp<InputReaderPolicyInterface>&readerPolicy,
  38. constsp<InputDispatcherPolicyInterface>&dispatcherPolicy){
  39. mDispatcher=newInputDispatcher(dispatcherPolicy);
  40. mReader=newInputReader(eventHub,readerPolicy,mDispatcher);
  41. initialize();
  42. }


功能描述:1)创建NativeInputManager对象并保存成gNativeInputManager,该变量马上就会被用到
2)创建NativeInputManager对象的同时创建EventHub对象,并将创建的EventHub对象mEventHub作为参数传递给InputManager
的构造函数创建InputManager对象mInputManager
3)构建InputManager的同时会为我们构建InputDispatcher和InputReader对象
4)好了其实到这里就已经进入了本地C++框架层了,先到此打住,把下面这个JNI方法先分析一番

------------------>B部分

[java] view plain copy
  1. staticvoidandroid_server_InputManager_nativeStart(JNIEnv*env,jclassclazz){
  2. if(checkInputManagerUnitialized(env)){
  3. return;
  4. }
  5. status_tresult=gNativeInputManager->getInputManager()->start();
  6. if(result){
  7. jniThrowRuntimeException(env,"Inputmanagercouldnotbestarted.");
  8. }
  9. }

功能描述:1)很简单直接调用上面初始化过程中创建的NativeInputManager对象mNativeInputManager去调用getInputManager()函数,该函数又刚好返回InputManager对象mInputManager了
2)再由mInputManager去调用它本身的start()方法来启动InputManager
3)从上面的这些方法可以得知在上层我们开启InputManager实质是开启了本地C++框架中的InputManager
4.C++Input框架的实现

更多相关文章

  1. 【Android】安卓中常用的图片加载方法
  2. android 申请移动应用的签名生成方法
  3. Android SDK下载和更新失败的解决方法!!!
  4. Android studioError:(13, 0) Gradle DSL method not found: 'an
  5. android字体加粗的方法
  6. android中各种图标尺寸以及多分辨率支持方法
  7. android 7.0 系统关闭彩信过CTA测试的方法

随机推荐

  1. Android(安卓)开发环境搭建
  2. android获取版本号
  3. 关于Android的文字排版和换行问题,彻底解
  4. Android(安卓)调试错误: java.lang.Secur
  5. android 获取实际view 宽度高度
  6. Android(安卓)Post Get 示例
  7. Android(安卓)room操作数据库
  8. Android(安卓)Action
  9. Android(安卓)拦截短信配置
  10. Android蓝牙开发浅谈