At the bottom
Linux driver
To set
Input
Event, after
Input_report_abs (Dev, the event you set (such as abs_y), the value to be uploaded); then synchronize input_sync (Dev );
Linux driver and above:
Windowmanagerservice
Class Constructor
Windowmanagerservice ()
There is a sentence:
Mqueue = new keyq ();
However
Private class keyq extends keyinputqueue
In
Keyinputqueue
Created
Inputdevicereader
Thread
Thread mthread = new thread ("inputdevicereader ")
Inputdevicereader
Read events from devices.
Code:
Thread mthread = new thread ("inputdevicereader "){
Public void run ()
{
Call in a loop:
Readevent (EV );
...
Send = preprocessevent (Di, Ev );
Actually called is
Keyq
Class
Preprocessevent
Function
...
Int keycode = rotatekeycodelocked (EV. keycode );
Int [] map = mkeyrotationmap;
For (INT I = 0; I <n; I + = 2)
{
If (Map [I] = keycode)
Return map [I + 1];
}//
Addlocked (Di, curtime,
Ev. Flags, rawinputevent. class_keyboard, newkeyevent (Di, Di. mdowntime,
Curtime, down, keycode, 0, scancode ,...));
Queuedevent EV = obtainlocked (device, when, flags, classtype, event );
}
}
Readevent ()
Actually
Com_android_server_keyinputqueue.cpp (frameworks/base/services/JNI)
In:
Static jboolean android_server_keyinputqueue_readevent (jnienv * ENV, jobject clazz, jobject event)
Bool res = hub-> getevent (& DeviceID, & type, & scancode, & keycode, & flags, & Value, & When );
Yes
Eventhub. cpp (frameworks/base/libs/UI)
In:
Bool eventhub: getevent (int32_t * outdeviceid, int32_t * outtype,
Int32_t * outscancode, int32_t * outkeycode, uint32_t * outflags,
Int32_t * outvalue, nsecs_t * outwhen)
The Read Device operation is called in the function:
Res = read (MFDs [I]. FD, & IEV, sizeof (IEV ));
Eventhub
:
The event is passed in from
Eventhub
Starting from,
Eventhub
Is the abstract structure of events, maintaining the running status of system devices. The device types include
Keyboard
,
Touchscreen
,
Traceball
. It passes
Open_device
Method: add the input devices provided by the system to this abstract structure and maintain a file descriptor for all input devices. If the input device is a keyboard, it will read
/System/usr/keylayout/
The ing file corresponding to the keyboard device in the directory.
Getevent
The method is
Eventhub
Use the device file descriptor in
Poll
The operation occurs at the driver layer. If the event is a keyboard event, it is called.
Map
The function converts the ing file to the corresponding key value and returns the scan code and key code
Keyinputqueue
.
Keylayoutmap
It mainly reads the keyboard ing file and converts the Keyboard Scan code and key code.
Frameworks/base/CORE/JNI/Server/com_android_server_keyinputqueue.cpp
Eventhub
And
Keyinputqueue
Of
JNI
Interface Layer
Keyinputqueue
:
In the thread
Inputdevicereader
The system determines whether the device status of the event has changed and the description structure of the device.
Inputdevice
.
Getevent
: Check whether any event occurs during the specified time period. If yes, return
True
Otherwise
False
.
Windowmanager
:
(Frameworks/base/services/Java/COM/Android/Server/windowmanagerservice. Java)
Process
Windowmanager
Creates a thread (
Inputdispatcherthread
), Read the events from the event queue in this thread (
Queuedevent EV = mqueue. getevent
(), And is divided into three types based on the types of events read (
Keyboard
,
Touchscreen
,
Trackball
).
Dispatchkey (keyevent) eV. event, 0, 0)
To pass the event
Binder
Send to the window application with focus, and then call
Mqueue. recycleevent (EV)
Continue the occurrence of the waiting for keyboard event
;
If it is a touch screen event, call
Dispatchpointer (EV, (motionevent) eV. event, 0, 0)
According to the event type (
Up
,
Down
,
Move
,
Out_side
), Such
Cancel
Or send the event to a specified window with permissions.
;
In
Eventhub. cpp
Member
Getevent
In
Pollres = poll (MFDs, mfdcount,-1 );
Always in
Poll
Event status. When there is no new event input, it stops in this function. When a new event is returned, a value is returned
Pollres
And then execute the READ function.
Res = read (MFDs [I]. FD, & IEV, sizeof (IEV ));
Read events.