Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 if (status == arc::mojom::BluetoothGattStatus::GATT_SUCCESS) | 166 if (status == arc::mojom::BluetoothGattStatus::GATT_SUCCESS) |
| 167 success_callback.Run(); | 167 success_callback.Run(); |
| 168 else | 168 else |
| 169 error_callback.Run(); | 169 error_callback.Run(); |
| 170 } | 170 } |
| 171 | 171 |
| 172 bool IsGattOffsetValid(int offset) { | 172 bool IsGattOffsetValid(int offset) { |
| 173 return 0 <= offset && offset < kMaxGattAttributeLength; | 173 return 0 <= offset && offset < kMaxGattAttributeLength; |
| 174 } | 174 } |
| 175 | 175 |
| 176 uint16_t GetUUID16(const BluetoothUUID& uuid) { | |
|
rickyz (no longer on Chrome)
2016/08/17 00:35:59
Let's add a comment explaining why we send a uuid1
puthik_chromium
2016/08/17 00:45:50
Comment added.
| |
| 177 // Convert xxxxyyyy-xxxx-xxxx-xxxx-xxxxxxxxxxxx to int16 yyyy | |
| 178 return std::stoi(uuid.canonical_value().substr(4, 4), nullptr, 16); | |
| 179 } | |
| 180 | |
| 176 } // namespace | 181 } // namespace |
| 177 | 182 |
| 178 namespace arc { | 183 namespace arc { |
| 179 | 184 |
| 180 ArcBluetoothBridge::ArcBluetoothBridge(ArcBridgeService* bridge_service) | 185 ArcBluetoothBridge::ArcBluetoothBridge(ArcBridgeService* bridge_service) |
| 181 : ArcService(bridge_service), binding_(this), weak_factory_(this) { | 186 : ArcService(bridge_service), binding_(this), weak_factory_(this) { |
| 182 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) { | 187 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) { |
| 183 VLOG(1) << "Registering bluetooth adapter."; | 188 VLOG(1) << "Registering bluetooth adapter."; |
| 184 BluetoothAdapterFactory::GetAdapter(base::Bind( | 189 BluetoothAdapterFactory::GetAdapter(base::Bind( |
| 185 &ArcBluetoothBridge::OnAdapterInitialized, weak_factory_.GetWeakPtr())); | 190 &ArcBluetoothBridge::OnAdapterInitialized, weak_factory_.GetWeakPtr())); |
| (...skipping 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1521 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); | 1526 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 1522 btp->set_discovery_timeout(bluetooth_adapter_->GetDiscoverableTimeout()); | 1527 btp->set_discovery_timeout(bluetooth_adapter_->GetDiscoverableTimeout()); |
| 1523 properties.push_back(std::move(btp)); | 1528 properties.push_back(std::move(btp)); |
| 1524 } | 1529 } |
| 1525 | 1530 |
| 1526 return properties; | 1531 return properties; |
| 1527 } | 1532 } |
| 1528 | 1533 |
| 1529 // Android support 5 types of Advertising Data. | 1534 // Android support 5 types of Advertising Data. |
| 1530 // However Chrome didn't expose AdvertiseFlag and ManufacturerData. | 1535 // However Chrome didn't expose AdvertiseFlag and ManufacturerData. |
| 1531 // So we will only expose local_name, service_uuids and service_data. | 1536 // So we will only expose local_name, service_uuids and service_data. |
|
rickyz (no longer on Chrome)
2016/08/17 00:35:59
Should this be updated to service_uuids_16?
puthik_chromium
2016/08/17 00:45:50
Added comment that UUIDs are 16 bits.
| |
| 1532 // TODO(crbug.com/618442) Make Chrome expose missing data. | 1537 // TODO(crbug.com/618442) Make Chrome expose missing data. |
| 1533 mojo::Array<mojom::BluetoothAdvertisingDataPtr> | 1538 mojo::Array<mojom::BluetoothAdvertisingDataPtr> |
| 1534 ArcBluetoothBridge::GetAdvertisingData(BluetoothDevice* device) const { | 1539 ArcBluetoothBridge::GetAdvertisingData(BluetoothDevice* device) const { |
| 1535 mojo::Array<mojom::BluetoothAdvertisingDataPtr> advertising_data; | 1540 mojo::Array<mojom::BluetoothAdvertisingDataPtr> advertising_data; |
| 1536 | 1541 |
| 1537 // LocalName | 1542 // LocalName |
| 1538 mojom::BluetoothAdvertisingDataPtr local_name = | 1543 mojom::BluetoothAdvertisingDataPtr local_name = |
| 1539 mojom::BluetoothAdvertisingData::New(); | 1544 mojom::BluetoothAdvertisingData::New(); |
| 1540 local_name->set_local_name(device->GetName() ? device->GetName().value() | 1545 local_name->set_local_name(device->GetName() ? device->GetName().value() |
| 1541 : nullptr); | 1546 : nullptr); |
| 1542 advertising_data.push_back(std::move(local_name)); | 1547 advertising_data.push_back(std::move(local_name)); |
| 1543 | 1548 |
| 1544 // ServiceUuid | 1549 // ServiceUuid |
| 1545 BluetoothDevice::UUIDList uuid_list = device->GetUUIDs(); | 1550 BluetoothDevice::UUIDList uuid_list = device->GetUUIDs(); |
| 1546 if (uuid_list.size() > 0) { | 1551 if (uuid_list.size() > 0) { |
| 1547 mojom::BluetoothAdvertisingDataPtr service_uuids = | 1552 mojom::BluetoothAdvertisingDataPtr service_uuids_16 = |
| 1548 mojom::BluetoothAdvertisingData::New(); | 1553 mojom::BluetoothAdvertisingData::New(); |
| 1549 service_uuids->set_service_uuids( | 1554 mojo::Array<uint16_t> uuid16s; |
| 1550 mojo::Array<mojom::BluetoothUUIDPtr>::From(uuid_list)); | 1555 for (auto& uuid : uuid_list) { |
| 1551 advertising_data.push_back(std::move(service_uuids)); | 1556 uuid16s.push_back(GetUUID16(uuid)); |
| 1557 } | |
| 1558 service_uuids_16->set_service_uuids_16(std::move(uuid16s)); | |
| 1559 advertising_data.push_back(std::move(service_uuids_16)); | |
| 1552 } | 1560 } |
| 1553 | 1561 |
| 1554 // Service data | 1562 // Service data |
| 1555 for (auto& uuid : device->GetServiceDataUUIDs()) { | 1563 for (auto& uuid : device->GetServiceDataUUIDs()) { |
| 1556 base::BinaryValue* data = device->GetServiceData(uuid); | 1564 base::BinaryValue* data = device->GetServiceData(uuid); |
| 1557 if (data->GetSize() == 0) | 1565 if (data->GetSize() == 0) |
| 1558 continue; | 1566 continue; |
| 1559 std::string data_str; | 1567 std::string data_str; |
| 1560 if (!data->GetAsString(&data_str)) | 1568 if (!data->GetAsString(&data_str)) |
| 1561 continue; | 1569 continue; |
| 1562 | 1570 |
| 1563 mojom::BluetoothAdvertisingDataPtr service_data_element = | 1571 mojom::BluetoothAdvertisingDataPtr service_data_element = |
| 1564 mojom::BluetoothAdvertisingData::New(); | 1572 mojom::BluetoothAdvertisingData::New(); |
| 1565 mojom::BluetoothServiceDataPtr service_data = | 1573 mojom::BluetoothServiceDataPtr service_data = |
| 1566 mojom::BluetoothServiceData::New(); | 1574 mojom::BluetoothServiceData::New(); |
| 1567 | 1575 |
| 1568 std::string uuid_str = uuid.canonical_value(); | 1576 service_data->uuid_16bit = GetUUID16(uuid); |
| 1569 // Convert xxxxyyyy-xxxx-xxxx-xxxx-xxxxxxxxxxxx to int16 yyyy | |
| 1570 service_data->uuid_16bit = std::stoi(uuid_str.substr(4, 4), nullptr, 16); | |
| 1571 for (auto& c : data_str) { | 1577 for (auto& c : data_str) { |
| 1572 service_data->data.push_back(c); | 1578 service_data->data.push_back(c); |
| 1573 } | 1579 } |
| 1574 service_data_element->set_service_data(std::move(service_data)); | 1580 service_data_element->set_service_data(std::move(service_data)); |
| 1575 advertising_data.push_back(std::move(service_data_element)); | 1581 advertising_data.push_back(std::move(service_data_element)); |
| 1576 } | 1582 } |
| 1577 | 1583 |
| 1578 return advertising_data; | 1584 return advertising_data; |
| 1579 } | 1585 } |
| 1580 | 1586 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1662 LOG(WARNING) << "Bluetooth instance is too old (version " << version | 1668 LOG(WARNING) << "Bluetooth instance is too old (version " << version |
| 1663 << ") need version " << version_need; | 1669 << ") need version " << version_need; |
| 1664 return false; | 1670 return false; |
| 1665 } | 1671 } |
| 1666 | 1672 |
| 1667 bool ArcBluetoothBridge::CalledOnValidThread() { | 1673 bool ArcBluetoothBridge::CalledOnValidThread() { |
| 1668 return thread_checker_.CalledOnValidThread(); | 1674 return thread_checker_.CalledOnValidThread(); |
| 1669 } | 1675 } |
| 1670 | 1676 |
| 1671 } // namespace arc | 1677 } // namespace arc |
| OLD | NEW |