Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Unified Diff: components/arc/bluetooth/arc_bluetooth_bridge.cc

Issue 2376873002: arc: bluetooth: Use uuid 128 bit for service uuid (Closed)
Patch Set: Add more code comment Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 3b8cf87ba4cd2e19c14df0cc88ef04ff501e8bc6..1f37d6925366674e8cc32aafd44fe3fda2fd32c1 100644
--- a/components/arc/bluetooth/arc_bluetooth_bridge.cc
+++ b/components/arc/bluetooth/arc_bluetooth_bridge.cc
@@ -194,7 +194,13 @@ 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) {
Rahul Chaturvedi 2016/09/29 22:10:47 Can't we get this from uuid.Format()?
puthik_chromium 2016/09/29 22:39:25 uuid.Format() return the size of uuid string given
+ // 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
return std::stoi(uuid.canonical_value().substr(4, 4), nullptr, 16);
@@ -1864,8 +1870,8 @@ ArcBluetoothBridge::GetAdapterProperties(
// Android support 5 types of Advertising Data.
// However Chrome didn't expose AdvertiseFlag and ManufacturerData.
// So we will only expose local_name, service_uuids and service_data.
-// Note that we need to use UUID 16 bits because Android does not support
-// UUID 128 bits.
+// Note that we need to use UUID 16 bits in service_data section
+// because Android does not support UUID 128 bits there.
// TODO(crbug.com/618442) Make Chrome expose missing data.
mojo::Array<mojom::BluetoothAdvertisingDataPtr>
ArcBluetoothBridge::GetAdvertisingData(BluetoothDevice* device) const {
@@ -1879,18 +1885,24 @@ ArcBluetoothBridge::GetAdvertisingData(BluetoothDevice* device) const {
advertising_data.push_back(std::move(local_name));
// ServiceUuid
- BluetoothDevice::UUIDSet uuid_set = device->GetUUIDs();
+ const 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;
+ uuid16s.reserve(uuid_set.size());
+ for (const auto& uuid : uuid_set)
+ uuid16s.push_back(GetUUID16(uuid));
+ service_uuids->set_service_uuids_16(std::move(uuid16s));
Rahul Chaturvedi 2016/09/29 22:10:47 Why do 16 bit UUIDs need to be handled differently
puthik_chromium 2016/09/29 22:39:25 Why do 16 bit UUIDs need to be handled differently
Rahul Chaturvedi 2016/09/29 22:53:39 Android's implementation and APIs can change (in f
+ } else {
+ mojo::Array<BluetoothUUID> uuids;
+ uuids.reserve(uuid_set.size());
+ for (const auto& uuid : uuid_set)
+ uuids.push_back(uuid);
+ 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
@@ -1900,6 +1912,7 @@ ArcBluetoothBridge::GetAdvertisingData(BluetoothDevice* device) const {
mojom::BluetoothServiceDataPtr service_data =
mojom::BluetoothServiceData::New();
+ // Android only support UUID 16 bit here.
Luis Héctor Chávez 2016/09/29 21:10:15 nit: s/support/supports/
puthik_chromium 2016/10/05 18:18:57 Done.
service_data->uuid_16bit = GetUUID16(uuid);
const std::vector<uint8_t>* data = device->GetServiceDataForUUID(uuid);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698