1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/events/devices/device_util_linux.h"
9 #include "base/files/file_enumerator.h"
10 #include "base/files/file_path.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/strings/string_util.h"
16 // We consider the touchscreen to be internal if it is an I2c device. We search
17 // all the dev input nodes registered by I2C devices to see if we can find
19 bool IsTouchscreenInternal(const base::FilePath
& path
) {
20 DCHECK(!base::MessageLoopForUI::IsCurrent());
21 std::string event_node
= path
.BaseName().value();
22 if (event_node
.empty() || !StartsWithASCII(event_node
, "event", false))
25 // Extract id "XXX" from "eventXXX"
26 std::string event_node_id
= event_node
.substr(5);
28 // I2C input device registers its dev input node at
29 // /sys/bus/i2c/devices/*/input/inputXXX/eventXXX
30 base::FileEnumerator
i2c_enum(
31 base::FilePath(FILE_PATH_LITERAL("/sys/bus/i2c/devices/")),
33 base::FileEnumerator::DIRECTORIES
);
34 for (base::FilePath i2c_name
= i2c_enum
.Next(); !i2c_name
.empty();
35 i2c_name
= i2c_enum
.Next()) {
36 base::FileEnumerator
input_enum(
37 i2c_name
.Append(FILE_PATH_LITERAL("input")),
39 base::FileEnumerator::DIRECTORIES
,
40 FILE_PATH_LITERAL("input*"));
41 for (base::FilePath input
= input_enum
.Next(); !input
.empty();
42 input
= input_enum
.Next()) {
43 if (input
.BaseName().value().substr(5) == event_node_id
)