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

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

Issue 2425813003: arc: bluetooth: Send missing advertise data to Android. (Closed)
Patch Set: Fix lhchavez comment Created 4 years, 1 month 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 | no next file » | 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 1989 matching lines...) Expand 10 before | Expand all | Expand 10 after
2000 le_features->total_trackable_advertisers = 0; 2000 le_features->total_trackable_advertisers = 0;
2001 le_features->extended_scan_support = false; 2001 le_features->extended_scan_support = false;
2002 le_features->debug_logging_supported = false; 2002 le_features->debug_logging_supported = false;
2003 btp->set_local_le_features(std::move(le_features)); 2003 btp->set_local_le_features(std::move(le_features));
2004 properties.push_back(std::move(btp)); 2004 properties.push_back(std::move(btp));
2005 } 2005 }
2006 2006
2007 return properties; 2007 return properties;
2008 } 2008 }
2009 2009
2010 // Android support 5 types of Advertising Data. 2010 // Android support 6 types of Advertising Data which are Advertising Data Flags,
2011 // However Chrome didn't expose AdvertiseFlag and ManufacturerData. 2011 // Local Name, Service UUIDs, Tx Power Level, Service Data, and Manufacturer
2012 // So we will only expose local_name, service_uuids and service_data. 2012 // Data. Note that we need to use 16-bit UUID in Service Data section because
2013 // Note that we need to use UUID 16 bits in service_data section 2013 // Android does not support 128-bit UUID there.
2014 // because Android does not support UUID 128 bits there.
2015 // TODO(crbug.com/618442) Make Chrome expose missing data.
2016 mojo::Array<mojom::BluetoothAdvertisingDataPtr> 2014 mojo::Array<mojom::BluetoothAdvertisingDataPtr>
2017 ArcBluetoothBridge::GetAdvertisingData(const BluetoothDevice* device) const { 2015 ArcBluetoothBridge::GetAdvertisingData(const BluetoothDevice* device) const {
2018 mojo::Array<mojom::BluetoothAdvertisingDataPtr> advertising_data; 2016 mojo::Array<mojom::BluetoothAdvertisingDataPtr> advertising_data;
2019 2017
2020 // LocalName 2018 // Advertising Data Flags
2019 if (device->GetAdvertisingDataFlags().has_value()) {
2020 mojom::BluetoothAdvertisingDataPtr flags =
2021 mojom::BluetoothAdvertisingData::New();
2022 flags->set_flags(device->GetAdvertisingDataFlags().value());
2023 advertising_data.push_back(std::move(flags));
2024 }
2025
2026 // Local Name
2021 mojom::BluetoothAdvertisingDataPtr local_name = 2027 mojom::BluetoothAdvertisingDataPtr local_name =
2022 mojom::BluetoothAdvertisingData::New(); 2028 mojom::BluetoothAdvertisingData::New();
2023 local_name->set_local_name(device->GetName() ? device->GetName().value() 2029 local_name->set_local_name(device->GetName() ? device->GetName().value()
2024 : nullptr); 2030 : nullptr);
2025 advertising_data.push_back(std::move(local_name)); 2031 advertising_data.push_back(std::move(local_name));
2026 2032
2027 // ServiceUuid 2033 // Service UUIDs
2028 const BluetoothDevice::UUIDSet& uuid_set = device->GetUUIDs(); 2034 const BluetoothDevice::UUIDSet& uuid_set = device->GetUUIDs();
2029 if (uuid_set.size() > 0) { 2035 if (uuid_set.size() > 0) {
2030 mojom::BluetoothAdvertisingDataPtr service_uuids = 2036 mojom::BluetoothAdvertisingDataPtr service_uuids =
2031 mojom::BluetoothAdvertisingData::New(); 2037 mojom::BluetoothAdvertisingData::New();
2032 service_uuids->set_service_uuids(mojo::Array<BluetoothUUID>::From( 2038 service_uuids->set_service_uuids(mojo::Array<BluetoothUUID>::From(
2033 std::vector<BluetoothUUID>(uuid_set.begin(), uuid_set.end()))); 2039 std::vector<BluetoothUUID>(uuid_set.begin(), uuid_set.end())));
2034 advertising_data.push_back(std::move(service_uuids)); 2040 advertising_data.push_back(std::move(service_uuids));
2035 } 2041 }
2036 2042
2037 // Service data 2043 // Tx Power Level
2044 if (device->GetInquiryTxPower().has_value()) {
2045 mojom::BluetoothAdvertisingDataPtr tx_power_level_element =
2046 mojom::BluetoothAdvertisingData::New();
2047 tx_power_level_element->set_tx_power_level(
2048 device->GetInquiryTxPower().value());
2049 advertising_data.push_back(std::move(tx_power_level_element));
2050 }
2051
2052 // Service Data
2038 for (const BluetoothUUID& uuid : device->GetServiceDataUUIDs()) { 2053 for (const BluetoothUUID& uuid : device->GetServiceDataUUIDs()) {
2039 mojom::BluetoothAdvertisingDataPtr service_data_element = 2054 mojom::BluetoothAdvertisingDataPtr service_data_element =
2040 mojom::BluetoothAdvertisingData::New(); 2055 mojom::BluetoothAdvertisingData::New();
2041 mojom::BluetoothServiceDataPtr service_data = 2056 mojom::BluetoothServiceDataPtr service_data =
2042 mojom::BluetoothServiceData::New(); 2057 mojom::BluetoothServiceData::New();
2043 2058
2044 // Android only supports UUID 16 bit here. 2059 // Android only supports UUID 16 bit here.
2045 service_data->uuid_16bit = GetUUID16(uuid); 2060 service_data->uuid_16bit = GetUUID16(uuid);
2046 2061
2047 const std::vector<uint8_t>* data = device->GetServiceDataForUUID(uuid); 2062 const std::vector<uint8_t>* data = device->GetServiceDataForUUID(uuid);
2048 DCHECK(data != nullptr); 2063 DCHECK(data != nullptr);
2049 2064
2050 std::vector<uint8_t> data_copy = *data; 2065 std::vector<uint8_t> data_copy = *data;
2051 service_data->data.Swap(&data_copy); 2066 service_data->data.Swap(&data_copy);
2052 2067
2053 service_data_element->set_service_data(std::move(service_data)); 2068 service_data_element->set_service_data(std::move(service_data));
2054 advertising_data.push_back(std::move(service_data_element)); 2069 advertising_data.push_back(std::move(service_data_element));
2055 } 2070 }
2056 2071
2072 // Manufacturer Data
2073 if (!device->GetManufacturerData().empty()) {
2074 std::vector<uint8_t> manufacturer_data;
2075 for (const auto& pair : device->GetManufacturerData()) {
2076 uint16_t id = pair.first;
2077 // Use little endian here.
2078 manufacturer_data.push_back(id & 0xff);
2079 manufacturer_data.push_back(id >> 8);
2080 manufacturer_data.insert(manufacturer_data.end(), pair.second.begin(),
2081 pair.second.end());
2082 }
2083 mojom::BluetoothAdvertisingDataPtr manufacturer_data_element =
2084 mojom::BluetoothAdvertisingData::New();
2085 manufacturer_data_element->set_manufacturer_data(manufacturer_data);
2086 advertising_data.push_back(std::move(manufacturer_data_element));
2087 }
2088
2057 return advertising_data; 2089 return advertising_data;
2058 } 2090 }
2059 2091
2060 void ArcBluetoothBridge::SendCachedDevicesFound() const { 2092 void ArcBluetoothBridge::SendCachedDevicesFound() const {
2061 DCHECK(bluetooth_adapter_); 2093 DCHECK(bluetooth_adapter_);
2062 2094
2063 // Send devices that have already been discovered, but aren't connected. 2095 // Send devices that have already been discovered, but aren't connected.
2064 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); 2096 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices();
2065 for (auto* device : devices) { 2097 for (auto* device : devices) {
2066 if (device->IsPaired()) 2098 if (device->IsPaired())
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
2134 sdp_bluetooth_instance->OnGetSdpRecords( 2166 sdp_bluetooth_instance->OnGetSdpRecords(
2135 status, std::move(remote_addr), target_uuid, 2167 status, std::move(remote_addr), target_uuid,
2136 mojo::Array<mojom::BluetoothSdpRecordPtr>::New(0)); 2168 mojo::Array<mojom::BluetoothSdpRecordPtr>::New(0));
2137 } 2169 }
2138 2170
2139 bool ArcBluetoothBridge::CalledOnValidThread() { 2171 bool ArcBluetoothBridge::CalledOnValidThread() {
2140 return thread_checker_.CalledOnValidThread(); 2172 return thread_checker_.CalledOnValidThread();
2141 } 2173 }
2142 2174
2143 } // namespace arc 2175 } // namespace arc
OLDNEW
« 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