Index: device/bluetooth/bluez/bluetooth_device_bluez.cc |
diff --git a/device/bluetooth/bluez/bluetooth_device_bluez.cc b/device/bluetooth/bluez/bluetooth_device_bluez.cc |
index 73e54871143c0599a4789e551dcd622dbde82343..4a14f6156328271882191e344ba9a2da6d67aeec 100644 |
--- a/device/bluetooth/bluez/bluetooth_device_bluez.cc |
+++ b/device/bluetooth/bluez/bluetooth_device_bluez.cc |
@@ -137,6 +137,16 @@ BluetoothDevice::ConnectErrorCode DBusErrorToConnectError( |
return error_code; |
} |
+int8_t EnsureValidRSSI(int16_t rssi) { |
+ return ((rssi < -128) || (rssi > 127)) ? BluetoothDevice::kUnknownRSSI : rssi; |
+} |
+ |
+int8_t EnsureValidTxPower(int16_t tx_power) { |
+ return ((tx_power < -127) || (tx_power > 127)) |
+ ? BluetoothDevice::kUnknownTxPower |
+ : tx_power; |
+} |
+ |
} // namespace |
namespace bluez { |
@@ -316,28 +326,28 @@ BluetoothDeviceBlueZ::UUIDList BluetoothDeviceBlueZ::GetUUIDs() const { |
return uuids; |
} |
-int16_t BluetoothDeviceBlueZ::GetInquiryRSSI() const { |
+int8_t BluetoothDeviceBlueZ::GetInquiryRSSI() const { |
bluez::BluetoothDeviceClient::Properties* properties = |
bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
object_path_); |
DCHECK(properties); |
if (!properties->rssi.is_valid()) |
- return kUnknownPower; |
+ return kUnknownRSSI; |
- return properties->rssi.value(); |
+ return EnsureValidRSSI(properties->rssi.value()); |
} |
-int16_t BluetoothDeviceBlueZ::GetInquiryTxPower() const { |
+int8_t BluetoothDeviceBlueZ::GetInquiryTxPower() const { |
bluez::BluetoothDeviceClient::Properties* properties = |
bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
object_path_); |
DCHECK(properties); |
if (!properties->tx_power.is_valid()) |
- return kUnknownPower; |
+ return kUnknownTxPower; |
- return properties->tx_power.value(); |
+ return EnsureValidTxPower(properties->tx_power.value()); |
} |
bool BluetoothDeviceBlueZ::ExpectingPinCode() const { |
@@ -598,7 +608,9 @@ void BluetoothDeviceBlueZ::OnGetConnInfo(const ConnectionInfoCallback& callback, |
int16_t rssi, |
int16_t transmit_power, |
int16_t max_transmit_power) { |
- callback.Run(ConnectionInfo(rssi, transmit_power, max_transmit_power)); |
+ callback.Run(ConnectionInfo(EnsureValidRSSI(rssi), |
+ EnsureValidTxPower(transmit_power), |
+ EnsureValidTxPower(max_transmit_power))); |
} |
void BluetoothDeviceBlueZ::OnGetConnInfoError( |