#include "services/device/hid/hid_service_linux.h"
#include <fcntl.h>
#include <linux/input.h>
#include <stdint.h>
#include <limits>
#include <memory>
#include <string>
#include <utility>
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_file.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/sequence_checker.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/threading/scoped_blocking_call.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/device_event_log/device_event_log.h"
#include "device/udev_linux/scoped_udev.h"
#include "device/udev_linux/udev_watcher.h"
#include "services/device/hid/hid_connection_linux.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "base/system/sys_info.h"
#include "chromeos/dbus/permission_broker/permission_broker_client.h"
#endif
namespace device {
namespace {
const char kDevtypeUsbDevice[] = …;
const char kSubsystemBluetooth[] = …;
const char kSubsystemHid[] = …;
const char kSubsystemHidraw[] = …;
const char kSubsystemUsb[] = …;
const char kHIDID[] = …;
const char kHIDName[] = …;
const char kHIDUnique[] = …;
const char kSysfsReportDescriptorKey[] = …;
const char kKernelHciPrefix[] = …;
udev_device* FindFirstHidAncestor(udev_device* device) { … }
udev_device* FindFirstNonHidAncestor(udev_device* device) { … }
const char* GetUsbDeviceSyspath(udev_device* usb_device) { … }
const char* GetBluetoothDeviceSyspath(udev_device* bt_device) { … }
const char* GetPhysicalDeviceId(udev_device* hidraw_device) { … }
mojom::HidBusType BusTypeFromLinuxBusId(uint16_t bus_id) { … }
}
struct HidServiceLinux::ConnectParams { … };
class HidServiceLinux::BlockingTaskRunnerHelper : public UdevWatcher::Observer { … };
HidServiceLinux::HidServiceLinux() { … }
HidServiceLinux::~HidServiceLinux() = default;
base::WeakPtr<HidService> HidServiceLinux::GetWeakPtr() { … }
void HidServiceLinux::Connect(const std::string& device_guid,
bool allow_protected_reports,
bool allow_fido_reports,
ConnectCallback callback) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
void HidServiceLinux::OnPathOpenComplete(std::unique_ptr<ConnectParams> params,
base::ScopedFD fd) {
params->fd = std::move(fd);
FinishOpen(std::move(params));
}
void HidServiceLinux::OnPathOpenError(const std::string& device_path,
ConnectCallback callback,
const std::string& error_name,
const std::string& error_message) {
HID_LOG(EVENT) << "Permission broker failed to open '" << device_path
<< "': " << error_name << ": " << error_message;
std::move(callback).Run(nullptr);
}
#else
void HidServiceLinux::OpenOnBlockingThread(
std::unique_ptr<ConnectParams> params) { … }
#endif
void HidServiceLinux::FinishOpen(std::unique_ptr<ConnectParams> params) { … }
}