Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/arc/bluetooth/arc_bluetooth_bridge.h" | 5 #include "components/arc/bluetooth/arc_bluetooth_bridge.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <iomanip> | 10 #include <iomanip> |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 VLOG(1) << "registering bluetooth adapter"; | 65 VLOG(1) << "registering bluetooth adapter"; |
| 66 BluetoothAdapterFactory::GetAdapter(base::Bind( | 66 BluetoothAdapterFactory::GetAdapter(base::Bind( |
| 67 &ArcBluetoothBridge::OnAdapterInitialized, weak_factory_.GetWeakPtr())); | 67 &ArcBluetoothBridge::OnAdapterInitialized, weak_factory_.GetWeakPtr())); |
| 68 } else { | 68 } else { |
| 69 VLOG(1) << "no bluetooth adapter available"; | 69 VLOG(1) << "no bluetooth adapter available"; |
| 70 } | 70 } |
| 71 | 71 |
| 72 arc_bridge_service()->AddObserver(this); | 72 arc_bridge_service()->AddObserver(this); |
| 73 } | 73 } |
| 74 | 74 |
| 75 ArcBluetoothBridge::ArcBluetoothBridge(ArcBridgeService* bridge_service, | |
|
rkc
2016/06/19 18:45:43
We don't need this constructor. We never use the t
| |
| 76 bool test_flag) | |
| 77 : ArcService(bridge_service), binding_(this), weak_factory_(this) { | |
| 78 if (!test_flag) { | |
| 79 LOG(ERROR) << "Test Constructor got called with test = false"; | |
| 80 } | |
| 81 arc_bridge_service()->AddObserver(this); | |
| 82 } | |
| 83 | |
| 75 ArcBluetoothBridge::~ArcBluetoothBridge() { | 84 ArcBluetoothBridge::~ArcBluetoothBridge() { |
| 76 arc_bridge_service()->RemoveObserver(this); | 85 arc_bridge_service()->RemoveObserver(this); |
| 77 | 86 |
| 78 if (bluetooth_adapter_) | 87 if (bluetooth_adapter_) |
| 79 bluetooth_adapter_->RemoveObserver(this); | 88 bluetooth_adapter_->RemoveObserver(this); |
| 80 } | 89 } |
| 81 | 90 |
| 82 void ArcBluetoothBridge::OnAdapterInitialized( | 91 void ArcBluetoothBridge::OnAdapterInitialized( |
| 83 scoped_refptr<BluetoothAdapter> adapter) { | 92 scoped_refptr<BluetoothAdapter> adapter) { |
| 84 bluetooth_adapter_ = adapter; | 93 bluetooth_adapter_ = adapter; |
| 85 bluetooth_adapter_->AddObserver(this); | 94 bluetooth_adapter_->AddObserver(this); |
| 86 } | 95 } |
| 87 | 96 |
| 88 void ArcBluetoothBridge::OnBluetoothInstanceReady() { | 97 void ArcBluetoothBridge::OnBluetoothInstanceReady() { |
| 89 mojom::BluetoothInstance* bluetooth_instance = | 98 mojom::BluetoothInstance* bluetooth_instance = |
| 90 arc_bridge_service()->bluetooth_instance(); | 99 arc_bridge_service()->bluetooth_instance(); |
| 91 if (!bluetooth_instance) { | 100 if (!bluetooth_instance) { |
| 92 LOG(ERROR) << "OnBluetoothInstanceReady called, " | 101 LOG(ERROR) << "OnBluetoothInstanceReady called, " |
| 93 << "but no bluetooth instance found"; | 102 << "but no bluetooth instance found"; |
| 94 return; | 103 return; |
| 95 } | 104 } |
| 96 | 105 |
| 97 arc_bridge_service()->bluetooth_instance()->Init( | 106 bluetooth_instance_ = base::WrapUnique(bluetooth_instance); |
|
rkc
2016/06/19 18:45:43
None of these changes are needed. This file, in fa
| |
| 98 binding_.CreateInterfacePtrAndBind()); | 107 bluetooth_version_ = arc_bridge_service()->bluetooth_version(); |
| 108 bluetooth_instance_->Init(binding_.CreateInterfacePtrAndBind()); | |
| 99 } | 109 } |
| 100 | 110 |
| 101 void ArcBluetoothBridge::AdapterPresentChanged(BluetoothAdapter* adapter, | 111 void ArcBluetoothBridge::AdapterPresentChanged(BluetoothAdapter* adapter, |
| 102 bool present) { | 112 bool present) { |
| 103 // If the adapter goes away, remove ourselves as an observer. | 113 // If the adapter goes away, remove ourselves as an observer. |
| 104 if (!present && adapter == bluetooth_adapter_) { | 114 if (!present && adapter == bluetooth_adapter_) { |
| 105 adapter->RemoveObserver(this); | 115 adapter->RemoveObserver(this); |
| 106 bluetooth_adapter_ = nullptr; | 116 bluetooth_adapter_ = nullptr; |
| 107 } | 117 } |
| 108 } | 118 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 120 BluetoothDevice* device) { | 130 BluetoothDevice* device) { |
| 121 if (!HasBluetoothInstance()) | 131 if (!HasBluetoothInstance()) |
| 122 return; | 132 return; |
| 123 | 133 |
| 124 if (device->IsConnected()) | 134 if (device->IsConnected()) |
| 125 return; | 135 return; |
| 126 | 136 |
| 127 mojo::Array<mojom::BluetoothPropertyPtr> properties = | 137 mojo::Array<mojom::BluetoothPropertyPtr> properties = |
| 128 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); | 138 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); |
| 129 | 139 |
| 130 arc_bridge_service()->bluetooth_instance()->OnDeviceFound( | 140 bluetooth_instance_->OnDeviceFound(std::move(properties)); |
| 131 std::move(properties)); | |
| 132 | 141 |
| 133 if (arc_bridge_service()->bluetooth_version() < kMinBtleVersion) { | 142 if (bluetooth_version_ < kMinBtleVersion) { |
| 134 LOG(WARNING) << "Bluetooth instance is too old and does not support BTLE"; | 143 LOG(WARNING) << "Bluetooth instance is too old and does not support BTLE"; |
| 135 return; | 144 return; |
| 136 } | 145 } |
| 137 | 146 |
| 138 mojom::BluetoothAddressPtr addr = | 147 mojom::BluetoothAddressPtr addr = |
| 139 mojom::BluetoothAddress::From(device->GetAddress()); | 148 mojom::BluetoothAddress::From(device->GetAddress()); |
| 140 int rssi = device->GetInquiryRSSI(); | 149 int rssi = device->GetInquiryRSSI(); |
| 141 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = | 150 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = |
| 142 GetAdvertisingData(device); | 151 GetAdvertisingData(device); |
| 143 arc_bridge_service()->bluetooth_instance()->OnLEDeviceFound( | 152 bluetooth_instance_->OnLEDeviceFound(std::move(addr), rssi, |
| 144 std::move(addr), rssi, std::move(adv_data)); | 153 std::move(adv_data)); |
| 145 } | 154 } |
| 146 | 155 |
| 147 void ArcBluetoothBridge::DeviceChanged(BluetoothAdapter* adapter, | 156 void ArcBluetoothBridge::DeviceChanged(BluetoothAdapter* adapter, |
| 148 BluetoothDevice* device) { | 157 BluetoothDevice* device) { |
| 149 // TODO(smbarber): device properties changed; inform the container. | 158 // TODO(smbarber): device properties changed; inform the container. |
| 150 } | 159 } |
| 151 | 160 |
| 152 void ArcBluetoothBridge::DeviceAddressChanged(BluetoothAdapter* adapter, | 161 void ArcBluetoothBridge::DeviceAddressChanged(BluetoothAdapter* adapter, |
| 153 BluetoothDevice* device, | 162 BluetoothDevice* device, |
| 154 const std::string& old_address) { | 163 const std::string& old_address) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 BluetoothDevice* device, | 206 BluetoothDevice* device, |
| 198 BluetoothRemoteGattService* service) { | 207 BluetoothRemoteGattService* service) { |
| 199 // Placeholder for GATT client functionality | 208 // Placeholder for GATT client functionality |
| 200 } | 209 } |
| 201 | 210 |
| 202 void ArcBluetoothBridge::GattServicesDiscovered(BluetoothAdapter* adapter, | 211 void ArcBluetoothBridge::GattServicesDiscovered(BluetoothAdapter* adapter, |
| 203 BluetoothDevice* device) { | 212 BluetoothDevice* device) { |
| 204 if (!HasBluetoothInstance()) | 213 if (!HasBluetoothInstance()) |
| 205 return; | 214 return; |
| 206 | 215 |
| 207 if (arc_bridge_service()->bluetooth_version() < kMinBtleVersion) { | 216 if (bluetooth_version_ < kMinBtleVersion) { |
| 208 LOG(WARNING) << "Bluetooth instance is too old and does not support BTLE"; | 217 LOG(WARNING) << "Bluetooth instance is too old and does not support BTLE"; |
| 209 return; | 218 return; |
| 210 } | 219 } |
| 211 | 220 |
| 212 mojom::BluetoothAddressPtr addr = | 221 mojom::BluetoothAddressPtr addr = |
| 213 mojom::BluetoothAddress::From(device->GetAddress()); | 222 mojom::BluetoothAddress::From(device->GetAddress()); |
| 214 | 223 |
| 215 arc_bridge_service()->bluetooth_instance()->OnSearchComplete( | 224 bluetooth_instance_->OnSearchComplete( |
| 216 std::move(addr), mojom::BluetoothGattStatus::GATT_SUCCESS); | 225 std::move(addr), mojom::BluetoothGattStatus::GATT_SUCCESS); |
| 217 } | 226 } |
| 218 | 227 |
| 219 void ArcBluetoothBridge::GattDiscoveryCompleteForService( | 228 void ArcBluetoothBridge::GattDiscoveryCompleteForService( |
| 220 BluetoothAdapter* adapter, | 229 BluetoothAdapter* adapter, |
| 221 BluetoothRemoteGattService* service) { | 230 BluetoothRemoteGattService* service) { |
| 222 // Placeholder for GATT client functionality | 231 // Placeholder for GATT client functionality |
| 223 } | 232 } |
| 224 | 233 |
| 225 void ArcBluetoothBridge::GattServiceChanged( | 234 void ArcBluetoothBridge::GattServiceChanged( |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 } | 300 } |
| 292 | 301 |
| 293 void ArcBluetoothBridge::GetAdapterProperty(mojom::BluetoothPropertyType type) { | 302 void ArcBluetoothBridge::GetAdapterProperty(mojom::BluetoothPropertyType type) { |
| 294 DCHECK(bluetooth_adapter_); | 303 DCHECK(bluetooth_adapter_); |
| 295 if (!HasBluetoothInstance()) | 304 if (!HasBluetoothInstance()) |
| 296 return; | 305 return; |
| 297 | 306 |
| 298 mojo::Array<mojom::BluetoothPropertyPtr> properties = | 307 mojo::Array<mojom::BluetoothPropertyPtr> properties = |
| 299 GetAdapterProperties(type); | 308 GetAdapterProperties(type); |
| 300 | 309 |
| 301 arc_bridge_service()->bluetooth_instance()->OnAdapterProperties( | 310 bluetooth_instance_->OnAdapterProperties(mojom::BluetoothStatus::SUCCESS, |
| 302 mojom::BluetoothStatus::SUCCESS, std::move(properties)); | 311 std::move(properties)); |
| 303 } | 312 } |
| 304 | 313 |
| 305 void ArcBluetoothBridge::SetAdapterProperty( | 314 void ArcBluetoothBridge::SetAdapterProperty( |
| 306 mojom::BluetoothPropertyPtr property) { | 315 mojom::BluetoothPropertyPtr property) { |
| 307 DCHECK(bluetooth_adapter_); | 316 DCHECK(bluetooth_adapter_); |
| 308 if (!HasBluetoothInstance()) | 317 if (!HasBluetoothInstance()) |
| 309 return; | 318 return; |
| 310 | 319 |
| 311 // TODO(smbarber): Implement SetAdapterProperty | 320 // TODO(smbarber): Implement SetAdapterProperty |
| 312 arc_bridge_service()->bluetooth_instance()->OnAdapterProperties( | 321 bluetooth_instance_->OnAdapterProperties( |
| 313 mojom::BluetoothStatus::FAIL, | 322 mojom::BluetoothStatus::FAIL, |
| 314 mojo::Array<mojom::BluetoothPropertyPtr>::New(0)); | 323 mojo::Array<mojom::BluetoothPropertyPtr>::New(0)); |
| 315 } | 324 } |
| 316 | 325 |
| 317 void ArcBluetoothBridge::GetRemoteDeviceProperty( | 326 void ArcBluetoothBridge::GetRemoteDeviceProperty( |
| 318 mojom::BluetoothAddressPtr remote_addr, | 327 mojom::BluetoothAddressPtr remote_addr, |
| 319 mojom::BluetoothPropertyType type) { | 328 mojom::BluetoothPropertyType type) { |
| 320 DCHECK(bluetooth_adapter_); | 329 DCHECK(bluetooth_adapter_); |
| 321 if (!HasBluetoothInstance()) | 330 if (!HasBluetoothInstance()) |
| 322 return; | 331 return; |
| 323 | 332 |
| 324 std::string addr_str = remote_addr->To<std::string>(); | 333 std::string addr_str = remote_addr->To<std::string>(); |
| 325 BluetoothDevice* device = bluetooth_adapter_->GetDevice(addr_str); | 334 BluetoothDevice* device = bluetooth_adapter_->GetDevice(addr_str); |
| 326 | 335 |
| 327 mojo::Array<mojom::BluetoothPropertyPtr> properties = | 336 mojo::Array<mojom::BluetoothPropertyPtr> properties = |
| 328 GetDeviceProperties(type, device); | 337 GetDeviceProperties(type, device); |
| 329 mojom::BluetoothStatus status = mojom::BluetoothStatus::SUCCESS; | 338 mojom::BluetoothStatus status = mojom::BluetoothStatus::SUCCESS; |
| 330 | 339 |
| 331 if (!device) { | 340 if (!device) { |
| 332 VLOG(1) << __func__ << ": device " << addr_str << " not available"; | 341 VLOG(1) << __func__ << ": device " << addr_str << " not available"; |
| 333 status = mojom::BluetoothStatus::FAIL; | 342 status = mojom::BluetoothStatus::FAIL; |
| 334 } | 343 } |
| 335 | 344 |
| 336 arc_bridge_service()->bluetooth_instance()->OnRemoteDeviceProperties( | 345 bluetooth_instance_->OnRemoteDeviceProperties(status, std::move(remote_addr), |
| 337 status, std::move(remote_addr), std::move(properties)); | 346 std::move(properties)); |
| 338 } | 347 } |
| 339 | 348 |
| 340 void ArcBluetoothBridge::SetRemoteDeviceProperty( | 349 void ArcBluetoothBridge::SetRemoteDeviceProperty( |
| 341 mojom::BluetoothAddressPtr remote_addr, | 350 mojom::BluetoothAddressPtr remote_addr, |
| 342 mojom::BluetoothPropertyPtr property) { | 351 mojom::BluetoothPropertyPtr property) { |
| 343 DCHECK(bluetooth_adapter_); | 352 DCHECK(bluetooth_adapter_); |
| 344 if (!HasBluetoothInstance()) | 353 if (!HasBluetoothInstance()) |
| 345 return; | 354 return; |
| 346 | 355 |
| 347 // TODO(smbarber): Implement SetRemoteDeviceProperty | 356 // TODO(smbarber): Implement SetRemoteDeviceProperty |
| 348 arc_bridge_service()->bluetooth_instance()->OnRemoteDeviceProperties( | 357 bluetooth_instance_->OnRemoteDeviceProperties( |
| 349 mojom::BluetoothStatus::FAIL, std::move(remote_addr), | 358 mojom::BluetoothStatus::FAIL, std::move(remote_addr), |
| 350 mojo::Array<mojom::BluetoothPropertyPtr>::New(0)); | 359 mojo::Array<mojom::BluetoothPropertyPtr>::New(0)); |
| 351 } | 360 } |
| 352 | 361 |
| 353 void ArcBluetoothBridge::GetRemoteServiceRecord( | 362 void ArcBluetoothBridge::GetRemoteServiceRecord( |
| 354 mojom::BluetoothAddressPtr remote_addr, | 363 mojom::BluetoothAddressPtr remote_addr, |
| 355 mojom::BluetoothUUIDPtr uuid) { | 364 mojom::BluetoothUUIDPtr uuid) { |
| 356 // TODO(smbarber): Implement GetRemoteServiceRecord | 365 // TODO(smbarber): Implement GetRemoteServiceRecord |
| 357 } | 366 } |
| 358 | 367 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 408 : mojom::BluetoothAdapterState::OFF); | 417 : mojom::BluetoothAdapterState::OFF); |
| 409 } | 418 } |
| 410 | 419 |
| 411 void ArcBluetoothBridge::OnDiscoveryStarted( | 420 void ArcBluetoothBridge::OnDiscoveryStarted( |
| 412 std::unique_ptr<BluetoothDiscoverySession> session) { | 421 std::unique_ptr<BluetoothDiscoverySession> session) { |
| 413 if (!HasBluetoothInstance()) | 422 if (!HasBluetoothInstance()) |
| 414 return; | 423 return; |
| 415 | 424 |
| 416 discovery_session_ = std::move(session); | 425 discovery_session_ = std::move(session); |
| 417 | 426 |
| 418 arc_bridge_service()->bluetooth_instance()->OnDiscoveryStateChanged( | 427 bluetooth_instance_->OnDiscoveryStateChanged( |
| 419 mojom::BluetoothDiscoveryState::STARTED); | 428 mojom::BluetoothDiscoveryState::STARTED); |
| 420 | 429 |
| 421 SendCachedDevicesFound(); | 430 SendCachedDevicesFound(); |
| 422 } | 431 } |
| 423 | 432 |
| 424 void ArcBluetoothBridge::OnDiscoveryStopped() { | 433 void ArcBluetoothBridge::OnDiscoveryStopped() { |
| 425 if (!HasBluetoothInstance()) | 434 if (!HasBluetoothInstance()) |
| 426 return; | 435 return; |
| 427 | 436 |
| 428 discovery_session_.reset(); | 437 discovery_session_.reset(); |
| 429 | 438 |
| 430 arc_bridge_service()->bluetooth_instance()->OnDiscoveryStateChanged( | 439 bluetooth_instance_->OnDiscoveryStateChanged( |
| 431 mojom::BluetoothDiscoveryState::STOPPED); | 440 mojom::BluetoothDiscoveryState::STOPPED); |
| 432 } | 441 } |
| 433 | 442 |
| 434 void ArcBluetoothBridge::CreateBond(mojom::BluetoothAddressPtr addr, | 443 void ArcBluetoothBridge::CreateBond(mojom::BluetoothAddressPtr addr, |
| 435 int32_t transport) { | 444 int32_t transport) { |
| 436 std::string addr_str = addr->To<std::string>(); | 445 std::string addr_str = addr->To<std::string>(); |
| 437 BluetoothDevice* device = bluetooth_adapter_->GetDevice(addr_str); | 446 BluetoothDevice* device = bluetooth_adapter_->GetDevice(addr_str); |
| 438 if (!device || !device->IsPairable()) { | 447 if (!device || !device->IsPairable()) { |
| 439 VLOG(1) << __func__ << ": device " << addr_str | 448 VLOG(1) << __func__ << ": device " << addr_str |
| 440 << " is no longer valid or pairable"; | 449 << " is no longer valid or pairable"; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 529 void ArcBluetoothBridge::StopLEScan() { | 538 void ArcBluetoothBridge::StopLEScan() { |
| 530 CancelDiscovery(); | 539 CancelDiscovery(); |
| 531 } | 540 } |
| 532 | 541 |
| 533 void ArcBluetoothBridge::OnGattConnectStateChanged( | 542 void ArcBluetoothBridge::OnGattConnectStateChanged( |
| 534 mojom::BluetoothAddressPtr addr, | 543 mojom::BluetoothAddressPtr addr, |
| 535 bool connected) const { | 544 bool connected) const { |
| 536 if (!HasBluetoothInstance()) | 545 if (!HasBluetoothInstance()) |
| 537 return; | 546 return; |
| 538 | 547 |
| 539 if (arc_bridge_service()->bluetooth_version() < kMinBtleVersion) { | 548 if (bluetooth_version_ < kMinBtleVersion) { |
| 540 LOG(WARNING) << "Bluetooth instance is too old and does not support BTLE"; | 549 LOG(WARNING) << "Bluetooth instance is too old and does not support BTLE"; |
| 541 return; | 550 return; |
| 542 } | 551 } |
| 543 | 552 |
| 544 DCHECK(addr); | 553 DCHECK(addr); |
| 545 | 554 |
| 546 arc_bridge_service()->bluetooth_instance()->OnLEConnectionStateChange( | 555 bluetooth_instance_->OnLEConnectionStateChange( |
| 547 std::move(addr), connected); | 556 std::move(addr), connected); |
| 548 } | 557 } |
| 549 | 558 |
| 550 void ArcBluetoothBridge::OnGattConnected( | 559 void ArcBluetoothBridge::OnGattConnected( |
| 551 mojom::BluetoothAddressPtr addr, | 560 mojom::BluetoothAddressPtr addr, |
| 552 std::unique_ptr<BluetoothGattConnection> connection) const { | 561 std::unique_ptr<BluetoothGattConnection> connection) const { |
| 553 OnGattConnectStateChanged(std::move(addr), true); | 562 OnGattConnectStateChanged(std::move(addr), true); |
| 554 } | 563 } |
| 555 | 564 |
| 556 void ArcBluetoothBridge::OnGattConnectError( | 565 void ArcBluetoothBridge::OnGattConnectError( |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 567 void ArcBluetoothBridge::ConnectLEDevice( | 576 void ArcBluetoothBridge::ConnectLEDevice( |
| 568 mojom::BluetoothAddressPtr remote_addr) { | 577 mojom::BluetoothAddressPtr remote_addr) { |
| 569 if (!HasBluetoothInstance()) | 578 if (!HasBluetoothInstance()) |
| 570 return; | 579 return; |
| 571 | 580 |
| 572 BluetoothDevice* device = | 581 BluetoothDevice* device = |
| 573 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); | 582 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); |
| 574 DCHECK(device); | 583 DCHECK(device); |
| 575 | 584 |
| 576 if (device->IsConnected()) { | 585 if (device->IsConnected()) { |
| 577 arc_bridge_service()->bluetooth_instance()->OnLEConnectionStateChange( | 586 bluetooth_instance_->OnLEConnectionStateChange(std::move(remote_addr), |
| 578 std::move(remote_addr), true); | 587 true); |
| 579 return; | 588 return; |
| 580 } | 589 } |
| 581 | 590 |
| 582 // Also pass disconnect callback in error case | 591 // Also pass disconnect callback in error case |
| 583 // since it would be disconnected anyway. | 592 // since it would be disconnected anyway. |
| 584 mojom::BluetoothAddressPtr remote_addr_clone = remote_addr.Clone(); | 593 mojom::BluetoothAddressPtr remote_addr_clone = remote_addr.Clone(); |
| 585 device->CreateGattConnection( | 594 device->CreateGattConnection( |
| 586 base::Bind(&ArcBluetoothBridge::OnGattConnected, | 595 base::Bind(&ArcBluetoothBridge::OnGattConnected, |
| 587 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr)), | 596 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr)), |
| 588 base::Bind(&ArcBluetoothBridge::OnGattConnectError, | 597 base::Bind(&ArcBluetoothBridge::OnGattConnectError, |
| 589 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr_clone))); | 598 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr_clone))); |
| 590 } | 599 } |
| 591 | 600 |
| 592 void ArcBluetoothBridge::DisconnectLEDevice( | 601 void ArcBluetoothBridge::DisconnectLEDevice( |
| 593 mojom::BluetoothAddressPtr remote_addr) { | 602 mojom::BluetoothAddressPtr remote_addr) { |
| 594 if (!HasBluetoothInstance()) | 603 if (!HasBluetoothInstance()) |
| 595 return; | 604 return; |
| 596 | 605 |
| 597 BluetoothDevice* device = | 606 BluetoothDevice* device = |
| 598 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); | 607 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); |
| 599 DCHECK(device); | 608 DCHECK(device); |
| 600 | 609 |
| 601 if (!device->IsConnected()) { | 610 if (!device->IsConnected()) { |
| 602 arc_bridge_service()->bluetooth_instance()->OnLEConnectionStateChange( | 611 bluetooth_instance_->OnLEConnectionStateChange(std::move(remote_addr), |
| 603 std::move(remote_addr), false); | 612 false); |
| 604 return; | 613 return; |
| 605 } | 614 } |
| 606 | 615 |
| 607 mojom::BluetoothAddressPtr remote_addr_clone = remote_addr.Clone(); | 616 mojom::BluetoothAddressPtr remote_addr_clone = remote_addr.Clone(); |
| 608 device->Disconnect( | 617 device->Disconnect( |
| 609 base::Bind(&ArcBluetoothBridge::OnGattDisconnected, | 618 base::Bind(&ArcBluetoothBridge::OnGattDisconnected, |
| 610 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr)), | 619 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr)), |
| 611 base::Bind(&ArcBluetoothBridge::OnGattDisconnected, | 620 base::Bind(&ArcBluetoothBridge::OnGattDisconnected, |
| 612 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr_clone))); | 621 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr_clone))); |
| 613 } | 622 } |
| 614 | 623 |
| 615 void ArcBluetoothBridge::SearchService(mojom::BluetoothAddressPtr remote_addr) { | 624 void ArcBluetoothBridge::SearchService(mojom::BluetoothAddressPtr remote_addr) { |
| 616 if (!HasBluetoothInstance()) | 625 if (!HasBluetoothInstance()) |
| 617 return; | 626 return; |
| 618 | 627 |
| 619 BluetoothDevice* device = | 628 BluetoothDevice* device = |
| 620 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); | 629 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); |
| 621 DCHECK(device); | 630 DCHECK(device); |
| 622 | 631 |
| 623 // Call the callback if discovery is completed | 632 // Call the callback if discovery is completed |
| 624 if (device->IsGattServicesDiscoveryComplete()) { | 633 if (device->IsGattServicesDiscoveryComplete()) { |
| 625 arc_bridge_service()->bluetooth_instance()->OnSearchComplete( | 634 bluetooth_instance_->OnSearchComplete( |
| 626 std::move(remote_addr), mojom::BluetoothGattStatus::GATT_SUCCESS); | 635 std::move(remote_addr), mojom::BluetoothGattStatus::GATT_SUCCESS); |
| 627 return; | 636 return; |
| 628 } | 637 } |
| 629 | 638 |
| 630 // Discard result. Will call the callback when discovery is completed. | 639 // Discard result. Will call the callback when discovery is completed. |
| 631 device->GetGattServices(); | 640 device->GetGattServices(); |
| 632 } | 641 } |
| 633 | 642 |
| 634 void ArcBluetoothBridge::OnStartLEListenDone( | 643 void ArcBluetoothBridge::OnStartLEListenDone( |
| 635 const StartLEListenCallback& callback, | 644 const StartLEListenCallback& callback, |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 741 db.push_back(std::move(characteristic_element)); | 750 db.push_back(std::move(characteristic_element)); |
| 742 | 751 |
| 743 for (auto descriptor : characteristic->GetDescriptors()) { | 752 for (auto descriptor : characteristic->GetDescriptors()) { |
| 744 db.push_back(CreateGattDBElement<device::BluetoothRemoteGattDescriptor>( | 753 db.push_back(CreateGattDBElement<device::BluetoothRemoteGattDescriptor>( |
| 745 mojom::BluetoothGattDBAttributeType::BTGATT_DB_DESCRIPTOR, | 754 mojom::BluetoothGattDBAttributeType::BTGATT_DB_DESCRIPTOR, |
| 746 descriptor)); | 755 descriptor)); |
| 747 } | 756 } |
| 748 } | 757 } |
| 749 } | 758 } |
| 750 | 759 |
| 751 arc_bridge_service()->bluetooth_instance()->OnGetGattDB( | 760 bluetooth_instance_->OnGetGattDB(std::move(remote_addr), std::move(db)); |
| 752 std::move(remote_addr), std::move(db)); | |
| 753 } | 761 } |
| 754 | 762 |
| 755 // Find Gatt Service/Characteristic/Descriptor from std::vector from UUID. | 763 // Find Gatt Service/Characteristic/Descriptor from std::vector from UUID. |
| 756 template <class T> | 764 template <class T> |
| 757 T* ArcBluetoothBridge::FindGattObjectFromUuid( | 765 T* ArcBluetoothBridge::FindGattObjectFromUuid( |
| 758 const std::vector<T*> gatt_objs, | 766 const std::vector<T*> gatt_objs, |
| 759 const device::BluetoothUUID uuid) const { | 767 const device::BluetoothUUID uuid) const { |
| 760 auto it = std::find_if(gatt_objs.begin(), gatt_objs.end(), | 768 auto it = std::find_if(gatt_objs.begin(), gatt_objs.end(), |
| 761 [&](T* obj) { return obj->GetUUID() == uuid; }); | 769 [&](T* obj) { return obj->GetUUID() == uuid; }); |
| 762 if (it == gatt_objs.end()) | 770 if (it == gatt_objs.end()) |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 990 } | 998 } |
| 991 | 999 |
| 992 void ArcBluetoothBridge::OnDiscoveryError() { | 1000 void ArcBluetoothBridge::OnDiscoveryError() { |
| 993 LOG(WARNING) << "failed to change discovery state"; | 1001 LOG(WARNING) << "failed to change discovery state"; |
| 994 } | 1002 } |
| 995 | 1003 |
| 996 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const { | 1004 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const { |
| 997 if (!HasBluetoothInstance()) | 1005 if (!HasBluetoothInstance()) |
| 998 return; | 1006 return; |
| 999 | 1007 |
| 1000 arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( | 1008 bluetooth_instance_->OnBondStateChanged(mojom::BluetoothStatus::SUCCESS, |
| 1001 mojom::BluetoothStatus::SUCCESS, std::move(addr), | 1009 std::move(addr), |
| 1002 mojom::BluetoothBondState::BONDING); | 1010 mojom::BluetoothBondState::BONDING); |
| 1003 } | 1011 } |
| 1004 | 1012 |
| 1005 void ArcBluetoothBridge::OnPairedDone(mojom::BluetoothAddressPtr addr) const { | 1013 void ArcBluetoothBridge::OnPairedDone(mojom::BluetoothAddressPtr addr) const { |
| 1006 if (!HasBluetoothInstance()) | 1014 if (!HasBluetoothInstance()) |
| 1007 return; | 1015 return; |
| 1008 | 1016 |
| 1009 arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( | 1017 bluetooth_instance_->OnBondStateChanged(mojom::BluetoothStatus::SUCCESS, |
| 1010 mojom::BluetoothStatus::SUCCESS, std::move(addr), | 1018 std::move(addr), |
| 1011 mojom::BluetoothBondState::BONDED); | 1019 mojom::BluetoothBondState::BONDED); |
| 1012 } | 1020 } |
| 1013 | 1021 |
| 1014 void ArcBluetoothBridge::OnPairedError( | 1022 void ArcBluetoothBridge::OnPairedError( |
| 1015 mojom::BluetoothAddressPtr addr, | 1023 mojom::BluetoothAddressPtr addr, |
| 1016 BluetoothDevice::ConnectErrorCode error_code) const { | 1024 BluetoothDevice::ConnectErrorCode error_code) const { |
| 1017 if (!HasBluetoothInstance()) | 1025 if (!HasBluetoothInstance()) |
| 1018 return; | 1026 return; |
| 1019 | 1027 |
| 1020 arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( | 1028 bluetooth_instance_->OnBondStateChanged(mojom::BluetoothStatus::FAIL, |
| 1021 mojom::BluetoothStatus::FAIL, std::move(addr), | 1029 std::move(addr), |
| 1022 mojom::BluetoothBondState::NONE); | 1030 mojom::BluetoothBondState::NONE); |
| 1023 } | 1031 } |
| 1024 | 1032 |
| 1025 void ArcBluetoothBridge::OnForgetDone(mojom::BluetoothAddressPtr addr) const { | 1033 void ArcBluetoothBridge::OnForgetDone(mojom::BluetoothAddressPtr addr) const { |
| 1026 if (!HasBluetoothInstance()) | 1034 if (!HasBluetoothInstance()) |
| 1027 return; | 1035 return; |
| 1028 | 1036 |
| 1029 arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( | 1037 bluetooth_instance_->OnBondStateChanged(mojom::BluetoothStatus::SUCCESS, |
| 1030 mojom::BluetoothStatus::SUCCESS, std::move(addr), | 1038 std::move(addr), |
| 1031 mojom::BluetoothBondState::NONE); | 1039 mojom::BluetoothBondState::NONE); |
| 1032 } | 1040 } |
| 1033 | 1041 |
| 1034 void ArcBluetoothBridge::OnForgetError(mojom::BluetoothAddressPtr addr) const { | 1042 void ArcBluetoothBridge::OnForgetError(mojom::BluetoothAddressPtr addr) const { |
| 1035 if (!HasBluetoothInstance()) | 1043 if (!HasBluetoothInstance()) |
| 1036 return; | 1044 return; |
| 1037 | 1045 |
| 1038 BluetoothDevice* device = | 1046 BluetoothDevice* device = |
| 1039 bluetooth_adapter_->GetDevice(addr->To<std::string>()); | 1047 bluetooth_adapter_->GetDevice(addr->To<std::string>()); |
| 1040 mojom::BluetoothBondState bond_state = mojom::BluetoothBondState::NONE; | 1048 mojom::BluetoothBondState bond_state = mojom::BluetoothBondState::NONE; |
| 1041 if (device && device->IsPaired()) { | 1049 if (device && device->IsPaired()) { |
| 1042 bond_state = mojom::BluetoothBondState::BONDED; | 1050 bond_state = mojom::BluetoothBondState::BONDED; |
| 1043 } | 1051 } |
| 1044 arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( | 1052 bluetooth_instance_->OnBondStateChanged(mojom::BluetoothStatus::FAIL, |
| 1045 mojom::BluetoothStatus::FAIL, std::move(addr), bond_state); | 1053 std::move(addr), bond_state); |
| 1046 } | 1054 } |
| 1047 | 1055 |
| 1048 mojo::Array<mojom::BluetoothPropertyPtr> | 1056 mojo::Array<mojom::BluetoothPropertyPtr> |
| 1049 ArcBluetoothBridge::GetDeviceProperties(mojom::BluetoothPropertyType type, | 1057 ArcBluetoothBridge::GetDeviceProperties(mojom::BluetoothPropertyType type, |
| 1050 BluetoothDevice* device) const { | 1058 BluetoothDevice* device) const { |
| 1051 mojo::Array<mojom::BluetoothPropertyPtr> properties; | 1059 mojo::Array<mojom::BluetoothPropertyPtr> properties; |
| 1052 | 1060 |
| 1053 if (!device) { | 1061 if (!device) { |
| 1054 return properties; | 1062 return properties; |
| 1055 } | 1063 } |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1249 return; | 1257 return; |
| 1250 | 1258 |
| 1251 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); | 1259 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); |
| 1252 for (auto device : devices) { | 1260 for (auto device : devices) { |
| 1253 if (device->IsPaired()) | 1261 if (device->IsPaired()) |
| 1254 continue; | 1262 continue; |
| 1255 | 1263 |
| 1256 mojo::Array<mojom::BluetoothPropertyPtr> properties = | 1264 mojo::Array<mojom::BluetoothPropertyPtr> properties = |
| 1257 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); | 1265 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); |
| 1258 | 1266 |
| 1259 arc_bridge_service()->bluetooth_instance()->OnDeviceFound( | 1267 bluetooth_instance_->OnDeviceFound(std::move(properties)); |
| 1260 std::move(properties)); | |
| 1261 | 1268 |
| 1262 if (arc_bridge_service()->bluetooth_version() >= kMinBtleVersion) { | 1269 if (bluetooth_version_ >= kMinBtleVersion) { |
| 1263 mojom::BluetoothAddressPtr addr = | 1270 mojom::BluetoothAddressPtr addr = |
| 1264 mojom::BluetoothAddress::From(device->GetAddress()); | 1271 mojom::BluetoothAddress::From(device->GetAddress()); |
| 1265 int rssi = device->GetInquiryRSSI(); | 1272 int rssi = device->GetInquiryRSSI(); |
| 1266 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = | 1273 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = |
| 1267 GetAdvertisingData(device); | 1274 GetAdvertisingData(device); |
| 1268 arc_bridge_service()->bluetooth_instance()->OnLEDeviceFound( | 1275 bluetooth_instance_->OnLEDeviceFound(std::move(addr), rssi, |
| 1269 std::move(addr), rssi, std::move(adv_data)); | 1276 std::move(adv_data)); |
| 1270 } | 1277 } |
| 1271 } | 1278 } |
| 1272 } | 1279 } |
| 1273 | 1280 |
| 1274 bool ArcBluetoothBridge::HasBluetoothInstance() const { | 1281 bool ArcBluetoothBridge::HasBluetoothInstance() const { |
| 1275 if (!arc_bridge_service()->bluetooth_instance()) { | 1282 if (!bluetooth_instance_) { |
| 1276 LOG(WARNING) << "no Bluetooth instance available"; | 1283 LOG(WARNING) << "no Bluetooth instance available"; |
| 1277 return false; | 1284 return false; |
| 1278 } | 1285 } |
| 1279 | 1286 |
| 1280 return true; | 1287 return true; |
| 1281 } | 1288 } |
| 1282 | 1289 |
| 1283 void ArcBluetoothBridge::SendCachedPairedDevices() const { | 1290 void ArcBluetoothBridge::SendCachedPairedDevices() const { |
| 1284 DCHECK(bluetooth_adapter_); | 1291 DCHECK(bluetooth_adapter_); |
| 1285 if (!HasBluetoothInstance()) | 1292 if (!HasBluetoothInstance()) |
| 1286 return; | 1293 return; |
| 1287 | 1294 |
| 1288 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); | 1295 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); |
| 1289 for (auto device : devices) { | 1296 for (auto device : devices) { |
| 1290 if (!device->IsPaired()) | 1297 if (!device->IsPaired()) |
| 1291 continue; | 1298 continue; |
| 1292 | 1299 |
| 1293 mojo::Array<mojom::BluetoothPropertyPtr> properties = | 1300 mojo::Array<mojom::BluetoothPropertyPtr> properties = |
| 1294 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); | 1301 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); |
| 1295 | 1302 |
| 1296 arc_bridge_service()->bluetooth_instance()->OnDeviceFound( | 1303 bluetooth_instance_->OnDeviceFound(std::move(properties)); |
| 1297 std::move(properties)); | |
| 1298 | 1304 |
| 1299 mojom::BluetoothAddressPtr addr = | 1305 mojom::BluetoothAddressPtr addr = |
| 1300 mojom::BluetoothAddress::From(device->GetAddress()); | 1306 mojom::BluetoothAddress::From(device->GetAddress()); |
| 1301 | 1307 |
| 1302 if (arc_bridge_service()->bluetooth_version() >= kMinBtleVersion) { | 1308 if (bluetooth_version_ >= kMinBtleVersion) { |
| 1303 int rssi = device->GetInquiryRSSI(); | 1309 int rssi = device->GetInquiryRSSI(); |
| 1304 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = | 1310 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = |
| 1305 GetAdvertisingData(device); | 1311 GetAdvertisingData(device); |
| 1306 arc_bridge_service()->bluetooth_instance()->OnLEDeviceFound( | 1312 bluetooth_instance_->OnLEDeviceFound(addr->Clone(), rssi, |
| 1307 addr->Clone(), rssi, std::move(adv_data)); | 1313 std::move(adv_data)); |
| 1308 } | 1314 } |
| 1309 | 1315 |
| 1310 // OnBondStateChanged must be called with mojom::BluetoothBondState::BONDING | 1316 // OnBondStateChanged must be called with mojom::BluetoothBondState::BONDING |
| 1311 // to | 1317 // to |
| 1312 // make sure the bond state machine on Android is ready to take the | 1318 // make sure the bond state machine on Android is ready to take the |
| 1313 // pair-done event. Otherwise the pair-done event will be dropped as an | 1319 // pair-done event. Otherwise the pair-done event will be dropped as an |
| 1314 // invalid change of paired status. | 1320 // invalid change of paired status. |
| 1315 OnPairing(addr->Clone()); | 1321 OnPairing(addr->Clone()); |
| 1316 OnPairedDone(std::move(addr)); | 1322 OnPairedDone(std::move(addr)); |
| 1317 } | 1323 } |
| 1318 } | 1324 } |
| 1319 | 1325 |
| 1320 } // namespace arc | 1326 } // namespace arc |
| OLD | NEW |