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 1357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1368 BluetoothDevice* device) const { | 1368 BluetoothDevice* device) const { |
1369 mojo::Array<mojom::BluetoothPropertyPtr> properties; | 1369 mojo::Array<mojom::BluetoothPropertyPtr> properties; |
1370 | 1370 |
1371 if (!device) { | 1371 if (!device) { |
1372 return properties; | 1372 return properties; |
1373 } | 1373 } |
1374 | 1374 |
1375 if (type == mojom::BluetoothPropertyType::ALL || | 1375 if (type == mojom::BluetoothPropertyType::ALL || |
1376 type == mojom::BluetoothPropertyType::BDNAME) { | 1376 type == mojom::BluetoothPropertyType::BDNAME) { |
1377 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); | 1377 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
1378 // TODO(615720): Use the upcoming GetName (was GetDeviceName). | 1378 btp->set_bdname(device->GetName() ? device->GetName().value() : nullptr); |
1379 btp->set_bdname( | |
1380 mojo::String::From(base::UTF16ToUTF8(device->GetNameForDisplay()))); | |
1381 properties.push_back(std::move(btp)); | 1379 properties.push_back(std::move(btp)); |
1382 } | 1380 } |
1383 if (type == mojom::BluetoothPropertyType::ALL || | 1381 if (type == mojom::BluetoothPropertyType::ALL || |
1384 type == mojom::BluetoothPropertyType::BDADDR) { | 1382 type == mojom::BluetoothPropertyType::BDADDR) { |
1385 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); | 1383 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
1386 btp->set_bdaddr(mojom::BluetoothAddress::From(device->GetAddress())); | 1384 btp->set_bdaddr(mojom::BluetoothAddress::From(device->GetAddress())); |
1387 properties.push_back(std::move(btp)); | 1385 properties.push_back(std::move(btp)); |
1388 } | 1386 } |
1389 if (type == mojom::BluetoothPropertyType::ALL || | 1387 if (type == mojom::BluetoothPropertyType::ALL || |
1390 type == mojom::BluetoothPropertyType::UUIDS) { | 1388 type == mojom::BluetoothPropertyType::UUIDS) { |
(...skipping 17 matching lines...) Expand all Loading... |
1408 } | 1406 } |
1409 if (type == mojom::BluetoothPropertyType::ALL || | 1407 if (type == mojom::BluetoothPropertyType::ALL || |
1410 type == mojom::BluetoothPropertyType::TYPE_OF_DEVICE) { | 1408 type == mojom::BluetoothPropertyType::TYPE_OF_DEVICE) { |
1411 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); | 1409 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
1412 btp->set_device_type(device->GetType()); | 1410 btp->set_device_type(device->GetType()); |
1413 properties.push_back(std::move(btp)); | 1411 properties.push_back(std::move(btp)); |
1414 } | 1412 } |
1415 if (type == mojom::BluetoothPropertyType::ALL || | 1413 if (type == mojom::BluetoothPropertyType::ALL || |
1416 type == mojom::BluetoothPropertyType::REMOTE_FRIENDLY_NAME) { | 1414 type == mojom::BluetoothPropertyType::REMOTE_FRIENDLY_NAME) { |
1417 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); | 1415 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
1418 // TODO(615720): Use the upcoming GetName (was GetDeviceName). | |
1419 btp->set_remote_friendly_name( | 1416 btp->set_remote_friendly_name( |
1420 mojo::String::From(base::UTF16ToUTF8(device->GetNameForDisplay()))); | 1417 mojo::String::From(base::UTF16ToUTF8(device->GetNameForDisplay()))); |
1421 properties.push_back(std::move(btp)); | 1418 properties.push_back(std::move(btp)); |
1422 } | 1419 } |
1423 if (type == mojom::BluetoothPropertyType::ALL || | 1420 if (type == mojom::BluetoothPropertyType::ALL || |
1424 type == mojom::BluetoothPropertyType::REMOTE_RSSI) { | 1421 type == mojom::BluetoothPropertyType::REMOTE_RSSI) { |
1425 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); | 1422 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
1426 btp->set_remote_rssi(device->GetInquiryRSSI()); | 1423 btp->set_remote_rssi(device->GetInquiryRSSI()); |
1427 properties.push_back(std::move(btp)); | 1424 properties.push_back(std::move(btp)); |
1428 } | 1425 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1513 // However Chrome didn't expose AdvertiseFlag and ManufacturerData. | 1510 // However Chrome didn't expose AdvertiseFlag and ManufacturerData. |
1514 // So we will only expose local_name, service_uuids and service_data. | 1511 // So we will only expose local_name, service_uuids and service_data. |
1515 // TODO(crbug.com/618442) Make Chrome expose missing data. | 1512 // TODO(crbug.com/618442) Make Chrome expose missing data. |
1516 mojo::Array<mojom::BluetoothAdvertisingDataPtr> | 1513 mojo::Array<mojom::BluetoothAdvertisingDataPtr> |
1517 ArcBluetoothBridge::GetAdvertisingData(BluetoothDevice* device) const { | 1514 ArcBluetoothBridge::GetAdvertisingData(BluetoothDevice* device) const { |
1518 mojo::Array<mojom::BluetoothAdvertisingDataPtr> advertising_data; | 1515 mojo::Array<mojom::BluetoothAdvertisingDataPtr> advertising_data; |
1519 | 1516 |
1520 // LocalName | 1517 // LocalName |
1521 mojom::BluetoothAdvertisingDataPtr local_name = | 1518 mojom::BluetoothAdvertisingDataPtr local_name = |
1522 mojom::BluetoothAdvertisingData::New(); | 1519 mojom::BluetoothAdvertisingData::New(); |
1523 local_name->set_local_name(base::UTF16ToUTF8(device->GetNameForDisplay())); | 1520 local_name->set_local_name(device->GetName() ? device->GetName().value() |
| 1521 : nullptr); |
1524 advertising_data.push_back(std::move(local_name)); | 1522 advertising_data.push_back(std::move(local_name)); |
1525 | 1523 |
1526 // ServiceUuid | 1524 // ServiceUuid |
1527 BluetoothDevice::UUIDList uuid_list = device->GetServiceDataUUIDs(); | 1525 BluetoothDevice::UUIDList uuid_list = device->GetServiceDataUUIDs(); |
1528 if (uuid_list.size() > 0) { | 1526 if (uuid_list.size() > 0) { |
1529 mojom::BluetoothAdvertisingDataPtr service_uuids = | 1527 mojom::BluetoothAdvertisingDataPtr service_uuids = |
1530 mojom::BluetoothAdvertisingData::New(); | 1528 mojom::BluetoothAdvertisingData::New(); |
1531 service_uuids->set_service_uuids( | 1529 service_uuids->set_service_uuids( |
1532 mojo::Array<mojom::BluetoothUUIDPtr>::From(uuid_list)); | 1530 mojo::Array<mojom::BluetoothUUIDPtr>::From(uuid_list)); |
1533 advertising_data.push_back(std::move(service_uuids)); | 1531 advertising_data.push_back(std::move(service_uuids)); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1642 LOG(WARNING) << "Bluetooth instance is too old (version " << version | 1640 LOG(WARNING) << "Bluetooth instance is too old (version " << version |
1643 << ") need version " << version_need; | 1641 << ") need version " << version_need; |
1644 return false; | 1642 return false; |
1645 } | 1643 } |
1646 | 1644 |
1647 bool ArcBluetoothBridge::CalledOnValidThread() { | 1645 bool ArcBluetoothBridge::CalledOnValidThread() { |
1648 return thread_checker_.CalledOnValidThread(); | 1646 return thread_checker_.CalledOnValidThread(); |
1649 } | 1647 } |
1650 | 1648 |
1651 } // namespace arc | 1649 } // namespace arc |
OLD | NEW |