blob: ed2a5c10b052ad5a63113b0c005a83a7a9cef3f1 [file] [log] [blame]
Jeff Brown46b9ac0a2010-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
Mathias Agopianb93a03f82012-02-17 15:34:57 -080024#include <androidfw/Input.h>
Jeff Brown8a90e6e2012-05-11 12:24:35 -070025#include <androidfw/VelocityControl.h>
26#include <androidfw/VelocityTracker.h>
Jeff Brown46b9ac0a2010-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 Brown46b9ac0a2010-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. */
284 virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const String8& inputDeviceDescriptor) = 0;
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700285
286 /* Gets a user-supplied alias for a particular input device, or an empty string if none. */
287 virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier) = 0;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700288};
289
290
Jeff Brownbe1aa822011-07-27 16:04:54 -0700291/* Processes raw input events and sends cooked event data to an input listener. */
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700292class InputReaderInterface : public virtual RefBase {
293protected:
294 InputReaderInterface() { }
295 virtual ~InputReaderInterface() { }
296
297public:
Jeff Brownb88102f2010-09-08 11:49:43 -0700298 /* Dumps the state of the input reader.
299 *
300 * This method may be called on any thread (usually by the input manager). */
301 virtual void dump(String8& dump) = 0;
302
Jeff Brown89ef0722011-08-10 16:25:21 -0700303 /* Called by the heatbeat to ensures that the reader has not deadlocked. */
304 virtual void monitor() = 0;
305
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700306 /* Runs a single iteration of the processing loop.
307 * Nominally reads and processes one incoming message from the EventHub.
308 *
309 * This method should be called on the input reader thread.
310 */
311 virtual void loopOnce() = 0;
312
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700313 /* Gets information about all input devices.
Jeff Brown6d0fec22010-07-23 21:28:06 -0700314 *
315 * This method may be called on any thread (usually by the input manager).
Jeff Brown9c3cda02010-06-15 01:31:58 -0700316 */
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700317 virtual void getInputDevices(Vector<InputDeviceInfo>& outInputDevices) = 0;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700318
319 /* Query current input state. */
320 virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask,
321 int32_t scanCode) = 0;
322 virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask,
323 int32_t keyCode) = 0;
324 virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask,
325 int32_t sw) = 0;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700326
327 /* Determine whether physical keys exist for the given framework-domain key codes. */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700328 virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask,
329 size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) = 0;
Jeff Brown1a84fd12011-06-02 01:26:32 -0700330
Jeff Brown474dcb52011-06-14 20:22:50 -0700331 /* Requests that a reconfiguration of all input devices.
332 * The changes flag is a bitfield that indicates what has changed and whether
333 * the input devices must all be reopened. */
334 virtual void requestRefreshConfiguration(uint32_t changes) = 0;
Jeff Browna47425a2012-04-13 04:09:27 -0700335
336 /* Controls the vibrator of a particular input device. */
337 virtual void vibrate(int32_t deviceId, const nsecs_t* pattern, size_t patternSize,
338 ssize_t repeat, int32_t token) = 0;
339 virtual void cancelVibrate(int32_t deviceId, int32_t token) = 0;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700340};
341
342
343/* Internal interface used by individual input devices to access global input device state
344 * and parameters maintained by the input reader.
345 */
346class InputReaderContext {
Jeff Brownc3db8582010-10-20 15:33:38 -0700347public:
Jeff Brown6d0fec22010-07-23 21:28:06 -0700348 InputReaderContext() { }
349 virtual ~InputReaderContext() { }
350
Jeff Brown6d0fec22010-07-23 21:28:06 -0700351 virtual void updateGlobalMetaState() = 0;
352 virtual int32_t getGlobalMetaState() = 0;
353
Jeff Brownfe508922011-01-18 15:10:10 -0800354 virtual void disableVirtualKeysUntil(nsecs_t time) = 0;
355 virtual bool shouldDropVirtualKey(nsecs_t now,
356 InputDevice* device, int32_t keyCode, int32_t scanCode) = 0;
357
Jeff Brown05dc66a2011-03-02 14:41:58 -0800358 virtual void fadePointer() = 0;
359
Jeff Brownaa3855d2011-03-17 01:34:19 -0700360 virtual void requestTimeoutAtTime(nsecs_t when) = 0;
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700361 virtual int32_t bumpGeneration() = 0;
Jeff Brownaa3855d2011-03-17 01:34:19 -0700362
Jeff Brown6d0fec22010-07-23 21:28:06 -0700363 virtual InputReaderPolicyInterface* getPolicy() = 0;
Jeff Brownbe1aa822011-07-27 16:04:54 -0700364 virtual InputListenerInterface* getListener() = 0;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700365 virtual EventHubInterface* getEventHub() = 0;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700366};
367
Jeff Brown9c3cda02010-06-15 01:31:58 -0700368
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700369/* The input reader reads raw event data from the event hub and processes it into input events
Jeff Brownbe1aa822011-07-27 16:04:54 -0700370 * that it sends to the input listener. Some functions of the input reader, such as early
Jeff Brown9c3cda02010-06-15 01:31:58 -0700371 * event filtering in low power states, are controlled by a separate policy object.
372 *
Jeff Brownbe1aa822011-07-27 16:04:54 -0700373 * The InputReader owns a collection of InputMappers. Most of the work it does happens
374 * on the input reader thread but the InputReader can receive queries from other system
375 * components running on arbitrary threads. To keep things manageable, the InputReader
376 * uses a single Mutex to guard its state. The Mutex may be held while calling into the
377 * EventHub or the InputReaderPolicy but it is never held while calling into the
378 * InputListener.
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700379 */
Jeff Brownbe1aa822011-07-27 16:04:54 -0700380class InputReader : public InputReaderInterface {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700381public:
382 InputReader(const sp<EventHubInterface>& eventHub,
Jeff Brown9c3cda02010-06-15 01:31:58 -0700383 const sp<InputReaderPolicyInterface>& policy,
Jeff Brownbe1aa822011-07-27 16:04:54 -0700384 const sp<InputListenerInterface>& listener);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700385 virtual ~InputReader();
386
Jeff Brownb88102f2010-09-08 11:49:43 -0700387 virtual void dump(String8& dump);
Jeff Brown89ef0722011-08-10 16:25:21 -0700388 virtual void monitor();
Jeff Brownb88102f2010-09-08 11:49:43 -0700389
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700390 virtual void loopOnce();
391
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700392 virtual void getInputDevices(Vector<InputDeviceInfo>& outInputDevices);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700393
Jeff Brown6d0fec22010-07-23 21:28:06 -0700394 virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask,
395 int32_t scanCode);
396 virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask,
397 int32_t keyCode);
398 virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask,
399 int32_t sw);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700400
Jeff Brown6d0fec22010-07-23 21:28:06 -0700401 virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask,
402 size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700403
Jeff Brown474dcb52011-06-14 20:22:50 -0700404 virtual void requestRefreshConfiguration(uint32_t changes);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700405
Jeff Browna47425a2012-04-13 04:09:27 -0700406 virtual void vibrate(int32_t deviceId, const nsecs_t* pattern, size_t patternSize,
407 ssize_t repeat, int32_t token);
408 virtual void cancelVibrate(int32_t deviceId, int32_t token);
409
Jeff Brownc3db8582010-10-20 15:33:38 -0700410protected:
Jeff Brownbe1aa822011-07-27 16:04:54 -0700411 // These members are protected so they can be instrumented by test cases.
412 virtual InputDevice* createDeviceLocked(int32_t deviceId,
Jeff Browne38fdfa2012-04-06 14:51:01 -0700413 const InputDeviceIdentifier& identifier, uint32_t classes);
Jeff Brownbe1aa822011-07-27 16:04:54 -0700414
415 class ContextImpl : public InputReaderContext {
416 InputReader* mReader;
417
418 public:
419 ContextImpl(InputReader* reader);
420
421 virtual void updateGlobalMetaState();
422 virtual int32_t getGlobalMetaState();
423 virtual void disableVirtualKeysUntil(nsecs_t time);
424 virtual bool shouldDropVirtualKey(nsecs_t now,
425 InputDevice* device, int32_t keyCode, int32_t scanCode);
426 virtual void fadePointer();
427 virtual void requestTimeoutAtTime(nsecs_t when);
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700428 virtual int32_t bumpGeneration();
Jeff Brownbe1aa822011-07-27 16:04:54 -0700429 virtual InputReaderPolicyInterface* getPolicy();
430 virtual InputListenerInterface* getListener();
431 virtual EventHubInterface* getEventHub();
432 } mContext;
433
434 friend class ContextImpl;
Jeff Brownc3db8582010-10-20 15:33:38 -0700435
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700436private:
Jeff Brownbe1aa822011-07-27 16:04:54 -0700437 Mutex mLock;
438
Jeff Brown112b5f52012-01-27 17:32:06 -0800439 Condition mReaderIsAliveCondition;
440
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700441 sp<EventHubInterface> mEventHub;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700442 sp<InputReaderPolicyInterface> mPolicy;
Jeff Brownbe1aa822011-07-27 16:04:54 -0700443 sp<QueuedInputListener> mQueuedListener;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700444
Jeff Brown214eaf42011-05-26 19:17:02 -0700445 InputReaderConfiguration mConfig;
446
Jeff Brownb7198742011-03-18 18:14:26 -0700447 // The event queue.
448 static const int EVENT_BUFFER_SIZE = 256;
449 RawEvent mEventBuffer[EVENT_BUFFER_SIZE];
450
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700451 KeyedVector<int32_t, InputDevice*> mDevices;
452
Jeff Brown6d0fec22010-07-23 21:28:06 -0700453 // low-level input event decoding and device management
Jeff Brownbe1aa822011-07-27 16:04:54 -0700454 void processEventsLocked(const RawEvent* rawEvents, size_t count);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700455
Jeff Brown65fd2512011-08-18 11:20:58 -0700456 void addDeviceLocked(nsecs_t when, int32_t deviceId);
457 void removeDeviceLocked(nsecs_t when, int32_t deviceId);
Jeff Brownbe1aa822011-07-27 16:04:54 -0700458 void processEventsForDeviceLocked(int32_t deviceId, const RawEvent* rawEvents, size_t count);
459 void timeoutExpiredLocked(nsecs_t when);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700460
Jeff Brownbe1aa822011-07-27 16:04:54 -0700461 void handleConfigurationChangedLocked(nsecs_t when);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700462
Jeff Brownbe1aa822011-07-27 16:04:54 -0700463 int32_t mGlobalMetaState;
464 void updateGlobalMetaStateLocked();
465 int32_t getGlobalMetaStateLocked();
Jeff Brown6d0fec22010-07-23 21:28:06 -0700466
Jeff Brownbe1aa822011-07-27 16:04:54 -0700467 void fadePointerLocked();
Jeff Brown6d0fec22010-07-23 21:28:06 -0700468
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700469 int32_t mGeneration;
470 int32_t bumpGenerationLocked();
471
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700472 void getInputDevicesLocked(Vector<InputDeviceInfo>& outInputDevices);
473
Jeff Brownbe1aa822011-07-27 16:04:54 -0700474 nsecs_t mDisableVirtualKeysTimeout;
475 void disableVirtualKeysUntilLocked(nsecs_t time);
476 bool shouldDropVirtualKeyLocked(nsecs_t now,
Jeff Brownfe508922011-01-18 15:10:10 -0800477 InputDevice* device, int32_t keyCode, int32_t scanCode);
478
Jeff Brownbe1aa822011-07-27 16:04:54 -0700479 nsecs_t mNextTimeout;
480 void requestTimeoutAtTimeLocked(nsecs_t when);
Jeff Brownaa3855d2011-03-17 01:34:19 -0700481
Jeff Brownbe1aa822011-07-27 16:04:54 -0700482 uint32_t mConfigurationChangesToRefresh;
483 void refreshConfigurationLocked(uint32_t changes);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700484
Jeff Brown6d0fec22010-07-23 21:28:06 -0700485 // state queries
486 typedef int32_t (InputDevice::*GetStateFunc)(uint32_t sourceMask, int32_t code);
Jeff Brownbe1aa822011-07-27 16:04:54 -0700487 int32_t getStateLocked(int32_t deviceId, uint32_t sourceMask, int32_t code,
Jeff Brown6d0fec22010-07-23 21:28:06 -0700488 GetStateFunc getStateFunc);
Jeff Brownbe1aa822011-07-27 16:04:54 -0700489 bool markSupportedKeyCodesLocked(int32_t deviceId, uint32_t sourceMask, size_t numCodes,
Jeff Brown6d0fec22010-07-23 21:28:06 -0700490 const int32_t* keyCodes, uint8_t* outFlags);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700491};
492
493
494/* Reads raw events from the event hub and processes them, endlessly. */
495class InputReaderThread : public Thread {
496public:
497 InputReaderThread(const sp<InputReaderInterface>& reader);
498 virtual ~InputReaderThread();
499
500private:
501 sp<InputReaderInterface> mReader;
502
503 virtual bool threadLoop();
504};
505
Jeff Brown6d0fec22010-07-23 21:28:06 -0700506
507/* Represents the state of a single input device. */
508class InputDevice {
509public:
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700510 InputDevice(InputReaderContext* context, int32_t id, int32_t generation,
Jeff Browne38fdfa2012-04-06 14:51:01 -0700511 const InputDeviceIdentifier& identifier, uint32_t classes);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700512 ~InputDevice();
513
514 inline InputReaderContext* getContext() { return mContext; }
515 inline int32_t getId() { return mId; }
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700516 inline int32_t getGeneration() { return mGeneration; }
Jeff Browne38fdfa2012-04-06 14:51:01 -0700517 inline const String8& getName() { return mIdentifier.name; }
Jeff Brown9ee285af2011-08-31 12:56:34 -0700518 inline uint32_t getClasses() { return mClasses; }
Jeff Brown6d0fec22010-07-23 21:28:06 -0700519 inline uint32_t getSources() { return mSources; }
520
Jeff Brown56194eb2011-03-02 19:23:13 -0800521 inline bool isExternal() { return mIsExternal; }
522 inline void setExternal(bool external) { mIsExternal = external; }
523
Jeff Brown6d0fec22010-07-23 21:28:06 -0700524 inline bool isIgnored() { return mMappers.isEmpty(); }
525
Jeff Brownef3d7e82010-09-30 14:33:04 -0700526 void dump(String8& dump);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700527 void addMapper(InputMapper* mapper);
Jeff Brown65fd2512011-08-18 11:20:58 -0700528 void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
529 void reset(nsecs_t when);
Jeff Brownb7198742011-03-18 18:14:26 -0700530 void process(const RawEvent* rawEvents, size_t count);
Jeff Brownaa3855d2011-03-17 01:34:19 -0700531 void timeoutExpired(nsecs_t when);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700532
533 void getDeviceInfo(InputDeviceInfo* outDeviceInfo);
534 int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
535 int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
536 int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
537 bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
538 const int32_t* keyCodes, uint8_t* outFlags);
Jeff Browna47425a2012-04-13 04:09:27 -0700539 void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat, int32_t token);
540 void cancelVibrate(int32_t token);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700541
542 int32_t getMetaState();
543
Jeff Brown05dc66a2011-03-02 14:41:58 -0800544 void fadePointer();
545
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700546 void bumpGeneration();
547
Jeff Brown65fd2512011-08-18 11:20:58 -0700548 void notifyReset(nsecs_t when);
549
Jeff Brown49754db2011-07-01 17:37:58 -0700550 inline const PropertyMap& getConfiguration() { return mConfiguration; }
551 inline EventHubInterface* getEventHub() { return mContext->getEventHub(); }
Jeff Brown8d608662010-08-30 03:02:23 -0700552
Jeff Brown65fd2512011-08-18 11:20:58 -0700553 bool hasKey(int32_t code) {
554 return getEventHub()->hasScanCode(mId, code);
555 }
556
Jeff Brown00710e92012-04-19 15:18:26 -0700557 bool hasAbsoluteAxis(int32_t code) {
558 RawAbsoluteAxisInfo info;
559 getEventHub()->getAbsoluteAxisInfo(mId, code, &info);
560 return info.valid;
561 }
562
Jeff Brown65fd2512011-08-18 11:20:58 -0700563 bool isKeyPressed(int32_t code) {
564 return getEventHub()->getScanCodeState(mId, code) == AKEY_STATE_DOWN;
565 }
566
567 int32_t getAbsoluteAxisValue(int32_t code) {
568 int32_t value;
569 getEventHub()->getAbsoluteAxisValue(mId, code, &value);
570 return value;
571 }
572
Jeff Brown6d0fec22010-07-23 21:28:06 -0700573private:
574 InputReaderContext* mContext;
575 int32_t mId;
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700576 int32_t mGeneration;
Jeff Browne38fdfa2012-04-06 14:51:01 -0700577 InputDeviceIdentifier mIdentifier;
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700578 String8 mAlias;
Jeff Brown9ee285af2011-08-31 12:56:34 -0700579 uint32_t mClasses;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700580
581 Vector<InputMapper*> mMappers;
582
Jeff Brown6d0fec22010-07-23 21:28:06 -0700583 uint32_t mSources;
Jeff Brown56194eb2011-03-02 19:23:13 -0800584 bool mIsExternal;
Jeff Brown80fd47c2011-05-24 01:07:44 -0700585 bool mDropUntilNextSync;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700586
587 typedef int32_t (InputMapper::*GetStateFunc)(uint32_t sourceMask, int32_t code);
588 int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc);
Jeff Brown8d608662010-08-30 03:02:23 -0700589
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800590 PropertyMap mConfiguration;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700591};
592
593
Jeff Brown49754db2011-07-01 17:37:58 -0700594/* Keeps track of the state of mouse or touch pad buttons. */
595class CursorButtonAccumulator {
596public:
597 CursorButtonAccumulator();
Jeff Brown65fd2512011-08-18 11:20:58 -0700598 void reset(InputDevice* device);
Jeff Brown49754db2011-07-01 17:37:58 -0700599
Jeff Brown49754db2011-07-01 17:37:58 -0700600 void process(const RawEvent* rawEvent);
601
602 uint32_t getButtonState() const;
603
604private:
605 bool mBtnLeft;
606 bool mBtnRight;
607 bool mBtnMiddle;
608 bool mBtnBack;
609 bool mBtnSide;
610 bool mBtnForward;
611 bool mBtnExtra;
612 bool mBtnTask;
Jeff Brown65fd2512011-08-18 11:20:58 -0700613
614 void clearButtons();
Jeff Brown49754db2011-07-01 17:37:58 -0700615};
616
617
618/* Keeps track of cursor movements. */
619
620class CursorMotionAccumulator {
621public:
622 CursorMotionAccumulator();
Jeff Brown65fd2512011-08-18 11:20:58 -0700623 void reset(InputDevice* device);
624
625 void process(const RawEvent* rawEvent);
626 void finishSync();
627
628 inline int32_t getRelativeX() const { return mRelX; }
629 inline int32_t getRelativeY() const { return mRelY; }
630
631private:
632 int32_t mRelX;
633 int32_t mRelY;
Jeff Brown49754db2011-07-01 17:37:58 -0700634
635 void clearRelativeAxes();
Jeff Brown65fd2512011-08-18 11:20:58 -0700636};
637
638
639/* Keeps track of cursor scrolling motions. */
640
641class CursorScrollAccumulator {
642public:
643 CursorScrollAccumulator();
644 void configure(InputDevice* device);
645 void reset(InputDevice* device);
646
Jeff Brown49754db2011-07-01 17:37:58 -0700647 void process(const RawEvent* rawEvent);
Jeff Brown65fd2512011-08-18 11:20:58 -0700648 void finishSync();
Jeff Brown49754db2011-07-01 17:37:58 -0700649
650 inline bool haveRelativeVWheel() const { return mHaveRelWheel; }
651 inline bool haveRelativeHWheel() const { return mHaveRelHWheel; }
652
653 inline int32_t getRelativeX() const { return mRelX; }
654 inline int32_t getRelativeY() const { return mRelY; }
655 inline int32_t getRelativeVWheel() const { return mRelWheel; }
656 inline int32_t getRelativeHWheel() const { return mRelHWheel; }
657
658private:
659 bool mHaveRelWheel;
660 bool mHaveRelHWheel;
661
662 int32_t mRelX;
663 int32_t mRelY;
664 int32_t mRelWheel;
665 int32_t mRelHWheel;
Jeff Brown65fd2512011-08-18 11:20:58 -0700666
667 void clearRelativeAxes();
Jeff Brown49754db2011-07-01 17:37:58 -0700668};
669
670
671/* Keeps track of the state of touch, stylus and tool buttons. */
672class TouchButtonAccumulator {
673public:
674 TouchButtonAccumulator();
675 void configure(InputDevice* device);
Jeff Brown65fd2512011-08-18 11:20:58 -0700676 void reset(InputDevice* device);
Jeff Brown49754db2011-07-01 17:37:58 -0700677
Jeff Brown49754db2011-07-01 17:37:58 -0700678 void process(const RawEvent* rawEvent);
679
680 uint32_t getButtonState() const;
681 int32_t getToolType() const;
Jeff Brownd87c6d52011-08-10 14:55:59 -0700682 bool isToolActive() const;
Jeff Brown49754db2011-07-01 17:37:58 -0700683 bool isHovering() const;
Jeff Brown00710e92012-04-19 15:18:26 -0700684 bool hasStylus() const;
Jeff Brown49754db2011-07-01 17:37:58 -0700685
686private:
687 bool mHaveBtnTouch;
Jeff Brown00710e92012-04-19 15:18:26 -0700688 bool mHaveStylus;
Jeff Brown49754db2011-07-01 17:37:58 -0700689
690 bool mBtnTouch;
691 bool mBtnStylus;
692 bool mBtnStylus2;
693 bool mBtnToolFinger;
694 bool mBtnToolPen;
695 bool mBtnToolRubber;
Jeff Brown65fd2512011-08-18 11:20:58 -0700696 bool mBtnToolBrush;
697 bool mBtnToolPencil;
698 bool mBtnToolAirbrush;
699 bool mBtnToolMouse;
700 bool mBtnToolLens;
Jeff Brownea6892e2011-08-23 17:31:25 -0700701 bool mBtnToolDoubleTap;
702 bool mBtnToolTripleTap;
703 bool mBtnToolQuadTap;
Jeff Brown65fd2512011-08-18 11:20:58 -0700704
705 void clearButtons();
Jeff Brown49754db2011-07-01 17:37:58 -0700706};
707
708
Jeff Brownbe1aa822011-07-27 16:04:54 -0700709/* Raw axis information from the driver. */
710struct RawPointerAxes {
711 RawAbsoluteAxisInfo x;
712 RawAbsoluteAxisInfo y;
713 RawAbsoluteAxisInfo pressure;
714 RawAbsoluteAxisInfo touchMajor;
715 RawAbsoluteAxisInfo touchMinor;
716 RawAbsoluteAxisInfo toolMajor;
717 RawAbsoluteAxisInfo toolMinor;
718 RawAbsoluteAxisInfo orientation;
719 RawAbsoluteAxisInfo distance;
Jeff Brown65fd2512011-08-18 11:20:58 -0700720 RawAbsoluteAxisInfo tiltX;
721 RawAbsoluteAxisInfo tiltY;
Jeff Brownbe1aa822011-07-27 16:04:54 -0700722 RawAbsoluteAxisInfo trackingId;
723 RawAbsoluteAxisInfo slot;
724
725 RawPointerAxes();
726 void clear();
727};
728
729
730/* Raw data for a collection of pointers including a pointer id mapping table. */
731struct RawPointerData {
732 struct Pointer {
733 uint32_t id;
734 int32_t x;
735 int32_t y;
736 int32_t pressure;
737 int32_t touchMajor;
738 int32_t touchMinor;
739 int32_t toolMajor;
740 int32_t toolMinor;
741 int32_t orientation;
742 int32_t distance;
Jeff Brown65fd2512011-08-18 11:20:58 -0700743 int32_t tiltX;
744 int32_t tiltY;
Jeff Brownbe1aa822011-07-27 16:04:54 -0700745 int32_t toolType; // a fully decoded AMOTION_EVENT_TOOL_TYPE constant
746 bool isHovering;
747 };
748
749 uint32_t pointerCount;
750 Pointer pointers[MAX_POINTERS];
751 BitSet32 hoveringIdBits, touchingIdBits;
752 uint32_t idToIndex[MAX_POINTER_ID + 1];
753
754 RawPointerData();
755 void clear();
756 void copyFrom(const RawPointerData& other);
757 void getCentroidOfTouchingPointers(float* outX, float* outY) const;
758
759 inline void markIdBit(uint32_t id, bool isHovering) {
760 if (isHovering) {
761 hoveringIdBits.markBit(id);
762 } else {
763 touchingIdBits.markBit(id);
764 }
765 }
766
767 inline void clearIdBits() {
768 hoveringIdBits.clear();
769 touchingIdBits.clear();
770 }
771
772 inline const Pointer& pointerForId(uint32_t id) const {
773 return pointers[idToIndex[id]];
774 }
775
776 inline bool isHovering(uint32_t pointerIndex) {
777 return pointers[pointerIndex].isHovering;
778 }
779};
780
781
782/* Cooked data for a collection of pointers including a pointer id mapping table. */
783struct CookedPointerData {
784 uint32_t pointerCount;
785 PointerProperties pointerProperties[MAX_POINTERS];
786 PointerCoords pointerCoords[MAX_POINTERS];
787 BitSet32 hoveringIdBits, touchingIdBits;
788 uint32_t idToIndex[MAX_POINTER_ID + 1];
789
790 CookedPointerData();
791 void clear();
792 void copyFrom(const CookedPointerData& other);
793
Jeff Brown4dac9012013-04-10 01:03:19 -0700794 inline const PointerCoords& pointerCoordsForId(uint32_t id) const {
795 return pointerCoords[idToIndex[id]];
796 }
797
Jeff Brownbe1aa822011-07-27 16:04:54 -0700798 inline bool isHovering(uint32_t pointerIndex) {
799 return hoveringIdBits.hasBit(pointerProperties[pointerIndex].id);
800 }
801};
802
803
Jeff Brown49754db2011-07-01 17:37:58 -0700804/* Keeps track of the state of single-touch protocol. */
805class SingleTouchMotionAccumulator {
806public:
807 SingleTouchMotionAccumulator();
808
Jeff Brown49754db2011-07-01 17:37:58 -0700809 void process(const RawEvent* rawEvent);
Jeff Brown65fd2512011-08-18 11:20:58 -0700810 void reset(InputDevice* device);
Jeff Brown49754db2011-07-01 17:37:58 -0700811
812 inline int32_t getAbsoluteX() const { return mAbsX; }
813 inline int32_t getAbsoluteY() const { return mAbsY; }
814 inline int32_t getAbsolutePressure() const { return mAbsPressure; }
815 inline int32_t getAbsoluteToolWidth() const { return mAbsToolWidth; }
816 inline int32_t getAbsoluteDistance() const { return mAbsDistance; }
Jeff Brown65fd2512011-08-18 11:20:58 -0700817 inline int32_t getAbsoluteTiltX() const { return mAbsTiltX; }
818 inline int32_t getAbsoluteTiltY() const { return mAbsTiltY; }
Jeff Brown49754db2011-07-01 17:37:58 -0700819
820private:
821 int32_t mAbsX;
822 int32_t mAbsY;
823 int32_t mAbsPressure;
824 int32_t mAbsToolWidth;
825 int32_t mAbsDistance;
Jeff Brown65fd2512011-08-18 11:20:58 -0700826 int32_t mAbsTiltX;
827 int32_t mAbsTiltY;
828
829 void clearAbsoluteAxes();
Jeff Brown49754db2011-07-01 17:37:58 -0700830};
831
832
833/* Keeps track of the state of multi-touch protocol. */
834class MultiTouchMotionAccumulator {
835public:
836 class Slot {
837 public:
838 inline bool isInUse() const { return mInUse; }
839 inline int32_t getX() const { return mAbsMTPositionX; }
840 inline int32_t getY() const { return mAbsMTPositionY; }
841 inline int32_t getTouchMajor() const { return mAbsMTTouchMajor; }
842 inline int32_t getTouchMinor() const {
843 return mHaveAbsMTTouchMinor ? mAbsMTTouchMinor : mAbsMTTouchMajor; }
844 inline int32_t getToolMajor() const { return mAbsMTWidthMajor; }
845 inline int32_t getToolMinor() const {
846 return mHaveAbsMTWidthMinor ? mAbsMTWidthMinor : mAbsMTWidthMajor; }
847 inline int32_t getOrientation() const { return mAbsMTOrientation; }
848 inline int32_t getTrackingId() const { return mAbsMTTrackingId; }
849 inline int32_t getPressure() const { return mAbsMTPressure; }
850 inline int32_t getDistance() const { return mAbsMTDistance; }
851 inline int32_t getToolType() const;
852
853 private:
854 friend class MultiTouchMotionAccumulator;
855
856 bool mInUse;
857 bool mHaveAbsMTTouchMinor;
858 bool mHaveAbsMTWidthMinor;
859 bool mHaveAbsMTToolType;
860
861 int32_t mAbsMTPositionX;
862 int32_t mAbsMTPositionY;
863 int32_t mAbsMTTouchMajor;
864 int32_t mAbsMTTouchMinor;
865 int32_t mAbsMTWidthMajor;
866 int32_t mAbsMTWidthMinor;
867 int32_t mAbsMTOrientation;
868 int32_t mAbsMTTrackingId;
869 int32_t mAbsMTPressure;
Jeff Brown49754db2011-07-01 17:37:58 -0700870 int32_t mAbsMTDistance;
Jeff Brownbe1aa822011-07-27 16:04:54 -0700871 int32_t mAbsMTToolType;
Jeff Brown49754db2011-07-01 17:37:58 -0700872
873 Slot();
Jeff Brown49754db2011-07-01 17:37:58 -0700874 void clear();
875 };
876
877 MultiTouchMotionAccumulator();
878 ~MultiTouchMotionAccumulator();
879
Jeff Brown00710e92012-04-19 15:18:26 -0700880 void configure(InputDevice* device, size_t slotCount, bool usingSlotsProtocol);
Jeff Brown65fd2512011-08-18 11:20:58 -0700881 void reset(InputDevice* device);
Jeff Brown49754db2011-07-01 17:37:58 -0700882 void process(const RawEvent* rawEvent);
Jeff Brown65fd2512011-08-18 11:20:58 -0700883 void finishSync();
Jeff Brown00710e92012-04-19 15:18:26 -0700884 bool hasStylus() const;
Jeff Brown49754db2011-07-01 17:37:58 -0700885
Jeff Brown49754db2011-07-01 17:37:58 -0700886 inline size_t getSlotCount() const { return mSlotCount; }
887 inline const Slot* getSlot(size_t index) const { return &mSlots[index]; }
888
889private:
890 int32_t mCurrentSlot;
891 Slot* mSlots;
892 size_t mSlotCount;
893 bool mUsingSlotsProtocol;
Jeff Brown00710e92012-04-19 15:18:26 -0700894 bool mHaveStylus;
Jeff Brown65fd2512011-08-18 11:20:58 -0700895
896 void clearSlots(int32_t initialSlot);
Jeff Brown49754db2011-07-01 17:37:58 -0700897};
898
899
Jeff Brown6d0fec22010-07-23 21:28:06 -0700900/* An input mapper transforms raw input events into cooked event data.
901 * A single input device can have multiple associated input mappers in order to interpret
902 * different classes of events.
Jeff Brown65fd2512011-08-18 11:20:58 -0700903 *
904 * InputMapper lifecycle:
905 * - create
906 * - configure with 0 changes
907 * - reset
908 * - process, process, process (may occasionally reconfigure with non-zero changes or reset)
909 * - reset
910 * - destroy
Jeff Brown6d0fec22010-07-23 21:28:06 -0700911 */
912class InputMapper {
913public:
914 InputMapper(InputDevice* device);
915 virtual ~InputMapper();
916
917 inline InputDevice* getDevice() { return mDevice; }
918 inline int32_t getDeviceId() { return mDevice->getId(); }
919 inline const String8 getDeviceName() { return mDevice->getName(); }
920 inline InputReaderContext* getContext() { return mContext; }
921 inline InputReaderPolicyInterface* getPolicy() { return mContext->getPolicy(); }
Jeff Brownbe1aa822011-07-27 16:04:54 -0700922 inline InputListenerInterface* getListener() { return mContext->getListener(); }
Jeff Brown6d0fec22010-07-23 21:28:06 -0700923 inline EventHubInterface* getEventHub() { return mContext->getEventHub(); }
924
925 virtual uint32_t getSources() = 0;
926 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
Jeff Brownef3d7e82010-09-30 14:33:04 -0700927 virtual void dump(String8& dump);
Jeff Brown65fd2512011-08-18 11:20:58 -0700928 virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
929 virtual void reset(nsecs_t when);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700930 virtual void process(const RawEvent* rawEvent) = 0;
Jeff Brownaa3855d2011-03-17 01:34:19 -0700931 virtual void timeoutExpired(nsecs_t when);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700932
933 virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
934 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
935 virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
936 virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
937 const int32_t* keyCodes, uint8_t* outFlags);
Jeff Browna47425a2012-04-13 04:09:27 -0700938 virtual void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat,
939 int32_t token);
940 virtual void cancelVibrate(int32_t token);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700941
942 virtual int32_t getMetaState();
943
Jeff Brown05dc66a2011-03-02 14:41:58 -0800944 virtual void fadePointer();
945
Jeff Brown6d0fec22010-07-23 21:28:06 -0700946protected:
947 InputDevice* mDevice;
948 InputReaderContext* mContext;
Jeff Browncb1404e2011-01-15 18:14:15 -0800949
Jeff Brownbe1aa822011-07-27 16:04:54 -0700950 status_t getAbsoluteAxisInfo(int32_t axis, RawAbsoluteAxisInfo* axisInfo);
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700951 void bumpGeneration();
Jeff Brownbe1aa822011-07-27 16:04:54 -0700952
Jeff Browncb1404e2011-01-15 18:14:15 -0800953 static void dumpRawAbsoluteAxisInfo(String8& dump,
954 const RawAbsoluteAxisInfo& axis, const char* name);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700955};
956
957
958class SwitchInputMapper : public InputMapper {
959public:
960 SwitchInputMapper(InputDevice* device);
961 virtual ~SwitchInputMapper();
962
963 virtual uint32_t getSources();
964 virtual void process(const RawEvent* rawEvent);
965
966 virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
967
968private:
Jeff Brownbcc046a2012-09-27 20:46:43 -0700969 uint32_t mUpdatedSwitchValues;
970 uint32_t mUpdatedSwitchMask;
971
972 void processSwitch(int32_t switchCode, int32_t switchValue);
973 void sync(nsecs_t when);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700974};
975
976
Jeff Browna47425a2012-04-13 04:09:27 -0700977class VibratorInputMapper : public InputMapper {
978public:
979 VibratorInputMapper(InputDevice* device);
980 virtual ~VibratorInputMapper();
981
982 virtual uint32_t getSources();
983 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
984 virtual void process(const RawEvent* rawEvent);
985
986 virtual void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat,
987 int32_t token);
988 virtual void cancelVibrate(int32_t token);
989 virtual void timeoutExpired(nsecs_t when);
990 virtual void dump(String8& dump);
991
992private:
993 bool mVibrating;
994 nsecs_t mPattern[MAX_VIBRATE_PATTERN_SIZE];
995 size_t mPatternSize;
996 ssize_t mRepeat;
997 int32_t mToken;
998 ssize_t mIndex;
999 nsecs_t mNextStepTime;
1000
1001 void nextStep();
1002 void stopVibrating();
1003};
1004
1005
Jeff Brown6d0fec22010-07-23 21:28:06 -07001006class KeyboardInputMapper : public InputMapper {
1007public:
Jeff Brownefd32662011-03-08 15:13:06 -08001008 KeyboardInputMapper(InputDevice* device, uint32_t source, int32_t keyboardType);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001009 virtual ~KeyboardInputMapper();
1010
1011 virtual uint32_t getSources();
1012 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
Jeff Brownef3d7e82010-09-30 14:33:04 -07001013 virtual void dump(String8& dump);
Jeff Brown65fd2512011-08-18 11:20:58 -07001014 virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
1015 virtual void reset(nsecs_t when);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001016 virtual void process(const RawEvent* rawEvent);
1017
1018 virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
1019 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
1020 virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
1021 const int32_t* keyCodes, uint8_t* outFlags);
1022
1023 virtual int32_t getMetaState();
1024
1025private:
1026 struct KeyDown {
1027 int32_t keyCode;
1028 int32_t scanCode;
1029 };
1030
Jeff Brownefd32662011-03-08 15:13:06 -08001031 uint32_t mSource;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001032 int32_t mKeyboardType;
1033
Jeff Brown65fd2512011-08-18 11:20:58 -07001034 int32_t mOrientation; // orientation for dpad keys
1035
Jeff Brownbe1aa822011-07-27 16:04:54 -07001036 Vector<KeyDown> mKeyDowns; // keys that are down
1037 int32_t mMetaState;
1038 nsecs_t mDownTime; // time of most recent key down
1039
Jeff Brown49ccac52012-04-11 18:27:33 -07001040 int32_t mCurrentHidUsage; // most recent HID usage seen this packet, or 0 if none
1041
Jeff Brownbe1aa822011-07-27 16:04:54 -07001042 struct LedState {
1043 bool avail; // led is available
1044 bool on; // we think the led is currently on
1045 };
1046 LedState mCapsLockLedState;
1047 LedState mNumLockLedState;
1048 LedState mScrollLockLedState;
1049
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001050 // Immutable configuration parameters.
1051 struct Parameters {
Jeff Brownd728bf52012-09-08 18:05:28 -07001052 bool hasAssociatedDisplay;
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001053 bool orientationAware;
1054 } mParameters;
1055
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001056 void configureParameters();
1057 void dumpParameters(String8& dump);
1058
Jeff Brown6d0fec22010-07-23 21:28:06 -07001059 bool isKeyboardOrGamepadKey(int32_t scanCode);
Jeff Brown6328cdc2010-07-29 18:18:33 -07001060
Jeff Brown6d0fec22010-07-23 21:28:06 -07001061 void processKey(nsecs_t when, bool down, int32_t keyCode, int32_t scanCode,
1062 uint32_t policyFlags);
1063
Jeff Brownbe1aa822011-07-27 16:04:54 -07001064 ssize_t findKeyDown(int32_t scanCode);
Jeff Brown497a92c2010-09-12 17:55:08 -07001065
Jeff Brownbe1aa822011-07-27 16:04:54 -07001066 void resetLedState();
1067 void initializeLedState(LedState& ledState, int32_t led);
1068 void updateLedState(bool reset);
1069 void updateLedStateForModifier(LedState& ledState, int32_t led,
Jeff Brown497a92c2010-09-12 17:55:08 -07001070 int32_t modifier, bool reset);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001071};
1072
1073
Jeff Brown83c09682010-12-23 17:50:18 -08001074class CursorInputMapper : public InputMapper {
Jeff Brown6d0fec22010-07-23 21:28:06 -07001075public:
Jeff Brown83c09682010-12-23 17:50:18 -08001076 CursorInputMapper(InputDevice* device);
1077 virtual ~CursorInputMapper();
Jeff Brown6d0fec22010-07-23 21:28:06 -07001078
1079 virtual uint32_t getSources();
1080 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
Jeff Brownef3d7e82010-09-30 14:33:04 -07001081 virtual void dump(String8& dump);
Jeff Brown65fd2512011-08-18 11:20:58 -07001082 virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
1083 virtual void reset(nsecs_t when);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001084 virtual void process(const RawEvent* rawEvent);
1085
Jeff Brownc3fc2d02010-08-10 15:47:53 -07001086 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
1087
Jeff Brown05dc66a2011-03-02 14:41:58 -08001088 virtual void fadePointer();
1089
Jeff Brown6d0fec22010-07-23 21:28:06 -07001090private:
1091 // Amount that trackball needs to move in order to generate a key event.
1092 static const int32_t TRACKBALL_MOVEMENT_THRESHOLD = 6;
1093
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001094 // Immutable configuration parameters.
1095 struct Parameters {
Jeff Brown83c09682010-12-23 17:50:18 -08001096 enum Mode {
1097 MODE_POINTER,
1098 MODE_NAVIGATION,
1099 };
1100
1101 Mode mode;
Jeff Brownd728bf52012-09-08 18:05:28 -07001102 bool hasAssociatedDisplay;
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001103 bool orientationAware;
1104 } mParameters;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001105
Jeff Brown49754db2011-07-01 17:37:58 -07001106 CursorButtonAccumulator mCursorButtonAccumulator;
1107 CursorMotionAccumulator mCursorMotionAccumulator;
Jeff Brown65fd2512011-08-18 11:20:58 -07001108 CursorScrollAccumulator mCursorScrollAccumulator;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001109
Jeff Brownefd32662011-03-08 15:13:06 -08001110 int32_t mSource;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001111 float mXScale;
1112 float mYScale;
1113 float mXPrecision;
1114 float mYPrecision;
Jeff Brown6f2fba42011-02-19 01:08:02 -08001115
Jeff Brown6f2fba42011-02-19 01:08:02 -08001116 float mVWheelScale;
1117 float mHWheelScale;
1118
Jeff Brown19c97d462011-06-01 12:33:19 -07001119 // Velocity controls for mouse pointer and wheel movements.
1120 // The controls for X and Y wheel movements are separate to keep them decoupled.
1121 VelocityControl mPointerVelocityControl;
1122 VelocityControl mWheelXVelocityControl;
1123 VelocityControl mWheelYVelocityControl;
1124
Jeff Brown65fd2512011-08-18 11:20:58 -07001125 int32_t mOrientation;
1126
Jeff Brown83c09682010-12-23 17:50:18 -08001127 sp<PointerControllerInterface> mPointerController;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001128
Jeff Brownbe1aa822011-07-27 16:04:54 -07001129 int32_t mButtonState;
1130 nsecs_t mDownTime;
Jeff Brown6328cdc2010-07-29 18:18:33 -07001131
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001132 void configureParameters();
1133 void dumpParameters(String8& dump);
1134
Jeff Brown6d0fec22010-07-23 21:28:06 -07001135 void sync(nsecs_t when);
1136};
1137
1138
1139class TouchInputMapper : public InputMapper {
1140public:
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001141 TouchInputMapper(InputDevice* device);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001142 virtual ~TouchInputMapper();
1143
1144 virtual uint32_t getSources();
1145 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
Jeff Brownef3d7e82010-09-30 14:33:04 -07001146 virtual void dump(String8& dump);
Jeff Brown65fd2512011-08-18 11:20:58 -07001147 virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
1148 virtual void reset(nsecs_t when);
1149 virtual void process(const RawEvent* rawEvent);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001150
1151 virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
1152 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
1153 virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
1154 const int32_t* keyCodes, uint8_t* outFlags);
1155
Jeff Brownace13b12011-03-09 17:39:48 -08001156 virtual void fadePointer();
Jeff Brown79ac9692011-04-19 21:20:10 -07001157 virtual void timeoutExpired(nsecs_t when);
Jeff Brownace13b12011-03-09 17:39:48 -08001158
Jeff Brown6d0fec22010-07-23 21:28:06 -07001159protected:
Jeff Brown65fd2512011-08-18 11:20:58 -07001160 CursorButtonAccumulator mCursorButtonAccumulator;
1161 CursorScrollAccumulator mCursorScrollAccumulator;
1162 TouchButtonAccumulator mTouchButtonAccumulator;
1163
Jeff Brown6d0fec22010-07-23 21:28:06 -07001164 struct VirtualKey {
1165 int32_t keyCode;
1166 int32_t scanCode;
1167 uint32_t flags;
1168
1169 // computed hit box, specified in touch screen coords based on known display size
1170 int32_t hitLeft;
1171 int32_t hitTop;
1172 int32_t hitRight;
1173 int32_t hitBottom;
1174
1175 inline bool isHit(int32_t x, int32_t y) const {
1176 return x >= hitLeft && x <= hitRight && y >= hitTop && y <= hitBottom;
1177 }
1178 };
1179
Jeff Brown65fd2512011-08-18 11:20:58 -07001180 // Input sources and device mode.
1181 uint32_t mSource;
1182
1183 enum DeviceMode {
1184 DEVICE_MODE_DISABLED, // input is disabled
1185 DEVICE_MODE_DIRECT, // direct mapping (touchscreen)
1186 DEVICE_MODE_UNSCALED, // unscaled mapping (touchpad)
Jeff Brown4dac9012013-04-10 01:03:19 -07001187 DEVICE_MODE_NAVIGATION, // unscaled mapping with assist gesture (touch navigation)
Jeff Brown65fd2512011-08-18 11:20:58 -07001188 DEVICE_MODE_POINTER, // pointer mapping (pointer)
1189 };
1190 DeviceMode mDeviceMode;
Jeff Brown83c09682010-12-23 17:50:18 -08001191
Jeff Brown214eaf42011-05-26 19:17:02 -07001192 // The reader's configuration.
Jeff Brown474dcb52011-06-14 20:22:50 -07001193 InputReaderConfiguration mConfig;
Jeff Brown214eaf42011-05-26 19:17:02 -07001194
Jeff Brown6d0fec22010-07-23 21:28:06 -07001195 // Immutable configuration parameters.
1196 struct Parameters {
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001197 enum DeviceType {
1198 DEVICE_TYPE_TOUCH_SCREEN,
1199 DEVICE_TYPE_TOUCH_PAD,
Michael Wrighte7a9ae82013-03-08 15:19:19 -08001200 DEVICE_TYPE_TOUCH_NAVIGATION,
Jeff Brownace13b12011-03-09 17:39:48 -08001201 DEVICE_TYPE_POINTER,
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001202 };
1203
1204 DeviceType deviceType;
Jeff Brownd728bf52012-09-08 18:05:28 -07001205 bool hasAssociatedDisplay;
Jeff Brownbc68a592011-07-25 12:58:12 -07001206 bool associatedDisplayIsExternal;
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001207 bool orientationAware;
1208
Jeff Brown2352b972011-04-12 22:39:53 -07001209 enum GestureMode {
1210 GESTURE_MODE_POINTER,
1211 GESTURE_MODE_SPOTS,
1212 };
1213 GestureMode gestureMode;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001214 } mParameters;
1215
Jeff Brown8d608662010-08-30 03:02:23 -07001216 // Immutable calibration parameters in parsed form.
1217 struct Calibration {
Jeff Browna1f89ce2011-08-11 00:05:01 -07001218 // Size
1219 enum SizeCalibration {
1220 SIZE_CALIBRATION_DEFAULT,
1221 SIZE_CALIBRATION_NONE,
1222 SIZE_CALIBRATION_GEOMETRIC,
1223 SIZE_CALIBRATION_DIAMETER,
Jeff Brown037f7272012-06-25 17:31:23 -07001224 SIZE_CALIBRATION_BOX,
Jeff Browna1f89ce2011-08-11 00:05:01 -07001225 SIZE_CALIBRATION_AREA,
Jeff Brown8d608662010-08-30 03:02:23 -07001226 };
1227
Jeff Browna1f89ce2011-08-11 00:05:01 -07001228 SizeCalibration sizeCalibration;
Jeff Brown8d608662010-08-30 03:02:23 -07001229
Jeff Browna1f89ce2011-08-11 00:05:01 -07001230 bool haveSizeScale;
1231 float sizeScale;
1232 bool haveSizeBias;
1233 float sizeBias;
1234 bool haveSizeIsSummed;
1235 bool sizeIsSummed;
Jeff Brown8d608662010-08-30 03:02:23 -07001236
1237 // Pressure
1238 enum PressureCalibration {
1239 PRESSURE_CALIBRATION_DEFAULT,
1240 PRESSURE_CALIBRATION_NONE,
1241 PRESSURE_CALIBRATION_PHYSICAL,
1242 PRESSURE_CALIBRATION_AMPLITUDE,
1243 };
Jeff Brown8d608662010-08-30 03:02:23 -07001244
1245 PressureCalibration pressureCalibration;
Jeff Brown8d608662010-08-30 03:02:23 -07001246 bool havePressureScale;
1247 float pressureScale;
1248
Jeff Brown8d608662010-08-30 03:02:23 -07001249 // Orientation
1250 enum OrientationCalibration {
1251 ORIENTATION_CALIBRATION_DEFAULT,
1252 ORIENTATION_CALIBRATION_NONE,
1253 ORIENTATION_CALIBRATION_INTERPOLATED,
Jeff Brown517bb4c2011-01-14 19:09:23 -08001254 ORIENTATION_CALIBRATION_VECTOR,
Jeff Brown8d608662010-08-30 03:02:23 -07001255 };
1256
1257 OrientationCalibration orientationCalibration;
Jeff Brown80fd47c2011-05-24 01:07:44 -07001258
1259 // Distance
1260 enum DistanceCalibration {
1261 DISTANCE_CALIBRATION_DEFAULT,
1262 DISTANCE_CALIBRATION_NONE,
1263 DISTANCE_CALIBRATION_SCALED,
1264 };
1265
1266 DistanceCalibration distanceCalibration;
1267 bool haveDistanceScale;
1268 float distanceScale;
Jeff Browna1f89ce2011-08-11 00:05:01 -07001269
1270 inline void applySizeScaleAndBias(float* outSize) const {
1271 if (haveSizeScale) {
1272 *outSize *= sizeScale;
1273 }
1274 if (haveSizeBias) {
1275 *outSize += sizeBias;
1276 }
1277 }
Jeff Brown8d608662010-08-30 03:02:23 -07001278 } mCalibration;
1279
Jeff Brownbe1aa822011-07-27 16:04:54 -07001280 // Raw pointer axis information from the driver.
1281 RawPointerAxes mRawPointerAxes;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001282
Jeff Brownbe1aa822011-07-27 16:04:54 -07001283 // Raw pointer sample data.
1284 RawPointerData mCurrentRawPointerData;
1285 RawPointerData mLastRawPointerData;
Jeff Brownace13b12011-03-09 17:39:48 -08001286
Jeff Brownbe1aa822011-07-27 16:04:54 -07001287 // Cooked pointer sample data.
1288 CookedPointerData mCurrentCookedPointerData;
1289 CookedPointerData mLastCookedPointerData;
1290
1291 // Button state.
1292 int32_t mCurrentButtonState;
1293 int32_t mLastButtonState;
1294
Jeff Brown65fd2512011-08-18 11:20:58 -07001295 // Scroll state.
1296 int32_t mCurrentRawVScroll;
1297 int32_t mCurrentRawHScroll;
1298
1299 // Id bits used to differentiate fingers, stylus and mouse tools.
1300 BitSet32 mCurrentFingerIdBits; // finger or unknown
1301 BitSet32 mLastFingerIdBits;
1302 BitSet32 mCurrentStylusIdBits; // stylus or eraser
1303 BitSet32 mLastStylusIdBits;
1304 BitSet32 mCurrentMouseIdBits; // mouse or lens
1305 BitSet32 mLastMouseIdBits;
1306
Jeff Brownbe1aa822011-07-27 16:04:54 -07001307 // True if we sent a HOVER_ENTER event.
1308 bool mSentHoverEnter;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001309
1310 // The time the primary pointer last went down.
1311 nsecs_t mDownTime;
1312
Jeff Brownace13b12011-03-09 17:39:48 -08001313 // The pointer controller, or null if the device is not a pointer.
1314 sp<PointerControllerInterface> mPointerController;
1315
Jeff Brownbe1aa822011-07-27 16:04:54 -07001316 Vector<VirtualKey> mVirtualKeys;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001317
Jeff Brown8d608662010-08-30 03:02:23 -07001318 virtual void configureParameters();
Jeff Brownef3d7e82010-09-30 14:33:04 -07001319 virtual void dumpParameters(String8& dump);
Jeff Brownbe1aa822011-07-27 16:04:54 -07001320 virtual void configureRawPointerAxes();
1321 virtual void dumpRawPointerAxes(String8& dump);
Jeff Brown65fd2512011-08-18 11:20:58 -07001322 virtual void configureSurface(nsecs_t when, bool* outResetNeeded);
Jeff Brownbe1aa822011-07-27 16:04:54 -07001323 virtual void dumpSurface(String8& dump);
1324 virtual void configureVirtualKeys();
1325 virtual void dumpVirtualKeys(String8& dump);
Jeff Brown8d608662010-08-30 03:02:23 -07001326 virtual void parseCalibration();
1327 virtual void resolveCalibration();
Jeff Brownef3d7e82010-09-30 14:33:04 -07001328 virtual void dumpCalibration(String8& dump);
Jeff Brown00710e92012-04-19 15:18:26 -07001329 virtual bool hasStylus() const = 0;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001330
Jeff Brown65fd2512011-08-18 11:20:58 -07001331 virtual void syncTouch(nsecs_t when, bool* outHavePointerIds) = 0;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001332
1333private:
Jeff Brown83d616a2012-09-09 20:33:43 -07001334 // The current viewport.
1335 // The components of the viewport are specified in the display's rotated orientation.
1336 DisplayViewport mViewport;
1337
1338 // The surface orientation, width and height set by configureSurface().
1339 // The width and height are derived from the viewport but are specified
1340 // in the natural orientation.
1341 // The surface origin specifies how the surface coordinates should be translated
1342 // to align with the logical display coordinate space.
1343 // The orientation may be different from the viewport orientation as it specifies
1344 // the rotation of the surface coordinates required to produce the viewport's
1345 // requested orientation, so it will depend on whether the device is orientation aware.
Jeff Brownbe1aa822011-07-27 16:04:54 -07001346 int32_t mSurfaceWidth;
1347 int32_t mSurfaceHeight;
Jeff Brown83d616a2012-09-09 20:33:43 -07001348 int32_t mSurfaceLeft;
1349 int32_t mSurfaceTop;
1350 int32_t mSurfaceOrientation;
Jeff Brownbe1aa822011-07-27 16:04:54 -07001351
1352 // Translation and scaling factors, orientation-independent.
Jeff Brown83d616a2012-09-09 20:33:43 -07001353 float mXTranslate;
Jeff Brownbe1aa822011-07-27 16:04:54 -07001354 float mXScale;
1355 float mXPrecision;
1356
Jeff Brown83d616a2012-09-09 20:33:43 -07001357 float mYTranslate;
Jeff Brownbe1aa822011-07-27 16:04:54 -07001358 float mYScale;
1359 float mYPrecision;
1360
1361 float mGeometricScale;
1362
Jeff Brownbe1aa822011-07-27 16:04:54 -07001363 float mPressureScale;
1364
1365 float mSizeScale;
1366
1367 float mOrientationScale;
1368
1369 float mDistanceScale;
1370
Jeff Brown65fd2512011-08-18 11:20:58 -07001371 bool mHaveTilt;
1372 float mTiltXCenter;
1373 float mTiltXScale;
1374 float mTiltYCenter;
1375 float mTiltYScale;
1376
Jeff Brownbe1aa822011-07-27 16:04:54 -07001377 // Oriented motion ranges for input device info.
1378 struct OrientedRanges {
1379 InputDeviceInfo::MotionRange x;
1380 InputDeviceInfo::MotionRange y;
Jeff Brownbe1aa822011-07-27 16:04:54 -07001381 InputDeviceInfo::MotionRange pressure;
1382
1383 bool haveSize;
1384 InputDeviceInfo::MotionRange size;
1385
1386 bool haveTouchSize;
1387 InputDeviceInfo::MotionRange touchMajor;
1388 InputDeviceInfo::MotionRange touchMinor;
1389
1390 bool haveToolSize;
1391 InputDeviceInfo::MotionRange toolMajor;
1392 InputDeviceInfo::MotionRange toolMinor;
1393
1394 bool haveOrientation;
1395 InputDeviceInfo::MotionRange orientation;
1396
1397 bool haveDistance;
1398 InputDeviceInfo::MotionRange distance;
Jeff Brown65fd2512011-08-18 11:20:58 -07001399
1400 bool haveTilt;
1401 InputDeviceInfo::MotionRange tilt;
1402
1403 OrientedRanges() {
1404 clear();
1405 }
1406
1407 void clear() {
1408 haveSize = false;
1409 haveTouchSize = false;
1410 haveToolSize = false;
1411 haveOrientation = false;
1412 haveDistance = false;
1413 haveTilt = false;
1414 }
Jeff Brownbe1aa822011-07-27 16:04:54 -07001415 } mOrientedRanges;
1416
1417 // Oriented dimensions and precision.
Jeff Brownbe1aa822011-07-27 16:04:54 -07001418 float mOrientedXPrecision;
1419 float mOrientedYPrecision;
1420
1421 struct CurrentVirtualKeyState {
1422 bool down;
1423 bool ignored;
1424 nsecs_t downTime;
1425 int32_t keyCode;
1426 int32_t scanCode;
1427 } mCurrentVirtualKey;
1428
Jeff Brown65fd2512011-08-18 11:20:58 -07001429 // Scale factor for gesture or mouse based pointer movements.
1430 float mPointerXMovementScale;
1431 float mPointerYMovementScale;
Jeff Brownbe1aa822011-07-27 16:04:54 -07001432
1433 // Scale factor for gesture based zooming and other freeform motions.
Jeff Brown65fd2512011-08-18 11:20:58 -07001434 float mPointerXZoomScale;
1435 float mPointerYZoomScale;
Jeff Brownbe1aa822011-07-27 16:04:54 -07001436
1437 // The maximum swipe width.
1438 float mPointerGestureMaxSwipeWidth;
1439
Jeff Brown4dac9012013-04-10 01:03:19 -07001440 // The start and end Y thresholds for invoking the assist navigation swipe.
1441 float mNavigationAssistStartY;
1442 float mNavigationAssistEndY;
1443
Jeff Brown6d0fec22010-07-23 21:28:06 -07001444 struct PointerDistanceHeapElement {
1445 uint32_t currentPointerIndex : 8;
1446 uint32_t lastPointerIndex : 8;
1447 uint64_t distance : 48; // squared distance
1448 };
1449
Jeff Brown65fd2512011-08-18 11:20:58 -07001450 enum PointerUsage {
1451 POINTER_USAGE_NONE,
1452 POINTER_USAGE_GESTURES,
1453 POINTER_USAGE_STYLUS,
1454 POINTER_USAGE_MOUSE,
1455 };
1456 PointerUsage mPointerUsage;
1457
Jeff Brownace13b12011-03-09 17:39:48 -08001458 struct PointerGesture {
1459 enum Mode {
1460 // No fingers, button is not pressed.
1461 // Nothing happening.
1462 NEUTRAL,
1463
1464 // No fingers, button is not pressed.
1465 // Tap detected.
1466 // Emits DOWN and UP events at the pointer location.
1467 TAP,
1468
Jeff Brown79ac9692011-04-19 21:20:10 -07001469 // Exactly one finger dragging following a tap.
1470 // Pointer follows the active finger.
1471 // Emits DOWN, MOVE and UP events at the pointer location.
Jeff Brown214eaf42011-05-26 19:17:02 -07001472 //
1473 // Detect double-taps when the finger goes up while in TAP_DRAG mode.
Jeff Brown79ac9692011-04-19 21:20:10 -07001474 TAP_DRAG,
1475
Jeff Brownace13b12011-03-09 17:39:48 -08001476 // Button is pressed.
1477 // Pointer follows the active finger if there is one. Other fingers are ignored.
1478 // Emits DOWN, MOVE and UP events at the pointer location.
Jeff Brown79ac9692011-04-19 21:20:10 -07001479 BUTTON_CLICK_OR_DRAG,
Jeff Brownace13b12011-03-09 17:39:48 -08001480
1481 // Exactly one finger, button is not pressed.
1482 // Pointer follows the active finger.
1483 // Emits HOVER_MOVE events at the pointer location.
Jeff Brown214eaf42011-05-26 19:17:02 -07001484 //
1485 // Detect taps when the finger goes up while in HOVER mode.
Jeff Brownace13b12011-03-09 17:39:48 -08001486 HOVER,
1487
Jeff Brown2352b972011-04-12 22:39:53 -07001488 // Exactly two fingers but neither have moved enough to clearly indicate
1489 // whether a swipe or freeform gesture was intended. We consider the
1490 // pointer to be pressed so this enables clicking or long-pressing on buttons.
1491 // Pointer does not move.
1492 // Emits DOWN, MOVE and UP events with a single stationary pointer coordinate.
1493 PRESS,
Jeff Brownace13b12011-03-09 17:39:48 -08001494
1495 // Exactly two fingers moving in the same direction, button is not pressed.
1496 // Pointer does not move.
1497 // Emits DOWN, MOVE and UP events with a single pointer coordinate that
1498 // follows the midpoint between both fingers.
Jeff Brownace13b12011-03-09 17:39:48 -08001499 SWIPE,
1500
1501 // Two or more fingers moving in arbitrary directions, button is not pressed.
1502 // Pointer does not move.
1503 // Emits DOWN, POINTER_DOWN, MOVE, POINTER_UP and UP events that follow
1504 // each finger individually relative to the initial centroid of the finger.
Jeff Brownace13b12011-03-09 17:39:48 -08001505 FREEFORM,
1506
1507 // Waiting for quiet time to end before starting the next gesture.
1508 QUIET,
1509 };
1510
Jeff Brown2352b972011-04-12 22:39:53 -07001511 // Time the first finger went down.
1512 nsecs_t firstTouchTime;
1513
Jeff Brownace13b12011-03-09 17:39:48 -08001514 // The active pointer id from the raw touch data.
1515 int32_t activeTouchId; // -1 if none
1516
1517 // The active pointer id from the gesture last delivered to the application.
1518 int32_t activeGestureId; // -1 if none
1519
1520 // Pointer coords and ids for the current and previous pointer gesture.
1521 Mode currentGestureMode;
Jeff Brownace13b12011-03-09 17:39:48 -08001522 BitSet32 currentGestureIdBits;
1523 uint32_t currentGestureIdToIndex[MAX_POINTER_ID + 1];
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001524 PointerProperties currentGestureProperties[MAX_POINTERS];
Jeff Brownace13b12011-03-09 17:39:48 -08001525 PointerCoords currentGestureCoords[MAX_POINTERS];
1526
1527 Mode lastGestureMode;
Jeff Brownace13b12011-03-09 17:39:48 -08001528 BitSet32 lastGestureIdBits;
1529 uint32_t lastGestureIdToIndex[MAX_POINTER_ID + 1];
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001530 PointerProperties lastGestureProperties[MAX_POINTERS];
Jeff Brownace13b12011-03-09 17:39:48 -08001531 PointerCoords lastGestureCoords[MAX_POINTERS];
1532
Jeff Brownace13b12011-03-09 17:39:48 -08001533 // Time the pointer gesture last went down.
1534 nsecs_t downTime;
1535
Jeff Brown79ac9692011-04-19 21:20:10 -07001536 // Time when the pointer went down for a TAP.
1537 nsecs_t tapDownTime;
1538
1539 // Time when the pointer went up for a TAP.
1540 nsecs_t tapUpTime;
Jeff Brownace13b12011-03-09 17:39:48 -08001541
Jeff Brown2352b972011-04-12 22:39:53 -07001542 // Location of initial tap.
1543 float tapX, tapY;
1544
Jeff Brownace13b12011-03-09 17:39:48 -08001545 // Time we started waiting for quiescence.
1546 nsecs_t quietTime;
1547
Jeff Brown2352b972011-04-12 22:39:53 -07001548 // Reference points for multitouch gestures.
1549 float referenceTouchX; // reference touch X/Y coordinates in surface units
1550 float referenceTouchY;
1551 float referenceGestureX; // reference gesture X/Y coordinates in pixels
1552 float referenceGestureY;
1553
Jeff Brown538881e2011-05-25 18:23:38 -07001554 // Distance that each pointer has traveled which has not yet been
1555 // subsumed into the reference gesture position.
1556 BitSet32 referenceIdBits;
1557 struct Delta {
1558 float dx, dy;
1559 };
1560 Delta referenceDeltas[MAX_POINTER_ID + 1];
1561
Jeff Brown2352b972011-04-12 22:39:53 -07001562 // Describes how touch ids are mapped to gesture ids for freeform gestures.
1563 uint32_t freeformTouchToGestureIdMap[MAX_POINTER_ID + 1];
1564
Jeff Brownace13b12011-03-09 17:39:48 -08001565 // A velocity tracker for determining whether to switch active pointers during drags.
1566 VelocityTracker velocityTracker;
1567
1568 void reset() {
Jeff Brown2352b972011-04-12 22:39:53 -07001569 firstTouchTime = LLONG_MIN;
Jeff Brownace13b12011-03-09 17:39:48 -08001570 activeTouchId = -1;
1571 activeGestureId = -1;
1572 currentGestureMode = NEUTRAL;
Jeff Brownace13b12011-03-09 17:39:48 -08001573 currentGestureIdBits.clear();
1574 lastGestureMode = NEUTRAL;
Jeff Brownace13b12011-03-09 17:39:48 -08001575 lastGestureIdBits.clear();
Jeff Brownace13b12011-03-09 17:39:48 -08001576 downTime = 0;
1577 velocityTracker.clear();
Jeff Brown79ac9692011-04-19 21:20:10 -07001578 resetTap();
Jeff Brownace13b12011-03-09 17:39:48 -08001579 resetQuietTime();
1580 }
1581
Jeff Brown79ac9692011-04-19 21:20:10 -07001582 void resetTap() {
1583 tapDownTime = LLONG_MIN;
1584 tapUpTime = LLONG_MIN;
Jeff Brownace13b12011-03-09 17:39:48 -08001585 }
1586
1587 void resetQuietTime() {
1588 quietTime = LLONG_MIN;
1589 }
1590 } mPointerGesture;
1591
Jeff Brown65fd2512011-08-18 11:20:58 -07001592 struct PointerSimple {
1593 PointerCoords currentCoords;
1594 PointerProperties currentProperties;
1595 PointerCoords lastCoords;
1596 PointerProperties lastProperties;
1597
1598 // True if the pointer is down.
1599 bool down;
1600
1601 // True if the pointer is hovering.
1602 bool hovering;
1603
1604 // Time the pointer last went down.
1605 nsecs_t downTime;
1606
1607 void reset() {
1608 currentCoords.clear();
1609 currentProperties.clear();
1610 lastCoords.clear();
1611 lastProperties.clear();
1612 down = false;
1613 hovering = false;
1614 downTime = 0;
1615 }
1616 } mPointerSimple;
1617
Jeff Brown4dac9012013-04-10 01:03:19 -07001618 struct Navigation {
1619 // The id of a pointer that is tracking a possible assist swipe.
1620 int32_t activeAssistId; // -1 if none
1621
1622 void reset() {
1623 activeAssistId = -1;
1624 }
1625 } mNavigation;
1626
Jeff Brown65fd2512011-08-18 11:20:58 -07001627 // The pointer and scroll velocity controls.
1628 VelocityControl mPointerVelocityControl;
1629 VelocityControl mWheelXVelocityControl;
1630 VelocityControl mWheelYVelocityControl;
1631
1632 void sync(nsecs_t when);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001633
Jeff Brownbe1aa822011-07-27 16:04:54 -07001634 bool consumeRawTouches(nsecs_t when, uint32_t policyFlags);
1635 void dispatchVirtualKey(nsecs_t when, uint32_t policyFlags,
1636 int32_t keyEventAction, int32_t keyEventFlags);
1637
Jeff Brown6d0fec22010-07-23 21:28:06 -07001638 void dispatchTouches(nsecs_t when, uint32_t policyFlags);
Jeff Brownbe1aa822011-07-27 16:04:54 -07001639 void dispatchHoverExit(nsecs_t when, uint32_t policyFlags);
1640 void dispatchHoverEnterAndMove(nsecs_t when, uint32_t policyFlags);
1641 void cookPointerData();
1642
Jeff Brown65fd2512011-08-18 11:20:58 -07001643 void dispatchPointerUsage(nsecs_t when, uint32_t policyFlags, PointerUsage pointerUsage);
1644 void abortPointerUsage(nsecs_t when, uint32_t policyFlags);
1645
Jeff Brown79ac9692011-04-19 21:20:10 -07001646 void dispatchPointerGestures(nsecs_t when, uint32_t policyFlags, bool isTimeout);
Jeff Brown65fd2512011-08-18 11:20:58 -07001647 void abortPointerGestures(nsecs_t when, uint32_t policyFlags);
Jeff Brown79ac9692011-04-19 21:20:10 -07001648 bool preparePointerGestures(nsecs_t when,
Jeff Brown65fd2512011-08-18 11:20:58 -07001649 bool* outCancelPreviousGesture, bool* outFinishPreviousGesture,
1650 bool isTimeout);
1651
1652 void dispatchPointerStylus(nsecs_t when, uint32_t policyFlags);
1653 void abortPointerStylus(nsecs_t when, uint32_t policyFlags);
1654
1655 void dispatchPointerMouse(nsecs_t when, uint32_t policyFlags);
1656 void abortPointerMouse(nsecs_t when, uint32_t policyFlags);
1657
1658 void dispatchPointerSimple(nsecs_t when, uint32_t policyFlags,
1659 bool down, bool hovering);
1660 void abortPointerSimple(nsecs_t when, uint32_t policyFlags);
Jeff Brownace13b12011-03-09 17:39:48 -08001661
Jeff Brown4dac9012013-04-10 01:03:19 -07001662 void dispatchNavigationAssist(nsecs_t when, uint32_t policyFlags);
1663
Jeff Brownace13b12011-03-09 17:39:48 -08001664 // 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 Brown46b9ac0a2010-04-22 18:58:52 -07001815} // namespace android
1816
1817#endif // _UI_INPUT_READER_H