| 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 <memory> | 10 #include <memory> |
| 10 #include <utility> | 11 #include <utility> |
| 11 | 12 |
| 12 #include "base/bind.h" | 13 #include "base/bind.h" |
| 13 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 16 #include "dbus/bus.h" | 17 #include "dbus/bus.h" |
| 17 #include "device/bluetooth/bluetooth_socket.h" | 18 #include "device/bluetooth/bluetooth_socket.h" |
| 18 #include "device/bluetooth/bluetooth_socket_thread.h" | 19 #include "device/bluetooth/bluetooth_socket_thread.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 if (vendor_id_source != NULL) | 81 if (vendor_id_source != NULL) |
| 81 *vendor_id_source = source_value; | 82 *vendor_id_source = source_value; |
| 82 if (vendor_id != NULL) | 83 if (vendor_id != NULL) |
| 83 *vendor_id = vendor_value; | 84 *vendor_id = vendor_value; |
| 84 if (product_id != NULL) | 85 if (product_id != NULL) |
| 85 *product_id = product_value; | 86 *product_id = product_value; |
| 86 if (device_id != NULL) | 87 if (device_id != NULL) |
| 87 *device_id = device_value; | 88 *device_id = device_value; |
| 88 } | 89 } |
| 89 | 90 |
| 91 int8_t ClampPower(int16_t power) { |
| 92 if (power < INT8_MIN) { |
| 93 return INT8_MIN; |
| 94 } |
| 95 if (power > INT8_MAX) { |
| 96 return INT8_MAX; |
| 97 } |
| 98 return static_cast<int8_t>(power); |
| 99 } |
| 100 |
| 90 void RecordPairingResult(BluetoothDevice::ConnectErrorCode error_code) { | 101 void RecordPairingResult(BluetoothDevice::ConnectErrorCode error_code) { |
| 91 UMAPairingResult pairing_result; | 102 UMAPairingResult pairing_result; |
| 92 switch (error_code) { | 103 switch (error_code) { |
| 93 case BluetoothDevice::ERROR_INPROGRESS: | 104 case BluetoothDevice::ERROR_INPROGRESS: |
| 94 pairing_result = UMA_PAIRING_RESULT_INPROGRESS; | 105 pairing_result = UMA_PAIRING_RESULT_INPROGRESS; |
| 95 break; | 106 break; |
| 96 case BluetoothDevice::ERROR_FAILED: | 107 case BluetoothDevice::ERROR_FAILED: |
| 97 pairing_result = UMA_PAIRING_RESULT_FAILED; | 108 pairing_result = UMA_PAIRING_RESULT_FAILED; |
| 98 break; | 109 break; |
| 99 case BluetoothDevice::ERROR_AUTH_FAILED: | 110 case BluetoothDevice::ERROR_AUTH_FAILED: |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 const std::vector<std::string>& dbus_uuids = properties->uuids.value(); | 357 const std::vector<std::string>& dbus_uuids = properties->uuids.value(); |
| 347 for (std::vector<std::string>::const_iterator iter = dbus_uuids.begin(); | 358 for (std::vector<std::string>::const_iterator iter = dbus_uuids.begin(); |
| 348 iter != dbus_uuids.end(); ++iter) { | 359 iter != dbus_uuids.end(); ++iter) { |
| 349 device::BluetoothUUID uuid(*iter); | 360 device::BluetoothUUID uuid(*iter); |
| 350 DCHECK(uuid.IsValid()); | 361 DCHECK(uuid.IsValid()); |
| 351 uuids.push_back(uuid); | 362 uuids.push_back(uuid); |
| 352 } | 363 } |
| 353 return uuids; | 364 return uuids; |
| 354 } | 365 } |
| 355 | 366 |
| 356 int16_t BluetoothDeviceBlueZ::GetInquiryRSSI() const { | 367 base::Optional<int8_t> BluetoothDeviceBlueZ::GetInquiryRSSI() const { |
| 357 bluez::BluetoothDeviceClient::Properties* properties = | 368 bluez::BluetoothDeviceClient::Properties* properties = |
| 358 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 369 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 359 object_path_); | 370 object_path_); |
| 360 DCHECK(properties); | 371 DCHECK(properties); |
| 361 | 372 |
| 362 if (!properties->rssi.is_valid()) | 373 if (!properties->rssi.is_valid()) |
| 363 return kUnknownPower; | 374 return base::nullopt; |
| 364 | 375 |
| 365 return properties->rssi.value(); | 376 // BlueZ uses int16_t because there is no int8_t for DBus, so we should never |
| 377 // get an int16_t that cannot be represented by an int8_t. But just in case |
| 378 // clamp the value. |
| 379 return ClampPower(properties->rssi.value()); |
| 366 } | 380 } |
| 367 | 381 |
| 368 int16_t BluetoothDeviceBlueZ::GetInquiryTxPower() const { | 382 base::Optional<int8_t> BluetoothDeviceBlueZ::GetInquiryTxPower() const { |
| 369 bluez::BluetoothDeviceClient::Properties* properties = | 383 bluez::BluetoothDeviceClient::Properties* properties = |
| 370 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 384 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 371 object_path_); | 385 object_path_); |
| 372 DCHECK(properties); | 386 DCHECK(properties); |
| 373 | 387 |
| 374 if (!properties->tx_power.is_valid()) | 388 if (!properties->tx_power.is_valid()) |
| 375 return kUnknownPower; | 389 return base::nullopt; |
| 376 | 390 |
| 377 return properties->tx_power.value(); | 391 // BlueZ uses int16_t because there is no int8_t for DBus, so we should never |
| 392 // get an int16_t that cannot be represented by an int8_t. But just in case |
| 393 // clamp the value. |
| 394 return ClampPower(properties->tx_power.value()); |
| 378 } | 395 } |
| 379 | 396 |
| 380 bool BluetoothDeviceBlueZ::ExpectingPinCode() const { | 397 bool BluetoothDeviceBlueZ::ExpectingPinCode() const { |
| 381 return pairing_.get() && pairing_->ExpectingPinCode(); | 398 return pairing_.get() && pairing_->ExpectingPinCode(); |
| 382 } | 399 } |
| 383 | 400 |
| 384 bool BluetoothDeviceBlueZ::ExpectingPasskey() const { | 401 bool BluetoothDeviceBlueZ::ExpectingPasskey() const { |
| 385 return pairing_.get() && pairing_->ExpectingPasskey(); | 402 return pairing_.get() && pairing_->ExpectingPasskey(); |
| 386 } | 403 } |
| 387 | 404 |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 void BluetoothDeviceBlueZ::OnForgetError(const ErrorCallback& error_callback, | 890 void BluetoothDeviceBlueZ::OnForgetError(const ErrorCallback& error_callback, |
| 874 const std::string& error_name, | 891 const std::string& error_name, |
| 875 const std::string& error_message) { | 892 const std::string& error_message) { |
| 876 LOG(WARNING) << object_path_.value() | 893 LOG(WARNING) << object_path_.value() |
| 877 << ": Failed to remove device: " << error_name << ": " | 894 << ": Failed to remove device: " << error_name << ": " |
| 878 << error_message; | 895 << error_message; |
| 879 error_callback.Run(); | 896 error_callback.Run(); |
| 880 } | 897 } |
| 881 | 898 |
| 882 } // namespace bluez | 899 } // namespace bluez |
| OLD | NEW |