Index: content/browser/bluetooth/bluetooth_device_chooser_controller.cc |
diff --git a/content/browser/bluetooth/bluetooth_device_chooser_controller.cc b/content/browser/bluetooth/bluetooth_device_chooser_controller.cc |
index dc4842b2dad2da78247315e3658014f4e3e3da7f..c891441f64fa9f852390276824acc70625c0bfd5 100644 |
--- a/content/browser/bluetooth/bluetooth_device_chooser_controller.cc |
+++ b/content/browser/bluetooth/bluetooth_device_chooser_controller.cc |
@@ -26,6 +26,17 @@ |
using device::BluetoothUUID; |
+namespace { |
+ |
+// Anything worse than or equal to this will show 0 bars. |
+const int kMinRSSI = -100; |
+// Anything better than or equal to this will show the maximum bars. |
+const int kMaxRSSI = -55; |
+// Number of RSSI levels used in the signal strength image. |
+const int kNumSignalStrengthLevels = 5; |
+ |
+} // namespace |
+ |
namespace content { |
bool BluetoothDeviceChooserController::use_test_scan_duration_ = false; |
@@ -340,13 +351,13 @@ void BluetoothDeviceChooserController::GetDevice( |
void BluetoothDeviceChooserController::AddFilteredDevice( |
const device::BluetoothDevice& device) { |
if (chooser_.get() && MatchesFilters(device, options_->filters)) { |
+ base::Optional<int8_t> rssi = device.GetInquiryRSSI(); |
chooser_->AddOrUpdateDevice( |
device.GetAddress(), !!device.GetName() /* should_update_name */, |
device.GetNameForDisplay(), |
// TODO(http://crbug.com/543466): Show connection and paired status. |
false /* is_gatt_connected */, false /* is_paired */, |
- // TODO(http://crbug.com/629689): Add signal strength indicator. |
- nullptr /* rssi */); |
+ rssi ? &rssi.value() : nullptr); |
ortuno
2016/08/19 23:07:24
Would it make sense to pass the level here directl
juncai
2016/08/19 23:16:23
That needs to change the BluetoothChooser's interf
juncai
2016/08/19 23:58:42
Actually now I think that doing it in this patch s
Jeffrey Yasskin
2016/08/20 00:03:29
Thanks. That should remove some awkward dependenci
juncai
2016/08/20 01:17:02
Done.
|
} |
} |
@@ -370,6 +381,19 @@ void BluetoothDeviceChooserController::AdapterPoweredChanged(bool powered) { |
} |
} |
+int BluetoothDeviceChooserController::CalculateSignalStrengthLevel( |
+ int8_t rssi) { |
+ if (rssi <= kMinRSSI) |
+ return 0; |
+ |
+ if (rssi >= kMaxRSSI) |
+ return kNumSignalStrengthLevels - 1; |
+ |
+ double input_range = kMaxRSSI - kMinRSSI; |
+ double output_range = kNumSignalStrengthLevels - 1; |
+ return static_cast<int>((rssi - kMinRSSI) * output_range / input_range); |
+} |
+ |
void BluetoothDeviceChooserController::SetTestScanDurationForTesting() { |
BluetoothDeviceChooserController::use_test_scan_duration_ = true; |
} |