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); |
207 std::vector<std::string> advertised_uuids_strings; | 208 std::vector<std::string> advertised_uuids_strings; |
208 AppendJavaStringArrayToStringVector(env, advertised_uuids, | 209 AppendJavaStringArrayToStringVector(env, advertised_uuids, |
209 &advertised_uuids_strings); | 210 &advertised_uuids_strings); |
210 | |
211 BluetoothDevice::UUIDList advertised_bluetooth_uuids; | 211 BluetoothDevice::UUIDList advertised_bluetooth_uuids; |
212 for (std::string& uuid : advertised_uuids_strings) { | 212 for (std::string& uuid : advertised_uuids_strings) { |
213 advertised_bluetooth_uuids.push_back(BluetoothUUID(std::move(uuid))); | 213 advertised_bluetooth_uuids.push_back(BluetoothUUID(std::move(uuid))); |
214 } | 214 } |
215 | 215 |
216 device_android->UpdateAdvertisementData(std::move(advertised_bluetooth_uuids), | 216 // Android uses INT32_MIN to indicate no Advertised Tx Power. |
217 {} /* service_data */); | 217 // https://developer.android.com/reference/android/bluetooth/le/ScanRecord.htm
l#getTxPowerLevel() |
| 218 base::Optional<int8_t> clamped_tx_power = |
| 219 tx_power == INT32_MIN |
| 220 ? base::nullopt |
| 221 : base::make_optional<int8_t>(BluetoothDevice::ClampPower(tx_power)); |
| 222 |
| 223 device_android->UpdateAdvertisementData( |
| 224 BluetoothDevice::ClampPower(rssi), std::move(advertised_bluetooth_uuids), |
| 225 {} /* service_data */, |
| 226 clamped_tx_power ? &clamped_tx_power.value() : nullptr); |
218 | 227 |
219 if (is_new_device) { | 228 if (is_new_device) { |
220 devices_.add(device_address, std::move(device_android_owner)); | 229 devices_.add(device_address, std::move(device_android_owner)); |
221 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 230 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
222 DeviceAdded(this, device_android)); | 231 DeviceAdded(this, device_android)); |
223 } else { | 232 } else { |
224 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 233 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
225 DeviceChanged(this, device_android)); | 234 DeviceChanged(this, device_android)); |
226 } | 235 } |
227 } | 236 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 // TODO(scheib): Support filters crbug.com/490401 | 332 // TODO(scheib): Support filters crbug.com/490401 |
324 NOTIMPLEMENTED(); | 333 NOTIMPLEMENTED(); |
325 error_callback.Run(UMABluetoothDiscoverySessionOutcome::NOT_IMPLEMENTED); | 334 error_callback.Run(UMABluetoothDiscoverySessionOutcome::NOT_IMPLEMENTED); |
326 } | 335 } |
327 | 336 |
328 void BluetoothAdapterAndroid::RemovePairingDelegateInternal( | 337 void BluetoothAdapterAndroid::RemovePairingDelegateInternal( |
329 device::BluetoothDevice::PairingDelegate* pairing_delegate) { | 338 device::BluetoothDevice::PairingDelegate* pairing_delegate) { |
330 } | 339 } |
331 | 340 |
332 } // namespace device | 341 } // namespace device |
OLD | NEW |