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

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

Send mapper events via context

Currently, mappers report input events directly to InputListener
(InputClassifier, formerly InputDispatcher). To do this, mappers have to
pull a lot of information from context first, and then report it to the
listener.

If we move this call into context, then mappers don't even need to know
about the existence of Notify*Args.

This will also allow us to consolidate places where event id is
generated.

This, in turn, will help us report the input event statistics from a
more centralized place, where we already know event id, and also know
the read time of the event.

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


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


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


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


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


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


@@ -868,16 +865,64 @@ InputReaderPolicyInterface* InputReader::ContextImpl::getPolicy() {
    return mReader->mPolicy.get();
    return mReader->mPolicy.get();
}
}


InputListenerInterface* InputReader::ContextImpl::getListener() {
    return mReader->mQueuedListener.get();
}

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


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

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::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);
}

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


} // namespace android
} // namespace android
+21 −2
Original line number Original line Diff line number Diff line
@@ -127,11 +127,30 @@ protected:
        void dispatchExternalStylusState(const StylusState& outState)
        void dispatchExternalStylusState(const StylusState& outState)
                NO_THREAD_SAFETY_ANALYSIS override;
                NO_THREAD_SAFETY_ANALYSIS override;
        InputReaderPolicyInterface* getPolicy() 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;
        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;
        void updateLedMetaState(int32_t metaState) NO_THREAD_SAFETY_ANALYSIS override;
        int32_t getLedMetaState() 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 notifyDeviceReset(nsecs_t when, int32_t deviceId) override;
        void notifyPointerCaptureChanged(nsecs_t when, bool hasCapture) override;

    } mContext;
    } mContext;


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


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


    virtual int32_t getNextId() = 0;

    virtual void updateLedMetaState(int32_t metaState) = 0;
    virtual void updateLedMetaState(int32_t metaState) = 0;
    virtual int32_t getLedMetaState() = 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 notifyDeviceReset(nsecs_t when, int32_t deviceId) = 0;
    virtual void notifyPointerCaptureChanged(nsecs_t when, bool hasCapture) = 0;
};
};


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


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


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


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


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


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


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


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


Loading