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

Commit f2f073b6 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Revert "Send mapper events via context"

This reverts commit cec3f6a9.

As we discussed with Chris and Michael, it is more natural to keep the
flow of inputreader -> inputdevice -> inputmapper -> inputlistener
rather than having to come back to inputreader.

This also reduces the redundancy of having to mimic the inputlistener
interface inside the inputreader context.

Bug: 169866723
Test: atest inputflinger_tests
Change-Id: I4244947810d99ff40cfffaa34f6374aa18a238c6
parent 1c69780e
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -520,7 +520,8 @@ void InputDevice::bumpGeneration() {
}

void InputDevice::notifyReset(nsecs_t when) {
    mContext->notifyDeviceReset(when, mId);
    NotifyDeviceResetArgs args(mContext->getNextId(), when, mId);
    mContext->getListener()->notifyDeviceReset(&args);
}

std::optional<int32_t> InputDevice::getAssociatedDisplayId() {
+11 −61
Original line number Diff line number Diff line
@@ -339,7 +339,8 @@ void InputReader::handleConfigurationChangedLocked(nsecs_t when) {
    updateGlobalMetaStateLocked();

    // Enqueue configuration changed.
    mContext.notifyConfigurationChanged(when);
    NotifyConfigurationChangedArgs args(mContext.getNextId(), when);
    mQueuedListener->notifyConfigurationChanged(&args);
}

void InputReader::refreshConfigurationLocked(uint32_t changes) {
@@ -366,7 +367,9 @@ void InputReader::refreshConfigurationLocked(uint32_t changes) {
    }

    if (changes & InputReaderConfiguration::CHANGE_POINTER_CAPTURE) {
        mContext.notifyPointerCaptureChanged(now, mConfig.pointerCapture);
        const NotifyPointerCaptureChangedArgs args(mContext.getNextId(), now,
                                                   mConfig.pointerCapture);
        mQueuedListener->notifyPointerCaptureChanged(&args);
    }
}

@@ -885,69 +888,16 @@ InputReaderPolicyInterface* InputReader::ContextImpl::getPolicy() {
    return mReader->mPolicy.get();
}

EventHubInterface* InputReader::ContextImpl::getEventHub() {
    return mReader->mEventHub.get();
}

void InputReader::ContextImpl::notifyConfigurationChanged(nsecs_t when) {
    NotifyConfigurationChangedArgs args(mIdGenerator.nextId(), when);
    mReader->mQueuedListener->notifyConfigurationChanged(&args);
InputListenerInterface* InputReader::ContextImpl::getListener() {
    return mReader->mQueuedListener.get();
}

void InputReader::ContextImpl::notifyKey(nsecs_t eventTime, int32_t deviceId, uint32_t source,
                                         int32_t displayId, uint32_t policyFlags, int32_t action,
                                         int32_t flags, int32_t keyCode, int32_t scanCode,
                                         int32_t metaState, nsecs_t downTime) {
    NotifyKeyArgs args(mIdGenerator.nextId(), eventTime, deviceId, source, displayId, policyFlags,
                       action, flags, keyCode, scanCode, metaState, downTime);
    mReader->mQueuedListener->notifyKey(&args);
}
void InputReader::ContextImpl::notifyMotion(
        nsecs_t eventTime, int32_t deviceId, uint32_t source, int32_t displayId,
        uint32_t policyFlags, int32_t action, int32_t actionButton, int32_t flags,
        int32_t metaState, int32_t buttonState, MotionClassification classification,
        int32_t edgeFlags, uint32_t pointerCount, const PointerProperties* pointerProperties,
        const PointerCoords* pointerCoords, float xPrecision, float yPrecision,
        float xCursorPosition, float yCursorPosition, nsecs_t downTime,
        const std::vector<TouchVideoFrame>& videoFrames) {
    NotifyMotionArgs args(mIdGenerator.nextId(), eventTime, deviceId, source, displayId,
                          policyFlags, action, actionButton, flags, metaState, buttonState,
                          classification, edgeFlags, pointerCount, pointerProperties, pointerCoords,
                          xPrecision, yPrecision, xCursorPosition, yCursorPosition, downTime,
                          videoFrames);
    mReader->mQueuedListener->notifyMotion(&args);
}

void InputReader::ContextImpl::notifySensor(nsecs_t when, int32_t deviceId,
                                            InputDeviceSensorType sensorType,
                                            InputDeviceSensorAccuracy accuracy,
                                            bool accuracyChanged, nsecs_t timestamp,
                                            std::vector<float> values) {
    NotifySensorArgs args(mIdGenerator.nextId(), when, deviceId, AINPUT_SOURCE_SENSOR, sensorType,
                          accuracy, accuracyChanged, timestamp, std::move(values));
    mReader->mQueuedListener->notifySensor(&args);
}

void InputReader::ContextImpl::notifyVibratorState(nsecs_t when, int32_t deviceId, bool isOn) {
    NotifyVibratorStateArgs args(mIdGenerator.nextId(), when, deviceId, isOn);
    mReader->mQueuedListener->notifyVibratorState(&args);
}

void InputReader::ContextImpl::notifySwitch(nsecs_t eventTime, uint32_t switchValues,
                                            uint32_t switchMask) {
    NotifySwitchArgs args(mIdGenerator.nextId(), eventTime, 0 /*policyFlags*/, switchValues,
                          switchMask);
    mReader->mQueuedListener->notifySwitch(&args);
}

void InputReader::ContextImpl::notifyDeviceReset(nsecs_t when, int32_t deviceId) {
    NotifyDeviceResetArgs args(mIdGenerator.nextId(), when, deviceId);
    mReader->mQueuedListener->notifyDeviceReset(&args);
EventHubInterface* InputReader::ContextImpl::getEventHub() {
    return mReader->mEventHub.get();
}

void InputReader::ContextImpl::notifyPointerCaptureChanged(nsecs_t when, bool hasCapture) {
    const NotifyPointerCaptureChangedArgs args(mIdGenerator.nextId(), when, hasCapture);
    mReader->mQueuedListener->notifyPointerCaptureChanged(&args);
int32_t InputReader::ContextImpl::getNextId() {
    return mIdGenerator.nextId();
}

} // namespace android
+2 −22
Original line number Diff line number Diff line
@@ -131,31 +131,11 @@ protected:
        void dispatchExternalStylusState(const StylusState& outState)
                NO_THREAD_SAFETY_ANALYSIS override;
        InputReaderPolicyInterface* getPolicy() NO_THREAD_SAFETY_ANALYSIS override;
        InputListenerInterface* getListener() NO_THREAD_SAFETY_ANALYSIS override;
        EventHubInterface* getEventHub() NO_THREAD_SAFETY_ANALYSIS override;
        int32_t getNextId() NO_THREAD_SAFETY_ANALYSIS override;
        void updateLedMetaState(int32_t metaState) NO_THREAD_SAFETY_ANALYSIS override;
        int32_t getLedMetaState() NO_THREAD_SAFETY_ANALYSIS override;

        // Send events to InputListener interface
        void notifyConfigurationChanged(nsecs_t when) override;
        void notifyKey(nsecs_t eventTime, int32_t deviceId, uint32_t source, int32_t displayId,
                       uint32_t policyFlags, int32_t action, int32_t flags, int32_t keyCode,
                       int32_t scanCode, int32_t metaState, nsecs_t downTime) override;
        void notifyMotion(nsecs_t eventTime, int32_t deviceId, uint32_t source, int32_t displayId,
                          uint32_t policyFlags, int32_t action, int32_t actionButton, int32_t flags,
                          int32_t metaState, int32_t buttonState,
                          MotionClassification classification, int32_t edgeFlags,
                          uint32_t pointerCount, const PointerProperties* pointerProperties,
                          const PointerCoords* pointerCoords, float xPrecision, float yPrecision,
                          float xCursorPosition, float yCursorPosition, nsecs_t downTime,
                          const std::vector<TouchVideoFrame>& videoFrames) override;
        void notifySwitch(nsecs_t eventTime, uint32_t switchValues, uint32_t switchMask) override;
        void notifySensor(nsecs_t when, int32_t deviceId, InputDeviceSensorType sensorType,
                          InputDeviceSensorAccuracy accuracy, bool accuracyChanged,
                          nsecs_t timestamp, std::vector<float> values) override;
        void notifyVibratorState(nsecs_t when, int32_t deviceId, bool isOn) override;
        void notifyDeviceReset(nsecs_t when, int32_t deviceId) override;
        void notifyPointerCaptureChanged(nsecs_t when, bool hasCapture) override;

    } mContext;

    friend class ContextImpl;
+3 −24
Original line number Diff line number Diff line
@@ -55,34 +55,13 @@ public:
    virtual void dispatchExternalStylusState(const StylusState& outState) = 0;

    virtual InputReaderPolicyInterface* getPolicy() = 0;
    virtual InputListenerInterface* getListener() = 0;
    virtual EventHubInterface* getEventHub() = 0;

    virtual int32_t getNextId() = 0;

    virtual void updateLedMetaState(int32_t metaState) = 0;
    virtual int32_t getLedMetaState() = 0;

    // Send events to InputListener interface

    virtual void notifyConfigurationChanged(nsecs_t when) = 0;
    virtual void notifyKey(nsecs_t eventTime, int32_t deviceId, uint32_t source, int32_t displayId,
                           uint32_t policyFlags, int32_t action, int32_t flags, int32_t keyCode,
                           int32_t scanCode, int32_t metaState, nsecs_t downTime) = 0;
    virtual void notifyMotion(nsecs_t eventTime, int32_t deviceId, uint32_t source,
                              int32_t displayId, uint32_t policyFlags, int32_t action,
                              int32_t actionButton, int32_t flags, int32_t metaState,
                              int32_t buttonState, MotionClassification classification,
                              int32_t edgeFlags, uint32_t pointerCount,
                              const PointerProperties* pointerProperties,
                              const PointerCoords* pointerCoords, float xPrecision,
                              float yPrecision, float xCursorPosition, float yCursorPosition,
                              nsecs_t downTime,
                              const std::vector<TouchVideoFrame>& videoFrames) = 0;
    virtual void notifySwitch(nsecs_t eventTime, uint32_t switchValues, uint32_t switchMask) = 0;
    virtual void notifySensor(nsecs_t when, int32_t deviceId, InputDeviceSensorType sensorType,
                              InputDeviceSensorAccuracy accuracy, bool accuracyChanged,
                              nsecs_t timestamp, std::vector<float> values) = 0;
    virtual void notifyVibratorState(nsecs_t when, int32_t deviceId, bool isOn) = 0;
    virtual void notifyDeviceReset(nsecs_t when, int32_t deviceId) = 0;
    virtual void notifyPointerCaptureChanged(nsecs_t when, bool hasCapture) = 0;
};

} // namespace android
+32 −24
Original line number Diff line number Diff line
@@ -175,7 +175,8 @@ void CursorInputMapper::configure(nsecs_t when, const InputReaderConfiguration*
        }
        bumpGeneration();
        if (changes) {
            getContext()->notifyDeviceReset(when, getDeviceId());
            NotifyDeviceResetArgs args(getContext()->getNextId(), when, getDeviceId());
            getListener()->notifyDeviceReset(&args);
        }
    }

@@ -382,35 +383,40 @@ void CursorInputMapper::sync(nsecs_t when) {
            while (!released.isEmpty()) {
                int32_t actionButton = BitSet32::valueForBit(released.clearFirstMarkedBit());
                buttonState &= ~actionButton;
                getContext()->notifyMotion(when, getDeviceId(), mSource, displayId, policyFlags,
                NotifyMotionArgs releaseArgs(getContext()->getNextId(), when, getDeviceId(),
                                             mSource, displayId, policyFlags,
                                             AMOTION_EVENT_ACTION_BUTTON_RELEASE, actionButton, 0,
                                             metaState, buttonState, MotionClassification::NONE,
                                             AMOTION_EVENT_EDGE_FLAG_NONE, 1, &pointerProperties,
                                             &pointerCoords, mXPrecision, mYPrecision,
                                             xCursorPosition, yCursorPosition, downTime,
                                             /* videoFrames */ {});
                getListener()->notifyMotion(&releaseArgs);
            }
        }

        getContext()->notifyMotion(when, getDeviceId(), mSource, displayId, policyFlags,
                                   motionEventAction, 0, 0, metaState, currentButtonState,
        NotifyMotionArgs args(getContext()->getNextId(), when, getDeviceId(), mSource, displayId,
                              policyFlags, motionEventAction, 0, 0, metaState, currentButtonState,
                              MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE, 1,
                              &pointerProperties, &pointerCoords, mXPrecision, mYPrecision,
                              xCursorPosition, yCursorPosition, downTime,
                              /* videoFrames */ {});
        getListener()->notifyMotion(&args);

        if (buttonsPressed) {
            BitSet32 pressed(buttonsPressed);
            while (!pressed.isEmpty()) {
                int32_t actionButton = BitSet32::valueForBit(pressed.clearFirstMarkedBit());
                buttonState |= actionButton;
                getContext()->notifyMotion(when, getDeviceId(), mSource, displayId, policyFlags,
                NotifyMotionArgs pressArgs(getContext()->getNextId(), when, getDeviceId(), mSource,
                                           displayId, policyFlags,
                                           AMOTION_EVENT_ACTION_BUTTON_PRESS, actionButton, 0,
                                           metaState, buttonState, MotionClassification::NONE,
                                           AMOTION_EVENT_EDGE_FLAG_NONE, 1, &pointerProperties,
                                           &pointerCoords, mXPrecision, mYPrecision,
                                           xCursorPosition, yCursorPosition, downTime,
                                           /* videoFrames */ {});
                getListener()->notifyMotion(&pressArgs);
            }
        }

@@ -418,12 +424,13 @@ void CursorInputMapper::sync(nsecs_t when) {

        // Send hover move after UP to tell the application that the mouse is hovering now.
        if (motionEventAction == AMOTION_EVENT_ACTION_UP && (mSource == AINPUT_SOURCE_MOUSE)) {
            getContext()->notifyMotion(when, getDeviceId(), mSource, displayId, policyFlags,
                                       AMOTION_EVENT_ACTION_HOVER_MOVE, 0, 0, metaState,
                                       currentButtonState, MotionClassification::NONE,
            NotifyMotionArgs hoverArgs(getContext()->getNextId(), when, getDeviceId(), mSource,
                                       displayId, policyFlags, AMOTION_EVENT_ACTION_HOVER_MOVE, 0,
                                       0, metaState, currentButtonState, MotionClassification::NONE,
                                       AMOTION_EVENT_EDGE_FLAG_NONE, 1, &pointerProperties,
                                       &pointerCoords, mXPrecision, mYPrecision, xCursorPosition,
                                       yCursorPosition, downTime, /* videoFrames */ {});
            getListener()->notifyMotion(&hoverArgs);
        }

        // Send scroll events.
@@ -431,12 +438,13 @@ void CursorInputMapper::sync(nsecs_t when) {
            pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_VSCROLL, vscroll);
            pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_HSCROLL, hscroll);

            getContext()->notifyMotion(when, getDeviceId(), mSource, displayId, policyFlags,
                                       AMOTION_EVENT_ACTION_SCROLL, 0, 0, metaState,
                                       currentButtonState, MotionClassification::NONE,
            NotifyMotionArgs scrollArgs(getContext()->getNextId(), when, getDeviceId(), mSource,
                                        displayId, policyFlags, AMOTION_EVENT_ACTION_SCROLL, 0, 0,
                                        metaState, currentButtonState, MotionClassification::NONE,
                                        AMOTION_EVENT_EDGE_FLAG_NONE, 1, &pointerProperties,
                                        &pointerCoords, mXPrecision, mYPrecision, xCursorPosition,
                                        yCursorPosition, downTime, /* videoFrames */ {});
            getListener()->notifyMotion(&scrollArgs);
        }
    }

Loading