| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "device/bluetooth/bluez/bluetooth_device_bluez.h" | 5 #include "device/bluetooth/bluez/bluetooth_device_bluez.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "components/device_event_log/device_event_log.h" |
| 18 #include "dbus/bus.h" | 19 #include "dbus/bus.h" |
| 19 #include "device/bluetooth/bluetooth_socket.h" | 20 #include "device/bluetooth/bluetooth_socket.h" |
| 20 #include "device/bluetooth/bluetooth_socket_thread.h" | 21 #include "device/bluetooth/bluetooth_socket_thread.h" |
| 21 #include "device/bluetooth/bluetooth_uuid.h" | 22 #include "device/bluetooth/bluetooth_uuid.h" |
| 22 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h" | 23 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h" |
| 23 #include "device/bluetooth/bluez/bluetooth_gatt_connection_bluez.h" | 24 #include "device/bluetooth/bluez/bluetooth_gatt_connection_bluez.h" |
| 24 #include "device/bluetooth/bluez/bluetooth_pairing_bluez.h" | 25 #include "device/bluetooth/bluez/bluetooth_pairing_bluez.h" |
| 25 #include "device/bluetooth/bluez/bluetooth_remote_gatt_service_bluez.h" | 26 #include "device/bluetooth/bluez/bluetooth_remote_gatt_service_bluez.h" |
| 26 #include "device/bluetooth/bluez/bluetooth_service_record_bluez.h" | 27 #include "device/bluetooth/bluez/bluetooth_service_record_bluez.h" |
| 27 #include "device/bluetooth/bluez/bluetooth_socket_bluez.h" | 28 #include "device/bluetooth/bluez/bluetooth_socket_bluez.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 if (sscanf(modalias.c_str(), "bluetooth:v%04xp%04xd%04x", &vendor_value, | 73 if (sscanf(modalias.c_str(), "bluetooth:v%04xp%04xd%04x", &vendor_value, |
| 73 &product_value, &device_value) == 3) { | 74 &product_value, &device_value) == 3) { |
| 74 source_value = BluetoothDevice::VENDOR_ID_BLUETOOTH; | 75 source_value = BluetoothDevice::VENDOR_ID_BLUETOOTH; |
| 75 } else if (sscanf(modalias.c_str(), "usb:v%04xp%04xd%04x", &vendor_value, | 76 } else if (sscanf(modalias.c_str(), "usb:v%04xp%04xd%04x", &vendor_value, |
| 76 &product_value, &device_value) == 3) { | 77 &product_value, &device_value) == 3) { |
| 77 source_value = BluetoothDevice::VENDOR_ID_USB; | 78 source_value = BluetoothDevice::VENDOR_ID_USB; |
| 78 } else { | 79 } else { |
| 79 return; | 80 return; |
| 80 } | 81 } |
| 81 | 82 |
| 82 if (vendor_id_source != NULL) | 83 if (vendor_id_source != nullptr) |
| 83 *vendor_id_source = source_value; | 84 *vendor_id_source = source_value; |
| 84 if (vendor_id != NULL) | 85 if (vendor_id != nullptr) |
| 85 *vendor_id = vendor_value; | 86 *vendor_id = vendor_value; |
| 86 if (product_id != NULL) | 87 if (product_id != nullptr) |
| 87 *product_id = product_value; | 88 *product_id = product_value; |
| 88 if (device_id != NULL) | 89 if (device_id != nullptr) |
| 89 *device_id = device_value; | 90 *device_id = device_value; |
| 90 } | 91 } |
| 91 | 92 |
| 92 void RecordPairingResult(BluetoothDevice::ConnectErrorCode error_code) { | 93 void RecordPairingResult(BluetoothDevice::ConnectErrorCode error_code) { |
| 93 UMAPairingResult pairing_result; | 94 UMAPairingResult pairing_result; |
| 94 switch (error_code) { | 95 switch (error_code) { |
| 95 case BluetoothDevice::ERROR_INPROGRESS: | 96 case BluetoothDevice::ERROR_INPROGRESS: |
| 96 pairing_result = UMA_PAIRING_RESULT_INPROGRESS; | 97 pairing_result = UMA_PAIRING_RESULT_INPROGRESS; |
| 97 break; | 98 break; |
| 98 case BluetoothDevice::ERROR_FAILED: | 99 case BluetoothDevice::ERROR_FAILED: |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 socket_thread_(socket_thread), | 158 socket_thread_(socket_thread), |
| 158 weak_ptr_factory_(this) { | 159 weak_ptr_factory_(this) { |
| 159 bluez::BluezDBusManager::Get()->GetBluetoothGattServiceClient()->AddObserver( | 160 bluez::BluezDBusManager::Get()->GetBluetoothGattServiceClient()->AddObserver( |
| 160 this); | 161 this); |
| 161 | 162 |
| 162 // If GATT Services have already been discovered update the list of Gatt | 163 // If GATT Services have already been discovered update the list of Gatt |
| 163 // Services. | 164 // Services. |
| 164 if (IsGattServicesDiscoveryComplete()) { | 165 if (IsGattServicesDiscoveryComplete()) { |
| 165 UpdateGattServices(object_path_); | 166 UpdateGattServices(object_path_); |
| 166 } else { | 167 } else { |
| 167 VLOG(2) << "Gatt services have not been fully resolved for device " | 168 BLUETOOTH_LOG(DEBUG) |
| 168 << object_path_.value(); | 169 << "Gatt services have not been fully resolved for device " |
| 170 << object_path_.value(); |
| 169 } | 171 } |
| 170 | 172 |
| 171 // Update all the data that we cache within Chrome and do not pull from | 173 // Update all the data that we cache within Chrome and do not pull from |
| 172 // properties every time. TODO(xiaoyinh): Add a test for this. See | 174 // properties every time. TODO(xiaoyinh): Add a test for this. See |
| 173 // http://crbug.com/688566. | 175 // http://crbug.com/688566. |
| 174 UpdateServiceData(); | 176 UpdateServiceData(); |
| 175 UpdateManufacturerData(); | 177 UpdateManufacturerData(); |
| 176 UpdateAdvertisingDataFlags(); | 178 UpdateAdvertisingDataFlags(); |
| 177 } | 179 } |
| 178 | 180 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 // IsPaired() returns true if we've connected to the device before. So we | 257 // IsPaired() returns true if we've connected to the device before. So we |
| 256 // check the dbus property directly. | 258 // check the dbus property directly. |
| 257 // TODO(crbug.com/649651): Use IsPaired once it returns true only for paired | 259 // TODO(crbug.com/649651): Use IsPaired once it returns true only for paired |
| 258 // devices. | 260 // devices. |
| 259 bluez::BluetoothDeviceClient::Properties* properties = | 261 bluez::BluetoothDeviceClient::Properties* properties = |
| 260 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 262 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 261 object_path_); | 263 object_path_); |
| 262 DCHECK(properties); | 264 DCHECK(properties); |
| 263 | 265 |
| 264 if (properties->paired.value()) { | 266 if (properties->paired.value()) { |
| 265 LOG(WARNING) << "Leaking connection to paired device."; | 267 BLUETOOTH_LOG(ERROR) << "Leaking connection to paired device."; |
| 266 return; | 268 return; |
| 267 } | 269 } |
| 268 | 270 |
| 269 Disconnect(base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); | 271 Disconnect(base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); |
| 270 } | 272 } |
| 271 | 273 |
| 272 std::string BluetoothDeviceBlueZ::GetAddress() const { | 274 std::string BluetoothDeviceBlueZ::GetAddress() const { |
| 273 bluez::BluetoothDeviceClient::Properties* properties = | 275 bluez::BluetoothDeviceClient::Properties* properties = |
| 274 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 276 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 275 object_path_); | 277 object_path_); |
| 276 DCHECK(properties); | 278 DCHECK(properties); |
| 277 | 279 |
| 278 return CanonicalizeAddress(properties->address.value()); | 280 return CanonicalizeAddress(properties->address.value()); |
| 279 } | 281 } |
| 280 | 282 |
| 281 BluetoothDevice::VendorIDSource BluetoothDeviceBlueZ::GetVendorIDSource() | 283 BluetoothDevice::VendorIDSource BluetoothDeviceBlueZ::GetVendorIDSource() |
| 282 const { | 284 const { |
| 283 VendorIDSource vendor_id_source = VENDOR_ID_UNKNOWN; | 285 VendorIDSource vendor_id_source = VENDOR_ID_UNKNOWN; |
| 284 ParseModalias(object_path_, &vendor_id_source, NULL, NULL, NULL); | 286 ParseModalias(object_path_, &vendor_id_source, nullptr, nullptr, nullptr); |
| 285 return vendor_id_source; | 287 return vendor_id_source; |
| 286 } | 288 } |
| 287 | 289 |
| 288 uint16_t BluetoothDeviceBlueZ::GetVendorID() const { | 290 uint16_t BluetoothDeviceBlueZ::GetVendorID() const { |
| 289 uint16_t vendor_id = 0; | 291 uint16_t vendor_id = 0; |
| 290 ParseModalias(object_path_, NULL, &vendor_id, NULL, NULL); | 292 ParseModalias(object_path_, nullptr, &vendor_id, nullptr, nullptr); |
| 291 return vendor_id; | 293 return vendor_id; |
| 292 } | 294 } |
| 293 | 295 |
| 294 uint16_t BluetoothDeviceBlueZ::GetProductID() const { | 296 uint16_t BluetoothDeviceBlueZ::GetProductID() const { |
| 295 uint16_t product_id = 0; | 297 uint16_t product_id = 0; |
| 296 ParseModalias(object_path_, NULL, NULL, &product_id, NULL); | 298 ParseModalias(object_path_, nullptr, nullptr, &product_id, nullptr); |
| 297 return product_id; | 299 return product_id; |
| 298 } | 300 } |
| 299 | 301 |
| 300 uint16_t BluetoothDeviceBlueZ::GetDeviceID() const { | 302 uint16_t BluetoothDeviceBlueZ::GetDeviceID() const { |
| 301 uint16_t device_id = 0; | 303 uint16_t device_id = 0; |
| 302 ParseModalias(object_path_, NULL, NULL, NULL, &device_id); | 304 ParseModalias(object_path_, nullptr, nullptr, nullptr, &device_id); |
| 303 return device_id; | 305 return device_id; |
| 304 } | 306 } |
| 305 | 307 |
| 306 uint16_t BluetoothDeviceBlueZ::GetAppearance() const { | 308 uint16_t BluetoothDeviceBlueZ::GetAppearance() const { |
| 307 bluez::BluetoothDeviceClient::Properties* properties = | 309 bluez::BluetoothDeviceClient::Properties* properties = |
| 308 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 310 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 309 object_path_); | 311 object_path_); |
| 310 DCHECK(properties); | 312 DCHECK(properties); |
| 311 | 313 |
| 312 if (!properties->appearance.is_valid()) | 314 if (!properties->appearance.is_valid()) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 bool BluetoothDeviceBlueZ::IsGattConnected() const { | 354 bool BluetoothDeviceBlueZ::IsGattConnected() const { |
| 353 // Bluez uses the same attribute for GATT Connections and Classic BT | 355 // Bluez uses the same attribute for GATT Connections and Classic BT |
| 354 // Connections. | 356 // Connections. |
| 355 return IsConnected(); | 357 return IsConnected(); |
| 356 } | 358 } |
| 357 | 359 |
| 358 bool BluetoothDeviceBlueZ::IsConnectable() const { | 360 bool BluetoothDeviceBlueZ::IsConnectable() const { |
| 359 bluez::BluetoothInputClient::Properties* input_properties = | 361 bluez::BluetoothInputClient::Properties* input_properties = |
| 360 bluez::BluezDBusManager::Get()->GetBluetoothInputClient()->GetProperties( | 362 bluez::BluezDBusManager::Get()->GetBluetoothInputClient()->GetProperties( |
| 361 object_path_); | 363 object_path_); |
| 362 // GetProperties returns NULL when the device does not implement the given | 364 // GetProperties returns nullptr when the device does not implement the given |
| 363 // interface. Non HID devices are normally connectable. | 365 // interface. Non HID devices are normally connectable. |
| 364 if (!input_properties) | 366 if (!input_properties) |
| 365 return true; | 367 return true; |
| 366 | 368 |
| 367 return input_properties->reconnect_mode.value() != "device"; | 369 return input_properties->reconnect_mode.value() != "device"; |
| 368 } | 370 } |
| 369 | 371 |
| 370 bool BluetoothDeviceBlueZ::IsConnecting() const { | 372 bool BluetoothDeviceBlueZ::IsConnecting() const { |
| 371 return num_connecting_calls_ > 0; | 373 return num_connecting_calls_ > 0; |
| 372 } | 374 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 | 429 |
| 428 bool BluetoothDeviceBlueZ::ExpectingConfirmation() const { | 430 bool BluetoothDeviceBlueZ::ExpectingConfirmation() const { |
| 429 return pairing_.get() && pairing_->ExpectingConfirmation(); | 431 return pairing_.get() && pairing_->ExpectingConfirmation(); |
| 430 } | 432 } |
| 431 | 433 |
| 432 void BluetoothDeviceBlueZ::GetConnectionInfo( | 434 void BluetoothDeviceBlueZ::GetConnectionInfo( |
| 433 const ConnectionInfoCallback& callback) { | 435 const ConnectionInfoCallback& callback) { |
| 434 // DBus method call should gracefully return an error if the device is not | 436 // DBus method call should gracefully return an error if the device is not |
| 435 // currently connected. | 437 // currently connected. |
| 436 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetConnInfo( | 438 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetConnInfo( |
| 437 object_path_, base::Bind(&BluetoothDeviceBlueZ::OnGetConnInfo, | 439 object_path_, |
| 438 weak_ptr_factory_.GetWeakPtr(), callback), | 440 base::Bind(&BluetoothDeviceBlueZ::OnGetConnInfo, |
| 441 weak_ptr_factory_.GetWeakPtr(), callback), |
| 439 base::Bind(&BluetoothDeviceBlueZ::OnGetConnInfoError, | 442 base::Bind(&BluetoothDeviceBlueZ::OnGetConnInfoError, |
| 440 weak_ptr_factory_.GetWeakPtr(), callback)); | 443 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 441 } | 444 } |
| 442 | 445 |
| 443 void BluetoothDeviceBlueZ::Connect( | 446 void BluetoothDeviceBlueZ::Connect( |
| 444 BluetoothDevice::PairingDelegate* pairing_delegate, | 447 BluetoothDevice::PairingDelegate* pairing_delegate, |
| 445 const base::Closure& callback, | 448 const base::Closure& callback, |
| 446 const ConnectErrorCallback& error_callback) { | 449 const ConnectErrorCallback& error_callback) { |
| 447 if (num_connecting_calls_++ == 0) | 450 if (num_connecting_calls_++ == 0) |
| 448 adapter()->NotifyDeviceChanged(this); | 451 adapter()->NotifyDeviceChanged(this); |
| 449 | 452 |
| 450 VLOG(1) << object_path_.value() << ": Connecting, " << num_connecting_calls_ | 453 BLUETOOTH_LOG(EVENT) << object_path_.value() << ": Connecting, " |
| 451 << " in progress"; | 454 << num_connecting_calls_ << " in progress"; |
| 452 | 455 |
| 453 if (IsPaired() || !pairing_delegate) { | 456 if (IsPaired() || !pairing_delegate) { |
| 454 // No need to pair, or unable to, skip straight to connection. | 457 // No need to pair, or unable to, skip straight to connection. |
| 455 ConnectInternal(false, callback, error_callback); | 458 ConnectInternal(false, callback, error_callback); |
| 456 } else { | 459 } else { |
| 457 // Initiate high-security connection with pairing. | 460 // Initiate high-security connection with pairing. |
| 458 BeginPairing(pairing_delegate); | 461 BeginPairing(pairing_delegate); |
| 459 | 462 |
| 460 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->Pair( | 463 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->Pair( |
| 461 object_path_, | 464 object_path_, |
| 462 base::Bind(&BluetoothDeviceBlueZ::OnPairDuringConnect, | 465 base::Bind(&BluetoothDeviceBlueZ::OnPairDuringConnect, |
| 463 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), | 466 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), |
| 464 base::Bind(&BluetoothDeviceBlueZ::OnPairDuringConnectError, | 467 base::Bind(&BluetoothDeviceBlueZ::OnPairDuringConnectError, |
| 465 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 468 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 466 } | 469 } |
| 467 } | 470 } |
| 468 | 471 |
| 469 void BluetoothDeviceBlueZ::Pair( | 472 void BluetoothDeviceBlueZ::Pair( |
| 470 BluetoothDevice::PairingDelegate* pairing_delegate, | 473 BluetoothDevice::PairingDelegate* pairing_delegate, |
| 471 const base::Closure& callback, | 474 const base::Closure& callback, |
| 472 const ConnectErrorCallback& error_callback) { | 475 const ConnectErrorCallback& error_callback) { |
| 473 DCHECK(pairing_delegate); | 476 DCHECK(pairing_delegate); |
| 474 BeginPairing(pairing_delegate); | 477 BeginPairing(pairing_delegate); |
| 475 | 478 |
| 476 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->Pair( | 479 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->Pair( |
| 477 object_path_, base::Bind(&BluetoothDeviceBlueZ::OnPair, | 480 object_path_, |
| 478 weak_ptr_factory_.GetWeakPtr(), callback), | 481 base::Bind(&BluetoothDeviceBlueZ::OnPair, weak_ptr_factory_.GetWeakPtr(), |
| 482 callback), |
| 479 base::Bind(&BluetoothDeviceBlueZ::OnPairError, | 483 base::Bind(&BluetoothDeviceBlueZ::OnPairError, |
| 480 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 484 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 481 } | 485 } |
| 482 | 486 |
| 483 void BluetoothDeviceBlueZ::SetPinCode(const std::string& pincode) { | 487 void BluetoothDeviceBlueZ::SetPinCode(const std::string& pincode) { |
| 484 if (!pairing_.get()) | 488 if (!pairing_.get()) |
| 485 return; | 489 return; |
| 486 | 490 |
| 487 pairing_->SetPinCode(pincode); | 491 pairing_->SetPinCode(pincode); |
| 488 } | 492 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 504 void BluetoothDeviceBlueZ::RejectPairing() { | 508 void BluetoothDeviceBlueZ::RejectPairing() { |
| 505 if (!pairing_.get()) | 509 if (!pairing_.get()) |
| 506 return; | 510 return; |
| 507 | 511 |
| 508 pairing_->RejectPairing(); | 512 pairing_->RejectPairing(); |
| 509 } | 513 } |
| 510 | 514 |
| 511 void BluetoothDeviceBlueZ::CancelPairing() { | 515 void BluetoothDeviceBlueZ::CancelPairing() { |
| 512 bool canceled = false; | 516 bool canceled = false; |
| 513 | 517 |
| 518 BLUETOOTH_LOG(EVENT) << object_path_.value() << ": CancelPairing"; |
| 519 |
| 514 // If there is a callback in progress that we can reply to then use that | 520 // If there is a callback in progress that we can reply to then use that |
| 515 // to cancel the current pairing request. | 521 // to cancel the current pairing request. |
| 516 if (pairing_.get() && pairing_->CancelPairing()) | 522 if (pairing_.get() && pairing_->CancelPairing()) |
| 517 canceled = true; | 523 canceled = true; |
| 518 | 524 |
| 519 // If not we have to send an explicit CancelPairing() to the device instead. | 525 // If not we have to send an explicit CancelPairing() to the device instead. |
| 520 if (!canceled) { | 526 if (!canceled) { |
| 521 VLOG(1) << object_path_.value() << ": No pairing context or callback. " | 527 BLUETOOTH_LOG(DEBUG) << object_path_.value() |
| 522 << "Sending explicit cancel"; | 528 << ": No pairing context or callback. " |
| 529 << "Sending explicit cancel"; |
| 523 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->CancelPairing( | 530 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->CancelPairing( |
| 524 object_path_, base::Bind(&base::DoNothing), | 531 object_path_, base::Bind(&base::DoNothing), |
| 525 base::Bind(&BluetoothDeviceBlueZ::OnCancelPairingError, | 532 base::Bind(&BluetoothDeviceBlueZ::OnCancelPairingError, |
| 526 weak_ptr_factory_.GetWeakPtr())); | 533 weak_ptr_factory_.GetWeakPtr())); |
| 527 } | 534 } |
| 528 | 535 |
| 529 // Since there is no callback to this method it's possible that the pairing | 536 // Since there is no callback to this method it's possible that the pairing |
| 530 // delegate is going to be freed before things complete (indeed it's | 537 // delegate is going to be freed before things complete (indeed it's |
| 531 // documented that this is the method you should call while freeing the | 538 // documented that this is the method you should call while freeing the |
| 532 // pairing delegate), so clear our the context holding on to it. | 539 // pairing delegate), so clear our the context holding on to it. |
| 533 EndPairing(); | 540 EndPairing(); |
| 534 } | 541 } |
| 535 | 542 |
| 536 void BluetoothDeviceBlueZ::Disconnect(const base::Closure& callback, | 543 void BluetoothDeviceBlueZ::Disconnect(const base::Closure& callback, |
| 537 const ErrorCallback& error_callback) { | 544 const ErrorCallback& error_callback) { |
| 538 VLOG(1) << object_path_.value() << ": Disconnecting"; | 545 BLUETOOTH_LOG(EVENT) << object_path_.value() << ": Disconnecting"; |
| 539 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->Disconnect( | 546 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->Disconnect( |
| 540 object_path_, base::Bind(&BluetoothDeviceBlueZ::OnDisconnect, | 547 object_path_, |
| 541 weak_ptr_factory_.GetWeakPtr(), callback), | 548 base::Bind(&BluetoothDeviceBlueZ::OnDisconnect, |
| 549 weak_ptr_factory_.GetWeakPtr(), callback), |
| 542 base::Bind(&BluetoothDeviceBlueZ::OnDisconnectError, | 550 base::Bind(&BluetoothDeviceBlueZ::OnDisconnectError, |
| 543 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 551 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 544 } | 552 } |
| 545 | 553 |
| 546 void BluetoothDeviceBlueZ::Forget(const base::Closure& callback, | 554 void BluetoothDeviceBlueZ::Forget(const base::Closure& callback, |
| 547 const ErrorCallback& error_callback) { | 555 const ErrorCallback& error_callback) { |
| 548 VLOG(1) << object_path_.value() << ": Removing device"; | 556 BLUETOOTH_LOG(EVENT) << object_path_.value() << ": Removing device"; |
| 549 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->RemoveDevice( | 557 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->RemoveDevice( |
| 550 adapter()->object_path(), object_path_, callback, | 558 adapter()->object_path(), object_path_, callback, |
| 551 base::Bind(&BluetoothDeviceBlueZ::OnForgetError, | 559 base::Bind(&BluetoothDeviceBlueZ::OnForgetError, |
| 552 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 560 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 553 } | 561 } |
| 554 | 562 |
| 555 void BluetoothDeviceBlueZ::ConnectToService( | 563 void BluetoothDeviceBlueZ::ConnectToService( |
| 556 const BluetoothUUID& uuid, | 564 const BluetoothUUID& uuid, |
| 557 const ConnectToServiceCallback& callback, | 565 const ConnectToServiceCallback& callback, |
| 558 const ConnectToServiceErrorCallback& error_callback) { | 566 const ConnectToServiceErrorCallback& error_callback) { |
| 559 VLOG(1) << object_path_.value() | 567 BLUETOOTH_LOG(EVENT) << object_path_.value() |
| 560 << ": Connecting to service: " << uuid.canonical_value(); | 568 << ": Connecting to service: " << uuid.canonical_value(); |
| 561 scoped_refptr<BluetoothSocketBlueZ> socket = | 569 scoped_refptr<BluetoothSocketBlueZ> socket = |
| 562 BluetoothSocketBlueZ::CreateBluetoothSocket(ui_task_runner_, | 570 BluetoothSocketBlueZ::CreateBluetoothSocket(ui_task_runner_, |
| 563 socket_thread_); | 571 socket_thread_); |
| 564 socket->Connect(this, uuid, BluetoothSocketBlueZ::SECURITY_LEVEL_MEDIUM, | 572 socket->Connect(this, uuid, BluetoothSocketBlueZ::SECURITY_LEVEL_MEDIUM, |
| 565 base::Bind(callback, socket), error_callback); | 573 base::Bind(callback, socket), error_callback); |
| 566 } | 574 } |
| 567 | 575 |
| 568 void BluetoothDeviceBlueZ::ConnectToServiceInsecurely( | 576 void BluetoothDeviceBlueZ::ConnectToServiceInsecurely( |
| 569 const BluetoothUUID& uuid, | 577 const BluetoothUUID& uuid, |
| 570 const ConnectToServiceCallback& callback, | 578 const ConnectToServiceCallback& callback, |
| 571 const ConnectToServiceErrorCallback& error_callback) { | 579 const ConnectToServiceErrorCallback& error_callback) { |
| 572 VLOG(1) << object_path_.value() | 580 BLUETOOTH_LOG(EVENT) << object_path_.value() |
| 573 << ": Connecting insecurely to service: " << uuid.canonical_value(); | 581 << ": Connecting insecurely to service: " |
| 582 << uuid.canonical_value(); |
| 574 scoped_refptr<BluetoothSocketBlueZ> socket = | 583 scoped_refptr<BluetoothSocketBlueZ> socket = |
| 575 BluetoothSocketBlueZ::CreateBluetoothSocket(ui_task_runner_, | 584 BluetoothSocketBlueZ::CreateBluetoothSocket(ui_task_runner_, |
| 576 socket_thread_); | 585 socket_thread_); |
| 577 socket->Connect(this, uuid, BluetoothSocketBlueZ::SECURITY_LEVEL_LOW, | 586 socket->Connect(this, uuid, BluetoothSocketBlueZ::SECURITY_LEVEL_LOW, |
| 578 base::Bind(callback, socket), error_callback); | 587 base::Bind(callback, socket), error_callback); |
| 579 } | 588 } |
| 580 | 589 |
| 581 void BluetoothDeviceBlueZ::CreateGattConnection( | 590 void BluetoothDeviceBlueZ::CreateGattConnection( |
| 582 const GattConnectionCallback& callback, | 591 const GattConnectionCallback& callback, |
| 583 const ConnectErrorCallback& error_callback) { | 592 const ConnectErrorCallback& error_callback) { |
| 584 // TODO(sacomoto): Workaround to retrieve the connection for already connected | 593 // TODO(sacomoto): Workaround to retrieve the connection for already connected |
| 585 // devices. Currently, BluetoothGattConnection::Disconnect doesn't do | 594 // devices. Currently, BluetoothGattConnection::Disconnect doesn't do |
| 586 // anything, the unique underlying physical GATT connection is kept. This | 595 // anything, the unique underlying physical GATT connection is kept. This |
| 587 // should be removed once the correct behavour is implemented and the GATT | 596 // should be removed once the correct behavour is implemented and the GATT |
| 588 // connections are reference counted (see todo below). | 597 // connections are reference counted (see todo below). |
| 589 if (IsConnected()) { | 598 if (IsConnected()) { |
| 590 OnCreateGattConnection(callback); | 599 OnCreateGattConnection(callback); |
| 591 return; | 600 return; |
| 592 } | 601 } |
| 593 | 602 |
| 594 // TODO(crbug.com/630586): Until there is a way to create a reference counted | 603 // TODO(crbug.com/630586): Until there is a way to create a reference counted |
| 595 // GATT connection in bluetoothd, simply do a regular connect. | 604 // GATT connection in bluetoothd, simply do a regular connect. |
| 596 Connect(NULL, base::Bind(&BluetoothDeviceBlueZ::OnCreateGattConnection, | 605 Connect(nullptr, |
| 597 weak_ptr_factory_.GetWeakPtr(), callback), | 606 base::Bind(&BluetoothDeviceBlueZ::OnCreateGattConnection, |
| 607 weak_ptr_factory_.GetWeakPtr(), callback), |
| 598 error_callback); | 608 error_callback); |
| 599 } | 609 } |
| 600 | 610 |
| 601 void BluetoothDeviceBlueZ::GetServiceRecords( | 611 void BluetoothDeviceBlueZ::GetServiceRecords( |
| 602 const GetServiceRecordsCallback& callback, | 612 const GetServiceRecordsCallback& callback, |
| 603 const GetServiceRecordsErrorCallback& error_callback) { | 613 const GetServiceRecordsErrorCallback& error_callback) { |
| 604 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetServiceRecords( | 614 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetServiceRecords( |
| 605 object_path_, callback, | 615 object_path_, callback, |
| 606 base::Bind(&BluetoothDeviceBlueZ::OnGetServiceRecordsError, | 616 base::Bind(&BluetoothDeviceBlueZ::OnGetServiceRecordsError, |
| 607 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 617 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 return pairing_.get(); | 670 return pairing_.get(); |
| 661 } | 671 } |
| 662 | 672 |
| 663 BluetoothAdapterBlueZ* BluetoothDeviceBlueZ::adapter() const { | 673 BluetoothAdapterBlueZ* BluetoothDeviceBlueZ::adapter() const { |
| 664 return static_cast<BluetoothAdapterBlueZ*>(adapter_); | 674 return static_cast<BluetoothAdapterBlueZ*>(adapter_); |
| 665 } | 675 } |
| 666 | 676 |
| 667 void BluetoothDeviceBlueZ::GattServiceAdded( | 677 void BluetoothDeviceBlueZ::GattServiceAdded( |
| 668 const dbus::ObjectPath& object_path) { | 678 const dbus::ObjectPath& object_path) { |
| 669 if (GetGattService(object_path.value())) { | 679 if (GetGattService(object_path.value())) { |
| 670 VLOG(1) << "Remote GATT service already exists: " << object_path.value(); | 680 BLUETOOTH_LOG(DEBUG) << "Remote GATT service already exists: " |
| 681 << object_path.value(); |
| 671 return; | 682 return; |
| 672 } | 683 } |
| 673 | 684 |
| 674 bluez::BluetoothGattServiceClient::Properties* properties = | 685 bluez::BluetoothGattServiceClient::Properties* properties = |
| 675 bluez::BluezDBusManager::Get() | 686 bluez::BluezDBusManager::Get() |
| 676 ->GetBluetoothGattServiceClient() | 687 ->GetBluetoothGattServiceClient() |
| 677 ->GetProperties(object_path); | 688 ->GetProperties(object_path); |
| 678 DCHECK(properties); | 689 DCHECK(properties); |
| 679 if (properties->device.value() != object_path_) { | 690 if (properties->device.value() != object_path_) { |
| 680 VLOG(2) << "Remote GATT service does not belong to this device."; | 691 BLUETOOTH_LOG(DEBUG) |
| 692 << "Remote GATT service does not belong to this device."; |
| 681 return; | 693 return; |
| 682 } | 694 } |
| 683 | 695 |
| 684 VLOG(1) << "Adding new remote GATT service for device: " << GetAddress(); | 696 BLUETOOTH_LOG(EVENT) << "Adding new remote GATT service for device: " |
| 697 << GetAddress(); |
| 685 | 698 |
| 686 BluetoothRemoteGattServiceBlueZ* service = | 699 BluetoothRemoteGattServiceBlueZ* service = |
| 687 new BluetoothRemoteGattServiceBlueZ(adapter(), this, object_path); | 700 new BluetoothRemoteGattServiceBlueZ(adapter(), this, object_path); |
| 688 | 701 |
| 689 gatt_services_[service->GetIdentifier()] = base::WrapUnique(service); | 702 gatt_services_[service->GetIdentifier()] = base::WrapUnique(service); |
| 690 DCHECK(service->object_path() == object_path); | 703 DCHECK(service->object_path() == object_path); |
| 691 DCHECK(service->GetUUID().IsValid()); | 704 DCHECK(service->GetUUID().IsValid()); |
| 692 | 705 |
| 693 DCHECK(adapter()); | 706 DCHECK(adapter()); |
| 694 adapter()->NotifyGattServiceAdded(service); | 707 adapter()->NotifyGattServiceAdded(service); |
| 695 } | 708 } |
| 696 | 709 |
| 697 void BluetoothDeviceBlueZ::GattServiceRemoved( | 710 void BluetoothDeviceBlueZ::GattServiceRemoved( |
| 698 const dbus::ObjectPath& object_path) { | 711 const dbus::ObjectPath& object_path) { |
| 699 auto iter = gatt_services_.find(object_path.value()); | 712 auto iter = gatt_services_.find(object_path.value()); |
| 700 if (iter == gatt_services_.end()) { | 713 if (iter == gatt_services_.end()) { |
| 701 VLOG(3) << "Unknown GATT service removed: " << object_path.value(); | 714 VLOG(3) << "Unknown GATT service removed: " << object_path.value(); |
| 702 return; | 715 return; |
| 703 } | 716 } |
| 704 | 717 |
| 705 BluetoothRemoteGattServiceBlueZ* service = | 718 BluetoothRemoteGattServiceBlueZ* service = |
| 706 static_cast<BluetoothRemoteGattServiceBlueZ*>(iter->second.get()); | 719 static_cast<BluetoothRemoteGattServiceBlueZ*>(iter->second.get()); |
| 707 | 720 |
| 708 VLOG(1) << "Removing remote GATT service with UUID: '" | 721 BLUETOOTH_LOG(EVENT) << "Removing remote GATT service with UUID: '" |
| 709 << service->GetUUID().canonical_value() | 722 << service->GetUUID().canonical_value() |
| 710 << "' from device: " << GetAddress(); | 723 << "' from device: " << GetAddress(); |
| 711 | 724 |
| 712 DCHECK(service->object_path() == object_path); | 725 DCHECK(service->object_path() == object_path); |
| 713 std::unique_ptr<BluetoothRemoteGattService> scoped_service = | 726 std::unique_ptr<BluetoothRemoteGattService> scoped_service = |
| 714 std::move(gatt_services_[object_path.value()]); | 727 std::move(gatt_services_[object_path.value()]); |
| 715 gatt_services_.erase(iter); | 728 gatt_services_.erase(iter); |
| 716 | 729 |
| 717 DCHECK(adapter()); | 730 DCHECK(adapter()); |
| 718 discovery_complete_notified_.erase(service); | 731 discovery_complete_notified_.erase(service); |
| 719 adapter()->NotifyGattServiceRemoved(service); | 732 adapter()->NotifyGattServiceRemoved(service); |
| 720 } | 733 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 int16_t rssi, | 771 int16_t rssi, |
| 759 int16_t transmit_power, | 772 int16_t transmit_power, |
| 760 int16_t max_transmit_power) { | 773 int16_t max_transmit_power) { |
| 761 callback.Run(ConnectionInfo(rssi, transmit_power, max_transmit_power)); | 774 callback.Run(ConnectionInfo(rssi, transmit_power, max_transmit_power)); |
| 762 } | 775 } |
| 763 | 776 |
| 764 void BluetoothDeviceBlueZ::OnGetConnInfoError( | 777 void BluetoothDeviceBlueZ::OnGetConnInfoError( |
| 765 const ConnectionInfoCallback& callback, | 778 const ConnectionInfoCallback& callback, |
| 766 const std::string& error_name, | 779 const std::string& error_name, |
| 767 const std::string& error_message) { | 780 const std::string& error_message) { |
| 768 LOG(WARNING) << object_path_.value() | 781 BLUETOOTH_LOG(ERROR) << object_path_.value() |
| 769 << ": Failed to get connection info: " << error_name << ": " | 782 << ": Failed to get connection info: " << error_name |
| 770 << error_message; | 783 << ": " << error_message; |
| 771 callback.Run(ConnectionInfo()); | 784 callback.Run(ConnectionInfo()); |
| 772 } | 785 } |
| 773 | 786 |
| 774 void BluetoothDeviceBlueZ::OnGetServiceRecordsError( | 787 void BluetoothDeviceBlueZ::OnGetServiceRecordsError( |
| 775 const GetServiceRecordsErrorCallback& error_callback, | 788 const GetServiceRecordsErrorCallback& error_callback, |
| 776 const std::string& error_name, | 789 const std::string& error_name, |
| 777 const std::string& error_message) { | 790 const std::string& error_message) { |
| 778 VLOG(1) << object_path_.value() | 791 BLUETOOTH_LOG(EVENT) << object_path_.value() |
| 779 << ": Failed to get service records: " << error_name << ": " | 792 << ": Failed to get service records: " << error_name |
| 780 << error_message; | 793 << ": " << error_message; |
| 781 BluetoothServiceRecordBlueZ::ErrorCode code = | 794 BluetoothServiceRecordBlueZ::ErrorCode code = |
| 782 BluetoothServiceRecordBlueZ::ErrorCode::UNKNOWN; | 795 BluetoothServiceRecordBlueZ::ErrorCode::UNKNOWN; |
| 783 if (error_name == bluetooth_device::kErrorNotConnected) { | 796 if (error_name == bluetooth_device::kErrorNotConnected) { |
| 784 code = BluetoothServiceRecordBlueZ::ErrorCode::ERROR_DEVICE_DISCONNECTED; | 797 code = BluetoothServiceRecordBlueZ::ErrorCode::ERROR_DEVICE_DISCONNECTED; |
| 785 } | 798 } |
| 786 error_callback.Run(code); | 799 error_callback.Run(code); |
| 787 } | 800 } |
| 788 | 801 |
| 789 void BluetoothDeviceBlueZ::ConnectInternal( | 802 void BluetoothDeviceBlueZ::ConnectInternal( |
| 790 bool after_pairing, | 803 bool after_pairing, |
| 791 const base::Closure& callback, | 804 const base::Closure& callback, |
| 792 const ConnectErrorCallback& error_callback) { | 805 const ConnectErrorCallback& error_callback) { |
| 793 VLOG(1) << object_path_.value() << ": Connecting"; | 806 BLUETOOTH_LOG(EVENT) << object_path_.value() << ": Connecting"; |
| 794 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->Connect( | 807 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->Connect( |
| 795 object_path_, | 808 object_path_, |
| 796 base::Bind(&BluetoothDeviceBlueZ::OnConnect, | 809 base::Bind(&BluetoothDeviceBlueZ::OnConnect, |
| 797 weak_ptr_factory_.GetWeakPtr(), after_pairing, callback), | 810 weak_ptr_factory_.GetWeakPtr(), after_pairing, callback), |
| 798 base::Bind(&BluetoothDeviceBlueZ::OnConnectError, | 811 base::Bind(&BluetoothDeviceBlueZ::OnConnectError, |
| 799 weak_ptr_factory_.GetWeakPtr(), after_pairing, | 812 weak_ptr_factory_.GetWeakPtr(), after_pairing, |
| 800 error_callback)); | 813 error_callback)); |
| 801 } | 814 } |
| 802 | 815 |
| 803 void BluetoothDeviceBlueZ::OnConnect(bool after_pairing, | 816 void BluetoothDeviceBlueZ::OnConnect(bool after_pairing, |
| 804 const base::Closure& callback) { | 817 const base::Closure& callback) { |
| 805 if (--num_connecting_calls_ == 0) | 818 if (--num_connecting_calls_ == 0) |
| 806 adapter()->NotifyDeviceChanged(this); | 819 adapter()->NotifyDeviceChanged(this); |
| 807 | 820 |
| 808 DCHECK(num_connecting_calls_ >= 0); | 821 DCHECK(num_connecting_calls_ >= 0); |
| 809 VLOG(1) << object_path_.value() << ": Connected, " << num_connecting_calls_ | 822 BLUETOOTH_LOG(EVENT) << object_path_.value() << ": Connected, " |
| 810 << " still in progress"; | 823 << num_connecting_calls_ << " still in progress"; |
| 811 | 824 |
| 812 SetTrusted(); | 825 SetTrusted(); |
| 813 | 826 |
| 814 if (after_pairing) | 827 if (after_pairing) |
| 815 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingResult", | 828 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingResult", |
| 816 UMA_PAIRING_RESULT_SUCCESS, | 829 UMA_PAIRING_RESULT_SUCCESS, |
| 817 UMA_PAIRING_RESULT_COUNT); | 830 UMA_PAIRING_RESULT_COUNT); |
| 818 | 831 |
| 819 callback.Run(); | 832 callback.Run(); |
| 820 } | 833 } |
| 821 | 834 |
| 822 void BluetoothDeviceBlueZ::OnCreateGattConnection( | 835 void BluetoothDeviceBlueZ::OnCreateGattConnection( |
| 823 const GattConnectionCallback& callback) { | 836 const GattConnectionCallback& callback) { |
| 824 std::unique_ptr<device::BluetoothGattConnection> conn( | 837 std::unique_ptr<device::BluetoothGattConnection> conn( |
| 825 new BluetoothGattConnectionBlueZ(adapter_, GetAddress(), object_path_)); | 838 new BluetoothGattConnectionBlueZ(adapter_, GetAddress(), object_path_)); |
| 826 callback.Run(std::move(conn)); | 839 callback.Run(std::move(conn)); |
| 827 } | 840 } |
| 828 | 841 |
| 829 void BluetoothDeviceBlueZ::OnConnectError( | 842 void BluetoothDeviceBlueZ::OnConnectError( |
| 830 bool after_pairing, | 843 bool after_pairing, |
| 831 const ConnectErrorCallback& error_callback, | 844 const ConnectErrorCallback& error_callback, |
| 832 const std::string& error_name, | 845 const std::string& error_name, |
| 833 const std::string& error_message) { | 846 const std::string& error_message) { |
| 834 if (--num_connecting_calls_ == 0) | 847 if (--num_connecting_calls_ == 0) |
| 835 adapter()->NotifyDeviceChanged(this); | 848 adapter()->NotifyDeviceChanged(this); |
| 836 | 849 |
| 837 DCHECK(num_connecting_calls_ >= 0); | 850 DCHECK(num_connecting_calls_ >= 0); |
| 838 LOG(WARNING) << object_path_.value() | 851 BLUETOOTH_LOG(ERROR) << object_path_.value() |
| 839 << ": Failed to connect device: " << error_name << ": " | 852 << ": Failed to connect device: " << error_name << ": " |
| 840 << error_message; | 853 << error_message; |
| 841 VLOG(1) << object_path_.value() << ": " << num_connecting_calls_ | 854 BLUETOOTH_LOG(DEBUG) << object_path_.value() << ": " << num_connecting_calls_ |
| 842 << " still in progress"; | 855 << " still in progress"; |
| 843 | 856 |
| 844 // Determine the error code from error_name. | 857 // Determine the error code from error_name. |
| 845 ConnectErrorCode error_code = ERROR_UNKNOWN; | 858 ConnectErrorCode error_code = ERROR_UNKNOWN; |
| 846 if (error_name == bluetooth_device::kErrorFailed) { | 859 if (error_name == bluetooth_device::kErrorFailed) { |
| 847 error_code = ERROR_FAILED; | 860 error_code = ERROR_FAILED; |
| 848 } else if (error_name == bluetooth_device::kErrorInProgress) { | 861 } else if (error_name == bluetooth_device::kErrorInProgress) { |
| 849 error_code = ERROR_INPROGRESS; | 862 error_code = ERROR_INPROGRESS; |
| 850 } else if (error_name == bluetooth_device::kErrorNotSupported) { | 863 } else if (error_name == bluetooth_device::kErrorNotSupported) { |
| 851 error_code = ERROR_UNSUPPORTED_DEVICE; | 864 error_code = ERROR_UNSUPPORTED_DEVICE; |
| 852 } | 865 } |
| 853 | 866 |
| 854 if (after_pairing) | 867 if (after_pairing) |
| 855 RecordPairingResult(error_code); | 868 RecordPairingResult(error_code); |
| 856 error_callback.Run(error_code); | 869 error_callback.Run(error_code); |
| 857 } | 870 } |
| 858 | 871 |
| 859 void BluetoothDeviceBlueZ::OnPairDuringConnect( | 872 void BluetoothDeviceBlueZ::OnPairDuringConnect( |
| 860 const base::Closure& callback, | 873 const base::Closure& callback, |
| 861 const ConnectErrorCallback& error_callback) { | 874 const ConnectErrorCallback& error_callback) { |
| 862 VLOG(1) << object_path_.value() << ": Paired"; | 875 BLUETOOTH_LOG(EVENT) << object_path_.value() << ": Paired"; |
| 863 | 876 |
| 864 EndPairing(); | 877 EndPairing(); |
| 865 | 878 |
| 866 ConnectInternal(true, callback, error_callback); | 879 ConnectInternal(true, callback, error_callback); |
| 867 } | 880 } |
| 868 | 881 |
| 869 void BluetoothDeviceBlueZ::OnPairDuringConnectError( | 882 void BluetoothDeviceBlueZ::OnPairDuringConnectError( |
| 870 const ConnectErrorCallback& error_callback, | 883 const ConnectErrorCallback& error_callback, |
| 871 const std::string& error_name, | 884 const std::string& error_name, |
| 872 const std::string& error_message) { | 885 const std::string& error_message) { |
| 873 if (--num_connecting_calls_ == 0) | 886 if (--num_connecting_calls_ == 0) |
| 874 adapter()->NotifyDeviceChanged(this); | 887 adapter()->NotifyDeviceChanged(this); |
| 875 | 888 |
| 876 DCHECK(num_connecting_calls_ >= 0); | 889 DCHECK(num_connecting_calls_ >= 0); |
| 877 LOG(WARNING) << object_path_.value() | 890 BLUETOOTH_LOG(ERROR) << object_path_.value() |
| 878 << ": Failed to pair device: " << error_name << ": " | 891 << ": Failed to pair device: " << error_name << ": " |
| 879 << error_message; | 892 << error_message; |
| 880 VLOG(1) << object_path_.value() << ": " << num_connecting_calls_ | 893 BLUETOOTH_LOG(DEBUG) << object_path_.value() << ": " << num_connecting_calls_ |
| 881 << " still in progress"; | 894 << " still in progress"; |
| 882 | 895 |
| 883 EndPairing(); | 896 EndPairing(); |
| 884 | 897 |
| 885 // Determine the error code from error_name. | 898 // Determine the error code from error_name. |
| 886 ConnectErrorCode error_code = DBusErrorToConnectError(error_name); | 899 ConnectErrorCode error_code = DBusErrorToConnectError(error_name); |
| 887 | 900 |
| 888 RecordPairingResult(error_code); | 901 RecordPairingResult(error_code); |
| 889 error_callback.Run(error_code); | 902 error_callback.Run(error_code); |
| 890 } | 903 } |
| 891 | 904 |
| 892 void BluetoothDeviceBlueZ::OnPair(const base::Closure& callback) { | 905 void BluetoothDeviceBlueZ::OnPair(const base::Closure& callback) { |
| 893 VLOG(1) << object_path_.value() << ": Paired"; | 906 BLUETOOTH_LOG(EVENT) << object_path_.value() << ": Paired"; |
| 894 EndPairing(); | 907 EndPairing(); |
| 895 callback.Run(); | 908 callback.Run(); |
| 896 } | 909 } |
| 897 | 910 |
| 898 void BluetoothDeviceBlueZ::OnPairError( | 911 void BluetoothDeviceBlueZ::OnPairError( |
| 899 const ConnectErrorCallback& error_callback, | 912 const ConnectErrorCallback& error_callback, |
| 900 const std::string& error_name, | 913 const std::string& error_name, |
| 901 const std::string& error_message) { | 914 const std::string& error_message) { |
| 902 LOG(WARNING) << object_path_.value() | 915 BLUETOOTH_LOG(ERROR) << object_path_.value() |
| 903 << ": Failed to pair device: " << error_name << ": " | 916 << ": Failed to pair device: " << error_name << ": " |
| 904 << error_message; | 917 << error_message; |
| 905 EndPairing(); | 918 EndPairing(); |
| 906 ConnectErrorCode error_code = DBusErrorToConnectError(error_name); | 919 ConnectErrorCode error_code = DBusErrorToConnectError(error_name); |
| 907 RecordPairingResult(error_code); | 920 RecordPairingResult(error_code); |
| 908 error_callback.Run(error_code); | 921 error_callback.Run(error_code); |
| 909 } | 922 } |
| 910 | 923 |
| 911 void BluetoothDeviceBlueZ::OnCancelPairingError( | 924 void BluetoothDeviceBlueZ::OnCancelPairingError( |
| 912 const std::string& error_name, | 925 const std::string& error_name, |
| 913 const std::string& error_message) { | 926 const std::string& error_message) { |
| 914 LOG(WARNING) << object_path_.value() | 927 BLUETOOTH_LOG(ERROR) << object_path_.value() |
| 915 << ": Failed to cancel pairing: " << error_name << ": " | 928 << ": Failed to cancel pairing: " << error_name << ": " |
| 916 << error_message; | 929 << error_message; |
| 917 } | 930 } |
| 918 | 931 |
| 919 void BluetoothDeviceBlueZ::SetTrusted() { | 932 void BluetoothDeviceBlueZ::SetTrusted() { |
| 920 // Unconditionally send the property change, rather than checking the value | 933 // Unconditionally send the property change, rather than checking the value |
| 921 // first; there's no harm in doing this and it solves any race conditions | 934 // first; there's no harm in doing this and it solves any race conditions |
| 922 // with the property becoming true or false and this call happening before | 935 // with the property becoming true or false and this call happening before |
| 923 // we get the D-Bus signal about the earlier change. | 936 // we get the D-Bus signal about the earlier change. |
| 924 bluez::BluezDBusManager::Get() | 937 bluez::BluezDBusManager::Get() |
| 925 ->GetBluetoothDeviceClient() | 938 ->GetBluetoothDeviceClient() |
| 926 ->GetProperties(object_path_) | 939 ->GetProperties(object_path_) |
| 927 ->trusted.Set(true, base::Bind(&BluetoothDeviceBlueZ::OnSetTrusted, | 940 ->trusted.Set(true, base::Bind(&BluetoothDeviceBlueZ::OnSetTrusted, |
| 928 weak_ptr_factory_.GetWeakPtr())); | 941 weak_ptr_factory_.GetWeakPtr())); |
| 929 } | 942 } |
| 930 | 943 |
| 931 void BluetoothDeviceBlueZ::OnSetTrusted(bool success) { | 944 void BluetoothDeviceBlueZ::OnSetTrusted(bool success) { |
| 932 LOG_IF(WARNING, !success) << object_path_.value() | 945 device_event_log::LogLevel log_level = |
| 933 << ": Failed to set device as trusted"; | 946 success ? device_event_log::LOG_LEVEL_DEBUG |
| 947 : device_event_log::LOG_LEVEL_ERROR; |
| 948 DEVICE_LOG(device_event_log::LOG_TYPE_BLUETOOTH, log_level) |
| 949 << object_path_.value() << ": OnSetTrusted: " << success; |
| 934 } | 950 } |
| 935 | 951 |
| 936 void BluetoothDeviceBlueZ::OnDisconnect(const base::Closure& callback) { | 952 void BluetoothDeviceBlueZ::OnDisconnect(const base::Closure& callback) { |
| 937 VLOG(1) << object_path_.value() << ": Disconnected"; | 953 BLUETOOTH_LOG(EVENT) << object_path_.value() << ": Disconnected"; |
| 938 // Do not notify about changed device since this is already done by | 954 // Do not notify about changed device since this is already done by |
| 939 // the dbus::PropertySet and the property change callback for BlueZ. | 955 // the dbus::PropertySet and the property change callback for BlueZ. |
| 940 DidDisconnectGatt(false /* notifyDeviceChanged */); | 956 DidDisconnectGatt(false /* notifyDeviceChanged */); |
| 941 callback.Run(); | 957 callback.Run(); |
| 942 } | 958 } |
| 943 | 959 |
| 944 void BluetoothDeviceBlueZ::OnDisconnectError( | 960 void BluetoothDeviceBlueZ::OnDisconnectError( |
| 945 const ErrorCallback& error_callback, | 961 const ErrorCallback& error_callback, |
| 946 const std::string& error_name, | 962 const std::string& error_name, |
| 947 const std::string& error_message) { | 963 const std::string& error_message) { |
| 948 LOG(WARNING) << object_path_.value() | 964 BLUETOOTH_LOG(ERROR) << object_path_.value() |
| 949 << ": Failed to disconnect device: " << error_name << ": " | 965 << ": Failed to disconnect device: " << error_name |
| 950 << error_message; | 966 << ": " << error_message; |
| 951 error_callback.Run(); | 967 error_callback.Run(); |
| 952 } | 968 } |
| 953 | 969 |
| 954 void BluetoothDeviceBlueZ::OnForgetError(const ErrorCallback& error_callback, | 970 void BluetoothDeviceBlueZ::OnForgetError(const ErrorCallback& error_callback, |
| 955 const std::string& error_name, | 971 const std::string& error_name, |
| 956 const std::string& error_message) { | 972 const std::string& error_message) { |
| 957 LOG(WARNING) << object_path_.value() | 973 BLUETOOTH_LOG(ERROR) << object_path_.value() |
| 958 << ": Failed to remove device: " << error_name << ": " | 974 << ": Failed to remove device: " << error_name << ": " |
| 959 << error_message; | 975 << error_message; |
| 960 error_callback.Run(); | 976 error_callback.Run(); |
| 961 } | 977 } |
| 962 | 978 |
| 963 } // namespace bluez | 979 } // namespace bluez |
| OLD | NEW |