| 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 <fcntl.h> | 8 #include <fcntl.h> |
| 8 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <sys/socket.h> |
| 9 | 11 |
| 10 #include <iomanip> | 12 #include <iomanip> |
| 11 #include <string> | 13 #include <string> |
| 12 #include <utility> | 14 #include <utility> |
| 13 | 15 |
| 14 #include "base/bind.h" | 16 #include "base/bind.h" |
| 15 #include "base/logging.h" | 17 #include "base/logging.h" |
| 16 #include "base/posix/eintr_wrapper.h" | 18 #include "base/posix/eintr_wrapper.h" |
| 17 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 21 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 21 #include "components/arc/arc_bridge_service.h" | 23 #include "components/arc/arc_bridge_service.h" |
| 22 #include "components/arc/bluetooth/bluetooth_type_converters.h" | 24 #include "components/arc/bluetooth/bluetooth_type_converters.h" |
| 23 #include "device/bluetooth/bluetooth_adapter_factory.h" | 25 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 24 #include "device/bluetooth/bluetooth_common.h" | 26 #include "device/bluetooth/bluetooth_common.h" |
| 25 #include "device/bluetooth/bluetooth_device.h" | 27 #include "device/bluetooth/bluetooth_device.h" |
| 26 #include "device/bluetooth/bluetooth_gatt_connection.h" | 28 #include "device/bluetooth/bluetooth_gatt_connection.h" |
| 27 #include "device/bluetooth/bluetooth_gatt_notify_session.h" | 29 #include "device/bluetooth/bluetooth_gatt_notify_session.h" |
| 28 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" | 30 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
| 29 #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h" | 31 #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h" |
| 30 #include "device/bluetooth/bluetooth_remote_gatt_service.h" | 32 #include "device/bluetooth/bluetooth_remote_gatt_service.h" |
| 33 #include "mojo/edk/embedder/embedder.h" |
| 34 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 31 | 35 |
| 32 using device::BluetoothAdapter; | 36 using device::BluetoothAdapter; |
| 33 using device::BluetoothAdapterFactory; | 37 using device::BluetoothAdapterFactory; |
| 34 using device::BluetoothAdvertisement; | 38 using device::BluetoothAdvertisement; |
| 35 using device::BluetoothDevice; | 39 using device::BluetoothDevice; |
| 36 using device::BluetoothDiscoveryFilter; | 40 using device::BluetoothDiscoveryFilter; |
| 37 using device::BluetoothDiscoverySession; | 41 using device::BluetoothDiscoverySession; |
| 38 using device::BluetoothGattConnection; | 42 using device::BluetoothGattConnection; |
| 39 using device::BluetoothGattNotifySession; | 43 using device::BluetoothGattNotifySession; |
| 40 using device::BluetoothGattCharacteristic; | 44 using device::BluetoothGattCharacteristic; |
| (...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 | 1020 |
| 1017 void ArcBluetoothBridge::ReadRemoteRssi( | 1021 void ArcBluetoothBridge::ReadRemoteRssi( |
| 1018 mojom::BluetoothAddressPtr remote_addr, | 1022 mojom::BluetoothAddressPtr remote_addr, |
| 1019 const ReadRemoteRssiCallback& callback) { | 1023 const ReadRemoteRssiCallback& callback) { |
| 1020 BluetoothDevice* device = | 1024 BluetoothDevice* device = |
| 1021 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); | 1025 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); |
| 1022 int rssi = device->GetInquiryRSSI(); | 1026 int rssi = device->GetInquiryRSSI(); |
| 1023 callback.Run(rssi); | 1027 callback.Run(rssi); |
| 1024 } | 1028 } |
| 1025 | 1029 |
| 1030 void ArcBluetoothBridge::OpenBluetoothSocket( |
| 1031 const OpenBluetoothSocketCallback& callback) { |
| 1032 base::ScopedFD sock(socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)); |
| 1033 if (!sock.is_valid()) { |
| 1034 LOG(ERROR) << "Failed to open socket."; |
| 1035 callback.Run(mojo::ScopedHandle()); |
| 1036 return; |
| 1037 } |
| 1038 mojo::edk::ScopedPlatformHandle platform_handle{ |
| 1039 mojo::edk::PlatformHandle(sock.release())}; |
| 1040 MojoHandle wrapped_handle; |
| 1041 MojoResult wrap_result = mojo::edk::CreatePlatformHandleWrapper( |
| 1042 std::move(platform_handle), &wrapped_handle); |
| 1043 if (wrap_result != MOJO_RESULT_OK) { |
| 1044 LOG(ERROR) << "Failed to wrap handles. Closing: " << wrap_result; |
| 1045 callback.Run(mojo::ScopedHandle()); |
| 1046 return; |
| 1047 } |
| 1048 mojo::ScopedHandle scoped_handle{mojo::Handle(wrapped_handle)}; |
| 1049 |
| 1050 callback.Run(std::move(scoped_handle)); |
| 1051 } |
| 1052 |
| 1026 void ArcBluetoothBridge::OnDiscoveryError() { | 1053 void ArcBluetoothBridge::OnDiscoveryError() { |
| 1027 LOG(WARNING) << "failed to change discovery state"; | 1054 LOG(WARNING) << "failed to change discovery state"; |
| 1028 } | 1055 } |
| 1029 | 1056 |
| 1030 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const { | 1057 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const { |
| 1031 if (!HasBluetoothInstance()) | 1058 if (!HasBluetoothInstance()) |
| 1032 return; | 1059 return; |
| 1033 | 1060 |
| 1034 arc_bridge_service()->bluetooth()->instance()->OnBondStateChanged( | 1061 arc_bridge_service()->bluetooth()->instance()->OnBondStateChanged( |
| 1035 mojom::BluetoothStatus::SUCCESS, std::move(addr), | 1062 mojom::BluetoothStatus::SUCCESS, std::move(addr), |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1354 uint32_t version_need) const { | 1381 uint32_t version_need) const { |
| 1355 uint32_t version = arc_bridge_service()->bluetooth()->version(); | 1382 uint32_t version = arc_bridge_service()->bluetooth()->version(); |
| 1356 if (version >= version_need) | 1383 if (version >= version_need) |
| 1357 return true; | 1384 return true; |
| 1358 LOG(WARNING) << "Bluetooth instance is too old (version " << version | 1385 LOG(WARNING) << "Bluetooth instance is too old (version " << version |
| 1359 << ") need version " << version_need; | 1386 << ") need version " << version_need; |
| 1360 return false; | 1387 return false; |
| 1361 } | 1388 } |
| 1362 | 1389 |
| 1363 } // namespace arc | 1390 } // namespace arc |
| OLD | NEW |