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