| 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 "device/bluetooth/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> |
| 11 | 11 |
| 12 #include <algorithm> | 12 #include <algorithm> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <utility> | 14 #include <utility> |
| 15 | 15 |
| 16 #include "base/location.h" | 16 #include "base/location.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/rand_util.h" | 19 #include "base/rand_util.h" |
| 20 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
| 21 #include "base/stl_util.h" | 21 #include "base/stl_util.h" |
| 22 #include "base/thread_task_runner_handle.h" | 22 #include "base/thread_task_runner_handle.h" |
| 23 #include "base/threading/worker_pool.h" | 23 #include "base/threading/worker_pool.h" |
| 24 #include "base/time/time.h" | 24 #include "base/time/time.h" |
| 25 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 26 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" | |
| 27 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" | |
| 28 #include "chromeos/dbus/fake_bluetooth_agent_service_provider.h" | |
| 29 #include "chromeos/dbus/fake_bluetooth_gatt_service_client.h" | |
| 30 #include "chromeos/dbus/fake_bluetooth_input_client.h" | |
| 31 #include "chromeos/dbus/fake_bluetooth_profile_manager_client.h" | |
| 32 #include "chromeos/dbus/fake_bluetooth_profile_service_provider.h" | |
| 33 #include "dbus/file_descriptor.h" | 25 #include "dbus/file_descriptor.h" |
| 26 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| 27 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h" |
| 28 #include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h" |
| 29 #include "device/bluetooth/dbus/fake_bluetooth_agent_service_provider.h" |
| 30 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h" |
| 31 #include "device/bluetooth/dbus/fake_bluetooth_input_client.h" |
| 32 #include "device/bluetooth/dbus/fake_bluetooth_profile_manager_client.h" |
| 33 #include "device/bluetooth/dbus/fake_bluetooth_profile_service_provider.h" |
| 34 #include "third_party/cros_system_api/dbus/service_constants.h" | 34 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 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; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 close(fd); | 87 close(fd); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void SimpleErrorCallback(const std::string& error_name, | 90 void SimpleErrorCallback(const std::string& error_name, |
| 91 const std::string& error_message) { | 91 const std::string& error_message) { |
| 92 VLOG(1) << "Bluetooth Error: " << error_name << ": " << error_message; | 92 VLOG(1) << "Bluetooth Error: " << error_name << ": " << error_message; |
| 93 } | 93 } |
| 94 | 94 |
| 95 } // namespace | 95 } // namespace |
| 96 | 96 |
| 97 namespace chromeos { | 97 namespace bluez { |
| 98 | 98 |
| 99 const char FakeBluetoothDeviceClient::kTestPinCode[] = "123456"; | 99 const char FakeBluetoothDeviceClient::kTestPinCode[] = "123456"; |
| 100 const int FakeBluetoothDeviceClient::kTestPassKey = 123456; | 100 const int FakeBluetoothDeviceClient::kTestPassKey = 123456; |
| 101 | 101 |
| 102 const char FakeBluetoothDeviceClient::kPairingMethodNone[] = "None"; | 102 const char FakeBluetoothDeviceClient::kPairingMethodNone[] = "None"; |
| 103 const char FakeBluetoothDeviceClient::kPairingMethodPinCode[] = "PIN Code"; | 103 const char FakeBluetoothDeviceClient::kPairingMethodPinCode[] = "PIN Code"; |
| 104 const char FakeBluetoothDeviceClient::kPairingMethodPassKey[] = "PassKey"; | 104 const char FakeBluetoothDeviceClient::kPairingMethodPassKey[] = "PassKey"; |
| 105 | 105 |
| 106 const char FakeBluetoothDeviceClient::kPairingActionConfirmation[] = | 106 const char FakeBluetoothDeviceClient::kPairingActionConfirmation[] = |
| 107 "Confirmation"; | 107 "Confirmation"; |
| 108 const char FakeBluetoothDeviceClient::kPairingActionDisplay[] = "Display"; | 108 const char FakeBluetoothDeviceClient::kPairingActionDisplay[] = "Display"; |
| 109 const char FakeBluetoothDeviceClient::kPairingActionFail[] = "Fail"; | 109 const char FakeBluetoothDeviceClient::kPairingActionFail[] = "Fail"; |
| 110 const char FakeBluetoothDeviceClient::kPairingActionRequest[] = "Request"; | 110 const char FakeBluetoothDeviceClient::kPairingActionRequest[] = "Request"; |
| 111 | 111 |
| 112 const char FakeBluetoothDeviceClient::kPairedDevicePath[] = | 112 const char FakeBluetoothDeviceClient::kPairedDevicePath[] = "/fake/hci0/dev0"; |
| 113 "/fake/hci0/dev0"; | |
| 114 const char FakeBluetoothDeviceClient::kPairedDeviceAddress[] = | 113 const char FakeBluetoothDeviceClient::kPairedDeviceAddress[] = |
| 115 "00:11:22:33:44:55"; | 114 "00:11:22:33:44:55"; |
| 116 const char FakeBluetoothDeviceClient::kPairedDeviceName[] = | 115 const char FakeBluetoothDeviceClient::kPairedDeviceName[] = "Fake Device"; |
| 117 "Fake Device"; | |
| 118 const uint32 FakeBluetoothDeviceClient::kPairedDeviceClass = 0x000104; | 116 const uint32 FakeBluetoothDeviceClient::kPairedDeviceClass = 0x000104; |
| 119 | 117 |
| 120 const char FakeBluetoothDeviceClient::kLegacyAutopairPath[] = | 118 const char FakeBluetoothDeviceClient::kLegacyAutopairPath[] = "/fake/hci0/dev1"; |
| 121 "/fake/hci0/dev1"; | |
| 122 const char FakeBluetoothDeviceClient::kLegacyAutopairAddress[] = | 119 const char FakeBluetoothDeviceClient::kLegacyAutopairAddress[] = |
| 123 "28:CF:DA:00:00:00"; | 120 "28:CF:DA:00:00:00"; |
| 124 const char FakeBluetoothDeviceClient::kLegacyAutopairName[] = | 121 const char FakeBluetoothDeviceClient::kLegacyAutopairName[] = |
| 125 "Bluetooth 2.0 Mouse"; | 122 "Bluetooth 2.0 Mouse"; |
| 126 const uint32 FakeBluetoothDeviceClient::kLegacyAutopairClass = 0x002580; | 123 const uint32 FakeBluetoothDeviceClient::kLegacyAutopairClass = 0x002580; |
| 127 | 124 |
| 128 const char FakeBluetoothDeviceClient::kDisplayPinCodePath[] = | 125 const char FakeBluetoothDeviceClient::kDisplayPinCodePath[] = "/fake/hci0/dev2"; |
| 129 "/fake/hci0/dev2"; | |
| 130 const char FakeBluetoothDeviceClient::kDisplayPinCodeAddress[] = | 126 const char FakeBluetoothDeviceClient::kDisplayPinCodeAddress[] = |
| 131 "28:37:37:00:00:00"; | 127 "28:37:37:00:00:00"; |
| 132 const char FakeBluetoothDeviceClient::kDisplayPinCodeName[] = | 128 const char FakeBluetoothDeviceClient::kDisplayPinCodeName[] = |
| 133 "Bluetooth 2.0 Keyboard"; | 129 "Bluetooth 2.0 Keyboard"; |
| 134 const uint32 FakeBluetoothDeviceClient::kDisplayPinCodeClass = 0x002540; | 130 const uint32 FakeBluetoothDeviceClient::kDisplayPinCodeClass = 0x002540; |
| 135 | 131 |
| 136 const char FakeBluetoothDeviceClient::kVanishingDevicePath[] = | 132 const char FakeBluetoothDeviceClient::kVanishingDevicePath[] = |
| 137 "/fake/hci0/dev3"; | 133 "/fake/hci0/dev3"; |
| 138 const char FakeBluetoothDeviceClient::kVanishingDeviceAddress[] = | 134 const char FakeBluetoothDeviceClient::kVanishingDeviceAddress[] = |
| 139 "01:02:03:04:05:06"; | 135 "01:02:03:04:05:06"; |
| 140 const char FakeBluetoothDeviceClient::kVanishingDeviceName[] = | 136 const char FakeBluetoothDeviceClient::kVanishingDeviceName[] = |
| 141 "Vanishing Device"; | 137 "Vanishing Device"; |
| 142 const uint32 FakeBluetoothDeviceClient::kVanishingDeviceClass = 0x000104; | 138 const uint32 FakeBluetoothDeviceClient::kVanishingDeviceClass = 0x000104; |
| 143 | 139 |
| 144 const char FakeBluetoothDeviceClient::kConnectUnpairablePath[] = | 140 const char FakeBluetoothDeviceClient::kConnectUnpairablePath[] = |
| 145 "/fake/hci0/dev4"; | 141 "/fake/hci0/dev4"; |
| 146 const char FakeBluetoothDeviceClient::kConnectUnpairableAddress[] = | 142 const char FakeBluetoothDeviceClient::kConnectUnpairableAddress[] = |
| 147 "7C:ED:8D:00:00:00"; | 143 "7C:ED:8D:00:00:00"; |
| 148 const char FakeBluetoothDeviceClient::kConnectUnpairableName[] = | 144 const char FakeBluetoothDeviceClient::kConnectUnpairableName[] = |
| 149 "Unpairable Device"; | 145 "Unpairable Device"; |
| 150 const uint32 FakeBluetoothDeviceClient::kConnectUnpairableClass = 0x002580; | 146 const uint32 FakeBluetoothDeviceClient::kConnectUnpairableClass = 0x002580; |
| 151 | 147 |
| 152 const char FakeBluetoothDeviceClient::kDisplayPasskeyPath[] = | 148 const char FakeBluetoothDeviceClient::kDisplayPasskeyPath[] = "/fake/hci0/dev5"; |
| 153 "/fake/hci0/dev5"; | |
| 154 const char FakeBluetoothDeviceClient::kDisplayPasskeyAddress[] = | 149 const char FakeBluetoothDeviceClient::kDisplayPasskeyAddress[] = |
| 155 "00:0F:F6:00:00:00"; | 150 "00:0F:F6:00:00:00"; |
| 156 const char FakeBluetoothDeviceClient::kDisplayPasskeyName[] = | 151 const char FakeBluetoothDeviceClient::kDisplayPasskeyName[] = |
| 157 "Bluetooth 2.1+ Keyboard"; | 152 "Bluetooth 2.1+ Keyboard"; |
| 158 const uint32 FakeBluetoothDeviceClient::kDisplayPasskeyClass = 0x002540; | 153 const uint32 FakeBluetoothDeviceClient::kDisplayPasskeyClass = 0x002540; |
| 159 | 154 |
| 160 const char FakeBluetoothDeviceClient::kRequestPinCodePath[] = | 155 const char FakeBluetoothDeviceClient::kRequestPinCodePath[] = "/fake/hci0/dev6"; |
| 161 "/fake/hci0/dev6"; | |
| 162 const char FakeBluetoothDeviceClient::kRequestPinCodeAddress[] = | 156 const char FakeBluetoothDeviceClient::kRequestPinCodeAddress[] = |
| 163 "00:24:BE:00:00:00"; | 157 "00:24:BE:00:00:00"; |
| 164 const char FakeBluetoothDeviceClient::kRequestPinCodeName[] = | 158 const char FakeBluetoothDeviceClient::kRequestPinCodeName[] = "PIN Device"; |
| 165 "PIN Device"; | |
| 166 const uint32 FakeBluetoothDeviceClient::kRequestPinCodeClass = 0x240408; | 159 const uint32 FakeBluetoothDeviceClient::kRequestPinCodeClass = 0x240408; |
| 167 | 160 |
| 168 const char FakeBluetoothDeviceClient::kConfirmPasskeyPath[] = | 161 const char FakeBluetoothDeviceClient::kConfirmPasskeyPath[] = "/fake/hci0/dev7"; |
| 169 "/fake/hci0/dev7"; | |
| 170 const char FakeBluetoothDeviceClient::kConfirmPasskeyAddress[] = | 162 const char FakeBluetoothDeviceClient::kConfirmPasskeyAddress[] = |
| 171 "20:7D:74:00:00:00"; | 163 "20:7D:74:00:00:00"; |
| 172 const char FakeBluetoothDeviceClient::kConfirmPasskeyName[] = | 164 const char FakeBluetoothDeviceClient::kConfirmPasskeyName[] = "Phone"; |
| 173 "Phone"; | |
| 174 const uint32 FakeBluetoothDeviceClient::kConfirmPasskeyClass = 0x7a020c; | 165 const uint32 FakeBluetoothDeviceClient::kConfirmPasskeyClass = 0x7a020c; |
| 175 | 166 |
| 176 const char FakeBluetoothDeviceClient::kRequestPasskeyPath[] = | 167 const char FakeBluetoothDeviceClient::kRequestPasskeyPath[] = "/fake/hci0/dev8"; |
| 177 "/fake/hci0/dev8"; | |
| 178 const char FakeBluetoothDeviceClient::kRequestPasskeyAddress[] = | 168 const char FakeBluetoothDeviceClient::kRequestPasskeyAddress[] = |
| 179 "20:7D:74:00:00:01"; | 169 "20:7D:74:00:00:01"; |
| 180 const char FakeBluetoothDeviceClient::kRequestPasskeyName[] = | 170 const char FakeBluetoothDeviceClient::kRequestPasskeyName[] = "Passkey Device"; |
| 181 "Passkey Device"; | |
| 182 const uint32 FakeBluetoothDeviceClient::kRequestPasskeyClass = 0x7a020c; | 171 const uint32 FakeBluetoothDeviceClient::kRequestPasskeyClass = 0x7a020c; |
| 183 | 172 |
| 184 const char FakeBluetoothDeviceClient::kUnconnectableDevicePath[] = | 173 const char FakeBluetoothDeviceClient::kUnconnectableDevicePath[] = |
| 185 "/fake/hci0/dev9"; | 174 "/fake/hci0/dev9"; |
| 186 const char FakeBluetoothDeviceClient::kUnconnectableDeviceAddress[] = | 175 const char FakeBluetoothDeviceClient::kUnconnectableDeviceAddress[] = |
| 187 "20:7D:74:00:00:02"; | 176 "20:7D:74:00:00:02"; |
| 188 const char FakeBluetoothDeviceClient::kUnconnectableDeviceName[] = | 177 const char FakeBluetoothDeviceClient::kUnconnectableDeviceName[] = |
| 189 "Unconnectable Device"; | 178 "Unconnectable Device"; |
| 190 const uint32 FakeBluetoothDeviceClient::kUnconnectableDeviceClass = 0x7a020c; | 179 const uint32 FakeBluetoothDeviceClient::kUnconnectableDeviceClass = 0x7a020c; |
| 191 | 180 |
| 192 const char FakeBluetoothDeviceClient::kUnpairableDevicePath[] = | 181 const char FakeBluetoothDeviceClient::kUnpairableDevicePath[] = |
| 193 "/fake/hci0/devA"; | 182 "/fake/hci0/devA"; |
| 194 const char FakeBluetoothDeviceClient::kUnpairableDeviceAddress[] = | 183 const char FakeBluetoothDeviceClient::kUnpairableDeviceAddress[] = |
| 195 "20:7D:74:00:00:03"; | 184 "20:7D:74:00:00:03"; |
| 196 const char FakeBluetoothDeviceClient::kUnpairableDeviceName[] = | 185 const char FakeBluetoothDeviceClient::kUnpairableDeviceName[] = |
| 197 "Unpairable Device"; | 186 "Unpairable Device"; |
| 198 const uint32 FakeBluetoothDeviceClient::kUnpairableDeviceClass = 0x002540; | 187 const uint32 FakeBluetoothDeviceClient::kUnpairableDeviceClass = 0x002540; |
| 199 | 188 |
| 200 const char FakeBluetoothDeviceClient::kJustWorksPath[] = | 189 const char FakeBluetoothDeviceClient::kJustWorksPath[] = "/fake/hci0/devB"; |
| 201 "/fake/hci0/devB"; | 190 const char FakeBluetoothDeviceClient::kJustWorksAddress[] = "00:0C:8A:00:00:00"; |
| 202 const char FakeBluetoothDeviceClient::kJustWorksAddress[] = | 191 const char FakeBluetoothDeviceClient::kJustWorksName[] = "Just-Works Device"; |
| 203 "00:0C:8A:00:00:00"; | |
| 204 const char FakeBluetoothDeviceClient::kJustWorksName[] = | |
| 205 "Just-Works Device"; | |
| 206 const uint32 FakeBluetoothDeviceClient::kJustWorksClass = 0x240428; | 192 const uint32 FakeBluetoothDeviceClient::kJustWorksClass = 0x240428; |
| 207 | 193 |
| 208 const char FakeBluetoothDeviceClient::kLowEnergyPath[] = | 194 const char FakeBluetoothDeviceClient::kLowEnergyPath[] = "/fake/hci0/devC"; |
| 209 "/fake/hci0/devC"; | 195 const char FakeBluetoothDeviceClient::kLowEnergyAddress[] = "00:1A:11:00:15:30"; |
| 210 const char FakeBluetoothDeviceClient::kLowEnergyAddress[] = | |
| 211 "00:1A:11:00:15:30"; | |
| 212 const char FakeBluetoothDeviceClient::kLowEnergyName[] = | 196 const char FakeBluetoothDeviceClient::kLowEnergyName[] = |
| 213 "Bluetooth 4.0 Heart Rate Monitor"; | 197 "Bluetooth 4.0 Heart Rate Monitor"; |
| 214 const uint32 FakeBluetoothDeviceClient::kLowEnergyClass = | 198 const uint32 FakeBluetoothDeviceClient::kLowEnergyClass = |
| 215 0x000918; // Major class "Health", Minor class "Heart/Pulse Rate Monitor." | 199 0x000918; // Major class "Health", Minor class "Heart/Pulse Rate Monitor." |
| 216 | 200 |
| 217 const char FakeBluetoothDeviceClient::kPairedUnconnectableDevicePath[] = | 201 const char FakeBluetoothDeviceClient::kPairedUnconnectableDevicePath[] = |
| 218 "/fake/hci0/devD"; | 202 "/fake/hci0/devD"; |
| 219 const char FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress[] = | 203 const char FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress[] = |
| 220 "20:7D:74:00:00:04"; | 204 "20:7D:74:00:00:04"; |
| 221 const char FakeBluetoothDeviceClient::kPairedUnconnectableDeviceName[] = | 205 const char FakeBluetoothDeviceClient::kPairedUnconnectableDeviceName[] = |
| 222 "Paired Unconnectable Device"; | 206 "Paired Unconnectable Device"; |
| 223 const uint32 FakeBluetoothDeviceClient::kPairedUnconnectableDeviceClass = | 207 const uint32 FakeBluetoothDeviceClient::kPairedUnconnectableDeviceClass = |
| 224 0x000104; | 208 0x000104; |
| 225 | 209 |
| 226 FakeBluetoothDeviceClient::Properties::Properties( | 210 FakeBluetoothDeviceClient::Properties::Properties( |
| 227 const PropertyChangedCallback& callback) | 211 const PropertyChangedCallback& callback) |
| 228 : BluetoothDeviceClient::Properties( | 212 : BluetoothDeviceClient::Properties( |
| 229 NULL, | 213 NULL, |
| 230 bluetooth_device::kBluetoothDeviceInterface, | 214 bluetooth_device::kBluetoothDeviceInterface, |
| 231 callback) { | 215 callback) {} |
| 232 } | |
| 233 | 216 |
| 234 FakeBluetoothDeviceClient::Properties::~Properties() { | 217 FakeBluetoothDeviceClient::Properties::~Properties() {} |
| 235 } | |
| 236 | 218 |
| 237 void FakeBluetoothDeviceClient::Properties::Get( | 219 void FakeBluetoothDeviceClient::Properties::Get( |
| 238 dbus::PropertyBase* property, | 220 dbus::PropertyBase* property, |
| 239 dbus::PropertySet::GetCallback callback) { | 221 dbus::PropertySet::GetCallback callback) { |
| 240 VLOG(1) << "Get " << property->name(); | 222 VLOG(1) << "Get " << property->name(); |
| 241 callback.Run(false); | 223 callback.Run(false); |
| 242 } | 224 } |
| 243 | 225 |
| 244 void FakeBluetoothDeviceClient::Properties::GetAll() { | 226 void FakeBluetoothDeviceClient::Properties::GetAll() { |
| 245 VLOG(1) << "GetAll"; | 227 VLOG(1) << "GetAll"; |
| 246 } | 228 } |
| 247 | 229 |
| 248 void FakeBluetoothDeviceClient::Properties::Set( | 230 void FakeBluetoothDeviceClient::Properties::Set( |
| 249 dbus::PropertyBase *property, | 231 dbus::PropertyBase* property, |
| 250 dbus::PropertySet::SetCallback callback) { | 232 dbus::PropertySet::SetCallback callback) { |
| 251 VLOG(1) << "Set " << property->name(); | 233 VLOG(1) << "Set " << property->name(); |
| 252 if (property->name() == trusted.name()) { | 234 if (property->name() == trusted.name()) { |
| 253 callback.Run(true); | 235 callback.Run(true); |
| 254 property->ReplaceValueWithSetValue(); | 236 property->ReplaceValueWithSetValue(); |
| 255 } else { | 237 } else { |
| 256 callback.Run(false); | 238 callback.Run(false); |
| 257 } | 239 } |
| 258 } | 240 } |
| 259 | 241 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 | 295 |
| 314 properties->uuids.ReplaceValue(uuids); | 296 properties->uuids.ReplaceValue(uuids); |
| 315 | 297 |
| 316 properties->modalias.ReplaceValue("usb:v05ACp030Dd0306"); | 298 properties->modalias.ReplaceValue("usb:v05ACp030Dd0306"); |
| 317 | 299 |
| 318 properties_map_.insert(dbus::ObjectPath(kPairedUnconnectableDevicePath), | 300 properties_map_.insert(dbus::ObjectPath(kPairedUnconnectableDevicePath), |
| 319 properties.Pass()); | 301 properties.Pass()); |
| 320 device_list_.push_back(dbus::ObjectPath(kPairedUnconnectableDevicePath)); | 302 device_list_.push_back(dbus::ObjectPath(kPairedUnconnectableDevicePath)); |
| 321 } | 303 } |
| 322 | 304 |
| 323 FakeBluetoothDeviceClient::~FakeBluetoothDeviceClient() { | 305 FakeBluetoothDeviceClient::~FakeBluetoothDeviceClient() {} |
| 324 } | |
| 325 | 306 |
| 326 void FakeBluetoothDeviceClient::Init(dbus::Bus* bus) { | 307 void FakeBluetoothDeviceClient::Init(dbus::Bus* bus) {} |
| 327 } | |
| 328 | 308 |
| 329 void FakeBluetoothDeviceClient::AddObserver(Observer* observer) { | 309 void FakeBluetoothDeviceClient::AddObserver(Observer* observer) { |
| 330 observers_.AddObserver(observer); | 310 observers_.AddObserver(observer); |
| 331 } | 311 } |
| 332 | 312 |
| 333 void FakeBluetoothDeviceClient::RemoveObserver(Observer* observer) { | 313 void FakeBluetoothDeviceClient::RemoveObserver(Observer* observer) { |
| 334 observers_.RemoveObserver(observer); | 314 observers_.RemoveObserver(observer); |
| 335 } | 315 } |
| 336 | 316 |
| 337 std::vector<dbus::ObjectPath> FakeBluetoothDeviceClient::GetDevicesForAdapter( | 317 std::vector<dbus::ObjectPath> FakeBluetoothDeviceClient::GetDevicesForAdapter( |
| 338 const dbus::ObjectPath& adapter_path) { | 318 const dbus::ObjectPath& adapter_path) { |
| 339 if (adapter_path == | 319 if (adapter_path == |
| 340 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)) | 320 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)) |
| 341 return device_list_; | 321 return device_list_; |
| 342 else | 322 else |
| 343 return std::vector<dbus::ObjectPath>(); | 323 return std::vector<dbus::ObjectPath>(); |
| 344 } | 324 } |
| 345 | 325 |
| 346 FakeBluetoothDeviceClient::Properties* | 326 FakeBluetoothDeviceClient::Properties* FakeBluetoothDeviceClient::GetProperties( |
| 347 FakeBluetoothDeviceClient::GetProperties(const dbus::ObjectPath& object_path) { | 327 const dbus::ObjectPath& object_path) { |
| 348 PropertiesMap::const_iterator iter = properties_map_.find(object_path); | 328 PropertiesMap::const_iterator iter = properties_map_.find(object_path); |
| 349 if (iter != properties_map_.end()) | 329 if (iter != properties_map_.end()) |
| 350 return iter->second; | 330 return iter->second; |
| 351 return NULL; | 331 return NULL; |
| 352 } | 332 } |
| 353 | 333 |
| 354 FakeBluetoothDeviceClient::SimulatedPairingOptions* | 334 FakeBluetoothDeviceClient::SimulatedPairingOptions* |
| 355 FakeBluetoothDeviceClient::GetPairingOptions( | 335 FakeBluetoothDeviceClient::GetPairingOptions( |
| 356 const dbus::ObjectPath& object_path) { | 336 const dbus::ObjectPath& object_path) { |
| 357 PairingOptionsMap::const_iterator iter = | 337 PairingOptionsMap::const_iterator iter = |
| 358 pairing_options_map_.find(object_path); | 338 pairing_options_map_.find(object_path); |
| 359 if (iter != pairing_options_map_.end()) | 339 if (iter != pairing_options_map_.end()) |
| 360 return iter->second; | 340 return iter->second; |
| 361 return iter != pairing_options_map_.end() ? iter->second : nullptr; | 341 return iter != pairing_options_map_.end() ? iter->second : nullptr; |
| 362 } | 342 } |
| 363 | 343 |
| 364 void FakeBluetoothDeviceClient::Connect( | 344 void FakeBluetoothDeviceClient::Connect(const dbus::ObjectPath& object_path, |
| 365 const dbus::ObjectPath& object_path, | 345 const base::Closure& callback, |
| 366 const base::Closure& callback, | 346 const ErrorCallback& error_callback) { |
| 367 const ErrorCallback& error_callback) { | |
| 368 VLOG(1) << "Connect: " << object_path.value(); | 347 VLOG(1) << "Connect: " << object_path.value(); |
| 369 Properties* properties = GetProperties(object_path); | 348 Properties* properties = GetProperties(object_path); |
| 370 | 349 |
| 371 if (properties->connected.value() == true) { | 350 if (properties->connected.value() == true) { |
| 372 // Already connected. | 351 // Already connected. |
| 373 callback.Run(); | 352 callback.Run(); |
| 374 return; | 353 return; |
| 375 } | 354 } |
| 376 | 355 |
| 377 if (properties->paired.value() != true && | 356 if (properties->paired.value() != true && |
| (...skipping 13 matching lines...) Expand all Loading... |
| 391 } | 370 } |
| 392 | 371 |
| 393 // The device can be connected. | 372 // The device can be connected. |
| 394 properties->connected.ReplaceValue(true); | 373 properties->connected.ReplaceValue(true); |
| 395 callback.Run(); | 374 callback.Run(); |
| 396 | 375 |
| 397 // Expose GATT services if connected to LE device. | 376 // Expose GATT services if connected to LE device. |
| 398 if (object_path == dbus::ObjectPath(kLowEnergyPath)) { | 377 if (object_path == dbus::ObjectPath(kLowEnergyPath)) { |
| 399 FakeBluetoothGattServiceClient* gatt_service_client = | 378 FakeBluetoothGattServiceClient* gatt_service_client = |
| 400 static_cast<FakeBluetoothGattServiceClient*>( | 379 static_cast<FakeBluetoothGattServiceClient*>( |
| 401 DBusThreadManager::Get()->GetBluetoothGattServiceClient()); | 380 bluez::BluezDBusManager::Get()->GetBluetoothGattServiceClient()); |
| 402 gatt_service_client->ExposeHeartRateService( | 381 gatt_service_client->ExposeHeartRateService( |
| 403 dbus::ObjectPath(kLowEnergyPath)); | 382 dbus::ObjectPath(kLowEnergyPath)); |
| 404 } | 383 } |
| 405 | 384 |
| 406 AddInputDeviceIfNeeded(object_path, properties); | 385 AddInputDeviceIfNeeded(object_path, properties); |
| 407 } | 386 } |
| 408 | 387 |
| 409 void FakeBluetoothDeviceClient::Disconnect( | 388 void FakeBluetoothDeviceClient::Disconnect( |
| 410 const dbus::ObjectPath& object_path, | 389 const dbus::ObjectPath& object_path, |
| 411 const base::Closure& callback, | 390 const base::Closure& callback, |
| 412 const ErrorCallback& error_callback) { | 391 const ErrorCallback& error_callback) { |
| 413 VLOG(1) << "Disconnect: " << object_path.value(); | 392 VLOG(1) << "Disconnect: " << object_path.value(); |
| 414 Properties* properties = GetProperties(object_path); | 393 Properties* properties = GetProperties(object_path); |
| 415 | 394 |
| 416 if (!properties->connected.value()) { | 395 if (!properties->connected.value()) { |
| 417 error_callback.Run("org.bluez.Error.NotConnected", "Not Connected"); | 396 error_callback.Run("org.bluez.Error.NotConnected", "Not Connected"); |
| 418 return; | 397 return; |
| 419 } | 398 } |
| 420 | 399 |
| 421 // Hide the Heart Rate Service if disconnected from LE device. | 400 // Hide the Heart Rate Service if disconnected from LE device. |
| 422 if (object_path == dbus::ObjectPath(kLowEnergyPath)) { | 401 if (object_path == dbus::ObjectPath(kLowEnergyPath)) { |
| 423 FakeBluetoothGattServiceClient* gatt_service_client = | 402 FakeBluetoothGattServiceClient* gatt_service_client = |
| 424 static_cast<FakeBluetoothGattServiceClient*>( | 403 static_cast<FakeBluetoothGattServiceClient*>( |
| 425 DBusThreadManager::Get()->GetBluetoothGattServiceClient()); | 404 bluez::BluezDBusManager::Get()->GetBluetoothGattServiceClient()); |
| 426 gatt_service_client->HideHeartRateService(); | 405 gatt_service_client->HideHeartRateService(); |
| 427 } | 406 } |
| 428 | 407 |
| 429 callback.Run(); | 408 callback.Run(); |
| 430 properties->connected.ReplaceValue(false); | 409 properties->connected.ReplaceValue(false); |
| 431 } | 410 } |
| 432 | 411 |
| 433 void FakeBluetoothDeviceClient::ConnectProfile( | 412 void FakeBluetoothDeviceClient::ConnectProfile( |
| 434 const dbus::ObjectPath& object_path, | 413 const dbus::ObjectPath& object_path, |
| 435 const std::string& uuid, | 414 const std::string& uuid, |
| 436 const base::Closure& callback, | 415 const base::Closure& callback, |
| 437 const ErrorCallback& error_callback) { | 416 const ErrorCallback& error_callback) { |
| 438 VLOG(1) << "ConnectProfile: " << object_path.value() << " " << uuid; | 417 VLOG(1) << "ConnectProfile: " << object_path.value() << " " << uuid; |
| 439 | 418 |
| 440 FakeBluetoothProfileManagerClient* fake_bluetooth_profile_manager_client = | 419 FakeBluetoothProfileManagerClient* fake_bluetooth_profile_manager_client = |
| 441 static_cast<FakeBluetoothProfileManagerClient*>( | 420 static_cast<FakeBluetoothProfileManagerClient*>( |
| 442 DBusThreadManager::Get()->GetBluetoothProfileManagerClient()); | 421 bluez::BluezDBusManager::Get()->GetBluetoothProfileManagerClient()); |
| 443 FakeBluetoothProfileServiceProvider* profile_service_provider = | 422 FakeBluetoothProfileServiceProvider* profile_service_provider = |
| 444 fake_bluetooth_profile_manager_client->GetProfileServiceProvider(uuid); | 423 fake_bluetooth_profile_manager_client->GetProfileServiceProvider(uuid); |
| 445 if (profile_service_provider == NULL) { | 424 if (profile_service_provider == NULL) { |
| 446 error_callback.Run(kNoResponseError, "Missing profile"); | 425 error_callback.Run(kNoResponseError, "Missing profile"); |
| 447 return; | 426 return; |
| 448 } | 427 } |
| 449 | 428 |
| 450 if (object_path == dbus::ObjectPath(kPairedUnconnectableDevicePath)) { | 429 if (object_path == dbus::ObjectPath(kPairedUnconnectableDevicePath)) { |
| 451 error_callback.Run(bluetooth_device::kErrorFailed, "unconnectable"); | 430 error_callback.Run(bluetooth_device::kErrorFailed, "unconnectable"); |
| 452 return; | 431 return; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 471 error_callback.Run(kNoResponseError, "failed to get socket flags"); | 450 error_callback.Run(kNoResponseError, "failed to get socket flags"); |
| 472 return; | 451 return; |
| 473 } | 452 } |
| 474 | 453 |
| 475 args |= O_NONBLOCK; | 454 args |= O_NONBLOCK; |
| 476 if (fcntl(fds[1], F_SETFL, args) < 0) { | 455 if (fcntl(fds[1], F_SETFL, args) < 0) { |
| 477 error_callback.Run(kNoResponseError, "failed to set socket non-blocking"); | 456 error_callback.Run(kNoResponseError, "failed to set socket non-blocking"); |
| 478 return; | 457 return; |
| 479 } | 458 } |
| 480 | 459 |
| 481 base::WorkerPool::GetTaskRunner(false)->PostTask( | 460 base::WorkerPool::GetTaskRunner(false) |
| 482 FROM_HERE, | 461 ->PostTask(FROM_HERE, base::Bind(&SimulatedProfileSocket, fds[0])); |
| 483 base::Bind(&SimulatedProfileSocket, | |
| 484 fds[0])); | |
| 485 | 462 |
| 486 scoped_ptr<dbus::FileDescriptor> fd(new dbus::FileDescriptor(fds[1])); | 463 scoped_ptr<dbus::FileDescriptor> fd(new dbus::FileDescriptor(fds[1])); |
| 487 | 464 |
| 488 // Post the new connection to the service provider. | 465 // Post the new connection to the service provider. |
| 489 BluetoothProfileServiceProvider::Delegate::Options options; | 466 BluetoothProfileServiceProvider::Delegate::Options options; |
| 490 | 467 |
| 491 profile_service_provider->NewConnection( | 468 profile_service_provider->NewConnection( |
| 492 object_path, | 469 object_path, fd.Pass(), options, |
| 493 fd.Pass(), | |
| 494 options, | |
| 495 base::Bind(&FakeBluetoothDeviceClient::ConnectionCallback, | 470 base::Bind(&FakeBluetoothDeviceClient::ConnectionCallback, |
| 496 base::Unretained(this), | 471 base::Unretained(this), object_path, callback, |
| 497 object_path, | |
| 498 callback, | |
| 499 error_callback)); | 472 error_callback)); |
| 500 } | 473 } |
| 501 | 474 |
| 502 void FakeBluetoothDeviceClient::DisconnectProfile( | 475 void FakeBluetoothDeviceClient::DisconnectProfile( |
| 503 const dbus::ObjectPath& object_path, | 476 const dbus::ObjectPath& object_path, |
| 504 const std::string& uuid, | 477 const std::string& uuid, |
| 505 const base::Closure& callback, | 478 const base::Closure& callback, |
| 506 const ErrorCallback& error_callback) { | 479 const ErrorCallback& error_callback) { |
| 507 VLOG(1) << "DisconnectProfile: " << object_path.value() << " " << uuid; | 480 VLOG(1) << "DisconnectProfile: " << object_path.value() << " " << uuid; |
| 508 | 481 |
| 509 FakeBluetoothProfileManagerClient* fake_bluetooth_profile_manager_client = | 482 FakeBluetoothProfileManagerClient* fake_bluetooth_profile_manager_client = |
| 510 static_cast<FakeBluetoothProfileManagerClient*>( | 483 static_cast<FakeBluetoothProfileManagerClient*>( |
| 511 DBusThreadManager::Get()->GetBluetoothProfileManagerClient()); | 484 bluez::BluezDBusManager::Get()->GetBluetoothProfileManagerClient()); |
| 512 FakeBluetoothProfileServiceProvider* profile_service_provider = | 485 FakeBluetoothProfileServiceProvider* profile_service_provider = |
| 513 fake_bluetooth_profile_manager_client->GetProfileServiceProvider(uuid); | 486 fake_bluetooth_profile_manager_client->GetProfileServiceProvider(uuid); |
| 514 if (profile_service_provider == NULL) { | 487 if (profile_service_provider == NULL) { |
| 515 error_callback.Run(kNoResponseError, "Missing profile"); | 488 error_callback.Run(kNoResponseError, "Missing profile"); |
| 516 return; | 489 return; |
| 517 } | 490 } |
| 518 | 491 |
| 519 profile_service_provider->RequestDisconnection( | 492 profile_service_provider->RequestDisconnection( |
| 520 object_path, | 493 object_path, base::Bind(&FakeBluetoothDeviceClient::DisconnectionCallback, |
| 521 base::Bind(&FakeBluetoothDeviceClient::DisconnectionCallback, | 494 base::Unretained(this), object_path, callback, |
| 522 base::Unretained(this), | 495 error_callback)); |
| 523 object_path, | |
| 524 callback, | |
| 525 error_callback)); | |
| 526 } | 496 } |
| 527 | 497 |
| 528 void FakeBluetoothDeviceClient::Pair( | 498 void FakeBluetoothDeviceClient::Pair(const dbus::ObjectPath& object_path, |
| 529 const dbus::ObjectPath& object_path, | 499 const base::Closure& callback, |
| 530 const base::Closure& callback, | 500 const ErrorCallback& error_callback) { |
| 531 const ErrorCallback& error_callback) { | |
| 532 VLOG(1) << "Pair: " << object_path.value(); | 501 VLOG(1) << "Pair: " << object_path.value(); |
| 533 Properties* properties = GetProperties(object_path); | 502 Properties* properties = GetProperties(object_path); |
| 534 | 503 |
| 535 if (properties->paired.value() == true) { | 504 if (properties->paired.value() == true) { |
| 536 // Already paired. | 505 // Already paired. |
| 537 callback.Run(); | 506 callback.Run(); |
| 538 return; | 507 return; |
| 539 } | 508 } |
| 540 | 509 |
| 541 SimulatePairing(object_path, false, callback, error_callback); | 510 SimulatePairing(object_path, false, callback, error_callback); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 incoming_pairing_simulation_step_ = 0; | 572 incoming_pairing_simulation_step_ = 0; |
| 604 } | 573 } |
| 605 | 574 |
| 606 void FakeBluetoothDeviceClient::SetSimulationIntervalMs(int interval_ms) { | 575 void FakeBluetoothDeviceClient::SetSimulationIntervalMs(int interval_ms) { |
| 607 simulation_interval_ms_ = interval_ms; | 576 simulation_interval_ms_ = interval_ms; |
| 608 } | 577 } |
| 609 | 578 |
| 610 void FakeBluetoothDeviceClient::CreateDevice( | 579 void FakeBluetoothDeviceClient::CreateDevice( |
| 611 const dbus::ObjectPath& adapter_path, | 580 const dbus::ObjectPath& adapter_path, |
| 612 const dbus::ObjectPath& device_path) { | 581 const dbus::ObjectPath& device_path) { |
| 613 if (std::find(device_list_.begin(), | 582 if (std::find(device_list_.begin(), device_list_.end(), device_path) != |
| 614 device_list_.end(), device_path) != device_list_.end()) | 583 device_list_.end()) |
| 615 return; | 584 return; |
| 616 | 585 |
| 617 scoped_ptr<Properties> properties( | 586 scoped_ptr<Properties> properties( |
| 618 new Properties(base::Bind(&FakeBluetoothDeviceClient::OnPropertyChanged, | 587 new Properties(base::Bind(&FakeBluetoothDeviceClient::OnPropertyChanged, |
| 619 base::Unretained(this), device_path))); | 588 base::Unretained(this), device_path))); |
| 620 properties->adapter.ReplaceValue(adapter_path); | 589 properties->adapter.ReplaceValue(adapter_path); |
| 621 | 590 |
| 622 if (device_path == dbus::ObjectPath(kLegacyAutopairPath)) { | 591 if (device_path == dbus::ObjectPath(kLegacyAutopairPath)) { |
| 623 properties->address.ReplaceValue(kLegacyAutopairAddress); | 592 properties->address.ReplaceValue(kLegacyAutopairAddress); |
| 624 properties->bluetooth_class.ReplaceValue(kLegacyAutopairClass); | 593 properties->bluetooth_class.ReplaceValue(kLegacyAutopairClass); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 properties->bluetooth_class.ReplaceValue(kLowEnergyClass); | 675 properties->bluetooth_class.ReplaceValue(kLowEnergyClass); |
| 707 properties->name.ReplaceValue("Heart Rate Monitor"); | 676 properties->name.ReplaceValue("Heart Rate Monitor"); |
| 708 properties->alias.ReplaceValue(kLowEnergyName); | 677 properties->alias.ReplaceValue(kLowEnergyName); |
| 709 | 678 |
| 710 std::vector<std::string> uuids; | 679 std::vector<std::string> uuids; |
| 711 uuids.push_back(FakeBluetoothGattServiceClient::kHeartRateServiceUUID); | 680 uuids.push_back(FakeBluetoothGattServiceClient::kHeartRateServiceUUID); |
| 712 properties->uuids.ReplaceValue(uuids); | 681 properties->uuids.ReplaceValue(uuids); |
| 713 | 682 |
| 714 } else { | 683 } else { |
| 715 NOTREACHED(); | 684 NOTREACHED(); |
| 716 | |
| 717 } | 685 } |
| 718 | 686 |
| 719 properties_map_.insert(device_path, properties.Pass()); | 687 properties_map_.insert(device_path, properties.Pass()); |
| 720 device_list_.push_back(device_path); | 688 device_list_.push_back(device_path); |
| 721 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, | 689 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, |
| 722 DeviceAdded(device_path)); | 690 DeviceAdded(device_path)); |
| 723 } | 691 } |
| 724 | 692 |
| 725 void FakeBluetoothDeviceClient::CreateDeviceWithProperties( | 693 void FakeBluetoothDeviceClient::CreateDeviceWithProperties( |
| 726 const dbus::ObjectPath& adapter_path, | 694 const dbus::ObjectPath& adapter_path, |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 Properties* properties = iter->second; | 955 Properties* properties = iter->second; |
| 988 | 956 |
| 989 VLOG(1) << "removing device: " << properties->alias.value(); | 957 VLOG(1) << "removing device: " << properties->alias.value(); |
| 990 device_list_.erase(listiter); | 958 device_list_.erase(listiter); |
| 991 | 959 |
| 992 // Remove the Input interface if it exists. This should be called before the | 960 // Remove the Input interface if it exists. This should be called before the |
| 993 // BluetoothDeviceClient::Observer::DeviceRemoved because it deletes the | 961 // BluetoothDeviceClient::Observer::DeviceRemoved because it deletes the |
| 994 // BluetoothDeviceChromeOS object, including the device_path referenced here. | 962 // BluetoothDeviceChromeOS object, including the device_path referenced here. |
| 995 FakeBluetoothInputClient* fake_bluetooth_input_client = | 963 FakeBluetoothInputClient* fake_bluetooth_input_client = |
| 996 static_cast<FakeBluetoothInputClient*>( | 964 static_cast<FakeBluetoothInputClient*>( |
| 997 DBusThreadManager::Get()->GetBluetoothInputClient()); | 965 bluez::BluezDBusManager::Get()->GetBluetoothInputClient()); |
| 998 fake_bluetooth_input_client->RemoveInputDevice(device_path); | 966 fake_bluetooth_input_client->RemoveInputDevice(device_path); |
| 999 | 967 |
| 1000 if (device_path == dbus::ObjectPath(kLowEnergyPath)) { | 968 if (device_path == dbus::ObjectPath(kLowEnergyPath)) { |
| 1001 FakeBluetoothGattServiceClient* gatt_service_client = | 969 FakeBluetoothGattServiceClient* gatt_service_client = |
| 1002 static_cast<FakeBluetoothGattServiceClient*>( | 970 static_cast<FakeBluetoothGattServiceClient*>( |
| 1003 DBusThreadManager::Get()->GetBluetoothGattServiceClient()); | 971 bluez::BluezDBusManager::Get()->GetBluetoothGattServiceClient()); |
| 1004 gatt_service_client->HideHeartRateService(); | 972 gatt_service_client->HideHeartRateService(); |
| 1005 } | 973 } |
| 1006 | 974 |
| 1007 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, | 975 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, |
| 1008 DeviceRemoved(device_path)); | 976 DeviceRemoved(device_path)); |
| 1009 | 977 |
| 1010 properties_map_.erase(iter); | 978 properties_map_.erase(iter); |
| 1011 PairingOptionsMap::const_iterator options_iter = | 979 PairingOptionsMap::const_iterator options_iter = |
| 1012 pairing_options_map_.find(device_path); | 980 pairing_options_map_.find(device_path); |
| 1013 | 981 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1076 | 1044 |
| 1077 } else if (discovery_simulation_step_ == 13) { | 1045 } else if (discovery_simulation_step_ == 13) { |
| 1078 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), | 1046 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), |
| 1079 base::RandInt(kMinRSSI, kMaxRSSI)); | 1047 base::RandInt(kMinRSSI, kMaxRSSI)); |
| 1080 RemoveDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 1048 RemoveDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 1081 dbus::ObjectPath(kVanishingDevicePath)); | 1049 dbus::ObjectPath(kVanishingDevicePath)); |
| 1082 } else if (discovery_simulation_step_ == 14) { | 1050 } else if (discovery_simulation_step_ == 14) { |
| 1083 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), | 1051 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), |
| 1084 base::RandInt(kMinRSSI, kMaxRSSI)); | 1052 base::RandInt(kMinRSSI, kMaxRSSI)); |
| 1085 return; | 1053 return; |
| 1086 | |
| 1087 } | 1054 } |
| 1088 | 1055 |
| 1089 ++discovery_simulation_step_; | 1056 ++discovery_simulation_step_; |
| 1090 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1057 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1091 FROM_HERE, | 1058 FROM_HERE, |
| 1092 base::Bind(&FakeBluetoothDeviceClient::DiscoverySimulationTimer, | 1059 base::Bind(&FakeBluetoothDeviceClient::DiscoverySimulationTimer, |
| 1093 base::Unretained(this)), | 1060 base::Unretained(this)), |
| 1094 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); | 1061 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); |
| 1095 } | 1062 } |
| 1096 | 1063 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1158 | 1125 |
| 1159 void FakeBluetoothDeviceClient::SimulatePairing( | 1126 void FakeBluetoothDeviceClient::SimulatePairing( |
| 1160 const dbus::ObjectPath& object_path, | 1127 const dbus::ObjectPath& object_path, |
| 1161 bool incoming_request, | 1128 bool incoming_request, |
| 1162 const base::Closure& callback, | 1129 const base::Closure& callback, |
| 1163 const ErrorCallback& error_callback) { | 1130 const ErrorCallback& error_callback) { |
| 1164 pairing_cancelled_ = false; | 1131 pairing_cancelled_ = false; |
| 1165 | 1132 |
| 1166 FakeBluetoothAgentManagerClient* fake_bluetooth_agent_manager_client = | 1133 FakeBluetoothAgentManagerClient* fake_bluetooth_agent_manager_client = |
| 1167 static_cast<FakeBluetoothAgentManagerClient*>( | 1134 static_cast<FakeBluetoothAgentManagerClient*>( |
| 1168 DBusThreadManager::Get()->GetBluetoothAgentManagerClient()); | 1135 bluez::BluezDBusManager::Get()->GetBluetoothAgentManagerClient()); |
| 1169 FakeBluetoothAgentServiceProvider* agent_service_provider = | 1136 FakeBluetoothAgentServiceProvider* agent_service_provider = |
| 1170 fake_bluetooth_agent_manager_client->GetAgentServiceProvider(); | 1137 fake_bluetooth_agent_manager_client->GetAgentServiceProvider(); |
| 1171 CHECK(agent_service_provider != NULL); | 1138 CHECK(agent_service_provider != NULL); |
| 1172 | 1139 |
| 1173 // Grab the device's pairing properties. | 1140 // Grab the device's pairing properties. |
| 1174 PairingOptionsMap::const_iterator iter = | 1141 PairingOptionsMap::const_iterator iter = |
| 1175 pairing_options_map_.find(object_path); | 1142 pairing_options_map_.find(object_path); |
| 1176 | 1143 |
| 1177 // If the device with path |object_path| has simulated pairing properties | 1144 // If the device with path |object_path| has simulated pairing properties |
| 1178 // defined, then pair it based on its |pairing_method|. | 1145 // defined, then pair it based on its |pairing_method|. |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1409 error_callback.Run(bluetooth_device::kErrorFailed, "Failed"); | 1376 error_callback.Run(bluetooth_device::kErrorFailed, "Failed"); |
| 1410 } | 1377 } |
| 1411 | 1378 |
| 1412 void FakeBluetoothDeviceClient::AddInputDeviceIfNeeded( | 1379 void FakeBluetoothDeviceClient::AddInputDeviceIfNeeded( |
| 1413 const dbus::ObjectPath& object_path, | 1380 const dbus::ObjectPath& object_path, |
| 1414 Properties* properties) { | 1381 Properties* properties) { |
| 1415 // If the paired device is a HID device based on it's bluetooth class, | 1382 // If the paired device is a HID device based on it's bluetooth class, |
| 1416 // simulate the Input interface. | 1383 // simulate the Input interface. |
| 1417 FakeBluetoothInputClient* fake_bluetooth_input_client = | 1384 FakeBluetoothInputClient* fake_bluetooth_input_client = |
| 1418 static_cast<FakeBluetoothInputClient*>( | 1385 static_cast<FakeBluetoothInputClient*>( |
| 1419 DBusThreadManager::Get()->GetBluetoothInputClient()); | 1386 bluez::BluezDBusManager::Get()->GetBluetoothInputClient()); |
| 1420 | 1387 |
| 1421 if ((properties->bluetooth_class.value() & 0x001f03) == 0x000500) | 1388 if ((properties->bluetooth_class.value() & 0x001f03) == 0x000500) |
| 1422 fake_bluetooth_input_client->AddInputDevice(object_path); | 1389 fake_bluetooth_input_client->AddInputDevice(object_path); |
| 1423 } | 1390 } |
| 1424 | 1391 |
| 1425 void FakeBluetoothDeviceClient::UpdateDeviceRSSI( | 1392 void FakeBluetoothDeviceClient::UpdateDeviceRSSI( |
| 1426 const dbus::ObjectPath& object_path, | 1393 const dbus::ObjectPath& object_path, |
| 1427 int16 rssi) { | 1394 int16 rssi) { |
| 1428 PropertiesMap::const_iterator iter = properties_map_.find(object_path); | 1395 PropertiesMap::const_iterator iter = properties_map_.find(object_path); |
| 1429 if (iter == properties_map_.end()) { | 1396 if (iter == properties_map_.end()) { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1579 | 1546 |
| 1580 void FakeBluetoothDeviceClient::SimulateKeypress( | 1547 void FakeBluetoothDeviceClient::SimulateKeypress( |
| 1581 uint16 entered, | 1548 uint16 entered, |
| 1582 const dbus::ObjectPath& object_path, | 1549 const dbus::ObjectPath& object_path, |
| 1583 const base::Closure& callback, | 1550 const base::Closure& callback, |
| 1584 const ErrorCallback& error_callback) { | 1551 const ErrorCallback& error_callback) { |
| 1585 VLOG(1) << "SimulateKeypress " << entered << ": " << object_path.value(); | 1552 VLOG(1) << "SimulateKeypress " << entered << ": " << object_path.value(); |
| 1586 | 1553 |
| 1587 FakeBluetoothAgentManagerClient* fake_bluetooth_agent_manager_client = | 1554 FakeBluetoothAgentManagerClient* fake_bluetooth_agent_manager_client = |
| 1588 static_cast<FakeBluetoothAgentManagerClient*>( | 1555 static_cast<FakeBluetoothAgentManagerClient*>( |
| 1589 DBusThreadManager::Get()->GetBluetoothAgentManagerClient()); | 1556 bluez::BluezDBusManager::Get()->GetBluetoothAgentManagerClient()); |
| 1590 FakeBluetoothAgentServiceProvider* agent_service_provider = | 1557 FakeBluetoothAgentServiceProvider* agent_service_provider = |
| 1591 fake_bluetooth_agent_manager_client->GetAgentServiceProvider(); | 1558 fake_bluetooth_agent_manager_client->GetAgentServiceProvider(); |
| 1592 | 1559 |
| 1593 // The agent service provider object could have been destroyed after the | 1560 // The agent service provider object could have been destroyed after the |
| 1594 // pairing is canceled. | 1561 // pairing is canceled. |
| 1595 if (!agent_service_provider) | 1562 if (!agent_service_provider) |
| 1596 return; | 1563 return; |
| 1597 | 1564 |
| 1598 agent_service_provider->DisplayPasskey(object_path, kTestPassKey, entered); | 1565 agent_service_provider->DisplayPasskey(object_path, kTestPassKey, entered); |
| 1599 | 1566 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1642 if (status == BluetoothProfileServiceProvider::Delegate::SUCCESS) { | 1609 if (status == BluetoothProfileServiceProvider::Delegate::SUCCESS) { |
| 1643 // TODO(keybuk): tear down this side of the connection | 1610 // TODO(keybuk): tear down this side of the connection |
| 1644 callback.Run(); | 1611 callback.Run(); |
| 1645 } else if (status == BluetoothProfileServiceProvider::Delegate::CANCELLED) { | 1612 } else if (status == BluetoothProfileServiceProvider::Delegate::CANCELLED) { |
| 1646 error_callback.Run(bluetooth_device::kErrorFailed, "Canceled"); | 1613 error_callback.Run(bluetooth_device::kErrorFailed, "Canceled"); |
| 1647 } else if (status == BluetoothProfileServiceProvider::Delegate::REJECTED) { | 1614 } else if (status == BluetoothProfileServiceProvider::Delegate::REJECTED) { |
| 1648 error_callback.Run(bluetooth_device::kErrorFailed, "Rejected"); | 1615 error_callback.Run(bluetooth_device::kErrorFailed, "Rejected"); |
| 1649 } | 1616 } |
| 1650 } | 1617 } |
| 1651 | 1618 |
| 1652 } // namespace chromeos | 1619 } // namespace bluez |
| OLD | NEW |