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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | components/arc/common/bluetooth.mojom » ('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 <fcntl.h> 7 #include <fcntl.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <iomanip> 10 #include <iomanip>
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 if (status == arc::mojom::BluetoothGattStatus::GATT_SUCCESS) 161 if (status == arc::mojom::BluetoothGattStatus::GATT_SUCCESS)
162 success_callback.Run(); 162 success_callback.Run();
163 else 163 else
164 error_callback.Run(); 164 error_callback.Run();
165 } 165 }
166 166
167 bool IsGattOffsetValid(int offset) { 167 bool IsGattOffsetValid(int offset) {
168 return 0 <= offset && offset < kMaxGattAttributeLength; 168 return 0 <= offset && offset < kMaxGattAttributeLength;
169 } 169 }
170 170
171 // This is needed because Android only support UUID 16 bits in advertising data.
172 uint16_t GetUUID16(const BluetoothUUID& uuid) {
173 // Convert xxxxyyyy-xxxx-xxxx-xxxx-xxxxxxxxxxxx to int16 yyyy
174 return std::stoi(uuid.canonical_value().substr(4, 4), nullptr, 16);
175 }
176
171 } // namespace 177 } // namespace
172 178
173 namespace arc { 179 namespace arc {
174 180
175 ArcBluetoothBridge::ArcBluetoothBridge(ArcBridgeService* bridge_service) 181 ArcBluetoothBridge::ArcBluetoothBridge(ArcBridgeService* bridge_service)
176 : ArcService(bridge_service), binding_(this), weak_factory_(this) { 182 : ArcService(bridge_service), binding_(this), weak_factory_(this) {
177 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) { 183 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) {
178 VLOG(1) << "registering bluetooth adapter"; 184 VLOG(1) << "registering bluetooth adapter";
179 BluetoothAdapterFactory::GetAdapter(base::Bind( 185 BluetoothAdapterFactory::GetAdapter(base::Bind(
180 &ArcBluetoothBridge::OnAdapterInitialized, weak_factory_.GetWeakPtr())); 186 &ArcBluetoothBridge::OnAdapterInitialized, weak_factory_.GetWeakPtr()));
(...skipping 1296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1477 btp->set_discovery_timeout(bluetooth_adapter_->GetDiscoverableTimeout()); 1483 btp->set_discovery_timeout(bluetooth_adapter_->GetDiscoverableTimeout());
1478 properties.push_back(std::move(btp)); 1484 properties.push_back(std::move(btp));
1479 } 1485 }
1480 1486
1481 return properties; 1487 return properties;
1482 } 1488 }
1483 1489
1484 // Android support 5 types of Advertising Data. 1490 // Android support 5 types of Advertising Data.
1485 // However Chrome didn't expose AdvertiseFlag and ManufacturerData. 1491 // However Chrome didn't expose AdvertiseFlag and ManufacturerData.
1486 // So we will only expose local_name, service_uuids and service_data. 1492 // So we will only expose local_name, service_uuids and service_data.
1493 // Note that we need to use UUID 16 bits because Android does not support
1494 // UUID 128 bits.
1487 // TODO(crbug.com/618442) Make Chrome expose missing data. 1495 // TODO(crbug.com/618442) Make Chrome expose missing data.
1488 mojo::Array<mojom::BluetoothAdvertisingDataPtr> 1496 mojo::Array<mojom::BluetoothAdvertisingDataPtr>
1489 ArcBluetoothBridge::GetAdvertisingData(BluetoothDevice* device) const { 1497 ArcBluetoothBridge::GetAdvertisingData(BluetoothDevice* device) const {
1490 mojo::Array<mojom::BluetoothAdvertisingDataPtr> advertising_data; 1498 mojo::Array<mojom::BluetoothAdvertisingDataPtr> advertising_data;
1491 1499
1492 // LocalName 1500 // LocalName
1493 mojom::BluetoothAdvertisingDataPtr local_name = 1501 mojom::BluetoothAdvertisingDataPtr local_name =
1494 mojom::BluetoothAdvertisingData::New(); 1502 mojom::BluetoothAdvertisingData::New();
1495 local_name->set_local_name(base::UTF16ToUTF8(device->GetNameForDisplay())); 1503 local_name->set_local_name(base::UTF16ToUTF8(device->GetNameForDisplay()));
1496 advertising_data.push_back(std::move(local_name)); 1504 advertising_data.push_back(std::move(local_name));
1497 1505
1498 // ServiceUuid 1506 // ServiceUuid
1499 BluetoothDevice::UUIDList uuid_list = device->GetServiceDataUUIDs(); 1507 BluetoothDevice::UUIDList uuid_list = device->GetServiceDataUUIDs();
1500 if (uuid_list.size() > 0) { 1508 if (uuid_list.size() > 0) {
1501 mojom::BluetoothAdvertisingDataPtr service_uuids = 1509 mojom::BluetoothAdvertisingDataPtr service_uuids_16 =
1502 mojom::BluetoothAdvertisingData::New(); 1510 mojom::BluetoothAdvertisingData::New();
1503 service_uuids->set_service_uuids( 1511 mojo::Array<uint16_t> uuid16s;
1504 mojo::Array<mojom::BluetoothUUIDPtr>::From(uuid_list)); 1512 for (auto& uuid : uuid_list) {
1505 advertising_data.push_back(std::move(service_uuids)); 1513 uuid16s.push_back(GetUUID16(uuid));
1514 }
1515 service_uuids_16->set_service_uuids_16(std::move(uuid16s));
1516 advertising_data.push_back(std::move(service_uuids_16));
1506 } 1517 }
1507 1518
1508 // Service data 1519 // Service data
1509 for (auto& uuid : uuid_list) { 1520 for (auto& uuid : uuid_list) {
1510 base::BinaryValue* data = device->GetServiceData(uuid); 1521 base::BinaryValue* data = device->GetServiceData(uuid);
1511 if (data->GetSize() == 0) 1522 if (data->GetSize() == 0)
1512 continue; 1523 continue;
1513 std::string data_str; 1524 std::string data_str;
1514 if (!data->GetAsString(&data_str)) 1525 if (!data->GetAsString(&data_str))
1515 continue; 1526 continue;
1516 1527
1517 mojom::BluetoothAdvertisingDataPtr service_data_element = 1528 mojom::BluetoothAdvertisingDataPtr service_data_element =
1518 mojom::BluetoothAdvertisingData::New(); 1529 mojom::BluetoothAdvertisingData::New();
1519 mojom::BluetoothServiceDataPtr service_data = 1530 mojom::BluetoothServiceDataPtr service_data =
1520 mojom::BluetoothServiceData::New(); 1531 mojom::BluetoothServiceData::New();
1521 1532
1522 std::string uuid_str = uuid.canonical_value(); 1533 service_data->uuid_16bit = GetUUID16(uuid);
1523 // Convert xxxxyyyy-xxxx-xxxx-xxxx-xxxxxxxxxxxx to int16 yyyy
1524 service_data->uuid_16bit = std::stoi(uuid_str.substr(4, 4), nullptr, 16);
1525 for (auto& c : data_str) { 1534 for (auto& c : data_str) {
1526 service_data->data.push_back(c); 1535 service_data->data.push_back(c);
1527 } 1536 }
1528 service_data_element->set_service_data(std::move(service_data)); 1537 service_data_element->set_service_data(std::move(service_data));
1529 advertising_data.push_back(std::move(service_data_element)); 1538 advertising_data.push_back(std::move(service_data_element));
1530 } 1539 }
1531 1540
1532 return advertising_data; 1541 return advertising_data;
1533 } 1542 }
1534 1543
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1614 LOG(WARNING) << "Bluetooth instance is too old (version " << version 1623 LOG(WARNING) << "Bluetooth instance is too old (version " << version
1615 << ") need version " << version_need; 1624 << ") need version " << version_need;
1616 return false; 1625 return false;
1617 } 1626 }
1618 1627
1619 bool ArcBluetoothBridge::CalledOnValidThread() { 1628 bool ArcBluetoothBridge::CalledOnValidThread() {
1620 return thread_checker_.CalledOnValidThread(); 1629 return thread_checker_.CalledOnValidThread();
1621 } 1630 }
1622 1631
1623 } // namespace arc 1632 } // namespace arc
OLDNEW
« 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