| 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 <bluetooth/bluetooth.h> | 7 #include <bluetooth/bluetooth.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 using device::BluetoothLocalGattCharacteristic; | 47 using device::BluetoothLocalGattCharacteristic; |
| 48 using device::BluetoothLocalGattDescriptor; | 48 using device::BluetoothLocalGattDescriptor; |
| 49 using device::BluetoothLocalGattService; | 49 using device::BluetoothLocalGattService; |
| 50 using device::BluetoothRemoteGattCharacteristic; | 50 using device::BluetoothRemoteGattCharacteristic; |
| 51 using device::BluetoothRemoteGattDescriptor; | 51 using device::BluetoothRemoteGattDescriptor; |
| 52 using device::BluetoothRemoteGattService; | 52 using device::BluetoothRemoteGattService; |
| 53 using device::BluetoothTransport; | 53 using device::BluetoothTransport; |
| 54 using device::BluetoothUUID; | 54 using device::BluetoothUUID; |
| 55 | 55 |
| 56 namespace { | 56 namespace { |
| 57 constexpr uint32_t kMinBtleVersion = 1; | |
| 58 constexpr uint32_t kMinBtleNotifyVersion = 2; | |
| 59 constexpr uint32_t kMinGattServerVersion = 3; | |
| 60 constexpr uint32_t kMinAddrChangeVersion = 4; | |
| 61 constexpr uint32_t kMinSdpSupportVersion = 5; | |
| 62 constexpr uint32_t kGattReadPermission = | 57 constexpr uint32_t kGattReadPermission = |
| 63 BluetoothGattCharacteristic::Permission::PERMISSION_READ | | 58 BluetoothGattCharacteristic::Permission::PERMISSION_READ | |
| 64 BluetoothGattCharacteristic::Permission::PERMISSION_READ_ENCRYPTED | | 59 BluetoothGattCharacteristic::Permission::PERMISSION_READ_ENCRYPTED | |
| 65 BluetoothGattCharacteristic::Permission:: | 60 BluetoothGattCharacteristic::Permission:: |
| 66 PERMISSION_READ_ENCRYPTED_AUTHENTICATED; | 61 PERMISSION_READ_ENCRYPTED_AUTHENTICATED; |
| 67 constexpr uint32_t kGattWritePermission = | 62 constexpr uint32_t kGattWritePermission = |
| 68 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE | | 63 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE | |
| 69 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE_ENCRYPTED | | 64 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE_ENCRYPTED | |
| 70 BluetoothGattCharacteristic::Permission:: | 65 BluetoothGattCharacteristic::Permission:: |
| 71 PERMISSION_WRITE_ENCRYPTED_AUTHENTICATED; | 66 PERMISSION_WRITE_ENCRYPTED_AUTHENTICATED; |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 // register ourselves as an observer with it then. Since our adapter is | 283 // register ourselves as an observer with it then. Since our adapter is |
| 289 // ready, we should register it now. | 284 // ready, we should register it now. |
| 290 if (!bluetooth_adapter_->HasObserver(this) && | 285 if (!bluetooth_adapter_->HasObserver(this) && |
| 291 arc_bridge_service()->bluetooth()->has_instance()) { | 286 arc_bridge_service()->bluetooth()->has_instance()) { |
| 292 bluetooth_adapter_->AddObserver(this); | 287 bluetooth_adapter_->AddObserver(this); |
| 293 } | 288 } |
| 294 } | 289 } |
| 295 | 290 |
| 296 void ArcBluetoothBridge::OnInstanceReady() { | 291 void ArcBluetoothBridge::OnInstanceReady() { |
| 297 mojom::BluetoothInstance* bluetooth_instance = | 292 mojom::BluetoothInstance* bluetooth_instance = |
| 298 arc_bridge_service()->bluetooth()->GetInstanceForMethod("Init"); | 293 GET_INSTANCE_FOR_METHOD(arc_bridge_service()->bluetooth(), Init); |
| 299 DCHECK(bluetooth_instance); | 294 DCHECK(bluetooth_instance); |
| 300 | 295 |
| 301 bluetooth_instance->Init(binding_.CreateInterfacePtrAndBind()); | 296 bluetooth_instance->Init(binding_.CreateInterfacePtrAndBind()); |
| 302 | 297 |
| 303 // The Bluetooth adapter was ready before the ARC instance, hence we didn't | 298 // The Bluetooth adapter was ready before the ARC instance, hence we didn't |
| 304 // register ourselves as an observer with it then. Since our instance is | 299 // register ourselves as an observer with it then. Since our instance is |
| 305 // ready, we should register it now. | 300 // ready, we should register it now. |
| 306 if (bluetooth_adapter_ && !bluetooth_adapter_->HasObserver(this)) | 301 if (bluetooth_adapter_ && !bluetooth_adapter_->HasObserver(this)) |
| 307 bluetooth_adapter_->AddObserver(this); | 302 bluetooth_adapter_->AddObserver(this); |
| 308 } | 303 } |
| 309 | 304 |
| 310 void ArcBluetoothBridge::OnInstanceClosed() { | 305 void ArcBluetoothBridge::OnInstanceClosed() { |
| 311 if (bluetooth_adapter_) | 306 if (bluetooth_adapter_) |
| 312 bluetooth_adapter_->RemoveObserver(this); | 307 bluetooth_adapter_->RemoveObserver(this); |
| 313 } | 308 } |
| 314 | 309 |
| 315 void ArcBluetoothBridge::SendDevice(const BluetoothDevice* device) const { | 310 void ArcBluetoothBridge::SendDevice(const BluetoothDevice* device) const { |
| 316 auto* bluetooth_instance = | 311 auto* bluetooth_instance = |
| 317 arc_bridge_service()->bluetooth()->GetInstanceForMethod("OnDeviceFound"); | 312 GET_INSTANCE_FOR_METHOD(arc_bridge_service()->bluetooth(), OnDeviceFound); |
| 318 if (!bluetooth_instance) | 313 if (!bluetooth_instance) |
| 319 return; | 314 return; |
| 320 | 315 |
| 321 std::vector<mojom::BluetoothPropertyPtr> properties = | 316 std::vector<mojom::BluetoothPropertyPtr> properties = |
| 322 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); | 317 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); |
| 323 | 318 |
| 324 bluetooth_instance->OnDeviceFound(std::move(properties)); | 319 bluetooth_instance->OnDeviceFound(std::move(properties)); |
| 325 | 320 |
| 326 | 321 |
| 327 if (!(device->GetType() & device::BLUETOOTH_TRANSPORT_LE)) | 322 if (!(device->GetType() & device::BLUETOOTH_TRANSPORT_LE)) |
| 328 return; | 323 return; |
| 329 | 324 |
| 330 base::Optional<int8_t> rssi = device->GetInquiryRSSI(); | 325 base::Optional<int8_t> rssi = device->GetInquiryRSSI(); |
| 331 mojom::BluetoothAddressPtr addr; | 326 mojom::BluetoothAddressPtr addr; |
| 332 | 327 |
| 333 // We only want to send updated advertise data to Android only when we are | 328 // We only want to send updated advertise data to Android only when we are |
| 334 // scanning which is checked by the validity of rssi. Here are the 2 cases | 329 // scanning which is checked by the validity of rssi. Here are the 2 cases |
| 335 // that we don't want to send updated advertise data to Android. | 330 // that we don't want to send updated advertise data to Android. |
| 336 // 1) Cached found device and 2) rssi became invalid when we stop scanning. | 331 // 1) Cached found device and 2) rssi became invalid when we stop scanning. |
| 337 if (rssi.has_value()) { | 332 if (rssi.has_value()) { |
| 338 auto* btle_instance = | 333 auto* btle_instance = GET_INSTANCE_FOR_METHOD( |
| 339 arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 334 arc_bridge_service()->bluetooth(), OnLEDeviceFound); |
| 340 "OnLEDeviceFound", kMinBtleVersion); | |
| 341 if (!btle_instance) | 335 if (!btle_instance) |
| 342 return; | 336 return; |
| 343 std::vector<mojom::BluetoothAdvertisingDataPtr> adv_data = | 337 std::vector<mojom::BluetoothAdvertisingDataPtr> adv_data = |
| 344 GetAdvertisingData(device); | 338 GetAdvertisingData(device); |
| 345 addr = mojom::BluetoothAddress::From(device->GetAddress()); | 339 addr = mojom::BluetoothAddress::From(device->GetAddress()); |
| 346 btle_instance->OnLEDeviceFound(std::move(addr), rssi.value(), | 340 btle_instance->OnLEDeviceFound(std::move(addr), rssi.value(), |
| 347 std::move(adv_data)); | 341 std::move(adv_data)); |
| 348 } | 342 } |
| 349 | 343 |
| 350 if (!device->IsConnected()) | 344 if (!device->IsConnected()) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 if (!(device->GetType() & device::BLUETOOTH_TRANSPORT_LE)) | 386 if (!(device->GetType() & device::BLUETOOTH_TRANSPORT_LE)) |
| 393 return; | 387 return; |
| 394 | 388 |
| 395 auto it = gatt_connection_cache_.find(old_address); | 389 auto it = gatt_connection_cache_.find(old_address); |
| 396 if (it == gatt_connection_cache_.end()) | 390 if (it == gatt_connection_cache_.end()) |
| 397 return; | 391 return; |
| 398 | 392 |
| 399 gatt_connection_cache_.erase(it); | 393 gatt_connection_cache_.erase(it); |
| 400 gatt_connection_cache_.insert(device->GetAddress()); | 394 gatt_connection_cache_.insert(device->GetAddress()); |
| 401 | 395 |
| 402 auto* btle_instance = arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 396 auto* btle_instance = GET_INSTANCE_FOR_METHOD( |
| 403 "OnLEDeviceAddressChange", kMinAddrChangeVersion); | 397 arc_bridge_service()->bluetooth(), OnLEDeviceAddressChange); |
| 404 if (!btle_instance) | 398 if (!btle_instance) |
| 405 return; | 399 return; |
| 406 | 400 |
| 407 mojom::BluetoothAddressPtr old_addr = | 401 mojom::BluetoothAddressPtr old_addr = |
| 408 mojom::BluetoothAddress::From(old_address); | 402 mojom::BluetoothAddress::From(old_address); |
| 409 mojom::BluetoothAddressPtr new_addr = | 403 mojom::BluetoothAddressPtr new_addr = |
| 410 mojom::BluetoothAddress::From(device->GetAddress()); | 404 mojom::BluetoothAddress::From(device->GetAddress()); |
| 411 btle_instance->OnLEDeviceAddressChange(std::move(old_addr), | 405 btle_instance->OnLEDeviceAddressChange(std::move(old_addr), |
| 412 std::move(new_addr)); | 406 std::move(new_addr)); |
| 413 } | 407 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 | 453 |
| 460 void ArcBluetoothBridge::GattServiceRemoved( | 454 void ArcBluetoothBridge::GattServiceRemoved( |
| 461 BluetoothAdapter* adapter, | 455 BluetoothAdapter* adapter, |
| 462 BluetoothDevice* device, | 456 BluetoothDevice* device, |
| 463 BluetoothRemoteGattService* service) { | 457 BluetoothRemoteGattService* service) { |
| 464 // Placeholder for GATT client functionality | 458 // Placeholder for GATT client functionality |
| 465 } | 459 } |
| 466 | 460 |
| 467 void ArcBluetoothBridge::GattServicesDiscovered(BluetoothAdapter* adapter, | 461 void ArcBluetoothBridge::GattServicesDiscovered(BluetoothAdapter* adapter, |
| 468 BluetoothDevice* device) { | 462 BluetoothDevice* device) { |
| 469 auto* btle_instance = arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 463 auto* btle_instance = GET_INSTANCE_FOR_METHOD( |
| 470 "OnSearchComplete", kMinBtleVersion); | 464 arc_bridge_service()->bluetooth(), OnSearchComplete); |
| 471 if (!btle_instance) | 465 if (!btle_instance) |
| 472 return; | 466 return; |
| 473 | 467 |
| 474 mojom::BluetoothAddressPtr addr = | 468 mojom::BluetoothAddressPtr addr = |
| 475 mojom::BluetoothAddress::From(device->GetAddress()); | 469 mojom::BluetoothAddress::From(device->GetAddress()); |
| 476 | 470 |
| 477 btle_instance->OnSearchComplete(std::move(addr), | 471 btle_instance->OnSearchComplete(std::move(addr), |
| 478 mojom::BluetoothGattStatus::GATT_SUCCESS); | 472 mojom::BluetoothGattStatus::GATT_SUCCESS); |
| 479 } | 473 } |
| 480 | 474 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 511 void ArcBluetoothBridge::GattDescriptorRemoved( | 505 void ArcBluetoothBridge::GattDescriptorRemoved( |
| 512 BluetoothAdapter* adapter, | 506 BluetoothAdapter* adapter, |
| 513 BluetoothRemoteGattDescriptor* descriptor) { | 507 BluetoothRemoteGattDescriptor* descriptor) { |
| 514 // Placeholder for GATT client functionality | 508 // Placeholder for GATT client functionality |
| 515 } | 509 } |
| 516 | 510 |
| 517 void ArcBluetoothBridge::GattCharacteristicValueChanged( | 511 void ArcBluetoothBridge::GattCharacteristicValueChanged( |
| 518 BluetoothAdapter* adapter, | 512 BluetoothAdapter* adapter, |
| 519 BluetoothRemoteGattCharacteristic* characteristic, | 513 BluetoothRemoteGattCharacteristic* characteristic, |
| 520 const std::vector<uint8_t>& value) { | 514 const std::vector<uint8_t>& value) { |
| 521 auto* btle_instance = arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 515 auto* btle_instance = |
| 522 "OnGattNotify", kMinBtleNotifyVersion); | 516 GET_INSTANCE_FOR_METHOD(arc_bridge_service()->bluetooth(), OnGattNotify); |
| 523 if (!btle_instance) | 517 if (!btle_instance) |
| 524 return; | 518 return; |
| 525 | 519 |
| 526 BluetoothRemoteGattService* service = characteristic->GetService(); | 520 BluetoothRemoteGattService* service = characteristic->GetService(); |
| 527 BluetoothDevice* device = service->GetDevice(); | 521 BluetoothDevice* device = service->GetDevice(); |
| 528 mojom::BluetoothAddressPtr address = | 522 mojom::BluetoothAddressPtr address = |
| 529 mojom::BluetoothAddress::From(device->GetAddress()); | 523 mojom::BluetoothAddress::From(device->GetAddress()); |
| 530 mojom::BluetoothGattServiceIDPtr service_id = | 524 mojom::BluetoothGattServiceIDPtr service_id = |
| 531 mojom::BluetoothGattServiceID::New(); | 525 mojom::BluetoothGattServiceID::New(); |
| 532 service_id->is_primary = service->IsPrimary(); | 526 service_id->is_primary = service->IsPrimary(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 550 } | 544 } |
| 551 | 545 |
| 552 template <class LocalGattAttribute> | 546 template <class LocalGattAttribute> |
| 553 void ArcBluetoothBridge::OnGattAttributeReadRequest( | 547 void ArcBluetoothBridge::OnGattAttributeReadRequest( |
| 554 const BluetoothDevice* device, | 548 const BluetoothDevice* device, |
| 555 const LocalGattAttribute* attribute, | 549 const LocalGattAttribute* attribute, |
| 556 int offset, | 550 int offset, |
| 557 const ValueCallback& success_callback, | 551 const ValueCallback& success_callback, |
| 558 const ErrorCallback& error_callback) { | 552 const ErrorCallback& error_callback) { |
| 559 DCHECK(CalledOnValidThread()); | 553 DCHECK(CalledOnValidThread()); |
| 560 auto* bluetooth_instance = | 554 auto* bluetooth_instance = GET_INSTANCE_FOR_METHOD( |
| 561 arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 555 arc_bridge_service()->bluetooth(), RequestGattRead); |
| 562 "RequestGattRead", kMinGattServerVersion); | |
| 563 if (!bluetooth_instance || !IsGattOffsetValid(offset)) { | 556 if (!bluetooth_instance || !IsGattOffsetValid(offset)) { |
| 564 error_callback.Run(); | 557 error_callback.Run(); |
| 565 return; | 558 return; |
| 566 } | 559 } |
| 567 | 560 |
| 568 DCHECK(gatt_handle_.find(attribute->GetIdentifier()) != gatt_handle_.end()); | 561 DCHECK(gatt_handle_.find(attribute->GetIdentifier()) != gatt_handle_.end()); |
| 569 | 562 |
| 570 bluetooth_instance->RequestGattRead( | 563 bluetooth_instance->RequestGattRead( |
| 571 mojom::BluetoothAddress::From(device->GetAddress()), | 564 mojom::BluetoothAddress::From(device->GetAddress()), |
| 572 gatt_handle_[attribute->GetIdentifier()], offset, false /* is_long */, | 565 gatt_handle_[attribute->GetIdentifier()], offset, false /* is_long */, |
| 573 base::Bind(&OnGattServerRead, success_callback, error_callback)); | 566 base::Bind(&OnGattServerRead, success_callback, error_callback)); |
| 574 } | 567 } |
| 575 | 568 |
| 576 template <class LocalGattAttribute> | 569 template <class LocalGattAttribute> |
| 577 void ArcBluetoothBridge::OnGattAttributeWriteRequest( | 570 void ArcBluetoothBridge::OnGattAttributeWriteRequest( |
| 578 const BluetoothDevice* device, | 571 const BluetoothDevice* device, |
| 579 const LocalGattAttribute* attribute, | 572 const LocalGattAttribute* attribute, |
| 580 const std::vector<uint8_t>& value, | 573 const std::vector<uint8_t>& value, |
| 581 int offset, | 574 int offset, |
| 582 const base::Closure& success_callback, | 575 const base::Closure& success_callback, |
| 583 const ErrorCallback& error_callback) { | 576 const ErrorCallback& error_callback) { |
| 584 DCHECK(CalledOnValidThread()); | 577 DCHECK(CalledOnValidThread()); |
| 585 auto* bluetooth_instance = | 578 auto* bluetooth_instance = GET_INSTANCE_FOR_METHOD( |
| 586 arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 579 arc_bridge_service()->bluetooth(), RequestGattWrite); |
| 587 "RequestGattWrite", kMinGattServerVersion); | |
| 588 if (!bluetooth_instance || !IsGattOffsetValid(offset)) { | 580 if (!bluetooth_instance || !IsGattOffsetValid(offset)) { |
| 589 error_callback.Run(); | 581 error_callback.Run(); |
| 590 return; | 582 return; |
| 591 } | 583 } |
| 592 | 584 |
| 593 DCHECK(gatt_handle_.find(attribute->GetIdentifier()) != gatt_handle_.end()); | 585 DCHECK(gatt_handle_.find(attribute->GetIdentifier()) != gatt_handle_.end()); |
| 594 | 586 |
| 595 bluetooth_instance->RequestGattWrite( | 587 bluetooth_instance->RequestGattWrite( |
| 596 mojom::BluetoothAddress::From(device->GetAddress()), | 588 mojom::BluetoothAddress::From(device->GetAddress()), |
| 597 gatt_handle_[attribute->GetIdentifier()], offset, value, | 589 gatt_handle_[attribute->GetIdentifier()], offset, value, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 DCHECK(bluetooth_adapter_); | 659 DCHECK(bluetooth_adapter_); |
| 668 bluetooth_adapter_->SetPowered( | 660 bluetooth_adapter_->SetPowered( |
| 669 false, base::Bind(&ArcBluetoothBridge::OnPoweredOff, | 661 false, base::Bind(&ArcBluetoothBridge::OnPoweredOff, |
| 670 weak_factory_.GetWeakPtr(), callback), | 662 weak_factory_.GetWeakPtr(), callback), |
| 671 base::Bind(&ArcBluetoothBridge::OnPoweredError, | 663 base::Bind(&ArcBluetoothBridge::OnPoweredError, |
| 672 weak_factory_.GetWeakPtr(), callback)); | 664 weak_factory_.GetWeakPtr(), callback)); |
| 673 } | 665 } |
| 674 | 666 |
| 675 void ArcBluetoothBridge::GetAdapterProperty(mojom::BluetoothPropertyType type) { | 667 void ArcBluetoothBridge::GetAdapterProperty(mojom::BluetoothPropertyType type) { |
| 676 DCHECK(bluetooth_adapter_); | 668 DCHECK(bluetooth_adapter_); |
| 677 auto* bluetooth_instance = | 669 auto* bluetooth_instance = GET_INSTANCE_FOR_METHOD( |
| 678 arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 670 arc_bridge_service()->bluetooth(), OnAdapterProperties); |
| 679 "OnAdapterProperties"); | |
| 680 if (!bluetooth_instance) | 671 if (!bluetooth_instance) |
| 681 return; | 672 return; |
| 682 | 673 |
| 683 std::vector<mojom::BluetoothPropertyPtr> properties = | 674 std::vector<mojom::BluetoothPropertyPtr> properties = |
| 684 GetAdapterProperties(type); | 675 GetAdapterProperties(type); |
| 685 | 676 |
| 686 bluetooth_instance->OnAdapterProperties(mojom::BluetoothStatus::SUCCESS, | 677 bluetooth_instance->OnAdapterProperties(mojom::BluetoothStatus::SUCCESS, |
| 687 std::move(properties)); | 678 std::move(properties)); |
| 688 } | 679 } |
| 689 | 680 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 discoverable, | 724 discoverable, |
| 734 base::Bind(&ArcBluetoothBridge::OnSetDiscoverable, | 725 base::Bind(&ArcBluetoothBridge::OnSetDiscoverable, |
| 735 weak_factory_.GetWeakPtr(), discoverable, true, timeout), | 726 weak_factory_.GetWeakPtr(), discoverable, true, timeout), |
| 736 base::Bind(&ArcBluetoothBridge::OnSetDiscoverable, | 727 base::Bind(&ArcBluetoothBridge::OnSetDiscoverable, |
| 737 weak_factory_.GetWeakPtr(), discoverable, false, timeout)); | 728 weak_factory_.GetWeakPtr(), discoverable, false, timeout)); |
| 738 } | 729 } |
| 739 | 730 |
| 740 void ArcBluetoothBridge::OnSetAdapterProperty( | 731 void ArcBluetoothBridge::OnSetAdapterProperty( |
| 741 mojom::BluetoothStatus status, | 732 mojom::BluetoothStatus status, |
| 742 mojom::BluetoothPropertyPtr property) { | 733 mojom::BluetoothPropertyPtr property) { |
| 743 auto* bluetooth_instance = | 734 auto* bluetooth_instance = GET_INSTANCE_FOR_METHOD( |
| 744 arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 735 arc_bridge_service()->bluetooth(), OnAdapterProperties); |
| 745 "OnAdapterProperties"); | |
| 746 DCHECK(bluetooth_instance); | 736 DCHECK(bluetooth_instance); |
| 747 | 737 |
| 748 std::vector<arc::mojom::BluetoothPropertyPtr> properties; | 738 std::vector<arc::mojom::BluetoothPropertyPtr> properties; |
| 749 properties.push_back(std::move(property)); | 739 properties.push_back(std::move(property)); |
| 750 | 740 |
| 751 bluetooth_instance->OnAdapterProperties(status, std::move(properties)); | 741 bluetooth_instance->OnAdapterProperties(status, std::move(properties)); |
| 752 } | 742 } |
| 753 | 743 |
| 754 void ArcBluetoothBridge::SetAdapterProperty( | 744 void ArcBluetoothBridge::SetAdapterProperty( |
| 755 mojom::BluetoothPropertyPtr property) { | 745 mojom::BluetoothPropertyPtr property) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 // Android does not set any other property type. | 777 // Android does not set any other property type. |
| 788 OnSetAdapterProperty(mojom::BluetoothStatus::UNSUPPORTED, | 778 OnSetAdapterProperty(mojom::BluetoothStatus::UNSUPPORTED, |
| 789 std::move(property)); | 779 std::move(property)); |
| 790 } | 780 } |
| 791 } | 781 } |
| 792 | 782 |
| 793 void ArcBluetoothBridge::GetRemoteDeviceProperty( | 783 void ArcBluetoothBridge::GetRemoteDeviceProperty( |
| 794 mojom::BluetoothAddressPtr remote_addr, | 784 mojom::BluetoothAddressPtr remote_addr, |
| 795 mojom::BluetoothPropertyType type) { | 785 mojom::BluetoothPropertyType type) { |
| 796 DCHECK(bluetooth_adapter_); | 786 DCHECK(bluetooth_adapter_); |
| 797 auto* bluetooth_instance = | 787 auto* bluetooth_instance = GET_INSTANCE_FOR_METHOD( |
| 798 arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 788 arc_bridge_service()->bluetooth(), OnRemoteDeviceProperties); |
| 799 "OnRemoteDeviceProperties"); | |
| 800 if (!bluetooth_instance) | 789 if (!bluetooth_instance) |
| 801 return; | 790 return; |
| 802 | 791 |
| 803 std::string addr_str = remote_addr->To<std::string>(); | 792 std::string addr_str = remote_addr->To<std::string>(); |
| 804 BluetoothDevice* device = bluetooth_adapter_->GetDevice(addr_str); | 793 BluetoothDevice* device = bluetooth_adapter_->GetDevice(addr_str); |
| 805 | 794 |
| 806 std::vector<mojom::BluetoothPropertyPtr> properties = | 795 std::vector<mojom::BluetoothPropertyPtr> properties = |
| 807 GetDeviceProperties(type, device); | 796 GetDeviceProperties(type, device); |
| 808 mojom::BluetoothStatus status = mojom::BluetoothStatus::SUCCESS; | 797 mojom::BluetoothStatus status = mojom::BluetoothStatus::SUCCESS; |
| 809 | 798 |
| 810 if (!device) { | 799 if (!device) { |
| 811 VLOG(1) << __func__ << ": device " << addr_str << " not available"; | 800 VLOG(1) << __func__ << ": device " << addr_str << " not available"; |
| 812 status = mojom::BluetoothStatus::FAIL; | 801 status = mojom::BluetoothStatus::FAIL; |
| 813 } | 802 } |
| 814 | 803 |
| 815 bluetooth_instance->OnRemoteDeviceProperties(status, std::move(remote_addr), | 804 bluetooth_instance->OnRemoteDeviceProperties(status, std::move(remote_addr), |
| 816 std::move(properties)); | 805 std::move(properties)); |
| 817 } | 806 } |
| 818 | 807 |
| 819 void ArcBluetoothBridge::SetRemoteDeviceProperty( | 808 void ArcBluetoothBridge::SetRemoteDeviceProperty( |
| 820 mojom::BluetoothAddressPtr remote_addr, | 809 mojom::BluetoothAddressPtr remote_addr, |
| 821 mojom::BluetoothPropertyPtr property) { | 810 mojom::BluetoothPropertyPtr property) { |
| 822 DCHECK(bluetooth_adapter_); | 811 DCHECK(bluetooth_adapter_); |
| 823 auto* bluetooth_instance = | 812 auto* bluetooth_instance = GET_INSTANCE_FOR_METHOD( |
| 824 arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 813 arc_bridge_service()->bluetooth(), OnRemoteDeviceProperties); |
| 825 "OnRemoteDeviceProperties"); | |
| 826 if (!bluetooth_instance) | 814 if (!bluetooth_instance) |
| 827 return; | 815 return; |
| 828 | 816 |
| 829 // Unsupported. Only used by Android hidden API, BluetoothDevice.SetAlias(). | 817 // Unsupported. Only used by Android hidden API, BluetoothDevice.SetAlias(). |
| 830 // And only Android Settings App / Android TV / NFC used that. | 818 // And only Android Settings App / Android TV / NFC used that. |
| 831 bluetooth_instance->OnRemoteDeviceProperties( | 819 bluetooth_instance->OnRemoteDeviceProperties( |
| 832 mojom::BluetoothStatus::UNSUPPORTED, std::move(remote_addr), | 820 mojom::BluetoothStatus::UNSUPPORTED, std::move(remote_addr), |
| 833 std::vector<mojom::BluetoothPropertyPtr>()); | 821 std::vector<mojom::BluetoothPropertyPtr>()); |
| 834 } | 822 } |
| 835 | 823 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 | 880 |
| 893 callback.Run(bluetooth_adapter_->IsPowered() | 881 callback.Run(bluetooth_adapter_->IsPowered() |
| 894 ? mojom::BluetoothAdapterState::ON | 882 ? mojom::BluetoothAdapterState::ON |
| 895 : mojom::BluetoothAdapterState::OFF); | 883 : mojom::BluetoothAdapterState::OFF); |
| 896 } | 884 } |
| 897 | 885 |
| 898 void ArcBluetoothBridge::OnDiscoveryStarted( | 886 void ArcBluetoothBridge::OnDiscoveryStarted( |
| 899 std::unique_ptr<BluetoothDiscoverySession> session) { | 887 std::unique_ptr<BluetoothDiscoverySession> session) { |
| 900 DCHECK(CalledOnValidThread()); | 888 DCHECK(CalledOnValidThread()); |
| 901 | 889 |
| 902 auto* bluetooth_instance = | 890 auto* bluetooth_instance = GET_INSTANCE_FOR_METHOD( |
| 903 arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 891 arc_bridge_service()->bluetooth(), OnDiscoveryStateChanged); |
| 904 "OnDiscoveryStateChanged"); | |
| 905 if (!bluetooth_instance) | 892 if (!bluetooth_instance) |
| 906 return; | 893 return; |
| 907 | 894 |
| 908 discovery_session_ = std::move(session); | 895 discovery_session_ = std::move(session); |
| 909 | 896 |
| 910 // We need to set timer to turn device discovery off because of the difference | 897 // We need to set timer to turn device discovery off because of the difference |
| 911 // between Android API (do device discovery once) and Chrome API (do device | 898 // between Android API (do device discovery once) and Chrome API (do device |
| 912 // discovery until user turns it off). | 899 // discovery until user turns it off). |
| 913 discovery_off_timer_.Start(FROM_HERE, kDiscoveryTimeout, | 900 discovery_off_timer_.Start(FROM_HERE, kDiscoveryTimeout, |
| 914 base::Bind(&ArcBluetoothBridge::CancelDiscovery, | 901 base::Bind(&ArcBluetoothBridge::CancelDiscovery, |
| 915 weak_factory_.GetWeakPtr())); | 902 weak_factory_.GetWeakPtr())); |
| 916 | 903 |
| 917 bluetooth_instance->OnDiscoveryStateChanged( | 904 bluetooth_instance->OnDiscoveryStateChanged( |
| 918 mojom::BluetoothDiscoveryState::STARTED); | 905 mojom::BluetoothDiscoveryState::STARTED); |
| 919 | 906 |
| 920 SendCachedDevicesFound(); | 907 SendCachedDevicesFound(); |
| 921 } | 908 } |
| 922 | 909 |
| 923 void ArcBluetoothBridge::OnDiscoveryStopped() { | 910 void ArcBluetoothBridge::OnDiscoveryStopped() { |
| 924 auto* bluetooth_instance = | 911 auto* bluetooth_instance = GET_INSTANCE_FOR_METHOD( |
| 925 arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 912 arc_bridge_service()->bluetooth(), OnDiscoveryStateChanged); |
| 926 "OnDiscoveryStateChanged"); | |
| 927 if (!bluetooth_instance) | 913 if (!bluetooth_instance) |
| 928 return; | 914 return; |
| 929 | 915 |
| 930 discovery_session_.reset(); | 916 discovery_session_.reset(); |
| 931 discovery_off_timer_.Stop(); | 917 discovery_off_timer_.Stop(); |
| 932 | 918 |
| 933 bluetooth_instance->OnDiscoveryStateChanged( | 919 bluetooth_instance->OnDiscoveryStateChanged( |
| 934 mojom::BluetoothDiscoveryState::STOPPED); | 920 mojom::BluetoothDiscoveryState::STOPPED); |
| 935 } | 921 } |
| 936 | 922 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1029 weak_factory_.GetWeakPtr())); | 1015 weak_factory_.GetWeakPtr())); |
| 1030 } | 1016 } |
| 1031 | 1017 |
| 1032 void ArcBluetoothBridge::StopLEScan() { | 1018 void ArcBluetoothBridge::StopLEScan() { |
| 1033 CancelDiscovery(); | 1019 CancelDiscovery(); |
| 1034 } | 1020 } |
| 1035 | 1021 |
| 1036 void ArcBluetoothBridge::OnGattConnectStateChanged( | 1022 void ArcBluetoothBridge::OnGattConnectStateChanged( |
| 1037 mojom::BluetoothAddressPtr addr, | 1023 mojom::BluetoothAddressPtr addr, |
| 1038 bool connected) const { | 1024 bool connected) const { |
| 1039 auto* btle_instance = arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 1025 auto* btle_instance = GET_INSTANCE_FOR_METHOD( |
| 1040 "OnLEConnectionStateChange", kMinBtleVersion); | 1026 arc_bridge_service()->bluetooth(), OnLEConnectionStateChange); |
| 1041 if (!btle_instance) | 1027 if (!btle_instance) |
| 1042 return; | 1028 return; |
| 1043 | 1029 |
| 1044 DCHECK(addr); | 1030 DCHECK(addr); |
| 1045 | 1031 |
| 1046 btle_instance->OnLEConnectionStateChange(std::move(addr), connected); | 1032 btle_instance->OnLEConnectionStateChange(std::move(addr), connected); |
| 1047 } | 1033 } |
| 1048 | 1034 |
| 1049 void ArcBluetoothBridge::OnGattConnected( | 1035 void ArcBluetoothBridge::OnGattConnected( |
| 1050 mojom::BluetoothAddressPtr addr, | 1036 mojom::BluetoothAddressPtr addr, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1069 << "but no gatt connection was found"; | 1055 << "but no gatt connection was found"; |
| 1070 } else { | 1056 } else { |
| 1071 gatt_connections_.erase(it); | 1057 gatt_connections_.erase(it); |
| 1072 } | 1058 } |
| 1073 | 1059 |
| 1074 OnGattConnectStateChanged(std::move(addr), false); | 1060 OnGattConnectStateChanged(std::move(addr), false); |
| 1075 } | 1061 } |
| 1076 | 1062 |
| 1077 void ArcBluetoothBridge::ConnectLEDevice( | 1063 void ArcBluetoothBridge::ConnectLEDevice( |
| 1078 mojom::BluetoothAddressPtr remote_addr) { | 1064 mojom::BluetoothAddressPtr remote_addr) { |
| 1079 auto* bluetooth_instance = | 1065 auto* bluetooth_instance = GET_INSTANCE_FOR_METHOD( |
| 1080 arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 1066 arc_bridge_service()->bluetooth(), OnLEConnectionStateChange); |
| 1081 "OnLEConnectionStateChange", kMinBtleVersion); | |
| 1082 if (!bluetooth_instance) | 1067 if (!bluetooth_instance) |
| 1083 return; | 1068 return; |
| 1084 | 1069 |
| 1085 BluetoothDevice* device = | 1070 BluetoothDevice* device = |
| 1086 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); | 1071 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); |
| 1087 DCHECK(device); | 1072 DCHECK(device); |
| 1088 | 1073 |
| 1089 if (device->IsConnected()) { | 1074 if (device->IsConnected()) { |
| 1090 bluetooth_instance->OnLEConnectionStateChange(std::move(remote_addr), true); | 1075 bluetooth_instance->OnLEConnectionStateChange(std::move(remote_addr), true); |
| 1091 return; | 1076 return; |
| 1092 } | 1077 } |
| 1093 | 1078 |
| 1094 // Also pass disconnect callback in error case since it would be disconnected | 1079 // Also pass disconnect callback in error case since it would be disconnected |
| 1095 // anyway. | 1080 // anyway. |
| 1096 mojom::BluetoothAddressPtr remote_addr_clone = remote_addr.Clone(); | 1081 mojom::BluetoothAddressPtr remote_addr_clone = remote_addr.Clone(); |
| 1097 device->CreateGattConnection( | 1082 device->CreateGattConnection( |
| 1098 base::Bind(&ArcBluetoothBridge::OnGattConnected, | 1083 base::Bind(&ArcBluetoothBridge::OnGattConnected, |
| 1099 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr)), | 1084 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr)), |
| 1100 base::Bind(&ArcBluetoothBridge::OnGattConnectError, | 1085 base::Bind(&ArcBluetoothBridge::OnGattConnectError, |
| 1101 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr_clone))); | 1086 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr_clone))); |
| 1102 } | 1087 } |
| 1103 | 1088 |
| 1104 void ArcBluetoothBridge::DisconnectLEDevice( | 1089 void ArcBluetoothBridge::DisconnectLEDevice( |
| 1105 mojom::BluetoothAddressPtr remote_addr) { | 1090 mojom::BluetoothAddressPtr remote_addr) { |
| 1106 auto* bluetooth_instance = | 1091 auto* bluetooth_instance = GET_INSTANCE_FOR_METHOD( |
| 1107 arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 1092 arc_bridge_service()->bluetooth(), OnLEConnectionStateChange); |
| 1108 "OnLEConnectionStateChange", kMinBtleVersion); | |
| 1109 if (!bluetooth_instance) | 1093 if (!bluetooth_instance) |
| 1110 return; | 1094 return; |
| 1111 | 1095 |
| 1112 BluetoothDevice* device = | 1096 BluetoothDevice* device = |
| 1113 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); | 1097 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); |
| 1114 DCHECK(device); | 1098 DCHECK(device); |
| 1115 | 1099 |
| 1116 if (!device->IsConnected()) { | 1100 if (!device->IsConnected()) { |
| 1117 bluetooth_instance->OnLEConnectionStateChange(std::move(remote_addr), | 1101 bluetooth_instance->OnLEConnectionStateChange(std::move(remote_addr), |
| 1118 false); | 1102 false); |
| 1119 return; | 1103 return; |
| 1120 } | 1104 } |
| 1121 | 1105 |
| 1122 mojom::BluetoothAddressPtr remote_addr_clone = remote_addr.Clone(); | 1106 mojom::BluetoothAddressPtr remote_addr_clone = remote_addr.Clone(); |
| 1123 device->Disconnect( | 1107 device->Disconnect( |
| 1124 base::Bind(&ArcBluetoothBridge::OnGattDisconnected, | 1108 base::Bind(&ArcBluetoothBridge::OnGattDisconnected, |
| 1125 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr)), | 1109 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr)), |
| 1126 base::Bind(&ArcBluetoothBridge::OnGattDisconnected, | 1110 base::Bind(&ArcBluetoothBridge::OnGattDisconnected, |
| 1127 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr_clone))); | 1111 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr_clone))); |
| 1128 } | 1112 } |
| 1129 | 1113 |
| 1130 void ArcBluetoothBridge::SearchService(mojom::BluetoothAddressPtr remote_addr) { | 1114 void ArcBluetoothBridge::SearchService(mojom::BluetoothAddressPtr remote_addr) { |
| 1131 auto* bluetooth_instance = | 1115 auto* bluetooth_instance = GET_INSTANCE_FOR_METHOD( |
| 1132 arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 1116 arc_bridge_service()->bluetooth(), OnSearchComplete); |
| 1133 "OnSearchComplete", kMinBtleVersion); | |
| 1134 if (!bluetooth_instance) | 1117 if (!bluetooth_instance) |
| 1135 return; | 1118 return; |
| 1136 | 1119 |
| 1137 BluetoothDevice* device = | 1120 BluetoothDevice* device = |
| 1138 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); | 1121 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); |
| 1139 DCHECK(device); | 1122 DCHECK(device); |
| 1140 | 1123 |
| 1141 // Call the callback if discovery is completed | 1124 // Call the callback if discovery is completed |
| 1142 if (device->IsGattServicesDiscoveryComplete()) { | 1125 if (device->IsGattServicesDiscoveryComplete()) { |
| 1143 bluetooth_instance->OnSearchComplete( | 1126 bluetooth_instance->OnSearchComplete( |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 return; | 1183 return; |
| 1201 } | 1184 } |
| 1202 advertisment_->Unregister(base::Bind(&ArcBluetoothBridge::OnStopLEListenDone, | 1185 advertisment_->Unregister(base::Bind(&ArcBluetoothBridge::OnStopLEListenDone, |
| 1203 weak_factory_.GetWeakPtr(), callback), | 1186 weak_factory_.GetWeakPtr(), callback), |
| 1204 base::Bind(&ArcBluetoothBridge::OnStopLEListenError, | 1187 base::Bind(&ArcBluetoothBridge::OnStopLEListenError, |
| 1205 weak_factory_.GetWeakPtr(), callback)); | 1188 weak_factory_.GetWeakPtr(), callback)); |
| 1206 } | 1189 } |
| 1207 | 1190 |
| 1208 void ArcBluetoothBridge::GetGattDB(mojom::BluetoothAddressPtr remote_addr) { | 1191 void ArcBluetoothBridge::GetGattDB(mojom::BluetoothAddressPtr remote_addr) { |
| 1209 auto* bluetooth_instance = | 1192 auto* bluetooth_instance = |
| 1210 arc_bridge_service()->bluetooth()->GetInstanceForMethod("OnGetGattDB", | 1193 GET_INSTANCE_FOR_METHOD(arc_bridge_service()->bluetooth(), OnGetGattDB); |
| 1211 kMinBtleVersion); | |
| 1212 if (!bluetooth_instance) | 1194 if (!bluetooth_instance) |
| 1213 return; | 1195 return; |
| 1214 | 1196 |
| 1215 BluetoothDevice* device = | 1197 BluetoothDevice* device = |
| 1216 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); | 1198 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); |
| 1217 std::vector<mojom::BluetoothGattDBElementPtr> db; | 1199 std::vector<mojom::BluetoothGattDBElementPtr> db; |
| 1218 for (auto* service : device->GetGattServices()) { | 1200 for (auto* service : device->GetGattServices()) { |
| 1219 mojom::BluetoothGattDBElementPtr service_element = CreateGattDBElement( | 1201 mojom::BluetoothGattDBElementPtr service_element = CreateGattDBElement( |
| 1220 service->IsPrimary() | 1202 service->IsPrimary() |
| 1221 ? mojom::BluetoothGattDBAttributeType::BTGATT_DB_PRIMARY_SERVICE | 1203 ? mojom::BluetoothGattDBAttributeType::BTGATT_DB_PRIMARY_SERVICE |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1767 << ", error code = " << error_code; | 1749 << ", error code = " << error_code; |
| 1768 advertisements_.erase(adv_handle); | 1750 advertisements_.erase(adv_handle); |
| 1769 callback.Run(mojom::BluetoothGattStatus::GATT_FAILURE); | 1751 callback.Run(mojom::BluetoothGattStatus::GATT_FAILURE); |
| 1770 } | 1752 } |
| 1771 | 1753 |
| 1772 void ArcBluetoothBridge::OnDiscoveryError() { | 1754 void ArcBluetoothBridge::OnDiscoveryError() { |
| 1773 LOG(WARNING) << "failed to change discovery state"; | 1755 LOG(WARNING) << "failed to change discovery state"; |
| 1774 } | 1756 } |
| 1775 | 1757 |
| 1776 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const { | 1758 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const { |
| 1777 auto* bluetooth_instance = | 1759 auto* bluetooth_instance = GET_INSTANCE_FOR_METHOD( |
| 1778 arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 1760 arc_bridge_service()->bluetooth(), OnBondStateChanged); |
| 1779 "OnBondStateChanged"); | |
| 1780 if (!bluetooth_instance) | 1761 if (!bluetooth_instance) |
| 1781 return; | 1762 return; |
| 1782 | 1763 |
| 1783 bluetooth_instance->OnBondStateChanged(mojom::BluetoothStatus::SUCCESS, | 1764 bluetooth_instance->OnBondStateChanged(mojom::BluetoothStatus::SUCCESS, |
| 1784 std::move(addr), | 1765 std::move(addr), |
| 1785 mojom::BluetoothBondState::BONDING); | 1766 mojom::BluetoothBondState::BONDING); |
| 1786 } | 1767 } |
| 1787 | 1768 |
| 1788 void ArcBluetoothBridge::OnPairedDone(mojom::BluetoothAddressPtr addr) const { | 1769 void ArcBluetoothBridge::OnPairedDone(mojom::BluetoothAddressPtr addr) const { |
| 1789 auto* bluetooth_instance = | 1770 auto* bluetooth_instance = GET_INSTANCE_FOR_METHOD( |
| 1790 arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 1771 arc_bridge_service()->bluetooth(), OnBondStateChanged); |
| 1791 "OnBondStateChanged"); | |
| 1792 if (!bluetooth_instance) | 1772 if (!bluetooth_instance) |
| 1793 return; | 1773 return; |
| 1794 | 1774 |
| 1795 bluetooth_instance->OnBondStateChanged(mojom::BluetoothStatus::SUCCESS, | 1775 bluetooth_instance->OnBondStateChanged(mojom::BluetoothStatus::SUCCESS, |
| 1796 std::move(addr), | 1776 std::move(addr), |
| 1797 mojom::BluetoothBondState::BONDED); | 1777 mojom::BluetoothBondState::BONDED); |
| 1798 } | 1778 } |
| 1799 | 1779 |
| 1800 void ArcBluetoothBridge::OnPairedError( | 1780 void ArcBluetoothBridge::OnPairedError( |
| 1801 mojom::BluetoothAddressPtr addr, | 1781 mojom::BluetoothAddressPtr addr, |
| 1802 BluetoothDevice::ConnectErrorCode error_code) const { | 1782 BluetoothDevice::ConnectErrorCode error_code) const { |
| 1803 auto* bluetooth_instance = | 1783 auto* bluetooth_instance = GET_INSTANCE_FOR_METHOD( |
| 1804 arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 1784 arc_bridge_service()->bluetooth(), OnBondStateChanged); |
| 1805 "OnBondStateChanged"); | |
| 1806 if (!bluetooth_instance) | 1785 if (!bluetooth_instance) |
| 1807 return; | 1786 return; |
| 1808 | 1787 |
| 1809 bluetooth_instance->OnBondStateChanged(mojom::BluetoothStatus::FAIL, | 1788 bluetooth_instance->OnBondStateChanged(mojom::BluetoothStatus::FAIL, |
| 1810 std::move(addr), | 1789 std::move(addr), |
| 1811 mojom::BluetoothBondState::NONE); | 1790 mojom::BluetoothBondState::NONE); |
| 1812 } | 1791 } |
| 1813 | 1792 |
| 1814 void ArcBluetoothBridge::OnForgetDone(mojom::BluetoothAddressPtr addr) const { | 1793 void ArcBluetoothBridge::OnForgetDone(mojom::BluetoothAddressPtr addr) const { |
| 1815 auto* bluetooth_instance = | 1794 auto* bluetooth_instance = GET_INSTANCE_FOR_METHOD( |
| 1816 arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 1795 arc_bridge_service()->bluetooth(), OnBondStateChanged); |
| 1817 "OnBondStateChanged"); | |
| 1818 if (!bluetooth_instance) | 1796 if (!bluetooth_instance) |
| 1819 return; | 1797 return; |
| 1820 | 1798 |
| 1821 bluetooth_instance->OnBondStateChanged(mojom::BluetoothStatus::SUCCESS, | 1799 bluetooth_instance->OnBondStateChanged(mojom::BluetoothStatus::SUCCESS, |
| 1822 std::move(addr), | 1800 std::move(addr), |
| 1823 mojom::BluetoothBondState::NONE); | 1801 mojom::BluetoothBondState::NONE); |
| 1824 } | 1802 } |
| 1825 | 1803 |
| 1826 void ArcBluetoothBridge::OnForgetError(mojom::BluetoothAddressPtr addr) const { | 1804 void ArcBluetoothBridge::OnForgetError(mojom::BluetoothAddressPtr addr) const { |
| 1827 auto* bluetooth_instance = | 1805 auto* bluetooth_instance = GET_INSTANCE_FOR_METHOD( |
| 1828 arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 1806 arc_bridge_service()->bluetooth(), OnBondStateChanged); |
| 1829 "OnBondStateChanged"); | |
| 1830 if (!bluetooth_instance) | 1807 if (!bluetooth_instance) |
| 1831 return; | 1808 return; |
| 1832 | 1809 |
| 1833 BluetoothDevice* device = | 1810 BluetoothDevice* device = |
| 1834 bluetooth_adapter_->GetDevice(addr->To<std::string>()); | 1811 bluetooth_adapter_->GetDevice(addr->To<std::string>()); |
| 1835 mojom::BluetoothBondState bond_state = mojom::BluetoothBondState::NONE; | 1812 mojom::BluetoothBondState bond_state = mojom::BluetoothBondState::NONE; |
| 1836 if (device && device->IsPaired()) { | 1813 if (device && device->IsPaired()) { |
| 1837 bond_state = mojom::BluetoothBondState::BONDED; | 1814 bond_state = mojom::BluetoothBondState::BONDED; |
| 1838 } | 1815 } |
| 1839 bluetooth_instance->OnBondStateChanged(mojom::BluetoothStatus::FAIL, | 1816 bluetooth_instance->OnBondStateChanged(mojom::BluetoothStatus::FAIL, |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2113 mojom::BluetoothAddress::From(device->GetAddress()); | 2090 mojom::BluetoothAddress::From(device->GetAddress()); |
| 2114 OnPairing(addr->Clone()); | 2091 OnPairing(addr->Clone()); |
| 2115 OnPairedDone(std::move(addr)); | 2092 OnPairedDone(std::move(addr)); |
| 2116 } | 2093 } |
| 2117 } | 2094 } |
| 2118 | 2095 |
| 2119 void ArcBluetoothBridge::OnGetServiceRecordsDone( | 2096 void ArcBluetoothBridge::OnGetServiceRecordsDone( |
| 2120 mojom::BluetoothAddressPtr remote_addr, | 2097 mojom::BluetoothAddressPtr remote_addr, |
| 2121 const BluetoothUUID& target_uuid, | 2098 const BluetoothUUID& target_uuid, |
| 2122 const std::vector<bluez::BluetoothServiceRecordBlueZ>& records_bluez) { | 2099 const std::vector<bluez::BluetoothServiceRecordBlueZ>& records_bluez) { |
| 2123 auto* sdp_bluetooth_instance = | 2100 auto* sdp_bluetooth_instance = GET_INSTANCE_FOR_METHOD( |
| 2124 arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 2101 arc_bridge_service()->bluetooth(), OnGetSdpRecords); |
| 2125 "OnGetSdpRecords", kMinSdpSupportVersion); | |
| 2126 if (!sdp_bluetooth_instance) | 2102 if (!sdp_bluetooth_instance) |
| 2127 return; | 2103 return; |
| 2128 | 2104 |
| 2129 std::vector<mojom::BluetoothSdpRecordPtr> records; | 2105 std::vector<mojom::BluetoothSdpRecordPtr> records; |
| 2130 for (const auto& r : records_bluez) | 2106 for (const auto& r : records_bluez) |
| 2131 records.push_back(mojom::BluetoothSdpRecord::From(r)); | 2107 records.push_back(mojom::BluetoothSdpRecord::From(r)); |
| 2132 | 2108 |
| 2133 sdp_bluetooth_instance->OnGetSdpRecords(mojom::BluetoothStatus::SUCCESS, | 2109 sdp_bluetooth_instance->OnGetSdpRecords(mojom::BluetoothStatus::SUCCESS, |
| 2134 std::move(remote_addr), target_uuid, | 2110 std::move(remote_addr), target_uuid, |
| 2135 std::move(records)); | 2111 std::move(records)); |
| 2136 } | 2112 } |
| 2137 | 2113 |
| 2138 void ArcBluetoothBridge::OnGetServiceRecordsError( | 2114 void ArcBluetoothBridge::OnGetServiceRecordsError( |
| 2139 mojom::BluetoothAddressPtr remote_addr, | 2115 mojom::BluetoothAddressPtr remote_addr, |
| 2140 const BluetoothUUID& target_uuid, | 2116 const BluetoothUUID& target_uuid, |
| 2141 bluez::BluetoothServiceRecordBlueZ::ErrorCode error_code) { | 2117 bluez::BluetoothServiceRecordBlueZ::ErrorCode error_code) { |
| 2142 auto* sdp_bluetooth_instance = | 2118 auto* sdp_bluetooth_instance = GET_INSTANCE_FOR_METHOD( |
| 2143 arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 2119 arc_bridge_service()->bluetooth(), OnGetSdpRecords); |
| 2144 "OnGetSdpRecords", kMinSdpSupportVersion); | |
| 2145 if (!sdp_bluetooth_instance) | 2120 if (!sdp_bluetooth_instance) |
| 2146 return; | 2121 return; |
| 2147 | 2122 |
| 2148 mojom::BluetoothStatus status; | 2123 mojom::BluetoothStatus status; |
| 2149 | 2124 |
| 2150 switch (error_code) { | 2125 switch (error_code) { |
| 2151 case bluez::BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY: | 2126 case bluez::BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY: |
| 2152 status = mojom::BluetoothStatus::NOT_READY; | 2127 status = mojom::BluetoothStatus::NOT_READY; |
| 2153 break; | 2128 break; |
| 2154 case bluez::BluetoothServiceRecordBlueZ::ErrorCode:: | 2129 case bluez::BluetoothServiceRecordBlueZ::ErrorCode:: |
| 2155 ERROR_DEVICE_DISCONNECTED: | 2130 ERROR_DEVICE_DISCONNECTED: |
| 2156 status = mojom::BluetoothStatus::RMT_DEV_DOWN; | 2131 status = mojom::BluetoothStatus::RMT_DEV_DOWN; |
| 2157 break; | 2132 break; |
| 2158 default: | 2133 default: |
| 2159 status = mojom::BluetoothStatus::FAIL; | 2134 status = mojom::BluetoothStatus::FAIL; |
| 2160 break; | 2135 break; |
| 2161 } | 2136 } |
| 2162 | 2137 |
| 2163 sdp_bluetooth_instance->OnGetSdpRecords( | 2138 sdp_bluetooth_instance->OnGetSdpRecords( |
| 2164 status, std::move(remote_addr), target_uuid, | 2139 status, std::move(remote_addr), target_uuid, |
| 2165 std::vector<mojom::BluetoothSdpRecordPtr>()); | 2140 std::vector<mojom::BluetoothSdpRecordPtr>()); |
| 2166 } | 2141 } |
| 2167 | 2142 |
| 2168 bool ArcBluetoothBridge::CalledOnValidThread() { | 2143 bool ArcBluetoothBridge::CalledOnValidThread() { |
| 2169 return thread_checker_.CalledOnValidThread(); | 2144 return thread_checker_.CalledOnValidThread(); |
| 2170 } | 2145 } |
| 2171 | 2146 |
| 2172 } // namespace arc | 2147 } // namespace arc |
| OLD | NEW |