OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "device/bluetooth/bluez/bluetooth_adapter_bluez.h" | 5 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstdint> | 8 #include <cstdint> |
9 #include <limits> | 9 #include <limits> |
10 #include <memory> | 10 #include <memory> |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
23 #include "base/time/time.h" | 23 #include "base/time/time.h" |
24 #include "build/build_config.h" | 24 #include "build/build_config.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_discovery_session_outcome.h" | 27 #include "device/bluetooth/bluetooth_discovery_session_outcome.h" |
28 #include "device/bluetooth/bluetooth_socket_thread.h" | 28 #include "device/bluetooth/bluetooth_socket_thread.h" |
29 #include "device/bluetooth/bluetooth_uuid.h" | 29 #include "device/bluetooth/bluetooth_uuid.h" |
30 #include "device/bluetooth/bluez/bluetooth_adapter_profile_bluez.h" | 30 #include "device/bluetooth/bluez/bluetooth_adapter_profile_bluez.h" |
31 #include "device/bluetooth/bluez/bluetooth_advertisement_bluez.h" | 31 #include "device/bluetooth/bluez/bluetooth_advertisement_bluez.h" |
32 #include "device/bluetooth/bluez/bluetooth_audio_sink_bluez.h" | |
33 #include "device/bluetooth/bluez/bluetooth_device_bluez.h" | 32 #include "device/bluetooth/bluez/bluetooth_device_bluez.h" |
34 #include "device/bluetooth/bluez/bluetooth_gatt_service_bluez.h" | 33 #include "device/bluetooth/bluez/bluetooth_gatt_service_bluez.h" |
35 #include "device/bluetooth/bluez/bluetooth_local_gatt_characteristic_bluez.h" | 34 #include "device/bluetooth/bluez/bluetooth_local_gatt_characteristic_bluez.h" |
36 #include "device/bluetooth/bluez/bluetooth_local_gatt_service_bluez.h" | 35 #include "device/bluetooth/bluez/bluetooth_local_gatt_service_bluez.h" |
37 #include "device/bluetooth/bluez/bluetooth_pairing_bluez.h" | 36 #include "device/bluetooth/bluez/bluetooth_pairing_bluez.h" |
38 #include "device/bluetooth/bluez/bluetooth_socket_bluez.h" | 37 #include "device/bluetooth/bluez/bluetooth_socket_bluez.h" |
39 #include "device/bluetooth/dbus/bluetooth_adapter_client.h" | 38 #include "device/bluetooth/dbus/bluetooth_adapter_client.h" |
40 #include "device/bluetooth/dbus/bluetooth_agent_manager_client.h" | 39 #include "device/bluetooth/dbus/bluetooth_agent_manager_client.h" |
41 #include "device/bluetooth/dbus/bluetooth_agent_service_provider.h" | 40 #include "device/bluetooth/dbus/bluetooth_agent_service_provider.h" |
42 #include "device/bluetooth/dbus/bluetooth_device_client.h" | 41 #include "device/bluetooth/dbus/bluetooth_device_client.h" |
43 #include "device/bluetooth/dbus/bluetooth_gatt_application_service_provider.h" | 42 #include "device/bluetooth/dbus/bluetooth_gatt_application_service_provider.h" |
44 #include "device/bluetooth/dbus/bluetooth_gatt_manager_client.h" | 43 #include "device/bluetooth/dbus/bluetooth_gatt_manager_client.h" |
45 #include "device/bluetooth/dbus/bluetooth_input_client.h" | 44 #include "device/bluetooth/dbus/bluetooth_input_client.h" |
46 #include "device/bluetooth/dbus/bluetooth_le_advertising_manager_client.h" | 45 #include "device/bluetooth/dbus/bluetooth_le_advertising_manager_client.h" |
47 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | 46 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
48 #include "third_party/cros_system_api/dbus/service_constants.h" | 47 #include "third_party/cros_system_api/dbus/service_constants.h" |
49 | 48 |
50 #if defined(OS_CHROMEOS) | 49 #if defined(OS_CHROMEOS) |
51 #include "chromeos/system/devicetype.h" | 50 #include "chromeos/system/devicetype.h" |
52 #endif | 51 #endif |
53 | 52 |
54 using device::BluetoothAdapter; | 53 using device::BluetoothAdapter; |
55 using device::BluetoothAudioSink; | |
56 using device::BluetoothDevice; | 54 using device::BluetoothDevice; |
57 using device::BluetoothDiscoveryFilter; | 55 using device::BluetoothDiscoveryFilter; |
58 using device::BluetoothSocket; | 56 using device::BluetoothSocket; |
59 using device::BluetoothUUID; | 57 using device::BluetoothUUID; |
60 using device::UMABluetoothDiscoverySessionOutcome; | 58 using device::UMABluetoothDiscoverySessionOutcome; |
61 | 59 |
62 namespace { | 60 namespace { |
63 | 61 |
64 // The agent path is relatively meaningless since BlueZ only permits one to | 62 // The agent path is relatively meaningless since BlueZ only permits one to |
65 // exist per D-Bus connection, it just has to be unique within Chromium. | 63 // exist per D-Bus connection, it just has to be unique within Chromium. |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 DCHECK(!dbus_is_shutdown_); | 433 DCHECK(!dbus_is_shutdown_); |
436 VLOG(1) << object_path_.value() | 434 VLOG(1) << object_path_.value() |
437 << ": Creating L2CAP service: " << uuid.canonical_value(); | 435 << ": Creating L2CAP service: " << uuid.canonical_value(); |
438 scoped_refptr<BluetoothSocketBlueZ> socket = | 436 scoped_refptr<BluetoothSocketBlueZ> socket = |
439 BluetoothSocketBlueZ::CreateBluetoothSocket(ui_task_runner_, | 437 BluetoothSocketBlueZ::CreateBluetoothSocket(ui_task_runner_, |
440 socket_thread_); | 438 socket_thread_); |
441 socket->Listen(this, BluetoothSocketBlueZ::kL2cap, uuid, options, | 439 socket->Listen(this, BluetoothSocketBlueZ::kL2cap, uuid, options, |
442 base::Bind(callback, socket), error_callback); | 440 base::Bind(callback, socket), error_callback); |
443 } | 441 } |
444 | 442 |
445 void BluetoothAdapterBlueZ::RegisterAudioSink( | |
446 const BluetoothAudioSink::Options& options, | |
447 const device::BluetoothAdapter::AcquiredCallback& callback, | |
448 const BluetoothAudioSink::ErrorCallback& error_callback) { | |
449 VLOG(1) << "Registering audio sink"; | |
450 if (!this->IsPresent()) { | |
451 error_callback.Run(BluetoothAudioSink::ERROR_INVALID_ADAPTER); | |
452 return; | |
453 } | |
454 scoped_refptr<BluetoothAudioSinkBlueZ> audio_sink( | |
455 new BluetoothAudioSinkBlueZ(this)); | |
456 audio_sink->Register(options, | |
457 base::Bind(&BluetoothAdapterBlueZ::OnRegisterAudioSink, | |
458 weak_ptr_factory_.GetWeakPtr(), callback, | |
459 error_callback, audio_sink), | |
460 error_callback); | |
461 } | |
462 | |
463 void BluetoothAdapterBlueZ::RegisterAdvertisement( | 443 void BluetoothAdapterBlueZ::RegisterAdvertisement( |
464 std::unique_ptr<device::BluetoothAdvertisement::Data> advertisement_data, | 444 std::unique_ptr<device::BluetoothAdvertisement::Data> advertisement_data, |
465 const CreateAdvertisementCallback& callback, | 445 const CreateAdvertisementCallback& callback, |
466 const AdvertisementErrorCallback& error_callback) { | 446 const AdvertisementErrorCallback& error_callback) { |
467 scoped_refptr<BluetoothAdvertisementBlueZ> advertisement( | 447 scoped_refptr<BluetoothAdvertisementBlueZ> advertisement( |
468 new BluetoothAdvertisementBlueZ(std::move(advertisement_data), this)); | 448 new BluetoothAdvertisementBlueZ(std::move(advertisement_data), this)); |
469 advertisement->Register(base::Bind(callback, advertisement), error_callback); | 449 advertisement->Register(base::Bind(callback, advertisement), error_callback); |
470 } | 450 } |
471 | 451 |
472 void BluetoothAdapterBlueZ::SetAdvertisingInterval( | 452 void BluetoothAdapterBlueZ::SetAdvertisingInterval( |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 VLOG(1) << "Pairing agent now default"; | 827 VLOG(1) << "Pairing agent now default"; |
848 } | 828 } |
849 | 829 |
850 void BluetoothAdapterBlueZ::OnRequestDefaultAgentError( | 830 void BluetoothAdapterBlueZ::OnRequestDefaultAgentError( |
851 const std::string& error_name, | 831 const std::string& error_name, |
852 const std::string& error_message) { | 832 const std::string& error_message) { |
853 LOG(WARNING) << ": Failed to make pairing agent default: " << error_name | 833 LOG(WARNING) << ": Failed to make pairing agent default: " << error_name |
854 << ": " << error_message; | 834 << ": " << error_message; |
855 } | 835 } |
856 | 836 |
857 void BluetoothAdapterBlueZ::OnRegisterAudioSink( | |
858 const device::BluetoothAdapter::AcquiredCallback& callback, | |
859 const device::BluetoothAudioSink::ErrorCallback& error_callback, | |
860 scoped_refptr<BluetoothAudioSink> audio_sink) { | |
861 if (!IsPresent()) { | |
862 VLOG(1) << "Failed to register audio sink, adapter not present"; | |
863 error_callback.Run(BluetoothAudioSink::ERROR_INVALID_ADAPTER); | |
864 return; | |
865 } | |
866 DCHECK(audio_sink.get()); | |
867 callback.Run(audio_sink); | |
868 } | |
869 | |
870 void BluetoothAdapterBlueZ::CreateServiceRecord( | 837 void BluetoothAdapterBlueZ::CreateServiceRecord( |
871 const BluetoothServiceRecordBlueZ& record, | 838 const BluetoothServiceRecordBlueZ& record, |
872 const ServiceRecordCallback& callback, | 839 const ServiceRecordCallback& callback, |
873 const ServiceRecordErrorCallback& error_callback) { | 840 const ServiceRecordErrorCallback& error_callback) { |
874 bluez::BluezDBusManager::Get() | 841 bluez::BluezDBusManager::Get() |
875 ->GetBluetoothAdapterClient() | 842 ->GetBluetoothAdapterClient() |
876 ->CreateServiceRecord( | 843 ->CreateServiceRecord( |
877 object_path_, record, callback, | 844 object_path_, record, callback, |
878 base::Bind(&BluetoothAdapterBlueZ::ServiceRecordErrorConnector, | 845 base::Bind(&BluetoothAdapterBlueZ::ServiceRecordErrorConnector, |
879 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 846 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1727 } else if (error_name == bluetooth_adapter::kErrorAlreadyExists) { | 1694 } else if (error_name == bluetooth_adapter::kErrorAlreadyExists) { |
1728 code = BluetoothServiceRecordBlueZ::ErrorCode::ERROR_RECORD_ALREADY_EXISTS; | 1695 code = BluetoothServiceRecordBlueZ::ErrorCode::ERROR_RECORD_ALREADY_EXISTS; |
1729 } else if (error_name == bluetooth_adapter::kErrorNotReady) { | 1696 } else if (error_name == bluetooth_adapter::kErrorNotReady) { |
1730 code = BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY; | 1697 code = BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY; |
1731 } | 1698 } |
1732 | 1699 |
1733 error_callback.Run(code); | 1700 error_callback.Run(code); |
1734 } | 1701 } |
1735 | 1702 |
1736 } // namespace bluez | 1703 } // namespace bluez |
OLD | NEW |