| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/dbus/fake_bluetooth_device_client.h" | 5 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
| 10 #include <sys/types.h> | 10 #include <sys/types.h> |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 connection_rssi_(kUnkownPower), | 308 connection_rssi_(kUnkownPower), |
| 309 transmit_power_(kUnkownPower), | 309 transmit_power_(kUnkownPower), |
| 310 max_transmit_power_(kUnkownPower), | 310 max_transmit_power_(kUnkownPower), |
| 311 delay_start_discovery_(false) { | 311 delay_start_discovery_(false) { |
| 312 std::unique_ptr<Properties> properties(new Properties( | 312 std::unique_ptr<Properties> properties(new Properties( |
| 313 base::Bind(&FakeBluetoothDeviceClient::OnPropertyChanged, | 313 base::Bind(&FakeBluetoothDeviceClient::OnPropertyChanged, |
| 314 base::Unretained(this), dbus::ObjectPath(kPairedDevicePath)))); | 314 base::Unretained(this), dbus::ObjectPath(kPairedDevicePath)))); |
| 315 properties->address.ReplaceValue(kPairedDeviceAddress); | 315 properties->address.ReplaceValue(kPairedDeviceAddress); |
| 316 properties->bluetooth_class.ReplaceValue(kPairedDeviceClass); | 316 properties->bluetooth_class.ReplaceValue(kPairedDeviceClass); |
| 317 properties->name.ReplaceValue(kPairedDeviceName); | 317 properties->name.ReplaceValue(kPairedDeviceName); |
| 318 properties->name.set_valid(true); |
| 318 properties->alias.ReplaceValue(kPairedDeviceAlias); | 319 properties->alias.ReplaceValue(kPairedDeviceAlias); |
| 319 properties->paired.ReplaceValue(true); | 320 properties->paired.ReplaceValue(true); |
| 320 properties->trusted.ReplaceValue(true); | 321 properties->trusted.ReplaceValue(true); |
| 321 properties->adapter.ReplaceValue( | 322 properties->adapter.ReplaceValue( |
| 322 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); | 323 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); |
| 323 | 324 |
| 324 std::vector<std::string> uuids; | 325 std::vector<std::string> uuids; |
| 325 uuids.push_back("00001800-0000-1000-8000-00805f9b34fb"); | 326 uuids.push_back("00001800-0000-1000-8000-00805f9b34fb"); |
| 326 uuids.push_back("00001801-0000-1000-8000-00805f9b34fb"); | 327 uuids.push_back("00001801-0000-1000-8000-00805f9b34fb"); |
| 327 properties->uuids.ReplaceValue(uuids); | 328 properties->uuids.ReplaceValue(uuids); |
| 328 | 329 |
| 329 properties->modalias.ReplaceValue("usb:v05ACp030Dd0306"); | 330 properties->modalias.ReplaceValue("usb:v05ACp030Dd0306"); |
| 330 | 331 |
| 331 properties_map_.insert(std::make_pair(dbus::ObjectPath(kPairedDevicePath), | 332 properties_map_.insert(std::make_pair(dbus::ObjectPath(kPairedDevicePath), |
| 332 std::move(properties))); | 333 std::move(properties))); |
| 333 device_list_.push_back(dbus::ObjectPath(kPairedDevicePath)); | 334 device_list_.push_back(dbus::ObjectPath(kPairedDevicePath)); |
| 334 | 335 |
| 335 properties.reset(new Properties(base::Bind( | 336 properties.reset(new Properties(base::Bind( |
| 336 &FakeBluetoothDeviceClient::OnPropertyChanged, base::Unretained(this), | 337 &FakeBluetoothDeviceClient::OnPropertyChanged, base::Unretained(this), |
| 337 dbus::ObjectPath(kPairedUnconnectableDevicePath)))); | 338 dbus::ObjectPath(kPairedUnconnectableDevicePath)))); |
| 338 properties->address.ReplaceValue(kPairedUnconnectableDeviceAddress); | 339 properties->address.ReplaceValue(kPairedUnconnectableDeviceAddress); |
| 339 properties->bluetooth_class.ReplaceValue(kPairedUnconnectableDeviceClass); | 340 properties->bluetooth_class.ReplaceValue(kPairedUnconnectableDeviceClass); |
| 340 properties->name.ReplaceValue(kPairedUnconnectableDeviceName); | 341 properties->name.ReplaceValue(kPairedUnconnectableDeviceName); |
| 342 properties->name.set_valid(true); |
| 341 properties->alias.ReplaceValue(kPairedUnconnectableDeviceAlias); | 343 properties->alias.ReplaceValue(kPairedUnconnectableDeviceAlias); |
| 342 properties->paired.ReplaceValue(true); | 344 properties->paired.ReplaceValue(true); |
| 343 properties->trusted.ReplaceValue(true); | 345 properties->trusted.ReplaceValue(true); |
| 344 properties->adapter.ReplaceValue( | 346 properties->adapter.ReplaceValue( |
| 345 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); | 347 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); |
| 346 | 348 |
| 347 properties->uuids.ReplaceValue(uuids); | 349 properties->uuids.ReplaceValue(uuids); |
| 348 | 350 |
| 349 properties->modalias.ReplaceValue("usb:v05ACp030Dd0306"); | 351 properties->modalias.ReplaceValue("usb:v05ACp030Dd0306"); |
| 350 | 352 |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 std::unique_ptr<Properties> properties( | 653 std::unique_ptr<Properties> properties( |
| 652 new Properties(base::Bind(&FakeBluetoothDeviceClient::OnPropertyChanged, | 654 new Properties(base::Bind(&FakeBluetoothDeviceClient::OnPropertyChanged, |
| 653 base::Unretained(this), device_path))); | 655 base::Unretained(this), device_path))); |
| 654 properties->adapter.ReplaceValue(adapter_path); | 656 properties->adapter.ReplaceValue(adapter_path); |
| 655 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeBredr); | 657 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeBredr); |
| 656 properties->type.set_valid(true); | 658 properties->type.set_valid(true); |
| 657 | 659 |
| 658 if (device_path == dbus::ObjectPath(kLegacyAutopairPath)) { | 660 if (device_path == dbus::ObjectPath(kLegacyAutopairPath)) { |
| 659 properties->address.ReplaceValue(kLegacyAutopairAddress); | 661 properties->address.ReplaceValue(kLegacyAutopairAddress); |
| 660 properties->bluetooth_class.ReplaceValue(kLegacyAutopairClass); | 662 properties->bluetooth_class.ReplaceValue(kLegacyAutopairClass); |
| 661 properties->name.ReplaceValue("LegacyAutopair"); | 663 properties->name.ReplaceValue(kLegacyAutopairName); |
| 662 properties->alias.ReplaceValue(kLegacyAutopairName); | 664 properties->name.set_valid(true); |
| 663 | 665 |
| 664 std::vector<std::string> uuids; | 666 std::vector<std::string> uuids; |
| 665 uuids.push_back("00001124-0000-1000-8000-00805f9b34fb"); | 667 uuids.push_back("00001124-0000-1000-8000-00805f9b34fb"); |
| 666 properties->uuids.ReplaceValue(uuids); | 668 properties->uuids.ReplaceValue(uuids); |
| 667 | 669 |
| 668 } else if (device_path == dbus::ObjectPath(kDisplayPinCodePath)) { | 670 } else if (device_path == dbus::ObjectPath(kDisplayPinCodePath)) { |
| 669 properties->address.ReplaceValue(kDisplayPinCodeAddress); | 671 properties->address.ReplaceValue(kDisplayPinCodeAddress); |
| 670 properties->bluetooth_class.ReplaceValue(kDisplayPinCodeClass); | 672 properties->bluetooth_class.ReplaceValue(kDisplayPinCodeClass); |
| 671 properties->name.ReplaceValue("DisplayPinCode"); | 673 properties->name.ReplaceValue(kDisplayPinCodeName); |
| 672 properties->alias.ReplaceValue(kDisplayPinCodeName); | 674 properties->name.set_valid(true); |
| 673 | 675 |
| 674 std::vector<std::string> uuids; | 676 std::vector<std::string> uuids; |
| 675 uuids.push_back("00001124-0000-1000-8000-00805f9b34fb"); | 677 uuids.push_back("00001124-0000-1000-8000-00805f9b34fb"); |
| 676 properties->uuids.ReplaceValue(uuids); | 678 properties->uuids.ReplaceValue(uuids); |
| 677 | 679 |
| 678 } else if (device_path == dbus::ObjectPath(kVanishingDevicePath)) { | 680 } else if (device_path == dbus::ObjectPath(kVanishingDevicePath)) { |
| 679 properties->address.ReplaceValue(kVanishingDeviceAddress); | 681 properties->address.ReplaceValue(kVanishingDeviceAddress); |
| 680 properties->bluetooth_class.ReplaceValue(kVanishingDeviceClass); | 682 properties->bluetooth_class.ReplaceValue(kVanishingDeviceClass); |
| 681 properties->name.ReplaceValue("VanishingDevice"); | 683 properties->name.ReplaceValue(kVanishingDeviceName); |
| 682 properties->alias.ReplaceValue(kVanishingDeviceName); | 684 properties->name.set_valid(true); |
| 683 | 685 |
| 684 } else if (device_path == dbus::ObjectPath(kConnectUnpairablePath)) { | 686 } else if (device_path == dbus::ObjectPath(kConnectUnpairablePath)) { |
| 685 properties->address.ReplaceValue(kConnectUnpairableAddress); | 687 properties->address.ReplaceValue(kConnectUnpairableAddress); |
| 686 properties->bluetooth_class.ReplaceValue(kConnectUnpairableClass); | 688 properties->bluetooth_class.ReplaceValue(kConnectUnpairableClass); |
| 687 properties->name.ReplaceValue("ConnectUnpairable"); | 689 properties->name.ReplaceValue(kConnectUnpairableName); |
| 688 properties->alias.ReplaceValue(kConnectUnpairableName); | 690 properties->name.set_valid(true); |
| 689 | 691 |
| 690 std::vector<std::string> uuids; | 692 std::vector<std::string> uuids; |
| 691 uuids.push_back("00001124-0000-1000-8000-00805f9b34fb"); | 693 uuids.push_back("00001124-0000-1000-8000-00805f9b34fb"); |
| 692 properties->uuids.ReplaceValue(uuids); | 694 properties->uuids.ReplaceValue(uuids); |
| 693 | 695 |
| 694 } else if (device_path == dbus::ObjectPath(kDisplayPasskeyPath)) { | 696 } else if (device_path == dbus::ObjectPath(kDisplayPasskeyPath)) { |
| 695 properties->address.ReplaceValue(kDisplayPasskeyAddress); | 697 properties->address.ReplaceValue(kDisplayPasskeyAddress); |
| 696 properties->bluetooth_class.ReplaceValue(kDisplayPasskeyClass); | 698 properties->bluetooth_class.ReplaceValue(kDisplayPasskeyClass); |
| 697 properties->name.ReplaceValue("DisplayPasskey"); | 699 properties->name.ReplaceValue(kDisplayPasskeyName); |
| 698 properties->alias.ReplaceValue(kDisplayPasskeyName); | 700 properties->name.set_valid(true); |
| 699 | 701 |
| 700 std::vector<std::string> uuids; | 702 std::vector<std::string> uuids; |
| 701 uuids.push_back("00001124-0000-1000-8000-00805f9b34fb"); | 703 uuids.push_back("00001124-0000-1000-8000-00805f9b34fb"); |
| 702 properties->uuids.ReplaceValue(uuids); | 704 properties->uuids.ReplaceValue(uuids); |
| 703 | 705 |
| 704 } else if (device_path == dbus::ObjectPath(kRequestPinCodePath)) { | 706 } else if (device_path == dbus::ObjectPath(kRequestPinCodePath)) { |
| 705 properties->address.ReplaceValue(kRequestPinCodeAddress); | 707 properties->address.ReplaceValue(kRequestPinCodeAddress); |
| 706 properties->bluetooth_class.ReplaceValue(kRequestPinCodeClass); | 708 properties->bluetooth_class.ReplaceValue(kRequestPinCodeClass); |
| 707 properties->name.ReplaceValue("RequestPinCode"); | 709 properties->name.ReplaceValue(kRequestPinCodeName); |
| 708 properties->alias.ReplaceValue(kRequestPinCodeName); | 710 properties->name.set_valid(true); |
| 709 | 711 |
| 710 } else if (device_path == dbus::ObjectPath(kConfirmPasskeyPath)) { | 712 } else if (device_path == dbus::ObjectPath(kConfirmPasskeyPath)) { |
| 711 properties->address.ReplaceValue(kConfirmPasskeyAddress); | 713 properties->address.ReplaceValue(kConfirmPasskeyAddress); |
| 712 properties->bluetooth_class.ReplaceValue(kConfirmPasskeyClass); | 714 properties->bluetooth_class.ReplaceValue(kConfirmPasskeyClass); |
| 713 properties->name.ReplaceValue("ConfirmPasskey"); | 715 properties->name.ReplaceValue(kConfirmPasskeyName); |
| 714 properties->alias.ReplaceValue(kConfirmPasskeyName); | 716 properties->name.set_valid(true); |
| 715 | 717 |
| 716 } else if (device_path == dbus::ObjectPath(kRequestPasskeyPath)) { | 718 } else if (device_path == dbus::ObjectPath(kRequestPasskeyPath)) { |
| 717 properties->address.ReplaceValue(kRequestPasskeyAddress); | 719 properties->address.ReplaceValue(kRequestPasskeyAddress); |
| 718 properties->bluetooth_class.ReplaceValue(kRequestPasskeyClass); | 720 properties->bluetooth_class.ReplaceValue(kRequestPasskeyClass); |
| 719 properties->name.ReplaceValue("RequestPasskey"); | 721 properties->name.ReplaceValue(kRequestPasskeyName); |
| 720 properties->alias.ReplaceValue(kRequestPasskeyName); | 722 properties->name.set_valid(true); |
| 721 | 723 |
| 722 } else if (device_path == dbus::ObjectPath(kUnconnectableDevicePath)) { | 724 } else if (device_path == dbus::ObjectPath(kUnconnectableDevicePath)) { |
| 723 properties->address.ReplaceValue(kUnconnectableDeviceAddress); | 725 properties->address.ReplaceValue(kUnconnectableDeviceAddress); |
| 724 properties->bluetooth_class.ReplaceValue(kUnconnectableDeviceClass); | 726 properties->bluetooth_class.ReplaceValue(kUnconnectableDeviceClass); |
| 725 properties->name.ReplaceValue("UnconnectableDevice"); | 727 properties->name.ReplaceValue(kUnconnectableDeviceName); |
| 726 properties->alias.ReplaceValue(kUnconnectableDeviceName); | 728 properties->name.set_valid(true); |
| 727 | 729 |
| 728 } else if (device_path == dbus::ObjectPath(kUnpairableDevicePath)) { | 730 } else if (device_path == dbus::ObjectPath(kUnpairableDevicePath)) { |
| 729 properties->address.ReplaceValue(kUnpairableDeviceAddress); | 731 properties->address.ReplaceValue(kUnpairableDeviceAddress); |
| 730 properties->bluetooth_class.ReplaceValue(kUnpairableDeviceClass); | 732 properties->bluetooth_class.ReplaceValue(kUnpairableDeviceClass); |
| 731 properties->name.ReplaceValue("Fake Unpairable Device"); | 733 properties->name.ReplaceValue(kUnpairableDeviceName); |
| 732 properties->alias.ReplaceValue(kUnpairableDeviceName); | 734 properties->name.set_valid(true); |
| 733 | 735 |
| 734 } else if (device_path == dbus::ObjectPath(kJustWorksPath)) { | 736 } else if (device_path == dbus::ObjectPath(kJustWorksPath)) { |
| 735 properties->address.ReplaceValue(kJustWorksAddress); | 737 properties->address.ReplaceValue(kJustWorksAddress); |
| 736 properties->bluetooth_class.ReplaceValue(kJustWorksClass); | 738 properties->bluetooth_class.ReplaceValue(kJustWorksClass); |
| 737 properties->name.ReplaceValue("JustWorks"); | 739 properties->name.ReplaceValue(kJustWorksName); |
| 738 properties->alias.ReplaceValue(kJustWorksName); | 740 properties->name.set_valid(true); |
| 739 | 741 |
| 740 } else if (device_path == dbus::ObjectPath(kLowEnergyPath)) { | 742 } else if (device_path == dbus::ObjectPath(kLowEnergyPath)) { |
| 741 properties->address.ReplaceValue(kLowEnergyAddress); | 743 properties->address.ReplaceValue(kLowEnergyAddress); |
| 742 properties->bluetooth_class.ReplaceValue(kLowEnergyClass); | 744 properties->bluetooth_class.ReplaceValue(kLowEnergyClass); |
| 743 properties->name.ReplaceValue("Heart Rate Monitor"); | 745 properties->name.ReplaceValue(kLowEnergyName); |
| 744 properties->alias.ReplaceValue(kLowEnergyName); | 746 properties->name.set_valid(true); |
| 745 properties->services_resolved.ReplaceValue(false); | 747 properties->services_resolved.ReplaceValue(false); |
| 746 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeLe); | 748 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeLe); |
| 747 | 749 |
| 748 std::vector<std::string> uuids; | 750 std::vector<std::string> uuids; |
| 749 uuids.push_back(FakeBluetoothGattServiceClient::kHeartRateServiceUUID); | 751 uuids.push_back(FakeBluetoothGattServiceClient::kHeartRateServiceUUID); |
| 750 properties->uuids.ReplaceValue(uuids); | 752 properties->uuids.ReplaceValue(uuids); |
| 751 } else if (device_path == | 753 } else if (device_path == |
| 752 dbus::ObjectPath(kConnectedTrustedNotPairedDevicePath)) { | 754 dbus::ObjectPath(kConnectedTrustedNotPairedDevicePath)) { |
| 753 properties->address.ReplaceValue(kConnectedTrustedNotPairedDeviceAddress); | 755 properties->address.ReplaceValue(kConnectedTrustedNotPairedDeviceAddress); |
| 754 properties->bluetooth_class.ReplaceValue( | 756 properties->bluetooth_class.ReplaceValue( |
| 755 kConnectedTrustedNotPairedDeviceClass); | 757 kConnectedTrustedNotPairedDeviceClass); |
| 756 properties->trusted.ReplaceValue(true); | 758 properties->trusted.ReplaceValue(true); |
| 757 properties->connected.ReplaceValue(true); | 759 properties->connected.ReplaceValue(true); |
| 758 properties->paired.ReplaceValue(false); | 760 properties->paired.ReplaceValue(false); |
| 759 properties->name.ReplaceValue("Connected Pairable Device"); | 761 properties->name.ReplaceValue(kConnectedTrustedNotPairedDeviceName); |
| 760 properties->alias.ReplaceValue(kConnectedTrustedNotPairedDeviceName); | 762 properties->name.set_valid(true); |
| 761 } else { | 763 } else { |
| 762 NOTREACHED(); | 764 NOTREACHED(); |
| 763 } | 765 } |
| 764 | 766 |
| 765 properties_map_.insert(std::make_pair(device_path, std::move(properties))); | 767 properties_map_.insert(std::make_pair(device_path, std::move(properties))); |
| 766 device_list_.push_back(device_path); | 768 device_list_.push_back(device_path); |
| 767 | 769 |
| 768 for (auto& observer : observers_) | 770 for (auto& observer : observers_) |
| 769 observer.DeviceAdded(device_path); | 771 observer.DeviceAdded(device_path); |
| 770 } | 772 } |
| 771 | 773 |
| 772 void FakeBluetoothDeviceClient::CreateDeviceWithProperties( | 774 void FakeBluetoothDeviceClient::CreateDeviceWithProperties( |
| 773 const dbus::ObjectPath& adapter_path, | 775 const dbus::ObjectPath& adapter_path, |
| 774 const IncomingDeviceProperties& props) { | 776 const IncomingDeviceProperties& props) { |
| 775 dbus::ObjectPath device_path(props.device_path); | 777 dbus::ObjectPath device_path(props.device_path); |
| 776 if (std::find(device_list_.begin(), device_list_.end(), device_path) != | 778 if (std::find(device_list_.begin(), device_list_.end(), device_path) != |
| 777 device_list_.end()) | 779 device_list_.end()) |
| 778 return; | 780 return; |
| 779 | 781 |
| 780 std::unique_ptr<Properties> properties( | 782 std::unique_ptr<Properties> properties( |
| 781 new Properties(base::Bind(&FakeBluetoothDeviceClient::OnPropertyChanged, | 783 new Properties(base::Bind(&FakeBluetoothDeviceClient::OnPropertyChanged, |
| 782 base::Unretained(this), device_path))); | 784 base::Unretained(this), device_path))); |
| 783 properties->adapter.ReplaceValue(adapter_path); | 785 properties->adapter.ReplaceValue(adapter_path); |
| 784 properties->name.ReplaceValue(props.device_name); | 786 properties->name.ReplaceValue(props.device_name); |
| 787 properties->name.set_valid(true); |
| 785 properties->alias.ReplaceValue(props.device_alias); | 788 properties->alias.ReplaceValue(props.device_alias); |
| 786 properties->address.ReplaceValue(props.device_address); | 789 properties->address.ReplaceValue(props.device_address); |
| 787 properties->bluetooth_class.ReplaceValue(props.device_class); | 790 properties->bluetooth_class.ReplaceValue(props.device_class); |
| 788 properties->trusted.ReplaceValue(props.is_trusted); | 791 properties->trusted.ReplaceValue(props.is_trusted); |
| 789 | 792 |
| 790 if (props.is_trusted) | 793 if (props.is_trusted) |
| 791 properties->paired.ReplaceValue(true); | 794 properties->paired.ReplaceValue(true); |
| 792 | 795 |
| 793 std::unique_ptr<SimulatedPairingOptions> options(new SimulatedPairingOptions); | 796 std::unique_ptr<SimulatedPairingOptions> options(new SimulatedPairingOptions); |
| 794 options->pairing_method = props.pairing_method; | 797 options->pairing_method = props.pairing_method; |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1051 const dbus::ObjectPath& adapter_path, | 1054 const dbus::ObjectPath& adapter_path, |
| 1052 const dbus::ObjectPath& device_path) { | 1055 const dbus::ObjectPath& device_path) { |
| 1053 std::vector<dbus::ObjectPath>::iterator listiter = | 1056 std::vector<dbus::ObjectPath>::iterator listiter = |
| 1054 std::find(device_list_.begin(), device_list_.end(), device_path); | 1057 std::find(device_list_.begin(), device_list_.end(), device_path); |
| 1055 if (listiter == device_list_.end()) | 1058 if (listiter == device_list_.end()) |
| 1056 return; | 1059 return; |
| 1057 | 1060 |
| 1058 PropertiesMap::const_iterator iter = properties_map_.find(device_path); | 1061 PropertiesMap::const_iterator iter = properties_map_.find(device_path); |
| 1059 Properties* properties = iter->second.get(); | 1062 Properties* properties = iter->second.get(); |
| 1060 | 1063 |
| 1061 VLOG(1) << "removing device: " << properties->alias.value(); | 1064 VLOG(1) << "removing device: " << properties->name.value(); |
| 1062 device_list_.erase(listiter); | 1065 device_list_.erase(listiter); |
| 1063 | 1066 |
| 1064 // Remove the Input interface if it exists. This should be called before the | 1067 // Remove the Input interface if it exists. This should be called before the |
| 1065 // BluetoothDeviceClient::Observer::DeviceRemoved because it deletes the | 1068 // BluetoothDeviceClient::Observer::DeviceRemoved because it deletes the |
| 1066 // BluetoothDeviceBlueZ object, including the device_path referenced here. | 1069 // BluetoothDeviceBlueZ object, including the device_path referenced here. |
| 1067 FakeBluetoothInputClient* fake_bluetooth_input_client = | 1070 FakeBluetoothInputClient* fake_bluetooth_input_client = |
| 1068 static_cast<FakeBluetoothInputClient*>( | 1071 static_cast<FakeBluetoothInputClient*>( |
| 1069 bluez::BluezDBusManager::Get()->GetBluetoothInputClient()); | 1072 bluez::BluezDBusManager::Get()->GetBluetoothInputClient()); |
| 1070 fake_bluetooth_input_client->RemoveInputDevice(device_path); | 1073 fake_bluetooth_input_client->RemoveInputDevice(device_path); |
| 1071 | 1074 |
| (...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1742 error_callback.Run(bluetooth_device::kErrorFailed, "Rejected"); | 1745 error_callback.Run(bluetooth_device::kErrorFailed, "Rejected"); |
| 1743 } | 1746 } |
| 1744 } | 1747 } |
| 1745 | 1748 |
| 1746 void FakeBluetoothDeviceClient::RemoveAllDevices() { | 1749 void FakeBluetoothDeviceClient::RemoveAllDevices() { |
| 1747 device_list_.clear(); | 1750 device_list_.clear(); |
| 1748 } | 1751 } |
| 1749 | 1752 |
| 1750 void FakeBluetoothDeviceClient::CreateTestDevice( | 1753 void FakeBluetoothDeviceClient::CreateTestDevice( |
| 1751 const dbus::ObjectPath& adapter_path, | 1754 const dbus::ObjectPath& adapter_path, |
| 1752 const std::string name, | 1755 const base::Optional<std::string> name, |
| 1753 const std::string alias, | 1756 const std::string alias, |
| 1754 const std::string device_address, | 1757 const std::string device_address, |
| 1755 const std::vector<std::string>& service_uuids, | 1758 const std::vector<std::string>& service_uuids, |
| 1756 device::BluetoothTransport type) { | 1759 device::BluetoothTransport type) { |
| 1757 // Create a random device path. | 1760 // Create a random device path. |
| 1758 dbus::ObjectPath device_path; | 1761 dbus::ObjectPath device_path; |
| 1759 do { | 1762 do { |
| 1760 device_path = dbus::ObjectPath(adapter_path.value() + "/dev" + | 1763 device_path = dbus::ObjectPath(adapter_path.value() + "/dev" + |
| 1761 base::RandBytesAsString(10)); | 1764 base::RandBytesAsString(10)); |
| 1762 } while (std::find(device_list_.begin(), device_list_.end(), device_path) != | 1765 } while (std::find(device_list_.begin(), device_list_.end(), device_path) != |
| 1763 device_list_.end()); | 1766 device_list_.end()); |
| 1764 | 1767 |
| 1765 std::unique_ptr<Properties> properties( | 1768 std::unique_ptr<Properties> properties( |
| 1766 new Properties(base::Bind(&FakeBluetoothDeviceClient::OnPropertyChanged, | 1769 new Properties(base::Bind(&FakeBluetoothDeviceClient::OnPropertyChanged, |
| 1767 base::Unretained(this), device_path))); | 1770 base::Unretained(this), device_path))); |
| 1768 properties->adapter.ReplaceValue(adapter_path); | 1771 properties->adapter.ReplaceValue(adapter_path); |
| 1769 | 1772 |
| 1770 properties->address.ReplaceValue(device_address); | 1773 properties->address.ReplaceValue(device_address); |
| 1771 properties->name.ReplaceValue(name); | 1774 properties->name.ReplaceValue( |
| 1775 name.value_or("Invalid Device Name set in " |
| 1776 "FakeBluetoothDeviceClient::CreateTestDevice")); |
| 1777 properties->name.set_valid(name.has_value()); |
| 1772 properties->alias.ReplaceValue(alias); | 1778 properties->alias.ReplaceValue(alias); |
| 1773 | 1779 |
| 1774 properties->uuids.ReplaceValue(service_uuids); | 1780 properties->uuids.ReplaceValue(service_uuids); |
| 1775 | 1781 |
| 1776 switch (type) { | 1782 switch (type) { |
| 1777 case device::BLUETOOTH_TRANSPORT_CLASSIC: | 1783 case device::BLUETOOTH_TRANSPORT_CLASSIC: |
| 1778 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeBredr); | 1784 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeBredr); |
| 1779 break; | 1785 break; |
| 1780 case device::BLUETOOTH_TRANSPORT_LE: | 1786 case device::BLUETOOTH_TRANSPORT_LE: |
| 1781 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeLe); | 1787 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeLe); |
| 1782 break; | 1788 break; |
| 1783 case device::BLUETOOTH_TRANSPORT_DUAL: | 1789 case device::BLUETOOTH_TRANSPORT_DUAL: |
| 1784 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeDual); | 1790 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeDual); |
| 1785 break; | 1791 break; |
| 1786 default: | 1792 default: |
| 1787 NOTREACHED(); | 1793 NOTREACHED(); |
| 1788 } | 1794 } |
| 1789 properties->type.set_valid(true); | 1795 properties->type.set_valid(true); |
| 1790 | 1796 |
| 1791 properties_map_.insert(std::make_pair(device_path, std::move(properties))); | 1797 properties_map_.insert(std::make_pair(device_path, std::move(properties))); |
| 1792 device_list_.push_back(device_path); | 1798 device_list_.push_back(device_path); |
| 1793 for (auto& observer : observers_) | 1799 for (auto& observer : observers_) |
| 1794 observer.DeviceAdded(device_path); | 1800 observer.DeviceAdded(device_path); |
| 1795 } | 1801 } |
| 1796 | 1802 |
| 1797 } // namespace bluez | 1803 } // namespace bluez |
| OLD | NEW |