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> |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 const uint32 FakeBluetoothDeviceClient::kWeirdDeviceClass = 0x7a020c; | 105 const uint32 FakeBluetoothDeviceClient::kWeirdDeviceClass = 0x7a020c; |
106 | 106 |
107 const char FakeBluetoothDeviceClient::kUnconnectableDevicePath[] = | 107 const char FakeBluetoothDeviceClient::kUnconnectableDevicePath[] = |
108 "/fake/hci0/dev9"; | 108 "/fake/hci0/dev9"; |
109 const char FakeBluetoothDeviceClient::kUnconnectableDeviceAddress[] = | 109 const char FakeBluetoothDeviceClient::kUnconnectableDeviceAddress[] = |
110 "20:7D:74:00:00:02"; | 110 "20:7D:74:00:00:02"; |
111 const char FakeBluetoothDeviceClient::kUnconnectableDeviceName[] = | 111 const char FakeBluetoothDeviceClient::kUnconnectableDeviceName[] = |
112 "Unconnectable Device"; | 112 "Unconnectable Device"; |
113 const uint32 FakeBluetoothDeviceClient::kUnconnectableDeviceClass = 0x7a020c; | 113 const uint32 FakeBluetoothDeviceClient::kUnconnectableDeviceClass = 0x7a020c; |
114 | 114 |
| 115 const char FakeBluetoothDeviceClient::kUnpairableDevicePath[] = |
| 116 "/fake/hci0/devA"; |
| 117 const char FakeBluetoothDeviceClient::kUnpairableDeviceAddress[] = |
| 118 "20:7D:74:00:00:03"; |
| 119 const char FakeBluetoothDeviceClient::kUnpairableDeviceName[] = |
| 120 "Unpairable Device"; |
| 121 const uint32 FakeBluetoothDeviceClient::kUnpairableDeviceClass = 0x002540; |
| 122 |
115 FakeBluetoothDeviceClient::Properties::Properties( | 123 FakeBluetoothDeviceClient::Properties::Properties( |
116 const PropertyChangedCallback& callback) | 124 const PropertyChangedCallback& callback) |
117 : ExperimentalBluetoothDeviceClient::Properties( | 125 : ExperimentalBluetoothDeviceClient::Properties( |
118 NULL, | 126 NULL, |
119 bluetooth_device::kExperimentalBluetoothDeviceInterface, | 127 bluetooth_device::kExperimentalBluetoothDeviceInterface, |
120 callback) { | 128 callback) { |
121 } | 129 } |
122 | 130 |
123 FakeBluetoothDeviceClient::Properties::~Properties() { | 131 FakeBluetoothDeviceClient::Properties::~Properties() { |
124 } | 132 } |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 } else if (object_path == dbus::ObjectPath(kWeirdDevicePath)) { | 373 } else if (object_path == dbus::ObjectPath(kWeirdDevicePath)) { |
366 // Request a Passkey from the user. | 374 // Request a Passkey from the user. |
367 agent_service_provider->RequestPasskey( | 375 agent_service_provider->RequestPasskey( |
368 object_path, | 376 object_path, |
369 base::Bind(&FakeBluetoothDeviceClient::PasskeyCallback, | 377 base::Bind(&FakeBluetoothDeviceClient::PasskeyCallback, |
370 base::Unretained(this), | 378 base::Unretained(this), |
371 object_path, | 379 object_path, |
372 callback, | 380 callback, |
373 error_callback)); | 381 error_callback)); |
374 | 382 |
| 383 } else if (object_path == dbus::ObjectPath(kUnpairableDevicePath)) { |
| 384 // Fails the pairing with an org.bluez.Error.Failed error. |
| 385 MessageLoop::current()->PostDelayedTask( |
| 386 FROM_HERE, |
| 387 base::Bind(&FakeBluetoothDeviceClient::FailSimulatedPairing, |
| 388 base::Unretained(this), |
| 389 object_path, error_callback), |
| 390 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); |
| 391 |
375 } else { | 392 } else { |
376 error_callback.Run(kNoResponseError, "No pairing fake"); | 393 error_callback.Run(kNoResponseError, "No pairing fake"); |
377 } | 394 } |
378 } | 395 } |
379 | 396 |
380 void FakeBluetoothDeviceClient::CancelPairing( | 397 void FakeBluetoothDeviceClient::CancelPairing( |
381 const dbus::ObjectPath& object_path, | 398 const dbus::ObjectPath& object_path, |
382 const base::Closure& callback, | 399 const base::Closure& callback, |
383 const ErrorCallback& error_callback) { | 400 const ErrorCallback& error_callback) { |
384 VLOG(1) << "CancelPairing: " << object_path.value(); | 401 VLOG(1) << "CancelPairing: " << object_path.value(); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 properties->adapter.ReplaceValue( | 662 properties->adapter.ReplaceValue( |
646 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); | 663 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); |
647 | 664 |
648 properties_map_[dbus::ObjectPath(kUnconnectableDevicePath)] = properties; | 665 properties_map_[dbus::ObjectPath(kUnconnectableDevicePath)] = properties; |
649 device_list_.push_back(dbus::ObjectPath(kUnconnectableDevicePath)); | 666 device_list_.push_back(dbus::ObjectPath(kUnconnectableDevicePath)); |
650 FOR_EACH_OBSERVER( | 667 FOR_EACH_OBSERVER( |
651 ExperimentalBluetoothDeviceClient::Observer, observers_, | 668 ExperimentalBluetoothDeviceClient::Observer, observers_, |
652 DeviceAdded(dbus::ObjectPath(kUnconnectableDevicePath))); | 669 DeviceAdded(dbus::ObjectPath(kUnconnectableDevicePath))); |
653 } | 670 } |
654 | 671 |
| 672 if (std::find(device_list_.begin(), device_list_.end(), |
| 673 dbus::ObjectPath(kUnpairableDevicePath)) == |
| 674 device_list_.end()) { |
| 675 Properties* properties = new Properties(base::Bind( |
| 676 &FakeBluetoothDeviceClient::OnPropertyChanged, |
| 677 base::Unretained(this), |
| 678 dbus::ObjectPath(kUnpairableDevicePath))); |
| 679 properties->address.ReplaceValue(kUnpairableDeviceAddress); |
| 680 properties->bluetooth_class.ReplaceValue(kUnpairableDeviceClass); |
| 681 properties->name.ReplaceValue("Fake Unpairable Device"); |
| 682 properties->alias.ReplaceValue(kUnpairableDeviceName); |
| 683 properties->adapter.ReplaceValue( |
| 684 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); |
| 685 |
| 686 properties_map_[dbus::ObjectPath(kUnpairableDevicePath)] = properties; |
| 687 device_list_.push_back(dbus::ObjectPath(kUnpairableDevicePath)); |
| 688 FOR_EACH_OBSERVER( |
| 689 ExperimentalBluetoothDeviceClient::Observer, observers_, |
| 690 DeviceAdded(dbus::ObjectPath(kUnpairableDevicePath))); |
| 691 } |
| 692 |
655 } else if (discovery_simulation_step_ == 13) { | 693 } else if (discovery_simulation_step_ == 13) { |
656 RemoveDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 694 RemoveDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
657 dbus::ObjectPath(kVanishingDevicePath)); | 695 dbus::ObjectPath(kVanishingDevicePath)); |
658 | 696 |
659 } else if (discovery_simulation_step_ == 14) { | 697 } else if (discovery_simulation_step_ == 14) { |
660 return; | 698 return; |
661 | 699 |
662 } | 700 } |
663 | 701 |
664 ++discovery_simulation_step_; | 702 ++discovery_simulation_step_; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 | 748 |
711 void FakeBluetoothDeviceClient::RejectSimulatedPairing( | 749 void FakeBluetoothDeviceClient::RejectSimulatedPairing( |
712 const dbus::ObjectPath& object_path, | 750 const dbus::ObjectPath& object_path, |
713 const ErrorCallback& error_callback) { | 751 const ErrorCallback& error_callback) { |
714 VLOG(1) << "RejectSimulatedPairing: " << object_path.value(); | 752 VLOG(1) << "RejectSimulatedPairing: " << object_path.value(); |
715 | 753 |
716 error_callback.Run(bluetooth_adapter::kErrorAuthenticationRejected, | 754 error_callback.Run(bluetooth_adapter::kErrorAuthenticationRejected, |
717 "Rejected"); | 755 "Rejected"); |
718 } | 756 } |
719 | 757 |
| 758 void FakeBluetoothDeviceClient::FailSimulatedPairing( |
| 759 const dbus::ObjectPath& object_path, |
| 760 const ErrorCallback& error_callback) { |
| 761 VLOG(1) << "FailSimulatedPairing: " << object_path.value(); |
| 762 |
| 763 error_callback.Run(bluetooth_adapter::kErrorFailed, "Failed"); |
| 764 } |
| 765 |
720 void FakeBluetoothDeviceClient::AddInputDeviceIfNeeded( | 766 void FakeBluetoothDeviceClient::AddInputDeviceIfNeeded( |
721 const dbus::ObjectPath& object_path, | 767 const dbus::ObjectPath& object_path, |
722 Properties* properties) { | 768 Properties* properties) { |
723 // If the paired device is a HID device based on it's bluetooth class, | 769 // If the paired device is a HID device based on it's bluetooth class, |
724 // simulate the Input interface. | 770 // simulate the Input interface. |
725 FakeBluetoothInputClient* fake_bluetooth_input_client = | 771 FakeBluetoothInputClient* fake_bluetooth_input_client = |
726 static_cast<FakeBluetoothInputClient*>( | 772 static_cast<FakeBluetoothInputClient*>( |
727 DBusThreadManager::Get()->GetExperimentalBluetoothInputClient()); | 773 DBusThreadManager::Get()->GetExperimentalBluetoothInputClient()); |
728 | 774 |
729 if ((properties->bluetooth_class.value() & 0x001f03) == 0x000500) | 775 if ((properties->bluetooth_class.value() & 0x001f03) == 0x000500) |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 FROM_HERE, | 914 FROM_HERE, |
869 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, | 915 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, |
870 base::Unretained(this), | 916 base::Unretained(this), |
871 object_path, callback, error_callback), | 917 object_path, callback, error_callback), |
872 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); | 918 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); |
873 | 919 |
874 } | 920 } |
875 } | 921 } |
876 | 922 |
877 } // namespace chromeos | 923 } // namespace chromeos |
OLD | NEW |