| 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 BluetoothGattService::GattErrorCode error_code) { | 145 BluetoothGattService::GattErrorCode error_code) { |
| 146 callback.Run(mojo::ConvertTo<arc::mojom::BluetoothGattStatus>(error_code)); | 146 callback.Run(mojo::ConvertTo<arc::mojom::BluetoothGattStatus>(error_code)); |
| 147 } | 147 } |
| 148 | 148 |
| 149 // Common success callback for ReadGattCharacteristic and ReadGattDescriptor | 149 // Common success callback for ReadGattCharacteristic and ReadGattDescriptor |
| 150 void OnGattReadDone(const GattReadCallback& callback, | 150 void OnGattReadDone(const GattReadCallback& callback, |
| 151 const std::vector<uint8_t>& result) { | 151 const std::vector<uint8_t>& result) { |
| 152 arc::mojom::BluetoothGattValuePtr gattValue = | 152 arc::mojom::BluetoothGattValuePtr gattValue = |
| 153 arc::mojom::BluetoothGattValue::New(); | 153 arc::mojom::BluetoothGattValue::New(); |
| 154 gattValue->status = arc::mojom::BluetoothGattStatus::GATT_SUCCESS; | 154 gattValue->status = arc::mojom::BluetoothGattStatus::GATT_SUCCESS; |
| 155 gattValue->value = mojo::Array<uint8_t>::From(result); | 155 gattValue->value = result; |
| 156 callback.Run(std::move(gattValue)); | 156 callback.Run(std::move(gattValue)); |
| 157 } | 157 } |
| 158 | 158 |
| 159 // Common error callback for ReadGattCharacteristic and ReadGattDescriptor | 159 // Common error callback for ReadGattCharacteristic and ReadGattDescriptor |
| 160 void OnGattReadError(const GattReadCallback& callback, | 160 void OnGattReadError(const GattReadCallback& callback, |
| 161 BluetoothGattService::GattErrorCode error_code) { | 161 BluetoothGattService::GattErrorCode error_code) { |
| 162 arc::mojom::BluetoothGattValuePtr gattValue = | 162 arc::mojom::BluetoothGattValuePtr gattValue = |
| 163 arc::mojom::BluetoothGattValue::New(); | 163 arc::mojom::BluetoothGattValue::New(); |
| 164 gattValue->status = | 164 gattValue->status = |
| 165 mojo::ConvertTo<arc::mojom::BluetoothGattStatus>(error_code); | 165 mojo::ConvertTo<arc::mojom::BluetoothGattStatus>(error_code); |
| 166 gattValue->value = nullptr; | 166 gattValue->value = std::vector<uint8_t>(); |
| 167 callback.Run(std::move(gattValue)); | 167 callback.Run(std::move(gattValue)); |
| 168 } | 168 } |
| 169 | 169 |
| 170 // Callback function for mojom::BluetoothInstance::RequestGattRead | 170 // Callback function for mojom::BluetoothInstance::RequestGattRead |
| 171 void OnGattServerRead( | 171 void OnGattServerRead( |
| 172 const BluetoothLocalGattService::Delegate::ValueCallback& success_callback, | 172 const BluetoothLocalGattService::Delegate::ValueCallback& success_callback, |
| 173 const BluetoothLocalGattService::Delegate::ErrorCallback& error_callback, | 173 const BluetoothLocalGattService::Delegate::ErrorCallback& error_callback, |
| 174 arc::mojom::BluetoothGattStatus status, | 174 arc::mojom::BluetoothGattStatus status, |
| 175 mojo::Array<uint8_t> value) { | 175 const std::vector<uint8_t>& value) { |
| 176 if (status == arc::mojom::BluetoothGattStatus::GATT_SUCCESS) | 176 if (status == arc::mojom::BluetoothGattStatus::GATT_SUCCESS) |
| 177 success_callback.Run(value.To<std::vector<uint8_t>>()); | 177 success_callback.Run(value); |
| 178 else | 178 else |
| 179 error_callback.Run(); | 179 error_callback.Run(); |
| 180 } | 180 } |
| 181 | 181 |
| 182 // Callback function for mojom::BluetoothInstance::RequestGattWrite | 182 // Callback function for mojom::BluetoothInstance::RequestGattWrite |
| 183 void OnGattServerWrite( | 183 void OnGattServerWrite( |
| 184 const base::Closure& success_callback, | 184 const base::Closure& success_callback, |
| 185 const BluetoothLocalGattService::Delegate::ErrorCallback& error_callback, | 185 const BluetoothLocalGattService::Delegate::ErrorCallback& error_callback, |
| 186 arc::mojom::BluetoothGattStatus status) { | 186 arc::mojom::BluetoothGattStatus status) { |
| 187 if (status == arc::mojom::BluetoothGattStatus::GATT_SUCCESS) | 187 if (status == arc::mojom::BluetoothGattStatus::GATT_SUCCESS) |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 if (bluetooth_adapter_) | 311 if (bluetooth_adapter_) |
| 312 bluetooth_adapter_->RemoveObserver(this); | 312 bluetooth_adapter_->RemoveObserver(this); |
| 313 } | 313 } |
| 314 | 314 |
| 315 void ArcBluetoothBridge::SendDevice(const BluetoothDevice* device) const { | 315 void ArcBluetoothBridge::SendDevice(const BluetoothDevice* device) const { |
| 316 auto* bluetooth_instance = | 316 auto* bluetooth_instance = |
| 317 arc_bridge_service()->bluetooth()->GetInstanceForMethod("OnDeviceFound"); | 317 arc_bridge_service()->bluetooth()->GetInstanceForMethod("OnDeviceFound"); |
| 318 if (!bluetooth_instance) | 318 if (!bluetooth_instance) |
| 319 return; | 319 return; |
| 320 | 320 |
| 321 mojo::Array<mojom::BluetoothPropertyPtr> properties = | 321 std::vector<mojom::BluetoothPropertyPtr> properties = |
| 322 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); | 322 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); |
| 323 | 323 |
| 324 bluetooth_instance->OnDeviceFound(std::move(properties)); | 324 bluetooth_instance->OnDeviceFound(std::move(properties)); |
| 325 | 325 |
| 326 | 326 |
| 327 if (!(device->GetType() & device::BLUETOOTH_TRANSPORT_LE)) | 327 if (!(device->GetType() & device::BLUETOOTH_TRANSPORT_LE)) |
| 328 return; | 328 return; |
| 329 | 329 |
| 330 base::Optional<int8_t> rssi = device->GetInquiryRSSI(); | 330 base::Optional<int8_t> rssi = device->GetInquiryRSSI(); |
| 331 mojom::BluetoothAddressPtr addr; | 331 mojom::BluetoothAddressPtr addr; |
| 332 | 332 |
| 333 // We only want to send updated advertise data to Android only when we are | 333 // 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 | 334 // 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. | 335 // 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. | 336 // 1) Cached found device and 2) rssi became invalid when we stop scanning. |
| 337 if (rssi.has_value()) { | 337 if (rssi.has_value()) { |
| 338 auto* btle_instance = | 338 auto* btle_instance = |
| 339 arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 339 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 340 "OnLEDeviceFound", kMinBtleVersion); | 340 "OnLEDeviceFound", kMinBtleVersion); |
| 341 if (!btle_instance) | 341 if (!btle_instance) |
| 342 return; | 342 return; |
| 343 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = | 343 std::vector<mojom::BluetoothAdvertisingDataPtr> adv_data = |
| 344 GetAdvertisingData(device); | 344 GetAdvertisingData(device); |
| 345 addr = mojom::BluetoothAddress::From(device->GetAddress()); | 345 addr = mojom::BluetoothAddress::From(device->GetAddress()); |
| 346 btle_instance->OnLEDeviceFound(std::move(addr), rssi.value(), | 346 btle_instance->OnLEDeviceFound(std::move(addr), rssi.value(), |
| 347 std::move(adv_data)); | 347 std::move(adv_data)); |
| 348 } | 348 } |
| 349 | 349 |
| 350 if (!device->IsConnected()) | 350 if (!device->IsConnected()) |
| 351 return; | 351 return; |
| 352 | 352 |
| 353 addr = mojom::BluetoothAddress::From(device->GetAddress()); | 353 addr = mojom::BluetoothAddress::From(device->GetAddress()); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 service_id->is_primary = service->IsPrimary(); | 532 service_id->is_primary = service->IsPrimary(); |
| 533 service_id->id = mojom::BluetoothGattID::New(); | 533 service_id->id = mojom::BluetoothGattID::New(); |
| 534 service_id->id->inst_id = ConvertGattIdentifierToId(service->GetIdentifier()); | 534 service_id->id->inst_id = ConvertGattIdentifierToId(service->GetIdentifier()); |
| 535 service_id->id->uuid = service->GetUUID(); | 535 service_id->id->uuid = service->GetUUID(); |
| 536 | 536 |
| 537 mojom::BluetoothGattIDPtr char_id = mojom::BluetoothGattID::New(); | 537 mojom::BluetoothGattIDPtr char_id = mojom::BluetoothGattID::New(); |
| 538 char_id->inst_id = ConvertGattIdentifierToId(characteristic->GetIdentifier()); | 538 char_id->inst_id = ConvertGattIdentifierToId(characteristic->GetIdentifier()); |
| 539 char_id->uuid = characteristic->GetUUID(); | 539 char_id->uuid = characteristic->GetUUID(); |
| 540 | 540 |
| 541 btle_instance->OnGattNotify(std::move(address), std::move(service_id), | 541 btle_instance->OnGattNotify(std::move(address), std::move(service_id), |
| 542 std::move(char_id), true /* is_notify */, | 542 std::move(char_id), true /* is_notify */, value); |
| 543 mojo::Array<uint8_t>::From(value)); | |
| 544 } | 543 } |
| 545 | 544 |
| 546 void ArcBluetoothBridge::GattDescriptorValueChanged( | 545 void ArcBluetoothBridge::GattDescriptorValueChanged( |
| 547 BluetoothAdapter* adapter, | 546 BluetoothAdapter* adapter, |
| 548 BluetoothRemoteGattDescriptor* descriptor, | 547 BluetoothRemoteGattDescriptor* descriptor, |
| 549 const std::vector<uint8_t>& value) { | 548 const std::vector<uint8_t>& value) { |
| 550 // Placeholder for GATT client functionality | 549 // Placeholder for GATT client functionality |
| 551 } | 550 } |
| 552 | 551 |
| 553 template <class LocalGattAttribute> | 552 template <class LocalGattAttribute> |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 "RequestGattWrite", kMinGattServerVersion); | 587 "RequestGattWrite", kMinGattServerVersion); |
| 589 if (!bluetooth_instance || !IsGattOffsetValid(offset)) { | 588 if (!bluetooth_instance || !IsGattOffsetValid(offset)) { |
| 590 error_callback.Run(); | 589 error_callback.Run(); |
| 591 return; | 590 return; |
| 592 } | 591 } |
| 593 | 592 |
| 594 DCHECK(gatt_handle_.find(attribute->GetIdentifier()) != gatt_handle_.end()); | 593 DCHECK(gatt_handle_.find(attribute->GetIdentifier()) != gatt_handle_.end()); |
| 595 | 594 |
| 596 bluetooth_instance->RequestGattWrite( | 595 bluetooth_instance->RequestGattWrite( |
| 597 mojom::BluetoothAddress::From(device->GetAddress()), | 596 mojom::BluetoothAddress::From(device->GetAddress()), |
| 598 gatt_handle_[attribute->GetIdentifier()], offset, | 597 gatt_handle_[attribute->GetIdentifier()], offset, value, |
| 599 mojo::Array<uint8_t>::From(value), | |
| 600 base::Bind(&OnGattServerWrite, success_callback, error_callback)); | 598 base::Bind(&OnGattServerWrite, success_callback, error_callback)); |
| 601 } | 599 } |
| 602 | 600 |
| 603 void ArcBluetoothBridge::OnCharacteristicReadRequest( | 601 void ArcBluetoothBridge::OnCharacteristicReadRequest( |
| 604 const BluetoothDevice* device, | 602 const BluetoothDevice* device, |
| 605 const BluetoothLocalGattCharacteristic* characteristic, | 603 const BluetoothLocalGattCharacteristic* characteristic, |
| 606 int offset, | 604 int offset, |
| 607 const ValueCallback& callback, | 605 const ValueCallback& callback, |
| 608 const ErrorCallback& error_callback) { | 606 const ErrorCallback& error_callback) { |
| 609 OnGattAttributeReadRequest(device, characteristic, offset, callback, | 607 OnGattAttributeReadRequest(device, characteristic, offset, callback, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 } | 673 } |
| 676 | 674 |
| 677 void ArcBluetoothBridge::GetAdapterProperty(mojom::BluetoothPropertyType type) { | 675 void ArcBluetoothBridge::GetAdapterProperty(mojom::BluetoothPropertyType type) { |
| 678 DCHECK(bluetooth_adapter_); | 676 DCHECK(bluetooth_adapter_); |
| 679 auto* bluetooth_instance = | 677 auto* bluetooth_instance = |
| 680 arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 678 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 681 "OnAdapterProperties"); | 679 "OnAdapterProperties"); |
| 682 if (!bluetooth_instance) | 680 if (!bluetooth_instance) |
| 683 return; | 681 return; |
| 684 | 682 |
| 685 mojo::Array<mojom::BluetoothPropertyPtr> properties = | 683 std::vector<mojom::BluetoothPropertyPtr> properties = |
| 686 GetAdapterProperties(type); | 684 GetAdapterProperties(type); |
| 687 | 685 |
| 688 bluetooth_instance->OnAdapterProperties(mojom::BluetoothStatus::SUCCESS, | 686 bluetooth_instance->OnAdapterProperties(mojom::BluetoothStatus::SUCCESS, |
| 689 std::move(properties)); | 687 std::move(properties)); |
| 690 } | 688 } |
| 691 | 689 |
| 692 void ArcBluetoothBridge::OnSetDiscoverable(bool discoverable, | 690 void ArcBluetoothBridge::OnSetDiscoverable(bool discoverable, |
| 693 bool success, | 691 bool success, |
| 694 uint32_t timeout) { | 692 uint32_t timeout) { |
| 695 DCHECK(CalledOnValidThread()); | 693 DCHECK(CalledOnValidThread()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 } | 738 } |
| 741 | 739 |
| 742 void ArcBluetoothBridge::OnSetAdapterProperty( | 740 void ArcBluetoothBridge::OnSetAdapterProperty( |
| 743 mojom::BluetoothStatus status, | 741 mojom::BluetoothStatus status, |
| 744 mojom::BluetoothPropertyPtr property) { | 742 mojom::BluetoothPropertyPtr property) { |
| 745 auto* bluetooth_instance = | 743 auto* bluetooth_instance = |
| 746 arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 744 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 747 "OnAdapterProperties"); | 745 "OnAdapterProperties"); |
| 748 DCHECK(bluetooth_instance); | 746 DCHECK(bluetooth_instance); |
| 749 | 747 |
| 750 auto properties = mojo::Array<arc::mojom::BluetoothPropertyPtr>::New(0); | 748 std::vector<arc::mojom::BluetoothPropertyPtr> properties; |
| 751 properties.push_back(std::move(property)); | 749 properties.push_back(std::move(property)); |
| 752 | 750 |
| 753 bluetooth_instance->OnAdapterProperties(status, std::move(properties)); | 751 bluetooth_instance->OnAdapterProperties(status, std::move(properties)); |
| 754 } | 752 } |
| 755 | 753 |
| 756 void ArcBluetoothBridge::SetAdapterProperty( | 754 void ArcBluetoothBridge::SetAdapterProperty( |
| 757 mojom::BluetoothPropertyPtr property) { | 755 mojom::BluetoothPropertyPtr property) { |
| 758 DCHECK(bluetooth_adapter_); | 756 DCHECK(bluetooth_adapter_); |
| 759 | 757 |
| 760 if (property->is_discovery_timeout()) { | 758 if (property->is_discovery_timeout()) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 DCHECK(bluetooth_adapter_); | 796 DCHECK(bluetooth_adapter_); |
| 799 auto* bluetooth_instance = | 797 auto* bluetooth_instance = |
| 800 arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 798 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 801 "OnRemoteDeviceProperties"); | 799 "OnRemoteDeviceProperties"); |
| 802 if (!bluetooth_instance) | 800 if (!bluetooth_instance) |
| 803 return; | 801 return; |
| 804 | 802 |
| 805 std::string addr_str = remote_addr->To<std::string>(); | 803 std::string addr_str = remote_addr->To<std::string>(); |
| 806 BluetoothDevice* device = bluetooth_adapter_->GetDevice(addr_str); | 804 BluetoothDevice* device = bluetooth_adapter_->GetDevice(addr_str); |
| 807 | 805 |
| 808 mojo::Array<mojom::BluetoothPropertyPtr> properties = | 806 std::vector<mojom::BluetoothPropertyPtr> properties = |
| 809 GetDeviceProperties(type, device); | 807 GetDeviceProperties(type, device); |
| 810 mojom::BluetoothStatus status = mojom::BluetoothStatus::SUCCESS; | 808 mojom::BluetoothStatus status = mojom::BluetoothStatus::SUCCESS; |
| 811 | 809 |
| 812 if (!device) { | 810 if (!device) { |
| 813 VLOG(1) << __func__ << ": device " << addr_str << " not available"; | 811 VLOG(1) << __func__ << ": device " << addr_str << " not available"; |
| 814 status = mojom::BluetoothStatus::FAIL; | 812 status = mojom::BluetoothStatus::FAIL; |
| 815 } | 813 } |
| 816 | 814 |
| 817 bluetooth_instance->OnRemoteDeviceProperties(status, std::move(remote_addr), | 815 bluetooth_instance->OnRemoteDeviceProperties(status, std::move(remote_addr), |
| 818 std::move(properties)); | 816 std::move(properties)); |
| 819 } | 817 } |
| 820 | 818 |
| 821 void ArcBluetoothBridge::SetRemoteDeviceProperty( | 819 void ArcBluetoothBridge::SetRemoteDeviceProperty( |
| 822 mojom::BluetoothAddressPtr remote_addr, | 820 mojom::BluetoothAddressPtr remote_addr, |
| 823 mojom::BluetoothPropertyPtr property) { | 821 mojom::BluetoothPropertyPtr property) { |
| 824 DCHECK(bluetooth_adapter_); | 822 DCHECK(bluetooth_adapter_); |
| 825 auto* bluetooth_instance = | 823 auto* bluetooth_instance = |
| 826 arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 824 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 827 "OnRemoteDeviceProperties"); | 825 "OnRemoteDeviceProperties"); |
| 828 if (!bluetooth_instance) | 826 if (!bluetooth_instance) |
| 829 return; | 827 return; |
| 830 | 828 |
| 831 // Unsupported. Only used by Android hidden API, BluetoothDevice.SetAlias(). | 829 // Unsupported. Only used by Android hidden API, BluetoothDevice.SetAlias(). |
| 832 // And only Android Settings App / Android TV / NFC used that. | 830 // And only Android Settings App / Android TV / NFC used that. |
| 833 bluetooth_instance->OnRemoteDeviceProperties( | 831 bluetooth_instance->OnRemoteDeviceProperties( |
| 834 mojom::BluetoothStatus::UNSUPPORTED, std::move(remote_addr), | 832 mojom::BluetoothStatus::UNSUPPORTED, std::move(remote_addr), |
| 835 mojo::Array<mojom::BluetoothPropertyPtr>::New(0)); | 833 std::vector<mojom::BluetoothPropertyPtr>()); |
| 836 } | 834 } |
| 837 | 835 |
| 838 void ArcBluetoothBridge::GetRemoteServiceRecord( | 836 void ArcBluetoothBridge::GetRemoteServiceRecord( |
| 839 mojom::BluetoothAddressPtr remote_addr, | 837 mojom::BluetoothAddressPtr remote_addr, |
| 840 const BluetoothUUID& uuid) { | 838 const BluetoothUUID& uuid) { |
| 841 // TODO(smbarber): Implement GetRemoteServiceRecord | 839 // TODO(smbarber): Implement GetRemoteServiceRecord |
| 842 } | 840 } |
| 843 | 841 |
| 844 void ArcBluetoothBridge::GetRemoteServices( | 842 void ArcBluetoothBridge::GetRemoteServices( |
| 845 mojom::BluetoothAddressPtr remote_addr) { | 843 mojom::BluetoothAddressPtr remote_addr) { |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1209 | 1207 |
| 1210 void ArcBluetoothBridge::GetGattDB(mojom::BluetoothAddressPtr remote_addr) { | 1208 void ArcBluetoothBridge::GetGattDB(mojom::BluetoothAddressPtr remote_addr) { |
| 1211 auto* bluetooth_instance = | 1209 auto* bluetooth_instance = |
| 1212 arc_bridge_service()->bluetooth()->GetInstanceForMethod("OnGetGattDB", | 1210 arc_bridge_service()->bluetooth()->GetInstanceForMethod("OnGetGattDB", |
| 1213 kMinBtleVersion); | 1211 kMinBtleVersion); |
| 1214 if (!bluetooth_instance) | 1212 if (!bluetooth_instance) |
| 1215 return; | 1213 return; |
| 1216 | 1214 |
| 1217 BluetoothDevice* device = | 1215 BluetoothDevice* device = |
| 1218 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); | 1216 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); |
| 1219 mojo::Array<mojom::BluetoothGattDBElementPtr> db; | 1217 std::vector<mojom::BluetoothGattDBElementPtr> db; |
| 1220 for (auto* service : device->GetGattServices()) { | 1218 for (auto* service : device->GetGattServices()) { |
| 1221 mojom::BluetoothGattDBElementPtr service_element = CreateGattDBElement( | 1219 mojom::BluetoothGattDBElementPtr service_element = CreateGattDBElement( |
| 1222 service->IsPrimary() | 1220 service->IsPrimary() |
| 1223 ? mojom::BluetoothGattDBAttributeType::BTGATT_DB_PRIMARY_SERVICE | 1221 ? mojom::BluetoothGattDBAttributeType::BTGATT_DB_PRIMARY_SERVICE |
| 1224 : mojom::BluetoothGattDBAttributeType::BTGATT_DB_SECONDARY_SERVICE, | 1222 : mojom::BluetoothGattDBAttributeType::BTGATT_DB_SECONDARY_SERVICE, |
| 1225 service); | 1223 service); |
| 1226 | 1224 |
| 1227 const auto& characteristics = service->GetCharacteristics(); | 1225 const auto& characteristics = service->GetCharacteristics(); |
| 1228 if (characteristics.size() > 0) { | 1226 if (characteristics.size() > 0) { |
| 1229 const auto& descriptors = characteristics.back()->GetDescriptors(); | 1227 const auto& descriptors = characteristics.back()->GetDescriptors(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1309 mojom::BluetoothGattServiceIDPtr service_id, | 1307 mojom::BluetoothGattServiceIDPtr service_id, |
| 1310 mojom::BluetoothGattIDPtr char_id, | 1308 mojom::BluetoothGattIDPtr char_id, |
| 1311 mojom::BluetoothGattValuePtr value, | 1309 mojom::BluetoothGattValuePtr value, |
| 1312 const WriteGattCharacteristicCallback& callback) { | 1310 const WriteGattCharacteristicCallback& callback) { |
| 1313 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic( | 1311 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic( |
| 1314 std::move(remote_addr), std::move(service_id), std::move(char_id)); | 1312 std::move(remote_addr), std::move(service_id), std::move(char_id)); |
| 1315 DCHECK(characteristic); | 1313 DCHECK(characteristic); |
| 1316 DCHECK(characteristic->GetPermissions() & kGattWritePermission); | 1314 DCHECK(characteristic->GetPermissions() & kGattWritePermission); |
| 1317 | 1315 |
| 1318 characteristic->WriteRemoteCharacteristic( | 1316 characteristic->WriteRemoteCharacteristic( |
| 1319 value->value.To<std::vector<uint8_t>>(), | 1317 value->value, base::Bind(&OnGattOperationDone, callback), |
| 1320 base::Bind(&OnGattOperationDone, callback), | |
| 1321 base::Bind(&OnGattOperationError, callback)); | 1318 base::Bind(&OnGattOperationError, callback)); |
| 1322 } | 1319 } |
| 1323 | 1320 |
| 1324 void ArcBluetoothBridge::ReadGattDescriptor( | 1321 void ArcBluetoothBridge::ReadGattDescriptor( |
| 1325 mojom::BluetoothAddressPtr remote_addr, | 1322 mojom::BluetoothAddressPtr remote_addr, |
| 1326 mojom::BluetoothGattServiceIDPtr service_id, | 1323 mojom::BluetoothGattServiceIDPtr service_id, |
| 1327 mojom::BluetoothGattIDPtr char_id, | 1324 mojom::BluetoothGattIDPtr char_id, |
| 1328 mojom::BluetoothGattIDPtr desc_id, | 1325 mojom::BluetoothGattIDPtr desc_id, |
| 1329 const ReadGattDescriptorCallback& callback) { | 1326 const ReadGattDescriptorCallback& callback) { |
| 1330 BluetoothRemoteGattDescriptor* descriptor = | 1327 BluetoothRemoteGattDescriptor* descriptor = |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1357 // directly to the CCC Descriptor. Therefore, until we fix | 1354 // directly to the CCC Descriptor. Therefore, until we fix |
| 1358 // https://crbug.com/622832, we return successfully when we encounter this. | 1355 // https://crbug.com/622832, we return successfully when we encounter this. |
| 1359 // TODO(http://crbug.com/622832) | 1356 // TODO(http://crbug.com/622832) |
| 1360 if (descriptor->GetUUID() == | 1357 if (descriptor->GetUUID() == |
| 1361 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid()) { | 1358 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid()) { |
| 1362 OnGattOperationDone(callback); | 1359 OnGattOperationDone(callback); |
| 1363 return; | 1360 return; |
| 1364 } | 1361 } |
| 1365 | 1362 |
| 1366 descriptor->WriteRemoteDescriptor( | 1363 descriptor->WriteRemoteDescriptor( |
| 1367 value->value.To<std::vector<uint8_t>>(), | 1364 value->value, base::Bind(&OnGattOperationDone, callback), |
| 1368 base::Bind(&OnGattOperationDone, callback), | |
| 1369 base::Bind(&OnGattOperationError, callback)); | 1365 base::Bind(&OnGattOperationError, callback)); |
| 1370 } | 1366 } |
| 1371 | 1367 |
| 1372 void ArcBluetoothBridge::OnGattNotifyStartDone( | 1368 void ArcBluetoothBridge::OnGattNotifyStartDone( |
| 1373 const RegisterForGattNotificationCallback& callback, | 1369 const RegisterForGattNotificationCallback& callback, |
| 1374 const std::string char_string_id, | 1370 const std::string char_string_id, |
| 1375 std::unique_ptr<BluetoothGattNotifySession> notify_session) { | 1371 std::unique_ptr<BluetoothGattNotifySession> notify_session) { |
| 1376 DCHECK(CalledOnValidThread()); | 1372 DCHECK(CalledOnValidThread()); |
| 1377 notification_session_[char_string_id] = std::move(notify_session); | 1373 notification_session_[char_string_id] = std::move(notify_session); |
| 1378 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS); | 1374 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1588 gatt_identifier_.erase(service_handle); | 1584 gatt_identifier_.erase(service_handle); |
| 1589 gatt_handle_.erase(service->GetIdentifier()); | 1585 gatt_handle_.erase(service->GetIdentifier()); |
| 1590 service->Delete(); | 1586 service->Delete(); |
| 1591 OnGattOperationDone(callback); | 1587 OnGattOperationDone(callback); |
| 1592 } | 1588 } |
| 1593 | 1589 |
| 1594 void ArcBluetoothBridge::SendIndication( | 1590 void ArcBluetoothBridge::SendIndication( |
| 1595 int32_t attribute_handle, | 1591 int32_t attribute_handle, |
| 1596 mojom::BluetoothAddressPtr address, | 1592 mojom::BluetoothAddressPtr address, |
| 1597 bool confirm, | 1593 bool confirm, |
| 1598 mojo::Array<uint8_t> value, | 1594 const std::vector<uint8_t>& value, |
| 1599 const SendIndicationCallback& callback) {} | 1595 const SendIndicationCallback& callback) {} |
| 1600 | 1596 |
| 1601 void ArcBluetoothBridge::GetSdpRecords(mojom::BluetoothAddressPtr remote_addr, | 1597 void ArcBluetoothBridge::GetSdpRecords(mojom::BluetoothAddressPtr remote_addr, |
| 1602 const BluetoothUUID& target_uuid) { | 1598 const BluetoothUUID& target_uuid) { |
| 1603 BluetoothDevice* device = | 1599 BluetoothDevice* device = |
| 1604 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); | 1600 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); |
| 1605 | 1601 |
| 1606 bluez::BluetoothDeviceBlueZ* device_bluez = | 1602 bluez::BluetoothDeviceBlueZ* device_bluez = |
| 1607 static_cast<bluez::BluetoothDeviceBlueZ*>(device); | 1603 static_cast<bluez::BluetoothDeviceBlueZ*>(device); |
| 1608 | 1604 |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1837 BluetoothDevice* device = | 1833 BluetoothDevice* device = |
| 1838 bluetooth_adapter_->GetDevice(addr->To<std::string>()); | 1834 bluetooth_adapter_->GetDevice(addr->To<std::string>()); |
| 1839 mojom::BluetoothBondState bond_state = mojom::BluetoothBondState::NONE; | 1835 mojom::BluetoothBondState bond_state = mojom::BluetoothBondState::NONE; |
| 1840 if (device && device->IsPaired()) { | 1836 if (device && device->IsPaired()) { |
| 1841 bond_state = mojom::BluetoothBondState::BONDED; | 1837 bond_state = mojom::BluetoothBondState::BONDED; |
| 1842 } | 1838 } |
| 1843 bluetooth_instance->OnBondStateChanged(mojom::BluetoothStatus::FAIL, | 1839 bluetooth_instance->OnBondStateChanged(mojom::BluetoothStatus::FAIL, |
| 1844 std::move(addr), bond_state); | 1840 std::move(addr), bond_state); |
| 1845 } | 1841 } |
| 1846 | 1842 |
| 1847 mojo::Array<mojom::BluetoothPropertyPtr> | 1843 std::vector<mojom::BluetoothPropertyPtr> |
| 1848 ArcBluetoothBridge::GetDeviceProperties(mojom::BluetoothPropertyType type, | 1844 ArcBluetoothBridge::GetDeviceProperties(mojom::BluetoothPropertyType type, |
| 1849 const BluetoothDevice* device) const { | 1845 const BluetoothDevice* device) const { |
| 1850 mojo::Array<mojom::BluetoothPropertyPtr> properties; | 1846 std::vector<mojom::BluetoothPropertyPtr> properties; |
| 1851 | 1847 |
| 1852 if (!device) { | 1848 if (!device) { |
| 1853 return properties; | 1849 return properties; |
| 1854 } | 1850 } |
| 1855 | 1851 |
| 1856 if (type == mojom::BluetoothPropertyType::ALL || | 1852 if (type == mojom::BluetoothPropertyType::ALL || |
| 1857 type == mojom::BluetoothPropertyType::BDNAME) { | 1853 type == mojom::BluetoothPropertyType::BDNAME) { |
| 1858 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); | 1854 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 1859 btp->set_bdname(device->GetName() ? device->GetName().value() : ""); | 1855 btp->set_bdname(device->GetName() ? device->GetName().value() : ""); |
| 1860 properties.push_back(std::move(btp)); | 1856 properties.push_back(std::move(btp)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1883 if (type == mojom::BluetoothPropertyType::ALL || | 1879 if (type == mojom::BluetoothPropertyType::ALL || |
| 1884 type == mojom::BluetoothPropertyType::TYPE_OF_DEVICE) { | 1880 type == mojom::BluetoothPropertyType::TYPE_OF_DEVICE) { |
| 1885 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); | 1881 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 1886 btp->set_device_type(device->GetType()); | 1882 btp->set_device_type(device->GetType()); |
| 1887 properties.push_back(std::move(btp)); | 1883 properties.push_back(std::move(btp)); |
| 1888 } | 1884 } |
| 1889 if (type == mojom::BluetoothPropertyType::ALL || | 1885 if (type == mojom::BluetoothPropertyType::ALL || |
| 1890 type == mojom::BluetoothPropertyType::REMOTE_FRIENDLY_NAME) { | 1886 type == mojom::BluetoothPropertyType::REMOTE_FRIENDLY_NAME) { |
| 1891 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); | 1887 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 1892 btp->set_remote_friendly_name( | 1888 btp->set_remote_friendly_name( |
| 1893 mojo::String::From(base::UTF16ToUTF8(device->GetNameForDisplay()))); | 1889 base::UTF16ToUTF8(device->GetNameForDisplay())); |
| 1894 properties.push_back(std::move(btp)); | 1890 properties.push_back(std::move(btp)); |
| 1895 } | 1891 } |
| 1896 if (type == mojom::BluetoothPropertyType::ALL || | 1892 if (type == mojom::BluetoothPropertyType::ALL || |
| 1897 type == mojom::BluetoothPropertyType::REMOTE_RSSI) { | 1893 type == mojom::BluetoothPropertyType::REMOTE_RSSI) { |
| 1898 base::Optional<int8_t> rssi = device->GetInquiryRSSI(); | 1894 base::Optional<int8_t> rssi = device->GetInquiryRSSI(); |
| 1899 if (rssi.has_value()) { | 1895 if (rssi.has_value()) { |
| 1900 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); | 1896 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 1901 btp->set_remote_rssi(rssi.value()); | 1897 btp->set_remote_rssi(rssi.value()); |
| 1902 properties.push_back(std::move(btp)); | 1898 properties.push_back(std::move(btp)); |
| 1903 } | 1899 } |
| 1904 } | 1900 } |
| 1905 // TODO(smbarber): Add remote version info | 1901 // TODO(smbarber): Add remote version info |
| 1906 | 1902 |
| 1907 return properties; | 1903 return properties; |
| 1908 } | 1904 } |
| 1909 | 1905 |
| 1910 mojo::Array<mojom::BluetoothPropertyPtr> | 1906 std::vector<mojom::BluetoothPropertyPtr> |
| 1911 ArcBluetoothBridge::GetAdapterProperties( | 1907 ArcBluetoothBridge::GetAdapterProperties( |
| 1912 mojom::BluetoothPropertyType type) const { | 1908 mojom::BluetoothPropertyType type) const { |
| 1913 mojo::Array<mojom::BluetoothPropertyPtr> properties; | 1909 std::vector<mojom::BluetoothPropertyPtr> properties; |
| 1914 | 1910 |
| 1915 if (type == mojom::BluetoothPropertyType::ALL || | 1911 if (type == mojom::BluetoothPropertyType::ALL || |
| 1916 type == mojom::BluetoothPropertyType::BDNAME) { | 1912 type == mojom::BluetoothPropertyType::BDNAME) { |
| 1917 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); | 1913 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 1918 std::string name = bluetooth_adapter_->GetName(); | 1914 std::string name = bluetooth_adapter_->GetName(); |
| 1919 btp->set_bdname(mojo::String(name)); | 1915 btp->set_bdname(name); |
| 1920 properties.push_back(std::move(btp)); | 1916 properties.push_back(std::move(btp)); |
| 1921 } | 1917 } |
| 1922 if (type == mojom::BluetoothPropertyType::ALL || | 1918 if (type == mojom::BluetoothPropertyType::ALL || |
| 1923 type == mojom::BluetoothPropertyType::BDADDR) { | 1919 type == mojom::BluetoothPropertyType::BDADDR) { |
| 1924 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); | 1920 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 1925 btp->set_bdaddr( | 1921 btp->set_bdaddr( |
| 1926 mojom::BluetoothAddress::From(bluetooth_adapter_->GetAddress())); | 1922 mojom::BluetoothAddress::From(bluetooth_adapter_->GetAddress())); |
| 1927 properties.push_back(std::move(btp)); | 1923 properties.push_back(std::move(btp)); |
| 1928 } | 1924 } |
| 1929 if (type == mojom::BluetoothPropertyType::ALL || | 1925 if (type == mojom::BluetoothPropertyType::ALL || |
| 1930 type == mojom::BluetoothPropertyType::UUIDS) { | 1926 type == mojom::BluetoothPropertyType::UUIDS) { |
| 1931 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); | 1927 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 1932 btp->set_uuids( | 1928 btp->set_uuids(bluetooth_adapter_->GetUUIDs()); |
| 1933 mojo::Array<BluetoothUUID>::From(bluetooth_adapter_->GetUUIDs())); | |
| 1934 properties.push_back(std::move(btp)); | 1929 properties.push_back(std::move(btp)); |
| 1935 } | 1930 } |
| 1936 if (type == mojom::BluetoothPropertyType::ALL || | 1931 if (type == mojom::BluetoothPropertyType::ALL || |
| 1937 type == mojom::BluetoothPropertyType::CLASS_OF_DEVICE) { | 1932 type == mojom::BluetoothPropertyType::CLASS_OF_DEVICE) { |
| 1938 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); | 1933 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 1939 btp->set_device_class(kBluetoothComputerClass); | 1934 btp->set_device_class(kBluetoothComputerClass); |
| 1940 properties.push_back(std::move(btp)); | 1935 properties.push_back(std::move(btp)); |
| 1941 } | 1936 } |
| 1942 if (type == mojom::BluetoothPropertyType::ALL || | 1937 if (type == mojom::BluetoothPropertyType::ALL || |
| 1943 type == mojom::BluetoothPropertyType::TYPE_OF_DEVICE) { | 1938 type == mojom::BluetoothPropertyType::TYPE_OF_DEVICE) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1955 scan_mode = mojom::BluetoothScanMode::CONNECTABLE_DISCOVERABLE; | 1950 scan_mode = mojom::BluetoothScanMode::CONNECTABLE_DISCOVERABLE; |
| 1956 | 1951 |
| 1957 btp->set_adapter_scan_mode(scan_mode); | 1952 btp->set_adapter_scan_mode(scan_mode); |
| 1958 properties.push_back(std::move(btp)); | 1953 properties.push_back(std::move(btp)); |
| 1959 } | 1954 } |
| 1960 if (type == mojom::BluetoothPropertyType::ALL || | 1955 if (type == mojom::BluetoothPropertyType::ALL || |
| 1961 type == mojom::BluetoothPropertyType::ADAPTER_BONDED_DEVICES) { | 1956 type == mojom::BluetoothPropertyType::ADAPTER_BONDED_DEVICES) { |
| 1962 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); | 1957 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 1963 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); | 1958 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); |
| 1964 | 1959 |
| 1965 mojo::Array<mojom::BluetoothAddressPtr> bonded_devices = | 1960 std::vector<mojom::BluetoothAddressPtr> bonded_devices; |
| 1966 mojo::Array<mojom::BluetoothAddressPtr>::New(0); | |
| 1967 | 1961 |
| 1968 for (auto* device : devices) { | 1962 for (auto* device : devices) { |
| 1969 if (device->IsPaired()) | 1963 if (device->IsPaired()) |
| 1970 continue; | 1964 continue; |
| 1971 | 1965 |
| 1972 mojom::BluetoothAddressPtr addr = | 1966 mojom::BluetoothAddressPtr addr = |
| 1973 mojom::BluetoothAddress::From(device->GetAddress()); | 1967 mojom::BluetoothAddress::From(device->GetAddress()); |
| 1974 bonded_devices.push_back(std::move(addr)); | 1968 bonded_devices.push_back(std::move(addr)); |
| 1975 } | 1969 } |
| 1976 | 1970 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2004 properties.push_back(std::move(btp)); | 1998 properties.push_back(std::move(btp)); |
| 2005 } | 1999 } |
| 2006 | 2000 |
| 2007 return properties; | 2001 return properties; |
| 2008 } | 2002 } |
| 2009 | 2003 |
| 2010 // Android support 6 types of Advertising Data which are Advertising Data Flags, | 2004 // Android support 6 types of Advertising Data which are Advertising Data Flags, |
| 2011 // Local Name, Service UUIDs, Tx Power Level, Service Data, and Manufacturer | 2005 // Local Name, Service UUIDs, Tx Power Level, Service Data, and Manufacturer |
| 2012 // Data. Note that we need to use 16-bit UUID in Service Data section because | 2006 // Data. Note that we need to use 16-bit UUID in Service Data section because |
| 2013 // Android does not support 128-bit UUID there. | 2007 // Android does not support 128-bit UUID there. |
| 2014 mojo::Array<mojom::BluetoothAdvertisingDataPtr> | 2008 std::vector<mojom::BluetoothAdvertisingDataPtr> |
| 2015 ArcBluetoothBridge::GetAdvertisingData(const BluetoothDevice* device) const { | 2009 ArcBluetoothBridge::GetAdvertisingData(const BluetoothDevice* device) const { |
| 2016 mojo::Array<mojom::BluetoothAdvertisingDataPtr> advertising_data; | 2010 std::vector<mojom::BluetoothAdvertisingDataPtr> advertising_data; |
| 2017 | 2011 |
| 2018 // Advertising Data Flags | 2012 // Advertising Data Flags |
| 2019 if (device->GetAdvertisingDataFlags().has_value()) { | 2013 if (device->GetAdvertisingDataFlags().has_value()) { |
| 2020 mojom::BluetoothAdvertisingDataPtr flags = | 2014 mojom::BluetoothAdvertisingDataPtr flags = |
| 2021 mojom::BluetoothAdvertisingData::New(); | 2015 mojom::BluetoothAdvertisingData::New(); |
| 2022 flags->set_flags(device->GetAdvertisingDataFlags().value()); | 2016 flags->set_flags(device->GetAdvertisingDataFlags().value()); |
| 2023 advertising_data.push_back(std::move(flags)); | 2017 advertising_data.push_back(std::move(flags)); |
| 2024 } | 2018 } |
| 2025 | 2019 |
| 2026 // Local Name | 2020 // Local Name |
| 2027 mojom::BluetoothAdvertisingDataPtr local_name = | 2021 mojom::BluetoothAdvertisingDataPtr local_name = |
| 2028 mojom::BluetoothAdvertisingData::New(); | 2022 mojom::BluetoothAdvertisingData::New(); |
| 2029 local_name->set_local_name(device->GetName() ? device->GetName().value() | 2023 local_name->set_local_name(device->GetName() ? device->GetName().value() |
| 2030 : ""); | 2024 : ""); |
| 2031 advertising_data.push_back(std::move(local_name)); | 2025 advertising_data.push_back(std::move(local_name)); |
| 2032 | 2026 |
| 2033 // Service UUIDs | 2027 // Service UUIDs |
| 2034 const BluetoothDevice::UUIDSet& uuid_set = device->GetUUIDs(); | 2028 const BluetoothDevice::UUIDSet& uuid_set = device->GetUUIDs(); |
| 2035 if (uuid_set.size() > 0) { | 2029 if (uuid_set.size() > 0) { |
| 2036 mojom::BluetoothAdvertisingDataPtr service_uuids = | 2030 mojom::BluetoothAdvertisingDataPtr service_uuids = |
| 2037 mojom::BluetoothAdvertisingData::New(); | 2031 mojom::BluetoothAdvertisingData::New(); |
| 2038 service_uuids->set_service_uuids(mojo::Array<BluetoothUUID>::From( | 2032 service_uuids->set_service_uuids( |
| 2039 std::vector<BluetoothUUID>(uuid_set.begin(), uuid_set.end()))); | 2033 std::vector<BluetoothUUID>(uuid_set.begin(), uuid_set.end())); |
| 2040 advertising_data.push_back(std::move(service_uuids)); | 2034 advertising_data.push_back(std::move(service_uuids)); |
| 2041 } | 2035 } |
| 2042 | 2036 |
| 2043 // Tx Power Level | 2037 // Tx Power Level |
| 2044 if (device->GetInquiryTxPower().has_value()) { | 2038 if (device->GetInquiryTxPower().has_value()) { |
| 2045 mojom::BluetoothAdvertisingDataPtr tx_power_level_element = | 2039 mojom::BluetoothAdvertisingDataPtr tx_power_level_element = |
| 2046 mojom::BluetoothAdvertisingData::New(); | 2040 mojom::BluetoothAdvertisingData::New(); |
| 2047 tx_power_level_element->set_tx_power_level( | 2041 tx_power_level_element->set_tx_power_level( |
| 2048 device->GetInquiryTxPower().value()); | 2042 device->GetInquiryTxPower().value()); |
| 2049 advertising_data.push_back(std::move(tx_power_level_element)); | 2043 advertising_data.push_back(std::move(tx_power_level_element)); |
| 2050 } | 2044 } |
| 2051 | 2045 |
| 2052 // Service Data | 2046 // Service Data |
| 2053 for (const BluetoothUUID& uuid : device->GetServiceDataUUIDs()) { | 2047 for (const BluetoothUUID& uuid : device->GetServiceDataUUIDs()) { |
| 2054 mojom::BluetoothAdvertisingDataPtr service_data_element = | 2048 mojom::BluetoothAdvertisingDataPtr service_data_element = |
| 2055 mojom::BluetoothAdvertisingData::New(); | 2049 mojom::BluetoothAdvertisingData::New(); |
| 2056 mojom::BluetoothServiceDataPtr service_data = | 2050 mojom::BluetoothServiceDataPtr service_data = |
| 2057 mojom::BluetoothServiceData::New(); | 2051 mojom::BluetoothServiceData::New(); |
| 2058 | 2052 |
| 2059 // Android only supports UUID 16 bit here. | 2053 // Android only supports UUID 16 bit here. |
| 2060 service_data->uuid_16bit = GetUUID16(uuid); | 2054 service_data->uuid_16bit = GetUUID16(uuid); |
| 2061 | 2055 |
| 2062 const std::vector<uint8_t>* data = device->GetServiceDataForUUID(uuid); | 2056 const std::vector<uint8_t>* data = device->GetServiceDataForUUID(uuid); |
| 2063 DCHECK(data != nullptr); | 2057 DCHECK(data != nullptr); |
| 2064 | 2058 |
| 2065 std::vector<uint8_t> data_copy = *data; | 2059 service_data->data = *data; |
| 2066 service_data->data.Swap(&data_copy); | |
| 2067 | 2060 |
| 2068 service_data_element->set_service_data(std::move(service_data)); | 2061 service_data_element->set_service_data(std::move(service_data)); |
| 2069 advertising_data.push_back(std::move(service_data_element)); | 2062 advertising_data.push_back(std::move(service_data_element)); |
| 2070 } | 2063 } |
| 2071 | 2064 |
| 2072 // Manufacturer Data | 2065 // Manufacturer Data |
| 2073 if (!device->GetManufacturerData().empty()) { | 2066 if (!device->GetManufacturerData().empty()) { |
| 2074 std::vector<uint8_t> manufacturer_data; | 2067 std::vector<uint8_t> manufacturer_data; |
| 2075 for (const auto& pair : device->GetManufacturerData()) { | 2068 for (const auto& pair : device->GetManufacturerData()) { |
| 2076 uint16_t id = pair.first; | 2069 uint16_t id = pair.first; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2126 void ArcBluetoothBridge::OnGetServiceRecordsDone( | 2119 void ArcBluetoothBridge::OnGetServiceRecordsDone( |
| 2127 mojom::BluetoothAddressPtr remote_addr, | 2120 mojom::BluetoothAddressPtr remote_addr, |
| 2128 const BluetoothUUID& target_uuid, | 2121 const BluetoothUUID& target_uuid, |
| 2129 const std::vector<bluez::BluetoothServiceRecordBlueZ>& records_bluez) { | 2122 const std::vector<bluez::BluetoothServiceRecordBlueZ>& records_bluez) { |
| 2130 auto* sdp_bluetooth_instance = | 2123 auto* sdp_bluetooth_instance = |
| 2131 arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 2124 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 2132 "OnGetSdpRecords", kMinSdpSupportVersion); | 2125 "OnGetSdpRecords", kMinSdpSupportVersion); |
| 2133 if (!sdp_bluetooth_instance) | 2126 if (!sdp_bluetooth_instance) |
| 2134 return; | 2127 return; |
| 2135 | 2128 |
| 2136 sdp_bluetooth_instance->OnGetSdpRecords( | 2129 std::vector<mojom::BluetoothSdpRecordPtr> records; |
| 2137 mojom::BluetoothStatus::SUCCESS, std::move(remote_addr), target_uuid, | 2130 for (const auto& r : records_bluez) |
| 2138 mojo::Array<mojom::BluetoothSdpRecordPtr>::From(records_bluez)); | 2131 records.push_back(mojom::BluetoothSdpRecord::From(r)); |
| 2132 |
| 2133 sdp_bluetooth_instance->OnGetSdpRecords(mojom::BluetoothStatus::SUCCESS, |
| 2134 std::move(remote_addr), target_uuid, |
| 2135 std::move(records)); |
| 2139 } | 2136 } |
| 2140 | 2137 |
| 2141 void ArcBluetoothBridge::OnGetServiceRecordsError( | 2138 void ArcBluetoothBridge::OnGetServiceRecordsError( |
| 2142 mojom::BluetoothAddressPtr remote_addr, | 2139 mojom::BluetoothAddressPtr remote_addr, |
| 2143 const BluetoothUUID& target_uuid, | 2140 const BluetoothUUID& target_uuid, |
| 2144 bluez::BluetoothServiceRecordBlueZ::ErrorCode error_code) { | 2141 bluez::BluetoothServiceRecordBlueZ::ErrorCode error_code) { |
| 2145 auto* sdp_bluetooth_instance = | 2142 auto* sdp_bluetooth_instance = |
| 2146 arc_bridge_service()->bluetooth()->GetInstanceForMethod( | 2143 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 2147 "OnGetSdpRecords", kMinSdpSupportVersion); | 2144 "OnGetSdpRecords", kMinSdpSupportVersion); |
| 2148 if (!sdp_bluetooth_instance) | 2145 if (!sdp_bluetooth_instance) |
| 2149 return; | 2146 return; |
| 2150 | 2147 |
| 2151 mojom::BluetoothStatus status; | 2148 mojom::BluetoothStatus status; |
| 2152 | 2149 |
| 2153 switch (error_code) { | 2150 switch (error_code) { |
| 2154 case bluez::BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY: | 2151 case bluez::BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY: |
| 2155 status = mojom::BluetoothStatus::NOT_READY; | 2152 status = mojom::BluetoothStatus::NOT_READY; |
| 2156 break; | 2153 break; |
| 2157 case bluez::BluetoothServiceRecordBlueZ::ErrorCode:: | 2154 case bluez::BluetoothServiceRecordBlueZ::ErrorCode:: |
| 2158 ERROR_DEVICE_DISCONNECTED: | 2155 ERROR_DEVICE_DISCONNECTED: |
| 2159 status = mojom::BluetoothStatus::RMT_DEV_DOWN; | 2156 status = mojom::BluetoothStatus::RMT_DEV_DOWN; |
| 2160 break; | 2157 break; |
| 2161 default: | 2158 default: |
| 2162 status = mojom::BluetoothStatus::FAIL; | 2159 status = mojom::BluetoothStatus::FAIL; |
| 2163 break; | 2160 break; |
| 2164 } | 2161 } |
| 2165 | 2162 |
| 2166 sdp_bluetooth_instance->OnGetSdpRecords( | 2163 sdp_bluetooth_instance->OnGetSdpRecords( |
| 2167 status, std::move(remote_addr), target_uuid, | 2164 status, std::move(remote_addr), target_uuid, |
| 2168 mojo::Array<mojom::BluetoothSdpRecordPtr>::New(0)); | 2165 std::vector<mojom::BluetoothSdpRecordPtr>()); |
| 2169 } | 2166 } |
| 2170 | 2167 |
| 2171 bool ArcBluetoothBridge::CalledOnValidThread() { | 2168 bool ArcBluetoothBridge::CalledOnValidThread() { |
| 2172 return thread_checker_.CalledOnValidThread(); | 2169 return thread_checker_.CalledOnValidThread(); |
| 2173 } | 2170 } |
| 2174 | 2171 |
| 2175 } // namespace arc | 2172 } // namespace arc |
| OLD | NEW |