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

Unified 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: Address jyasskin's comments Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/bluetooth_adapter_android.cc
diff --git a/device/bluetooth/bluetooth_adapter_android.cc b/device/bluetooth/bluetooth_adapter_android.cc
index 5905d49d41f19a3d63cced7de8fcb6bb577a7636..958f3655b8929e04066dc0f31bc87b8555f8abbb 100644
--- a/device/bluetooth/bluetooth_adapter_android.cc
+++ b/device/bluetooth/bluetooth_adapter_android.cc
@@ -184,8 +184,9 @@ void BluetoothAdapterAndroid::CreateOrUpdateDeviceOnScan(
const JavaParamRef<jstring>& address,
const JavaParamRef<jobject>&
bluetooth_device_wrapper, // Java Type: bluetoothDeviceWrapper
- const JavaParamRef<jobjectArray>&
- advertised_uuids) { // Java Type: String[]
+ int32_t rssi,
+ const JavaParamRef<jobjectArray>& advertised_uuids, // Java Type: String[]
+ int32_t tx_power) {
std::string device_address = ConvertJavaStringToUTF8(env, address);
DevicesMap::const_iterator iter = devices_.find(device_address);
@@ -204,17 +205,23 @@ void BluetoothAdapterAndroid::CreateOrUpdateDeviceOnScan(
device_android = static_cast<BluetoothDeviceAndroid*>(iter->second);
}
DCHECK(device_android);
+
std::vector<std::string> advertised_uuids_strings;
AppendJavaStringArrayToStringVector(env, advertised_uuids,
&advertised_uuids_strings);
-
BluetoothDevice::UUIDList advertised_bluetooth_uuids;
for (std::string& uuid : advertised_uuids_strings) {
advertised_bluetooth_uuids.push_back(BluetoothUUID(std::move(uuid)));
}
- device_android->UpdateAdvertisementData(std::move(advertised_bluetooth_uuids),
- {} /* service_data */);
+ int8_t clamped_tx_power = BluetoothDevice::ClampPower(tx_power);
+
+ device_android->UpdateAdvertisementData(
+ BluetoothDevice::ClampPower(rssi), std::move(advertised_bluetooth_uuids),
+ {} /* service_data */,
+ // Android uses INT32_MIN to indicate no Advertised Tx Power.
+ // https://developer.android.com/reference/android/bluetooth/le/ScanRecord.html#getTxPowerLevel()
+ tx_power == INT32_MIN ? nullptr : &clamped_tx_power);
if (is_new_device) {
devices_.add(device_address, std::move(device_android_owner));

Powered by Google App Engine
This is Rietveld 408576698