blob: 5cf3ccfa38c33a27b11c76ae8cbcaa7a7aeb5008 [file] [log] [blame]
// Copyright 2018 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stdint.h>
#include <memory>
#include <vector>
#include <libusb-1.0/libusb.h>
#include <base/macros.h>
#include <base/time/time.h>
#include <brillo/dbus/dbus_object.h>
#include "permission_broker/libusb_wrapper.h"
namespace permission_broker {
// This class encapsulates the logic used to interact with the VBUS subsystem to
// control the power state of USB devices.
class UsbControl {
explicit UsbControl(std::unique_ptr<UsbDeviceManagerInterface> manager);
// Based on |vid| and |pid| of a USB device, this function determines if the
// device type can be controlled by the API. The UsbControl implements an
// allow/deny mechanism, meaning that if a device is *not* allowed, it
// cannot be controlled.
bool IsDeviceAllowed(uint16_t vid, uint16_t pid) const;
// When called, this function will find all the USB devices identified by
// |vid| and |pid| and will try to power-cycle them using the VBUS subsystem.
// The |delay| determines the delay between powering all the devices found on
// and powering them all off.
void PowerCycleUsbPorts(
base::Callback<void(bool)> callback,
uint16_t vid,
uint16_t pid,
base::TimeDelta delay);
std::unique_ptr<UsbDeviceManagerInterface> manager_ = nullptr;
} // namespace permission_broker