Chromium Code Reviews| 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. |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 const uint32 FakeBluetoothDeviceClient::kUnpairableDeviceClass = 0x002540; | 162 const uint32 FakeBluetoothDeviceClient::kUnpairableDeviceClass = 0x002540; |
| 161 | 163 |
| 162 const char FakeBluetoothDeviceClient::kJustWorksPath[] = | 164 const char FakeBluetoothDeviceClient::kJustWorksPath[] = |
| 163 "/fake/hci0/devB"; | 165 "/fake/hci0/devB"; |
| 164 const char FakeBluetoothDeviceClient::kJustWorksAddress[] = | 166 const char FakeBluetoothDeviceClient::kJustWorksAddress[] = |
| 165 "00:0C:8A:00:00:00"; | 167 "00:0C:8A:00:00:00"; |
| 166 const char FakeBluetoothDeviceClient::kJustWorksName[] = | 168 const char FakeBluetoothDeviceClient::kJustWorksName[] = |
| 167 "Just-Works Device"; | 169 "Just-Works Device"; |
| 168 const uint32 FakeBluetoothDeviceClient::kJustWorksClass = 0x240428; | 170 const uint32 FakeBluetoothDeviceClient::kJustWorksClass = 0x240428; |
| 169 | 171 |
| 172 const char FakeBluetoothDeviceClient::kLowEnergyPath[] = | |
| 173 "/fake/hci0/devC"; | |
| 174 const char FakeBluetoothDeviceClient::kLowEnergyAddress[] = | |
| 175 "00:1A:11:00:15:30"; | |
| 176 const char FakeBluetoothDeviceClient::kLowEnergyName[] = | |
| 177 "Bluetooth 4.0 Heart Rate Monitor"; | |
| 178 const uint32 FakeBluetoothDeviceClient::kLowEnergyClass = | |
| 179 0x000918; // Major class "Health", Minor class "Heart/Pulse Rate Monitor." | |
| 180 | |
| 170 FakeBluetoothDeviceClient::Properties::Properties( | 181 FakeBluetoothDeviceClient::Properties::Properties( |
| 171 const PropertyChangedCallback& callback) | 182 const PropertyChangedCallback& callback) |
| 172 : BluetoothDeviceClient::Properties( | 183 : BluetoothDeviceClient::Properties( |
| 173 NULL, | 184 NULL, |
| 174 bluetooth_device::kBluetoothDeviceInterface, | 185 bluetooth_device::kBluetoothDeviceInterface, |
| 175 callback) { | 186 callback) { |
| 176 } | 187 } |
| 177 | 188 |
| 178 FakeBluetoothDeviceClient::Properties::~Properties() { | 189 FakeBluetoothDeviceClient::Properties::~Properties() { |
| 179 } | 190 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 286 // Must not be paired | 297 // Must not be paired |
| 287 error_callback.Run(bluetooth_device::kErrorFailed, | 298 error_callback.Run(bluetooth_device::kErrorFailed, |
| 288 "Connection fails while paired"); | 299 "Connection fails while paired"); |
| 289 return; | 300 return; |
| 290 } | 301 } |
| 291 | 302 |
| 292 // The device can be connected. | 303 // The device can be connected. |
| 293 properties->connected.ReplaceValue(true); | 304 properties->connected.ReplaceValue(true); |
| 294 callback.Run(); | 305 callback.Run(); |
| 295 | 306 |
| 307 // Expose GATT services if connected to LE device. | |
| 308 if (object_path == dbus::ObjectPath(kLowEnergyPath)) { | |
| 309 FakeBluetoothGattServiceClient* gatt_service_client = | |
| 310 static_cast<FakeBluetoothGattServiceClient*>( | |
| 311 DBusThreadManager::Get()->GetBluetoothGattServiceClient()); | |
| 312 gatt_service_client->ExposeHeartRateService( | |
| 313 dbus::ObjectPath(kLowEnergyPath)); | |
| 314 } | |
| 315 | |
| 296 AddInputDeviceIfNeeded(object_path, properties); | 316 AddInputDeviceIfNeeded(object_path, properties); |
| 297 } | 317 } |
| 298 | 318 |
| 299 void FakeBluetoothDeviceClient::Disconnect( | 319 void FakeBluetoothDeviceClient::Disconnect( |
| 300 const dbus::ObjectPath& object_path, | 320 const dbus::ObjectPath& object_path, |
| 301 const base::Closure& callback, | 321 const base::Closure& callback, |
| 302 const ErrorCallback& error_callback) { | 322 const ErrorCallback& error_callback) { |
| 303 VLOG(1) << "Disconnect: " << object_path.value(); | 323 VLOG(1) << "Disconnect: " << object_path.value(); |
| 304 Properties* properties = GetProperties(object_path); | 324 Properties* properties = GetProperties(object_path); |
| 305 | 325 |
| 306 if (properties->connected.value() == true) { | 326 if (!properties->connected.value()) { |
| 307 callback.Run(); | |
| 308 properties->connected.ReplaceValue(false); | |
| 309 } else { | |
| 310 error_callback.Run("org.bluez.Error.NotConnected", "Not Connected"); | 327 error_callback.Run("org.bluez.Error.NotConnected", "Not Connected"); |
| 328 return; | |
| 311 } | 329 } |
| 330 | |
| 331 // Hide the Heart Rate Service if disconnected from LE device. | |
| 332 if (object_path == dbus::ObjectPath(kLowEnergyPath)) { | |
| 333 FakeBluetoothGattServiceClient* gatt_service_client = | |
| 334 static_cast<FakeBluetoothGattServiceClient*>( | |
| 335 DBusThreadManager::Get()->GetBluetoothGattServiceClient()); | |
| 336 gatt_service_client->HideHeartRateService(); | |
| 337 } | |
| 338 | |
| 339 callback.Run(); | |
| 340 properties->connected.ReplaceValue(false); | |
| 312 } | 341 } |
| 313 | 342 |
| 314 void FakeBluetoothDeviceClient::ConnectProfile( | 343 void FakeBluetoothDeviceClient::ConnectProfile( |
| 315 const dbus::ObjectPath& object_path, | 344 const dbus::ObjectPath& object_path, |
| 316 const std::string& uuid, | 345 const std::string& uuid, |
| 317 const base::Closure& callback, | 346 const base::Closure& callback, |
| 318 const ErrorCallback& error_callback) { | 347 const ErrorCallback& error_callback) { |
| 319 VLOG(1) << "ConnectProfile: " << object_path.value() << " " << uuid; | 348 VLOG(1) << "ConnectProfile: " << object_path.value() << " " << uuid; |
| 320 | 349 |
| 321 FakeBluetoothProfileManagerClient* fake_bluetooth_profile_manager_client = | 350 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); | 586 properties->bluetooth_class.ReplaceValue(kUnpairableDeviceClass); |
| 558 properties->name.ReplaceValue("Fake Unpairable Device"); | 587 properties->name.ReplaceValue("Fake Unpairable Device"); |
| 559 properties->alias.ReplaceValue(kUnpairableDeviceName); | 588 properties->alias.ReplaceValue(kUnpairableDeviceName); |
| 560 | 589 |
| 561 } else if (device_path == dbus::ObjectPath(kJustWorksPath)) { | 590 } else if (device_path == dbus::ObjectPath(kJustWorksPath)) { |
| 562 properties->address.ReplaceValue(kJustWorksAddress); | 591 properties->address.ReplaceValue(kJustWorksAddress); |
| 563 properties->bluetooth_class.ReplaceValue(kJustWorksClass); | 592 properties->bluetooth_class.ReplaceValue(kJustWorksClass); |
| 564 properties->name.ReplaceValue("JustWorks"); | 593 properties->name.ReplaceValue("JustWorks"); |
| 565 properties->alias.ReplaceValue(kJustWorksName); | 594 properties->alias.ReplaceValue(kJustWorksName); |
| 566 | 595 |
| 596 } else if (device_path == dbus::ObjectPath(kLowEnergyPath)) { | |
| 597 properties->address.ReplaceValue(kLowEnergyAddress); | |
| 598 properties->bluetooth_class.ReplaceValue(kLowEnergyClass); | |
| 599 properties->name.ReplaceValue("Heart Rate Monitor"); | |
| 600 properties->alias.ReplaceValue(kLowEnergyName); | |
| 601 | |
| 602 std::vector<std::string> uuids; | |
| 603 uuids.push_back(FakeBluetoothGattServiceClient::kHeartRateServiceUUID); | |
| 604 properties->uuids.ReplaceValue(uuids); | |
| 605 | |
| 567 } else { | 606 } else { |
| 568 NOTREACHED(); | 607 NOTREACHED(); |
| 569 | 608 |
| 570 } | 609 } |
| 571 | 610 |
| 572 properties_map_[device_path] = properties; | 611 properties_map_[device_path] = properties; |
| 573 device_list_.push_back(device_path); | 612 device_list_.push_back(device_path); |
| 574 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, | 613 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, |
| 575 DeviceAdded(device_path)); | 614 DeviceAdded(device_path)); |
| 576 } | 615 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 590 device_list_.erase(listiter); | 629 device_list_.erase(listiter); |
| 591 | 630 |
| 592 // Remove the Input interface if it exists. This should be called before the | 631 // Remove the Input interface if it exists. This should be called before the |
| 593 // BluetoothDeviceClient::Observer::DeviceRemoved because it deletes the | 632 // BluetoothDeviceClient::Observer::DeviceRemoved because it deletes the |
| 594 // BluetoothDeviceChromeOS object, including the device_path referenced here. | 633 // BluetoothDeviceChromeOS object, including the device_path referenced here. |
| 595 FakeBluetoothInputClient* fake_bluetooth_input_client = | 634 FakeBluetoothInputClient* fake_bluetooth_input_client = |
| 596 static_cast<FakeBluetoothInputClient*>( | 635 static_cast<FakeBluetoothInputClient*>( |
| 597 DBusThreadManager::Get()->GetBluetoothInputClient()); | 636 DBusThreadManager::Get()->GetBluetoothInputClient()); |
| 598 fake_bluetooth_input_client->RemoveInputDevice(device_path); | 637 fake_bluetooth_input_client->RemoveInputDevice(device_path); |
| 599 | 638 |
| 639 if (device_path == dbus::ObjectPath(kLowEnergyPath)) { | |
| 640 FakeBluetoothGattServiceClient* gatt_service_client = | |
| 641 static_cast<FakeBluetoothGattServiceClient*>( | |
| 642 DBusThreadManager::Get()->GetBluetoothGattServiceClient()); | |
| 643 gatt_service_client->HideHeartRateService(); | |
| 644 } | |
| 645 | |
| 600 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, | 646 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, |
| 601 DeviceRemoved(device_path)); | 647 DeviceRemoved(device_path)); |
| 602 | 648 |
| 603 delete properties; | 649 delete properties; |
| 604 properties_map_.erase(iter); | 650 properties_map_.erase(iter); |
| 605 } | 651 } |
| 606 | 652 |
| 607 void FakeBluetoothDeviceClient::OnPropertyChanged( | 653 void FakeBluetoothDeviceClient::OnPropertyChanged( |
| 608 const dbus::ObjectPath& object_path, | 654 const dbus::ObjectPath& object_path, |
| 609 const std::string& property_name) { | 655 const std::string& property_name) { |
| 656 VLOG(2) << "Fake Bluetooth device property changed: " << object_path.value() | |
| 657 << ": " << property_name; | |
| 610 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, | 658 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, |
| 611 DevicePropertyChanged(object_path, property_name)); | 659 DevicePropertyChanged(object_path, property_name)); |
| 612 } | 660 } |
| 613 | 661 |
| 614 void FakeBluetoothDeviceClient::DiscoverySimulationTimer() { | 662 void FakeBluetoothDeviceClient::DiscoverySimulationTimer() { |
| 615 if (!discovery_simulation_step_) | 663 if (!discovery_simulation_step_) |
| 616 return; | 664 return; |
| 617 | 665 |
| 618 // Timer fires every .75s, the numbers below are arbitrary to give a feel | 666 // Timer fires every .75s, the numbers below are arbitrary to give a feel |
| 619 // for a discovery process. | 667 // for a discovery process. |
| 620 VLOG(1) << "discovery simulation, step " << discovery_simulation_step_; | 668 VLOG(1) << "discovery simulation, step " << discovery_simulation_step_; |
| 621 if (discovery_simulation_step_ == 2) { | 669 if (discovery_simulation_step_ == 2) { |
| 622 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 670 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 623 dbus::ObjectPath(kLegacyAutopairPath)); | 671 dbus::ObjectPath(kLegacyAutopairPath)); |
| 672 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | |
| 673 dbus::ObjectPath(kLowEnergyPath)); | |
| 624 | 674 |
| 625 } else if (discovery_simulation_step_ == 4) { | 675 } else if (discovery_simulation_step_ == 4) { |
| 626 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 676 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 627 dbus::ObjectPath(kDisplayPinCodePath)); | 677 dbus::ObjectPath(kDisplayPinCodePath)); |
| 628 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 678 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 629 dbus::ObjectPath(kVanishingDevicePath)); | 679 dbus::ObjectPath(kVanishingDevicePath)); |
| 680 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), base::RandInt(-90, -30)); | |
|
keybuk
2014/03/21 23:57:33
nit: use constants
armansito
2014/03/22 02:22:00
Done.
| |
| 630 | 681 |
| 631 } else if (discovery_simulation_step_ == 7) { | 682 } else if (discovery_simulation_step_ == 7) { |
| 632 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 683 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 633 dbus::ObjectPath(kConnectUnpairablePath)); | 684 dbus::ObjectPath(kConnectUnpairablePath)); |
| 685 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), base::RandInt(-90, -30)); | |
| 634 | 686 |
| 635 } else if (discovery_simulation_step_ == 8) { | 687 } else if (discovery_simulation_step_ == 8) { |
| 636 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 688 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 637 dbus::ObjectPath(kDisplayPasskeyPath)); | 689 dbus::ObjectPath(kDisplayPasskeyPath)); |
| 638 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 690 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 639 dbus::ObjectPath(kRequestPinCodePath)); | 691 dbus::ObjectPath(kRequestPinCodePath)); |
| 692 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), base::RandInt(-90, -30)); | |
| 640 | 693 |
| 641 } else if (discovery_simulation_step_ == 10) { | 694 } else if (discovery_simulation_step_ == 10) { |
| 642 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 695 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 643 dbus::ObjectPath(kConfirmPasskeyPath)); | 696 dbus::ObjectPath(kConfirmPasskeyPath)); |
| 644 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 697 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 645 dbus::ObjectPath(kRequestPasskeyPath)); | 698 dbus::ObjectPath(kRequestPasskeyPath)); |
| 646 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 699 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 647 dbus::ObjectPath(kUnconnectableDevicePath)); | 700 dbus::ObjectPath(kUnconnectableDevicePath)); |
| 648 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 701 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 649 dbus::ObjectPath(kUnpairableDevicePath)); | 702 dbus::ObjectPath(kUnpairableDevicePath)); |
| 650 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 703 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 651 dbus::ObjectPath(kJustWorksPath)); | 704 dbus::ObjectPath(kJustWorksPath)); |
| 705 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), base::RandInt(-90, -30)); | |
| 652 | 706 |
| 653 } else if (discovery_simulation_step_ == 13) { | 707 } else if (discovery_simulation_step_ == 13) { |
| 654 RemoveDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 708 RemoveDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 655 dbus::ObjectPath(kVanishingDevicePath)); | 709 dbus::ObjectPath(kVanishingDevicePath)); |
| 710 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), base::RandInt(-90, -30)); | |
| 656 | 711 |
| 657 } else if (discovery_simulation_step_ == 14) { | 712 } else if (discovery_simulation_step_ == 14) { |
| 713 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), base::RandInt(-90, -30)); | |
| 658 return; | 714 return; |
| 659 | 715 |
| 660 } | 716 } |
| 661 | 717 |
| 662 ++discovery_simulation_step_; | 718 ++discovery_simulation_step_; |
| 663 base::MessageLoop::current()->PostDelayedTask( | 719 base::MessageLoop::current()->PostDelayedTask( |
| 664 FROM_HERE, | 720 FROM_HERE, |
| 665 base::Bind(&FakeBluetoothDeviceClient::DiscoverySimulationTimer, | 721 base::Bind(&FakeBluetoothDeviceClient::DiscoverySimulationTimer, |
| 666 base::Unretained(this)), | 722 base::Unretained(this)), |
| 667 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); | 723 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 737 | 793 |
| 738 FakeBluetoothAgentManagerClient* fake_bluetooth_agent_manager_client = | 794 FakeBluetoothAgentManagerClient* fake_bluetooth_agent_manager_client = |
| 739 static_cast<FakeBluetoothAgentManagerClient*>( | 795 static_cast<FakeBluetoothAgentManagerClient*>( |
| 740 DBusThreadManager::Get()->GetBluetoothAgentManagerClient()); | 796 DBusThreadManager::Get()->GetBluetoothAgentManagerClient()); |
| 741 FakeBluetoothAgentServiceProvider* agent_service_provider = | 797 FakeBluetoothAgentServiceProvider* agent_service_provider = |
| 742 fake_bluetooth_agent_manager_client->GetAgentServiceProvider(); | 798 fake_bluetooth_agent_manager_client->GetAgentServiceProvider(); |
| 743 CHECK(agent_service_provider != NULL); | 799 CHECK(agent_service_provider != NULL); |
| 744 | 800 |
| 745 if (object_path == dbus::ObjectPath(kLegacyAutopairPath) || | 801 if (object_path == dbus::ObjectPath(kLegacyAutopairPath) || |
| 746 object_path == dbus::ObjectPath(kConnectUnpairablePath) || | 802 object_path == dbus::ObjectPath(kConnectUnpairablePath) || |
| 747 object_path == dbus::ObjectPath(kUnconnectableDevicePath)) { | 803 object_path == dbus::ObjectPath(kUnconnectableDevicePath) || |
| 804 object_path == dbus::ObjectPath(kLowEnergyPath)) { | |
| 748 // No need to call anything on the pairing delegate, just wait 3 times | 805 // 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. | 806 // the interval before acting as if the other end accepted it. |
| 750 base::MessageLoop::current()->PostDelayedTask( | 807 base::MessageLoop::current()->PostDelayedTask( |
| 751 FROM_HERE, | 808 FROM_HERE, |
| 752 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, | 809 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, |
| 753 base::Unretained(this), | 810 base::Unretained(this), |
| 754 object_path, callback, error_callback), | 811 object_path, callback, error_callback), |
| 755 base::TimeDelta::FromMilliseconds(3 * simulation_interval_ms_)); | 812 base::TimeDelta::FromMilliseconds(3 * simulation_interval_ms_)); |
| 756 | 813 |
| 757 } else if (object_path == dbus::ObjectPath(kDisplayPinCodePath)) { | 814 } 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, | 971 // If the paired device is a HID device based on it's bluetooth class, |
| 915 // simulate the Input interface. | 972 // simulate the Input interface. |
| 916 FakeBluetoothInputClient* fake_bluetooth_input_client = | 973 FakeBluetoothInputClient* fake_bluetooth_input_client = |
| 917 static_cast<FakeBluetoothInputClient*>( | 974 static_cast<FakeBluetoothInputClient*>( |
| 918 DBusThreadManager::Get()->GetBluetoothInputClient()); | 975 DBusThreadManager::Get()->GetBluetoothInputClient()); |
| 919 | 976 |
| 920 if ((properties->bluetooth_class.value() & 0x001f03) == 0x000500) | 977 if ((properties->bluetooth_class.value() & 0x001f03) == 0x000500) |
| 921 fake_bluetooth_input_client->AddInputDevice(object_path); | 978 fake_bluetooth_input_client->AddInputDevice(object_path); |
| 922 } | 979 } |
| 923 | 980 |
| 981 void FakeBluetoothDeviceClient::UpdateDeviceRSSI( | |
| 982 const dbus::ObjectPath& object_path, | |
| 983 int16 rssi) { | |
| 984 PropertiesMap::iterator iter = properties_map_.find(object_path); | |
| 985 if (iter == properties_map_.end()) { | |
| 986 VLOG(2) << "Fake device does not exist: " << object_path.value(); | |
| 987 return; | |
| 988 } | |
| 989 Properties* properties = iter->second; | |
| 990 DCHECK(properties); | |
| 991 properties->rssi.ReplaceValue(rssi); | |
| 992 } | |
| 993 | |
| 924 void FakeBluetoothDeviceClient::PinCodeCallback( | 994 void FakeBluetoothDeviceClient::PinCodeCallback( |
| 925 const dbus::ObjectPath& object_path, | 995 const dbus::ObjectPath& object_path, |
| 926 const base::Closure& callback, | 996 const base::Closure& callback, |
| 927 const ErrorCallback& error_callback, | 997 const ErrorCallback& error_callback, |
| 928 BluetoothAgentServiceProvider::Delegate::Status status, | 998 BluetoothAgentServiceProvider::Delegate::Status status, |
| 929 const std::string& pincode) { | 999 const std::string& pincode) { |
| 930 VLOG(1) << "PinCodeCallback: " << object_path.value(); | 1000 VLOG(1) << "PinCodeCallback: " << object_path.value(); |
| 931 | 1001 |
| 932 if (status == BluetoothAgentServiceProvider::Delegate::SUCCESS) { | 1002 if (status == BluetoothAgentServiceProvider::Delegate::SUCCESS) { |
| 933 base::MessageLoop::current()->PostDelayedTask( | 1003 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 | 1163 // TODO(keybuk): tear down this side of the connection |
| 1094 callback.Run(); | 1164 callback.Run(); |
| 1095 } else if (status == BluetoothProfileServiceProvider::Delegate::CANCELLED) { | 1165 } else if (status == BluetoothProfileServiceProvider::Delegate::CANCELLED) { |
| 1096 error_callback.Run(bluetooth_device::kErrorFailed, "Canceled"); | 1166 error_callback.Run(bluetooth_device::kErrorFailed, "Canceled"); |
| 1097 } else if (status == BluetoothProfileServiceProvider::Delegate::REJECTED) { | 1167 } else if (status == BluetoothProfileServiceProvider::Delegate::REJECTED) { |
| 1098 error_callback.Run(bluetooth_device::kErrorFailed, "Rejected"); | 1168 error_callback.Run(bluetooth_device::kErrorFailed, "Rejected"); |
| 1099 } | 1169 } |
| 1100 } | 1170 } |
| 1101 | 1171 |
| 1102 } // namespace chromeos | 1172 } // namespace chromeos |
| OLD | NEW |