blob: db4679b403ae0eaa8f9c7f2f547376b99600c0d3 [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"
21#include "InputDispatcher.h"
22#include "PointerController.h"
23
Jeff Brown46b9ac02010-04-22 18:58:52 -070024#include <ui/Input.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080025#include <ui/DisplayInfo.h>
Jeff Brown46b9ac02010-04-22 18:58:52 -070026#include <utils/KeyedVector.h>
27#include <utils/threads.h>
28#include <utils/Timers.h>
29#include <utils/RefBase.h>
30#include <utils/String8.h>
31#include <utils/BitSet.h>
32
33#include <stddef.h>
34#include <unistd.h>
35
Jeff Brown46b9ac02010-04-22 18:58:52 -070036namespace android {
37
Jeff Brown6d0fec22010-07-23 21:28:06 -070038class InputDevice;
39class InputMapper;
40
Jeff Brown8d608662010-08-30 03:02:23 -070041
Jeff Brown9c3cda02010-06-15 01:31:58 -070042/*
Jeff Brown214eaf42011-05-26 19:17:02 -070043 * Input reader configuration.
44 *
45 * Specifies various options that modify the behavior of the input reader.
46 */
47struct InputReaderConfiguration {
48 // Determines whether to turn on some hacks we have to improve the touch interaction with a
49 // certain device whose screen currently is not all that good.
50 bool filterTouchEvents;
51
52 // Determines whether to turn on some hacks to improve touch interaction with another device
53 // where touch coordinate data can get corrupted.
54 bool filterJumpyTouchEvents;
55
56 // Gets the amount of time to disable virtual keys after the screen is touched
57 // in order to filter out accidental virtual key presses due to swiping gestures
58 // or taps near the edge of the display. May be 0 to disable the feature.
59 nsecs_t virtualKeyQuietTime;
60
61 // The excluded device names for the platform.
62 // Devices with these names will be ignored.
63 Vector<String8> excludedDeviceNames;
64
65 // Quiet time between certain pointer gesture transitions.
66 // Time to allow for all fingers or buttons to settle into a stable state before
67 // starting a new gesture.
68 nsecs_t pointerGestureQuietInterval;
69
70 // The minimum speed that a pointer must travel for us to consider switching the active
71 // touch pointer to it during a drag. This threshold is set to avoid switching due
72 // to noise from a finger resting on the touch pad (perhaps just pressing it down).
73 float pointerGestureDragMinSwitchSpeed; // in pixels per second
74
75 // Tap gesture delay time.
76 // The time between down and up must be less than this to be considered a tap.
77 nsecs_t pointerGestureTapInterval;
78
79 // Tap drag gesture delay time.
80 // The time between the previous tap's up and the next down must be less than
81 // this to be considered a drag. Otherwise, the previous tap is finished and a
82 // new tap begins.
83 //
84 // Note that the previous tap will be held down for this entire duration so this
85 // interval must be shorter than the long press timeout.
86 nsecs_t pointerGestureTapDragInterval;
87
88 // The distance in pixels that the pointer is allowed to move from initial down
89 // to up and still be called a tap.
90 float pointerGestureTapSlop; // in pixels
91
92 // Time after the first touch points go down to settle on an initial centroid.
93 // This is intended to be enough time to handle cases where the user puts down two
94 // fingers at almost but not quite exactly the same time.
95 nsecs_t pointerGestureMultitouchSettleInterval;
96
97 // The transition from PRESS to SWIPE or FREEFORM gesture mode is made when
98 // both of the pointers are moving at least this fast.
99 float pointerGestureMultitouchMinSpeed; // in pixels per second
100
101 // The transition from PRESS to SWIPE gesture mode can only occur when the
102 // cosine of the angle between the two vectors is greater than or equal to than this value
103 // which indicates that the vectors are oriented in the same direction.
104 // When the vectors are oriented in the exactly same direction, the cosine is 1.0.
105 // (In exactly opposite directions, the cosine is -1.0.)
106 float pointerGestureSwipeTransitionAngleCosine;
107
108 // The transition from PRESS to SWIPE gesture mode can only occur when the
109 // fingers are no more than this far apart relative to the diagonal size of
110 // the touch pad. For example, a ratio of 0.5 means that the fingers must be
111 // no more than half the diagonal size of the touch pad apart.
112 float pointerGestureSwipeMaxWidthRatio;
113
114 // The gesture movement speed factor relative to the size of the display.
115 // Movement speed applies when the fingers are moving in the same direction.
116 // Without acceleration, a full swipe of the touch pad diagonal in movement mode
117 // will cover this portion of the display diagonal.
118 float pointerGestureMovementSpeedRatio;
119
120 // The gesture zoom speed factor relative to the size of the display.
121 // Zoom speed applies when the fingers are mostly moving relative to each other
122 // to execute a scale gesture or similar.
123 // Without acceleration, a full swipe of the touch pad diagonal in zoom mode
124 // will cover this portion of the display diagonal.
125 float pointerGestureZoomSpeedRatio;
126
127 InputReaderConfiguration() :
128 filterTouchEvents(false),
129 filterJumpyTouchEvents(false),
130 virtualKeyQuietTime(0),
131 pointerGestureQuietInterval(100 * 1000000LL), // 100 ms
132 pointerGestureDragMinSwitchSpeed(50), // 50 pixels per second
133 pointerGestureTapInterval(150 * 1000000LL), // 150 ms
134 pointerGestureTapDragInterval(150 * 1000000LL), // 150 ms
135 pointerGestureTapSlop(10.0f), // 10 pixels
136 pointerGestureMultitouchSettleInterval(100 * 1000000LL), // 100 ms
137 pointerGestureMultitouchMinSpeed(150.0f), // 150 pixels per second
138 pointerGestureSwipeTransitionAngleCosine(0.5f), // cosine of 45degrees
139 pointerGestureSwipeMaxWidthRatio(0.333f),
140 pointerGestureMovementSpeedRatio(0.8f),
141 pointerGestureZoomSpeedRatio(0.3f) { }
142};
143
144
145/*
Jeff Brown9c3cda02010-06-15 01:31:58 -0700146 * Input reader policy interface.
147 *
148 * The input reader policy is used by the input reader to interact with the Window Manager
149 * and other system components.
150 *
151 * The actual implementation is partially supported by callbacks into the DVM
152 * via JNI. This interface is also mocked in the unit tests.
153 */
154class InputReaderPolicyInterface : public virtual RefBase {
155protected:
156 InputReaderPolicyInterface() { }
157 virtual ~InputReaderPolicyInterface() { }
158
159public:
160 /* Display orientations. */
161 enum {
162 ROTATION_0 = 0,
163 ROTATION_90 = 1,
164 ROTATION_180 = 2,
165 ROTATION_270 = 3
166 };
167
Jeff Brown9c3cda02010-06-15 01:31:58 -0700168 /* Gets information about the display with the specified id.
169 * Returns true if the display info is available, false otherwise.
170 */
171 virtual bool getDisplayInfo(int32_t displayId,
172 int32_t* width, int32_t* height, int32_t* orientation) = 0;
173
Jeff Brown214eaf42011-05-26 19:17:02 -0700174 /* Gets the input reader configuration. */
175 virtual void getReaderConfiguration(InputReaderConfiguration* outConfig) = 0;
Jeff Brown83c09682010-12-23 17:50:18 -0800176
177 /* Gets a pointer controller associated with the specified cursor device (ie. a mouse). */
178 virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId) = 0;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700179};
180
181
182/* Processes raw input events and sends cooked event data to an input dispatcher. */
Jeff Brown46b9ac02010-04-22 18:58:52 -0700183class InputReaderInterface : public virtual RefBase {
184protected:
185 InputReaderInterface() { }
186 virtual ~InputReaderInterface() { }
187
188public:
Jeff Brownb88102f2010-09-08 11:49:43 -0700189 /* Dumps the state of the input reader.
190 *
191 * This method may be called on any thread (usually by the input manager). */
192 virtual void dump(String8& dump) = 0;
193
Jeff Brown46b9ac02010-04-22 18:58:52 -0700194 /* Runs a single iteration of the processing loop.
195 * Nominally reads and processes one incoming message from the EventHub.
196 *
197 * This method should be called on the input reader thread.
198 */
199 virtual void loopOnce() = 0;
200
Jeff Brown9c3cda02010-06-15 01:31:58 -0700201 /* Gets the current input device configuration.
202 *
203 * This method may be called on any thread (usually by the input manager).
204 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700205 virtual void getInputConfiguration(InputConfiguration* outConfiguration) = 0;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700206
Jeff Brown6d0fec22010-07-23 21:28:06 -0700207 /* Gets information about the specified input device.
208 * Returns OK if the device information was obtained or NAME_NOT_FOUND if there
209 * was no such device.
210 *
211 * This method may be called on any thread (usually by the input manager).
Jeff Brown9c3cda02010-06-15 01:31:58 -0700212 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700213 virtual status_t getInputDeviceInfo(int32_t deviceId, InputDeviceInfo* outDeviceInfo) = 0;
214
215 /* Gets the list of all registered device ids. */
216 virtual void getInputDeviceIds(Vector<int32_t>& outDeviceIds) = 0;
217
218 /* Query current input state. */
219 virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask,
220 int32_t scanCode) = 0;
221 virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask,
222 int32_t keyCode) = 0;
223 virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask,
224 int32_t sw) = 0;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700225
226 /* Determine whether physical keys exist for the given framework-domain key codes. */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700227 virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask,
228 size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) = 0;
229};
230
231
232/* Internal interface used by individual input devices to access global input device state
233 * and parameters maintained by the input reader.
234 */
235class InputReaderContext {
Jeff Brownc3db8582010-10-20 15:33:38 -0700236public:
Jeff Brown6d0fec22010-07-23 21:28:06 -0700237 InputReaderContext() { }
238 virtual ~InputReaderContext() { }
239
Jeff Brown6d0fec22010-07-23 21:28:06 -0700240 virtual void updateGlobalMetaState() = 0;
241 virtual int32_t getGlobalMetaState() = 0;
242
Jeff Brownfe508922011-01-18 15:10:10 -0800243 virtual void disableVirtualKeysUntil(nsecs_t time) = 0;
244 virtual bool shouldDropVirtualKey(nsecs_t now,
245 InputDevice* device, int32_t keyCode, int32_t scanCode) = 0;
246
Jeff Brown05dc66a2011-03-02 14:41:58 -0800247 virtual void fadePointer() = 0;
248
Jeff Brown68d60752011-03-17 01:34:19 -0700249 virtual void requestTimeoutAtTime(nsecs_t when) = 0;
250
Jeff Brown6d0fec22010-07-23 21:28:06 -0700251 virtual InputReaderPolicyInterface* getPolicy() = 0;
Jeff Brown214eaf42011-05-26 19:17:02 -0700252 virtual const InputReaderConfiguration* getConfig() = 0;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700253 virtual InputDispatcherInterface* getDispatcher() = 0;
254 virtual EventHubInterface* getEventHub() = 0;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700255};
256
Jeff Brown9c3cda02010-06-15 01:31:58 -0700257
Jeff Brown46b9ac02010-04-22 18:58:52 -0700258/* The input reader reads raw event data from the event hub and processes it into input events
Jeff Brown9c3cda02010-06-15 01:31:58 -0700259 * that it sends to the input dispatcher. Some functions of the input reader, such as early
260 * event filtering in low power states, are controlled by a separate policy object.
261 *
262 * IMPORTANT INVARIANT:
Jeff Brown6d0fec22010-07-23 21:28:06 -0700263 * Because the policy and dispatcher can potentially block or cause re-entrance into
264 * the input reader, the input reader never calls into other components while holding
Jeff Brown6328cdc2010-07-29 18:18:33 -0700265 * an exclusive internal lock whenever re-entrance can happen.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700266 */
Jeff Brownc3db8582010-10-20 15:33:38 -0700267class InputReader : public InputReaderInterface, protected InputReaderContext {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700268public:
269 InputReader(const sp<EventHubInterface>& eventHub,
Jeff Brown9c3cda02010-06-15 01:31:58 -0700270 const sp<InputReaderPolicyInterface>& policy,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700271 const sp<InputDispatcherInterface>& dispatcher);
272 virtual ~InputReader();
273
Jeff Brownb88102f2010-09-08 11:49:43 -0700274 virtual void dump(String8& dump);
275
Jeff Brown46b9ac02010-04-22 18:58:52 -0700276 virtual void loopOnce();
277
Jeff Brown6d0fec22010-07-23 21:28:06 -0700278 virtual void getInputConfiguration(InputConfiguration* outConfiguration);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700279
Jeff Brown6d0fec22010-07-23 21:28:06 -0700280 virtual status_t getInputDeviceInfo(int32_t deviceId, InputDeviceInfo* outDeviceInfo);
281 virtual void getInputDeviceIds(Vector<int32_t>& outDeviceIds);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700282
Jeff Brown6d0fec22010-07-23 21:28:06 -0700283 virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask,
284 int32_t scanCode);
285 virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask,
286 int32_t keyCode);
287 virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask,
288 int32_t sw);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700289
Jeff Brown6d0fec22010-07-23 21:28:06 -0700290 virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask,
291 size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700292
Jeff Brownc3db8582010-10-20 15:33:38 -0700293protected:
294 // These methods are protected virtual so they can be overridden and instrumented
295 // by test cases.
296 virtual InputDevice* createDevice(int32_t deviceId, const String8& name, uint32_t classes);
297
Jeff Brown46b9ac02010-04-22 18:58:52 -0700298private:
Jeff Brown46b9ac02010-04-22 18:58:52 -0700299 sp<EventHubInterface> mEventHub;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700300 sp<InputReaderPolicyInterface> mPolicy;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700301 sp<InputDispatcherInterface> mDispatcher;
302
Jeff Brown214eaf42011-05-26 19:17:02 -0700303 InputReaderConfiguration mConfig;
304
Jeff Brown6d0fec22010-07-23 21:28:06 -0700305 virtual InputReaderPolicyInterface* getPolicy() { return mPolicy.get(); }
Jeff Brown214eaf42011-05-26 19:17:02 -0700306 virtual const InputReaderConfiguration* getConfig() { return &mConfig; }
Jeff Brown6d0fec22010-07-23 21:28:06 -0700307 virtual InputDispatcherInterface* getDispatcher() { return mDispatcher.get(); }
308 virtual EventHubInterface* getEventHub() { return mEventHub.get(); }
309
Jeff Browndbf8d272011-03-18 18:14:26 -0700310 // The event queue.
311 static const int EVENT_BUFFER_SIZE = 256;
312 RawEvent mEventBuffer[EVENT_BUFFER_SIZE];
313
Jeff Brown6d0fec22010-07-23 21:28:06 -0700314 // This reader/writer lock guards the list of input devices.
315 // The writer lock must be held whenever the list of input devices is modified
316 // and then promptly released.
317 // The reader lock must be held whenever the list of input devices is traversed or an
318 // input device in the list is accessed.
319 // This lock only protects the registry and prevents inadvertent deletion of device objects
320 // that are in use. Individual devices are responsible for guarding their own internal state
321 // as needed for concurrent operation.
322 RWLock mDeviceRegistryLock;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700323 KeyedVector<int32_t, InputDevice*> mDevices;
324
Jeff Brown6d0fec22010-07-23 21:28:06 -0700325 // low-level input event decoding and device management
Jeff Browndbf8d272011-03-18 18:14:26 -0700326 void processEvents(const RawEvent* rawEvents, size_t count);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700327
Jeff Brown7342bb92010-10-01 18:55:43 -0700328 void addDevice(int32_t deviceId);
329 void removeDevice(int32_t deviceId);
Jeff Browndbf8d272011-03-18 18:14:26 -0700330 void processEventsForDevice(int32_t deviceId, const RawEvent* rawEvents, size_t count);
Jeff Brown68d60752011-03-17 01:34:19 -0700331 void timeoutExpired(nsecs_t when);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700332
Jeff Brownc3db8582010-10-20 15:33:38 -0700333 void handleConfigurationChanged(nsecs_t when);
Jeff Browndbf8d272011-03-18 18:14:26 -0700334 void configureExcludedDevices();
Jeff Brown9c3cda02010-06-15 01:31:58 -0700335
Jeff Brown6d0fec22010-07-23 21:28:06 -0700336 // state management for all devices
337 Mutex mStateLock;
338
339 int32_t mGlobalMetaState;
340 virtual void updateGlobalMetaState();
341 virtual int32_t getGlobalMetaState();
342
Jeff Brown05dc66a2011-03-02 14:41:58 -0800343 virtual void fadePointer();
344
Jeff Brown6d0fec22010-07-23 21:28:06 -0700345 InputConfiguration mInputConfiguration;
346 void updateInputConfiguration();
347
Jeff Browndbf8d272011-03-18 18:14:26 -0700348 nsecs_t mDisableVirtualKeysTimeout; // only accessed by reader thread
Jeff Brownfe508922011-01-18 15:10:10 -0800349 virtual void disableVirtualKeysUntil(nsecs_t time);
350 virtual bool shouldDropVirtualKey(nsecs_t now,
351 InputDevice* device, int32_t keyCode, int32_t scanCode);
352
Jeff Browndbf8d272011-03-18 18:14:26 -0700353 nsecs_t mNextTimeout; // only accessed by reader thread
Jeff Brown68d60752011-03-17 01:34:19 -0700354 virtual void requestTimeoutAtTime(nsecs_t when);
355
Jeff Brown6d0fec22010-07-23 21:28:06 -0700356 // state queries
357 typedef int32_t (InputDevice::*GetStateFunc)(uint32_t sourceMask, int32_t code);
358 int32_t getState(int32_t deviceId, uint32_t sourceMask, int32_t code,
359 GetStateFunc getStateFunc);
360 bool markSupportedKeyCodes(int32_t deviceId, uint32_t sourceMask, size_t numCodes,
361 const int32_t* keyCodes, uint8_t* outFlags);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700362};
363
364
365/* Reads raw events from the event hub and processes them, endlessly. */
366class InputReaderThread : public Thread {
367public:
368 InputReaderThread(const sp<InputReaderInterface>& reader);
369 virtual ~InputReaderThread();
370
371private:
372 sp<InputReaderInterface> mReader;
373
374 virtual bool threadLoop();
375};
376
Jeff Brown6d0fec22010-07-23 21:28:06 -0700377
378/* Represents the state of a single input device. */
379class InputDevice {
380public:
381 InputDevice(InputReaderContext* context, int32_t id, const String8& name);
382 ~InputDevice();
383
384 inline InputReaderContext* getContext() { return mContext; }
385 inline int32_t getId() { return mId; }
386 inline const String8& getName() { return mName; }
387 inline uint32_t getSources() { return mSources; }
388
Jeff Brown56194eb2011-03-02 19:23:13 -0800389 inline bool isExternal() { return mIsExternal; }
390 inline void setExternal(bool external) { mIsExternal = external; }
391
Jeff Brown6d0fec22010-07-23 21:28:06 -0700392 inline bool isIgnored() { return mMappers.isEmpty(); }
393
Jeff Brownef3d7e82010-09-30 14:33:04 -0700394 void dump(String8& dump);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700395 void addMapper(InputMapper* mapper);
396 void configure();
397 void reset();
Jeff Browndbf8d272011-03-18 18:14:26 -0700398 void process(const RawEvent* rawEvents, size_t count);
Jeff Brown68d60752011-03-17 01:34:19 -0700399 void timeoutExpired(nsecs_t when);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700400
401 void getDeviceInfo(InputDeviceInfo* outDeviceInfo);
402 int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
403 int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
404 int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
405 bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
406 const int32_t* keyCodes, uint8_t* outFlags);
407
408 int32_t getMetaState();
409
Jeff Brown05dc66a2011-03-02 14:41:58 -0800410 void fadePointer();
411
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800412 inline const PropertyMap& getConfiguration() {
413 return mConfiguration;
Jeff Brown8d608662010-08-30 03:02:23 -0700414 }
415
Jeff Brown6d0fec22010-07-23 21:28:06 -0700416private:
417 InputReaderContext* mContext;
418 int32_t mId;
419
420 Vector<InputMapper*> mMappers;
421
422 String8 mName;
423 uint32_t mSources;
Jeff Brown56194eb2011-03-02 19:23:13 -0800424 bool mIsExternal;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700425
426 typedef int32_t (InputMapper::*GetStateFunc)(uint32_t sourceMask, int32_t code);
427 int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc);
Jeff Brown8d608662010-08-30 03:02:23 -0700428
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800429 PropertyMap mConfiguration;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700430};
431
432
433/* An input mapper transforms raw input events into cooked event data.
434 * A single input device can have multiple associated input mappers in order to interpret
435 * different classes of events.
436 */
437class InputMapper {
438public:
439 InputMapper(InputDevice* device);
440 virtual ~InputMapper();
441
442 inline InputDevice* getDevice() { return mDevice; }
443 inline int32_t getDeviceId() { return mDevice->getId(); }
444 inline const String8 getDeviceName() { return mDevice->getName(); }
445 inline InputReaderContext* getContext() { return mContext; }
446 inline InputReaderPolicyInterface* getPolicy() { return mContext->getPolicy(); }
Jeff Brown214eaf42011-05-26 19:17:02 -0700447 inline const InputReaderConfiguration* getConfig() { return mContext->getConfig(); }
Jeff Brown6d0fec22010-07-23 21:28:06 -0700448 inline InputDispatcherInterface* getDispatcher() { return mContext->getDispatcher(); }
449 inline EventHubInterface* getEventHub() { return mContext->getEventHub(); }
450
451 virtual uint32_t getSources() = 0;
452 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
Jeff Brownef3d7e82010-09-30 14:33:04 -0700453 virtual void dump(String8& dump);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700454 virtual void configure();
455 virtual void reset();
456 virtual void process(const RawEvent* rawEvent) = 0;
Jeff Brown68d60752011-03-17 01:34:19 -0700457 virtual void timeoutExpired(nsecs_t when);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700458
459 virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
460 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
461 virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
462 virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
463 const int32_t* keyCodes, uint8_t* outFlags);
464
465 virtual int32_t getMetaState();
466
Jeff Brown05dc66a2011-03-02 14:41:58 -0800467 virtual void fadePointer();
468
Jeff Brown6d0fec22010-07-23 21:28:06 -0700469protected:
470 InputDevice* mDevice;
471 InputReaderContext* mContext;
Jeff Browncb1404e2011-01-15 18:14:15 -0800472
473 static void dumpRawAbsoluteAxisInfo(String8& dump,
474 const RawAbsoluteAxisInfo& axis, const char* name);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700475};
476
477
478class SwitchInputMapper : public InputMapper {
479public:
480 SwitchInputMapper(InputDevice* device);
481 virtual ~SwitchInputMapper();
482
483 virtual uint32_t getSources();
484 virtual void process(const RawEvent* rawEvent);
485
486 virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
487
488private:
489 void processSwitch(nsecs_t when, int32_t switchCode, int32_t switchValue);
490};
491
492
493class KeyboardInputMapper : public InputMapper {
494public:
Jeff Brownefd32662011-03-08 15:13:06 -0800495 KeyboardInputMapper(InputDevice* device, uint32_t source, int32_t keyboardType);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700496 virtual ~KeyboardInputMapper();
497
498 virtual uint32_t getSources();
499 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
Jeff Brownef3d7e82010-09-30 14:33:04 -0700500 virtual void dump(String8& dump);
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800501 virtual void configure();
Jeff Brown6d0fec22010-07-23 21:28:06 -0700502 virtual void reset();
503 virtual void process(const RawEvent* rawEvent);
504
505 virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
506 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
507 virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
508 const int32_t* keyCodes, uint8_t* outFlags);
509
510 virtual int32_t getMetaState();
511
512private:
Jeff Brown6328cdc2010-07-29 18:18:33 -0700513 Mutex mLock;
514
Jeff Brown6d0fec22010-07-23 21:28:06 -0700515 struct KeyDown {
516 int32_t keyCode;
517 int32_t scanCode;
518 };
519
Jeff Brownefd32662011-03-08 15:13:06 -0800520 uint32_t mSource;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700521 int32_t mKeyboardType;
522
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800523 // Immutable configuration parameters.
524 struct Parameters {
525 int32_t associatedDisplayId;
526 bool orientationAware;
527 } mParameters;
528
Jeff Brown6328cdc2010-07-29 18:18:33 -0700529 struct LockedState {
530 Vector<KeyDown> keyDowns; // keys that are down
531 int32_t metaState;
532 nsecs_t downTime; // time of most recent key down
Jeff Brown497a92c2010-09-12 17:55:08 -0700533
534 struct LedState {
535 bool avail; // led is available
536 bool on; // we think the led is currently on
537 };
538 LedState capsLockLedState;
539 LedState numLockLedState;
540 LedState scrollLockLedState;
Jeff Brown6328cdc2010-07-29 18:18:33 -0700541 } mLocked;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700542
Jeff Brown6328cdc2010-07-29 18:18:33 -0700543 void initializeLocked();
Jeff Brown6d0fec22010-07-23 21:28:06 -0700544
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800545 void configureParameters();
546 void dumpParameters(String8& dump);
547
Jeff Brown6d0fec22010-07-23 21:28:06 -0700548 bool isKeyboardOrGamepadKey(int32_t scanCode);
Jeff Brown6328cdc2010-07-29 18:18:33 -0700549
Jeff Brown6d0fec22010-07-23 21:28:06 -0700550 void processKey(nsecs_t when, bool down, int32_t keyCode, int32_t scanCode,
551 uint32_t policyFlags);
552
Jeff Brown6328cdc2010-07-29 18:18:33 -0700553 ssize_t findKeyDownLocked(int32_t scanCode);
Jeff Brown497a92c2010-09-12 17:55:08 -0700554
Jeff Brown49ed71d2010-12-06 17:13:33 -0800555 void resetLedStateLocked();
556 void initializeLedStateLocked(LockedState::LedState& ledState, int32_t led);
Jeff Brown497a92c2010-09-12 17:55:08 -0700557 void updateLedStateLocked(bool reset);
558 void updateLedStateForModifierLocked(LockedState::LedState& ledState, int32_t led,
559 int32_t modifier, bool reset);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700560};
561
562
Jeff Brown83c09682010-12-23 17:50:18 -0800563class CursorInputMapper : public InputMapper {
Jeff Brown6d0fec22010-07-23 21:28:06 -0700564public:
Jeff Brown83c09682010-12-23 17:50:18 -0800565 CursorInputMapper(InputDevice* device);
566 virtual ~CursorInputMapper();
Jeff Brown6d0fec22010-07-23 21:28:06 -0700567
568 virtual uint32_t getSources();
569 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
Jeff Brownef3d7e82010-09-30 14:33:04 -0700570 virtual void dump(String8& dump);
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800571 virtual void configure();
Jeff Brown6d0fec22010-07-23 21:28:06 -0700572 virtual void reset();
573 virtual void process(const RawEvent* rawEvent);
574
Jeff Brownc3fc2d02010-08-10 15:47:53 -0700575 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
576
Jeff Brown05dc66a2011-03-02 14:41:58 -0800577 virtual void fadePointer();
578
Jeff Brown6d0fec22010-07-23 21:28:06 -0700579private:
580 // Amount that trackball needs to move in order to generate a key event.
581 static const int32_t TRACKBALL_MOVEMENT_THRESHOLD = 6;
582
Jeff Brown6328cdc2010-07-29 18:18:33 -0700583 Mutex mLock;
584
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800585 // Immutable configuration parameters.
586 struct Parameters {
Jeff Brown83c09682010-12-23 17:50:18 -0800587 enum Mode {
588 MODE_POINTER,
589 MODE_NAVIGATION,
590 };
591
592 Mode mode;
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800593 int32_t associatedDisplayId;
594 bool orientationAware;
595 } mParameters;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700596
597 struct Accumulator {
598 enum {
Jeff Brownefd32662011-03-08 15:13:06 -0800599 FIELD_BUTTONS = 1,
Jeff Brown6d0fec22010-07-23 21:28:06 -0700600 FIELD_REL_X = 2,
Jeff Brown6f2fba42011-02-19 01:08:02 -0800601 FIELD_REL_Y = 4,
602 FIELD_REL_WHEEL = 8,
603 FIELD_REL_HWHEEL = 16,
Jeff Brown6d0fec22010-07-23 21:28:06 -0700604 };
605
606 uint32_t fields;
607
Jeff Brownefd32662011-03-08 15:13:06 -0800608 uint32_t buttonDown;
609 uint32_t buttonUp;
610
Jeff Brown6d0fec22010-07-23 21:28:06 -0700611 int32_t relX;
612 int32_t relY;
Jeff Brown6f2fba42011-02-19 01:08:02 -0800613 int32_t relWheel;
614 int32_t relHWheel;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700615
616 inline void clear() {
617 fields = 0;
618 }
Jeff Brown6d0fec22010-07-23 21:28:06 -0700619 } mAccumulator;
620
Jeff Brownefd32662011-03-08 15:13:06 -0800621 int32_t mSource;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700622 float mXScale;
623 float mYScale;
624 float mXPrecision;
625 float mYPrecision;
Jeff Brown6f2fba42011-02-19 01:08:02 -0800626
627 bool mHaveVWheel;
628 bool mHaveHWheel;
629 float mVWheelScale;
630 float mHWheelScale;
631
Jeff Brown83c09682010-12-23 17:50:18 -0800632 sp<PointerControllerInterface> mPointerController;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700633
Jeff Brown6328cdc2010-07-29 18:18:33 -0700634 struct LockedState {
Jeff Brownefd32662011-03-08 15:13:06 -0800635 uint32_t buttonState;
Jeff Brown6328cdc2010-07-29 18:18:33 -0700636 nsecs_t downTime;
637 } mLocked;
638
639 void initializeLocked();
Jeff Brown6d0fec22010-07-23 21:28:06 -0700640
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800641 void configureParameters();
642 void dumpParameters(String8& dump);
643
Jeff Brown6d0fec22010-07-23 21:28:06 -0700644 void sync(nsecs_t when);
645};
646
647
648class TouchInputMapper : public InputMapper {
649public:
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800650 TouchInputMapper(InputDevice* device);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700651 virtual ~TouchInputMapper();
652
653 virtual uint32_t getSources();
654 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
Jeff Brownef3d7e82010-09-30 14:33:04 -0700655 virtual void dump(String8& dump);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700656 virtual void configure();
657 virtual void reset();
658
659 virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
660 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
661 virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
662 const int32_t* keyCodes, uint8_t* outFlags);
663
Jeff Brown96ad3972011-03-09 17:39:48 -0800664 virtual void fadePointer();
Jeff Brown325bd072011-04-19 21:20:10 -0700665 virtual void timeoutExpired(nsecs_t when);
Jeff Brown96ad3972011-03-09 17:39:48 -0800666
Jeff Brown6d0fec22010-07-23 21:28:06 -0700667protected:
Jeff Brown6328cdc2010-07-29 18:18:33 -0700668 Mutex mLock;
669
Jeff Brown6d0fec22010-07-23 21:28:06 -0700670 struct VirtualKey {
671 int32_t keyCode;
672 int32_t scanCode;
673 uint32_t flags;
674
675 // computed hit box, specified in touch screen coords based on known display size
676 int32_t hitLeft;
677 int32_t hitTop;
678 int32_t hitRight;
679 int32_t hitBottom;
680
681 inline bool isHit(int32_t x, int32_t y) const {
682 return x >= hitLeft && x <= hitRight && y >= hitTop && y <= hitBottom;
683 }
684 };
685
Jeff Brown8d608662010-08-30 03:02:23 -0700686 // Raw data for a single pointer.
Jeff Brown6d0fec22010-07-23 21:28:06 -0700687 struct PointerData {
688 uint32_t id;
689 int32_t x;
690 int32_t y;
691 int32_t pressure;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700692 int32_t touchMajor;
693 int32_t touchMinor;
694 int32_t toolMajor;
695 int32_t toolMinor;
696 int32_t orientation;
Jeff Brownc3db8582010-10-20 15:33:38 -0700697
698 inline bool operator== (const PointerData& other) const {
699 return id == other.id
700 && x == other.x
701 && y == other.y
702 && pressure == other.pressure
703 && touchMajor == other.touchMajor
704 && touchMinor == other.touchMinor
705 && toolMajor == other.toolMajor
706 && toolMinor == other.toolMinor
707 && orientation == other.orientation;
708 }
709 inline bool operator!= (const PointerData& other) const {
710 return !(*this == other);
711 }
Jeff Brown6d0fec22010-07-23 21:28:06 -0700712 };
713
Jeff Brown8d608662010-08-30 03:02:23 -0700714 // Raw data for a collection of pointers including a pointer id mapping table.
Jeff Brown6d0fec22010-07-23 21:28:06 -0700715 struct TouchData {
716 uint32_t pointerCount;
717 PointerData pointers[MAX_POINTERS];
718 BitSet32 idBits;
719 uint32_t idToIndex[MAX_POINTER_ID + 1];
Jeff Brown96ad3972011-03-09 17:39:48 -0800720 uint32_t buttonState;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700721
722 void copyFrom(const TouchData& other) {
723 pointerCount = other.pointerCount;
724 idBits = other.idBits;
Jeff Brown96ad3972011-03-09 17:39:48 -0800725 buttonState = other.buttonState;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700726
727 for (uint32_t i = 0; i < pointerCount; i++) {
728 pointers[i] = other.pointers[i];
Jeff Brown9e2ad362010-07-30 19:20:11 -0700729
730 int id = pointers[i].id;
731 idToIndex[id] = other.idToIndex[id];
Jeff Brown6d0fec22010-07-23 21:28:06 -0700732 }
733 }
734
735 inline void clear() {
736 pointerCount = 0;
737 idBits.clear();
Jeff Brown96ad3972011-03-09 17:39:48 -0800738 buttonState = 0;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700739 }
Jeff Brown86ea1f52011-04-12 22:39:53 -0700740
741 void getCentroid(float* outX, float* outY) {
742 float x = 0, y = 0;
743 if (pointerCount != 0) {
744 for (uint32_t i = 0; i < pointerCount; i++) {
745 x += pointers[i].x;
746 y += pointers[i].y;
747 }
748 x /= pointerCount;
749 y /= pointerCount;
750 }
751 *outX = x;
752 *outY = y;
753 }
Jeff Brown6d0fec22010-07-23 21:28:06 -0700754 };
755
Jeff Brown83c09682010-12-23 17:50:18 -0800756 // Input sources supported by the device.
Jeff Brownefd32662011-03-08 15:13:06 -0800757 uint32_t mTouchSource; // sources when reporting touch data
Jeff Brown96ad3972011-03-09 17:39:48 -0800758 uint32_t mPointerSource; // sources when reporting pointer gestures
Jeff Brown83c09682010-12-23 17:50:18 -0800759
Jeff Brown214eaf42011-05-26 19:17:02 -0700760 // The reader's configuration.
761 const InputReaderConfiguration* mConfig;
762
Jeff Brown6d0fec22010-07-23 21:28:06 -0700763 // Immutable configuration parameters.
764 struct Parameters {
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800765 enum DeviceType {
766 DEVICE_TYPE_TOUCH_SCREEN,
767 DEVICE_TYPE_TOUCH_PAD,
Jeff Brown96ad3972011-03-09 17:39:48 -0800768 DEVICE_TYPE_POINTER,
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800769 };
770
771 DeviceType deviceType;
772 int32_t associatedDisplayId;
773 bool orientationAware;
774
Jeff Brown6d0fec22010-07-23 21:28:06 -0700775 bool useBadTouchFilter;
776 bool useJumpyTouchFilter;
777 bool useAveragingTouchFilter;
Jeff Brown86ea1f52011-04-12 22:39:53 -0700778
779 enum GestureMode {
780 GESTURE_MODE_POINTER,
781 GESTURE_MODE_SPOTS,
782 };
783 GestureMode gestureMode;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700784 } mParameters;
785
Jeff Brown8d608662010-08-30 03:02:23 -0700786 // Immutable calibration parameters in parsed form.
787 struct Calibration {
Jeff Brownc6d282b2010-10-14 21:42:15 -0700788 // Touch Size
789 enum TouchSizeCalibration {
790 TOUCH_SIZE_CALIBRATION_DEFAULT,
791 TOUCH_SIZE_CALIBRATION_NONE,
792 TOUCH_SIZE_CALIBRATION_GEOMETRIC,
793 TOUCH_SIZE_CALIBRATION_PRESSURE,
Jeff Brown8d608662010-08-30 03:02:23 -0700794 };
795
Jeff Brownc6d282b2010-10-14 21:42:15 -0700796 TouchSizeCalibration touchSizeCalibration;
Jeff Brown8d608662010-08-30 03:02:23 -0700797
Jeff Brownc6d282b2010-10-14 21:42:15 -0700798 // Tool Size
799 enum ToolSizeCalibration {
800 TOOL_SIZE_CALIBRATION_DEFAULT,
801 TOOL_SIZE_CALIBRATION_NONE,
802 TOOL_SIZE_CALIBRATION_GEOMETRIC,
803 TOOL_SIZE_CALIBRATION_LINEAR,
804 TOOL_SIZE_CALIBRATION_AREA,
Jeff Brown8d608662010-08-30 03:02:23 -0700805 };
806
Jeff Brownc6d282b2010-10-14 21:42:15 -0700807 ToolSizeCalibration toolSizeCalibration;
808 bool haveToolSizeLinearScale;
809 float toolSizeLinearScale;
810 bool haveToolSizeLinearBias;
811 float toolSizeLinearBias;
812 bool haveToolSizeAreaScale;
813 float toolSizeAreaScale;
814 bool haveToolSizeAreaBias;
815 float toolSizeAreaBias;
816 bool haveToolSizeIsSummed;
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800817 bool toolSizeIsSummed;
Jeff Brown8d608662010-08-30 03:02:23 -0700818
819 // Pressure
820 enum PressureCalibration {
821 PRESSURE_CALIBRATION_DEFAULT,
822 PRESSURE_CALIBRATION_NONE,
823 PRESSURE_CALIBRATION_PHYSICAL,
824 PRESSURE_CALIBRATION_AMPLITUDE,
825 };
826 enum PressureSource {
827 PRESSURE_SOURCE_DEFAULT,
828 PRESSURE_SOURCE_PRESSURE,
829 PRESSURE_SOURCE_TOUCH,
830 };
831
832 PressureCalibration pressureCalibration;
833 PressureSource pressureSource;
834 bool havePressureScale;
835 float pressureScale;
836
837 // Size
838 enum SizeCalibration {
839 SIZE_CALIBRATION_DEFAULT,
840 SIZE_CALIBRATION_NONE,
841 SIZE_CALIBRATION_NORMALIZED,
842 };
843
844 SizeCalibration sizeCalibration;
845
846 // Orientation
847 enum OrientationCalibration {
848 ORIENTATION_CALIBRATION_DEFAULT,
849 ORIENTATION_CALIBRATION_NONE,
850 ORIENTATION_CALIBRATION_INTERPOLATED,
Jeff Brown517bb4c2011-01-14 19:09:23 -0800851 ORIENTATION_CALIBRATION_VECTOR,
Jeff Brown8d608662010-08-30 03:02:23 -0700852 };
853
854 OrientationCalibration orientationCalibration;
855 } mCalibration;
856
857 // Raw axis information from the driver.
858 struct RawAxes {
Jeff Brown6d0fec22010-07-23 21:28:06 -0700859 RawAbsoluteAxisInfo x;
860 RawAbsoluteAxisInfo y;
861 RawAbsoluteAxisInfo pressure;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700862 RawAbsoluteAxisInfo touchMajor;
863 RawAbsoluteAxisInfo touchMinor;
864 RawAbsoluteAxisInfo toolMajor;
865 RawAbsoluteAxisInfo toolMinor;
866 RawAbsoluteAxisInfo orientation;
Jeff Brown8d608662010-08-30 03:02:23 -0700867 } mRawAxes;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700868
Jeff Brown6328cdc2010-07-29 18:18:33 -0700869 // Current and previous touch sample data.
Jeff Brown6d0fec22010-07-23 21:28:06 -0700870 TouchData mCurrentTouch;
Jeff Brown96ad3972011-03-09 17:39:48 -0800871 PointerCoords mCurrentTouchCoords[MAX_POINTERS];
872
Jeff Brown6d0fec22010-07-23 21:28:06 -0700873 TouchData mLastTouch;
Jeff Brown96ad3972011-03-09 17:39:48 -0800874 PointerCoords mLastTouchCoords[MAX_POINTERS];
Jeff Brown6d0fec22010-07-23 21:28:06 -0700875
876 // The time the primary pointer last went down.
877 nsecs_t mDownTime;
878
Jeff Brown96ad3972011-03-09 17:39:48 -0800879 // The pointer controller, or null if the device is not a pointer.
880 sp<PointerControllerInterface> mPointerController;
881
Jeff Brown6328cdc2010-07-29 18:18:33 -0700882 struct LockedState {
883 Vector<VirtualKey> virtualKeys;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700884
Jeff Brown6328cdc2010-07-29 18:18:33 -0700885 // The surface orientation and width and height set by configureSurfaceLocked().
886 int32_t surfaceOrientation;
887 int32_t surfaceWidth, surfaceHeight;
888
Jeff Brownefd32662011-03-08 15:13:06 -0800889 // The associated display orientation and width and height set by configureSurfaceLocked().
890 int32_t associatedDisplayOrientation;
891 int32_t associatedDisplayWidth, associatedDisplayHeight;
892
Jeff Brown6328cdc2010-07-29 18:18:33 -0700893 // Translation and scaling factors, orientation-independent.
Jeff Brown6328cdc2010-07-29 18:18:33 -0700894 float xScale;
895 float xPrecision;
896
Jeff Brown6328cdc2010-07-29 18:18:33 -0700897 float yScale;
898 float yPrecision;
899
Jeff Brown8d608662010-08-30 03:02:23 -0700900 float geometricScale;
901
Jeff Brownc6d282b2010-10-14 21:42:15 -0700902 float toolSizeLinearScale;
903 float toolSizeLinearBias;
904 float toolSizeAreaScale;
905 float toolSizeAreaBias;
Jeff Brown8d608662010-08-30 03:02:23 -0700906
Jeff Brown6328cdc2010-07-29 18:18:33 -0700907 float pressureScale;
908
Jeff Brown6328cdc2010-07-29 18:18:33 -0700909 float sizeScale;
910
911 float orientationScale;
912
913 // Oriented motion ranges for input device info.
914 struct OrientedRanges {
915 InputDeviceInfo::MotionRange x;
916 InputDeviceInfo::MotionRange y;
Jeff Brown8d608662010-08-30 03:02:23 -0700917
918 bool havePressure;
Jeff Brown6328cdc2010-07-29 18:18:33 -0700919 InputDeviceInfo::MotionRange pressure;
Jeff Brown8d608662010-08-30 03:02:23 -0700920
921 bool haveSize;
Jeff Brown6328cdc2010-07-29 18:18:33 -0700922 InputDeviceInfo::MotionRange size;
Jeff Brown8d608662010-08-30 03:02:23 -0700923
Jeff Brownc6d282b2010-10-14 21:42:15 -0700924 bool haveTouchSize;
Jeff Brown6328cdc2010-07-29 18:18:33 -0700925 InputDeviceInfo::MotionRange touchMajor;
926 InputDeviceInfo::MotionRange touchMinor;
Jeff Brown8d608662010-08-30 03:02:23 -0700927
Jeff Brownc6d282b2010-10-14 21:42:15 -0700928 bool haveToolSize;
Jeff Brown6328cdc2010-07-29 18:18:33 -0700929 InputDeviceInfo::MotionRange toolMajor;
930 InputDeviceInfo::MotionRange toolMinor;
Jeff Brown8d608662010-08-30 03:02:23 -0700931
932 bool haveOrientation;
Jeff Brown6328cdc2010-07-29 18:18:33 -0700933 InputDeviceInfo::MotionRange orientation;
934 } orientedRanges;
935
936 // Oriented dimensions and precision.
937 float orientedSurfaceWidth, orientedSurfaceHeight;
938 float orientedXPrecision, orientedYPrecision;
939
940 struct CurrentVirtualKeyState {
941 bool down;
942 nsecs_t downTime;
943 int32_t keyCode;
944 int32_t scanCode;
945 } currentVirtualKey;
Jeff Brown96ad3972011-03-09 17:39:48 -0800946
947 // Scale factor for gesture based pointer movements.
948 float pointerGestureXMovementScale;
949 float pointerGestureYMovementScale;
950
951 // Scale factor for gesture based zooming and other freeform motions.
952 float pointerGestureXZoomScale;
953 float pointerGestureYZoomScale;
954
Jeff Brown86ea1f52011-04-12 22:39:53 -0700955 // The maximum swipe width.
956 float pointerGestureMaxSwipeWidth;
Jeff Brown6328cdc2010-07-29 18:18:33 -0700957 } mLocked;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700958
Jeff Brown8d608662010-08-30 03:02:23 -0700959 virtual void configureParameters();
Jeff Brownef3d7e82010-09-30 14:33:04 -0700960 virtual void dumpParameters(String8& dump);
Jeff Brown8d608662010-08-30 03:02:23 -0700961 virtual void configureRawAxes();
Jeff Brownef3d7e82010-09-30 14:33:04 -0700962 virtual void dumpRawAxes(String8& dump);
Jeff Brown6328cdc2010-07-29 18:18:33 -0700963 virtual bool configureSurfaceLocked();
Jeff Brownef3d7e82010-09-30 14:33:04 -0700964 virtual void dumpSurfaceLocked(String8& dump);
Jeff Brown6328cdc2010-07-29 18:18:33 -0700965 virtual void configureVirtualKeysLocked();
Jeff Brownef3d7e82010-09-30 14:33:04 -0700966 virtual void dumpVirtualKeysLocked(String8& dump);
Jeff Brown8d608662010-08-30 03:02:23 -0700967 virtual void parseCalibration();
968 virtual void resolveCalibration();
Jeff Brownef3d7e82010-09-30 14:33:04 -0700969 virtual void dumpCalibration(String8& dump);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700970
971 enum TouchResult {
972 // Dispatch the touch normally.
973 DISPATCH_TOUCH,
974 // Do not dispatch the touch, but keep tracking the current stroke.
975 SKIP_TOUCH,
976 // Do not dispatch the touch, and drop all information associated with the current stoke
977 // so the next movement will appear as a new down.
978 DROP_STROKE
979 };
980
981 void syncTouch(nsecs_t when, bool havePointerIds);
982
983private:
984 /* Maximum number of historical samples to average. */
985 static const uint32_t AVERAGING_HISTORY_SIZE = 5;
986
987 /* Slop distance for jumpy pointer detection.
988 * The vertical range of the screen divided by this is our epsilon value. */
989 static const uint32_t JUMPY_EPSILON_DIVISOR = 212;
990
991 /* Number of jumpy points to drop for touchscreens that need it. */
992 static const uint32_t JUMPY_TRANSITION_DROPS = 3;
993 static const uint32_t JUMPY_DROP_LIMIT = 3;
994
995 /* Maximum squared distance for averaging.
996 * If moving farther than this, turn of averaging to avoid lag in response. */
997 static const uint64_t AVERAGING_DISTANCE_LIMIT = 75 * 75;
998
999 struct AveragingTouchFilterState {
1000 // Individual history tracks are stored by pointer id
1001 uint32_t historyStart[MAX_POINTERS];
1002 uint32_t historyEnd[MAX_POINTERS];
1003 struct {
1004 struct {
1005 int32_t x;
1006 int32_t y;
1007 int32_t pressure;
1008 } pointers[MAX_POINTERS];
1009 } historyData[AVERAGING_HISTORY_SIZE];
1010 } mAveragingTouchFilter;
1011
Jeff Brown2dfd7a72010-08-17 20:38:35 -07001012 struct JumpyTouchFilterState {
Jeff Brown6d0fec22010-07-23 21:28:06 -07001013 uint32_t jumpyPointsDropped;
1014 } mJumpyTouchFilter;
1015
1016 struct PointerDistanceHeapElement {
1017 uint32_t currentPointerIndex : 8;
1018 uint32_t lastPointerIndex : 8;
1019 uint64_t distance : 48; // squared distance
1020 };
1021
Jeff Brown96ad3972011-03-09 17:39:48 -08001022 struct PointerGesture {
1023 enum Mode {
1024 // No fingers, button is not pressed.
1025 // Nothing happening.
1026 NEUTRAL,
1027
1028 // No fingers, button is not pressed.
1029 // Tap detected.
1030 // Emits DOWN and UP events at the pointer location.
1031 TAP,
1032
Jeff Brown325bd072011-04-19 21:20:10 -07001033 // Exactly one finger dragging following a tap.
1034 // Pointer follows the active finger.
1035 // Emits DOWN, MOVE and UP events at the pointer location.
Jeff Brown214eaf42011-05-26 19:17:02 -07001036 //
1037 // Detect double-taps when the finger goes up while in TAP_DRAG mode.
Jeff Brown325bd072011-04-19 21:20:10 -07001038 TAP_DRAG,
1039
Jeff Brown96ad3972011-03-09 17:39:48 -08001040 // Button is pressed.
1041 // Pointer follows the active finger if there is one. Other fingers are ignored.
1042 // Emits DOWN, MOVE and UP events at the pointer location.
Jeff Brown325bd072011-04-19 21:20:10 -07001043 BUTTON_CLICK_OR_DRAG,
Jeff Brown96ad3972011-03-09 17:39:48 -08001044
1045 // Exactly one finger, button is not pressed.
1046 // Pointer follows the active finger.
1047 // Emits HOVER_MOVE events at the pointer location.
Jeff Brown214eaf42011-05-26 19:17:02 -07001048 //
1049 // Detect taps when the finger goes up while in HOVER mode.
Jeff Brown96ad3972011-03-09 17:39:48 -08001050 HOVER,
1051
Jeff Brown86ea1f52011-04-12 22:39:53 -07001052 // Exactly two fingers but neither have moved enough to clearly indicate
1053 // whether a swipe or freeform gesture was intended. We consider the
1054 // pointer to be pressed so this enables clicking or long-pressing on buttons.
1055 // Pointer does not move.
1056 // Emits DOWN, MOVE and UP events with a single stationary pointer coordinate.
1057 PRESS,
Jeff Brown96ad3972011-03-09 17:39:48 -08001058
1059 // Exactly two fingers moving in the same direction, button is not pressed.
1060 // Pointer does not move.
1061 // Emits DOWN, MOVE and UP events with a single pointer coordinate that
1062 // follows the midpoint between both fingers.
Jeff Brown96ad3972011-03-09 17:39:48 -08001063 SWIPE,
1064
1065 // Two or more fingers moving in arbitrary directions, button is not pressed.
1066 // Pointer does not move.
1067 // Emits DOWN, POINTER_DOWN, MOVE, POINTER_UP and UP events that follow
1068 // each finger individually relative to the initial centroid of the finger.
Jeff Brown96ad3972011-03-09 17:39:48 -08001069 FREEFORM,
1070
1071 // Waiting for quiet time to end before starting the next gesture.
1072 QUIET,
1073 };
1074
Jeff Brown86ea1f52011-04-12 22:39:53 -07001075 // Time the first finger went down.
1076 nsecs_t firstTouchTime;
1077
Jeff Brown96ad3972011-03-09 17:39:48 -08001078 // The active pointer id from the raw touch data.
1079 int32_t activeTouchId; // -1 if none
1080
1081 // The active pointer id from the gesture last delivered to the application.
1082 int32_t activeGestureId; // -1 if none
1083
1084 // Pointer coords and ids for the current and previous pointer gesture.
1085 Mode currentGestureMode;
Jeff Brown96ad3972011-03-09 17:39:48 -08001086 BitSet32 currentGestureIdBits;
1087 uint32_t currentGestureIdToIndex[MAX_POINTER_ID + 1];
1088 PointerCoords currentGestureCoords[MAX_POINTERS];
1089
1090 Mode lastGestureMode;
Jeff Brown96ad3972011-03-09 17:39:48 -08001091 BitSet32 lastGestureIdBits;
1092 uint32_t lastGestureIdToIndex[MAX_POINTER_ID + 1];
1093 PointerCoords lastGestureCoords[MAX_POINTERS];
1094
Jeff Brown86ea1f52011-04-12 22:39:53 -07001095 // Pointer coords and ids for the current spots.
1096 PointerControllerInterface::SpotGesture spotGesture;
1097 BitSet32 spotIdBits; // same set of ids as touch ids
1098 uint32_t spotIdToIndex[MAX_POINTER_ID + 1];
1099 PointerCoords spotCoords[MAX_POINTERS];
Jeff Brown96ad3972011-03-09 17:39:48 -08001100
1101 // Time the pointer gesture last went down.
1102 nsecs_t downTime;
1103
Jeff Brown325bd072011-04-19 21:20:10 -07001104 // Time when the pointer went down for a TAP.
1105 nsecs_t tapDownTime;
1106
1107 // Time when the pointer went up for a TAP.
1108 nsecs_t tapUpTime;
Jeff Brown96ad3972011-03-09 17:39:48 -08001109
Jeff Brown86ea1f52011-04-12 22:39:53 -07001110 // Location of initial tap.
1111 float tapX, tapY;
1112
Jeff Brown96ad3972011-03-09 17:39:48 -08001113 // Time we started waiting for quiescence.
1114 nsecs_t quietTime;
1115
Jeff Brown86ea1f52011-04-12 22:39:53 -07001116 // Reference points for multitouch gestures.
1117 float referenceTouchX; // reference touch X/Y coordinates in surface units
1118 float referenceTouchY;
1119 float referenceGestureX; // reference gesture X/Y coordinates in pixels
1120 float referenceGestureY;
1121
Jeff Brown538881e2011-05-25 18:23:38 -07001122 // Distance that each pointer has traveled which has not yet been
1123 // subsumed into the reference gesture position.
1124 BitSet32 referenceIdBits;
1125 struct Delta {
1126 float dx, dy;
1127 };
1128 Delta referenceDeltas[MAX_POINTER_ID + 1];
1129
Jeff Brown86ea1f52011-04-12 22:39:53 -07001130 // Describes how touch ids are mapped to gesture ids for freeform gestures.
1131 uint32_t freeformTouchToGestureIdMap[MAX_POINTER_ID + 1];
1132
Jeff Brown96ad3972011-03-09 17:39:48 -08001133 // A velocity tracker for determining whether to switch active pointers during drags.
1134 VelocityTracker velocityTracker;
1135
1136 void reset() {
Jeff Brown86ea1f52011-04-12 22:39:53 -07001137 firstTouchTime = LLONG_MIN;
Jeff Brown96ad3972011-03-09 17:39:48 -08001138 activeTouchId = -1;
1139 activeGestureId = -1;
1140 currentGestureMode = NEUTRAL;
Jeff Brown96ad3972011-03-09 17:39:48 -08001141 currentGestureIdBits.clear();
1142 lastGestureMode = NEUTRAL;
Jeff Brown96ad3972011-03-09 17:39:48 -08001143 lastGestureIdBits.clear();
Jeff Brown86ea1f52011-04-12 22:39:53 -07001144 spotGesture = PointerControllerInterface::SPOT_GESTURE_NEUTRAL;
1145 spotIdBits.clear();
Jeff Brown96ad3972011-03-09 17:39:48 -08001146 downTime = 0;
1147 velocityTracker.clear();
Jeff Brown325bd072011-04-19 21:20:10 -07001148 resetTap();
Jeff Brown96ad3972011-03-09 17:39:48 -08001149 resetQuietTime();
1150 }
1151
Jeff Brown325bd072011-04-19 21:20:10 -07001152 void resetTap() {
1153 tapDownTime = LLONG_MIN;
1154 tapUpTime = LLONG_MIN;
Jeff Brown96ad3972011-03-09 17:39:48 -08001155 }
1156
1157 void resetQuietTime() {
1158 quietTime = LLONG_MIN;
1159 }
1160 } mPointerGesture;
1161
Jeff Brown6328cdc2010-07-29 18:18:33 -07001162 void initializeLocked();
Jeff Brown6d0fec22010-07-23 21:28:06 -07001163
1164 TouchResult consumeOffScreenTouches(nsecs_t when, uint32_t policyFlags);
1165 void dispatchTouches(nsecs_t when, uint32_t policyFlags);
Jeff Brown96ad3972011-03-09 17:39:48 -08001166 void prepareTouches(int32_t* outEdgeFlags, float* outXPrecision, float* outYPrecision);
Jeff Brown325bd072011-04-19 21:20:10 -07001167 void dispatchPointerGestures(nsecs_t when, uint32_t policyFlags, bool isTimeout);
1168 bool preparePointerGestures(nsecs_t when,
1169 bool* outCancelPreviousGesture, bool* outFinishPreviousGesture, bool isTimeout);
Jeff Brown86ea1f52011-04-12 22:39:53 -07001170 void moveSpotsLocked();
Jeff Brown96ad3972011-03-09 17:39:48 -08001171
1172 // Dispatches a motion event.
1173 // If the changedId is >= 0 and the action is POINTER_DOWN or POINTER_UP, the
1174 // method will take care of setting the index and transmuting the action to DOWN or UP
1175 // it is the first / last pointer to go down / up.
1176 void dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32_t source,
1177 int32_t action, int32_t flags, uint32_t metaState, int32_t edgeFlags,
1178 const PointerCoords* coords, const uint32_t* idToIndex, BitSet32 idBits,
1179 int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime);
1180
1181 // Updates pointer coords for pointers with specified ids that have moved.
1182 // Returns true if any of them changed.
1183 bool updateMovedPointerCoords(const PointerCoords* inCoords, const uint32_t* inIdToIndex,
1184 PointerCoords* outCoords, const uint32_t* outIdToIndex, BitSet32 idBits) const;
1185
Jeff Brownefd32662011-03-08 15:13:06 -08001186 void suppressSwipeOntoVirtualKeys(nsecs_t when);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001187
Jeff Brown6328cdc2010-07-29 18:18:33 -07001188 bool isPointInsideSurfaceLocked(int32_t x, int32_t y);
1189 const VirtualKey* findVirtualKeyHitLocked(int32_t x, int32_t y);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001190
1191 bool applyBadTouchFilter();
1192 bool applyJumpyTouchFilter();
1193 void applyAveragingTouchFilter();
1194 void calculatePointerIds();
1195};
1196
1197
1198class SingleTouchInputMapper : public TouchInputMapper {
1199public:
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001200 SingleTouchInputMapper(InputDevice* device);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001201 virtual ~SingleTouchInputMapper();
1202
1203 virtual void reset();
1204 virtual void process(const RawEvent* rawEvent);
1205
1206protected:
Jeff Brown8d608662010-08-30 03:02:23 -07001207 virtual void configureRawAxes();
Jeff Brown6d0fec22010-07-23 21:28:06 -07001208
1209private:
1210 struct Accumulator {
1211 enum {
1212 FIELD_BTN_TOUCH = 1,
1213 FIELD_ABS_X = 2,
1214 FIELD_ABS_Y = 4,
1215 FIELD_ABS_PRESSURE = 8,
Jeff Brownefd32662011-03-08 15:13:06 -08001216 FIELD_ABS_TOOL_WIDTH = 16,
Jeff Brown96ad3972011-03-09 17:39:48 -08001217 FIELD_BUTTONS = 32,
Jeff Brown6d0fec22010-07-23 21:28:06 -07001218 };
1219
1220 uint32_t fields;
1221
1222 bool btnTouch;
1223 int32_t absX;
1224 int32_t absY;
1225 int32_t absPressure;
1226 int32_t absToolWidth;
1227
Jeff Brown96ad3972011-03-09 17:39:48 -08001228 uint32_t buttonDown;
1229 uint32_t buttonUp;
1230
Jeff Brown6d0fec22010-07-23 21:28:06 -07001231 inline void clear() {
1232 fields = 0;
Jeff Brown96ad3972011-03-09 17:39:48 -08001233 buttonDown = 0;
1234 buttonUp = 0;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001235 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07001236 } mAccumulator;
1237
1238 bool mDown;
1239 int32_t mX;
1240 int32_t mY;
1241 int32_t mPressure;
Jeff Brown8d608662010-08-30 03:02:23 -07001242 int32_t mToolWidth;
Jeff Brown96ad3972011-03-09 17:39:48 -08001243 uint32_t mButtonState;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001244
1245 void initialize();
1246
1247 void sync(nsecs_t when);
1248};
1249
1250
1251class MultiTouchInputMapper : public TouchInputMapper {
1252public:
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001253 MultiTouchInputMapper(InputDevice* device);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001254 virtual ~MultiTouchInputMapper();
1255
1256 virtual void reset();
1257 virtual void process(const RawEvent* rawEvent);
1258
1259protected:
Jeff Brown8d608662010-08-30 03:02:23 -07001260 virtual void configureRawAxes();
Jeff Brown6d0fec22010-07-23 21:28:06 -07001261
1262private:
1263 struct Accumulator {
1264 enum {
1265 FIELD_ABS_MT_POSITION_X = 1,
1266 FIELD_ABS_MT_POSITION_Y = 2,
1267 FIELD_ABS_MT_TOUCH_MAJOR = 4,
1268 FIELD_ABS_MT_TOUCH_MINOR = 8,
1269 FIELD_ABS_MT_WIDTH_MAJOR = 16,
1270 FIELD_ABS_MT_WIDTH_MINOR = 32,
1271 FIELD_ABS_MT_ORIENTATION = 64,
Jeff Brown2dfd7a72010-08-17 20:38:35 -07001272 FIELD_ABS_MT_TRACKING_ID = 128,
1273 FIELD_ABS_MT_PRESSURE = 256,
Jeff Brown6d0fec22010-07-23 21:28:06 -07001274 };
1275
1276 uint32_t pointerCount;
1277 struct Pointer {
1278 uint32_t fields;
1279
1280 int32_t absMTPositionX;
1281 int32_t absMTPositionY;
1282 int32_t absMTTouchMajor;
1283 int32_t absMTTouchMinor;
1284 int32_t absMTWidthMajor;
1285 int32_t absMTWidthMinor;
1286 int32_t absMTOrientation;
1287 int32_t absMTTrackingId;
Jeff Brown2dfd7a72010-08-17 20:38:35 -07001288 int32_t absMTPressure;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001289
1290 inline void clear() {
1291 fields = 0;
1292 }
1293 } pointers[MAX_POINTERS + 1]; // + 1 to remove the need for extra range checks
1294
Jeff Brown96ad3972011-03-09 17:39:48 -08001295 // Bitfield of buttons that went down or up.
1296 uint32_t buttonDown;
1297 uint32_t buttonUp;
1298
Jeff Brown6d0fec22010-07-23 21:28:06 -07001299 inline void clear() {
1300 pointerCount = 0;
1301 pointers[0].clear();
Jeff Brown96ad3972011-03-09 17:39:48 -08001302 buttonDown = 0;
1303 buttonUp = 0;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001304 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07001305 } mAccumulator;
1306
Jeff Brown96ad3972011-03-09 17:39:48 -08001307 uint32_t mButtonState;
1308
Jeff Brown6d0fec22010-07-23 21:28:06 -07001309 void initialize();
1310
1311 void sync(nsecs_t when);
1312};
1313
Jeff Browncb1404e2011-01-15 18:14:15 -08001314
1315class JoystickInputMapper : public InputMapper {
1316public:
1317 JoystickInputMapper(InputDevice* device);
1318 virtual ~JoystickInputMapper();
1319
1320 virtual uint32_t getSources();
1321 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
1322 virtual void dump(String8& dump);
1323 virtual void configure();
1324 virtual void reset();
1325 virtual void process(const RawEvent* rawEvent);
1326
1327private:
Jeff Brown6f2fba42011-02-19 01:08:02 -08001328 struct Axis {
1329 RawAbsoluteAxisInfo rawAxisInfo;
Jeff Brown85297452011-03-04 13:07:49 -08001330 AxisInfo axisInfo;
Jeff Browncb1404e2011-01-15 18:14:15 -08001331
Jeff Brown6f2fba42011-02-19 01:08:02 -08001332 bool explicitlyMapped; // true if the axis was explicitly assigned an axis id
Jeff Browncb1404e2011-01-15 18:14:15 -08001333
Jeff Brown6f2fba42011-02-19 01:08:02 -08001334 float scale; // scale factor from raw to normalized values
1335 float offset; // offset to add after scaling for normalization
Jeff Brown85297452011-03-04 13:07:49 -08001336 float highScale; // scale factor from raw to normalized values of high split
1337 float highOffset; // offset to add after scaling for normalization of high split
Jeff Browncb1404e2011-01-15 18:14:15 -08001338
Jeff Brown6f2fba42011-02-19 01:08:02 -08001339 float min; // normalized inclusive minimum
1340 float max; // normalized inclusive maximum
1341 float flat; // normalized flat region size
1342 float fuzz; // normalized error tolerance
Jeff Browncb1404e2011-01-15 18:14:15 -08001343
Jeff Brown6f2fba42011-02-19 01:08:02 -08001344 float filter; // filter out small variations of this size
Jeff Brown85297452011-03-04 13:07:49 -08001345 float currentValue; // current value
1346 float newValue; // most recent value
1347 float highCurrentValue; // current value of high split
1348 float highNewValue; // most recent value of high split
Jeff Browncb1404e2011-01-15 18:14:15 -08001349
Jeff Brown85297452011-03-04 13:07:49 -08001350 void initialize(const RawAbsoluteAxisInfo& rawAxisInfo, const AxisInfo& axisInfo,
1351 bool explicitlyMapped, float scale, float offset,
1352 float highScale, float highOffset,
Jeff Brown6f2fba42011-02-19 01:08:02 -08001353 float min, float max, float flat, float fuzz) {
1354 this->rawAxisInfo = rawAxisInfo;
Jeff Brown85297452011-03-04 13:07:49 -08001355 this->axisInfo = axisInfo;
Jeff Brown6f2fba42011-02-19 01:08:02 -08001356 this->explicitlyMapped = explicitlyMapped;
1357 this->scale = scale;
1358 this->offset = offset;
Jeff Brown85297452011-03-04 13:07:49 -08001359 this->highScale = highScale;
1360 this->highOffset = highOffset;
Jeff Brown6f2fba42011-02-19 01:08:02 -08001361 this->min = min;
1362 this->max = max;
1363 this->flat = flat;
1364 this->fuzz = fuzz;
1365 this->filter = 0;
Jeff Brown85297452011-03-04 13:07:49 -08001366 resetValue();
1367 }
1368
1369 void resetValue() {
1370 this->currentValue = 0;
Jeff Brown6f2fba42011-02-19 01:08:02 -08001371 this->newValue = 0;
Jeff Brown85297452011-03-04 13:07:49 -08001372 this->highCurrentValue = 0;
1373 this->highNewValue = 0;
Jeff Browncb1404e2011-01-15 18:14:15 -08001374 }
1375 };
1376
Jeff Brown6f2fba42011-02-19 01:08:02 -08001377 // Axes indexed by raw ABS_* axis index.
1378 KeyedVector<int32_t, Axis> mAxes;
Jeff Browncb1404e2011-01-15 18:14:15 -08001379
Jeff Brown6f2fba42011-02-19 01:08:02 -08001380 void sync(nsecs_t when, bool force);
Jeff Browncb1404e2011-01-15 18:14:15 -08001381
Jeff Brown85297452011-03-04 13:07:49 -08001382 bool haveAxis(int32_t axisId);
Jeff Brown6f2fba42011-02-19 01:08:02 -08001383 void pruneAxes(bool ignoreExplicitlyMappedAxes);
Jeff Brown85297452011-03-04 13:07:49 -08001384 bool filterAxes(bool force);
1385
1386 static bool hasValueChangedSignificantly(float filter,
1387 float newValue, float currentValue, float min, float max);
1388 static bool hasMovedNearerToValueWithinFilteredRange(float filter,
1389 float newValue, float currentValue, float thresholdValue);
Jeff Browncb1404e2011-01-15 18:14:15 -08001390
Jeff Brown6f2fba42011-02-19 01:08:02 -08001391 static bool isCenteredAxis(int32_t axis);
Jeff Browncb1404e2011-01-15 18:14:15 -08001392};
1393
Jeff Brown46b9ac02010-04-22 18:58:52 -07001394} // namespace android
1395
1396#endif // _UI_INPUT_READER_H