OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "device/bluetooth/dbus/fake_bluetooth_device_client.h" | 5 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
(...skipping 1533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1544 if (iter == properties_map_.end()) { | 1544 if (iter == properties_map_.end()) { |
1545 VLOG(2) << "Fake device does not exist: " << object_path.value(); | 1545 VLOG(2) << "Fake device does not exist: " << object_path.value(); |
1546 return; | 1546 return; |
1547 } | 1547 } |
1548 Properties* properties = iter->second.get(); | 1548 Properties* properties = iter->second.get(); |
1549 DCHECK(properties); | 1549 DCHECK(properties); |
1550 properties->rssi.set_valid(true); | 1550 properties->rssi.set_valid(true); |
1551 properties->rssi.ReplaceValue(rssi); | 1551 properties->rssi.ReplaceValue(rssi); |
1552 } | 1552 } |
1553 | 1553 |
1554 void FakeBluetoothDeviceClient::UpdateServiceData( | |
1555 const dbus::ObjectPath& object_path, | |
1556 const std::unordered_map<std::string, std::vector<uint8_t>>& service_data) { | |
1557 PropertiesMap::const_iterator iter = properties_map_.find(object_path); | |
1558 if (iter == properties_map_.end()) { | |
1559 VLOG(2) << "Fake device does not exist: " << object_path.value(); | |
1560 return; | |
1561 } | |
1562 Properties* properties = iter->second.get(); | |
1563 DCHECK(properties); | |
1564 properties->service_data.set_valid(true); | |
1565 | |
1566 // BlueZ caches all the previously received advertisements. To mimic BlueZ | |
1567 // caching behavior, merge the new data here with the existing data. | |
1568 // TODO(crbug.com/707039): once the BlueZ caching behavior is changed, this | |
1569 // needs to be updated as well. | |
1570 std::unordered_map<std::string, std::vector<uint8_t>> merged_data = | |
1571 service_data; | |
1572 merged_data.insert(properties->service_data.value().begin(), | |
1573 properties->service_data.value().end()); | |
1574 properties->service_data.ReplaceValue(merged_data); | |
1575 } | |
1576 | |
1577 void FakeBluetoothDeviceClient::UpdateConnectionInfo( | 1554 void FakeBluetoothDeviceClient::UpdateConnectionInfo( |
1578 uint16_t connection_rssi, | 1555 uint16_t connection_rssi, |
1579 uint16_t transmit_power, | 1556 uint16_t transmit_power, |
1580 uint16_t max_transmit_power) { | 1557 uint16_t max_transmit_power) { |
1581 connection_rssi_ = connection_rssi; | 1558 connection_rssi_ = connection_rssi; |
1582 transmit_power_ = transmit_power; | 1559 transmit_power_ = transmit_power; |
1583 max_transmit_power_ = max_transmit_power; | 1560 max_transmit_power_ = max_transmit_power; |
1584 } | 1561 } |
1585 | 1562 |
1586 void FakeBluetoothDeviceClient::PinCodeCallback( | 1563 void FakeBluetoothDeviceClient::PinCodeCallback( |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1791 void FakeBluetoothDeviceClient::RemoveAllDevices() { | 1768 void FakeBluetoothDeviceClient::RemoveAllDevices() { |
1792 device_list_.clear(); | 1769 device_list_.clear(); |
1793 } | 1770 } |
1794 | 1771 |
1795 void FakeBluetoothDeviceClient::CreateTestDevice( | 1772 void FakeBluetoothDeviceClient::CreateTestDevice( |
1796 const dbus::ObjectPath& adapter_path, | 1773 const dbus::ObjectPath& adapter_path, |
1797 const base::Optional<std::string> name, | 1774 const base::Optional<std::string> name, |
1798 const std::string alias, | 1775 const std::string alias, |
1799 const std::string device_address, | 1776 const std::string device_address, |
1800 const std::vector<std::string>& service_uuids, | 1777 const std::vector<std::string>& service_uuids, |
1801 device::BluetoothTransport type, | 1778 device::BluetoothTransport type) { |
1802 const std::unordered_map<std::string, std::vector<uint8_t>>& service_data) { | |
1803 // Create a random device path. | 1779 // Create a random device path. |
1804 dbus::ObjectPath device_path; | 1780 dbus::ObjectPath device_path; |
1805 std::string id; | 1781 std::string id; |
1806 do { | 1782 do { |
1807 // Construct an id that is valid according to the DBUS specification. | 1783 // Construct an id that is valid according to the DBUS specification. |
1808 base::Base64Encode(base::RandBytesAsString(10), &id); | 1784 base::Base64Encode(base::RandBytesAsString(10), &id); |
1809 base::RemoveChars(id, "+/=", &id); | 1785 base::RemoveChars(id, "+/=", &id); |
1810 device_path = dbus::ObjectPath(adapter_path.value() + "/dev" + id); | 1786 device_path = dbus::ObjectPath(adapter_path.value() + "/dev" + id); |
1811 } while (std::find(device_list_.begin(), device_list_.end(), device_path) != | 1787 } while (std::find(device_list_.begin(), device_list_.end(), device_path) != |
1812 device_list_.end()); | 1788 device_list_.end()); |
(...skipping 22 matching lines...) Expand all Loading... |
1835 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeLe); | 1811 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeLe); |
1836 break; | 1812 break; |
1837 case device::BLUETOOTH_TRANSPORT_DUAL: | 1813 case device::BLUETOOTH_TRANSPORT_DUAL: |
1838 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeDual); | 1814 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeDual); |
1839 break; | 1815 break; |
1840 default: | 1816 default: |
1841 NOTREACHED(); | 1817 NOTREACHED(); |
1842 } | 1818 } |
1843 properties->type.set_valid(true); | 1819 properties->type.set_valid(true); |
1844 | 1820 |
1845 if (!service_data.empty()) { | |
1846 properties->service_data.ReplaceValue(service_data); | |
1847 properties->service_data.set_valid(true); | |
1848 } | |
1849 | |
1850 properties_map_.insert(std::make_pair(device_path, std::move(properties))); | 1821 properties_map_.insert(std::make_pair(device_path, std::move(properties))); |
1851 device_list_.push_back(device_path); | 1822 device_list_.push_back(device_path); |
1852 for (auto& observer : observers_) | 1823 for (auto& observer : observers_) |
1853 observer.DeviceAdded(device_path); | 1824 observer.DeviceAdded(device_path); |
1854 } | 1825 } |
1855 | 1826 |
1856 } // namespace bluez | 1827 } // namespace bluez |
OLD | NEW |