Commit 9174ce4e authored by Michael Spang's avatar Michael Spang Committed by Commit Bot

ozone: evdev: Add some tests for internal USB device quirks

Add some tests for quirks to force USB devices to probe as internal
devices.

Bug: b/116723180
Test: events_unittests
Change-Id: Ic044d3db80034bf972f7099a569251f21d3da9ce
Reviewed-on: https://chromium-review.googlesource.com/c/1281226
Commit-Queue: Michael Spang <spang@chromium.org>
Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#599755}
parent 1a8e6069
......@@ -73,17 +73,12 @@ bool GetDeviceName(int fd, const base::FilePath& path, std::string* name) {
return true;
}
bool GetDeviceIdentifiers(int fd,
const base::FilePath& path,
uint16_t* vendor,
uint16_t* product) {
struct input_id evdev_id;
if (ioctl(fd, EVIOCGID, &evdev_id) < 0) {
bool GetDeviceIdentifiers(int fd, const base::FilePath& path, input_id* id) {
*id = {};
if (ioctl(fd, EVIOCGID, id) < 0) {
PLOG(INFO) << "Failed EVIOCGID (path=" << path.value() << ")";
return false;
}
*vendor = evdev_id.vendor;
*product = evdev_id.product;
return true;
}
......@@ -190,17 +185,14 @@ bool EventDeviceInfo::Initialize(int fd, const base::FilePath& path) {
if (!GetDeviceName(fd, path, &name_))
return false;
if (!GetDeviceIdentifiers(fd, path, &vendor_id_, &product_id_))
if (!GetDeviceIdentifiers(fd, path, &input_id_))
return false;
GetDevicePhysInfo(fd, path, &phys_);
device_type_ = GetInputDeviceTypeFromPath(path);
// TODO(spang): Implement these quirks in a better way.
constexpr uint16_t kGoogleVendorId = 0x18d1;
if (vendor_id_ == kGoogleVendorId && product_id_ == 0x5030)
device_type_ = InputDeviceType::INPUT_DEVICE_INTERNAL;
device_type_ = GetInputDeviceTypeFromId(input_id_);
if (device_type_ == InputDeviceType::INPUT_DEVICE_UNKNOWN)
device_type_ = GetInputDeviceTypeFromPath(path);
return true;
}
......@@ -267,9 +259,8 @@ void EventDeviceInfo::SetDeviceType(InputDeviceType type) {
device_type_ = type;
}
void EventDeviceInfo::SetId(uint16_t vendor_id, uint16_t product_id) {
vendor_id_ = vendor_id;
product_id_ = product_id;
void EventDeviceInfo::SetId(input_id id) {
input_id_ = id;
}
bool EventDeviceInfo::HasEventType(unsigned int type) const {
......@@ -465,6 +456,26 @@ bool EventDeviceInfo::HasGamepad() const {
return support_gamepad_btn && !HasTablet() && !HasKeyboard();
}
// static
ui::InputDeviceType EventDeviceInfo::GetInputDeviceTypeFromId(input_id id) {
constexpr uint16_t kGoogleVendorId = 0x18d1;
constexpr uint16_t kHammerProductId = 0x5030;
if (id.bustype == BUS_USB && id.vendor == kGoogleVendorId &&
id.product == kHammerProductId)
return InputDeviceType::INPUT_DEVICE_INTERNAL;
switch (id.bustype) {
case BUS_I2C:
return ui::InputDeviceType::INPUT_DEVICE_INTERNAL;
case BUS_USB:
return ui::InputDeviceType::INPUT_DEVICE_USB;
case BUS_BLUETOOTH:
return ui::InputDeviceType::INPUT_DEVICE_BLUETOOTH;
default:
return ui::InputDeviceType::INPUT_DEVICE_UNKNOWN;
}
}
EventDeviceInfo::LegacyAbsoluteDeviceType
EventDeviceInfo::ProbeLegacyAbsoluteDevice() const {
if (!HasAbsXY())
......
......@@ -69,7 +69,7 @@ class EVENTS_OZONE_EVDEV_EXPORT EventDeviceInfo {
void SetAbsMtSlots(unsigned int code, const std::vector<int32_t>& values);
void SetAbsMtSlot(unsigned int code, unsigned int slot, uint32_t value);
void SetDeviceType(InputDeviceType type);
void SetId(uint16_t vendor_id, uint16_t product_id);
void SetId(input_id id);
// Check events this device can generate.
bool HasEventType(unsigned int type) const;
......@@ -94,8 +94,9 @@ class EVENTS_OZONE_EVDEV_EXPORT EventDeviceInfo {
// Device identification.
const std::string& name() const { return name_; }
const std::string& phys() const { return phys_; }
uint16_t vendor_id() const { return vendor_id_; }
uint16_t product_id() const { return product_id_; }
uint16_t bustype() const { return input_id_.bustype; }
uint16_t vendor_id() const { return input_id_.vendor; }
uint16_t product_id() const { return input_id_.product; }
// Check input device properties.
bool HasProp(unsigned int code) const;
......@@ -147,6 +148,9 @@ class EVENTS_OZONE_EVDEV_EXPORT EventDeviceInfo {
// The device type (internal or external.)
InputDeviceType device_type() const { return device_type_; }
// Determines InputDeviceType from device identification.
static InputDeviceType GetInputDeviceTypeFromId(input_id id);
private:
enum class LegacyAbsoluteDeviceType {
TOUCHPAD,
......@@ -175,8 +179,7 @@ class EVENTS_OZONE_EVDEV_EXPORT EventDeviceInfo {
// Device identification.
std::string name_;
uint16_t vendor_id_;
uint16_t product_id_;
input_id input_id_ = {};
// Device evdev physical property containing the output for EVIOCGPHYS that is
// (supposed to be) stable between reboots and hotplugs.
......
......@@ -84,6 +84,8 @@ TEST_F(EventDeviceInfoTest, BasicUsbKeyboard) {
EXPECT_FALSE(devinfo.HasTouchscreen());
EXPECT_FALSE(devinfo.HasTablet());
EXPECT_FALSE(devinfo.HasGamepad());
EXPECT_EQ(ui::InputDeviceType::INPUT_DEVICE_USB, devinfo.device_type());
}
TEST_F(EventDeviceInfoTest, BasicUsbKeyboard_Extra) {
......@@ -96,6 +98,8 @@ TEST_F(EventDeviceInfoTest, BasicUsbKeyboard_Extra) {
EXPECT_FALSE(devinfo.HasTouchscreen());
EXPECT_FALSE(devinfo.HasTablet());
EXPECT_FALSE(devinfo.HasGamepad());
EXPECT_EQ(ui::InputDeviceType::INPUT_DEVICE_USB, devinfo.device_type());
}
TEST_F(EventDeviceInfoTest, BasicUsbMouse) {
......@@ -108,6 +112,8 @@ TEST_F(EventDeviceInfoTest, BasicUsbMouse) {
EXPECT_FALSE(devinfo.HasTouchscreen());
EXPECT_FALSE(devinfo.HasTablet());
EXPECT_FALSE(devinfo.HasGamepad());
EXPECT_EQ(ui::InputDeviceType::INPUT_DEVICE_USB, devinfo.device_type());
}
TEST_F(EventDeviceInfoTest, BasicUsbTouchscreen) {
......@@ -120,6 +126,8 @@ TEST_F(EventDeviceInfoTest, BasicUsbTouchscreen) {
EXPECT_TRUE(devinfo.HasTouchscreen());
EXPECT_FALSE(devinfo.HasTablet());
EXPECT_FALSE(devinfo.HasGamepad());
EXPECT_EQ(ui::InputDeviceType::INPUT_DEVICE_USB, devinfo.device_type());
}
TEST_F(EventDeviceInfoTest, BasicUsbTablet) {
......@@ -132,6 +140,8 @@ TEST_F(EventDeviceInfoTest, BasicUsbTablet) {
EXPECT_FALSE(devinfo.HasTouchscreen());
EXPECT_TRUE(devinfo.HasTablet());
EXPECT_FALSE(devinfo.HasGamepad());
EXPECT_EQ(ui::InputDeviceType::INPUT_DEVICE_USB, devinfo.device_type());
}
TEST_F(EventDeviceInfoTest, BasicUsbTouchpad) {
......@@ -144,6 +154,8 @@ TEST_F(EventDeviceInfoTest, BasicUsbTouchpad) {
EXPECT_FALSE(devinfo.HasTouchscreen());
EXPECT_FALSE(devinfo.HasTablet());
EXPECT_FALSE(devinfo.HasGamepad());
EXPECT_EQ(ui::InputDeviceType::INPUT_DEVICE_USB, devinfo.device_type());
}
TEST_F(EventDeviceInfoTest, HybridKeyboardWithMouse) {
......@@ -170,6 +182,8 @@ TEST_F(EventDeviceInfoTest, AbsoluteMouseTouchscreen) {
EXPECT_TRUE(devinfo.HasTouchscreen());
EXPECT_FALSE(devinfo.HasTablet());
EXPECT_FALSE(devinfo.HasGamepad());
EXPECT_EQ(ui::InputDeviceType::INPUT_DEVICE_USB, devinfo.device_type());
}
TEST_F(EventDeviceInfoTest, OnScreenStylus) {
......@@ -182,6 +196,36 @@ TEST_F(EventDeviceInfoTest, OnScreenStylus) {
EXPECT_TRUE(devinfo.HasTouchscreen());
EXPECT_FALSE(devinfo.HasTablet());
EXPECT_FALSE(devinfo.HasGamepad());
EXPECT_EQ(ui::InputDeviceType::INPUT_DEVICE_INTERNAL, devinfo.device_type());
}
TEST_F(EventDeviceInfoTest, HammerKeyboard) {
EventDeviceInfo devinfo;
EXPECT_TRUE(CapabilitiesToDeviceInfo(kHammerKeyboard, &devinfo));
EXPECT_TRUE(devinfo.HasKeyboard());
EXPECT_FALSE(devinfo.HasMouse());
EXPECT_FALSE(devinfo.HasTouchpad());
EXPECT_FALSE(devinfo.HasTouchscreen());
EXPECT_FALSE(devinfo.HasTablet());
EXPECT_FALSE(devinfo.HasGamepad());
EXPECT_EQ(ui::InputDeviceType::INPUT_DEVICE_INTERNAL, devinfo.device_type());
}
TEST_F(EventDeviceInfoTest, HammerTouchpad) {
EventDeviceInfo devinfo;
EXPECT_TRUE(CapabilitiesToDeviceInfo(kHammerTouchpad, &devinfo));
EXPECT_FALSE(devinfo.HasKeyboard());
EXPECT_FALSE(devinfo.HasMouse());
EXPECT_TRUE(devinfo.HasTouchpad());
EXPECT_FALSE(devinfo.HasTouchscreen());
EXPECT_FALSE(devinfo.HasTablet());
EXPECT_FALSE(devinfo.HasGamepad());
EXPECT_EQ(ui::InputDeviceType::INPUT_DEVICE_INTERNAL, devinfo.device_type());
}
} // namespace ui
......@@ -627,19 +627,66 @@ const DeviceCapabilities kEveStylus = {
arraysize(kEveStylusAbsAxes),
};
ui::InputDeviceType InputDeviceTypeFromBusType(int bustype) {
switch (bustype) {
case BUS_I8042:
case BUS_I2C:
return ui::InputDeviceType::INPUT_DEVICE_INTERNAL;
case BUS_USB:
case 0x1D: // Used in kLogitechTouchKeyboardK400 but not listed in input.h.
return ui::InputDeviceType::INPUT_DEVICE_USB;
default:
NOTREACHED() << "Unexpected bus type";
return ui::InputDeviceType::INPUT_DEVICE_UNKNOWN;
}
}
const DeviceCapabilities kHammerKeyboard = {
/* path */
"/sys/devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0/0003:18D1:5030.0002/"
"input/input10/event9",
/* name */ "Google Inc. Hammer",
/* phys */ "usb-0000:00:14.0-7/input0",
/* uniq */ "410020000d57345436313920",
/* bustype */ "0003",
/* vendor */ "18d1",
/* product */ "5030",
/* version */ "0100",
/* prop */ "0",
/* ev */ "100013",
/* key */
"88 0 0 0 0 0 1000000000007 ff000000000007ff febeffdfffefffff "
"fffffffffffffffe",
/* rel */ "0",
/* abs */ "0",
/* msc */ "10",
/* sw */ "0",
/* led */ "0",
/* ff */ "0",
};
const DeviceAbsoluteAxis kHammerTouchpadAbsAxes[] = {
{ABS_X, {0, 0, 2160, 0, 0, 21}},
{ABS_Y, {0, 0, 1080, 0, 0, 14}},
{ABS_PRESSURE, {0, 0, 255, 0, 0, 0}},
{ABS_MT_SLOT, {0, 0, 9, 0, 0, 0}},
{ABS_MT_TOUCH_MAJOR, {0, 0, 255, 0, 0, 3}},
{ABS_MT_TOUCH_MINOR, {0, 0, 255, 0, 0, 3}},
{ABS_MT_ORIENTATION, {0, 0, 1, 0, 0, 0}},
{ABS_MT_POSITION_X, {0, 0, 2160, 0, 0, 21}},
{ABS_MT_POSITION_Y, {0, 0, 1080, 0, 0, 14}},
{ABS_MT_TRACKING_ID, {0, 0, 65535, 0, 0, 0}},
{ABS_MT_PRESSURE, {0, 0, 255, 0, 0, 0}},
};
const DeviceCapabilities kHammerTouchpad = {
/* path */
"/sys/devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.2/0003:18D1:5030.0003/"
"input/input11/event10",
/* name */ "Google Inc. Hammer Touchpad",
/* phys */ "usb-0000:00:14.0-7/input2",
/* uniq */ "410020000d57345436313920",
/* bustype */ "0003",
/* vendor */ "18d1",
/* product */ "5030",
/* version */ "0100",
/* prop */ "5",
/* ev */ "1b",
/* key */ "e520 10000 0 0 0 0",
/* rel */ "0",
/* abs */ "673800001000003",
/* msc */ "20",
/* sw */ "0",
/* led */ "0",
/* ff */ "0",
kHammerTouchpadAbsAxes,
arraysize(kHammerTouchpadAbsAxes),
};
bool CapabilitiesToDeviceInfo(const DeviceCapabilities& capabilities,
EventDeviceInfo* devinfo) {
......@@ -695,17 +742,14 @@ bool CapabilitiesToDeviceInfo(const DeviceCapabilities& capabilities,
devinfo->SetAbsMtSlots(code, zero_slots);
}
int bustype = 0;
sscanf(capabilities.bustype, "%x", &bustype);
devinfo->SetDeviceType(InputDeviceTypeFromBusType(bustype));
int vendor_id = 0;
int product_id = 0;
input_id id = {};
sscanf(capabilities.vendor, "%" SCNx16, &id.vendor);
sscanf(capabilities.product, "%" SCNx16, &id.product);
sscanf(capabilities.bustype, "%" SCNx16, &id.bustype);
sscanf(capabilities.version, "%" SCNx16, &id.version);
devinfo->SetId(id);
devinfo->SetDeviceType(EventDeviceInfo::GetInputDeviceTypeFromId(id));
sscanf(capabilities.vendor, "%x", &vendor_id);
sscanf(capabilities.product, "%x", &product_id);
devinfo->SetId(static_cast<uint16_t>(vendor_id),
static_cast<uint16_t>(product_id));
return true;
}
......
......@@ -77,6 +77,8 @@ extern const DeviceCapabilities kLogitechTouchKeyboardK400;
extern const DeviceCapabilities kElo_TouchSystems_2700;
extern const DeviceCapabilities kWilsonBeachActiveStylus;
extern const DeviceCapabilities kEveStylus;
extern const DeviceCapabilities kHammerKeyboard;
extern const DeviceCapabilities kHammerTouchpad;
} // namspace ui
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment