Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(425)

Side by Side Diff: chromeos/dbus/fake_bluetooth_device_client.cc

Issue 183853010: Bluetooth: notify user of incoming pairing requests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fit nits, add unit tests dep Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chromeos/dbus/fake_bluetooth_device_client.h" 5 #include "chromeos/dbus/fake_bluetooth_device_client.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <unistd.h> 8 #include <unistd.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 #include <sys/socket.h> 10 #include <sys/socket.h>
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 count = len; 55 count = len;
56 len = write(fd, buf, count); 56 len = write(fd, buf, count);
57 if (len < 0) { 57 if (len < 0) {
58 close(fd); 58 close(fd);
59 return; 59 return;
60 } 60 }
61 61
62 close(fd); 62 close(fd);
63 } 63 }
64 64
65 void SimpleErrorCallback(const std::string& error_name,
66 const std::string& error_message) {
67 VLOG(1) << "Bluetooth Error: " << error_name << ": " << error_message;
68 }
69
65 } // namespace 70 } // namespace
66 71
67 namespace chromeos { 72 namespace chromeos {
68 73
69 const char FakeBluetoothDeviceClient::kPairedDevicePath[] = 74 const char FakeBluetoothDeviceClient::kPairedDevicePath[] =
70 "/fake/hci0/dev0"; 75 "/fake/hci0/dev0";
71 const char FakeBluetoothDeviceClient::kPairedDeviceAddress[] = 76 const char FakeBluetoothDeviceClient::kPairedDeviceAddress[] =
72 "00:11:22:33:44:55"; 77 "00:11:22:33:44:55";
73 const char FakeBluetoothDeviceClient::kPairedDeviceName[] = 78 const char FakeBluetoothDeviceClient::kPairedDeviceName[] =
74 "Fake Device"; 79 "Fake Device";
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 callback.Run(true); 197 callback.Run(true);
193 property->ReplaceValueWithSetValue(); 198 property->ReplaceValueWithSetValue();
194 } else { 199 } else {
195 callback.Run(false); 200 callback.Run(false);
196 } 201 }
197 } 202 }
198 203
199 FakeBluetoothDeviceClient::FakeBluetoothDeviceClient() 204 FakeBluetoothDeviceClient::FakeBluetoothDeviceClient()
200 : simulation_interval_ms_(kSimulationIntervalMs), 205 : simulation_interval_ms_(kSimulationIntervalMs),
201 discovery_simulation_step_(0), 206 discovery_simulation_step_(0),
207 incoming_pairing_simulation_step_(0),
202 pairing_cancelled_(false) { 208 pairing_cancelled_(false) {
203 Properties* properties = new Properties(base::Bind( 209 Properties* properties = new Properties(base::Bind(
204 &FakeBluetoothDeviceClient::OnPropertyChanged, 210 &FakeBluetoothDeviceClient::OnPropertyChanged,
205 base::Unretained(this), 211 base::Unretained(this),
206 dbus::ObjectPath(kPairedDevicePath))); 212 dbus::ObjectPath(kPairedDevicePath)));
207 properties->address.ReplaceValue(kPairedDeviceAddress); 213 properties->address.ReplaceValue(kPairedDeviceAddress);
208 properties->bluetooth_class.ReplaceValue(kPairedDeviceClass); 214 properties->bluetooth_class.ReplaceValue(kPairedDeviceClass);
209 properties->name.ReplaceValue("Fake Device (Name)"); 215 properties->name.ReplaceValue("Fake Device (Name)");
210 properties->alias.ReplaceValue(kPairedDeviceName); 216 properties->alias.ReplaceValue(kPairedDeviceName);
211 properties->paired.ReplaceValue(true); 217 properties->paired.ReplaceValue(true);
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 base::Unretained(this)), 439 base::Unretained(this)),
434 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); 440 base::TimeDelta::FromMilliseconds(simulation_interval_ms_));
435 } 441 }
436 442
437 void FakeBluetoothDeviceClient::EndDiscoverySimulation( 443 void FakeBluetoothDeviceClient::EndDiscoverySimulation(
438 const dbus::ObjectPath& adapter_path) { 444 const dbus::ObjectPath& adapter_path) {
439 VLOG(1) << "stopping discovery simulation"; 445 VLOG(1) << "stopping discovery simulation";
440 discovery_simulation_step_ = 0; 446 discovery_simulation_step_ = 0;
441 } 447 }
442 448
449 void FakeBluetoothDeviceClient::BeginIncomingPairingSimulation(
450 const dbus::ObjectPath& adapter_path) {
451 VLOG(1) << "starting incoming pairing simulation";
452
453 incoming_pairing_simulation_step_ = 1;
454
455 base::MessageLoop::current()->PostDelayedTask(
456 FROM_HERE,
457 base::Bind(&FakeBluetoothDeviceClient::IncomingPairingSimulationTimer,
458 base::Unretained(this)),
459 base::TimeDelta::FromMilliseconds(30 * simulation_interval_ms_));
460 }
461
462 void FakeBluetoothDeviceClient::EndIncomingPairingSimulation(
463 const dbus::ObjectPath& adapter_path) {
464 VLOG(1) << "stopping incoming pairing simulation";
465 incoming_pairing_simulation_step_ = 0;
466 }
467
443 void FakeBluetoothDeviceClient::SetSimulationIntervalMs(int interval_ms) { 468 void FakeBluetoothDeviceClient::SetSimulationIntervalMs(int interval_ms) {
444 simulation_interval_ms_ = interval_ms; 469 simulation_interval_ms_ = interval_ms;
445 } 470 }
446 471
447 void FakeBluetoothDeviceClient::CreateDevice( 472 void FakeBluetoothDeviceClient::CreateDevice(
448 const dbus::ObjectPath& adapter_path, 473 const dbus::ObjectPath& adapter_path,
449 const dbus::ObjectPath& device_path) { 474 const dbus::ObjectPath& device_path) {
450 if (std::find(device_list_.begin(), 475 if (std::find(device_list_.begin(),
451 device_list_.end(), device_path) != device_list_.end()) 476 device_list_.end(), device_path) != device_list_.end())
452 return; 477 return;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 } 660 }
636 661
637 ++discovery_simulation_step_; 662 ++discovery_simulation_step_;
638 base::MessageLoop::current()->PostDelayedTask( 663 base::MessageLoop::current()->PostDelayedTask(
639 FROM_HERE, 664 FROM_HERE,
640 base::Bind(&FakeBluetoothDeviceClient::DiscoverySimulationTimer, 665 base::Bind(&FakeBluetoothDeviceClient::DiscoverySimulationTimer,
641 base::Unretained(this)), 666 base::Unretained(this)),
642 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); 667 base::TimeDelta::FromMilliseconds(simulation_interval_ms_));
643 } 668 }
644 669
670 void FakeBluetoothDeviceClient::IncomingPairingSimulationTimer() {
671 if (!incoming_pairing_simulation_step_)
672 return;
673
674 VLOG(1) << "incoming pairing simulation, step "
675 << incoming_pairing_simulation_step_;
676 switch (incoming_pairing_simulation_step_) {
677 case 1:
678 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
679 dbus::ObjectPath(kPhonePath));
680 SimulatePairing(dbus::ObjectPath(kPhonePath), true,
681 base::Bind(&base::DoNothing),
682 base::Bind(&SimpleErrorCallback));
683 break;
684 case 2:
685 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
686 dbus::ObjectPath(kBoseSpeakersPath));
687 SimulatePairing(dbus::ObjectPath(kBoseSpeakersPath), true,
688 base::Bind(&base::DoNothing),
689 base::Bind(&SimpleErrorCallback));
690 break;
691 case 3:
692 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
693 dbus::ObjectPath(kAppleKeyboardPath));
694 SimulatePairing(dbus::ObjectPath(kAppleKeyboardPath), true,
695 base::Bind(&base::DoNothing),
696 base::Bind(&SimpleErrorCallback));
697 break;
698 case 4:
699 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
700 dbus::ObjectPath(kMotorolaKeyboardPath));
701 SimulatePairing(dbus::ObjectPath(kMotorolaKeyboardPath), true,
702 base::Bind(&base::DoNothing),
703 base::Bind(&SimpleErrorCallback));
704 break;
705 case 5:
706 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
707 dbus::ObjectPath(kSonyHeadphonesPath));
708 SimulatePairing(dbus::ObjectPath(kSonyHeadphonesPath), true,
709 base::Bind(&base::DoNothing),
710 base::Bind(&SimpleErrorCallback));
711 break;
712 case 6:
713 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
714 dbus::ObjectPath(kWeirdDevicePath));
715 SimulatePairing(dbus::ObjectPath(kWeirdDevicePath), true,
716 base::Bind(&base::DoNothing),
717 base::Bind(&SimpleErrorCallback));
718 break;
719 default:
720 return;
721 }
722
723 ++incoming_pairing_simulation_step_;
724 base::MessageLoop::current()->PostDelayedTask(
725 FROM_HERE,
726 base::Bind(&FakeBluetoothDeviceClient::IncomingPairingSimulationTimer,
727 base::Unretained(this)),
728 base::TimeDelta::FromMilliseconds(45 * simulation_interval_ms_));
729 }
645 730
646 void FakeBluetoothDeviceClient::SimulatePairing( 731 void FakeBluetoothDeviceClient::SimulatePairing(
647 const dbus::ObjectPath& object_path, 732 const dbus::ObjectPath& object_path,
648 bool incoming_request, 733 bool incoming_request,
649 const base::Closure& callback, 734 const base::Closure& callback,
650 const ErrorCallback& error_callback) { 735 const ErrorCallback& error_callback) {
651 pairing_cancelled_ = false; 736 pairing_cancelled_ = false;
652 737
653 FakeBluetoothAgentManagerClient* fake_bluetooth_agent_manager_client = 738 FakeBluetoothAgentManagerClient* fake_bluetooth_agent_manager_client =
654 static_cast<FakeBluetoothAgentManagerClient*>( 739 static_cast<FakeBluetoothAgentManagerClient*>(
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 // TODO(keybuk): tear down this side of the connection 1093 // TODO(keybuk): tear down this side of the connection
1009 callback.Run(); 1094 callback.Run();
1010 } else if (status == BluetoothProfileServiceProvider::Delegate::CANCELLED) { 1095 } else if (status == BluetoothProfileServiceProvider::Delegate::CANCELLED) {
1011 error_callback.Run(bluetooth_device::kErrorFailed, "Canceled"); 1096 error_callback.Run(bluetooth_device::kErrorFailed, "Canceled");
1012 } else if (status == BluetoothProfileServiceProvider::Delegate::REJECTED) { 1097 } else if (status == BluetoothProfileServiceProvider::Delegate::REJECTED) {
1013 error_callback.Run(bluetooth_device::kErrorFailed, "Rejected"); 1098 error_callback.Run(bluetooth_device::kErrorFailed, "Rejected");
1014 } 1099 }
1015 } 1100 }
1016 1101
1017 } // namespace chromeos 1102 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698