| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/arc/bluetooth/arc_bluetooth_bridge.h" | 5 #include "components/arc/bluetooth/arc_bluetooth_bridge.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <iomanip> | 10 #include <iomanip> |
| (...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 return element; | 727 return element; |
| 728 } | 728 } |
| 729 | 729 |
| 730 void ArcBluetoothBridge::GetGattDB(mojom::BluetoothAddressPtr remote_addr) { | 730 void ArcBluetoothBridge::GetGattDB(mojom::BluetoothAddressPtr remote_addr) { |
| 731 if (!HasBluetoothInstance()) | 731 if (!HasBluetoothInstance()) |
| 732 return; | 732 return; |
| 733 | 733 |
| 734 BluetoothDevice* device = | 734 BluetoothDevice* device = |
| 735 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); | 735 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); |
| 736 mojo::Array<mojom::BluetoothGattDBElementPtr> db; | 736 mojo::Array<mojom::BluetoothGattDBElementPtr> db; |
| 737 for (auto service : device->GetGattServices()) { | 737 for (auto* service : device->GetGattServices()) { |
| 738 mojom::BluetoothGattDBElementPtr service_element = CreateGattDBElement< | 738 mojom::BluetoothGattDBElementPtr service_element = CreateGattDBElement< |
| 739 device::BluetoothRemoteGattService>( | 739 device::BluetoothRemoteGattService>( |
| 740 service->IsPrimary() | 740 service->IsPrimary() |
| 741 ? mojom::BluetoothGattDBAttributeType::BTGATT_DB_PRIMARY_SERVICE | 741 ? mojom::BluetoothGattDBAttributeType::BTGATT_DB_PRIMARY_SERVICE |
| 742 : mojom::BluetoothGattDBAttributeType::BTGATT_DB_SECONDARY_SERVICE, | 742 : mojom::BluetoothGattDBAttributeType::BTGATT_DB_SECONDARY_SERVICE, |
| 743 service); | 743 service); |
| 744 | 744 |
| 745 const auto& characteristics = service->GetCharacteristics(); | 745 const auto& characteristics = service->GetCharacteristics(); |
| 746 if (characteristics.size() > 0) { | 746 if (characteristics.size() > 0) { |
| 747 const auto& descriptors = characteristics.back()->GetDescriptors(); | 747 const auto& descriptors = characteristics.back()->GetDescriptors(); |
| 748 service_element->start_handle = | 748 service_element->start_handle = |
| 749 ConvertGattIdentifierToId(characteristics.front()->GetIdentifier()); | 749 ConvertGattIdentifierToId(characteristics.front()->GetIdentifier()); |
| 750 service_element->end_handle = ConvertGattIdentifierToId( | 750 service_element->end_handle = ConvertGattIdentifierToId( |
| 751 descriptors.size() > 0 ? descriptors.back()->GetIdentifier() | 751 descriptors.size() > 0 ? descriptors.back()->GetIdentifier() |
| 752 : characteristics.back()->GetIdentifier()); | 752 : characteristics.back()->GetIdentifier()); |
| 753 } | 753 } |
| 754 db.push_back(std::move(service_element)); | 754 db.push_back(std::move(service_element)); |
| 755 | 755 |
| 756 for (auto characteristic : characteristics) { | 756 for (auto* characteristic : characteristics) { |
| 757 mojom::BluetoothGattDBElementPtr characteristic_element = | 757 mojom::BluetoothGattDBElementPtr characteristic_element = |
| 758 CreateGattDBElement<device::BluetoothRemoteGattCharacteristic>( | 758 CreateGattDBElement<device::BluetoothRemoteGattCharacteristic>( |
| 759 mojom::BluetoothGattDBAttributeType::BTGATT_DB_CHARACTERISTIC, | 759 mojom::BluetoothGattDBAttributeType::BTGATT_DB_CHARACTERISTIC, |
| 760 characteristic); | 760 characteristic); |
| 761 characteristic_element->properties = characteristic->GetProperties(); | 761 characteristic_element->properties = characteristic->GetProperties(); |
| 762 db.push_back(std::move(characteristic_element)); | 762 db.push_back(std::move(characteristic_element)); |
| 763 | 763 |
| 764 for (auto descriptor : characteristic->GetDescriptors()) { | 764 for (auto* descriptor : characteristic->GetDescriptors()) { |
| 765 db.push_back(CreateGattDBElement<device::BluetoothRemoteGattDescriptor>( | 765 db.push_back(CreateGattDBElement<device::BluetoothRemoteGattDescriptor>( |
| 766 mojom::BluetoothGattDBAttributeType::BTGATT_DB_DESCRIPTOR, | 766 mojom::BluetoothGattDBAttributeType::BTGATT_DB_DESCRIPTOR, |
| 767 descriptor)); | 767 descriptor)); |
| 768 } | 768 } |
| 769 } | 769 } |
| 770 } | 770 } |
| 771 | 771 |
| 772 arc_bridge_service()->bluetooth()->instance()->OnGetGattDB( | 772 arc_bridge_service()->bluetooth()->instance()->OnGetGattDB( |
| 773 std::move(remote_addr), std::move(db)); | 773 std::move(remote_addr), std::move(db)); |
| 774 } | 774 } |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1196 properties.push_back(std::move(btp)); | 1196 properties.push_back(std::move(btp)); |
| 1197 } | 1197 } |
| 1198 if (type == mojom::BluetoothPropertyType::ALL || | 1198 if (type == mojom::BluetoothPropertyType::ALL || |
| 1199 type == mojom::BluetoothPropertyType::ADAPTER_BONDED_DEVICES) { | 1199 type == mojom::BluetoothPropertyType::ADAPTER_BONDED_DEVICES) { |
| 1200 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); | 1200 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 1201 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); | 1201 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); |
| 1202 | 1202 |
| 1203 mojo::Array<mojom::BluetoothAddressPtr> bonded_devices = | 1203 mojo::Array<mojom::BluetoothAddressPtr> bonded_devices = |
| 1204 mojo::Array<mojom::BluetoothAddressPtr>::New(0); | 1204 mojo::Array<mojom::BluetoothAddressPtr>::New(0); |
| 1205 | 1205 |
| 1206 for (auto device : devices) { | 1206 for (auto* device : devices) { |
| 1207 if (device->IsPaired()) | 1207 if (device->IsPaired()) |
| 1208 continue; | 1208 continue; |
| 1209 | 1209 |
| 1210 mojom::BluetoothAddressPtr addr = | 1210 mojom::BluetoothAddressPtr addr = |
| 1211 mojom::BluetoothAddress::From(device->GetAddress()); | 1211 mojom::BluetoothAddress::From(device->GetAddress()); |
| 1212 bonded_devices.push_back(std::move(addr)); | 1212 bonded_devices.push_back(std::move(addr)); |
| 1213 } | 1213 } |
| 1214 | 1214 |
| 1215 btp->set_bonded_devices(std::move(bonded_devices)); | 1215 btp->set_bonded_devices(std::move(bonded_devices)); |
| 1216 properties.push_back(std::move(btp)); | 1216 properties.push_back(std::move(btp)); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1275 | 1275 |
| 1276 return advertising_data; | 1276 return advertising_data; |
| 1277 } | 1277 } |
| 1278 | 1278 |
| 1279 void ArcBluetoothBridge::SendCachedDevicesFound() const { | 1279 void ArcBluetoothBridge::SendCachedDevicesFound() const { |
| 1280 // Send devices that have already been discovered, but aren't connected. | 1280 // Send devices that have already been discovered, but aren't connected. |
| 1281 if (!HasBluetoothInstance()) | 1281 if (!HasBluetoothInstance()) |
| 1282 return; | 1282 return; |
| 1283 | 1283 |
| 1284 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); | 1284 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); |
| 1285 for (auto device : devices) { | 1285 for (auto* device : devices) { |
| 1286 if (device->IsPaired()) | 1286 if (device->IsPaired()) |
| 1287 continue; | 1287 continue; |
| 1288 | 1288 |
| 1289 mojo::Array<mojom::BluetoothPropertyPtr> properties = | 1289 mojo::Array<mojom::BluetoothPropertyPtr> properties = |
| 1290 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); | 1290 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); |
| 1291 | 1291 |
| 1292 arc_bridge_service()->bluetooth()->instance()->OnDeviceFound( | 1292 arc_bridge_service()->bluetooth()->instance()->OnDeviceFound( |
| 1293 std::move(properties)); | 1293 std::move(properties)); |
| 1294 | 1294 |
| 1295 if (arc_bridge_service()->bluetooth()->version() >= kMinBtleVersion) { | 1295 if (arc_bridge_service()->bluetooth()->version() >= kMinBtleVersion) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1312 | 1312 |
| 1313 return true; | 1313 return true; |
| 1314 } | 1314 } |
| 1315 | 1315 |
| 1316 void ArcBluetoothBridge::SendCachedPairedDevices() const { | 1316 void ArcBluetoothBridge::SendCachedPairedDevices() const { |
| 1317 DCHECK(bluetooth_adapter_); | 1317 DCHECK(bluetooth_adapter_); |
| 1318 if (!HasBluetoothInstance()) | 1318 if (!HasBluetoothInstance()) |
| 1319 return; | 1319 return; |
| 1320 | 1320 |
| 1321 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); | 1321 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); |
| 1322 for (auto device : devices) { | 1322 for (auto* device : devices) { |
| 1323 if (!device->IsPaired()) | 1323 if (!device->IsPaired()) |
| 1324 continue; | 1324 continue; |
| 1325 | 1325 |
| 1326 mojo::Array<mojom::BluetoothPropertyPtr> properties = | 1326 mojo::Array<mojom::BluetoothPropertyPtr> properties = |
| 1327 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); | 1327 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); |
| 1328 | 1328 |
| 1329 arc_bridge_service()->bluetooth()->instance()->OnDeviceFound( | 1329 arc_bridge_service()->bluetooth()->instance()->OnDeviceFound( |
| 1330 std::move(properties)); | 1330 std::move(properties)); |
| 1331 | 1331 |
| 1332 mojom::BluetoothAddressPtr addr = | 1332 mojom::BluetoothAddressPtr addr = |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1354 uint32_t version_need) const { | 1354 uint32_t version_need) const { |
| 1355 uint32_t version = arc_bridge_service()->bluetooth()->version(); | 1355 uint32_t version = arc_bridge_service()->bluetooth()->version(); |
| 1356 if (version >= version_need) | 1356 if (version >= version_need) |
| 1357 return true; | 1357 return true; |
| 1358 LOG(WARNING) << "Bluetooth instance is too old (version " << version | 1358 LOG(WARNING) << "Bluetooth instance is too old (version " << version |
| 1359 << ") need version " << version_need; | 1359 << ") need version " << version_need; |
| 1360 return false; | 1360 return false; |
| 1361 } | 1361 } |
| 1362 | 1362 |
| 1363 } // namespace arc | 1363 } // namespace arc |
| OLD | NEW |