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 <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <iomanip> | 10 #include <iomanip> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/posix/eintr_wrapper.h" | 15 #include "base/posix/eintr_wrapper.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 20 #include "components/arc/arc_bridge_service.h" | 20 #include "components/arc/arc_bridge_service.h" |
| 21 #include "components/arc/bluetooth/bluetooth_type_converters.h" | 21 #include "components/arc/bluetooth/bluetooth_type_converters.h" |
| 22 #include "device/bluetooth/bluetooth_adapter_factory.h" | |
| 23 #include "device/bluetooth/bluetooth_common.h" | 22 #include "device/bluetooth/bluetooth_common.h" |
| 24 #include "device/bluetooth/bluetooth_device.h" | 23 #include "device/bluetooth/bluetooth_device.h" |
| 25 #include "device/bluetooth/bluetooth_gatt_connection.h" | 24 #include "device/bluetooth/bluetooth_gatt_connection.h" |
| 26 #include "device/bluetooth/bluetooth_gatt_notify_session.h" | 25 #include "device/bluetooth/bluetooth_gatt_notify_session.h" |
| 27 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" | 26 #include "device/bluetooth/bluetooth_local_gatt_characteristic.h" |
| 28 #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h" | 27 #include "device/bluetooth/bluetooth_local_gatt_descriptor.h" |
| 29 #include "device/bluetooth/bluetooth_remote_gatt_service.h" | |
| 30 | 28 |
| 31 using device::BluetoothAdapter; | 29 using device::BluetoothAdapter; |
| 32 using device::BluetoothAdapterFactory; | 30 using device::BluetoothAdapterFactory; |
| 33 using device::BluetoothAdvertisement; | 31 using device::BluetoothAdvertisement; |
| 34 using device::BluetoothDevice; | 32 using device::BluetoothDevice; |
| 35 using device::BluetoothDiscoveryFilter; | 33 using device::BluetoothDiscoveryFilter; |
| 36 using device::BluetoothDiscoverySession; | 34 using device::BluetoothDiscoverySession; |
| 37 using device::BluetoothGattConnection; | 35 using device::BluetoothGattConnection; |
| 38 using device::BluetoothGattNotifySession; | 36 using device::BluetoothGattNotifySession; |
| 39 using device::BluetoothGattCharacteristic; | 37 using device::BluetoothGattCharacteristic; |
| 40 using device::BluetoothGattDescriptor; | 38 using device::BluetoothGattDescriptor; |
| 41 using device::BluetoothGattService; | 39 using device::BluetoothGattService; |
| 40 using device::BluetoothLocalGattCharacteristic; | |
| 41 using device::BluetoothLocalGattDescriptor; | |
| 42 using device::BluetoothLocalGattService; | |
| 42 using device::BluetoothRemoteGattCharacteristic; | 43 using device::BluetoothRemoteGattCharacteristic; |
| 43 using device::BluetoothRemoteGattDescriptor; | 44 using device::BluetoothRemoteGattDescriptor; |
| 44 using device::BluetoothRemoteGattService; | 45 using device::BluetoothRemoteGattService; |
| 46 using device::BluetoothTransport; | |
| 45 using device::BluetoothUUID; | 47 using device::BluetoothUUID; |
| 46 | 48 |
| 47 namespace { | 49 namespace { |
| 48 constexpr int32_t kMinBtleVersion = 1; | 50 constexpr int32_t kMinBtleVersion = 1; |
| 49 constexpr int32_t kMinBtleNotifyVersion = 2; | 51 constexpr int32_t kMinBtleNotifyVersion = 2; |
| 50 constexpr uint32_t kGattReadPermission = | 52 constexpr uint32_t kGattReadPermission = |
| 51 BluetoothGattCharacteristic::Permission::PERMISSION_READ | | 53 BluetoothGattCharacteristic::Permission::PERMISSION_READ | |
| 52 BluetoothGattCharacteristic::Permission::PERMISSION_READ_ENCRYPTED | | 54 BluetoothGattCharacteristic::Permission::PERMISSION_READ_ENCRYPTED | |
| 53 BluetoothGattCharacteristic::Permission:: | 55 BluetoothGattCharacteristic::Permission:: |
| 54 PERMISSION_READ_ENCRYPTED_AUTHENTICATED; | 56 PERMISSION_READ_ENCRYPTED_AUTHENTICATED; |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 true /* is_notify */, mojo::Array<uint8_t>::From(value)); | 283 true /* is_notify */, mojo::Array<uint8_t>::From(value)); |
| 282 } | 284 } |
| 283 | 285 |
| 284 void ArcBluetoothBridge::GattDescriptorValueChanged( | 286 void ArcBluetoothBridge::GattDescriptorValueChanged( |
| 285 BluetoothAdapter* adapter, | 287 BluetoothAdapter* adapter, |
| 286 BluetoothRemoteGattDescriptor* descriptor, | 288 BluetoothRemoteGattDescriptor* descriptor, |
| 287 const std::vector<uint8_t>& value) { | 289 const std::vector<uint8_t>& value) { |
| 288 // Placeholder for GATT client functionality | 290 // Placeholder for GATT client functionality |
| 289 } | 291 } |
| 290 | 292 |
| 293 void ArcBluetoothBridge::OnCharacteristicReadRequest( | |
| 294 const BluetoothDevice* device, | |
| 295 const BluetoothLocalGattCharacteristic* characteristic, | |
| 296 int offset, | |
| 297 const ValueCallback& callback, | |
| 298 const ErrorCallback& error_callback) {} | |
|
palmer
2016/07/16 00:21:04
Are these functions going to be filled in with imp
puthik_chromium
2016/07/16 00:27:18
The implementation is in http://crrev.com/21040430
puthik_chromium
2016/07/18 21:27:39
The |offset| is |int| type in Android API.
https:
| |
| 299 | |
| 300 void ArcBluetoothBridge::OnCharacteristicWriteRequest( | |
| 301 const BluetoothDevice* device, | |
| 302 const BluetoothLocalGattCharacteristic* characteristic, | |
| 303 const std::vector<uint8_t>& value, | |
| 304 int offset, | |
| 305 const base::Closure& callback, | |
| 306 const ErrorCallback& error_callback) {} | |
| 307 | |
| 308 void ArcBluetoothBridge::OnDescriptorReadRequest( | |
| 309 const BluetoothDevice* device, | |
| 310 const BluetoothLocalGattDescriptor* descriptor, | |
| 311 int offset, | |
| 312 const ValueCallback& callback, | |
| 313 const ErrorCallback& error_callback) {} | |
| 314 | |
| 315 void ArcBluetoothBridge::OnDescriptorWriteRequest( | |
| 316 const BluetoothDevice* device, | |
| 317 const BluetoothLocalGattDescriptor* descriptor, | |
| 318 const std::vector<uint8_t>& value, | |
| 319 int offset, | |
| 320 const base::Closure& callback, | |
| 321 const ErrorCallback& error_callback) {} | |
| 322 | |
| 323 void ArcBluetoothBridge::OnNotificationsStart( | |
| 324 const BluetoothDevice* device, | |
| 325 const BluetoothLocalGattCharacteristic* characteristic) {} | |
| 326 | |
| 327 void ArcBluetoothBridge::OnNotificationsStop( | |
| 328 const BluetoothDevice* device, | |
| 329 const BluetoothLocalGattCharacteristic* characteristic) {} | |
| 330 | |
| 291 void ArcBluetoothBridge::EnableAdapter(const EnableAdapterCallback& callback) { | 331 void ArcBluetoothBridge::EnableAdapter(const EnableAdapterCallback& callback) { |
| 292 DCHECK(bluetooth_adapter_); | 332 DCHECK(bluetooth_adapter_); |
| 293 if (!bluetooth_adapter_->IsPowered()) { | 333 if (!bluetooth_adapter_->IsPowered()) { |
| 294 bluetooth_adapter_->SetPowered( | 334 bluetooth_adapter_->SetPowered( |
| 295 true, base::Bind(&ArcBluetoothBridge::OnPoweredOn, | 335 true, base::Bind(&ArcBluetoothBridge::OnPoweredOn, |
| 296 weak_factory_.GetWeakPtr(), callback), | 336 weak_factory_.GetWeakPtr(), callback), |
| 297 base::Bind(&ArcBluetoothBridge::OnPoweredError, | 337 base::Bind(&ArcBluetoothBridge::OnPoweredError, |
| 298 weak_factory_.GetWeakPtr(), callback)); | 338 weak_factory_.GetWeakPtr(), callback)); |
| 299 return; | 339 return; |
| 300 } | 340 } |
| (...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1015 | 1055 |
| 1016 void ArcBluetoothBridge::ReadRemoteRssi( | 1056 void ArcBluetoothBridge::ReadRemoteRssi( |
| 1017 mojom::BluetoothAddressPtr remote_addr, | 1057 mojom::BluetoothAddressPtr remote_addr, |
| 1018 const ReadRemoteRssiCallback& callback) { | 1058 const ReadRemoteRssiCallback& callback) { |
| 1019 BluetoothDevice* device = | 1059 BluetoothDevice* device = |
| 1020 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); | 1060 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); |
| 1021 int rssi = device->GetInquiryRSSI(); | 1061 int rssi = device->GetInquiryRSSI(); |
| 1022 callback.Run(rssi); | 1062 callback.Run(rssi); |
| 1023 } | 1063 } |
| 1024 | 1064 |
| 1065 void ArcBluetoothBridge::AddService(mojom::BluetoothGattServiceIDPtr service_id, | |
| 1066 int32_t num_handles, | |
| 1067 const AddServiceCallback& callback) {} | |
| 1068 | |
| 1069 void ArcBluetoothBridge::AddCharacteristic( | |
| 1070 int32_t service_handle, | |
| 1071 mojom::BluetoothUUIDPtr uuid, | |
| 1072 int32_t properties, | |
| 1073 int32_t permissions, | |
| 1074 const AddCharacteristicCallback& callback) {} | |
| 1075 | |
| 1076 void ArcBluetoothBridge::AddDescriptor(int32_t service_handle, | |
| 1077 mojom::BluetoothUUIDPtr uuid, | |
| 1078 int32_t permissions, | |
| 1079 const AddDescriptorCallback& callback) {} | |
| 1080 | |
| 1081 void ArcBluetoothBridge::StartService(int32_t service_handle, | |
| 1082 const StartServiceCallback& callback) {} | |
| 1083 | |
| 1084 void ArcBluetoothBridge::StopService(int32_t service_handle, | |
| 1085 const StopServiceCallback& callback) {} | |
| 1086 | |
| 1087 void ArcBluetoothBridge::DeleteService(int32_t service_handle, | |
| 1088 const DeleteServiceCallback& callback) {} | |
| 1089 | |
| 1090 void ArcBluetoothBridge::SendIndication( | |
| 1091 int32_t attribute_handle, | |
| 1092 mojom::BluetoothAddressPtr address, | |
| 1093 bool confirm, | |
| 1094 mojo::Array<uint8_t> value, | |
| 1095 const SendIndicationCallback& callback) {} | |
| 1096 | |
| 1097 void ArcBluetoothBridge::SendResponse(int32_t trans_id, | |
| 1098 int32_t status, | |
| 1099 mojo::Array<uint8_t> value, | |
| 1100 const SendResponseCallback& callback) {} | |
| 1101 | |
| 1025 void ArcBluetoothBridge::OnDiscoveryError() { | 1102 void ArcBluetoothBridge::OnDiscoveryError() { |
| 1026 LOG(WARNING) << "failed to change discovery state"; | 1103 LOG(WARNING) << "failed to change discovery state"; |
| 1027 } | 1104 } |
| 1028 | 1105 |
| 1029 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const { | 1106 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const { |
| 1030 if (!HasBluetoothInstance()) | 1107 if (!HasBluetoothInstance()) |
| 1031 return; | 1108 return; |
| 1032 | 1109 |
| 1033 arc_bridge_service()->bluetooth()->instance()->OnBondStateChanged( | 1110 arc_bridge_service()->bluetooth()->instance()->OnBondStateChanged( |
| 1034 mojom::BluetoothStatus::SUCCESS, std::move(addr), | 1111 mojom::BluetoothStatus::SUCCESS, std::move(addr), |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1353 uint32_t version_need) const { | 1430 uint32_t version_need) const { |
| 1354 uint32_t version = arc_bridge_service()->bluetooth()->version(); | 1431 uint32_t version = arc_bridge_service()->bluetooth()->version(); |
| 1355 if (version >= version_need) | 1432 if (version >= version_need) |
| 1356 return true; | 1433 return true; |
| 1357 LOG(WARNING) << "Bluetooth instance is too old (version " << version | 1434 LOG(WARNING) << "Bluetooth instance is too old (version " << version |
| 1358 << ") need version " << version_need; | 1435 << ") need version " << version_need; |
| 1359 return false; | 1436 return false; |
| 1360 } | 1437 } |
| 1361 | 1438 |
| 1362 } // namespace arc | 1439 } // namespace arc |
| OLD | NEW |