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

Commit 7bc23bf2 authored by Ambrus Weisz's avatar Ambrus Weisz
Browse files

Update TouchInputMapper to support new VirtualNavigationTouchpad.

This change propagates type associations to InputDevice.cpp. The type associations are used there to define the device type for touch input mapper to use. This is required because of the virtual nature of the navigation touchpad the implementation can't rely on idc files.

Design doc: http://go/virtual-touchpad
Test: atest cts/tests/tests/hardware/src/android/hardware/input/cts/tests/VirtualNavigationTouchpadTest
Test: atest frameworks/native/services/inputflinger/tests/InputReader_test.cpp
Bug: 252767726

Change-Id: Ia4252460c16deb093d61b059e5030d902a4c9a2c
parent f8bdc4cd
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -191,6 +191,9 @@ struct InputReaderConfiguration {
        // The set of disabled input devices (disabledDevices) has changed.
        CHANGE_ENABLED_STATE = 1 << 9,

        // The device type has been updated.
        CHANGE_DEVICE_TYPE = 1 << 10,

        // All devices must be reopened.
        CHANGE_MUST_REOPEN = 1 << 31,
    };
@@ -212,6 +215,10 @@ struct InputReaderConfiguration {
    // Used to determine which DisplayViewport should be tied to which InputDevice.
    std::unordered_map<std::string, std::string> uniqueIdAssociations;

    // The associations between input device ports device types.
    // This is used to determine which device type and source should be tied to which InputDevice.
    std::unordered_map<std::string, std::string> deviceTypeAssociations;

    // The suggested display ID to show the cursor.
    int32_t defaultPointerDisplayId;

@@ -326,7 +333,6 @@ struct InputReaderConfiguration {
    std::optional<DisplayViewport> getDisplayViewportById(int32_t displayId) const;
    void setDisplayViewports(const std::vector<DisplayViewport>& viewports);


    void dump(std::string& dump) const;
    void dumpViewport(std::string& dump, const DisplayViewport& viewport) const;

+13 −0
Original line number Diff line number Diff line
@@ -56,6 +56,16 @@ InputDevice::InputDevice(InputReaderContext* context, int32_t id, int32_t genera

InputDevice::~InputDevice() {}

template <typename K, typename V>
std::optional<V> getValueByKey(const std::unordered_map<K, V>& map, K key) {
    auto it = map.find(key);
    std::optional<V> value = std::nullopt;
    if (it != map.end()) {
        value = it->second;
    }
    return value;
}

bool InputDevice::isEnabled() {
    if (!hasEventHubDevices()) {
        return false;
@@ -291,6 +301,9 @@ std::list<NotifyArgs> InputDevice::configure(nsecs_t when, const InputReaderConf
                context.getConfiguration(&configuration);
                mConfiguration.addAll(&configuration);
            });

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

        if (!changes || (changes & InputReaderConfiguration::CHANGE_KEYBOARD_LAYOUTS)) {
+7 −0
Original line number Diff line number Diff line
@@ -65,6 +65,9 @@ public:
    inline std::optional<std::string> getAssociatedDisplayUniqueId() const {
        return mAssociatedDisplayUniqueId;
    }
    inline std::optional<std::string> getDeviceTypeAssociation() const {
        return mAssociatedDeviceType;
    }
    inline std::optional<DisplayViewport> getAssociatedViewport() const {
        return mAssociatedViewport;
    }
@@ -180,6 +183,7 @@ private:
    bool mIsExternal;
    std::optional<uint8_t> mAssociatedDisplayPort;
    std::optional<std::string> mAssociatedDisplayUniqueId;
    std::optional<std::string> mAssociatedDeviceType;
    std::optional<DisplayViewport> mAssociatedViewport;
    bool mHasMic;
    bool mDropUntilNextSync;
@@ -408,6 +412,9 @@ public:
    inline std::optional<std::string> getAssociatedDisplayUniqueId() const {
        return mDevice.getAssociatedDisplayUniqueId();
    }
    inline std::optional<std::string> getDeviceTypeAssociation() const {
        return mDevice.getDeviceTypeAssociation();
    }
    inline std::optional<DisplayViewport> getAssociatedViewport() const {
        return mDevice.getAssociatedViewport();
    }
+32 −25
Original line number Diff line number Diff line
@@ -392,33 +392,10 @@ void TouchInputMapper::configureParameters() {
        }
    }

    if (getDeviceContext().hasInputProperty(INPUT_PROP_DIRECT)) {
        // The device is a touch screen.
        mParameters.deviceType = Parameters::DeviceType::TOUCH_SCREEN;
    } else if (getDeviceContext().hasInputProperty(INPUT_PROP_POINTER)) {
        // The device is a pointing device like a track pad.
        mParameters.deviceType = Parameters::DeviceType::POINTER;
    } else {
        // The device is a touch pad of unknown purpose.
        mParameters.deviceType = Parameters::DeviceType::POINTER;
    }
    configureDeviceType();

    mParameters.hasButtonUnderPad = getDeviceContext().hasInputProperty(INPUT_PROP_BUTTONPAD);

    std::string deviceTypeString;
    if (getDeviceContext().getConfiguration().tryGetProperty("touch.deviceType",
                                                             deviceTypeString)) {
        if (deviceTypeString == "touchScreen") {
            mParameters.deviceType = Parameters::DeviceType::TOUCH_SCREEN;
        } else if (deviceTypeString == "touchNavigation") {
            mParameters.deviceType = Parameters::DeviceType::TOUCH_NAVIGATION;
        } else if (deviceTypeString == "pointer") {
            mParameters.deviceType = Parameters::DeviceType::POINTER;
        } else if (deviceTypeString != "default") {
            ALOGW("Invalid value for touch.deviceType: '%s'", deviceTypeString.c_str());
        }
    }

    mParameters.orientationAware = mParameters.deviceType == Parameters::DeviceType::TOUCH_SCREEN;
    getDeviceContext().getConfiguration().tryGetProperty("touch.orientationAware",
                                                         mParameters.orientationAware);
@@ -444,7 +421,9 @@ void TouchInputMapper::configureParameters() {
    mParameters.associatedDisplayIsExternal = false;
    if (mParameters.orientationAware ||
        mParameters.deviceType == Parameters::DeviceType::TOUCH_SCREEN ||
        mParameters.deviceType == Parameters::DeviceType::POINTER) {
        mParameters.deviceType == Parameters::DeviceType::POINTER ||
        (mParameters.deviceType == Parameters::DeviceType::TOUCH_NAVIGATION &&
         getDeviceContext().getAssociatedViewport())) {
        mParameters.hasAssociatedDisplay = true;
        if (mParameters.deviceType == Parameters::DeviceType::TOUCH_SCREEN) {
            mParameters.associatedDisplayIsExternal = getDeviceContext().isExternal();
@@ -473,6 +452,34 @@ void TouchInputMapper::configureParameters() {
                                                         mParameters.enableForInactiveViewport);
}

void TouchInputMapper::configureDeviceType() {
    if (getDeviceContext().hasInputProperty(INPUT_PROP_DIRECT)) {
        // The device is a touch screen.
        mParameters.deviceType = Parameters::DeviceType::TOUCH_SCREEN;
    } else if (getDeviceContext().hasInputProperty(INPUT_PROP_POINTER)) {
        // The device is a pointing device like a track pad.
        mParameters.deviceType = Parameters::DeviceType::POINTER;
    } else {
        // The device is a touch pad of unknown purpose.
        mParameters.deviceType = Parameters::DeviceType::POINTER;
    }

    // Type association takes precedence over the device type found in the idc file.
    std::string deviceTypeString = getDeviceContext().getDeviceTypeAssociation().value_or("");
    if (deviceTypeString.empty()) {
        getDeviceContext().getConfiguration().tryGetProperty("touch.deviceType", deviceTypeString);
    }
    if (deviceTypeString == "touchScreen") {
        mParameters.deviceType = Parameters::DeviceType::TOUCH_SCREEN;
    } else if (deviceTypeString == "touchNavigation") {
        mParameters.deviceType = Parameters::DeviceType::TOUCH_NAVIGATION;
    } else if (deviceTypeString == "pointer") {
        mParameters.deviceType = Parameters::DeviceType::POINTER;
    } else if (deviceTypeString != "default" && deviceTypeString != "") {
        ALOGW("Invalid value for touch.deviceType: '%s'", deviceTypeString.c_str());
    }
}

void TouchInputMapper::dumpParameters(std::string& dump) {
    dump += INDENT3 "Parameters:\n";

+2 −0
Original line number Diff line number Diff line
@@ -814,6 +814,8 @@ private:
    static void assignPointerIds(const RawState& last, RawState& current);

    void rotateAndScale(float& x, float& y) const;

    void configureDeviceType();
};

} // namespace android
Loading