#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "device/fido/aoa/android_accessory_discovery.h"
#include <utility>
#include "base/containers/contains.h"
#include "base/containers/extend.h"
#include "base/containers/flat_set.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/metrics/histogram_functions.h"
#include "base/no_destructor.h"
#include "base/rand_util.h"
#include "base/time/time.h"
#include "components/device_event_log/device_event_log.h"
#include "device/fido/aoa/android_accessory_device.h"
#include "services/device/public/mojom/usb_manager.mojom.h"
#include "services/device/public/mojom/usb_manager_client.mojom.h"
namespace device {
namespace {
enum class AOADiscoveryEvent { … };
void RecordEvent(AOADiscoveryEvent event) { … }
base::flat_set<std::string>& KnownAccessories() { … }
}
AndroidAccessoryDiscovery::AndroidAccessoryDiscovery(
mojo::Remote<device::mojom::UsbDeviceManager> device_manager,
std::string request_description)
: … { … }
AndroidAccessoryDiscovery::~AndroidAccessoryDiscovery() = default;
void AndroidAccessoryDiscovery::StartInternal() { … }
void AndroidAccessoryDiscovery::OnDeviceAdded(
device::mojom::UsbDeviceInfoPtr device_info) { … }
static std::optional<AndroidAccessoryDiscovery::InterfaceInfo>
FindAccessoryInterface(const device::mojom::UsbDeviceInfoPtr& device_info) { … }
void AndroidAccessoryDiscovery::HandleAccessoryDevice(
mojo::Remote<device::mojom::UsbDevice> device,
device::mojom::UsbDeviceInfoPtr device_info) { … }
enum AccessoryControlRequest : uint8_t { … };
static mojom::UsbControlTransferParamsPtr ControlTransferParams(
AccessoryControlRequest request,
uint16_t index = 0) { … }
static constexpr unsigned kTimeoutMilliseconds = …;
static constexpr unsigned kLongTimeoutMilliseconds = …;
void AndroidAccessoryDiscovery::OnOpenAccessory(
mojo::Remote<device::mojom::UsbDevice> device,
device::mojom::UsbDeviceInfoPtr device_info,
InterfaceInfo interface_info,
device::mojom::UsbOpenDeviceResultPtr result) { … }
void AndroidAccessoryDiscovery::OnAccessoryConfigured(
mojo::Remote<device::mojom::UsbDevice> device,
InterfaceInfo interface_info,
bool success) { … }
void AndroidAccessoryDiscovery::OnAccessoryInterfaceClaimed(
mojo::Remote<device::mojom::UsbDevice> device,
InterfaceInfo interface_info,
mojom::UsbClaimInterfaceResult result) { … }
void AndroidAccessoryDiscovery::OnSyncWritten(
mojo::Remote<device::mojom::UsbDevice> device,
InterfaceInfo interface_info,
std::array<uint8_t, kSyncNonceLength> nonce,
mojom::UsbTransferStatus result) { … }
void AndroidAccessoryDiscovery::OnReadComplete(
mojo::Remote<device::mojom::UsbDevice> device,
InterfaceInfo interface_info,
std::array<uint8_t, kSyncNonceLength> nonce,
mojom::UsbTransferStatus result,
base::span<const uint8_t> payload) { … }
void AndroidAccessoryDiscovery::OnOpen(
mojo::Remote<device::mojom::UsbDevice> device,
device::mojom::UsbOpenDeviceResultPtr result) { … }
void AndroidAccessoryDiscovery::OnVersionReply(
mojo::Remote<device::mojom::UsbDevice> device,
device::mojom::UsbTransferStatus status,
base::span<const uint8_t> payload) { … }
static std::vector<uint8_t> VectorFromString(const char* str) { … }
void AndroidAccessoryDiscovery::OnConfigurationStepComplete(
mojo::Remote<device::mojom::UsbDevice> device,
unsigned step,
device::mojom::UsbTransferStatus status) { … }
void AndroidAccessoryDiscovery::OnDeviceRemoved(
device::mojom::UsbDeviceInfoPtr device_info) { … }
void AndroidAccessoryDiscovery::OnGetDevices(
std::vector<device::mojom::UsbDeviceInfoPtr> devices) { … }
}