widget/gonk/libui/InputReader.h

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /*
michael@0 2 * Copyright (C) 2010 The Android Open Source Project
michael@0 3 *
michael@0 4 * Licensed under the Apache License, Version 2.0 (the "License");
michael@0 5 * you may not use this file except in compliance with the License.
michael@0 6 * You may obtain a copy of the License at
michael@0 7 *
michael@0 8 * http://www.apache.org/licenses/LICENSE-2.0
michael@0 9 *
michael@0 10 * Unless required by applicable law or agreed to in writing, software
michael@0 11 * distributed under the License is distributed on an "AS IS" BASIS,
michael@0 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
michael@0 13 * See the License for the specific language governing permissions and
michael@0 14 * limitations under the License.
michael@0 15 */
michael@0 16
michael@0 17 #ifndef _UI_INPUT_READER_H
michael@0 18 #define _UI_INPUT_READER_H
michael@0 19
michael@0 20 #include "EventHub.h"
michael@0 21 #include "PointerController.h"
michael@0 22 #include "InputListener.h"
michael@0 23
michael@0 24 #include "Input.h"
michael@0 25 #include "VelocityControl.h"
michael@0 26 #include "VelocityTracker.h"
michael@0 27 #include <utils/KeyedVector.h>
michael@0 28 #include <utils/threads.h>
michael@0 29 #include <utils/Timers.h>
michael@0 30 #include <utils/RefBase.h>
michael@0 31 #include <utils/String8.h>
michael@0 32 #include <utils/BitSet.h>
michael@0 33
michael@0 34 #include <stddef.h>
michael@0 35 #include <unistd.h>
michael@0 36
michael@0 37 // Maximum supported size of a vibration pattern.
michael@0 38 // Must be at least 2.
michael@0 39 #define MAX_VIBRATE_PATTERN_SIZE 100
michael@0 40
michael@0 41 // Maximum allowable delay value in a vibration pattern before
michael@0 42 // which the delay will be truncated.
michael@0 43 #define MAX_VIBRATE_PATTERN_DELAY_NSECS (1000000 * 1000000000LL)
michael@0 44
michael@0 45 namespace android {
michael@0 46
michael@0 47 class InputDevice;
michael@0 48 class InputMapper;
michael@0 49
michael@0 50 /*
michael@0 51 * Describes how coordinates are mapped on a physical display.
michael@0 52 * See com.android.server.display.DisplayViewport.
michael@0 53 */
michael@0 54 struct DisplayViewport {
michael@0 55 int32_t displayId; // -1 if invalid
michael@0 56 int32_t orientation;
michael@0 57 int32_t logicalLeft;
michael@0 58 int32_t logicalTop;
michael@0 59 int32_t logicalRight;
michael@0 60 int32_t logicalBottom;
michael@0 61 int32_t physicalLeft;
michael@0 62 int32_t physicalTop;
michael@0 63 int32_t physicalRight;
michael@0 64 int32_t physicalBottom;
michael@0 65 int32_t deviceWidth;
michael@0 66 int32_t deviceHeight;
michael@0 67
michael@0 68 DisplayViewport() :
michael@0 69 displayId(ADISPLAY_ID_NONE), orientation(DISPLAY_ORIENTATION_0),
michael@0 70 logicalLeft(0), logicalTop(0), logicalRight(0), logicalBottom(0),
michael@0 71 physicalLeft(0), physicalTop(0), physicalRight(0), physicalBottom(0),
michael@0 72 deviceWidth(0), deviceHeight(0) {
michael@0 73 }
michael@0 74
michael@0 75 bool operator==(const DisplayViewport& other) const {
michael@0 76 return displayId == other.displayId
michael@0 77 && orientation == other.orientation
michael@0 78 && logicalLeft == other.logicalLeft
michael@0 79 && logicalTop == other.logicalTop
michael@0 80 && logicalRight == other.logicalRight
michael@0 81 && logicalBottom == other.logicalBottom
michael@0 82 && physicalLeft == other.physicalLeft
michael@0 83 && physicalTop == other.physicalTop
michael@0 84 && physicalRight == other.physicalRight
michael@0 85 && physicalBottom == other.physicalBottom
michael@0 86 && deviceWidth == other.deviceWidth
michael@0 87 && deviceHeight == other.deviceHeight;
michael@0 88 }
michael@0 89
michael@0 90 bool operator!=(const DisplayViewport& other) const {
michael@0 91 return !(*this == other);
michael@0 92 }
michael@0 93
michael@0 94 inline bool isValid() const {
michael@0 95 return displayId >= 0;
michael@0 96 }
michael@0 97
michael@0 98 void setNonDisplayViewport(int32_t width, int32_t height) {
michael@0 99 displayId = ADISPLAY_ID_NONE;
michael@0 100 orientation = DISPLAY_ORIENTATION_0;
michael@0 101 logicalLeft = 0;
michael@0 102 logicalTop = 0;
michael@0 103 logicalRight = width;
michael@0 104 logicalBottom = height;
michael@0 105 physicalLeft = 0;
michael@0 106 physicalTop = 0;
michael@0 107 physicalRight = width;
michael@0 108 physicalBottom = height;
michael@0 109 deviceWidth = width;
michael@0 110 deviceHeight = height;
michael@0 111 }
michael@0 112 };
michael@0 113
michael@0 114 /*
michael@0 115 * Input reader configuration.
michael@0 116 *
michael@0 117 * Specifies various options that modify the behavior of the input reader.
michael@0 118 */
michael@0 119 struct InputReaderConfiguration {
michael@0 120 // Describes changes that have occurred.
michael@0 121 enum {
michael@0 122 // The pointer speed changed.
michael@0 123 CHANGE_POINTER_SPEED = 1 << 0,
michael@0 124
michael@0 125 // The pointer gesture control changed.
michael@0 126 CHANGE_POINTER_GESTURE_ENABLEMENT = 1 << 1,
michael@0 127
michael@0 128 // The display size or orientation changed.
michael@0 129 CHANGE_DISPLAY_INFO = 1 << 2,
michael@0 130
michael@0 131 // The visible touches option changed.
michael@0 132 CHANGE_SHOW_TOUCHES = 1 << 3,
michael@0 133
michael@0 134 // The keyboard layouts must be reloaded.
michael@0 135 CHANGE_KEYBOARD_LAYOUTS = 1 << 4,
michael@0 136
michael@0 137 // The device name alias supplied by the may have changed for some devices.
michael@0 138 CHANGE_DEVICE_ALIAS = 1 << 5,
michael@0 139
michael@0 140 // All devices must be reopened.
michael@0 141 CHANGE_MUST_REOPEN = 1 << 31,
michael@0 142 };
michael@0 143
michael@0 144 // Gets the amount of time to disable virtual keys after the screen is touched
michael@0 145 // in order to filter out accidental virtual key presses due to swiping gestures
michael@0 146 // or taps near the edge of the display. May be 0 to disable the feature.
michael@0 147 nsecs_t virtualKeyQuietTime;
michael@0 148
michael@0 149 // The excluded device names for the platform.
michael@0 150 // Devices with these names will be ignored.
michael@0 151 Vector<String8> excludedDeviceNames;
michael@0 152
michael@0 153 // Velocity control parameters for mouse pointer movements.
michael@0 154 VelocityControlParameters pointerVelocityControlParameters;
michael@0 155
michael@0 156 // Velocity control parameters for mouse wheel movements.
michael@0 157 VelocityControlParameters wheelVelocityControlParameters;
michael@0 158
michael@0 159 // True if pointer gestures are enabled.
michael@0 160 bool pointerGesturesEnabled;
michael@0 161
michael@0 162 // Quiet time between certain pointer gesture transitions.
michael@0 163 // Time to allow for all fingers or buttons to settle into a stable state before
michael@0 164 // starting a new gesture.
michael@0 165 nsecs_t pointerGestureQuietInterval;
michael@0 166
michael@0 167 // The minimum speed that a pointer must travel for us to consider switching the active
michael@0 168 // touch pointer to it during a drag. This threshold is set to avoid switching due
michael@0 169 // to noise from a finger resting on the touch pad (perhaps just pressing it down).
michael@0 170 float pointerGestureDragMinSwitchSpeed; // in pixels per second
michael@0 171
michael@0 172 // Tap gesture delay time.
michael@0 173 // The time between down and up must be less than this to be considered a tap.
michael@0 174 nsecs_t pointerGestureTapInterval;
michael@0 175
michael@0 176 // Tap drag gesture delay time.
michael@0 177 // The time between the previous tap's up and the next down must be less than
michael@0 178 // this to be considered a drag. Otherwise, the previous tap is finished and a
michael@0 179 // new tap begins.
michael@0 180 //
michael@0 181 // Note that the previous tap will be held down for this entire duration so this
michael@0 182 // interval must be shorter than the long press timeout.
michael@0 183 nsecs_t pointerGestureTapDragInterval;
michael@0 184
michael@0 185 // The distance in pixels that the pointer is allowed to move from initial down
michael@0 186 // to up and still be called a tap.
michael@0 187 float pointerGestureTapSlop; // in pixels
michael@0 188
michael@0 189 // Time after the first touch points go down to settle on an initial centroid.
michael@0 190 // This is intended to be enough time to handle cases where the user puts down two
michael@0 191 // fingers at almost but not quite exactly the same time.
michael@0 192 nsecs_t pointerGestureMultitouchSettleInterval;
michael@0 193
michael@0 194 // The transition from PRESS to SWIPE or FREEFORM gesture mode is made when
michael@0 195 // at least two pointers have moved at least this far from their starting place.
michael@0 196 float pointerGestureMultitouchMinDistance; // in pixels
michael@0 197
michael@0 198 // The transition from PRESS to SWIPE gesture mode can only occur when the
michael@0 199 // cosine of the angle between the two vectors is greater than or equal to than this value
michael@0 200 // which indicates that the vectors are oriented in the same direction.
michael@0 201 // When the vectors are oriented in the exactly same direction, the cosine is 1.0.
michael@0 202 // (In exactly opposite directions, the cosine is -1.0.)
michael@0 203 float pointerGestureSwipeTransitionAngleCosine;
michael@0 204
michael@0 205 // The transition from PRESS to SWIPE gesture mode can only occur when the
michael@0 206 // fingers are no more than this far apart relative to the diagonal size of
michael@0 207 // the touch pad. For example, a ratio of 0.5 means that the fingers must be
michael@0 208 // no more than half the diagonal size of the touch pad apart.
michael@0 209 float pointerGestureSwipeMaxWidthRatio;
michael@0 210
michael@0 211 // The gesture movement speed factor relative to the size of the display.
michael@0 212 // Movement speed applies when the fingers are moving in the same direction.
michael@0 213 // Without acceleration, a full swipe of the touch pad diagonal in movement mode
michael@0 214 // will cover this portion of the display diagonal.
michael@0 215 float pointerGestureMovementSpeedRatio;
michael@0 216
michael@0 217 // The gesture zoom speed factor relative to the size of the display.
michael@0 218 // Zoom speed applies when the fingers are mostly moving relative to each other
michael@0 219 // to execute a scale gesture or similar.
michael@0 220 // Without acceleration, a full swipe of the touch pad diagonal in zoom mode
michael@0 221 // will cover this portion of the display diagonal.
michael@0 222 float pointerGestureZoomSpeedRatio;
michael@0 223
michael@0 224 // True to show the location of touches on the touch screen as spots.
michael@0 225 bool showTouches;
michael@0 226
michael@0 227 InputReaderConfiguration() :
michael@0 228 virtualKeyQuietTime(0),
michael@0 229 pointerVelocityControlParameters(1.0f, 500.0f, 3000.0f, 3.0f),
michael@0 230 wheelVelocityControlParameters(1.0f, 15.0f, 50.0f, 4.0f),
michael@0 231 pointerGesturesEnabled(true),
michael@0 232 pointerGestureQuietInterval(100 * 1000000LL), // 100 ms
michael@0 233 pointerGestureDragMinSwitchSpeed(50), // 50 pixels per second
michael@0 234 pointerGestureTapInterval(150 * 1000000LL), // 150 ms
michael@0 235 pointerGestureTapDragInterval(150 * 1000000LL), // 150 ms
michael@0 236 pointerGestureTapSlop(10.0f), // 10 pixels
michael@0 237 pointerGestureMultitouchSettleInterval(100 * 1000000LL), // 100 ms
michael@0 238 pointerGestureMultitouchMinDistance(15), // 15 pixels
michael@0 239 pointerGestureSwipeTransitionAngleCosine(0.2588f), // cosine of 75 degrees
michael@0 240 pointerGestureSwipeMaxWidthRatio(0.25f),
michael@0 241 pointerGestureMovementSpeedRatio(0.8f),
michael@0 242 pointerGestureZoomSpeedRatio(0.3f),
michael@0 243 showTouches(false) { }
michael@0 244
michael@0 245 bool getDisplayInfo(bool external, DisplayViewport* outViewport) const;
michael@0 246 void setDisplayInfo(bool external, const DisplayViewport& viewport);
michael@0 247
michael@0 248 private:
michael@0 249 DisplayViewport mInternalDisplay;
michael@0 250 DisplayViewport mExternalDisplay;
michael@0 251 };
michael@0 252
michael@0 253
michael@0 254 /*
michael@0 255 * Input reader policy interface.
michael@0 256 *
michael@0 257 * The input reader policy is used by the input reader to interact with the Window Manager
michael@0 258 * and other system components.
michael@0 259 *
michael@0 260 * The actual implementation is partially supported by callbacks into the DVM
michael@0 261 * via JNI. This interface is also mocked in the unit tests.
michael@0 262 *
michael@0 263 * These methods must NOT re-enter the input reader since they may be called while
michael@0 264 * holding the input reader lock.
michael@0 265 */
michael@0 266 class InputReaderPolicyInterface : public virtual RefBase {
michael@0 267 protected:
michael@0 268 InputReaderPolicyInterface() { }
michael@0 269 virtual ~InputReaderPolicyInterface() { }
michael@0 270
michael@0 271 public:
michael@0 272 /* Gets the input reader configuration. */
michael@0 273 virtual void getReaderConfiguration(InputReaderConfiguration* outConfig) = 0;
michael@0 274
michael@0 275 /* Gets a pointer controller associated with the specified cursor device (ie. a mouse). */
michael@0 276 virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId) = 0;
michael@0 277
michael@0 278 /* Notifies the input reader policy that some input devices have changed
michael@0 279 * and provides information about all current input devices.
michael@0 280 */
michael@0 281 virtual void notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices) = 0;
michael@0 282
michael@0 283 /* Gets the keyboard layout for a particular input device. */
michael@0 284 virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const String8& inputDeviceDescriptor) = 0;
michael@0 285
michael@0 286 /* Gets a user-supplied alias for a particular input device, or an empty string if none. */
michael@0 287 virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier) = 0;
michael@0 288 };
michael@0 289
michael@0 290
michael@0 291 /* Processes raw input events and sends cooked event data to an input listener. */
michael@0 292 class InputReaderInterface : public virtual RefBase {
michael@0 293 protected:
michael@0 294 InputReaderInterface() { }
michael@0 295 virtual ~InputReaderInterface() { }
michael@0 296
michael@0 297 public:
michael@0 298 /* Dumps the state of the input reader.
michael@0 299 *
michael@0 300 * This method may be called on any thread (usually by the input manager). */
michael@0 301 virtual void dump(String8& dump) = 0;
michael@0 302
michael@0 303 /* Called by the heatbeat to ensures that the reader has not deadlocked. */
michael@0 304 virtual void monitor() = 0;
michael@0 305
michael@0 306 /* Runs a single iteration of the processing loop.
michael@0 307 * Nominally reads and processes one incoming message from the EventHub.
michael@0 308 *
michael@0 309 * This method should be called on the input reader thread.
michael@0 310 */
michael@0 311 virtual void loopOnce() = 0;
michael@0 312
michael@0 313 /* Gets information about all input devices.
michael@0 314 *
michael@0 315 * This method may be called on any thread (usually by the input manager).
michael@0 316 */
michael@0 317 virtual void getInputDevices(Vector<InputDeviceInfo>& outInputDevices) = 0;
michael@0 318
michael@0 319 /* Query current input state. */
michael@0 320 virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask,
michael@0 321 int32_t scanCode) = 0;
michael@0 322 virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask,
michael@0 323 int32_t keyCode) = 0;
michael@0 324 virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask,
michael@0 325 int32_t sw) = 0;
michael@0 326
michael@0 327 /* Determine whether physical keys exist for the given framework-domain key codes. */
michael@0 328 virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask,
michael@0 329 size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) = 0;
michael@0 330
michael@0 331 /* Requests that a reconfiguration of all input devices.
michael@0 332 * The changes flag is a bitfield that indicates what has changed and whether
michael@0 333 * the input devices must all be reopened. */
michael@0 334 virtual void requestRefreshConfiguration(uint32_t changes) = 0;
michael@0 335
michael@0 336 /* Controls the vibrator of a particular input device. */
michael@0 337 virtual void vibrate(int32_t deviceId, const nsecs_t* pattern, size_t patternSize,
michael@0 338 ssize_t repeat, int32_t token) = 0;
michael@0 339 virtual void cancelVibrate(int32_t deviceId, int32_t token) = 0;
michael@0 340 };
michael@0 341
michael@0 342
michael@0 343 /* Internal interface used by individual input devices to access global input device state
michael@0 344 * and parameters maintained by the input reader.
michael@0 345 */
michael@0 346 class InputReaderContext {
michael@0 347 public:
michael@0 348 InputReaderContext() { }
michael@0 349 virtual ~InputReaderContext() { }
michael@0 350
michael@0 351 virtual void updateGlobalMetaState() = 0;
michael@0 352 virtual int32_t getGlobalMetaState() = 0;
michael@0 353
michael@0 354 virtual void disableVirtualKeysUntil(nsecs_t time) = 0;
michael@0 355 virtual bool shouldDropVirtualKey(nsecs_t now,
michael@0 356 InputDevice* device, int32_t keyCode, int32_t scanCode) = 0;
michael@0 357
michael@0 358 virtual void fadePointer() = 0;
michael@0 359
michael@0 360 virtual void requestTimeoutAtTime(nsecs_t when) = 0;
michael@0 361 virtual int32_t bumpGeneration() = 0;
michael@0 362
michael@0 363 virtual InputReaderPolicyInterface* getPolicy() = 0;
michael@0 364 virtual InputListenerInterface* getListener() = 0;
michael@0 365 virtual EventHubInterface* getEventHub() = 0;
michael@0 366 };
michael@0 367
michael@0 368
michael@0 369 /* The input reader reads raw event data from the event hub and processes it into input events
michael@0 370 * that it sends to the input listener. Some functions of the input reader, such as early
michael@0 371 * event filtering in low power states, are controlled by a separate policy object.
michael@0 372 *
michael@0 373 * The InputReader owns a collection of InputMappers. Most of the work it does happens
michael@0 374 * on the input reader thread but the InputReader can receive queries from other system
michael@0 375 * components running on arbitrary threads. To keep things manageable, the InputReader
michael@0 376 * uses a single Mutex to guard its state. The Mutex may be held while calling into the
michael@0 377 * EventHub or the InputReaderPolicy but it is never held while calling into the
michael@0 378 * InputListener.
michael@0 379 */
michael@0 380 class InputReader : public InputReaderInterface {
michael@0 381 public:
michael@0 382 InputReader(const sp<EventHubInterface>& eventHub,
michael@0 383 const sp<InputReaderPolicyInterface>& policy,
michael@0 384 const sp<InputListenerInterface>& listener);
michael@0 385 virtual ~InputReader();
michael@0 386
michael@0 387 virtual void dump(String8& dump);
michael@0 388 virtual void monitor();
michael@0 389
michael@0 390 virtual void loopOnce();
michael@0 391
michael@0 392 virtual void getInputDevices(Vector<InputDeviceInfo>& outInputDevices);
michael@0 393
michael@0 394 virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask,
michael@0 395 int32_t scanCode);
michael@0 396 virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask,
michael@0 397 int32_t keyCode);
michael@0 398 virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask,
michael@0 399 int32_t sw);
michael@0 400
michael@0 401 virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask,
michael@0 402 size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags);
michael@0 403
michael@0 404 virtual void requestRefreshConfiguration(uint32_t changes);
michael@0 405
michael@0 406 virtual void vibrate(int32_t deviceId, const nsecs_t* pattern, size_t patternSize,
michael@0 407 ssize_t repeat, int32_t token);
michael@0 408 virtual void cancelVibrate(int32_t deviceId, int32_t token);
michael@0 409
michael@0 410 protected:
michael@0 411 // These members are protected so they can be instrumented by test cases.
michael@0 412 virtual InputDevice* createDeviceLocked(int32_t deviceId,
michael@0 413 const InputDeviceIdentifier& identifier, uint32_t classes);
michael@0 414
michael@0 415 class ContextImpl : public InputReaderContext {
michael@0 416 InputReader* mReader;
michael@0 417
michael@0 418 public:
michael@0 419 ContextImpl(InputReader* reader);
michael@0 420
michael@0 421 virtual void updateGlobalMetaState();
michael@0 422 virtual int32_t getGlobalMetaState();
michael@0 423 virtual void disableVirtualKeysUntil(nsecs_t time);
michael@0 424 virtual bool shouldDropVirtualKey(nsecs_t now,
michael@0 425 InputDevice* device, int32_t keyCode, int32_t scanCode);
michael@0 426 virtual void fadePointer();
michael@0 427 virtual void requestTimeoutAtTime(nsecs_t when);
michael@0 428 virtual int32_t bumpGeneration();
michael@0 429 virtual InputReaderPolicyInterface* getPolicy();
michael@0 430 virtual InputListenerInterface* getListener();
michael@0 431 virtual EventHubInterface* getEventHub();
michael@0 432 } mContext;
michael@0 433
michael@0 434 friend class ContextImpl;
michael@0 435
michael@0 436 private:
michael@0 437 Mutex mLock;
michael@0 438
michael@0 439 Condition mReaderIsAliveCondition;
michael@0 440
michael@0 441 sp<EventHubInterface> mEventHub;
michael@0 442 sp<InputReaderPolicyInterface> mPolicy;
michael@0 443 sp<QueuedInputListener> mQueuedListener;
michael@0 444
michael@0 445 InputReaderConfiguration mConfig;
michael@0 446
michael@0 447 // The event queue.
michael@0 448 static const int EVENT_BUFFER_SIZE = 256;
michael@0 449 RawEvent mEventBuffer[EVENT_BUFFER_SIZE];
michael@0 450
michael@0 451 KeyedVector<int32_t, InputDevice*> mDevices;
michael@0 452
michael@0 453 // low-level input event decoding and device management
michael@0 454 void processEventsLocked(const RawEvent* rawEvents, size_t count);
michael@0 455
michael@0 456 void addDeviceLocked(nsecs_t when, int32_t deviceId);
michael@0 457 void removeDeviceLocked(nsecs_t when, int32_t deviceId);
michael@0 458 void processEventsForDeviceLocked(int32_t deviceId, const RawEvent* rawEvents, size_t count);
michael@0 459 void timeoutExpiredLocked(nsecs_t when);
michael@0 460
michael@0 461 void handleConfigurationChangedLocked(nsecs_t when);
michael@0 462
michael@0 463 int32_t mGlobalMetaState;
michael@0 464 void updateGlobalMetaStateLocked();
michael@0 465 int32_t getGlobalMetaStateLocked();
michael@0 466
michael@0 467 void fadePointerLocked();
michael@0 468
michael@0 469 int32_t mGeneration;
michael@0 470 int32_t bumpGenerationLocked();
michael@0 471
michael@0 472 void getInputDevicesLocked(Vector<InputDeviceInfo>& outInputDevices);
michael@0 473
michael@0 474 nsecs_t mDisableVirtualKeysTimeout;
michael@0 475 void disableVirtualKeysUntilLocked(nsecs_t time);
michael@0 476 bool shouldDropVirtualKeyLocked(nsecs_t now,
michael@0 477 InputDevice* device, int32_t keyCode, int32_t scanCode);
michael@0 478
michael@0 479 nsecs_t mNextTimeout;
michael@0 480 void requestTimeoutAtTimeLocked(nsecs_t when);
michael@0 481
michael@0 482 uint32_t mConfigurationChangesToRefresh;
michael@0 483 void refreshConfigurationLocked(uint32_t changes);
michael@0 484
michael@0 485 // state queries
michael@0 486 typedef int32_t (InputDevice::*GetStateFunc)(uint32_t sourceMask, int32_t code);
michael@0 487 int32_t getStateLocked(int32_t deviceId, uint32_t sourceMask, int32_t code,
michael@0 488 GetStateFunc getStateFunc);
michael@0 489 bool markSupportedKeyCodesLocked(int32_t deviceId, uint32_t sourceMask, size_t numCodes,
michael@0 490 const int32_t* keyCodes, uint8_t* outFlags);
michael@0 491 };
michael@0 492
michael@0 493
michael@0 494 /* Reads raw events from the event hub and processes them, endlessly. */
michael@0 495 class InputReaderThread : public Thread {
michael@0 496 public:
michael@0 497 InputReaderThread(const sp<InputReaderInterface>& reader);
michael@0 498 virtual ~InputReaderThread();
michael@0 499
michael@0 500 private:
michael@0 501 uint32_t mFoo;
michael@0 502 sp<InputReaderInterface> mReader;
michael@0 503
michael@0 504 virtual bool threadLoop();
michael@0 505 };
michael@0 506
michael@0 507
michael@0 508 /* Represents the state of a single input device. */
michael@0 509 class InputDevice {
michael@0 510 public:
michael@0 511 InputDevice(InputReaderContext* context, int32_t id, int32_t generation,
michael@0 512 const InputDeviceIdentifier& identifier, uint32_t classes);
michael@0 513 ~InputDevice();
michael@0 514
michael@0 515 inline InputReaderContext* getContext() { return mContext; }
michael@0 516 inline int32_t getId() { return mId; }
michael@0 517 inline int32_t getGeneration() { return mGeneration; }
michael@0 518 inline const String8& getName() { return mIdentifier.name; }
michael@0 519 inline uint32_t getClasses() { return mClasses; }
michael@0 520 inline uint32_t getSources() { return mSources; }
michael@0 521
michael@0 522 inline bool isExternal() { return mIsExternal; }
michael@0 523 inline void setExternal(bool external) { mIsExternal = external; }
michael@0 524
michael@0 525 inline bool isIgnored() { return mMappers.isEmpty(); }
michael@0 526
michael@0 527 void dump(String8& dump);
michael@0 528 void addMapper(InputMapper* mapper);
michael@0 529 void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
michael@0 530 void reset(nsecs_t when);
michael@0 531 void process(const RawEvent* rawEvents, size_t count);
michael@0 532 void timeoutExpired(nsecs_t when);
michael@0 533
michael@0 534 void getDeviceInfo(InputDeviceInfo* outDeviceInfo);
michael@0 535 int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
michael@0 536 int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
michael@0 537 int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
michael@0 538 bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
michael@0 539 const int32_t* keyCodes, uint8_t* outFlags);
michael@0 540 void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat, int32_t token);
michael@0 541 void cancelVibrate(int32_t token);
michael@0 542
michael@0 543 int32_t getMetaState();
michael@0 544
michael@0 545 void fadePointer();
michael@0 546
michael@0 547 void bumpGeneration();
michael@0 548
michael@0 549 void notifyReset(nsecs_t when);
michael@0 550
michael@0 551 inline const PropertyMap& getConfiguration() { return mConfiguration; }
michael@0 552 inline EventHubInterface* getEventHub() { return mContext->getEventHub(); }
michael@0 553
michael@0 554 bool hasKey(int32_t code) {
michael@0 555 return getEventHub()->hasScanCode(mId, code);
michael@0 556 }
michael@0 557
michael@0 558 bool hasAbsoluteAxis(int32_t code) {
michael@0 559 RawAbsoluteAxisInfo info;
michael@0 560 getEventHub()->getAbsoluteAxisInfo(mId, code, &info);
michael@0 561 return info.valid;
michael@0 562 }
michael@0 563
michael@0 564 bool isKeyPressed(int32_t code) {
michael@0 565 return getEventHub()->getScanCodeState(mId, code) == AKEY_STATE_DOWN;
michael@0 566 }
michael@0 567
michael@0 568 int32_t getAbsoluteAxisValue(int32_t code) {
michael@0 569 int32_t value;
michael@0 570 getEventHub()->getAbsoluteAxisValue(mId, code, &value);
michael@0 571 return value;
michael@0 572 }
michael@0 573
michael@0 574 private:
michael@0 575 InputReaderContext* mContext;
michael@0 576 int32_t mId;
michael@0 577 int32_t mGeneration;
michael@0 578 InputDeviceIdentifier mIdentifier;
michael@0 579 String8 mAlias;
michael@0 580 uint32_t mClasses;
michael@0 581
michael@0 582 Vector<InputMapper*> mMappers;
michael@0 583
michael@0 584 uint32_t mSources;
michael@0 585 bool mIsExternal;
michael@0 586 bool mDropUntilNextSync;
michael@0 587
michael@0 588 typedef int32_t (InputMapper::*GetStateFunc)(uint32_t sourceMask, int32_t code);
michael@0 589 int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc);
michael@0 590
michael@0 591 PropertyMap mConfiguration;
michael@0 592 };
michael@0 593
michael@0 594
michael@0 595 /* Keeps track of the state of mouse or touch pad buttons. */
michael@0 596 class CursorButtonAccumulator {
michael@0 597 public:
michael@0 598 CursorButtonAccumulator();
michael@0 599 void reset(InputDevice* device);
michael@0 600
michael@0 601 void process(const RawEvent* rawEvent);
michael@0 602
michael@0 603 uint32_t getButtonState() const;
michael@0 604
michael@0 605 private:
michael@0 606 bool mBtnLeft;
michael@0 607 bool mBtnRight;
michael@0 608 bool mBtnMiddle;
michael@0 609 bool mBtnBack;
michael@0 610 bool mBtnSide;
michael@0 611 bool mBtnForward;
michael@0 612 bool mBtnExtra;
michael@0 613 bool mBtnTask;
michael@0 614
michael@0 615 void clearButtons();
michael@0 616 };
michael@0 617
michael@0 618
michael@0 619 /* Keeps track of cursor movements. */
michael@0 620
michael@0 621 class CursorMotionAccumulator {
michael@0 622 public:
michael@0 623 CursorMotionAccumulator();
michael@0 624 void reset(InputDevice* device);
michael@0 625
michael@0 626 void process(const RawEvent* rawEvent);
michael@0 627 void finishSync();
michael@0 628
michael@0 629 inline int32_t getRelativeX() const { return mRelX; }
michael@0 630 inline int32_t getRelativeY() const { return mRelY; }
michael@0 631
michael@0 632 private:
michael@0 633 int32_t mRelX;
michael@0 634 int32_t mRelY;
michael@0 635
michael@0 636 void clearRelativeAxes();
michael@0 637 };
michael@0 638
michael@0 639
michael@0 640 /* Keeps track of cursor scrolling motions. */
michael@0 641
michael@0 642 class CursorScrollAccumulator {
michael@0 643 public:
michael@0 644 CursorScrollAccumulator();
michael@0 645 void configure(InputDevice* device);
michael@0 646 void reset(InputDevice* device);
michael@0 647
michael@0 648 void process(const RawEvent* rawEvent);
michael@0 649 void finishSync();
michael@0 650
michael@0 651 inline bool haveRelativeVWheel() const { return mHaveRelWheel; }
michael@0 652 inline bool haveRelativeHWheel() const { return mHaveRelHWheel; }
michael@0 653
michael@0 654 inline int32_t getRelativeX() const { return mRelX; }
michael@0 655 inline int32_t getRelativeY() const { return mRelY; }
michael@0 656 inline int32_t getRelativeVWheel() const { return mRelWheel; }
michael@0 657 inline int32_t getRelativeHWheel() const { return mRelHWheel; }
michael@0 658
michael@0 659 private:
michael@0 660 bool mHaveRelWheel;
michael@0 661 bool mHaveRelHWheel;
michael@0 662
michael@0 663 int32_t mRelX;
michael@0 664 int32_t mRelY;
michael@0 665 int32_t mRelWheel;
michael@0 666 int32_t mRelHWheel;
michael@0 667
michael@0 668 void clearRelativeAxes();
michael@0 669 };
michael@0 670
michael@0 671
michael@0 672 /* Keeps track of the state of touch, stylus and tool buttons. */
michael@0 673 class TouchButtonAccumulator {
michael@0 674 public:
michael@0 675 TouchButtonAccumulator();
michael@0 676 void configure(InputDevice* device);
michael@0 677 void reset(InputDevice* device);
michael@0 678
michael@0 679 void process(const RawEvent* rawEvent);
michael@0 680
michael@0 681 uint32_t getButtonState() const;
michael@0 682 int32_t getToolType() const;
michael@0 683 bool isToolActive() const;
michael@0 684 bool isHovering() const;
michael@0 685 bool hasStylus() const;
michael@0 686
michael@0 687 private:
michael@0 688 bool mHaveBtnTouch;
michael@0 689 bool mHaveStylus;
michael@0 690
michael@0 691 bool mBtnTouch;
michael@0 692 bool mBtnStylus;
michael@0 693 bool mBtnStylus2;
michael@0 694 bool mBtnToolFinger;
michael@0 695 bool mBtnToolPen;
michael@0 696 bool mBtnToolRubber;
michael@0 697 bool mBtnToolBrush;
michael@0 698 bool mBtnToolPencil;
michael@0 699 bool mBtnToolAirbrush;
michael@0 700 bool mBtnToolMouse;
michael@0 701 bool mBtnToolLens;
michael@0 702 bool mBtnToolDoubleTap;
michael@0 703 bool mBtnToolTripleTap;
michael@0 704 bool mBtnToolQuadTap;
michael@0 705
michael@0 706 void clearButtons();
michael@0 707 };
michael@0 708
michael@0 709
michael@0 710 /* Raw axis information from the driver. */
michael@0 711 struct RawPointerAxes {
michael@0 712 RawAbsoluteAxisInfo x;
michael@0 713 RawAbsoluteAxisInfo y;
michael@0 714 RawAbsoluteAxisInfo pressure;
michael@0 715 RawAbsoluteAxisInfo touchMajor;
michael@0 716 RawAbsoluteAxisInfo touchMinor;
michael@0 717 RawAbsoluteAxisInfo toolMajor;
michael@0 718 RawAbsoluteAxisInfo toolMinor;
michael@0 719 RawAbsoluteAxisInfo orientation;
michael@0 720 RawAbsoluteAxisInfo distance;
michael@0 721 RawAbsoluteAxisInfo tiltX;
michael@0 722 RawAbsoluteAxisInfo tiltY;
michael@0 723 RawAbsoluteAxisInfo trackingId;
michael@0 724 RawAbsoluteAxisInfo slot;
michael@0 725
michael@0 726 RawPointerAxes();
michael@0 727 void clear();
michael@0 728 };
michael@0 729
michael@0 730
michael@0 731 /* Raw data for a collection of pointers including a pointer id mapping table. */
michael@0 732 struct RawPointerData {
michael@0 733 struct Pointer {
michael@0 734 uint32_t id;
michael@0 735 int32_t x;
michael@0 736 int32_t y;
michael@0 737 int32_t pressure;
michael@0 738 int32_t touchMajor;
michael@0 739 int32_t touchMinor;
michael@0 740 int32_t toolMajor;
michael@0 741 int32_t toolMinor;
michael@0 742 int32_t orientation;
michael@0 743 int32_t distance;
michael@0 744 int32_t tiltX;
michael@0 745 int32_t tiltY;
michael@0 746 int32_t toolType; // a fully decoded AMOTION_EVENT_TOOL_TYPE constant
michael@0 747 bool isHovering;
michael@0 748 };
michael@0 749
michael@0 750 uint32_t pointerCount;
michael@0 751 Pointer pointers[MAX_POINTERS];
michael@0 752 BitSet32 hoveringIdBits, touchingIdBits;
michael@0 753 uint32_t idToIndex[MAX_POINTER_ID + 1];
michael@0 754
michael@0 755 RawPointerData();
michael@0 756 void clear();
michael@0 757 void copyFrom(const RawPointerData& other);
michael@0 758 void getCentroidOfTouchingPointers(float* outX, float* outY) const;
michael@0 759
michael@0 760 inline void markIdBit(uint32_t id, bool isHovering) {
michael@0 761 if (isHovering) {
michael@0 762 hoveringIdBits.markBit(id);
michael@0 763 } else {
michael@0 764 touchingIdBits.markBit(id);
michael@0 765 }
michael@0 766 }
michael@0 767
michael@0 768 inline void clearIdBits() {
michael@0 769 hoveringIdBits.clear();
michael@0 770 touchingIdBits.clear();
michael@0 771 }
michael@0 772
michael@0 773 inline const Pointer& pointerForId(uint32_t id) const {
michael@0 774 return pointers[idToIndex[id]];
michael@0 775 }
michael@0 776
michael@0 777 inline bool isHovering(uint32_t pointerIndex) {
michael@0 778 return pointers[pointerIndex].isHovering;
michael@0 779 }
michael@0 780 };
michael@0 781
michael@0 782
michael@0 783 /* Cooked data for a collection of pointers including a pointer id mapping table. */
michael@0 784 struct CookedPointerData {
michael@0 785 uint32_t pointerCount;
michael@0 786 PointerProperties pointerProperties[MAX_POINTERS];
michael@0 787 PointerCoords pointerCoords[MAX_POINTERS];
michael@0 788 BitSet32 hoveringIdBits, touchingIdBits;
michael@0 789 uint32_t idToIndex[MAX_POINTER_ID + 1];
michael@0 790
michael@0 791 CookedPointerData();
michael@0 792 void clear();
michael@0 793 void copyFrom(const CookedPointerData& other);
michael@0 794
michael@0 795 inline const PointerCoords& pointerCoordsForId(uint32_t id) const {
michael@0 796 return pointerCoords[idToIndex[id]];
michael@0 797 }
michael@0 798
michael@0 799 inline bool isHovering(uint32_t pointerIndex) {
michael@0 800 return hoveringIdBits.hasBit(pointerProperties[pointerIndex].id);
michael@0 801 }
michael@0 802 };
michael@0 803
michael@0 804
michael@0 805 /* Keeps track of the state of single-touch protocol. */
michael@0 806 class SingleTouchMotionAccumulator {
michael@0 807 public:
michael@0 808 SingleTouchMotionAccumulator();
michael@0 809
michael@0 810 void process(const RawEvent* rawEvent);
michael@0 811 void reset(InputDevice* device);
michael@0 812
michael@0 813 inline int32_t getAbsoluteX() const { return mAbsX; }
michael@0 814 inline int32_t getAbsoluteY() const { return mAbsY; }
michael@0 815 inline int32_t getAbsolutePressure() const { return mAbsPressure; }
michael@0 816 inline int32_t getAbsoluteToolWidth() const { return mAbsToolWidth; }
michael@0 817 inline int32_t getAbsoluteDistance() const { return mAbsDistance; }
michael@0 818 inline int32_t getAbsoluteTiltX() const { return mAbsTiltX; }
michael@0 819 inline int32_t getAbsoluteTiltY() const { return mAbsTiltY; }
michael@0 820
michael@0 821 private:
michael@0 822 int32_t mAbsX;
michael@0 823 int32_t mAbsY;
michael@0 824 int32_t mAbsPressure;
michael@0 825 int32_t mAbsToolWidth;
michael@0 826 int32_t mAbsDistance;
michael@0 827 int32_t mAbsTiltX;
michael@0 828 int32_t mAbsTiltY;
michael@0 829
michael@0 830 void clearAbsoluteAxes();
michael@0 831 };
michael@0 832
michael@0 833
michael@0 834 /* Keeps track of the state of multi-touch protocol. */
michael@0 835 class MultiTouchMotionAccumulator {
michael@0 836 public:
michael@0 837 class Slot {
michael@0 838 public:
michael@0 839 inline bool isInUse() const { return mInUse; }
michael@0 840 inline int32_t getX() const { return mAbsMTPositionX; }
michael@0 841 inline int32_t getY() const { return mAbsMTPositionY; }
michael@0 842 inline int32_t getTouchMajor() const { return mAbsMTTouchMajor; }
michael@0 843 inline int32_t getTouchMinor() const {
michael@0 844 return mHaveAbsMTTouchMinor ? mAbsMTTouchMinor : mAbsMTTouchMajor; }
michael@0 845 inline int32_t getToolMajor() const { return mAbsMTWidthMajor; }
michael@0 846 inline int32_t getToolMinor() const {
michael@0 847 return mHaveAbsMTWidthMinor ? mAbsMTWidthMinor : mAbsMTWidthMajor; }
michael@0 848 inline int32_t getOrientation() const { return mAbsMTOrientation; }
michael@0 849 inline int32_t getTrackingId() const { return mAbsMTTrackingId; }
michael@0 850 inline int32_t getPressure() const { return mAbsMTPressure; }
michael@0 851 inline int32_t getDistance() const { return mAbsMTDistance; }
michael@0 852 inline int32_t getToolType() const;
michael@0 853
michael@0 854 private:
michael@0 855 friend class MultiTouchMotionAccumulator;
michael@0 856
michael@0 857 bool mInUse;
michael@0 858 bool mHaveAbsMTTouchMinor;
michael@0 859 bool mHaveAbsMTWidthMinor;
michael@0 860 bool mHaveAbsMTToolType;
michael@0 861
michael@0 862 int32_t mAbsMTPositionX;
michael@0 863 int32_t mAbsMTPositionY;
michael@0 864 int32_t mAbsMTTouchMajor;
michael@0 865 int32_t mAbsMTTouchMinor;
michael@0 866 int32_t mAbsMTWidthMajor;
michael@0 867 int32_t mAbsMTWidthMinor;
michael@0 868 int32_t mAbsMTOrientation;
michael@0 869 int32_t mAbsMTTrackingId;
michael@0 870 int32_t mAbsMTPressure;
michael@0 871 int32_t mAbsMTDistance;
michael@0 872 int32_t mAbsMTToolType;
michael@0 873
michael@0 874 Slot();
michael@0 875 void clear();
michael@0 876 };
michael@0 877
michael@0 878 MultiTouchMotionAccumulator();
michael@0 879 ~MultiTouchMotionAccumulator();
michael@0 880
michael@0 881 void configure(InputDevice* device, size_t slotCount, bool usingSlotsProtocol);
michael@0 882 void reset(InputDevice* device);
michael@0 883 void process(const RawEvent* rawEvent);
michael@0 884 void finishSync();
michael@0 885 bool hasStylus() const;
michael@0 886
michael@0 887 inline size_t getSlotCount() const { return mSlotCount; }
michael@0 888 inline const Slot* getSlot(size_t index) const { return &mSlots[index]; }
michael@0 889
michael@0 890 private:
michael@0 891 int32_t mCurrentSlot;
michael@0 892 Slot* mSlots;
michael@0 893 size_t mSlotCount;
michael@0 894 bool mUsingSlotsProtocol;
michael@0 895 bool mHaveStylus;
michael@0 896
michael@0 897 void clearSlots(int32_t initialSlot);
michael@0 898 };
michael@0 899
michael@0 900
michael@0 901 /* An input mapper transforms raw input events into cooked event data.
michael@0 902 * A single input device can have multiple associated input mappers in order to interpret
michael@0 903 * different classes of events.
michael@0 904 *
michael@0 905 * InputMapper lifecycle:
michael@0 906 * - create
michael@0 907 * - configure with 0 changes
michael@0 908 * - reset
michael@0 909 * - process, process, process (may occasionally reconfigure with non-zero changes or reset)
michael@0 910 * - reset
michael@0 911 * - destroy
michael@0 912 */
michael@0 913 class InputMapper {
michael@0 914 public:
michael@0 915 InputMapper(InputDevice* device);
michael@0 916 virtual ~InputMapper();
michael@0 917
michael@0 918 inline InputDevice* getDevice() { return mDevice; }
michael@0 919 inline int32_t getDeviceId() { return mDevice->getId(); }
michael@0 920 inline const String8 getDeviceName() { return mDevice->getName(); }
michael@0 921 inline InputReaderContext* getContext() { return mContext; }
michael@0 922 inline InputReaderPolicyInterface* getPolicy() { return mContext->getPolicy(); }
michael@0 923 inline InputListenerInterface* getListener() { return mContext->getListener(); }
michael@0 924 inline EventHubInterface* getEventHub() { return mContext->getEventHub(); }
michael@0 925
michael@0 926 virtual uint32_t getSources() = 0;
michael@0 927 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
michael@0 928 virtual void dump(String8& dump);
michael@0 929 virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
michael@0 930 virtual void reset(nsecs_t when);
michael@0 931 virtual void process(const RawEvent* rawEvent) = 0;
michael@0 932 virtual void timeoutExpired(nsecs_t when);
michael@0 933
michael@0 934 virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
michael@0 935 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
michael@0 936 virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
michael@0 937 virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
michael@0 938 const int32_t* keyCodes, uint8_t* outFlags);
michael@0 939 virtual void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat,
michael@0 940 int32_t token);
michael@0 941 virtual void cancelVibrate(int32_t token);
michael@0 942
michael@0 943 virtual int32_t getMetaState();
michael@0 944
michael@0 945 virtual void fadePointer();
michael@0 946
michael@0 947 protected:
michael@0 948 InputDevice* mDevice;
michael@0 949 InputReaderContext* mContext;
michael@0 950
michael@0 951 status_t getAbsoluteAxisInfo(int32_t axis, RawAbsoluteAxisInfo* axisInfo);
michael@0 952 void bumpGeneration();
michael@0 953
michael@0 954 static void dumpRawAbsoluteAxisInfo(String8& dump,
michael@0 955 const RawAbsoluteAxisInfo& axis, const char* name);
michael@0 956 };
michael@0 957
michael@0 958
michael@0 959 class SwitchInputMapper : public InputMapper {
michael@0 960 public:
michael@0 961 SwitchInputMapper(InputDevice* device);
michael@0 962 virtual ~SwitchInputMapper();
michael@0 963
michael@0 964 virtual uint32_t getSources();
michael@0 965 virtual void process(const RawEvent* rawEvent);
michael@0 966
michael@0 967 virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
michael@0 968
michael@0 969 private:
michael@0 970 uint32_t mUpdatedSwitchValues;
michael@0 971 uint32_t mUpdatedSwitchMask;
michael@0 972
michael@0 973 void processSwitch(int32_t switchCode, int32_t switchValue);
michael@0 974 void sync(nsecs_t when);
michael@0 975 };
michael@0 976
michael@0 977
michael@0 978 class VibratorInputMapper : public InputMapper {
michael@0 979 public:
michael@0 980 VibratorInputMapper(InputDevice* device);
michael@0 981 virtual ~VibratorInputMapper();
michael@0 982
michael@0 983 virtual uint32_t getSources();
michael@0 984 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
michael@0 985 virtual void process(const RawEvent* rawEvent);
michael@0 986
michael@0 987 virtual void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat,
michael@0 988 int32_t token);
michael@0 989 virtual void cancelVibrate(int32_t token);
michael@0 990 virtual void timeoutExpired(nsecs_t when);
michael@0 991 virtual void dump(String8& dump);
michael@0 992
michael@0 993 private:
michael@0 994 bool mVibrating;
michael@0 995 nsecs_t mPattern[MAX_VIBRATE_PATTERN_SIZE];
michael@0 996 size_t mPatternSize;
michael@0 997 ssize_t mRepeat;
michael@0 998 int32_t mToken;
michael@0 999 ssize_t mIndex;
michael@0 1000 nsecs_t mNextStepTime;
michael@0 1001
michael@0 1002 void nextStep();
michael@0 1003 void stopVibrating();
michael@0 1004 };
michael@0 1005
michael@0 1006
michael@0 1007 class KeyboardInputMapper : public InputMapper {
michael@0 1008 public:
michael@0 1009 KeyboardInputMapper(InputDevice* device, uint32_t source, int32_t keyboardType);
michael@0 1010 virtual ~KeyboardInputMapper();
michael@0 1011
michael@0 1012 virtual uint32_t getSources();
michael@0 1013 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
michael@0 1014 virtual void dump(String8& dump);
michael@0 1015 virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
michael@0 1016 virtual void reset(nsecs_t when);
michael@0 1017 virtual void process(const RawEvent* rawEvent);
michael@0 1018
michael@0 1019 virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
michael@0 1020 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
michael@0 1021 virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
michael@0 1022 const int32_t* keyCodes, uint8_t* outFlags);
michael@0 1023
michael@0 1024 virtual int32_t getMetaState();
michael@0 1025
michael@0 1026 private:
michael@0 1027 struct KeyDown {
michael@0 1028 int32_t keyCode;
michael@0 1029 int32_t scanCode;
michael@0 1030 };
michael@0 1031
michael@0 1032 uint32_t mSource;
michael@0 1033 int32_t mKeyboardType;
michael@0 1034
michael@0 1035 int32_t mOrientation; // orientation for dpad keys
michael@0 1036
michael@0 1037 Vector<KeyDown> mKeyDowns; // keys that are down
michael@0 1038 int32_t mMetaState;
michael@0 1039 nsecs_t mDownTime; // time of most recent key down
michael@0 1040
michael@0 1041 int32_t mCurrentHidUsage; // most recent HID usage seen this packet, or 0 if none
michael@0 1042
michael@0 1043 struct LedState {
michael@0 1044 bool avail; // led is available
michael@0 1045 bool on; // we think the led is currently on
michael@0 1046 };
michael@0 1047 LedState mCapsLockLedState;
michael@0 1048 LedState mNumLockLedState;
michael@0 1049 LedState mScrollLockLedState;
michael@0 1050
michael@0 1051 // Immutable configuration parameters.
michael@0 1052 struct Parameters {
michael@0 1053 bool hasAssociatedDisplay;
michael@0 1054 bool orientationAware;
michael@0 1055 } mParameters;
michael@0 1056
michael@0 1057 void configureParameters();
michael@0 1058 void dumpParameters(String8& dump);
michael@0 1059
michael@0 1060 bool isKeyboardOrGamepadKey(int32_t scanCode);
michael@0 1061
michael@0 1062 void processKey(nsecs_t when, bool down, int32_t keyCode, int32_t scanCode,
michael@0 1063 uint32_t policyFlags);
michael@0 1064
michael@0 1065 ssize_t findKeyDown(int32_t scanCode);
michael@0 1066
michael@0 1067 void resetLedState();
michael@0 1068 void initializeLedState(LedState& ledState, int32_t led);
michael@0 1069 void updateLedState(bool reset);
michael@0 1070 void updateLedStateForModifier(LedState& ledState, int32_t led,
michael@0 1071 int32_t modifier, bool reset);
michael@0 1072 };
michael@0 1073
michael@0 1074
michael@0 1075 class CursorInputMapper : public InputMapper {
michael@0 1076 public:
michael@0 1077 CursorInputMapper(InputDevice* device);
michael@0 1078 virtual ~CursorInputMapper();
michael@0 1079
michael@0 1080 virtual uint32_t getSources();
michael@0 1081 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
michael@0 1082 virtual void dump(String8& dump);
michael@0 1083 virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
michael@0 1084 virtual void reset(nsecs_t when);
michael@0 1085 virtual void process(const RawEvent* rawEvent);
michael@0 1086
michael@0 1087 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
michael@0 1088
michael@0 1089 virtual void fadePointer();
michael@0 1090
michael@0 1091 private:
michael@0 1092 // Amount that trackball needs to move in order to generate a key event.
michael@0 1093 static const int32_t TRACKBALL_MOVEMENT_THRESHOLD = 6;
michael@0 1094
michael@0 1095 // Immutable configuration parameters.
michael@0 1096 struct Parameters {
michael@0 1097 enum Mode {
michael@0 1098 MODE_POINTER,
michael@0 1099 MODE_NAVIGATION,
michael@0 1100 };
michael@0 1101
michael@0 1102 Mode mode;
michael@0 1103 bool hasAssociatedDisplay;
michael@0 1104 bool orientationAware;
michael@0 1105 } mParameters;
michael@0 1106
michael@0 1107 CursorButtonAccumulator mCursorButtonAccumulator;
michael@0 1108 CursorMotionAccumulator mCursorMotionAccumulator;
michael@0 1109 CursorScrollAccumulator mCursorScrollAccumulator;
michael@0 1110
michael@0 1111 int32_t mSource;
michael@0 1112 float mXScale;
michael@0 1113 float mYScale;
michael@0 1114 float mXPrecision;
michael@0 1115 float mYPrecision;
michael@0 1116
michael@0 1117 float mVWheelScale;
michael@0 1118 float mHWheelScale;
michael@0 1119
michael@0 1120 // Velocity controls for mouse pointer and wheel movements.
michael@0 1121 // The controls for X and Y wheel movements are separate to keep them decoupled.
michael@0 1122 VelocityControl mPointerVelocityControl;
michael@0 1123 VelocityControl mWheelXVelocityControl;
michael@0 1124 VelocityControl mWheelYVelocityControl;
michael@0 1125
michael@0 1126 int32_t mOrientation;
michael@0 1127
michael@0 1128 sp<PointerControllerInterface> mPointerController;
michael@0 1129
michael@0 1130 int32_t mButtonState;
michael@0 1131 nsecs_t mDownTime;
michael@0 1132
michael@0 1133 void configureParameters();
michael@0 1134 void dumpParameters(String8& dump);
michael@0 1135
michael@0 1136 void sync(nsecs_t when);
michael@0 1137 };
michael@0 1138
michael@0 1139
michael@0 1140 class TouchInputMapper : public InputMapper {
michael@0 1141 public:
michael@0 1142 TouchInputMapper(InputDevice* device);
michael@0 1143 virtual ~TouchInputMapper();
michael@0 1144
michael@0 1145 virtual uint32_t getSources();
michael@0 1146 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
michael@0 1147 virtual void dump(String8& dump);
michael@0 1148 virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
michael@0 1149 virtual void reset(nsecs_t when);
michael@0 1150 virtual void process(const RawEvent* rawEvent);
michael@0 1151
michael@0 1152 virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
michael@0 1153 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
michael@0 1154 virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
michael@0 1155 const int32_t* keyCodes, uint8_t* outFlags);
michael@0 1156
michael@0 1157 virtual void fadePointer();
michael@0 1158 virtual void timeoutExpired(nsecs_t when);
michael@0 1159
michael@0 1160 protected:
michael@0 1161 CursorButtonAccumulator mCursorButtonAccumulator;
michael@0 1162 CursorScrollAccumulator mCursorScrollAccumulator;
michael@0 1163 TouchButtonAccumulator mTouchButtonAccumulator;
michael@0 1164
michael@0 1165 struct VirtualKey {
michael@0 1166 int32_t keyCode;
michael@0 1167 int32_t scanCode;
michael@0 1168 uint32_t flags;
michael@0 1169
michael@0 1170 // computed hit box, specified in touch screen coords based on known display size
michael@0 1171 int32_t hitLeft;
michael@0 1172 int32_t hitTop;
michael@0 1173 int32_t hitRight;
michael@0 1174 int32_t hitBottom;
michael@0 1175
michael@0 1176 inline bool isHit(int32_t x, int32_t y) const {
michael@0 1177 return x >= hitLeft && x <= hitRight && y >= hitTop && y <= hitBottom;
michael@0 1178 }
michael@0 1179 };
michael@0 1180
michael@0 1181 // Input sources and device mode.
michael@0 1182 uint32_t mSource;
michael@0 1183
michael@0 1184 enum DeviceMode {
michael@0 1185 DEVICE_MODE_DISABLED, // input is disabled
michael@0 1186 DEVICE_MODE_DIRECT, // direct mapping (touchscreen)
michael@0 1187 DEVICE_MODE_UNSCALED, // unscaled mapping (touchpad)
michael@0 1188 DEVICE_MODE_NAVIGATION, // unscaled mapping with assist gesture (touch navigation)
michael@0 1189 DEVICE_MODE_POINTER, // pointer mapping (pointer)
michael@0 1190 };
michael@0 1191 DeviceMode mDeviceMode;
michael@0 1192
michael@0 1193 // The reader's configuration.
michael@0 1194 InputReaderConfiguration mConfig;
michael@0 1195
michael@0 1196 // Immutable configuration parameters.
michael@0 1197 struct Parameters {
michael@0 1198 enum DeviceType {
michael@0 1199 DEVICE_TYPE_TOUCH_SCREEN,
michael@0 1200 DEVICE_TYPE_TOUCH_PAD,
michael@0 1201 DEVICE_TYPE_TOUCH_NAVIGATION,
michael@0 1202 DEVICE_TYPE_POINTER,
michael@0 1203 };
michael@0 1204
michael@0 1205 DeviceType deviceType;
michael@0 1206 bool hasAssociatedDisplay;
michael@0 1207 bool associatedDisplayIsExternal;
michael@0 1208 bool orientationAware;
michael@0 1209
michael@0 1210 enum GestureMode {
michael@0 1211 GESTURE_MODE_POINTER,
michael@0 1212 GESTURE_MODE_SPOTS,
michael@0 1213 };
michael@0 1214 GestureMode gestureMode;
michael@0 1215 } mParameters;
michael@0 1216
michael@0 1217 // Immutable calibration parameters in parsed form.
michael@0 1218 struct Calibration {
michael@0 1219 // Size
michael@0 1220 enum SizeCalibration {
michael@0 1221 SIZE_CALIBRATION_DEFAULT,
michael@0 1222 SIZE_CALIBRATION_NONE,
michael@0 1223 SIZE_CALIBRATION_GEOMETRIC,
michael@0 1224 SIZE_CALIBRATION_DIAMETER,
michael@0 1225 SIZE_CALIBRATION_BOX,
michael@0 1226 SIZE_CALIBRATION_AREA,
michael@0 1227 };
michael@0 1228
michael@0 1229 SizeCalibration sizeCalibration;
michael@0 1230
michael@0 1231 bool haveSizeScale;
michael@0 1232 float sizeScale;
michael@0 1233 bool haveSizeBias;
michael@0 1234 float sizeBias;
michael@0 1235 bool haveSizeIsSummed;
michael@0 1236 bool sizeIsSummed;
michael@0 1237
michael@0 1238 // Pressure
michael@0 1239 enum PressureCalibration {
michael@0 1240 PRESSURE_CALIBRATION_DEFAULT,
michael@0 1241 PRESSURE_CALIBRATION_NONE,
michael@0 1242 PRESSURE_CALIBRATION_PHYSICAL,
michael@0 1243 PRESSURE_CALIBRATION_AMPLITUDE,
michael@0 1244 };
michael@0 1245
michael@0 1246 PressureCalibration pressureCalibration;
michael@0 1247 bool havePressureScale;
michael@0 1248 float pressureScale;
michael@0 1249
michael@0 1250 // Orientation
michael@0 1251 enum OrientationCalibration {
michael@0 1252 ORIENTATION_CALIBRATION_DEFAULT,
michael@0 1253 ORIENTATION_CALIBRATION_NONE,
michael@0 1254 ORIENTATION_CALIBRATION_INTERPOLATED,
michael@0 1255 ORIENTATION_CALIBRATION_VECTOR,
michael@0 1256 };
michael@0 1257
michael@0 1258 OrientationCalibration orientationCalibration;
michael@0 1259
michael@0 1260 // Distance
michael@0 1261 enum DistanceCalibration {
michael@0 1262 DISTANCE_CALIBRATION_DEFAULT,
michael@0 1263 DISTANCE_CALIBRATION_NONE,
michael@0 1264 DISTANCE_CALIBRATION_SCALED,
michael@0 1265 };
michael@0 1266
michael@0 1267 DistanceCalibration distanceCalibration;
michael@0 1268 bool haveDistanceScale;
michael@0 1269 float distanceScale;
michael@0 1270
michael@0 1271 enum CoverageCalibration {
michael@0 1272 COVERAGE_CALIBRATION_DEFAULT,
michael@0 1273 COVERAGE_CALIBRATION_NONE,
michael@0 1274 COVERAGE_CALIBRATION_BOX,
michael@0 1275 };
michael@0 1276
michael@0 1277 CoverageCalibration coverageCalibration;
michael@0 1278
michael@0 1279 inline void applySizeScaleAndBias(float* outSize) const {
michael@0 1280 if (haveSizeScale) {
michael@0 1281 *outSize *= sizeScale;
michael@0 1282 }
michael@0 1283 if (haveSizeBias) {
michael@0 1284 *outSize += sizeBias;
michael@0 1285 }
michael@0 1286 }
michael@0 1287 } mCalibration;
michael@0 1288
michael@0 1289 // Raw pointer axis information from the driver.
michael@0 1290 RawPointerAxes mRawPointerAxes;
michael@0 1291
michael@0 1292 // Raw pointer sample data.
michael@0 1293 RawPointerData mCurrentRawPointerData;
michael@0 1294 RawPointerData mLastRawPointerData;
michael@0 1295
michael@0 1296 // Cooked pointer sample data.
michael@0 1297 CookedPointerData mCurrentCookedPointerData;
michael@0 1298 CookedPointerData mLastCookedPointerData;
michael@0 1299
michael@0 1300 // Button state.
michael@0 1301 int32_t mCurrentButtonState;
michael@0 1302 int32_t mLastButtonState;
michael@0 1303
michael@0 1304 // Scroll state.
michael@0 1305 int32_t mCurrentRawVScroll;
michael@0 1306 int32_t mCurrentRawHScroll;
michael@0 1307
michael@0 1308 // Id bits used to differentiate fingers, stylus and mouse tools.
michael@0 1309 BitSet32 mCurrentFingerIdBits; // finger or unknown
michael@0 1310 BitSet32 mLastFingerIdBits;
michael@0 1311 BitSet32 mCurrentStylusIdBits; // stylus or eraser
michael@0 1312 BitSet32 mLastStylusIdBits;
michael@0 1313 BitSet32 mCurrentMouseIdBits; // mouse or lens
michael@0 1314 BitSet32 mLastMouseIdBits;
michael@0 1315
michael@0 1316 // True if we sent a HOVER_ENTER event.
michael@0 1317 bool mSentHoverEnter;
michael@0 1318
michael@0 1319 // The time the primary pointer last went down.
michael@0 1320 nsecs_t mDownTime;
michael@0 1321
michael@0 1322 // The pointer controller, or null if the device is not a pointer.
michael@0 1323 sp<PointerControllerInterface> mPointerController;
michael@0 1324
michael@0 1325 Vector<VirtualKey> mVirtualKeys;
michael@0 1326
michael@0 1327 virtual void configureParameters();
michael@0 1328 virtual void dumpParameters(String8& dump);
michael@0 1329 virtual void configureRawPointerAxes();
michael@0 1330 virtual void dumpRawPointerAxes(String8& dump);
michael@0 1331 virtual void configureSurface(nsecs_t when, bool* outResetNeeded);
michael@0 1332 virtual void dumpSurface(String8& dump);
michael@0 1333 virtual void configureVirtualKeys();
michael@0 1334 virtual void dumpVirtualKeys(String8& dump);
michael@0 1335 virtual void parseCalibration();
michael@0 1336 virtual void resolveCalibration();
michael@0 1337 virtual void dumpCalibration(String8& dump);
michael@0 1338 virtual bool hasStylus() const = 0;
michael@0 1339
michael@0 1340 virtual void syncTouch(nsecs_t when, bool* outHavePointerIds) = 0;
michael@0 1341
michael@0 1342 private:
michael@0 1343 // The current viewport.
michael@0 1344 // The components of the viewport are specified in the display's rotated orientation.
michael@0 1345 DisplayViewport mViewport;
michael@0 1346
michael@0 1347 // The surface orientation, width and height set by configureSurface().
michael@0 1348 // The width and height are derived from the viewport but are specified
michael@0 1349 // in the natural orientation.
michael@0 1350 // The surface origin specifies how the surface coordinates should be translated
michael@0 1351 // to align with the logical display coordinate space.
michael@0 1352 // The orientation may be different from the viewport orientation as it specifies
michael@0 1353 // the rotation of the surface coordinates required to produce the viewport's
michael@0 1354 // requested orientation, so it will depend on whether the device is orientation aware.
michael@0 1355 int32_t mSurfaceWidth;
michael@0 1356 int32_t mSurfaceHeight;
michael@0 1357 int32_t mSurfaceLeft;
michael@0 1358 int32_t mSurfaceTop;
michael@0 1359 int32_t mSurfaceOrientation;
michael@0 1360
michael@0 1361 // Translation and scaling factors, orientation-independent.
michael@0 1362 float mXTranslate;
michael@0 1363 float mXScale;
michael@0 1364 float mXPrecision;
michael@0 1365
michael@0 1366 float mYTranslate;
michael@0 1367 float mYScale;
michael@0 1368 float mYPrecision;
michael@0 1369
michael@0 1370 float mGeometricScale;
michael@0 1371
michael@0 1372 float mPressureScale;
michael@0 1373
michael@0 1374 float mSizeScale;
michael@0 1375
michael@0 1376 float mOrientationScale;
michael@0 1377
michael@0 1378 float mDistanceScale;
michael@0 1379
michael@0 1380 bool mHaveTilt;
michael@0 1381 float mTiltXCenter;
michael@0 1382 float mTiltXScale;
michael@0 1383 float mTiltYCenter;
michael@0 1384 float mTiltYScale;
michael@0 1385
michael@0 1386 // Oriented motion ranges for input device info.
michael@0 1387 struct OrientedRanges {
michael@0 1388 InputDeviceInfo::MotionRange x;
michael@0 1389 InputDeviceInfo::MotionRange y;
michael@0 1390 InputDeviceInfo::MotionRange pressure;
michael@0 1391
michael@0 1392 bool haveSize;
michael@0 1393 InputDeviceInfo::MotionRange size;
michael@0 1394
michael@0 1395 bool haveTouchSize;
michael@0 1396 InputDeviceInfo::MotionRange touchMajor;
michael@0 1397 InputDeviceInfo::MotionRange touchMinor;
michael@0 1398
michael@0 1399 bool haveToolSize;
michael@0 1400 InputDeviceInfo::MotionRange toolMajor;
michael@0 1401 InputDeviceInfo::MotionRange toolMinor;
michael@0 1402
michael@0 1403 bool haveOrientation;
michael@0 1404 InputDeviceInfo::MotionRange orientation;
michael@0 1405
michael@0 1406 bool haveDistance;
michael@0 1407 InputDeviceInfo::MotionRange distance;
michael@0 1408
michael@0 1409 bool haveTilt;
michael@0 1410 InputDeviceInfo::MotionRange tilt;
michael@0 1411
michael@0 1412 OrientedRanges() {
michael@0 1413 clear();
michael@0 1414 }
michael@0 1415
michael@0 1416 void clear() {
michael@0 1417 haveSize = false;
michael@0 1418 haveTouchSize = false;
michael@0 1419 haveToolSize = false;
michael@0 1420 haveOrientation = false;
michael@0 1421 haveDistance = false;
michael@0 1422 haveTilt = false;
michael@0 1423 }
michael@0 1424 } mOrientedRanges;
michael@0 1425
michael@0 1426 // Oriented dimensions and precision.
michael@0 1427 float mOrientedXPrecision;
michael@0 1428 float mOrientedYPrecision;
michael@0 1429
michael@0 1430 struct CurrentVirtualKeyState {
michael@0 1431 bool down;
michael@0 1432 bool ignored;
michael@0 1433 nsecs_t downTime;
michael@0 1434 int32_t keyCode;
michael@0 1435 int32_t scanCode;
michael@0 1436 } mCurrentVirtualKey;
michael@0 1437
michael@0 1438 // Scale factor for gesture or mouse based pointer movements.
michael@0 1439 float mPointerXMovementScale;
michael@0 1440 float mPointerYMovementScale;
michael@0 1441
michael@0 1442 // Scale factor for gesture based zooming and other freeform motions.
michael@0 1443 float mPointerXZoomScale;
michael@0 1444 float mPointerYZoomScale;
michael@0 1445
michael@0 1446 // The maximum swipe width.
michael@0 1447 float mPointerGestureMaxSwipeWidth;
michael@0 1448
michael@0 1449 struct PointerDistanceHeapElement {
michael@0 1450 uint32_t currentPointerIndex : 8;
michael@0 1451 uint32_t lastPointerIndex : 8;
michael@0 1452 uint64_t distance : 48; // squared distance
michael@0 1453 };
michael@0 1454
michael@0 1455 enum PointerUsage {
michael@0 1456 POINTER_USAGE_NONE,
michael@0 1457 POINTER_USAGE_GESTURES,
michael@0 1458 POINTER_USAGE_STYLUS,
michael@0 1459 POINTER_USAGE_MOUSE,
michael@0 1460 };
michael@0 1461 PointerUsage mPointerUsage;
michael@0 1462
michael@0 1463 struct PointerGesture {
michael@0 1464 enum Mode {
michael@0 1465 // No fingers, button is not pressed.
michael@0 1466 // Nothing happening.
michael@0 1467 NEUTRAL,
michael@0 1468
michael@0 1469 // No fingers, button is not pressed.
michael@0 1470 // Tap detected.
michael@0 1471 // Emits DOWN and UP events at the pointer location.
michael@0 1472 TAP,
michael@0 1473
michael@0 1474 // Exactly one finger dragging following a tap.
michael@0 1475 // Pointer follows the active finger.
michael@0 1476 // Emits DOWN, MOVE and UP events at the pointer location.
michael@0 1477 //
michael@0 1478 // Detect double-taps when the finger goes up while in TAP_DRAG mode.
michael@0 1479 TAP_DRAG,
michael@0 1480
michael@0 1481 // Button is pressed.
michael@0 1482 // Pointer follows the active finger if there is one. Other fingers are ignored.
michael@0 1483 // Emits DOWN, MOVE and UP events at the pointer location.
michael@0 1484 BUTTON_CLICK_OR_DRAG,
michael@0 1485
michael@0 1486 // Exactly one finger, button is not pressed.
michael@0 1487 // Pointer follows the active finger.
michael@0 1488 // Emits HOVER_MOVE events at the pointer location.
michael@0 1489 //
michael@0 1490 // Detect taps when the finger goes up while in HOVER mode.
michael@0 1491 HOVER,
michael@0 1492
michael@0 1493 // Exactly two fingers but neither have moved enough to clearly indicate
michael@0 1494 // whether a swipe or freeform gesture was intended. We consider the
michael@0 1495 // pointer to be pressed so this enables clicking or long-pressing on buttons.
michael@0 1496 // Pointer does not move.
michael@0 1497 // Emits DOWN, MOVE and UP events with a single stationary pointer coordinate.
michael@0 1498 PRESS,
michael@0 1499
michael@0 1500 // Exactly two fingers moving in the same direction, button is not pressed.
michael@0 1501 // Pointer does not move.
michael@0 1502 // Emits DOWN, MOVE and UP events with a single pointer coordinate that
michael@0 1503 // follows the midpoint between both fingers.
michael@0 1504 SWIPE,
michael@0 1505
michael@0 1506 // Two or more fingers moving in arbitrary directions, button is not pressed.
michael@0 1507 // Pointer does not move.
michael@0 1508 // Emits DOWN, POINTER_DOWN, MOVE, POINTER_UP and UP events that follow
michael@0 1509 // each finger individually relative to the initial centroid of the finger.
michael@0 1510 FREEFORM,
michael@0 1511
michael@0 1512 // Waiting for quiet time to end before starting the next gesture.
michael@0 1513 QUIET,
michael@0 1514 };
michael@0 1515
michael@0 1516 // Time the first finger went down.
michael@0 1517 nsecs_t firstTouchTime;
michael@0 1518
michael@0 1519 // The active pointer id from the raw touch data.
michael@0 1520 int32_t activeTouchId; // -1 if none
michael@0 1521
michael@0 1522 // The active pointer id from the gesture last delivered to the application.
michael@0 1523 int32_t activeGestureId; // -1 if none
michael@0 1524
michael@0 1525 // Pointer coords and ids for the current and previous pointer gesture.
michael@0 1526 Mode currentGestureMode;
michael@0 1527 BitSet32 currentGestureIdBits;
michael@0 1528 uint32_t currentGestureIdToIndex[MAX_POINTER_ID + 1];
michael@0 1529 PointerProperties currentGestureProperties[MAX_POINTERS];
michael@0 1530 PointerCoords currentGestureCoords[MAX_POINTERS];
michael@0 1531
michael@0 1532 Mode lastGestureMode;
michael@0 1533 BitSet32 lastGestureIdBits;
michael@0 1534 uint32_t lastGestureIdToIndex[MAX_POINTER_ID + 1];
michael@0 1535 PointerProperties lastGestureProperties[MAX_POINTERS];
michael@0 1536 PointerCoords lastGestureCoords[MAX_POINTERS];
michael@0 1537
michael@0 1538 // Time the pointer gesture last went down.
michael@0 1539 nsecs_t downTime;
michael@0 1540
michael@0 1541 // Time when the pointer went down for a TAP.
michael@0 1542 nsecs_t tapDownTime;
michael@0 1543
michael@0 1544 // Time when the pointer went up for a TAP.
michael@0 1545 nsecs_t tapUpTime;
michael@0 1546
michael@0 1547 // Location of initial tap.
michael@0 1548 float tapX, tapY;
michael@0 1549
michael@0 1550 // Time we started waiting for quiescence.
michael@0 1551 nsecs_t quietTime;
michael@0 1552
michael@0 1553 // Reference points for multitouch gestures.
michael@0 1554 float referenceTouchX; // reference touch X/Y coordinates in surface units
michael@0 1555 float referenceTouchY;
michael@0 1556 float referenceGestureX; // reference gesture X/Y coordinates in pixels
michael@0 1557 float referenceGestureY;
michael@0 1558
michael@0 1559 // Distance that each pointer has traveled which has not yet been
michael@0 1560 // subsumed into the reference gesture position.
michael@0 1561 BitSet32 referenceIdBits;
michael@0 1562 struct Delta {
michael@0 1563 float dx, dy;
michael@0 1564 };
michael@0 1565 Delta referenceDeltas[MAX_POINTER_ID + 1];
michael@0 1566
michael@0 1567 // Describes how touch ids are mapped to gesture ids for freeform gestures.
michael@0 1568 uint32_t freeformTouchToGestureIdMap[MAX_POINTER_ID + 1];
michael@0 1569
michael@0 1570 // A velocity tracker for determining whether to switch active pointers during drags.
michael@0 1571 VelocityTracker velocityTracker;
michael@0 1572
michael@0 1573 void reset() {
michael@0 1574 firstTouchTime = LLONG_MIN;
michael@0 1575 activeTouchId = -1;
michael@0 1576 activeGestureId = -1;
michael@0 1577 currentGestureMode = NEUTRAL;
michael@0 1578 currentGestureIdBits.clear();
michael@0 1579 lastGestureMode = NEUTRAL;
michael@0 1580 lastGestureIdBits.clear();
michael@0 1581 downTime = 0;
michael@0 1582 velocityTracker.clear();
michael@0 1583 resetTap();
michael@0 1584 resetQuietTime();
michael@0 1585 }
michael@0 1586
michael@0 1587 void resetTap() {
michael@0 1588 tapDownTime = LLONG_MIN;
michael@0 1589 tapUpTime = LLONG_MIN;
michael@0 1590 }
michael@0 1591
michael@0 1592 void resetQuietTime() {
michael@0 1593 quietTime = LLONG_MIN;
michael@0 1594 }
michael@0 1595 } mPointerGesture;
michael@0 1596
michael@0 1597 struct PointerSimple {
michael@0 1598 PointerCoords currentCoords;
michael@0 1599 PointerProperties currentProperties;
michael@0 1600 PointerCoords lastCoords;
michael@0 1601 PointerProperties lastProperties;
michael@0 1602
michael@0 1603 // True if the pointer is down.
michael@0 1604 bool down;
michael@0 1605
michael@0 1606 // True if the pointer is hovering.
michael@0 1607 bool hovering;
michael@0 1608
michael@0 1609 // Time the pointer last went down.
michael@0 1610 nsecs_t downTime;
michael@0 1611
michael@0 1612 void reset() {
michael@0 1613 currentCoords.clear();
michael@0 1614 currentProperties.clear();
michael@0 1615 lastCoords.clear();
michael@0 1616 lastProperties.clear();
michael@0 1617 down = false;
michael@0 1618 hovering = false;
michael@0 1619 downTime = 0;
michael@0 1620 }
michael@0 1621 } mPointerSimple;
michael@0 1622
michael@0 1623 // The pointer and scroll velocity controls.
michael@0 1624 VelocityControl mPointerVelocityControl;
michael@0 1625 VelocityControl mWheelXVelocityControl;
michael@0 1626 VelocityControl mWheelYVelocityControl;
michael@0 1627
michael@0 1628 void sync(nsecs_t when);
michael@0 1629
michael@0 1630 bool consumeRawTouches(nsecs_t when, uint32_t policyFlags);
michael@0 1631 void dispatchVirtualKey(nsecs_t when, uint32_t policyFlags,
michael@0 1632 int32_t keyEventAction, int32_t keyEventFlags);
michael@0 1633
michael@0 1634 void dispatchTouches(nsecs_t when, uint32_t policyFlags);
michael@0 1635 void dispatchHoverExit(nsecs_t when, uint32_t policyFlags);
michael@0 1636 void dispatchHoverEnterAndMove(nsecs_t when, uint32_t policyFlags);
michael@0 1637 void cookPointerData();
michael@0 1638
michael@0 1639 void dispatchPointerUsage(nsecs_t when, uint32_t policyFlags, PointerUsage pointerUsage);
michael@0 1640 void abortPointerUsage(nsecs_t when, uint32_t policyFlags);
michael@0 1641
michael@0 1642 void dispatchPointerGestures(nsecs_t when, uint32_t policyFlags, bool isTimeout);
michael@0 1643 void abortPointerGestures(nsecs_t when, uint32_t policyFlags);
michael@0 1644 bool preparePointerGestures(nsecs_t when,
michael@0 1645 bool* outCancelPreviousGesture, bool* outFinishPreviousGesture,
michael@0 1646 bool isTimeout);
michael@0 1647
michael@0 1648 void dispatchPointerStylus(nsecs_t when, uint32_t policyFlags);
michael@0 1649 void abortPointerStylus(nsecs_t when, uint32_t policyFlags);
michael@0 1650
michael@0 1651 void dispatchPointerMouse(nsecs_t when, uint32_t policyFlags);
michael@0 1652 void abortPointerMouse(nsecs_t when, uint32_t policyFlags);
michael@0 1653
michael@0 1654 void dispatchPointerSimple(nsecs_t when, uint32_t policyFlags,
michael@0 1655 bool down, bool hovering);
michael@0 1656 void abortPointerSimple(nsecs_t when, uint32_t policyFlags);
michael@0 1657
michael@0 1658 // Dispatches a motion event.
michael@0 1659 // If the changedId is >= 0 and the action is POINTER_DOWN or POINTER_UP, the
michael@0 1660 // method will take care of setting the index and transmuting the action to DOWN or UP
michael@0 1661 // it is the first / last pointer to go down / up.
michael@0 1662 void dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32_t source,
michael@0 1663 int32_t action, int32_t flags, int32_t metaState, int32_t buttonState,
michael@0 1664 int32_t edgeFlags,
michael@0 1665 const PointerProperties* properties, const PointerCoords* coords,
michael@0 1666 const uint32_t* idToIndex, BitSet32 idBits,
michael@0 1667 int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime);
michael@0 1668
michael@0 1669 // Updates pointer coords and properties for pointers with specified ids that have moved.
michael@0 1670 // Returns true if any of them changed.
michael@0 1671 bool updateMovedPointers(const PointerProperties* inProperties,
michael@0 1672 const PointerCoords* inCoords, const uint32_t* inIdToIndex,
michael@0 1673 PointerProperties* outProperties, PointerCoords* outCoords,
michael@0 1674 const uint32_t* outIdToIndex, BitSet32 idBits) const;
michael@0 1675
michael@0 1676 bool isPointInsideSurface(int32_t x, int32_t y);
michael@0 1677 const VirtualKey* findVirtualKeyHit(int32_t x, int32_t y);
michael@0 1678
michael@0 1679 void assignPointerIds();
michael@0 1680 };
michael@0 1681
michael@0 1682
michael@0 1683 class SingleTouchInputMapper : public TouchInputMapper {
michael@0 1684 public:
michael@0 1685 SingleTouchInputMapper(InputDevice* device);
michael@0 1686 virtual ~SingleTouchInputMapper();
michael@0 1687
michael@0 1688 virtual void reset(nsecs_t when);
michael@0 1689 virtual void process(const RawEvent* rawEvent);
michael@0 1690
michael@0 1691 protected:
michael@0 1692 virtual void syncTouch(nsecs_t when, bool* outHavePointerIds);
michael@0 1693 virtual void configureRawPointerAxes();
michael@0 1694 virtual bool hasStylus() const;
michael@0 1695
michael@0 1696 private:
michael@0 1697 SingleTouchMotionAccumulator mSingleTouchMotionAccumulator;
michael@0 1698 };
michael@0 1699
michael@0 1700
michael@0 1701 class MultiTouchInputMapper : public TouchInputMapper {
michael@0 1702 public:
michael@0 1703 MultiTouchInputMapper(InputDevice* device);
michael@0 1704 virtual ~MultiTouchInputMapper();
michael@0 1705
michael@0 1706 virtual void reset(nsecs_t when);
michael@0 1707 virtual void process(const RawEvent* rawEvent);
michael@0 1708
michael@0 1709 protected:
michael@0 1710 virtual void syncTouch(nsecs_t when, bool* outHavePointerIds);
michael@0 1711 virtual void configureRawPointerAxes();
michael@0 1712 virtual bool hasStylus() const;
michael@0 1713
michael@0 1714 private:
michael@0 1715 MultiTouchMotionAccumulator mMultiTouchMotionAccumulator;
michael@0 1716
michael@0 1717 // Specifies the pointer id bits that are in use, and their associated tracking id.
michael@0 1718 BitSet32 mPointerIdBits;
michael@0 1719 int32_t mPointerTrackingIdMap[MAX_POINTER_ID + 1];
michael@0 1720 };
michael@0 1721
michael@0 1722
michael@0 1723 class JoystickInputMapper : public InputMapper {
michael@0 1724 public:
michael@0 1725 JoystickInputMapper(InputDevice* device);
michael@0 1726 virtual ~JoystickInputMapper();
michael@0 1727
michael@0 1728 virtual uint32_t getSources();
michael@0 1729 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
michael@0 1730 virtual void dump(String8& dump);
michael@0 1731 virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
michael@0 1732 virtual void reset(nsecs_t when);
michael@0 1733 virtual void process(const RawEvent* rawEvent);
michael@0 1734
michael@0 1735 private:
michael@0 1736 struct Axis {
michael@0 1737 RawAbsoluteAxisInfo rawAxisInfo;
michael@0 1738 AxisInfo axisInfo;
michael@0 1739
michael@0 1740 bool explicitlyMapped; // true if the axis was explicitly assigned an axis id
michael@0 1741
michael@0 1742 float scale; // scale factor from raw to normalized values
michael@0 1743 float offset; // offset to add after scaling for normalization
michael@0 1744 float highScale; // scale factor from raw to normalized values of high split
michael@0 1745 float highOffset; // offset to add after scaling for normalization of high split
michael@0 1746
michael@0 1747 float min; // normalized inclusive minimum
michael@0 1748 float max; // normalized inclusive maximum
michael@0 1749 float flat; // normalized flat region size
michael@0 1750 float fuzz; // normalized error tolerance
michael@0 1751 float resolution; // normalized resolution in units/mm
michael@0 1752
michael@0 1753 float filter; // filter out small variations of this size
michael@0 1754 float currentValue; // current value
michael@0 1755 float newValue; // most recent value
michael@0 1756 float highCurrentValue; // current value of high split
michael@0 1757 float highNewValue; // most recent value of high split
michael@0 1758
michael@0 1759 void initialize(const RawAbsoluteAxisInfo& rawAxisInfo, const AxisInfo& axisInfo,
michael@0 1760 bool explicitlyMapped, float scale, float offset,
michael@0 1761 float highScale, float highOffset,
michael@0 1762 float min, float max, float flat, float fuzz, float resolution) {
michael@0 1763 this->rawAxisInfo = rawAxisInfo;
michael@0 1764 this->axisInfo = axisInfo;
michael@0 1765 this->explicitlyMapped = explicitlyMapped;
michael@0 1766 this->scale = scale;
michael@0 1767 this->offset = offset;
michael@0 1768 this->highScale = highScale;
michael@0 1769 this->highOffset = highOffset;
michael@0 1770 this->min = min;
michael@0 1771 this->max = max;
michael@0 1772 this->flat = flat;
michael@0 1773 this->fuzz = fuzz;
michael@0 1774 this->resolution = resolution;
michael@0 1775 this->filter = 0;
michael@0 1776 resetValue();
michael@0 1777 }
michael@0 1778
michael@0 1779 void resetValue() {
michael@0 1780 this->currentValue = 0;
michael@0 1781 this->newValue = 0;
michael@0 1782 this->highCurrentValue = 0;
michael@0 1783 this->highNewValue = 0;
michael@0 1784 }
michael@0 1785 };
michael@0 1786
michael@0 1787 // Axes indexed by raw ABS_* axis index.
michael@0 1788 KeyedVector<int32_t, Axis> mAxes;
michael@0 1789
michael@0 1790 void sync(nsecs_t when, bool force);
michael@0 1791
michael@0 1792 bool haveAxis(int32_t axisId);
michael@0 1793 void pruneAxes(bool ignoreExplicitlyMappedAxes);
michael@0 1794 bool filterAxes(bool force);
michael@0 1795
michael@0 1796 static bool hasValueChangedSignificantly(float filter,
michael@0 1797 float newValue, float currentValue, float min, float max);
michael@0 1798 static bool hasMovedNearerToValueWithinFilteredRange(float filter,
michael@0 1799 float newValue, float currentValue, float thresholdValue);
michael@0 1800
michael@0 1801 static bool isCenteredAxis(int32_t axis);
michael@0 1802 static int32_t getCompatAxis(int32_t axis);
michael@0 1803
michael@0 1804 static void addMotionRange(int32_t axisId, const Axis& axis, InputDeviceInfo* info);
michael@0 1805 static void setPointerCoordsAxisValue(PointerCoords* pointerCoords, int32_t axis,
michael@0 1806 float value);
michael@0 1807 };
michael@0 1808
michael@0 1809 } // namespace android
michael@0 1810
michael@0 1811 #endif // _UI_INPUT_READER_H

mercurial