本文简要介绍Android Input系统的目录结构,详细说明可参考:https://blog.csdn.net/iEearth/article/details/86756978。
input命令是adb shell中的一个命令行调试input的工具,详细说明可参考:https://blog.csdn.net/iEearth/article/details/73555140。
在目录frameworks/base/core/java/android/hardware/input中有一些hardware相关的java代码,如下所示。各文件的用途可以从文件名看出来,重要的是InputManger,上面提到的input命令就是通过InputManager的injectInputEvent注入input事件的。
frameworks/base/core/java/android/hardware/input
├── IInputDevicesChangedListener.aidl
├── IInputManager.aidl
├── InputDeviceIdentifier.aidl
├── InputDeviceIdentifier.java
├── InputManagerInternal.java
├── InputManager.java
├── ITabletModeChangedListener.aidl
├── KeyboardLayout.aidl
├── KeyboardLayout.java
├── TouchCalibration.aidl
└── TouchCalibration.java
下面是input相关的jni文件,重点是com_android_server_input_InputManagerService.cpp中的NativeInputManager,是Java层InputManagerService与Native层InputManager沟通的桥梁。
frameworks/base/services/core/jni/com_android_server_input_InputWindowHandle.cpp
frameworks/base/services/core/jni/com_android_server_input_InputApplicationHandle.h
frameworks/base/services/core/jni/com_android_server_input_InputWindowHandle.h
frameworks/base/services/core/jni/com_android_server_input_InputManagerService.cpp
frameworks/base/services/core/jni/com_android_server_input_InputApplicationHandle.cpp
在目录frameworks/base/services/core/java/com/android/server/input中有一些service相关的java代码,如下所示。
frameworks/base/services/core/java/com/android/server/input
├── InputApplicationHandle.java
├── InputForwarder.java
├── InputManagerService.java
├── InputWindowHandle.java
├── OWNERS
└── PersistentDataStore.java
libinputservice用于光标控制,即Pointer、Sprinte,包括如下几个文件。
frameworks/base/libs/input
├── Android.bp
├── PointerController.cpp
├── PointerController.h
├── SpriteController.cpp
└── SpriteController.h
libandroid中包括一个input相关的文件,把AInputEvent中的函数作了个简单的封装,如下所示。
frameworks/base/native/android/input.cpp
int32_t AInputEvent_getType(const AInputEvent* event) {
return static_cast<const InputEvent*>(event)->getType();
}
libinput包括如下几个文件,其中有一个很重要的InputTransport,定义了Input事件的传输机制,包括InputChannel、InputMessage、InputPublisher和InputConsumer四部分。InputMessage是Input事件传输的基本单元;InputChannel用于跨进程传输InputMessage;InputPublisher用于事件派发;InputConsumer用于事件接收。
frameworks/native/include/android/input.h
frameworks/native/include/input
├── DisplayViewport.h
├── IInputFlinger.h
├── InputDevice.h
├── InputEventLabels.h
├── Input.h
├── InputTransport.h
├── Keyboard.h
├── KeyCharacterMap.h
├── KeyLayoutMap.h
├── VelocityControl.h
├── VelocityTracker.h
└── VirtualKeyMap.h
frameworks/native/libs/input
├── Android.bp
├── IInputFlinger.cpp
├── Input.cpp
├── InputDevice.cpp
├── InputTransport.cpp
├── Keyboard.cpp
├── KeyCharacterMap.cpp
├── KeyLayoutMap.cpp
├── VelocityControl.cpp
├── VelocityTracker.cpp
└── VirtualKeyMap.cpp
InputFlinger是Android Native层Input相关的核心模块,简单来说就是InputReader从EventHub中读取Input事件,然后交由InputDispatcher进行事件派发。文件目录如下。
frameworks/native/services/inputflinger
├── Android.bp
├── EventHub.cpp
├── EventHub.h
├── host
│ ├── Android.bp
│ ├── InputDriver.cpp
│ ├── InputDriver.h
│ ├── InputFlinger.cpp
│ ├── InputFlinger.h
│ ├── inputflinger.rc
│ ├── InputHost.cpp
│ ├── InputHost.h
│ └── main.cpp
├── InputApplication.cpp
├── InputApplication.h
├── InputDispatcher.cpp
├── InputDispatcher.h
├── InputListener.cpp
├── InputListener.h
├── InputManager.cpp
├── InputManager.h
├── InputReader.cpp
├── InputReader.h
├── InputWindow.cpp
├── InputWindow.h
├── PointerControllerInterface.h
evdev、hal相关,目录结构如下。
hardware/libhardware/include/hardware/input.h
hardware/libhardware/modules/input
└── evdev
├── Android.bp
├── BitUtils.cpp
├── BitUtils.h
├── EvdevModule.cpp
├── InputDevice.cpp
├── InputDevice.h
├── InputDeviceManager.cpp
├── InputDeviceManager.h
├── InputHost.cpp
├── InputHost.h
├── InputHub.cpp
├── InputHub.h
├── InputMapper.cpp
├── InputMapper.h
├── MouseInputMapper.cpp
├── MouseInputMapper.h
├── SwitchInputMapper.cpp
└── SwitchInputMapper.h
安全相关,包括如下两个文件。
system/sepolicy/private/inputflinger.te
system/sepolicy/public/inputflinger.te