Note: This analysis was made a long time ago and used for analysis.CodeIs Android 2.1 eclair. In the latest Android 4.x, the input-related code has changed. In Android 2.1, input-related code is scattered in the/frameworks/base/libs/UI/AND/frameworks/base/service/Java/COM/Android/Server/directories. In Android 4.x, the code is centralized/Frameworks/base/services/input/
And
/Frameworks/base/services/Java/COM/Android/Server/input/. At the same time, the names and content of some files have also changed. For example, the keyinputqueue Java layer and JNI layer files in Android 2.1 are stored in Android 4. X has been replaced by inputmanager; eventhub. the content of CPP has changed. However, the following analysis still helps to study how keyboard input events in Android 4.x are converted into Android media button events. The key entry is eventhub. Starting with eventhub, you can trace Android through code analysis at the upper layer.
The input event processing process in inputmanager. You can analyze the data at the lower layer to reach the Linux input device.
In the blue is native code, while in the green is Java code. The top thread: inputdevicereader is the control center of the entire input process (in Android 4. x, this thread is in inputmanager. cpp ). This thread reads the input devices in the/dev/input directory of Linux Through eventhub: getevent () to obtain the hardware key input. Based on a key layout map associated with each input device, the key input is mapped to a key that can be recognized by Android.
Code. For example, if the key input value of an avrcp input device is 200, It is mapped to media_play.
Note that before eventhub: getevnet () reads input devices, you must determine whether the devices has been enabled. If not, call eventhub: openplatforminput () to scan devices in/dev/input, open these devices and load their respective key layout map (/frameworks/base/data/keyboards *. the KL file is used to define the key layout map, where avrcp. KL defines the Bluetooth avrcp Input
The key layout map of the device. In the root Fs of Android device, these. KL files are stored in the/system/usr/keylayout/directory ). The file descriptor and device_t pointers of these opened devices are stored in MFDs and mdevices respectively.
After the inputdevicereader thread obtains the key code, it is handed over to the Java-Layer Code for processing. Finally, an action_media_button intent is created by interceptkeytq () in phonewindowmanager. Java to broadcast. (In Android 4.x, the last step of broadcasting the media button is also implemented in phonewindowmanager. Java by interceptkeybeforequeueing. Interceptkeybeforequeueing () is android
Interceptkeytq ().) In 2.1 ().)
Finally, let's talk about the function call process for creating acrcp input device. In/external/Bluetooth/bluz/Audio/control. C, avctp_connect_cb ()-> init_uinput ()-> uinput_create (). Note that this creation process is only applicable to versions earlier than Android 4.2. From Android 4.2, Android replaced bluez with Bluetooth stack of Broadcom.