Commit c3ef9171 authored by horo@chromium.org's avatar horo@chromium.org

Revert 282212 "Retrieve "connected" property from BLE devices."

Tests on XP are failing. 

http://build.chromium.org/p/chromium.win/builders/XP%20Tests%20%282%29/builds/34594 
http://build.chromium.org/p/chromium.win/builders/XP%20Tests%20%282%29

We should use LoadLibrary and GetProcAddress to call SetupDIGetDeviceProperty
because it is not available in WinXP.

> Retrieve "connected" property from BLE devices.
> 
> We have to use the SetupDIGetDeviceProperty API to retrieve this specific property, as the "connected" status is something common to many PnP devices.
> 
> BUG=388016
> 
> Review URL: https://codereview.chromium.org/379943003

TBR=rpaquay@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282295 0039d316-1c4b-4281-b951-d872f2087c98
parent 192ad7eb
...@@ -4,10 +4,6 @@ ...@@ -4,10 +4,6 @@
#include "device/bluetooth/bluetooth_low_energy_win.h" #include "device/bluetooth/bluetooth_low_energy_win.h"
#include <cfg.h>
#define INITGUID // For DEVPKEY_Xxxx guid/pid pairs
#include <devpkey.h>
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/win/windows_version.h" #include "base/win/windows_version.h"
...@@ -15,7 +11,6 @@ ...@@ -15,7 +11,6 @@
namespace { namespace {
using device::win::DeviceRegistryPropertyValue; using device::win::DeviceRegistryPropertyValue;
using device::win::DevicePropertyValue;
const char kPlatformNotSupported[] = const char kPlatformNotSupported[] =
"Bluetooth Low energy is only supported on Windows 8 and later."; "Bluetooth Low energy is only supported on Windows 8 and later.";
...@@ -130,47 +125,6 @@ bool CheckExpectedLength(size_t actual_length, ...@@ -130,47 +125,6 @@ bool CheckExpectedLength(size_t actual_length,
return true; return true;
} }
bool CollectBluetoothLowEnergyDeviceProperty(
const ScopedDeviceInfoSetHandle& device_info_handle,
PSP_DEVINFO_DATA device_info_data,
const DEVPROPKEY& key,
scoped_ptr<DevicePropertyValue>* value,
std::string* error) {
DWORD required_length;
DEVPROPTYPE prop_type;
BOOL success = SetupDiGetDeviceProperty(device_info_handle,
device_info_data,
&key,
&prop_type,
NULL,
0,
&required_length,
0);
if (!CheckInsufficientBuffer(!!success, kDeviceInfoError, error))
return false;
scoped_ptr<uint8_t[]> prop_value(new uint8_t[required_length]);
DWORD actual_length = required_length;
success = SetupDiGetDeviceProperty(device_info_handle,
device_info_data,
&key,
&prop_type,
prop_value.get(),
actual_length,
&required_length,
0);
if (!CheckSuccess(!!success, kDeviceInfoError, error))
return false;
if (!CheckExpectedLength(
actual_length, required_length, kDeviceInfoError, error)) {
return false;
}
(*value) = scoped_ptr<DevicePropertyValue>(
new DevicePropertyValue(prop_type, prop_value.Pass(), actual_length));
return true;
}
bool CollectBluetoothLowEnergyDeviceRegistryProperty( bool CollectBluetoothLowEnergyDeviceRegistryProperty(
const ScopedDeviceInfoSetHandle& device_info_handle, const ScopedDeviceInfoSetHandle& device_info_handle,
PSP_DEVINFO_DATA device_info_data, PSP_DEVINFO_DATA device_info_data,
...@@ -188,7 +142,7 @@ bool CollectBluetoothLowEnergyDeviceRegistryProperty( ...@@ -188,7 +142,7 @@ bool CollectBluetoothLowEnergyDeviceRegistryProperty(
if (!CheckInsufficientBuffer(!!success, kDeviceInfoError, error)) if (!CheckInsufficientBuffer(!!success, kDeviceInfoError, error))
return false; return false;
scoped_ptr<uint8_t[]> property_value(new uint8_t[required_length]); scoped_ptr<UINT8[]> property_value(new UINT8[required_length]);
ULONG actual_length = required_length; ULONG actual_length = required_length;
DWORD property_type; DWORD property_type;
success = SetupDiGetDeviceRegistryProperty(device_info_handle, success = SetupDiGetDeviceRegistryProperty(device_info_handle,
...@@ -201,9 +155,8 @@ bool CollectBluetoothLowEnergyDeviceRegistryProperty( ...@@ -201,9 +155,8 @@ bool CollectBluetoothLowEnergyDeviceRegistryProperty(
if (!CheckSuccess(!!success, kDeviceInfoError, error)) if (!CheckSuccess(!!success, kDeviceInfoError, error))
return false; return false;
if (!CheckExpectedLength( if (!CheckExpectedLength(
actual_length, required_length, kDeviceInfoError, error)) { actual_length, required_length, kDeviceInfoError, error))
return false; return false;
}
(*value) = DeviceRegistryPropertyValue::Create( (*value) = DeviceRegistryPropertyValue::Create(
property_type, property_value.Pass(), actual_length).Pass(); property_type, property_value.Pass(), actual_length).Pass();
...@@ -302,29 +255,6 @@ bool CollectBluetoothLowEnergyDeviceAddress( ...@@ -302,29 +255,6 @@ bool CollectBluetoothLowEnergyDeviceAddress(
device_info->id, &device_info->address, error); device_info->id, &device_info->address, error);
} }
bool CollectBluetoothLowEnergyDeviceStatus(
const ScopedDeviceInfoSetHandle& device_info_handle,
PSP_DEVINFO_DATA device_info_data,
scoped_ptr<device::win::BluetoothLowEnergyDeviceInfo>& device_info,
std::string* error) {
scoped_ptr<DevicePropertyValue> value;
if (!CollectBluetoothLowEnergyDeviceProperty(device_info_handle,
device_info_data,
DEVPKEY_Device_DevNodeStatus,
&value,
error)) {
return false;
}
if (value->property_type() != DEVPROP_TYPE_UINT32) {
*error = kDeviceInfoError;
return false;
}
device_info->connected = !(value->AsUint32() & DN_DEVICE_DISCONNECTED);
return true;
}
bool CollectBluetoothLowEnergyDeviceInfo( bool CollectBluetoothLowEnergyDeviceInfo(
const ScopedDeviceInfoSetHandle& device_info_handle, const ScopedDeviceInfoSetHandle& device_info_handle,
PSP_DEVICE_INTERFACE_DATA device_interface_data, PSP_DEVICE_INTERFACE_DATA device_interface_data,
...@@ -341,7 +271,7 @@ bool CollectBluetoothLowEnergyDeviceInfo( ...@@ -341,7 +271,7 @@ bool CollectBluetoothLowEnergyDeviceInfo(
if (!CheckInsufficientBuffer(!!success, kDeviceInfoError, error)) if (!CheckInsufficientBuffer(!!success, kDeviceInfoError, error))
return false; return false;
scoped_ptr<uint8_t[]> interface_data(new uint8_t[required_length]); scoped_ptr<UINT8[]> interface_data(new UINT8[required_length]);
ZeroMemory(interface_data.get(), required_length); ZeroMemory(interface_data.get(), required_length);
PSP_DEVICE_INTERFACE_DETAIL_DATA device_interface_detail_data = PSP_DEVICE_INTERFACE_DETAIL_DATA device_interface_detail_data =
...@@ -362,9 +292,8 @@ bool CollectBluetoothLowEnergyDeviceInfo( ...@@ -362,9 +292,8 @@ bool CollectBluetoothLowEnergyDeviceInfo(
if (!CheckSuccess(!!success, kDeviceInfoError, error)) if (!CheckSuccess(!!success, kDeviceInfoError, error))
return false; return false;
if (!CheckExpectedLength( if (!CheckExpectedLength(
actual_length, required_length, kDeviceInfoError, error)) { actual_length, required_length, kDeviceInfoError, error))
return false; return false;
}
scoped_ptr<device::win::BluetoothLowEnergyDeviceInfo> result( scoped_ptr<device::win::BluetoothLowEnergyDeviceInfo> result(
new device::win::BluetoothLowEnergyDeviceInfo()); new device::win::BluetoothLowEnergyDeviceInfo());
...@@ -382,10 +311,6 @@ bool CollectBluetoothLowEnergyDeviceInfo( ...@@ -382,10 +311,6 @@ bool CollectBluetoothLowEnergyDeviceInfo(
device_info_handle, &device_info_data, result, error)) { device_info_handle, &device_info_data, result, error)) {
return false; return false;
} }
if (!CollectBluetoothLowEnergyDeviceStatus(
device_info_handle, &device_info_data, result, error)) {
return false;
}
(*device_info) = result.Pass(); (*device_info) = result.Pass();
return true; return true;
} }
...@@ -397,7 +322,7 @@ DeviceInfoResult EnumerateSingleBluetoothLowEnergyDevice( ...@@ -397,7 +322,7 @@ DeviceInfoResult EnumerateSingleBluetoothLowEnergyDevice(
DWORD device_index, DWORD device_index,
scoped_ptr<device::win::BluetoothLowEnergyDeviceInfo>* device_info, scoped_ptr<device::win::BluetoothLowEnergyDeviceInfo>* device_info,
std::string* error) { std::string* error) {
// Enumerate device of BLUETOOTHLE_DEVICE interface class // Enumerate device of LE_DEVICE interface class
GUID BluetoothInterfaceGUID = GUID_BLUETOOTHLE_DEVICE_INTERFACE; GUID BluetoothInterfaceGUID = GUID_BLUETOOTHLE_DEVICE_INTERFACE;
SP_DEVICE_INTERFACE_DATA device_interface_data = {0}; SP_DEVICE_INTERFACE_DATA device_interface_data = {0};
device_interface_data.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); device_interface_data.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
...@@ -416,9 +341,8 @@ DeviceInfoResult EnumerateSingleBluetoothLowEnergyDevice( ...@@ -416,9 +341,8 @@ DeviceInfoResult EnumerateSingleBluetoothLowEnergyDevice(
} }
if (!CollectBluetoothLowEnergyDeviceInfo( if (!CollectBluetoothLowEnergyDeviceInfo(
device_info_handle, &device_interface_data, device_info, error)) { device_info_handle, &device_interface_data, device_info, error))
return kError; return kError;
}
return kOk; return kOk;
} }
...@@ -504,28 +428,6 @@ DWORD DeviceRegistryPropertyValue::AsDWORD() const { ...@@ -504,28 +428,6 @@ DWORD DeviceRegistryPropertyValue::AsDWORD() const {
return *value; return *value;
} }
DevicePropertyValue::DevicePropertyValue(DEVPROPTYPE property_type,
scoped_ptr<uint8_t[]> value,
size_t value_size)
: property_type_(property_type),
value_(value.Pass()),
value_size_(value_size) {
}
uint32_t DevicePropertyValue::AsUint32() const {
CHECK_EQ(property_type_, static_cast<DEVPROPTYPE>(DEVPROP_TYPE_UINT32));
CHECK_EQ(value_size_, sizeof(uint32_t));
return *reinterpret_cast<uint32_t*>(value_.get());
}
BluetoothLowEnergyDeviceInfo::BluetoothLowEnergyDeviceInfo()
: connected(false) {
address.ullLong = BLUETOOTH_NULL_ADDRESS;
}
BluetoothLowEnergyDeviceInfo::~BluetoothLowEnergyDeviceInfo() {
}
bool IsBluetoothLowEnergySupported() { bool IsBluetoothLowEnergySupported() {
return base::win::GetVersion() >= base::win::VERSION_WIN8; return base::win::GetVersion() >= base::win::VERSION_WIN8;
} }
......
...@@ -53,8 +53,7 @@ class DeviceRegistryPropertyValue { ...@@ -53,8 +53,7 @@ class DeviceRegistryPropertyValue {
// Creates a property value instance, where |property_type| is one of REG_xxx // Creates a property value instance, where |property_type| is one of REG_xxx
// registry value type (e.g. REG_SZ, REG_DWORD), |value| is a byte array // registry value type (e.g. REG_SZ, REG_DWORD), |value| is a byte array
// containing the propery value and |value_size| is the number of bytes in // containing the propery value and |value_size| is the number of bytes in
// |value|. Note the returned instance takes ownership of the bytes in // |value|. Note the returned instance takes ownership of |value| array.
// |value|.
static scoped_ptr<DeviceRegistryPropertyValue> Create( static scoped_ptr<DeviceRegistryPropertyValue> Create(
DWORD property_type, DWORD property_type,
scoped_ptr<uint8_t[]> value, scoped_ptr<uint8_t[]> value,
...@@ -79,41 +78,16 @@ class DeviceRegistryPropertyValue { ...@@ -79,41 +78,16 @@ class DeviceRegistryPropertyValue {
DISALLOW_COPY_AND_ASSIGN(DeviceRegistryPropertyValue); DISALLOW_COPY_AND_ASSIGN(DeviceRegistryPropertyValue);
}; };
// Represents the value associated to a DEVPROPKEY.
class DevicePropertyValue {
public:
// Creates a property value instance, where |property_type| is one of
// DEVPROP_TYPE_xxx value type , |value| is a byte array containing the
// propery value and |value_size| is the number of bytes in |value|. Note the
// returned instance takes ownership of the bytes in |value|.
DevicePropertyValue(DEVPROPTYPE property_type,
scoped_ptr<uint8_t[]> value,
size_t value_size);
DEVPROPTYPE property_type() const { return property_type_; }
uint32_t AsUint32() const;
private:
DEVPROPTYPE property_type_;
scoped_ptr<uint8_t[]> value_;
size_t value_size_;
DISALLOW_COPY_AND_ASSIGN(DevicePropertyValue);
};
// Returns true only on Windows platforms supporting Bluetooth Low Energy. // Returns true only on Windows platforms supporting Bluetooth Low Energy.
bool IsBluetoothLowEnergySupported(); bool IsBluetoothLowEnergySupported();
struct BluetoothLowEnergyDeviceInfo { struct BluetoothLowEnergyDeviceInfo {
BluetoothLowEnergyDeviceInfo(); BluetoothLowEnergyDeviceInfo() { address.ullLong = BLUETOOTH_NULL_ADDRESS; }
~BluetoothLowEnergyDeviceInfo();
base::FilePath path; base::FilePath path;
std::string id; std::string id;
std::string friendly_name; std::string friendly_name;
BLUETOOTH_ADDRESS address; BLUETOOTH_ADDRESS address;
bool connected;
}; };
// Enumerates the list of known (i.e. already paired) Bluetooth LE devices on // Enumerates the list of known (i.e. already paired) Bluetooth LE devices on
......
...@@ -71,15 +71,4 @@ TEST_F(BluetoothLowEnergyWinTest, DeviceRegistryPropertyValueAsDWORD) { ...@@ -71,15 +71,4 @@ TEST_F(BluetoothLowEnergyWinTest, DeviceRegistryPropertyValueAsDWORD) {
EXPECT_EQ(test_value, value->AsDWORD()); EXPECT_EQ(test_value, value->AsDWORD());
} }
TEST_F(BluetoothLowEnergyWinTest, DevicePropertyValueAsUint32) {
uint32_t test_value = 5u;
size_t buffer_size = sizeof(uint32_t);
scoped_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]);
memcpy(buffer.get(), &test_value, buffer_size);
scoped_ptr<device::win::DevicePropertyValue> value(
new device::win::DevicePropertyValue(
DEVPROP_TYPE_UINT32, buffer.Pass(), buffer_size));
EXPECT_EQ(test_value, value->AsUint32());
}
} // namespace device } // namespace device
...@@ -406,7 +406,6 @@ void BluetoothTaskManagerWin::GetKnownDevices() { ...@@ -406,7 +406,6 @@ void BluetoothTaskManagerWin::GetKnownDevices() {
DeviceState* device_state = new DeviceState(); DeviceState* device_state = new DeviceState();
device_state->name = device_info->friendly_name; device_state->name = device_info->friendly_name;
device_state->address = BluetoothAddressToString(device_info->address); device_state->address = BluetoothAddressToString(device_info->address);
device_state->connected = device_info->connected;
device_list->push_back(device_state); device_list->push_back(device_state);
} }
} }
......
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