blob: 674f67dadd328da6a73ac3121b012ad22846eb3c [file] [log] [blame]
Jeff Brown46b9ac02010-04-22 18:58:52 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _UI_INPUT_READER_H
18#define _UI_INPUT_READER_H
19
Jeff Brownb4ff35d2011-01-02 16:37:43 -080020#include "EventHub.h"
Jeff Brownb4ff35d2011-01-02 16:37:43 -080021#include "PointerController.h"
Jeff Brownbe1aa822011-07-27 16:04:54 -070022#include "InputListener.h"
Jeff Brownb4ff35d2011-01-02 16:37:43 -080023
Jeff Brown9d3b1a42013-07-01 19:07:15 -070024#include <input/Input.h>
25#include <input/VelocityControl.h>
26#include <input/VelocityTracker.h>
Jeff Brown46b9ac02010-04-22 18:58:52 -070027#include <utils/KeyedVector.h>
28#include <utils/threads.h>
29#include <utils/Timers.h>
30#include <utils/RefBase.h>
31#include <utils/String8.h>
32#include <utils/BitSet.h>
33
34#include <stddef.h>
35#include <unistd.h>
36
Jeff Browna47425a2012-04-13 04:09:27 -070037// Maximum supported size of a vibration pattern.
38// Must be at least 2.
39#define MAX_VIBRATE_PATTERN_SIZE 100
40
41// Maximum allowable delay value in a vibration pattern before
42// which the delay will be truncated.
43#define MAX_VIBRATE_PATTERN_DELAY_NSECS (1000000 * 1000000000LL)
44
Jeff Brown46b9ac02010-04-22 18:58:52 -070045namespace android {
46
Jeff Brown6d0fec22010-07-23 21:28:06 -070047class InputDevice;
48class InputMapper;
49
Jeff Brownd728bf52012-09-08 18:05:28 -070050/*
51 * Describes how coordinates are mapped on a physical display.
52 * See com.android.server.display.DisplayViewport.
53 */
54struct DisplayViewport {
55 int32_t displayId; // -1 if invalid
56 int32_t orientation;
57 int32_t logicalLeft;
58 int32_t logicalTop;
59 int32_t logicalRight;
60 int32_t logicalBottom;
61 int32_t physicalLeft;
62 int32_t physicalTop;
63 int32_t physicalRight;
64 int32_t physicalBottom;
Jeff Brown83d616a2012-09-09 20:33:43 -070065 int32_t deviceWidth;
66 int32_t deviceHeight;
Jeff Brownd728bf52012-09-08 18:05:28 -070067
68 DisplayViewport() :
Jeff Brown83d616a2012-09-09 20:33:43 -070069 displayId(ADISPLAY_ID_NONE), orientation(DISPLAY_ORIENTATION_0),
Jeff Brownd728bf52012-09-08 18:05:28 -070070 logicalLeft(0), logicalTop(0), logicalRight(0), logicalBottom(0),
Jeff Brown83d616a2012-09-09 20:33:43 -070071 physicalLeft(0), physicalTop(0), physicalRight(0), physicalBottom(0),
72 deviceWidth(0), deviceHeight(0) {
Jeff Brownd728bf52012-09-08 18:05:28 -070073 }
74
75 bool operator==(const DisplayViewport& other) const {
76 return displayId == other.displayId
77 && orientation == other.orientation
78 && logicalLeft == other.logicalLeft
79 && logicalTop == other.logicalTop
80 && logicalRight == other.logicalRight
81 && logicalBottom == other.logicalBottom
82 && physicalLeft == other.physicalLeft
83 && physicalTop == other.physicalTop
84 && physicalRight == other.physicalRight
Jeff Brown83d616a2012-09-09 20:33:43 -070085 && physicalBottom == other.physicalBottom
86 && deviceWidth == other.deviceWidth
87 && deviceHeight == other.deviceHeight;
Jeff Brownd728bf52012-09-08 18:05:28 -070088 }
89
90 bool operator!=(const DisplayViewport& other) const {
91 return !(*this == other);
92 }
Jeff Brown83d616a2012-09-09 20:33:43 -070093
94 inline bool isValid() const {
95 return displayId >= 0;
96 }
97
98 void setNonDisplayViewport(int32_t width, int32_t height) {
99 displayId = ADISPLAY_ID_NONE;
100 orientation = DISPLAY_ORIENTATION_0;
101 logicalLeft = 0;
102 logicalTop = 0;
103 logicalRight = width;
104 logicalBottom = height;
105 physicalLeft = 0;
106 physicalTop = 0;
107 physicalRight = width;
108 physicalBottom = height;
109 deviceWidth = width;
110 deviceHeight = height;
111 }
Jeff Brownd728bf52012-09-08 18:05:28 -0700112};
Jeff Brown8d608662010-08-30 03:02:23 -0700113
Jeff Brown9c3cda02010-06-15 01:31:58 -0700114/*
Jeff Brown214eaf42011-05-26 19:17:02 -0700115 * Input reader configuration.
116 *
117 * Specifies various options that modify the behavior of the input reader.
118 */
119struct InputReaderConfiguration {
Jeff Brown474dcb52011-06-14 20:22:50 -0700120 // Describes changes that have occurred.
121 enum {
122 // The pointer speed changed.
123 CHANGE_POINTER_SPEED = 1 << 0,
124
125 // The pointer gesture control changed.
126 CHANGE_POINTER_GESTURE_ENABLEMENT = 1 << 1,
127
Jeff Brown65fd2512011-08-18 11:20:58 -0700128 // The display size or orientation changed.
129 CHANGE_DISPLAY_INFO = 1 << 2,
130
Jeff Browndaf4a122011-08-26 17:14:14 -0700131 // The visible touches option changed.
132 CHANGE_SHOW_TOUCHES = 1 << 3,
133
Jeff Brown6ec6f792012-04-17 16:52:41 -0700134 // The keyboard layouts must be reloaded.
135 CHANGE_KEYBOARD_LAYOUTS = 1 << 4,
136
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700137 // The device name alias supplied by the may have changed for some devices.
138 CHANGE_DEVICE_ALIAS = 1 << 5,
139
Jeff Brown474dcb52011-06-14 20:22:50 -0700140 // All devices must be reopened.
141 CHANGE_MUST_REOPEN = 1 << 31,
142 };
143
Jeff Brown214eaf42011-05-26 19:17:02 -0700144 // Gets the amount of time to disable virtual keys after the screen is touched
145 // in order to filter out accidental virtual key presses due to swiping gestures
146 // or taps near the edge of the display. May be 0 to disable the feature.
147 nsecs_t virtualKeyQuietTime;
148
149 // The excluded device names for the platform.
150 // Devices with these names will be ignored.
151 Vector<String8> excludedDeviceNames;
152
Jeff Brown19c97d462011-06-01 12:33:19 -0700153 // Velocity control parameters for mouse pointer movements.
154 VelocityControlParameters pointerVelocityControlParameters;
155
156 // Velocity control parameters for mouse wheel movements.
157 VelocityControlParameters wheelVelocityControlParameters;
158
Jeff Brown474dcb52011-06-14 20:22:50 -0700159 // True if pointer gestures are enabled.
160 bool pointerGesturesEnabled;
161
Jeff Brown214eaf42011-05-26 19:17:02 -0700162 // Quiet time between certain pointer gesture transitions.
163 // Time to allow for all fingers or buttons to settle into a stable state before
164 // starting a new gesture.
165 nsecs_t pointerGestureQuietInterval;
166
167 // The minimum speed that a pointer must travel for us to consider switching the active
168 // touch pointer to it during a drag. This threshold is set to avoid switching due
169 // to noise from a finger resting on the touch pad (perhaps just pressing it down).
170 float pointerGestureDragMinSwitchSpeed; // in pixels per second
171
172 // Tap gesture delay time.
173 // The time between down and up must be less than this to be considered a tap.
174 nsecs_t pointerGestureTapInterval;
175
176 // Tap drag gesture delay time.
177 // The time between the previous tap's up and the next down must be less than
178 // this to be considered a drag. Otherwise, the previous tap is finished and a
179 // new tap begins.
180 //
181 // Note that the previous tap will be held down for this entire duration so this
182 // interval must be shorter than the long press timeout.
183 nsecs_t pointerGestureTapDragInterval;
184
185 // The distance in pixels that the pointer is allowed to move from initial down
186 // to up and still be called a tap.
187 float pointerGestureTapSlop; // in pixels
188
189 // Time after the first touch points go down to settle on an initial centroid.
190 // This is intended to be enough time to handle cases where the user puts down two
191 // fingers at almost but not quite exactly the same time.
192 nsecs_t pointerGestureMultitouchSettleInterval;
193
194 // The transition from PRESS to SWIPE or FREEFORM gesture mode is made when
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700195 // at least two pointers have moved at least this far from their starting place.
196 float pointerGestureMultitouchMinDistance; // in pixels
Jeff Brown214eaf42011-05-26 19:17:02 -0700197
198 // The transition from PRESS to SWIPE gesture mode can only occur when the
199 // cosine of the angle between the two vectors is greater than or equal to than this value
200 // which indicates that the vectors are oriented in the same direction.
201 // When the vectors are oriented in the exactly same direction, the cosine is 1.0.
202 // (In exactly opposite directions, the cosine is -1.0.)
203 float pointerGestureSwipeTransitionAngleCosine;
204
205 // The transition from PRESS to SWIPE gesture mode can only occur when the
206 // fingers are no more than this far apart relative to the diagonal size of
207 // the touch pad. For example, a ratio of 0.5 means that the fingers must be
208 // no more than half the diagonal size of the touch pad apart.
209 float pointerGestureSwipeMaxWidthRatio;
210
211 // The gesture movement speed factor relative to the size of the display.
212 // Movement speed applies when the fingers are moving in the same direction.
213 // Without acceleration, a full swipe of the touch pad diagonal in movement mode
214 // will cover this portion of the display diagonal.
215 float pointerGestureMovementSpeedRatio;
216
217 // The gesture zoom speed factor relative to the size of the display.
218 // Zoom speed applies when the fingers are mostly moving relative to each other
219 // to execute a scale gesture or similar.
220 // Without acceleration, a full swipe of the touch pad diagonal in zoom mode
221 // will cover this portion of the display diagonal.
222 float pointerGestureZoomSpeedRatio;
223
Jeff Browndaf4a122011-08-26 17:14:14 -0700224 // True to show the location of touches on the touch screen as spots.
225 bool showTouches;
226
Jeff Brown214eaf42011-05-26 19:17:02 -0700227 InputReaderConfiguration() :
Jeff Brown214eaf42011-05-26 19:17:02 -0700228 virtualKeyQuietTime(0),
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700229 pointerVelocityControlParameters(1.0f, 500.0f, 3000.0f, 3.0f),
Jeff Brown19c97d462011-06-01 12:33:19 -0700230 wheelVelocityControlParameters(1.0f, 15.0f, 50.0f, 4.0f),
Jeff Brown474dcb52011-06-14 20:22:50 -0700231 pointerGesturesEnabled(true),
Jeff Brown214eaf42011-05-26 19:17:02 -0700232 pointerGestureQuietInterval(100 * 1000000LL), // 100 ms
233 pointerGestureDragMinSwitchSpeed(50), // 50 pixels per second
234 pointerGestureTapInterval(150 * 1000000LL), // 150 ms
235 pointerGestureTapDragInterval(150 * 1000000LL), // 150 ms
236 pointerGestureTapSlop(10.0f), // 10 pixels
237 pointerGestureMultitouchSettleInterval(100 * 1000000LL), // 100 ms
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700238 pointerGestureMultitouchMinDistance(15), // 15 pixels
Jeff Brown6674d9b2011-06-07 16:50:14 -0700239 pointerGestureSwipeTransitionAngleCosine(0.2588f), // cosine of 75 degrees
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700240 pointerGestureSwipeMaxWidthRatio(0.25f),
241 pointerGestureMovementSpeedRatio(0.8f),
Jeff Browndaf4a122011-08-26 17:14:14 -0700242 pointerGestureZoomSpeedRatio(0.3f),
243 showTouches(false) { }
Jeff Brown65fd2512011-08-18 11:20:58 -0700244
Jeff Brownd728bf52012-09-08 18:05:28 -0700245 bool getDisplayInfo(bool external, DisplayViewport* outViewport) const;
246 void setDisplayInfo(bool external, const DisplayViewport& viewport);
Jeff Brown65fd2512011-08-18 11:20:58 -0700247
248private:
Jeff Brownd728bf52012-09-08 18:05:28 -0700249 DisplayViewport mInternalDisplay;
250 DisplayViewport mExternalDisplay;
Jeff Brown214eaf42011-05-26 19:17:02 -0700251};
252
253
254/*
Jeff Brown9c3cda02010-06-15 01:31:58 -0700255 * Input reader policy interface.
256 *
257 * The input reader policy is used by the input reader to interact with the Window Manager
258 * and other system components.
259 *
260 * The actual implementation is partially supported by callbacks into the DVM
261 * via JNI. This interface is also mocked in the unit tests.
Jeff Brownbe1aa822011-07-27 16:04:54 -0700262 *
263 * These methods must NOT re-enter the input reader since they may be called while
264 * holding the input reader lock.
Jeff Brown9c3cda02010-06-15 01:31:58 -0700265 */
266class InputReaderPolicyInterface : public virtual RefBase {
267protected:
268 InputReaderPolicyInterface() { }
269 virtual ~InputReaderPolicyInterface() { }
270
271public:
Jeff Brown214eaf42011-05-26 19:17:02 -0700272 /* Gets the input reader configuration. */
273 virtual void getReaderConfiguration(InputReaderConfiguration* outConfig) = 0;
Jeff Brown83c09682010-12-23 17:50:18 -0800274
275 /* Gets a pointer controller associated with the specified cursor device (ie. a mouse). */
276 virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId) = 0;
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700277
278 /* Notifies the input reader policy that some input devices have changed
279 * and provides information about all current input devices.
280 */
281 virtual void notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices) = 0;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700282
283 /* Gets the keyboard layout for a particular input device. */
RoboErikfb290df2013-12-16 11:27:55 -0800284 virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(
285 const InputDeviceIdentifier& identifier) = 0;
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700286
287 /* Gets a user-supplied alias for a particular input device, or an empty string if none. */
288 virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier) = 0;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700289};
290
291
Jeff Brownbe1aa822011-07-27 16:04:54 -0700292/* Processes raw input events and sends cooked event data to an input listener. */
Jeff Brown46b9ac02010-04-22 18:58:52 -0700293class InputReaderInterface : public virtual RefBase {
294protected:
295 InputReaderInterface() { }
296 virtual ~InputReaderInterface() { }
297
298public:
Jeff Brownb88102f2010-09-08 11:49:43 -0700299 /* Dumps the state of the input reader.
300 *
301 * This method may be called on any thread (usually by the input manager). */
302 virtual void dump(String8& dump) = 0;
303
Jeff Brown89ef0722011-08-10 16:25:21 -0700304 /* Called by the heatbeat to ensures that the reader has not deadlocked. */
305 virtual void monitor() = 0;
306
Jeff Brown46b9ac02010-04-22 18:58:52 -0700307 /* Runs a single iteration of the processing loop.
308 * Nominally reads and processes one incoming message from the EventHub.
309 *
310 * This method should be called on the input reader thread.
311 */
312 virtual void loopOnce() = 0;
313
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700314 /* Gets information about all input devices.
Jeff Brown6d0fec22010-07-23 21:28:06 -0700315 *
316 * This method may be called on any thread (usually by the input manager).
Jeff Brown9c3cda02010-06-15 01:31:58 -0700317 */
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700318 virtual void getInputDevices(Vector<InputDeviceInfo>& outInputDevices) = 0;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700319
320 /* Query current input state. */
321 virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask,
322 int32_t scanCode) = 0;
323 virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask,
324 int32_t keyCode) = 0;
325 virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask,
326 int32_t sw) = 0;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700327
328 /* Determine whether physical keys exist for the given framework-domain key codes. */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700329 virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask,
330 size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) = 0;
Jeff Brown1a84fd12011-06-02 01:26:32 -0700331
Jeff Brown474dcb52011-06-14 20:22:50 -0700332 /* Requests that a reconfiguration of all input devices.
333 * The changes flag is a bitfield that indicates what has changed and whether
334 * the input devices must all be reopened. */
335 virtual void requestRefreshConfiguration(uint32_t changes) = 0;
Jeff Browna47425a2012-04-13 04:09:27 -0700336
337 /* Controls the vibrator of a particular input device. */
338 virtual void vibrate(int32_t deviceId, const nsecs_t* pattern, size_t patternSize,
339 ssize_t repeat, int32_t token) = 0;
340 virtual void cancelVibrate(int32_t deviceId, int32_t token) = 0;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700341};
342
343
344/* Internal interface used by individual input devices to access global input device state
345 * and parameters maintained by the input reader.
346 */
347class InputReaderContext {
Jeff Brownc3db8582010-10-20 15:33:38 -0700348public:
Jeff Brown6d0fec22010-07-23 21:28:06 -0700349 InputReaderContext() { }
350 virtual ~InputReaderContext() { }
351
Jeff Brown6d0fec22010-07-23 21:28:06 -0700352 virtual void updateGlobalMetaState() = 0;
353 virtual int32_t getGlobalMetaState() = 0;
354
Jeff Brownfe508922011-01-18 15:10:10 -0800355 virtual void disableVirtualKeysUntil(nsecs_t time) = 0;
356 virtual bool shouldDropVirtualKey(nsecs_t now,
357 InputDevice* device, int32_t keyCode, int32_t scanCode) = 0;
358
Jeff Brown05dc66a2011-03-02 14:41:58 -0800359 virtual void fadePointer() = 0;
360
Jeff Brownaa3855d2011-03-17 01:34:19 -0700361 virtual void requestTimeoutAtTime(nsecs_t when) = 0;
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700362 virtual int32_t bumpGeneration() = 0;
Jeff Brownaa3855d2011-03-17 01:34:19 -0700363
Jeff Brown6d0fec22010-07-23 21:28:06 -0700364 virtual InputReaderPolicyInterface* getPolicy() = 0;
Jeff Brownbe1aa822011-07-27 16:04:54 -0700365 virtual InputListenerInterface* getListener() = 0;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700366 virtual EventHubInterface* getEventHub() = 0;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700367};
368
Jeff Brown9c3cda02010-06-15 01:31:58 -0700369
Jeff Brown46b9ac02010-04-22 18:58:52 -0700370/* The input reader reads raw event data from the event hub and processes it into input events
Jeff Brownbe1aa822011-07-27 16:04:54 -0700371 * that it sends to the input listener. Some functions of the input reader, such as early
Jeff Brown9c3cda02010-06-15 01:31:58 -0700372 * event filtering in low power states, are controlled by a separate policy object.
373 *
Jeff Brownbe1aa822011-07-27 16:04:54 -0700374 * The InputReader owns a collection of InputMappers. Most of the work it does happens
375 * on the input reader thread but the InputReader can receive queries from other system
376 * components running on arbitrary threads. To keep things manageable, the InputReader
377 * uses a single Mutex to guard its state. The Mutex may be held while calling into the
378 * EventHub or the InputReaderPolicy but it is never held while calling into the
379 * InputListener.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700380 */
Jeff Brownbe1aa822011-07-27 16:04:54 -0700381class InputReader : public InputReaderInterface {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700382public:
383 InputReader(const sp<EventHubInterface>& eventHub,
Jeff Brown9c3cda02010-06-15 01:31:58 -0700384 const sp<InputReaderPolicyInterface>& policy,
Jeff Brownbe1aa822011-07-27 16:04:54 -0700385 const sp<InputListenerInterface>& listener);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700386 virtual ~InputReader();
387
Jeff Brownb88102f2010-09-08 11:49:43 -0700388 virtual void dump(String8& dump);
Jeff Brown89ef0722011-08-10 16:25:21 -0700389 virtual void monitor();
Jeff Brownb88102f2010-09-08 11:49:43 -0700390
Jeff Brown46b9ac02010-04-22 18:58:52 -0700391 virtual void loopOnce();
392
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700393 virtual void getInputDevices(Vector<InputDeviceInfo>& outInputDevices);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700394
Jeff Brown6d0fec22010-07-23 21:28:06 -0700395 virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask,
396 int32_t scanCode);
397 virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask,
398 int32_t keyCode);
399 virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask,
400 int32_t sw);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700401
Jeff Brown6d0fec22010-07-23 21:28:06 -0700402 virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask,
403 size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700404
Jeff Brown474dcb52011-06-14 20:22:50 -0700405 virtual void requestRefreshConfiguration(uint32_t changes);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700406
Jeff Browna47425a2012-04-13 04:09:27 -0700407 virtual void vibrate(int32_t deviceId, const nsecs_t* pattern, size_t patternSize,
408 ssize_t repeat, int32_t token);
409 virtual void cancelVibrate(int32_t deviceId, int32_t token);
410
Jeff Brownc3db8582010-10-20 15:33:38 -0700411protected:
Jeff Brownbe1aa822011-07-27 16:04:54 -0700412 // These members are protected so they can be instrumented by test cases.
Michael Wrightac6c78b2013-07-17 13:21:45 -0700413 virtual InputDevice* createDeviceLocked(int32_t deviceId, int32_t controllerNumber,
Jeff Browne38fdfa2012-04-06 14:51:01 -0700414 const InputDeviceIdentifier& identifier, uint32_t classes);
Jeff Brownbe1aa822011-07-27 16:04:54 -0700415
416 class ContextImpl : public InputReaderContext {
417 InputReader* mReader;
418
419 public:
420 ContextImpl(InputReader* reader);
421
422 virtual void updateGlobalMetaState();
423 virtual int32_t getGlobalMetaState();
424 virtual void disableVirtualKeysUntil(nsecs_t time);
425 virtual bool shouldDropVirtualKey(nsecs_t now,
426 InputDevice* device, int32_t keyCode, int32_t scanCode);
427 virtual void fadePointer();
428 virtual void requestTimeoutAtTime(nsecs_t when);
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700429 virtual int32_t bumpGeneration();
Jeff Brownbe1aa822011-07-27 16:04:54 -0700430 virtual InputReaderPolicyInterface* getPolicy();
431 virtual InputListenerInterface* getListener();
432 virtual EventHubInterface* getEventHub();
433 } mContext;
434
435 friend class ContextImpl;
Jeff Brownc3db8582010-10-20 15:33:38 -0700436
Jeff Brown46b9ac02010-04-22 18:58:52 -0700437private:
Jeff Brownbe1aa822011-07-27 16:04:54 -0700438 Mutex mLock;
439
Jeff Brown112b5f52012-01-27 17:32:06 -0800440 Condition mReaderIsAliveCondition;
441
Jeff Brown46b9ac02010-04-22 18:58:52 -0700442 sp<EventHubInterface> mEventHub;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700443 sp<InputReaderPolicyInterface> mPolicy;
Jeff Brownbe1aa822011-07-27 16:04:54 -0700444 sp<QueuedInputListener> mQueuedListener;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700445
Jeff Brown214eaf42011-05-26 19:17:02 -0700446 InputReaderConfiguration mConfig;
447
Jeff Brownb7198742011-03-18 18:14:26 -0700448 // The event queue.
449 static const int EVENT_BUFFER_SIZE = 256;
450 RawEvent mEventBuffer[EVENT_BUFFER_SIZE];
451
Jeff Brown46b9ac02010-04-22 18:58:52 -0700452 KeyedVector<int32_t, InputDevice*> mDevices;
453
Jeff Brown6d0fec22010-07-23 21:28:06 -0700454 // low-level input event decoding and device management
Jeff Brownbe1aa822011-07-27 16:04:54 -0700455 void processEventsLocked(const RawEvent* rawEvents, size_t count);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700456
Jeff Brown65fd2512011-08-18 11:20:58 -0700457 void addDeviceLocked(nsecs_t when, int32_t deviceId);
458 void removeDeviceLocked(nsecs_t when, int32_t deviceId);
Jeff Brownbe1aa822011-07-27 16:04:54 -0700459 void processEventsForDeviceLocked(int32_t deviceId, const RawEvent* rawEvents, size_t count);
460 void timeoutExpiredLocked(nsecs_t when);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700461
Jeff Brownbe1aa822011-07-27 16:04:54 -0700462 void handleConfigurationChangedLocked(nsecs_t when);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700463
Jeff Brownbe1aa822011-07-27 16:04:54 -0700464 int32_t mGlobalMetaState;
465 void updateGlobalMetaStateLocked();
466 int32_t getGlobalMetaStateLocked();
Jeff Brown6d0fec22010-07-23 21:28:06 -0700467
Jeff Brownbe1aa822011-07-27 16:04:54 -0700468 void fadePointerLocked();
Jeff Brown6d0fec22010-07-23 21:28:06 -0700469
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700470 int32_t mGeneration;
471 int32_t bumpGenerationLocked();
472
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700473 void getInputDevicesLocked(Vector<InputDeviceInfo>& outInputDevices);
474
Jeff Brownbe1aa822011-07-27 16:04:54 -0700475 nsecs_t mDisableVirtualKeysTimeout;
476 void disableVirtualKeysUntilLocked(nsecs_t time);
477 bool shouldDropVirtualKeyLocked(nsecs_t now,
Jeff Brownfe508922011-01-18 15:10:10 -0800478 InputDevice* device, int32_t keyCode, int32_t scanCode);
479
Jeff Brownbe1aa822011-07-27 16:04:54 -0700480 nsecs_t mNextTimeout;
481 void requestTimeoutAtTimeLocked(nsecs_t when);
Jeff Brownaa3855d2011-03-17 01:34:19 -0700482
Jeff Brownbe1aa822011-07-27 16:04:54 -0700483 uint32_t mConfigurationChangesToRefresh;
484 void refreshConfigurationLocked(uint32_t changes);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700485
Jeff Brown6d0fec22010-07-23 21:28:06 -0700486 // state queries
487 typedef int32_t (InputDevice::*GetStateFunc)(uint32_t sourceMask, int32_t code);
Jeff Brownbe1aa822011-07-27 16:04:54 -0700488 int32_t getStateLocked(int32_t deviceId, uint32_t sourceMask, int32_t code,
Jeff Brown6d0fec22010-07-23 21:28:06 -0700489 GetStateFunc getStateFunc);
Jeff Brownbe1aa822011-07-27 16:04:54 -0700490 bool markSupportedKeyCodesLocked(int32_t deviceId, uint32_t sourceMask, size_t numCodes,
Jeff Brown6d0fec22010-07-23 21:28:06 -0700491 const int32_t* keyCodes, uint8_t* outFlags);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700492};
493
494
495/* Reads raw events from the event hub and processes them, endlessly. */
496class InputReaderThread : public Thread {
497public:
498 InputReaderThread(const sp<InputReaderInterface>& reader);
499 virtual ~InputReaderThread();
500
501private:
502 sp<InputReaderInterface> mReader;
503
504 virtual bool threadLoop();
505};
506
Jeff Brown6d0fec22010-07-23 21:28:06 -0700507
508/* Represents the state of a single input device. */
509class InputDevice {
510public:
Michael Wrightac6c78b2013-07-17 13:21:45 -0700511 InputDevice(InputReaderContext* context, int32_t id, int32_t generation, int32_t
512 controllerNumber, const InputDeviceIdentifier& identifier, uint32_t classes);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700513 ~InputDevice();
514
515 inline InputReaderContext* getContext() { return mContext; }
Michael Wrightac6c78b2013-07-17 13:21:45 -0700516 inline int32_t getId() const { return mId; }
517 inline int32_t getControllerNumber() const { return mControllerNumber; }
518 inline int32_t getGeneration() const { return mGeneration; }
519 inline const String8& getName() const { return mIdentifier.name; }
520 inline uint32_t getClasses() const { return mClasses; }
521 inline uint32_t getSources() const { return mSources; }
Jeff Brown6d0fec22010-07-23 21:28:06 -0700522
Jeff Brown56194eb2011-03-02 19:23:13 -0800523 inline bool isExternal() { return mIsExternal; }
524 inline void setExternal(bool external) { mIsExternal = external; }
525
Jeff Brown6d0fec22010-07-23 21:28:06 -0700526 inline bool isIgnored() { return mMappers.isEmpty(); }
527
Jeff Brownef3d7e82010-09-30 14:33:04 -0700528 void dump(String8& dump);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700529 void addMapper(InputMapper* mapper);
Jeff Brown65fd2512011-08-18 11:20:58 -0700530 void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
531 void reset(nsecs_t when);
Jeff Brownb7198742011-03-18 18:14:26 -0700532 void process(const RawEvent* rawEvents, size_t count);
Jeff Brownaa3855d2011-03-17 01:34:19 -0700533 void timeoutExpired(nsecs_t when);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700534
535 void getDeviceInfo(InputDeviceInfo* outDeviceInfo);
536 int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
537 int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
538 int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
539 bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
540 const int32_t* keyCodes, uint8_t* outFlags);
Jeff Browna47425a2012-04-13 04:09:27 -0700541 void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat, int32_t token);
542 void cancelVibrate(int32_t token);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700543
544 int32_t getMetaState();
545
Jeff Brown05dc66a2011-03-02 14:41:58 -0800546 void fadePointer();
547
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700548 void bumpGeneration();
549
Jeff Brown65fd2512011-08-18 11:20:58 -0700550 void notifyReset(nsecs_t when);
551
Jeff Brown49754db2011-07-01 17:37:58 -0700552 inline const PropertyMap& getConfiguration() { return mConfiguration; }
553 inline EventHubInterface* getEventHub() { return mContext->getEventHub(); }
Jeff Brown8d608662010-08-30 03:02:23 -0700554
Jeff Brown65fd2512011-08-18 11:20:58 -0700555 bool hasKey(int32_t code) {
556 return getEventHub()->hasScanCode(mId, code);
557 }
558
Jeff Brown00710e92012-04-19 15:18:26 -0700559 bool hasAbsoluteAxis(int32_t code) {
560 RawAbsoluteAxisInfo info;
561 getEventHub()->getAbsoluteAxisInfo(mId, code, &info);
562 return info.valid;
563 }
564
Jeff Brown65fd2512011-08-18 11:20:58 -0700565 bool isKeyPressed(int32_t code) {
566 return getEventHub()->getScanCodeState(mId, code) == AKEY_STATE_DOWN;
567 }
568
569 int32_t getAbsoluteAxisValue(int32_t code) {
570 int32_t value;
571 getEventHub()->getAbsoluteAxisValue(mId, code, &value);
572 return value;
573 }
574
Jeff Brown6d0fec22010-07-23 21:28:06 -0700575private:
576 InputReaderContext* mContext;
577 int32_t mId;
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700578 int32_t mGeneration;
Michael Wright67774c72013-09-25 14:13:40 -0700579 int32_t mControllerNumber;
Jeff Browne38fdfa2012-04-06 14:51:01 -0700580 InputDeviceIdentifier mIdentifier;
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700581 String8 mAlias;
Jeff Brown9ee285a2011-08-31 12:56:34 -0700582 uint32_t mClasses;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700583
584 Vector<InputMapper*> mMappers;
585
Jeff Brown6d0fec22010-07-23 21:28:06 -0700586 uint32_t mSources;
Jeff Brown56194eb2011-03-02 19:23:13 -0800587 bool mIsExternal;
Jeff Brown80fd47c2011-05-24 01:07:44 -0700588 bool mDropUntilNextSync;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700589
590 typedef int32_t (InputMapper::*GetStateFunc)(uint32_t sourceMask, int32_t code);
591 int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc);
Jeff Brown8d608662010-08-30 03:02:23 -0700592
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800593 PropertyMap mConfiguration;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700594};
595
596
Jeff Brown49754db2011-07-01 17:37:58 -0700597/* Keeps track of the state of mouse or touch pad buttons. */
598class CursorButtonAccumulator {
599public:
600 CursorButtonAccumulator();
Jeff Brown65fd2512011-08-18 11:20:58 -0700601 void reset(InputDevice* device);
Jeff Brown49754db2011-07-01 17:37:58 -0700602
Jeff Brown49754db2011-07-01 17:37:58 -0700603 void process(const RawEvent* rawEvent);
604
605 uint32_t getButtonState() const;
606
607private:
608 bool mBtnLeft;
609 bool mBtnRight;
610 bool mBtnMiddle;
611 bool mBtnBack;
612 bool mBtnSide;
613 bool mBtnForward;
614 bool mBtnExtra;
615 bool mBtnTask;
Jeff Brown65fd2512011-08-18 11:20:58 -0700616
617 void clearButtons();
Jeff Brown49754db2011-07-01 17:37:58 -0700618};
619
620
621/* Keeps track of cursor movements. */
622
623class CursorMotionAccumulator {
624public:
625 CursorMotionAccumulator();
Jeff Brown65fd2512011-08-18 11:20:58 -0700626 void reset(InputDevice* device);
627
628 void process(const RawEvent* rawEvent);
629 void finishSync();
630
631 inline int32_t getRelativeX() const { return mRelX; }
632 inline int32_t getRelativeY() const { return mRelY; }
633
634private:
635 int32_t mRelX;
636 int32_t mRelY;
Jeff Brown49754db2011-07-01 17:37:58 -0700637
638 void clearRelativeAxes();
Jeff Brown65fd2512011-08-18 11:20:58 -0700639};
640
641
642/* Keeps track of cursor scrolling motions. */
643
644class CursorScrollAccumulator {
645public:
646 CursorScrollAccumulator();
647 void configure(InputDevice* device);
648 void reset(InputDevice* device);
649
Jeff Brown49754db2011-07-01 17:37:58 -0700650 void process(const RawEvent* rawEvent);
Jeff Brown65fd2512011-08-18 11:20:58 -0700651 void finishSync();
Jeff Brown49754db2011-07-01 17:37:58 -0700652
653 inline bool haveRelativeVWheel() const { return mHaveRelWheel; }
654 inline bool haveRelativeHWheel() const { return mHaveRelHWheel; }
655
656 inline int32_t getRelativeX() const { return mRelX; }
657 inline int32_t getRelativeY() const { return mRelY; }
658 inline int32_t getRelativeVWheel() const { return mRelWheel; }
659 inline int32_t getRelativeHWheel() const { return mRelHWheel; }
660
661private:
662 bool mHaveRelWheel;
663 bool mHaveRelHWheel;
664
665 int32_t mRelX;
666 int32_t mRelY;
667 int32_t mRelWheel;
668 int32_t mRelHWheel;
Jeff Brown65fd2512011-08-18 11:20:58 -0700669
670 void clearRelativeAxes();
Jeff Brown49754db2011-07-01 17:37:58 -0700671};
672
673
674/* Keeps track of the state of touch, stylus and tool buttons. */
675class TouchButtonAccumulator {
676public:
677 TouchButtonAccumulator();
678 void configure(InputDevice* device);
Jeff Brown65fd2512011-08-18 11:20:58 -0700679 void reset(InputDevice* device);
Jeff Brown49754db2011-07-01 17:37:58 -0700680
Jeff Brown49754db2011-07-01 17:37:58 -0700681 void process(const RawEvent* rawEvent);
682
683 uint32_t getButtonState() const;
684 int32_t getToolType() const;
Jeff Brownd87c6d52011-08-10 14:55:59 -0700685 bool isToolActive() const;
Jeff Brown49754db2011-07-01 17:37:58 -0700686 bool isHovering() const;
Jeff Brown00710e92012-04-19 15:18:26 -0700687 bool hasStylus() const;
Jeff Brown49754db2011-07-01 17:37:58 -0700688
689private:
690 bool mHaveBtnTouch;
Jeff Brown00710e92012-04-19 15:18:26 -0700691 bool mHaveStylus;
Jeff Brown49754db2011-07-01 17:37:58 -0700692
693 bool mBtnTouch;
694 bool mBtnStylus;
695 bool mBtnStylus2;
696 bool mBtnToolFinger;
697 bool mBtnToolPen;
698 bool mBtnToolRubber;
Jeff Brown65fd2512011-08-18 11:20:58 -0700699 bool mBtnToolBrush;
700 bool mBtnToolPencil;
701 bool mBtnToolAirbrush;
702 bool mBtnToolMouse;
703 bool mBtnToolLens;
Jeff Brownea6892e2011-08-23 17:31:25 -0700704 bool mBtnToolDoubleTap;
705 bool mBtnToolTripleTap;
706 bool mBtnToolQuadTap;
Jeff Brown65fd2512011-08-18 11:20:58 -0700707
708 void clearButtons();
Jeff Brown49754db2011-07-01 17:37:58 -0700709};
710
711
Jeff Brownbe1aa822011-07-27 16:04:54 -0700712/* Raw axis information from the driver. */
713struct RawPointerAxes {
714 RawAbsoluteAxisInfo x;
715 RawAbsoluteAxisInfo y;
716 RawAbsoluteAxisInfo pressure;
717 RawAbsoluteAxisInfo touchMajor;
718 RawAbsoluteAxisInfo touchMinor;
719 RawAbsoluteAxisInfo toolMajor;
720 RawAbsoluteAxisInfo toolMinor;
721 RawAbsoluteAxisInfo orientation;
722 RawAbsoluteAxisInfo distance;
Jeff Brown65fd2512011-08-18 11:20:58 -0700723 RawAbsoluteAxisInfo tiltX;
724 RawAbsoluteAxisInfo tiltY;
Jeff Brownbe1aa822011-07-27 16:04:54 -0700725 RawAbsoluteAxisInfo trackingId;
726 RawAbsoluteAxisInfo slot;
727
728 RawPointerAxes();
729 void clear();
730};
731
732
733/* Raw data for a collection of pointers including a pointer id mapping table. */
734struct RawPointerData {
735 struct Pointer {
736 uint32_t id;
737 int32_t x;
738 int32_t y;
739 int32_t pressure;
740 int32_t touchMajor;
741 int32_t touchMinor;
742 int32_t toolMajor;
743 int32_t toolMinor;
744 int32_t orientation;
745 int32_t distance;
Jeff Brown65fd2512011-08-18 11:20:58 -0700746 int32_t tiltX;
747 int32_t tiltY;
Jeff Brownbe1aa822011-07-27 16:04:54 -0700748 int32_t toolType; // a fully decoded AMOTION_EVENT_TOOL_TYPE constant
749 bool isHovering;
750 };
751
752 uint32_t pointerCount;
753 Pointer pointers[MAX_POINTERS];
754 BitSet32 hoveringIdBits, touchingIdBits;
755 uint32_t idToIndex[MAX_POINTER_ID + 1];
756
757 RawPointerData();
758 void clear();
759 void copyFrom(const RawPointerData& other);
760 void getCentroidOfTouchingPointers(float* outX, float* outY) const;
761
762 inline void markIdBit(uint32_t id, bool isHovering) {
763 if (isHovering) {
764 hoveringIdBits.markBit(id);
765 } else {
766 touchingIdBits.markBit(id);
767 }
768 }
769
770 inline void clearIdBits() {
771 hoveringIdBits.clear();
772 touchingIdBits.clear();
773 }
774
775 inline const Pointer& pointerForId(uint32_t id) const {
776 return pointers[idToIndex[id]];
777 }
778
779 inline bool isHovering(uint32_t pointerIndex) {
780 return pointers[pointerIndex].isHovering;
781 }
782};
783
784
785/* Cooked data for a collection of pointers including a pointer id mapping table. */
786struct CookedPointerData {
787 uint32_t pointerCount;
788 PointerProperties pointerProperties[MAX_POINTERS];
789 PointerCoords pointerCoords[MAX_POINTERS];
790 BitSet32 hoveringIdBits, touchingIdBits;
791 uint32_t idToIndex[MAX_POINTER_ID + 1];
792
793 CookedPointerData();
794 void clear();
795 void copyFrom(const CookedPointerData& other);
796
Jeff Brown4dac9012013-04-10 01:03:19 -0700797 inline const PointerCoords& pointerCoordsForId(uint32_t id) const {
798 return pointerCoords[idToIndex[id]];
799 }
800
Jeff Brownbe1aa822011-07-27 16:04:54 -0700801 inline bool isHovering(uint32_t pointerIndex) {
802 return hoveringIdBits.hasBit(pointerProperties[pointerIndex].id);
803 }
804};
805
806
Jeff Brown49754db2011-07-01 17:37:58 -0700807/* Keeps track of the state of single-touch protocol. */
808class SingleTouchMotionAccumulator {
809public:
810 SingleTouchMotionAccumulator();
811
Jeff Brown49754db2011-07-01 17:37:58 -0700812 void process(const RawEvent* rawEvent);
Jeff Brown65fd2512011-08-18 11:20:58 -0700813 void reset(InputDevice* device);
Jeff Brown49754db2011-07-01 17:37:58 -0700814
815 inline int32_t getAbsoluteX() const { return mAbsX; }
816 inline int32_t getAbsoluteY() const { return mAbsY; }
817 inline int32_t getAbsolutePressure() const { return mAbsPressure; }
818 inline int32_t getAbsoluteToolWidth() const { return mAbsToolWidth; }
819 inline int32_t getAbsoluteDistance() const { return mAbsDistance; }
Jeff Brown65fd2512011-08-18 11:20:58 -0700820 inline int32_t getAbsoluteTiltX() const { return mAbsTiltX; }
821 inline int32_t getAbsoluteTiltY() const { return mAbsTiltY; }
Jeff Brown49754db2011-07-01 17:37:58 -0700822
823private:
824 int32_t mAbsX;
825 int32_t mAbsY;
826 int32_t mAbsPressure;
827 int32_t mAbsToolWidth;
828 int32_t mAbsDistance;
Jeff Brown65fd2512011-08-18 11:20:58 -0700829 int32_t mAbsTiltX;
830 int32_t mAbsTiltY;
831
832 void clearAbsoluteAxes();
Jeff Brown49754db2011-07-01 17:37:58 -0700833};
834
835
836/* Keeps track of the state of multi-touch protocol. */
837class MultiTouchMotionAccumulator {
838public:
839 class Slot {
840 public:
841 inline bool isInUse() const { return mInUse; }
842 inline int32_t getX() const { return mAbsMTPositionX; }
843 inline int32_t getY() const { return mAbsMTPositionY; }
844 inline int32_t getTouchMajor() const { return mAbsMTTouchMajor; }
845 inline int32_t getTouchMinor() const {
846 return mHaveAbsMTTouchMinor ? mAbsMTTouchMinor : mAbsMTTouchMajor; }
847 inline int32_t getToolMajor() const { return mAbsMTWidthMajor; }
848 inline int32_t getToolMinor() const {
849 return mHaveAbsMTWidthMinor ? mAbsMTWidthMinor : mAbsMTWidthMajor; }
850 inline int32_t getOrientation() const { return mAbsMTOrientation; }
851 inline int32_t getTrackingId() const { return mAbsMTTrackingId; }
852 inline int32_t getPressure() const { return mAbsMTPressure; }
853 inline int32_t getDistance() const { return mAbsMTDistance; }
854 inline int32_t getToolType() const;
855
856 private:
857 friend class MultiTouchMotionAccumulator;
858
859 bool mInUse;
860 bool mHaveAbsMTTouchMinor;
861 bool mHaveAbsMTWidthMinor;
862 bool mHaveAbsMTToolType;
863
864 int32_t mAbsMTPositionX;
865 int32_t mAbsMTPositionY;
866 int32_t mAbsMTTouchMajor;
867 int32_t mAbsMTTouchMinor;
868 int32_t mAbsMTWidthMajor;
869 int32_t mAbsMTWidthMinor;
870 int32_t mAbsMTOrientation;
871 int32_t mAbsMTTrackingId;
872 int32_t mAbsMTPressure;
Jeff Brown49754db2011-07-01 17:37:58 -0700873 int32_t mAbsMTDistance;
Jeff Brownbe1aa822011-07-27 16:04:54 -0700874 int32_t mAbsMTToolType;
Jeff Brown49754db2011-07-01 17:37:58 -0700875
876 Slot();
Jeff Brown49754db2011-07-01 17:37:58 -0700877 void clear();
878 };
879
880 MultiTouchMotionAccumulator();
881 ~MultiTouchMotionAccumulator();
882
Jeff Brown00710e92012-04-19 15:18:26 -0700883 void configure(InputDevice* device, size_t slotCount, bool usingSlotsProtocol);
Jeff Brown65fd2512011-08-18 11:20:58 -0700884 void reset(InputDevice* device);
Jeff Brown49754db2011-07-01 17:37:58 -0700885 void process(const RawEvent* rawEvent);
Jeff Brown65fd2512011-08-18 11:20:58 -0700886 void finishSync();
Jeff Brown00710e92012-04-19 15:18:26 -0700887 bool hasStylus() const;
Jeff Brown49754db2011-07-01 17:37:58 -0700888
Jeff Brown49754db2011-07-01 17:37:58 -0700889 inline size_t getSlotCount() const { return mSlotCount; }
890 inline const Slot* getSlot(size_t index) const { return &mSlots[index]; }
891
892private:
893 int32_t mCurrentSlot;
894 Slot* mSlots;
895 size_t mSlotCount;
896 bool mUsingSlotsProtocol;
Jeff Brown00710e92012-04-19 15:18:26 -0700897 bool mHaveStylus;
Jeff Brown65fd2512011-08-18 11:20:58 -0700898
899 void clearSlots(int32_t initialSlot);
Jeff Brown49754db2011-07-01 17:37:58 -0700900};
901
902
Jeff Brown6d0fec22010-07-23 21:28:06 -0700903/* An input mapper transforms raw input events into cooked event data.
904 * A single input device can have multiple associated input mappers in order to interpret
905 * different classes of events.
Jeff Brown65fd2512011-08-18 11:20:58 -0700906 *
907 * InputMapper lifecycle:
908 * - create
909 * - configure with 0 changes
910 * - reset
911 * - process, process, process (may occasionally reconfigure with non-zero changes or reset)
912 * - reset
913 * - destroy
Jeff Brown6d0fec22010-07-23 21:28:06 -0700914 */
915class InputMapper {
916public:
917 InputMapper(InputDevice* device);
918 virtual ~InputMapper();
919
920 inline InputDevice* getDevice() { return mDevice; }
921 inline int32_t getDeviceId() { return mDevice->getId(); }
922 inline const String8 getDeviceName() { return mDevice->getName(); }
923 inline InputReaderContext* getContext() { return mContext; }
924 inline InputReaderPolicyInterface* getPolicy() { return mContext->getPolicy(); }
Jeff Brownbe1aa822011-07-27 16:04:54 -0700925 inline InputListenerInterface* getListener() { return mContext->getListener(); }
Jeff Brown6d0fec22010-07-23 21:28:06 -0700926 inline EventHubInterface* getEventHub() { return mContext->getEventHub(); }
927
928 virtual uint32_t getSources() = 0;
929 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
Jeff Brownef3d7e82010-09-30 14:33:04 -0700930 virtual void dump(String8& dump);
Jeff Brown65fd2512011-08-18 11:20:58 -0700931 virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
932 virtual void reset(nsecs_t when);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700933 virtual void process(const RawEvent* rawEvent) = 0;
Jeff Brownaa3855d2011-03-17 01:34:19 -0700934 virtual void timeoutExpired(nsecs_t when);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700935
936 virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
937 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
938 virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
939 virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
940 const int32_t* keyCodes, uint8_t* outFlags);
Jeff Browna47425a2012-04-13 04:09:27 -0700941 virtual void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat,
942 int32_t token);
943 virtual void cancelVibrate(int32_t token);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700944
945 virtual int32_t getMetaState();
946
Jeff Brown05dc66a2011-03-02 14:41:58 -0800947 virtual void fadePointer();
948
Jeff Brown6d0fec22010-07-23 21:28:06 -0700949protected:
950 InputDevice* mDevice;
951 InputReaderContext* mContext;
Jeff Browncb1404e2011-01-15 18:14:15 -0800952
Jeff Brownbe1aa822011-07-27 16:04:54 -0700953 status_t getAbsoluteAxisInfo(int32_t axis, RawAbsoluteAxisInfo* axisInfo);
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700954 void bumpGeneration();
Jeff Brownbe1aa822011-07-27 16:04:54 -0700955
Jeff Browncb1404e2011-01-15 18:14:15 -0800956 static void dumpRawAbsoluteAxisInfo(String8& dump,
957 const RawAbsoluteAxisInfo& axis, const char* name);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700958};
959
960
961class SwitchInputMapper : public InputMapper {
962public:
963 SwitchInputMapper(InputDevice* device);
964 virtual ~SwitchInputMapper();
965
966 virtual uint32_t getSources();
967 virtual void process(const RawEvent* rawEvent);
968
969 virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
970
971private:
Jeff Brownbcc046a2012-09-27 20:46:43 -0700972 uint32_t mUpdatedSwitchValues;
973 uint32_t mUpdatedSwitchMask;
974
975 void processSwitch(int32_t switchCode, int32_t switchValue);
976 void sync(nsecs_t when);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700977};
978
979
Jeff Browna47425a2012-04-13 04:09:27 -0700980class VibratorInputMapper : public InputMapper {
981public:
982 VibratorInputMapper(InputDevice* device);
983 virtual ~VibratorInputMapper();
984
985 virtual uint32_t getSources();
986 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
987 virtual void process(const RawEvent* rawEvent);
988
989 virtual void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat,
990 int32_t token);
991 virtual void cancelVibrate(int32_t token);
992 virtual void timeoutExpired(nsecs_t when);
993 virtual void dump(String8& dump);
994
995private:
996 bool mVibrating;
997 nsecs_t mPattern[MAX_VIBRATE_PATTERN_SIZE];
998 size_t mPatternSize;
999 ssize_t mRepeat;
1000 int32_t mToken;
1001 ssize_t mIndex;
1002 nsecs_t mNextStepTime;
1003
1004 void nextStep();
1005 void stopVibrating();
1006};
1007
1008
Jeff Brown6d0fec22010-07-23 21:28:06 -07001009class KeyboardInputMapper : public InputMapper {
1010public:
Jeff Brownefd32662011-03-08 15:13:06 -08001011 KeyboardInputMapper(InputDevice* device, uint32_t source, int32_t keyboardType);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001012 virtual ~KeyboardInputMapper();
1013
1014 virtual uint32_t getSources();
1015 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
Jeff Brownef3d7e82010-09-30 14:33:04 -07001016 virtual void dump(String8& dump);
Jeff Brown65fd2512011-08-18 11:20:58 -07001017 virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
1018 virtual void reset(nsecs_t when);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001019 virtual void process(const RawEvent* rawEvent);
1020
1021 virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
1022 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
1023 virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
1024 const int32_t* keyCodes, uint8_t* outFlags);
1025
1026 virtual int32_t getMetaState();
1027
1028private:
1029 struct KeyDown {
1030 int32_t keyCode;
1031 int32_t scanCode;
1032 };
1033
Jeff Brownefd32662011-03-08 15:13:06 -08001034 uint32_t mSource;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001035 int32_t mKeyboardType;
1036
Jeff Brown65fd2512011-08-18 11:20:58 -07001037 int32_t mOrientation; // orientation for dpad keys
1038
Jeff Brownbe1aa822011-07-27 16:04:54 -07001039 Vector<KeyDown> mKeyDowns; // keys that are down
1040 int32_t mMetaState;
1041 nsecs_t mDownTime; // time of most recent key down
1042
Jeff Brown49ccac52012-04-11 18:27:33 -07001043 int32_t mCurrentHidUsage; // most recent HID usage seen this packet, or 0 if none
1044
Jeff Brownbe1aa822011-07-27 16:04:54 -07001045 struct LedState {
1046 bool avail; // led is available
1047 bool on; // we think the led is currently on
1048 };
1049 LedState mCapsLockLedState;
1050 LedState mNumLockLedState;
1051 LedState mScrollLockLedState;
1052
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001053 // Immutable configuration parameters.
1054 struct Parameters {
Jeff Brownd728bf52012-09-08 18:05:28 -07001055 bool hasAssociatedDisplay;
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001056 bool orientationAware;
1057 } mParameters;
1058
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001059 void configureParameters();
1060 void dumpParameters(String8& dump);
1061
Jeff Brown6d0fec22010-07-23 21:28:06 -07001062 bool isKeyboardOrGamepadKey(int32_t scanCode);
Jeff Brown6328cdc2010-07-29 18:18:33 -07001063
Jeff Brown6d0fec22010-07-23 21:28:06 -07001064 void processKey(nsecs_t when, bool down, int32_t keyCode, int32_t scanCode,
1065 uint32_t policyFlags);
1066
Jeff Brownbe1aa822011-07-27 16:04:54 -07001067 ssize_t findKeyDown(int32_t scanCode);
Jeff Brown497a92c2010-09-12 17:55:08 -07001068
Jeff Brownbe1aa822011-07-27 16:04:54 -07001069 void resetLedState();
1070 void initializeLedState(LedState& ledState, int32_t led);
1071 void updateLedState(bool reset);
1072 void updateLedStateForModifier(LedState& ledState, int32_t led,
Jeff Brown497a92c2010-09-12 17:55:08 -07001073 int32_t modifier, bool reset);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001074};
1075
1076
Jeff Brown83c09682010-12-23 17:50:18 -08001077class CursorInputMapper : public InputMapper {
Jeff Brown6d0fec22010-07-23 21:28:06 -07001078public:
Jeff Brown83c09682010-12-23 17:50:18 -08001079 CursorInputMapper(InputDevice* device);
1080 virtual ~CursorInputMapper();
Jeff Brown6d0fec22010-07-23 21:28:06 -07001081
1082 virtual uint32_t getSources();
1083 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
Jeff Brownef3d7e82010-09-30 14:33:04 -07001084 virtual void dump(String8& dump);
Jeff Brown65fd2512011-08-18 11:20:58 -07001085 virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
1086 virtual void reset(nsecs_t when);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001087 virtual void process(const RawEvent* rawEvent);
1088
Jeff Brownc3fc2d02010-08-10 15:47:53 -07001089 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
1090
Jeff Brown05dc66a2011-03-02 14:41:58 -08001091 virtual void fadePointer();
1092
Jeff Brown6d0fec22010-07-23 21:28:06 -07001093private:
1094 // Amount that trackball needs to move in order to generate a key event.
1095 static const int32_t TRACKBALL_MOVEMENT_THRESHOLD = 6;
1096
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001097 // Immutable configuration parameters.
1098 struct Parameters {
Jeff Brown83c09682010-12-23 17:50:18 -08001099 enum Mode {
1100 MODE_POINTER,
1101 MODE_NAVIGATION,
1102 };
1103
1104 Mode mode;
Jeff Brownd728bf52012-09-08 18:05:28 -07001105 bool hasAssociatedDisplay;
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001106 bool orientationAware;
1107 } mParameters;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001108
Jeff Brown49754db2011-07-01 17:37:58 -07001109 CursorButtonAccumulator mCursorButtonAccumulator;
1110 CursorMotionAccumulator mCursorMotionAccumulator;
Jeff Brown65fd2512011-08-18 11:20:58 -07001111 CursorScrollAccumulator mCursorScrollAccumulator;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001112
Jeff Brownefd32662011-03-08 15:13:06 -08001113 int32_t mSource;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001114 float mXScale;
1115 float mYScale;
1116 float mXPrecision;
1117 float mYPrecision;
Jeff Brown6f2fba42011-02-19 01:08:02 -08001118
Jeff Brown6f2fba42011-02-19 01:08:02 -08001119 float mVWheelScale;
1120 float mHWheelScale;
1121
Jeff Brown19c97d462011-06-01 12:33:19 -07001122 // Velocity controls for mouse pointer and wheel movements.
1123 // The controls for X and Y wheel movements are separate to keep them decoupled.
1124 VelocityControl mPointerVelocityControl;
1125 VelocityControl mWheelXVelocityControl;
1126 VelocityControl mWheelYVelocityControl;
1127
Jeff Brown65fd2512011-08-18 11:20:58 -07001128 int32_t mOrientation;
1129
Jeff Brown83c09682010-12-23 17:50:18 -08001130 sp<PointerControllerInterface> mPointerController;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001131
Jeff Brownbe1aa822011-07-27 16:04:54 -07001132 int32_t mButtonState;
1133 nsecs_t mDownTime;
Jeff Brown6328cdc2010-07-29 18:18:33 -07001134
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001135 void configureParameters();
1136 void dumpParameters(String8& dump);
1137
Jeff Brown6d0fec22010-07-23 21:28:06 -07001138 void sync(nsecs_t when);
1139};
1140
1141
1142class TouchInputMapper : public InputMapper {
1143public:
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001144 TouchInputMapper(InputDevice* device);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001145 virtual ~TouchInputMapper();
1146
1147 virtual uint32_t getSources();
1148 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
Jeff Brownef3d7e82010-09-30 14:33:04 -07001149 virtual void dump(String8& dump);
Jeff Brown65fd2512011-08-18 11:20:58 -07001150 virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
1151 virtual void reset(nsecs_t when);
1152 virtual void process(const RawEvent* rawEvent);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001153
1154 virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
1155 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
1156 virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
1157 const int32_t* keyCodes, uint8_t* outFlags);
1158
Jeff Brownace13b12011-03-09 17:39:48 -08001159 virtual void fadePointer();
Jeff Brown79ac9692011-04-19 21:20:10 -07001160 virtual void timeoutExpired(nsecs_t when);
Jeff Brownace13b12011-03-09 17:39:48 -08001161
Jeff Brown6d0fec22010-07-23 21:28:06 -07001162protected:
Jeff Brown65fd2512011-08-18 11:20:58 -07001163 CursorButtonAccumulator mCursorButtonAccumulator;
1164 CursorScrollAccumulator mCursorScrollAccumulator;
1165 TouchButtonAccumulator mTouchButtonAccumulator;
1166
Jeff Brown6d0fec22010-07-23 21:28:06 -07001167 struct VirtualKey {
1168 int32_t keyCode;
1169 int32_t scanCode;
1170 uint32_t flags;
1171
1172 // computed hit box, specified in touch screen coords based on known display size
1173 int32_t hitLeft;
1174 int32_t hitTop;
1175 int32_t hitRight;
1176 int32_t hitBottom;
1177
1178 inline bool isHit(int32_t x, int32_t y) const {
1179 return x >= hitLeft && x <= hitRight && y >= hitTop && y <= hitBottom;
1180 }
1181 };
1182
Jeff Brown65fd2512011-08-18 11:20:58 -07001183 // Input sources and device mode.
1184 uint32_t mSource;
1185
1186 enum DeviceMode {
1187 DEVICE_MODE_DISABLED, // input is disabled
1188 DEVICE_MODE_DIRECT, // direct mapping (touchscreen)
1189 DEVICE_MODE_UNSCALED, // unscaled mapping (touchpad)
Jeff Brown4dac9012013-04-10 01:03:19 -07001190 DEVICE_MODE_NAVIGATION, // unscaled mapping with assist gesture (touch navigation)
Jeff Brown65fd2512011-08-18 11:20:58 -07001191 DEVICE_MODE_POINTER, // pointer mapping (pointer)
1192 };
1193 DeviceMode mDeviceMode;
Jeff Brown83c09682010-12-23 17:50:18 -08001194
Jeff Brown214eaf42011-05-26 19:17:02 -07001195 // The reader's configuration.
Jeff Brown474dcb52011-06-14 20:22:50 -07001196 InputReaderConfiguration mConfig;
Jeff Brown214eaf42011-05-26 19:17:02 -07001197
Jeff Brown6d0fec22010-07-23 21:28:06 -07001198 // Immutable configuration parameters.
1199 struct Parameters {
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001200 enum DeviceType {
1201 DEVICE_TYPE_TOUCH_SCREEN,
1202 DEVICE_TYPE_TOUCH_PAD,
Michael Wrighte7a9ae82013-03-08 15:19:19 -08001203 DEVICE_TYPE_TOUCH_NAVIGATION,
Jeff Brownace13b12011-03-09 17:39:48 -08001204 DEVICE_TYPE_POINTER,
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001205 };
1206
1207 DeviceType deviceType;
Jeff Brownd728bf52012-09-08 18:05:28 -07001208 bool hasAssociatedDisplay;
Jeff Brownbc68a592011-07-25 12:58:12 -07001209 bool associatedDisplayIsExternal;
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001210 bool orientationAware;
Michael Wright7ddd1102013-05-20 15:04:55 -07001211 bool hasButtonUnderPad;
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001212
Jeff Brown2352b972011-04-12 22:39:53 -07001213 enum GestureMode {
1214 GESTURE_MODE_POINTER,
1215 GESTURE_MODE_SPOTS,
1216 };
1217 GestureMode gestureMode;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001218 } mParameters;
1219
Jeff Brown8d608662010-08-30 03:02:23 -07001220 // Immutable calibration parameters in parsed form.
1221 struct Calibration {
Jeff Browna1f89ce2011-08-11 00:05:01 -07001222 // Size
1223 enum SizeCalibration {
1224 SIZE_CALIBRATION_DEFAULT,
1225 SIZE_CALIBRATION_NONE,
1226 SIZE_CALIBRATION_GEOMETRIC,
1227 SIZE_CALIBRATION_DIAMETER,
Jeff Brown037f7272012-06-25 17:31:23 -07001228 SIZE_CALIBRATION_BOX,
Jeff Browna1f89ce2011-08-11 00:05:01 -07001229 SIZE_CALIBRATION_AREA,
Jeff Brown8d608662010-08-30 03:02:23 -07001230 };
1231
Jeff Browna1f89ce2011-08-11 00:05:01 -07001232 SizeCalibration sizeCalibration;
Jeff Brown8d608662010-08-30 03:02:23 -07001233
Jeff Browna1f89ce2011-08-11 00:05:01 -07001234 bool haveSizeScale;
1235 float sizeScale;
1236 bool haveSizeBias;
1237 float sizeBias;
1238 bool haveSizeIsSummed;
1239 bool sizeIsSummed;
Jeff Brown8d608662010-08-30 03:02:23 -07001240
1241 // Pressure
1242 enum PressureCalibration {
1243 PRESSURE_CALIBRATION_DEFAULT,
1244 PRESSURE_CALIBRATION_NONE,
1245 PRESSURE_CALIBRATION_PHYSICAL,
1246 PRESSURE_CALIBRATION_AMPLITUDE,
1247 };
Jeff Brown8d608662010-08-30 03:02:23 -07001248
1249 PressureCalibration pressureCalibration;
Jeff Brown8d608662010-08-30 03:02:23 -07001250 bool havePressureScale;
1251 float pressureScale;
1252
Jeff Brown8d608662010-08-30 03:02:23 -07001253 // Orientation
1254 enum OrientationCalibration {
1255 ORIENTATION_CALIBRATION_DEFAULT,
1256 ORIENTATION_CALIBRATION_NONE,
1257 ORIENTATION_CALIBRATION_INTERPOLATED,
Jeff Brown517bb4c2011-01-14 19:09:23 -08001258 ORIENTATION_CALIBRATION_VECTOR,
Jeff Brown8d608662010-08-30 03:02:23 -07001259 };
1260
1261 OrientationCalibration orientationCalibration;
Jeff Brown80fd47c2011-05-24 01:07:44 -07001262
1263 // Distance
1264 enum DistanceCalibration {
1265 DISTANCE_CALIBRATION_DEFAULT,
1266 DISTANCE_CALIBRATION_NONE,
1267 DISTANCE_CALIBRATION_SCALED,
1268 };
1269
1270 DistanceCalibration distanceCalibration;
1271 bool haveDistanceScale;
1272 float distanceScale;
Jeff Browna1f89ce2011-08-11 00:05:01 -07001273
Michael Wright86172f62013-05-15 23:16:54 -07001274 enum CoverageCalibration {
1275 COVERAGE_CALIBRATION_DEFAULT,
1276 COVERAGE_CALIBRATION_NONE,
1277 COVERAGE_CALIBRATION_BOX,
1278 };
1279
1280 CoverageCalibration coverageCalibration;
1281
Jeff Browna1f89ce2011-08-11 00:05:01 -07001282 inline void applySizeScaleAndBias(float* outSize) const {
1283 if (haveSizeScale) {
1284 *outSize *= sizeScale;
1285 }
1286 if (haveSizeBias) {
1287 *outSize += sizeBias;
1288 }
Michael Wrighteeadb322013-08-14 13:44:23 -07001289 if (*outSize < 0) {
1290 *outSize = 0;
1291 }
Jeff Browna1f89ce2011-08-11 00:05:01 -07001292 }
Jeff Brown8d608662010-08-30 03:02:23 -07001293 } mCalibration;
1294
Jeff Brownbe1aa822011-07-27 16:04:54 -07001295 // Raw pointer axis information from the driver.
1296 RawPointerAxes mRawPointerAxes;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001297
Jeff Brownbe1aa822011-07-27 16:04:54 -07001298 // Raw pointer sample data.
1299 RawPointerData mCurrentRawPointerData;
1300 RawPointerData mLastRawPointerData;
Jeff Brownace13b12011-03-09 17:39:48 -08001301
Jeff Brownbe1aa822011-07-27 16:04:54 -07001302 // Cooked pointer sample data.
1303 CookedPointerData mCurrentCookedPointerData;
1304 CookedPointerData mLastCookedPointerData;
1305
1306 // Button state.
1307 int32_t mCurrentButtonState;
1308 int32_t mLastButtonState;
1309
Jeff Brown65fd2512011-08-18 11:20:58 -07001310 // Scroll state.
1311 int32_t mCurrentRawVScroll;
1312 int32_t mCurrentRawHScroll;
1313
1314 // Id bits used to differentiate fingers, stylus and mouse tools.
1315 BitSet32 mCurrentFingerIdBits; // finger or unknown
1316 BitSet32 mLastFingerIdBits;
1317 BitSet32 mCurrentStylusIdBits; // stylus or eraser
1318 BitSet32 mLastStylusIdBits;
1319 BitSet32 mCurrentMouseIdBits; // mouse or lens
1320 BitSet32 mLastMouseIdBits;
1321
Jeff Brownbe1aa822011-07-27 16:04:54 -07001322 // True if we sent a HOVER_ENTER event.
1323 bool mSentHoverEnter;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001324
1325 // The time the primary pointer last went down.
1326 nsecs_t mDownTime;
1327
Jeff Brownace13b12011-03-09 17:39:48 -08001328 // The pointer controller, or null if the device is not a pointer.
1329 sp<PointerControllerInterface> mPointerController;
1330
Jeff Brownbe1aa822011-07-27 16:04:54 -07001331 Vector<VirtualKey> mVirtualKeys;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001332
Jeff Brown8d608662010-08-30 03:02:23 -07001333 virtual void configureParameters();
Jeff Brownef3d7e82010-09-30 14:33:04 -07001334 virtual void dumpParameters(String8& dump);
Jeff Brownbe1aa822011-07-27 16:04:54 -07001335 virtual void configureRawPointerAxes();
1336 virtual void dumpRawPointerAxes(String8& dump);
Jeff Brown65fd2512011-08-18 11:20:58 -07001337 virtual void configureSurface(nsecs_t when, bool* outResetNeeded);
Jeff Brownbe1aa822011-07-27 16:04:54 -07001338 virtual void dumpSurface(String8& dump);
1339 virtual void configureVirtualKeys();
1340 virtual void dumpVirtualKeys(String8& dump);
Jeff Brown8d608662010-08-30 03:02:23 -07001341 virtual void parseCalibration();
1342 virtual void resolveCalibration();
Jeff Brownef3d7e82010-09-30 14:33:04 -07001343 virtual void dumpCalibration(String8& dump);
Jeff Brown00710e92012-04-19 15:18:26 -07001344 virtual bool hasStylus() const = 0;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001345
Jeff Brown65fd2512011-08-18 11:20:58 -07001346 virtual void syncTouch(nsecs_t when, bool* outHavePointerIds) = 0;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001347
1348private:
Jeff Brown83d616a2012-09-09 20:33:43 -07001349 // The current viewport.
1350 // The components of the viewport are specified in the display's rotated orientation.
1351 DisplayViewport mViewport;
1352
1353 // The surface orientation, width and height set by configureSurface().
1354 // The width and height are derived from the viewport but are specified
1355 // in the natural orientation.
1356 // The surface origin specifies how the surface coordinates should be translated
1357 // to align with the logical display coordinate space.
1358 // The orientation may be different from the viewport orientation as it specifies
1359 // the rotation of the surface coordinates required to produce the viewport's
1360 // requested orientation, so it will depend on whether the device is orientation aware.
Jeff Brownbe1aa822011-07-27 16:04:54 -07001361 int32_t mSurfaceWidth;
1362 int32_t mSurfaceHeight;
Jeff Brown83d616a2012-09-09 20:33:43 -07001363 int32_t mSurfaceLeft;
1364 int32_t mSurfaceTop;
1365 int32_t mSurfaceOrientation;
Jeff Brownbe1aa822011-07-27 16:04:54 -07001366
1367 // Translation and scaling factors, orientation-independent.
Jeff Brown83d616a2012-09-09 20:33:43 -07001368 float mXTranslate;
Jeff Brownbe1aa822011-07-27 16:04:54 -07001369 float mXScale;
1370 float mXPrecision;
1371
Jeff Brown83d616a2012-09-09 20:33:43 -07001372 float mYTranslate;
Jeff Brownbe1aa822011-07-27 16:04:54 -07001373 float mYScale;
1374 float mYPrecision;
1375
1376 float mGeometricScale;
1377
Jeff Brownbe1aa822011-07-27 16:04:54 -07001378 float mPressureScale;
1379
1380 float mSizeScale;
1381
1382 float mOrientationScale;
1383
1384 float mDistanceScale;
1385
Jeff Brown65fd2512011-08-18 11:20:58 -07001386 bool mHaveTilt;
1387 float mTiltXCenter;
1388 float mTiltXScale;
1389 float mTiltYCenter;
1390 float mTiltYScale;
1391
Jeff Brownbe1aa822011-07-27 16:04:54 -07001392 // Oriented motion ranges for input device info.
1393 struct OrientedRanges {
1394 InputDeviceInfo::MotionRange x;
1395 InputDeviceInfo::MotionRange y;
Jeff Brownbe1aa822011-07-27 16:04:54 -07001396 InputDeviceInfo::MotionRange pressure;
1397
1398 bool haveSize;
1399 InputDeviceInfo::MotionRange size;
1400
1401 bool haveTouchSize;
1402 InputDeviceInfo::MotionRange touchMajor;
1403 InputDeviceInfo::MotionRange touchMinor;
1404
1405 bool haveToolSize;
1406 InputDeviceInfo::MotionRange toolMajor;
1407 InputDeviceInfo::MotionRange toolMinor;
1408
1409 bool haveOrientation;
1410 InputDeviceInfo::MotionRange orientation;
1411
1412 bool haveDistance;
1413 InputDeviceInfo::MotionRange distance;
Jeff Brown65fd2512011-08-18 11:20:58 -07001414
1415 bool haveTilt;
1416 InputDeviceInfo::MotionRange tilt;
1417
1418 OrientedRanges() {
1419 clear();
1420 }
1421
1422 void clear() {
1423 haveSize = false;
1424 haveTouchSize = false;
1425 haveToolSize = false;
1426 haveOrientation = false;
1427 haveDistance = false;
1428 haveTilt = false;
1429 }
Jeff Brownbe1aa822011-07-27 16:04:54 -07001430 } mOrientedRanges;
1431
1432 // Oriented dimensions and precision.
Jeff Brownbe1aa822011-07-27 16:04:54 -07001433 float mOrientedXPrecision;
1434 float mOrientedYPrecision;
1435
1436 struct CurrentVirtualKeyState {
1437 bool down;
1438 bool ignored;
1439 nsecs_t downTime;
1440 int32_t keyCode;
1441 int32_t scanCode;
1442 } mCurrentVirtualKey;
1443
Jeff Brown65fd2512011-08-18 11:20:58 -07001444 // Scale factor for gesture or mouse based pointer movements.
1445 float mPointerXMovementScale;
1446 float mPointerYMovementScale;
Jeff Brownbe1aa822011-07-27 16:04:54 -07001447
1448 // Scale factor for gesture based zooming and other freeform motions.
Jeff Brown65fd2512011-08-18 11:20:58 -07001449 float mPointerXZoomScale;
1450 float mPointerYZoomScale;
Jeff Brownbe1aa822011-07-27 16:04:54 -07001451
1452 // The maximum swipe width.
1453 float mPointerGestureMaxSwipeWidth;
1454
Jeff Brown6d0fec22010-07-23 21:28:06 -07001455 struct PointerDistanceHeapElement {
1456 uint32_t currentPointerIndex : 8;
1457 uint32_t lastPointerIndex : 8;
1458 uint64_t distance : 48; // squared distance
1459 };
1460
Jeff Brown65fd2512011-08-18 11:20:58 -07001461 enum PointerUsage {
1462 POINTER_USAGE_NONE,
1463 POINTER_USAGE_GESTURES,
1464 POINTER_USAGE_STYLUS,
1465 POINTER_USAGE_MOUSE,
1466 };
1467 PointerUsage mPointerUsage;
1468
Jeff Brownace13b12011-03-09 17:39:48 -08001469 struct PointerGesture {
1470 enum Mode {
1471 // No fingers, button is not pressed.
1472 // Nothing happening.
1473 NEUTRAL,
1474
1475 // No fingers, button is not pressed.
1476 // Tap detected.
1477 // Emits DOWN and UP events at the pointer location.
1478 TAP,
1479
Jeff Brown79ac9692011-04-19 21:20:10 -07001480 // Exactly one finger dragging following a tap.
1481 // Pointer follows the active finger.
1482 // Emits DOWN, MOVE and UP events at the pointer location.
Jeff Brown214eaf42011-05-26 19:17:02 -07001483 //
1484 // Detect double-taps when the finger goes up while in TAP_DRAG mode.
Jeff Brown79ac9692011-04-19 21:20:10 -07001485 TAP_DRAG,
1486
Jeff Brownace13b12011-03-09 17:39:48 -08001487 // Button is pressed.
1488 // Pointer follows the active finger if there is one. Other fingers are ignored.
1489 // Emits DOWN, MOVE and UP events at the pointer location.
Jeff Brown79ac9692011-04-19 21:20:10 -07001490 BUTTON_CLICK_OR_DRAG,
Jeff Brownace13b12011-03-09 17:39:48 -08001491
1492 // Exactly one finger, button is not pressed.
1493 // Pointer follows the active finger.
1494 // Emits HOVER_MOVE events at the pointer location.
Jeff Brown214eaf42011-05-26 19:17:02 -07001495 //
1496 // Detect taps when the finger goes up while in HOVER mode.
Jeff Brownace13b12011-03-09 17:39:48 -08001497 HOVER,
1498
Jeff Brown2352b972011-04-12 22:39:53 -07001499 // Exactly two fingers but neither have moved enough to clearly indicate
1500 // whether a swipe or freeform gesture was intended. We consider the
1501 // pointer to be pressed so this enables clicking or long-pressing on buttons.
1502 // Pointer does not move.
1503 // Emits DOWN, MOVE and UP events with a single stationary pointer coordinate.
1504 PRESS,
Jeff Brownace13b12011-03-09 17:39:48 -08001505
1506 // Exactly two fingers moving in the same direction, button is not pressed.
1507 // Pointer does not move.
1508 // Emits DOWN, MOVE and UP events with a single pointer coordinate that
1509 // follows the midpoint between both fingers.
Jeff Brownace13b12011-03-09 17:39:48 -08001510 SWIPE,
1511
1512 // Two or more fingers moving in arbitrary directions, button is not pressed.
1513 // Pointer does not move.
1514 // Emits DOWN, POINTER_DOWN, MOVE, POINTER_UP and UP events that follow
1515 // each finger individually relative to the initial centroid of the finger.
Jeff Brownace13b12011-03-09 17:39:48 -08001516 FREEFORM,
1517
1518 // Waiting for quiet time to end before starting the next gesture.
1519 QUIET,
1520 };
1521
Jeff Brown2352b972011-04-12 22:39:53 -07001522 // Time the first finger went down.
1523 nsecs_t firstTouchTime;
1524
Jeff Brownace13b12011-03-09 17:39:48 -08001525 // The active pointer id from the raw touch data.
1526 int32_t activeTouchId; // -1 if none
1527
1528 // The active pointer id from the gesture last delivered to the application.
1529 int32_t activeGestureId; // -1 if none
1530
1531 // Pointer coords and ids for the current and previous pointer gesture.
1532 Mode currentGestureMode;
Jeff Brownace13b12011-03-09 17:39:48 -08001533 BitSet32 currentGestureIdBits;
1534 uint32_t currentGestureIdToIndex[MAX_POINTER_ID + 1];
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001535 PointerProperties currentGestureProperties[MAX_POINTERS];
Jeff Brownace13b12011-03-09 17:39:48 -08001536 PointerCoords currentGestureCoords[MAX_POINTERS];
1537
1538 Mode lastGestureMode;
Jeff Brownace13b12011-03-09 17:39:48 -08001539 BitSet32 lastGestureIdBits;
1540 uint32_t lastGestureIdToIndex[MAX_POINTER_ID + 1];
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001541 PointerProperties lastGestureProperties[MAX_POINTERS];
Jeff Brownace13b12011-03-09 17:39:48 -08001542 PointerCoords lastGestureCoords[MAX_POINTERS];
1543
Jeff Brownace13b12011-03-09 17:39:48 -08001544 // Time the pointer gesture last went down.
1545 nsecs_t downTime;
1546
Jeff Brown79ac9692011-04-19 21:20:10 -07001547 // Time when the pointer went down for a TAP.
1548 nsecs_t tapDownTime;
1549
1550 // Time when the pointer went up for a TAP.
1551 nsecs_t tapUpTime;
Jeff Brownace13b12011-03-09 17:39:48 -08001552
Jeff Brown2352b972011-04-12 22:39:53 -07001553 // Location of initial tap.
1554 float tapX, tapY;
1555
Jeff Brownace13b12011-03-09 17:39:48 -08001556 // Time we started waiting for quiescence.
1557 nsecs_t quietTime;
1558
Jeff Brown2352b972011-04-12 22:39:53 -07001559 // Reference points for multitouch gestures.
1560 float referenceTouchX; // reference touch X/Y coordinates in surface units
1561 float referenceTouchY;
1562 float referenceGestureX; // reference gesture X/Y coordinates in pixels
1563 float referenceGestureY;
1564
Jeff Brown538881e2011-05-25 18:23:38 -07001565 // Distance that each pointer has traveled which has not yet been
1566 // subsumed into the reference gesture position.
1567 BitSet32 referenceIdBits;
1568 struct Delta {
1569 float dx, dy;
1570 };
1571 Delta referenceDeltas[MAX_POINTER_ID + 1];
1572
Jeff Brown2352b972011-04-12 22:39:53 -07001573 // Describes how touch ids are mapped to gesture ids for freeform gestures.
1574 uint32_t freeformTouchToGestureIdMap[MAX_POINTER_ID + 1];
1575
Jeff Brownace13b12011-03-09 17:39:48 -08001576 // A velocity tracker for determining whether to switch active pointers during drags.
1577 VelocityTracker velocityTracker;
1578
1579 void reset() {
Jeff Brown2352b972011-04-12 22:39:53 -07001580 firstTouchTime = LLONG_MIN;
Jeff Brownace13b12011-03-09 17:39:48 -08001581 activeTouchId = -1;
1582 activeGestureId = -1;
1583 currentGestureMode = NEUTRAL;
Jeff Brownace13b12011-03-09 17:39:48 -08001584 currentGestureIdBits.clear();
1585 lastGestureMode = NEUTRAL;
Jeff Brownace13b12011-03-09 17:39:48 -08001586 lastGestureIdBits.clear();
Jeff Brownace13b12011-03-09 17:39:48 -08001587 downTime = 0;
1588 velocityTracker.clear();
Jeff Brown79ac9692011-04-19 21:20:10 -07001589 resetTap();
Jeff Brownace13b12011-03-09 17:39:48 -08001590 resetQuietTime();
1591 }
1592
Jeff Brown79ac9692011-04-19 21:20:10 -07001593 void resetTap() {
1594 tapDownTime = LLONG_MIN;
1595 tapUpTime = LLONG_MIN;
Jeff Brownace13b12011-03-09 17:39:48 -08001596 }
1597
1598 void resetQuietTime() {
1599 quietTime = LLONG_MIN;
1600 }
1601 } mPointerGesture;
1602
Jeff Brown65fd2512011-08-18 11:20:58 -07001603 struct PointerSimple {
1604 PointerCoords currentCoords;
1605 PointerProperties currentProperties;
1606 PointerCoords lastCoords;
1607 PointerProperties lastProperties;
1608
1609 // True if the pointer is down.
1610 bool down;
1611
1612 // True if the pointer is hovering.
1613 bool hovering;
1614
1615 // Time the pointer last went down.
1616 nsecs_t downTime;
1617
1618 void reset() {
1619 currentCoords.clear();
1620 currentProperties.clear();
1621 lastCoords.clear();
1622 lastProperties.clear();
1623 down = false;
1624 hovering = false;
1625 downTime = 0;
1626 }
1627 } mPointerSimple;
1628
1629 // The pointer and scroll velocity controls.
1630 VelocityControl mPointerVelocityControl;
1631 VelocityControl mWheelXVelocityControl;
1632 VelocityControl mWheelYVelocityControl;
1633
1634 void sync(nsecs_t when);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001635
Jeff Brownbe1aa822011-07-27 16:04:54 -07001636 bool consumeRawTouches(nsecs_t when, uint32_t policyFlags);
1637 void dispatchVirtualKey(nsecs_t when, uint32_t policyFlags,
1638 int32_t keyEventAction, int32_t keyEventFlags);
1639
Jeff Brown6d0fec22010-07-23 21:28:06 -07001640 void dispatchTouches(nsecs_t when, uint32_t policyFlags);
Jeff Brownbe1aa822011-07-27 16:04:54 -07001641 void dispatchHoverExit(nsecs_t when, uint32_t policyFlags);
1642 void dispatchHoverEnterAndMove(nsecs_t when, uint32_t policyFlags);
1643 void cookPointerData();
1644
Jeff Brown65fd2512011-08-18 11:20:58 -07001645 void dispatchPointerUsage(nsecs_t when, uint32_t policyFlags, PointerUsage pointerUsage);
1646 void abortPointerUsage(nsecs_t when, uint32_t policyFlags);
1647
Jeff Brown79ac9692011-04-19 21:20:10 -07001648 void dispatchPointerGestures(nsecs_t when, uint32_t policyFlags, bool isTimeout);
Jeff Brown65fd2512011-08-18 11:20:58 -07001649 void abortPointerGestures(nsecs_t when, uint32_t policyFlags);
Jeff Brown79ac9692011-04-19 21:20:10 -07001650 bool preparePointerGestures(nsecs_t when,
Jeff Brown65fd2512011-08-18 11:20:58 -07001651 bool* outCancelPreviousGesture, bool* outFinishPreviousGesture,
1652 bool isTimeout);
1653
1654 void dispatchPointerStylus(nsecs_t when, uint32_t policyFlags);
1655 void abortPointerStylus(nsecs_t when, uint32_t policyFlags);
1656
1657 void dispatchPointerMouse(nsecs_t when, uint32_t policyFlags);
1658 void abortPointerMouse(nsecs_t when, uint32_t policyFlags);
1659
1660 void dispatchPointerSimple(nsecs_t when, uint32_t policyFlags,
1661 bool down, bool hovering);
1662 void abortPointerSimple(nsecs_t when, uint32_t policyFlags);
Jeff Brownace13b12011-03-09 17:39:48 -08001663
1664 // Dispatches a motion event.
1665 // If the changedId is >= 0 and the action is POINTER_DOWN or POINTER_UP, the
1666 // method will take care of setting the index and transmuting the action to DOWN or UP
1667 // it is the first / last pointer to go down / up.
1668 void dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32_t source,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001669 int32_t action, int32_t flags, int32_t metaState, int32_t buttonState,
1670 int32_t edgeFlags,
1671 const PointerProperties* properties, const PointerCoords* coords,
1672 const uint32_t* idToIndex, BitSet32 idBits,
Jeff Brownace13b12011-03-09 17:39:48 -08001673 int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime);
1674
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001675 // Updates pointer coords and properties for pointers with specified ids that have moved.
Jeff Brownace13b12011-03-09 17:39:48 -08001676 // Returns true if any of them changed.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001677 bool updateMovedPointers(const PointerProperties* inProperties,
1678 const PointerCoords* inCoords, const uint32_t* inIdToIndex,
1679 PointerProperties* outProperties, PointerCoords* outCoords,
1680 const uint32_t* outIdToIndex, BitSet32 idBits) const;
Jeff Brownace13b12011-03-09 17:39:48 -08001681
Jeff Brownbe1aa822011-07-27 16:04:54 -07001682 bool isPointInsideSurface(int32_t x, int32_t y);
1683 const VirtualKey* findVirtualKeyHit(int32_t x, int32_t y);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001684
Jeff Brownbe1aa822011-07-27 16:04:54 -07001685 void assignPointerIds();
Jeff Brown6d0fec22010-07-23 21:28:06 -07001686};
1687
1688
1689class SingleTouchInputMapper : public TouchInputMapper {
1690public:
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001691 SingleTouchInputMapper(InputDevice* device);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001692 virtual ~SingleTouchInputMapper();
1693
Jeff Brown65fd2512011-08-18 11:20:58 -07001694 virtual void reset(nsecs_t when);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001695 virtual void process(const RawEvent* rawEvent);
1696
1697protected:
Jeff Brown65fd2512011-08-18 11:20:58 -07001698 virtual void syncTouch(nsecs_t when, bool* outHavePointerIds);
Jeff Brownbe1aa822011-07-27 16:04:54 -07001699 virtual void configureRawPointerAxes();
Jeff Brown00710e92012-04-19 15:18:26 -07001700 virtual bool hasStylus() const;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001701
1702private:
Jeff Brown49754db2011-07-01 17:37:58 -07001703 SingleTouchMotionAccumulator mSingleTouchMotionAccumulator;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001704};
1705
1706
1707class MultiTouchInputMapper : public TouchInputMapper {
1708public:
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001709 MultiTouchInputMapper(InputDevice* device);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001710 virtual ~MultiTouchInputMapper();
1711
Jeff Brown65fd2512011-08-18 11:20:58 -07001712 virtual void reset(nsecs_t when);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001713 virtual void process(const RawEvent* rawEvent);
1714
1715protected:
Jeff Brown65fd2512011-08-18 11:20:58 -07001716 virtual void syncTouch(nsecs_t when, bool* outHavePointerIds);
Jeff Brownbe1aa822011-07-27 16:04:54 -07001717 virtual void configureRawPointerAxes();
Jeff Brown00710e92012-04-19 15:18:26 -07001718 virtual bool hasStylus() const;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001719
1720private:
Jeff Brown49754db2011-07-01 17:37:58 -07001721 MultiTouchMotionAccumulator mMultiTouchMotionAccumulator;
Jeff Brownace13b12011-03-09 17:39:48 -08001722
Jeff Brown6894a292011-07-01 17:59:27 -07001723 // Specifies the pointer id bits that are in use, and their associated tracking id.
1724 BitSet32 mPointerIdBits;
1725 int32_t mPointerTrackingIdMap[MAX_POINTER_ID + 1];
Jeff Brown6d0fec22010-07-23 21:28:06 -07001726};
1727
Jeff Browncb1404e2011-01-15 18:14:15 -08001728
1729class JoystickInputMapper : public InputMapper {
1730public:
1731 JoystickInputMapper(InputDevice* device);
1732 virtual ~JoystickInputMapper();
1733
1734 virtual uint32_t getSources();
1735 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
1736 virtual void dump(String8& dump);
Jeff Brown65fd2512011-08-18 11:20:58 -07001737 virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
1738 virtual void reset(nsecs_t when);
Jeff Browncb1404e2011-01-15 18:14:15 -08001739 virtual void process(const RawEvent* rawEvent);
1740
1741private:
Jeff Brown6f2fba42011-02-19 01:08:02 -08001742 struct Axis {
1743 RawAbsoluteAxisInfo rawAxisInfo;
Jeff Brown85297452011-03-04 13:07:49 -08001744 AxisInfo axisInfo;
Jeff Browncb1404e2011-01-15 18:14:15 -08001745
Jeff Brown6f2fba42011-02-19 01:08:02 -08001746 bool explicitlyMapped; // true if the axis was explicitly assigned an axis id
Jeff Browncb1404e2011-01-15 18:14:15 -08001747
Jeff Brown6f2fba42011-02-19 01:08:02 -08001748 float scale; // scale factor from raw to normalized values
1749 float offset; // offset to add after scaling for normalization
Jeff Brown85297452011-03-04 13:07:49 -08001750 float highScale; // scale factor from raw to normalized values of high split
1751 float highOffset; // offset to add after scaling for normalization of high split
Jeff Browncb1404e2011-01-15 18:14:15 -08001752
Michael Wrightc6091c62013-04-01 20:56:04 -07001753 float min; // normalized inclusive minimum
1754 float max; // normalized inclusive maximum
1755 float flat; // normalized flat region size
1756 float fuzz; // normalized error tolerance
1757 float resolution; // normalized resolution in units/mm
Jeff Browncb1404e2011-01-15 18:14:15 -08001758
Jeff Brown6f2fba42011-02-19 01:08:02 -08001759 float filter; // filter out small variations of this size
Jeff Brown85297452011-03-04 13:07:49 -08001760 float currentValue; // current value
1761 float newValue; // most recent value
1762 float highCurrentValue; // current value of high split
1763 float highNewValue; // most recent value of high split
Jeff Browncb1404e2011-01-15 18:14:15 -08001764
Jeff Brown85297452011-03-04 13:07:49 -08001765 void initialize(const RawAbsoluteAxisInfo& rawAxisInfo, const AxisInfo& axisInfo,
1766 bool explicitlyMapped, float scale, float offset,
1767 float highScale, float highOffset,
Michael Wrightc6091c62013-04-01 20:56:04 -07001768 float min, float max, float flat, float fuzz, float resolution) {
Jeff Brown6f2fba42011-02-19 01:08:02 -08001769 this->rawAxisInfo = rawAxisInfo;
Jeff Brown85297452011-03-04 13:07:49 -08001770 this->axisInfo = axisInfo;
Jeff Brown6f2fba42011-02-19 01:08:02 -08001771 this->explicitlyMapped = explicitlyMapped;
1772 this->scale = scale;
1773 this->offset = offset;
Jeff Brown85297452011-03-04 13:07:49 -08001774 this->highScale = highScale;
1775 this->highOffset = highOffset;
Jeff Brown6f2fba42011-02-19 01:08:02 -08001776 this->min = min;
1777 this->max = max;
1778 this->flat = flat;
1779 this->fuzz = fuzz;
Michael Wrightc6091c62013-04-01 20:56:04 -07001780 this->resolution = resolution;
Jeff Brown6f2fba42011-02-19 01:08:02 -08001781 this->filter = 0;
Jeff Brown85297452011-03-04 13:07:49 -08001782 resetValue();
1783 }
1784
1785 void resetValue() {
1786 this->currentValue = 0;
Jeff Brown6f2fba42011-02-19 01:08:02 -08001787 this->newValue = 0;
Jeff Brown85297452011-03-04 13:07:49 -08001788 this->highCurrentValue = 0;
1789 this->highNewValue = 0;
Jeff Browncb1404e2011-01-15 18:14:15 -08001790 }
1791 };
1792
Jeff Brown6f2fba42011-02-19 01:08:02 -08001793 // Axes indexed by raw ABS_* axis index.
1794 KeyedVector<int32_t, Axis> mAxes;
Jeff Browncb1404e2011-01-15 18:14:15 -08001795
Jeff Brown6f2fba42011-02-19 01:08:02 -08001796 void sync(nsecs_t when, bool force);
Jeff Browncb1404e2011-01-15 18:14:15 -08001797
Jeff Brown85297452011-03-04 13:07:49 -08001798 bool haveAxis(int32_t axisId);
Jeff Brown6f2fba42011-02-19 01:08:02 -08001799 void pruneAxes(bool ignoreExplicitlyMappedAxes);
Jeff Brown85297452011-03-04 13:07:49 -08001800 bool filterAxes(bool force);
1801
1802 static bool hasValueChangedSignificantly(float filter,
1803 float newValue, float currentValue, float min, float max);
1804 static bool hasMovedNearerToValueWithinFilteredRange(float filter,
1805 float newValue, float currentValue, float thresholdValue);
Jeff Browncb1404e2011-01-15 18:14:15 -08001806
Jeff Brown6f2fba42011-02-19 01:08:02 -08001807 static bool isCenteredAxis(int32_t axis);
Michael Wright2b08c612013-04-24 20:05:10 -07001808 static int32_t getCompatAxis(int32_t axis);
1809
1810 static void addMotionRange(int32_t axisId, const Axis& axis, InputDeviceInfo* info);
1811 static void setPointerCoordsAxisValue(PointerCoords* pointerCoords, int32_t axis,
1812 float value);
Jeff Browncb1404e2011-01-15 18:14:15 -08001813};
1814
Jeff Brown46b9ac02010-04-22 18:58:52 -07001815} // namespace android
1816
1817#endif // _UI_INPUT_READER_H