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

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

InputMapper refactor: Configure empty InputDevice am: 7f4dd512 am: f5f4fd5a

parents 0b2b357f f5f4fd5a
Loading
Loading
Loading
Loading
+31 −30
Original line number Original line Diff line number Diff line
@@ -151,21 +151,22 @@ void InputDevice::addEmptyEventHubDevice(int32_t eventHubId) {
        return;
        return;
    }
    }
    std::unique_ptr<InputDeviceContext> contextPtr(new InputDeviceContext(*this, eventHubId));
    std::unique_ptr<InputDeviceContext> contextPtr(new InputDeviceContext(*this, eventHubId));
    std::vector<std::unique_ptr<InputMapper>> mappers;
    mDevices.insert(

            {eventHubId,
    mDevices.insert({eventHubId, std::make_pair(std::move(contextPtr), std::move(mappers))});
             std::make_pair<std::unique_ptr<InputDeviceContext>,
                            std::vector<std::unique_ptr<InputMapper>>>(std::move(contextPtr), {})});
}
}


void InputDevice::addEventHubDevice(int32_t eventHubId,
void InputDevice::populateMappers(int32_t eventHubId,
                                  const InputReaderConfiguration& readerConfig) {
                                  const InputReaderConfiguration& readerConfig) {
    if (mDevices.find(eventHubId) != mDevices.end()) {
    auto targetDevice = mDevices.find(eventHubId);
        return;
    LOG_ALWAYS_FATAL_IF(targetDevice == mDevices.end(),
    }
                        "InputDevice::populateMappers(): missing device with eventHubId %d ",
    std::unique_ptr<InputDeviceContext> contextPtr(new InputDeviceContext(*this, eventHubId));
                        eventHubId);
    std::vector<std::unique_ptr<InputMapper>> mappers = createMappers(*contextPtr, readerConfig);
    // create and add mappers to device

    InputDeviceContext& context = *targetDevice->second.first;
    // insert the context into the devices set
    std::vector<std::unique_ptr<InputMapper>> mappers = createMappers(context, readerConfig);
    mDevices.insert({eventHubId, std::make_pair(std::move(contextPtr), std::move(mappers))});
    targetDevice->second.second = std::move(mappers);
    // Must change generation to flag this device as changed
    // Must change generation to flag this device as changed
    bumpGeneration();
    bumpGeneration();
}
}
@@ -440,29 +441,29 @@ int32_t InputDevice::getState(uint32_t sourceMask, int32_t code, GetStateFunc ge
}
}


std::vector<std::unique_ptr<InputMapper>> InputDevice::createMappers(
std::vector<std::unique_ptr<InputMapper>> InputDevice::createMappers(
        InputDeviceContext& contextPtr, const InputReaderConfiguration& readerConfig) {
        InputDeviceContext& context, const InputReaderConfiguration& readerConfig) {
    ftl::Flags<InputDeviceClass> classes = contextPtr.getDeviceClasses();
    ftl::Flags<InputDeviceClass> classes = context.getDeviceClasses();
    std::vector<std::unique_ptr<InputMapper>> mappers;
    std::vector<std::unique_ptr<InputMapper>> mappers;


    // Switch-like devices.
    // Switch-like devices.
    if (classes.test(InputDeviceClass::SWITCH)) {
    if (classes.test(InputDeviceClass::SWITCH)) {
        mappers.push_back(createInputMapper<SwitchInputMapper>(contextPtr, readerConfig));
        mappers.push_back(createInputMapper<SwitchInputMapper>(context, readerConfig));
    }
    }


    // Scroll wheel-like devices.
    // Scroll wheel-like devices.
    if (classes.test(InputDeviceClass::ROTARY_ENCODER)) {
    if (classes.test(InputDeviceClass::ROTARY_ENCODER)) {
        mappers.push_back(createInputMapper<RotaryEncoderInputMapper>(contextPtr, readerConfig));
        mappers.push_back(createInputMapper<RotaryEncoderInputMapper>(context, readerConfig));
    }
    }


    // Vibrator-like devices.
    // Vibrator-like devices.
    if (classes.test(InputDeviceClass::VIBRATOR)) {
    if (classes.test(InputDeviceClass::VIBRATOR)) {
        mappers.push_back(createInputMapper<VibratorInputMapper>(contextPtr, readerConfig));
        mappers.push_back(createInputMapper<VibratorInputMapper>(context, readerConfig));
    }
    }


    // Battery-like devices or light-containing devices.
    // Battery-like devices or light-containing devices.
    // PeripheralController will be created with associated EventHub device.
    // PeripheralController will be created with associated EventHub device.
    if (classes.test(InputDeviceClass::BATTERY) || classes.test(InputDeviceClass::LIGHT)) {
    if (classes.test(InputDeviceClass::BATTERY) || classes.test(InputDeviceClass::LIGHT)) {
        mController = std::make_unique<PeripheralController>(contextPtr);
        mController = std::make_unique<PeripheralController>(context);
    }
    }


    // Keyboard-like devices.
    // Keyboard-like devices.
@@ -482,13 +483,13 @@ std::vector<std::unique_ptr<InputMapper>> InputDevice::createMappers(
    }
    }


    if (keyboardSource != 0) {
    if (keyboardSource != 0) {
        mappers.push_back(createInputMapper<KeyboardInputMapper>(contextPtr, readerConfig,
        mappers.push_back(createInputMapper<KeyboardInputMapper>(context, readerConfig,
                                                                 keyboardSource, keyboardType));
                                                                 keyboardSource, keyboardType));
    }
    }


    // Cursor-like devices.
    // Cursor-like devices.
    if (classes.test(InputDeviceClass::CURSOR)) {
    if (classes.test(InputDeviceClass::CURSOR)) {
        mappers.push_back(createInputMapper<CursorInputMapper>(contextPtr, readerConfig));
        mappers.push_back(createInputMapper<CursorInputMapper>(context, readerConfig));
    }
    }


    // Touchscreens and touchpad devices.
    // Touchscreens and touchpad devices.
@@ -496,31 +497,31 @@ std::vector<std::unique_ptr<InputMapper>> InputDevice::createMappers(
            sysprop::InputProperties::enable_touchpad_gestures_library().value_or(true);
            sysprop::InputProperties::enable_touchpad_gestures_library().value_or(true);
    // TODO(b/272518665): Fix the new touchpad stack for Sony DualShock 4 (5c4, 9cc) touchpads, or
    // TODO(b/272518665): Fix the new touchpad stack for Sony DualShock 4 (5c4, 9cc) touchpads, or
    // at least load this setting from the IDC file.
    // at least load this setting from the IDC file.
    const InputDeviceIdentifier identifier = contextPtr.getDeviceIdentifier();
    const InputDeviceIdentifier identifier = context.getDeviceIdentifier();
    const bool isSonyDualShock4Touchpad = identifier.vendor == 0x054c &&
    const bool isSonyDualShock4Touchpad = identifier.vendor == 0x054c &&
            (identifier.product == 0x05c4 || identifier.product == 0x09cc);
            (identifier.product == 0x05c4 || identifier.product == 0x09cc);
    if (ENABLE_TOUCHPAD_GESTURES_LIBRARY && classes.test(InputDeviceClass::TOUCHPAD) &&
    if (ENABLE_TOUCHPAD_GESTURES_LIBRARY && classes.test(InputDeviceClass::TOUCHPAD) &&
        classes.test(InputDeviceClass::TOUCH_MT) && !isSonyDualShock4Touchpad) {
        classes.test(InputDeviceClass::TOUCH_MT) && !isSonyDualShock4Touchpad) {
        mappers.push_back(createInputMapper<TouchpadInputMapper>(contextPtr, readerConfig));
        mappers.push_back(createInputMapper<TouchpadInputMapper>(context, readerConfig));
    } else if (classes.test(InputDeviceClass::TOUCH_MT)) {
    } else if (classes.test(InputDeviceClass::TOUCH_MT)) {
        mappers.push_back(std::make_unique<MultiTouchInputMapper>(contextPtr, readerConfig));
        mappers.push_back(std::make_unique<MultiTouchInputMapper>(context, readerConfig));
    } else if (classes.test(InputDeviceClass::TOUCH)) {
    } else if (classes.test(InputDeviceClass::TOUCH)) {
        mappers.push_back(std::make_unique<SingleTouchInputMapper>(contextPtr, readerConfig));
        mappers.push_back(std::make_unique<SingleTouchInputMapper>(context, readerConfig));
    }
    }


    // Joystick-like devices.
    // Joystick-like devices.
    if (classes.test(InputDeviceClass::JOYSTICK)) {
    if (classes.test(InputDeviceClass::JOYSTICK)) {
        mappers.push_back(createInputMapper<JoystickInputMapper>(contextPtr, readerConfig));
        mappers.push_back(createInputMapper<JoystickInputMapper>(context, readerConfig));
    }
    }


    // Motion sensor enabled devices.
    // Motion sensor enabled devices.
    if (classes.test(InputDeviceClass::SENSOR)) {
    if (classes.test(InputDeviceClass::SENSOR)) {
        mappers.push_back(createInputMapper<SensorInputMapper>(contextPtr, readerConfig));
        mappers.push_back(createInputMapper<SensorInputMapper>(context, readerConfig));
    }
    }


    // External stylus-like devices.
    // External stylus-like devices.
    if (classes.test(InputDeviceClass::EXTERNAL_STYLUS)) {
    if (classes.test(InputDeviceClass::EXTERNAL_STYLUS)) {
        mappers.push_back(createInputMapper<ExternalStylusInputMapper>(contextPtr, readerConfig));
        mappers.push_back(createInputMapper<ExternalStylusInputMapper>(context, readerConfig));
    }
    }
    return mappers;
    return mappers;
}
}
+3 −1
Original line number Original line Diff line number Diff line
@@ -334,7 +334,9 @@ 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);
    device->addEmptyEventHubDevice(eventHubId);
    auto unused = device->configure(systemTime(SYSTEM_TIME_MONOTONIC), mConfig, /*changes=*/{});
    device->populateMappers(eventHubId, mConfig);
    return device;
    return device;
}
}


+2 −2
Original line number Original line Diff line number Diff line
@@ -81,7 +81,7 @@ 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);
    void populateMappers(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,
@@ -203,7 +203,7 @@ private:
    int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc);
    int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc);


    std::vector<std::unique_ptr<InputMapper>> createMappers(
    std::vector<std::unique_ptr<InputMapper>> createMappers(
            InputDeviceContext& contextPtr, const InputReaderConfiguration& readerConfig);
            InputDeviceContext& context, const InputReaderConfiguration& readerConfig);


    PropertyMap mConfiguration;
    PropertyMap mConfiguration;


+4 −1
Original line number Original line Diff line number Diff line
@@ -2584,7 +2584,10 @@ 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());
    device.addEmptyEventHubDevice(TEST_EVENTHUB_ID);
    auto unused = device.configure(systemTime(SYSTEM_TIME_MONOTONIC),
                                   mFakePolicy->getReaderConfiguration(), /*changes=*/{});
    device.populateMappers(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);