diff options
author | tengs <tengs@chromium.org> | 2015-01-07 13:31:30 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-07 21:32:08 +0000 |
commit | d060690f69581b758adb9b477ebe5e08acbccfa7 (patch) | |
tree | 6dfd27e6130f8c961ffa84b628edc017e16e6173 | |
parent | 574fc997fce7f47ee223764f02ac1c423265ff0a (diff) | |
download | chromium_src-d060690f69581b758adb9b477ebe5e08acbccfa7.zip chromium_src-d060690f69581b758adb9b477ebe5e08acbccfa7.tar.gz chromium_src-d060690f69581b758adb9b477ebe5e08acbccfa7.tar.bz2 |
Add GetConnectionInfo function for BluetoothDevice, replacing the existing
GetRSSI, GetHostTransmitPower, and GetMaximumHostTransmitPower functions.
On Mac, this function uses IOBluetooth APIs.
On ChromeOS, this function is a wrapper for the GetConnInfo() DBus plugin API.
On Windows, this function is unimplemented.
BUG=382683
Review URL: https://codereview.chromium.org/735893002
Cr-Commit-Position: refs/heads/master@{#310372}
19 files changed, 246 insertions, 305 deletions
diff --git a/chromeos/dbus/bluetooth_device_client.cc b/chromeos/dbus/bluetooth_device_client.cc index 777b1aa..e2eae7d 100644 --- a/chromeos/dbus/bluetooth_device_client.cc +++ b/chromeos/dbus/bluetooth_device_client.cc @@ -16,6 +16,13 @@ namespace chromeos { +namespace { + +// Value returned for the the RSSI or TX power if it cannot be read. +const int kUnknownPower = 127; + +} // namespace + const char BluetoothDeviceClient::kNoResponseError[] = "org.chromium.Error.NoResponse"; const char BluetoothDeviceClient::kUnknownDeviceError[] = @@ -41,10 +48,6 @@ BluetoothDeviceClient::Properties::Properties( RegisterProperty(bluetooth_device::kLegacyPairingProperty, &legacy_pairing); RegisterProperty(bluetooth_device::kModaliasProperty, &modalias); RegisterProperty(bluetooth_device::kRSSIProperty, &rssi); - RegisterProperty(bluetooth_device::kConnectionRSSI, &connection_rssi); - RegisterProperty(bluetooth_device::kConnectionTXPower, &connection_tx_power); - RegisterProperty(bluetooth_device::kConnectionTXPowerMax, - &connection_tx_power_max); } BluetoothDeviceClient::Properties::~Properties() { @@ -273,37 +276,12 @@ class BluetoothDeviceClientImpl } // BluetoothDeviceClient override. - virtual void StartConnectionMonitor( - const dbus::ObjectPath& object_path, - const base::Closure& callback, - const ErrorCallback& error_callback) override { - dbus::MethodCall method_call(bluetooth_device::kBluetoothDeviceInterface, - bluetooth_device::kStartConnectionMonitor); - - dbus::ObjectProxy* object_proxy = - object_manager_->GetObjectProxy(object_path); - if (!object_proxy) { - error_callback.Run(kUnknownDeviceError, ""); - return; - } - object_proxy->CallMethodWithErrorCallback( - &method_call, - dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, - base::Bind(&BluetoothDeviceClientImpl::OnSuccess, - weak_ptr_factory_.GetWeakPtr(), - callback), - base::Bind(&BluetoothDeviceClientImpl::OnError, - weak_ptr_factory_.GetWeakPtr(), - error_callback)); - } - - // BluetoothDeviceClient override. - virtual void StopConnectionMonitor( - const dbus::ObjectPath& object_path, - const base::Closure& callback, - const ErrorCallback& error_callback) override { - dbus::MethodCall method_call(bluetooth_device::kBluetoothDeviceInterface, - bluetooth_device::kStopConnectionMonitor); + void GetConnInfo(const dbus::ObjectPath& object_path, + const ConnInfoCallback& callback, + const ErrorCallback& error_callback) override { + dbus::MethodCall method_call( + bluetooth_plugin_device::kBluetoothPluginInterface, + bluetooth_plugin_device::kGetConnInfo); dbus::ObjectProxy* object_proxy = object_manager_->GetObjectProxy(object_path); @@ -312,14 +290,11 @@ class BluetoothDeviceClientImpl return; } object_proxy->CallMethodWithErrorCallback( - &method_call, - dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, - base::Bind(&BluetoothDeviceClientImpl::OnSuccess, - weak_ptr_factory_.GetWeakPtr(), - callback), + &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, + base::Bind(&BluetoothDeviceClientImpl::OnGetConnInfoSuccess, + weak_ptr_factory_.GetWeakPtr(), callback), base::Bind(&BluetoothDeviceClientImpl::OnError, - weak_ptr_factory_.GetWeakPtr(), - error_callback)); + weak_ptr_factory_.GetWeakPtr(), error_callback)); } protected: @@ -365,6 +340,27 @@ class BluetoothDeviceClientImpl callback.Run(); } + // Called when a response for the GetConnInfo method is received. + void OnGetConnInfoSuccess(const ConnInfoCallback& callback, + dbus::Response* response) { + int16 rssi = kUnknownPower; + int16 transmit_power = kUnknownPower; + int16 max_transmit_power = kUnknownPower; + + if (!response) { + LOG(ERROR) << "GetConnInfo succeeded, but no response received."; + callback.Run(rssi, transmit_power, max_transmit_power); + return; + } + + dbus::MessageReader reader(response); + if (!reader.PopInt16(&rssi) || !reader.PopInt16(&transmit_power) || + !reader.PopInt16(&max_transmit_power)) { + LOG(ERROR) << "Arguments for GetConnInfo invalid."; + } + callback.Run(rssi, transmit_power, max_transmit_power); + } + // Called when a response for a failed method call is received. void OnError(const ErrorCallback& error_callback, dbus::ErrorResponse* response) { diff --git a/chromeos/dbus/bluetooth_device_client.h b/chromeos/dbus/bluetooth_device_client.h index a09b4ef..ec82bde 100644 --- a/chromeos/dbus/bluetooth_device_client.h +++ b/chromeos/dbus/bluetooth_device_client.h @@ -80,20 +80,6 @@ class CHROMEOS_EXPORT BluetoothDeviceClient : public DBusClient { // discovered during inquiry. Read-only. dbus::Property<int16> rssi; - // Received signal strength indicator when a connection is open to the - // device. This property is not set unless connection monitor is enabled. - // Read-only. - dbus::Property<int16> connection_rssi; - - // The transmit power level of the host when a connection is open - // to the device. This property is not set unless connection monitor is - // enabled. Read-only. - dbus::Property<int16> connection_tx_power; - - // The maximum transmit power level of the host that can be set - // when connected to the device. Read-only. - dbus::Property<int16> connection_tx_power_max; - Properties(dbus::ObjectProxy* object_proxy, const std::string& interface_name, const PropertyChangedCallback& callback); @@ -184,18 +170,18 @@ class CHROMEOS_EXPORT BluetoothDeviceClient : public DBusClient { const base::Closure& callback, const ErrorCallback& error_callback) = 0; - // Starts connection monitor for the device with object path - // |object_path|. Connection monitor is a mode the connection properties, - // RSSI and TX power are tracked and updated when they change. - virtual void StartConnectionMonitor(const dbus::ObjectPath& object_path, - const base::Closure& callback, - const ErrorCallback& error_callback) = 0; - - // Stops connection monitor for the device with object path - // |object_path|. - virtual void StopConnectionMonitor(const dbus::ObjectPath& object_path, - const base::Closure& callback, - const ErrorCallback& error_callback) = 0; + // The callback invoked for a successful GetConnInfo API call with the + // RSSI, TX power, and maximum TX power of the current connection. + typedef base::Callback<void(int16 rssi, + int16 transmit_power, + int16 max_transmit_power)> ConnInfoCallback; + + // Returns the RSSI, TX power, and maximum TX power of a connection to the + // device with object path |object_path|. If the device is not connected, then + // an error will be returned. + virtual void GetConnInfo(const dbus::ObjectPath& object_path, + const ConnInfoCallback& callback, + const ErrorCallback& error_callback) = 0; // Creates the instance. static BluetoothDeviceClient* Create(); diff --git a/chromeos/dbus/fake_bluetooth_device_client.cc b/chromeos/dbus/fake_bluetooth_device_client.cc index 87b6591d..325d95e 100644 --- a/chromeos/dbus/fake_bluetooth_device_client.cc +++ b/chromeos/dbus/fake_bluetooth_device_client.cc @@ -44,6 +44,9 @@ const int kSimulationIntervalMs = 750; const int kMinRSSI = -90; const int kMaxRSSI = -30; +// The default value of connection info properties from GetConnInfo(). +const int kUnkownPower = 127; + void SimulatedProfileSocket(int fd) { // Simulate a server-side socket of a profile; read data from the socket, @@ -221,7 +224,9 @@ FakeBluetoothDeviceClient::FakeBluetoothDeviceClient() discovery_simulation_step_(0), incoming_pairing_simulation_step_(0), pairing_cancelled_(false), - connection_monitor_started_(false) { + connection_rssi_(kUnkownPower), + transmit_power_(kUnkownPower), + max_transmit_power_(kUnkownPower) { Properties* properties = new Properties(base::Bind( &FakeBluetoothDeviceClient::OnPropertyChanged, base::Unretained(this), @@ -461,21 +466,17 @@ void FakeBluetoothDeviceClient::CancelPairing( callback.Run(); } -void FakeBluetoothDeviceClient::StartConnectionMonitor( +void FakeBluetoothDeviceClient::GetConnInfo( const dbus::ObjectPath& object_path, - const base::Closure& callback, + const ConnInfoCallback& callback, const ErrorCallback& error_callback) { - VLOG(1) << "StartConnectionMonitor: " << object_path.value(); - connection_monitor_started_ = true; - callback.Run(); -} + Properties* properties = GetProperties(object_path); + if (!properties->connected.value()) { + error_callback.Run("org.bluez.Error.NotConnected", "Not Connected"); + return; + } -void FakeBluetoothDeviceClient::StopConnectionMonitor( - const dbus::ObjectPath& object_path, - const base::Closure& callback, - const ErrorCallback& error_callback) { - connection_monitor_started_ = false; - callback.Run(); + callback.Run(connection_rssi_, transmit_power_, max_transmit_power_); } void FakeBluetoothDeviceClient::BeginDiscoverySimulation( @@ -1019,6 +1020,15 @@ void FakeBluetoothDeviceClient::UpdateDeviceRSSI( properties->rssi.ReplaceValue(rssi); } +void FakeBluetoothDeviceClient::UpdateConnectionInfo( + uint16 connection_rssi, + uint16 transmit_power, + uint16 max_transmit_power) { + connection_rssi_ = connection_rssi; + transmit_power_ = transmit_power; + max_transmit_power_ = max_transmit_power; +} + void FakeBluetoothDeviceClient::PinCodeCallback( const dbus::ObjectPath& object_path, const base::Closure& callback, diff --git a/chromeos/dbus/fake_bluetooth_device_client.h b/chromeos/dbus/fake_bluetooth_device_client.h index 8d476cf..b8e743a 100644 --- a/chromeos/dbus/fake_bluetooth_device_client.h +++ b/chromeos/dbus/fake_bluetooth_device_client.h @@ -69,14 +69,9 @@ class CHROMEOS_EXPORT FakeBluetoothDeviceClient virtual void CancelPairing(const dbus::ObjectPath& object_path, const base::Closure& callback, const ErrorCallback& error_callback) override; - virtual void StartConnectionMonitor( - const dbus::ObjectPath& object_path, - const base::Closure& callback, - const ErrorCallback& error_callback) override; - virtual void StopConnectionMonitor( - const dbus::ObjectPath& object_path, - const base::Closure& callback, - const ErrorCallback& error_callback) override; + void GetConnInfo(const dbus::ObjectPath& object_path, + const ConnInfoCallback& callback, + const ErrorCallback& error_callback) override; void SetSimulationIntervalMs(int interval_ms); @@ -105,6 +100,12 @@ class CHROMEOS_EXPORT FakeBluetoothDeviceClient const base::Closure& callback, const ErrorCallback& error_callback); + // Updates the connection properties of the fake device that will be returned + // by GetConnInfo. + void UpdateConnectionInfo(uint16 connection_rssi, + uint16 transmit_power, + uint16 max_transmit_power); + // Object paths, names, addresses and bluetooth classes of the devices // we can emulate. static const char kPairedDevicePath[]; @@ -250,7 +251,10 @@ class CHROMEOS_EXPORT FakeBluetoothDeviceClient uint32_t discovery_simulation_step_; uint32_t incoming_pairing_simulation_step_; bool pairing_cancelled_; - bool connection_monitor_started_; + + int16 connection_rssi_; + int16 transmit_power_; + int16 max_transmit_power_; }; } // namespace chromeos diff --git a/device/bluetooth/bluetooth_adapter_chromeos.cc b/device/bluetooth/bluetooth_adapter_chromeos.cc index 8472994..68fb9ab 100644 --- a/device/bluetooth/bluetooth_adapter_chromeos.cc +++ b/device/bluetooth/bluetooth_adapter_chromeos.cc @@ -379,9 +379,7 @@ 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->connection_rssi.name() || - property_name == properties->connection_tx_power.name()) + property_name == properties->rssi.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 77027cb..08c353e 100644 --- a/device/bluetooth/bluetooth_chromeos_unittest.cc +++ b/device/bluetooth/bluetooth_chromeos_unittest.cc @@ -143,6 +143,13 @@ class TestObserver : public BluetoothAdapter::Observer { scoped_refptr<BluetoothAdapter> adapter_; }; +// Callback for BluetoothDevice::GetConnectionInfo() that simply saves the +// connection info to the bound argument. +void SaveConnectionInfo(BluetoothDevice::ConnectionInfo* out, + const BluetoothDevice::ConnectionInfo& conn_info) { + *out = conn_info; +}; + } // namespace class TestPairingDelegate : public BluetoothDevice::PairingDelegate { @@ -3272,4 +3279,43 @@ TEST_F(BluetoothChromeOSTest, DeviceId) { EXPECT_EQ(0, device->GetDeviceID()); } +TEST_F(BluetoothChromeOSTest, GetConnectionInfoForDisconnectedDevice) { + GetAdapter(); + BluetoothDevice* device = + adapter_->GetDevice(FakeBluetoothDeviceClient::kPairedDeviceAddress); + + // Calling GetConnectionInfo for an unconnected device should return a result + // in which all fields are filled with BluetoothDevice::kUnknownPower. + BluetoothDevice::ConnectionInfo conn_info(0, 0, 0); + device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info)); + int unknown_power = BluetoothDevice::kUnknownPower; + EXPECT_NE(0, unknown_power); + EXPECT_EQ(unknown_power, conn_info.rssi); + EXPECT_EQ(unknown_power, conn_info.transmit_power); + EXPECT_EQ(unknown_power, conn_info.max_transmit_power); +} + +TEST_F(BluetoothChromeOSTest, GetConnectionInfoForConnectedDevice) { + GetAdapter(); + BluetoothDevice* device = + adapter_->GetDevice(FakeBluetoothDeviceClient::kPairedDeviceAddress); + + device->Connect( + NULL, + base::Bind(&BluetoothChromeOSTest::Callback, + base::Unretained(this)), + base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, + base::Unretained(this))); + EXPECT_TRUE(device->IsConnected()); + + // Calling GetConnectionInfo for a connected device should return valid + // results. + fake_bluetooth_device_client_->UpdateConnectionInfo(-10, 3, 4); + BluetoothDevice::ConnectionInfo conn_info; + device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info)); + EXPECT_EQ(-10, conn_info.rssi); + EXPECT_EQ(3, conn_info.transmit_power); + EXPECT_EQ(4, conn_info.max_transmit_power); +} + } // namespace chromeos diff --git a/device/bluetooth/bluetooth_device.cc b/device/bluetooth/bluetooth_device.cc index 87c1190..1f88d2e 100644 --- a/device/bluetooth/bluetooth_device.cc +++ b/device/bluetooth/bluetooth_device.cc @@ -21,6 +21,19 @@ BluetoothDevice::~BluetoothDevice() { STLDeleteValues(&gatt_services_); } +BluetoothDevice::ConnectionInfo::ConnectionInfo() + : rssi(kUnknownPower), + transmit_power(kUnknownPower), + max_transmit_power(kUnknownPower) {} + +BluetoothDevice::ConnectionInfo::ConnectionInfo( + int rssi, int transmit_power, int max_transmit_power) + : rssi(rssi), + transmit_power(transmit_power), + max_transmit_power(max_transmit_power) {} + +BluetoothDevice::ConnectionInfo::~ConnectionInfo() {} + base::string16 BluetoothDevice::GetName() const { std::string name = GetDeviceName(); if (!name.empty()) { diff --git a/device/bluetooth/bluetooth_device.h b/device/bluetooth/bluetooth_device.h index 0234f17..3c00e44 100644 --- a/device/bluetooth/bluetooth_device.h +++ b/device/bluetooth/bluetooth_device.h @@ -69,6 +69,16 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDevice { // The value returned if the RSSI or transmit power cannot be read. static const int kUnknownPower = 127; + struct ConnectionInfo { + int rssi; + int transmit_power; + int max_transmit_power; + + ConnectionInfo(); + ConnectionInfo(int rssi, int transmit_power, int max_transmit_power); + ~ConnectionInfo(); + }; + // Possible errors passed back to an error callback function in case of a // failed call to Connect(). enum ConnectErrorCode { @@ -204,28 +214,6 @@ class DEVICE_BLUETOOTH_EXPORT 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; @@ -270,6 +258,8 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDevice { // In the success case this callback is not called. typedef base::Callback<void(enum ConnectErrorCode)> ConnectErrorCallback; + typedef base::Callback<void(const ConnectionInfo&)> ConnectionInfoCallback; + // Indicates whether the device is currently pairing and expecting a // PIN Code to be returned. virtual bool ExpectingPinCode() const = 0; @@ -282,6 +272,21 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDevice { // confirmation of a displayed passkey. virtual bool ExpectingConfirmation() const = 0; + // Returns the RSSI and TX power of the active 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. + // + // 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. + // + // If the device isn't connected, then the ConnectionInfo struct passed into + // the callback will be populated with |kUnknownPower|. + virtual void GetConnectionInfo(const ConnectionInfoCallback& callback) = 0; + // Initiates a connection to the device, pairing first if necessary. // // Method calls will be made on the supplied object |pairing_delegate| @@ -385,12 +390,6 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDevice { const GattConnectionCallback& callback, const ConnectErrorCallback& error_callback) = 0; - // Starts monitoring the connection properties, RSSI and TX power. These - // properties will be tracked, and updated when their values change. Exactly - // one of |callback| or |error_callback| will be run. - virtual void StartConnectionMonitor(const base::Closure& callback, - const ErrorCallback& error_callback) = 0; - // Returns the list of discovered GATT services. virtual std::vector<BluetoothGattService*> GetGattServices() const; diff --git a/device/bluetooth/bluetooth_device_chromeos.cc b/device/bluetooth/bluetooth_device_chromeos.cc index 0fe723e..285b1dc 100644 --- a/device/bluetooth/bluetooth_device_chromeos.cc +++ b/device/bluetooth/bluetooth_device_chromeos.cc @@ -212,42 +212,6 @@ uint16 BluetoothDeviceChromeOS::GetDeviceID() const { return device_id; } -int BluetoothDeviceChromeOS::GetRSSI() const { - BluetoothDeviceClient::Properties* properties = - DBusThreadManager::Get()->GetBluetoothDeviceClient()->GetProperties( - object_path_); - DCHECK(properties); - - if (!IsConnected()) { - NOTIMPLEMENTED(); - return kUnknownPower; - } - - return connection_monitor_started_ ? properties->connection_rssi.value() - : kUnknownPower; -} - -int BluetoothDeviceChromeOS::GetCurrentHostTransmitPower() const { - BluetoothDeviceClient::Properties* properties = - DBusThreadManager::Get()->GetBluetoothDeviceClient()->GetProperties( - object_path_); - DCHECK(properties); - - return IsConnected() && connection_monitor_started_ - ? properties->connection_tx_power.value() - : kUnknownPower; -} - -int BluetoothDeviceChromeOS::GetMaximumHostTransmitPower() const { - BluetoothDeviceClient::Properties* properties = - DBusThreadManager::Get()->GetBluetoothDeviceClient()->GetProperties( - object_path_); - DCHECK(properties); - - return IsConnected() ? properties->connection_tx_power_max.value() - : kUnknownPower; -} - bool BluetoothDeviceChromeOS::IsPaired() const { BluetoothDeviceClient::Properties* properties = DBusThreadManager::Get()->GetBluetoothDeviceClient()-> @@ -314,6 +278,17 @@ bool BluetoothDeviceChromeOS::ExpectingConfirmation() const { return pairing_.get() && pairing_->ExpectingConfirmation(); } +void BluetoothDeviceChromeOS::GetConnectionInfo( + const ConnectionInfoCallback& callback) { + // DBus method call should gracefully return an error if the device is not + // currently connected. + DBusThreadManager::Get()->GetBluetoothDeviceClient()->GetConnInfo( + object_path_, base::Bind(&BluetoothDeviceChromeOS::OnGetConnInfo, + weak_ptr_factory_.GetWeakPtr(), callback), + base::Bind(&BluetoothDeviceChromeOS::OnGetConnInfoError, + weak_ptr_factory_.GetWeakPtr(), callback)); +} + void BluetoothDeviceChromeOS::Connect( BluetoothDevice::PairingDelegate* pairing_delegate, const base::Closure& callback, @@ -461,19 +436,6 @@ void BluetoothDeviceChromeOS::CreateGattConnection( error_callback); } -void BluetoothDeviceChromeOS::StartConnectionMonitor( - const base::Closure& callback, - const ErrorCallback& error_callback) { - DBusThreadManager::Get()->GetBluetoothDeviceClient()->StartConnectionMonitor( - object_path_, - base::Bind(&BluetoothDeviceChromeOS::OnStartConnectionMonitor, - weak_ptr_factory_.GetWeakPtr(), - callback), - base::Bind(&BluetoothDeviceChromeOS::OnStartConnectionMonitorError, - weak_ptr_factory_.GetWeakPtr(), - error_callback)); -} - BluetoothPairingChromeOS* BluetoothDeviceChromeOS::BeginPairing( BluetoothDevice::PairingDelegate* pairing_delegate) { pairing_.reset(new BluetoothPairingChromeOS(this, pairing_delegate)); @@ -538,6 +500,24 @@ void BluetoothDeviceChromeOS::GattServiceRemoved( delete service; } +void BluetoothDeviceChromeOS::OnGetConnInfo( + const ConnectionInfoCallback& callback, + int16 rssi, + int16 transmit_power, + int16 max_transmit_power) { + callback.Run(ConnectionInfo(rssi, transmit_power, max_transmit_power)); +} + +void BluetoothDeviceChromeOS::OnGetConnInfoError( + const ConnectionInfoCallback& callback, + const std::string& error_name, + const std::string& error_message) { + LOG(WARNING) << object_path_.value() + << ": Failed to get connection info: " << error_name << ": " + << error_message; + callback.Run(ConnectionInfo()); +} + void BluetoothDeviceChromeOS::ConnectInternal( bool after_pairing, const base::Closure& callback, @@ -681,22 +661,6 @@ void BluetoothDeviceChromeOS::OnSetTrusted(bool success) { << ": Failed to set device as trusted"; } -void BluetoothDeviceChromeOS::OnStartConnectionMonitor( - const base::Closure& callback) { - connection_monitor_started_ = true; - callback.Run(); -} - -void BluetoothDeviceChromeOS::OnStartConnectionMonitorError( - const ErrorCallback& error_callback, - const std::string& error_name, - const std::string& error_message) { - LOG(WARNING) << object_path_.value() - << ": Failed to start connection monitor: " << error_name << ": " - << error_message; - error_callback.Run(); -} - void BluetoothDeviceChromeOS::OnDisconnect(const base::Closure& callback) { VLOG(1) << object_path_.value() << ": Disconnected"; callback.Run(); diff --git a/device/bluetooth/bluetooth_device_chromeos.h b/device/bluetooth/bluetooth_device_chromeos.h index 8e91cd7..dd85355 100644 --- a/device/bluetooth/bluetooth_device_chromeos.h +++ b/device/bluetooth/bluetooth_device_chromeos.h @@ -39,9 +39,6 @@ class DEVICE_BLUETOOTH_EXPORT 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; @@ -50,6 +47,8 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDeviceChromeOS virtual bool ExpectingPinCode() const override; virtual bool ExpectingPasskey() const override; virtual bool ExpectingConfirmation() const override; + void GetConnectionInfo( + const ConnectionInfoCallback& callback) override; virtual void Connect( device::BluetoothDevice::PairingDelegate* pairing_delegate, const base::Closure& callback, @@ -74,9 +73,6 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDeviceChromeOS virtual void CreateGattConnection( const GattConnectionCallback& callback, const ConnectErrorCallback& error_callback) override; - virtual void StartConnectionMonitor( - const base::Closure& callback, - const ErrorCallback& error_callback) override; // Creates a pairing object with the given delegate |pairing_delegate| and // establishes it as the pairing context for this device. All pairing-related @@ -112,6 +108,16 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDeviceChromeOS virtual void GattServiceAdded(const dbus::ObjectPath& object_path) override; virtual void GattServiceRemoved(const dbus::ObjectPath& object_path) override; + // Called by dbus:: on completion of the D-Bus method call to get the + // connection attributes of the current connection to the device. + void OnGetConnInfo(const ConnectionInfoCallback& callback, + int16 rssi, + int16 transmit_power, + int16 max_transmit_power); + void OnGetConnInfoError(const ConnectionInfoCallback& callback, + const std::string& error_name, + const std::string& error_message); + // Internal method to initiate a connection to this device, and methods called // by dbus:: on completion of the D-Bus method call. void ConnectInternal(bool after_pairing, @@ -159,13 +165,6 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDeviceChromeOS const std::string& error_name, const std::string& error_message); - // Called by dbus:: on completion of the D-Bus method call to start the - // connection monitor. - void OnStartConnectionMonitor(const base::Closure& callback); - void OnStartConnectionMonitorError(const ErrorCallback& error_callback, - const std::string& error_name, - const std::string& error_message); - // The adapter that owns this device instance. BluetoothAdapterChromeOS* adapter_; diff --git a/device/bluetooth/bluetooth_device_mac.h b/device/bluetooth/bluetooth_device_mac.h index 8f0ed08..7dd1bae 100644 --- a/device/bluetooth/bluetooth_device_mac.h +++ b/device/bluetooth/bluetooth_device_mac.h @@ -30,9 +30,6 @@ class BluetoothDeviceMac : public BluetoothDevice { uint16 GetVendorID() const override; uint16 GetProductID() const override; uint16 GetDeviceID() const override; - int GetRSSI() const override; - int GetCurrentHostTransmitPower() const override; - int GetMaximumHostTransmitPower() const override; bool IsPaired() const override; bool IsConnected() const override; bool IsConnectable() const override; @@ -41,6 +38,7 @@ class BluetoothDeviceMac : public BluetoothDevice { bool ExpectingPinCode() const override; bool ExpectingPasskey() const override; bool ExpectingConfirmation() const override; + void GetConnectionInfo(const ConnectionInfoCallback& callback) override; void Connect(PairingDelegate* pairing_delegate, const base::Closure& callback, const ConnectErrorCallback& error_callback) override; @@ -63,8 +61,6 @@ class BluetoothDeviceMac : public BluetoothDevice { void CreateGattConnection( const GattConnectionCallback& callback, const ConnectErrorCallback& error_callback) override; - void StartConnectionMonitor(const base::Closure& callback, - const ErrorCallback& error_callback) override; // Returns the timestamp when the device was last seen during an inquiry. // Returns nil if the device has never been seen during an inquiry. diff --git a/device/bluetooth/bluetooth_device_mac.mm b/device/bluetooth/bluetooth_device_mac.mm index 4aad7cf8..536d8d7 100644 --- a/device/bluetooth/bluetooth_device_mac.mm +++ b/device/bluetooth/bluetooth_device_mac.mm @@ -93,30 +93,6 @@ 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]; } @@ -164,6 +140,28 @@ bool BluetoothDeviceMac::ExpectingConfirmation() const { return false; } +void BluetoothDeviceMac::GetConnectionInfo( + const ConnectionInfoCallback& callback) { + ConnectionInfo connection_info; + if (![device_ isConnected]) { + callback.Run(connection_info); + return; + } + + connection_info.rssi = [device_ rawRSSI]; + // The API guarantees that +127 is returned in case the RSSI is not readable: + // http://goo.gl/bpURYv + if (connection_info.rssi == 127) + connection_info.rssi = kUnknownPower; + + connection_info.transmit_power = + GetHostTransmitPower(kReadCurrentTransmitPowerLevel); + connection_info.max_transmit_power = + GetHostTransmitPower(kReadMaximumTransmitPowerLevel); + + callback.Run(connection_info); +} + void BluetoothDeviceMac::Connect( PairingDelegate* pairing_delegate, const base::Closure& callback, @@ -223,12 +221,6 @@ void BluetoothDeviceMac::CreateGattConnection( error_callback.Run(ERROR_UNSUPPORTED_DEVICE); } -void BluetoothDeviceMac::StartConnectionMonitor( - const base::Closure& callback, - const ErrorCallback& error_callback) { - NOTIMPLEMENTED(); -} - NSDate* BluetoothDeviceMac::GetLastInquiryUpdate() { return [device_ getLastInquiryUpdate]; } diff --git a/device/bluetooth/bluetooth_device_win.cc b/device/bluetooth/bluetooth_device_win.cc index a9f690a..1c5cf3c 100644 --- a/device/bluetooth/bluetooth_device_win.cc +++ b/device/bluetooth/bluetooth_device_win.cc @@ -168,21 +168,6 @@ 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_; } @@ -218,6 +203,12 @@ bool BluetoothDeviceWin::ExpectingConfirmation() const { return false; } +void BluetoothDeviceWin::GetConnectionInfo( + const ConnectionInfoCallback& callback) { + NOTIMPLEMENTED(); + callback.Run(ConnectionInfo()); +} + void BluetoothDeviceWin::Connect( PairingDelegate* pairing_delegate, const base::Closure& callback, @@ -279,12 +270,6 @@ void BluetoothDeviceWin::CreateGattConnection( error_callback.Run(ERROR_UNSUPPORTED_DEVICE); } -void BluetoothDeviceWin::StartConnectionMonitor( - const base::Closure& callback, - const ErrorCallback& error_callback) { - NOTIMPLEMENTED(); -} - const BluetoothServiceRecordWin* BluetoothDeviceWin::GetServiceRecord( const device::BluetoothUUID& uuid) const { for (ServiceRecordList::const_iterator iter = service_record_list_.begin(); diff --git a/device/bluetooth/bluetooth_device_win.h b/device/bluetooth/bluetooth_device_win.h index 6394cfa..ee36d37 100644 --- a/device/bluetooth/bluetooth_device_win.h +++ b/device/bluetooth/bluetooth_device_win.h @@ -37,9 +37,6 @@ class DEVICE_BLUETOOTH_EXPORT 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; @@ -48,6 +45,8 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDeviceWin : public BluetoothDevice { virtual bool ExpectingPinCode() const override; virtual bool ExpectingPasskey() const override; virtual bool ExpectingConfirmation() const override; + virtual void GetConnectionInfo( + const ConnectionInfoCallback& callback) override; virtual void Connect( PairingDelegate* pairing_delegate, const base::Closure& callback, @@ -72,9 +71,6 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDeviceWin : public BluetoothDevice { virtual void CreateGattConnection( const GattConnectionCallback& callback, const ConnectErrorCallback& error_callback) override; - virtual void StartConnectionMonitor( - const base::Closure& callback, - const ErrorCallback& error_callback) override; // Used by BluetoothProfileWin to retrieve the service record for the given // |uuid|. diff --git a/device/bluetooth/test/mock_bluetooth_device.cc b/device/bluetooth/test/mock_bluetooth_device.cc index e8130da..5235d5b 100644 --- a/device/bluetooth/test/mock_bluetooth_device.cc +++ b/device/bluetooth/test/mock_bluetooth_device.cc @@ -26,12 +26,6 @@ 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 6ec0af4..c0e8b0b 100644 --- a/device/bluetooth/test/mock_bluetooth_device.h +++ b/device/bluetooth/test/mock_bluetooth_device.h @@ -35,9 +35,6 @@ 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()); @@ -46,6 +43,7 @@ class MockBluetoothDevice : public BluetoothDevice { MOCK_CONST_METHOD0(ExpectingPinCode, bool()); MOCK_CONST_METHOD0(ExpectingPasskey, bool()); MOCK_CONST_METHOD0(ExpectingConfirmation, bool()); + MOCK_METHOD1(GetConnectionInfo, void(const ConnectionInfoCallback& callback)); MOCK_METHOD3(Connect, void(BluetoothDevice::PairingDelegate* pairing_delegate, const base::Closure& callback, diff --git a/extensions/browser/api/bluetooth/bluetooth_api_utils.cc b/extensions/browser/api/bluetooth/bluetooth_api_utils.cc index 58a5d0a..05bd0765 100644 --- a/extensions/browser/api/bluetooth/bluetooth_api_utils.cc +++ b/extensions/browser/api/bluetooth/bluetooth_api_utils.cc @@ -112,19 +112,6 @@ 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/extensions/browser/api/bluetooth/bluetooth_apitest.cc b/extensions/browser/api/bluetooth/bluetooth_apitest.cc index 694a46d..0a78e1b 100644 --- a/extensions/browser/api/bluetooth/bluetooth_apitest.cc +++ b/extensions/browser/api/bluetooth/bluetooth_apitest.cc @@ -427,11 +427,6 @@ 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/extensions/common/api/bluetooth.idl b/extensions/common/api/bluetooth.idl index 1febc8b..9e19443 100644 --- a/extensions/common/api/bluetooth.idl +++ b/extensions/common/api/bluetooth.idl @@ -65,23 +65,6 @@ 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. - [nodoc] 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. - [nodoc] 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. - [nodoc] 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 |