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