1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
|
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ash/arc/bluetooth/arc_bluez_bridge.h"
#include <bluetooth/bluetooth.h>
#include <bluetooth/l2cap.h>
#include <bluetooth/rfcomm.h>
#include <fcntl.h>
#include <stdint.h>
#include <sys/socket.h>
#include "base/check.h"
#include "base/posix/eintr_wrapper.h"
#include "chromeos/ash/experiences/arc/bluetooth/bluetooth_type_converters.h"
#include "chromeos/ash/experiences/arc/session/arc_bridge_service.h"
#include "device/bluetooth/bluetooth_common.h"
#include "device/bluetooth/bluetooth_device.h"
#include "device/bluetooth/bluez/bluetooth_device_bluez.h"
using device::BluetoothAdapter;
using device::BluetoothAdapterFactory;
using device::BluetoothAdvertisement;
using device::BluetoothDevice;
using device::BluetoothDiscoveryFilter;
using device::BluetoothDiscoverySession;
using device::BluetoothGattCharacteristic;
using device::BluetoothGattConnection;
using device::BluetoothGattDescriptor;
using device::BluetoothGattNotifySession;
using device::BluetoothGattService;
using device::BluetoothLocalGattCharacteristic;
using device::BluetoothLocalGattDescriptor;
using device::BluetoothLocalGattService;
using device::BluetoothRemoteGattCharacteristic;
using device::BluetoothRemoteGattDescriptor;
using device::BluetoothRemoteGattService;
using device::BluetoothTransport;
using device::BluetoothUUID;
namespace {
// Bluetooth SDP Service Class ID List Attribute identifier
constexpr uint16_t kServiceClassIDListAttributeID = 0x0001;
void OnCreateServiceRecordDone(
arc::ArcBluetoothBridge::CreateSdpRecordCallback callback,
uint32_t service_handle) {
arc::mojom::BluetoothCreateSdpRecordResultPtr result =
arc::mojom::BluetoothCreateSdpRecordResult::New();
result->status = arc::mojom::BluetoothStatus::SUCCESS;
result->service_handle = service_handle;
std::move(callback).Run(std::move(result));
}
void OnCreateServiceRecordError(
arc::ArcBluetoothBridge::CreateSdpRecordCallback callback,
bluez::BluetoothServiceRecordBlueZ::ErrorCode error_code) {
arc::mojom::BluetoothCreateSdpRecordResultPtr result =
arc::mojom::BluetoothCreateSdpRecordResult::New();
if (error_code ==
bluez::BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY) {
result->status = arc::mojom::BluetoothStatus::NOT_READY;
} else {
result->status = arc::mojom::BluetoothStatus::FAIL;
}
std::move(callback).Run(std::move(result));
}
void OnRemoveServiceRecordDone(
arc::ArcBluetoothBridge::RemoveSdpRecordCallback callback) {
std::move(callback).Run(arc::mojom::BluetoothStatus::SUCCESS);
}
void OnRemoveServiceRecordError(
arc::ArcBluetoothBridge::RemoveSdpRecordCallback callback,
bluez::BluetoothServiceRecordBlueZ::ErrorCode error_code) {
arc::mojom::BluetoothStatus status;
if (error_code ==
bluez::BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY) {
status = arc::mojom::BluetoothStatus::NOT_READY;
} else {
status = arc::mojom::BluetoothStatus::FAIL;
}
std::move(callback).Run(status);
}
} // namespace
namespace arc {
ArcBluezBridge::ArcBluezBridge(content::BrowserContext* context,
ArcBridgeService* bridge_service)
: ArcBluetoothBridge(context, bridge_service) {}
ArcBluezBridge::~ArcBluezBridge() = default;
bluez::BluetoothAdapterBlueZ* ArcBluezBridge::GetAdapter() const {
return static_cast<bluez::BluetoothAdapterBlueZ*>(bluetooth_adapter_.get());
}
void ArcBluezBridge::HandlePoweredOn() {}
void ArcBluezBridge::GetSdpRecords(mojom::BluetoothAddressPtr remote_addr,
const BluetoothUUID& target_uuid) {
BluetoothDevice* device =
GetAdapter()->GetDevice(remote_addr->To<std::string>());
if (!device) {
OnGetServiceRecordsError(std::move(remote_addr), target_uuid,
bluez::BluetoothServiceRecordBlueZ::ErrorCode::
ERROR_DEVICE_DISCONNECTED);
return;
}
bluez::BluetoothDeviceBlueZ* device_bluez =
static_cast<bluez::BluetoothDeviceBlueZ*>(device);
mojom::BluetoothAddressPtr remote_addr_clone = remote_addr.Clone();
device_bluez->GetServiceRecords(
base::BindOnce(&ArcBluezBridge::OnGetServiceRecordsFinished,
weak_factory_.GetWeakPtr(), std::move(remote_addr),
target_uuid),
base::BindOnce(&ArcBluezBridge::OnGetServiceRecordsError,
weak_factory_.GetWeakPtr(), std::move(remote_addr_clone),
target_uuid));
}
void ArcBluezBridge::CreateSdpRecord(
mojom::BluetoothSdpRecordPtr record_mojo,
arc::ArcBluetoothBridge::CreateSdpRecordCallback callback) {
auto record = record_mojo.To<bluez::BluetoothServiceRecordBlueZ>();
// Check if ServiceClassIDList attribute (attribute ID 0x0001) is included
// after type conversion, since it is mandatory for creating a service record.
if (!record.IsAttributePresented(kServiceClassIDListAttributeID)) {
mojom::BluetoothCreateSdpRecordResultPtr result =
mojom::BluetoothCreateSdpRecordResult::New();
result->status = mojom::BluetoothStatus::FAIL;
std::move(callback).Run(std::move(result));
return;
}
auto split_callback = base::SplitOnceCallback(std::move(callback));
GetAdapter()->CreateServiceRecord(
record,
base::BindOnce(&OnCreateServiceRecordDone,
std::move(split_callback.first)),
base::BindOnce(&OnCreateServiceRecordError,
std::move(split_callback.second)));
}
void ArcBluezBridge::RemoveSdpRecord(uint32_t service_handle,
RemoveSdpRecordCallback callback) {
auto split_callback = base::SplitOnceCallback(std::move(callback));
GetAdapter()->RemoveServiceRecord(
service_handle,
base::BindOnce(&OnRemoveServiceRecordDone,
std::move(split_callback.first)),
base::BindOnce(&OnRemoveServiceRecordError,
std::move(split_callback.second)));
}
void ArcBluezBridge::CloseBluetoothListeningSocket(
BluetoothListeningSocket* ptr) {
auto itr = listening_sockets_.find(ptr);
CHECK(itr != listening_sockets_.end());
listening_sockets_.erase(itr);
}
void ArcBluezBridge::CloseBluetoothConnectingSocket(
BluetoothConnectingSocket* ptr) {
auto itr = connecting_sockets_.find(ptr);
CHECK(itr != connecting_sockets_.end());
connecting_sockets_.erase(itr);
}
void ArcBluezBridge::OnGetServiceRecordsDone(
mojom::BluetoothAddressPtr remote_addr,
const BluetoothUUID& target_uuid,
const std::vector<bluez::BluetoothServiceRecordBlueZ>& records_bluez) {
auto* sdp_bluetooth_instance = ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service_->bluetooth(), OnGetSdpRecords);
if (!sdp_bluetooth_instance) {
return;
}
std::vector<mojom::BluetoothSdpRecordPtr> records;
for (const auto& r : records_bluez) {
records.push_back(mojom::BluetoothSdpRecord::From(r));
}
sdp_bluetooth_instance->OnGetSdpRecords(mojom::BluetoothStatus::SUCCESS,
std::move(remote_addr), target_uuid,
std::move(records));
}
void ArcBluezBridge::OnGetServiceRecordsError(
mojom::BluetoothAddressPtr remote_addr,
const BluetoothUUID& target_uuid,
bluez::BluetoothServiceRecordBlueZ::ErrorCode error_code) {
auto* sdp_bluetooth_instance = ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service_->bluetooth(), OnGetSdpRecords);
if (!sdp_bluetooth_instance) {
return;
}
mojom::BluetoothStatus status;
switch (error_code) {
case bluez::BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY:
status = mojom::BluetoothStatus::NOT_READY;
break;
case bluez::BluetoothServiceRecordBlueZ::ErrorCode::
ERROR_DEVICE_DISCONNECTED:
status = mojom::BluetoothStatus::RMT_DEV_DOWN;
break;
default:
status = mojom::BluetoothStatus::FAIL;
break;
}
sdp_bluetooth_instance->OnGetSdpRecords(
status, std::move(remote_addr), target_uuid,
std::vector<mojom::BluetoothSdpRecordPtr>());
}
namespace {
union BluetoothSocketAddress {
sockaddr sock;
sockaddr_rc rfcomm;
sockaddr_l2 l2cap;
};
int32_t GetSockOptvalFromFlags(mojom::BluetoothSocketType sock_type,
mojom::BluetoothSocketFlagsPtr sock_flags) {
int optval = 0;
switch (sock_type) {
case mojom::BluetoothSocketType::TYPE_RFCOMM:
optval |= sock_flags->encrypt ? RFCOMM_LM_ENCRYPT : 0;
optval |= sock_flags->auth ? RFCOMM_LM_AUTH : 0;
optval |= sock_flags->auth_mitm ? RFCOMM_LM_SECURE : 0;
optval |= sock_flags->auth_16_digit ? RFCOMM_LM_SECURE : 0;
return optval;
case mojom::BluetoothSocketType::TYPE_L2CAP_LE:
optval |= sock_flags->encrypt ? L2CAP_LM_ENCRYPT : 0;
optval |= sock_flags->auth ? L2CAP_LM_AUTH : 0;
optval |= sock_flags->auth_mitm ? L2CAP_LM_SECURE : 0;
optval |= sock_flags->auth_16_digit ? L2CAP_LM_SECURE : 0;
return optval;
}
}
// Opens an AF_BLUETOOTH socket with |sock_type|, sets L2CAP_LM or RFCOMM_LM
// with |optval|, and binds the socket to address with |port|.
base::ScopedFD OpenBluetoothSocketImpl(mojom::BluetoothSocketType sock_type,
int32_t optval,
uint16_t port) {
int protocol;
int level;
int optname;
switch (sock_type) {
case mojom::BluetoothSocketType::TYPE_RFCOMM:
protocol = BTPROTO_RFCOMM;
level = SOL_RFCOMM;
optname = RFCOMM_LM;
break;
case mojom::BluetoothSocketType::TYPE_L2CAP_LE:
protocol = BTPROTO_L2CAP;
level = SOL_L2CAP;
optname = L2CAP_LM;
break;
default:
LOG(ERROR) << "Unknown socket type " << sock_type;
return {};
}
base::ScopedFD sock(socket(AF_BLUETOOTH, SOCK_STREAM, protocol));
if (!sock.is_valid()) {
PLOG(ERROR) << "Failed to open bluetooth socket.";
return {};
}
if (setsockopt(sock.get(), level, optname, &optval, sizeof(optval)) == -1) {
PLOG(ERROR) << "Failed to setopt() on socket.";
return {};
}
if (fcntl(sock.get(), F_SETFL, O_NONBLOCK | fcntl(sock.get(), F_GETFL)) ==
-1) {
PLOG(ERROR) << "Failed to fcntl() on socket.";
return {};
}
BluetoothSocketAddress sa = {};
switch (sock_type) {
case mojom::BluetoothSocketType::TYPE_RFCOMM:
sa.rfcomm.rc_family = AF_BLUETOOTH;
sa.rfcomm.rc_channel = port;
break;
case mojom::BluetoothSocketType::TYPE_L2CAP_LE:
sa.l2cap.l2_family = AF_BLUETOOTH;
sa.l2cap.l2_psm = htobs(port);
sa.l2cap.l2_bdaddr_type = BDADDR_LE_PUBLIC;
break;
default:
LOG(ERROR) << "Unknown socket type " << sock_type;
return {};
}
if (bind(sock.get(), &sa.sock, sizeof(sa)) == -1) {
PLOG(ERROR) << "Failed to bind()";
return {};
}
return sock;
}
} // namespace
void ArcBluezBridge::OnBluezListeningSocketReady(
ArcBluezBridge::BluetoothListeningSocket* sock_wrapper) {
BluetoothSocketAddress sa;
socklen_t addr_len = sizeof(sa);
base::ScopedFD accept_fd(
accept(sock_wrapper->file.get(), &sa.sock, &addr_len));
if (!accept_fd.is_valid()) {
PLOG(ERROR) << "Failed to accept()";
return;
}
if (fcntl(accept_fd.get(), F_SETFL,
O_NONBLOCK | fcntl(accept_fd.get(), F_GETFL)) == -1) {
PLOG(ERROR) << "Failed to fnctl()";
return;
}
mojo::ScopedHandle handle =
mojo::WrapPlatformHandle(mojo::PlatformHandle(std::move(accept_fd)));
// Tells Android we successfully accept() a new connection.
auto connection = mojom::BluetoothSocketConnection::New();
connection->sock = std::move(handle);
switch (sock_wrapper->sock_type) {
case mojom::BluetoothSocketType::TYPE_RFCOMM:
connection->addr =
mojom::BluetoothAddress::From<bdaddr_t>(sa.rfcomm.rc_bdaddr);
connection->port = sa.rfcomm.rc_channel;
break;
case mojom::BluetoothSocketType::TYPE_L2CAP_LE:
connection->addr =
mojom::BluetoothAddress::From<bdaddr_t>(sa.l2cap.l2_bdaddr);
connection->port = btohs(sa.l2cap.l2_psm);
break;
default:
LOG(ERROR) << "Unknown socket type " << sock_wrapper->sock_type;
return;
}
sock_wrapper->remote->OnAccepted(std::move(connection));
}
void ArcBluezBridge::OnBluezConnectingSocketReady(
ArcBluezBridge::BluetoothConnectingSocket* sock_wrapper) {
// When connect() is ready, we will transfer this fd to Android, and Android
// is responsible for closing it. The file watcher |controller| needs to be
// disabled first, and then the fd ownership is transferred.
sock_wrapper->controller.reset();
base::ScopedFD fd = std::move(sock_wrapper->file);
// Checks whether connect() succeeded.
int err = 0;
socklen_t len = sizeof(err);
int ret = getsockopt(fd.get(), SOL_SOCKET, SO_ERROR, &err, &len);
if (ret != 0 || err != 0) {
LOG(ERROR) << "Failed to connect. err=" << err;
sock_wrapper->remote->OnConnectFailed();
}
// Gets peer address.
BluetoothSocketAddress peer_sa;
socklen_t peer_sa_len = sizeof(peer_sa);
if (getpeername(fd.get(), &peer_sa.sock, &peer_sa_len) == -1) {
PLOG(ERROR) << "Failed to getpeername().";
sock_wrapper->remote->OnConnectFailed();
}
// Gets our port.
BluetoothSocketAddress local_sa;
socklen_t local_sa_len = sizeof(local_sa);
if (getsockname(fd.get(), &local_sa.sock, &local_sa_len) == -1) {
PLOG(ERROR) << "Failed to getsockname()";
sock_wrapper->remote->OnConnectFailed();
}
mojo::ScopedHandle handle =
mojo::WrapPlatformHandle(mojo::PlatformHandle(std::move(fd)));
// Notifies Android.
auto connection = mojom::BluetoothSocketConnection::New();
connection->sock = std::move(handle);
switch (sock_wrapper->sock_type) {
case mojom::BluetoothSocketType::TYPE_RFCOMM:
connection->addr =
mojom::BluetoothAddress::From<bdaddr_t>(peer_sa.rfcomm.rc_bdaddr);
connection->port = local_sa.rfcomm.rc_channel;
break;
case mojom::BluetoothSocketType::TYPE_L2CAP_LE:
connection->addr =
mojom::BluetoothAddress::From<bdaddr_t>(peer_sa.l2cap.l2_bdaddr);
connection->port = btohs(local_sa.l2cap.l2_psm);
break;
default:
LOG(ERROR) << "Unknown socket type " << sock_wrapper->sock_type;
return;
}
sock_wrapper->remote->OnConnected(std::move(connection));
}
void ArcBluezBridge::CreateBluetoothListenSocket(
mojom::BluetoothSocketType type,
mojom::BluetoothSocketFlagsPtr flags,
int port,
BluetoothSocketListenCallback callback) {
std::unique_ptr<ArcBluezBridge::BluetoothListeningSocket> sock_wrapper =
nullptr;
int32_t optval = GetSockOptvalFromFlags(type, std::move(flags));
uint16_t listen_port = static_cast<uint16_t>(port);
do {
base::ScopedFD sock = OpenBluetoothSocketImpl(type, optval, listen_port);
if (!sock.is_valid()) {
LOG(ERROR) << "Failed to open listen socket.";
break;
}
if (listen(sock.get(), /*backlog=*/1) == -1) {
PLOG(ERROR) << "Failed to listen()";
break;
}
BluetoothSocketAddress local_addr;
socklen_t addr_len = sizeof(local_addr);
if (getsockname(sock.get(), &local_addr.sock, &addr_len) == -1) {
PLOG(ERROR) << "Failed to getsockname()";
break;
}
sock_wrapper = std::make_unique<BluetoothListeningSocket>();
sock_wrapper->sock_type = type;
sock_wrapper->controller = base::FileDescriptorWatcher::WatchReadable(
sock.get(),
base::BindRepeating(&ArcBluezBridge::OnBluezListeningSocketReady,
weak_factory_.GetWeakPtr(), sock_wrapper.get()));
sock_wrapper->file = std::move(sock);
if (type == mojom::BluetoothSocketType::TYPE_RFCOMM) {
listen_port = local_addr.rfcomm.rc_channel;
} else if (type == mojom::BluetoothSocketType::TYPE_L2CAP_LE) {
listen_port = btohs(local_addr.l2cap.l2_psm);
} else {
LOG(ERROR) << "Unknown socket type " << type;
break;
}
} while (!sock_wrapper.get());
if (sock_wrapper) {
std::move(callback).Run(mojom::BluetoothStatus::SUCCESS, listen_port,
sock_wrapper->remote.BindNewPipeAndPassReceiver());
BluetoothListeningSocket* socket = sock_wrapper.get();
listening_sockets_.insert(std::move(sock_wrapper));
socket->remote.set_disconnect_handler(
base::BindOnce(&ArcBluezBridge::CloseBluetoothListeningSocket,
weak_factory_.GetWeakPtr(), socket));
} else {
std::move(callback).Run(
mojom::BluetoothStatus::FAIL, /*port=*/0,
mojo::PendingReceiver<mojom::BluetoothListenSocketClient>());
}
}
void ArcBluezBridge::CreateBluetoothConnectSocket(
mojom::BluetoothSocketType type,
mojom::BluetoothSocketFlagsPtr flags,
mojom::BluetoothAddressPtr addr,
int port,
BluetoothSocketConnectCallback callback) {
std::unique_ptr<ArcBluetoothBridge::BluetoothConnectingSocket> sock_wrapper =
nullptr;
int32_t optval = GetSockOptvalFromFlags(type, std::move(flags));
base::ScopedFD sock = OpenBluetoothSocketImpl(type, optval, kAutoSockPort);
int ret = 0;
do {
if (!sock.is_valid()) {
LOG(ERROR) << "Failed to open connect socket.";
break;
}
std::string addr_str = addr->To<std::string>();
BluetoothDevice* device = bluetooth_adapter_->GetDevice(addr_str);
if (!device) {
break;
}
const auto addr_type = device->GetAddressType();
if (addr_type == BluetoothDevice::ADDR_TYPE_UNKNOWN) {
LOG(ERROR) << "Unknown address type.";
break;
}
BluetoothSocketAddress sa = {};
if (type == mojom::BluetoothSocketType::TYPE_RFCOMM) {
sa.rfcomm.rc_family = AF_BLUETOOTH;
sa.rfcomm.rc_bdaddr = addr->To<bdaddr_t>();
sa.rfcomm.rc_channel = static_cast<uint8_t>(port);
} else if (type == mojom::BluetoothSocketType::TYPE_L2CAP_LE) {
sa.l2cap.l2_family = AF_BLUETOOTH;
sa.l2cap.l2_bdaddr = addr->To<bdaddr_t>();
sa.l2cap.l2_psm = htobs(port);
sa.l2cap.l2_bdaddr_type = addr_type == BluetoothDevice::ADDR_TYPE_PUBLIC
? BDADDR_LE_PUBLIC
: BDADDR_LE_RANDOM;
} else {
LOG(ERROR) << "Unknown socket type " << type;
}
ret = HANDLE_EINTR(connect(
sock.get(), reinterpret_cast<const struct sockaddr*>(&sa), sizeof(sa)));
sock_wrapper =
std::make_unique<ArcBluetoothBridge::BluetoothConnectingSocket>();
sock_wrapper->sock_type = type;
} while (sock_wrapper == nullptr);
if (sock_wrapper) {
if (ret == 0) {
// connect() returns success immediately.
sock_wrapper->file = std::move(sock);
// BluetoothSocketConnect() is a blocking mojo call on the ARC side, so
// the callback needs to be triggered asynchronously and thus we use a
// PostTask here.
base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE,
base::BindOnce(&ArcBluezBridge::OnBluezConnectingSocketReady,
weak_factory_.GetWeakPtr(), sock_wrapper.get()));
} else if (errno == EINPROGRESS) {
sock_wrapper->controller = base::FileDescriptorWatcher::WatchWritable(
sock.get(),
base::BindRepeating(&ArcBluezBridge::OnBluezConnectingSocketReady,
weak_factory_.GetWeakPtr(), sock_wrapper.get()));
sock_wrapper->file = std::move(sock);
} else {
PLOG(ERROR) << "Failed to connect.";
std::move(callback).Run(
mojom::BluetoothStatus::FAIL,
mojo::PendingReceiver<arc::mojom::BluetoothConnectSocketClient>());
return;
}
} else {
std::move(callback).Run(
mojom::BluetoothStatus::FAIL,
mojo::PendingReceiver<arc::mojom::BluetoothConnectSocketClient>());
return;
}
std::move(callback).Run(mojom::BluetoothStatus::SUCCESS,
sock_wrapper->remote.BindNewPipeAndPassReceiver());
BluetoothConnectingSocket* socket = sock_wrapper.get();
connecting_sockets_.insert(std::move(sock_wrapper));
socket->remote.set_disconnect_handler(
base::BindOnce(&ArcBluezBridge::CloseBluetoothConnectingSocket,
weak_factory_.GetWeakPtr(), socket));
}
} // namespace arc
|