diff options
author | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-01 06:13:30 +0000 |
---|---|---|
committer | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-01 06:13:30 +0000 |
commit | eb6725fe48e19c20cda719fec1e0044a1229b7bb (patch) | |
tree | 01045bf8eba847347c1d1005ac6fc5d8e7ec39aa | |
parent | ea0c7a8181c55705c07342995dc1f927316b34b3 (diff) | |
download | chromium_src-eb6725fe48e19c20cda719fec1e0044a1229b7bb.zip chromium_src-eb6725fe48e19c20cda719fec1e0044a1229b7bb.tar.gz chromium_src-eb6725fe48e19c20cda719fec1e0044a1229b7bb.tar.bz2 |
Expose device RSSI and Tx power via the chrome.bluetooth API.
This CL only implements the fetching of these values on Mac.
BUG=365966
TEST=browser_tests
R=kalman@chromium.org, keybuk@chromium.org
Review URL: https://codereview.chromium.org/246603008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267458 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.cc | 13 | ||||
-rw-r--r-- | chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc | 5 | ||||
-rw-r--r-- | chrome/common/extensions/api/bluetooth.idl | 17 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device.h | 25 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_chromeos.cc | 15 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_chromeos.h | 3 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_mac.h | 10 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_mac.mm | 63 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_win.cc | 15 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_win.h | 3 | ||||
-rw-r--r-- | device/bluetooth/test/mock_bluetooth_device.cc | 6 | ||||
-rw-r--r-- | device/bluetooth/test/mock_bluetooth_device.h | 3 |
12 files changed, 172 insertions, 6 deletions
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.cc index bd7bec3..e13ec1b 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.cc +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.cc @@ -112,6 +112,19 @@ void BluetoothDeviceToApiDevice(const device::BluetoothDevice& device, out->paired.reset(new bool(device.IsPaired())); out->connected.reset(new bool(device.IsConnected())); + int rssi = device.GetRSSI(); + if (rssi != BluetoothDevice::kUnknownPower) + out->rssi.reset(new int(rssi)); + + if (*out->connected) { + int current_transmit_power = device.GetCurrentHostTransmitPower(); + if (current_transmit_power != BluetoothDevice::kUnknownPower) + out->current_host_transmit_power.reset(new int(current_transmit_power)); + int maximum_transmit_power = device.GetMaximumHostTransmitPower(); + if (maximum_transmit_power != BluetoothDevice::kUnknownPower) + out->maximum_host_transmit_power.reset(new int(maximum_transmit_power)); + } + std::vector<std::string>* string_uuids = new std::vector<std::string>(); const device::BluetoothDevice::UUIDList& uuids = device.GetUUIDs(); for (device::BluetoothDevice::UUIDList::const_iterator iter = uuids.begin(); diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc index 4c1e85f..a567584 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc @@ -655,6 +655,11 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, DeviceInfo) { .WillRepeatedly(testing::Return(0x240A)); EXPECT_CALL(*device1_.get(), GetDeviceID()) .WillRepeatedly(testing::Return(0x0400)); + EXPECT_CALL(*device1_, GetRSSI()).WillRepeatedly(testing::Return(-42)); + EXPECT_CALL(*device1_, GetCurrentHostTransmitPower()) + .WillRepeatedly(testing::Return(-16)); + EXPECT_CALL(*device1_, GetMaximumHostTransmitPower()) + .WillRepeatedly(testing::Return(10)); BluetoothDevice::UUIDList uuids; uuids.push_back(BluetoothUUID("1105")); diff --git a/chrome/common/extensions/api/bluetooth.idl b/chrome/common/extensions/api/bluetooth.idl index b42fce4..cebbf80 100644 --- a/chrome/common/extensions/api/bluetooth.idl +++ b/chrome/common/extensions/api/bluetooth.idl @@ -61,6 +61,23 @@ namespace bluetooth { // Indicates whether the device is currently connected to the system. boolean? connected; + // Indicates the RSSI ("received signal strength indication") of the + // connection to the device, measured in dBm, to a resolution of 1dBm. + // If the device is currently connected, then measures the RSSI of the + // connection signal. Otherwise, measures the RSSI of the last inquiry sent + // to the device, where available. Absent if unavailable. + long? rssi; + + // Indicates the host's current transmit power ("Tx power") for the + // connection to the device, measured in dBm, to a resolution of 1dBm. + // This value is only available if the device is currently connected. + long? currentHostTransmitPower; + + // Indicates the host's maximum transmit power ("Tx power") for the + // connection to the device, measured in dBm, to a resolution of 1dBm. + // This value is only available if the device is currently connected. + long? maximumHostTransmitPower; + // UUIDs of protocols, profiles and services advertised by the device. // For classic Bluetooth devices, this list is obtained from EIR data and // SDP tables. For Low Energy devices, this list is obtained from AD and diff --git a/device/bluetooth/bluetooth_device.h b/device/bluetooth/bluetooth_device.h index 28fd7ac..220066c 100644 --- a/device/bluetooth/bluetooth_device.h +++ b/device/bluetooth/bluetooth_device.h @@ -66,6 +66,9 @@ class BluetoothDevice { DEVICE_KEYBOARD_MOUSE_COMBO }; + // The value returned if the RSSI or transmit power cannot be read. + static const int kUnknownPower = 127; + // Possible errors passed back to an error callback function in case of a // failed call to Connect(). enum ConnectErrorCode { @@ -227,6 +230,28 @@ class BluetoothDevice { // DEVICE_PERIPHERAL. DeviceType GetDeviceType() const; + // Gets the "received signal strength indication" (RSSI) of the current + // connection to the device. The RSSI indicates the power present in the + // received radio signal, measured in dBm, to a resolution of 1dBm. Larger + // (typically, less negative) values indicate a stronger signal. + // If the device is not currently connected, then returns the RSSI read from + // the last inquiry that returned the device, where available. In case of an + // error, returns |kUnknownPower|. Otherwise, returns the connection's RSSI. + virtual int GetRSSI() const = 0; + + // These two methods are used to read the current or maximum transmit power + // ("Tx power") of the current connection to the device. The transmit power + // indicates the strength of the signal broadcast from the host's Bluetooth + // antenna when communicating with the device, measured in dBm, to a + // resolution of 1dBm. Larger (typically, less negative) values + // indicate a stronger signal. + // It is only meaningful to call this method when there is a connection + // established to the device. If there is no connection, or in case of an + // error, returns |kUnknownPower|. Otherwise, returns the connection's + // transmit power. + virtual int GetCurrentHostTransmitPower() const = 0; + virtual int GetMaximumHostTransmitPower() const = 0; + // Indicates whether the device is known to support pairing based on its // device class and address. bool IsPairable() const; diff --git a/device/bluetooth/bluetooth_device_chromeos.cc b/device/bluetooth/bluetooth_device_chromeos.cc index b5f7386..e894136 100644 --- a/device/bluetooth/bluetooth_device_chromeos.cc +++ b/device/bluetooth/bluetooth_device_chromeos.cc @@ -212,6 +212,21 @@ uint16 BluetoothDeviceChromeOS::GetDeviceID() const { return device_id; } +int BluetoothDeviceChromeOS::GetRSSI() const { + NOTIMPLEMENTED(); + return kUnknownPower; +} + +int BluetoothDeviceChromeOS::GetCurrentHostTransmitPower() const { + NOTIMPLEMENTED(); + return kUnknownPower; +} + +int BluetoothDeviceChromeOS::GetMaximumHostTransmitPower() const { + NOTIMPLEMENTED(); + return kUnknownPower; +} + bool BluetoothDeviceChromeOS::IsPaired() const { BluetoothDeviceClient::Properties* properties = DBusThreadManager::Get()->GetBluetoothDeviceClient()-> diff --git a/device/bluetooth/bluetooth_device_chromeos.h b/device/bluetooth/bluetooth_device_chromeos.h index 156d9ea..96265ae 100644 --- a/device/bluetooth/bluetooth_device_chromeos.h +++ b/device/bluetooth/bluetooth_device_chromeos.h @@ -37,6 +37,9 @@ class BluetoothDeviceChromeOS virtual uint16 GetVendorID() const OVERRIDE; virtual uint16 GetProductID() const OVERRIDE; virtual uint16 GetDeviceID() const OVERRIDE; + virtual int GetRSSI() const OVERRIDE; + virtual int GetCurrentHostTransmitPower() const OVERRIDE; + virtual int GetMaximumHostTransmitPower() const OVERRIDE; virtual bool IsPaired() const OVERRIDE; virtual bool IsConnected() const OVERRIDE; virtual bool IsConnectable() const OVERRIDE; diff --git a/device/bluetooth/bluetooth_device_mac.h b/device/bluetooth/bluetooth_device_mac.h index ec87ff7..1503f1dc 100644 --- a/device/bluetooth/bluetooth_device_mac.h +++ b/device/bluetooth/bluetooth_device_mac.h @@ -5,6 +5,8 @@ #ifndef DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_MAC_H_ #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_MAC_H_ +#import <IOBluetooth/IOBluetooth.h> + #include <string> #include "base/basictypes.h" @@ -32,6 +34,9 @@ class BluetoothDeviceMac : public BluetoothDevice { virtual uint16 GetVendorID() const OVERRIDE; virtual uint16 GetProductID() const OVERRIDE; virtual uint16 GetDeviceID() const OVERRIDE; + virtual int GetRSSI() const OVERRIDE; + virtual int GetCurrentHostTransmitPower() const OVERRIDE; + virtual int GetMaximumHostTransmitPower() const OVERRIDE; virtual bool IsPaired() const OVERRIDE; virtual bool IsConnected() const OVERRIDE; virtual bool IsConnectable() const OVERRIDE; @@ -72,6 +77,11 @@ class BluetoothDeviceMac : public BluetoothDevice { private: friend class BluetoothAdapterMac; + // Implementation to read the host's transmit power level of type + // |power_level_type|. + int GetHostTransmitPower( + BluetoothHCITransmitPowerLevelType power_level_type) const; + // List of observers interested in event notifications from us. ObserverList<Observer> observers_; diff --git a/device/bluetooth/bluetooth_device_mac.mm b/device/bluetooth/bluetooth_device_mac.mm index 24c2b45..aaeffb8 100644 --- a/device/bluetooth/bluetooth_device_mac.mm +++ b/device/bluetooth/bluetooth_device_mac.mm @@ -4,11 +4,6 @@ #include "device/bluetooth/bluetooth_device_mac.h" -#include <IOBluetooth/Bluetooth.h> -#import <IOBluetooth/objc/IOBluetoothDevice.h> -#import <IOBluetooth/objc/IOBluetoothSDPServiceRecord.h> -#import <IOBluetooth/objc/IOBluetoothSDPUUID.h> - #include <string> #include "base/basictypes.h" @@ -28,13 +23,23 @@ @interface IOBluetoothDevice (LionSDKDeclarations) - (NSString*)addressString; -- (NSString*)name; - (unsigned int)classOfDevice; +- (BluetoothConnectionHandle)connectionHandle; +- (BluetoothHCIRSSIValue)rawRSSI; - (NSArray*)services; @end #endif // MAC_OS_X_VERSION_10_7 +// Undocumented API for accessing the Bluetooth transmit power level. +// Similar to the API defined here [ http://goo.gl/20Q5vE ]. +@interface IOBluetoothHostController (UndocumentedAPI) +- (IOReturn) + BluetoothHCIReadTransmitPowerLevel:(BluetoothConnectionHandle)connection + inType:(BluetoothHCITransmitPowerLevelType)type + outTransmitPowerLevel:(BluetoothHCITransmitPowerLevel*)level; +@end + namespace device { BluetoothDeviceMac::BluetoothDeviceMac(IOBluetoothDevice* device) @@ -84,6 +89,30 @@ uint16 BluetoothDeviceMac::GetDeviceID() const { return 0; } +int BluetoothDeviceMac::GetRSSI() const { + if (![device_ isConnected]) { + NOTIMPLEMENTED(); + return kUnknownPower; + } + + int rssi = [device_ rawRSSI]; + + // The API guarantees that +127 is returned in case the RSSI is not readable: + // http://goo.gl/bpURYv + if (rssi == 127) + return kUnknownPower; + + return rssi; +} + +int BluetoothDeviceMac::GetCurrentHostTransmitPower() const { + return GetHostTransmitPower(kReadCurrentTransmitPowerLevel); +} + +int BluetoothDeviceMac::GetMaximumHostTransmitPower() const { + return GetHostTransmitPower(kReadMaximumTransmitPowerLevel); +} + bool BluetoothDeviceMac::IsPaired() const { return [device_ isPaired]; } @@ -183,4 +212,26 @@ void BluetoothDeviceMac::ClearOutOfBandPairingData( NOTIMPLEMENTED(); } +int BluetoothDeviceMac::GetHostTransmitPower( + BluetoothHCITransmitPowerLevelType power_level_type) const { + IOBluetoothHostController* controller = + [IOBluetoothHostController defaultController]; + + // Bail if the undocumented API is unavailable on this machine. + SEL selector = @selector( + BluetoothHCIReadTransmitPowerLevel:inType:outTransmitPowerLevel:); + if (![controller respondsToSelector:selector]) + return kUnknownPower; + + BluetoothHCITransmitPowerLevel power_level; + IOReturn result = + [controller BluetoothHCIReadTransmitPowerLevel:[device_ connectionHandle] + inType:power_level_type + outTransmitPowerLevel:&power_level]; + if (result != kIOReturnSuccess) + return kUnknownPower; + + return power_level; +} + } // namespace device diff --git a/device/bluetooth/bluetooth_device_win.cc b/device/bluetooth/bluetooth_device_win.cc index 81a9386..53995ff 100644 --- a/device/bluetooth/bluetooth_device_win.cc +++ b/device/bluetooth/bluetooth_device_win.cc @@ -111,6 +111,21 @@ uint16 BluetoothDeviceWin::GetDeviceID() const { return 0; } +int BluetoothDeviceWin::GetRSSI() const { + NOTIMPLEMENTED(); + return kUnknownPower; +} + +int BluetoothDeviceWin::GetCurrentHostTransmitPower() const { + NOTIMPLEMENTED(); + return kUnknownPower; +} + +int BluetoothDeviceWin::GetMaximumHostTransmitPower() const { + NOTIMPLEMENTED(); + return kUnknownPower; +} + bool BluetoothDeviceWin::IsPaired() const { return paired_; } diff --git a/device/bluetooth/bluetooth_device_win.h b/device/bluetooth/bluetooth_device_win.h index 232da0f..128a87c 100644 --- a/device/bluetooth/bluetooth_device_win.h +++ b/device/bluetooth/bluetooth_device_win.h @@ -40,6 +40,9 @@ class BluetoothDeviceWin : public BluetoothDevice { virtual uint16 GetVendorID() const OVERRIDE; virtual uint16 GetProductID() const OVERRIDE; virtual uint16 GetDeviceID() const OVERRIDE; + virtual int GetRSSI() const OVERRIDE; + virtual int GetCurrentHostTransmitPower() const OVERRIDE; + virtual int GetMaximumHostTransmitPower() const OVERRIDE; virtual bool IsPaired() const OVERRIDE; virtual bool IsConnected() const OVERRIDE; virtual bool IsConnectable() const OVERRIDE; diff --git a/device/bluetooth/test/mock_bluetooth_device.cc b/device/bluetooth/test/mock_bluetooth_device.cc index 5235d5b..e8130da 100644 --- a/device/bluetooth/test/mock_bluetooth_device.cc +++ b/device/bluetooth/test/mock_bluetooth_device.cc @@ -26,6 +26,12 @@ MockBluetoothDevice::MockBluetoothDevice(MockBluetoothAdapter* adapter, .WillByDefault(testing::Return(address_)); ON_CALL(*this, GetDeviceType()) .WillByDefault(testing::Return(DEVICE_UNKNOWN)); + ON_CALL(*this, GetRSSI()) + .WillByDefault(testing::Return(kUnknownPower)); + ON_CALL(*this, GetCurrentHostTransmitPower()) + .WillByDefault(testing::Return(kUnknownPower)); + ON_CALL(*this, GetMaximumHostTransmitPower()) + .WillByDefault(testing::Return(kUnknownPower)); ON_CALL(*this, GetVendorIDSource()) .WillByDefault(testing::Return(VENDOR_ID_UNKNOWN)); ON_CALL(*this, GetVendorID()) diff --git a/device/bluetooth/test/mock_bluetooth_device.h b/device/bluetooth/test/mock_bluetooth_device.h index 4d910d1..9291e9b 100644 --- a/device/bluetooth/test/mock_bluetooth_device.h +++ b/device/bluetooth/test/mock_bluetooth_device.h @@ -38,6 +38,9 @@ class MockBluetoothDevice : public BluetoothDevice { MOCK_CONST_METHOD0(GetDeviceID, uint16()); MOCK_CONST_METHOD0(GetName, base::string16()); MOCK_CONST_METHOD0(GetDeviceType, BluetoothDevice::DeviceType()); + MOCK_CONST_METHOD0(GetRSSI, int()); + MOCK_CONST_METHOD0(GetCurrentHostTransmitPower, int()); + MOCK_CONST_METHOD0(GetMaximumHostTransmitPower, int()); MOCK_CONST_METHOD0(IsPaired, bool()); MOCK_CONST_METHOD0(IsConnected, bool()); MOCK_CONST_METHOD0(IsConnectable, bool()); |