Commit 1b3a81a0 authored by jpawlowski's avatar jpawlowski Committed by Commit bot

Expose TxPower for bluetooth devices during discovery

This patch adds wiring to expose TxPower field during device discovery.

BUG=407773
R=armansito@chromium.org

Review URL: https://codereview.chromium.org/1133173002

Cr-Commit-Position: refs/heads/master@{#329694}
parent 3e86f223
...@@ -47,6 +47,7 @@ BluetoothDeviceClient::Properties::Properties( ...@@ -47,6 +47,7 @@ BluetoothDeviceClient::Properties::Properties(
RegisterProperty(bluetooth_device::kLegacyPairingProperty, &legacy_pairing); RegisterProperty(bluetooth_device::kLegacyPairingProperty, &legacy_pairing);
RegisterProperty(bluetooth_device::kModaliasProperty, &modalias); RegisterProperty(bluetooth_device::kModaliasProperty, &modalias);
RegisterProperty(bluetooth_device::kRSSIProperty, &rssi); RegisterProperty(bluetooth_device::kRSSIProperty, &rssi);
RegisterProperty(bluetooth_device::kTxPowerProperty, &tx_power);
} }
BluetoothDeviceClient::Properties::~Properties() { BluetoothDeviceClient::Properties::~Properties() {
......
...@@ -48,6 +48,10 @@ class CHROMEOS_EXPORT BluetoothDeviceClient : public DBusClient { ...@@ -48,6 +48,10 @@ class CHROMEOS_EXPORT BluetoothDeviceClient : public DBusClient {
// Read-only. // Read-only.
dbus::Property<std::vector<std::string> > uuids; dbus::Property<std::vector<std::string> > uuids;
// Transmitted power level. This field is avaliable only for LE devices
// that include this field in AD. Read-only.
dbus::Property<int16> tx_power;
// Indicates that the device is currently paired. Read-only. // Indicates that the device is currently paired. Read-only.
dbus::Property<bool> paired; dbus::Property<bool> paired;
......
...@@ -428,7 +428,8 @@ void BluetoothAdapterChromeOS::DevicePropertyChanged( ...@@ -428,7 +428,8 @@ void BluetoothAdapterChromeOS::DevicePropertyChanged(
property_name == properties->trusted.name() || property_name == properties->trusted.name() ||
property_name == properties->connected.name() || property_name == properties->connected.name() ||
property_name == properties->uuids.name() || property_name == properties->uuids.name() ||
property_name == properties->rssi.name()) property_name == properties->rssi.name() ||
property_name == properties->tx_power.name())
NotifyDeviceChanged(device_chromeos); NotifyDeviceChanged(device_chromeos);
// When a device becomes paired, mark it as trusted so that the user does // When a device becomes paired, mark it as trusted so that the user does
......
...@@ -2204,6 +2204,76 @@ TEST_F(BluetoothChromeOSTest, DeviceUuidsChanged) { ...@@ -2204,6 +2204,76 @@ TEST_F(BluetoothChromeOSTest, DeviceUuidsChanged) {
EXPECT_EQ(uuids[4], BluetoothUUID("110a")); EXPECT_EQ(uuids[4], BluetoothUUID("110a"));
} }
TEST_F(BluetoothChromeOSTest, DeviceInquiryRSSIInvalidated) {
// Simulate invalidation of inquiry RSSI of a device, as it occurs
// when discovery is finished.
GetAdapter();
BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
ASSERT_EQ(2U, devices.size());
ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress,
devices[0]->GetAddress());
FakeBluetoothDeviceClient::Properties* properties =
fake_bluetooth_device_client_->GetProperties(
dbus::ObjectPath(FakeBluetoothDeviceClient::kPairedDevicePath));
// During discovery, rssi is a valid value (-75)
properties->rssi.ReplaceValue(-75);
properties->rssi.set_valid(true);
ASSERT_EQ(-75, devices[0]->GetInquiryRSSI());
// Install an observer; expect the DeviceChanged method to be called when
// we invalidate the RSSI of the device.
TestBluetoothAdapterObserver observer(adapter_);
// When discovery is over, the value should be invalidated.
properties->rssi.set_valid(false);
properties->NotifyPropertyChanged(properties->rssi.name());
EXPECT_EQ(1, observer.device_changed_count());
EXPECT_EQ(devices[0], observer.last_device());
int unknown_power = BluetoothDevice::kUnknownPower;
EXPECT_EQ(unknown_power, devices[0]->GetInquiryRSSI());
}
TEST_F(BluetoothChromeOSTest, DeviceInquiryTxPowerInvalidated) {
// Simulate invalidation of inquiry TxPower of a device, as it occurs
// when discovery is finished.
GetAdapter();
BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
ASSERT_EQ(2U, devices.size());
ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress,
devices[0]->GetAddress());
FakeBluetoothDeviceClient::Properties* properties =
fake_bluetooth_device_client_->GetProperties(
dbus::ObjectPath(FakeBluetoothDeviceClient::kPairedDevicePath));
// During discovery, tx_power is a valid value (0)
properties->tx_power.ReplaceValue(0);
properties->tx_power.set_valid(true);
ASSERT_EQ(0, devices[0]->GetInquiryTxPower());
// Install an observer; expect the DeviceChanged method to be called when
// we invalidate the tx_power of the device.
TestBluetoothAdapterObserver observer(adapter_);
// When discovery is over, the value should be invalidated.
properties->tx_power.set_valid(false);
properties->NotifyPropertyChanged(properties->tx_power.name());
EXPECT_EQ(1, observer.device_changed_count());
EXPECT_EQ(devices[0], observer.last_device());
int unknown_power = BluetoothDevice::kUnknownPower;
EXPECT_EQ(unknown_power, devices[0]->GetInquiryTxPower());
}
TEST_F(BluetoothChromeOSTest, ForgetDevice) { TEST_F(BluetoothChromeOSTest, ForgetDevice) {
GetAdapter(); GetAdapter();
......
...@@ -263,6 +263,12 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDevice { ...@@ -263,6 +263,12 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDevice {
// this method will return |kUnknownPower|. // this method will return |kUnknownPower|.
virtual int16 GetInquiryRSSI() const = 0; virtual int16 GetInquiryRSSI() const = 0;
// The transmitted power level. This field is avaliable only for LE devices
// that include this field in AD. It is avaliable and valid only during
// discovery. If not during discovery, or TxPower wasn't reported, this
// method will return |kUnknownPower|.
virtual int16 GetInquiryTxPower() const = 0;
// The ErrorCallback is used for methods that can fail in which case it // The ErrorCallback is used for methods that can fail in which case it
// is called, in the success case the callback is simply not called. // is called, in the success case the callback is simply not called.
typedef base::Callback<void()> ErrorCallback; typedef base::Callback<void()> ErrorCallback;
......
...@@ -278,6 +278,18 @@ int16 BluetoothDeviceChromeOS::GetInquiryRSSI() const { ...@@ -278,6 +278,18 @@ int16 BluetoothDeviceChromeOS::GetInquiryRSSI() const {
return properties->rssi.value(); return properties->rssi.value();
} }
int16 BluetoothDeviceChromeOS::GetInquiryTxPower() const {
BluetoothDeviceClient::Properties* properties =
DBusThreadManager::Get()->GetBluetoothDeviceClient()->
GetProperties(object_path_);
DCHECK(properties);
if (!properties->tx_power.is_valid())
return kUnknownPower;
return properties->tx_power.value();
}
bool BluetoothDeviceChromeOS::ExpectingPinCode() const { bool BluetoothDeviceChromeOS::ExpectingPinCode() const {
return pairing_.get() && pairing_->ExpectingPinCode(); return pairing_.get() && pairing_->ExpectingPinCode();
} }
......
...@@ -45,6 +45,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDeviceChromeOS ...@@ -45,6 +45,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDeviceChromeOS
bool IsConnecting() const override; bool IsConnecting() const override;
UUIDList GetUUIDs() const override; UUIDList GetUUIDs() const override;
int16 GetInquiryRSSI() const override; int16 GetInquiryRSSI() const override;
int16 GetInquiryTxPower() const override;
bool ExpectingPinCode() const override; bool ExpectingPinCode() const override;
bool ExpectingPasskey() const override; bool ExpectingPasskey() const override;
bool ExpectingConfirmation() const override; bool ExpectingConfirmation() const override;
......
...@@ -36,6 +36,7 @@ class BluetoothDeviceMac : public BluetoothDevice { ...@@ -36,6 +36,7 @@ class BluetoothDeviceMac : public BluetoothDevice {
bool IsConnecting() const override; bool IsConnecting() const override;
UUIDList GetUUIDs() const override; UUIDList GetUUIDs() const override;
int16 GetInquiryRSSI() const override; int16 GetInquiryRSSI() const override;
int16 GetInquiryTxPower() const override;
bool ExpectingPinCode() const override; bool ExpectingPinCode() const override;
bool ExpectingPasskey() const override; bool ExpectingPasskey() const override;
bool ExpectingConfirmation() const override; bool ExpectingConfirmation() const override;
......
...@@ -129,6 +129,11 @@ int16 BluetoothDeviceMac::GetInquiryRSSI() const { ...@@ -129,6 +129,11 @@ int16 BluetoothDeviceMac::GetInquiryRSSI() const {
return kUnknownPower; return kUnknownPower;
} }
int16 BluetoothDeviceMac::GetInquiryTxPower() const {
NOTIMPLEMENTED();
return kUnknownPower;
}
bool BluetoothDeviceMac::ExpectingPinCode() const { bool BluetoothDeviceMac::ExpectingPinCode() const {
NOTIMPLEMENTED(); NOTIMPLEMENTED();
return false; return false;
......
...@@ -192,6 +192,11 @@ int16 BluetoothDeviceWin::GetInquiryRSSI() const { ...@@ -192,6 +192,11 @@ int16 BluetoothDeviceWin::GetInquiryRSSI() const {
return kUnknownPower; return kUnknownPower;
} }
int16 BluetoothDeviceWin::GetInquiryTxPower() const {
NOTIMPLEMENTED();
return kUnknownPower;
}
bool BluetoothDeviceWin::ExpectingPinCode() const { bool BluetoothDeviceWin::ExpectingPinCode() const {
NOTIMPLEMENTED(); NOTIMPLEMENTED();
return false; return false;
......
...@@ -43,6 +43,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDeviceWin : public BluetoothDevice { ...@@ -43,6 +43,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDeviceWin : public BluetoothDevice {
bool IsConnecting() const override; bool IsConnecting() const override;
UUIDList GetUUIDs() const override; UUIDList GetUUIDs() const override;
int16 GetInquiryRSSI() const override; int16 GetInquiryRSSI() const override;
int16 GetInquiryTxPower() const override;
bool ExpectingPinCode() const override; bool ExpectingPinCode() const override;
bool ExpectingPasskey() const override; bool ExpectingPasskey() const override;
bool ExpectingConfirmation() const override; bool ExpectingConfirmation() const override;
......
...@@ -42,6 +42,7 @@ class BluetoothLowEnergyDeviceMac : public BluetoothDevice { ...@@ -42,6 +42,7 @@ class BluetoothLowEnergyDeviceMac : public BluetoothDevice {
bool IsConnecting() const override; bool IsConnecting() const override;
BluetoothDevice::UUIDList GetUUIDs() const override; BluetoothDevice::UUIDList GetUUIDs() const override;
int16 GetInquiryRSSI() const override; int16 GetInquiryRSSI() const override;
int16 GetInquiryTxPower() const override;
bool ExpectingPinCode() const override; bool ExpectingPinCode() const override;
bool ExpectingPasskey() const override; bool ExpectingPasskey() const override;
bool ExpectingConfirmation() const override; bool ExpectingConfirmation() const override;
......
...@@ -147,6 +147,11 @@ int16 BluetoothLowEnergyDeviceMac::GetInquiryRSSI() const { ...@@ -147,6 +147,11 @@ int16 BluetoothLowEnergyDeviceMac::GetInquiryRSSI() const {
return kUnknownPower; return kUnknownPower;
} }
int16 BluetoothLowEnergyDeviceMac::GetInquiryTxPower() const {
NOTIMPLEMENTED();
return kUnknownPower;
}
bool BluetoothLowEnergyDeviceMac::ExpectingPinCode() const { bool BluetoothLowEnergyDeviceMac::ExpectingPinCode() const {
return false; return false;
} }
......
...@@ -41,6 +41,7 @@ class MockBluetoothDevice : public BluetoothDevice { ...@@ -41,6 +41,7 @@ class MockBluetoothDevice : public BluetoothDevice {
MOCK_CONST_METHOD0(IsConnecting, bool()); MOCK_CONST_METHOD0(IsConnecting, bool());
MOCK_CONST_METHOD0(GetUUIDs, UUIDList()); MOCK_CONST_METHOD0(GetUUIDs, UUIDList());
MOCK_CONST_METHOD0(GetInquiryRSSI, int16()); MOCK_CONST_METHOD0(GetInquiryRSSI, int16());
MOCK_CONST_METHOD0(GetInquiryTxPower, int16());
MOCK_CONST_METHOD0(ExpectingPinCode, bool()); MOCK_CONST_METHOD0(ExpectingPinCode, bool());
MOCK_CONST_METHOD0(ExpectingPasskey, bool()); MOCK_CONST_METHOD0(ExpectingPasskey, bool());
MOCK_CONST_METHOD0(ExpectingConfirmation, bool()); MOCK_CONST_METHOD0(ExpectingConfirmation, bool());
......
...@@ -123,6 +123,11 @@ void BluetoothDeviceToApiDevice(const device::BluetoothDevice& device, ...@@ -123,6 +123,11 @@ void BluetoothDeviceToApiDevice(const device::BluetoothDevice& device,
out->inquiry_rssi.reset(new int(device.GetInquiryRSSI())); out->inquiry_rssi.reset(new int(device.GetInquiryRSSI()));
else else
out->inquiry_rssi.reset(); out->inquiry_rssi.reset();
if (device.GetInquiryTxPower() != device::BluetoothDevice::kUnknownPower)
out->inquiry_tx_power.reset(new int(device.GetInquiryTxPower()));
else
out->inquiry_tx_power.reset();
} }
void PopulateAdapterState(const device::BluetoothAdapter& adapter, void PopulateAdapterState(const device::BluetoothAdapter& adapter,
......
...@@ -75,6 +75,11 @@ namespace bluetooth { ...@@ -75,6 +75,11 @@ namespace bluetooth {
// The received signal strength, in dBm. This field is avaliable and valid // The received signal strength, in dBm. This field is avaliable and valid
// only during discovery. Outside of discovery it's value is not specified. // only during discovery. Outside of discovery it's value is not specified.
long? inquiryRssi; long? inquiryRssi;
// The transmitted power level. This field is avaliable only for LE devices
// that include this field in AD. It is avaliable and valid only during
// discovery.
long? inquiryTxPower;
}; };
// Callback from the <code>getDevice</code> method. // Callback from the <code>getDevice</code> method.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment