1 <html devsite> 2 <head> 3 <title>Overview</title> 4 <meta name="project_path" value="/_project.yaml" /> 5 <meta name="book_path" value="/_book.yaml" /> 6 </head> 7 <body> 8 <!-- 9 Copyright 2017 The Android Open Source Project 10 11 Licensed under the Apache License, Version 2.0 (the "License"); 12 you may not use this file except in compliance with the License. 13 You may obtain a copy of the License at 14 15 http://www.apache.org/licenses/LICENSE-2.0 16 17 Unless required by applicable law or agreed to in writing, software 18 distributed under the License is distributed on an "AS IS" BASIS, 19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 See the License for the specific language governing permissions and 21 limitations under the License. 22 --> 23 24 25 26 <p>The Android input subsystem nominally consists of an event pipeline 27 that traverses multiple layers of the system.</p> 28 <h2 id="input-pipeline">Input Pipeline</h2> 29 <p>At the lowest layer, the physical input device produces signals that 30 describe state changes such as key presses and touch contact points. 31 The device firmware encodes and transmits these signals in some way 32 such as by sending USB HID reports to the system or by producing 33 interrupts on an I2C bus.</p> 34 <p>The signals are then decoded by a device driver in the Linux kernel. 35 The Linux kernel provides drivers for many standard peripherals, 36 particularly those that adhere to the HID protocol. However, an OEM 37 must often provide custom drivers for embedded devices that are 38 tightly integrated into the system at a low-level, such as touch screens.</p> 39 <p>The input device drivers are responsible for translating device-specific 40 signals into a standard input event format, by way of the Linux 41 input protocol. The Linux input protocol defines a standard set of 42 event types and codes in the <code>linux/input.h</code> kernel header file. 43 In this way, components outside the kernel do not need to care about 44 the details such as physical scan codes, HID usages, I2C messages, 45 GPIO pins, and the like.</p> 46 <p>Next, the Android <code>EventHub</code> component reads input events from the kernel 47 by opening the <code>evdev</code> driver associated with each input device. 48 The Android InputReader component then decodes the input events 49 according to the device class and produces a stream of Android input 50 events. As part of this process, the Linux input protocol event codes 51 are translated into Android event codes according to the 52 input device configuration, keyboard layout files, and various 53 mapping tables.</p> 54 <p>Finally, the <code>InputReader</code> sends input events to the InputDispatcher 55 which forwards them to the appropriate window.</p> 56 <h2 id="control-points">Control Points</h2> 57 <p>There are several stages in the input pipeline which effect control 58 over the behavior of the input device.</p> 59 <h3 id="driver-and-firmware-configuration">Driver and Firmware Configuration</h3> 60 <p>Input device drivers frequently configure the behavior of the input 61 device by setting parameters in registers or even uploading the 62 firmware itself. This is particularly the case for embedded 63 devices such as touch screens where a large part of the calibration 64 process involves tuning these parameters or fixing the firmware 65 to provide the desired accuracy and responsiveness and to suppress 66 noise.</p> 67 <p>Driver configuration options are often specified as module parameters 68 in the kernel board support package (BSP) so that the same driver 69 can support multiple different hardware implementations.</p> 70 <p>This documentation does attempt to describe driver or firmware 71 configuration, but it does offer guidance as to device calibration 72 in general.</p> 73 <h3 id="board-configuration-properties">Board Configuration Properties</h3> 74 <p>The kernel board support package (BSP) may export board configuration 75 properties via SysFS that are used by the Android InputReader component, 76 such as the placement of virtual keys on a touch screen.</p> 77 <p>Refer to the device class sections for details about how different 78 devices use board configuration properties.</p> 79 <h3 id="resource-overlays">Resource Overlays</h3> 80 <p>A few input behaviors are configured by way of resource overlays 81 in <code>config.xml</code> such as the operation of lid switch.</p> 82 <p>Here are a few examples:</p> 83 <ul> 84 <li> 85 <p><code>config_lidKeyboardAccessibility</code>: Specifies the effect of the 86 lid switch on whether the hardware keyboard is accessible or hidden.</p> 87 </li> 88 <li> 89 <p><code>config_lidNavigationAccessibility</code>: Specifies the effect of the 90 lid switch on whether the trackpad is accessible or hidden.</p> 91 </li> 92 <li> 93 <p><code>config_longPressOnPowerBehavior</code>: Specifies what should happen when 94 the user holds down the power button.</p> 95 </li> 96 <li> 97 <p><code>config_lidOpenRotation</code>: Specifies the effect of the lid switch 98 on screen orientation.</p> 99 </li> 100 </ul> 101 <p>Refer to the documentation within <code>frameworks/base/core/res/res/values/config.xml</code> 102 for details about each configuration option.</p> 103 <h3 id="key-maps">Key Maps</h3> 104 <p>Key maps are used by the Android <code>EventHub</code> and <code>InputReader</code> components 105 to configure the mapping from Linux event codes to Android event codes 106 for keys, joystick buttons and joystick axes. The mapping may 107 be device or language dependent.</p> 108 <p>Refer to the device class sections for details about how different 109 devices use key maps.</p> 110 <h3 id="input-device-configuration-files">Input Device Configuration Files</h3> 111 <p>Input device configuration files are used by the Android <code>EventHub</code> and 112 <code>InputReader</code> components to configure special device characteristics 113 such as how touch size information is reported.</p> 114 <p>Refer to the device class sections for details about how different 115 devices use input device configuration maps.</p> 116 <h2 id="understanding-hid-usages-and-event-codes">Understanding HID Usages and Event Codes</h2> 117 <p>There are often several different identifiers used to refer to any 118 given key on a keyboard, button on a game controller, joystick axis 119 or other control. The relationships between these identifiers 120 are not always the same: they are dependent on a set of mapping tables, 121 some of which are fixed, and some which vary based on characteristics 122 of the device, the device driver, the current locale, the system 123 configuration, user preferences and other factors.</p> 124 <dl> 125 <dt>Physical Scan Code</dt> 126 <dd> 127 <p>A physical scan code is a device-specific identifier that is associated 128 with each key, button or other control. Because physical scan codes 129 often vary from one device to another, the firmware or device driver 130 is responsible for mapping them to standard identifiers such as 131 HID Usages or Linux key codes.</p> 132 <p>Scan codes are mainly of interest for keyboards. Other devices 133 typically communicate at a low-level using GPIO pins, I2C messages 134 or other means. Consequently, the upper layers of the software 135 stack rely on the device drivers to make sense of what is going on.</p> 136 </dd> 137 <dt>HID Usage</dt> 138 <dd> 139 <p>A HID usage is a standard identifier that is used to report the 140 state of a control such as a keyboard key, joystick axis, 141 mouse button, or touch contact point. Most USB and Bluetooth 142 input devices conform to the HID specification, which enables 143 the system to interface with them in a uniform manner.</p> 144 <p>The Android Framework relies on the Linux kernel HID drivers to 145 translate HID usage codes into Linux key codes and other identifiers. 146 Therefore HID usages are mainly of interest to peripheral manufacturers.</p> 147 </dd> 148 <dt>Linux Key Code</dt> 149 <dd> 150 <p>A Linux key code is a standard identifier for a key or button. 151 Linux key codes are defined in the <code>linux/input.h</code> header file using 152 constants that begin with the prefix <code>KEY_</code> or <code>BTN_</code>. The Linux 153 kernel input drivers are responsible for translating physical 154 scan codes, HID usages and other device-specific signals into Linux 155 key codes and delivering information about them as part of 156 <code>EV_KEY</code> events.</p> 157 <p>The Android API sometimes refers to the Linux key code associated 158 with a key as its "scan code". This is technically incorrect in 159 but it helps to distinguish Linux key codes from Android key codes 160 in the API.</p> 161 </dd> 162 <dt>Linux Relative or Absolute Axis Code</dt> 163 <dd> 164 <p>A Linux relative or absolute axis code is a standard identifier 165 for reporting relative movements or absolute positions along an 166 axis, such as the relative movements of a mouse along its X axis 167 or the absolute position of a joystick along its X axis. 168 Linux axis code are defined in the <code>linux/input.h</code> header file using 169 constants that begin with the prefix <code>REL_</code> or <code>ABS_</code>. The Linux 170 kernel input drivers are responsible for translating HID usages 171 and other device-specific signals into Linux axis codes and 172 delivering information about them as part of <code>EV_REL</code> and 173 <code>EV_ABS</code> events.</p> 174 </dd> 175 <dt>Linux Switch Code</dt> 176 <dd> 177 <p>A Linux switch code is a standard identifier for reporting the 178 state of a switch on a device, such as a lid switch. Linux 179 switch codes are defined in the <code>linux/input.h</code> header file 180 using constants that begin with the prefix <code>SW_</code>. The Linux 181 kernel input drivers report switch state changes as <code>EV_SW</code> events.</p> 182 <p>Android applications generally do not receive events from switches, 183 but the system may use them internally to control various 184 device-specific functions.</p> 185 </dd> 186 <dt>Android Key Code</dt> 187 <dd> 188 <p>An Android key code is a standard identifier defined in the Android 189 API for indicating a particular key such as 'HOME'. Android key codes 190 are defined by the <code>android.view.KeyEvent</code> class as constants that 191 begin with the prefix <code>KEYCODE_</code>.</p> 192 <p>The key layout specifies how Linux key codes are mapped to Android 193 key codes. Different key layouts may be used depending on the keyboard 194 model, language, country, layout, or special functions.</p> 195 <p>Combinations of Android key codes are transformed into character codes 196 using a device and locale specific key character map. For example, 197 when the keys identified as <code>KEYCODE_SHIFT</code> and <code>KEYCODE_A</code> are both 198 pressed together, the system looks up the combination in the key 199 character map and finds the capital letter 'A', which is then inserted 200 into the currently focused text widget.</p> 201 </dd> 202 <dt>Android Axis Code</dt> 203 <dd> 204 <p>An Android axis code is a standard identifier defined in the Android 205 API for indicating a particular device axis. Android axis codes are 206 defined by the <code>android.view.MotionEvent</code> class as constants that 207 begin with the prefix <code>AXIS_</code>.</p> 208 <p>The key layout specifies how Linux Axis Codes are mapped to Android 209 axis codes. Different key layouts may be used depending on the device 210 model, language, country, layout, or special functions.</p> 211 </dd> 212 <dt>Android Meta State</dt> 213 <dd> 214 <p>An Android meta state is a standard identifier defined in the Android 215 API for indicating which modifier keys are pressed. Android meta states 216 are defined by the <code>android.view.KeyEvent</code> class as constants that 217 begin with the prefix <code>META_</code>.</p> 218 <p>The current meta state is determined by the Android InputReader 219 component which monitors when modifier keys such as <code>KEYCODE_SHIFT_LEFT</code> 220 are pressed / released and sets / resets the appropriate meta state flag.</p> 221 <p>The relationship between modifier keys and meta states is hardcoded 222 but the key layout can alter how the modifier keys themselves are 223 mapped which in turns affects the meta states.</p> 224 </dd> 225 <dt>Android Button State</dt> 226 <dd> 227 <p>An Android button state is a standard identifier defined in the Android 228 API for indicating which buttons (on a mouse or stylus) are pressed. 229 Android button states are defined by the <code>android.view.MotionEvent</code> 230 class as constants that begin with the prefix <code>BUTTON_</code>.</p> 231 <p>The current button state is determined by the Android InputReader 232 component which monitors when buttons (on a mouse or stylus) are 233 pressed / released and sets / resets appropriate button state flag.</p> 234 <p>The relationship between buttons and button states is hardcoded.</p> 235 </dd> 236 </dl> 237 <h2 id="further-reading">Further Reading</h2> 238 <ol> 239 <li><a href="http://www.kernel.org/doc/Documentation/input/event-codes.txt">Linux input event codes</a></li> 240 <li><a href="http://www.kernel.org/doc/Documentation/input/multi-touch-protocol.txt">Linux multi-touch protocol</a></li> 241 <li><a href="http://www.kernel.org/doc/Documentation/input/input.txt">Linux input drivers</a></li> 242 <li><a href="http://www.kernel.org/doc/Documentation/input/ff.txt">Linux force feedback</a></li> 243 <li><a href="http://www.usb.org/developers/hidpage">HID information, including HID usage tables</a></li> 244 </ol> 245 246 </body> 247 </html> 248