summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjpawlowski <jpawlowski@chromium.org>2015-05-13 12:13:36 -0700
committerCommit bot <commit-bot@chromium.org>2015-05-13 19:13:49 +0000
commit1b3a81a03eb66b03afbdb4403308d566fb4221c8 (patch)
tree3d19cdbae960e3538816647a9315f6e24ab59ce9
parent3e86f2231ea55908721b264d00e679aa25ecf03b (diff)
downloadchromium_src-1b3a81a03eb66b03afbdb4403308d566fb4221c8.zip
chromium_src-1b3a81a03eb66b03afbdb4403308d566fb4221c8.tar.gz
chromium_src-1b3a81a03eb66b03afbdb4403308d566fb4221c8.tar.bz2
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}
-rw-r--r--chromeos/dbus/bluetooth_device_client.cc1
-rw-r--r--chromeos/dbus/bluetooth_device_client.h4
-rw-r--r--device/bluetooth/bluetooth_adapter_chromeos.cc3
-rw-r--r--device/bluetooth/bluetooth_chromeos_unittest.cc70
-rw-r--r--device/bluetooth/bluetooth_device.h6
-rw-r--r--device/bluetooth/bluetooth_device_chromeos.cc12
-rw-r--r--device/bluetooth/bluetooth_device_chromeos.h1
-rw-r--r--device/bluetooth/bluetooth_device_mac.h1
-rw-r--r--device/bluetooth/bluetooth_device_mac.mm5
-rw-r--r--device/bluetooth/bluetooth_device_win.cc5
-rw-r--r--device/bluetooth/bluetooth_device_win.h1
-rw-r--r--device/bluetooth/bluetooth_low_energy_device_mac.h1
-rw-r--r--device/bluetooth/bluetooth_low_energy_device_mac.mm5
-rw-r--r--device/bluetooth/test/mock_bluetooth_device.h1
-rw-r--r--extensions/browser/api/bluetooth/bluetooth_api_utils.cc5
-rw-r--r--extensions/common/api/bluetooth.idl5
16 files changed, 125 insertions, 1 deletions
diff --git a/chromeos/dbus/bluetooth_device_client.cc b/chromeos/dbus/bluetooth_device_client.cc
index 96fba62..30e5a36 100644
--- a/chromeos/dbus/bluetooth_device_client.cc
+++ b/chromeos/dbus/bluetooth_device_client.cc
@@ -47,6 +47,7 @@ BluetoothDeviceClient::Properties::Properties(
RegisterProperty(bluetooth_device::kLegacyPairingProperty, &legacy_pairing);
RegisterProperty(bluetooth_device::kModaliasProperty, &modalias);
RegisterProperty(bluetooth_device::kRSSIProperty, &rssi);
+ RegisterProperty(bluetooth_device::kTxPowerProperty, &tx_power);
}
BluetoothDeviceClient::Properties::~Properties() {
diff --git a/chromeos/dbus/bluetooth_device_client.h b/chromeos/dbus/bluetooth_device_client.h
index 353fd5b..4a0d6b4 100644
--- a/chromeos/dbus/bluetooth_device_client.h
+++ b/chromeos/dbus/bluetooth_device_client.h
@@ -48,6 +48,10 @@ class CHROMEOS_EXPORT BluetoothDeviceClient : public DBusClient {
// Read-only.
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.
dbus::Property<bool> paired;
diff --git a/device/bluetooth/bluetooth_adapter_chromeos.cc b/device/bluetooth/bluetooth_adapter_chromeos.cc
index 5af69c8..a521c8f 100644
--- a/device/bluetooth/bluetooth_adapter_chromeos.cc
+++ b/device/bluetooth/bluetooth_adapter_chromeos.cc
@@ -428,7 +428,8 @@ void BluetoothAdapterChromeOS::DevicePropertyChanged(
property_name == properties->trusted.name() ||
property_name == properties->connected.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);
// When a device becomes paired, mark it as trusted so that the user does
diff --git a/device/bluetooth/bluetooth_chromeos_unittest.cc b/device/bluetooth/bluetooth_chromeos_unittest.cc
index 18728ef..ad19d8b 100644
--- a/device/bluetooth/bluetooth_chromeos_unittest.cc
+++ b/device/bluetooth/bluetooth_chromeos_unittest.cc
@@ -2204,6 +2204,76 @@ TEST_F(BluetoothChromeOSTest, DeviceUuidsChanged) {
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) {
GetAdapter();
diff --git a/device/bluetooth/bluetooth_device.h b/device/bluetooth/bluetooth_device.h
index d4e7d42..ccf71da 100644
--- a/device/bluetooth/bluetooth_device.h
+++ b/device/bluetooth/bluetooth_device.h
@@ -263,6 +263,12 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDevice {
// this method will return |kUnknownPower|.
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
// is called, in the success case the callback is simply not called.
typedef base::Callback<void()> ErrorCallback;
diff --git a/device/bluetooth/bluetooth_device_chromeos.cc b/device/bluetooth/bluetooth_device_chromeos.cc
index a1a2569..30b5379 100644
--- a/device/bluetooth/bluetooth_device_chromeos.cc
+++ b/device/bluetooth/bluetooth_device_chromeos.cc
@@ -278,6 +278,18 @@ int16 BluetoothDeviceChromeOS::GetInquiryRSSI() const {
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 {
return pairing_.get() && pairing_->ExpectingPinCode();
}
diff --git a/device/bluetooth/bluetooth_device_chromeos.h b/device/bluetooth/bluetooth_device_chromeos.h
index 6e4c09e..94612d3 100644
--- a/device/bluetooth/bluetooth_device_chromeos.h
+++ b/device/bluetooth/bluetooth_device_chromeos.h
@@ -45,6 +45,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDeviceChromeOS
bool IsConnecting() const override;
UUIDList GetUUIDs() const override;
int16 GetInquiryRSSI() const override;
+ int16 GetInquiryTxPower() const override;
bool ExpectingPinCode() const override;
bool ExpectingPasskey() const override;
bool ExpectingConfirmation() const override;
diff --git a/device/bluetooth/bluetooth_device_mac.h b/device/bluetooth/bluetooth_device_mac.h
index a2ecf1d..daa8e4d 100644
--- a/device/bluetooth/bluetooth_device_mac.h
+++ b/device/bluetooth/bluetooth_device_mac.h
@@ -36,6 +36,7 @@ class BluetoothDeviceMac : public BluetoothDevice {
bool IsConnecting() const override;
UUIDList GetUUIDs() const override;
int16 GetInquiryRSSI() const override;
+ int16 GetInquiryTxPower() const override;
bool ExpectingPinCode() const override;
bool ExpectingPasskey() const override;
bool ExpectingConfirmation() const override;
diff --git a/device/bluetooth/bluetooth_device_mac.mm b/device/bluetooth/bluetooth_device_mac.mm
index aabe35e..63da264 100644
--- a/device/bluetooth/bluetooth_device_mac.mm
+++ b/device/bluetooth/bluetooth_device_mac.mm
@@ -129,6 +129,11 @@ int16 BluetoothDeviceMac::GetInquiryRSSI() const {
return kUnknownPower;
}
+int16 BluetoothDeviceMac::GetInquiryTxPower() const {
+ NOTIMPLEMENTED();
+ return kUnknownPower;
+}
+
bool BluetoothDeviceMac::ExpectingPinCode() const {
NOTIMPLEMENTED();
return false;
diff --git a/device/bluetooth/bluetooth_device_win.cc b/device/bluetooth/bluetooth_device_win.cc
index 0cd8071..de00817 100644
--- a/device/bluetooth/bluetooth_device_win.cc
+++ b/device/bluetooth/bluetooth_device_win.cc
@@ -192,6 +192,11 @@ int16 BluetoothDeviceWin::GetInquiryRSSI() const {
return kUnknownPower;
}
+int16 BluetoothDeviceWin::GetInquiryTxPower() const {
+ NOTIMPLEMENTED();
+ return kUnknownPower;
+}
+
bool BluetoothDeviceWin::ExpectingPinCode() const {
NOTIMPLEMENTED();
return false;
diff --git a/device/bluetooth/bluetooth_device_win.h b/device/bluetooth/bluetooth_device_win.h
index 4471fda..d16c3a0 100644
--- a/device/bluetooth/bluetooth_device_win.h
+++ b/device/bluetooth/bluetooth_device_win.h
@@ -43,6 +43,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDeviceWin : public BluetoothDevice {
bool IsConnecting() const override;
UUIDList GetUUIDs() const override;
int16 GetInquiryRSSI() const override;
+ int16 GetInquiryTxPower() const override;
bool ExpectingPinCode() const override;
bool ExpectingPasskey() const override;
bool ExpectingConfirmation() const override;
diff --git a/device/bluetooth/bluetooth_low_energy_device_mac.h b/device/bluetooth/bluetooth_low_energy_device_mac.h
index 9f6ef69..2d5bb6f 100644
--- a/device/bluetooth/bluetooth_low_energy_device_mac.h
+++ b/device/bluetooth/bluetooth_low_energy_device_mac.h
@@ -42,6 +42,7 @@ class BluetoothLowEnergyDeviceMac : public BluetoothDevice {
bool IsConnecting() const override;
BluetoothDevice::UUIDList GetUUIDs() const override;
int16 GetInquiryRSSI() const override;
+ int16 GetInquiryTxPower() const override;
bool ExpectingPinCode() const override;
bool ExpectingPasskey() const override;
bool ExpectingConfirmation() const override;
diff --git a/device/bluetooth/bluetooth_low_energy_device_mac.mm b/device/bluetooth/bluetooth_low_energy_device_mac.mm
index e7dc1af..0357ad9 100644
--- a/device/bluetooth/bluetooth_low_energy_device_mac.mm
+++ b/device/bluetooth/bluetooth_low_energy_device_mac.mm
@@ -147,6 +147,11 @@ int16 BluetoothLowEnergyDeviceMac::GetInquiryRSSI() const {
return kUnknownPower;
}
+int16 BluetoothLowEnergyDeviceMac::GetInquiryTxPower() const {
+ NOTIMPLEMENTED();
+ return kUnknownPower;
+}
+
bool BluetoothLowEnergyDeviceMac::ExpectingPinCode() const {
return false;
}
diff --git a/device/bluetooth/test/mock_bluetooth_device.h b/device/bluetooth/test/mock_bluetooth_device.h
index cedf402..039c8ce 100644
--- a/device/bluetooth/test/mock_bluetooth_device.h
+++ b/device/bluetooth/test/mock_bluetooth_device.h
@@ -41,6 +41,7 @@ class MockBluetoothDevice : public BluetoothDevice {
MOCK_CONST_METHOD0(IsConnecting, bool());
MOCK_CONST_METHOD0(GetUUIDs, UUIDList());
MOCK_CONST_METHOD0(GetInquiryRSSI, int16());
+ MOCK_CONST_METHOD0(GetInquiryTxPower, int16());
MOCK_CONST_METHOD0(ExpectingPinCode, bool());
MOCK_CONST_METHOD0(ExpectingPasskey, bool());
MOCK_CONST_METHOD0(ExpectingConfirmation, bool());
diff --git a/extensions/browser/api/bluetooth/bluetooth_api_utils.cc b/extensions/browser/api/bluetooth/bluetooth_api_utils.cc
index 79a10e8..5913643 100644
--- a/extensions/browser/api/bluetooth/bluetooth_api_utils.cc
+++ b/extensions/browser/api/bluetooth/bluetooth_api_utils.cc
@@ -123,6 +123,11 @@ void BluetoothDeviceToApiDevice(const device::BluetoothDevice& device,
out->inquiry_rssi.reset(new int(device.GetInquiryRSSI()));
else
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,
diff --git a/extensions/common/api/bluetooth.idl b/extensions/common/api/bluetooth.idl
index 9051289..98908f0 100644
--- a/extensions/common/api/bluetooth.idl
+++ b/extensions/common/api/bluetooth.idl
@@ -75,6 +75,11 @@ namespace bluetooth {
// The received signal strength, in dBm. This field is avaliable and valid
// only during discovery. Outside of discovery it's value is not specified.
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.