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

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

Issue 2268113002: arc: bluetooth: Use UUID 16 bits in advertising data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Created 4 years, 4 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 | components/arc/common/bluetooth.mojom » ('j') | 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 8e661fbf37806a8f210eb947f6a1a472bb3ed071..97b1836611d4dc64ba5790e3f4c339546c058461 100644
--- a/components/arc/bluetooth/arc_bluetooth_bridge.cc
+++ b/components/arc/bluetooth/arc_bluetooth_bridge.cc
@@ -168,6 +168,12 @@ bool IsGattOffsetValid(int offset) {
return 0 <= offset && offset < kMaxGattAttributeLength;
}
+// This is needed because Android only support UUID 16 bits 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);
+}
+
} // namespace
namespace arc {
@@ -1484,6 +1490,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.
// TODO(crbug.com/618442) Make Chrome expose missing data.
mojo::Array<mojom::BluetoothAdvertisingDataPtr>
ArcBluetoothBridge::GetAdvertisingData(BluetoothDevice* device) const {
@@ -1498,11 +1506,14 @@ ArcBluetoothBridge::GetAdvertisingData(BluetoothDevice* device) const {
// ServiceUuid
BluetoothDevice::UUIDList uuid_list = device->GetServiceDataUUIDs();
if (uuid_list.size() > 0) {
- mojom::BluetoothAdvertisingDataPtr service_uuids =
+ mojom::BluetoothAdvertisingDataPtr service_uuids_16 =
mojom::BluetoothAdvertisingData::New();
- service_uuids->set_service_uuids(
- mojo::Array<mojom::BluetoothUUIDPtr>::From(uuid_list));
- advertising_data.push_back(std::move(service_uuids));
+ mojo::Array<uint16_t> uuid16s;
+ for (auto& uuid : uuid_list) {
+ uuid16s.push_back(GetUUID16(uuid));
+ }
+ service_uuids_16->set_service_uuids_16(std::move(uuid16s));
+ advertising_data.push_back(std::move(service_uuids_16));
}
// Service data
@@ -1519,9 +1530,7 @@ ArcBluetoothBridge::GetAdvertisingData(BluetoothDevice* device) const {
mojom::BluetoothServiceDataPtr service_data =
mojom::BluetoothServiceData::New();
- std::string uuid_str = uuid.canonical_value();
- // Convert xxxxyyyy-xxxx-xxxx-xxxx-xxxxxxxxxxxx to int16 yyyy
- service_data->uuid_16bit = std::stoi(uuid_str.substr(4, 4), nullptr, 16);
+ service_data->uuid_16bit = GetUUID16(uuid);
for (auto& c : data_str) {
service_data->data.push_back(c);
}
« no previous file with comments | « no previous file | components/arc/common/bluetooth.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698