Android Input System
According to the Convention, the essence of the input system is described before the android input system is studied: from a philosophical point of view, the input system is used to solve the problem of where and where to go. Input is essentially to collect user input information and place it to the target location.
Android does not input a system category in the source code category. The input system research in this chapter is a comprehensive analysis. The previous GWES analysis, especially the focus path and Window Manager Proxy of view, are the basis of this chapter's analysis, see the previous chapter on window management.
Composition of Android Input System
The input system consists of the following parts:
- 1) Background Window Management Service
- 2) Focus activity
- 3) Focus window
- 4) Focus view: used to receive keyboard messages
From the perspective of the input system, The Window Manager Service of Android solves the problem of user information input collection, while focusactvitiy, the focus window and focus view concepts are designed to solve the problem of where user input should be placed. In the entire android system, there is only one focus window, and the focus view belonging to the window is the true focus view.
In the Android system, multiple actvitiy instances are required to run simultaneously. In the implementation, each time the actvitiy into focused actvitiy (setFocusedActivity@ActivityManagerService.java) Activation Program, the activity of the main window is set to foreground window, that is, the top-level window in the system, the apptoken concept is introduced to solve the ownership problem of window objects. In this process, logically, we select an activity as the focus activity to receive system messages. In essence, the focus window of the Focus activity is the foreground window.
Changes in the focus window will change the focus view, and changes in the foreground window will also lead to changes in the focus view. The focus and optical mark concepts are used to manage the transfer of input devices and input events. The cursor is a small bitmap drawn on the screen to indicate the current input position. Keyboard input has a similar concept of input focus and keyboard input insert. Only Windows with input focus can obtain Keyboard Events. Changing the focus of a window is usually done by a special combination of buttons or a touchevent event. A window with an input focus is usually drawn with a keyboard plug-in. The existence, form, position, and control of the insert operator are completely completed by the window event processing routine.
Now we can look at the actvitiy Input System in a more macro position. We can start from the Linux driver to the end of the input box. Here I will introduce the concept of a big input system. The Android big input system includes: linux driver, Window Manager, message system, view focus path, and focus view.
Android Input System Architecture
Now we can look at the composition of the input system from the perspective of Android code analysis. This process is analyzed and processed from the code:
On the Window Manager service end
ReadEvent@com_android_server_KeyInputQueue.cpp
KeyQ@WindowMangerService.java
KeyInputQ@KeyInputeQueue.java
InputDispatcherThread@WindowMangerService.java
On the client side
IWindow@ViewRoot.Java
ViewRoot@ViewRoot.java
Keyinputq creates an independent thread inputdevicereader in windowmangerservice, uses the native function readevent to read data from the Linux driver, constructs a rawevent, and puts it in the keyq message queue.
Inputdispatcherthread reads events from keyq, finds the focus window in window manager, and uses the mclient interface recorded by the focus window to deliver events to the client. The client transmits an event based on its focus path until the event is processed.