chromium/services/device/hid/hid_service_linux.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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"

// TODO(huangs): Enable for IS_CHROMEOS_LACROS. This will simplify crosapi so
// that it won't need to pass HidManager around (crbug.com/1109621).
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "base/system/sys_info.h"
#include "chromeos/dbus/permission_broker/permission_broker_client.h"  // nogncheck
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

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[] =;

// Walks up the sysfs device tree starting at |device| and returns the first
// ancestor in the "hid" subsystem. Returns nullptr on failure.
udev_device* FindFirstHidAncestor(udev_device* device) {}

// Walks up the sysfs device tree starting at |device| and returns the first
// ancestor not in the "hid" or "hidraw" subsystems. Returns nullptr on failure.
udev_device* FindFirstNonHidAncestor(udev_device* device) {}

// Returns the sysfs path for a USB device |usb_device|, or nullptr if the sysfs
// path could not be retrieved. |usb_device| must be a device in the "usb"
// subsystem.
//
// Some USB devices expose multiple interfaces. If |usb_device| refers to a
// single USB interface, walk up the device tree to find the ancestor that
// represents the physical device.
const char* GetUsbDeviceSyspath(udev_device* usb_device) {}

// Returns the sysfs path for a Bluetooth Classic device |bt_device|, or nullptr
// if the sysfs path could not be retrieved. |bt_device| must be a device in the
// "bluetooth" subsystem.
const char* GetBluetoothDeviceSyspath(udev_device* bt_device) {}

// Returns the physical device ID for a device |hidraw_device|. On Linux, the
// physical device ID is the sysfs path to the device node that represents the
// physical device if it is available. When the physical device node is not
// available, the sysfs path of the HID interface is returned instead. Returns
// nullptr on failure.
const char* GetPhysicalDeviceId(udev_device* hidraw_device) {}

// Convert from a Linux |bus_id| (defined in linux/input.h) to a
// mojom::HidBusType.
mojom::HidBusType BusTypeFromLinuxBusId(uint16_t bus_id) {}

}  // namespace

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)

// static
void HidServiceLinux::OnPathOpenComplete(std::unique_ptr<ConnectParams> params,
                                         base::ScopedFD fd) {
  params->fd = std::move(fd);
  FinishOpen(std::move(params));
}

// static
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

// static
void HidServiceLinux::OpenOnBlockingThread(
    std::unique_ptr<ConnectParams> params) {}

#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

// static
void HidServiceLinux::FinishOpen(std::unique_ptr<ConnectParams> params) {}

}  // namespace device