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

Commit ed6c3def authored by Arpit Singh's avatar Arpit Singh
Browse files

InputMapper refactor: Change readerconfig pointer to const ref

We are refactoring Input-mapper to ensure they are configured at the
time of initialisation.

In this CL we are changing InputReaderConfiguration raw pointer to
a const reference and rename it to readerConfig for clarity.

Test: build, inputflinger_tests, presubmit checks

Bug: 256009910
Change-Id: Iae22c8cfba836bd311a51fca13d680456a61e604
parent cda245fe
Loading
Loading
Loading
Loading
+17 −12
Original line number Diff line number Diff line
@@ -253,7 +253,8 @@ void InputDevice::removeEventHubDevice(int32_t eventHubId) {
    mDevices.erase(eventHubId);
}

std::list<NotifyArgs> InputDevice::configure(nsecs_t when, const InputReaderConfiguration* config,
std::list<NotifyArgs> InputDevice::configure(nsecs_t when,
                                             const InputReaderConfiguration& readerConfig,
                                             uint32_t changes) {
    std::list<NotifyArgs> out;
    mSources = 0;
@@ -291,7 +292,7 @@ std::list<NotifyArgs> InputDevice::configure(nsecs_t when, const InputReaderConf
            });

            mAssociatedDeviceType =
                    getValueByKey(config->deviceTypeAssociations, mIdentifier.location);
                    getValueByKey(readerConfig.deviceTypeAssociations, mIdentifier.location);
        }

        if (!changes || (changes & InputReaderConfiguration::CHANGE_KEYBOARD_LAYOUTS)) {
@@ -325,8 +326,8 @@ std::list<NotifyArgs> InputDevice::configure(nsecs_t when, const InputReaderConf
            // Do not execute this code on the first configure, because 'setEnabled' would call
            // InputMapper::reset, and you can't reset a mapper before it has been configured.
            // The mappers are configured for the first time at the bottom of this function.
            auto it = config->disabledDevices.find(mId);
            bool enabled = it == config->disabledDevices.end();
            auto it = readerConfig.disabledDevices.find(mId);
            bool enabled = it == readerConfig.disabledDevices.end();
            out += setEnabled(enabled, when);
        }

@@ -338,13 +339,14 @@ std::list<NotifyArgs> InputDevice::configure(nsecs_t when, const InputReaderConf
            // Find the display port that corresponds to the current input port.
            const std::string& inputPort = mIdentifier.location;
            if (!inputPort.empty()) {
                const std::unordered_map<std::string, uint8_t>& ports = config->portAssociations;
                const std::unordered_map<std::string, uint8_t>& ports =
                        readerConfig.portAssociations;
                const auto& displayPort = ports.find(inputPort);
                if (displayPort != ports.end()) {
                    mAssociatedDisplayPort = std::make_optional(displayPort->second);
                } else {
                    const std::unordered_map<std::string, std::string>& displayUniqueIds =
                            config->uniqueIdAssociations;
                            readerConfig.uniqueIdAssociations;
                    const auto& displayUniqueId = displayUniqueIds.find(inputPort);
                    if (displayUniqueId != displayUniqueIds.end()) {
                        mAssociatedDisplayUniqueId = displayUniqueId->second;
@@ -356,9 +358,11 @@ std::list<NotifyArgs> InputDevice::configure(nsecs_t when, const InputReaderConf
            // "disabledDevices" list. If it is associated with a specific display, and it was not
            // explicitly disabled, then enable/disable the device based on whether we can find the
            // corresponding viewport.
            bool enabled = (config->disabledDevices.find(mId) == config->disabledDevices.end());
            bool enabled =
                    (readerConfig.disabledDevices.find(mId) == readerConfig.disabledDevices.end());
            if (mAssociatedDisplayPort) {
                mAssociatedViewport = config->getDisplayViewportByPort(*mAssociatedDisplayPort);
                mAssociatedViewport =
                        readerConfig.getDisplayViewportByPort(*mAssociatedDisplayPort);
                if (!mAssociatedViewport) {
                    ALOGW("Input device %s should be associated with display on port %" PRIu8 ", "
                          "but the corresponding viewport is not found.",
@@ -367,7 +371,7 @@ std::list<NotifyArgs> InputDevice::configure(nsecs_t when, const InputReaderConf
                }
            } else if (mAssociatedDisplayUniqueId != std::nullopt) {
                mAssociatedViewport =
                        config->getDisplayViewportByUniqueId(*mAssociatedDisplayUniqueId);
                        readerConfig.getDisplayViewportByUniqueId(*mAssociatedDisplayUniqueId);
                if (!mAssociatedViewport) {
                    ALOGW("Input device %s should be associated with display %s but the "
                          "corresponding viewport cannot be found",
@@ -384,15 +388,16 @@ std::list<NotifyArgs> InputDevice::configure(nsecs_t when, const InputReaderConf
            }
        }

        for_each_mapper([this, when, &config, changes, &out](InputMapper& mapper) {
            out += mapper.reconfigure(when, config, changes);
        for_each_mapper([this, when, &readerConfig, changes, &out](InputMapper& mapper) {
            out += mapper.reconfigure(when, readerConfig, changes);
            mSources |= mapper.getSources();
        });

        // If a device is just plugged but it might be disabled, we need to update some info like
        // axis range of touch from each InputMapper first, then disable it.
        if (!changes) {
            out += setEnabled(config->disabledDevices.find(mId) == config->disabledDevices.end(),
            out += setEnabled(readerConfig.disabledDevices.find(mId) ==
                                      readerConfig.disabledDevices.end(),
                              when);
        }
    }
+3 −3
Original line number Diff line number Diff line
@@ -234,7 +234,7 @@ void InputReader::addDeviceLocked(nsecs_t when, int32_t eventHubId) {
    InputDeviceIdentifier identifier = mEventHub->getDeviceIdentifier(eventHubId);
    std::shared_ptr<InputDevice> device = createDeviceLocked(eventHubId, identifier);

    notifyAll(device->configure(when, &mConfig, 0));
    notifyAll(device->configure(when, mConfig, 0));
    notifyAll(device->reset(when));

    if (device->isIgnored()) {
@@ -310,7 +310,7 @@ void InputReader::removeDeviceLocked(nsecs_t when, int32_t eventHubId) {

    std::list<NotifyArgs> resetEvents;
    if (device->hasEventHubDevices()) {
        resetEvents += device->configure(when, &mConfig, 0);
        resetEvents += device->configure(when, mConfig, 0);
    }
    resetEvents += device->reset(when);
    notifyAll(std::move(resetEvents));
@@ -408,7 +408,7 @@ void InputReader::refreshConfigurationLocked(uint32_t changes) {
    } else {
        for (auto& devicePair : mDevices) {
            std::shared_ptr<InputDevice>& device = devicePair.second;
            notifyAll(device->configure(now, &mConfig, changes));
            notifyAll(device->configure(now, mConfig, changes));
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@ public:
    void addEventHubDevice(int32_t eventHubId, bool populateMappers = true);
    void removeEventHubDevice(int32_t eventHubId);
    [[nodiscard]] std::list<NotifyArgs> configure(nsecs_t when,
                                                  const InputReaderConfiguration* config,
                                                  const InputReaderConfiguration& readerConfig,
                                                  uint32_t changes);
    [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when);
    [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvents, size_t count);
+7 −7
Original line number Diff line number Diff line
@@ -134,7 +134,7 @@ void CursorInputMapper::dump(std::string& dump) {
}

std::list<NotifyArgs> CursorInputMapper::reconfigure(nsecs_t when,
                                                     const InputReaderConfiguration* config,
                                                     const InputReaderConfiguration& config,
                                                     uint32_t changes) {
    std::list<NotifyArgs> out = InputMapper::reconfigure(when, config, changes);

@@ -173,10 +173,10 @@ std::list<NotifyArgs> CursorInputMapper::reconfigure(nsecs_t when,
    }

    const bool configurePointerCapture = mParameters.mode != Parameters::Mode::NAVIGATION &&
            ((!changes && config->pointerCaptureRequest.enable) ||
            ((!changes && config.pointerCaptureRequest.enable) ||
             (changes & InputReaderConfiguration::CHANGE_POINTER_CAPTURE));
    if (configurePointerCapture) {
        if (config->pointerCaptureRequest.enable) {
        if (config.pointerCaptureRequest.enable) {
            if (mParameters.mode == Parameters::Mode::POINTER) {
                mParameters.mode = Parameters::Mode::POINTER_RELATIVE;
                mSource = AINPUT_SOURCE_MOUSE_RELATIVE;
@@ -207,9 +207,9 @@ std::list<NotifyArgs> CursorInputMapper::reconfigure(nsecs_t when,
            mWheelXVelocityControl.setParameters(FLAT_VELOCITY_CONTROL_PARAMS);
            mWheelYVelocityControl.setParameters(FLAT_VELOCITY_CONTROL_PARAMS);
        } else {
            mPointerVelocityControl.setParameters(config->pointerVelocityControlParameters);
            mWheelXVelocityControl.setParameters(config->wheelVelocityControlParameters);
            mWheelYVelocityControl.setParameters(config->wheelVelocityControlParameters);
            mPointerVelocityControl.setParameters(config.pointerVelocityControlParameters);
            mWheelXVelocityControl.setParameters(config.wheelVelocityControlParameters);
            mWheelYVelocityControl.setParameters(config.wheelVelocityControlParameters);
        }
    }

@@ -241,7 +241,7 @@ std::list<NotifyArgs> CursorInputMapper::reconfigure(nsecs_t when,
        // rotations and report values directly from the input device.
        if (!isOrientedDevice && mDisplayId &&
            mParameters.mode != Parameters::Mode::POINTER_RELATIVE) {
            if (auto viewport = config->getDisplayViewportById(*mDisplayId); viewport) {
            if (auto viewport = config.getDisplayViewportById(*mDisplayId); viewport) {
                mOrientation = getInverseRotation(viewport->orientation);
            }
        }
+1 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ public:
    virtual void populateDeviceInfo(InputDeviceInfo& deviceInfo) override;
    virtual void dump(std::string& dump) override;
    [[nodiscard]] std::list<NotifyArgs> reconfigure(nsecs_t when,
                                                    const InputReaderConfiguration* config,
                                                    const InputReaderConfiguration& config,
                                                    uint32_t changes) override;
    [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when) override;
    [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvent) override;
Loading