Chromium Code Reviews| Index: components/arc/bluetooth/arc_bluetooth_bridge.cc |
| diff --git a/components/arc/bluetooth/arc_bluetooth_bridge.cc b/components/arc/bluetooth/arc_bluetooth_bridge.cc |
| index 6d43d563199ef82754b4738a5a433caea2323bf0..1b5b4674a36be6d5d7334a52a0e3bdaee7cba80c 100644 |
| --- a/components/arc/bluetooth/arc_bluetooth_bridge.cc |
| +++ b/components/arc/bluetooth/arc_bluetooth_bridge.cc |
| @@ -194,9 +194,17 @@ bool IsGattOffsetValid(int offset) { |
| return 0 <= offset && offset < kMaxGattAttributeLength; |
| } |
| -// This is needed because Android only support UUID 16 bits in advertising data. |
| +bool isUuid16(const BluetoothUUID& uuid) { |
| + // Convert to uuid16 and compare with original uuid. |
| + return uuid == BluetoothUUID(uuid.canonical_value().substr(4, 4)); |
| +} |
| + |
| +// This is needed because Android only support UUID 16 bits in service data |
| +// section in advertising data |
| uint16_t GetUUID16(const BluetoothUUID& uuid) { |
| // Convert xxxxyyyy-xxxx-xxxx-xxxx-xxxxxxxxxxxx to int16 yyyy |
| + if (!isUuid16(uuid)) |
| + LOG(WARNING) << "Illegal conversion to UUID16 " << uuid.canonical_value(); |
| return std::stoi(uuid.canonical_value().substr(4, 4), nullptr, 16); |
| } |
| @@ -1873,16 +1881,26 @@ ArcBluetoothBridge::GetAdvertisingData(BluetoothDevice* device) const { |
| // ServiceUuid |
| BluetoothDevice::UUIDSet uuid_set = device->GetUUIDs(); |
| if (uuid_set.size() > 0) { |
| - mojom::BluetoothAdvertisingDataPtr service_uuids_16 = |
| + mojom::BluetoothAdvertisingDataPtr service_uuids = |
| mojom::BluetoothAdvertisingData::New(); |
| - mojo::Array<uint16_t> uuid16s(uuid_set.size()); |
| - size_t i = 0; |
| - for (const auto& uuid : uuid_set) { |
| - uuid16s[i] = GetUUID16(uuid); |
| - i++; |
| + if (std::all_of(uuid_set.begin(), uuid_set.end(), isUuid16)) { |
| + mojo::Array<uint16_t> uuid16s(uuid_set.size()); |
| + size_t i = 0; |
| + for (const auto& uuid : uuid_set) { |
| + uuid16s[i] = GetUUID16(uuid); |
| + i++; |
|
Luis Héctor Chávez
2016/09/28 16:11:48
Ugh, more of this pattern :(
Can you try using th
puthik_chromium
2016/09/29 02:06:08
It works.
Thanks for doing this.
|
| + } |
| + service_uuids->set_service_uuids_16(std::move(uuid16s)); |
| + } else { |
| + mojo::Array<BluetoothUUID> uuids(uuid_set.size()); |
| + size_t i = 0; |
| + for (const auto& uuid : uuid_set) { |
| + uuids[i] = uuid; |
| + i++; |
| + } |
| + service_uuids->set_service_uuids(std::move(uuids)); |
| } |
| - service_uuids_16->set_service_uuids_16(std::move(uuid16s)); |
| - advertising_data.push_back(std::move(service_uuids_16)); |
| + advertising_data.push_back(std::move(service_uuids)); |
| } |
| // Service data |