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

Commit 0a724d24 authored by Arpit Singh's avatar Arpit Singh Committed by Automerger Merge Worker
Browse files

InputMapper refactor: Configure empty InputDevice am: 4f61f3c9 am: 691001a8

parents 116bf964 691001a8
Loading
Loading
Loading
Loading
+16 −19
Original line number Original line Diff line number Diff line
@@ -173,18 +173,23 @@ void InputDevice::addEmptyEventHubDevice(int32_t eventHubId) {
    mDevices.insert({eventHubId, std::make_pair(std::move(contextPtr), std::move(mappers))});
    mDevices.insert({eventHubId, std::make_pair(std::move(contextPtr), std::move(mappers))});
}
}


void InputDevice::addEventHubDevice(int32_t eventHubId,
[[nodiscard]] std::list<NotifyArgs> InputDevice::addEventHubDevice(
                                    const InputReaderConfiguration& readerConfig) {
        nsecs_t when, int32_t eventHubId, const InputReaderConfiguration& readerConfig) {
    if (mDevices.find(eventHubId) != mDevices.end()) {
    if (mDevices.find(eventHubId) != mDevices.end()) {
        return;
        return {};
    }
    }
    std::unique_ptr<InputDeviceContext> contextPtr(new InputDeviceContext(*this, eventHubId));
    std::vector<std::unique_ptr<InputMapper>> mappers = createMappers(*contextPtr, readerConfig);


    // insert the context into the devices set
    // Add an empty device configure and keep it enabled to allow mapper population
    mDevices.insert({eventHubId, std::make_pair(std::move(contextPtr), std::move(mappers))});
    // with correct configuration/context
    addEmptyEventHubDevice(eventHubId);
    std::list<NotifyArgs> out = configure(when, readerConfig, {}, /*forceEnable=*/true);

    DevicePair& devicePair = mDevices[eventHubId];
    devicePair.second = createMappers(*devicePair.first, readerConfig);

    // Must change generation to flag this device as changed
    // Must change generation to flag this device as changed
    bumpGeneration();
    bumpGeneration();
    return out;
}
}


void InputDevice::removeEventHubDevice(int32_t eventHubId) {
void InputDevice::removeEventHubDevice(int32_t eventHubId) {
@@ -197,7 +202,7 @@ void InputDevice::removeEventHubDevice(int32_t eventHubId) {


std::list<NotifyArgs> InputDevice::configure(nsecs_t when,
std::list<NotifyArgs> InputDevice::configure(nsecs_t when,
                                             const InputReaderConfiguration& readerConfig,
                                             const InputReaderConfiguration& readerConfig,
                                             ConfigurationChanges changes) {
                                             ConfigurationChanges changes, bool forceEnable) {
    std::list<NotifyArgs> out;
    std::list<NotifyArgs> out;
    mSources = 0;
    mSources = 0;
    mClasses = ftl::Flags<InputDeviceClass>(0);
    mClasses = ftl::Flags<InputDeviceClass>(0);
@@ -311,25 +316,17 @@ std::list<NotifyArgs> InputDevice::configure(nsecs_t when,
            }
            }
        }
        }


        if (changes.test(Change::ENABLED_STATE) || changes.test(Change::DISPLAY_INFO)) {
        if (!changes.any() || changes.test(Change::ENABLED_STATE) ||
            changes.test(Change::DISPLAY_INFO)) {
            // Whether a device is enabled can depend on the display association,
            // Whether a device is enabled can depend on the display association,
            // so update the enabled state when there is a change in display info.
            // so update the enabled state when there is a change in display info.
            // NOTE: The first configuration of a mapper must happen with the device enabled.
            out += updateEnableState(when, readerConfig, forceEnable);
            // Do not execute this code on the first configure to prevent mappers
            // from being configured with the device disabled.
            out += updateEnableState(when, readerConfig, false);
        }
        }


        for_each_mapper([this, when, &readerConfig, changes, &out](InputMapper& mapper) {
        for_each_mapper([this, when, &readerConfig, changes, &out](InputMapper& mapper) {
            out += mapper.reconfigure(when, readerConfig, changes);
            out += mapper.reconfigure(when, readerConfig, changes);
            mSources |= mapper.getSources();
            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.any()) {
            out += updateEnableState(when, readerConfig);
        }
    }
    }
    return out;
    return out;
}
}
+3 −3
Original line number Original line Diff line number Diff line
@@ -234,7 +234,7 @@ void InputReader::addDeviceLocked(nsecs_t when, int32_t eventHubId) {
    }
    }


    InputDeviceIdentifier identifier = mEventHub->getDeviceIdentifier(eventHubId);
    InputDeviceIdentifier identifier = mEventHub->getDeviceIdentifier(eventHubId);
    std::shared_ptr<InputDevice> device = createDeviceLocked(eventHubId, identifier);
    std::shared_ptr<InputDevice> device = createDeviceLocked(when, eventHubId, identifier);


    notifyAll(device->configure(when, mConfig, /*changes=*/{}));
    notifyAll(device->configure(when, mConfig, /*changes=*/{}));
    notifyAll(device->reset(when));
    notifyAll(device->reset(when));
@@ -319,7 +319,7 @@ void InputReader::removeDeviceLocked(nsecs_t when, int32_t eventHubId) {
}
}


std::shared_ptr<InputDevice> InputReader::createDeviceLocked(
std::shared_ptr<InputDevice> InputReader::createDeviceLocked(
        int32_t eventHubId, const InputDeviceIdentifier& identifier) {
        nsecs_t when, int32_t eventHubId, const InputDeviceIdentifier& identifier) {
    auto deviceIt = std::find_if(mDevices.begin(), mDevices.end(), [identifier](auto& devicePair) {
    auto deviceIt = std::find_if(mDevices.begin(), mDevices.end(), [identifier](auto& devicePair) {
        const InputDeviceIdentifier identifier2 =
        const InputDeviceIdentifier identifier2 =
                devicePair.second->getDeviceInfo().getIdentifier();
                devicePair.second->getDeviceInfo().getIdentifier();
@@ -334,7 +334,7 @@ std::shared_ptr<InputDevice> InputReader::createDeviceLocked(
        device = std::make_shared<InputDevice>(&mContext, deviceId, bumpGenerationLocked(),
        device = std::make_shared<InputDevice>(&mContext, deviceId, bumpGenerationLocked(),
                                               identifier);
                                               identifier);
    }
    }
    device->addEventHubDevice(eventHubId, mConfig);
    notifyAll(device->addEventHubDevice(when, eventHubId, mConfig));
    return device;
    return device;
}
}


+4 −2
Original line number Original line Diff line number Diff line
@@ -80,11 +80,13 @@ public:


    void dump(std::string& dump, const std::string& eventHubDevStr);
    void dump(std::string& dump, const std::string& eventHubDevStr);
    void addEmptyEventHubDevice(int32_t eventHubId);
    void addEmptyEventHubDevice(int32_t eventHubId);
    void addEventHubDevice(int32_t eventHubId, const InputReaderConfiguration& readerConfig);
    [[nodiscard]] std::list<NotifyArgs> addEventHubDevice(
            nsecs_t when, int32_t eventHubId, const InputReaderConfiguration& readerConfig);
    void removeEventHubDevice(int32_t eventHubId);
    void removeEventHubDevice(int32_t eventHubId);
    [[nodiscard]] std::list<NotifyArgs> configure(nsecs_t when,
    [[nodiscard]] std::list<NotifyArgs> configure(nsecs_t when,
                                                  const InputReaderConfiguration& readerConfig,
                                                  const InputReaderConfiguration& readerConfig,
                                                  ConfigurationChanges changes);
                                                  ConfigurationChanges changes,
                                                  bool forceEnable = false);
    [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when);
    [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when);
    [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvents, size_t count);
    [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvents, size_t count);
    [[nodiscard]] std::list<NotifyArgs> timeoutExpired(nsecs_t when);
    [[nodiscard]] std::list<NotifyArgs> timeoutExpired(nsecs_t when);
+1 −1
Original line number Original line Diff line number Diff line
@@ -121,7 +121,7 @@ public:


protected:
protected:
    // These members are protected so they can be instrumented by test cases.
    // These members are protected so they can be instrumented by test cases.
    virtual std::shared_ptr<InputDevice> createDeviceLocked(int32_t deviceId,
    virtual std::shared_ptr<InputDevice> createDeviceLocked(nsecs_t when, int32_t deviceId,
                                                            const InputDeviceIdentifier& identifier)
                                                            const InputDeviceIdentifier& identifier)
            REQUIRES(mLock);
            REQUIRES(mLock);


+2 −1
Original line number Original line Diff line number Diff line
@@ -2660,7 +2660,8 @@ TEST_F(InputDeviceTest, DumpDoesNotCrash) {
    mFakeEventHub->addDevice(TEST_EVENTHUB_ID, "Test EventHub device", InputDeviceClass::BATTERY);
    mFakeEventHub->addDevice(TEST_EVENTHUB_ID, "Test EventHub device", InputDeviceClass::BATTERY);
    InputDevice device(mReader->getContext(), /*id=*/1, /*generation=*/2, /*identifier=*/{});
    InputDevice device(mReader->getContext(), /*id=*/1, /*generation=*/2, /*identifier=*/{});
    device.addEventHubDevice(TEST_EVENTHUB_ID, mFakePolicy->getReaderConfiguration());
    auto _ = device.addEventHubDevice(ARBITRARY_TIME, TEST_EVENTHUB_ID,
                                      mFakePolicy->getReaderConfiguration());
    device.removeEventHubDevice(TEST_EVENTHUB_ID);
    device.removeEventHubDevice(TEST_EVENTHUB_ID);
    std::string dumpStr, eventHubDevStr;
    std::string dumpStr, eventHubDevStr;
    device.dump(dumpStr, eventHubDevStr);
    device.dump(dumpStr, eventHubDevStr);
Loading