Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: device/bluetooth/bluetooth_adapter_android.cc

Issue 2248913002: bluetooth: Implement RSSI and Tx Power on macOS and Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-refactor-adv-data
Patch Set: Clean up Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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.
Jeffrey Yasskin 2016/08/24 04:32:02 Link to https://developer.android.com/reference/an
ortuno 2016/08/24 21:29:09 Done.
217 {} /* service_data */); 217 base::Optional<int8_t> clamped_tx_power =
218 tx_power == INT32_MIN
219 ? base::nullopt
220 : base::make_optional<int8_t>(BluetoothDevice::ClampPower(tx_power));
221
222 device_android->UpdateAdvertisementData(
223 BluetoothDevice::ClampPower(rssi), std::move(advertised_bluetooth_uuids),
224 {} /* service_data */,
225 clamped_tx_power ? &clamped_tx_power.value() : nullptr);
Jeffrey Yasskin 2016/08/24 04:32:02 Should UpdateAdvertisementData take an optional, i
ortuno 2016/08/24 21:29:09 Hmmm I thought about passing an optional but base:
Jeffrey Yasskin 2016/08/24 22:32:07 As discussed over IM, it probably makes sense to s
ortuno 2016/08/25 16:42:34 Done.
218 226
219 if (is_new_device) { 227 if (is_new_device) {
220 devices_.add(device_address, std::move(device_android_owner)); 228 devices_.add(device_address, std::move(device_android_owner));
221 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 229 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
222 DeviceAdded(this, device_android)); 230 DeviceAdded(this, device_android));
223 } else { 231 } else {
224 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 232 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
225 DeviceChanged(this, device_android)); 233 DeviceChanged(this, device_android));
226 } 234 }
227 } 235 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 // TODO(scheib): Support filters crbug.com/490401 331 // TODO(scheib): Support filters crbug.com/490401
324 NOTIMPLEMENTED(); 332 NOTIMPLEMENTED();
325 error_callback.Run(UMABluetoothDiscoverySessionOutcome::NOT_IMPLEMENTED); 333 error_callback.Run(UMABluetoothDiscoverySessionOutcome::NOT_IMPLEMENTED);
326 } 334 }
327 335
328 void BluetoothAdapterAndroid::RemovePairingDelegateInternal( 336 void BluetoothAdapterAndroid::RemovePairingDelegateInternal(
329 device::BluetoothDevice::PairingDelegate* pairing_delegate) { 337 device::BluetoothDevice::PairingDelegate* pairing_delegate) {
330 } 338 }
331 339
332 } // namespace device 340 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698