Add an API to get the supported USI version for a display
The InputManager#getHostUsiVersion(displayId) API can be used to tell if
a display supports the Universal Stylus Initiative protocol for styluses,
and can be used to address version compatibility issues.
We first dynamically attempt to find an InputDevice associated with the
display that supports USI. If there are none, we check the statically
add USI version for the display in config_displayUsiVersionArray.
Checking the config as a fallback means the USI InputDevice does not
have be registered/open perpetually for the getHostUsiVersion() API to
return the correct values.
Bug: 261596890
Test: manual with device
Test: atest TouchScreenTest
Change-Id: Ifabd00aa996ba88258d8112e5de3582adaf27629
diff --git a/include/input/InputDevice.h b/include/input/InputDevice.h
index 09933d3..66d3435 100644
--- a/include/input/InputDevice.h
+++ b/include/input/InputDevice.h
@@ -214,6 +214,12 @@
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 @@
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 @@
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 @@
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;
diff --git a/libs/input/InputDevice.cpp b/libs/input/InputDevice.cpp
index 87333f2..9c7c0c1 100644
--- a/libs/input/InputDevice.cpp
+++ b/libs/input/InputDevice.cpp
@@ -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 @@
// --- 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 @@
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 @@
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 @@
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();
diff --git a/services/inputflinger/reader/InputDevice.cpp b/services/inputflinger/reader/InputDevice.cpp
index 6e78e82..9bd50f7 100644
--- a/services/inputflinger/reader/InputDevice.cpp
+++ b/services/inputflinger/reader/InputDevice.cpp
@@ -452,7 +452,8 @@
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); });
diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.cpp b/services/inputflinger/reader/mapper/TouchInputMapper.cpp
index 4d51aee..31287a3 100644
--- a/services/inputflinger/reader/mapper/TouchInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/TouchInputMapper.cpp
@@ -55,6 +55,10 @@
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 @@
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 @@
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 @@
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));
}
diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.h b/services/inputflinger/reader/mapper/TouchInputMapper.h
index 6e35b46..87deb39 100644
--- a/services/inputflinger/reader/mapper/TouchInputMapper.h
+++ b/services/inputflinger/reader/mapper/TouchInputMapper.h
@@ -234,8 +234,8 @@
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;
diff --git a/services/inputflinger/tests/PreferStylusOverTouch_test.cpp b/services/inputflinger/tests/PreferStylusOverTouch_test.cpp
index bd05360..7265362 100644
--- a/services/inputflinger/tests/PreferStylusOverTouch_test.cpp
+++ b/services/inputflinger/tests/PreferStylusOverTouch_test.cpp
@@ -15,6 +15,7 @@
*/
#include <gtest/gtest.h>
+#include <gui/constants.h>
#include "../PreferStylusOverTouchBlocker.h"
namespace android {
@@ -438,7 +439,7 @@
InputDeviceInfo stylusDevice;
stylusDevice.initialize(STYLUS_DEVICE_ID, 1 /*generation*/, 1 /*controllerNumber*/,
{} /*identifier*/, "stylus device", false /*external*/,
- false /*hasMic*/);
+ false /*hasMic*/, ADISPLAY_ID_NONE);
notifyInputDevicesChanged({stylusDevice});
// The touchscreen device was removed, so we no longer remember anything about it. We should
// again start blocking touch events from it.
diff --git a/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp b/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp
index 4c84160..e12f88e 100644
--- a/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp
+++ b/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp
@@ -105,7 +105,7 @@
auto info = InputDeviceInfo();
info.initialize(DEVICE_ID, /*generation*/ 1, /*controllerNumber*/ 1, identifier, "alias",
- /*isExternal*/ false, /*hasMic*/ false);
+ /*isExternal*/ false, /*hasMic*/ false, ADISPLAY_ID_NONE);
info.addSource(AINPUT_SOURCE_TOUCHSCREEN);
info.addMotionRange(AMOTION_EVENT_AXIS_X, AINPUT_SOURCE_TOUCHSCREEN, 0, 1599, /*flat*/ 0,
/*fuzz*/ 0, X_RESOLUTION);