为什么KeyEvent会先被PhoneWindowManager.java(Ics 4.03) 文件的 interceptKeyBeforeDispatching()处理;

来源:互联网 发布:热门推荐算法 编辑:程序博客网 时间:2024/06/09 20:38
为什么KeyEvent会先被PhoneWindowManager.java(Ics 4.03)文件的
interceptKeyBeforeDispatching()处理;
一些按键HOME/MENU/SEARCH需要特殊处理,不会发送到activity,android系统都是在
interceptKeyBeforeDispatching()做特殊处理,那么为什么按键会先被这个函数接受,而不是别的函数,系统Event的传递流程是什么?
下面会一步步揭晓;
SystemServer.java
System.loadLibrary("android_servers");
libandroid_servers:
extern "C" jintJNI_OnLoad(JavaVM* vm, void* reserved)
{
   register_android_server_InputManager(env);
}
这样:
Java层里面nativeInit就对应 native层的: android_server_InputManager_nativeInit
建立javac的关联:
native,会有一个thread一直去polling linuxinput输入;
如果是TYPE_KEY的话,会call下列函数:
InputDispatcher.cpp  
dispatchKeyLocked()->doInterceptKeyBeforeDispatchingLockedInterruptible()
->mPolicy->interceptKeyBeforeDispatching()
mPolicy实体C 层的com_android_server_InputManager.cpp
那么C层的interceptKeyBeforeDispatching()是如何实现的呢?
GET_METHOD_ID(gCallbacksClassInfo.interceptKeyBeforeDispatching,clazz,
           "interceptKeyBeforeDispatching",
           "(Lcom/android/server/wm/InputWindowHandle;Landroid/view/KeyEvent;I)J");
所以C层的interceptKeyBeforeDispatching对应java层的:
InputManager.java->  interceptKeyBeforeDispatching;
这样就来到的java的世界,在C层的keyevent就传递给了java层;
再来看java层的处理流程
public long interceptKeyBeforeDispatching(InputWindowHandlefocus,
                KeyEvent event, intpolicyFlags) {
           return mWindowManagerService.mInputMonitor.interceptKeyBeforeDispatching(
                    focus, event, policyFlags);
       }
所以interceptKeyBeforeDispatching函数最终会调用
finalInputMonitor mInputMonitor = new InputMonitor(this);
    public long interceptKeyBeforeDispatching(
         
        return mService.mPolicy.interceptKeyBeforeDispatching(windowState, event,policyFlags);
    }
0 0
原创粉丝点击