Commit c61e0f5a authored by spang's avatar spang Committed by Commit bot

events: Generalize IsTouchscreenInternal to any device type

This logic can also be used for keyboards, mice, touchpads, and tablets.

TEST=chrome on link_freon & rush_ryu
BUG=437539

Review URL: https://codereview.chromium.org/791743004

Cr-Commit-Position: refs/heads/master@{#308082}
parent 6d49e5ca
......@@ -14,12 +14,11 @@
namespace ui {
// We consider the touchscreen to be internal if it is an I2c device.
bool IsTouchscreenInternal(const base::FilePath& path) {
InputDeviceType GetInputDeviceTypeFromPath(const base::FilePath& path) {
DCHECK(!base::MessageLoopForUI::IsCurrent());
std::string event_node = path.BaseName().value();
if (event_node.empty() || !StartsWithASCII(event_node, "event", false))
return false;
return InputDeviceType::INPUT_DEVICE_UNKNOWN;
// Find sysfs device path for this device.
base::FilePath sysfs_path =
......@@ -29,19 +28,37 @@ bool IsTouchscreenInternal(const base::FilePath& path) {
// Device does not exist.
if (sysfs_path.empty())
return false;
return InputDeviceType::INPUT_DEVICE_UNKNOWN;
// Check all parent devices. If any of them is the "i2c" subsystem,
// consider the device internal. Otherwise consider it external.
const base::FilePath i2c_subsystem(FILE_PATH_LITERAL("/sys/bus/i2c"));
// Check ancestor devices for a known bus attachment.
for (base::FilePath path = sysfs_path; path != base::FilePath("/");
path = path.DirName()) {
if (base::MakeAbsoluteFilePath(
path.Append(FILE_PATH_LITERAL("subsystem"))) == i2c_subsystem)
return true;
std::string subsystem_path =
base::MakeAbsoluteFilePath(path.Append(FILE_PATH_LITERAL("subsystem")))
.value();
if (subsystem_path.empty())
continue;
// Internal bus attachments.
if (subsystem_path == "/sys/bus/pci")
return InputDeviceType::INPUT_DEVICE_INTERNAL;
if (subsystem_path == "/sys/bus/i2c")
return InputDeviceType::INPUT_DEVICE_INTERNAL;
if (subsystem_path == "/sys/bus/acpi")
return InputDeviceType::INPUT_DEVICE_INTERNAL;
if (subsystem_path == "/sys/bus/serio")
return InputDeviceType::INPUT_DEVICE_INTERNAL;
if (subsystem_path == "/sys/bus/platform")
return InputDeviceType::INPUT_DEVICE_INTERNAL;
// External bus attachments.
if (subsystem_path == "/sys/bus/usb")
return InputDeviceType::INPUT_DEVICE_EXTERNAL;
if (subsystem_path == "/sys/class/bluetooth")
return InputDeviceType::INPUT_DEVICE_EXTERNAL;
}
return false;
return InputDeviceType::INPUT_DEVICE_UNKNOWN;
}
} // namespace
......@@ -6,6 +6,7 @@
#define UI_EVENTS_DEVICES_DEVICE_UTIL_LINUX_H_
#include "ui/events/devices/events_devices_export.h"
#include "ui/events/devices/input_device.h"
namespace base {
class FilePath;
......@@ -13,8 +14,9 @@ class FilePath;
namespace ui {
// Returns true if the device described by |path| is an internal device.
EVENTS_DEVICES_EXPORT bool IsTouchscreenInternal(const base::FilePath& path);
// Finds device type (internal or external) based on device path.
EVENTS_DEVICES_EXPORT InputDeviceType
GetInputDeviceTypeFromPath(const base::FilePath& path);
} // namespace ui
......
......@@ -80,7 +80,7 @@ TouchEventConverterEvdev::TouchEventConverterEvdev(
syn_dropped_(false),
is_type_a_(false),
current_slot_(0),
is_internal_(IsTouchscreenInternal(path)) {
is_internal_(GetInputDeviceTypeFromPath(path) == INPUT_DEVICE_INTERNAL) {
}
TouchEventConverterEvdev::~TouchEventConverterEvdev() {
......
......@@ -299,9 +299,7 @@ void HandleTouchscreenDevicesInWorker(
// Touchscreens should have absolute X and Y axes, and be direct touch
// devices.
if (max_x > 0.0 && max_y > 0.0 && is_direct_touch) {
InputDeviceType type = IsTouchscreenInternal(device_info.path)
? InputDeviceType::INPUT_DEVICE_INTERNAL
: InputDeviceType::INPUT_DEVICE_EXTERNAL;
InputDeviceType type = GetInputDeviceTypeFromPath(device_info.path);
// |max_x| and |max_y| are inclusive values, so we need to add 1 to get
// the size.
devices.push_back(TouchscreenDevice(
......
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