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/bluetooth_adapter_android.h" | 5 #include "device/bluetooth/bluetooth_adapter_android.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 num_discovery_sessions_ = 0; | 177 num_discovery_sessions_ = 0; |
178 MarkDiscoverySessionsAsInactive(); | 178 MarkDiscoverySessionsAsInactive(); |
179 } | 179 } |
180 | 180 |
181 void BluetoothAdapterAndroid::CreateOrUpdateDeviceOnScan( | 181 void BluetoothAdapterAndroid::CreateOrUpdateDeviceOnScan( |
182 JNIEnv* env, | 182 JNIEnv* env, |
183 const JavaParamRef<jobject>& caller, | 183 const JavaParamRef<jobject>& caller, |
184 const JavaParamRef<jstring>& address, | 184 const JavaParamRef<jstring>& address, |
185 const JavaParamRef<jobject>& | 185 const JavaParamRef<jobject>& |
186 bluetooth_device_wrapper, // Java Type: bluetoothDeviceWrapper | 186 bluetooth_device_wrapper, // Java Type: bluetoothDeviceWrapper |
187 const JavaParamRef<jobjectArray>& | 187 int32_t rssi, |
188 advertised_uuids) { // Java Type: String[] | 188 const JavaParamRef<jobjectArray>& advertised_uuids, // Java Type: String[] |
| 189 int32_t tx_power) { |
189 std::string device_address = ConvertJavaStringToUTF8(env, address); | 190 std::string device_address = ConvertJavaStringToUTF8(env, address); |
190 DevicesMap::const_iterator iter = devices_.find(device_address); | 191 DevicesMap::const_iterator iter = devices_.find(device_address); |
191 | 192 |
192 bool is_new_device = false; | 193 bool is_new_device = false; |
193 std::unique_ptr<BluetoothDeviceAndroid> device_android_owner; | 194 std::unique_ptr<BluetoothDeviceAndroid> device_android_owner; |
194 BluetoothDeviceAndroid* device_android; | 195 BluetoothDeviceAndroid* device_android; |
195 | 196 |
196 if (iter == devices_.end()) { | 197 if (iter == devices_.end()) { |
197 // New device. | 198 // New device. |
198 is_new_device = true; | 199 is_new_device = true; |
199 device_android_owner.reset( | 200 device_android_owner.reset( |
200 BluetoothDeviceAndroid::Create(this, bluetooth_device_wrapper)); | 201 BluetoothDeviceAndroid::Create(this, bluetooth_device_wrapper)); |
201 device_android = device_android_owner.get(); | 202 device_android = device_android_owner.get(); |
202 } else { | 203 } else { |
203 // Existing device. | 204 // Existing device. |
204 device_android = static_cast<BluetoothDeviceAndroid*>(iter->second); | 205 device_android = static_cast<BluetoothDeviceAndroid*>(iter->second); |
205 } | 206 } |
206 DCHECK(device_android); | 207 DCHECK(device_android); |
| 208 |
207 std::vector<std::string> advertised_uuids_strings; | 209 std::vector<std::string> advertised_uuids_strings; |
208 AppendJavaStringArrayToStringVector(env, advertised_uuids, | 210 AppendJavaStringArrayToStringVector(env, advertised_uuids, |
209 &advertised_uuids_strings); | 211 &advertised_uuids_strings); |
210 | |
211 BluetoothDevice::UUIDList advertised_bluetooth_uuids; | 212 BluetoothDevice::UUIDList advertised_bluetooth_uuids; |
212 for (std::string& uuid : advertised_uuids_strings) { | 213 for (std::string& uuid : advertised_uuids_strings) { |
213 advertised_bluetooth_uuids.push_back(BluetoothUUID(std::move(uuid))); | 214 advertised_bluetooth_uuids.push_back(BluetoothUUID(std::move(uuid))); |
214 } | 215 } |
215 | 216 |
216 device_android->UpdateAdvertisementData(std::move(advertised_bluetooth_uuids), | 217 int8_t clamped_tx_power = BluetoothDevice::ClampPower(tx_power); |
217 {} /* service_data */); | 218 |
| 219 device_android->UpdateAdvertisementData( |
| 220 BluetoothDevice::ClampPower(rssi), std::move(advertised_bluetooth_uuids), |
| 221 {} /* service_data */, |
| 222 // Android uses INT32_MIN to indicate no Advertised Tx Power. |
| 223 // https://developer.android.com/reference/android/bluetooth/le/ScanRecord
.html#getTxPowerLevel() |
| 224 tx_power == INT32_MIN ? nullptr : &clamped_tx_power); |
218 | 225 |
219 if (is_new_device) { | 226 if (is_new_device) { |
220 devices_.add(device_address, std::move(device_android_owner)); | 227 devices_.add(device_address, std::move(device_android_owner)); |
221 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 228 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
222 DeviceAdded(this, device_android)); | 229 DeviceAdded(this, device_android)); |
223 } else { | 230 } else { |
224 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 231 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
225 DeviceChanged(this, device_android)); | 232 DeviceChanged(this, device_android)); |
226 } | 233 } |
227 } | 234 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 // TODO(scheib): Support filters crbug.com/490401 | 330 // TODO(scheib): Support filters crbug.com/490401 |
324 NOTIMPLEMENTED(); | 331 NOTIMPLEMENTED(); |
325 error_callback.Run(UMABluetoothDiscoverySessionOutcome::NOT_IMPLEMENTED); | 332 error_callback.Run(UMABluetoothDiscoverySessionOutcome::NOT_IMPLEMENTED); |
326 } | 333 } |
327 | 334 |
328 void BluetoothAdapterAndroid::RemovePairingDelegateInternal( | 335 void BluetoothAdapterAndroid::RemovePairingDelegateInternal( |
329 device::BluetoothDevice::PairingDelegate* pairing_delegate) { | 336 device::BluetoothDevice::PairingDelegate* pairing_delegate) { |
330 } | 337 } |
331 | 338 |
332 } // namespace device | 339 } // namespace device |
OLD | NEW |