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

Unified Diff: components/proximity_auth/proximity_monitor_impl.cc

Issue 2845433003: [EasyUnlock] Update ProximityMonitor to only check for RSSI proximity. (Closed)
Patch Set: [EasyUnlock] Update ProximityMonitor to only check for RSSI proximity. Created 3 years, 8 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: components/proximity_auth/proximity_monitor_impl.cc
diff --git a/components/proximity_auth/proximity_monitor_impl.cc b/components/proximity_auth/proximity_monitor_impl.cc
index 02422caf5b0830bdff76838ef4a004c27c0c062b..908b3ac95121a1d0d432e4896b8d22dd86d67bc2 100644
--- a/components/proximity_auth/proximity_monitor_impl.cc
+++ b/components/proximity_auth/proximity_monitor_impl.cc
@@ -27,16 +27,15 @@ const int kPollingTimeoutMs = 250;
// The RSSI threshold below which we consider the remote device to not be in
// proximity.
-const int kRssiThreshold = -5;
+const int kRssiThreshold = -45;
// The weight of the most recent RSSI sample.
const double kRssiSampleWeight = 0.3;
ProximityMonitorImpl::ProximityMonitorImpl(
- const cryptauth::RemoteDevice& remote_device,
+ cryptauth::Connection* connection,
std::unique_ptr<base::TickClock> clock)
- : remote_device_(remote_device),
- strategy_(Strategy::NONE),
+ : connection_(connection),
remote_device_is_in_proximity_(false),
is_active_(false),
clock_(std::move(clock)),
@@ -50,11 +49,6 @@ ProximityMonitorImpl::ProximityMonitorImpl(
PA_LOG(ERROR) << "[Proximity] Proximity monitoring unavailable: "
<< "Bluetooth is unsupported on this platform.";
}
-
- // TODO(isherman): Test prefs to set the strategy. Need to read from "Local
- // State" prefs on the sign-in screen, and per-user prefs on the lock screen.
- // TODO(isherman): Unlike in the JS app, destroy and recreate the proximity
- // monitor when the connection state changes.
}
ProximityMonitorImpl::~ProximityMonitorImpl() {
@@ -71,17 +65,8 @@ void ProximityMonitorImpl::Stop() {
UpdatePollingState();
}
-ProximityMonitor::Strategy ProximityMonitorImpl::GetStrategy() const {
- return strategy_;
-}
-
bool ProximityMonitorImpl::IsUnlockAllowed() const {
- return strategy_ == Strategy::NONE || remote_device_is_in_proximity_;
-}
-
-bool ProximityMonitorImpl::IsInRssiRange() const {
- return (strategy_ != Strategy::NONE && rssi_rolling_average_ &&
- *rssi_rolling_average_ > kRssiThreshold);
+ return remote_device_is_in_proximity_;
}
void ProximityMonitorImpl::RecordProximityMetricsOnAuthSuccess() {
@@ -89,12 +74,6 @@ void ProximityMonitorImpl::RecordProximityMetricsOnAuthSuccess() {
? *rssi_rolling_average_
: metrics::kUnknownProximityValue;
- int last_transmit_power_delta =
- last_transmit_power_reading_
- ? (last_transmit_power_reading_->transmit_power -
- last_transmit_power_reading_->max_transmit_power)
- : metrics::kUnknownProximityValue;
-
// If no zero RSSI value has been read, then record an overflow.
base::TimeDelta time_since_last_zero_rssi;
if (last_zero_rssi_timestamp_)
@@ -103,11 +82,11 @@ void ProximityMonitorImpl::RecordProximityMetricsOnAuthSuccess() {
time_since_last_zero_rssi = base::TimeDelta::FromDays(100);
std::string remote_device_model = metrics::kUnknownDeviceModel;
- if (remote_device_.name != remote_device_.bluetooth_address)
- remote_device_model = remote_device_.name;
+ cryptauth::RemoteDevice remote_device = connection_->remote_device();
+ if (!remote_device.name.empty())
+ remote_device_model = remote_device.name;
metrics::RecordAuthProximityRollingRssi(round(rssi_rolling_average));
- metrics::RecordAuthProximityTransmitPowerDelta(last_transmit_power_delta);
metrics::RecordAuthProximityTimeSinceLastZeroRssi(time_since_last_zero_rssi);
metrics::RecordAuthProximityRemoteDeviceModelHash(remote_device_model);
}
@@ -120,24 +99,6 @@ void ProximityMonitorImpl::RemoveObserver(ProximityMonitorObserver* observer) {
observers_.RemoveObserver(observer);
}
-void ProximityMonitorImpl::SetStrategy(Strategy strategy) {
- if (strategy_ == strategy)
- return;
- strategy_ = strategy;
- CheckForProximityStateChange();
- UpdatePollingState();
-}
-
-ProximityMonitorImpl::TransmitPowerReading::TransmitPowerReading(
- int transmit_power,
- int max_transmit_power)
- : transmit_power(transmit_power), max_transmit_power(max_transmit_power) {
-}
-
-bool ProximityMonitorImpl::TransmitPowerReading::IsInProximity() const {
- return transmit_power < max_transmit_power;
-}
-
void ProximityMonitorImpl::OnAdapterInitialized(
scoped_refptr<device::BluetoothAdapter> adapter) {
bluetooth_adapter_ = adapter;
@@ -170,25 +131,23 @@ void ProximityMonitorImpl::PerformScheduledUpdatePollingState() {
}
bool ProximityMonitorImpl::ShouldPoll() const {
- // Note: We poll even if the strategy is NONE so we can record measurements.
return is_active_ && bluetooth_adapter_;
}
void ProximityMonitorImpl::Poll() {
DCHECK(ShouldPoll());
- BluetoothDevice* device =
- bluetooth_adapter_->GetDevice(remote_device_.bluetooth_address);
+ std::string address = connection_->GetDeviceAddress();
+ BluetoothDevice* device = bluetooth_adapter_->GetDevice(address);
if (!device) {
- PA_LOG(ERROR) << "Unknown Bluetooth device with address "
- << remote_device_.bluetooth_address;
+ PA_LOG(ERROR) << "Unknown Bluetooth device with address " << address;
ClearProximityState();
return;
}
if (!device->IsConnected()) {
- PA_LOG(ERROR) << "Bluetooth device with address "
- << remote_device_.bluetooth_address << " is not connected.";
+ PA_LOG(ERROR) << "Bluetooth device with address " << address
+ << " is not connected.";
ClearProximityState();
return;
}
@@ -204,17 +163,12 @@ void ProximityMonitorImpl::OnConnectionInfo(
return;
}
- if (connection_info.rssi != BluetoothDevice::kUnknownPower &&
- connection_info.transmit_power != BluetoothDevice::kUnknownPower &&
- connection_info.max_transmit_power != BluetoothDevice::kUnknownPower) {
+ if (connection_info.rssi != BluetoothDevice::kUnknownPower) {
AddSample(connection_info);
} else {
PA_LOG(WARNING) << "[Proximity] Unkown values received from API: "
- << connection_info.rssi << " "
- << connection_info.transmit_power << " "
- << connection_info.max_transmit_power;
+ << connection_info.rssi;
rssi_rolling_average_.reset();
- last_transmit_power_reading_.reset();
CheckForProximityStateChange();
}
}
@@ -227,7 +181,6 @@ void ProximityMonitorImpl::ClearProximityState() {
remote_device_is_in_proximity_ = false;
rssi_rolling_average_.reset();
- last_transmit_power_reading_.reset();
last_zero_rssi_timestamp_.reset();
}
@@ -240,8 +193,6 @@ void ProximityMonitorImpl::AddSample(
*rssi_rolling_average_ =
weight * connection_info.rssi + (1 - weight) * (*rssi_rolling_average_);
}
- last_transmit_power_reading_.reset(new TransmitPowerReading(
- connection_info.transmit_power, connection_info.max_transmit_power));
// It's rare but possible for the RSSI to be positive briefly.
if (connection_info.rssi >= 0)
@@ -251,22 +202,11 @@ void ProximityMonitorImpl::AddSample(
}
void ProximityMonitorImpl::CheckForProximityStateChange() {
- if (strategy_ == Strategy::NONE)
- return;
-
- bool is_now_in_proximity = false;
- switch (strategy_) {
- case Strategy::NONE:
- return;
-
- case Strategy::CHECK_RSSI:
- is_now_in_proximity = IsInRssiRange();
- break;
+ bool is_now_in_proximity =
+ rssi_rolling_average_ && *rssi_rolling_average_ > kRssiThreshold;
- case Strategy::CHECK_TRANSMIT_POWER:
- is_now_in_proximity = (last_transmit_power_reading_ &&
- last_transmit_power_reading_->IsInProximity());
- break;
+ if (rssi_rolling_average_) {
+ LOG(WARNING) << "RSSI: " << *rssi_rolling_average_;
}
if (remote_device_is_in_proximity_ != is_now_in_proximity) {

Powered by Google App Engine
This is Rietveld 408576698