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