| Index: device/bluetooth/bluetooth_device_mac.mm
|
| diff --git a/device/bluetooth/bluetooth_device_mac.mm b/device/bluetooth/bluetooth_device_mac.mm
|
| index 60574b040c30b88738dc67db2c4a853261a0e803..6ec64992eabad12e14bb848612e6dd02b159a029 100644
|
| --- a/device/bluetooth/bluetooth_device_mac.mm
|
| +++ b/device/bluetooth/bluetooth_device_mac.mm
|
| @@ -11,7 +11,6 @@
|
| #include "base/sequenced_task_runner.h"
|
| #include "base/strings/string_number_conversions.h"
|
| #include "base/strings/string_util.h"
|
| -#include "base/strings/stringprintf.h"
|
| #include "base/strings/sys_string_conversions.h"
|
| #include "device/bluetooth/bluetooth_profile_mac.h"
|
| #include "device/bluetooth/bluetooth_socket_mac.h"
|
| @@ -40,10 +39,12 @@
|
| outTransmitPowerLevel:(BluetoothHCITransmitPowerLevel*)level;
|
| @end
|
|
|
| +namespace device {
|
| namespace {
|
|
|
| -void ExtractUuid(IOBluetoothSDPDataElement* service_class_data,
|
| - std::string* uuid) {
|
| +// Returns the first (should be, only) UUID contained within the
|
| +// |service_class_data|. Returns an invalid (empty) UUID if none is found.
|
| +BluetoothUUID ExtractUuid(IOBluetoothSDPDataElement* service_class_data) {
|
| NSArray* inner_elements = [service_class_data getArrayValue];
|
| IOBluetoothSDPUUID* sdp_uuid = nil;
|
| for (IOBluetoothSDPDataElement* inner_element in inner_elements) {
|
| @@ -52,21 +53,22 @@ void ExtractUuid(IOBluetoothSDPDataElement* service_class_data,
|
| break;
|
| }
|
| }
|
| - if (sdp_uuid != nil) {
|
| - const uint8* uuid_bytes = reinterpret_cast<const uint8*>([sdp_uuid bytes]);
|
| - *uuid = base::StringPrintf(
|
| - "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
| - uuid_bytes[0], uuid_bytes[1], uuid_bytes[2], uuid_bytes[3],
|
| - uuid_bytes[4], uuid_bytes[5], uuid_bytes[6], uuid_bytes[7],
|
| - uuid_bytes[8], uuid_bytes[9], uuid_bytes[10], uuid_bytes[11],
|
| - uuid_bytes[12], uuid_bytes[13], uuid_bytes[14], uuid_bytes[15]);
|
| - }
|
| +
|
| + if (!sdp_uuid)
|
| + return BluetoothUUID();
|
| +
|
| + const uint8* uuid_bytes = reinterpret_cast<const uint8*>([sdp_uuid bytes]);
|
| + std::string uuid_str = base::HexEncode(uuid_bytes, 16);
|
| + DCHECK_EQ(uuid_str.size(), 32U);
|
| + uuid_str.insert(8, "-");
|
| + uuid_str.insert(13, "-");
|
| + uuid_str.insert(18, "-");
|
| + uuid_str.insert(23, "-");
|
| + return BluetoothUUID(uuid_str);
|
| }
|
|
|
| } // namespace
|
|
|
| -namespace device {
|
| -
|
| BluetoothDeviceMac::BluetoothDeviceMac(IOBluetoothDevice* device)
|
| : device_([device retain]) {
|
| }
|
| @@ -157,14 +159,14 @@ bool BluetoothDeviceMac::IsConnecting() const {
|
| BluetoothDevice::UUIDList BluetoothDeviceMac::GetUUIDs() const {
|
| UUIDList uuids;
|
| for (IOBluetoothSDPServiceRecord* service_record in [device_ services]) {
|
| - const BluetoothSDPServiceAttributeID service_class_id = 1;
|
| IOBluetoothSDPDataElement* service_class_data =
|
| - [service_record getAttributeDataElement:service_class_id];
|
| + [service_record getAttributeDataElement:
|
| + kBluetoothSDPAttributeIdentifierServiceClassIDList];
|
| if ([service_class_data getTypeDescriptor] ==
|
| kBluetoothSDPDataElementTypeDataElementSequence) {
|
| - std::string uuid_str;
|
| - ExtractUuid(service_class_data, &uuid_str);
|
| - uuids.push_back(BluetoothUUID(uuid_str));
|
| + BluetoothUUID uuid = ExtractUuid(service_class_data);
|
| + if (uuid.IsValid())
|
| + uuids.push_back(uuid);
|
| }
|
| }
|
| return uuids;
|
|
|