OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/test/bluetooth_test_bluez.h" | 5 #include "device/bluetooth/test/bluetooth_test_bluez.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 115 |
116 BluetoothDevice* BluetoothTestBlueZ::SimulateLowEnergyDevice( | 116 BluetoothDevice* BluetoothTestBlueZ::SimulateLowEnergyDevice( |
117 int device_ordinal) { | 117 int device_ordinal) { |
118 if (device_ordinal > 6 || device_ordinal < 1) | 118 if (device_ordinal > 6 || device_ordinal < 1) |
119 return nullptr; | 119 return nullptr; |
120 | 120 |
121 base::Optional<std::string> device_name = kTestDeviceName; | 121 base::Optional<std::string> device_name = kTestDeviceName; |
122 std::string device_address = kTestDeviceAddress1; | 122 std::string device_address = kTestDeviceAddress1; |
123 std::vector<std::string> service_uuids; | 123 std::vector<std::string> service_uuids; |
124 BluetoothTransport device_type = BLUETOOTH_TRANSPORT_LE; | 124 BluetoothTransport device_type = BLUETOOTH_TRANSPORT_LE; |
| 125 std::unordered_map<std::string, std::vector<uint8_t>> service_data; |
125 | 126 |
126 switch (device_ordinal) { | 127 switch (device_ordinal) { |
127 case 1: | 128 case 1: |
128 service_uuids.push_back(kTestUUIDGenericAccess); | 129 service_uuids.push_back(kTestUUIDGenericAccess); |
129 service_uuids.push_back(kTestUUIDGenericAttribute); | 130 service_uuids.push_back(kTestUUIDGenericAttribute); |
| 131 service_data[kTestUUIDHeartRate] = {0x01}; |
130 break; | 132 break; |
131 case 2: | 133 case 2: |
132 service_uuids.push_back(kTestUUIDImmediateAlert); | 134 service_uuids.push_back(kTestUUIDImmediateAlert); |
133 service_uuids.push_back(kTestUUIDLinkLoss); | 135 service_uuids.push_back(kTestUUIDLinkLoss); |
| 136 service_data[kTestUUIDHeartRate] = {}; |
| 137 service_data[kTestUUIDImmediateAlert] = {0x00, 0x02}; |
134 break; | 138 break; |
135 case 3: | 139 case 3: |
136 device_name = kTestDeviceNameEmpty; | 140 device_name = kTestDeviceNameEmpty; |
137 break; | 141 break; |
138 case 4: | 142 case 4: |
139 device_name = kTestDeviceNameEmpty; | 143 device_name = kTestDeviceNameEmpty; |
140 device_address = kTestDeviceAddress2; | 144 device_address = kTestDeviceAddress2; |
141 break; | 145 break; |
142 case 5: | 146 case 5: |
143 device_name = base::nullopt; | 147 device_name = base::nullopt; |
144 case 6: | 148 case 6: |
145 device_address = kTestDeviceAddress2; | 149 device_address = kTestDeviceAddress2; |
146 device_type = BLUETOOTH_TRANSPORT_DUAL; | 150 device_type = BLUETOOTH_TRANSPORT_DUAL; |
147 break; | 151 break; |
148 } | 152 } |
149 | 153 |
150 if (!adapter_->GetDevice(device_address)) { | 154 BluetoothDevice* device = adapter_->GetDevice(device_address); |
151 fake_bluetooth_device_client_->CreateTestDevice( | 155 if (device) { |
152 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 156 fake_bluetooth_device_client_->UpdateServiceData(GetDevicePath(device), |
153 /* name */ device_name, | 157 service_data); |
154 /* alias */ device_name.value_or("") + "(alias)", device_address, | 158 return device; |
155 service_uuids, device_type); | |
156 } | 159 } |
157 BluetoothDevice* device = adapter_->GetDevice(device_address); | |
158 | 160 |
159 return device; | 161 fake_bluetooth_device_client_->CreateTestDevice( |
| 162 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
| 163 /* name */ device_name, |
| 164 /* alias */ device_name.value_or("") + "(alias)", device_address, |
| 165 service_uuids, device_type, service_data); |
| 166 |
| 167 return adapter_->GetDevice(device_address); |
160 } | 168 } |
161 | 169 |
162 BluetoothDevice* BluetoothTestBlueZ::SimulateClassicDevice() { | 170 BluetoothDevice* BluetoothTestBlueZ::SimulateClassicDevice() { |
163 std::string device_name = kTestDeviceName; | 171 std::string device_name = kTestDeviceName; |
164 std::string device_address = kTestDeviceAddress3; | 172 std::string device_address = kTestDeviceAddress3; |
165 std::vector<std::string> service_uuids; | 173 std::vector<std::string> service_uuids; |
| 174 std::unordered_map<std::string, std::vector<uint8_t>> service_data; |
166 | 175 |
167 if (!adapter_->GetDevice(device_address)) { | 176 if (!adapter_->GetDevice(device_address)) { |
168 fake_bluetooth_device_client_->CreateTestDevice( | 177 fake_bluetooth_device_client_->CreateTestDevice( |
169 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 178 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
170 device_name /* name */, device_name /* alias */, device_address, | 179 device_name /* name */, device_name /* alias */, device_address, |
171 service_uuids, BLUETOOTH_TRANSPORT_CLASSIC); | 180 service_uuids, BLUETOOTH_TRANSPORT_CLASSIC, service_data); |
172 } | 181 } |
173 return adapter_->GetDevice(device_address); | 182 return adapter_->GetDevice(device_address); |
174 } | 183 } |
175 | 184 |
176 void BluetoothTestBlueZ::SimulateLocalGattCharacteristicValueReadRequest( | 185 void BluetoothTestBlueZ::SimulateLocalGattCharacteristicValueReadRequest( |
177 BluetoothDevice* from_device, | 186 BluetoothDevice* from_device, |
178 BluetoothLocalGattCharacteristic* characteristic, | 187 BluetoothLocalGattCharacteristic* characteristic, |
179 const BluetoothLocalGattService::Delegate::ValueCallback& value_callback, | 188 const BluetoothLocalGattService::Delegate::ValueCallback& value_callback, |
180 const base::Closure& error_callback) { | 189 const base::Closure& error_callback) { |
181 bluez::BluetoothLocalGattCharacteristicBlueZ* characteristic_bluez = | 190 bluez::BluetoothLocalGattCharacteristicBlueZ* characteristic_bluez = |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 std::vector<BluetoothLocalGattService*> services; | 350 std::vector<BluetoothLocalGattService*> services; |
342 bluez::BluetoothAdapterBlueZ* adapter_bluez = | 351 bluez::BluetoothAdapterBlueZ* adapter_bluez = |
343 static_cast<bluez::BluetoothAdapterBlueZ*>(adapter_.get()); | 352 static_cast<bluez::BluetoothAdapterBlueZ*>(adapter_.get()); |
344 | 353 |
345 for (const auto& iter : adapter_bluez->registered_gatt_services_) | 354 for (const auto& iter : adapter_bluez->registered_gatt_services_) |
346 services.push_back(iter.second); | 355 services.push_back(iter.second); |
347 return services; | 356 return services; |
348 } | 357 } |
349 | 358 |
350 } // namespace device | 359 } // namespace device |
OLD | NEW |