blob: 671e194a4eab8f93eb30fd4aece91f91c47bffec [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"
21#include "InputDispatcher.h"
22#include "PointerController.h"
23
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070024#include <ui/Input.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080025#include <ui/DisplayInfo.h>
Jeff Brown46b9ac0a2010-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 Brown46b9ac0a2010-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/*
43 * Input reader policy interface.
44 *
45 * The input reader policy is used by the input reader to interact with the Window Manager
46 * and other system components.
47 *
48 * The actual implementation is partially supported by callbacks into the DVM
49 * via JNI. This interface is also mocked in the unit tests.
50 */
51class InputReaderPolicyInterface : public virtual RefBase {
52protected:
53 InputReaderPolicyInterface() { }
54 virtual ~InputReaderPolicyInterface() { }
55
56public:
57 /* Display orientations. */
58 enum {
59 ROTATION_0 = 0,
60 ROTATION_90 = 1,
61 ROTATION_180 = 2,
62 ROTATION_270 = 3
63 };
64
Jeff Brown9c3cda02010-06-15 01:31:58 -070065 /* Gets information about the display with the specified id.
66 * Returns true if the display info is available, false otherwise.
67 */
68 virtual bool getDisplayInfo(int32_t displayId,
69 int32_t* width, int32_t* height, int32_t* orientation) = 0;
70
Jeff Brown9c3cda02010-06-15 01:31:58 -070071 /* Determines whether to turn on some hacks we have to improve the touch interaction with a
72 * certain device whose screen currently is not all that good.
73 */
74 virtual bool filterTouchEvents() = 0;
75
76 /* Determines whether to turn on some hacks to improve touch interaction with another device
77 * where touch coordinate data can get corrupted.
78 */
79 virtual bool filterJumpyTouchEvents() = 0;
80
Jeff Brownfe508922011-01-18 15:10:10 -080081 /* Gets the amount of time to disable virtual keys after the screen is touched
82 * in order to filter out accidental virtual key presses due to swiping gestures
83 * or taps near the edge of the display. May be 0 to disable the feature.
84 */
85 virtual nsecs_t getVirtualKeyQuietTime() = 0;
86
Jeff Brown9c3cda02010-06-15 01:31:58 -070087 /* Gets the excluded device names for the platform. */
88 virtual void getExcludedDeviceNames(Vector<String8>& outExcludedDeviceNames) = 0;
Jeff Brown83c09682010-12-23 17:50:18 -080089
90 /* Gets a pointer controller associated with the specified cursor device (ie. a mouse). */
91 virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId) = 0;
Jeff Brown9c3cda02010-06-15 01:31:58 -070092};
93
94
95/* Processes raw input events and sends cooked event data to an input dispatcher. */
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070096class InputReaderInterface : public virtual RefBase {
97protected:
98 InputReaderInterface() { }
99 virtual ~InputReaderInterface() { }
100
101public:
Jeff Brownb88102f2010-09-08 11:49:43 -0700102 /* Dumps the state of the input reader.
103 *
104 * This method may be called on any thread (usually by the input manager). */
105 virtual void dump(String8& dump) = 0;
106
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700107 /* Runs a single iteration of the processing loop.
108 * Nominally reads and processes one incoming message from the EventHub.
109 *
110 * This method should be called on the input reader thread.
111 */
112 virtual void loopOnce() = 0;
113
Jeff Brown9c3cda02010-06-15 01:31:58 -0700114 /* Gets the current input device configuration.
115 *
116 * This method may be called on any thread (usually by the input manager).
117 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700118 virtual void getInputConfiguration(InputConfiguration* outConfiguration) = 0;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700119
Jeff Brown6d0fec22010-07-23 21:28:06 -0700120 /* Gets information about the specified input device.
121 * Returns OK if the device information was obtained or NAME_NOT_FOUND if there
122 * was no such device.
123 *
124 * This method may be called on any thread (usually by the input manager).
Jeff Brown9c3cda02010-06-15 01:31:58 -0700125 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700126 virtual status_t getInputDeviceInfo(int32_t deviceId, InputDeviceInfo* outDeviceInfo) = 0;
127
128 /* Gets the list of all registered device ids. */
129 virtual void getInputDeviceIds(Vector<int32_t>& outDeviceIds) = 0;
130
131 /* Query current input state. */
132 virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask,
133 int32_t scanCode) = 0;
134 virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask,
135 int32_t keyCode) = 0;
136 virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask,
137 int32_t sw) = 0;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700138
139 /* Determine whether physical keys exist for the given framework-domain key codes. */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700140 virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask,
141 size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) = 0;
142};
143
144
145/* Internal interface used by individual input devices to access global input device state
146 * and parameters maintained by the input reader.
147 */
148class InputReaderContext {
Jeff Brownc3db8582010-10-20 15:33:38 -0700149public:
Jeff Brown6d0fec22010-07-23 21:28:06 -0700150 InputReaderContext() { }
151 virtual ~InputReaderContext() { }
152
Jeff Brown6d0fec22010-07-23 21:28:06 -0700153 virtual void updateGlobalMetaState() = 0;
154 virtual int32_t getGlobalMetaState() = 0;
155
Jeff Brownfe508922011-01-18 15:10:10 -0800156 virtual void disableVirtualKeysUntil(nsecs_t time) = 0;
157 virtual bool shouldDropVirtualKey(nsecs_t now,
158 InputDevice* device, int32_t keyCode, int32_t scanCode) = 0;
159
Jeff Brown05dc66a2011-03-02 14:41:58 -0800160 virtual void fadePointer() = 0;
161
Jeff Brownaa3855d2011-03-17 01:34:19 -0700162 virtual void requestTimeoutAtTime(nsecs_t when) = 0;
163
Jeff Brown6d0fec22010-07-23 21:28:06 -0700164 virtual InputReaderPolicyInterface* getPolicy() = 0;
165 virtual InputDispatcherInterface* getDispatcher() = 0;
166 virtual EventHubInterface* getEventHub() = 0;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700167};
168
Jeff Brown9c3cda02010-06-15 01:31:58 -0700169
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700170/* The input reader reads raw event data from the event hub and processes it into input events
Jeff Brown9c3cda02010-06-15 01:31:58 -0700171 * that it sends to the input dispatcher. Some functions of the input reader, such as early
172 * event filtering in low power states, are controlled by a separate policy object.
173 *
174 * IMPORTANT INVARIANT:
Jeff Brown6d0fec22010-07-23 21:28:06 -0700175 * Because the policy and dispatcher can potentially block or cause re-entrance into
176 * the input reader, the input reader never calls into other components while holding
Jeff Brown6328cdc2010-07-29 18:18:33 -0700177 * an exclusive internal lock whenever re-entrance can happen.
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700178 */
Jeff Brownc3db8582010-10-20 15:33:38 -0700179class InputReader : public InputReaderInterface, protected InputReaderContext {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700180public:
181 InputReader(const sp<EventHubInterface>& eventHub,
Jeff Brown9c3cda02010-06-15 01:31:58 -0700182 const sp<InputReaderPolicyInterface>& policy,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700183 const sp<InputDispatcherInterface>& dispatcher);
184 virtual ~InputReader();
185
Jeff Brownb88102f2010-09-08 11:49:43 -0700186 virtual void dump(String8& dump);
187
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700188 virtual void loopOnce();
189
Jeff Brown6d0fec22010-07-23 21:28:06 -0700190 virtual void getInputConfiguration(InputConfiguration* outConfiguration);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700191
Jeff Brown6d0fec22010-07-23 21:28:06 -0700192 virtual status_t getInputDeviceInfo(int32_t deviceId, InputDeviceInfo* outDeviceInfo);
193 virtual void getInputDeviceIds(Vector<int32_t>& outDeviceIds);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700194
Jeff Brown6d0fec22010-07-23 21:28:06 -0700195 virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask,
196 int32_t scanCode);
197 virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask,
198 int32_t keyCode);
199 virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask,
200 int32_t sw);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700201
Jeff Brown6d0fec22010-07-23 21:28:06 -0700202 virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask,
203 size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700204
Jeff Brownc3db8582010-10-20 15:33:38 -0700205protected:
206 // These methods are protected virtual so they can be overridden and instrumented
207 // by test cases.
208 virtual InputDevice* createDevice(int32_t deviceId, const String8& name, uint32_t classes);
209
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700210private:
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700211 sp<EventHubInterface> mEventHub;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700212 sp<InputReaderPolicyInterface> mPolicy;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700213 sp<InputDispatcherInterface> mDispatcher;
214
Jeff Brown6d0fec22010-07-23 21:28:06 -0700215 virtual InputReaderPolicyInterface* getPolicy() { return mPolicy.get(); }
216 virtual InputDispatcherInterface* getDispatcher() { return mDispatcher.get(); }
217 virtual EventHubInterface* getEventHub() { return mEventHub.get(); }
218
Jeff Brownb7198742011-03-18 18:14:26 -0700219 // The event queue.
220 static const int EVENT_BUFFER_SIZE = 256;
221 RawEvent mEventBuffer[EVENT_BUFFER_SIZE];
222
Jeff Brown6d0fec22010-07-23 21:28:06 -0700223 // This reader/writer lock guards the list of input devices.
224 // The writer lock must be held whenever the list of input devices is modified
225 // and then promptly released.
226 // The reader lock must be held whenever the list of input devices is traversed or an
227 // input device in the list is accessed.
228 // This lock only protects the registry and prevents inadvertent deletion of device objects
229 // that are in use. Individual devices are responsible for guarding their own internal state
230 // as needed for concurrent operation.
231 RWLock mDeviceRegistryLock;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700232 KeyedVector<int32_t, InputDevice*> mDevices;
233
Jeff Brown6d0fec22010-07-23 21:28:06 -0700234 // low-level input event decoding and device management
Jeff Brownb7198742011-03-18 18:14:26 -0700235 void processEvents(const RawEvent* rawEvents, size_t count);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700236
Jeff Brown7342bb92010-10-01 18:55:43 -0700237 void addDevice(int32_t deviceId);
238 void removeDevice(int32_t deviceId);
Jeff Brownb7198742011-03-18 18:14:26 -0700239 void processEventsForDevice(int32_t deviceId, const RawEvent* rawEvents, size_t count);
Jeff Brownaa3855d2011-03-17 01:34:19 -0700240 void timeoutExpired(nsecs_t when);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700241
Jeff Brownc3db8582010-10-20 15:33:38 -0700242 void handleConfigurationChanged(nsecs_t when);
Jeff Brownb7198742011-03-18 18:14:26 -0700243 void configureExcludedDevices();
Jeff Brown9c3cda02010-06-15 01:31:58 -0700244
Jeff Brown6d0fec22010-07-23 21:28:06 -0700245 // state management for all devices
246 Mutex mStateLock;
247
248 int32_t mGlobalMetaState;
249 virtual void updateGlobalMetaState();
250 virtual int32_t getGlobalMetaState();
251
Jeff Brown05dc66a2011-03-02 14:41:58 -0800252 virtual void fadePointer();
253
Jeff Brown6d0fec22010-07-23 21:28:06 -0700254 InputConfiguration mInputConfiguration;
255 void updateInputConfiguration();
256
Jeff Brownb7198742011-03-18 18:14:26 -0700257 nsecs_t mDisableVirtualKeysTimeout; // only accessed by reader thread
Jeff Brownfe508922011-01-18 15:10:10 -0800258 virtual void disableVirtualKeysUntil(nsecs_t time);
259 virtual bool shouldDropVirtualKey(nsecs_t now,
260 InputDevice* device, int32_t keyCode, int32_t scanCode);
261
Jeff Brownb7198742011-03-18 18:14:26 -0700262 nsecs_t mNextTimeout; // only accessed by reader thread
Jeff Brownaa3855d2011-03-17 01:34:19 -0700263 virtual void requestTimeoutAtTime(nsecs_t when);
264
Jeff Brown6d0fec22010-07-23 21:28:06 -0700265 // state queries
266 typedef int32_t (InputDevice::*GetStateFunc)(uint32_t sourceMask, int32_t code);
267 int32_t getState(int32_t deviceId, uint32_t sourceMask, int32_t code,
268 GetStateFunc getStateFunc);
269 bool markSupportedKeyCodes(int32_t deviceId, uint32_t sourceMask, size_t numCodes,
270 const int32_t* keyCodes, uint8_t* outFlags);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700271};
272
273
274/* Reads raw events from the event hub and processes them, endlessly. */
275class InputReaderThread : public Thread {
276public:
277 InputReaderThread(const sp<InputReaderInterface>& reader);
278 virtual ~InputReaderThread();
279
280private:
281 sp<InputReaderInterface> mReader;
282
283 virtual bool threadLoop();
284};
285
Jeff Brown6d0fec22010-07-23 21:28:06 -0700286
287/* Represents the state of a single input device. */
288class InputDevice {
289public:
290 InputDevice(InputReaderContext* context, int32_t id, const String8& name);
291 ~InputDevice();
292
293 inline InputReaderContext* getContext() { return mContext; }
294 inline int32_t getId() { return mId; }
295 inline const String8& getName() { return mName; }
296 inline uint32_t getSources() { return mSources; }
297
Jeff Brown56194eb2011-03-02 19:23:13 -0800298 inline bool isExternal() { return mIsExternal; }
299 inline void setExternal(bool external) { mIsExternal = external; }
300
Jeff Brown6d0fec22010-07-23 21:28:06 -0700301 inline bool isIgnored() { return mMappers.isEmpty(); }
302
Jeff Brownef3d7e82010-09-30 14:33:04 -0700303 void dump(String8& dump);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700304 void addMapper(InputMapper* mapper);
305 void configure();
306 void reset();
Jeff Brownb7198742011-03-18 18:14:26 -0700307 void process(const RawEvent* rawEvents, size_t count);
Jeff Brownaa3855d2011-03-17 01:34:19 -0700308 void timeoutExpired(nsecs_t when);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700309
310 void getDeviceInfo(InputDeviceInfo* outDeviceInfo);
311 int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
312 int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
313 int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
314 bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
315 const int32_t* keyCodes, uint8_t* outFlags);
316
317 int32_t getMetaState();
318
Jeff Brown05dc66a2011-03-02 14:41:58 -0800319 void fadePointer();
320
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800321 inline const PropertyMap& getConfiguration() {
322 return mConfiguration;
Jeff Brown8d608662010-08-30 03:02:23 -0700323 }
324
Jeff Brown6d0fec22010-07-23 21:28:06 -0700325private:
326 InputReaderContext* mContext;
327 int32_t mId;
328
329 Vector<InputMapper*> mMappers;
330
331 String8 mName;
332 uint32_t mSources;
Jeff Brown56194eb2011-03-02 19:23:13 -0800333 bool mIsExternal;
Jeff Brown80fd47c2011-05-24 01:07:44 -0700334 bool mDropUntilNextSync;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700335
336 typedef int32_t (InputMapper::*GetStateFunc)(uint32_t sourceMask, int32_t code);
337 int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc);
Jeff Brown8d608662010-08-30 03:02:23 -0700338
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800339 PropertyMap mConfiguration;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700340};
341
342
343/* An input mapper transforms raw input events into cooked event data.
344 * A single input device can have multiple associated input mappers in order to interpret
345 * different classes of events.
346 */
347class InputMapper {
348public:
349 InputMapper(InputDevice* device);
350 virtual ~InputMapper();
351
352 inline InputDevice* getDevice() { return mDevice; }
353 inline int32_t getDeviceId() { return mDevice->getId(); }
354 inline const String8 getDeviceName() { return mDevice->getName(); }
355 inline InputReaderContext* getContext() { return mContext; }
356 inline InputReaderPolicyInterface* getPolicy() { return mContext->getPolicy(); }
357 inline InputDispatcherInterface* getDispatcher() { return mContext->getDispatcher(); }
358 inline EventHubInterface* getEventHub() { return mContext->getEventHub(); }
359
360 virtual uint32_t getSources() = 0;
361 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
Jeff Brownef3d7e82010-09-30 14:33:04 -0700362 virtual void dump(String8& dump);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700363 virtual void configure();
364 virtual void reset();
365 virtual void process(const RawEvent* rawEvent) = 0;
Jeff Brownaa3855d2011-03-17 01:34:19 -0700366 virtual void timeoutExpired(nsecs_t when);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700367
368 virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
369 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
370 virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
371 virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
372 const int32_t* keyCodes, uint8_t* outFlags);
373
374 virtual int32_t getMetaState();
375
Jeff Brown05dc66a2011-03-02 14:41:58 -0800376 virtual void fadePointer();
377
Jeff Brown6d0fec22010-07-23 21:28:06 -0700378protected:
379 InputDevice* mDevice;
380 InputReaderContext* mContext;
Jeff Browncb1404e2011-01-15 18:14:15 -0800381
382 static void dumpRawAbsoluteAxisInfo(String8& dump,
383 const RawAbsoluteAxisInfo& axis, const char* name);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700384};
385
386
387class SwitchInputMapper : public InputMapper {
388public:
389 SwitchInputMapper(InputDevice* device);
390 virtual ~SwitchInputMapper();
391
392 virtual uint32_t getSources();
393 virtual void process(const RawEvent* rawEvent);
394
395 virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
396
397private:
398 void processSwitch(nsecs_t when, int32_t switchCode, int32_t switchValue);
399};
400
401
402class KeyboardInputMapper : public InputMapper {
403public:
Jeff Brownefd32662011-03-08 15:13:06 -0800404 KeyboardInputMapper(InputDevice* device, uint32_t source, int32_t keyboardType);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700405 virtual ~KeyboardInputMapper();
406
407 virtual uint32_t getSources();
408 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
Jeff Brownef3d7e82010-09-30 14:33:04 -0700409 virtual void dump(String8& dump);
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800410 virtual void configure();
Jeff Brown6d0fec22010-07-23 21:28:06 -0700411 virtual void reset();
412 virtual void process(const RawEvent* rawEvent);
413
414 virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
415 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
416 virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
417 const int32_t* keyCodes, uint8_t* outFlags);
418
419 virtual int32_t getMetaState();
420
421private:
Jeff Brown6328cdc2010-07-29 18:18:33 -0700422 Mutex mLock;
423
Jeff Brown6d0fec22010-07-23 21:28:06 -0700424 struct KeyDown {
425 int32_t keyCode;
426 int32_t scanCode;
427 };
428
Jeff Brownefd32662011-03-08 15:13:06 -0800429 uint32_t mSource;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700430 int32_t mKeyboardType;
431
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800432 // Immutable configuration parameters.
433 struct Parameters {
434 int32_t associatedDisplayId;
435 bool orientationAware;
436 } mParameters;
437
Jeff Brown6328cdc2010-07-29 18:18:33 -0700438 struct LockedState {
439 Vector<KeyDown> keyDowns; // keys that are down
440 int32_t metaState;
441 nsecs_t downTime; // time of most recent key down
Jeff Brown497a92c2010-09-12 17:55:08 -0700442
443 struct LedState {
444 bool avail; // led is available
445 bool on; // we think the led is currently on
446 };
447 LedState capsLockLedState;
448 LedState numLockLedState;
449 LedState scrollLockLedState;
Jeff Brown6328cdc2010-07-29 18:18:33 -0700450 } mLocked;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700451
Jeff Brown6328cdc2010-07-29 18:18:33 -0700452 void initializeLocked();
Jeff Brown6d0fec22010-07-23 21:28:06 -0700453
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800454 void configureParameters();
455 void dumpParameters(String8& dump);
456
Jeff Brown6d0fec22010-07-23 21:28:06 -0700457 bool isKeyboardOrGamepadKey(int32_t scanCode);
Jeff Brown6328cdc2010-07-29 18:18:33 -0700458
Jeff Brown6d0fec22010-07-23 21:28:06 -0700459 void processKey(nsecs_t when, bool down, int32_t keyCode, int32_t scanCode,
460 uint32_t policyFlags);
461
Jeff Brown6328cdc2010-07-29 18:18:33 -0700462 ssize_t findKeyDownLocked(int32_t scanCode);
Jeff Brown497a92c2010-09-12 17:55:08 -0700463
Jeff Brown49ed71d2010-12-06 17:13:33 -0800464 void resetLedStateLocked();
465 void initializeLedStateLocked(LockedState::LedState& ledState, int32_t led);
Jeff Brown497a92c2010-09-12 17:55:08 -0700466 void updateLedStateLocked(bool reset);
467 void updateLedStateForModifierLocked(LockedState::LedState& ledState, int32_t led,
468 int32_t modifier, bool reset);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700469};
470
471
Jeff Brown83c09682010-12-23 17:50:18 -0800472class CursorInputMapper : public InputMapper {
Jeff Brown6d0fec22010-07-23 21:28:06 -0700473public:
Jeff Brown83c09682010-12-23 17:50:18 -0800474 CursorInputMapper(InputDevice* device);
475 virtual ~CursorInputMapper();
Jeff Brown6d0fec22010-07-23 21:28:06 -0700476
477 virtual uint32_t getSources();
478 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
Jeff Brownef3d7e82010-09-30 14:33:04 -0700479 virtual void dump(String8& dump);
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800480 virtual void configure();
Jeff Brown6d0fec22010-07-23 21:28:06 -0700481 virtual void reset();
482 virtual void process(const RawEvent* rawEvent);
483
Jeff Brownc3fc2d02010-08-10 15:47:53 -0700484 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
485
Jeff Brown05dc66a2011-03-02 14:41:58 -0800486 virtual void fadePointer();
487
Jeff Brown6d0fec22010-07-23 21:28:06 -0700488private:
489 // Amount that trackball needs to move in order to generate a key event.
490 static const int32_t TRACKBALL_MOVEMENT_THRESHOLD = 6;
491
Jeff Brown6328cdc2010-07-29 18:18:33 -0700492 Mutex mLock;
493
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800494 // Immutable configuration parameters.
495 struct Parameters {
Jeff Brown83c09682010-12-23 17:50:18 -0800496 enum Mode {
497 MODE_POINTER,
498 MODE_NAVIGATION,
499 };
500
501 Mode mode;
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800502 int32_t associatedDisplayId;
503 bool orientationAware;
504 } mParameters;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700505
506 struct Accumulator {
507 enum {
Jeff Brownefd32662011-03-08 15:13:06 -0800508 FIELD_BUTTONS = 1,
Jeff Brown6d0fec22010-07-23 21:28:06 -0700509 FIELD_REL_X = 2,
Jeff Brown6f2fba42011-02-19 01:08:02 -0800510 FIELD_REL_Y = 4,
511 FIELD_REL_WHEEL = 8,
512 FIELD_REL_HWHEEL = 16,
Jeff Brown6d0fec22010-07-23 21:28:06 -0700513 };
514
515 uint32_t fields;
516
Jeff Brownefd32662011-03-08 15:13:06 -0800517 uint32_t buttonDown;
518 uint32_t buttonUp;
519
Jeff Brown6d0fec22010-07-23 21:28:06 -0700520 int32_t relX;
521 int32_t relY;
Jeff Brown6f2fba42011-02-19 01:08:02 -0800522 int32_t relWheel;
523 int32_t relHWheel;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700524
525 inline void clear() {
526 fields = 0;
527 }
Jeff Brown6d0fec22010-07-23 21:28:06 -0700528 } mAccumulator;
529
Jeff Brownefd32662011-03-08 15:13:06 -0800530 int32_t mSource;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700531 float mXScale;
532 float mYScale;
533 float mXPrecision;
534 float mYPrecision;
Jeff Brown6f2fba42011-02-19 01:08:02 -0800535
536 bool mHaveVWheel;
537 bool mHaveHWheel;
538 float mVWheelScale;
539 float mHWheelScale;
540
Jeff Brown83c09682010-12-23 17:50:18 -0800541 sp<PointerControllerInterface> mPointerController;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700542
Jeff Brown6328cdc2010-07-29 18:18:33 -0700543 struct LockedState {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700544 int32_t buttonState;
Jeff Brown6328cdc2010-07-29 18:18:33 -0700545 nsecs_t downTime;
546 } mLocked;
547
548 void initializeLocked();
Jeff Brown6d0fec22010-07-23 21:28:06 -0700549
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800550 void configureParameters();
551 void dumpParameters(String8& dump);
552
Jeff Brown6d0fec22010-07-23 21:28:06 -0700553 void sync(nsecs_t when);
554};
555
556
557class TouchInputMapper : public InputMapper {
558public:
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800559 TouchInputMapper(InputDevice* device);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700560 virtual ~TouchInputMapper();
561
562 virtual uint32_t getSources();
563 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
Jeff Brownef3d7e82010-09-30 14:33:04 -0700564 virtual void dump(String8& dump);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700565 virtual void configure();
566 virtual void reset();
567
568 virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
569 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
570 virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
571 const int32_t* keyCodes, uint8_t* outFlags);
572
Jeff Brownace13b12011-03-09 17:39:48 -0800573 virtual void fadePointer();
Jeff Brown79ac9692011-04-19 21:20:10 -0700574 virtual void timeoutExpired(nsecs_t when);
Jeff Brownace13b12011-03-09 17:39:48 -0800575
Jeff Brown6d0fec22010-07-23 21:28:06 -0700576protected:
Jeff Brown6328cdc2010-07-29 18:18:33 -0700577 Mutex mLock;
578
Jeff Brown6d0fec22010-07-23 21:28:06 -0700579 struct VirtualKey {
580 int32_t keyCode;
581 int32_t scanCode;
582 uint32_t flags;
583
584 // computed hit box, specified in touch screen coords based on known display size
585 int32_t hitLeft;
586 int32_t hitTop;
587 int32_t hitRight;
588 int32_t hitBottom;
589
590 inline bool isHit(int32_t x, int32_t y) const {
591 return x >= hitLeft && x <= hitRight && y >= hitTop && y <= hitBottom;
592 }
593 };
594
Jeff Brown8d608662010-08-30 03:02:23 -0700595 // Raw data for a single pointer.
Jeff Brown6d0fec22010-07-23 21:28:06 -0700596 struct PointerData {
597 uint32_t id;
598 int32_t x;
599 int32_t y;
600 int32_t pressure;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700601 int32_t touchMajor;
602 int32_t touchMinor;
603 int32_t toolMajor;
604 int32_t toolMinor;
605 int32_t orientation;
Jeff Brown80fd47c2011-05-24 01:07:44 -0700606 int32_t distance;
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700607 bool isStylus;
Jeff Brownc3db8582010-10-20 15:33:38 -0700608
609 inline bool operator== (const PointerData& other) const {
610 return id == other.id
611 && x == other.x
612 && y == other.y
613 && pressure == other.pressure
614 && touchMajor == other.touchMajor
615 && touchMinor == other.touchMinor
616 && toolMajor == other.toolMajor
617 && toolMinor == other.toolMinor
Jeff Brown80fd47c2011-05-24 01:07:44 -0700618 && orientation == other.orientation
619 && distance == other.distance;
Jeff Brownc3db8582010-10-20 15:33:38 -0700620 }
621 inline bool operator!= (const PointerData& other) const {
622 return !(*this == other);
623 }
Jeff Brown6d0fec22010-07-23 21:28:06 -0700624 };
625
Jeff Brown8d608662010-08-30 03:02:23 -0700626 // Raw data for a collection of pointers including a pointer id mapping table.
Jeff Brown6d0fec22010-07-23 21:28:06 -0700627 struct TouchData {
628 uint32_t pointerCount;
629 PointerData pointers[MAX_POINTERS];
630 BitSet32 idBits;
631 uint32_t idToIndex[MAX_POINTER_ID + 1];
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700632 int32_t buttonState;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700633
634 void copyFrom(const TouchData& other) {
635 pointerCount = other.pointerCount;
636 idBits = other.idBits;
Jeff Brownace13b12011-03-09 17:39:48 -0800637 buttonState = other.buttonState;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700638
639 for (uint32_t i = 0; i < pointerCount; i++) {
640 pointers[i] = other.pointers[i];
Jeff Brown9e2ad362010-07-30 19:20:11 -0700641
642 int id = pointers[i].id;
643 idToIndex[id] = other.idToIndex[id];
Jeff Brown6d0fec22010-07-23 21:28:06 -0700644 }
645 }
646
647 inline void clear() {
648 pointerCount = 0;
649 idBits.clear();
Jeff Brownace13b12011-03-09 17:39:48 -0800650 buttonState = 0;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700651 }
Jeff Brown2352b972011-04-12 22:39:53 -0700652
653 void getCentroid(float* outX, float* outY) {
654 float x = 0, y = 0;
655 if (pointerCount != 0) {
656 for (uint32_t i = 0; i < pointerCount; i++) {
657 x += pointers[i].x;
658 y += pointers[i].y;
659 }
660 x /= pointerCount;
661 y /= pointerCount;
662 }
663 *outX = x;
664 *outY = y;
665 }
Jeff Brown6d0fec22010-07-23 21:28:06 -0700666 };
667
Jeff Brown83c09682010-12-23 17:50:18 -0800668 // Input sources supported by the device.
Jeff Brownefd32662011-03-08 15:13:06 -0800669 uint32_t mTouchSource; // sources when reporting touch data
Jeff Brownace13b12011-03-09 17:39:48 -0800670 uint32_t mPointerSource; // sources when reporting pointer gestures
Jeff Brown83c09682010-12-23 17:50:18 -0800671
Jeff Brown6d0fec22010-07-23 21:28:06 -0700672 // Immutable configuration parameters.
673 struct Parameters {
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800674 enum DeviceType {
675 DEVICE_TYPE_TOUCH_SCREEN,
676 DEVICE_TYPE_TOUCH_PAD,
Jeff Brownace13b12011-03-09 17:39:48 -0800677 DEVICE_TYPE_POINTER,
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800678 };
679
680 DeviceType deviceType;
681 int32_t associatedDisplayId;
682 bool orientationAware;
683
Jeff Brown6d0fec22010-07-23 21:28:06 -0700684 bool useBadTouchFilter;
685 bool useJumpyTouchFilter;
686 bool useAveragingTouchFilter;
Jeff Brownfe508922011-01-18 15:10:10 -0800687 nsecs_t virtualKeyQuietTime;
Jeff Brown2352b972011-04-12 22:39:53 -0700688
689 enum GestureMode {
690 GESTURE_MODE_POINTER,
691 GESTURE_MODE_SPOTS,
692 };
693 GestureMode gestureMode;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700694 } mParameters;
695
Jeff Brown8d608662010-08-30 03:02:23 -0700696 // Immutable calibration parameters in parsed form.
697 struct Calibration {
Jeff Brownc6d282b2010-10-14 21:42:15 -0700698 // Touch Size
699 enum TouchSizeCalibration {
700 TOUCH_SIZE_CALIBRATION_DEFAULT,
701 TOUCH_SIZE_CALIBRATION_NONE,
702 TOUCH_SIZE_CALIBRATION_GEOMETRIC,
703 TOUCH_SIZE_CALIBRATION_PRESSURE,
Jeff Brown8d608662010-08-30 03:02:23 -0700704 };
705
Jeff Brownc6d282b2010-10-14 21:42:15 -0700706 TouchSizeCalibration touchSizeCalibration;
Jeff Brown8d608662010-08-30 03:02:23 -0700707
Jeff Brownc6d282b2010-10-14 21:42:15 -0700708 // Tool Size
709 enum ToolSizeCalibration {
710 TOOL_SIZE_CALIBRATION_DEFAULT,
711 TOOL_SIZE_CALIBRATION_NONE,
712 TOOL_SIZE_CALIBRATION_GEOMETRIC,
713 TOOL_SIZE_CALIBRATION_LINEAR,
714 TOOL_SIZE_CALIBRATION_AREA,
Jeff Brown8d608662010-08-30 03:02:23 -0700715 };
716
Jeff Brownc6d282b2010-10-14 21:42:15 -0700717 ToolSizeCalibration toolSizeCalibration;
718 bool haveToolSizeLinearScale;
719 float toolSizeLinearScale;
720 bool haveToolSizeLinearBias;
721 float toolSizeLinearBias;
722 bool haveToolSizeAreaScale;
723 float toolSizeAreaScale;
724 bool haveToolSizeAreaBias;
725 float toolSizeAreaBias;
726 bool haveToolSizeIsSummed;
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800727 bool toolSizeIsSummed;
Jeff Brown8d608662010-08-30 03:02:23 -0700728
729 // Pressure
730 enum PressureCalibration {
731 PRESSURE_CALIBRATION_DEFAULT,
732 PRESSURE_CALIBRATION_NONE,
733 PRESSURE_CALIBRATION_PHYSICAL,
734 PRESSURE_CALIBRATION_AMPLITUDE,
735 };
736 enum PressureSource {
737 PRESSURE_SOURCE_DEFAULT,
738 PRESSURE_SOURCE_PRESSURE,
739 PRESSURE_SOURCE_TOUCH,
740 };
741
742 PressureCalibration pressureCalibration;
743 PressureSource pressureSource;
744 bool havePressureScale;
745 float pressureScale;
746
747 // Size
748 enum SizeCalibration {
749 SIZE_CALIBRATION_DEFAULT,
750 SIZE_CALIBRATION_NONE,
751 SIZE_CALIBRATION_NORMALIZED,
752 };
753
754 SizeCalibration sizeCalibration;
755
756 // Orientation
757 enum OrientationCalibration {
758 ORIENTATION_CALIBRATION_DEFAULT,
759 ORIENTATION_CALIBRATION_NONE,
760 ORIENTATION_CALIBRATION_INTERPOLATED,
Jeff Brown517bb4c2011-01-14 19:09:23 -0800761 ORIENTATION_CALIBRATION_VECTOR,
Jeff Brown8d608662010-08-30 03:02:23 -0700762 };
763
764 OrientationCalibration orientationCalibration;
Jeff Brown80fd47c2011-05-24 01:07:44 -0700765
766 // Distance
767 enum DistanceCalibration {
768 DISTANCE_CALIBRATION_DEFAULT,
769 DISTANCE_CALIBRATION_NONE,
770 DISTANCE_CALIBRATION_SCALED,
771 };
772
773 DistanceCalibration distanceCalibration;
774 bool haveDistanceScale;
775 float distanceScale;
Jeff Brown8d608662010-08-30 03:02:23 -0700776 } mCalibration;
777
778 // Raw axis information from the driver.
779 struct RawAxes {
Jeff Brown6d0fec22010-07-23 21:28:06 -0700780 RawAbsoluteAxisInfo x;
781 RawAbsoluteAxisInfo y;
782 RawAbsoluteAxisInfo pressure;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700783 RawAbsoluteAxisInfo touchMajor;
784 RawAbsoluteAxisInfo touchMinor;
785 RawAbsoluteAxisInfo toolMajor;
786 RawAbsoluteAxisInfo toolMinor;
787 RawAbsoluteAxisInfo orientation;
Jeff Brown80fd47c2011-05-24 01:07:44 -0700788 RawAbsoluteAxisInfo distance;
789 RawAbsoluteAxisInfo trackingId;
790 RawAbsoluteAxisInfo slot;
Jeff Brown8d608662010-08-30 03:02:23 -0700791 } mRawAxes;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700792
Jeff Brown6328cdc2010-07-29 18:18:33 -0700793 // Current and previous touch sample data.
Jeff Brown6d0fec22010-07-23 21:28:06 -0700794 TouchData mCurrentTouch;
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700795 PointerProperties mCurrentTouchProperties[MAX_POINTERS];
Jeff Brownace13b12011-03-09 17:39:48 -0800796 PointerCoords mCurrentTouchCoords[MAX_POINTERS];
797
Jeff Brown6d0fec22010-07-23 21:28:06 -0700798 TouchData mLastTouch;
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700799 PointerProperties mLastTouchProperties[MAX_POINTERS];
Jeff Brownace13b12011-03-09 17:39:48 -0800800 PointerCoords mLastTouchCoords[MAX_POINTERS];
Jeff Brown6d0fec22010-07-23 21:28:06 -0700801
802 // The time the primary pointer last went down.
803 nsecs_t mDownTime;
804
Jeff Brownace13b12011-03-09 17:39:48 -0800805 // The pointer controller, or null if the device is not a pointer.
806 sp<PointerControllerInterface> mPointerController;
807
Jeff Brown6328cdc2010-07-29 18:18:33 -0700808 struct LockedState {
809 Vector<VirtualKey> virtualKeys;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700810
Jeff Brown6328cdc2010-07-29 18:18:33 -0700811 // The surface orientation and width and height set by configureSurfaceLocked().
812 int32_t surfaceOrientation;
813 int32_t surfaceWidth, surfaceHeight;
814
Jeff Brownefd32662011-03-08 15:13:06 -0800815 // The associated display orientation and width and height set by configureSurfaceLocked().
816 int32_t associatedDisplayOrientation;
817 int32_t associatedDisplayWidth, associatedDisplayHeight;
818
Jeff Brown6328cdc2010-07-29 18:18:33 -0700819 // Translation and scaling factors, orientation-independent.
Jeff Brown6328cdc2010-07-29 18:18:33 -0700820 float xScale;
821 float xPrecision;
822
Jeff Brown6328cdc2010-07-29 18:18:33 -0700823 float yScale;
824 float yPrecision;
825
Jeff Brown8d608662010-08-30 03:02:23 -0700826 float geometricScale;
827
Jeff Brownc6d282b2010-10-14 21:42:15 -0700828 float toolSizeLinearScale;
829 float toolSizeLinearBias;
830 float toolSizeAreaScale;
831 float toolSizeAreaBias;
Jeff Brown8d608662010-08-30 03:02:23 -0700832
Jeff Brown6328cdc2010-07-29 18:18:33 -0700833 float pressureScale;
834
Jeff Brown6328cdc2010-07-29 18:18:33 -0700835 float sizeScale;
836
837 float orientationScale;
838
Jeff Brown80fd47c2011-05-24 01:07:44 -0700839 float distanceScale;
840
Jeff Brown6328cdc2010-07-29 18:18:33 -0700841 // Oriented motion ranges for input device info.
842 struct OrientedRanges {
843 InputDeviceInfo::MotionRange x;
844 InputDeviceInfo::MotionRange y;
Jeff Brown8d608662010-08-30 03:02:23 -0700845
846 bool havePressure;
Jeff Brown6328cdc2010-07-29 18:18:33 -0700847 InputDeviceInfo::MotionRange pressure;
Jeff Brown8d608662010-08-30 03:02:23 -0700848
849 bool haveSize;
Jeff Brown6328cdc2010-07-29 18:18:33 -0700850 InputDeviceInfo::MotionRange size;
Jeff Brown8d608662010-08-30 03:02:23 -0700851
Jeff Brownc6d282b2010-10-14 21:42:15 -0700852 bool haveTouchSize;
Jeff Brown6328cdc2010-07-29 18:18:33 -0700853 InputDeviceInfo::MotionRange touchMajor;
854 InputDeviceInfo::MotionRange touchMinor;
Jeff Brown8d608662010-08-30 03:02:23 -0700855
Jeff Brownc6d282b2010-10-14 21:42:15 -0700856 bool haveToolSize;
Jeff Brown6328cdc2010-07-29 18:18:33 -0700857 InputDeviceInfo::MotionRange toolMajor;
858 InputDeviceInfo::MotionRange toolMinor;
Jeff Brown8d608662010-08-30 03:02:23 -0700859
860 bool haveOrientation;
Jeff Brown6328cdc2010-07-29 18:18:33 -0700861 InputDeviceInfo::MotionRange orientation;
Jeff Brown80fd47c2011-05-24 01:07:44 -0700862
863 bool haveDistance;
864 InputDeviceInfo::MotionRange distance;
Jeff Brown6328cdc2010-07-29 18:18:33 -0700865 } orientedRanges;
866
867 // Oriented dimensions and precision.
868 float orientedSurfaceWidth, orientedSurfaceHeight;
869 float orientedXPrecision, orientedYPrecision;
870
871 struct CurrentVirtualKeyState {
872 bool down;
873 nsecs_t downTime;
874 int32_t keyCode;
875 int32_t scanCode;
876 } currentVirtualKey;
Jeff Brownace13b12011-03-09 17:39:48 -0800877
878 // Scale factor for gesture based pointer movements.
879 float pointerGestureXMovementScale;
880 float pointerGestureYMovementScale;
881
882 // Scale factor for gesture based zooming and other freeform motions.
883 float pointerGestureXZoomScale;
884 float pointerGestureYZoomScale;
885
Jeff Brown2352b972011-04-12 22:39:53 -0700886 // The maximum swipe width.
887 float pointerGestureMaxSwipeWidth;
Jeff Brown6328cdc2010-07-29 18:18:33 -0700888 } mLocked;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700889
Jeff Brown8d608662010-08-30 03:02:23 -0700890 virtual void configureParameters();
Jeff Brownef3d7e82010-09-30 14:33:04 -0700891 virtual void dumpParameters(String8& dump);
Jeff Brown8d608662010-08-30 03:02:23 -0700892 virtual void configureRawAxes();
Jeff Brownef3d7e82010-09-30 14:33:04 -0700893 virtual void dumpRawAxes(String8& dump);
Jeff Brown6328cdc2010-07-29 18:18:33 -0700894 virtual bool configureSurfaceLocked();
Jeff Brownef3d7e82010-09-30 14:33:04 -0700895 virtual void dumpSurfaceLocked(String8& dump);
Jeff Brown6328cdc2010-07-29 18:18:33 -0700896 virtual void configureVirtualKeysLocked();
Jeff Brownef3d7e82010-09-30 14:33:04 -0700897 virtual void dumpVirtualKeysLocked(String8& dump);
Jeff Brown8d608662010-08-30 03:02:23 -0700898 virtual void parseCalibration();
899 virtual void resolveCalibration();
Jeff Brownef3d7e82010-09-30 14:33:04 -0700900 virtual void dumpCalibration(String8& dump);
Jeff Brown6d0fec22010-07-23 21:28:06 -0700901
902 enum TouchResult {
903 // Dispatch the touch normally.
904 DISPATCH_TOUCH,
905 // Do not dispatch the touch, but keep tracking the current stroke.
906 SKIP_TOUCH,
907 // Do not dispatch the touch, and drop all information associated with the current stoke
908 // so the next movement will appear as a new down.
909 DROP_STROKE
910 };
911
912 void syncTouch(nsecs_t when, bool havePointerIds);
913
914private:
915 /* Maximum number of historical samples to average. */
916 static const uint32_t AVERAGING_HISTORY_SIZE = 5;
917
918 /* Slop distance for jumpy pointer detection.
919 * The vertical range of the screen divided by this is our epsilon value. */
920 static const uint32_t JUMPY_EPSILON_DIVISOR = 212;
921
922 /* Number of jumpy points to drop for touchscreens that need it. */
923 static const uint32_t JUMPY_TRANSITION_DROPS = 3;
924 static const uint32_t JUMPY_DROP_LIMIT = 3;
925
926 /* Maximum squared distance for averaging.
927 * If moving farther than this, turn of averaging to avoid lag in response. */
928 static const uint64_t AVERAGING_DISTANCE_LIMIT = 75 * 75;
929
930 struct AveragingTouchFilterState {
931 // Individual history tracks are stored by pointer id
932 uint32_t historyStart[MAX_POINTERS];
933 uint32_t historyEnd[MAX_POINTERS];
934 struct {
935 struct {
936 int32_t x;
937 int32_t y;
938 int32_t pressure;
939 } pointers[MAX_POINTERS];
940 } historyData[AVERAGING_HISTORY_SIZE];
941 } mAveragingTouchFilter;
942
Jeff Brown2dfd7a72010-08-17 20:38:35 -0700943 struct JumpyTouchFilterState {
Jeff Brown6d0fec22010-07-23 21:28:06 -0700944 uint32_t jumpyPointsDropped;
945 } mJumpyTouchFilter;
946
947 struct PointerDistanceHeapElement {
948 uint32_t currentPointerIndex : 8;
949 uint32_t lastPointerIndex : 8;
950 uint64_t distance : 48; // squared distance
951 };
952
Jeff Brownace13b12011-03-09 17:39:48 -0800953 struct PointerGesture {
954 enum Mode {
955 // No fingers, button is not pressed.
956 // Nothing happening.
957 NEUTRAL,
958
959 // No fingers, button is not pressed.
960 // Tap detected.
961 // Emits DOWN and UP events at the pointer location.
962 TAP,
963
Jeff Brown79ac9692011-04-19 21:20:10 -0700964 // Exactly one finger dragging following a tap.
965 // Pointer follows the active finger.
966 // Emits DOWN, MOVE and UP events at the pointer location.
967 TAP_DRAG,
968
Jeff Brownace13b12011-03-09 17:39:48 -0800969 // Button is pressed.
970 // Pointer follows the active finger if there is one. Other fingers are ignored.
971 // Emits DOWN, MOVE and UP events at the pointer location.
Jeff Brown79ac9692011-04-19 21:20:10 -0700972 BUTTON_CLICK_OR_DRAG,
Jeff Brownace13b12011-03-09 17:39:48 -0800973
974 // Exactly one finger, button is not pressed.
975 // Pointer follows the active finger.
976 // Emits HOVER_MOVE events at the pointer location.
977 HOVER,
978
Jeff Brown2352b972011-04-12 22:39:53 -0700979 // Exactly two fingers but neither have moved enough to clearly indicate
980 // whether a swipe or freeform gesture was intended. We consider the
981 // pointer to be pressed so this enables clicking or long-pressing on buttons.
982 // Pointer does not move.
983 // Emits DOWN, MOVE and UP events with a single stationary pointer coordinate.
984 PRESS,
Jeff Brownace13b12011-03-09 17:39:48 -0800985
986 // Exactly two fingers moving in the same direction, button is not pressed.
987 // Pointer does not move.
988 // Emits DOWN, MOVE and UP events with a single pointer coordinate that
989 // follows the midpoint between both fingers.
Jeff Brownace13b12011-03-09 17:39:48 -0800990 SWIPE,
991
992 // Two or more fingers moving in arbitrary directions, button is not pressed.
993 // Pointer does not move.
994 // Emits DOWN, POINTER_DOWN, MOVE, POINTER_UP and UP events that follow
995 // each finger individually relative to the initial centroid of the finger.
Jeff Brownace13b12011-03-09 17:39:48 -0800996 FREEFORM,
997
998 // Waiting for quiet time to end before starting the next gesture.
999 QUIET,
1000 };
1001
Jeff Brown2352b972011-04-12 22:39:53 -07001002 // Time the first finger went down.
1003 nsecs_t firstTouchTime;
1004
Jeff Brownace13b12011-03-09 17:39:48 -08001005 // The active pointer id from the raw touch data.
1006 int32_t activeTouchId; // -1 if none
1007
1008 // The active pointer id from the gesture last delivered to the application.
1009 int32_t activeGestureId; // -1 if none
1010
1011 // Pointer coords and ids for the current and previous pointer gesture.
1012 Mode currentGestureMode;
Jeff Brownace13b12011-03-09 17:39:48 -08001013 BitSet32 currentGestureIdBits;
1014 uint32_t currentGestureIdToIndex[MAX_POINTER_ID + 1];
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001015 PointerProperties currentGestureProperties[MAX_POINTERS];
Jeff Brownace13b12011-03-09 17:39:48 -08001016 PointerCoords currentGestureCoords[MAX_POINTERS];
1017
1018 Mode lastGestureMode;
Jeff Brownace13b12011-03-09 17:39:48 -08001019 BitSet32 lastGestureIdBits;
1020 uint32_t lastGestureIdToIndex[MAX_POINTER_ID + 1];
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001021 PointerProperties lastGestureProperties[MAX_POINTERS];
Jeff Brownace13b12011-03-09 17:39:48 -08001022 PointerCoords lastGestureCoords[MAX_POINTERS];
1023
Jeff Brown2352b972011-04-12 22:39:53 -07001024 // Pointer coords and ids for the current spots.
1025 PointerControllerInterface::SpotGesture spotGesture;
1026 BitSet32 spotIdBits; // same set of ids as touch ids
1027 uint32_t spotIdToIndex[MAX_POINTER_ID + 1];
1028 PointerCoords spotCoords[MAX_POINTERS];
Jeff Brownace13b12011-03-09 17:39:48 -08001029
1030 // Time the pointer gesture last went down.
1031 nsecs_t downTime;
1032
Jeff Brown79ac9692011-04-19 21:20:10 -07001033 // Time when the pointer went down for a TAP.
1034 nsecs_t tapDownTime;
1035
1036 // Time when the pointer went up for a TAP.
1037 nsecs_t tapUpTime;
Jeff Brownace13b12011-03-09 17:39:48 -08001038
Jeff Brown2352b972011-04-12 22:39:53 -07001039 // Location of initial tap.
1040 float tapX, tapY;
1041
Jeff Brownace13b12011-03-09 17:39:48 -08001042 // Time we started waiting for quiescence.
1043 nsecs_t quietTime;
1044
Jeff Brown2352b972011-04-12 22:39:53 -07001045 // Reference points for multitouch gestures.
1046 float referenceTouchX; // reference touch X/Y coordinates in surface units
1047 float referenceTouchY;
1048 float referenceGestureX; // reference gesture X/Y coordinates in pixels
1049 float referenceGestureY;
1050
Jeff Brown538881e2011-05-25 18:23:38 -07001051 // Distance that each pointer has traveled which has not yet been
1052 // subsumed into the reference gesture position.
1053 BitSet32 referenceIdBits;
1054 struct Delta {
1055 float dx, dy;
1056 };
1057 Delta referenceDeltas[MAX_POINTER_ID + 1];
1058
Jeff Brown2352b972011-04-12 22:39:53 -07001059 // Describes how touch ids are mapped to gesture ids for freeform gestures.
1060 uint32_t freeformTouchToGestureIdMap[MAX_POINTER_ID + 1];
1061
Jeff Brownace13b12011-03-09 17:39:48 -08001062 // A velocity tracker for determining whether to switch active pointers during drags.
1063 VelocityTracker velocityTracker;
1064
1065 void reset() {
Jeff Brown2352b972011-04-12 22:39:53 -07001066 firstTouchTime = LLONG_MIN;
Jeff Brownace13b12011-03-09 17:39:48 -08001067 activeTouchId = -1;
1068 activeGestureId = -1;
1069 currentGestureMode = NEUTRAL;
Jeff Brownace13b12011-03-09 17:39:48 -08001070 currentGestureIdBits.clear();
1071 lastGestureMode = NEUTRAL;
Jeff Brownace13b12011-03-09 17:39:48 -08001072 lastGestureIdBits.clear();
Jeff Brown2352b972011-04-12 22:39:53 -07001073 spotGesture = PointerControllerInterface::SPOT_GESTURE_NEUTRAL;
1074 spotIdBits.clear();
Jeff Brownace13b12011-03-09 17:39:48 -08001075 downTime = 0;
1076 velocityTracker.clear();
Jeff Brown79ac9692011-04-19 21:20:10 -07001077 resetTap();
Jeff Brownace13b12011-03-09 17:39:48 -08001078 resetQuietTime();
1079 }
1080
Jeff Brown79ac9692011-04-19 21:20:10 -07001081 void resetTap() {
1082 tapDownTime = LLONG_MIN;
1083 tapUpTime = LLONG_MIN;
Jeff Brownace13b12011-03-09 17:39:48 -08001084 }
1085
1086 void resetQuietTime() {
1087 quietTime = LLONG_MIN;
1088 }
1089 } mPointerGesture;
1090
Jeff Brown6328cdc2010-07-29 18:18:33 -07001091 void initializeLocked();
Jeff Brown6d0fec22010-07-23 21:28:06 -07001092
1093 TouchResult consumeOffScreenTouches(nsecs_t when, uint32_t policyFlags);
1094 void dispatchTouches(nsecs_t when, uint32_t policyFlags);
Jeff Brownace13b12011-03-09 17:39:48 -08001095 void prepareTouches(int32_t* outEdgeFlags, float* outXPrecision, float* outYPrecision);
Jeff Brown79ac9692011-04-19 21:20:10 -07001096 void dispatchPointerGestures(nsecs_t when, uint32_t policyFlags, bool isTimeout);
1097 bool preparePointerGestures(nsecs_t when,
1098 bool* outCancelPreviousGesture, bool* outFinishPreviousGesture, bool isTimeout);
Jeff Brown2352b972011-04-12 22:39:53 -07001099 void moveSpotsLocked();
Jeff Brownace13b12011-03-09 17:39:48 -08001100
1101 // Dispatches a motion event.
1102 // If the changedId is >= 0 and the action is POINTER_DOWN or POINTER_UP, the
1103 // method will take care of setting the index and transmuting the action to DOWN or UP
1104 // it is the first / last pointer to go down / up.
1105 void dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32_t source,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001106 int32_t action, int32_t flags, int32_t metaState, int32_t buttonState,
1107 int32_t edgeFlags,
1108 const PointerProperties* properties, const PointerCoords* coords,
1109 const uint32_t* idToIndex, BitSet32 idBits,
Jeff Brownace13b12011-03-09 17:39:48 -08001110 int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime);
1111
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001112 // Updates pointer coords and properties for pointers with specified ids that have moved.
Jeff Brownace13b12011-03-09 17:39:48 -08001113 // Returns true if any of them changed.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001114 bool updateMovedPointers(const PointerProperties* inProperties,
1115 const PointerCoords* inCoords, const uint32_t* inIdToIndex,
1116 PointerProperties* outProperties, PointerCoords* outCoords,
1117 const uint32_t* outIdToIndex, BitSet32 idBits) const;
Jeff Brownace13b12011-03-09 17:39:48 -08001118
Jeff Brownefd32662011-03-08 15:13:06 -08001119 void suppressSwipeOntoVirtualKeys(nsecs_t when);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001120
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001121 int32_t getTouchToolType(bool isStylus) const;
Jeff Brown6328cdc2010-07-29 18:18:33 -07001122 bool isPointInsideSurfaceLocked(int32_t x, int32_t y);
1123 const VirtualKey* findVirtualKeyHitLocked(int32_t x, int32_t y);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001124
1125 bool applyBadTouchFilter();
1126 bool applyJumpyTouchFilter();
1127 void applyAveragingTouchFilter();
1128 void calculatePointerIds();
1129};
1130
1131
1132class SingleTouchInputMapper : public TouchInputMapper {
1133public:
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001134 SingleTouchInputMapper(InputDevice* device);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001135 virtual ~SingleTouchInputMapper();
1136
1137 virtual void reset();
1138 virtual void process(const RawEvent* rawEvent);
1139
1140protected:
Jeff Brown8d608662010-08-30 03:02:23 -07001141 virtual void configureRawAxes();
Jeff Brown6d0fec22010-07-23 21:28:06 -07001142
1143private:
1144 struct Accumulator {
1145 enum {
1146 FIELD_BTN_TOUCH = 1,
1147 FIELD_ABS_X = 2,
1148 FIELD_ABS_Y = 4,
1149 FIELD_ABS_PRESSURE = 8,
Jeff Brownefd32662011-03-08 15:13:06 -08001150 FIELD_ABS_TOOL_WIDTH = 16,
Jeff Brownace13b12011-03-09 17:39:48 -08001151 FIELD_BUTTONS = 32,
Jeff Brown6d0fec22010-07-23 21:28:06 -07001152 };
1153
1154 uint32_t fields;
1155
1156 bool btnTouch;
1157 int32_t absX;
1158 int32_t absY;
1159 int32_t absPressure;
1160 int32_t absToolWidth;
1161
Jeff Brownace13b12011-03-09 17:39:48 -08001162 uint32_t buttonDown;
1163 uint32_t buttonUp;
1164
Jeff Brown6d0fec22010-07-23 21:28:06 -07001165 inline void clear() {
1166 fields = 0;
Jeff Brownace13b12011-03-09 17:39:48 -08001167 buttonDown = 0;
1168 buttonUp = 0;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001169 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07001170 } mAccumulator;
1171
1172 bool mDown;
1173 int32_t mX;
1174 int32_t mY;
1175 int32_t mPressure;
Jeff Brown8d608662010-08-30 03:02:23 -07001176 int32_t mToolWidth;
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001177 int32_t mButtonState;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001178
Jeff Brown80fd47c2011-05-24 01:07:44 -07001179 void clearState();
Jeff Brown6d0fec22010-07-23 21:28:06 -07001180
1181 void sync(nsecs_t when);
1182};
1183
1184
1185class MultiTouchInputMapper : public TouchInputMapper {
1186public:
Jeff Brown47e6b1b2010-11-29 17:37:49 -08001187 MultiTouchInputMapper(InputDevice* device);
Jeff Brown6d0fec22010-07-23 21:28:06 -07001188 virtual ~MultiTouchInputMapper();
1189
1190 virtual void reset();
1191 virtual void process(const RawEvent* rawEvent);
1192
1193protected:
Jeff Brown8d608662010-08-30 03:02:23 -07001194 virtual void configureRawAxes();
Jeff Brown6d0fec22010-07-23 21:28:06 -07001195
1196private:
1197 struct Accumulator {
1198 enum {
Jeff Brown80fd47c2011-05-24 01:07:44 -07001199 FIELD_ABS_MT_POSITION_X = 1 << 0,
1200 FIELD_ABS_MT_POSITION_Y = 1 << 1,
1201 FIELD_ABS_MT_TOUCH_MAJOR = 1 << 2,
1202 FIELD_ABS_MT_TOUCH_MINOR = 1 << 3,
1203 FIELD_ABS_MT_WIDTH_MAJOR = 1 << 4,
1204 FIELD_ABS_MT_WIDTH_MINOR = 1 << 5,
1205 FIELD_ABS_MT_ORIENTATION = 1 << 6,
1206 FIELD_ABS_MT_TRACKING_ID = 1 << 7,
1207 FIELD_ABS_MT_PRESSURE = 1 << 8,
1208 FIELD_ABS_MT_TOOL_TYPE = 1 << 9,
1209 FIELD_ABS_MT_DISTANCE = 1 << 10,
Jeff Brown6d0fec22010-07-23 21:28:06 -07001210 };
1211
Jeff Brown80fd47c2011-05-24 01:07:44 -07001212 struct Slot {
1213 uint32_t fields; // 0 if slot is unused
Jeff Brown6d0fec22010-07-23 21:28:06 -07001214
1215 int32_t absMTPositionX;
1216 int32_t absMTPositionY;
1217 int32_t absMTTouchMajor;
1218 int32_t absMTTouchMinor;
1219 int32_t absMTWidthMajor;
1220 int32_t absMTWidthMinor;
1221 int32_t absMTOrientation;
1222 int32_t absMTTrackingId;
Jeff Brown2dfd7a72010-08-17 20:38:35 -07001223 int32_t absMTPressure;
Jeff Brown80fd47c2011-05-24 01:07:44 -07001224 int32_t absMTToolType;
1225 int32_t absMTDistance;
1226
1227 inline Slot() {
1228 clear();
1229 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07001230
1231 inline void clear() {
1232 fields = 0;
1233 }
Jeff Brown80fd47c2011-05-24 01:07:44 -07001234 };
1235
1236 // Current slot index.
1237 int32_t currentSlot;
1238
1239 // Array of slots.
1240 Slot* slots;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001241
Jeff Brownace13b12011-03-09 17:39:48 -08001242 // Bitfield of buttons that went down or up.
1243 uint32_t buttonDown;
1244 uint32_t buttonUp;
1245
Jeff Brown80fd47c2011-05-24 01:07:44 -07001246 Accumulator() : slots(NULL) {
1247 clear(false);
1248 }
1249
1250 ~Accumulator() {
1251 delete[] slots;
1252 }
1253
1254 void allocateSlots(size_t slotCount) {
1255 slots = new Slot[slotCount];
1256 }
1257
1258 void clear(size_t slotCount) {
1259 for (size_t i = 0; i < slotCount; i++) {
1260 slots[i].clear();
1261 }
1262 currentSlot = 0;
Jeff Brownace13b12011-03-09 17:39:48 -08001263 buttonDown = 0;
1264 buttonUp = 0;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001265 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07001266 } mAccumulator;
1267
Jeff Brown80fd47c2011-05-24 01:07:44 -07001268 size_t mSlotCount;
1269 bool mUsingSlotsProtocol;
1270
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001271 int32_t mButtonState;
Jeff Brownace13b12011-03-09 17:39:48 -08001272
Jeff Brown80fd47c2011-05-24 01:07:44 -07001273 void clearState();
Jeff Brown6d0fec22010-07-23 21:28:06 -07001274
1275 void sync(nsecs_t when);
1276};
1277
Jeff Browncb1404e2011-01-15 18:14:15 -08001278
1279class JoystickInputMapper : public InputMapper {
1280public:
1281 JoystickInputMapper(InputDevice* device);
1282 virtual ~JoystickInputMapper();
1283
1284 virtual uint32_t getSources();
1285 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
1286 virtual void dump(String8& dump);
1287 virtual void configure();
1288 virtual void reset();
1289 virtual void process(const RawEvent* rawEvent);
1290
1291private:
Jeff Brown6f2fba42011-02-19 01:08:02 -08001292 struct Axis {
1293 RawAbsoluteAxisInfo rawAxisInfo;
Jeff Brown85297452011-03-04 13:07:49 -08001294 AxisInfo axisInfo;
Jeff Browncb1404e2011-01-15 18:14:15 -08001295
Jeff Brown6f2fba42011-02-19 01:08:02 -08001296 bool explicitlyMapped; // true if the axis was explicitly assigned an axis id
Jeff Browncb1404e2011-01-15 18:14:15 -08001297
Jeff Brown6f2fba42011-02-19 01:08:02 -08001298 float scale; // scale factor from raw to normalized values
1299 float offset; // offset to add after scaling for normalization
Jeff Brown85297452011-03-04 13:07:49 -08001300 float highScale; // scale factor from raw to normalized values of high split
1301 float highOffset; // offset to add after scaling for normalization of high split
Jeff Browncb1404e2011-01-15 18:14:15 -08001302
Jeff Brown6f2fba42011-02-19 01:08:02 -08001303 float min; // normalized inclusive minimum
1304 float max; // normalized inclusive maximum
1305 float flat; // normalized flat region size
1306 float fuzz; // normalized error tolerance
Jeff Browncb1404e2011-01-15 18:14:15 -08001307
Jeff Brown6f2fba42011-02-19 01:08:02 -08001308 float filter; // filter out small variations of this size
Jeff Brown85297452011-03-04 13:07:49 -08001309 float currentValue; // current value
1310 float newValue; // most recent value
1311 float highCurrentValue; // current value of high split
1312 float highNewValue; // most recent value of high split
Jeff Browncb1404e2011-01-15 18:14:15 -08001313
Jeff Brown85297452011-03-04 13:07:49 -08001314 void initialize(const RawAbsoluteAxisInfo& rawAxisInfo, const AxisInfo& axisInfo,
1315 bool explicitlyMapped, float scale, float offset,
1316 float highScale, float highOffset,
Jeff Brown6f2fba42011-02-19 01:08:02 -08001317 float min, float max, float flat, float fuzz) {
1318 this->rawAxisInfo = rawAxisInfo;
Jeff Brown85297452011-03-04 13:07:49 -08001319 this->axisInfo = axisInfo;
Jeff Brown6f2fba42011-02-19 01:08:02 -08001320 this->explicitlyMapped = explicitlyMapped;
1321 this->scale = scale;
1322 this->offset = offset;
Jeff Brown85297452011-03-04 13:07:49 -08001323 this->highScale = highScale;
1324 this->highOffset = highOffset;
Jeff Brown6f2fba42011-02-19 01:08:02 -08001325 this->min = min;
1326 this->max = max;
1327 this->flat = flat;
1328 this->fuzz = fuzz;
1329 this->filter = 0;
Jeff Brown85297452011-03-04 13:07:49 -08001330 resetValue();
1331 }
1332
1333 void resetValue() {
1334 this->currentValue = 0;
Jeff Brown6f2fba42011-02-19 01:08:02 -08001335 this->newValue = 0;
Jeff Brown85297452011-03-04 13:07:49 -08001336 this->highCurrentValue = 0;
1337 this->highNewValue = 0;
Jeff Browncb1404e2011-01-15 18:14:15 -08001338 }
1339 };
1340
Jeff Brown6f2fba42011-02-19 01:08:02 -08001341 // Axes indexed by raw ABS_* axis index.
1342 KeyedVector<int32_t, Axis> mAxes;
Jeff Browncb1404e2011-01-15 18:14:15 -08001343
Jeff Brown6f2fba42011-02-19 01:08:02 -08001344 void sync(nsecs_t when, bool force);
Jeff Browncb1404e2011-01-15 18:14:15 -08001345
Jeff Brown85297452011-03-04 13:07:49 -08001346 bool haveAxis(int32_t axisId);
Jeff Brown6f2fba42011-02-19 01:08:02 -08001347 void pruneAxes(bool ignoreExplicitlyMappedAxes);
Jeff Brown85297452011-03-04 13:07:49 -08001348 bool filterAxes(bool force);
1349
1350 static bool hasValueChangedSignificantly(float filter,
1351 float newValue, float currentValue, float min, float max);
1352 static bool hasMovedNearerToValueWithinFilteredRange(float filter,
1353 float newValue, float currentValue, float thresholdValue);
Jeff Browncb1404e2011-01-15 18:14:15 -08001354
Jeff Brown6f2fba42011-02-19 01:08:02 -08001355 static bool isCenteredAxis(int32_t axis);
Jeff Browncb1404e2011-01-15 18:14:15 -08001356};
1357
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001358} // namespace android
1359
1360#endif // _UI_INPUT_READER_H