diff options
author | Yufeng Shen <miletus@chromium.org> | 2014-12-22 15:35:04 -0500 |
---|---|---|
committer | Yufeng Shen <miletus@chromium.org> | 2014-12-22 20:36:03 +0000 |
commit | 67c8ce6d16f866ccfecde6f7b6e7ae92bf2bfe16 (patch) | |
tree | 2f087a0555a0e4ab36b2e325469bd6a46a04645e | |
parent | e7a04e9cbc3d8b58fbc02db90f52e876d1abeeb0 (diff) | |
download | chromium_src-67c8ce6d16f866ccfecde6f7b6e7ae92bf2bfe16.zip chromium_src-67c8ce6d16f866ccfecde6f7b6e7ae92bf2bfe16.tar.gz chromium_src-67c8ce6d16f866ccfecde6f7b6e7ae92bf2bfe16.tar.bz2 |
events: devices: Fix i2c device detection in IsTouchscreenInternal
The current logic is wrong, since it does not look deeply enough for child
input class devices. To fix the current approach, we'd need a recursive
search, but let's not do that.
Instead, find the device path and check the subsystem of each ancestor
device. If it's an i2c device, one of those will be the i2c subsytem.
BUG=chrome-os-partner:34013
TEST=Check calibration on link_freon & rush_ryu
TBR=sadrul@chromium.org
Review URL: https://codereview.chromium.org/750713002
Cr-Commit-Position: refs/heads/master@{#305504}
(cherry picked from commit 0035518ae14df18d28d86a3dffe07d33b23394fa)
Review URL: https://codereview.chromium.org/819933002
Cr-Commit-Position: refs/branch-heads/2214@{#351}
Cr-Branched-From: 03655fd3f6d72165dc3c9bd2c89807305316fe6c-refs/heads/master@{#303346}
-rw-r--r-- | ui/events/devices/device_util_linux.cc | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/ui/events/devices/device_util_linux.cc b/ui/events/devices/device_util_linux.cc index 89247f1..76d31db 100644 --- a/ui/events/devices/device_util_linux.cc +++ b/ui/events/devices/device_util_linux.cc @@ -8,36 +8,35 @@ #include "base/files/file_enumerator.h" #include "base/files/file_path.h" +#include "base/files/file_util.h" #include "base/strings/string_util.h" namespace ui { +// We consider the touchscreen to be internal if it is an I2c device. bool IsTouchscreenInternal(const base::FilePath& path) { std::string event_node = path.BaseName().value(); if (event_node.empty() || !StartsWithASCII(event_node, "event", false)) return false; - // Extract id "XXX" from "eventXXX" - std::string event_node_id = event_node.substr(5); - - // I2C input device registers its dev input node at - // /sys/bus/i2c/devices/*/input/inputXXX/eventXXX - base::FileEnumerator i2c_enum( - base::FilePath(FILE_PATH_LITERAL("/sys/bus/i2c/devices/")), - false, - base::FileEnumerator::DIRECTORIES); - for (base::FilePath i2c_name = i2c_enum.Next(); !i2c_name.empty(); - i2c_name = i2c_enum.Next()) { - base::FileEnumerator input_enum( - i2c_name.Append(FILE_PATH_LITERAL("input")), - false, - base::FileEnumerator::DIRECTORIES, - FILE_PATH_LITERAL("input*")); - for (base::FilePath input = input_enum.Next(); !input.empty(); - input = input_enum.Next()) { - if (input.BaseName().value().substr(5) == event_node_id) - return true; - } + // Find sysfs device path for this device. + base::FilePath sysfs_path = + base::FilePath(FILE_PATH_LITERAL("/sys/class/input")); + sysfs_path = sysfs_path.Append(path.BaseName()); + sysfs_path = base::MakeAbsoluteFilePath(sysfs_path); + + // Device does not exist. + if (sysfs_path.empty()) + return false; + + // 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")); + 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; } return false; |