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