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 <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
17 #include "base/time.h" | 17 #include "base/time.h" |
18 #include "chromeos/dbus/dbus_thread_manager.h" | 18 #include "chromeos/dbus/dbus_thread_manager.h" |
19 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" | 19 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" |
20 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" | 20 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" |
21 #include "chromeos/dbus/fake_bluetooth_agent_service_provider.h" | 21 #include "chromeos/dbus/fake_bluetooth_agent_service_provider.h" |
| 22 #include "chromeos/dbus/fake_bluetooth_input_client.h" |
22 #include "dbus/object_path.h" | 23 #include "dbus/object_path.h" |
23 #include "third_party/cros_system_api/dbus/service_constants.h" | 24 #include "third_party/cros_system_api/dbus/service_constants.h" |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 // Default interval between simulated events. | 28 // Default interval between simulated events. |
28 const int kSimulationIntervalMs = 750; | 29 const int kSimulationIntervalMs = 750; |
29 | 30 |
30 } | 31 } |
31 | 32 |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 object_path == dbus::ObjectPath(kMicrosoftMousePath)) { | 218 object_path == dbus::ObjectPath(kMicrosoftMousePath)) { |
218 // Must not be paired | 219 // Must not be paired |
219 error_callback.Run(bluetooth_adapter::kErrorFailed, | 220 error_callback.Run(bluetooth_adapter::kErrorFailed, |
220 "Connection fails while paired"); | 221 "Connection fails while paired"); |
221 return; | 222 return; |
222 } | 223 } |
223 | 224 |
224 // The device can be connected. | 225 // The device can be connected. |
225 properties->connected.ReplaceValue(true); | 226 properties->connected.ReplaceValue(true); |
226 | 227 |
| 228 AddInputDeviceIfNeeded(object_path, properties); |
| 229 |
227 callback.Run(); | 230 callback.Run(); |
228 properties->NotifyPropertyChanged(properties->connected.name()); | 231 properties->NotifyPropertyChanged(properties->connected.name()); |
229 } | 232 } |
230 | 233 |
231 void FakeBluetoothDeviceClient::Disconnect( | 234 void FakeBluetoothDeviceClient::Disconnect( |
232 const dbus::ObjectPath& object_path, | 235 const dbus::ObjectPath& object_path, |
233 const base::Closure& callback, | 236 const base::Closure& callback, |
234 const ErrorCallback& error_callback) { | 237 const ErrorCallback& error_callback) { |
235 VLOG(1) << "Disconnect: " << object_path.value(); | 238 VLOG(1) << "Disconnect: " << object_path.value(); |
236 Properties* properties = GetProperties(object_path); | 239 Properties* properties = GetProperties(object_path); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 std::find(device_list_.begin(), device_list_.end(), device_path); | 409 std::find(device_list_.begin(), device_list_.end(), device_path); |
407 if (listiter == device_list_.end()) | 410 if (listiter == device_list_.end()) |
408 return; | 411 return; |
409 | 412 |
410 PropertiesMap::iterator iter = properties_map_.find(device_path); | 413 PropertiesMap::iterator iter = properties_map_.find(device_path); |
411 Properties* properties = iter->second; | 414 Properties* properties = iter->second; |
412 | 415 |
413 VLOG(1) << "removing device: " << properties->alias.value(); | 416 VLOG(1) << "removing device: " << properties->alias.value(); |
414 device_list_.erase(listiter); | 417 device_list_.erase(listiter); |
415 | 418 |
| 419 // Remove the Input interface if it exists. This should be called before the |
| 420 // ExperimentalBluetoothDeviceClient::Observer::DeviceRemoved because it |
| 421 // deletes the BluetoothDeviceExperimentalChromeOS object, including the |
| 422 // device_path referenced here. |
| 423 FakeBluetoothInputClient* fake_bluetooth_input_client = |
| 424 static_cast<FakeBluetoothInputClient*>( |
| 425 DBusThreadManager::Get()->GetExperimentalBluetoothInputClient()); |
| 426 fake_bluetooth_input_client->RemoveInputDevice(device_path); |
| 427 |
416 FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, | 428 FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, |
417 DeviceRemoved(device_path)); | 429 DeviceRemoved(device_path)); |
418 | 430 |
419 delete properties; | 431 delete properties; |
420 properties_map_.erase(iter); | 432 properties_map_.erase(iter); |
421 } | 433 } |
422 | 434 |
423 void FakeBluetoothDeviceClient::OnPropertyChanged( | 435 void FakeBluetoothDeviceClient::OnPropertyChanged( |
424 const dbus::ObjectPath& object_path, | 436 const dbus::ObjectPath& object_path, |
425 const std::string& property_name) { | 437 const std::string& property_name) { |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 if (pairing_cancelled_) { | 633 if (pairing_cancelled_) { |
622 pairing_cancelled_ = false; | 634 pairing_cancelled_ = false; |
623 | 635 |
624 error_callback.Run(bluetooth_adapter::kErrorAuthenticationCanceled, | 636 error_callback.Run(bluetooth_adapter::kErrorAuthenticationCanceled, |
625 "Cancaled"); | 637 "Cancaled"); |
626 } else { | 638 } else { |
627 Properties* properties = GetProperties(object_path); | 639 Properties* properties = GetProperties(object_path); |
628 | 640 |
629 properties->paired.ReplaceValue(true); | 641 properties->paired.ReplaceValue(true); |
630 | 642 |
| 643 AddInputDeviceIfNeeded(object_path, properties); |
| 644 |
631 callback.Run(); | 645 callback.Run(); |
632 properties->NotifyPropertyChanged(properties->paired.name()); | 646 properties->NotifyPropertyChanged(properties->paired.name()); |
633 } | 647 } |
634 } | 648 } |
635 | 649 |
636 void FakeBluetoothDeviceClient::TimeoutSimulatedPairing( | 650 void FakeBluetoothDeviceClient::TimeoutSimulatedPairing( |
637 const dbus::ObjectPath& object_path, | 651 const dbus::ObjectPath& object_path, |
638 const ErrorCallback& error_callback) { | 652 const ErrorCallback& error_callback) { |
639 VLOG(1) << "TimeoutSimulatedPairing: " << object_path.value(); | 653 VLOG(1) << "TimeoutSimulatedPairing: " << object_path.value(); |
640 | 654 |
(...skipping 12 matching lines...) Expand all Loading... |
653 | 667 |
654 void FakeBluetoothDeviceClient::RejectSimulatedPairing( | 668 void FakeBluetoothDeviceClient::RejectSimulatedPairing( |
655 const dbus::ObjectPath& object_path, | 669 const dbus::ObjectPath& object_path, |
656 const ErrorCallback& error_callback) { | 670 const ErrorCallback& error_callback) { |
657 VLOG(1) << "RejectSimulatedPairing: " << object_path.value(); | 671 VLOG(1) << "RejectSimulatedPairing: " << object_path.value(); |
658 | 672 |
659 error_callback.Run(bluetooth_adapter::kErrorAuthenticationRejected, | 673 error_callback.Run(bluetooth_adapter::kErrorAuthenticationRejected, |
660 "Rejected"); | 674 "Rejected"); |
661 } | 675 } |
662 | 676 |
| 677 void FakeBluetoothDeviceClient::AddInputDeviceIfNeeded( |
| 678 const dbus::ObjectPath& object_path, |
| 679 Properties* properties) { |
| 680 // If the paired device is a HID device based on it's bluetooth class, |
| 681 // simulate the Input interface. |
| 682 FakeBluetoothInputClient* fake_bluetooth_input_client = |
| 683 static_cast<FakeBluetoothInputClient*>( |
| 684 DBusThreadManager::Get()->GetExperimentalBluetoothInputClient()); |
| 685 |
| 686 if ((properties->bluetooth_class.value() & 0x001f03) == 0x000500) { |
| 687 std::vector<std::string> uuids = properties->uuids.value(); |
| 688 if (std::find(uuids.begin(), uuids.end(), |
| 689 "00001124-0000-1000-8000-00805f9b34fb") == uuids.end()) { |
| 690 uuids.push_back("00001124-0000-1000-8000-00805f9b34fb"); |
| 691 properties->uuids.ReplaceValue(uuids); |
| 692 fake_bluetooth_input_client->AddInputDevice(object_path); |
| 693 } |
| 694 } |
| 695 } |
| 696 |
663 void FakeBluetoothDeviceClient::PinCodeCallback( | 697 void FakeBluetoothDeviceClient::PinCodeCallback( |
664 const dbus::ObjectPath& object_path, | 698 const dbus::ObjectPath& object_path, |
665 const base::Closure& callback, | 699 const base::Closure& callback, |
666 const ErrorCallback& error_callback, | 700 const ErrorCallback& error_callback, |
667 ExperimentalBluetoothAgentServiceProvider::Delegate::Status status, | 701 ExperimentalBluetoothAgentServiceProvider::Delegate::Status status, |
668 const std::string& pincode) { | 702 const std::string& pincode) { |
669 VLOG(1) << "PinCodeCallback: " << object_path.value(); | 703 VLOG(1) << "PinCodeCallback: " << object_path.value(); |
670 | 704 |
671 if (status == ExperimentalBluetoothAgentServiceProvider::Delegate::SUCCESS) { | 705 if (status == ExperimentalBluetoothAgentServiceProvider::Delegate::SUCCESS) { |
672 MessageLoop::current()->PostDelayedTask( | 706 MessageLoop::current()->PostDelayedTask( |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 FROM_HERE, | 832 FROM_HERE, |
799 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, | 833 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, |
800 base::Unretained(this), | 834 base::Unretained(this), |
801 object_path, callback, error_callback), | 835 object_path, callback, error_callback), |
802 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); | 836 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); |
803 | 837 |
804 } | 838 } |
805 } | 839 } |
806 | 840 |
807 } // namespace chromeos | 841 } // namespace chromeos |
OLD | NEW |