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 "components/proximity_auth/proximity_monitor_impl.h" | 5 #include "components/proximity_auth/proximity_monitor_impl.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 weak_ptr_factory_.GetWeakPtr())); | 197 weak_ptr_factory_.GetWeakPtr())); |
198 } | 198 } |
199 | 199 |
200 void ProximityMonitorImpl::OnConnectionInfo( | 200 void ProximityMonitorImpl::OnConnectionInfo( |
201 const BluetoothDevice::ConnectionInfo& connection_info) { | 201 const BluetoothDevice::ConnectionInfo& connection_info) { |
202 if (!is_active_) { | 202 if (!is_active_) { |
203 PA_LOG(INFO) << "[Proximity] Got connection info after stopping"; | 203 PA_LOG(INFO) << "[Proximity] Got connection info after stopping"; |
204 return; | 204 return; |
205 } | 205 } |
206 | 206 |
207 if (connection_info.rssi != BluetoothDevice::kUnknownPower && | 207 if (connection_info.rssi && connection_info.transmit_power && |
208 connection_info.transmit_power != BluetoothDevice::kUnknownPower && | 208 connection_info.max_transmit_power) { |
209 connection_info.max_transmit_power != BluetoothDevice::kUnknownPower) { | |
210 AddSample(connection_info); | 209 AddSample(connection_info); |
211 } else { | 210 } else { |
212 PA_LOG(WARNING) << "[Proximity] Unkown values received from API: " | 211 PA_LOG(WARNING) << "[Proximity] Unkown values received from API."; |
213 << connection_info.rssi << " " | |
214 << connection_info.transmit_power << " " | |
215 << connection_info.max_transmit_power; | |
216 rssi_rolling_average_.reset(); | 212 rssi_rolling_average_.reset(); |
217 last_transmit_power_reading_.reset(); | 213 last_transmit_power_reading_.reset(); |
218 CheckForProximityStateChange(); | 214 CheckForProximityStateChange(); |
219 } | 215 } |
220 } | 216 } |
221 | 217 |
222 void ProximityMonitorImpl::ClearProximityState() { | 218 void ProximityMonitorImpl::ClearProximityState() { |
223 if (is_active_ && remote_device_is_in_proximity_) { | 219 if (is_active_ && remote_device_is_in_proximity_) { |
224 FOR_EACH_OBSERVER(ProximityMonitorObserver, observers_, | 220 FOR_EACH_OBSERVER(ProximityMonitorObserver, observers_, |
225 OnProximityStateChanged()); | 221 OnProximityStateChanged()); |
226 } | 222 } |
227 | 223 |
228 remote_device_is_in_proximity_ = false; | 224 remote_device_is_in_proximity_ = false; |
229 rssi_rolling_average_.reset(); | 225 rssi_rolling_average_.reset(); |
230 last_transmit_power_reading_.reset(); | 226 last_transmit_power_reading_.reset(); |
231 last_zero_rssi_timestamp_.reset(); | 227 last_zero_rssi_timestamp_.reset(); |
232 } | 228 } |
233 | 229 |
234 void ProximityMonitorImpl::AddSample( | 230 void ProximityMonitorImpl::AddSample( |
235 const BluetoothDevice::ConnectionInfo& connection_info) { | 231 const BluetoothDevice::ConnectionInfo& connection_info) { |
236 double weight = kRssiSampleWeight; | 232 double weight = kRssiSampleWeight; |
237 if (!rssi_rolling_average_) { | 233 if (!rssi_rolling_average_) { |
238 rssi_rolling_average_.reset(new double(connection_info.rssi)); | 234 rssi_rolling_average_.reset(new double(connection_info.rssi.value())); |
239 } else { | 235 } else { |
240 *rssi_rolling_average_ = | 236 *rssi_rolling_average_ = weight * connection_info.rssi.value() + |
241 weight * connection_info.rssi + (1 - weight) * (*rssi_rolling_average_); | 237 (1 - weight) * (*rssi_rolling_average_); |
242 } | 238 } |
243 last_transmit_power_reading_.reset(new TransmitPowerReading( | 239 last_transmit_power_reading_.reset( |
244 connection_info.transmit_power, connection_info.max_transmit_power)); | 240 new TransmitPowerReading(connection_info.transmit_power.value(), |
| 241 connection_info.max_transmit_power.value())); |
245 | 242 |
246 // It's rare but possible for the RSSI to be positive briefly. | 243 // It's rare but possible for the RSSI to be positive briefly. |
247 if (connection_info.rssi >= 0) | 244 if (connection_info.rssi.value() >= 0) |
248 last_zero_rssi_timestamp_.reset(new base::TimeTicks(clock_->NowTicks())); | 245 last_zero_rssi_timestamp_.reset(new base::TimeTicks(clock_->NowTicks())); |
249 | 246 |
250 CheckForProximityStateChange(); | 247 CheckForProximityStateChange(); |
251 } | 248 } |
252 | 249 |
253 void ProximityMonitorImpl::CheckForProximityStateChange() { | 250 void ProximityMonitorImpl::CheckForProximityStateChange() { |
254 if (strategy_ == Strategy::NONE) | 251 if (strategy_ == Strategy::NONE) |
255 return; | 252 return; |
256 | 253 |
257 bool is_now_in_proximity = false; | 254 bool is_now_in_proximity = false; |
(...skipping 14 matching lines...) Expand all Loading... |
272 if (remote_device_is_in_proximity_ != is_now_in_proximity) { | 269 if (remote_device_is_in_proximity_ != is_now_in_proximity) { |
273 PA_LOG(INFO) << "[Proximity] Updated proximity state: " | 270 PA_LOG(INFO) << "[Proximity] Updated proximity state: " |
274 << (is_now_in_proximity ? "proximate" : "distant"); | 271 << (is_now_in_proximity ? "proximate" : "distant"); |
275 remote_device_is_in_proximity_ = is_now_in_proximity; | 272 remote_device_is_in_proximity_ = is_now_in_proximity; |
276 FOR_EACH_OBSERVER(ProximityMonitorObserver, observers_, | 273 FOR_EACH_OBSERVER(ProximityMonitorObserver, observers_, |
277 OnProximityStateChanged()); | 274 OnProximityStateChanged()); |
278 } | 275 } |
279 } | 276 } |
280 | 277 |
281 } // namespace proximity_auth | 278 } // namespace proximity_auth |
OLD | NEW |