blob: e7c909ab3fa8a807d09a462449c758fed3e06049 [file] [log] [blame]
Robert Ly35f2fda2013-01-29 16:27:05 -08001page.title=Touch Devices
2@jd:body
3
4<!--
5 Copyright 2010 The Android Open Source Project
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-->
19<p>Android supports a variety of touch screens and touch pads, including
20stylus-based digitizer tablets.</p>
21<p>Touch screens are touch devices that are associated with a display such that
22the user has the impression of directly manipulating items on screen.</p>
23<p>Touch pads are touch devices that are not associated with a display such as a
24digitizer tablet. Touch pads are typically used for pointing or for
25absolute indirect positioning or gesture-based control of a user interface.</p>
26<p>Touch devices may have buttons whose functions are similar to mouse buttons.</p>
27<p>Touch devices can sometimes be manipulated using a variety of different tools
28such as fingers or a stylus depending on the underlying touch sensor technology.</p>
29<p>Touch devices are sometimes used to implement virtual keys. For example, on
30some Android devices, the touch screen sensor area extends beyond the edge of
31the display and serves dual purpose as part of a touch sensitive key pad.</p>
32<p>Due to the great variety of touch devices, Android relies on a large number of
33configuration properties to describe the characteristics and desired behavior
34of each device.</p>
35<h2 id="touch-device-classification">Touch Device Classification</h2>
36<p>An input device is classified as a <em>multi-touch</em> device if both of
37the following conditions hold:</p>
38<ul>
39<li>
40<p>The input device reports the presence of the <code>ABS_MT_POSITION_X</code> and
41 <code>ABS_MT_POSITION_Y</code> absolute axes.</p>
42</li>
43<li>
44<p>The input device does not have any gamepad buttons. This condition
45 resolves an ambiguity with certain gamepads that report axes with codes
46 that overlaps those of the MT axes.</p>
47</li>
48</ul>
49<p>An input device is classified as a <em>single-touch</em> device if both of the
50following conditions hold:</p>
51<ul>
52<li>
53<p>The input device is not classified as a multi-touch device. An input device
54 is either classified as a single-touch device or as a multi-touch device,
55 never both.</p>
56</li>
57<li>
58<p>The input device reports the presence of the <code>ABS_X</code> and <code>ABS_Y</code> absolute
59 axes, and the presence of the <code>BTN_TOUCH</code> key code.</p>
60</li>
61</ul>
62<p>Once an input device has been classified as a touch device, the presence
63of virtual keys is determined by attempting to load the virtual key map file
64for the device. If a virtual key map is available, then the key layout
65file for the device is also loaded.</p>
66<p>Refer to the section below about the location and format of virtual key map
67files.</p>
68<p>Next, the system loads the input device configuration file for the touch device.</p>
69<p><strong>All built-in touch devices should have input device configuration files.</strong>
70If no input device configuration file is present, the system will
71choose a default configuration that is appropriate for typical general-purpose
72touch peripherals such as external USB or Bluetooth HID touch screens
73or touch pads. These defaults are not designed for built-in touch screens and
74will most likely result in incorrect behavior.</p>
75<p>After the input device configuration loaded, the system will classify the
76input device as a <em>touch screen</em>, <em>touch pad</em> or <em>pointer</em> device.</p>
77<ul>
78<li>
79<p>A <em>touch screen</em> device is used for direct manipulation of objects on the
80 screen. Since the user is directly touching the screen, the system does
81 not require any additional affordances to indicate the objects being
82 manipulated.</p>
83</li>
84<li>
85<p>A <em>touch pad</em> device is used to provide absolute positioning information
86 to an application about touches on a given sensor area. It may be useful
87 for digitizer tablets.</p>
88</li>
89<li>
90<p>A <em>pointer</em> device is used for indirect manipulation of objects on the
91 screen using a cursor. Fingers are interpreted as multi-touch pointer
92 gestures. Other tools, such as styluses, are interpreted using
93 absolute positions.</p>
94<p>See <a href="#indirect-multi-touch-pointer-gestures">Indirect Multi-touch Pointer Gestures</a>
95for more information.</p>
96</li>
97</ul>
98<p>The following rules are used to classify the input device as a <em>touch screen</em>,
99<em>touch pad</em> or <em>pointer</em> device.</p>
100<ul>
101<li>
102<p>If the <code>touch.deviceType</code> property is set, then the device type will be
103 set as indicated.</p>
104</li>
105<li>
106<p>If the input device reports the presence of the <code>INPUT_PROP_DIRECT</code>
107 input property (via the <code>EVIOCGPROP</code> ioctl), then the device type will
108 be set to <em>touch screen</em>. This condition assumes that direct input touch
109 devices are attached to a display that is also connected.</p>
110</li>
111<li>
112<p>If the input device reports the presence of the <code>INPUT_PROP_POINTER</code>
113 input property (via the <code>EVIOCGPROP</code> ioctl), then the device type will
114 be set to <em>pointer</em>.</p>
115</li>
116<li>
117<p>If the input device reports the presence of the <code>REL_X</code> or <code>REL_Y</code> relative
118 axes, then the device type will be set to <em>touch pad</em>. This condition
119 resolves an ambiguity for input devices that consist of both a mouse and
120 a touch pad. In this case, the touch pad will not be used to control
121 the pointer because the mouse already controls it.</p>
122</li>
123<li>
124<p>Otherwise, the device type will be set to <em>pointer</em>. This default ensures
125 that touch pads that have not been designated any other special purpose
126 will serve to control the pointer.</p>
127</li>
128</ul>
129<h2 id="buttons">Buttons</h2>
130<p>Buttons are <em>optional</em> controls that may be used by applications to perform
131additional functions. Buttons on touch devices behave similarly to mouse
132buttons and are mainly of use with <em>pointer</em> type touch devices or with a
133stylus.</p>
134<p>The following buttons are supported:</p>
135<ul>
136<li>
137<p><code>BTN_LEFT</code>: mapped to <code>MotionEvent.BUTTON_PRIMARY</code>.</p>
138</li>
139<li>
140<p><code>BTN_RIGHT</code>: mapped to <code>MotionEvent.BUTTON_SECONDARY</code>.</p>
141</li>
142<li>
143<p><code>BTN_MIDDLE</code>: mapped to <code>MotionEvent.BUTTON_MIDDLE</code>.</p>
144</li>
145<li>
146<p><code>BTN_BACK</code> and <code>BTN_SIDE</code>: mapped to <code>MotionEvent.BUTTON_BACK</code>.
147 Pressing this button also synthesizes a key press with the key code
148 <code>KeyEvent.KEYCODE_BACK</code>.</p>
149</li>
150<li>
151<p><code>BTN_FORWARD</code> and <code>BTN_EXTRA</code>: mapped to <code>MotionEvent.BUTTON_FORWARD</code>.
152 Pressing this button also synthesizes a key press with the key code
153 <code>KeyEvent.KEYCODE_FORWARD</code>.</p>
154</li>
155<li>
156<p><code>BTN_STYLUS</code>: mapped to <code>MotionEvent.BUTTON_SECONDARY</code>.</p>
157</li>
158<li>
159<p><code>BTN_STYLUS2</code>: mapped to <code>MotionEvent.BUTTON_TERTIARY</code>.</p>
160</li>
161</ul>
162<h2 id="tools-and-tool-types">Tools and Tool Types</h2>
163<p>A <em>tool</em> is a finger, stylus or other apparatus that is used to interact with
164the touch device. Some touch devices can distinguish between different
165types of tools.</p>
166<p>Elsewhere in Android, as in the <code>MotionEvent</code> API, a <em>tool</em> is often referred
167to as a <em>pointer</em>.</p>
168<p>The following tool types are supported:</p>
169<ul>
170<li>
171<p><code>BTN_TOOL_FINGER</code> and <code>MT_TOOL_FINGER</code>: mapped to <code>MotionEvent.TOOL_TYPE_FINGER</code>.</p>
172</li>
173<li>
174<p><code>BTN_TOOL_PEN</code> and <code>MT_TOOL_PEN</code>: mapped to <code>MotionEvent.TOOL_TYPE_STYLUS</code>.</p>
175</li>
176<li>
177<p><code>BTN_TOOL_RUBBER</code>: mapped to <code>MotionEvent.TOOL_TYPE_ERASER</code>.</p>
178</li>
179<li>
180<p><code>BTN_TOOL_BRUSH</code>: mapped to <code>MotionEvent.TOOL_TYPE_STYLUS</code>.</p>
181</li>
182<li>
183<p><code>BTN_TOOL_PENCIL</code>: mapped to <code>MotionEvent.TOOL_TYPE_STYLUS</code>.</p>
184</li>
185<li>
186<p><code>BTN_TOOL_AIRBRUSH</code>: mapped to <code>MotionEvent.TOOL_TYPE_STYLUS</code>.</p>
187</li>
188<li>
189<p><code>BTN_TOOL_MOUSE</code>: mapped to <code>MotionEvent.TOOL_TYPE_MOUSE</code>.</p>
190</li>
191<li>
192<p><code>BTN_TOOL_LENS</code>: mapped to <code>MotionEvent.TOOL_TYPE_MOUSE</code>.</p>
193</li>
194<li>
195<p><code>BTN_TOOL_DOUBLETAP</code>, <code>BTN_TOOL_TRIPLETAP</code>, and <code>BTN_TOOL_QUADTAP</code>:
196 mapped to <code>MotionEvent.TOOL_TYPE_FINGER</code>.</p>
197</li>
198</ul>
199<h2 id="hovering-vs-touching-tools">Hovering vs. Touching Tools</h2>
200<p>Tools can either be in contact with the touch device or in range and hovering
201above it. Not all touch devices are able to sense the presence of a tool
202hovering above the touch device. Those that do, such as RF-based stylus digitizers,
203can often detect when the tool is within a limited range of the digitizer.</p>
204<p>The <code>InputReader</code> component takes care to distinguish touching tools from hovering
205tools. Likewise, touching tools and hovering tools are reported to applications
206in different ways.</p>
207<p>Touching tools are reported to applications as touch events
208using <code>MotionEvent.ACTION_DOWN</code>, <code>MotionEvent.ACTION_MOVE</code>, <code>MotionEvent.ACTION_DOWN</code>,
209<code>MotionEvent.ACTION_POINTER_DOWN</code> and <code>MotionEvent.ACTION_POINTER_UP</code>.</p>
210<p>Hovering tools are reported to applications as generic motion events using
211<code>MotionEvent.ACTION_HOVER_ENTER</code>, <code>MotionEvent.ACTION_HOVER_MOVE</code>
212and <code>MotionEvent.ACTION_HOVER_EXIT</code>.</p>
213<h2 id="touch-device-driver-requirements">Touch Device Driver Requirements</h2>
214<ol>
215<li>
216<p>Touch device drivers should only register axes and key codes for the axes
217 and buttons that they actually support. Registering excess axes or key codes
218 may confuse the device classification algorithm or cause the system to incorrectly
219 detect the capabilities of the device.</p>
220<p>For example, if the device reports the <code>BTN_TOUCH</code> key code, the system will
221assume that <code>BTN_TOUCH</code> will always be used to indicate whether the tool is
222actually touching the screen or is merely in range and hovering.</p>
223</li>
224<li>
225<p>Single-touch devices use the following Linux input events:</p>
226<ul>
227<li>
228<p><code>ABS_X</code>: <em>(REQUIRED)</em> Reports the X coordinate of the tool.</p>
229</li>
230<li>
231<p><code>ABS_Y</code>: <em>(REQUIRED)</em> Reports the Y coordinate of the tool.</p>
232</li>
233<li>
234<p><code>ABS_PRESSURE</code>: <em>(optional)</em> Reports the physical pressure applied to the tip
235 of the tool or the signal strength of the touch contact.</p>
236</li>
237<li>
238<p><code>ABS_TOOL_WIDTH</code>: <em>(optional)</em> Reports the cross-sectional area or width of the
239 touch contact or of the tool itself.</p>
240</li>
241<li>
242<p><code>ABS_DISTANCE</code>: <em>(optional)</em> Reports the distance of the tool from the surface of
243 the touch device.</p>
244</li>
245<li>
246<p><code>ABS_TILT_X</code>: <em>(optional)</em> Reports the tilt of the tool from the surface of the
247 touch device along the X axis.</p>
248</li>
249<li>
250<p><code>ABS_TILT_Y</code>: <em>(optional)</em> Reports the tilt of the tool from the surface of the
251 touch device along the Y axis.</p>
252</li>
253<li>
254<p><code>BTN_TOUCH</code>: <em>(REQUIRED)</em> Indicates whether the tool is touching the device.</p>
255</li>
256<li>
257<p><code>BTN_LEFT</code>, <code>BTN_RIGHT</code>, <code>BTN_MIDDLE</code>, <code>BTN_BACK</code>, <code>BTN_SIDE</code>, <code>BTN_FORWARD</code>,
258 <code>BTN_EXTRA</code>, <code>BTN_STYLUS</code>, <code>BTN_STYLUS2</code>:
259 <em>(optional)</em> Reports <a href="#buttons">button</a> states.</p>
260</li>
261<li>
262<p><code>BTN_TOOL_FINGER</code>, <code>BTN_TOOL_PEN</code>, <code>BTN_TOOL_RUBBER</code>, <code>BTN_TOOL_BRUSH</code>,
263 <code>BTN_TOOL_PENCIL</code>, <code>BTN_TOOL_AIRBRUSH</code>, <code>BTN_TOOL_MOUSE</code>, <code>BTN_TOOL_LENS</code>,
264 <code>BTN_TOOL_DOUBLETAP</code>, <code>BTN_TOOL_TRIPLETAP</code>, <code>BTN_TOOL_QUADTAP</code>:
265 <em>(optional)</em> Reports the <a href="#tools-and-tool-types">tool type</a>.</p>
266</li>
267</ul>
268</li>
269<li>
270<p>Multi-touch devices use the following Linux input events:</p>
271<ul>
272<li>
273<p><code>ABS_MT_POSITION_X</code>: <em>(REQUIRED)</em> Reports the X coordinate of the tool.</p>
274</li>
275<li>
276<p><code>ABS_MT_POSITION_Y</code>: <em>(REQUIRED)</em> Reports the Y coordinate of the tool.</p>
277</li>
278<li>
279<p><code>ABS_MT_PRESSURE</code>: <em>(optional)</em> Reports the physical pressure applied to the
280 tip of the tool or the signal strength of the touch contact.</p>
281</li>
282<li>
283<p><code>ABS_MT_TOUCH_MAJOR</code>: <em>(optional)</em> Reports the cross-sectional area of the
284 touch contact, or the length of the longer dimension of the touch contact.</p>
285</li>
286<li>
287<p><code>ABS_MT_TOUCH_MINOR</code>: <em>(optional)</em> Reports the length of the shorter dimension of the
288 touch contact. This axis should not be used if <code>ABS_MT_TOUCH_MAJOR</code> is reporting an
289 area measurement.</p>
290</li>
291<li>
292<p><code>ABS_MT_WIDTH_MAJOR</code>: <em>(optional)</em> Reports the cross-sectional area of the tool itself,
293 or the length of the longer dimension of the tool itself.
294 This axis should not be used if the dimensions of the tool itself are unknown.</p>
295</li>
296<li>
297<p><code>ABS_MT_WIDTH_MINOR</code>: <em>(optional)</em> Reports the length of the shorter dimension of
298 the tool itself. This axis should not be used if <code>ABS_MT_WIDTH_MAJOR</code> is reporting
299 an area measurement or if the dimensions of the tool itself are unknown.</p>
300</li>
301<li>
302<p><code>ABS_MT_ORIENTATION</code>: <em>(optional)</em> Reports the orientation of the tool.</p>
303</li>
304<li>
305<p><code>ABS_MT_DISTANCE</code>: <em>(optional)</em> Reports the distance of the tool from the
306 surface of the touch device.</p>
307</li>
308<li>
309<p><code>ABS_MT_TOOL_TYPE</code>: <em>(optional)</em> Reports the <a href="#tools-and-tool-types">tool type</a> as
310 <code>MT_TOOL_FINGER</code> or <code>MT_TOOL_PEN</code>.</p>
311</li>
312<li>
313<p><code>ABS_MT_TRACKING_ID</code>: <em>(optional)</em> Reports the tracking id of the tool.
314 The tracking id is an arbitrary non-negative integer that is used to identify
315 and track each tool independently when multiple tools are active. For example,
316 when multiple fingers are touching the device, each finger should be assigned a distinct
317 tracking id that is used as long as the finger remains in contact. Tracking ids
318 may be reused when their associated tools move out of range.</p>
319</li>
320<li>
321<p><code>ABS_MT_SLOT</code>: <em>(optional)</em> Reports the slot id of the tool, when using the Linux
322 multi-touch protocol 'B'. Refer to the Linux multi-touch protocol documentation
323 for more details.</p>
324</li>
325<li>
326<p><code>BTN_TOUCH</code>: <em>(REQUIRED)</em> Indicates whether the tool is touching the device.</p>
327</li>
328<li>
329<p><code>BTN_LEFT</code>, <code>BTN_RIGHT</code>, <code>BTN_MIDDLE</code>, <code>BTN_BACK</code>, <code>BTN_SIDE</code>, <code>BTN_FORWARD</code>,
330 <code>BTN_EXTRA</code>, <code>BTN_STYLUS</code>, <code>BTN_STYLUS2</code>:
331 <em>(optional)</em> Reports <a href="#buttons">button</a> states.</p>
332</li>
333<li>
334<p><code>BTN_TOOL_FINGER</code>, <code>BTN_TOOL_PEN</code>, <code>BTN_TOOL_RUBBER</code>, <code>BTN_TOOL_BRUSH</code>,
335 <code>BTN_TOOL_PENCIL</code>, <code>BTN_TOOL_AIRBRUSH</code>, <code>BTN_TOOL_MOUSE</code>, <code>BTN_TOOL_LENS</code>,
336 <code>BTN_TOOL_DOUBLETAP</code>, <code>BTN_TOOL_TRIPLETAP</code>, <code>BTN_TOOL_QUADTAP</code>:
337 <em>(optional)</em> Reports the <a href="#tools-and-tool-types">tool type</a>.</p>
338</li>
339</ul>
340</li>
341<li>
342<p>If axes for both the single-touch and multi-touch protocol are defined, then
343 only the multi-touch axes will be used and the single-touch axes will be ignored.</p>
344</li>
345<li>
346<p>The minimum and maximum values of the <code>ABS_X</code>, <code>ABS_Y</code>, <code>ABS_MT_POSITION_X</code>
347 and <code>ABS_MT_POSITION_Y</code> axes define the bounds of the active area of the device
348 in device-specific surface units. In the case of a touch screen, the active area
349 describes the part of the touch device that actually covers the display.</p>
350<p>For a touch screen, the system automatically interpolates the reported touch
351positions in surface units to obtain touch positions in display pixels according
352to the following calculation:</p>
353<pre><code>displayX = (x - minX) * displayWidth / (maxX - minX + 1)
354displayY = (y - minY) * displayHeight / (maxY - minY + 1)
355</code></pre>
356<p>A touch screen may report touches outside of the reported active area.</p>
357<p>Touches that are initiated outside the active area are not delivered to applications
358but may be used for virtual keys.</p>
359<p>Touches that are initiated inside the active area, or that enter and exit the display
360area are delivered to applications. Consequently, if a touch starts within the
361bounds of an application and then moves outside of the active area, the application
362may receive touch events with display coordinates that are negative or beyond the
363bounds of the display. This is expected behavior.</p>
364<p>A touch device should never clamp touch coordinates to the bounds of the active
365area. If a touch exits the active area, it should be reported as being outside of
366the active area, or it should not be reported at all.</p>
367<p>For example, if the user's finger is touching near the top-left corner of the
368touch screen, it may report a coordinate of (minX, minY). If the finger continues
369to move further outside of the active area, the touch screen should either start
370reporting coordinates with components less than minX and minY, such as
371(minX - 2, minY - 3), or it should stop reporting the touch altogether.
372In other words, the touch screen should <em>not</em> be reporting (minX, minY)
373when the user's finger is really touching outside of the active area.</p>
374<p>Clamping touch coordinates to the display edge creates an artificial
375hard boundary around the edge of the screen which prevents the system from
376smoothly tracking motions that enter or exit the bounds of the display area.</p>
377</li>
378<li>
379<p>The values reported by <code>ABS_PRESSURE</code> or <code>ABS_MT_PRESSURE</code>, if they
380 are reported at all, must be non-zero when the tool is touching the device
381 and zero otherwise to indicate that the tool is hovering.</p>
382<p>Reporting pressure information is <em>optional</em> but strongly recommended.
383Applications can use pressure information to implement pressure-sensitive drawing
384and other effects.</p>
385</li>
386<li>
387<p>The values reported by <code>ABS_TOOL_WIDTH</code>, <code>ABS_MT_TOUCH_MAJOR</code>, <code>ABS_MT_TOUCH_MINOR</code>,
388 <code>ABS_MT_WIDTH_MAJOR</code>, or <code>ABS_MT_WIDTH_MINOR</code> should be non-zero when the tool
389 is touching the device and zero otherwise, but this is not required.
390 For example, the touch device may be able to measure the size of finger touch
391 contacts but not stylus touch contacts.</p>
392<p>Reporting size information is <em>optional</em> but strongly recommended.
393Applications can use pressure information to implement size-sensitive drawing
394and other effects.</p>
395</li>
396<li>
397<p>The values reported by <code>ABS_DISTANCE</code> or <code>ABS_MT_DISTANCE</code> should approach
398 zero when the tool is touching the device. The distance may remain non-zero
399 even when the tool is in direct contact. The exact values reported depend
400 on the manner in which the hardware measures distance.</p>
401<p>Reporting distance information is <em>optional</em> but recommended for
402stylus devices.</p>
403</li>
404<li>
405<p>The values reported by <code>ABS_TILT_X</code> and <code>ABS_TILT_Y</code> should be zero when the
406 tool is perpendicular to the device. A non-zero tilt is taken as an indication
407 that the tool is held at an incline.</p>
408<p>The tilt angles along the X and Y axes are assumed to be specified in degrees
409from perpendicular. The center point (perfectly perpendicular) is given
410by <code>(max + min) / 2</code> for each axis. Values smaller than the center point
411represent a tilt up or to the left, values larger than the center point
412represent a tilt down or to the right.</p>
413<p>The <code>InputReader</code> converts the X and Y tilt components into a perpendicular
414tilt angle ranging from 0 to <code>PI / 2</code> radians and a planar orientation angle
415ranging from <code>-PI</code> to <code>PI</code> radians. This representation results in a
416description of orientation that is compatible with what is used to describe
417finger touches.</p>
418<p>Reporting tilt information is <em>optional</em> but recommended for stylus devices.</p>
419</li>
420<li>
421<p>If the tool type is reported by <code>ABS_MT_TOOL_TYPE</code>, it will supercede any tool
422 type information reported by <code>BTN_TOOL_*</code>.
423 If no tool type information is available at all, the tool type defaults to
424 <code>MotionEvent.TOOL_TYPE_FINGER</code>.</p>
425</li>
426<li>
427<p>A tool is determined to be active based on the following conditions:</p>
428<ul>
429<li>
430<p>When using the single-touch protocol, the tool is active if <code>BTN_TOUCH</code>,
431 or <code>BTN_TOOL_*</code> is 1.</p>
432<p>This condition implies that the <code>InputReader</code> needs to have at least some
433information about the nature of the tool, either whether it is touching,
434or at least its tool type. If no information is available,
435then the tool is assumed to be inactive (out of range).</p>
436</li>
437<li>
438<p>When using the multi-touch protocol 'A', the tool is active whenever it
439 appears in the most recent sync report. When the tool stops appearing in
440 sync reports, it ceases to exist.</p>
441</li>
442<li>
443<p>When using the multi-touch protocol 'B', the tool is active as long as
444 it has an active slot. When the slot it cleared, the tool ceases to exist.</p>
445</li>
446</ul>
447</li>
448<li>
449<p>A tool is determined to be hovering based on the following conditions:</p>
450<ul>
451<li>
452<p>If the tool is <code>BTN_TOOL_MOUSE</code> or <code>BTN_TOOL_LENS</code>, then the tool
453 is not hovering, even if either of the following conditions are true.</p>
454</li>
455<li>
456<p>If the tool is active and the driver reports pressure information,
457 and the reported pressure is zero, then the tool is hovering.</p>
458</li>
459<li>
460<p>If the tool is active and the driver supports the <code>BTN_TOUCH</code> key code and
461 <code>BTN_TOUCH</code> has a value of zero, then the tool is hovering.</p>
462</li>
463</ul>
464</li>
465<li>
466<p>The <code>InputReader</code> supports both multi-touch protocol 'A' and 'B'. New drivers
467 should use the 'B' protocol but either will work.</p>
468</li>
469<li>
470<p><strong>As of Android Ice Cream Sandwich 4.0, touch screen drivers may need to be changed
471 to comply with the Linux input protocol specification.</strong></p>
472<p>The following changes may be required:</p>
473<ul>
474<li>
475<p>When a tool becomes inactive (finger goes "up"), it should stop appearing
476 in subsequent multi-touch sync reports. When all tools become inactive
477 (all fingers go "up"), the driver should send an empty sync report packet,
478 such as <code>SYN_MT_REPORT</code> followed by <code>SYN_REPORT</code>.</p>
479<p>Previous versions of Android expected "up" events to be reported by sending
480a pressure value of 0. The old behavior was incompatible with the
481Linux input protocol specification and is no longer supported.</p>
482</li>
483<li>
484<p>Physical pressure or signal strength information should be reported using
485 <code>ABS_MT_PRESSURE</code>.</p>
486<p>Previous versions of Android retrieved pressure information from
487<code>ABS_MT_TOUCH_MAJOR</code>. The old behavior was incompatible with the
488Linux input protocol specification and is no longer supported.</p>
489</li>
490<li>
491<p>Touch size information should be reported using <code>ABS_MT_TOUCH_MAJOR</code>.</p>
492<p>Previous versions of Android retrieved size information from
493<code>ABS_MT_TOOL_MAJOR</code>. The old behavior was incompatible with the
494Linux input protocol specification and is no longer supported.</p>
495</li>
496</ul>
497<p>Touch device drivers no longer need Android-specific customizations.
498By relying on the standard Linux input protocol, Android can support a
499wider variety of touch peripherals, such as external HID multi-touch
500touch screens, using unmodified drivers.</p>
501</li>
502</ol>
503<h2 id="touch-device-operation">Touch Device Operation</h2>
504<p>The following is a brief summary of the touch device operation on Android.</p>
505<ol>
506<li>
507<p>The <code>EventHub</code> reads raw events from the <code>evdev</code> driver.</p>
508</li>
509<li>
510<p>The <code>InputReader</code> consumes the raw events and updates internal state about
511 the position and other characteristics of each tool. It also tracks
512 button states.</p>
513</li>
514<li>
515<p>If the BACK or FORWARD buttons were pressed or released, the <code>InputReader</code>
516 notifies the <code>InputDispatcher</code> about the key event.</p>
517</li>
518<li>
519<p>The <code>InputReader</code> determines whether a virtual key press occurred. If so,
520 it notifies the <code>InputDispatcher</code> about the key event.</p>
521</li>
522<li>
523<p>The <code>InputReader</code> determines whether the touch was initiated within the
524 bounds of the display. If so, it notifies the <code>InputDispatcher</code> about
525 the touch event.</p>
526</li>
527<li>
528<p>If there are no touching tools but there is at least one hovering tool,
529 the <code>InputReader</code> notifies the <code>InputDispatcher</code> about the hover event.</p>
530</li>
531<li>
532<p>If the touch device type is <em>pointer</em>, the <code>InputReader</code> performs pointer
533 gesture detection, moves the pointer and spots accordingly and notifies
534 the <code>InputDispatcher</code> about the pointer event.</p>
535</li>
536<li>
537<p>The <code>InputDispatcher</code> uses the <code>WindowManagerPolicy</code> to determine whether
538 the events should be dispatched and whether they should wake the device.
539 Then, the <code>InputDispatcher</code> delivers the events to the appropriate applications.</p>
540</li>
541</ol>
542<h2 id="touch-device-configuration">Touch Device Configuration</h2>
543<p>Touch device behavior is determined by the device's axes, buttons, input properties,
544input device configuration, virtual key map and key layout.</p>
545<p>Refer to the following sections for more details about the files that
546participate in keyboard configuration:</p>
547<ul>
Clay Murphy72bdea02013-06-18 16:44:01 -0700548<li><a href="input-device-configuration-files.html">Input Device Configuration Files</a></li>
Robert Ly35f2fda2013-01-29 16:27:05 -0800549<li><a href="#virtual-key-map-files">Virtual Key Map Files</a></li>
550</ul>
551<h3 id="properties">Properties</h3>
552<p>The system relies on many input device configuration properties to configure
553and calibrate touch device behavior.</p>
554<p>One reason for this is that the device drivers for touch devices often report
555the characteristics of touches using device-specific units.</p>
556<p>For example, many touch devices measure the touch contact area
557using an internal device-specific scale, such as the total number of
558sensor nodes that were triggered by the touch. This raw size value would
559not be meaningful applications because they would need to know about the
560physical size and other characteristics of the touch device sensor nodes.</p>
561<p>The system uses calibration parameters encoded in input device configuration
562files to decode, transform, and normalize the values reported by the touch
563device into a simpler standard representation that applications can understand.</p>
564<h3 id="documentation-conventions">Documentation Conventions</h3>
565<p>For documentation purposes, we will use the following conventions to describe
566the values used by the system during the calibration process.</p>
567<h4 id="raw-axis-values">Raw Axis Values</h4>
568<p>The following expressions denote the raw values reported by the touch
569device driver as <code>EV_ABS</code> events.</p>
570<dl>
571<dt><code>raw.x</code></dt>
572<dd>The value of the <code>ABS_X</code> or <code>ABS_MT_POSITION_X</code> axis.</dd>
573<dt><code>raw.y</code></dt>
574<dd>The value of the <code>ABS_Y</code> or <code>ABS_MT_POSITION_Y</code> axis.</dd>
575<dt><code>raw.pressure</code></dt>
576<dd>The value of the <code>ABS_PRESSURE</code> or <code>ABS_MT_PRESSURE</code> axis, or 0 if not available.</dd>
577<dt><code>raw.touchMajor</code></dt>
578<dd>The value of the <code>ABS_MT_TOUCH_MAJOR</code> axis, or 0 if not available.</dd>
579<dt><code>raw.touchMinor</code></dt>
580<dd>The value of the <code>ABS_MT_TOUCH_MINOR</code> axis, or <code>raw.touchMajor</code> if not available.</dd>
581<dt><code>raw.toolMajor</code></dt>
582<dd>The value of the <code>ABS_TOOL_WIDTH</code> or <code>ABS_MT_WIDTH_MAJOR</code> axis, or 0 if not available.</dd>
583<dt><code>raw.toolMinor</code></dt>
584<dd>The value of the <code>ABS_MT_WIDTH_MINOR</code> axis, or <code>raw.toolMajor</code> if not available.</dd>
585<dt><code>raw.orientation</code></dt>
586<dd>The value of the <code>ABS_MT_ORIENTATION</code> axis, or 0 if not available.</dd>
587<dt><code>raw.distance</code></dt>
588<dd>The value of the <code>ABS_DISTANCE</code> or <code>ABS_MT_DISTANCE</code> axis, or 0 if not available.</dd>
589<dt><code>raw.tiltX</code></dt>
590<dd>The value of the <code>ABS_TILT_X</code> axis, or 0 if not available.</dd>
591<dt><code>raw.tiltY</code></dt>
592<dd>The value of the <code>ABS_TILT_Y</code> axis, or 0 if not available.</dd>
593</dl>
594<h4 id="raw-axis-ranges">Raw Axis Ranges</h4>
595<p>The following expressions denote the bounds of raw values. They are obtained
596by calling <code>EVIOCGABS</code> ioctl for each axis.</p>
597<dl>
598<dt><code>raw.*.min</code></dt>
599<dd>The inclusive minimum value of the raw axis.</dd>
600<dt><code>raw.*.max</code></dt>
601<dd>The inclusive maximum value of the raw axis.</dd>
602<dt><code>raw.*.range</code></dt>
603<dd>Equivalent to <code>raw.*.max - raw.*.min</code>.</dd>
604<dt><code>raw.*.fuzz</code></dt>
605<dd>The accuracy of the raw axis. eg. fuzz = 1 implies values are accurate to +/- 1 unit.</dd>
606<dt><code>raw.width</code></dt>
607<dd>The inclusive width of the touch area, equivalent to <code>raw.x.range + 1</code>.</dd>
608<dt><code>raw.height</code></dt>
609<dd>The inclusive height of the touch area, equivalent to <code>raw.y.range + 1</code>.</dd>
610</dl>
611<h4 id="output-ranges">Output Ranges</h4>
612<p>The following expressions denote the characteristics of the output coordinate system.
613The system uses linear interpolation to translate touch position information from
614the surface units used by the touch device into the output units that will
615be reported to applications such as display pixels.</p>
616<dl>
617<dt><code>output.width</code></dt>
618<dd>The output width. For touch screens (associated with a display), this
619is the display width in pixels. For touch pads (not associated with a display),
620the output width equals <code>raw.width</code>, indicating that no interpolation will
621be performed.</dd>
622<dt><code>output.height</code></dt>
623<dd>The output height. For touch screens (associated with a display), this
624is the display height in pixels. For touch pads (not associated with a display),
625the output height equals <code>raw.height</code>, indicating that no interpolation will
626be performed.</dd>
627<dt><code>output.diag</code></dt>
628<dd>The diagonal length of the output coordinate system, equivalent to
629<code>sqrt(output.width ^2 + output.height ^2)</code>.</dd>
630</dl>
631<h3 id="basic-configuration">Basic Configuration</h3>
632<p>The touch input mapper uses many configuration properties in the input device
633configuration file to specify calibration values. The following table describes
634some general purpose configuration properties. All other properties are described
635in the following sections along with the fields they are used to calibrate.</p>
636<h4 id="touchdevicetype"><code>touch.deviceType</code></h4>
637<p><em>Definition:</em> <code>touch.deviceType</code> = <code>touchScreen</code> | <code>touchPad</code> | <code>pointer</code> | <code>default</code></p>
638<p>Specifies the touch device type.</p>
639<ul>
640<li>
641<p>If the value is <code>touchScreen</code>, the touch device is a touch screen associated
642 with a display.</p>
643</li>
644<li>
645<p>If the value is <code>touchPad</code>, the touch device is a touch pad not associated
646 with a display.</p>
647</li>
648<li>
649<p>If the value is <code>pointer</code>, the touch device is a touch pad not associated
650 with a display, and its motions are used for
651 <a href="#indirect-multi-touch-pointer-gestures">indirect multi-touch pointer gestures</a>.</p>
652</li>
653<li>
654<p>If the value is <code>default</code>, the system automatically detects the device type
655 according to the classification algorithm.</p>
656</li>
657</ul>
658<p>Refer to the <a href="#touch-device-classification">Classification</a> section for more details
659about how the device type influences the behavior of the touch device.</p>
660<p>Prior to Honeycomb, all touch devices were assumed to be touch screens.</p>
661<h4 id="touchorientationaware"><code>touch.orientationAware</code></h4>
662<p><em>Definition:</em> <code>touch.orientationAware</code> = <code>0</code> | <code>1</code></p>
663<p>Specifies whether the touch device should react to display orientation changes.</p>
664<ul>
665<li>
666<p>If the value is <code>1</code>, touch positions reported by the touch device are rotated
667 whenever the display orientation changes.</p>
668</li>
669<li>
670<p>If the value is <code>0</code>, touch positions reported by the touch device are immune
671 to display orientation changes.</p>
672</li>
673</ul>
674<p>The default value is <code>1</code> if the device is a touch screen, <code>0</code> otherwise.</p>
675<p>The system distinguishes between internal and external touch screens and displays.
676An orientation aware internal touch screen is rotated based on the orientation
677of the internal display. An orientation aware external touch screen is rotated
678based on the orientation of the external display.</p>
679<p>Orientation awareness is used to support rotation of touch screens on devices
680like the Nexus One. For example, when the device is rotated clockwise 90 degrees
681from its natural orientation, the absolute positions of touches are remapped such
682that a touch in the top-left corner of the touch screen's absolute coordinate system
683is reported as a touch in the top-left corner of the display's rotated coordinate system.
684This is done so that touches are reported with the same coordinate system that
685applications use to draw their visual elements.</p>
686<p>Prior to Honeycomb, all touch devices were assumed to be orientation aware.</p>
687<h4 id="touchgesturemode"><code>touch.gestureMode</code></h4>
688<p><em>Definition:</em> <code>touch.gestureMode</code> = <code>pointer</code> | <code>spots</code> | <code>default</code></p>
689<p>Specifies the presentation mode for pointer gestures. This configuration property
690is only relevant when the touch device is of type <em>pointer</em>.</p>
691<ul>
692<li>
693<p>If the value is <code>pointer</code>, the touch pad gestures are presented by way of a cursor
694 similar to a mouse pointer.</p>
695</li>
696<li>
697<p>If the value is <code>spots</code>, the touch pad gestures are presented by an anchor
698 that represents the centroid of the gesture and a set of circular spots
699 that represent the position of individual fingers.</p>
700</li>
701</ul>
702<p>The default value is <code>pointer</code> when the <code>INPUT_PROP_SEMI_MT</code> input property
703is set, or <code>spots</code> otherwise.</p>
704<h3 id="x-and-y-fields"><code>X</code> and <code>Y</code> Fields</h3>
705<p>The X and Y fields provide positional information for the center of the contact area.</p>
706<h4 id="calculation">Calculation</h4>
707<p>The calculation is straightforward: positional information from the touch driver is
708linearly interpolated to the output coordinate system.</p>
709<pre><code>xScale = output.width / raw.width
710yScale = output.height / raw.height
711
712If not orientation aware or screen rotation is 0 degrees:
713output.x = (raw.x - raw.x.min) * xScale
714output.y = (raw.y - raw.y.min) * yScale
715Else If rotation is 90 degrees:
716 output.x = (raw.y - raw.y.min) * yScale
717 output.y = (raw.x.max - raw.x) * xScale
718Else If rotation is 180 degrees:
719 output.x = (raw.x.max - raw.x) * xScale
720 output.y = (raw.y.max - raw.y) * yScale
721Else If rotation is 270 degrees:
722 output.x = (raw.y.max - raw.y) * yScale
723 output.y = (raw.x - raw.x.min) * xScale
724End If
725</code></pre>
726<h3 id="touchmajor-touchminor-toolmajor-toolminor-size-fields"><code>TouchMajor</code>, <code>TouchMinor</code>, <code>ToolMajor</code>, <code>ToolMinor</code>, <code>Size</code> Fields</h3>
727<p>The <code>TouchMajor</code> and <code>TouchMinor</code> fields describe the approximate dimensions
728of the contact area in output units (pixels).</p>
729<p>The <code>ToolMajor</code> and <code>ToolMinor</code> fields describe the approximate dimensions
730of the <a href="#tools-and-tool-types">tool</a> itself in output units (pixels).</p>
731<p>The <code>Size</code> field describes the normalized size of the touch relative to
732the largest possible touch that the touch device can sense. The smallest
733possible normalized size is 0.0 (no contact, or it is unmeasurable), and the largest
734possible normalized size is 1.0 (sensor area is saturated).</p>
735<p>When both the approximate length and breadth can be measured, then the <code>TouchMajor</code> field
736specifies the longer dimension and the <code>TouchMinor</code> field specifies the shorter dimension
737of the contact area. When only the approximate diameter of the contact area can be measured,
738then the <code>TouchMajor</code> and <code>TouchMinor</code> fields will be equal.</p>
739<p>Likewise, the <code>ToolMajor</code> field specifies the longer dimension and the <code>ToolMinor</code>
740field specifies the shorter dimension of the tool's cross-sectional area.</p>
741<p>If the touch size is unavailable but the tool size is available, then the tool size
742will be set equal to the touch size. Conversely, if the tool size is unavailable
743but the touch size is available, then the touch size will be set equal to the tool size.</p>
744<p>Touch devices measure or report the touch size and tool size in various ways.
745The current implementation supports three different kinds of measurements:
746diameter, area, and geometric bounding box in surface units.</p>
747<h4 id="touchsizecalibration"><code>touch.size.calibration</code></h4>
748<p><em>Definition:</em> <code>touch.size.calibration</code> = <code>none</code> | <code>geometric</code> | <code>diameter</code>
749| <code>area</code> | <code>default</code></p>
750<p>Specifies the kind of measurement used by the touch driver to report the
751touch size and tool size.</p>
752<ul>
753<li>
754<p>If the value is <code>none</code>, the size is set to zero.</p>
755</li>
756<li>
757<p>If the value is <code>geometric</code>, the size is assumed to be specified in the same
758 surface units as the position, so it is scaled in the same manner.</p>
759</li>
760<li>
761<p>If the value is <code>diameter</code>, the size is assumed to be proportional to
762 the diameter (width) of the touch or tool.</p>
763</li>
764<li>
765<p>If the value is <code>area</code>, the size is assumed to be proportional to the
766 area of the touch or tool.</p>
767</li>
768<li>
769<p>If the value is <code>default</code>, the system uses the <code>geometric</code> calibration if the
770 <code>raw.touchMajor</code> or <code>raw.toolMajor</code> axis is available, otherwise it uses
771 the <code>none</code> calibration.</p>
772</li>
773</ul>
774<h4 id="touchsizescale"><code>touch.size.scale</code></h4>
775<p><em>Definition:</em> <code>touch.size.scale</code> = &lt;a non-negative floating point number&gt;</p>
776<p>Specifies a constant scale factor used in the calibration.</p>
777<p>The default value is <code>1.0</code>.</p>
778<h4 id="touchsizebias"><code>touch.size.bias</code></h4>
779<p><em>Definition:</em> <code>touch.size.bias</code> = &lt;a non-negative floating point number&gt;</p>
780<p>Specifies a constant bias value used in the calibration.</p>
781<p>The default value is <code>0.0</code>.</p>
782<h4 id="touchsizeissummed"><code>touch.size.isSummed</code></h4>
783<p><em>Definition:</em> <code>touch.size.isSummed</code> = <code>0</code> | <code>1</code></p>
784<p>Specifies whether the size is reported as the sum of the sizes of all
785active contacts, or is reported individually for each contact.</p>
786<ul>
787<li>
788<p>If the value is <code>1</code>, the reported size will be divided by the number
789 of contacts prior to use.</p>
790</li>
791<li>
792<p>If the value is <code>0</code>, the reported size will be used as is.</p>
793</li>
794</ul>
795<p>The default value is <code>0</code>.</p>
796<p>Some touch devices, particularly "Semi-MT" devices cannot distinguish the
797individual dimensions of multiple contacts so they report a size measurement
798that represents their total area or width. This property should only be set to
799<code>1</code> for such devices. If in doubt, set this value to <code>0</code>.</p>
800<h4 id="calculation_1">Calculation</h4>
801<p>The calculation of the <code>TouchMajor</code>, <code>TouchMinor</code>, <code>ToolMajor</code>, <code>ToolMinor</code>
802and <code>Size</code> fields depends on the specified calibration parameters.</p>
803<pre><code>If raw.touchMajor and raw.toolMajor are available:
804 touchMajor = raw.touchMajor
805 touchMinor = raw.touchMinor
806 toolMajor = raw.toolMajor
807 toolMinor = raw.toolMinor
808Else If raw.touchMajor is available:
809 toolMajor = touchMajor = raw.touchMajor
810 toolMinor = touchMinor = raw.touchMinor
811Else If raw.toolMajor is available:
812 touchMajor = toolMajor = raw.toolMajor
813 touchMinor = toolMinor = raw.toolMinor
814Else
815 touchMajor = toolMajor = 0
816 touchMinor = toolMinor = 0
817 size = 0
818End If
819
820size = avg(touchMajor, touchMinor)
821
822If touch.size.isSummed == 1:
823 touchMajor = touchMajor / numberOfActiveContacts
824 touchMinor = touchMinor / numberOfActiveContacts
825 toolMajor = toolMajor / numberOfActiveContacts
826 toolMinor = toolMinor / numberOfActiveContacts
827 size = size / numberOfActiveContacts
828End If
829
830If touch.size.calibration == "none":
831 touchMajor = toolMajor = 0
832 touchMinor = toolMinor = 0
833 size = 0
834Else If touch.size.calibration == "geometric":
835 outputScale = average(output.width / raw.width, output.height / raw.height)
836 touchMajor = touchMajor * outputScale
837 touchMinor = touchMinor * outputScale
838 toolMajor = toolMajor * outputScale
839 toolMinor = toolMinor * outputScale
840Else If touch.size.calibration == "area":
841 touchMajor = sqrt(touchMajor)
842 touchMinor = touchMajor
843 toolMajor = sqrt(toolMajor)
844 toolMinor = toolMajor
845Else If touch.size.calibration == "diameter":
846 touchMinor = touchMajor
847 toolMinor = toolMajor
848End If
849
850If touchMajor != 0:
851 output.touchMajor = touchMajor * touch.size.scale + touch.size.bias
852Else
853 output.touchMajor = 0
854End If
855
856If touchMinor != 0:
857 output.touchMinor = touchMinor * touch.size.scale + touch.size.bias
858Else
859 output.touchMinor = 0
860End If
861
862If toolMajor != 0:
863 output.toolMajor = toolMajor * touch.size.scale + touch.size.bias
864Else
865 output.toolMajor = 0
866End If
867
868If toolMinor != 0:
869 output.toolMinor = toolMinor * touch.size.scale + touch.size.bias
870Else
871 output.toolMinor = 0
872End If
873
874output.size = size
875</code></pre>
876<h3 id="pressure-field"><code>Pressure</code> Field</h3>
877<p>The <code>Pressure</code> field describes the approximate physical pressure applied to the
878touch device as a normalized value between 0.0 (no touch) and 1.0 (full force).</p>
879<p>A zero pressure indicates that the tool is hovering.</p>
880<h4 id="touchpressurecalibration"><code>touch.pressure.calibration</code></h4>
881<p><em>Definition:</em> <code>touch.pressure.calibration</code> = <code>none</code> | <code>physical</code> | <code>amplitude</code> | <code>default</code></p>
882<p>Specifies the kind of measurement used by the touch driver to report the pressure.</p>
883<ul>
884<li>
885<p>If the value is <code>none</code>, the pressure is unknown so it is set to 1.0 when
886 touching and 0.0 when hovering.</p>
887</li>
888<li>
889<p>If the value is <code>physical</code>, the pressure axis is assumed to measure the actual
890 physical intensity of pressure applied to the touch pad.</p>
891</li>
892<li>
893<p>If the value is <code>amplitude</code>, the pressure axis is assumed to measure the signal
894 amplitude, which is related to the size of the contact and the pressure applied.</p>
895</li>
896<li>
897<p>If the value is <code>default</code>, the system uses the <code>physical</code> calibration if the
898 pressure axis available, otherwise uses <code>none</code>.</p>
899</li>
900</ul>
901<h4 id="touchpressurescale"><code>touch.pressure.scale</code></h4>
902<p><em>Definition:</em> <code>touch.pressure.scale</code> = &lt;a non-negative floating point number&gt;</p>
903<p>Specifies a constant scale factor used in the calibration.</p>
904<p>The default value is <code>1.0 / raw.pressure.max</code>.</p>
905<h4 id="calculation_2">Calculation</h4>
906<p>The calculation of the <code>Pressure</code> field depends on the specified calibration parameters.</p>
907<pre><code>If touch.pressure.calibration == "physical" or "amplitude":
908 output.pressure = raw.pressure * touch.pressure.scale
909Else
910 If hovering:
911 output.pressure = 0
912 Else
913 output.pressure = 1
914 End If
915End If
916</code></pre>
917<h3 id="orientation-and-tilt-fields"><code>Orientation</code> and <code>Tilt</code> Fields</h3>
918<p>The <code>Orientation</code> field describes the orientation of the touch and tool as an
919angular measurement. An orientation of <code>0</code> indicates that the major axis is
920oriented vertically, <code>-PI/2</code> indicates that the major axis is oriented to the left,
921<code>PI/2</code> indicates that the major axis is oriented to the right. When a stylus
922tool is present, the orientation range may be described in a full circle range
923from <code>-PI</code> or <code>PI</code>.</p>
924<p>The <code>Tilt</code> field describes the inclination of the tool as an angular measurement.
925A tilt of <code>0</code> indicates that the tool is perpendicular to the surface.
926A tilt of <code>PI/2</code> indicates that the tool is flat on the surface.</p>
927<h4 id="touchorientationcalibration"><code>touch.orientation.calibration</code></h4>
928<p><em>Definition:</em> <code>touch.orientation.calibration</code> = <code>none</code> | <code>interpolated</code> | <code>vector</code> | <code>default</code></p>
929<p>Specifies the kind of measurement used by the touch driver to report the orientation.</p>
930<ul>
931<li>
932<p>If the value is <code>none</code>, the orientation is unknown so it is set to 0.</p>
933</li>
934<li>
935<p>If the value is <code>interpolated</code>, the orientation is linearly interpolated such that a
936 raw value of <code>raw.orientation.min</code> maps to <code>-PI/2</code> and a raw value of
937 <code>raw.orientation.max</code> maps to <code>PI/2</code>. The center value of
938 <code>(raw.orientation.min + raw.orientation.max) / 2</code> maps to <code>0</code>.</p>
939</li>
940<li>
941<p>If the value is <code>vector</code>, the orientation is interpreted as a packed vector consisiting
942 of two signed 4-bit fields. This representation is used on Atmel Object Based Protocol
943 parts. When decoded, the vector yields an orientation angle and confidence
944 magnitude. The confidence magnitude is used to scale the size information,
945 unless it is geometric.</p>
946</li>
947<li>
948<p>If the value is <code>default</code>, the system uses the <code>interpolated</code> calibration if the
949 orientation axis available, otherwise uses <code>none</code>.</p>
950</li>
951</ul>
952<h4 id="calculation_3">Calculation</h4>
953<p>The calculation of the <code>Orientation</code> and <code>Tilt</code> fields depends on the specified
954calibration parameters and available input.</p>
955<pre><code>If touch.tiltX and touch.tiltY are available:
956 tiltXCenter = average(raw.tiltX.min, raw.tiltX.max)
957 tiltYCenter = average(raw.tiltY.min, raw.tiltY.max)
958 tiltXAngle = (raw.tiltX - tiltXCenter) * PI / 180
959 tiltYAngle = (raw.tiltY - tiltYCenter) * PI / 180
960 output.orientation = atan2(-sin(tiltXAngle), sinf(tiltYAngle))
961 output.tilt = acos(cos(tiltXAngle) * cos(tiltYAngle))
962Else If touch.orientation.calibration == "interpolated":
963 center = average(raw.orientation.min, raw.orientation.max)
964 output.orientation = PI / (raw.orientation.max - raw.orientation.min)
965 output.tilt = 0
966Else If touch.orientation.calibration == "vector":
967 c1 = (raw.orientation &amp; 0xF0) &gt;&gt; 4
968 c2 = raw.orientation &amp; 0x0F
969
970 If c1 != 0 or c2 != 0:
971 If c1 &gt;= 8 Then c1 = c1 - 16
972 If c2 &gt;= 8 Then c2 = c2 - 16
973 angle = atan2(c1, c2) / 2
974 confidence = sqrt(c1*c1 + c2*c2)
975
976 output.orientation = angle
977
978 If touch.size.calibration == "diameter" or "area":
979 scale = 1.0 + confidence / 16
980 output.touchMajor *= scale
981 output.touchMinor /= scale
982 output.toolMajor *= scale
983 output.toolMinor /= scale
984 End If
985 Else
986 output.orientation = 0
987 End If
988 output.tilt = 0
989Else
990 output.orientation = 0
991 output.tilt = 0
992End If
993
994If orientation aware:
995 If screen rotation is 90 degrees:
996 output.orientation = output.orientation - PI / 2
997 Else If screen rotation is 270 degrees:
998 output.orientation = output.orientation + PI / 2
999 End If
1000End If
1001</code></pre>
1002<h3 id="distance-field"><code>Distance</code> Field</h3>
1003<p>The <code>Distance</code> field describes the distance between the tool and the touch device
1004surface. A value of 0.0 indicates direct contact and larger values indicate
1005increasing distance from the surface.</p>
1006<h4 id="touchdistancecalibration"><code>touch.distance.calibration</code></h4>
1007<p><em>Definition:</em> <code>touch.distance.calibration</code> = <code>none</code> | <code>scaled</code> | <code>default</code></p>
1008<p>Specifies the kind of measurement used by the touch driver to report the distance.</p>
1009<ul>
1010<li>
1011<p>If the value is <code>none</code>, the distance is unknown so it is set to 0.</p>
1012</li>
1013<li>
1014<p>If the value is <code>scaled</code>, the reported distance is multiplied by a
1015 constant scale factor.</p>
1016</li>
1017<li>
1018<p>If the value is <code>default</code>, the system uses the <code>scaled</code> calibration if the
1019 distance axis available, otherwise uses <code>none</code>.</p>
1020</li>
1021</ul>
1022<h4 id="touchdistancescale"><code>touch.distance.scale</code></h4>
1023<p><em>Definition:</em> <code>touch.distance.scale</code> = &lt;a non-negative floating point number&gt;</p>
1024<p>Specifies a constant scale factor used in the calibration.</p>
1025<p>The default value is <code>1.0</code>.</p>
1026<h4 id="calculation_4">Calculation</h4>
1027<p>The calculation of the <code>Distance</code> field depends on the specified calibration parameters.</p>
1028<pre><code>If touch.distance.calibration == "scaled":
1029 output.distance = raw.distance * touch.distance.scale
1030Else
1031 output.distance = 0
1032End If
1033</code></pre>
1034<h3 id="example">Example</h3>
1035<pre><code># Input device configuration file for a touch screen that supports pressure,
1036# size and orientation. The pressure and size scale factors were obtained
1037# by measuring the characteristics of the device itself and deriving
1038# useful approximations based on the resolution of the touch sensor and the
1039# display.
1040#
1041# Note that these parameters are specific to a particular device model.
1042# Different parameters will need to be used for other devices.
1043
1044# Basic Parameters
1045touch.deviceType = touchScreen
1046touch.orientationAware = 1
1047
1048# Size
1049# Based on empirical measurements, we estimate the size of the contact
1050# using size = sqrt(area) * 28 + 0.
1051touch.size.calibration = area
1052touch.size.scale = 28
1053touch.size.bias = 0
1054touch.size.isSummed = 0
1055
1056# Pressure
1057# Driver reports signal strength as pressure.
1058#
1059# A normal index finger touch typically registers about 80 signal strength
1060# units although we don't expect these values to be accurate.
1061touch.pressure.calibration = amplitude
1062touch.pressure.scale = 0.0125
1063
1064# Orientation
1065touch.orientation.calibration = vector
1066</code></pre>
1067<h3 id="compatibility-notes">Compatibility Notes</h3>
1068<p>The configuration properties for touch devices changed significantly in
1069Android Ice Cream Sandwich 4.0. <strong>All input device configuration files for touch
1070devices must be updated to use the new configuration properties.</strong></p>
1071<p>Older touch device <a href="#touch-device-driver-requirements">drivers</a> may also need to be
1072updated.</p>
1073<h2 id="virtual-key-map-files">Virtual Key Map Files</h2>
1074<p>Touch devices are often used to implement virtual keys.</p>
1075<p>There are several ways of doing this, depending on the capabilities of the
1076touch controller. Some touch controllers can be directly configured to implement
1077soft keys by setting firmware registers. Other times it is desirable to perform
1078the mapping from touch coordinates to key codes in software.</p>
1079<p>When virtual keys are implemented in software, the kernel must export a virtual key map
1080file called <code>virtualkeys.&lt;devicename&gt;</code> as a board property. For example,
1081if the touch screen device drivers reports its name as "touchyfeely" then
1082the virtual key map file must have the path <code>/sys/board_properties/virtualkeys.touchyfeely</code>.</p>
1083<p>A virtual key map file describes the coordinates and Linux key codes of virtual keys
1084on the touch screen.</p>
1085<p>In addition to the virtual key map file, there must be a corresponding key layout
1086file and key character map file to map the Linux key codes to Android key codes and
1087to specify the type of the keyboard device (usually <code>SPECIAL_FUNCTION</code>).</p>
1088<h3 id="syntax">Syntax</h3>
1089<p>A virtual key map file is a plain text file consisting of a sequence of virtual key
1090layout descriptions either separated by newlines or by colons.</p>
1091<p>Comment lines begin with '#' and continue to the end of the line.</p>
1092<p>Each virtual key is described by 6 colon-delimited components:</p>
1093<ul>
1094<li><code>0x01</code>: A version code. Must always be <code>0x01</code>.</li>
1095<li>&lt;Linux key code&gt;: The Linux key code of the virtual key.</li>
1096<li>&lt;centerX&gt;: The X pixel coordinate of the center of the virtual key.</li>
1097<li>&lt;centerY&gt;: The Y pixel coordinate of the center of the virtual key.</li>
1098<li>&lt;width&gt;: The width of the virtual key in pixels.</li>
1099<li>&lt;height&gt;: The height of the virtual key in pixels.</li>
1100</ul>
1101<p>All coordinates and sizes are specified in terms of the display coordinate system.</p>
1102<p>Here is a virtual key map file all written on one line.</p>
1103<pre><code># All on one line
11040x01:158:55:835:90:55:0x01:139:172:835:125:55:0x01:102:298:835:115:55:0x01:217:412:835:95:55
1105</code></pre>
1106<p>The same virtual key map file can also be written on multiple lines.</p>
1107<pre><code># One key per line
11080x01:158:55:835:90:55
11090x01:139:172:835:125:55
11100x01:102:298:835:115:55
11110x01:217:412:835:95:55
1112</code></pre>
1113<p>In the above example, the touch screen has a resolution of 480x800. Accordingly, all of
1114the virtual keys have a &lt;centerY&gt; coordinate of 835, which is a little bit below
1115the visible area of the touch screen.</p>
1116<p>The first key has a Linux scan code of <code>158</code> (<code>KEY_BACK</code>), centerX of <code>55</code>,
1117centerY of <code>835</code>, width of <code>90</code> and height of <code>55</code>.</p>
1118<h3 id="example_1">Example</h3>
1119<p>Virtual key map file: <code>/sys/board_properties/virtualkeys.touchyfeely</code>.</p>
1120<pre><code>0x01:158:55:835:90:55
11210x01:139:172:835:125:55
11220x01:102:298:835:115:55
11230x01:217:412:835:95:55
1124</code></pre>
1125<p>Key layout file: <code>/system/usr/keylayout/touchyfeely.kl</code>.</p>
1126<pre><code>key 158 BACK
1127key 139 MENU
1128key 102 HOME
1129key 217 SEARCH
1130</code></pre>
1131<p>Key character map file: <code>/system/usr/keychars/touchyfeely.kcm</code>.</p>
1132<pre><code>type SPECIAL_FUNCTION
1133</code></pre>
1134<h2 id="indirect-multi-touch-pointer-gestures">Indirect Multi-touch Pointer Gestures</h2>
1135<p>In pointer mode, the system interprets the following gestures:</p>
1136<ol>
1137<li>
1138<p>Single finger tap: click.</p>
1139</li>
1140<li>
1141<p>Single finger motion: move the pointer.</p>
1142</li>
1143<li>
1144<p>Single finger motion plus button presses: drag the pointer.</p>
1145</li>
1146<li>
1147<p>Two finger motion both fingers moving in the same direction: drag the area under the pointer
1148 in that direction. The pointer itself does not move.</p>
1149</li>
1150<li>
1151<p>Two finger motion both fingers moving towards each other or apart in
1152 different directions: pan/scale/rotate the area surrounding the pointer.
1153 The pointer itself does not move.</p>
1154</li>
1155<li>
1156<p>Multiple finger motion: freeform gesture.</p>
1157</li>
1158</ol>
1159<h2 id="further-reading">Further Reading</h2>
1160<ol>
1161<li><a href="http://www.kernel.org/doc/Documentation/input/multi-touch-protocol.txt">Linux multi-touch protocol</a></li>
1162<li><a href="http://lii-enac.fr/en/architecture/linux-input/multitouch-devices.html">ENAC list of available multitouch devices on Linux</a></li>
1163</ol>