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 "chromeos/dbus/fake_bluetooth_device_client.h" | 5 #include "chromeos/dbus/fake_bluetooth_device_client.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <unistd.h> | 8 #include <unistd.h> |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 property->ReplaceValueWithSetValue(); | 213 property->ReplaceValueWithSetValue(); |
214 } else { | 214 } else { |
215 callback.Run(false); | 215 callback.Run(false); |
216 } | 216 } |
217 } | 217 } |
218 | 218 |
219 FakeBluetoothDeviceClient::FakeBluetoothDeviceClient() | 219 FakeBluetoothDeviceClient::FakeBluetoothDeviceClient() |
220 : simulation_interval_ms_(kSimulationIntervalMs), | 220 : simulation_interval_ms_(kSimulationIntervalMs), |
221 discovery_simulation_step_(0), | 221 discovery_simulation_step_(0), |
222 incoming_pairing_simulation_step_(0), | 222 incoming_pairing_simulation_step_(0), |
223 pairing_cancelled_(false) { | 223 pairing_cancelled_(false), |
| 224 connection_monitor_started_(false) { |
224 Properties* properties = new Properties(base::Bind( | 225 Properties* properties = new Properties(base::Bind( |
225 &FakeBluetoothDeviceClient::OnPropertyChanged, | 226 &FakeBluetoothDeviceClient::OnPropertyChanged, |
226 base::Unretained(this), | 227 base::Unretained(this), |
227 dbus::ObjectPath(kPairedDevicePath))); | 228 dbus::ObjectPath(kPairedDevicePath))); |
228 properties->address.ReplaceValue(kPairedDeviceAddress); | 229 properties->address.ReplaceValue(kPairedDeviceAddress); |
229 properties->bluetooth_class.ReplaceValue(kPairedDeviceClass); | 230 properties->bluetooth_class.ReplaceValue(kPairedDeviceClass); |
230 properties->name.ReplaceValue("Fake Device (Name)"); | 231 properties->name.ReplaceValue("Fake Device (Name)"); |
231 properties->alias.ReplaceValue(kPairedDeviceName); | 232 properties->alias.ReplaceValue(kPairedDeviceName); |
232 properties->paired.ReplaceValue(true); | 233 properties->paired.ReplaceValue(true); |
233 properties->trusted.ReplaceValue(true); | 234 properties->trusted.ReplaceValue(true); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 | 453 |
453 void FakeBluetoothDeviceClient::CancelPairing( | 454 void FakeBluetoothDeviceClient::CancelPairing( |
454 const dbus::ObjectPath& object_path, | 455 const dbus::ObjectPath& object_path, |
455 const base::Closure& callback, | 456 const base::Closure& callback, |
456 const ErrorCallback& error_callback) { | 457 const ErrorCallback& error_callback) { |
457 VLOG(1) << "CancelPairing: " << object_path.value(); | 458 VLOG(1) << "CancelPairing: " << object_path.value(); |
458 pairing_cancelled_ = true; | 459 pairing_cancelled_ = true; |
459 callback.Run(); | 460 callback.Run(); |
460 } | 461 } |
461 | 462 |
| 463 void FakeBluetoothDeviceClient::StartConnectionMonitor( |
| 464 const dbus::ObjectPath& object_path, |
| 465 const base::Closure& callback, |
| 466 const ErrorCallback& error_callback) { |
| 467 VLOG(1) << "StartConnectionMonitor: " << object_path.value(); |
| 468 connection_monitor_started_ = true; |
| 469 callback.Run(); |
| 470 } |
| 471 |
| 472 void FakeBluetoothDeviceClient::StopConnectionMonitor( |
| 473 const dbus::ObjectPath& object_path, |
| 474 const base::Closure& callback, |
| 475 const ErrorCallback& error_callback) { |
| 476 connection_monitor_started_ = false; |
| 477 callback.Run(); |
| 478 } |
462 | 479 |
463 void FakeBluetoothDeviceClient::BeginDiscoverySimulation( | 480 void FakeBluetoothDeviceClient::BeginDiscoverySimulation( |
464 const dbus::ObjectPath& adapter_path) { | 481 const dbus::ObjectPath& adapter_path) { |
465 VLOG(1) << "starting discovery simulation"; | 482 VLOG(1) << "starting discovery simulation"; |
466 | 483 |
467 discovery_simulation_step_ = 1; | 484 discovery_simulation_step_ = 1; |
468 | 485 |
469 base::MessageLoop::current()->PostDelayedTask( | 486 base::MessageLoop::current()->PostDelayedTask( |
470 FROM_HERE, | 487 FROM_HERE, |
471 base::Bind(&FakeBluetoothDeviceClient::DiscoverySimulationTimer, | 488 base::Bind(&FakeBluetoothDeviceClient::DiscoverySimulationTimer, |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 691 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
675 dbus::ObjectPath(kLegacyAutopairPath)); | 692 dbus::ObjectPath(kLegacyAutopairPath)); |
676 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 693 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
677 dbus::ObjectPath(kLowEnergyPath)); | 694 dbus::ObjectPath(kLowEnergyPath)); |
678 | 695 |
679 } else if (discovery_simulation_step_ == 4) { | 696 } else if (discovery_simulation_step_ == 4) { |
680 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 697 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
681 dbus::ObjectPath(kDisplayPinCodePath)); | 698 dbus::ObjectPath(kDisplayPinCodePath)); |
682 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 699 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
683 dbus::ObjectPath(kVanishingDevicePath)); | 700 dbus::ObjectPath(kVanishingDevicePath)); |
684 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), | 701 UpdateInquiryRSSI(dbus::ObjectPath(kLowEnergyPath), |
685 base::RandInt(kMinRSSI, kMaxRSSI)); | 702 base::RandInt(kMinRSSI, kMaxRSSI)); |
686 | 703 |
687 } else if (discovery_simulation_step_ == 7) { | 704 } else if (discovery_simulation_step_ == 7) { |
688 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 705 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
689 dbus::ObjectPath(kConnectUnpairablePath)); | 706 dbus::ObjectPath(kConnectUnpairablePath)); |
690 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), | 707 UpdateInquiryRSSI(dbus::ObjectPath(kLowEnergyPath), |
691 base::RandInt(kMinRSSI, kMaxRSSI)); | 708 base::RandInt(kMinRSSI, kMaxRSSI)); |
692 | 709 |
693 } else if (discovery_simulation_step_ == 8) { | 710 } else if (discovery_simulation_step_ == 8) { |
694 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 711 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
695 dbus::ObjectPath(kDisplayPasskeyPath)); | 712 dbus::ObjectPath(kDisplayPasskeyPath)); |
696 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 713 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
697 dbus::ObjectPath(kRequestPinCodePath)); | 714 dbus::ObjectPath(kRequestPinCodePath)); |
698 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), | 715 UpdateInquiryRSSI(dbus::ObjectPath(kLowEnergyPath), |
699 base::RandInt(kMinRSSI, kMaxRSSI)); | 716 base::RandInt(kMinRSSI, kMaxRSSI)); |
700 | 717 |
701 } else if (discovery_simulation_step_ == 10) { | 718 } else if (discovery_simulation_step_ == 10) { |
702 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 719 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
703 dbus::ObjectPath(kConfirmPasskeyPath)); | 720 dbus::ObjectPath(kConfirmPasskeyPath)); |
704 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 721 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
705 dbus::ObjectPath(kRequestPasskeyPath)); | 722 dbus::ObjectPath(kRequestPasskeyPath)); |
706 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 723 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
707 dbus::ObjectPath(kUnconnectableDevicePath)); | 724 dbus::ObjectPath(kUnconnectableDevicePath)); |
708 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 725 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
709 dbus::ObjectPath(kUnpairableDevicePath)); | 726 dbus::ObjectPath(kUnpairableDevicePath)); |
710 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 727 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
711 dbus::ObjectPath(kJustWorksPath)); | 728 dbus::ObjectPath(kJustWorksPath)); |
712 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), | 729 UpdateInquiryRSSI(dbus::ObjectPath(kLowEnergyPath), |
713 base::RandInt(kMinRSSI, kMaxRSSI)); | 730 base::RandInt(kMinRSSI, kMaxRSSI)); |
714 | 731 |
715 } else if (discovery_simulation_step_ == 13) { | 732 } else if (discovery_simulation_step_ == 13) { |
716 RemoveDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 733 RemoveDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
717 dbus::ObjectPath(kVanishingDevicePath)); | 734 dbus::ObjectPath(kVanishingDevicePath)); |
718 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), | 735 UpdateInquiryRSSI(dbus::ObjectPath(kLowEnergyPath), |
719 base::RandInt(kMinRSSI, kMaxRSSI)); | 736 base::RandInt(kMinRSSI, kMaxRSSI)); |
720 | 737 |
721 } else if (discovery_simulation_step_ == 14) { | 738 } else if (discovery_simulation_step_ == 14) { |
722 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), | 739 UpdateInquiryRSSI(dbus::ObjectPath(kLowEnergyPath), |
723 base::RandInt(kMinRSSI, kMaxRSSI)); | 740 base::RandInt(kMinRSSI, kMaxRSSI)); |
724 return; | 741 return; |
725 | 742 |
726 } | 743 } |
727 | 744 |
728 ++discovery_simulation_step_; | 745 ++discovery_simulation_step_; |
729 base::MessageLoop::current()->PostDelayedTask( | 746 base::MessageLoop::current()->PostDelayedTask( |
730 FROM_HERE, | 747 FROM_HERE, |
731 base::Bind(&FakeBluetoothDeviceClient::DiscoverySimulationTimer, | 748 base::Bind(&FakeBluetoothDeviceClient::DiscoverySimulationTimer, |
732 base::Unretained(this)), | 749 base::Unretained(this)), |
733 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); | 750 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 // If the paired device is a HID device based on it's bluetooth class, | 998 // If the paired device is a HID device based on it's bluetooth class, |
982 // simulate the Input interface. | 999 // simulate the Input interface. |
983 FakeBluetoothInputClient* fake_bluetooth_input_client = | 1000 FakeBluetoothInputClient* fake_bluetooth_input_client = |
984 static_cast<FakeBluetoothInputClient*>( | 1001 static_cast<FakeBluetoothInputClient*>( |
985 DBusThreadManager::Get()->GetBluetoothInputClient()); | 1002 DBusThreadManager::Get()->GetBluetoothInputClient()); |
986 | 1003 |
987 if ((properties->bluetooth_class.value() & 0x001f03) == 0x000500) | 1004 if ((properties->bluetooth_class.value() & 0x001f03) == 0x000500) |
988 fake_bluetooth_input_client->AddInputDevice(object_path); | 1005 fake_bluetooth_input_client->AddInputDevice(object_path); |
989 } | 1006 } |
990 | 1007 |
991 void FakeBluetoothDeviceClient::UpdateDeviceRSSI( | 1008 void FakeBluetoothDeviceClient::UpdateInquiryRSSI( |
992 const dbus::ObjectPath& object_path, | 1009 const dbus::ObjectPath& object_path, |
993 int16 rssi) { | 1010 int16 rssi) { |
994 PropertiesMap::iterator iter = properties_map_.find(object_path); | 1011 PropertiesMap::iterator iter = properties_map_.find(object_path); |
995 if (iter == properties_map_.end()) { | 1012 if (iter == properties_map_.end()) { |
996 VLOG(2) << "Fake device does not exist: " << object_path.value(); | 1013 VLOG(2) << "Fake device does not exist: " << object_path.value(); |
997 return; | 1014 return; |
998 } | 1015 } |
999 Properties* properties = iter->second; | 1016 Properties* properties = iter->second; |
1000 DCHECK(properties); | 1017 DCHECK(properties); |
1001 properties->rssi.ReplaceValue(rssi); | 1018 properties->inquiry_rssi.ReplaceValue(rssi); |
1002 } | 1019 } |
1003 | 1020 |
1004 void FakeBluetoothDeviceClient::PinCodeCallback( | 1021 void FakeBluetoothDeviceClient::PinCodeCallback( |
1005 const dbus::ObjectPath& object_path, | 1022 const dbus::ObjectPath& object_path, |
1006 const base::Closure& callback, | 1023 const base::Closure& callback, |
1007 const ErrorCallback& error_callback, | 1024 const ErrorCallback& error_callback, |
1008 BluetoothAgentServiceProvider::Delegate::Status status, | 1025 BluetoothAgentServiceProvider::Delegate::Status status, |
1009 const std::string& pincode) { | 1026 const std::string& pincode) { |
1010 VLOG(1) << "PinCodeCallback: " << object_path.value(); | 1027 VLOG(1) << "PinCodeCallback: " << object_path.value(); |
1011 | 1028 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1173 // TODO(keybuk): tear down this side of the connection | 1190 // TODO(keybuk): tear down this side of the connection |
1174 callback.Run(); | 1191 callback.Run(); |
1175 } else if (status == BluetoothProfileServiceProvider::Delegate::CANCELLED) { | 1192 } else if (status == BluetoothProfileServiceProvider::Delegate::CANCELLED) { |
1176 error_callback.Run(bluetooth_device::kErrorFailed, "Canceled"); | 1193 error_callback.Run(bluetooth_device::kErrorFailed, "Canceled"); |
1177 } else if (status == BluetoothProfileServiceProvider::Delegate::REJECTED) { | 1194 } else if (status == BluetoothProfileServiceProvider::Delegate::REJECTED) { |
1178 error_callback.Run(bluetooth_device::kErrorFailed, "Rejected"); | 1195 error_callback.Run(bluetooth_device::kErrorFailed, "Rejected"); |
1179 } | 1196 } |
1180 } | 1197 } |
1181 | 1198 |
1182 } // namespace chromeos | 1199 } // namespace chromeos |
OLD | NEW |