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 <sys/socket.h> | 8 #include <sys/socket.h> |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
(...skipping 27 matching lines...) Expand all Loading... |
38 // Default interval between simulated events. | 38 // Default interval between simulated events. |
39 const int kSimulationIntervalMs = 750; | 39 const int kSimulationIntervalMs = 750; |
40 | 40 |
41 // Minimum and maximum bounds for randomly generated RSSI values. | 41 // Minimum and maximum bounds for randomly generated RSSI values. |
42 const int kMinRSSI = -90; | 42 const int kMinRSSI = -90; |
43 const int kMaxRSSI = -30; | 43 const int kMaxRSSI = -30; |
44 | 44 |
45 // The default value of connection info properties from GetConnInfo(). | 45 // The default value of connection info properties from GetConnInfo(). |
46 const int kUnkownPower = 127; | 46 const int kUnkownPower = 127; |
47 | 47 |
| 48 const char kPairingMethodNone[] = "None"; |
| 49 const char kPairingMethodPinCode[] = "PIN Code"; |
| 50 const char kPairingMethodPassKey[] = "PassKey"; |
| 51 const char kTestPinCode[] = "123456"; |
| 52 |
| 53 // This is meant to delay the removal of a pre defined device until the |
| 54 // developer has time to see it. |
| 55 const int kVanishingDevicePairTimeMultiplier = 4; |
| 56 |
| 57 // Meant to delay a pair request for an observable amount of time. |
| 58 const int kIncomingSimulationPairTimeMultiplier = 45; |
| 59 |
| 60 // Meant to delay a request that asks for pair requests for an observable |
| 61 // amount of time. |
| 62 const int kIncomingSimulationStartPairTimeMultiplier = 30; |
| 63 |
| 64 // This allows the PIN code dialog to be shown for a long enough time to see |
| 65 // the PIN code UI in detail. |
| 66 const int kPinCodeDevicePairTimeMultiplier = 7; |
| 67 |
| 68 // This allows the pairing dialog to be shown for a long enough time to see |
| 69 // its UI in detail. |
| 70 const int kSimulateNormalPairTimeMultiplier = 3; |
| 71 |
| 72 const int kTestPassKey = 123456; |
48 | 73 |
49 void SimulatedProfileSocket(int fd) { | 74 void SimulatedProfileSocket(int fd) { |
50 // Simulate a server-side socket of a profile; read data from the socket, | 75 // Simulate a server-side socket of a profile; read data from the socket, |
51 // write it back, and then close. | 76 // write it back, and then close. |
52 char buf[1024]; | 77 char buf[1024]; |
53 ssize_t len; | 78 ssize_t len; |
54 ssize_t count; | 79 ssize_t count; |
55 | 80 |
56 len = read(fd, buf, sizeof buf); | 81 len = read(fd, buf, sizeof buf); |
57 if (len < 0) { | 82 if (len < 0) { |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 dbus::PropertySet::SetCallback callback) { | 244 dbus::PropertySet::SetCallback callback) { |
220 VLOG(1) << "Set " << property->name(); | 245 VLOG(1) << "Set " << property->name(); |
221 if (property->name() == trusted.name()) { | 246 if (property->name() == trusted.name()) { |
222 callback.Run(true); | 247 callback.Run(true); |
223 property->ReplaceValueWithSetValue(); | 248 property->ReplaceValueWithSetValue(); |
224 } else { | 249 } else { |
225 callback.Run(false); | 250 callback.Run(false); |
226 } | 251 } |
227 } | 252 } |
228 | 253 |
| 254 FakeBluetoothDeviceClient::IncomingDeviceProperties:: |
| 255 IncomingDeviceProperties() {} |
| 256 |
| 257 FakeBluetoothDeviceClient::IncomingDeviceProperties:: |
| 258 ~IncomingDeviceProperties() {} |
| 259 |
229 FakeBluetoothDeviceClient::FakeBluetoothDeviceClient() | 260 FakeBluetoothDeviceClient::FakeBluetoothDeviceClient() |
230 : simulation_interval_ms_(kSimulationIntervalMs), | 261 : simulation_interval_ms_(kSimulationIntervalMs), |
231 discovery_simulation_step_(0), | 262 discovery_simulation_step_(0), |
232 incoming_pairing_simulation_step_(0), | 263 incoming_pairing_simulation_step_(0), |
233 pairing_cancelled_(false), | 264 pairing_cancelled_(false), |
234 connection_rssi_(kUnkownPower), | 265 connection_rssi_(kUnkownPower), |
235 transmit_power_(kUnkownPower), | 266 transmit_power_(kUnkownPower), |
236 max_transmit_power_(kUnkownPower) { | 267 max_transmit_power_(kUnkownPower) { |
237 Properties* properties = new Properties(base::Bind( | 268 scoped_ptr<Properties> properties(new Properties( |
238 &FakeBluetoothDeviceClient::OnPropertyChanged, | 269 base::Bind(&FakeBluetoothDeviceClient::OnPropertyChanged, |
239 base::Unretained(this), | 270 base::Unretained(this), dbus::ObjectPath(kPairedDevicePath)))); |
240 dbus::ObjectPath(kPairedDevicePath))); | |
241 properties->address.ReplaceValue(kPairedDeviceAddress); | 271 properties->address.ReplaceValue(kPairedDeviceAddress); |
242 properties->bluetooth_class.ReplaceValue(kPairedDeviceClass); | 272 properties->bluetooth_class.ReplaceValue(kPairedDeviceClass); |
243 properties->name.ReplaceValue("Fake Device (Name)"); | 273 properties->name.ReplaceValue("Fake Device (Name)"); |
244 properties->alias.ReplaceValue(kPairedDeviceName); | 274 properties->alias.ReplaceValue(kPairedDeviceName); |
245 properties->paired.ReplaceValue(true); | 275 properties->paired.ReplaceValue(true); |
246 properties->trusted.ReplaceValue(true); | 276 properties->trusted.ReplaceValue(true); |
247 properties->adapter.ReplaceValue( | 277 properties->adapter.ReplaceValue( |
248 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); | 278 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); |
249 | 279 |
250 std::vector<std::string> uuids; | 280 std::vector<std::string> uuids; |
251 uuids.push_back("00001800-0000-1000-8000-00805f9b34fb"); | 281 uuids.push_back("00001800-0000-1000-8000-00805f9b34fb"); |
252 uuids.push_back("00001801-0000-1000-8000-00805f9b34fb"); | 282 uuids.push_back("00001801-0000-1000-8000-00805f9b34fb"); |
253 properties->uuids.ReplaceValue(uuids); | 283 properties->uuids.ReplaceValue(uuids); |
254 | 284 |
255 properties->modalias.ReplaceValue("usb:v05ACp030Dd0306"); | 285 properties->modalias.ReplaceValue("usb:v05ACp030Dd0306"); |
256 | 286 |
257 properties_map_[dbus::ObjectPath(kPairedDevicePath)] = properties; | 287 properties_map_.insert(dbus::ObjectPath(kPairedDevicePath), |
| 288 properties.Pass()); |
258 device_list_.push_back(dbus::ObjectPath(kPairedDevicePath)); | 289 device_list_.push_back(dbus::ObjectPath(kPairedDevicePath)); |
259 | 290 |
260 properties = new Properties(base::Bind( | 291 properties.reset(new Properties(base::Bind( |
261 &FakeBluetoothDeviceClient::OnPropertyChanged, base::Unretained(this), | 292 &FakeBluetoothDeviceClient::OnPropertyChanged, base::Unretained(this), |
262 dbus::ObjectPath(kPairedUnconnectableDevicePath))); | 293 dbus::ObjectPath(kPairedUnconnectableDevicePath)))); |
263 properties->address.ReplaceValue(kPairedUnconnectableDeviceAddress); | 294 properties->address.ReplaceValue(kPairedUnconnectableDeviceAddress); |
264 properties->bluetooth_class.ReplaceValue(kPairedUnconnectableDeviceClass); | 295 properties->bluetooth_class.ReplaceValue(kPairedUnconnectableDeviceClass); |
265 properties->name.ReplaceValue("Fake Device 2 (Unconnectable)"); | 296 properties->name.ReplaceValue("Fake Device 2 (Unconnectable)"); |
266 properties->alias.ReplaceValue(kPairedUnconnectableDeviceName); | 297 properties->alias.ReplaceValue(kPairedUnconnectableDeviceName); |
267 properties->paired.ReplaceValue(true); | 298 properties->paired.ReplaceValue(true); |
268 properties->trusted.ReplaceValue(true); | 299 properties->trusted.ReplaceValue(true); |
269 properties->adapter.ReplaceValue( | 300 properties->adapter.ReplaceValue( |
270 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); | 301 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); |
271 | 302 |
272 properties->uuids.ReplaceValue(uuids); | 303 properties->uuids.ReplaceValue(uuids); |
273 | 304 |
274 properties->modalias.ReplaceValue("usb:v05ACp030Dd0306"); | 305 properties->modalias.ReplaceValue("usb:v05ACp030Dd0306"); |
275 | 306 |
276 properties_map_[dbus::ObjectPath(kPairedUnconnectableDevicePath)] = | 307 properties_map_.insert(dbus::ObjectPath(kPairedUnconnectableDevicePath), |
277 properties; | 308 properties.Pass()); |
278 device_list_.push_back(dbus::ObjectPath(kPairedUnconnectableDevicePath)); | 309 device_list_.push_back(dbus::ObjectPath(kPairedUnconnectableDevicePath)); |
279 } | 310 } |
280 | 311 |
281 FakeBluetoothDeviceClient::~FakeBluetoothDeviceClient() { | 312 FakeBluetoothDeviceClient::~FakeBluetoothDeviceClient() { |
282 // Clean up Properties structures | |
283 STLDeleteValues(&properties_map_); | |
284 } | 313 } |
285 | 314 |
286 void FakeBluetoothDeviceClient::Init(dbus::Bus* bus) { | 315 void FakeBluetoothDeviceClient::Init(dbus::Bus* bus) { |
287 } | 316 } |
288 | 317 |
289 void FakeBluetoothDeviceClient::AddObserver(Observer* observer) { | 318 void FakeBluetoothDeviceClient::AddObserver(Observer* observer) { |
290 observers_.AddObserver(observer); | 319 observers_.AddObserver(observer); |
291 } | 320 } |
292 | 321 |
293 void FakeBluetoothDeviceClient::RemoveObserver(Observer* observer) { | 322 void FakeBluetoothDeviceClient::RemoveObserver(Observer* observer) { |
294 observers_.RemoveObserver(observer); | 323 observers_.RemoveObserver(observer); |
295 } | 324 } |
296 | 325 |
297 std::vector<dbus::ObjectPath> FakeBluetoothDeviceClient::GetDevicesForAdapter( | 326 std::vector<dbus::ObjectPath> FakeBluetoothDeviceClient::GetDevicesForAdapter( |
298 const dbus::ObjectPath& adapter_path) { | 327 const dbus::ObjectPath& adapter_path) { |
299 if (adapter_path == | 328 if (adapter_path == |
300 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)) | 329 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)) |
301 return device_list_; | 330 return device_list_; |
302 else | 331 else |
303 return std::vector<dbus::ObjectPath>(); | 332 return std::vector<dbus::ObjectPath>(); |
304 } | 333 } |
305 | 334 |
306 FakeBluetoothDeviceClient::Properties* | 335 FakeBluetoothDeviceClient::Properties* |
307 FakeBluetoothDeviceClient::GetProperties(const dbus::ObjectPath& object_path) { | 336 FakeBluetoothDeviceClient::GetProperties(const dbus::ObjectPath& object_path) { |
308 PropertiesMap::iterator iter = properties_map_.find(object_path); | 337 PropertiesMap::const_iterator iter = properties_map_.find(object_path); |
309 if (iter != properties_map_.end()) | 338 if (iter != properties_map_.end()) |
310 return iter->second; | 339 return iter->second; |
311 return NULL; | 340 return NULL; |
312 } | 341 } |
313 | 342 |
| 343 FakeBluetoothDeviceClient::SimulatedPairingOptions* |
| 344 FakeBluetoothDeviceClient::GetPairingOptions( |
| 345 const dbus::ObjectPath& object_path) { |
| 346 PairingOptionsMap::const_iterator iter = |
| 347 pairing_options_map_.find(object_path); |
| 348 if (iter != pairing_options_map_.end()) |
| 349 return iter->second; |
| 350 return iter != pairing_options_map_.end() ? iter->second : nullptr; |
| 351 } |
| 352 |
314 void FakeBluetoothDeviceClient::Connect( | 353 void FakeBluetoothDeviceClient::Connect( |
315 const dbus::ObjectPath& object_path, | 354 const dbus::ObjectPath& object_path, |
316 const base::Closure& callback, | 355 const base::Closure& callback, |
317 const ErrorCallback& error_callback) { | 356 const ErrorCallback& error_callback) { |
318 VLOG(1) << "Connect: " << object_path.value(); | 357 VLOG(1) << "Connect: " << object_path.value(); |
319 Properties* properties = GetProperties(object_path); | 358 Properties* properties = GetProperties(object_path); |
320 | 359 |
321 if (properties->connected.value() == true) { | 360 if (properties->connected.value() == true) { |
322 // Already connected. | 361 // Already connected. |
323 callback.Run(); | 362 callback.Run(); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 void FakeBluetoothDeviceClient::BeginIncomingPairingSimulation( | 574 void FakeBluetoothDeviceClient::BeginIncomingPairingSimulation( |
536 const dbus::ObjectPath& adapter_path) { | 575 const dbus::ObjectPath& adapter_path) { |
537 VLOG(1) << "starting incoming pairing simulation"; | 576 VLOG(1) << "starting incoming pairing simulation"; |
538 | 577 |
539 incoming_pairing_simulation_step_ = 1; | 578 incoming_pairing_simulation_step_ = 1; |
540 | 579 |
541 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 580 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
542 FROM_HERE, | 581 FROM_HERE, |
543 base::Bind(&FakeBluetoothDeviceClient::IncomingPairingSimulationTimer, | 582 base::Bind(&FakeBluetoothDeviceClient::IncomingPairingSimulationTimer, |
544 base::Unretained(this)), | 583 base::Unretained(this)), |
545 base::TimeDelta::FromMilliseconds(30 * simulation_interval_ms_)); | 584 base::TimeDelta::FromMilliseconds( |
| 585 kIncomingSimulationStartPairTimeMultiplier * |
| 586 simulation_interval_ms_)); |
546 } | 587 } |
547 | 588 |
548 void FakeBluetoothDeviceClient::EndIncomingPairingSimulation( | 589 void FakeBluetoothDeviceClient::EndIncomingPairingSimulation( |
549 const dbus::ObjectPath& adapter_path) { | 590 const dbus::ObjectPath& adapter_path) { |
550 VLOG(1) << "stopping incoming pairing simulation"; | 591 VLOG(1) << "stopping incoming pairing simulation"; |
551 incoming_pairing_simulation_step_ = 0; | 592 incoming_pairing_simulation_step_ = 0; |
552 } | 593 } |
553 | 594 |
554 void FakeBluetoothDeviceClient::SetSimulationIntervalMs(int interval_ms) { | 595 void FakeBluetoothDeviceClient::SetSimulationIntervalMs(int interval_ms) { |
555 simulation_interval_ms_ = interval_ms; | 596 simulation_interval_ms_ = interval_ms; |
556 } | 597 } |
557 | 598 |
558 void FakeBluetoothDeviceClient::CreateDevice( | 599 void FakeBluetoothDeviceClient::CreateDevice( |
559 const dbus::ObjectPath& adapter_path, | 600 const dbus::ObjectPath& adapter_path, |
560 const dbus::ObjectPath& device_path) { | 601 const dbus::ObjectPath& device_path) { |
561 if (std::find(device_list_.begin(), | 602 if (std::find(device_list_.begin(), |
562 device_list_.end(), device_path) != device_list_.end()) | 603 device_list_.end(), device_path) != device_list_.end()) |
563 return; | 604 return; |
564 | 605 |
565 Properties* properties = new Properties(base::Bind( | 606 scoped_ptr<Properties> properties( |
566 &FakeBluetoothDeviceClient::OnPropertyChanged, | 607 new Properties(base::Bind(&FakeBluetoothDeviceClient::OnPropertyChanged, |
567 base::Unretained(this), | 608 base::Unretained(this), device_path))); |
568 device_path)); | |
569 properties->adapter.ReplaceValue(adapter_path); | 609 properties->adapter.ReplaceValue(adapter_path); |
570 | 610 |
571 if (device_path == dbus::ObjectPath(kLegacyAutopairPath)) { | 611 if (device_path == dbus::ObjectPath(kLegacyAutopairPath)) { |
572 properties->address.ReplaceValue(kLegacyAutopairAddress); | 612 properties->address.ReplaceValue(kLegacyAutopairAddress); |
573 properties->bluetooth_class.ReplaceValue(kLegacyAutopairClass); | 613 properties->bluetooth_class.ReplaceValue(kLegacyAutopairClass); |
574 properties->name.ReplaceValue("LegacyAutopair"); | 614 properties->name.ReplaceValue("LegacyAutopair"); |
575 properties->alias.ReplaceValue(kLegacyAutopairName); | 615 properties->alias.ReplaceValue(kLegacyAutopairName); |
576 | 616 |
577 std::vector<std::string> uuids; | 617 std::vector<std::string> uuids; |
578 uuids.push_back("00001124-0000-1000-8000-00805f9b34fb"); | 618 uuids.push_back("00001124-0000-1000-8000-00805f9b34fb"); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 | 698 |
659 std::vector<std::string> uuids; | 699 std::vector<std::string> uuids; |
660 uuids.push_back(FakeBluetoothGattServiceClient::kHeartRateServiceUUID); | 700 uuids.push_back(FakeBluetoothGattServiceClient::kHeartRateServiceUUID); |
661 properties->uuids.ReplaceValue(uuids); | 701 properties->uuids.ReplaceValue(uuids); |
662 | 702 |
663 } else { | 703 } else { |
664 NOTREACHED(); | 704 NOTREACHED(); |
665 | 705 |
666 } | 706 } |
667 | 707 |
668 properties_map_[device_path] = properties; | 708 properties_map_.insert(device_path, properties.Pass()); |
669 device_list_.push_back(device_path); | 709 device_list_.push_back(device_path); |
670 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, | 710 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, |
671 DeviceAdded(device_path)); | 711 DeviceAdded(device_path)); |
672 } | 712 } |
| 713 |
| 714 void FakeBluetoothDeviceClient::CreateDeviceWithProperties( |
| 715 const dbus::ObjectPath& adapter_path, |
| 716 const IncomingDeviceProperties& props) { |
| 717 dbus::ObjectPath device_path(props.device_path); |
| 718 if (std::find(device_list_.begin(), device_list_.end(), device_path) != |
| 719 device_list_.end()) |
| 720 return; |
| 721 |
| 722 scoped_ptr<Properties> properties( |
| 723 new Properties(base::Bind(&FakeBluetoothDeviceClient::OnPropertyChanged, |
| 724 base::Unretained(this), device_path))); |
| 725 properties->adapter.ReplaceValue(adapter_path); |
| 726 properties->name.ReplaceValue(props.device_name); |
| 727 properties->alias.ReplaceValue(props.device_alias); |
| 728 properties->address.ReplaceValue(props.device_address); |
| 729 properties->bluetooth_class.ReplaceValue(props.device_class); |
| 730 properties->trusted.ReplaceValue(props.is_trusted); |
| 731 |
| 732 if (props.is_trusted) |
| 733 properties->paired.ReplaceValue(true); |
| 734 |
| 735 scoped_ptr<SimulatedPairingOptions> options(new SimulatedPairingOptions); |
| 736 options->pairing_method = props.pairing_method; |
| 737 options->pairing_auth_token = props.pairing_auth_token; |
| 738 |
| 739 properties_map_.insert(device_path, properties.Pass()); |
| 740 device_list_.push_back(device_path); |
| 741 pairing_options_map_.insert(device_path, options.Pass()); |
| 742 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, |
| 743 DeviceAdded(device_path)); |
| 744 } |
673 | 745 |
674 void FakeBluetoothDeviceClient::RemoveDevice( | 746 void FakeBluetoothDeviceClient::RemoveDevice( |
675 const dbus::ObjectPath& adapter_path, | 747 const dbus::ObjectPath& adapter_path, |
676 const dbus::ObjectPath& device_path) { | 748 const dbus::ObjectPath& device_path) { |
677 std::vector<dbus::ObjectPath>::iterator listiter = | 749 std::vector<dbus::ObjectPath>::iterator listiter = |
678 std::find(device_list_.begin(), device_list_.end(), device_path); | 750 std::find(device_list_.begin(), device_list_.end(), device_path); |
679 if (listiter == device_list_.end()) | 751 if (listiter == device_list_.end()) |
680 return; | 752 return; |
681 | 753 |
682 PropertiesMap::iterator iter = properties_map_.find(device_path); | 754 PropertiesMap::const_iterator iter = properties_map_.find(device_path); |
683 Properties* properties = iter->second; | 755 Properties* properties = iter->second; |
684 | 756 |
685 VLOG(1) << "removing device: " << properties->alias.value(); | 757 VLOG(1) << "removing device: " << properties->alias.value(); |
686 device_list_.erase(listiter); | 758 device_list_.erase(listiter); |
687 | 759 |
688 // Remove the Input interface if it exists. This should be called before the | 760 // Remove the Input interface if it exists. This should be called before the |
689 // BluetoothDeviceClient::Observer::DeviceRemoved because it deletes the | 761 // BluetoothDeviceClient::Observer::DeviceRemoved because it deletes the |
690 // BluetoothDeviceChromeOS object, including the device_path referenced here. | 762 // BluetoothDeviceChromeOS object, including the device_path referenced here. |
691 FakeBluetoothInputClient* fake_bluetooth_input_client = | 763 FakeBluetoothInputClient* fake_bluetooth_input_client = |
692 static_cast<FakeBluetoothInputClient*>( | 764 static_cast<FakeBluetoothInputClient*>( |
693 DBusThreadManager::Get()->GetBluetoothInputClient()); | 765 DBusThreadManager::Get()->GetBluetoothInputClient()); |
694 fake_bluetooth_input_client->RemoveInputDevice(device_path); | 766 fake_bluetooth_input_client->RemoveInputDevice(device_path); |
695 | 767 |
696 if (device_path == dbus::ObjectPath(kLowEnergyPath)) { | 768 if (device_path == dbus::ObjectPath(kLowEnergyPath)) { |
697 FakeBluetoothGattServiceClient* gatt_service_client = | 769 FakeBluetoothGattServiceClient* gatt_service_client = |
698 static_cast<FakeBluetoothGattServiceClient*>( | 770 static_cast<FakeBluetoothGattServiceClient*>( |
699 DBusThreadManager::Get()->GetBluetoothGattServiceClient()); | 771 DBusThreadManager::Get()->GetBluetoothGattServiceClient()); |
700 gatt_service_client->HideHeartRateService(); | 772 gatt_service_client->HideHeartRateService(); |
701 } | 773 } |
702 | 774 |
703 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, | 775 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, |
704 DeviceRemoved(device_path)); | 776 DeviceRemoved(device_path)); |
705 | 777 |
706 delete properties; | |
707 properties_map_.erase(iter); | 778 properties_map_.erase(iter); |
| 779 PairingOptionsMap::const_iterator options_iter = |
| 780 pairing_options_map_.find(device_path); |
| 781 |
| 782 if (options_iter != pairing_options_map_.end()) { |
| 783 pairing_options_map_.erase(options_iter); |
| 784 } |
708 } | 785 } |
709 | 786 |
710 void FakeBluetoothDeviceClient::OnPropertyChanged( | 787 void FakeBluetoothDeviceClient::OnPropertyChanged( |
711 const dbus::ObjectPath& object_path, | 788 const dbus::ObjectPath& object_path, |
712 const std::string& property_name) { | 789 const std::string& property_name) { |
713 VLOG(2) << "Fake Bluetooth device property changed: " << object_path.value() | 790 VLOG(2) << "Fake Bluetooth device property changed: " << object_path.value() |
714 << ": " << property_name; | 791 << ": " << property_name; |
715 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, | 792 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, |
716 DevicePropertyChanged(object_path, property_name)); | 793 DevicePropertyChanged(object_path, property_name)); |
717 } | 794 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 840 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
764 dbus::ObjectPath(kJustWorksPath)); | 841 dbus::ObjectPath(kJustWorksPath)); |
765 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), | 842 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), |
766 base::RandInt(kMinRSSI, kMaxRSSI)); | 843 base::RandInt(kMinRSSI, kMaxRSSI)); |
767 | 844 |
768 } else if (discovery_simulation_step_ == 13) { | 845 } else if (discovery_simulation_step_ == 13) { |
769 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), | 846 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), |
770 base::RandInt(kMinRSSI, kMaxRSSI)); | 847 base::RandInt(kMinRSSI, kMaxRSSI)); |
771 RemoveDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 848 RemoveDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
772 dbus::ObjectPath(kVanishingDevicePath)); | 849 dbus::ObjectPath(kVanishingDevicePath)); |
773 | |
774 } else if (discovery_simulation_step_ == 14) { | 850 } else if (discovery_simulation_step_ == 14) { |
775 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), | 851 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), |
776 base::RandInt(kMinRSSI, kMaxRSSI)); | 852 base::RandInt(kMinRSSI, kMaxRSSI)); |
777 return; | 853 return; |
778 | 854 |
779 } | 855 } |
780 | 856 |
781 ++discovery_simulation_step_; | 857 ++discovery_simulation_step_; |
782 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 858 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
783 FROM_HERE, | 859 FROM_HERE, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 break; | 913 break; |
838 default: | 914 default: |
839 return; | 915 return; |
840 } | 916 } |
841 | 917 |
842 ++incoming_pairing_simulation_step_; | 918 ++incoming_pairing_simulation_step_; |
843 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 919 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
844 FROM_HERE, | 920 FROM_HERE, |
845 base::Bind(&FakeBluetoothDeviceClient::IncomingPairingSimulationTimer, | 921 base::Bind(&FakeBluetoothDeviceClient::IncomingPairingSimulationTimer, |
846 base::Unretained(this)), | 922 base::Unretained(this)), |
847 base::TimeDelta::FromMilliseconds(45 * simulation_interval_ms_)); | 923 base::TimeDelta::FromMilliseconds(kIncomingSimulationPairTimeMultiplier * |
| 924 simulation_interval_ms_)); |
848 } | 925 } |
849 | 926 |
850 void FakeBluetoothDeviceClient::SimulatePairing( | 927 void FakeBluetoothDeviceClient::SimulatePairing( |
851 const dbus::ObjectPath& object_path, | 928 const dbus::ObjectPath& object_path, |
852 bool incoming_request, | 929 bool incoming_request, |
853 const base::Closure& callback, | 930 const base::Closure& callback, |
854 const ErrorCallback& error_callback) { | 931 const ErrorCallback& error_callback) { |
855 pairing_cancelled_ = false; | 932 pairing_cancelled_ = false; |
856 | 933 |
857 FakeBluetoothAgentManagerClient* fake_bluetooth_agent_manager_client = | 934 FakeBluetoothAgentManagerClient* fake_bluetooth_agent_manager_client = |
858 static_cast<FakeBluetoothAgentManagerClient*>( | 935 static_cast<FakeBluetoothAgentManagerClient*>( |
859 DBusThreadManager::Get()->GetBluetoothAgentManagerClient()); | 936 DBusThreadManager::Get()->GetBluetoothAgentManagerClient()); |
860 FakeBluetoothAgentServiceProvider* agent_service_provider = | 937 FakeBluetoothAgentServiceProvider* agent_service_provider = |
861 fake_bluetooth_agent_manager_client->GetAgentServiceProvider(); | 938 fake_bluetooth_agent_manager_client->GetAgentServiceProvider(); |
862 CHECK(agent_service_provider != NULL); | 939 CHECK(agent_service_provider != NULL); |
863 | 940 |
864 if (object_path == dbus::ObjectPath(kLegacyAutopairPath) || | 941 // Grab the device's pairing properties. |
865 object_path == dbus::ObjectPath(kConnectUnpairablePath) || | 942 PairingOptionsMap::const_iterator iter = |
866 object_path == dbus::ObjectPath(kUnconnectableDevicePath) || | 943 pairing_options_map_.find(object_path); |
867 object_path == dbus::ObjectPath(kLowEnergyPath)) { | |
868 // No need to call anything on the pairing delegate, just wait 3 times | |
869 // the interval before acting as if the other end accepted it. | |
870 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
871 FROM_HERE, | |
872 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, | |
873 base::Unretained(this), object_path, callback, | |
874 error_callback), | |
875 base::TimeDelta::FromMilliseconds(3 * simulation_interval_ms_)); | |
876 | 944 |
877 } else if (object_path == dbus::ObjectPath(kDisplayPinCodePath)) { | 945 // If the device with path |object_path| has simulated pairing properties |
878 // Display a Pincode, and wait 7 times the interval before acting as | 946 // defined, then pair it based on its |pairing_method|. |
879 // if the other end accepted it. | 947 if (iter != pairing_options_map_.end()) { |
880 agent_service_provider->DisplayPinCode(object_path, "123456"); | 948 if (iter->second->pairing_method == kPairingMethodNone || |
| 949 iter->second->pairing_method.empty()) { |
| 950 // Simply pair and connect the device. |
| 951 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 952 FROM_HERE, |
| 953 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, |
| 954 base::Unretained(this), object_path, callback, |
| 955 error_callback), |
| 956 base::TimeDelta::FromMilliseconds(kSimulateNormalPairTimeMultiplier * |
| 957 simulation_interval_ms_)); |
| 958 } else if (iter->second->pairing_method == kPairingMethodPinCode) { |
| 959 // Display a Pincode, and wait before acting as if the other end accepted |
| 960 // it. |
| 961 agent_service_provider->DisplayPinCode(object_path, |
| 962 iter->second->pairing_auth_token); |
881 | 963 |
882 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 964 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
883 FROM_HERE, | 965 FROM_HERE, |
884 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, | 966 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, |
885 base::Unretained(this), object_path, callback, | 967 base::Unretained(this), object_path, callback, |
886 error_callback), | 968 error_callback), |
887 base::TimeDelta::FromMilliseconds(7 * simulation_interval_ms_)); | 969 base::TimeDelta::FromMilliseconds(kPinCodeDevicePairTimeMultiplier * |
| 970 simulation_interval_ms_)); |
| 971 } else if (iter->second->pairing_method == kPairingMethodPassKey) { |
| 972 // Display a passkey, and each interval act as if another key was entered |
| 973 // for it. |
| 974 agent_service_provider->DisplayPasskey( |
| 975 object_path, std::stoi(iter->second->pairing_auth_token), 0); |
888 | 976 |
889 } else if (object_path == dbus::ObjectPath(kVanishingDevicePath)) { | 977 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
890 // The vanishing device simulates being too far away, and thus times out. | 978 FROM_HERE, base::Bind(&FakeBluetoothDeviceClient::SimulateKeypress, |
891 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 979 base::Unretained(this), 1, object_path, |
892 FROM_HERE, | 980 callback, error_callback), |
893 base::Bind(&FakeBluetoothDeviceClient::TimeoutSimulatedPairing, | 981 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); |
894 base::Unretained(this), object_path, error_callback), | 982 } |
895 base::TimeDelta::FromMilliseconds(4 * simulation_interval_ms_)); | 983 } else { |
896 | 984 if (object_path == dbus::ObjectPath(kLegacyAutopairPath) || |
897 } else if (object_path == dbus::ObjectPath(kDisplayPasskeyPath)) { | 985 object_path == dbus::ObjectPath(kConnectUnpairablePath) || |
898 // Display a passkey, and each interval act as if another key was entered | 986 object_path == dbus::ObjectPath(kUnconnectableDevicePath) || |
899 // for it. | 987 object_path == dbus::ObjectPath(kLowEnergyPath)) { |
900 agent_service_provider->DisplayPasskey(object_path, 123456, 0); | |
901 | |
902 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
903 FROM_HERE, base::Bind(&FakeBluetoothDeviceClient::SimulateKeypress, | |
904 base::Unretained(this), 1, object_path, callback, | |
905 error_callback), | |
906 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); | |
907 | |
908 } else if (object_path == dbus::ObjectPath(kRequestPinCodePath)) { | |
909 // Request a Pincode. | |
910 agent_service_provider->RequestPinCode( | |
911 object_path, | |
912 base::Bind(&FakeBluetoothDeviceClient::PinCodeCallback, | |
913 base::Unretained(this), | |
914 object_path, | |
915 callback, | |
916 error_callback)); | |
917 | |
918 } else if (object_path == dbus::ObjectPath(kConfirmPasskeyPath)) { | |
919 // Request confirmation of a Passkey. | |
920 agent_service_provider->RequestConfirmation( | |
921 object_path, 123456, | |
922 base::Bind(&FakeBluetoothDeviceClient::ConfirmationCallback, | |
923 base::Unretained(this), | |
924 object_path, | |
925 callback, | |
926 error_callback)); | |
927 | |
928 } else if (object_path == dbus::ObjectPath(kRequestPasskeyPath)) { | |
929 // Request a Passkey from the user. | |
930 agent_service_provider->RequestPasskey( | |
931 object_path, | |
932 base::Bind(&FakeBluetoothDeviceClient::PasskeyCallback, | |
933 base::Unretained(this), | |
934 object_path, | |
935 callback, | |
936 error_callback)); | |
937 | |
938 } else if (object_path == dbus::ObjectPath(kUnpairableDevicePath)) { | |
939 // Fails the pairing with an org.bluez.Error.Failed error. | |
940 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
941 FROM_HERE, | |
942 base::Bind(&FakeBluetoothDeviceClient::FailSimulatedPairing, | |
943 base::Unretained(this), object_path, error_callback), | |
944 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); | |
945 | |
946 } else if (object_path == dbus::ObjectPath(kJustWorksPath)) { | |
947 if (incoming_request) { | |
948 agent_service_provider->RequestAuthorization( | |
949 object_path, | |
950 base::Bind(&FakeBluetoothDeviceClient::ConfirmationCallback, | |
951 base::Unretained(this), | |
952 object_path, | |
953 callback, | |
954 error_callback)); | |
955 | |
956 } else { | |
957 // No need to call anything on the pairing delegate, just wait 3 times | 988 // No need to call anything on the pairing delegate, just wait 3 times |
958 // the interval before acting as if the other end accepted it. | 989 // the interval before acting as if the other end accepted it. |
959 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 990 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
960 FROM_HERE, | 991 FROM_HERE, |
961 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, | 992 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, |
962 base::Unretained(this), object_path, callback, | 993 base::Unretained(this), object_path, callback, |
963 error_callback), | 994 error_callback), |
964 base::TimeDelta::FromMilliseconds(3 * simulation_interval_ms_)); | 995 base::TimeDelta::FromMilliseconds(kSimulateNormalPairTimeMultiplier * |
| 996 simulation_interval_ms_)); |
| 997 |
| 998 } else if (object_path == dbus::ObjectPath(kDisplayPinCodePath)) { |
| 999 // Display a Pincode, and wait before acting as if the other end accepted |
| 1000 // it. |
| 1001 agent_service_provider->DisplayPinCode(object_path, kTestPinCode); |
| 1002 |
| 1003 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1004 FROM_HERE, |
| 1005 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, |
| 1006 base::Unretained(this), object_path, callback, |
| 1007 error_callback), |
| 1008 base::TimeDelta::FromMilliseconds(kPinCodeDevicePairTimeMultiplier * |
| 1009 simulation_interval_ms_)); |
| 1010 |
| 1011 } else if (object_path == dbus::ObjectPath(kVanishingDevicePath)) { |
| 1012 // The vanishing device simulates being too far away, and thus times out. |
| 1013 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1014 FROM_HERE, |
| 1015 base::Bind(&FakeBluetoothDeviceClient::TimeoutSimulatedPairing, |
| 1016 base::Unretained(this), object_path, error_callback), |
| 1017 base::TimeDelta::FromMilliseconds(kVanishingDevicePairTimeMultiplier * |
| 1018 simulation_interval_ms_)); |
| 1019 |
| 1020 } else if (object_path == dbus::ObjectPath(kDisplayPasskeyPath)) { |
| 1021 // Display a passkey, and each interval act as if another key was entered |
| 1022 // for it. |
| 1023 agent_service_provider->DisplayPasskey(object_path, kTestPassKey, 0); |
| 1024 |
| 1025 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1026 FROM_HERE, base::Bind(&FakeBluetoothDeviceClient::SimulateKeypress, |
| 1027 base::Unretained(this), 1, object_path, |
| 1028 callback, error_callback), |
| 1029 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); |
| 1030 |
| 1031 } else if (object_path == dbus::ObjectPath(kRequestPinCodePath)) { |
| 1032 // Request a Pincode. |
| 1033 agent_service_provider->RequestPinCode( |
| 1034 object_path, base::Bind(&FakeBluetoothDeviceClient::PinCodeCallback, |
| 1035 base::Unretained(this), object_path, callback, |
| 1036 error_callback)); |
| 1037 |
| 1038 } else if (object_path == dbus::ObjectPath(kConfirmPasskeyPath)) { |
| 1039 // Request confirmation of a Passkey. |
| 1040 agent_service_provider->RequestConfirmation( |
| 1041 object_path, kTestPassKey, |
| 1042 base::Bind(&FakeBluetoothDeviceClient::ConfirmationCallback, |
| 1043 base::Unretained(this), object_path, callback, |
| 1044 error_callback)); |
| 1045 |
| 1046 } else if (object_path == dbus::ObjectPath(kRequestPasskeyPath)) { |
| 1047 // Request a Passkey from the user. |
| 1048 agent_service_provider->RequestPasskey( |
| 1049 object_path, base::Bind(&FakeBluetoothDeviceClient::PasskeyCallback, |
| 1050 base::Unretained(this), object_path, callback, |
| 1051 error_callback)); |
| 1052 |
| 1053 } else if (object_path == dbus::ObjectPath(kUnpairableDevicePath)) { |
| 1054 // Fails the pairing with an org.bluez.Error.Failed error. |
| 1055 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1056 FROM_HERE, |
| 1057 base::Bind(&FakeBluetoothDeviceClient::FailSimulatedPairing, |
| 1058 base::Unretained(this), object_path, error_callback), |
| 1059 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); |
| 1060 |
| 1061 } else if (object_path == dbus::ObjectPath(kJustWorksPath)) { |
| 1062 if (incoming_request) { |
| 1063 agent_service_provider->RequestAuthorization( |
| 1064 object_path, |
| 1065 base::Bind(&FakeBluetoothDeviceClient::ConfirmationCallback, |
| 1066 base::Unretained(this), object_path, callback, |
| 1067 error_callback)); |
| 1068 |
| 1069 } else { |
| 1070 // No need to call anything on the pairing delegate, just wait before |
| 1071 // acting as if the other end accepted it. |
| 1072 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1073 FROM_HERE, |
| 1074 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, |
| 1075 base::Unretained(this), object_path, callback, |
| 1076 error_callback), |
| 1077 base::TimeDelta::FromMilliseconds( |
| 1078 kSimulateNormalPairTimeMultiplier * simulation_interval_ms_)); |
| 1079 } |
| 1080 |
| 1081 } else { |
| 1082 error_callback.Run(kNoResponseError, "No pairing fake"); |
965 } | 1083 } |
966 | |
967 } else { | |
968 error_callback.Run(kNoResponseError, "No pairing fake"); | |
969 } | 1084 } |
970 } | 1085 } |
971 | 1086 |
972 void FakeBluetoothDeviceClient::CompleteSimulatedPairing( | 1087 void FakeBluetoothDeviceClient::CompleteSimulatedPairing( |
973 const dbus::ObjectPath& object_path, | 1088 const dbus::ObjectPath& object_path, |
974 const base::Closure& callback, | 1089 const base::Closure& callback, |
975 const ErrorCallback& error_callback) { | 1090 const ErrorCallback& error_callback) { |
976 VLOG(1) << "CompleteSimulatedPairing: " << object_path.value(); | 1091 VLOG(1) << "CompleteSimulatedPairing: " << object_path.value(); |
977 if (pairing_cancelled_) { | 1092 if (pairing_cancelled_) { |
978 pairing_cancelled_ = false; | 1093 pairing_cancelled_ = false; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 static_cast<FakeBluetoothInputClient*>( | 1148 static_cast<FakeBluetoothInputClient*>( |
1034 DBusThreadManager::Get()->GetBluetoothInputClient()); | 1149 DBusThreadManager::Get()->GetBluetoothInputClient()); |
1035 | 1150 |
1036 if ((properties->bluetooth_class.value() & 0x001f03) == 0x000500) | 1151 if ((properties->bluetooth_class.value() & 0x001f03) == 0x000500) |
1037 fake_bluetooth_input_client->AddInputDevice(object_path); | 1152 fake_bluetooth_input_client->AddInputDevice(object_path); |
1038 } | 1153 } |
1039 | 1154 |
1040 void FakeBluetoothDeviceClient::UpdateDeviceRSSI( | 1155 void FakeBluetoothDeviceClient::UpdateDeviceRSSI( |
1041 const dbus::ObjectPath& object_path, | 1156 const dbus::ObjectPath& object_path, |
1042 int16 rssi) { | 1157 int16 rssi) { |
1043 PropertiesMap::iterator iter = properties_map_.find(object_path); | 1158 PropertiesMap::const_iterator iter = properties_map_.find(object_path); |
1044 if (iter == properties_map_.end()) { | 1159 if (iter == properties_map_.end()) { |
1045 VLOG(2) << "Fake device does not exist: " << object_path.value(); | 1160 VLOG(2) << "Fake device does not exist: " << object_path.value(); |
1046 return; | 1161 return; |
1047 } | 1162 } |
1048 Properties* properties = iter->second; | 1163 Properties* properties = iter->second; |
1049 DCHECK(properties); | 1164 DCHECK(properties); |
1050 properties->rssi.ReplaceValue(rssi); | 1165 properties->rssi.ReplaceValue(rssi); |
1051 } | 1166 } |
1052 | 1167 |
1053 void FakeBluetoothDeviceClient::UpdateConnectionInfo( | 1168 void FakeBluetoothDeviceClient::UpdateConnectionInfo( |
(...skipping 12 matching lines...) Expand all Loading... |
1066 BluetoothAgentServiceProvider::Delegate::Status status, | 1181 BluetoothAgentServiceProvider::Delegate::Status status, |
1067 const std::string& pincode) { | 1182 const std::string& pincode) { |
1068 VLOG(1) << "PinCodeCallback: " << object_path.value(); | 1183 VLOG(1) << "PinCodeCallback: " << object_path.value(); |
1069 | 1184 |
1070 if (status == BluetoothAgentServiceProvider::Delegate::SUCCESS) { | 1185 if (status == BluetoothAgentServiceProvider::Delegate::SUCCESS) { |
1071 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1186 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
1072 FROM_HERE, | 1187 FROM_HERE, |
1073 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, | 1188 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, |
1074 base::Unretained(this), object_path, callback, | 1189 base::Unretained(this), object_path, callback, |
1075 error_callback), | 1190 error_callback), |
1076 base::TimeDelta::FromMilliseconds(3 * simulation_interval_ms_)); | 1191 base::TimeDelta::FromMilliseconds(kSimulateNormalPairTimeMultiplier * |
| 1192 simulation_interval_ms_)); |
1077 | 1193 |
1078 } else if (status == BluetoothAgentServiceProvider::Delegate::CANCELLED) { | 1194 } else if (status == BluetoothAgentServiceProvider::Delegate::CANCELLED) { |
1079 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1195 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
1080 FROM_HERE, | 1196 FROM_HERE, |
1081 base::Bind(&FakeBluetoothDeviceClient::CancelSimulatedPairing, | 1197 base::Bind(&FakeBluetoothDeviceClient::CancelSimulatedPairing, |
1082 base::Unretained(this), object_path, error_callback), | 1198 base::Unretained(this), object_path, error_callback), |
1083 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); | 1199 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); |
1084 | 1200 |
1085 } else if (status == BluetoothAgentServiceProvider::Delegate::REJECTED) { | 1201 } else if (status == BluetoothAgentServiceProvider::Delegate::REJECTED) { |
1086 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1202 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
(...skipping 11 matching lines...) Expand all Loading... |
1098 BluetoothAgentServiceProvider::Delegate::Status status, | 1214 BluetoothAgentServiceProvider::Delegate::Status status, |
1099 uint32 passkey) { | 1215 uint32 passkey) { |
1100 VLOG(1) << "PasskeyCallback: " << object_path.value(); | 1216 VLOG(1) << "PasskeyCallback: " << object_path.value(); |
1101 | 1217 |
1102 if (status == BluetoothAgentServiceProvider::Delegate::SUCCESS) { | 1218 if (status == BluetoothAgentServiceProvider::Delegate::SUCCESS) { |
1103 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1219 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
1104 FROM_HERE, | 1220 FROM_HERE, |
1105 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, | 1221 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, |
1106 base::Unretained(this), object_path, callback, | 1222 base::Unretained(this), object_path, callback, |
1107 error_callback), | 1223 error_callback), |
1108 base::TimeDelta::FromMilliseconds(3 * simulation_interval_ms_)); | 1224 base::TimeDelta::FromMilliseconds(kSimulateNormalPairTimeMultiplier * |
| 1225 simulation_interval_ms_)); |
1109 | 1226 |
1110 } else if (status == BluetoothAgentServiceProvider::Delegate::CANCELLED) { | 1227 } else if (status == BluetoothAgentServiceProvider::Delegate::CANCELLED) { |
1111 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1228 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
1112 FROM_HERE, | 1229 FROM_HERE, |
1113 base::Bind(&FakeBluetoothDeviceClient::CancelSimulatedPairing, | 1230 base::Bind(&FakeBluetoothDeviceClient::CancelSimulatedPairing, |
1114 base::Unretained(this), object_path, error_callback), | 1231 base::Unretained(this), object_path, error_callback), |
1115 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); | 1232 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); |
1116 | 1233 |
1117 } else if (status == BluetoothAgentServiceProvider::Delegate::REJECTED) { | 1234 } else if (status == BluetoothAgentServiceProvider::Delegate::REJECTED) { |
1118 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1235 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
(...skipping 10 matching lines...) Expand all Loading... |
1129 const ErrorCallback& error_callback, | 1246 const ErrorCallback& error_callback, |
1130 BluetoothAgentServiceProvider::Delegate::Status status) { | 1247 BluetoothAgentServiceProvider::Delegate::Status status) { |
1131 VLOG(1) << "ConfirmationCallback: " << object_path.value(); | 1248 VLOG(1) << "ConfirmationCallback: " << object_path.value(); |
1132 | 1249 |
1133 if (status == BluetoothAgentServiceProvider::Delegate::SUCCESS) { | 1250 if (status == BluetoothAgentServiceProvider::Delegate::SUCCESS) { |
1134 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1251 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
1135 FROM_HERE, | 1252 FROM_HERE, |
1136 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, | 1253 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, |
1137 base::Unretained(this), object_path, callback, | 1254 base::Unretained(this), object_path, callback, |
1138 error_callback), | 1255 error_callback), |
1139 base::TimeDelta::FromMilliseconds(3 * simulation_interval_ms_)); | 1256 base::TimeDelta::FromMilliseconds(kSimulateNormalPairTimeMultiplier * |
| 1257 simulation_interval_ms_)); |
1140 | 1258 |
1141 } else if (status == BluetoothAgentServiceProvider::Delegate::CANCELLED) { | 1259 } else if (status == BluetoothAgentServiceProvider::Delegate::CANCELLED) { |
1142 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1260 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
1143 FROM_HERE, | 1261 FROM_HERE, |
1144 base::Bind(&FakeBluetoothDeviceClient::CancelSimulatedPairing, | 1262 base::Bind(&FakeBluetoothDeviceClient::CancelSimulatedPairing, |
1145 base::Unretained(this), object_path, error_callback), | 1263 base::Unretained(this), object_path, error_callback), |
1146 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); | 1264 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); |
1147 | 1265 |
1148 } else if (status == BluetoothAgentServiceProvider::Delegate::REJECTED) { | 1266 } else if (status == BluetoothAgentServiceProvider::Delegate::REJECTED) { |
1149 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1267 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
(...skipping 15 matching lines...) Expand all Loading... |
1165 static_cast<FakeBluetoothAgentManagerClient*>( | 1283 static_cast<FakeBluetoothAgentManagerClient*>( |
1166 DBusThreadManager::Get()->GetBluetoothAgentManagerClient()); | 1284 DBusThreadManager::Get()->GetBluetoothAgentManagerClient()); |
1167 FakeBluetoothAgentServiceProvider* agent_service_provider = | 1285 FakeBluetoothAgentServiceProvider* agent_service_provider = |
1168 fake_bluetooth_agent_manager_client->GetAgentServiceProvider(); | 1286 fake_bluetooth_agent_manager_client->GetAgentServiceProvider(); |
1169 | 1287 |
1170 // The agent service provider object could have been destroyed after the | 1288 // The agent service provider object could have been destroyed after the |
1171 // pairing is canceled. | 1289 // pairing is canceled. |
1172 if (!agent_service_provider) | 1290 if (!agent_service_provider) |
1173 return; | 1291 return; |
1174 | 1292 |
1175 agent_service_provider->DisplayPasskey(object_path, 123456, entered); | 1293 agent_service_provider->DisplayPasskey(object_path, kTestPassKey, entered); |
1176 | 1294 |
1177 if (entered < 7) { | 1295 if (entered < 7) { |
1178 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1296 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
1179 FROM_HERE, base::Bind(&FakeBluetoothDeviceClient::SimulateKeypress, | 1297 FROM_HERE, base::Bind(&FakeBluetoothDeviceClient::SimulateKeypress, |
1180 base::Unretained(this), entered + 1, object_path, | 1298 base::Unretained(this), entered + 1, object_path, |
1181 callback, error_callback), | 1299 callback, error_callback), |
1182 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); | 1300 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); |
1183 | 1301 |
1184 } else { | 1302 } else { |
1185 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1303 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1220 // TODO(keybuk): tear down this side of the connection | 1338 // TODO(keybuk): tear down this side of the connection |
1221 callback.Run(); | 1339 callback.Run(); |
1222 } else if (status == BluetoothProfileServiceProvider::Delegate::CANCELLED) { | 1340 } else if (status == BluetoothProfileServiceProvider::Delegate::CANCELLED) { |
1223 error_callback.Run(bluetooth_device::kErrorFailed, "Canceled"); | 1341 error_callback.Run(bluetooth_device::kErrorFailed, "Canceled"); |
1224 } else if (status == BluetoothProfileServiceProvider::Delegate::REJECTED) { | 1342 } else if (status == BluetoothProfileServiceProvider::Delegate::REJECTED) { |
1225 error_callback.Run(bluetooth_device::kErrorFailed, "Rejected"); | 1343 error_callback.Run(bluetooth_device::kErrorFailed, "Rejected"); |
1226 } | 1344 } |
1227 } | 1345 } |
1228 | 1346 |
1229 } // namespace chromeos | 1347 } // namespace chromeos |
OLD | NEW |