| 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> |
| 11 | 11 |
| 12 #include <algorithm> | 12 #include <algorithm> |
| 13 #include <map> | 13 #include <map> |
| 14 #include <string> | 14 #include <string> |
| 15 #include <utility> | 15 #include <utility> |
| 16 #include <vector> | 16 #include <vector> |
| 17 | 17 |
| 18 #include "base/bind.h" | 18 #include "base/bind.h" |
| 19 #include "base/logging.h" | 19 #include "base/logging.h" |
| 20 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
| 21 #include "base/message_loop/message_loop.h" | 21 #include "base/message_loop/message_loop.h" |
| 22 #include "base/rand_util.h" |
| 22 #include "base/stl_util.h" | 23 #include "base/stl_util.h" |
| 23 #include "base/threading/worker_pool.h" | 24 #include "base/threading/worker_pool.h" |
| 24 #include "base/time/time.h" | 25 #include "base/time/time.h" |
| 25 #include "chromeos/dbus/dbus_thread_manager.h" | 26 #include "chromeos/dbus/dbus_thread_manager.h" |
| 26 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" | 27 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" |
| 27 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" | 28 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" |
| 28 #include "chromeos/dbus/fake_bluetooth_agent_service_provider.h" | 29 #include "chromeos/dbus/fake_bluetooth_agent_service_provider.h" |
| 30 #include "chromeos/dbus/fake_bluetooth_gatt_service_client.h" |
| 29 #include "chromeos/dbus/fake_bluetooth_input_client.h" | 31 #include "chromeos/dbus/fake_bluetooth_input_client.h" |
| 30 #include "chromeos/dbus/fake_bluetooth_profile_manager_client.h" | 32 #include "chromeos/dbus/fake_bluetooth_profile_manager_client.h" |
| 31 #include "chromeos/dbus/fake_bluetooth_profile_service_provider.h" | 33 #include "chromeos/dbus/fake_bluetooth_profile_service_provider.h" |
| 32 #include "dbus/file_descriptor.h" | 34 #include "dbus/file_descriptor.h" |
| 33 #include "dbus/object_path.h" | 35 #include "dbus/object_path.h" |
| 34 #include "third_party/cros_system_api/dbus/service_constants.h" | 36 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 35 | 37 |
| 36 namespace { | 38 namespace { |
| 37 | 39 |
| 38 // Default interval between simulated events. | 40 // Default interval between simulated events. |
| 39 const int kSimulationIntervalMs = 750; | 41 const int kSimulationIntervalMs = 750; |
| 40 | 42 |
| 43 // Minimum and maximum bounds for randomly generated RSSI values. |
| 44 const int kMinRSSI = -90; |
| 45 const int kMaxRSSI = -30; |
| 46 |
| 41 | 47 |
| 42 void SimulatedProfileSocket(int fd) { | 48 void SimulatedProfileSocket(int fd) { |
| 43 // Simulate a server-side socket of a profile; read data from the socket, | 49 // Simulate a server-side socket of a profile; read data from the socket, |
| 44 // write it back, and then close. | 50 // write it back, and then close. |
| 45 char buf[1024]; | 51 char buf[1024]; |
| 46 ssize_t len; | 52 ssize_t len; |
| 47 ssize_t count; | 53 ssize_t count; |
| 48 | 54 |
| 49 len = read(fd, buf, sizeof buf); | 55 len = read(fd, buf, sizeof buf); |
| 50 if (len < 0) { | 56 if (len < 0) { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 const uint32 FakeBluetoothDeviceClient::kUnpairableDeviceClass = 0x002540; | 166 const uint32 FakeBluetoothDeviceClient::kUnpairableDeviceClass = 0x002540; |
| 161 | 167 |
| 162 const char FakeBluetoothDeviceClient::kJustWorksPath[] = | 168 const char FakeBluetoothDeviceClient::kJustWorksPath[] = |
| 163 "/fake/hci0/devB"; | 169 "/fake/hci0/devB"; |
| 164 const char FakeBluetoothDeviceClient::kJustWorksAddress[] = | 170 const char FakeBluetoothDeviceClient::kJustWorksAddress[] = |
| 165 "00:0C:8A:00:00:00"; | 171 "00:0C:8A:00:00:00"; |
| 166 const char FakeBluetoothDeviceClient::kJustWorksName[] = | 172 const char FakeBluetoothDeviceClient::kJustWorksName[] = |
| 167 "Just-Works Device"; | 173 "Just-Works Device"; |
| 168 const uint32 FakeBluetoothDeviceClient::kJustWorksClass = 0x240428; | 174 const uint32 FakeBluetoothDeviceClient::kJustWorksClass = 0x240428; |
| 169 | 175 |
| 176 const char FakeBluetoothDeviceClient::kLowEnergyPath[] = |
| 177 "/fake/hci0/devC"; |
| 178 const char FakeBluetoothDeviceClient::kLowEnergyAddress[] = |
| 179 "00:1A:11:00:15:30"; |
| 180 const char FakeBluetoothDeviceClient::kLowEnergyName[] = |
| 181 "Bluetooth 4.0 Heart Rate Monitor"; |
| 182 const uint32 FakeBluetoothDeviceClient::kLowEnergyClass = |
| 183 0x000918; // Major class "Health", Minor class "Heart/Pulse Rate Monitor." |
| 184 |
| 170 FakeBluetoothDeviceClient::Properties::Properties( | 185 FakeBluetoothDeviceClient::Properties::Properties( |
| 171 const PropertyChangedCallback& callback) | 186 const PropertyChangedCallback& callback) |
| 172 : BluetoothDeviceClient::Properties( | 187 : BluetoothDeviceClient::Properties( |
| 173 NULL, | 188 NULL, |
| 174 bluetooth_device::kBluetoothDeviceInterface, | 189 bluetooth_device::kBluetoothDeviceInterface, |
| 175 callback) { | 190 callback) { |
| 176 } | 191 } |
| 177 | 192 |
| 178 FakeBluetoothDeviceClient::Properties::~Properties() { | 193 FakeBluetoothDeviceClient::Properties::~Properties() { |
| 179 } | 194 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 // Must not be paired | 301 // Must not be paired |
| 287 error_callback.Run(bluetooth_device::kErrorFailed, | 302 error_callback.Run(bluetooth_device::kErrorFailed, |
| 288 "Connection fails while paired"); | 303 "Connection fails while paired"); |
| 289 return; | 304 return; |
| 290 } | 305 } |
| 291 | 306 |
| 292 // The device can be connected. | 307 // The device can be connected. |
| 293 properties->connected.ReplaceValue(true); | 308 properties->connected.ReplaceValue(true); |
| 294 callback.Run(); | 309 callback.Run(); |
| 295 | 310 |
| 311 // Expose GATT services if connected to LE device. |
| 312 if (object_path == dbus::ObjectPath(kLowEnergyPath)) { |
| 313 FakeBluetoothGattServiceClient* gatt_service_client = |
| 314 static_cast<FakeBluetoothGattServiceClient*>( |
| 315 DBusThreadManager::Get()->GetBluetoothGattServiceClient()); |
| 316 gatt_service_client->ExposeHeartRateService( |
| 317 dbus::ObjectPath(kLowEnergyPath)); |
| 318 } |
| 319 |
| 296 AddInputDeviceIfNeeded(object_path, properties); | 320 AddInputDeviceIfNeeded(object_path, properties); |
| 297 } | 321 } |
| 298 | 322 |
| 299 void FakeBluetoothDeviceClient::Disconnect( | 323 void FakeBluetoothDeviceClient::Disconnect( |
| 300 const dbus::ObjectPath& object_path, | 324 const dbus::ObjectPath& object_path, |
| 301 const base::Closure& callback, | 325 const base::Closure& callback, |
| 302 const ErrorCallback& error_callback) { | 326 const ErrorCallback& error_callback) { |
| 303 VLOG(1) << "Disconnect: " << object_path.value(); | 327 VLOG(1) << "Disconnect: " << object_path.value(); |
| 304 Properties* properties = GetProperties(object_path); | 328 Properties* properties = GetProperties(object_path); |
| 305 | 329 |
| 306 if (properties->connected.value() == true) { | 330 if (!properties->connected.value()) { |
| 307 callback.Run(); | |
| 308 properties->connected.ReplaceValue(false); | |
| 309 } else { | |
| 310 error_callback.Run("org.bluez.Error.NotConnected", "Not Connected"); | 331 error_callback.Run("org.bluez.Error.NotConnected", "Not Connected"); |
| 332 return; |
| 311 } | 333 } |
| 334 |
| 335 // Hide the Heart Rate Service if disconnected from LE device. |
| 336 if (object_path == dbus::ObjectPath(kLowEnergyPath)) { |
| 337 FakeBluetoothGattServiceClient* gatt_service_client = |
| 338 static_cast<FakeBluetoothGattServiceClient*>( |
| 339 DBusThreadManager::Get()->GetBluetoothGattServiceClient()); |
| 340 gatt_service_client->HideHeartRateService(); |
| 341 } |
| 342 |
| 343 callback.Run(); |
| 344 properties->connected.ReplaceValue(false); |
| 312 } | 345 } |
| 313 | 346 |
| 314 void FakeBluetoothDeviceClient::ConnectProfile( | 347 void FakeBluetoothDeviceClient::ConnectProfile( |
| 315 const dbus::ObjectPath& object_path, | 348 const dbus::ObjectPath& object_path, |
| 316 const std::string& uuid, | 349 const std::string& uuid, |
| 317 const base::Closure& callback, | 350 const base::Closure& callback, |
| 318 const ErrorCallback& error_callback) { | 351 const ErrorCallback& error_callback) { |
| 319 VLOG(1) << "ConnectProfile: " << object_path.value() << " " << uuid; | 352 VLOG(1) << "ConnectProfile: " << object_path.value() << " " << uuid; |
| 320 | 353 |
| 321 FakeBluetoothProfileManagerClient* fake_bluetooth_profile_manager_client = | 354 FakeBluetoothProfileManagerClient* fake_bluetooth_profile_manager_client = |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 properties->bluetooth_class.ReplaceValue(kUnpairableDeviceClass); | 590 properties->bluetooth_class.ReplaceValue(kUnpairableDeviceClass); |
| 558 properties->name.ReplaceValue("Fake Unpairable Device"); | 591 properties->name.ReplaceValue("Fake Unpairable Device"); |
| 559 properties->alias.ReplaceValue(kUnpairableDeviceName); | 592 properties->alias.ReplaceValue(kUnpairableDeviceName); |
| 560 | 593 |
| 561 } else if (device_path == dbus::ObjectPath(kJustWorksPath)) { | 594 } else if (device_path == dbus::ObjectPath(kJustWorksPath)) { |
| 562 properties->address.ReplaceValue(kJustWorksAddress); | 595 properties->address.ReplaceValue(kJustWorksAddress); |
| 563 properties->bluetooth_class.ReplaceValue(kJustWorksClass); | 596 properties->bluetooth_class.ReplaceValue(kJustWorksClass); |
| 564 properties->name.ReplaceValue("JustWorks"); | 597 properties->name.ReplaceValue("JustWorks"); |
| 565 properties->alias.ReplaceValue(kJustWorksName); | 598 properties->alias.ReplaceValue(kJustWorksName); |
| 566 | 599 |
| 600 } else if (device_path == dbus::ObjectPath(kLowEnergyPath)) { |
| 601 properties->address.ReplaceValue(kLowEnergyAddress); |
| 602 properties->bluetooth_class.ReplaceValue(kLowEnergyClass); |
| 603 properties->name.ReplaceValue("Heart Rate Monitor"); |
| 604 properties->alias.ReplaceValue(kLowEnergyName); |
| 605 |
| 606 std::vector<std::string> uuids; |
| 607 uuids.push_back(FakeBluetoothGattServiceClient::kHeartRateServiceUUID); |
| 608 properties->uuids.ReplaceValue(uuids); |
| 609 |
| 567 } else { | 610 } else { |
| 568 NOTREACHED(); | 611 NOTREACHED(); |
| 569 | 612 |
| 570 } | 613 } |
| 571 | 614 |
| 572 properties_map_[device_path] = properties; | 615 properties_map_[device_path] = properties; |
| 573 device_list_.push_back(device_path); | 616 device_list_.push_back(device_path); |
| 574 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, | 617 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, |
| 575 DeviceAdded(device_path)); | 618 DeviceAdded(device_path)); |
| 576 } | 619 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 590 device_list_.erase(listiter); | 633 device_list_.erase(listiter); |
| 591 | 634 |
| 592 // Remove the Input interface if it exists. This should be called before the | 635 // Remove the Input interface if it exists. This should be called before the |
| 593 // BluetoothDeviceClient::Observer::DeviceRemoved because it deletes the | 636 // BluetoothDeviceClient::Observer::DeviceRemoved because it deletes the |
| 594 // BluetoothDeviceChromeOS object, including the device_path referenced here. | 637 // BluetoothDeviceChromeOS object, including the device_path referenced here. |
| 595 FakeBluetoothInputClient* fake_bluetooth_input_client = | 638 FakeBluetoothInputClient* fake_bluetooth_input_client = |
| 596 static_cast<FakeBluetoothInputClient*>( | 639 static_cast<FakeBluetoothInputClient*>( |
| 597 DBusThreadManager::Get()->GetBluetoothInputClient()); | 640 DBusThreadManager::Get()->GetBluetoothInputClient()); |
| 598 fake_bluetooth_input_client->RemoveInputDevice(device_path); | 641 fake_bluetooth_input_client->RemoveInputDevice(device_path); |
| 599 | 642 |
| 643 if (device_path == dbus::ObjectPath(kLowEnergyPath)) { |
| 644 FakeBluetoothGattServiceClient* gatt_service_client = |
| 645 static_cast<FakeBluetoothGattServiceClient*>( |
| 646 DBusThreadManager::Get()->GetBluetoothGattServiceClient()); |
| 647 gatt_service_client->HideHeartRateService(); |
| 648 } |
| 649 |
| 600 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, | 650 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, |
| 601 DeviceRemoved(device_path)); | 651 DeviceRemoved(device_path)); |
| 602 | 652 |
| 603 delete properties; | 653 delete properties; |
| 604 properties_map_.erase(iter); | 654 properties_map_.erase(iter); |
| 605 } | 655 } |
| 606 | 656 |
| 607 void FakeBluetoothDeviceClient::OnPropertyChanged( | 657 void FakeBluetoothDeviceClient::OnPropertyChanged( |
| 608 const dbus::ObjectPath& object_path, | 658 const dbus::ObjectPath& object_path, |
| 609 const std::string& property_name) { | 659 const std::string& property_name) { |
| 660 VLOG(2) << "Fake Bluetooth device property changed: " << object_path.value() |
| 661 << ": " << property_name; |
| 610 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, | 662 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, |
| 611 DevicePropertyChanged(object_path, property_name)); | 663 DevicePropertyChanged(object_path, property_name)); |
| 612 } | 664 } |
| 613 | 665 |
| 614 void FakeBluetoothDeviceClient::DiscoverySimulationTimer() { | 666 void FakeBluetoothDeviceClient::DiscoverySimulationTimer() { |
| 615 if (!discovery_simulation_step_) | 667 if (!discovery_simulation_step_) |
| 616 return; | 668 return; |
| 617 | 669 |
| 618 // Timer fires every .75s, the numbers below are arbitrary to give a feel | 670 // Timer fires every .75s, the numbers below are arbitrary to give a feel |
| 619 // for a discovery process. | 671 // for a discovery process. |
| 620 VLOG(1) << "discovery simulation, step " << discovery_simulation_step_; | 672 VLOG(1) << "discovery simulation, step " << discovery_simulation_step_; |
| 621 if (discovery_simulation_step_ == 2) { | 673 if (discovery_simulation_step_ == 2) { |
| 622 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 674 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 623 dbus::ObjectPath(kLegacyAutopairPath)); | 675 dbus::ObjectPath(kLegacyAutopairPath)); |
| 676 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 677 dbus::ObjectPath(kLowEnergyPath)); |
| 624 | 678 |
| 625 } else if (discovery_simulation_step_ == 4) { | 679 } else if (discovery_simulation_step_ == 4) { |
| 626 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 680 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 627 dbus::ObjectPath(kDisplayPinCodePath)); | 681 dbus::ObjectPath(kDisplayPinCodePath)); |
| 628 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 682 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 629 dbus::ObjectPath(kVanishingDevicePath)); | 683 dbus::ObjectPath(kVanishingDevicePath)); |
| 684 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), |
| 685 base::RandInt(kMinRSSI, kMaxRSSI)); |
| 630 | 686 |
| 631 } else if (discovery_simulation_step_ == 7) { | 687 } else if (discovery_simulation_step_ == 7) { |
| 632 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 688 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 633 dbus::ObjectPath(kConnectUnpairablePath)); | 689 dbus::ObjectPath(kConnectUnpairablePath)); |
| 690 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), |
| 691 base::RandInt(kMinRSSI, kMaxRSSI)); |
| 634 | 692 |
| 635 } else if (discovery_simulation_step_ == 8) { | 693 } else if (discovery_simulation_step_ == 8) { |
| 636 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 694 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 637 dbus::ObjectPath(kDisplayPasskeyPath)); | 695 dbus::ObjectPath(kDisplayPasskeyPath)); |
| 638 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 696 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 639 dbus::ObjectPath(kRequestPinCodePath)); | 697 dbus::ObjectPath(kRequestPinCodePath)); |
| 698 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), |
| 699 base::RandInt(kMinRSSI, kMaxRSSI)); |
| 640 | 700 |
| 641 } else if (discovery_simulation_step_ == 10) { | 701 } else if (discovery_simulation_step_ == 10) { |
| 642 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 702 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 643 dbus::ObjectPath(kConfirmPasskeyPath)); | 703 dbus::ObjectPath(kConfirmPasskeyPath)); |
| 644 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 704 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 645 dbus::ObjectPath(kRequestPasskeyPath)); | 705 dbus::ObjectPath(kRequestPasskeyPath)); |
| 646 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 706 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 647 dbus::ObjectPath(kUnconnectableDevicePath)); | 707 dbus::ObjectPath(kUnconnectableDevicePath)); |
| 648 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 708 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 649 dbus::ObjectPath(kUnpairableDevicePath)); | 709 dbus::ObjectPath(kUnpairableDevicePath)); |
| 650 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 710 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 651 dbus::ObjectPath(kJustWorksPath)); | 711 dbus::ObjectPath(kJustWorksPath)); |
| 712 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), |
| 713 base::RandInt(kMinRSSI, kMaxRSSI)); |
| 652 | 714 |
| 653 } else if (discovery_simulation_step_ == 13) { | 715 } else if (discovery_simulation_step_ == 13) { |
| 654 RemoveDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 716 RemoveDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 655 dbus::ObjectPath(kVanishingDevicePath)); | 717 dbus::ObjectPath(kVanishingDevicePath)); |
| 718 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), |
| 719 base::RandInt(kMinRSSI, kMaxRSSI)); |
| 656 | 720 |
| 657 } else if (discovery_simulation_step_ == 14) { | 721 } else if (discovery_simulation_step_ == 14) { |
| 722 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), |
| 723 base::RandInt(kMinRSSI, kMaxRSSI)); |
| 658 return; | 724 return; |
| 659 | 725 |
| 660 } | 726 } |
| 661 | 727 |
| 662 ++discovery_simulation_step_; | 728 ++discovery_simulation_step_; |
| 663 base::MessageLoop::current()->PostDelayedTask( | 729 base::MessageLoop::current()->PostDelayedTask( |
| 664 FROM_HERE, | 730 FROM_HERE, |
| 665 base::Bind(&FakeBluetoothDeviceClient::DiscoverySimulationTimer, | 731 base::Bind(&FakeBluetoothDeviceClient::DiscoverySimulationTimer, |
| 666 base::Unretained(this)), | 732 base::Unretained(this)), |
| 667 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); | 733 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 | 803 |
| 738 FakeBluetoothAgentManagerClient* fake_bluetooth_agent_manager_client = | 804 FakeBluetoothAgentManagerClient* fake_bluetooth_agent_manager_client = |
| 739 static_cast<FakeBluetoothAgentManagerClient*>( | 805 static_cast<FakeBluetoothAgentManagerClient*>( |
| 740 DBusThreadManager::Get()->GetBluetoothAgentManagerClient()); | 806 DBusThreadManager::Get()->GetBluetoothAgentManagerClient()); |
| 741 FakeBluetoothAgentServiceProvider* agent_service_provider = | 807 FakeBluetoothAgentServiceProvider* agent_service_provider = |
| 742 fake_bluetooth_agent_manager_client->GetAgentServiceProvider(); | 808 fake_bluetooth_agent_manager_client->GetAgentServiceProvider(); |
| 743 CHECK(agent_service_provider != NULL); | 809 CHECK(agent_service_provider != NULL); |
| 744 | 810 |
| 745 if (object_path == dbus::ObjectPath(kLegacyAutopairPath) || | 811 if (object_path == dbus::ObjectPath(kLegacyAutopairPath) || |
| 746 object_path == dbus::ObjectPath(kConnectUnpairablePath) || | 812 object_path == dbus::ObjectPath(kConnectUnpairablePath) || |
| 747 object_path == dbus::ObjectPath(kUnconnectableDevicePath)) { | 813 object_path == dbus::ObjectPath(kUnconnectableDevicePath) || |
| 814 object_path == dbus::ObjectPath(kLowEnergyPath)) { |
| 748 // No need to call anything on the pairing delegate, just wait 3 times | 815 // No need to call anything on the pairing delegate, just wait 3 times |
| 749 // the interval before acting as if the other end accepted it. | 816 // the interval before acting as if the other end accepted it. |
| 750 base::MessageLoop::current()->PostDelayedTask( | 817 base::MessageLoop::current()->PostDelayedTask( |
| 751 FROM_HERE, | 818 FROM_HERE, |
| 752 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, | 819 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, |
| 753 base::Unretained(this), | 820 base::Unretained(this), |
| 754 object_path, callback, error_callback), | 821 object_path, callback, error_callback), |
| 755 base::TimeDelta::FromMilliseconds(3 * simulation_interval_ms_)); | 822 base::TimeDelta::FromMilliseconds(3 * simulation_interval_ms_)); |
| 756 | 823 |
| 757 } else if (object_path == dbus::ObjectPath(kDisplayPinCodePath)) { | 824 } else if (object_path == dbus::ObjectPath(kDisplayPinCodePath)) { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 // If the paired device is a HID device based on it's bluetooth class, | 981 // If the paired device is a HID device based on it's bluetooth class, |
| 915 // simulate the Input interface. | 982 // simulate the Input interface. |
| 916 FakeBluetoothInputClient* fake_bluetooth_input_client = | 983 FakeBluetoothInputClient* fake_bluetooth_input_client = |
| 917 static_cast<FakeBluetoothInputClient*>( | 984 static_cast<FakeBluetoothInputClient*>( |
| 918 DBusThreadManager::Get()->GetBluetoothInputClient()); | 985 DBusThreadManager::Get()->GetBluetoothInputClient()); |
| 919 | 986 |
| 920 if ((properties->bluetooth_class.value() & 0x001f03) == 0x000500) | 987 if ((properties->bluetooth_class.value() & 0x001f03) == 0x000500) |
| 921 fake_bluetooth_input_client->AddInputDevice(object_path); | 988 fake_bluetooth_input_client->AddInputDevice(object_path); |
| 922 } | 989 } |
| 923 | 990 |
| 991 void FakeBluetoothDeviceClient::UpdateDeviceRSSI( |
| 992 const dbus::ObjectPath& object_path, |
| 993 int16 rssi) { |
| 994 PropertiesMap::iterator iter = properties_map_.find(object_path); |
| 995 if (iter == properties_map_.end()) { |
| 996 VLOG(2) << "Fake device does not exist: " << object_path.value(); |
| 997 return; |
| 998 } |
| 999 Properties* properties = iter->second; |
| 1000 DCHECK(properties); |
| 1001 properties->rssi.ReplaceValue(rssi); |
| 1002 } |
| 1003 |
| 924 void FakeBluetoothDeviceClient::PinCodeCallback( | 1004 void FakeBluetoothDeviceClient::PinCodeCallback( |
| 925 const dbus::ObjectPath& object_path, | 1005 const dbus::ObjectPath& object_path, |
| 926 const base::Closure& callback, | 1006 const base::Closure& callback, |
| 927 const ErrorCallback& error_callback, | 1007 const ErrorCallback& error_callback, |
| 928 BluetoothAgentServiceProvider::Delegate::Status status, | 1008 BluetoothAgentServiceProvider::Delegate::Status status, |
| 929 const std::string& pincode) { | 1009 const std::string& pincode) { |
| 930 VLOG(1) << "PinCodeCallback: " << object_path.value(); | 1010 VLOG(1) << "PinCodeCallback: " << object_path.value(); |
| 931 | 1011 |
| 932 if (status == BluetoothAgentServiceProvider::Delegate::SUCCESS) { | 1012 if (status == BluetoothAgentServiceProvider::Delegate::SUCCESS) { |
| 933 base::MessageLoop::current()->PostDelayedTask( | 1013 base::MessageLoop::current()->PostDelayedTask( |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1093 // TODO(keybuk): tear down this side of the connection | 1173 // TODO(keybuk): tear down this side of the connection |
| 1094 callback.Run(); | 1174 callback.Run(); |
| 1095 } else if (status == BluetoothProfileServiceProvider::Delegate::CANCELLED) { | 1175 } else if (status == BluetoothProfileServiceProvider::Delegate::CANCELLED) { |
| 1096 error_callback.Run(bluetooth_device::kErrorFailed, "Canceled"); | 1176 error_callback.Run(bluetooth_device::kErrorFailed, "Canceled"); |
| 1097 } else if (status == BluetoothProfileServiceProvider::Delegate::REJECTED) { | 1177 } else if (status == BluetoothProfileServiceProvider::Delegate::REJECTED) { |
| 1098 error_callback.Run(bluetooth_device::kErrorFailed, "Rejected"); | 1178 error_callback.Run(bluetooth_device::kErrorFailed, "Rejected"); |
| 1099 } | 1179 } |
| 1100 } | 1180 } |
| 1101 | 1181 |
| 1102 } // namespace chromeos | 1182 } // namespace chromeos |
| OLD | NEW |