Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/arc/bluetooth/arc_bluetooth_bridge.h" | 5 #include "components/arc/bluetooth/arc_bluetooth_bridge.h" |
| 6 | 6 |
| 7 #include <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 10 matching lines...) Expand all Loading... | |
| 21 #include "base/threading/thread_task_runner_handle.h" | 21 #include "base/threading/thread_task_runner_handle.h" |
| 22 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 23 #include "components/arc/arc_bridge_service.h" | 23 #include "components/arc/arc_bridge_service.h" |
| 24 #include "components/arc/bluetooth/bluetooth_type_converters.h" | 24 #include "components/arc/bluetooth/bluetooth_type_converters.h" |
| 25 #include "device/bluetooth/bluetooth_common.h" | 25 #include "device/bluetooth/bluetooth_common.h" |
| 26 #include "device/bluetooth/bluetooth_device.h" | 26 #include "device/bluetooth/bluetooth_device.h" |
| 27 #include "device/bluetooth/bluetooth_gatt_connection.h" | 27 #include "device/bluetooth/bluetooth_gatt_connection.h" |
| 28 #include "device/bluetooth/bluetooth_gatt_notify_session.h" | 28 #include "device/bluetooth/bluetooth_gatt_notify_session.h" |
| 29 #include "device/bluetooth/bluetooth_local_gatt_characteristic.h" | 29 #include "device/bluetooth/bluetooth_local_gatt_characteristic.h" |
| 30 #include "device/bluetooth/bluetooth_local_gatt_descriptor.h" | 30 #include "device/bluetooth/bluetooth_local_gatt_descriptor.h" |
| 31 #include "device/bluetooth/bluez/bluetooth_device_bluez.h" | |
| 31 #include "mojo/edk/embedder/embedder.h" | 32 #include "mojo/edk/embedder/embedder.h" |
| 32 #include "mojo/edk/embedder/scoped_platform_handle.h" | 33 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 33 | 34 |
| 34 using device::BluetoothAdapter; | 35 using device::BluetoothAdapter; |
| 35 using device::BluetoothAdapterFactory; | 36 using device::BluetoothAdapterFactory; |
| 36 using device::BluetoothAdvertisement; | 37 using device::BluetoothAdvertisement; |
| 37 using device::BluetoothDevice; | 38 using device::BluetoothDevice; |
| 38 using device::BluetoothDiscoveryFilter; | 39 using device::BluetoothDiscoveryFilter; |
| 39 using device::BluetoothDiscoverySession; | 40 using device::BluetoothDiscoverySession; |
| 40 using device::BluetoothGattConnection; | 41 using device::BluetoothGattConnection; |
| 41 using device::BluetoothGattNotifySession; | 42 using device::BluetoothGattNotifySession; |
| 42 using device::BluetoothGattCharacteristic; | 43 using device::BluetoothGattCharacteristic; |
| 43 using device::BluetoothGattDescriptor; | 44 using device::BluetoothGattDescriptor; |
| 44 using device::BluetoothGattService; | 45 using device::BluetoothGattService; |
| 45 using device::BluetoothLocalGattCharacteristic; | 46 using device::BluetoothLocalGattCharacteristic; |
| 46 using device::BluetoothLocalGattDescriptor; | 47 using device::BluetoothLocalGattDescriptor; |
| 47 using device::BluetoothLocalGattService; | 48 using device::BluetoothLocalGattService; |
| 48 using device::BluetoothRemoteGattCharacteristic; | 49 using device::BluetoothRemoteGattCharacteristic; |
| 49 using device::BluetoothRemoteGattDescriptor; | 50 using device::BluetoothRemoteGattDescriptor; |
| 50 using device::BluetoothRemoteGattService; | 51 using device::BluetoothRemoteGattService; |
| 51 using device::BluetoothTransport; | 52 using device::BluetoothTransport; |
| 52 using device::BluetoothUUID; | 53 using device::BluetoothUUID; |
| 53 | 54 |
| 54 namespace { | 55 namespace { |
| 55 constexpr int32_t kMinBtleVersion = 1; | 56 constexpr int32_t kMinBtleVersion = 1; |
| 56 constexpr int32_t kMinBtleNotifyVersion = 2; | 57 constexpr int32_t kMinBtleNotifyVersion = 2; |
| 57 constexpr int32_t kMinGattServerVersion = 3; | 58 constexpr int32_t kMinGattServerVersion = 3; |
| 58 constexpr int32_t kMinAddrChangeVersion = 4; | 59 constexpr int32_t kMinAddrChangeVersion = 4; |
| 60 constexpr int32_t kMinSdpSupportVersion = 5; | |
| 59 constexpr uint32_t kGattReadPermission = | 61 constexpr uint32_t kGattReadPermission = |
| 60 BluetoothGattCharacteristic::Permission::PERMISSION_READ | | 62 BluetoothGattCharacteristic::Permission::PERMISSION_READ | |
| 61 BluetoothGattCharacteristic::Permission::PERMISSION_READ_ENCRYPTED | | 63 BluetoothGattCharacteristic::Permission::PERMISSION_READ_ENCRYPTED | |
| 62 BluetoothGattCharacteristic::Permission:: | 64 BluetoothGattCharacteristic::Permission:: |
| 63 PERMISSION_READ_ENCRYPTED_AUTHENTICATED; | 65 PERMISSION_READ_ENCRYPTED_AUTHENTICATED; |
| 64 constexpr uint32_t kGattWritePermission = | 66 constexpr uint32_t kGattWritePermission = |
| 65 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE | | 67 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE | |
| 66 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE_ENCRYPTED | | 68 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE_ENCRYPTED | |
| 67 BluetoothGattCharacteristic::Permission:: | 69 BluetoothGattCharacteristic::Permission:: |
| 68 PERMISSION_WRITE_ENCRYPTED_AUTHENTICATED; | 70 PERMISSION_WRITE_ENCRYPTED_AUTHENTICATED; |
| 69 constexpr int32_t kInvalidGattAttributeHandle = -1; | 71 constexpr int32_t kInvalidGattAttributeHandle = -1; |
| 70 // Bluetooth Specification Version 4.2 Vol 3 Part F Section 3.2.2 | 72 // Bluetooth Specification Version 4.2 Vol 3 Part F Section 3.2.2 |
| 71 // An attribute handle of value 0xFFFF is known as the maximum attribute handle. | 73 // An attribute handle of value 0xFFFF is known as the maximum attribute handle. |
| 72 constexpr int32_t kMaxGattAttributeHandle = 0xFFFF; | 74 constexpr int32_t kMaxGattAttributeHandle = 0xFFFF; |
| 73 // Bluetooth Specification Version 4.2 Vol 3 Part F Section 3.2.9 | 75 // Bluetooth Specification Version 4.2 Vol 3 Part F Section 3.2.9 |
| 74 // The maximum length of an attribute value shall be 512 octets. | 76 // The maximum length of an attribute value shall be 512 octets. |
| 75 constexpr int kMaxGattAttributeLength = 512; | 77 constexpr int kMaxGattAttributeLength = 512; |
| 76 // Copied from Android at system/bt/stack/btm/btm_ble_int.h | 78 // Copied from Android at system/bt/stack/btm/btm_ble_int.h |
| 77 // https://goo.gl/k7PM6u | 79 // https://goo.gl/k7PM6u |
| 78 constexpr uint16_t kAndroidMBluetoothVersionNumber = 95; | 80 constexpr uint16_t kAndroidMBluetoothVersionNumber = 95; |
| 79 constexpr uint16_t kMaxAdvertisement = 5; | 81 constexpr uint16_t kMaxAdvertisement = 5; |
| 82 // Bluetooth SDP Service Class ID List Attribute identifier | |
| 83 constexpr uint16_t kServiceClassIDListAttributeID = 0x0001; | |
| 80 | 84 |
| 81 using GattStatusCallback = | 85 using GattStatusCallback = |
| 82 base::Callback<void(arc::mojom::BluetoothGattStatus)>; | 86 base::Callback<void(arc::mojom::BluetoothGattStatus)>; |
| 83 using GattReadCallback = | 87 using GattReadCallback = |
| 84 base::Callback<void(arc::mojom::BluetoothGattValuePtr)>; | 88 base::Callback<void(arc::mojom::BluetoothGattValuePtr)>; |
| 89 using CreateSdpRecordCallback = | |
| 90 base::Callback<void(arc::mojom::BluetoothCreateSdpRecordResultPtr)>; | |
| 91 using RemoveSdpRecordCallback = | |
| 92 base::Callback<void(arc::mojom::BluetoothStatus)>; | |
| 85 | 93 |
| 86 // Example of identifier: /org/bluez/hci0/dev_E0_CF_65_8C_86_1A/service001a | 94 // Example of identifier: /org/bluez/hci0/dev_E0_CF_65_8C_86_1A/service001a |
| 87 // Convert the last 4 characters of |identifier| to an | 95 // Convert the last 4 characters of |identifier| to an |
| 88 // int, by interpreting them as hexadecimal digits. | 96 // int, by interpreting them as hexadecimal digits. |
| 89 int ConvertGattIdentifierToId(const std::string identifier) { | 97 int ConvertGattIdentifierToId(const std::string identifier) { |
| 90 return std::stoi(identifier.substr(identifier.size() - 4), nullptr, 16); | 98 return std::stoi(identifier.substr(identifier.size() - 4), nullptr, 16); |
| 91 } | 99 } |
| 92 | 100 |
| 93 // Create GattDBElement and fill in common data for | 101 // Create GattDBElement and fill in common data for |
| 94 // Gatt Service/Characteristic/Descriptor. | 102 // Gatt Service/Characteristic/Descriptor. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 mojo::Array<arc::mojom::BluetoothPropertyPtr> GetDiscoveryTimeoutProperty( | 195 mojo::Array<arc::mojom::BluetoothPropertyPtr> GetDiscoveryTimeoutProperty( |
| 188 uint32_t timeout) { | 196 uint32_t timeout) { |
| 189 arc::mojom::BluetoothPropertyPtr property = | 197 arc::mojom::BluetoothPropertyPtr property = |
| 190 arc::mojom::BluetoothProperty::New(); | 198 arc::mojom::BluetoothProperty::New(); |
| 191 property->set_discovery_timeout(timeout); | 199 property->set_discovery_timeout(timeout); |
| 192 mojo::Array<arc::mojom::BluetoothPropertyPtr> properties; | 200 mojo::Array<arc::mojom::BluetoothPropertyPtr> properties; |
| 193 properties.push_back(std::move(property)); | 201 properties.push_back(std::move(property)); |
| 194 return properties; | 202 return properties; |
| 195 } | 203 } |
| 196 | 204 |
| 205 void OnCreateServiceRecordDone(const CreateSdpRecordCallback& callback, | |
| 206 uint32_t service_handle) { | |
| 207 arc::mojom::BluetoothCreateSdpRecordResultPtr result = | |
| 208 arc::mojom::BluetoothCreateSdpRecordResult::New(); | |
| 209 result->status = arc::mojom::BluetoothStatus::SUCCESS; | |
| 210 result->service_handle = service_handle; | |
| 211 | |
| 212 callback.Run(std::move(result)); | |
| 213 } | |
| 214 | |
| 215 void OnCreateServiceRecordError( | |
| 216 const CreateSdpRecordCallback& callback, | |
| 217 bluez::BluetoothServiceRecordBlueZ::ErrorCode error_code) { | |
| 218 arc::mojom::BluetoothCreateSdpRecordResultPtr result = | |
| 219 arc::mojom::BluetoothCreateSdpRecordResult::New(); | |
| 220 if (error_code == | |
| 221 bluez::BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY) | |
|
Luis Héctor Chávez
2016/09/06 17:42:29
nit: you cannot elide the braces when the if state
Miao
2016/09/07 17:58:29
Done.
| |
| 222 result->status = arc::mojom::BluetoothStatus::NOT_READY; | |
| 223 else | |
| 224 result->status = arc::mojom::BluetoothStatus::FAIL; | |
| 225 | |
| 226 callback.Run(std::move(result)); | |
| 227 } | |
| 228 | |
| 229 void OnRemoveServiceRecordDone(const RemoveSdpRecordCallback& callback) { | |
| 230 callback.Run(arc::mojom::BluetoothStatus::SUCCESS); | |
| 231 } | |
| 232 | |
| 233 void OnRemoveServiceRecordError( | |
| 234 const RemoveSdpRecordCallback& callback, | |
| 235 bluez::BluetoothServiceRecordBlueZ::ErrorCode error_code) { | |
| 236 arc::mojom::BluetoothStatus status; | |
| 237 if (error_code == | |
| 238 bluez::BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY) | |
| 239 status = arc::mojom::BluetoothStatus::NOT_READY; | |
| 240 else | |
| 241 status = arc::mojom::BluetoothStatus::FAIL; | |
| 242 | |
| 243 callback.Run(status); | |
| 244 } | |
| 245 | |
| 197 } // namespace | 246 } // namespace |
| 198 | 247 |
| 199 namespace arc { | 248 namespace arc { |
| 200 | 249 |
| 201 ArcBluetoothBridge::ArcBluetoothBridge(ArcBridgeService* bridge_service) | 250 ArcBluetoothBridge::ArcBluetoothBridge(ArcBridgeService* bridge_service) |
| 202 : ArcService(bridge_service), binding_(this), weak_factory_(this) { | 251 : ArcService(bridge_service), binding_(this), weak_factory_(this) { |
| 203 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) { | 252 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) { |
| 204 VLOG(1) << "Registering bluetooth adapter."; | 253 VLOG(1) << "Registering bluetooth adapter."; |
| 205 BluetoothAdapterFactory::GetAdapter(base::Bind( | 254 BluetoothAdapterFactory::GetAdapter(base::Bind( |
| 206 &ArcBluetoothBridge::OnAdapterInitialized, weak_factory_.GetWeakPtr())); | 255 &ArcBluetoothBridge::OnAdapterInitialized, weak_factory_.GetWeakPtr())); |
| (...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 966 BluetoothDevice* device = | 1015 BluetoothDevice* device = |
| 967 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); | 1016 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); |
| 968 DCHECK(device); | 1017 DCHECK(device); |
| 969 | 1018 |
| 970 if (device->IsConnected()) { | 1019 if (device->IsConnected()) { |
| 971 arc_bridge_service()->bluetooth()->instance()->OnLEConnectionStateChange( | 1020 arc_bridge_service()->bluetooth()->instance()->OnLEConnectionStateChange( |
| 972 std::move(remote_addr), true); | 1021 std::move(remote_addr), true); |
| 973 return; | 1022 return; |
| 974 } | 1023 } |
| 975 | 1024 |
| 976 // Also pass disconnect callback in error case | 1025 // Also pass disconnect callback in error case since it would be disconnected |
| 977 // since it would be disconnected anyway. | 1026 // anyway. |
| 978 mojom::BluetoothAddressPtr remote_addr_clone = remote_addr.Clone(); | 1027 mojom::BluetoothAddressPtr remote_addr_clone = remote_addr.Clone(); |
| 979 device->CreateGattConnection( | 1028 device->CreateGattConnection( |
| 980 base::Bind(&ArcBluetoothBridge::OnGattConnected, | 1029 base::Bind(&ArcBluetoothBridge::OnGattConnected, |
| 981 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr)), | 1030 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr)), |
| 982 base::Bind(&ArcBluetoothBridge::OnGattConnectError, | 1031 base::Bind(&ArcBluetoothBridge::OnGattConnectError, |
| 983 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr_clone))); | 1032 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr_clone))); |
| 984 } | 1033 } |
| 985 | 1034 |
| 986 void ArcBluetoothBridge::DisconnectLEDevice( | 1035 void ArcBluetoothBridge::DisconnectLEDevice( |
| 987 mojom::BluetoothAddressPtr remote_addr) { | 1036 mojom::BluetoothAddressPtr remote_addr) { |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1465 OnGattOperationDone(callback); | 1514 OnGattOperationDone(callback); |
| 1466 } | 1515 } |
| 1467 | 1516 |
| 1468 void ArcBluetoothBridge::SendIndication( | 1517 void ArcBluetoothBridge::SendIndication( |
| 1469 int32_t attribute_handle, | 1518 int32_t attribute_handle, |
| 1470 mojom::BluetoothAddressPtr address, | 1519 mojom::BluetoothAddressPtr address, |
| 1471 bool confirm, | 1520 bool confirm, |
| 1472 mojo::Array<uint8_t> value, | 1521 mojo::Array<uint8_t> value, |
| 1473 const SendIndicationCallback& callback) {} | 1522 const SendIndicationCallback& callback) {} |
| 1474 | 1523 |
| 1524 void ArcBluetoothBridge::GetSdpRecords(mojom::BluetoothAddressPtr remote_addr, | |
| 1525 mojom::BluetoothUUIDPtr target_uuid) { | |
| 1526 BluetoothDevice* device = | |
| 1527 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); | |
| 1528 | |
| 1529 bluez::BluetoothDeviceBlueZ* device_bluez = | |
| 1530 static_cast<bluez::BluetoothDeviceBlueZ*>(device); | |
| 1531 | |
| 1532 mojom::BluetoothAddressPtr remote_addr_clone = remote_addr.Clone(); | |
| 1533 mojom::BluetoothUUIDPtr target_uuid_clone = target_uuid.Clone(); | |
| 1534 | |
| 1535 device_bluez->GetServiceRecords( | |
| 1536 base::Bind(&ArcBluetoothBridge::OnGetServiceRecordsDone, | |
| 1537 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr), | |
| 1538 base::Passed(&target_uuid)), | |
| 1539 base::Bind(&ArcBluetoothBridge::OnGetServiceRecordsError, | |
| 1540 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr_clone), | |
| 1541 base::Passed(&target_uuid_clone))); | |
| 1542 } | |
| 1543 | |
| 1544 void ArcBluetoothBridge::CreateSdpRecord( | |
| 1545 mojom::BluetoothSdpRecordPtr record_mojo, | |
| 1546 const CreateSdpRecordCallback& callback) { | |
| 1547 auto record = record_mojo.To<bluez::BluetoothServiceRecordBlueZ>(); | |
| 1548 | |
| 1549 // Check if ServiceClassIDList attribute (attribute ID 0x0001) is included | |
| 1550 // after type conversion, since it is mandatory for creating a service record. | |
| 1551 if (!record.IsAttributePresented(kServiceClassIDListAttributeID)) { | |
| 1552 mojom::BluetoothCreateSdpRecordResultPtr result = | |
| 1553 mojom::BluetoothCreateSdpRecordResult::New(); | |
| 1554 result->status = mojom::BluetoothStatus::FAIL; | |
| 1555 callback.Run(std::move(result)); | |
| 1556 return; | |
| 1557 } | |
| 1558 | |
| 1559 bluetooth_adapter_->CreateServiceRecord( | |
| 1560 record, base::Bind(&OnCreateServiceRecordDone, callback), | |
| 1561 base::Bind(&OnCreateServiceRecordError, callback)); | |
| 1562 } | |
| 1563 | |
| 1564 void ArcBluetoothBridge::RemoveSdpRecord( | |
| 1565 uint32_t service_handle, | |
| 1566 const RemoveSdpRecordCallback& callback) { | |
| 1567 bluetooth_adapter_->RemoveServiceRecord( | |
| 1568 service_handle, base::Bind(&OnRemoveServiceRecordDone, callback), | |
| 1569 base::Bind(&OnRemoveServiceRecordError, callback)); | |
| 1570 } | |
| 1571 | |
| 1475 void ArcBluetoothBridge::OnDiscoveryError() { | 1572 void ArcBluetoothBridge::OnDiscoveryError() { |
| 1476 LOG(WARNING) << "failed to change discovery state"; | 1573 LOG(WARNING) << "failed to change discovery state"; |
| 1477 } | 1574 } |
| 1478 | 1575 |
| 1479 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const { | 1576 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const { |
| 1480 if (!HasBluetoothInstance()) | 1577 if (!HasBluetoothInstance()) |
| 1481 return; | 1578 return; |
| 1482 | 1579 |
| 1483 arc_bridge_service()->bluetooth()->instance()->OnBondStateChanged( | 1580 arc_bridge_service()->bluetooth()->instance()->OnBondStateChanged( |
| 1484 mojom::BluetoothStatus::SUCCESS, std::move(addr), | 1581 mojom::BluetoothStatus::SUCCESS, std::move(addr), |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1808 if (arc_bridge_service()->bluetooth()->version() >= kMinBtleVersion) { | 1905 if (arc_bridge_service()->bluetooth()->version() >= kMinBtleVersion) { |
| 1809 base::Optional<int8_t> rssi = device->GetInquiryRSSI(); | 1906 base::Optional<int8_t> rssi = device->GetInquiryRSSI(); |
| 1810 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = | 1907 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = |
| 1811 GetAdvertisingData(device); | 1908 GetAdvertisingData(device); |
| 1812 arc_bridge_service()->bluetooth()->instance()->OnLEDeviceFound( | 1909 arc_bridge_service()->bluetooth()->instance()->OnLEDeviceFound( |
| 1813 addr->Clone(), rssi.value_or(mojom::kUnknownPower), | 1910 addr->Clone(), rssi.value_or(mojom::kUnknownPower), |
| 1814 std::move(adv_data)); | 1911 std::move(adv_data)); |
| 1815 } | 1912 } |
| 1816 | 1913 |
| 1817 // OnBondStateChanged must be called with mojom::BluetoothBondState::BONDING | 1914 // OnBondStateChanged must be called with mojom::BluetoothBondState::BONDING |
| 1818 // to | 1915 // to make sure the bond state machine on Android is ready to take the |
| 1819 // make sure the bond state machine on Android is ready to take the | |
| 1820 // pair-done event. Otherwise the pair-done event will be dropped as an | 1916 // pair-done event. Otherwise the pair-done event will be dropped as an |
| 1821 // invalid change of paired status. | 1917 // invalid change of paired status. |
| 1822 OnPairing(addr->Clone()); | 1918 OnPairing(addr->Clone()); |
| 1823 OnPairedDone(std::move(addr)); | 1919 OnPairedDone(std::move(addr)); |
| 1824 } | 1920 } |
| 1825 } | 1921 } |
| 1826 | 1922 |
| 1923 void ArcBluetoothBridge::OnGetServiceRecordsDone( | |
| 1924 mojom::BluetoothAddressPtr remote_addr, | |
| 1925 mojom::BluetoothUUIDPtr target_uuid, | |
| 1926 const std::vector<bluez::BluetoothServiceRecordBlueZ>& records_bluez) { | |
| 1927 if (!CheckBluetoothInstanceVersion(kMinSdpSupportVersion)) | |
| 1928 return; | |
| 1929 | |
| 1930 if (!HasBluetoothInstance()) | |
| 1931 return; | |
| 1932 | |
| 1933 arc_bridge_service()->bluetooth()->instance()->OnGetSdpRecords( | |
| 1934 mojom::BluetoothStatus::SUCCESS, std::move(remote_addr), | |
| 1935 std::move(target_uuid), | |
| 1936 mojo::Array<mojom::BluetoothSdpRecordPtr>::From(records_bluez)); | |
| 1937 } | |
| 1938 | |
| 1939 void ArcBluetoothBridge::OnGetServiceRecordsError( | |
| 1940 mojom::BluetoothAddressPtr remote_addr, | |
| 1941 mojom::BluetoothUUIDPtr target_uuid, | |
| 1942 bluez::BluetoothServiceRecordBlueZ::ErrorCode error_code) { | |
| 1943 mojom::BluetoothStatus status; | |
| 1944 | |
| 1945 switch (error_code) { | |
| 1946 case bluez::BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY: | |
| 1947 status = mojom::BluetoothStatus::NOT_READY; | |
| 1948 break; | |
| 1949 case bluez::BluetoothServiceRecordBlueZ::ErrorCode:: | |
| 1950 ERROR_DEVICE_DISCONNECTED: | |
| 1951 status = mojom::BluetoothStatus::RMT_DEV_DOWN; | |
| 1952 break; | |
| 1953 default: | |
| 1954 status = mojom::BluetoothStatus::FAIL; | |
| 1955 break; | |
| 1956 } | |
| 1957 | |
| 1958 arc_bridge_service()->bluetooth()->instance()->OnGetSdpRecords( | |
|
Luis Héctor Chávez
2016/09/06 17:42:29
this needs the HasBluetoothInstance() check, as we
Miao
2016/09/07 17:58:29
Done.
| |
| 1959 status, std::move(remote_addr), std::move(target_uuid), | |
| 1960 mojo::Array<mojom::BluetoothSdpRecordPtr>::New(0)); | |
| 1961 } | |
| 1962 | |
| 1827 bool ArcBluetoothBridge::CheckBluetoothInstanceVersion( | 1963 bool ArcBluetoothBridge::CheckBluetoothInstanceVersion( |
| 1828 uint32_t version_need) const { | 1964 uint32_t version_need) const { |
| 1829 uint32_t version = arc_bridge_service()->bluetooth()->version(); | 1965 uint32_t version = arc_bridge_service()->bluetooth()->version(); |
| 1830 if (version >= version_need) | 1966 if (version >= version_need) |
| 1831 return true; | 1967 return true; |
| 1832 LOG(WARNING) << "Bluetooth instance is too old (version " << version | 1968 LOG(WARNING) << "Bluetooth instance is too old (version " << version |
| 1833 << ") need version " << version_need; | 1969 << ") need version " << version_need; |
| 1834 return false; | 1970 return false; |
| 1835 } | 1971 } |
| 1836 | 1972 |
| 1837 bool ArcBluetoothBridge::CalledOnValidThread() { | 1973 bool ArcBluetoothBridge::CalledOnValidThread() { |
| 1838 return thread_checker_.CalledOnValidThread(); | 1974 return thread_checker_.CalledOnValidThread(); |
| 1839 } | 1975 } |
| 1840 | 1976 |
| 1841 } // namespace arc | 1977 } // namespace arc |
| OLD | NEW |