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) { |
| 222 result->status = arc::mojom::BluetoothStatus::NOT_READY; |
| 223 } else { |
| 224 result->status = arc::mojom::BluetoothStatus::FAIL; |
| 225 } |
| 226 |
| 227 callback.Run(std::move(result)); |
| 228 } |
| 229 |
| 230 void OnRemoveServiceRecordDone(const RemoveSdpRecordCallback& callback) { |
| 231 callback.Run(arc::mojom::BluetoothStatus::SUCCESS); |
| 232 } |
| 233 |
| 234 void OnRemoveServiceRecordError( |
| 235 const RemoveSdpRecordCallback& callback, |
| 236 bluez::BluetoothServiceRecordBlueZ::ErrorCode error_code) { |
| 237 arc::mojom::BluetoothStatus status; |
| 238 if (error_code == |
| 239 bluez::BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY) |
| 240 status = arc::mojom::BluetoothStatus::NOT_READY; |
| 241 else |
| 242 status = arc::mojom::BluetoothStatus::FAIL; |
| 243 |
| 244 callback.Run(status); |
| 245 } |
| 246 |
197 } // namespace | 247 } // namespace |
198 | 248 |
199 namespace arc { | 249 namespace arc { |
200 | 250 |
201 ArcBluetoothBridge::ArcBluetoothBridge(ArcBridgeService* bridge_service) | 251 ArcBluetoothBridge::ArcBluetoothBridge(ArcBridgeService* bridge_service) |
202 : ArcService(bridge_service), binding_(this), weak_factory_(this) { | 252 : ArcService(bridge_service), binding_(this), weak_factory_(this) { |
203 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) { | 253 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) { |
204 VLOG(1) << "Registering bluetooth adapter."; | 254 VLOG(1) << "Registering bluetooth adapter."; |
205 BluetoothAdapterFactory::GetAdapter(base::Bind( | 255 BluetoothAdapterFactory::GetAdapter(base::Bind( |
206 &ArcBluetoothBridge::OnAdapterInitialized, weak_factory_.GetWeakPtr())); | 256 &ArcBluetoothBridge::OnAdapterInitialized, weak_factory_.GetWeakPtr())); |
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 BluetoothDevice* device = | 1016 BluetoothDevice* device = |
967 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); | 1017 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); |
968 DCHECK(device); | 1018 DCHECK(device); |
969 | 1019 |
970 if (device->IsConnected()) { | 1020 if (device->IsConnected()) { |
971 arc_bridge_service()->bluetooth()->instance()->OnLEConnectionStateChange( | 1021 arc_bridge_service()->bluetooth()->instance()->OnLEConnectionStateChange( |
972 std::move(remote_addr), true); | 1022 std::move(remote_addr), true); |
973 return; | 1023 return; |
974 } | 1024 } |
975 | 1025 |
976 // Also pass disconnect callback in error case | 1026 // Also pass disconnect callback in error case since it would be disconnected |
977 // since it would be disconnected anyway. | 1027 // anyway. |
978 mojom::BluetoothAddressPtr remote_addr_clone = remote_addr.Clone(); | 1028 mojom::BluetoothAddressPtr remote_addr_clone = remote_addr.Clone(); |
979 device->CreateGattConnection( | 1029 device->CreateGattConnection( |
980 base::Bind(&ArcBluetoothBridge::OnGattConnected, | 1030 base::Bind(&ArcBluetoothBridge::OnGattConnected, |
981 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr)), | 1031 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr)), |
982 base::Bind(&ArcBluetoothBridge::OnGattConnectError, | 1032 base::Bind(&ArcBluetoothBridge::OnGattConnectError, |
983 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr_clone))); | 1033 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr_clone))); |
984 } | 1034 } |
985 | 1035 |
986 void ArcBluetoothBridge::DisconnectLEDevice( | 1036 void ArcBluetoothBridge::DisconnectLEDevice( |
987 mojom::BluetoothAddressPtr remote_addr) { | 1037 mojom::BluetoothAddressPtr remote_addr) { |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1465 OnGattOperationDone(callback); | 1515 OnGattOperationDone(callback); |
1466 } | 1516 } |
1467 | 1517 |
1468 void ArcBluetoothBridge::SendIndication( | 1518 void ArcBluetoothBridge::SendIndication( |
1469 int32_t attribute_handle, | 1519 int32_t attribute_handle, |
1470 mojom::BluetoothAddressPtr address, | 1520 mojom::BluetoothAddressPtr address, |
1471 bool confirm, | 1521 bool confirm, |
1472 mojo::Array<uint8_t> value, | 1522 mojo::Array<uint8_t> value, |
1473 const SendIndicationCallback& callback) {} | 1523 const SendIndicationCallback& callback) {} |
1474 | 1524 |
| 1525 void ArcBluetoothBridge::GetSdpRecords(mojom::BluetoothAddressPtr remote_addr, |
| 1526 mojom::BluetoothUUIDPtr target_uuid) { |
| 1527 BluetoothDevice* device = |
| 1528 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); |
| 1529 |
| 1530 bluez::BluetoothDeviceBlueZ* device_bluez = |
| 1531 static_cast<bluez::BluetoothDeviceBlueZ*>(device); |
| 1532 |
| 1533 mojom::BluetoothAddressPtr remote_addr_clone = remote_addr.Clone(); |
| 1534 mojom::BluetoothUUIDPtr target_uuid_clone = target_uuid.Clone(); |
| 1535 |
| 1536 device_bluez->GetServiceRecords( |
| 1537 base::Bind(&ArcBluetoothBridge::OnGetServiceRecordsDone, |
| 1538 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr), |
| 1539 base::Passed(&target_uuid)), |
| 1540 base::Bind(&ArcBluetoothBridge::OnGetServiceRecordsError, |
| 1541 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr_clone), |
| 1542 base::Passed(&target_uuid_clone))); |
| 1543 } |
| 1544 |
| 1545 void ArcBluetoothBridge::CreateSdpRecord( |
| 1546 mojom::BluetoothSdpRecordPtr record_mojo, |
| 1547 const CreateSdpRecordCallback& callback) { |
| 1548 auto record = record_mojo.To<bluez::BluetoothServiceRecordBlueZ>(); |
| 1549 |
| 1550 // Check if ServiceClassIDList attribute (attribute ID 0x0001) is included |
| 1551 // after type conversion, since it is mandatory for creating a service record. |
| 1552 if (!record.IsAttributePresented(kServiceClassIDListAttributeID)) { |
| 1553 mojom::BluetoothCreateSdpRecordResultPtr result = |
| 1554 mojom::BluetoothCreateSdpRecordResult::New(); |
| 1555 result->status = mojom::BluetoothStatus::FAIL; |
| 1556 callback.Run(std::move(result)); |
| 1557 return; |
| 1558 } |
| 1559 |
| 1560 bluetooth_adapter_->CreateServiceRecord( |
| 1561 record, base::Bind(&OnCreateServiceRecordDone, callback), |
| 1562 base::Bind(&OnCreateServiceRecordError, callback)); |
| 1563 } |
| 1564 |
| 1565 void ArcBluetoothBridge::RemoveSdpRecord( |
| 1566 uint32_t service_handle, |
| 1567 const RemoveSdpRecordCallback& callback) { |
| 1568 bluetooth_adapter_->RemoveServiceRecord( |
| 1569 service_handle, base::Bind(&OnRemoveServiceRecordDone, callback), |
| 1570 base::Bind(&OnRemoveServiceRecordError, callback)); |
| 1571 } |
| 1572 |
1475 void ArcBluetoothBridge::OnDiscoveryError() { | 1573 void ArcBluetoothBridge::OnDiscoveryError() { |
1476 LOG(WARNING) << "failed to change discovery state"; | 1574 LOG(WARNING) << "failed to change discovery state"; |
1477 } | 1575 } |
1478 | 1576 |
1479 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const { | 1577 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const { |
1480 if (!HasBluetoothInstance()) | 1578 if (!HasBluetoothInstance()) |
1481 return; | 1579 return; |
1482 | 1580 |
1483 arc_bridge_service()->bluetooth()->instance()->OnBondStateChanged( | 1581 arc_bridge_service()->bluetooth()->instance()->OnBondStateChanged( |
1484 mojom::BluetoothStatus::SUCCESS, std::move(addr), | 1582 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) { | 1906 if (arc_bridge_service()->bluetooth()->version() >= kMinBtleVersion) { |
1809 base::Optional<int8_t> rssi = device->GetInquiryRSSI(); | 1907 base::Optional<int8_t> rssi = device->GetInquiryRSSI(); |
1810 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = | 1908 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = |
1811 GetAdvertisingData(device); | 1909 GetAdvertisingData(device); |
1812 arc_bridge_service()->bluetooth()->instance()->OnLEDeviceFound( | 1910 arc_bridge_service()->bluetooth()->instance()->OnLEDeviceFound( |
1813 addr->Clone(), rssi.value_or(mojom::kUnknownPower), | 1911 addr->Clone(), rssi.value_or(mojom::kUnknownPower), |
1814 std::move(adv_data)); | 1912 std::move(adv_data)); |
1815 } | 1913 } |
1816 | 1914 |
1817 // OnBondStateChanged must be called with mojom::BluetoothBondState::BONDING | 1915 // OnBondStateChanged must be called with mojom::BluetoothBondState::BONDING |
1818 // to | 1916 // 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 | 1917 // pair-done event. Otherwise the pair-done event will be dropped as an |
1821 // invalid change of paired status. | 1918 // invalid change of paired status. |
1822 OnPairing(addr->Clone()); | 1919 OnPairing(addr->Clone()); |
1823 OnPairedDone(std::move(addr)); | 1920 OnPairedDone(std::move(addr)); |
1824 } | 1921 } |
1825 } | 1922 } |
1826 | 1923 |
| 1924 void ArcBluetoothBridge::OnGetServiceRecordsDone( |
| 1925 mojom::BluetoothAddressPtr remote_addr, |
| 1926 mojom::BluetoothUUIDPtr target_uuid, |
| 1927 const std::vector<bluez::BluetoothServiceRecordBlueZ>& records_bluez) { |
| 1928 if (!CheckBluetoothInstanceVersion(kMinSdpSupportVersion)) |
| 1929 return; |
| 1930 |
| 1931 if (!HasBluetoothInstance()) |
| 1932 return; |
| 1933 |
| 1934 arc_bridge_service()->bluetooth()->instance()->OnGetSdpRecords( |
| 1935 mojom::BluetoothStatus::SUCCESS, std::move(remote_addr), |
| 1936 std::move(target_uuid), |
| 1937 mojo::Array<mojom::BluetoothSdpRecordPtr>::From(records_bluez)); |
| 1938 } |
| 1939 |
| 1940 void ArcBluetoothBridge::OnGetServiceRecordsError( |
| 1941 mojom::BluetoothAddressPtr remote_addr, |
| 1942 mojom::BluetoothUUIDPtr target_uuid, |
| 1943 bluez::BluetoothServiceRecordBlueZ::ErrorCode error_code) { |
| 1944 if (!HasBluetoothInstance()) |
| 1945 return; |
| 1946 |
| 1947 if (!CheckBluetoothInstanceVersion(kMinSdpSupportVersion)) |
| 1948 return; |
| 1949 |
| 1950 mojom::BluetoothStatus status; |
| 1951 |
| 1952 switch (error_code) { |
| 1953 case bluez::BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY: |
| 1954 status = mojom::BluetoothStatus::NOT_READY; |
| 1955 break; |
| 1956 case bluez::BluetoothServiceRecordBlueZ::ErrorCode:: |
| 1957 ERROR_DEVICE_DISCONNECTED: |
| 1958 status = mojom::BluetoothStatus::RMT_DEV_DOWN; |
| 1959 break; |
| 1960 default: |
| 1961 status = mojom::BluetoothStatus::FAIL; |
| 1962 break; |
| 1963 } |
| 1964 |
| 1965 arc_bridge_service()->bluetooth()->instance()->OnGetSdpRecords( |
| 1966 status, std::move(remote_addr), std::move(target_uuid), |
| 1967 mojo::Array<mojom::BluetoothSdpRecordPtr>::New(0)); |
| 1968 } |
| 1969 |
1827 bool ArcBluetoothBridge::CheckBluetoothInstanceVersion( | 1970 bool ArcBluetoothBridge::CheckBluetoothInstanceVersion( |
1828 uint32_t version_need) const { | 1971 uint32_t version_need) const { |
1829 uint32_t version = arc_bridge_service()->bluetooth()->version(); | 1972 uint32_t version = arc_bridge_service()->bluetooth()->version(); |
1830 if (version >= version_need) | 1973 if (version >= version_need) |
1831 return true; | 1974 return true; |
1832 LOG(WARNING) << "Bluetooth instance is too old (version " << version | 1975 LOG(WARNING) << "Bluetooth instance is too old (version " << version |
1833 << ") need version " << version_need; | 1976 << ") need version " << version_need; |
1834 return false; | 1977 return false; |
1835 } | 1978 } |
1836 | 1979 |
1837 bool ArcBluetoothBridge::CalledOnValidThread() { | 1980 bool ArcBluetoothBridge::CalledOnValidThread() { |
1838 return thread_checker_.CalledOnValidThread(); | 1981 return thread_checker_.CalledOnValidThread(); |
1839 } | 1982 } |
1840 | 1983 |
1841 } // namespace arc | 1984 } // namespace arc |
OLD | NEW |