Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b7efb89e authored by Jeff Brown's avatar Jeff Brown Committed by Android Git Automerger
Browse files

am 860c2df4: Merge "Add unit tests for native input and fix bugs identified." into gingerbread

Merge commit '860c2df4132a2a0be9bcb0e91bfb7e79588c000f' into gingerbread-plus-aosp

* commit '860c2df4132a2a0be9bcb0e91bfb7e79588c000f':
  Add unit tests for native input and fix bugs identified.
parents 61d622ea f35c8735
Loading
Loading
Loading
Loading
+23 −5
Original line number Original line Diff line number Diff line
@@ -170,11 +170,10 @@ public:
 * and parameters maintained by the input reader.
 * and parameters maintained by the input reader.
 */
 */
class InputReaderContext {
class InputReaderContext {
protected:
public:
    InputReaderContext() { }
    InputReaderContext() { }
    virtual ~InputReaderContext() { }
    virtual ~InputReaderContext() { }


public:
    virtual void updateGlobalMetaState() = 0;
    virtual void updateGlobalMetaState() = 0;
    virtual int32_t getGlobalMetaState() = 0;
    virtual int32_t getGlobalMetaState() = 0;


@@ -193,7 +192,7 @@ public:
 *     the input reader, the input reader never calls into other components while holding
 *     the input reader, the input reader never calls into other components while holding
 *     an exclusive internal lock whenever re-entrance can happen.
 *     an exclusive internal lock whenever re-entrance can happen.
 */
 */
class InputReader : public InputReaderInterface, private InputReaderContext {
class InputReader : public InputReaderInterface, protected InputReaderContext {
public:
public:
    InputReader(const sp<EventHubInterface>& eventHub,
    InputReader(const sp<EventHubInterface>& eventHub,
            const sp<InputReaderPolicyInterface>& policy,
            const sp<InputReaderPolicyInterface>& policy,
@@ -219,6 +218,11 @@ public:
    virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask,
    virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask,
            size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags);
            size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags);


protected:
    // These methods are protected virtual so they can be overridden and instrumented
    // by test cases.
    virtual InputDevice* createDevice(int32_t deviceId, const String8& name, uint32_t classes);

private:
private:
    sp<EventHubInterface> mEventHub;
    sp<EventHubInterface> mEventHub;
    sp<InputReaderPolicyInterface> mPolicy;
    sp<InputReaderPolicyInterface> mPolicy;
@@ -244,12 +248,11 @@ private:


    void addDevice(int32_t deviceId);
    void addDevice(int32_t deviceId);
    void removeDevice(int32_t deviceId);
    void removeDevice(int32_t deviceId);
    InputDevice* createDevice(int32_t deviceId, const String8& name, uint32_t classes);
    void configureExcludedDevices();
    void configureExcludedDevices();


    void consumeEvent(const RawEvent* rawEvent);
    void consumeEvent(const RawEvent* rawEvent);


    void handleConfigurationChanged();
    void handleConfigurationChanged(nsecs_t when);


    // state management for all devices
    // state management for all devices
    Mutex mStateLock;
    Mutex mStateLock;
@@ -533,6 +536,21 @@ protected:
        int32_t toolMajor;
        int32_t toolMajor;
        int32_t toolMinor;
        int32_t toolMinor;
        int32_t orientation;
        int32_t orientation;

        inline bool operator== (const PointerData& other) const {
            return id == other.id
                    && x == other.x
                    && y == other.y
                    && pressure == other.pressure
                    && touchMajor == other.touchMajor
                    && touchMinor == other.touchMinor
                    && toolMajor == other.toolMajor
                    && toolMinor == other.toolMinor
                    && orientation == other.orientation;
        }
        inline bool operator!= (const PointerData& other) const {
            return !(*this == other);
        }
    };
    };


    // Raw data for a collection of pointers including a pointer id mapping table.
    // Raw data for a collection of pointers including a pointer id mapping table.
+3 −0
Original line number Original line Diff line number Diff line
@@ -370,6 +370,7 @@ bool EventHub::getEvent(RawEvent* outEvent)
                outEvent->deviceId = device->id;
                outEvent->deviceId = device->id;
            }
            }
            outEvent->type = DEVICE_REMOVED;
            outEvent->type = DEVICE_REMOVED;
            outEvent->when = systemTime(SYSTEM_TIME_MONOTONIC);
            delete device;
            delete device;
            mNeedToSendFinishedDeviceScan = true;
            mNeedToSendFinishedDeviceScan = true;
            return true;
            return true;
@@ -386,6 +387,7 @@ bool EventHub::getEvent(RawEvent* outEvent)
                outEvent->deviceId = device->id;
                outEvent->deviceId = device->id;
            }
            }
            outEvent->type = DEVICE_ADDED;
            outEvent->type = DEVICE_ADDED;
            outEvent->when = systemTime(SYSTEM_TIME_MONOTONIC);
            mNeedToSendFinishedDeviceScan = true;
            mNeedToSendFinishedDeviceScan = true;
            return true;
            return true;
        }
        }
@@ -393,6 +395,7 @@ bool EventHub::getEvent(RawEvent* outEvent)
        if (mNeedToSendFinishedDeviceScan) {
        if (mNeedToSendFinishedDeviceScan) {
            mNeedToSendFinishedDeviceScan = false;
            mNeedToSendFinishedDeviceScan = false;
            outEvent->type = FINISHED_DEVICE_SCAN;
            outEvent->type = FINISHED_DEVICE_SCAN;
            outEvent->when = systemTime(SYSTEM_TIME_MONOTONIC);
            return true;
            return true;
        }
        }


+9 −2
Original line number Original line Diff line number Diff line
@@ -124,12 +124,19 @@ static bool validateMotionEvent(int32_t action, size_t pointerCount,
                pointerCount, MAX_POINTERS);
                pointerCount, MAX_POINTERS);
        return false;
        return false;
    }
    }
    BitSet32 pointerIdBits;
    for (size_t i = 0; i < pointerCount; i++) {
    for (size_t i = 0; i < pointerCount; i++) {
        if (pointerIds[i] < 0 || pointerIds[i] > MAX_POINTER_ID) {
        int32_t id = pointerIds[i];
        if (id < 0 || id > MAX_POINTER_ID) {
            LOGE("Motion event has invalid pointer id %d; value must be between 0 and %d",
            LOGE("Motion event has invalid pointer id %d; value must be between 0 and %d",
                    pointerIds[i], MAX_POINTER_ID);
                    id, MAX_POINTER_ID);
            return false;
            return false;
        }
        }
        if (pointerIdBits.hasBit(id)) {
            LOGE("Motion event has duplicate pointer id %d", id);
            return false;
        }
        pointerIdBits.markBit(id);
    }
    }
    return true;
    return true;
}
}
+55 −16
Original line number Original line Diff line number Diff line
@@ -234,7 +234,7 @@ void InputReader::process(const RawEvent* rawEvent) {
        break;
        break;


    case EventHubInterface::FINISHED_DEVICE_SCAN:
    case EventHubInterface::FINISHED_DEVICE_SCAN:
        handleConfigurationChanged();
        handleConfigurationChanged(rawEvent->when);
        break;
        break;


    default:
    default:
@@ -372,7 +372,7 @@ void InputReader::consumeEvent(const RawEvent* rawEvent) {
    } // release device registry reader lock
    } // release device registry reader lock
}
}


void InputReader::handleConfigurationChanged() {
void InputReader::handleConfigurationChanged(nsecs_t when) {
    // Reset global meta state because it depends on the list of all configured devices.
    // Reset global meta state because it depends on the list of all configured devices.
    updateGlobalMetaState();
    updateGlobalMetaState();


@@ -380,7 +380,6 @@ void InputReader::handleConfigurationChanged() {
    updateInputConfiguration();
    updateInputConfiguration();


    // Enqueue configuration changed.
    // Enqueue configuration changed.
    nsecs_t when = systemTime(SYSTEM_TIME_MONOTONIC);
    mDispatcher->notifyConfigurationChanged(when);
    mDispatcher->notifyConfigurationChanged(when);
}
}


@@ -2094,7 +2093,7 @@ TouchInputMapper::TouchResult TouchInputMapper::consumeOffScreenTouches(
                mLocked.currentVirtualKey.down = false;
                mLocked.currentVirtualKey.down = false;
#if DEBUG_VIRTUAL_KEYS
#if DEBUG_VIRTUAL_KEYS
                LOGD("VirtualKeys: Generating key up: keyCode=%d, scanCode=%d",
                LOGD("VirtualKeys: Generating key up: keyCode=%d, scanCode=%d",
                        mCurrentVirtualKey.keyCode, mCurrentVirtualKey.scanCode);
                        mLocked.currentVirtualKey.keyCode, mLocked.currentVirtualKey.scanCode);
#endif
#endif
                keyEventAction = AKEY_EVENT_ACTION_UP;
                keyEventAction = AKEY_EVENT_ACTION_UP;
                keyEventFlags = AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY;
                keyEventFlags = AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY;
@@ -2119,13 +2118,22 @@ TouchInputMapper::TouchResult TouchInputMapper::consumeOffScreenTouches(
            mLocked.currentVirtualKey.down = false;
            mLocked.currentVirtualKey.down = false;
#if DEBUG_VIRTUAL_KEYS
#if DEBUG_VIRTUAL_KEYS
            LOGD("VirtualKeys: Canceling key: keyCode=%d, scanCode=%d",
            LOGD("VirtualKeys: Canceling key: keyCode=%d, scanCode=%d",
                    mCurrentVirtualKey.keyCode, mCurrentVirtualKey.scanCode);
                    mLocked.currentVirtualKey.keyCode, mLocked.currentVirtualKey.scanCode);
#endif
#endif
            keyEventAction = AKEY_EVENT_ACTION_UP;
            keyEventAction = AKEY_EVENT_ACTION_UP;
            keyEventFlags = AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY
            keyEventFlags = AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY
                    | AKEY_EVENT_FLAG_CANCELED;
                    | AKEY_EVENT_FLAG_CANCELED;

            // Check whether the pointer moved inside the display area where we should
            // start a new stroke.
            int32_t x = mCurrentTouch.pointers[0].x;
            int32_t y = mCurrentTouch.pointers[0].y;
            if (isPointInsideSurfaceLocked(x, y)) {
                mLastTouch.clear();
                touchResult = DISPATCH_TOUCH;
            } else {
                touchResult = DROP_STROKE;
                touchResult = DROP_STROKE;
            goto DispatchVirtualKey;
            }
        } else {
        } else {
            if (mCurrentTouch.pointerCount >= 1 && mLastTouch.pointerCount == 0) {
            if (mCurrentTouch.pointerCount >= 1 && mLastTouch.pointerCount == 0) {
                // Pointer just went down.  Handle off-screen touches, if needed.
                // Pointer just went down.  Handle off-screen touches, if needed.
@@ -2143,7 +2151,8 @@ TouchInputMapper::TouchResult TouchInputMapper::consumeOffScreenTouches(
                            mLocked.currentVirtualKey.scanCode = virtualKey->scanCode;
                            mLocked.currentVirtualKey.scanCode = virtualKey->scanCode;
#if DEBUG_VIRTUAL_KEYS
#if DEBUG_VIRTUAL_KEYS
                            LOGD("VirtualKeys: Generating key down: keyCode=%d, scanCode=%d",
                            LOGD("VirtualKeys: Generating key down: keyCode=%d, scanCode=%d",
                                    mCurrentVirtualKey.keyCode, mCurrentVirtualKey.scanCode);
                                    mLocked.currentVirtualKey.keyCode,
                                    mLocked.currentVirtualKey.scanCode);
#endif
#endif
                            keyEventAction = AKEY_EVENT_ACTION_DOWN;
                            keyEventAction = AKEY_EVENT_ACTION_DOWN;
                            keyEventFlags = AKEY_EVENT_FLAG_FROM_SYSTEM
                            keyEventFlags = AKEY_EVENT_FLAG_FROM_SYSTEM
@@ -2190,13 +2199,34 @@ void TouchInputMapper::dispatchTouches(nsecs_t when, uint32_t policyFlags) {
        dispatchTouch(when, policyFlags, & mCurrentTouch,
        dispatchTouch(when, policyFlags, & mCurrentTouch,
                currentIdBits, -1, currentPointerCount, motionEventAction);
                currentIdBits, -1, currentPointerCount, motionEventAction);
    } else {
    } else {
        // There may be pointers going up and pointers going down at the same time when pointer
        // There may be pointers going up and pointers going down and pointers moving
        // ids are reported by the device driver.
        // all at the same time.
        BitSet32 upIdBits(lastIdBits.value & ~ currentIdBits.value);
        BitSet32 upIdBits(lastIdBits.value & ~ currentIdBits.value);
        BitSet32 downIdBits(currentIdBits.value & ~ lastIdBits.value);
        BitSet32 downIdBits(currentIdBits.value & ~ lastIdBits.value);
        BitSet32 activeIdBits(lastIdBits.value);
        BitSet32 activeIdBits(lastIdBits.value);
        uint32_t pointerCount = lastPointerCount;
        uint32_t pointerCount = lastPointerCount;


        // Produce an intermediate representation of the touch data that consists of the
        // old location of pointers that have just gone up and the new location of pointers that
        // have just moved but omits the location of pointers that have just gone down.
        TouchData interimTouch;
        interimTouch.copyFrom(mLastTouch);

        BitSet32 moveIdBits(lastIdBits.value & currentIdBits.value);
        bool moveNeeded = false;
        while (!moveIdBits.isEmpty()) {
            uint32_t moveId = moveIdBits.firstMarkedBit();
            moveIdBits.clearBit(moveId);

            int32_t oldIndex = mLastTouch.idToIndex[moveId];
            int32_t newIndex = mCurrentTouch.idToIndex[moveId];
            if (mLastTouch.pointers[oldIndex] != mCurrentTouch.pointers[newIndex]) {
                interimTouch.pointers[oldIndex] = mCurrentTouch.pointers[newIndex];
                moveNeeded = true;
            }
        }

        // Dispatch pointer up events using the interim pointer locations.
        while (!upIdBits.isEmpty()) {
        while (!upIdBits.isEmpty()) {
            uint32_t upId = upIdBits.firstMarkedBit();
            uint32_t upId = upIdBits.firstMarkedBit();
            upIdBits.clearBit(upId);
            upIdBits.clearBit(upId);
@@ -2210,11 +2240,20 @@ void TouchInputMapper::dispatchTouches(nsecs_t when, uint32_t policyFlags) {
                motionEventAction = AMOTION_EVENT_ACTION_POINTER_UP;
                motionEventAction = AMOTION_EVENT_ACTION_POINTER_UP;
            }
            }


            dispatchTouch(when, policyFlags, & mLastTouch,
            dispatchTouch(when, policyFlags, &interimTouch,
                    oldActiveIdBits, upId, pointerCount, motionEventAction);
                    oldActiveIdBits, upId, pointerCount, motionEventAction);
            pointerCount -= 1;
            pointerCount -= 1;
        }
        }


        // Dispatch move events if any of the remaining pointers moved from their old locations.
        // Although applications receive new locations as part of individual pointer up
        // events, they do not generally handle them except when presented in a move event.
        if (moveNeeded) {
            dispatchTouch(when, policyFlags, &mCurrentTouch,
                    activeIdBits, -1, pointerCount, AMOTION_EVENT_ACTION_MOVE);
        }

        // Dispatch pointer down events using the new pointer locations.
        while (!downIdBits.isEmpty()) {
        while (!downIdBits.isEmpty()) {
            uint32_t downId = downIdBits.firstMarkedBit();
            uint32_t downId = downIdBits.firstMarkedBit();
            downIdBits.clearBit(downId);
            downIdBits.clearBit(downId);
@@ -3339,8 +3378,8 @@ void MultiTouchInputMapper::sync(nsecs_t when) {


        if (fields & Accumulator::FIELD_ABS_MT_PRESSURE) {
        if (fields & Accumulator::FIELD_ABS_MT_PRESSURE) {
            if (inPointer.absMTPressure <= 0) {
            if (inPointer.absMTPressure <= 0) {
                // Some devices send sync packets with X / Y but with a 0 presure to indicate
                // Some devices send sync packets with X / Y but with a 0 pressure to indicate
                // a pointer up.  Drop this finger.
                // a pointer going up.  Drop this finger.
                continue;
                continue;
            }
            }
            outPointer.pressure = inPointer.absMTPressure;
            outPointer.pressure = inPointer.absMTPressure;
+1 −0
Original line number Original line Diff line number Diff line
@@ -7,6 +7,7 @@ ifneq ($(TARGET_SIMULATOR),true)
# Build the unit tests.
# Build the unit tests.
test_src_files := \
test_src_files := \
    InputChannel_test.cpp \
    InputChannel_test.cpp \
    InputReader_test.cpp \
    InputDispatcher_test.cpp \
    InputDispatcher_test.cpp \
    InputPublisherAndConsumer_test.cpp
    InputPublisherAndConsumer_test.cpp


Loading