widget/gonk/libui/InputReader.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/gonk/libui/InputReader.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,1811 @@
     1.4 +/*
     1.5 + * Copyright (C) 2010 The Android Open Source Project
     1.6 + *
     1.7 + * Licensed under the Apache License, Version 2.0 (the "License");
     1.8 + * you may not use this file except in compliance with the License.
     1.9 + * You may obtain a copy of the License at
    1.10 + *
    1.11 + *      http://www.apache.org/licenses/LICENSE-2.0
    1.12 + *
    1.13 + * Unless required by applicable law or agreed to in writing, software
    1.14 + * distributed under the License is distributed on an "AS IS" BASIS,
    1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.16 + * See the License for the specific language governing permissions and
    1.17 + * limitations under the License.
    1.18 + */
    1.19 +
    1.20 +#ifndef _UI_INPUT_READER_H
    1.21 +#define _UI_INPUT_READER_H
    1.22 +
    1.23 +#include "EventHub.h"
    1.24 +#include "PointerController.h"
    1.25 +#include "InputListener.h"
    1.26 +
    1.27 +#include "Input.h"
    1.28 +#include "VelocityControl.h"
    1.29 +#include "VelocityTracker.h"
    1.30 +#include <utils/KeyedVector.h>
    1.31 +#include <utils/threads.h>
    1.32 +#include <utils/Timers.h>
    1.33 +#include <utils/RefBase.h>
    1.34 +#include <utils/String8.h>
    1.35 +#include <utils/BitSet.h>
    1.36 +
    1.37 +#include <stddef.h>
    1.38 +#include <unistd.h>
    1.39 +
    1.40 +// Maximum supported size of a vibration pattern.
    1.41 +// Must be at least 2.
    1.42 +#define MAX_VIBRATE_PATTERN_SIZE 100
    1.43 +
    1.44 +// Maximum allowable delay value in a vibration pattern before
    1.45 +// which the delay will be truncated.
    1.46 +#define MAX_VIBRATE_PATTERN_DELAY_NSECS (1000000 * 1000000000LL)
    1.47 +
    1.48 +namespace android {
    1.49 +
    1.50 +class InputDevice;
    1.51 +class InputMapper;
    1.52 +
    1.53 +/*
    1.54 + * Describes how coordinates are mapped on a physical display.
    1.55 + * See com.android.server.display.DisplayViewport.
    1.56 + */
    1.57 +struct DisplayViewport {
    1.58 +    int32_t displayId; // -1 if invalid
    1.59 +    int32_t orientation;
    1.60 +    int32_t logicalLeft;
    1.61 +    int32_t logicalTop;
    1.62 +    int32_t logicalRight;
    1.63 +    int32_t logicalBottom;
    1.64 +    int32_t physicalLeft;
    1.65 +    int32_t physicalTop;
    1.66 +    int32_t physicalRight;
    1.67 +    int32_t physicalBottom;
    1.68 +    int32_t deviceWidth;
    1.69 +    int32_t deviceHeight;
    1.70 +
    1.71 +    DisplayViewport() :
    1.72 +            displayId(ADISPLAY_ID_NONE), orientation(DISPLAY_ORIENTATION_0),
    1.73 +            logicalLeft(0), logicalTop(0), logicalRight(0), logicalBottom(0),
    1.74 +            physicalLeft(0), physicalTop(0), physicalRight(0), physicalBottom(0),
    1.75 +            deviceWidth(0), deviceHeight(0) {
    1.76 +    }
    1.77 +
    1.78 +    bool operator==(const DisplayViewport& other) const {
    1.79 +        return displayId == other.displayId
    1.80 +                && orientation == other.orientation
    1.81 +                && logicalLeft == other.logicalLeft
    1.82 +                && logicalTop == other.logicalTop
    1.83 +                && logicalRight == other.logicalRight
    1.84 +                && logicalBottom == other.logicalBottom
    1.85 +                && physicalLeft == other.physicalLeft
    1.86 +                && physicalTop == other.physicalTop
    1.87 +                && physicalRight == other.physicalRight
    1.88 +                && physicalBottom == other.physicalBottom
    1.89 +                && deviceWidth == other.deviceWidth
    1.90 +                && deviceHeight == other.deviceHeight;
    1.91 +    }
    1.92 +
    1.93 +    bool operator!=(const DisplayViewport& other) const {
    1.94 +        return !(*this == other);
    1.95 +    }
    1.96 +
    1.97 +    inline bool isValid() const {
    1.98 +        return displayId >= 0;
    1.99 +    }
   1.100 +
   1.101 +    void setNonDisplayViewport(int32_t width, int32_t height) {
   1.102 +        displayId = ADISPLAY_ID_NONE;
   1.103 +        orientation = DISPLAY_ORIENTATION_0;
   1.104 +        logicalLeft = 0;
   1.105 +        logicalTop = 0;
   1.106 +        logicalRight = width;
   1.107 +        logicalBottom = height;
   1.108 +        physicalLeft = 0;
   1.109 +        physicalTop = 0;
   1.110 +        physicalRight = width;
   1.111 +        physicalBottom = height;
   1.112 +        deviceWidth = width;
   1.113 +        deviceHeight = height;
   1.114 +    }
   1.115 +};
   1.116 +
   1.117 +/*
   1.118 + * Input reader configuration.
   1.119 + *
   1.120 + * Specifies various options that modify the behavior of the input reader.
   1.121 + */
   1.122 +struct InputReaderConfiguration {
   1.123 +    // Describes changes that have occurred.
   1.124 +    enum {
   1.125 +        // The pointer speed changed.
   1.126 +        CHANGE_POINTER_SPEED = 1 << 0,
   1.127 +
   1.128 +        // The pointer gesture control changed.
   1.129 +        CHANGE_POINTER_GESTURE_ENABLEMENT = 1 << 1,
   1.130 +
   1.131 +        // The display size or orientation changed.
   1.132 +        CHANGE_DISPLAY_INFO = 1 << 2,
   1.133 +
   1.134 +        // The visible touches option changed.
   1.135 +        CHANGE_SHOW_TOUCHES = 1 << 3,
   1.136 +
   1.137 +        // The keyboard layouts must be reloaded.
   1.138 +        CHANGE_KEYBOARD_LAYOUTS = 1 << 4,
   1.139 +
   1.140 +        // The device name alias supplied by the may have changed for some devices.
   1.141 +        CHANGE_DEVICE_ALIAS = 1 << 5,
   1.142 +
   1.143 +        // All devices must be reopened.
   1.144 +        CHANGE_MUST_REOPEN = 1 << 31,
   1.145 +    };
   1.146 +
   1.147 +    // Gets the amount of time to disable virtual keys after the screen is touched
   1.148 +    // in order to filter out accidental virtual key presses due to swiping gestures
   1.149 +    // or taps near the edge of the display.  May be 0 to disable the feature.
   1.150 +    nsecs_t virtualKeyQuietTime;
   1.151 +
   1.152 +    // The excluded device names for the platform.
   1.153 +    // Devices with these names will be ignored.
   1.154 +    Vector<String8> excludedDeviceNames;
   1.155 +
   1.156 +    // Velocity control parameters for mouse pointer movements.
   1.157 +    VelocityControlParameters pointerVelocityControlParameters;
   1.158 +
   1.159 +    // Velocity control parameters for mouse wheel movements.
   1.160 +    VelocityControlParameters wheelVelocityControlParameters;
   1.161 +
   1.162 +    // True if pointer gestures are enabled.
   1.163 +    bool pointerGesturesEnabled;
   1.164 +
   1.165 +    // Quiet time between certain pointer gesture transitions.
   1.166 +    // Time to allow for all fingers or buttons to settle into a stable state before
   1.167 +    // starting a new gesture.
   1.168 +    nsecs_t pointerGestureQuietInterval;
   1.169 +
   1.170 +    // The minimum speed that a pointer must travel for us to consider switching the active
   1.171 +    // touch pointer to it during a drag.  This threshold is set to avoid switching due
   1.172 +    // to noise from a finger resting on the touch pad (perhaps just pressing it down).
   1.173 +    float pointerGestureDragMinSwitchSpeed; // in pixels per second
   1.174 +
   1.175 +    // Tap gesture delay time.
   1.176 +    // The time between down and up must be less than this to be considered a tap.
   1.177 +    nsecs_t pointerGestureTapInterval;
   1.178 +
   1.179 +    // Tap drag gesture delay time.
   1.180 +    // The time between the previous tap's up and the next down must be less than
   1.181 +    // this to be considered a drag.  Otherwise, the previous tap is finished and a
   1.182 +    // new tap begins.
   1.183 +    //
   1.184 +    // Note that the previous tap will be held down for this entire duration so this
   1.185 +    // interval must be shorter than the long press timeout.
   1.186 +    nsecs_t pointerGestureTapDragInterval;
   1.187 +
   1.188 +    // The distance in pixels that the pointer is allowed to move from initial down
   1.189 +    // to up and still be called a tap.
   1.190 +    float pointerGestureTapSlop; // in pixels
   1.191 +
   1.192 +    // Time after the first touch points go down to settle on an initial centroid.
   1.193 +    // This is intended to be enough time to handle cases where the user puts down two
   1.194 +    // fingers at almost but not quite exactly the same time.
   1.195 +    nsecs_t pointerGestureMultitouchSettleInterval;
   1.196 +
   1.197 +    // The transition from PRESS to SWIPE or FREEFORM gesture mode is made when
   1.198 +    // at least two pointers have moved at least this far from their starting place.
   1.199 +    float pointerGestureMultitouchMinDistance; // in pixels
   1.200 +
   1.201 +    // The transition from PRESS to SWIPE gesture mode can only occur when the
   1.202 +    // cosine of the angle between the two vectors is greater than or equal to than this value
   1.203 +    // which indicates that the vectors are oriented in the same direction.
   1.204 +    // When the vectors are oriented in the exactly same direction, the cosine is 1.0.
   1.205 +    // (In exactly opposite directions, the cosine is -1.0.)
   1.206 +    float pointerGestureSwipeTransitionAngleCosine;
   1.207 +
   1.208 +    // The transition from PRESS to SWIPE gesture mode can only occur when the
   1.209 +    // fingers are no more than this far apart relative to the diagonal size of
   1.210 +    // the touch pad.  For example, a ratio of 0.5 means that the fingers must be
   1.211 +    // no more than half the diagonal size of the touch pad apart.
   1.212 +    float pointerGestureSwipeMaxWidthRatio;
   1.213 +
   1.214 +    // The gesture movement speed factor relative to the size of the display.
   1.215 +    // Movement speed applies when the fingers are moving in the same direction.
   1.216 +    // Without acceleration, a full swipe of the touch pad diagonal in movement mode
   1.217 +    // will cover this portion of the display diagonal.
   1.218 +    float pointerGestureMovementSpeedRatio;
   1.219 +
   1.220 +    // The gesture zoom speed factor relative to the size of the display.
   1.221 +    // Zoom speed applies when the fingers are mostly moving relative to each other
   1.222 +    // to execute a scale gesture or similar.
   1.223 +    // Without acceleration, a full swipe of the touch pad diagonal in zoom mode
   1.224 +    // will cover this portion of the display diagonal.
   1.225 +    float pointerGestureZoomSpeedRatio;
   1.226 +
   1.227 +    // True to show the location of touches on the touch screen as spots.
   1.228 +    bool showTouches;
   1.229 +
   1.230 +    InputReaderConfiguration() :
   1.231 +            virtualKeyQuietTime(0),
   1.232 +            pointerVelocityControlParameters(1.0f, 500.0f, 3000.0f, 3.0f),
   1.233 +            wheelVelocityControlParameters(1.0f, 15.0f, 50.0f, 4.0f),
   1.234 +            pointerGesturesEnabled(true),
   1.235 +            pointerGestureQuietInterval(100 * 1000000LL), // 100 ms
   1.236 +            pointerGestureDragMinSwitchSpeed(50), // 50 pixels per second
   1.237 +            pointerGestureTapInterval(150 * 1000000LL), // 150 ms
   1.238 +            pointerGestureTapDragInterval(150 * 1000000LL), // 150 ms
   1.239 +            pointerGestureTapSlop(10.0f), // 10 pixels
   1.240 +            pointerGestureMultitouchSettleInterval(100 * 1000000LL), // 100 ms
   1.241 +            pointerGestureMultitouchMinDistance(15), // 15 pixels
   1.242 +            pointerGestureSwipeTransitionAngleCosine(0.2588f), // cosine of 75 degrees
   1.243 +            pointerGestureSwipeMaxWidthRatio(0.25f),
   1.244 +            pointerGestureMovementSpeedRatio(0.8f),
   1.245 +            pointerGestureZoomSpeedRatio(0.3f),
   1.246 +            showTouches(false) { }
   1.247 +
   1.248 +    bool getDisplayInfo(bool external, DisplayViewport* outViewport) const;
   1.249 +    void setDisplayInfo(bool external, const DisplayViewport& viewport);
   1.250 +
   1.251 +private:
   1.252 +    DisplayViewport mInternalDisplay;
   1.253 +    DisplayViewport mExternalDisplay;
   1.254 +};
   1.255 +
   1.256 +
   1.257 +/*
   1.258 + * Input reader policy interface.
   1.259 + *
   1.260 + * The input reader policy is used by the input reader to interact with the Window Manager
   1.261 + * and other system components.
   1.262 + *
   1.263 + * The actual implementation is partially supported by callbacks into the DVM
   1.264 + * via JNI.  This interface is also mocked in the unit tests.
   1.265 + *
   1.266 + * These methods must NOT re-enter the input reader since they may be called while
   1.267 + * holding the input reader lock.
   1.268 + */
   1.269 +class InputReaderPolicyInterface : public virtual RefBase {
   1.270 +protected:
   1.271 +    InputReaderPolicyInterface() { }
   1.272 +    virtual ~InputReaderPolicyInterface() { }
   1.273 +
   1.274 +public:
   1.275 +    /* Gets the input reader configuration. */
   1.276 +    virtual void getReaderConfiguration(InputReaderConfiguration* outConfig) = 0;
   1.277 +
   1.278 +    /* Gets a pointer controller associated with the specified cursor device (ie. a mouse). */
   1.279 +    virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId) = 0;
   1.280 +
   1.281 +    /* Notifies the input reader policy that some input devices have changed
   1.282 +     * and provides information about all current input devices.
   1.283 +     */
   1.284 +    virtual void notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices) = 0;
   1.285 +
   1.286 +    /* Gets the keyboard layout for a particular input device. */
   1.287 +    virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const String8& inputDeviceDescriptor) = 0;
   1.288 +
   1.289 +    /* Gets a user-supplied alias for a particular input device, or an empty string if none. */
   1.290 +    virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier) = 0;
   1.291 +};
   1.292 +
   1.293 +
   1.294 +/* Processes raw input events and sends cooked event data to an input listener. */
   1.295 +class InputReaderInterface : public virtual RefBase {
   1.296 +protected:
   1.297 +    InputReaderInterface() { }
   1.298 +    virtual ~InputReaderInterface() { }
   1.299 +
   1.300 +public:
   1.301 +    /* Dumps the state of the input reader.
   1.302 +     *
   1.303 +     * This method may be called on any thread (usually by the input manager). */
   1.304 +    virtual void dump(String8& dump) = 0;
   1.305 +
   1.306 +    /* Called by the heatbeat to ensures that the reader has not deadlocked. */
   1.307 +    virtual void monitor() = 0;
   1.308 +
   1.309 +    /* Runs a single iteration of the processing loop.
   1.310 +     * Nominally reads and processes one incoming message from the EventHub.
   1.311 +     *
   1.312 +     * This method should be called on the input reader thread.
   1.313 +     */
   1.314 +    virtual void loopOnce() = 0;
   1.315 +
   1.316 +    /* Gets information about all input devices.
   1.317 +     *
   1.318 +     * This method may be called on any thread (usually by the input manager).
   1.319 +     */
   1.320 +    virtual void getInputDevices(Vector<InputDeviceInfo>& outInputDevices) = 0;
   1.321 +
   1.322 +    /* Query current input state. */
   1.323 +    virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask,
   1.324 +            int32_t scanCode) = 0;
   1.325 +    virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask,
   1.326 +            int32_t keyCode) = 0;
   1.327 +    virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask,
   1.328 +            int32_t sw) = 0;
   1.329 +
   1.330 +    /* Determine whether physical keys exist for the given framework-domain key codes. */
   1.331 +    virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask,
   1.332 +            size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) = 0;
   1.333 +
   1.334 +    /* Requests that a reconfiguration of all input devices.
   1.335 +     * The changes flag is a bitfield that indicates what has changed and whether
   1.336 +     * the input devices must all be reopened. */
   1.337 +    virtual void requestRefreshConfiguration(uint32_t changes) = 0;
   1.338 +
   1.339 +    /* Controls the vibrator of a particular input device. */
   1.340 +    virtual void vibrate(int32_t deviceId, const nsecs_t* pattern, size_t patternSize,
   1.341 +            ssize_t repeat, int32_t token) = 0;
   1.342 +    virtual void cancelVibrate(int32_t deviceId, int32_t token) = 0;
   1.343 +};
   1.344 +
   1.345 +
   1.346 +/* Internal interface used by individual input devices to access global input device state
   1.347 + * and parameters maintained by the input reader.
   1.348 + */
   1.349 +class InputReaderContext {
   1.350 +public:
   1.351 +    InputReaderContext() { }
   1.352 +    virtual ~InputReaderContext() { }
   1.353 +
   1.354 +    virtual void updateGlobalMetaState() = 0;
   1.355 +    virtual int32_t getGlobalMetaState() = 0;
   1.356 +
   1.357 +    virtual void disableVirtualKeysUntil(nsecs_t time) = 0;
   1.358 +    virtual bool shouldDropVirtualKey(nsecs_t now,
   1.359 +            InputDevice* device, int32_t keyCode, int32_t scanCode) = 0;
   1.360 +
   1.361 +    virtual void fadePointer() = 0;
   1.362 +
   1.363 +    virtual void requestTimeoutAtTime(nsecs_t when) = 0;
   1.364 +    virtual int32_t bumpGeneration() = 0;
   1.365 +
   1.366 +    virtual InputReaderPolicyInterface* getPolicy() = 0;
   1.367 +    virtual InputListenerInterface* getListener() = 0;
   1.368 +    virtual EventHubInterface* getEventHub() = 0;
   1.369 +};
   1.370 +
   1.371 +
   1.372 +/* The input reader reads raw event data from the event hub and processes it into input events
   1.373 + * that it sends to the input listener.  Some functions of the input reader, such as early
   1.374 + * event filtering in low power states, are controlled by a separate policy object.
   1.375 + *
   1.376 + * The InputReader owns a collection of InputMappers.  Most of the work it does happens
   1.377 + * on the input reader thread but the InputReader can receive queries from other system
   1.378 + * components running on arbitrary threads.  To keep things manageable, the InputReader
   1.379 + * uses a single Mutex to guard its state.  The Mutex may be held while calling into the
   1.380 + * EventHub or the InputReaderPolicy but it is never held while calling into the
   1.381 + * InputListener.
   1.382 + */
   1.383 +class InputReader : public InputReaderInterface {
   1.384 +public:
   1.385 +    InputReader(const sp<EventHubInterface>& eventHub,
   1.386 +            const sp<InputReaderPolicyInterface>& policy,
   1.387 +            const sp<InputListenerInterface>& listener);
   1.388 +    virtual ~InputReader();
   1.389 +
   1.390 +    virtual void dump(String8& dump);
   1.391 +    virtual void monitor();
   1.392 +
   1.393 +    virtual void loopOnce();
   1.394 +
   1.395 +    virtual void getInputDevices(Vector<InputDeviceInfo>& outInputDevices);
   1.396 +
   1.397 +    virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask,
   1.398 +            int32_t scanCode);
   1.399 +    virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask,
   1.400 +            int32_t keyCode);
   1.401 +    virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask,
   1.402 +            int32_t sw);
   1.403 +
   1.404 +    virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask,
   1.405 +            size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags);
   1.406 +
   1.407 +    virtual void requestRefreshConfiguration(uint32_t changes);
   1.408 +
   1.409 +    virtual void vibrate(int32_t deviceId, const nsecs_t* pattern, size_t patternSize,
   1.410 +            ssize_t repeat, int32_t token);
   1.411 +    virtual void cancelVibrate(int32_t deviceId, int32_t token);
   1.412 +
   1.413 +protected:
   1.414 +    // These members are protected so they can be instrumented by test cases.
   1.415 +    virtual InputDevice* createDeviceLocked(int32_t deviceId,
   1.416 +            const InputDeviceIdentifier& identifier, uint32_t classes);
   1.417 +
   1.418 +    class ContextImpl : public InputReaderContext {
   1.419 +        InputReader* mReader;
   1.420 +
   1.421 +    public:
   1.422 +        ContextImpl(InputReader* reader);
   1.423 +
   1.424 +        virtual void updateGlobalMetaState();
   1.425 +        virtual int32_t getGlobalMetaState();
   1.426 +        virtual void disableVirtualKeysUntil(nsecs_t time);
   1.427 +        virtual bool shouldDropVirtualKey(nsecs_t now,
   1.428 +                InputDevice* device, int32_t keyCode, int32_t scanCode);
   1.429 +        virtual void fadePointer();
   1.430 +        virtual void requestTimeoutAtTime(nsecs_t when);
   1.431 +        virtual int32_t bumpGeneration();
   1.432 +        virtual InputReaderPolicyInterface* getPolicy();
   1.433 +        virtual InputListenerInterface* getListener();
   1.434 +        virtual EventHubInterface* getEventHub();
   1.435 +    } mContext;
   1.436 +
   1.437 +    friend class ContextImpl;
   1.438 +
   1.439 +private:
   1.440 +    Mutex mLock;
   1.441 +
   1.442 +    Condition mReaderIsAliveCondition;
   1.443 +
   1.444 +    sp<EventHubInterface> mEventHub;
   1.445 +    sp<InputReaderPolicyInterface> mPolicy;
   1.446 +    sp<QueuedInputListener> mQueuedListener;
   1.447 +
   1.448 +    InputReaderConfiguration mConfig;
   1.449 +
   1.450 +    // The event queue.
   1.451 +    static const int EVENT_BUFFER_SIZE = 256;
   1.452 +    RawEvent mEventBuffer[EVENT_BUFFER_SIZE];
   1.453 +
   1.454 +    KeyedVector<int32_t, InputDevice*> mDevices;
   1.455 +
   1.456 +    // low-level input event decoding and device management
   1.457 +    void processEventsLocked(const RawEvent* rawEvents, size_t count);
   1.458 +
   1.459 +    void addDeviceLocked(nsecs_t when, int32_t deviceId);
   1.460 +    void removeDeviceLocked(nsecs_t when, int32_t deviceId);
   1.461 +    void processEventsForDeviceLocked(int32_t deviceId, const RawEvent* rawEvents, size_t count);
   1.462 +    void timeoutExpiredLocked(nsecs_t when);
   1.463 +
   1.464 +    void handleConfigurationChangedLocked(nsecs_t when);
   1.465 +
   1.466 +    int32_t mGlobalMetaState;
   1.467 +    void updateGlobalMetaStateLocked();
   1.468 +    int32_t getGlobalMetaStateLocked();
   1.469 +
   1.470 +    void fadePointerLocked();
   1.471 +
   1.472 +    int32_t mGeneration;
   1.473 +    int32_t bumpGenerationLocked();
   1.474 +
   1.475 +    void getInputDevicesLocked(Vector<InputDeviceInfo>& outInputDevices);
   1.476 +
   1.477 +    nsecs_t mDisableVirtualKeysTimeout;
   1.478 +    void disableVirtualKeysUntilLocked(nsecs_t time);
   1.479 +    bool shouldDropVirtualKeyLocked(nsecs_t now,
   1.480 +            InputDevice* device, int32_t keyCode, int32_t scanCode);
   1.481 +
   1.482 +    nsecs_t mNextTimeout;
   1.483 +    void requestTimeoutAtTimeLocked(nsecs_t when);
   1.484 +
   1.485 +    uint32_t mConfigurationChangesToRefresh;
   1.486 +    void refreshConfigurationLocked(uint32_t changes);
   1.487 +
   1.488 +    // state queries
   1.489 +    typedef int32_t (InputDevice::*GetStateFunc)(uint32_t sourceMask, int32_t code);
   1.490 +    int32_t getStateLocked(int32_t deviceId, uint32_t sourceMask, int32_t code,
   1.491 +            GetStateFunc getStateFunc);
   1.492 +    bool markSupportedKeyCodesLocked(int32_t deviceId, uint32_t sourceMask, size_t numCodes,
   1.493 +            const int32_t* keyCodes, uint8_t* outFlags);
   1.494 +};
   1.495 +
   1.496 +
   1.497 +/* Reads raw events from the event hub and processes them, endlessly. */
   1.498 +class InputReaderThread : public Thread {
   1.499 +public:
   1.500 +    InputReaderThread(const sp<InputReaderInterface>& reader);
   1.501 +    virtual ~InputReaderThread();
   1.502 +
   1.503 +private:
   1.504 +    uint32_t mFoo;
   1.505 +    sp<InputReaderInterface> mReader;
   1.506 +
   1.507 +    virtual bool threadLoop();
   1.508 +};
   1.509 +
   1.510 +
   1.511 +/* Represents the state of a single input device. */
   1.512 +class InputDevice {
   1.513 +public:
   1.514 +    InputDevice(InputReaderContext* context, int32_t id, int32_t generation,
   1.515 +            const InputDeviceIdentifier& identifier, uint32_t classes);
   1.516 +    ~InputDevice();
   1.517 +
   1.518 +    inline InputReaderContext* getContext() { return mContext; }
   1.519 +    inline int32_t getId() { return mId; }
   1.520 +    inline int32_t getGeneration() { return mGeneration; }
   1.521 +    inline const String8& getName() { return mIdentifier.name; }
   1.522 +    inline uint32_t getClasses() { return mClasses; }
   1.523 +    inline uint32_t getSources() { return mSources; }
   1.524 +
   1.525 +    inline bool isExternal() { return mIsExternal; }
   1.526 +    inline void setExternal(bool external) { mIsExternal = external; }
   1.527 +
   1.528 +    inline bool isIgnored() { return mMappers.isEmpty(); }
   1.529 +
   1.530 +    void dump(String8& dump);
   1.531 +    void addMapper(InputMapper* mapper);
   1.532 +    void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
   1.533 +    void reset(nsecs_t when);
   1.534 +    void process(const RawEvent* rawEvents, size_t count);
   1.535 +    void timeoutExpired(nsecs_t when);
   1.536 +
   1.537 +    void getDeviceInfo(InputDeviceInfo* outDeviceInfo);
   1.538 +    int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
   1.539 +    int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
   1.540 +    int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
   1.541 +    bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
   1.542 +            const int32_t* keyCodes, uint8_t* outFlags);
   1.543 +    void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat, int32_t token);
   1.544 +    void cancelVibrate(int32_t token);
   1.545 +
   1.546 +    int32_t getMetaState();
   1.547 +
   1.548 +    void fadePointer();
   1.549 +
   1.550 +    void bumpGeneration();
   1.551 +
   1.552 +    void notifyReset(nsecs_t when);
   1.553 +
   1.554 +    inline const PropertyMap& getConfiguration() { return mConfiguration; }
   1.555 +    inline EventHubInterface* getEventHub() { return mContext->getEventHub(); }
   1.556 +
   1.557 +    bool hasKey(int32_t code) {
   1.558 +        return getEventHub()->hasScanCode(mId, code);
   1.559 +    }
   1.560 +
   1.561 +    bool hasAbsoluteAxis(int32_t code) {
   1.562 +        RawAbsoluteAxisInfo info;
   1.563 +        getEventHub()->getAbsoluteAxisInfo(mId, code, &info);
   1.564 +        return info.valid;
   1.565 +    }
   1.566 +
   1.567 +    bool isKeyPressed(int32_t code) {
   1.568 +        return getEventHub()->getScanCodeState(mId, code) == AKEY_STATE_DOWN;
   1.569 +    }
   1.570 +
   1.571 +    int32_t getAbsoluteAxisValue(int32_t code) {
   1.572 +        int32_t value;
   1.573 +        getEventHub()->getAbsoluteAxisValue(mId, code, &value);
   1.574 +        return value;
   1.575 +    }
   1.576 +
   1.577 +private:
   1.578 +    InputReaderContext* mContext;
   1.579 +    int32_t mId;
   1.580 +    int32_t mGeneration;
   1.581 +    InputDeviceIdentifier mIdentifier;
   1.582 +    String8 mAlias;
   1.583 +    uint32_t mClasses;
   1.584 +
   1.585 +    Vector<InputMapper*> mMappers;
   1.586 +
   1.587 +    uint32_t mSources;
   1.588 +    bool mIsExternal;
   1.589 +    bool mDropUntilNextSync;
   1.590 +
   1.591 +    typedef int32_t (InputMapper::*GetStateFunc)(uint32_t sourceMask, int32_t code);
   1.592 +    int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc);
   1.593 +
   1.594 +    PropertyMap mConfiguration;
   1.595 +};
   1.596 +
   1.597 +
   1.598 +/* Keeps track of the state of mouse or touch pad buttons. */
   1.599 +class CursorButtonAccumulator {
   1.600 +public:
   1.601 +    CursorButtonAccumulator();
   1.602 +    void reset(InputDevice* device);
   1.603 +
   1.604 +    void process(const RawEvent* rawEvent);
   1.605 +
   1.606 +    uint32_t getButtonState() const;
   1.607 +
   1.608 +private:
   1.609 +    bool mBtnLeft;
   1.610 +    bool mBtnRight;
   1.611 +    bool mBtnMiddle;
   1.612 +    bool mBtnBack;
   1.613 +    bool mBtnSide;
   1.614 +    bool mBtnForward;
   1.615 +    bool mBtnExtra;
   1.616 +    bool mBtnTask;
   1.617 +
   1.618 +    void clearButtons();
   1.619 +};
   1.620 +
   1.621 +
   1.622 +/* Keeps track of cursor movements. */
   1.623 +
   1.624 +class CursorMotionAccumulator {
   1.625 +public:
   1.626 +    CursorMotionAccumulator();
   1.627 +    void reset(InputDevice* device);
   1.628 +
   1.629 +    void process(const RawEvent* rawEvent);
   1.630 +    void finishSync();
   1.631 +
   1.632 +    inline int32_t getRelativeX() const { return mRelX; }
   1.633 +    inline int32_t getRelativeY() const { return mRelY; }
   1.634 +
   1.635 +private:
   1.636 +    int32_t mRelX;
   1.637 +    int32_t mRelY;
   1.638 +
   1.639 +    void clearRelativeAxes();
   1.640 +};
   1.641 +
   1.642 +
   1.643 +/* Keeps track of cursor scrolling motions. */
   1.644 +
   1.645 +class CursorScrollAccumulator {
   1.646 +public:
   1.647 +    CursorScrollAccumulator();
   1.648 +    void configure(InputDevice* device);
   1.649 +    void reset(InputDevice* device);
   1.650 +
   1.651 +    void process(const RawEvent* rawEvent);
   1.652 +    void finishSync();
   1.653 +
   1.654 +    inline bool haveRelativeVWheel() const { return mHaveRelWheel; }
   1.655 +    inline bool haveRelativeHWheel() const { return mHaveRelHWheel; }
   1.656 +
   1.657 +    inline int32_t getRelativeX() const { return mRelX; }
   1.658 +    inline int32_t getRelativeY() const { return mRelY; }
   1.659 +    inline int32_t getRelativeVWheel() const { return mRelWheel; }
   1.660 +    inline int32_t getRelativeHWheel() const { return mRelHWheel; }
   1.661 +
   1.662 +private:
   1.663 +    bool mHaveRelWheel;
   1.664 +    bool mHaveRelHWheel;
   1.665 +
   1.666 +    int32_t mRelX;
   1.667 +    int32_t mRelY;
   1.668 +    int32_t mRelWheel;
   1.669 +    int32_t mRelHWheel;
   1.670 +
   1.671 +    void clearRelativeAxes();
   1.672 +};
   1.673 +
   1.674 +
   1.675 +/* Keeps track of the state of touch, stylus and tool buttons. */
   1.676 +class TouchButtonAccumulator {
   1.677 +public:
   1.678 +    TouchButtonAccumulator();
   1.679 +    void configure(InputDevice* device);
   1.680 +    void reset(InputDevice* device);
   1.681 +
   1.682 +    void process(const RawEvent* rawEvent);
   1.683 +
   1.684 +    uint32_t getButtonState() const;
   1.685 +    int32_t getToolType() const;
   1.686 +    bool isToolActive() const;
   1.687 +    bool isHovering() const;
   1.688 +    bool hasStylus() const;
   1.689 +
   1.690 +private:
   1.691 +    bool mHaveBtnTouch;
   1.692 +    bool mHaveStylus;
   1.693 +
   1.694 +    bool mBtnTouch;
   1.695 +    bool mBtnStylus;
   1.696 +    bool mBtnStylus2;
   1.697 +    bool mBtnToolFinger;
   1.698 +    bool mBtnToolPen;
   1.699 +    bool mBtnToolRubber;
   1.700 +    bool mBtnToolBrush;
   1.701 +    bool mBtnToolPencil;
   1.702 +    bool mBtnToolAirbrush;
   1.703 +    bool mBtnToolMouse;
   1.704 +    bool mBtnToolLens;
   1.705 +    bool mBtnToolDoubleTap;
   1.706 +    bool mBtnToolTripleTap;
   1.707 +    bool mBtnToolQuadTap;
   1.708 +
   1.709 +    void clearButtons();
   1.710 +};
   1.711 +
   1.712 +
   1.713 +/* Raw axis information from the driver. */
   1.714 +struct RawPointerAxes {
   1.715 +    RawAbsoluteAxisInfo x;
   1.716 +    RawAbsoluteAxisInfo y;
   1.717 +    RawAbsoluteAxisInfo pressure;
   1.718 +    RawAbsoluteAxisInfo touchMajor;
   1.719 +    RawAbsoluteAxisInfo touchMinor;
   1.720 +    RawAbsoluteAxisInfo toolMajor;
   1.721 +    RawAbsoluteAxisInfo toolMinor;
   1.722 +    RawAbsoluteAxisInfo orientation;
   1.723 +    RawAbsoluteAxisInfo distance;
   1.724 +    RawAbsoluteAxisInfo tiltX;
   1.725 +    RawAbsoluteAxisInfo tiltY;
   1.726 +    RawAbsoluteAxisInfo trackingId;
   1.727 +    RawAbsoluteAxisInfo slot;
   1.728 +
   1.729 +    RawPointerAxes();
   1.730 +    void clear();
   1.731 +};
   1.732 +
   1.733 +
   1.734 +/* Raw data for a collection of pointers including a pointer id mapping table. */
   1.735 +struct RawPointerData {
   1.736 +    struct Pointer {
   1.737 +        uint32_t id;
   1.738 +        int32_t x;
   1.739 +        int32_t y;
   1.740 +        int32_t pressure;
   1.741 +        int32_t touchMajor;
   1.742 +        int32_t touchMinor;
   1.743 +        int32_t toolMajor;
   1.744 +        int32_t toolMinor;
   1.745 +        int32_t orientation;
   1.746 +        int32_t distance;
   1.747 +        int32_t tiltX;
   1.748 +        int32_t tiltY;
   1.749 +        int32_t toolType; // a fully decoded AMOTION_EVENT_TOOL_TYPE constant
   1.750 +        bool isHovering;
   1.751 +    };
   1.752 +
   1.753 +    uint32_t pointerCount;
   1.754 +    Pointer pointers[MAX_POINTERS];
   1.755 +    BitSet32 hoveringIdBits, touchingIdBits;
   1.756 +    uint32_t idToIndex[MAX_POINTER_ID + 1];
   1.757 +
   1.758 +    RawPointerData();
   1.759 +    void clear();
   1.760 +    void copyFrom(const RawPointerData& other);
   1.761 +    void getCentroidOfTouchingPointers(float* outX, float* outY) const;
   1.762 +
   1.763 +    inline void markIdBit(uint32_t id, bool isHovering) {
   1.764 +        if (isHovering) {
   1.765 +            hoveringIdBits.markBit(id);
   1.766 +        } else {
   1.767 +            touchingIdBits.markBit(id);
   1.768 +        }
   1.769 +    }
   1.770 +
   1.771 +    inline void clearIdBits() {
   1.772 +        hoveringIdBits.clear();
   1.773 +        touchingIdBits.clear();
   1.774 +    }
   1.775 +
   1.776 +    inline const Pointer& pointerForId(uint32_t id) const {
   1.777 +        return pointers[idToIndex[id]];
   1.778 +    }
   1.779 +
   1.780 +    inline bool isHovering(uint32_t pointerIndex) {
   1.781 +        return pointers[pointerIndex].isHovering;
   1.782 +    }
   1.783 +};
   1.784 +
   1.785 +
   1.786 +/* Cooked data for a collection of pointers including a pointer id mapping table. */
   1.787 +struct CookedPointerData {
   1.788 +    uint32_t pointerCount;
   1.789 +    PointerProperties pointerProperties[MAX_POINTERS];
   1.790 +    PointerCoords pointerCoords[MAX_POINTERS];
   1.791 +    BitSet32 hoveringIdBits, touchingIdBits;
   1.792 +    uint32_t idToIndex[MAX_POINTER_ID + 1];
   1.793 +
   1.794 +    CookedPointerData();
   1.795 +    void clear();
   1.796 +    void copyFrom(const CookedPointerData& other);
   1.797 +
   1.798 +    inline const PointerCoords& pointerCoordsForId(uint32_t id) const {
   1.799 +        return pointerCoords[idToIndex[id]];
   1.800 +    }
   1.801 +
   1.802 +    inline bool isHovering(uint32_t pointerIndex) {
   1.803 +        return hoveringIdBits.hasBit(pointerProperties[pointerIndex].id);
   1.804 +    }
   1.805 +};
   1.806 +
   1.807 +
   1.808 +/* Keeps track of the state of single-touch protocol. */
   1.809 +class SingleTouchMotionAccumulator {
   1.810 +public:
   1.811 +    SingleTouchMotionAccumulator();
   1.812 +
   1.813 +    void process(const RawEvent* rawEvent);
   1.814 +    void reset(InputDevice* device);
   1.815 +
   1.816 +    inline int32_t getAbsoluteX() const { return mAbsX; }
   1.817 +    inline int32_t getAbsoluteY() const { return mAbsY; }
   1.818 +    inline int32_t getAbsolutePressure() const { return mAbsPressure; }
   1.819 +    inline int32_t getAbsoluteToolWidth() const { return mAbsToolWidth; }
   1.820 +    inline int32_t getAbsoluteDistance() const { return mAbsDistance; }
   1.821 +    inline int32_t getAbsoluteTiltX() const { return mAbsTiltX; }
   1.822 +    inline int32_t getAbsoluteTiltY() const { return mAbsTiltY; }
   1.823 +
   1.824 +private:
   1.825 +    int32_t mAbsX;
   1.826 +    int32_t mAbsY;
   1.827 +    int32_t mAbsPressure;
   1.828 +    int32_t mAbsToolWidth;
   1.829 +    int32_t mAbsDistance;
   1.830 +    int32_t mAbsTiltX;
   1.831 +    int32_t mAbsTiltY;
   1.832 +
   1.833 +    void clearAbsoluteAxes();
   1.834 +};
   1.835 +
   1.836 +
   1.837 +/* Keeps track of the state of multi-touch protocol. */
   1.838 +class MultiTouchMotionAccumulator {
   1.839 +public:
   1.840 +    class Slot {
   1.841 +    public:
   1.842 +        inline bool isInUse() const { return mInUse; }
   1.843 +        inline int32_t getX() const { return mAbsMTPositionX; }
   1.844 +        inline int32_t getY() const { return mAbsMTPositionY; }
   1.845 +        inline int32_t getTouchMajor() const { return mAbsMTTouchMajor; }
   1.846 +        inline int32_t getTouchMinor() const {
   1.847 +            return mHaveAbsMTTouchMinor ? mAbsMTTouchMinor : mAbsMTTouchMajor; }
   1.848 +        inline int32_t getToolMajor() const { return mAbsMTWidthMajor; }
   1.849 +        inline int32_t getToolMinor() const {
   1.850 +            return mHaveAbsMTWidthMinor ? mAbsMTWidthMinor : mAbsMTWidthMajor; }
   1.851 +        inline int32_t getOrientation() const { return mAbsMTOrientation; }
   1.852 +        inline int32_t getTrackingId() const { return mAbsMTTrackingId; }
   1.853 +        inline int32_t getPressure() const { return mAbsMTPressure; }
   1.854 +        inline int32_t getDistance() const { return mAbsMTDistance; }
   1.855 +        inline int32_t getToolType() const;
   1.856 +
   1.857 +    private:
   1.858 +        friend class MultiTouchMotionAccumulator;
   1.859 +
   1.860 +        bool mInUse;
   1.861 +        bool mHaveAbsMTTouchMinor;
   1.862 +        bool mHaveAbsMTWidthMinor;
   1.863 +        bool mHaveAbsMTToolType;
   1.864 +
   1.865 +        int32_t mAbsMTPositionX;
   1.866 +        int32_t mAbsMTPositionY;
   1.867 +        int32_t mAbsMTTouchMajor;
   1.868 +        int32_t mAbsMTTouchMinor;
   1.869 +        int32_t mAbsMTWidthMajor;
   1.870 +        int32_t mAbsMTWidthMinor;
   1.871 +        int32_t mAbsMTOrientation;
   1.872 +        int32_t mAbsMTTrackingId;
   1.873 +        int32_t mAbsMTPressure;
   1.874 +        int32_t mAbsMTDistance;
   1.875 +        int32_t mAbsMTToolType;
   1.876 +
   1.877 +        Slot();
   1.878 +        void clear();
   1.879 +    };
   1.880 +
   1.881 +    MultiTouchMotionAccumulator();
   1.882 +    ~MultiTouchMotionAccumulator();
   1.883 +
   1.884 +    void configure(InputDevice* device, size_t slotCount, bool usingSlotsProtocol);
   1.885 +    void reset(InputDevice* device);
   1.886 +    void process(const RawEvent* rawEvent);
   1.887 +    void finishSync();
   1.888 +    bool hasStylus() const;
   1.889 +
   1.890 +    inline size_t getSlotCount() const { return mSlotCount; }
   1.891 +    inline const Slot* getSlot(size_t index) const { return &mSlots[index]; }
   1.892 +
   1.893 +private:
   1.894 +    int32_t mCurrentSlot;
   1.895 +    Slot* mSlots;
   1.896 +    size_t mSlotCount;
   1.897 +    bool mUsingSlotsProtocol;
   1.898 +    bool mHaveStylus;
   1.899 +
   1.900 +    void clearSlots(int32_t initialSlot);
   1.901 +};
   1.902 +
   1.903 +
   1.904 +/* An input mapper transforms raw input events into cooked event data.
   1.905 + * A single input device can have multiple associated input mappers in order to interpret
   1.906 + * different classes of events.
   1.907 + *
   1.908 + * InputMapper lifecycle:
   1.909 + * - create
   1.910 + * - configure with 0 changes
   1.911 + * - reset
   1.912 + * - process, process, process (may occasionally reconfigure with non-zero changes or reset)
   1.913 + * - reset
   1.914 + * - destroy
   1.915 + */
   1.916 +class InputMapper {
   1.917 +public:
   1.918 +    InputMapper(InputDevice* device);
   1.919 +    virtual ~InputMapper();
   1.920 +
   1.921 +    inline InputDevice* getDevice() { return mDevice; }
   1.922 +    inline int32_t getDeviceId() { return mDevice->getId(); }
   1.923 +    inline const String8 getDeviceName() { return mDevice->getName(); }
   1.924 +    inline InputReaderContext* getContext() { return mContext; }
   1.925 +    inline InputReaderPolicyInterface* getPolicy() { return mContext->getPolicy(); }
   1.926 +    inline InputListenerInterface* getListener() { return mContext->getListener(); }
   1.927 +    inline EventHubInterface* getEventHub() { return mContext->getEventHub(); }
   1.928 +
   1.929 +    virtual uint32_t getSources() = 0;
   1.930 +    virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
   1.931 +    virtual void dump(String8& dump);
   1.932 +    virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
   1.933 +    virtual void reset(nsecs_t when);
   1.934 +    virtual void process(const RawEvent* rawEvent) = 0;
   1.935 +    virtual void timeoutExpired(nsecs_t when);
   1.936 +
   1.937 +    virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
   1.938 +    virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
   1.939 +    virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
   1.940 +    virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
   1.941 +            const int32_t* keyCodes, uint8_t* outFlags);
   1.942 +    virtual void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat,
   1.943 +            int32_t token);
   1.944 +    virtual void cancelVibrate(int32_t token);
   1.945 +
   1.946 +    virtual int32_t getMetaState();
   1.947 +
   1.948 +    virtual void fadePointer();
   1.949 +
   1.950 +protected:
   1.951 +    InputDevice* mDevice;
   1.952 +    InputReaderContext* mContext;
   1.953 +
   1.954 +    status_t getAbsoluteAxisInfo(int32_t axis, RawAbsoluteAxisInfo* axisInfo);
   1.955 +    void bumpGeneration();
   1.956 +
   1.957 +    static void dumpRawAbsoluteAxisInfo(String8& dump,
   1.958 +            const RawAbsoluteAxisInfo& axis, const char* name);
   1.959 +};
   1.960 +
   1.961 +
   1.962 +class SwitchInputMapper : public InputMapper {
   1.963 +public:
   1.964 +    SwitchInputMapper(InputDevice* device);
   1.965 +    virtual ~SwitchInputMapper();
   1.966 +
   1.967 +    virtual uint32_t getSources();
   1.968 +    virtual void process(const RawEvent* rawEvent);
   1.969 +
   1.970 +    virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
   1.971 +
   1.972 +private:
   1.973 +    uint32_t mUpdatedSwitchValues;
   1.974 +    uint32_t mUpdatedSwitchMask;
   1.975 +
   1.976 +    void processSwitch(int32_t switchCode, int32_t switchValue);
   1.977 +    void sync(nsecs_t when);
   1.978 +};
   1.979 +
   1.980 +
   1.981 +class VibratorInputMapper : public InputMapper {
   1.982 +public:
   1.983 +    VibratorInputMapper(InputDevice* device);
   1.984 +    virtual ~VibratorInputMapper();
   1.985 +
   1.986 +    virtual uint32_t getSources();
   1.987 +    virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
   1.988 +    virtual void process(const RawEvent* rawEvent);
   1.989 +
   1.990 +    virtual void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat,
   1.991 +            int32_t token);
   1.992 +    virtual void cancelVibrate(int32_t token);
   1.993 +    virtual void timeoutExpired(nsecs_t when);
   1.994 +    virtual void dump(String8& dump);
   1.995 +
   1.996 +private:
   1.997 +    bool mVibrating;
   1.998 +    nsecs_t mPattern[MAX_VIBRATE_PATTERN_SIZE];
   1.999 +    size_t mPatternSize;
  1.1000 +    ssize_t mRepeat;
  1.1001 +    int32_t mToken;
  1.1002 +    ssize_t mIndex;
  1.1003 +    nsecs_t mNextStepTime;
  1.1004 +
  1.1005 +    void nextStep();
  1.1006 +    void stopVibrating();
  1.1007 +};
  1.1008 +
  1.1009 +
  1.1010 +class KeyboardInputMapper : public InputMapper {
  1.1011 +public:
  1.1012 +    KeyboardInputMapper(InputDevice* device, uint32_t source, int32_t keyboardType);
  1.1013 +    virtual ~KeyboardInputMapper();
  1.1014 +
  1.1015 +    virtual uint32_t getSources();
  1.1016 +    virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
  1.1017 +    virtual void dump(String8& dump);
  1.1018 +    virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
  1.1019 +    virtual void reset(nsecs_t when);
  1.1020 +    virtual void process(const RawEvent* rawEvent);
  1.1021 +
  1.1022 +    virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
  1.1023 +    virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
  1.1024 +    virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
  1.1025 +            const int32_t* keyCodes, uint8_t* outFlags);
  1.1026 +
  1.1027 +    virtual int32_t getMetaState();
  1.1028 +
  1.1029 +private:
  1.1030 +    struct KeyDown {
  1.1031 +        int32_t keyCode;
  1.1032 +        int32_t scanCode;
  1.1033 +    };
  1.1034 +
  1.1035 +    uint32_t mSource;
  1.1036 +    int32_t mKeyboardType;
  1.1037 +
  1.1038 +    int32_t mOrientation; // orientation for dpad keys
  1.1039 +
  1.1040 +    Vector<KeyDown> mKeyDowns; // keys that are down
  1.1041 +    int32_t mMetaState;
  1.1042 +    nsecs_t mDownTime; // time of most recent key down
  1.1043 +
  1.1044 +    int32_t mCurrentHidUsage; // most recent HID usage seen this packet, or 0 if none
  1.1045 +
  1.1046 +    struct LedState {
  1.1047 +        bool avail; // led is available
  1.1048 +        bool on;    // we think the led is currently on
  1.1049 +    };
  1.1050 +    LedState mCapsLockLedState;
  1.1051 +    LedState mNumLockLedState;
  1.1052 +    LedState mScrollLockLedState;
  1.1053 +
  1.1054 +    // Immutable configuration parameters.
  1.1055 +    struct Parameters {
  1.1056 +        bool hasAssociatedDisplay;
  1.1057 +        bool orientationAware;
  1.1058 +    } mParameters;
  1.1059 +
  1.1060 +    void configureParameters();
  1.1061 +    void dumpParameters(String8& dump);
  1.1062 +
  1.1063 +    bool isKeyboardOrGamepadKey(int32_t scanCode);
  1.1064 +
  1.1065 +    void processKey(nsecs_t when, bool down, int32_t keyCode, int32_t scanCode,
  1.1066 +            uint32_t policyFlags);
  1.1067 +
  1.1068 +    ssize_t findKeyDown(int32_t scanCode);
  1.1069 +
  1.1070 +    void resetLedState();
  1.1071 +    void initializeLedState(LedState& ledState, int32_t led);
  1.1072 +    void updateLedState(bool reset);
  1.1073 +    void updateLedStateForModifier(LedState& ledState, int32_t led,
  1.1074 +            int32_t modifier, bool reset);
  1.1075 +};
  1.1076 +
  1.1077 +
  1.1078 +class CursorInputMapper : public InputMapper {
  1.1079 +public:
  1.1080 +    CursorInputMapper(InputDevice* device);
  1.1081 +    virtual ~CursorInputMapper();
  1.1082 +
  1.1083 +    virtual uint32_t getSources();
  1.1084 +    virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
  1.1085 +    virtual void dump(String8& dump);
  1.1086 +    virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
  1.1087 +    virtual void reset(nsecs_t when);
  1.1088 +    virtual void process(const RawEvent* rawEvent);
  1.1089 +
  1.1090 +    virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
  1.1091 +
  1.1092 +    virtual void fadePointer();
  1.1093 +
  1.1094 +private:
  1.1095 +    // Amount that trackball needs to move in order to generate a key event.
  1.1096 +    static const int32_t TRACKBALL_MOVEMENT_THRESHOLD = 6;
  1.1097 +
  1.1098 +    // Immutable configuration parameters.
  1.1099 +    struct Parameters {
  1.1100 +        enum Mode {
  1.1101 +            MODE_POINTER,
  1.1102 +            MODE_NAVIGATION,
  1.1103 +        };
  1.1104 +
  1.1105 +        Mode mode;
  1.1106 +        bool hasAssociatedDisplay;
  1.1107 +        bool orientationAware;
  1.1108 +    } mParameters;
  1.1109 +
  1.1110 +    CursorButtonAccumulator mCursorButtonAccumulator;
  1.1111 +    CursorMotionAccumulator mCursorMotionAccumulator;
  1.1112 +    CursorScrollAccumulator mCursorScrollAccumulator;
  1.1113 +
  1.1114 +    int32_t mSource;
  1.1115 +    float mXScale;
  1.1116 +    float mYScale;
  1.1117 +    float mXPrecision;
  1.1118 +    float mYPrecision;
  1.1119 +
  1.1120 +    float mVWheelScale;
  1.1121 +    float mHWheelScale;
  1.1122 +
  1.1123 +    // Velocity controls for mouse pointer and wheel movements.
  1.1124 +    // The controls for X and Y wheel movements are separate to keep them decoupled.
  1.1125 +    VelocityControl mPointerVelocityControl;
  1.1126 +    VelocityControl mWheelXVelocityControl;
  1.1127 +    VelocityControl mWheelYVelocityControl;
  1.1128 +
  1.1129 +    int32_t mOrientation;
  1.1130 +
  1.1131 +    sp<PointerControllerInterface> mPointerController;
  1.1132 +
  1.1133 +    int32_t mButtonState;
  1.1134 +    nsecs_t mDownTime;
  1.1135 +
  1.1136 +    void configureParameters();
  1.1137 +    void dumpParameters(String8& dump);
  1.1138 +
  1.1139 +    void sync(nsecs_t when);
  1.1140 +};
  1.1141 +
  1.1142 +
  1.1143 +class TouchInputMapper : public InputMapper {
  1.1144 +public:
  1.1145 +    TouchInputMapper(InputDevice* device);
  1.1146 +    virtual ~TouchInputMapper();
  1.1147 +
  1.1148 +    virtual uint32_t getSources();
  1.1149 +    virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
  1.1150 +    virtual void dump(String8& dump);
  1.1151 +    virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
  1.1152 +    virtual void reset(nsecs_t when);
  1.1153 +    virtual void process(const RawEvent* rawEvent);
  1.1154 +
  1.1155 +    virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
  1.1156 +    virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
  1.1157 +    virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
  1.1158 +            const int32_t* keyCodes, uint8_t* outFlags);
  1.1159 +
  1.1160 +    virtual void fadePointer();
  1.1161 +    virtual void timeoutExpired(nsecs_t when);
  1.1162 +
  1.1163 +protected:
  1.1164 +    CursorButtonAccumulator mCursorButtonAccumulator;
  1.1165 +    CursorScrollAccumulator mCursorScrollAccumulator;
  1.1166 +    TouchButtonAccumulator mTouchButtonAccumulator;
  1.1167 +
  1.1168 +    struct VirtualKey {
  1.1169 +        int32_t keyCode;
  1.1170 +        int32_t scanCode;
  1.1171 +        uint32_t flags;
  1.1172 +
  1.1173 +        // computed hit box, specified in touch screen coords based on known display size
  1.1174 +        int32_t hitLeft;
  1.1175 +        int32_t hitTop;
  1.1176 +        int32_t hitRight;
  1.1177 +        int32_t hitBottom;
  1.1178 +
  1.1179 +        inline bool isHit(int32_t x, int32_t y) const {
  1.1180 +            return x >= hitLeft && x <= hitRight && y >= hitTop && y <= hitBottom;
  1.1181 +        }
  1.1182 +    };
  1.1183 +
  1.1184 +    // Input sources and device mode.
  1.1185 +    uint32_t mSource;
  1.1186 +
  1.1187 +    enum DeviceMode {
  1.1188 +        DEVICE_MODE_DISABLED, // input is disabled
  1.1189 +        DEVICE_MODE_DIRECT, // direct mapping (touchscreen)
  1.1190 +        DEVICE_MODE_UNSCALED, // unscaled mapping (touchpad)
  1.1191 +        DEVICE_MODE_NAVIGATION, // unscaled mapping with assist gesture (touch navigation)
  1.1192 +        DEVICE_MODE_POINTER, // pointer mapping (pointer)
  1.1193 +    };
  1.1194 +    DeviceMode mDeviceMode;
  1.1195 +
  1.1196 +    // The reader's configuration.
  1.1197 +    InputReaderConfiguration mConfig;
  1.1198 +
  1.1199 +    // Immutable configuration parameters.
  1.1200 +    struct Parameters {
  1.1201 +        enum DeviceType {
  1.1202 +            DEVICE_TYPE_TOUCH_SCREEN,
  1.1203 +            DEVICE_TYPE_TOUCH_PAD,
  1.1204 +            DEVICE_TYPE_TOUCH_NAVIGATION,
  1.1205 +            DEVICE_TYPE_POINTER,
  1.1206 +        };
  1.1207 +
  1.1208 +        DeviceType deviceType;
  1.1209 +        bool hasAssociatedDisplay;
  1.1210 +        bool associatedDisplayIsExternal;
  1.1211 +        bool orientationAware;
  1.1212 +
  1.1213 +        enum GestureMode {
  1.1214 +            GESTURE_MODE_POINTER,
  1.1215 +            GESTURE_MODE_SPOTS,
  1.1216 +        };
  1.1217 +        GestureMode gestureMode;
  1.1218 +    } mParameters;
  1.1219 +
  1.1220 +    // Immutable calibration parameters in parsed form.
  1.1221 +    struct Calibration {
  1.1222 +        // Size
  1.1223 +        enum SizeCalibration {
  1.1224 +            SIZE_CALIBRATION_DEFAULT,
  1.1225 +            SIZE_CALIBRATION_NONE,
  1.1226 +            SIZE_CALIBRATION_GEOMETRIC,
  1.1227 +            SIZE_CALIBRATION_DIAMETER,
  1.1228 +            SIZE_CALIBRATION_BOX,
  1.1229 +            SIZE_CALIBRATION_AREA,
  1.1230 +        };
  1.1231 +
  1.1232 +        SizeCalibration sizeCalibration;
  1.1233 +
  1.1234 +        bool haveSizeScale;
  1.1235 +        float sizeScale;
  1.1236 +        bool haveSizeBias;
  1.1237 +        float sizeBias;
  1.1238 +        bool haveSizeIsSummed;
  1.1239 +        bool sizeIsSummed;
  1.1240 +
  1.1241 +        // Pressure
  1.1242 +        enum PressureCalibration {
  1.1243 +            PRESSURE_CALIBRATION_DEFAULT,
  1.1244 +            PRESSURE_CALIBRATION_NONE,
  1.1245 +            PRESSURE_CALIBRATION_PHYSICAL,
  1.1246 +            PRESSURE_CALIBRATION_AMPLITUDE,
  1.1247 +        };
  1.1248 +
  1.1249 +        PressureCalibration pressureCalibration;
  1.1250 +        bool havePressureScale;
  1.1251 +        float pressureScale;
  1.1252 +
  1.1253 +        // Orientation
  1.1254 +        enum OrientationCalibration {
  1.1255 +            ORIENTATION_CALIBRATION_DEFAULT,
  1.1256 +            ORIENTATION_CALIBRATION_NONE,
  1.1257 +            ORIENTATION_CALIBRATION_INTERPOLATED,
  1.1258 +            ORIENTATION_CALIBRATION_VECTOR,
  1.1259 +        };
  1.1260 +
  1.1261 +        OrientationCalibration orientationCalibration;
  1.1262 +
  1.1263 +        // Distance
  1.1264 +        enum DistanceCalibration {
  1.1265 +            DISTANCE_CALIBRATION_DEFAULT,
  1.1266 +            DISTANCE_CALIBRATION_NONE,
  1.1267 +            DISTANCE_CALIBRATION_SCALED,
  1.1268 +        };
  1.1269 +
  1.1270 +        DistanceCalibration distanceCalibration;
  1.1271 +        bool haveDistanceScale;
  1.1272 +        float distanceScale;
  1.1273 +
  1.1274 +        enum CoverageCalibration {
  1.1275 +            COVERAGE_CALIBRATION_DEFAULT,
  1.1276 +            COVERAGE_CALIBRATION_NONE,
  1.1277 +            COVERAGE_CALIBRATION_BOX,
  1.1278 +        };
  1.1279 +
  1.1280 +        CoverageCalibration coverageCalibration;
  1.1281 +
  1.1282 +        inline void applySizeScaleAndBias(float* outSize) const {
  1.1283 +            if (haveSizeScale) {
  1.1284 +                *outSize *= sizeScale;
  1.1285 +            }
  1.1286 +            if (haveSizeBias) {
  1.1287 +                *outSize += sizeBias;
  1.1288 +            }
  1.1289 +        }
  1.1290 +    } mCalibration;
  1.1291 +
  1.1292 +    // Raw pointer axis information from the driver.
  1.1293 +    RawPointerAxes mRawPointerAxes;
  1.1294 +
  1.1295 +    // Raw pointer sample data.
  1.1296 +    RawPointerData mCurrentRawPointerData;
  1.1297 +    RawPointerData mLastRawPointerData;
  1.1298 +
  1.1299 +    // Cooked pointer sample data.
  1.1300 +    CookedPointerData mCurrentCookedPointerData;
  1.1301 +    CookedPointerData mLastCookedPointerData;
  1.1302 +
  1.1303 +    // Button state.
  1.1304 +    int32_t mCurrentButtonState;
  1.1305 +    int32_t mLastButtonState;
  1.1306 +
  1.1307 +    // Scroll state.
  1.1308 +    int32_t mCurrentRawVScroll;
  1.1309 +    int32_t mCurrentRawHScroll;
  1.1310 +
  1.1311 +    // Id bits used to differentiate fingers, stylus and mouse tools.
  1.1312 +    BitSet32 mCurrentFingerIdBits; // finger or unknown
  1.1313 +    BitSet32 mLastFingerIdBits;
  1.1314 +    BitSet32 mCurrentStylusIdBits; // stylus or eraser
  1.1315 +    BitSet32 mLastStylusIdBits;
  1.1316 +    BitSet32 mCurrentMouseIdBits; // mouse or lens
  1.1317 +    BitSet32 mLastMouseIdBits;
  1.1318 +
  1.1319 +    // True if we sent a HOVER_ENTER event.
  1.1320 +    bool mSentHoverEnter;
  1.1321 +
  1.1322 +    // The time the primary pointer last went down.
  1.1323 +    nsecs_t mDownTime;
  1.1324 +
  1.1325 +    // The pointer controller, or null if the device is not a pointer.
  1.1326 +    sp<PointerControllerInterface> mPointerController;
  1.1327 +
  1.1328 +    Vector<VirtualKey> mVirtualKeys;
  1.1329 +
  1.1330 +    virtual void configureParameters();
  1.1331 +    virtual void dumpParameters(String8& dump);
  1.1332 +    virtual void configureRawPointerAxes();
  1.1333 +    virtual void dumpRawPointerAxes(String8& dump);
  1.1334 +    virtual void configureSurface(nsecs_t when, bool* outResetNeeded);
  1.1335 +    virtual void dumpSurface(String8& dump);
  1.1336 +    virtual void configureVirtualKeys();
  1.1337 +    virtual void dumpVirtualKeys(String8& dump);
  1.1338 +    virtual void parseCalibration();
  1.1339 +    virtual void resolveCalibration();
  1.1340 +    virtual void dumpCalibration(String8& dump);
  1.1341 +    virtual bool hasStylus() const = 0;
  1.1342 +
  1.1343 +    virtual void syncTouch(nsecs_t when, bool* outHavePointerIds) = 0;
  1.1344 +
  1.1345 +private:
  1.1346 +    // The current viewport.
  1.1347 +    // The components of the viewport are specified in the display's rotated orientation.
  1.1348 +    DisplayViewport mViewport;
  1.1349 +
  1.1350 +    // The surface orientation, width and height set by configureSurface().
  1.1351 +    // The width and height are derived from the viewport but are specified
  1.1352 +    // in the natural orientation.
  1.1353 +    // The surface origin specifies how the surface coordinates should be translated
  1.1354 +    // to align with the logical display coordinate space.
  1.1355 +    // The orientation may be different from the viewport orientation as it specifies
  1.1356 +    // the rotation of the surface coordinates required to produce the viewport's
  1.1357 +    // requested orientation, so it will depend on whether the device is orientation aware.
  1.1358 +    int32_t mSurfaceWidth;
  1.1359 +    int32_t mSurfaceHeight;
  1.1360 +    int32_t mSurfaceLeft;
  1.1361 +    int32_t mSurfaceTop;
  1.1362 +    int32_t mSurfaceOrientation;
  1.1363 +
  1.1364 +    // Translation and scaling factors, orientation-independent.
  1.1365 +    float mXTranslate;
  1.1366 +    float mXScale;
  1.1367 +    float mXPrecision;
  1.1368 +
  1.1369 +    float mYTranslate;
  1.1370 +    float mYScale;
  1.1371 +    float mYPrecision;
  1.1372 +
  1.1373 +    float mGeometricScale;
  1.1374 +
  1.1375 +    float mPressureScale;
  1.1376 +
  1.1377 +    float mSizeScale;
  1.1378 +
  1.1379 +    float mOrientationScale;
  1.1380 +
  1.1381 +    float mDistanceScale;
  1.1382 +
  1.1383 +    bool mHaveTilt;
  1.1384 +    float mTiltXCenter;
  1.1385 +    float mTiltXScale;
  1.1386 +    float mTiltYCenter;
  1.1387 +    float mTiltYScale;
  1.1388 +
  1.1389 +    // Oriented motion ranges for input device info.
  1.1390 +    struct OrientedRanges {
  1.1391 +        InputDeviceInfo::MotionRange x;
  1.1392 +        InputDeviceInfo::MotionRange y;
  1.1393 +        InputDeviceInfo::MotionRange pressure;
  1.1394 +
  1.1395 +        bool haveSize;
  1.1396 +        InputDeviceInfo::MotionRange size;
  1.1397 +
  1.1398 +        bool haveTouchSize;
  1.1399 +        InputDeviceInfo::MotionRange touchMajor;
  1.1400 +        InputDeviceInfo::MotionRange touchMinor;
  1.1401 +
  1.1402 +        bool haveToolSize;
  1.1403 +        InputDeviceInfo::MotionRange toolMajor;
  1.1404 +        InputDeviceInfo::MotionRange toolMinor;
  1.1405 +
  1.1406 +        bool haveOrientation;
  1.1407 +        InputDeviceInfo::MotionRange orientation;
  1.1408 +
  1.1409 +        bool haveDistance;
  1.1410 +        InputDeviceInfo::MotionRange distance;
  1.1411 +
  1.1412 +        bool haveTilt;
  1.1413 +        InputDeviceInfo::MotionRange tilt;
  1.1414 +
  1.1415 +        OrientedRanges() {
  1.1416 +            clear();
  1.1417 +        }
  1.1418 +
  1.1419 +        void clear() {
  1.1420 +            haveSize = false;
  1.1421 +            haveTouchSize = false;
  1.1422 +            haveToolSize = false;
  1.1423 +            haveOrientation = false;
  1.1424 +            haveDistance = false;
  1.1425 +            haveTilt = false;
  1.1426 +        }
  1.1427 +    } mOrientedRanges;
  1.1428 +
  1.1429 +    // Oriented dimensions and precision.
  1.1430 +    float mOrientedXPrecision;
  1.1431 +    float mOrientedYPrecision;
  1.1432 +
  1.1433 +    struct CurrentVirtualKeyState {
  1.1434 +        bool down;
  1.1435 +        bool ignored;
  1.1436 +        nsecs_t downTime;
  1.1437 +        int32_t keyCode;
  1.1438 +        int32_t scanCode;
  1.1439 +    } mCurrentVirtualKey;
  1.1440 +
  1.1441 +    // Scale factor for gesture or mouse based pointer movements.
  1.1442 +    float mPointerXMovementScale;
  1.1443 +    float mPointerYMovementScale;
  1.1444 +
  1.1445 +    // Scale factor for gesture based zooming and other freeform motions.
  1.1446 +    float mPointerXZoomScale;
  1.1447 +    float mPointerYZoomScale;
  1.1448 +
  1.1449 +    // The maximum swipe width.
  1.1450 +    float mPointerGestureMaxSwipeWidth;
  1.1451 +
  1.1452 +    struct PointerDistanceHeapElement {
  1.1453 +        uint32_t currentPointerIndex : 8;
  1.1454 +        uint32_t lastPointerIndex : 8;
  1.1455 +        uint64_t distance : 48; // squared distance
  1.1456 +    };
  1.1457 +
  1.1458 +    enum PointerUsage {
  1.1459 +        POINTER_USAGE_NONE,
  1.1460 +        POINTER_USAGE_GESTURES,
  1.1461 +        POINTER_USAGE_STYLUS,
  1.1462 +        POINTER_USAGE_MOUSE,
  1.1463 +    };
  1.1464 +    PointerUsage mPointerUsage;
  1.1465 +
  1.1466 +    struct PointerGesture {
  1.1467 +        enum Mode {
  1.1468 +            // No fingers, button is not pressed.
  1.1469 +            // Nothing happening.
  1.1470 +            NEUTRAL,
  1.1471 +
  1.1472 +            // No fingers, button is not pressed.
  1.1473 +            // Tap detected.
  1.1474 +            // Emits DOWN and UP events at the pointer location.
  1.1475 +            TAP,
  1.1476 +
  1.1477 +            // Exactly one finger dragging following a tap.
  1.1478 +            // Pointer follows the active finger.
  1.1479 +            // Emits DOWN, MOVE and UP events at the pointer location.
  1.1480 +            //
  1.1481 +            // Detect double-taps when the finger goes up while in TAP_DRAG mode.
  1.1482 +            TAP_DRAG,
  1.1483 +
  1.1484 +            // Button is pressed.
  1.1485 +            // Pointer follows the active finger if there is one.  Other fingers are ignored.
  1.1486 +            // Emits DOWN, MOVE and UP events at the pointer location.
  1.1487 +            BUTTON_CLICK_OR_DRAG,
  1.1488 +
  1.1489 +            // Exactly one finger, button is not pressed.
  1.1490 +            // Pointer follows the active finger.
  1.1491 +            // Emits HOVER_MOVE events at the pointer location.
  1.1492 +            //
  1.1493 +            // Detect taps when the finger goes up while in HOVER mode.
  1.1494 +            HOVER,
  1.1495 +
  1.1496 +            // Exactly two fingers but neither have moved enough to clearly indicate
  1.1497 +            // whether a swipe or freeform gesture was intended.  We consider the
  1.1498 +            // pointer to be pressed so this enables clicking or long-pressing on buttons.
  1.1499 +            // Pointer does not move.
  1.1500 +            // Emits DOWN, MOVE and UP events with a single stationary pointer coordinate.
  1.1501 +            PRESS,
  1.1502 +
  1.1503 +            // Exactly two fingers moving in the same direction, button is not pressed.
  1.1504 +            // Pointer does not move.
  1.1505 +            // Emits DOWN, MOVE and UP events with a single pointer coordinate that
  1.1506 +            // follows the midpoint between both fingers.
  1.1507 +            SWIPE,
  1.1508 +
  1.1509 +            // Two or more fingers moving in arbitrary directions, button is not pressed.
  1.1510 +            // Pointer does not move.
  1.1511 +            // Emits DOWN, POINTER_DOWN, MOVE, POINTER_UP and UP events that follow
  1.1512 +            // each finger individually relative to the initial centroid of the finger.
  1.1513 +            FREEFORM,
  1.1514 +
  1.1515 +            // Waiting for quiet time to end before starting the next gesture.
  1.1516 +            QUIET,
  1.1517 +        };
  1.1518 +
  1.1519 +        // Time the first finger went down.
  1.1520 +        nsecs_t firstTouchTime;
  1.1521 +
  1.1522 +        // The active pointer id from the raw touch data.
  1.1523 +        int32_t activeTouchId; // -1 if none
  1.1524 +
  1.1525 +        // The active pointer id from the gesture last delivered to the application.
  1.1526 +        int32_t activeGestureId; // -1 if none
  1.1527 +
  1.1528 +        // Pointer coords and ids for the current and previous pointer gesture.
  1.1529 +        Mode currentGestureMode;
  1.1530 +        BitSet32 currentGestureIdBits;
  1.1531 +        uint32_t currentGestureIdToIndex[MAX_POINTER_ID + 1];
  1.1532 +        PointerProperties currentGestureProperties[MAX_POINTERS];
  1.1533 +        PointerCoords currentGestureCoords[MAX_POINTERS];
  1.1534 +
  1.1535 +        Mode lastGestureMode;
  1.1536 +        BitSet32 lastGestureIdBits;
  1.1537 +        uint32_t lastGestureIdToIndex[MAX_POINTER_ID + 1];
  1.1538 +        PointerProperties lastGestureProperties[MAX_POINTERS];
  1.1539 +        PointerCoords lastGestureCoords[MAX_POINTERS];
  1.1540 +
  1.1541 +        // Time the pointer gesture last went down.
  1.1542 +        nsecs_t downTime;
  1.1543 +
  1.1544 +        // Time when the pointer went down for a TAP.
  1.1545 +        nsecs_t tapDownTime;
  1.1546 +
  1.1547 +        // Time when the pointer went up for a TAP.
  1.1548 +        nsecs_t tapUpTime;
  1.1549 +
  1.1550 +        // Location of initial tap.
  1.1551 +        float tapX, tapY;
  1.1552 +
  1.1553 +        // Time we started waiting for quiescence.
  1.1554 +        nsecs_t quietTime;
  1.1555 +
  1.1556 +        // Reference points for multitouch gestures.
  1.1557 +        float referenceTouchX;    // reference touch X/Y coordinates in surface units
  1.1558 +        float referenceTouchY;
  1.1559 +        float referenceGestureX;  // reference gesture X/Y coordinates in pixels
  1.1560 +        float referenceGestureY;
  1.1561 +
  1.1562 +        // Distance that each pointer has traveled which has not yet been
  1.1563 +        // subsumed into the reference gesture position.
  1.1564 +        BitSet32 referenceIdBits;
  1.1565 +        struct Delta {
  1.1566 +            float dx, dy;
  1.1567 +        };
  1.1568 +        Delta referenceDeltas[MAX_POINTER_ID + 1];
  1.1569 +
  1.1570 +        // Describes how touch ids are mapped to gesture ids for freeform gestures.
  1.1571 +        uint32_t freeformTouchToGestureIdMap[MAX_POINTER_ID + 1];
  1.1572 +
  1.1573 +        // A velocity tracker for determining whether to switch active pointers during drags.
  1.1574 +        VelocityTracker velocityTracker;
  1.1575 +
  1.1576 +        void reset() {
  1.1577 +            firstTouchTime = LLONG_MIN;
  1.1578 +            activeTouchId = -1;
  1.1579 +            activeGestureId = -1;
  1.1580 +            currentGestureMode = NEUTRAL;
  1.1581 +            currentGestureIdBits.clear();
  1.1582 +            lastGestureMode = NEUTRAL;
  1.1583 +            lastGestureIdBits.clear();
  1.1584 +            downTime = 0;
  1.1585 +            velocityTracker.clear();
  1.1586 +            resetTap();
  1.1587 +            resetQuietTime();
  1.1588 +        }
  1.1589 +
  1.1590 +        void resetTap() {
  1.1591 +            tapDownTime = LLONG_MIN;
  1.1592 +            tapUpTime = LLONG_MIN;
  1.1593 +        }
  1.1594 +
  1.1595 +        void resetQuietTime() {
  1.1596 +            quietTime = LLONG_MIN;
  1.1597 +        }
  1.1598 +    } mPointerGesture;
  1.1599 +
  1.1600 +    struct PointerSimple {
  1.1601 +        PointerCoords currentCoords;
  1.1602 +        PointerProperties currentProperties;
  1.1603 +        PointerCoords lastCoords;
  1.1604 +        PointerProperties lastProperties;
  1.1605 +
  1.1606 +        // True if the pointer is down.
  1.1607 +        bool down;
  1.1608 +
  1.1609 +        // True if the pointer is hovering.
  1.1610 +        bool hovering;
  1.1611 +
  1.1612 +        // Time the pointer last went down.
  1.1613 +        nsecs_t downTime;
  1.1614 +
  1.1615 +        void reset() {
  1.1616 +            currentCoords.clear();
  1.1617 +            currentProperties.clear();
  1.1618 +            lastCoords.clear();
  1.1619 +            lastProperties.clear();
  1.1620 +            down = false;
  1.1621 +            hovering = false;
  1.1622 +            downTime = 0;
  1.1623 +        }
  1.1624 +    } mPointerSimple;
  1.1625 +
  1.1626 +    // The pointer and scroll velocity controls.
  1.1627 +    VelocityControl mPointerVelocityControl;
  1.1628 +    VelocityControl mWheelXVelocityControl;
  1.1629 +    VelocityControl mWheelYVelocityControl;
  1.1630 +
  1.1631 +    void sync(nsecs_t when);
  1.1632 +
  1.1633 +    bool consumeRawTouches(nsecs_t when, uint32_t policyFlags);
  1.1634 +    void dispatchVirtualKey(nsecs_t when, uint32_t policyFlags,
  1.1635 +            int32_t keyEventAction, int32_t keyEventFlags);
  1.1636 +
  1.1637 +    void dispatchTouches(nsecs_t when, uint32_t policyFlags);
  1.1638 +    void dispatchHoverExit(nsecs_t when, uint32_t policyFlags);
  1.1639 +    void dispatchHoverEnterAndMove(nsecs_t when, uint32_t policyFlags);
  1.1640 +    void cookPointerData();
  1.1641 +
  1.1642 +    void dispatchPointerUsage(nsecs_t when, uint32_t policyFlags, PointerUsage pointerUsage);
  1.1643 +    void abortPointerUsage(nsecs_t when, uint32_t policyFlags);
  1.1644 +
  1.1645 +    void dispatchPointerGestures(nsecs_t when, uint32_t policyFlags, bool isTimeout);
  1.1646 +    void abortPointerGestures(nsecs_t when, uint32_t policyFlags);
  1.1647 +    bool preparePointerGestures(nsecs_t when,
  1.1648 +            bool* outCancelPreviousGesture, bool* outFinishPreviousGesture,
  1.1649 +            bool isTimeout);
  1.1650 +
  1.1651 +    void dispatchPointerStylus(nsecs_t when, uint32_t policyFlags);
  1.1652 +    void abortPointerStylus(nsecs_t when, uint32_t policyFlags);
  1.1653 +
  1.1654 +    void dispatchPointerMouse(nsecs_t when, uint32_t policyFlags);
  1.1655 +    void abortPointerMouse(nsecs_t when, uint32_t policyFlags);
  1.1656 +
  1.1657 +    void dispatchPointerSimple(nsecs_t when, uint32_t policyFlags,
  1.1658 +            bool down, bool hovering);
  1.1659 +    void abortPointerSimple(nsecs_t when, uint32_t policyFlags);
  1.1660 +
  1.1661 +    // Dispatches a motion event.
  1.1662 +    // If the changedId is >= 0 and the action is POINTER_DOWN or POINTER_UP, the
  1.1663 +    // method will take care of setting the index and transmuting the action to DOWN or UP
  1.1664 +    // it is the first / last pointer to go down / up.
  1.1665 +    void dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32_t source,
  1.1666 +            int32_t action, int32_t flags, int32_t metaState, int32_t buttonState,
  1.1667 +            int32_t edgeFlags,
  1.1668 +            const PointerProperties* properties, const PointerCoords* coords,
  1.1669 +            const uint32_t* idToIndex, BitSet32 idBits,
  1.1670 +            int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime);
  1.1671 +
  1.1672 +    // Updates pointer coords and properties for pointers with specified ids that have moved.
  1.1673 +    // Returns true if any of them changed.
  1.1674 +    bool updateMovedPointers(const PointerProperties* inProperties,
  1.1675 +            const PointerCoords* inCoords, const uint32_t* inIdToIndex,
  1.1676 +            PointerProperties* outProperties, PointerCoords* outCoords,
  1.1677 +            const uint32_t* outIdToIndex, BitSet32 idBits) const;
  1.1678 +
  1.1679 +    bool isPointInsideSurface(int32_t x, int32_t y);
  1.1680 +    const VirtualKey* findVirtualKeyHit(int32_t x, int32_t y);
  1.1681 +
  1.1682 +    void assignPointerIds();
  1.1683 +};
  1.1684 +
  1.1685 +
  1.1686 +class SingleTouchInputMapper : public TouchInputMapper {
  1.1687 +public:
  1.1688 +    SingleTouchInputMapper(InputDevice* device);
  1.1689 +    virtual ~SingleTouchInputMapper();
  1.1690 +
  1.1691 +    virtual void reset(nsecs_t when);
  1.1692 +    virtual void process(const RawEvent* rawEvent);
  1.1693 +
  1.1694 +protected:
  1.1695 +    virtual void syncTouch(nsecs_t when, bool* outHavePointerIds);
  1.1696 +    virtual void configureRawPointerAxes();
  1.1697 +    virtual bool hasStylus() const;
  1.1698 +
  1.1699 +private:
  1.1700 +    SingleTouchMotionAccumulator mSingleTouchMotionAccumulator;
  1.1701 +};
  1.1702 +
  1.1703 +
  1.1704 +class MultiTouchInputMapper : public TouchInputMapper {
  1.1705 +public:
  1.1706 +    MultiTouchInputMapper(InputDevice* device);
  1.1707 +    virtual ~MultiTouchInputMapper();
  1.1708 +
  1.1709 +    virtual void reset(nsecs_t when);
  1.1710 +    virtual void process(const RawEvent* rawEvent);
  1.1711 +
  1.1712 +protected:
  1.1713 +    virtual void syncTouch(nsecs_t when, bool* outHavePointerIds);
  1.1714 +    virtual void configureRawPointerAxes();
  1.1715 +    virtual bool hasStylus() const;
  1.1716 +
  1.1717 +private:
  1.1718 +    MultiTouchMotionAccumulator mMultiTouchMotionAccumulator;
  1.1719 +
  1.1720 +    // Specifies the pointer id bits that are in use, and their associated tracking id.
  1.1721 +    BitSet32 mPointerIdBits;
  1.1722 +    int32_t mPointerTrackingIdMap[MAX_POINTER_ID + 1];
  1.1723 +};
  1.1724 +
  1.1725 +
  1.1726 +class JoystickInputMapper : public InputMapper {
  1.1727 +public:
  1.1728 +    JoystickInputMapper(InputDevice* device);
  1.1729 +    virtual ~JoystickInputMapper();
  1.1730 +
  1.1731 +    virtual uint32_t getSources();
  1.1732 +    virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
  1.1733 +    virtual void dump(String8& dump);
  1.1734 +    virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
  1.1735 +    virtual void reset(nsecs_t when);
  1.1736 +    virtual void process(const RawEvent* rawEvent);
  1.1737 +
  1.1738 +private:
  1.1739 +    struct Axis {
  1.1740 +        RawAbsoluteAxisInfo rawAxisInfo;
  1.1741 +        AxisInfo axisInfo;
  1.1742 +
  1.1743 +        bool explicitlyMapped; // true if the axis was explicitly assigned an axis id
  1.1744 +
  1.1745 +        float scale;   // scale factor from raw to normalized values
  1.1746 +        float offset;  // offset to add after scaling for normalization
  1.1747 +        float highScale;  // scale factor from raw to normalized values of high split
  1.1748 +        float highOffset; // offset to add after scaling for normalization of high split
  1.1749 +
  1.1750 +        float min;        // normalized inclusive minimum
  1.1751 +        float max;        // normalized inclusive maximum
  1.1752 +        float flat;       // normalized flat region size
  1.1753 +        float fuzz;       // normalized error tolerance
  1.1754 +        float resolution; // normalized resolution in units/mm
  1.1755 +
  1.1756 +        float filter;  // filter out small variations of this size
  1.1757 +        float currentValue; // current value
  1.1758 +        float newValue; // most recent value
  1.1759 +        float highCurrentValue; // current value of high split
  1.1760 +        float highNewValue; // most recent value of high split
  1.1761 +
  1.1762 +        void initialize(const RawAbsoluteAxisInfo& rawAxisInfo, const AxisInfo& axisInfo,
  1.1763 +                bool explicitlyMapped, float scale, float offset,
  1.1764 +                float highScale, float highOffset,
  1.1765 +                float min, float max, float flat, float fuzz, float resolution) {
  1.1766 +            this->rawAxisInfo = rawAxisInfo;
  1.1767 +            this->axisInfo = axisInfo;
  1.1768 +            this->explicitlyMapped = explicitlyMapped;
  1.1769 +            this->scale = scale;
  1.1770 +            this->offset = offset;
  1.1771 +            this->highScale = highScale;
  1.1772 +            this->highOffset = highOffset;
  1.1773 +            this->min = min;
  1.1774 +            this->max = max;
  1.1775 +            this->flat = flat;
  1.1776 +            this->fuzz = fuzz;
  1.1777 +            this->resolution = resolution;
  1.1778 +            this->filter = 0;
  1.1779 +            resetValue();
  1.1780 +        }
  1.1781 +
  1.1782 +        void resetValue() {
  1.1783 +            this->currentValue = 0;
  1.1784 +            this->newValue = 0;
  1.1785 +            this->highCurrentValue = 0;
  1.1786 +            this->highNewValue = 0;
  1.1787 +        }
  1.1788 +    };
  1.1789 +
  1.1790 +    // Axes indexed by raw ABS_* axis index.
  1.1791 +    KeyedVector<int32_t, Axis> mAxes;
  1.1792 +
  1.1793 +    void sync(nsecs_t when, bool force);
  1.1794 +
  1.1795 +    bool haveAxis(int32_t axisId);
  1.1796 +    void pruneAxes(bool ignoreExplicitlyMappedAxes);
  1.1797 +    bool filterAxes(bool force);
  1.1798 +
  1.1799 +    static bool hasValueChangedSignificantly(float filter,
  1.1800 +            float newValue, float currentValue, float min, float max);
  1.1801 +    static bool hasMovedNearerToValueWithinFilteredRange(float filter,
  1.1802 +            float newValue, float currentValue, float thresholdValue);
  1.1803 +
  1.1804 +    static bool isCenteredAxis(int32_t axis);
  1.1805 +    static int32_t getCompatAxis(int32_t axis);
  1.1806 +
  1.1807 +    static void addMotionRange(int32_t axisId, const Axis& axis, InputDeviceInfo* info);
  1.1808 +    static void setPointerCoordsAxisValue(PointerCoords* pointerCoords, int32_t axis,
  1.1809 +            float value);
  1.1810 +};
  1.1811 +
  1.1812 +} // namespace android
  1.1813 +
  1.1814 +#endif // _UI_INPUT_READER_H

mercurial