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

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

Merge "InputMapper refactor: TouchInputMapper::Parameters" into udc-dev am: 449a984c

parents 711c5b1a 449a984c
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -407,7 +407,7 @@ public:
    inline const std::string getName() const { return mDevice.getName(); }
    inline const std::string getName() const { return mDevice.getName(); }
    inline const std::string getDescriptor() { return mDevice.getDescriptor(); }
    inline const std::string getDescriptor() { return mDevice.getDescriptor(); }
    inline const std::string getLocation() { return mDevice.getLocation(); }
    inline const std::string getLocation() { return mDevice.getLocation(); }
    inline bool isExternal() { return mDevice.isExternal(); }
    inline bool isExternal() const { return mDevice.isExternal(); }
    inline std::optional<uint8_t> getAssociatedDisplayPort() const {
    inline std::optional<uint8_t> getAssociatedDisplayPort() const {
        return mDevice.getAssociatedDisplayPort();
        return mDevice.getAssociatedDisplayPort();
    }
    }
@@ -424,7 +424,7 @@ public:
        return mDevice.cancelTouch(when, readTime);
        return mDevice.cancelTouch(when, readTime);
    }
    }
    inline void bumpGeneration() { mDevice.bumpGeneration(); }
    inline void bumpGeneration() { mDevice.bumpGeneration(); }
    inline const PropertyMap& getConfiguration() { return mDevice.getConfiguration(); }
    inline const PropertyMap& getConfiguration() const { return mDevice.getConfiguration(); }


private:
private:
    InputDevice& mDevice;
    InputDevice& mDevice;
+51 −45
Original line number Original line Diff line number Diff line
@@ -125,9 +125,8 @@ TouchInputMapper::TouchInputMapper(InputDeviceContext& deviceContext,
                                   const InputReaderConfiguration& readerConfig)
                                   const InputReaderConfiguration& readerConfig)
      : InputMapper(deviceContext, readerConfig),
      : InputMapper(deviceContext, readerConfig),
        mTouchButtonAccumulator(deviceContext),
        mTouchButtonAccumulator(deviceContext),
        mSource(0),
        mConfig(readerConfig),
        mDeviceMode(DeviceMode::DISABLED),
        mParameters(computeParameters(deviceContext)) {}
        mInputDeviceOrientation(ui::ROTATION_0) {}


TouchInputMapper::~TouchInputMapper() {}
TouchInputMapper::~TouchInputMapper() {}


@@ -300,7 +299,7 @@ std::list<NotifyArgs> TouchInputMapper::reconfigure(nsecs_t when,
    // various other parameters so should result in a reconfiguration.
    // various other parameters so should result in a reconfiguration.
    if (!changes.any() || changes.test(InputReaderConfiguration::Change::DEVICE_TYPE)) {
    if (!changes.any() || changes.test(InputReaderConfiguration::Change::DEVICE_TYPE)) {
        // Configure basic parameters.
        // Configure basic parameters.
        configureParameters();
        mParameters = computeParameters(getDeviceContext());


        // Configure common accumulators.
        // Configure common accumulators.
        mCursorScrollAccumulator.configure(getDeviceContext());
        mCursorScrollAccumulator.configure(getDeviceContext());
@@ -361,112 +360,119 @@ void TouchInputMapper::resolveExternalStylusPresence() {
    }
    }
}
}


void TouchInputMapper::configureParameters() {
TouchInputMapper::Parameters TouchInputMapper::computeParameters(
        const InputDeviceContext& deviceContext) {
    Parameters parameters;
    // Use the pointer presentation mode for devices that do not support distinct
    // Use the pointer presentation mode for devices that do not support distinct
    // multitouch.  The spot-based presentation relies on being able to accurately
    // multitouch.  The spot-based presentation relies on being able to accurately
    // locate two or more fingers on the touch pad.
    // locate two or more fingers on the touch pad.
    mParameters.gestureMode = getDeviceContext().hasInputProperty(INPUT_PROP_SEMI_MT)
    parameters.gestureMode = deviceContext.hasInputProperty(INPUT_PROP_SEMI_MT)
            ? Parameters::GestureMode::SINGLE_TOUCH
            ? Parameters::GestureMode::SINGLE_TOUCH
            : Parameters::GestureMode::MULTI_TOUCH;
            : Parameters::GestureMode::MULTI_TOUCH;


    const PropertyMap& config = getDeviceContext().getConfiguration();
    const PropertyMap& config = deviceContext.getConfiguration();
    std::optional<std::string> gestureModeString = config.getString("touch.gestureMode");
    std::optional<std::string> gestureModeString = config.getString("touch.gestureMode");
    if (gestureModeString.has_value()) {
    if (gestureModeString.has_value()) {
        if (*gestureModeString == "single-touch") {
        if (*gestureModeString == "single-touch") {
            mParameters.gestureMode = Parameters::GestureMode::SINGLE_TOUCH;
            parameters.gestureMode = Parameters::GestureMode::SINGLE_TOUCH;
        } else if (*gestureModeString == "multi-touch") {
        } else if (*gestureModeString == "multi-touch") {
            mParameters.gestureMode = Parameters::GestureMode::MULTI_TOUCH;
            parameters.gestureMode = Parameters::GestureMode::MULTI_TOUCH;
        } else if (*gestureModeString != "default") {
        } else if (*gestureModeString != "default") {
            ALOGW("Invalid value for touch.gestureMode: '%s'", gestureModeString->c_str());
            ALOGW("Invalid value for touch.gestureMode: '%s'", gestureModeString->c_str());
        }
        }
    }
    }


    configureDeviceType();
    parameters.deviceType = computeDeviceType(deviceContext);


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


    mParameters.orientationAware =
    parameters.orientationAware =
            config.getBool("touch.orientationAware")
            config.getBool("touch.orientationAware")
                    .value_or(mParameters.deviceType == Parameters::DeviceType::TOUCH_SCREEN);
                    .value_or(parameters.deviceType == Parameters::DeviceType::TOUCH_SCREEN);


    mParameters.orientation = ui::ROTATION_0;
    parameters.orientation = ui::ROTATION_0;
    std::optional<std::string> orientationString = config.getString("touch.orientation");
    std::optional<std::string> orientationString = config.getString("touch.orientation");
    if (orientationString.has_value()) {
    if (orientationString.has_value()) {
        if (mParameters.deviceType != Parameters::DeviceType::TOUCH_SCREEN) {
        if (parameters.deviceType != Parameters::DeviceType::TOUCH_SCREEN) {
            ALOGW("The configuration 'touch.orientation' is only supported for touchscreens.");
            ALOGW("The configuration 'touch.orientation' is only supported for touchscreens.");
        } else if (*orientationString == "ORIENTATION_90") {
        } else if (*orientationString == "ORIENTATION_90") {
            mParameters.orientation = ui::ROTATION_90;
            parameters.orientation = ui::ROTATION_90;
        } else if (*orientationString == "ORIENTATION_180") {
        } else if (*orientationString == "ORIENTATION_180") {
            mParameters.orientation = ui::ROTATION_180;
            parameters.orientation = ui::ROTATION_180;
        } else if (*orientationString == "ORIENTATION_270") {
        } else if (*orientationString == "ORIENTATION_270") {
            mParameters.orientation = ui::ROTATION_270;
            parameters.orientation = ui::ROTATION_270;
        } else if (*orientationString != "ORIENTATION_0") {
        } else if (*orientationString != "ORIENTATION_0") {
            ALOGW("Invalid value for touch.orientation: '%s'", orientationString->c_str());
            ALOGW("Invalid value for touch.orientation: '%s'", orientationString->c_str());
        }
        }
    }
    }


    mParameters.hasAssociatedDisplay = false;
    parameters.hasAssociatedDisplay = false;
    mParameters.associatedDisplayIsExternal = false;
    parameters.associatedDisplayIsExternal = false;
    if (mParameters.orientationAware ||
    if (parameters.orientationAware ||
        mParameters.deviceType == Parameters::DeviceType::TOUCH_SCREEN ||
        parameters.deviceType == Parameters::DeviceType::TOUCH_SCREEN ||
        mParameters.deviceType == Parameters::DeviceType::POINTER ||
        parameters.deviceType == Parameters::DeviceType::POINTER ||
        (mParameters.deviceType == Parameters::DeviceType::TOUCH_NAVIGATION &&
        (parameters.deviceType == Parameters::DeviceType::TOUCH_NAVIGATION &&
         getDeviceContext().getAssociatedViewport())) {
         deviceContext.getAssociatedViewport())) {
        mParameters.hasAssociatedDisplay = true;
        parameters.hasAssociatedDisplay = true;
        if (mParameters.deviceType == Parameters::DeviceType::TOUCH_SCREEN) {
        if (parameters.deviceType == Parameters::DeviceType::TOUCH_SCREEN) {
            mParameters.associatedDisplayIsExternal = getDeviceContext().isExternal();
            parameters.associatedDisplayIsExternal = deviceContext.isExternal();
            mParameters.uniqueDisplayId = config.getString("touch.displayId").value_or("").c_str();
            parameters.uniqueDisplayId = config.getString("touch.displayId").value_or("").c_str();
        }
        }
    }
    }
    if (getDeviceContext().getAssociatedDisplayPort()) {
    if (deviceContext.getAssociatedDisplayPort()) {
        mParameters.hasAssociatedDisplay = true;
        parameters.hasAssociatedDisplay = true;
    }
    }


    // Initial downs on external touch devices should wake the device.
    // Initial downs on external touch devices should wake the device.
    // Normally we don't do this for internal touch screens to prevent them from waking
    // Normally we don't do this for internal touch screens to prevent them from waking
    // up in your pocket but you can enable it using the input device configuration.
    // up in your pocket but you can enable it using the input device configuration.
    mParameters.wake = config.getBool("touch.wake").value_or(getDeviceContext().isExternal());
    parameters.wake = config.getBool("touch.wake").value_or(deviceContext.isExternal());


    std::optional<int32_t> usiVersionMajor = config.getInt("touch.usiVersionMajor");
    std::optional<int32_t> usiVersionMajor = config.getInt("touch.usiVersionMajor");
    std::optional<int32_t> usiVersionMinor = config.getInt("touch.usiVersionMinor");
    std::optional<int32_t> usiVersionMinor = config.getInt("touch.usiVersionMinor");
    if (usiVersionMajor.has_value() && usiVersionMinor.has_value()) {
    if (usiVersionMajor.has_value() && usiVersionMinor.has_value()) {
        mParameters.usiVersion = {
        parameters.usiVersion = {
                .majorVersion = *usiVersionMajor,
                .majorVersion = *usiVersionMajor,
                .minorVersion = *usiVersionMinor,
                .minorVersion = *usiVersionMinor,
        };
        };
    }
    }


    mParameters.enableForInactiveViewport =
    parameters.enableForInactiveViewport =
            config.getBool("touch.enableForInactiveViewport").value_or(false);
            config.getBool("touch.enableForInactiveViewport").value_or(false);

    return parameters;
}
}


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


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


void TouchInputMapper::dumpParameters(std::string& dump) {
void TouchInputMapper::dumpParameters(std::string& dump) {
+5 −6
Original line number Original line Diff line number Diff line
@@ -192,7 +192,7 @@ protected:
    };
    };


    // Input sources and device mode.
    // Input sources and device mode.
    uint32_t mSource;
    uint32_t mSource{0};


    enum class DeviceMode {
    enum class DeviceMode {
        DISABLED,   // input is disabled
        DISABLED,   // input is disabled
@@ -203,7 +203,7 @@ protected:


        ftl_last = POINTER
        ftl_last = POINTER
    };
    };
    DeviceMode mDeviceMode;
    DeviceMode mDeviceMode{DeviceMode::DISABLED};


    // The reader's configuration.
    // The reader's configuration.
    InputReaderConfiguration mConfig;
    InputReaderConfiguration mConfig;
@@ -377,7 +377,6 @@ protected:


    std::vector<VirtualKey> mVirtualKeys;
    std::vector<VirtualKey> mVirtualKeys;


    virtual void configureParameters();
    virtual void dumpParameters(std::string& dump);
    virtual void dumpParameters(std::string& dump);
    virtual void configureRawPointerAxes();
    virtual void configureRawPointerAxes();
    virtual void dumpRawPointerAxes(std::string& dump);
    virtual void dumpRawPointerAxes(std::string& dump);
@@ -413,7 +412,7 @@ private:
    // The orientation of the input device relative to that of the display panel. It specifies
    // The orientation of the input device relative to that of the display panel. It specifies
    // the rotation of the input device coordinates required to produce the display panel
    // the rotation of the input device coordinates required to produce the display panel
    // orientation, so it will depend on whether the device is orientation aware.
    // orientation, so it will depend on whether the device is orientation aware.
    ui::Rotation mInputDeviceOrientation;
    ui::Rotation mInputDeviceOrientation{ui::ROTATION_0};


    // The transform that maps the input device's raw coordinate space to the un-rotated display's
    // The transform that maps the input device's raw coordinate space to the un-rotated display's
    // coordinate space. InputReader generates events in the un-rotated display's coordinate space.
    // coordinate space. InputReader generates events in the un-rotated display's coordinate space.
@@ -824,8 +823,8 @@ private:


    // Compute input transforms for DIRECT and POINTER modes.
    // Compute input transforms for DIRECT and POINTER modes.
    void computeInputTransforms();
    void computeInputTransforms();

    static Parameters::DeviceType computeDeviceType(const InputDeviceContext& deviceContext);
    void configureDeviceType();
    static Parameters computeParameters(const InputDeviceContext& deviceContext);
};
};


} // namespace android
} // namespace android