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

Commit d3cf4c28 authored by Prabir Pradhan's avatar Prabir Pradhan Committed by Android (Google) Code Review
Browse files

Merge "Add an API to get the supported USI version for a display"

parents 5568dbec e04ffaaa
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -214,6 +214,12 @@ struct KeyboardLayoutInfo {
    std::string layoutType;
};

// The version of the Universal Stylus Initiative (USI) protocol supported by the input device.
struct InputDeviceUsiVersion {
    int32_t majorVersion = -1;
    int32_t minorVersion = -1;
};

/*
 * Describes the characteristics and capabilities of an input device.
 */
@@ -235,7 +241,7 @@ public:

    void initialize(int32_t id, int32_t generation, int32_t controllerNumber,
                    const InputDeviceIdentifier& identifier, const std::string& alias,
                    bool isExternal, bool hasMic);
                    bool isExternal, bool hasMic, int32_t associatedDisplayId);

    inline int32_t getId() const { return mId; }
    inline int32_t getControllerNumber() const { return mControllerNumber; }
@@ -295,8 +301,12 @@ public:

    std::vector<InputDeviceLightInfo> getLights();

    inline void setSupportsUsi(bool supportsUsi) { mSupportsUsi = supportsUsi; }
    inline bool supportsUsi() const { return mSupportsUsi; }
    inline void setUsiVersion(std::optional<InputDeviceUsiVersion> usiVersion) {
        mUsiVersion = std::move(usiVersion);
    }
    inline std::optional<InputDeviceUsiVersion> getUsiVersion() const { return mUsiVersion; }

    inline int32_t getAssociatedDisplayId() const { return mAssociatedDisplayId; }

private:
    int32_t mId;
@@ -310,8 +320,8 @@ private:
    uint32_t mSources;
    int32_t mKeyboardType;
    std::shared_ptr<KeyCharacterMap> mKeyCharacterMap;
    // Whether this device supports the Universal Stylus Initiative (USI) protocol for styluses.
    bool mSupportsUsi;
    std::optional<InputDeviceUsiVersion> mUsiVersion;
    int32_t mAssociatedDisplayId;

    bool mHasVibrator;
    bool mHasBattery;
+7 −4
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@

#include <android-base/stringprintf.h>
#include <ftl/enum.h>
#include <gui/constants.h>
#include <input/InputDevice.h>
#include <input/InputEventLabels.h>

@@ -166,7 +167,7 @@ std::string InputDeviceIdentifier::getCanonicalName() const {
// --- InputDeviceInfo ---

InputDeviceInfo::InputDeviceInfo() {
    initialize(-1, 0, -1, InputDeviceIdentifier(), "", false, false);
    initialize(-1, 0, -1, InputDeviceIdentifier(), "", false, false, ADISPLAY_ID_NONE);
}

InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other)
@@ -181,7 +182,8 @@ InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other)
        mSources(other.mSources),
        mKeyboardType(other.mKeyboardType),
        mKeyCharacterMap(other.mKeyCharacterMap),
        mSupportsUsi(other.mSupportsUsi),
        mUsiVersion(other.mUsiVersion),
        mAssociatedDisplayId(other.mAssociatedDisplayId),
        mHasVibrator(other.mHasVibrator),
        mHasBattery(other.mHasBattery),
        mHasButtonUnderPad(other.mHasButtonUnderPad),
@@ -195,7 +197,7 @@ InputDeviceInfo::~InputDeviceInfo() {

void InputDeviceInfo::initialize(int32_t id, int32_t generation, int32_t controllerNumber,
                                 const InputDeviceIdentifier& identifier, const std::string& alias,
                                 bool isExternal, bool hasMic) {
                                 bool isExternal, bool hasMic, int32_t associatedDisplayId) {
    mId = id;
    mGeneration = generation;
    mControllerNumber = controllerNumber;
@@ -205,11 +207,12 @@ void InputDeviceInfo::initialize(int32_t id, int32_t generation, int32_t control
    mHasMic = hasMic;
    mSources = 0;
    mKeyboardType = AINPUT_KEYBOARD_TYPE_NONE;
    mAssociatedDisplayId = associatedDisplayId;
    mHasVibrator = false;
    mHasBattery = false;
    mHasButtonUnderPad = false;
    mHasSensor = false;
    mSupportsUsi = false;
    mUsiVersion.reset();
    mMotionRanges.clear();
    mSensors.clear();
    mLights.clear();
+2 −1
Original line number Diff line number Diff line
@@ -452,7 +452,8 @@ std::list<NotifyArgs> InputDevice::updateExternalStylusState(const StylusState&
InputDeviceInfo InputDevice::getDeviceInfo() {
    InputDeviceInfo outDeviceInfo;
    outDeviceInfo.initialize(mId, mGeneration, mControllerNumber, mIdentifier, mAlias, mIsExternal,
                             mHasMic);
                             mHasMic, getAssociatedDisplayId().value_or(ADISPLAY_ID_NONE));

    for_each_mapper(
            [&outDeviceInfo](InputMapper& mapper) { mapper.populateDeviceInfo(&outDeviceInfo); });

+14 −5
Original line number Diff line number Diff line
@@ -55,6 +55,10 @@ static bool isPointInRect(const Rect& rect, vec2 p) {
    return p.x >= rect.left && p.x < rect.right && p.y >= rect.top && p.y < rect.bottom;
}

static std::string toString(const InputDeviceUsiVersion& v) {
    return base::StringPrintf("%d.%d", v.majorVersion, v.minorVersion);
}

template <typename T>
inline static void swap(T& a, T& b) {
    T temp = a;
@@ -188,7 +192,7 @@ void TouchInputMapper::populateDeviceInfo(InputDeviceInfo* info) {
        info->addMotionRange(AMOTION_EVENT_AXIS_HSCROLL, mSource, -1.0f, 1.0f, 0.0f, 0.0f, 0.0f);
    }
    info->setButtonUnderPad(mParameters.hasButtonUnderPad);
    info->setSupportsUsi(mParameters.supportsUsi);
    info->setUsiVersion(mParameters.usiVersion);
}

void TouchInputMapper::dump(std::string& dump) {
@@ -421,9 +425,13 @@ void TouchInputMapper::configureParameters() {
    mParameters.wake = getDeviceContext().isExternal();
    getDeviceContext().getConfiguration().tryGetProperty("touch.wake", mParameters.wake);

    mParameters.supportsUsi = false;
    getDeviceContext().getConfiguration().tryGetProperty("touch.supportsUsi",
                                                         mParameters.supportsUsi);
    InputDeviceUsiVersion usiVersion;
    if (getDeviceContext().getConfiguration().tryGetProperty("touch.usiVersionMajor",
                                                             usiVersion.majorVersion) &&
        getDeviceContext().getConfiguration().tryGetProperty("touch.usiVersionMinor",
                                                             usiVersion.minorVersion)) {
        mParameters.usiVersion = usiVersion;
    }

    mParameters.enableForInactiveViewport = false;
    getDeviceContext().getConfiguration().tryGetProperty("touch.enableForInactiveViewport",
@@ -472,7 +480,8 @@ void TouchInputMapper::dumpParameters(std::string& dump) {
                         mParameters.uniqueDisplayId.c_str());
    dump += StringPrintf(INDENT4 "OrientationAware: %s\n", toString(mParameters.orientationAware));
    dump += INDENT4 "Orientation: " + ftl::enum_string(mParameters.orientation) + "\n";
    dump += StringPrintf(INDENT4 "SupportsUsi: %s\n", toString(mParameters.supportsUsi));
    dump += StringPrintf(INDENT4 "UsiVersion: %s\n",
                         toString(mParameters.usiVersion, toString).c_str());
    dump += StringPrintf(INDENT4 "EnableForInactiveViewport: %s\n",
                         toString(mParameters.enableForInactiveViewport));
}
+2 −2
Original line number Diff line number Diff line
@@ -234,8 +234,8 @@ protected:

        bool wake;

        // Whether the device supports the Universal Stylus Initiative (USI) protocol for styluses.
        bool supportsUsi;
        // The Universal Stylus Initiative (USI) protocol version supported by this device.
        std::optional<InputDeviceUsiVersion> usiVersion;

        // Allows touches while the display is off.
        bool enableForInactiveViewport;
Loading