diff options
author | keybuk@chromium.org <keybuk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-11 22:44:48 +0000 |
---|---|---|
committer | keybuk@chromium.org <keybuk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-11 22:44:48 +0000 |
commit | c8154319793257327d61d505dbccac9f5917d16b (patch) | |
tree | 3538b3f18c8e9f3111e4f4cafa47a7842c9106e4 /device | |
parent | cb84ed9d9ef538a84eec01015ca3017fac9bd86e (diff) | |
download | chromium_src-c8154319793257327d61d505dbccac9f5917d16b.zip chromium_src-c8154319793257327d61d505dbccac9f5917d16b.tar.gz chromium_src-c8154319793257327d61d505dbccac9f5917d16b.tar.bz2 |
Add BluetoothDevice::VendorIDSource()
The Vendor ID of a device can be either allocated by the Bluetooth SIG
or USB IF, providing two completely seperate overlapping namespaces for
identifiers.
In order to distinguish which vendor an identifier represents, add a
VendorIDSource() method to BluetoothDevice that returns BLUETOOTH or
USB respectively.
Add to the metrics collection as well.
BUG=350432
TEST=device_unittests
R=armansito@chromium.org, isherman@chromium.org
Review URL: https://codereview.chromium.org/191223003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@256344 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device')
-rw-r--r-- | device/bluetooth/bluetooth_chromeos_unittest.cc | 6 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device.h | 13 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_chromeos.cc | 44 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_chromeos.h | 1 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_mac.h | 1 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_mac.mm | 5 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_win.cc | 5 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_win.h | 1 | ||||
-rw-r--r-- | device/bluetooth/test/mock_bluetooth_device.h | 1 |
9 files changed, 63 insertions, 14 deletions
diff --git a/device/bluetooth/bluetooth_chromeos_unittest.cc b/device/bluetooth/bluetooth_chromeos_unittest.cc index de0f75d..d24ad94 100644 --- a/device/bluetooth/bluetooth_chromeos_unittest.cc +++ b/device/bluetooth/bluetooth_chromeos_unittest.cc @@ -1451,6 +1451,7 @@ TEST_F(BluetoothChromeOSTest, DeviceProperties) { EXPECT_EQ(uuids[0], "00001800-0000-1000-8000-00805f9b34fb"); EXPECT_EQ(uuids[1], "00001801-0000-1000-8000-00805f9b34fb"); + EXPECT_EQ(BluetoothDevice::VENDOR_ID_USB, devices[0]->GetVendorIDSource()); EXPECT_EQ(0x05ac, devices[0]->GetVendorID()); EXPECT_EQ(0x030d, devices[0]->GetProductID()); EXPECT_EQ(0x0306, devices[0]->GetDeviceID()); @@ -3104,6 +3105,7 @@ TEST_F(BluetoothChromeOSTest, DeviceId) { // Valid USB IF-assigned identifier. ASSERT_EQ("usb:v05ACp030Dd0306", properties->modalias.value()); + EXPECT_EQ(BluetoothDevice::VENDOR_ID_USB, device->GetVendorIDSource()); EXPECT_EQ(0x05ac, device->GetVendorID()); EXPECT_EQ(0x030d, device->GetProductID()); EXPECT_EQ(0x0306, device->GetDeviceID()); @@ -3111,6 +3113,7 @@ TEST_F(BluetoothChromeOSTest, DeviceId) { // Valid Bluetooth SIG-assigned identifier. properties->modalias.ReplaceValue("bluetooth:v00E0p2400d0400"); + EXPECT_EQ(BluetoothDevice::VENDOR_ID_BLUETOOTH, device->GetVendorIDSource()); EXPECT_EQ(0x00e0, device->GetVendorID()); EXPECT_EQ(0x2400, device->GetProductID()); EXPECT_EQ(0x0400, device->GetDeviceID()); @@ -3118,6 +3121,7 @@ TEST_F(BluetoothChromeOSTest, DeviceId) { // Invalid USB IF-assigned identifier. properties->modalias.ReplaceValue("usb:x00E0p2400d0400"); + EXPECT_EQ(BluetoothDevice::VENDOR_ID_UNKNOWN, device->GetVendorIDSource()); EXPECT_EQ(0, device->GetVendorID()); EXPECT_EQ(0, device->GetProductID()); EXPECT_EQ(0, device->GetDeviceID()); @@ -3125,6 +3129,7 @@ TEST_F(BluetoothChromeOSTest, DeviceId) { // Invalid Bluetooth SIG-assigned identifier. properties->modalias.ReplaceValue("bluetooth:x00E0p2400d0400"); + EXPECT_EQ(BluetoothDevice::VENDOR_ID_UNKNOWN, device->GetVendorIDSource()); EXPECT_EQ(0, device->GetVendorID()); EXPECT_EQ(0, device->GetProductID()); EXPECT_EQ(0, device->GetDeviceID()); @@ -3132,6 +3137,7 @@ TEST_F(BluetoothChromeOSTest, DeviceId) { // Unknown vendor specification identifier. properties->modalias.ReplaceValue("chrome:v00E0p2400d0400"); + EXPECT_EQ(BluetoothDevice::VENDOR_ID_UNKNOWN, device->GetVendorIDSource()); EXPECT_EQ(0, device->GetVendorID()); EXPECT_EQ(0, device->GetProductID()); EXPECT_EQ(0, device->GetDeviceID()); diff --git a/device/bluetooth/bluetooth_device.h b/device/bluetooth/bluetooth_device.h index 48df49f..cb1e7ec 100644 --- a/device/bluetooth/bluetooth_device.h +++ b/device/bluetooth/bluetooth_device.h @@ -33,6 +33,15 @@ struct BluetoothOutOfBandPairingData; // for devices coming and going, as well as properties being updated. class BluetoothDevice { public: + // Possible values that may be returned by GetVendorIDSource(), + // indicating different organisations that allocate the identifiers returned + // by GetVendorID(). + enum VendorIDSource { + VENDOR_ID_UNKNOWN, + VENDOR_ID_BLUETOOTH, + VENDOR_ID_USB + }; + // Possible values that may be returned by GetDeviceType(), representing // different types of bluetooth device that we support or are aware of // decoded from the bluetooth class information. @@ -175,6 +184,10 @@ class BluetoothDevice { // a unique key to identify the device and copied where needed. virtual std::string GetAddress() const = 0; + // Returns the allocation source of the identifier returned by GetVendorID(), + // where available, or VENDOR_ID_UNKNOWN where not. + virtual VendorIDSource GetVendorIDSource() const = 0; + // Returns the Vendor ID of the device, where available. virtual uint16 GetVendorID() const = 0; diff --git a/device/bluetooth/bluetooth_device_chromeos.cc b/device/bluetooth/bluetooth_device_chromeos.cc index 27ab143..d68fd0b 100644 --- a/device/bluetooth/bluetooth_device_chromeos.cc +++ b/device/bluetooth/bluetooth_device_chromeos.cc @@ -42,28 +42,37 @@ enum UMAPairingResult { }; void ParseModalias(const dbus::ObjectPath& object_path, - uint16 *vendor_id, - uint16 *product_id, - uint16 *device_id) { + BluetoothDevice::VendorIDSource* vendor_id_source, + uint16* vendor_id, + uint16* product_id, + uint16* device_id) { chromeos::BluetoothDeviceClient::Properties* properties = chromeos::DBusThreadManager::Get()->GetBluetoothDeviceClient()-> GetProperties(object_path); DCHECK(properties); std::string modalias = properties->modalias.value(); + BluetoothDevice::VendorIDSource source_value; int vendor_value, product_value, device_value; if (sscanf(modalias.c_str(), "bluetooth:v%04xp%04xd%04x", - &vendor_value, &product_value, &device_value) == 3 || - sscanf(modalias.c_str(), "usb:v%04xp%04xd%04x", &vendor_value, &product_value, &device_value) == 3) { - if (vendor_id != NULL) - *vendor_id = vendor_value; - if (product_id != NULL) - *product_id = product_value; - if (device_id != NULL) - *device_id = device_value; + source_value = BluetoothDevice::VENDOR_ID_BLUETOOTH; + } else if (sscanf(modalias.c_str(), "usb:v%04xp%04xd%04x", + &vendor_value, &product_value, &device_value) == 3) { + source_value = BluetoothDevice::VENDOR_ID_USB; + } else { + return; } + + if (vendor_id_source != NULL) + *vendor_id_source = source_value; + if (vendor_id != NULL) + *vendor_id = vendor_value; + if (product_id != NULL) + *product_id = product_value; + if (device_id != NULL) + *device_id = device_value; } void RecordPairingResult(BluetoothDevice::ConnectErrorCode error_code) { @@ -142,21 +151,28 @@ std::string BluetoothDeviceChromeOS::GetAddress() const { return properties->address.value(); } +BluetoothDevice::VendorIDSource +BluetoothDeviceChromeOS::GetVendorIDSource() const { + VendorIDSource vendor_id_source = VENDOR_ID_UNKNOWN; + ParseModalias(object_path_, &vendor_id_source, NULL, NULL, NULL); + return vendor_id_source; +} + uint16 BluetoothDeviceChromeOS::GetVendorID() const { uint16 vendor_id = 0; - ParseModalias(object_path_, &vendor_id, NULL, NULL); + ParseModalias(object_path_, NULL, &vendor_id, NULL, NULL); return vendor_id; } uint16 BluetoothDeviceChromeOS::GetProductID() const { uint16 product_id = 0; - ParseModalias(object_path_, NULL, &product_id, NULL); + ParseModalias(object_path_, NULL, NULL, &product_id, NULL); return product_id; } uint16 BluetoothDeviceChromeOS::GetDeviceID() const { uint16 device_id = 0; - ParseModalias(object_path_, NULL, NULL, &device_id); + ParseModalias(object_path_, NULL, NULL, NULL, &device_id); return device_id; } diff --git a/device/bluetooth/bluetooth_device_chromeos.h b/device/bluetooth/bluetooth_device_chromeos.h index 797f66e..bc94c3c 100644 --- a/device/bluetooth/bluetooth_device_chromeos.h +++ b/device/bluetooth/bluetooth_device_chromeos.h @@ -26,6 +26,7 @@ class BluetoothDeviceChromeOS // BluetoothDevice override virtual uint32 GetBluetoothClass() const OVERRIDE; virtual std::string GetAddress() const OVERRIDE; + virtual VendorIDSource GetVendorIDSource() const OVERRIDE; virtual uint16 GetVendorID() const OVERRIDE; virtual uint16 GetProductID() const OVERRIDE; virtual uint16 GetDeviceID() const OVERRIDE; diff --git a/device/bluetooth/bluetooth_device_mac.h b/device/bluetooth/bluetooth_device_mac.h index bc887b9..bc3ce19 100644 --- a/device/bluetooth/bluetooth_device_mac.h +++ b/device/bluetooth/bluetooth_device_mac.h @@ -26,6 +26,7 @@ class BluetoothDeviceMac : public BluetoothDevice { // BluetoothDevice override virtual uint32 GetBluetoothClass() const OVERRIDE; virtual std::string GetAddress() const OVERRIDE; + virtual VendorIDSource GetVendorIDSource() const OVERRIDE; virtual uint16 GetVendorID() const OVERRIDE; virtual uint16 GetProductID() const OVERRIDE; virtual uint16 GetDeviceID() const OVERRIDE; diff --git a/device/bluetooth/bluetooth_device_mac.mm b/device/bluetooth/bluetooth_device_mac.mm index 39acbef..50762d2 100644 --- a/device/bluetooth/bluetooth_device_mac.mm +++ b/device/bluetooth/bluetooth_device_mac.mm @@ -82,6 +82,11 @@ std::string BluetoothDeviceMac::GetAddress() const { return base::SysNSStringToUTF8([device_ addressString]); } +BluetoothDevice::VendorIDSource +BluetoothDeviceMac::GetVendorIDSource() const { + return VENDOR_ID_UNKNOWN; +} + uint16 BluetoothDeviceMac::GetVendorID() const { return 0; } diff --git a/device/bluetooth/bluetooth_device_win.cc b/device/bluetooth/bluetooth_device_win.cc index bfd9bc6..3f95efd 100644 --- a/device/bluetooth/bluetooth_device_win.cc +++ b/device/bluetooth/bluetooth_device_win.cc @@ -71,6 +71,11 @@ std::string BluetoothDeviceWin::GetAddress() const { return address_; } +BluetoothDevice::VendorIDSource +BluetoothDeviceWin::GetVendorIDSource() const { + return VENDOR_ID_UNKNOWN; +} + uint16 BluetoothDeviceWin::GetVendorID() const { return 0; } diff --git a/device/bluetooth/bluetooth_device_win.h b/device/bluetooth/bluetooth_device_win.h index 452f6f2..274364b 100644 --- a/device/bluetooth/bluetooth_device_win.h +++ b/device/bluetooth/bluetooth_device_win.h @@ -26,6 +26,7 @@ class BluetoothDeviceWin : public BluetoothDevice { // BluetoothDevice override virtual uint32 GetBluetoothClass() const OVERRIDE; virtual std::string GetAddress() const OVERRIDE; + virtual VendorIDSource GetVendorIDSource() const OVERRIDE; virtual uint16 GetVendorID() const OVERRIDE; virtual uint16 GetProductID() const OVERRIDE; virtual uint16 GetDeviceID() const OVERRIDE; diff --git a/device/bluetooth/test/mock_bluetooth_device.h b/device/bluetooth/test/mock_bluetooth_device.h index de2907d..bc028e5 100644 --- a/device/bluetooth/test/mock_bluetooth_device.h +++ b/device/bluetooth/test/mock_bluetooth_device.h @@ -29,6 +29,7 @@ class MockBluetoothDevice : public BluetoothDevice { MOCK_CONST_METHOD0(GetBluetoothClass, uint32()); MOCK_CONST_METHOD0(GetDeviceName, std::string()); MOCK_CONST_METHOD0(GetAddress, std::string()); + MOCK_CONST_METHOD0(GetVendorIDSource, BluetoothDevice::VendorIDSource()); MOCK_CONST_METHOD0(GetVendorID, uint16()); MOCK_CONST_METHOD0(GetProductID, uint16()); MOCK_CONST_METHOD0(GetDeviceID, uint16()); |