Chromium Code Reviews| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 count = len; | 62 count = len; |
| 63 len = write(fd, buf, count); | 63 len = write(fd, buf, count); |
| 64 if (len < 0) { | 64 if (len < 0) { |
| 65 close(fd); | 65 close(fd); |
| 66 return; | 66 return; |
| 67 } | 67 } |
| 68 | 68 |
| 69 close(fd); | 69 close(fd); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void SimpleErrorCallback(const std::string& error_name, | |
| 73 const std::string& error_message) { | |
| 74 VLOG(1) << "Bluetooth Error: " << error_name << ": " << error_message; | |
| 75 } | |
| 76 | |
| 77 } // namespace | 72 } // namespace |
| 78 | 73 |
| 79 namespace chromeos { | 74 namespace chromeos { |
| 80 | 75 |
| 81 const char FakeBluetoothDeviceClient::kPairedDevicePath[] = | 76 const char FakeBluetoothDeviceClient::kPairedDevicePath[] = |
| 82 "/fake/hci0/dev0"; | 77 "/fake/hci0/dev0"; |
| 83 const char FakeBluetoothDeviceClient::kPairedDeviceAddress[] = | 78 const char FakeBluetoothDeviceClient::kPairedDeviceAddress[] = |
| 84 "00:11:22:33:44:55"; | 79 "00:11:22:33:44:55"; |
| 85 const char FakeBluetoothDeviceClient::kPairedDeviceName[] = | 80 const char FakeBluetoothDeviceClient::kPairedDeviceName[] = |
| 86 "Fake Device"; | 81 "Fake Device"; |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 } | 299 } |
| 305 | 300 |
| 306 FakeBluetoothDeviceClient::Properties* | 301 FakeBluetoothDeviceClient::Properties* |
| 307 FakeBluetoothDeviceClient::GetProperties(const dbus::ObjectPath& object_path) { | 302 FakeBluetoothDeviceClient::GetProperties(const dbus::ObjectPath& object_path) { |
| 308 PropertiesMap::iterator iter = properties_map_.find(object_path); | 303 PropertiesMap::iterator iter = properties_map_.find(object_path); |
| 309 if (iter != properties_map_.end()) | 304 if (iter != properties_map_.end()) |
| 310 return iter->second; | 305 return iter->second; |
| 311 return NULL; | 306 return NULL; |
| 312 } | 307 } |
| 313 | 308 |
| 309 FakeBluetoothDeviceClient::SimulatedPairingOptions* | |
| 310 FakeBluetoothDeviceClient::GetPairingOptions( | |
| 311 const dbus::ObjectPath& object_path) { | |
| 312 PairingOptionsMap::iterator iter = pairing_options_map_.find(object_path); | |
| 313 if (iter != pairing_options_map_.end()) | |
| 314 return iter->second; | |
| 315 return NULL; | |
| 316 } | |
| 317 | |
| 314 void FakeBluetoothDeviceClient::Connect( | 318 void FakeBluetoothDeviceClient::Connect( |
| 315 const dbus::ObjectPath& object_path, | 319 const dbus::ObjectPath& object_path, |
| 316 const base::Closure& callback, | 320 const base::Closure& callback, |
| 317 const ErrorCallback& error_callback) { | 321 const ErrorCallback& error_callback) { |
| 318 VLOG(1) << "Connect: " << object_path.value(); | 322 VLOG(1) << "Connect: " << object_path.value(); |
| 319 Properties* properties = GetProperties(object_path); | 323 Properties* properties = GetProperties(object_path); |
| 320 | 324 |
| 321 if (properties->connected.value() == true) { | 325 if (properties->connected.value() == true) { |
| 322 // Already connected. | 326 // Already connected. |
| 323 callback.Run(); | 327 callback.Run(); |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 548 void FakeBluetoothDeviceClient::EndIncomingPairingSimulation( | 552 void FakeBluetoothDeviceClient::EndIncomingPairingSimulation( |
| 549 const dbus::ObjectPath& adapter_path) { | 553 const dbus::ObjectPath& adapter_path) { |
| 550 VLOG(1) << "stopping incoming pairing simulation"; | 554 VLOG(1) << "stopping incoming pairing simulation"; |
| 551 incoming_pairing_simulation_step_ = 0; | 555 incoming_pairing_simulation_step_ = 0; |
| 552 } | 556 } |
| 553 | 557 |
| 554 void FakeBluetoothDeviceClient::SetSimulationIntervalMs(int interval_ms) { | 558 void FakeBluetoothDeviceClient::SetSimulationIntervalMs(int interval_ms) { |
| 555 simulation_interval_ms_ = interval_ms; | 559 simulation_interval_ms_ = interval_ms; |
| 556 } | 560 } |
| 557 | 561 |
| 562 void FakeBluetoothDeviceClient::SimpleErrorCallback( | |
|
xiyuan
2015/07/30 17:21:22
Why move this into FakeBluetoothDeviceClient inter
rfrappier
2015/07/30 22:21:39
Forgot to revert this change (I thought I needed i
| |
| 563 const std::string& error_name, | |
| 564 const std::string& error_message) { | |
| 565 VLOG(1) << "Bluetooth Error: " << error_name << ": " << error_message; | |
| 566 } | |
| 567 | |
| 558 void FakeBluetoothDeviceClient::CreateDevice( | 568 void FakeBluetoothDeviceClient::CreateDevice( |
| 559 const dbus::ObjectPath& adapter_path, | 569 const dbus::ObjectPath& adapter_path, |
| 560 const dbus::ObjectPath& device_path) { | 570 const dbus::ObjectPath& device_path) { |
| 561 if (std::find(device_list_.begin(), | 571 if (std::find(device_list_.begin(), |
| 562 device_list_.end(), device_path) != device_list_.end()) | 572 device_list_.end(), device_path) != device_list_.end()) |
| 563 return; | 573 return; |
| 564 | 574 |
| 565 Properties* properties = new Properties(base::Bind( | 575 Properties* properties = new Properties(base::Bind( |
| 566 &FakeBluetoothDeviceClient::OnPropertyChanged, | 576 &FakeBluetoothDeviceClient::OnPropertyChanged, |
| 567 base::Unretained(this), | 577 base::Unretained(this), |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 664 NOTREACHED(); | 674 NOTREACHED(); |
| 665 | 675 |
| 666 } | 676 } |
| 667 | 677 |
| 668 properties_map_[device_path] = properties; | 678 properties_map_[device_path] = properties; |
| 669 device_list_.push_back(device_path); | 679 device_list_.push_back(device_path); |
| 670 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, | 680 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, |
| 671 DeviceAdded(device_path)); | 681 DeviceAdded(device_path)); |
| 672 } | 682 } |
| 673 | 683 |
| 684 void FakeBluetoothDeviceClient::CreateDeviceWithProperties( | |
| 685 const dbus::ObjectPath& adapter_path, | |
| 686 const dbus::ObjectPath& device_path, | |
| 687 const std::string& device_name, | |
| 688 const std::string& device_alias, | |
| 689 const std::string& device_address, | |
| 690 const std::string& pairing_method, | |
| 691 const std::string& pairing_auth_token, | |
| 692 const uint32& device_class, | |
| 693 const bool is_trusted) { | |
| 694 if (std::find(device_list_.begin(), device_list_.end(), device_path) != | |
| 695 device_list_.end()) | |
|
stevenjb
2015/07/30 18:28:52
LOG(ERROR) << "Bluetootl device already exists: "
rfrappier
2015/07/30 22:21:39
This will probably be removed later to allow for e
| |
| 696 return; | |
| 697 | |
| 698 Properties* properties = | |
|
stevenjb
2015/07/30 18:28:51
Use a scoped_ptr here so that ownership passing is
rfrappier
2015/07/30 22:21:39
Done.
| |
| 699 new Properties(base::Bind(&FakeBluetoothDeviceClient::OnPropertyChanged, | |
| 700 base::Unretained(this), device_path)); | |
| 701 properties->adapter.ReplaceValue(adapter_path); | |
| 702 properties->name.ReplaceValue(device_name); | |
| 703 properties->alias.ReplaceValue(device_alias); | |
| 704 properties->address.ReplaceValue(device_address); | |
| 705 properties->bluetooth_class.ReplaceValue(device_class); | |
| 706 properties->trusted.ReplaceValue(is_trusted); | |
| 707 | |
| 708 if (is_trusted) | |
| 709 properties->paired.ReplaceValue(true); | |
| 710 | |
| 711 SimulatedPairingOptions* options = new SimulatedPairingOptions; | |
|
stevenjb
2015/07/30 18:28:52
scoped_ptr
rfrappier
2015/07/30 22:21:39
Done.
| |
| 712 options->pairing_method = pairing_method; | |
| 713 options->pairing_auth_token = pairing_auth_token; | |
| 714 | |
| 715 properties_map_[device_path] = properties; | |
|
stevenjb
2015/07/30 18:28:52
If we make this a ScopedPtrMap, this will be prope
rfrappier
2015/07/30 22:21:39
Acknowledged.
| |
| 716 device_list_.push_back(device_path); | |
| 717 pairing_options_map_[device_path] = options; | |
|
xiyuan
2015/07/30 17:21:22
This leaks. You need to do "STLDeleteValues()" sim
stevenjb
2015/07/30 18:28:52
A good reason to use ScopedPtrMap for both of thes
rfrappier
2015/07/30 22:21:39
Done.
| |
| 718 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, | |
| 719 DeviceAdded(device_path)); | |
| 720 } | |
| 721 | |
| 674 void FakeBluetoothDeviceClient::RemoveDevice( | 722 void FakeBluetoothDeviceClient::RemoveDevice( |
| 675 const dbus::ObjectPath& adapter_path, | 723 const dbus::ObjectPath& adapter_path, |
| 676 const dbus::ObjectPath& device_path) { | 724 const dbus::ObjectPath& device_path) { |
| 677 std::vector<dbus::ObjectPath>::iterator listiter = | 725 std::vector<dbus::ObjectPath>::iterator listiter = |
| 678 std::find(device_list_.begin(), device_list_.end(), device_path); | 726 std::find(device_list_.begin(), device_list_.end(), device_path); |
| 679 if (listiter == device_list_.end()) | 727 if (listiter == device_list_.end()) |
| 680 return; | 728 return; |
| 681 | 729 |
| 682 PropertiesMap::iterator iter = properties_map_.find(device_path); | 730 PropertiesMap::iterator iter = properties_map_.find(device_path); |
| 683 Properties* properties = iter->second; | 731 Properties* properties = iter->second; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 789 void FakeBluetoothDeviceClient::IncomingPairingSimulationTimer() { | 837 void FakeBluetoothDeviceClient::IncomingPairingSimulationTimer() { |
| 790 if (!incoming_pairing_simulation_step_) | 838 if (!incoming_pairing_simulation_step_) |
| 791 return; | 839 return; |
| 792 | 840 |
| 793 VLOG(1) << "incoming pairing simulation, step " | 841 VLOG(1) << "incoming pairing simulation, step " |
| 794 << incoming_pairing_simulation_step_; | 842 << incoming_pairing_simulation_step_; |
| 795 switch (incoming_pairing_simulation_step_) { | 843 switch (incoming_pairing_simulation_step_) { |
| 796 case 1: | 844 case 1: |
| 797 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 845 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 798 dbus::ObjectPath(kConfirmPasskeyPath)); | 846 dbus::ObjectPath(kConfirmPasskeyPath)); |
| 799 SimulatePairing(dbus::ObjectPath(kConfirmPasskeyPath), true, | 847 SimulatePairing( |
| 800 base::Bind(&base::DoNothing), | 848 dbus::ObjectPath(kConfirmPasskeyPath), true, |
| 801 base::Bind(&SimpleErrorCallback)); | 849 base::Bind(&base::DoNothing), |
| 850 base::Bind(&FakeBluetoothDeviceClient::SimpleErrorCallback)); | |
| 802 break; | 851 break; |
| 803 case 2: | 852 case 2: |
| 804 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 853 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 805 dbus::ObjectPath(kJustWorksPath)); | 854 dbus::ObjectPath(kJustWorksPath)); |
| 806 SimulatePairing(dbus::ObjectPath(kJustWorksPath), true, | 855 SimulatePairing( |
| 807 base::Bind(&base::DoNothing), | 856 dbus::ObjectPath(kJustWorksPath), true, base::Bind(&base::DoNothing), |
| 808 base::Bind(&SimpleErrorCallback)); | 857 base::Bind(&FakeBluetoothDeviceClient::SimpleErrorCallback)); |
| 809 break; | 858 break; |
| 810 case 3: | 859 case 3: |
| 811 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 860 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 812 dbus::ObjectPath(kDisplayPinCodePath)); | 861 dbus::ObjectPath(kDisplayPinCodePath)); |
| 813 SimulatePairing(dbus::ObjectPath(kDisplayPinCodePath), true, | 862 SimulatePairing( |
| 814 base::Bind(&base::DoNothing), | 863 dbus::ObjectPath(kDisplayPinCodePath), true, |
| 815 base::Bind(&SimpleErrorCallback)); | 864 base::Bind(&base::DoNothing), |
| 865 base::Bind(&FakeBluetoothDeviceClient::SimpleErrorCallback)); | |
| 816 break; | 866 break; |
| 817 case 4: | 867 case 4: |
| 818 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 868 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 819 dbus::ObjectPath(kDisplayPasskeyPath)); | 869 dbus::ObjectPath(kDisplayPasskeyPath)); |
| 820 SimulatePairing(dbus::ObjectPath(kDisplayPasskeyPath), true, | 870 SimulatePairing( |
| 821 base::Bind(&base::DoNothing), | 871 dbus::ObjectPath(kDisplayPasskeyPath), true, |
| 822 base::Bind(&SimpleErrorCallback)); | 872 base::Bind(&base::DoNothing), |
| 873 base::Bind(&FakeBluetoothDeviceClient::SimpleErrorCallback)); | |
| 823 break; | 874 break; |
| 824 case 5: | 875 case 5: |
| 825 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 876 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 826 dbus::ObjectPath(kRequestPinCodePath)); | 877 dbus::ObjectPath(kRequestPinCodePath)); |
| 827 SimulatePairing(dbus::ObjectPath(kRequestPinCodePath), true, | 878 SimulatePairing( |
| 828 base::Bind(&base::DoNothing), | 879 dbus::ObjectPath(kRequestPinCodePath), true, |
| 829 base::Bind(&SimpleErrorCallback)); | 880 base::Bind(&base::DoNothing), |
| 881 base::Bind(&FakeBluetoothDeviceClient::SimpleErrorCallback)); | |
| 830 break; | 882 break; |
| 831 case 6: | 883 case 6: |
| 832 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 884 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 833 dbus::ObjectPath(kRequestPasskeyPath)); | 885 dbus::ObjectPath(kRequestPasskeyPath)); |
| 834 SimulatePairing(dbus::ObjectPath(kRequestPasskeyPath), true, | 886 SimulatePairing( |
| 835 base::Bind(&base::DoNothing), | 887 dbus::ObjectPath(kRequestPasskeyPath), true, |
| 836 base::Bind(&SimpleErrorCallback)); | 888 base::Bind(&base::DoNothing), |
| 889 base::Bind(&FakeBluetoothDeviceClient::SimpleErrorCallback)); | |
| 837 break; | 890 break; |
| 838 default: | 891 default: |
| 839 return; | 892 return; |
| 840 } | 893 } |
| 841 | 894 |
| 842 ++incoming_pairing_simulation_step_; | 895 ++incoming_pairing_simulation_step_; |
| 843 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 896 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 844 FROM_HERE, | 897 FROM_HERE, |
| 845 base::Bind(&FakeBluetoothDeviceClient::IncomingPairingSimulationTimer, | 898 base::Bind(&FakeBluetoothDeviceClient::IncomingPairingSimulationTimer, |
| 846 base::Unretained(this)), | 899 base::Unretained(this)), |
| 847 base::TimeDelta::FromMilliseconds(45 * simulation_interval_ms_)); | 900 base::TimeDelta::FromMilliseconds(45 * simulation_interval_ms_)); |
| 848 } | 901 } |
| 849 | 902 |
| 850 void FakeBluetoothDeviceClient::SimulatePairing( | 903 void FakeBluetoothDeviceClient::SimulatePairing( |
| 851 const dbus::ObjectPath& object_path, | 904 const dbus::ObjectPath& object_path, |
| 852 bool incoming_request, | 905 bool incoming_request, |
| 853 const base::Closure& callback, | 906 const base::Closure& callback, |
| 854 const ErrorCallback& error_callback) { | 907 const ErrorCallback& error_callback) { |
| 855 pairing_cancelled_ = false; | 908 pairing_cancelled_ = false; |
| 856 | 909 |
| 857 FakeBluetoothAgentManagerClient* fake_bluetooth_agent_manager_client = | 910 FakeBluetoothAgentManagerClient* fake_bluetooth_agent_manager_client = |
| 858 static_cast<FakeBluetoothAgentManagerClient*>( | 911 static_cast<FakeBluetoothAgentManagerClient*>( |
| 859 DBusThreadManager::Get()->GetBluetoothAgentManagerClient()); | 912 DBusThreadManager::Get()->GetBluetoothAgentManagerClient()); |
| 860 FakeBluetoothAgentServiceProvider* agent_service_provider = | 913 FakeBluetoothAgentServiceProvider* agent_service_provider = |
| 861 fake_bluetooth_agent_manager_client->GetAgentServiceProvider(); | 914 fake_bluetooth_agent_manager_client->GetAgentServiceProvider(); |
| 862 CHECK(agent_service_provider != NULL); | 915 CHECK(agent_service_provider != NULL); |
| 863 | 916 |
| 864 if (object_path == dbus::ObjectPath(kLegacyAutopairPath) || | 917 // Grab the device's pairing properties. |
| 865 object_path == dbus::ObjectPath(kConnectUnpairablePath) || | 918 PairingOptionsMap::iterator iter = pairing_options_map_.find(object_path); |
| 866 object_path == dbus::ObjectPath(kUnconnectableDevicePath) || | |
| 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 | 919 |
| 877 } else if (object_path == dbus::ObjectPath(kDisplayPinCodePath)) { | 920 // If the device with path |object_path| has simulated pairing properties |
| 878 // Display a Pincode, and wait 7 times the interval before acting as | 921 // defined, then pair it based on its |pairing_method|. |
| 879 // if the other end accepted it. | 922 if (iter != pairing_options_map_.end()) { |
| 880 agent_service_provider->DisplayPinCode(object_path, "123456"); | 923 if (iter->second->pairing_method == "None" || |
|
xiyuan
2015/07/30 17:21:22
nit: Put "None", "PIN Code" etc in const.
rfrappier
2015/07/30 22:21:39
Done.
| |
| 924 iter->second->pairing_method == "") { | |
| 925 // Simply pair and connect the device. | |
| 926 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 927 FROM_HERE, | |
| 928 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, | |
| 929 base::Unretained(this), object_path, callback, | |
| 930 error_callback), | |
| 931 base::TimeDelta::FromMilliseconds(3 * simulation_interval_ms_)); | |
| 932 } else if (iter->second->pairing_method == "PIN Code") { | |
| 933 // Display a Pincode, and wait 7 times the interval before acting as | |
| 934 // if the other end accepted it. | |
| 935 agent_service_provider->DisplayPinCode(object_path, | |
| 936 iter->second->pairing_auth_token); | |
| 881 | 937 |
| 882 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 938 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 883 FROM_HERE, | 939 FROM_HERE, |
| 884 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, | 940 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, |
| 885 base::Unretained(this), object_path, callback, | 941 base::Unretained(this), object_path, callback, |
| 886 error_callback), | 942 error_callback), |
| 887 base::TimeDelta::FromMilliseconds(7 * simulation_interval_ms_)); | 943 base::TimeDelta::FromMilliseconds(7 * simulation_interval_ms_)); |
|
stevenjb
2015/07/30 18:28:52
7 should be a const and used here and below.
rfrappier
2015/07/30 22:21:39
Done.
| |
| 944 } else if (iter->second->pairing_method == "PassKey") { | |
| 945 // Display a passkey, and each interval act as if another key was entered | |
| 946 // for it. | |
| 947 agent_service_provider->DisplayPasskey( | |
| 948 object_path, std::stoi(iter->second->pairing_auth_token), 0); | |
| 888 | 949 |
| 889 } else if (object_path == dbus::ObjectPath(kVanishingDevicePath)) { | 950 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 890 // The vanishing device simulates being too far away, and thus times out. | 951 FROM_HERE, base::Bind(&FakeBluetoothDeviceClient::SimulateKeypress, |
| 891 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 952 base::Unretained(this), 1, object_path, |
| 892 FROM_HERE, | 953 callback, error_callback), |
| 893 base::Bind(&FakeBluetoothDeviceClient::TimeoutSimulatedPairing, | 954 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); |
| 894 base::Unretained(this), object_path, error_callback), | 955 } |
| 895 base::TimeDelta::FromMilliseconds(4 * simulation_interval_ms_)); | 956 } else { |
| 896 | 957 if (object_path == dbus::ObjectPath(kLegacyAutopairPath) || |
| 897 } else if (object_path == dbus::ObjectPath(kDisplayPasskeyPath)) { | 958 object_path == dbus::ObjectPath(kConnectUnpairablePath) || |
| 898 // Display a passkey, and each interval act as if another key was entered | 959 object_path == dbus::ObjectPath(kUnconnectableDevicePath) || |
| 899 // for it. | 960 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 | 961 // 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. | 962 // the interval before acting as if the other end accepted it. |
| 959 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 963 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 960 FROM_HERE, | 964 FROM_HERE, |
| 961 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, | 965 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, |
| 962 base::Unretained(this), object_path, callback, | 966 base::Unretained(this), object_path, callback, |
| 963 error_callback), | 967 error_callback), |
| 964 base::TimeDelta::FromMilliseconds(3 * simulation_interval_ms_)); | 968 base::TimeDelta::FromMilliseconds(3 * simulation_interval_ms_)); |
| 969 | |
| 970 } else if (object_path == dbus::ObjectPath(kDisplayPinCodePath)) { | |
| 971 // Display a Pincode, and wait 7 times the interval before acting as | |
| 972 // if the other end accepted it. | |
| 973 agent_service_provider->DisplayPinCode(object_path, "123456"); | |
|
stevenjb
2015/07/30 18:28:52
"123456" should be declared as a const char[].
rfrappier
2015/07/30 22:21:39
Done.
| |
| 974 | |
| 975 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 976 FROM_HERE, | |
| 977 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, | |
| 978 base::Unretained(this), object_path, callback, | |
| 979 error_callback), | |
| 980 base::TimeDelta::FromMilliseconds(7 * simulation_interval_ms_)); | |
| 981 | |
| 982 } else if (object_path == dbus::ObjectPath(kVanishingDevicePath)) { | |
| 983 // The vanishing device simulates being too far away, and thus times out. | |
| 984 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 985 FROM_HERE, | |
| 986 base::Bind(&FakeBluetoothDeviceClient::TimeoutSimulatedPairing, | |
| 987 base::Unretained(this), object_path, error_callback), | |
| 988 base::TimeDelta::FromMilliseconds(4 * simulation_interval_ms_)); | |
| 989 | |
| 990 } else if (object_path == dbus::ObjectPath(kDisplayPasskeyPath)) { | |
| 991 // Display a passkey, and each interval act as if another key was entered | |
| 992 // for it. | |
| 993 agent_service_provider->DisplayPasskey(object_path, 123456, 0); | |
|
stevenjb
2015/07/30 18:28:52
const int for 123456
rfrappier
2015/07/30 22:21:39
Done.
| |
| 994 | |
| 995 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 996 FROM_HERE, base::Bind(&FakeBluetoothDeviceClient::SimulateKeypress, | |
| 997 base::Unretained(this), 1, object_path, | |
| 998 callback, error_callback), | |
| 999 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); | |
| 1000 | |
| 1001 } else if (object_path == dbus::ObjectPath(kRequestPinCodePath)) { | |
| 1002 // Request a Pincode. | |
| 1003 agent_service_provider->RequestPinCode( | |
| 1004 object_path, base::Bind(&FakeBluetoothDeviceClient::PinCodeCallback, | |
| 1005 base::Unretained(this), object_path, callback, | |
| 1006 error_callback)); | |
| 1007 | |
| 1008 } else if (object_path == dbus::ObjectPath(kConfirmPasskeyPath)) { | |
| 1009 // Request confirmation of a Passkey. | |
| 1010 agent_service_provider->RequestConfirmation( | |
| 1011 object_path, 123456, | |
| 1012 base::Bind(&FakeBluetoothDeviceClient::ConfirmationCallback, | |
| 1013 base::Unretained(this), object_path, callback, | |
| 1014 error_callback)); | |
| 1015 | |
| 1016 } else if (object_path == dbus::ObjectPath(kRequestPasskeyPath)) { | |
| 1017 // Request a Passkey from the user. | |
| 1018 agent_service_provider->RequestPasskey( | |
| 1019 object_path, base::Bind(&FakeBluetoothDeviceClient::PasskeyCallback, | |
| 1020 base::Unretained(this), object_path, callback, | |
| 1021 error_callback)); | |
| 1022 | |
| 1023 } else if (object_path == dbus::ObjectPath(kUnpairableDevicePath)) { | |
| 1024 // Fails the pairing with an org.bluez.Error.Failed error. | |
| 1025 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 1026 FROM_HERE, | |
| 1027 base::Bind(&FakeBluetoothDeviceClient::FailSimulatedPairing, | |
| 1028 base::Unretained(this), object_path, error_callback), | |
| 1029 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); | |
| 1030 | |
| 1031 } else if (object_path == dbus::ObjectPath(kJustWorksPath)) { | |
| 1032 if (incoming_request) { | |
| 1033 agent_service_provider->RequestAuthorization( | |
| 1034 object_path, | |
| 1035 base::Bind(&FakeBluetoothDeviceClient::ConfirmationCallback, | |
| 1036 base::Unretained(this), object_path, callback, | |
| 1037 error_callback)); | |
| 1038 | |
| 1039 } else { | |
| 1040 // No need to call anything on the pairing delegate, just wait 3 times | |
| 1041 // the interval before acting as if the other end accepted it. | |
| 1042 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 1043 FROM_HERE, | |
| 1044 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, | |
| 1045 base::Unretained(this), object_path, callback, | |
| 1046 error_callback), | |
| 1047 base::TimeDelta::FromMilliseconds(3 * simulation_interval_ms_)); | |
|
stevenjb
2015/07/30 18:28:52
const int for 3
rfrappier
2015/07/30 22:21:39
Done.
| |
| 1048 } | |
| 1049 | |
| 1050 } else { | |
| 1051 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 1052 FROM_HERE, | |
| 1053 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, | |
| 1054 base::Unretained(this), object_path, callback, | |
| 1055 error_callback), | |
| 1056 base::TimeDelta::FromMilliseconds(3 * simulation_interval_ms_)); | |
| 1057 // error_callback.Run(kNoResponseError, "No pairing fake"); | |
| 965 } | 1058 } |
| 966 | |
| 967 } else { | |
| 968 error_callback.Run(kNoResponseError, "No pairing fake"); | |
| 969 } | 1059 } |
| 970 } | 1060 } |
| 971 | 1061 |
| 972 void FakeBluetoothDeviceClient::CompleteSimulatedPairing( | 1062 void FakeBluetoothDeviceClient::CompleteSimulatedPairing( |
| 973 const dbus::ObjectPath& object_path, | 1063 const dbus::ObjectPath& object_path, |
| 974 const base::Closure& callback, | 1064 const base::Closure& callback, |
| 975 const ErrorCallback& error_callback) { | 1065 const ErrorCallback& error_callback) { |
| 976 VLOG(1) << "CompleteSimulatedPairing: " << object_path.value(); | 1066 VLOG(1) << "CompleteSimulatedPairing: " << object_path.value(); |
| 977 if (pairing_cancelled_) { | 1067 if (pairing_cancelled_) { |
| 978 pairing_cancelled_ = false; | 1068 pairing_cancelled_ = false; |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1220 // TODO(keybuk): tear down this side of the connection | 1310 // TODO(keybuk): tear down this side of the connection |
| 1221 callback.Run(); | 1311 callback.Run(); |
| 1222 } else if (status == BluetoothProfileServiceProvider::Delegate::CANCELLED) { | 1312 } else if (status == BluetoothProfileServiceProvider::Delegate::CANCELLED) { |
| 1223 error_callback.Run(bluetooth_device::kErrorFailed, "Canceled"); | 1313 error_callback.Run(bluetooth_device::kErrorFailed, "Canceled"); |
| 1224 } else if (status == BluetoothProfileServiceProvider::Delegate::REJECTED) { | 1314 } else if (status == BluetoothProfileServiceProvider::Delegate::REJECTED) { |
| 1225 error_callback.Run(bluetooth_device::kErrorFailed, "Rejected"); | 1315 error_callback.Run(bluetooth_device::kErrorFailed, "Rejected"); |
| 1226 } | 1316 } |
| 1227 } | 1317 } |
| 1228 | 1318 |
| 1229 } // namespace chromeos | 1319 } // namespace chromeos |
| OLD | NEW |