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

Side by Side Diff: components/arc/bluetooth/arc_bluetooth_bridge.cc

Issue 2204263003: arc: bluetooth: Use UUID 16 bits in advertising data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add comment 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 unified diff | Download patch
« no previous file with comments | « no previous file | components/arc/bluetooth/arc_bluetooth_bridge_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/arc/bluetooth/arc_bluetooth_bridge.h" 5 #include "components/arc/bluetooth/arc_bluetooth_bridge.h"
6 6
7 #include <bluetooth/bluetooth.h> 7 #include <bluetooth/bluetooth.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <sys/socket.h> 10 #include <sys/socket.h>
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 if (status == arc::mojom::BluetoothGattStatus::GATT_SUCCESS) 170 if (status == arc::mojom::BluetoothGattStatus::GATT_SUCCESS)
171 success_callback.Run(); 171 success_callback.Run();
172 else 172 else
173 error_callback.Run(); 173 error_callback.Run();
174 } 174 }
175 175
176 bool IsGattOffsetValid(int offset) { 176 bool IsGattOffsetValid(int offset) {
177 return 0 <= offset && offset < kMaxGattAttributeLength; 177 return 0 <= offset && offset < kMaxGattAttributeLength;
178 } 178 }
179 179
180 // This is needed because Android only support UUID 16 bits in advertising data.
181 uint16_t GetUUID16(const BluetoothUUID& uuid) {
182 // Convert xxxxyyyy-xxxx-xxxx-xxxx-xxxxxxxxxxxx to int16 yyyy
183 return std::stoi(uuid.canonical_value().substr(4, 4), nullptr, 16);
184 }
185
180 } // namespace 186 } // namespace
181 187
182 namespace arc { 188 namespace arc {
183 189
184 ArcBluetoothBridge::ArcBluetoothBridge(ArcBridgeService* bridge_service) 190 ArcBluetoothBridge::ArcBluetoothBridge(ArcBridgeService* bridge_service)
185 : ArcService(bridge_service), binding_(this), weak_factory_(this) { 191 : ArcService(bridge_service), binding_(this), weak_factory_(this) {
186 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) { 192 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) {
187 VLOG(1) << "Registering bluetooth adapter."; 193 VLOG(1) << "Registering bluetooth adapter.";
188 BluetoothAdapterFactory::GetAdapter(base::Bind( 194 BluetoothAdapterFactory::GetAdapter(base::Bind(
189 &ArcBluetoothBridge::OnAdapterInitialized, weak_factory_.GetWeakPtr())); 195 &ArcBluetoothBridge::OnAdapterInitialized, weak_factory_.GetWeakPtr()));
(...skipping 1356 matching lines...) Expand 10 before | Expand all | Expand 10 after
1546 btp->set_local_le_features(std::move(le_features)); 1552 btp->set_local_le_features(std::move(le_features));
1547 properties.push_back(std::move(btp)); 1553 properties.push_back(std::move(btp));
1548 } 1554 }
1549 1555
1550 return properties; 1556 return properties;
1551 } 1557 }
1552 1558
1553 // Android support 5 types of Advertising Data. 1559 // Android support 5 types of Advertising Data.
1554 // However Chrome didn't expose AdvertiseFlag and ManufacturerData. 1560 // However Chrome didn't expose AdvertiseFlag and ManufacturerData.
1555 // So we will only expose local_name, service_uuids and service_data. 1561 // So we will only expose local_name, service_uuids and service_data.
1562 // Note that we need to use UUID 16 bits because Android does not support
1563 // UUID 128 bits.
1556 // TODO(crbug.com/618442) Make Chrome expose missing data. 1564 // TODO(crbug.com/618442) Make Chrome expose missing data.
1557 mojo::Array<mojom::BluetoothAdvertisingDataPtr> 1565 mojo::Array<mojom::BluetoothAdvertisingDataPtr>
1558 ArcBluetoothBridge::GetAdvertisingData(BluetoothDevice* device) const { 1566 ArcBluetoothBridge::GetAdvertisingData(BluetoothDevice* device) const {
1559 mojo::Array<mojom::BluetoothAdvertisingDataPtr> advertising_data; 1567 mojo::Array<mojom::BluetoothAdvertisingDataPtr> advertising_data;
1560 1568
1561 // LocalName 1569 // LocalName
1562 mojom::BluetoothAdvertisingDataPtr local_name = 1570 mojom::BluetoothAdvertisingDataPtr local_name =
1563 mojom::BluetoothAdvertisingData::New(); 1571 mojom::BluetoothAdvertisingData::New();
1564 local_name->set_local_name(device->GetName() ? device->GetName().value() 1572 local_name->set_local_name(device->GetName() ? device->GetName().value()
1565 : nullptr); 1573 : nullptr);
1566 advertising_data.push_back(std::move(local_name)); 1574 advertising_data.push_back(std::move(local_name));
1567 1575
1568 // ServiceUuid 1576 // ServiceUuid
1569 BluetoothDevice::UUIDList uuid_list = device->GetUUIDs(); 1577 BluetoothDevice::UUIDList uuid_list = device->GetUUIDs();
1570 if (uuid_list.size() > 0) { 1578 if (uuid_list.size() > 0) {
1571 mojom::BluetoothAdvertisingDataPtr service_uuids = 1579 mojom::BluetoothAdvertisingDataPtr service_uuids_16 =
1572 mojom::BluetoothAdvertisingData::New(); 1580 mojom::BluetoothAdvertisingData::New();
1573 service_uuids->set_service_uuids( 1581 mojo::Array<uint16_t> uuid16s;
1574 mojo::Array<mojom::BluetoothUUIDPtr>::From(uuid_list)); 1582 for (auto& uuid : uuid_list) {
1575 advertising_data.push_back(std::move(service_uuids)); 1583 uuid16s.push_back(GetUUID16(uuid));
1584 }
1585 service_uuids_16->set_service_uuids_16(std::move(uuid16s));
1586 advertising_data.push_back(std::move(service_uuids_16));
1576 } 1587 }
1577 1588
1578 // Service data 1589 // Service data
1579 for (auto& uuid : device->GetServiceDataUUIDs()) { 1590 for (auto& uuid : device->GetServiceDataUUIDs()) {
1580 base::BinaryValue* data = device->GetServiceData(uuid); 1591 base::BinaryValue* data = device->GetServiceData(uuid);
1581 if (data->GetSize() == 0) 1592 if (data->GetSize() == 0)
1582 continue; 1593 continue;
1583 std::string data_str; 1594 std::string data_str;
1584 if (!data->GetAsString(&data_str)) 1595 if (!data->GetAsString(&data_str))
1585 continue; 1596 continue;
1586 1597
1587 mojom::BluetoothAdvertisingDataPtr service_data_element = 1598 mojom::BluetoothAdvertisingDataPtr service_data_element =
1588 mojom::BluetoothAdvertisingData::New(); 1599 mojom::BluetoothAdvertisingData::New();
1589 mojom::BluetoothServiceDataPtr service_data = 1600 mojom::BluetoothServiceDataPtr service_data =
1590 mojom::BluetoothServiceData::New(); 1601 mojom::BluetoothServiceData::New();
1591 1602
1592 std::string uuid_str = uuid.canonical_value(); 1603 service_data->uuid_16bit = GetUUID16(uuid);
1593 // Convert xxxxyyyy-xxxx-xxxx-xxxx-xxxxxxxxxxxx to int16 yyyy
1594 service_data->uuid_16bit = std::stoi(uuid_str.substr(4, 4), nullptr, 16);
1595 for (auto& c : data_str) { 1604 for (auto& c : data_str) {
1596 service_data->data.push_back(c); 1605 service_data->data.push_back(c);
1597 } 1606 }
1598 service_data_element->set_service_data(std::move(service_data)); 1607 service_data_element->set_service_data(std::move(service_data));
1599 advertising_data.push_back(std::move(service_data_element)); 1608 advertising_data.push_back(std::move(service_data_element));
1600 } 1609 }
1601 1610
1602 return advertising_data; 1611 return advertising_data;
1603 } 1612 }
1604 1613
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1686 LOG(WARNING) << "Bluetooth instance is too old (version " << version 1695 LOG(WARNING) << "Bluetooth instance is too old (version " << version
1687 << ") need version " << version_need; 1696 << ") need version " << version_need;
1688 return false; 1697 return false;
1689 } 1698 }
1690 1699
1691 bool ArcBluetoothBridge::CalledOnValidThread() { 1700 bool ArcBluetoothBridge::CalledOnValidThread() {
1692 return thread_checker_.CalledOnValidThread(); 1701 return thread_checker_.CalledOnValidThread();
1693 } 1702 }
1694 1703
1695 } // namespace arc 1704 } // namespace arc
OLDNEW
« no previous file with comments | « no previous file | components/arc/bluetooth/arc_bluetooth_bridge_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698