Commit bfabbfb6 authored by tengs's avatar tengs Committed by Commit bot

[EasyUnlock] Update ProximityMonitor to only check for RSSI proximity.

This CL also changes UnlockManager to use the new interface for ProximityMonitor.

Review-Url: https://codereview.chromium.org/2845433003
Cr-Commit-Position: refs/heads/master@{#467860}
parent 97681b52
......@@ -22,6 +22,10 @@ cryptauth::RemoteDevice FakeRemoteDeviceLifeCycle::GetRemoteDevice() const {
return remote_device_;
}
cryptauth::Connection* FakeRemoteDeviceLifeCycle::GetConnection() const {
return connection_;
}
RemoteDeviceLifeCycle::State FakeRemoteDeviceLifeCycle::GetState() const {
return state_;
}
......
......@@ -7,6 +7,7 @@
#include "base/macros.h"
#include "base/observer_list.h"
#include "components/cryptauth/fake_connection.h"
#include "components/cryptauth/remote_device.h"
#include "components/proximity_auth/remote_device_life_cycle.h"
......@@ -20,6 +21,7 @@ class FakeRemoteDeviceLifeCycle : public RemoteDeviceLifeCycle {
// RemoteDeviceLifeCycle:
void Start() override;
cryptauth::RemoteDevice GetRemoteDevice() const override;
cryptauth::Connection* GetConnection() const override;
State GetState() const override;
Messenger* GetMessenger() override;
void AddObserver(Observer* observer) override;
......@@ -30,6 +32,10 @@ class FakeRemoteDeviceLifeCycle : public RemoteDeviceLifeCycle {
void set_messenger(Messenger* messenger) { messenger_ = messenger; }
void set_connection(cryptauth::Connection* connection) {
connection_ = connection;
}
bool started() { return started_; }
base::ObserverList<Observer>& observers() { return observers_; }
......@@ -43,6 +49,8 @@ class FakeRemoteDeviceLifeCycle : public RemoteDeviceLifeCycle {
State state_;
cryptauth::Connection* connection_;
Messenger* messenger_;
DISALLOW_COPY_AND_ASSIGN(FakeRemoteDeviceLifeCycle);
......
......@@ -42,6 +42,11 @@ class Messenger {
// Returns the SecureContext instance used by the messenger. Ownership of the
// SecureContext is not passed.
virtual cryptauth::SecureContext* GetSecureContext() const = 0;
// Returns the underlying raw connection. Note that you should use
// |GetSecureContext()| instead if you want to send and receive messages
// securely.
virtual cryptauth::Connection* GetConnection() const = 0;
};
} // namespace proximity_auth
......
......@@ -154,6 +154,10 @@ cryptauth::SecureContext* MessengerImpl::GetSecureContext() const {
return secure_context_.get();
}
cryptauth::Connection* MessengerImpl::GetConnection() const {
return connection_.get();
}
MessengerImpl::PendingMessage::PendingMessage() {}
MessengerImpl::PendingMessage::PendingMessage(
......
......@@ -44,6 +44,7 @@ class MessengerImpl : public Messenger, public cryptauth::ConnectionObserver {
void RequestDecryption(const std::string& challenge) override;
void RequestUnlock() override;
cryptauth::SecureContext* GetSecureContext() const override;
cryptauth::Connection* GetConnection() const override;
// Exposed for testing.
cryptauth::Connection* connection() { return connection_.get(); }
......
......@@ -13,8 +13,6 @@ namespace proximity_auth {
// sufficiently close to the local device to permit unlocking.
class ProximityMonitor {
public:
enum class Strategy { NONE, CHECK_RSSI, CHECK_TRANSMIT_POWER };
virtual ~ProximityMonitor() {}
// Activates the proximity monitor. No-op if the proximity monitor is already
......@@ -25,18 +23,10 @@ class ProximityMonitor {
// already inactive.
virtual void Stop() = 0;
// Returns the strategy used to determine whether the remote device is in
// proximity.
virtual Strategy GetStrategy() const = 0;
// Returns |true| iff the remote device is close enough to the local device,
// given the user's current settings.
virtual bool IsUnlockAllowed() const = 0;
// Returns |true| iff the remote device is close enough to the local device,
// according to its RSSI measurement.
virtual bool IsInRssiRange() const = 0;
// Records the current proximity measurements to UMA. This should be called
// when the user successfully authenticates using proximity auth.
virtual void RecordProximityMetricsOnAuthSuccess() = 0;
......
......@@ -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,26 +74,12 @@ 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_)
time_since_last_zero_rssi = clock_->NowTicks() - *last_zero_rssi_timestamp_;
else
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 +91,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 +123,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 +155,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,8 +173,6 @@ void ProximityMonitorImpl::ClearProximityState() {
remote_device_is_in_proximity_ = false;
rssi_rolling_average_.reset();
last_transmit_power_reading_.reset();
last_zero_rssi_timestamp_.reset();
}
void ProximityMonitorImpl::AddSample(
......@@ -240,33 +184,16 @@ 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)
last_zero_rssi_timestamp_.reset(new base::TimeTicks(clock_->NowTicks()));
CheckForProximityStateChange();
}
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) {
......
......@@ -11,13 +11,13 @@
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "components/cryptauth/connection.h"
#include "components/cryptauth/remote_device.h"
#include "components/proximity_auth/proximity_monitor.h"
#include "device/bluetooth/bluetooth_device.h"
namespace base {
class TickClock;
class TimeTicks;
}
namespace device {
......@@ -31,41 +31,20 @@ class ProximityMonitorObserver;
// The concrete implemenation of the proximity monitor interface.
class ProximityMonitorImpl : public ProximityMonitor {
public:
// The |observer| is not owned, and must outlive |this| instance.
ProximityMonitorImpl(const cryptauth::RemoteDevice& remote_device,
// The |connection| is not owned, and must outlive |this| instance.
ProximityMonitorImpl(cryptauth::Connection* connection,
std::unique_ptr<base::TickClock> clock);
~ProximityMonitorImpl() override;
// ProximityMonitor:
void Start() override;
void Stop() override;
Strategy GetStrategy() const override;
bool IsUnlockAllowed() const override;
bool IsInRssiRange() const override;
void RecordProximityMetricsOnAuthSuccess() override;
void AddObserver(ProximityMonitorObserver* observer) override;
void RemoveObserver(ProximityMonitorObserver* observer) override;
protected:
// Sets the proximity detection strategy. Exposed for testing.
// TODO(isherman): Stop exposing this for testing once prefs are properly
// hooked up.
virtual void SetStrategy(Strategy strategy);
private:
struct TransmitPowerReading {
TransmitPowerReading(int transmit_power, int max_transmit_power);
// Returns true if |this| transmit power reading indicates proximity.
bool IsInProximity() const;
// The current transmit power.
int transmit_power;
// The maximum possible transmit power.
int max_transmit_power;
};
// Callback for asynchronous initialization of the Bluetooth adpater.
void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter);
......@@ -95,7 +74,7 @@ class ProximityMonitorImpl : public ProximityMonitor {
void ClearProximityState();
// Updates the proximity state with a new |connection_info| sample of the
// current RSSI and Tx power, and the device's maximum Tx power.
// current RSSI.
void AddSample(
const device::BluetoothDevice::ConnectionInfo& connection_info);
......@@ -103,8 +82,9 @@ class ProximityMonitorImpl : public ProximityMonitor {
// samples. Notifies |observers_| on a change.
void CheckForProximityStateChange();
// The remote device being monitored.
const cryptauth::RemoteDevice remote_device_;
// The current connection being monitored. Not owned and must outlive this
// instance.
cryptauth::Connection* connection_;
// The observers attached to the ProximityMonitor.
base::ObserverList<ProximityMonitorObserver> observers_;
......@@ -112,9 +92,6 @@ class ProximityMonitorImpl : public ProximityMonitor {
// The Bluetooth adapter that will be polled for connection info.
scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_;
// The strategy used to determine whether the remote device is in proximity.
Strategy strategy_;
// Whether the remote device is currently in close proximity to the local
// device.
bool remote_device_is_in_proximity_;
......@@ -129,18 +106,6 @@ class ProximityMonitorImpl : public ProximityMonitor {
// measurement.
std::unique_ptr<double> rssi_rolling_average_;
// The last TX power reading. Null if the monitor is inactive, has not
// recently observed a TX power reading, or the most recent connection info
// included an invalid measurement.
std::unique_ptr<TransmitPowerReading> last_transmit_power_reading_;
// The timestamp of the last zero RSSI reading. An RSSI value of 0 is special
// because both devices adjust their transmit powers such that the RSSI is in
// this golden range, if possible. Null if the monitor is inactive, has not
// recently observed an RSSI reading, or the most recent connection info
// included an invalid measurement.
std::unique_ptr<base::TimeTicks> last_zero_rssi_timestamp_;
// Used to access non-decreasing time measurements.
std::unique_ptr<base::TickClock> clock_;
......
......@@ -15,6 +15,7 @@
#include "base/test/test_simple_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "components/cryptauth/fake_connection.h"
#include "components/cryptauth/remote_device.h"
#include "components/proximity_auth/logging/logging.h"
#include "components/proximity_auth/proximity_monitor_observer.h"
......@@ -33,24 +34,11 @@ namespace proximity_auth {
namespace {
const char kRemoteDeviceUserId[] = "example@gmail.com";
const char kBluetoothAddress[] = "AA:BB:CC:DD:EE:FF";
const char kRemoteDevicePublicKey[] = "Remote Public Key";
const char kRemoteDeviceName[] = "LGE Nexus 5";
const char kBluetoothAddress[] = "AA:BB:CC:DD:EE:FF";
const char kPersistentSymmetricKey[] = "PSK";
class TestProximityMonitorImpl : public ProximityMonitorImpl {
public:
explicit TestProximityMonitorImpl(
const cryptauth::RemoteDevice& remote_device,
std::unique_ptr<base::TickClock> clock)
: ProximityMonitorImpl(remote_device, std::move(clock)) {}
~TestProximityMonitorImpl() override {}
using ProximityMonitorImpl::SetStrategy;
private:
DISALLOW_COPY_AND_ASSIGN(TestProximityMonitorImpl);
};
const int kRssiThreshold = -45;
class MockProximityMonitorObserver : public ProximityMonitorObserver {
public:
......@@ -83,17 +71,17 @@ class ProximityAuthProximityMonitorImplTest : public testing::Test {
remote_bluetooth_device_(&*bluetooth_adapter_,
0,
kRemoteDeviceName,
kBluetoothAddress,
"",
false /* paired */,
true /* connected */),
monitor_(
cryptauth::RemoteDevice(kRemoteDeviceUserId,
remote_device_(kRemoteDeviceUserId,
kRemoteDeviceName,
kRemoteDevicePublicKey,
kBluetoothAddress,
kPersistentSymmetricKey,
std::string()),
base::WrapUnique(clock_)),
connection_(remote_device_),
monitor_(&connection_, base::WrapUnique(clock_)),
task_runner_(new base::TestSimpleTaskRunner()),
thread_task_runner_handle_(task_runner_) {
ON_CALL(*bluetooth_adapter_, GetDevice(kBluetoothAddress))
......@@ -102,6 +90,7 @@ class ProximityAuthProximityMonitorImplTest : public testing::Test {
.WillByDefault(SaveArg<0>(&connection_info_callback_));
monitor_.AddObserver(&observer_);
}
~ProximityAuthProximityMonitorImplTest() override {}
void RunPendingTasks() { task_runner_->RunPendingTasks(); }
......@@ -126,9 +115,11 @@ class ProximityAuthProximityMonitorImplTest : public testing::Test {
// Mocks used for verifying interactions with the Bluetooth subsystem.
scoped_refptr<device::MockBluetoothAdapter> bluetooth_adapter_;
NiceMock<device::MockBluetoothDevice> remote_bluetooth_device_;
cryptauth::RemoteDevice remote_device_;
cryptauth::FakeConnection connection_;
// The proximity monitor under test.
TestProximityMonitorImpl monitor_;
ProximityMonitorImpl monitor_;
private:
scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
......@@ -137,304 +128,124 @@ class ProximityAuthProximityMonitorImplTest : public testing::Test {
ScopedDisableLoggingForTesting disable_logging_;
};
TEST_F(ProximityAuthProximityMonitorImplTest, GetStrategy) {
EXPECT_EQ(ProximityMonitor::Strategy::NONE, monitor_.GetStrategy());
monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_TRANSMIT_POWER);
EXPECT_EQ(ProximityMonitor::Strategy::CHECK_TRANSMIT_POWER,
monitor_.GetStrategy());
}
TEST_F(ProximityAuthProximityMonitorImplTest, ProximityState_StrategyIsNone) {
monitor_.SetStrategy(ProximityMonitor::Strategy::NONE);
EXPECT_TRUE(monitor_.IsUnlockAllowed());
EXPECT_FALSE(monitor_.IsInRssiRange());
}
TEST_F(ProximityAuthProximityMonitorImplTest, ProximityState_NeverStarted) {
monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_RSSI);
EXPECT_FALSE(monitor_.IsUnlockAllowed());
EXPECT_FALSE(monitor_.IsInRssiRange());
}
TEST_F(ProximityAuthProximityMonitorImplTest,
ProximityState_Started_NoConnectionInfoReceivedYet) {
monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_RSSI);
monitor_.Start();
TEST_F(ProximityAuthProximityMonitorImplTest, IsUnlockAllowed_NeverStarted) {
EXPECT_FALSE(monitor_.IsUnlockAllowed());
EXPECT_FALSE(monitor_.IsInRssiRange());
}
TEST_F(ProximityAuthProximityMonitorImplTest,
ProximityState_InformsObserverOfChanges) {
monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_TRANSMIT_POWER);
// Initially, the device is not in proximity.
IsUnlockAllowed_Started_NoConnectionInfoReceivedYet) {
monitor_.Start();
EXPECT_FALSE(monitor_.IsUnlockAllowed());
// Simulate a reading indicating proximity.
EXPECT_CALL(observer_, OnProximityStateChanged()).Times(1);
ProvideConnectionInfo({0, 0, 4});
EXPECT_TRUE(monitor_.IsUnlockAllowed());
// Simulate a reading indicating non-proximity.
EXPECT_CALL(observer_, OnProximityStateChanged()).Times(1);
ProvideConnectionInfo({0, 4, 4});
EXPECT_FALSE(monitor_.IsUnlockAllowed());
}
TEST_F(ProximityAuthProximityMonitorImplTest,
ProximityState_CheckRssi_RssiIndicatesProximity_TxPowerDoesNot) {
monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_RSSI);
TEST_F(ProximityAuthProximityMonitorImplTest, IsUnlockAllowed_RssiInRange) {
monitor_.Start();
ProvideConnectionInfo({0, 4, 4});
EXPECT_TRUE(monitor_.IsUnlockAllowed());
EXPECT_TRUE(monitor_.IsInRssiRange());
}
TEST_F(ProximityAuthProximityMonitorImplTest,
ProximityState_CheckRssi_TxPowerIndicatesProximity_RssiDoesNot) {
monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_RSSI);
monitor_.Start();
ProvideConnectionInfo({-10, 0, 4});
EXPECT_FALSE(monitor_.IsUnlockAllowed());
EXPECT_FALSE(monitor_.IsInRssiRange());
}
TEST_F(ProximityAuthProximityMonitorImplTest,
ProximityState_CheckRssi_NeitherRssiNorTxPowerIndicatesProximity) {
monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_RSSI);
monitor_.Start();
ProvideConnectionInfo({-10, 4, 4});
EXPECT_FALSE(monitor_.IsUnlockAllowed());
EXPECT_FALSE(monitor_.IsInRssiRange());
}
TEST_F(ProximityAuthProximityMonitorImplTest,
ProximityState_CheckRssi_BothRssiAndTxPowerIndicateProximity) {
monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_RSSI);
monitor_.Start();
ProvideConnectionInfo({0, 0, 4});
EXPECT_TRUE(monitor_.IsUnlockAllowed());
EXPECT_TRUE(monitor_.IsInRssiRange());
}
TEST_F(ProximityAuthProximityMonitorImplTest,
ProximityState_CheckRssi_UnknownRssi) {
monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_RSSI);
TEST_F(ProximityAuthProximityMonitorImplTest, IsUnlockAllowed_UnknownRssi) {
monitor_.Start();
ProvideConnectionInfo({0, 0, 4});
ProvideConnectionInfo({BluetoothDevice::kUnknownPower, 0, 4});
EXPECT_FALSE(monitor_.IsUnlockAllowed());
EXPECT_FALSE(monitor_.IsInRssiRange());
}
TEST_F(ProximityAuthProximityMonitorImplTest,
ProximityState_CheckRssi_UnknownTxPower) {
monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_RSSI);
monitor_.Start();
ProvideConnectionInfo({0, 0, 4});
ProvideConnectionInfo({0, BluetoothDevice::kUnknownPower, 4});
EXPECT_FALSE(monitor_.IsUnlockAllowed());
EXPECT_FALSE(monitor_.IsInRssiRange());
}
TEST_F(ProximityAuthProximityMonitorImplTest,
ProximityState_CheckRssi_UnknownMaxTxPower) {
monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_RSSI);
monitor_.Start();
ProvideConnectionInfo({0, 0, 4});
ProvideConnectionInfo({0, 0, BluetoothDevice::kUnknownPower});
EXPECT_FALSE(monitor_.IsUnlockAllowed());
EXPECT_FALSE(monitor_.IsInRssiRange());
}
TEST_F(ProximityAuthProximityMonitorImplTest,
ProximityState_CheckTxPower_RssiIndicatesProximity_TxPowerDoesNot) {
monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_TRANSMIT_POWER);
IsUnlockAllowed_InformsObserverOfChanges) {
// Initially, the device is not in proximity.
monitor_.Start();
ProvideConnectionInfo({0, 4, 4});
EXPECT_FALSE(monitor_.IsUnlockAllowed());
EXPECT_TRUE(monitor_.IsInRssiRange());
}
TEST_F(ProximityAuthProximityMonitorImplTest,
ProximityState_CheckTxPower_TxPowerIndicatesProximity_RssiDoesNot) {
monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_TRANSMIT_POWER);
monitor_.Start();
ProvideConnectionInfo({-10, 0, 4});
// Simulate receiving an RSSI reading in proximity.
EXPECT_CALL(observer_, OnProximityStateChanged()).Times(1);
ProvideConnectionInfo({kRssiThreshold / 2, 4, 4});
EXPECT_TRUE(monitor_.IsUnlockAllowed());
EXPECT_FALSE(monitor_.IsInRssiRange());
}
TEST_F(ProximityAuthProximityMonitorImplTest,
ProximityState_CheckTxPower_NeitherRssiNorTxPowerIndicatesProximity) {
monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_TRANSMIT_POWER);
monitor_.Start();
ProvideConnectionInfo({-10, 4, 4});
// Simulate a reading indicating non-proximity.
EXPECT_CALL(observer_, OnProximityStateChanged()).Times(1);
ProvideConnectionInfo({2 * kRssiThreshold, 4, 4});
ProvideConnectionInfo({2 * kRssiThreshold, 4, 4});
EXPECT_FALSE(monitor_.IsUnlockAllowed());
EXPECT_FALSE(monitor_.IsInRssiRange());
}
TEST_F(ProximityAuthProximityMonitorImplTest,
ProximityState_CheckTxPower_BothRssiAndTxPowerIndicateProximity) {
monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_TRANSMIT_POWER);
TEST_F(ProximityAuthProximityMonitorImplTest, IsUnlockAllowed_StartThenStop) {
monitor_.Start();
ProvideConnectionInfo({0, 0, 4});
EXPECT_TRUE(monitor_.IsUnlockAllowed());
EXPECT_TRUE(monitor_.IsInRssiRange());
}
TEST_F(ProximityAuthProximityMonitorImplTest,
ProximityState_CheckTxPower_UnknownRssi) {
monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_TRANSMIT_POWER);
monitor_.Start();
ProvideConnectionInfo({0, 0, 4});
ProvideConnectionInfo({BluetoothDevice::kUnknownPower, 0, 4});
EXPECT_FALSE(monitor_.IsUnlockAllowed());
EXPECT_FALSE(monitor_.IsInRssiRange());
}
TEST_F(ProximityAuthProximityMonitorImplTest,
ProximityState_CheckTxPower_UnknownTxPower) {
monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_TRANSMIT_POWER);
monitor_.Start();
ProvideConnectionInfo({0, 0, 4});
ProvideConnectionInfo({0, BluetoothDevice::kUnknownPower, 4});
EXPECT_FALSE(monitor_.IsUnlockAllowed());
EXPECT_FALSE(monitor_.IsInRssiRange());
}
TEST_F(ProximityAuthProximityMonitorImplTest,
ProximityState_CheckTxPower_UnknownMaxTxPower) {
monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_TRANSMIT_POWER);
monitor_.Start();
ProvideConnectionInfo({0, 0, 4});
ProvideConnectionInfo({0, 0, BluetoothDevice::kUnknownPower});
EXPECT_FALSE(monitor_.IsUnlockAllowed());
EXPECT_FALSE(monitor_.IsInRssiRange());
}
TEST_F(ProximityAuthProximityMonitorImplTest, ProximityState_StartThenStop) {
monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_RSSI);
monitor_.Start();
ProvideConnectionInfo({0, 0, 4});
monitor_.Stop();
EXPECT_FALSE(monitor_.IsUnlockAllowed());
EXPECT_FALSE(monitor_.IsInRssiRange());
}
TEST_F(ProximityAuthProximityMonitorImplTest,
ProximityState_StartThenStopThenStartAgain) {
monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_RSSI);
IsUnlockAllowed_StartThenStopThenStartAgain) {
monitor_.Start();
ProvideConnectionInfo({-10, 4, 4});
ProvideConnectionInfo({-10, 4, 4});
ProvideConnectionInfo({-10, 4, 4});
ProvideConnectionInfo({-10, 4, 4});
ProvideConnectionInfo({-10, 4, 4});
ProvideConnectionInfo({kRssiThreshold / 2, 4, 4});
ProvideConnectionInfo({kRssiThreshold / 2, 4, 4});
ProvideConnectionInfo({kRssiThreshold / 2, 4, 4});
ProvideConnectionInfo({kRssiThreshold / 2, 4, 4});
ProvideConnectionInfo({kRssiThreshold / 2, 4, 4});
EXPECT_TRUE(monitor_.IsUnlockAllowed());
monitor_.Stop();
// Restarting the monitor should immediately reset the proximity state, rather
// than building on the previous rolling average.
monitor_.Start();
ProvideConnectionInfo({0, 4, 4});
ProvideConnectionInfo({kRssiThreshold - 1, 4, 4});
EXPECT_TRUE(monitor_.IsUnlockAllowed());
EXPECT_TRUE(monitor_.IsInRssiRange());
EXPECT_FALSE(monitor_.IsUnlockAllowed());
}
TEST_F(ProximityAuthProximityMonitorImplTest,
ProximityState_RemoteDeviceRemainsInProximity) {
monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_RSSI);
IsUnlockAllowed_RemoteDeviceRemainsInProximity) {
monitor_.Start();
ProvideConnectionInfo({0, 4, 4});
ProvideConnectionInfo({-1, 4, 4});
ProvideConnectionInfo({0, 4, 4});
ProvideConnectionInfo({-2, 4, 4});
ProvideConnectionInfo({-1, 4, 4});
ProvideConnectionInfo({kRssiThreshold / 2 + 1, 4, 4});
ProvideConnectionInfo({kRssiThreshold / 2 - 1, 4, 4});
ProvideConnectionInfo({kRssiThreshold / 2 + 2, 4, 4});
ProvideConnectionInfo({kRssiThreshold / 2 - 3, 4, 4});
EXPECT_TRUE(monitor_.IsUnlockAllowed());
EXPECT_TRUE(monitor_.IsInRssiRange());
// Brief drops in RSSI should be handled by weighted averaging.
ProvideConnectionInfo({-10, 4, 4});
ProvideConnectionInfo({kRssiThreshold - 5, 4, 4});
EXPECT_TRUE(monitor_.IsUnlockAllowed());
EXPECT_TRUE(monitor_.IsInRssiRange());
}
TEST_F(ProximityAuthProximityMonitorImplTest,
ProximityState_RemoteDeviceLeavesProximity) {
monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_RSSI);
IsUnlockAllowed_RemoteDeviceLeavesProximity) {
monitor_.Start();
// Start with a device in proximity.
ProvideConnectionInfo({0, 4, 4});
EXPECT_TRUE(monitor_.IsUnlockAllowed());
EXPECT_TRUE(monitor_.IsInRssiRange());
// Simulate readings for the remote device leaving proximity.
ProvideConnectionInfo({-1, 4, 4});
ProvideConnectionInfo({-4, 4, 4});
ProvideConnectionInfo({0, 4, 4});
ProvideConnectionInfo({-10, 4, 4});
ProvideConnectionInfo({-8, 4, 4});
ProvideConnectionInfo({-15, 4, 4});
ProvideConnectionInfo({-10, 4, 4});
ProvideConnectionInfo({-10, 4, 4});
ProvideConnectionInfo({-10, 4, 4});
ProvideConnectionInfo({-10, 4, 4});
ProvideConnectionInfo({-20, 4, 4});
ProvideConnectionInfo({kRssiThreshold, 4, 4});
ProvideConnectionInfo({kRssiThreshold - 10, 4, 4});
ProvideConnectionInfo({kRssiThreshold - 20, 4, 4});
ProvideConnectionInfo({kRssiThreshold - 20, 4, 4});
EXPECT_FALSE(monitor_.IsUnlockAllowed());
EXPECT_FALSE(monitor_.IsInRssiRange());
}
TEST_F(ProximityAuthProximityMonitorImplTest,
ProximityState_RemoteDeviceEntersProximity) {
monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_RSSI);
IsUnlockAllowed_RemoteDeviceEntersProximity) {
monitor_.Start();
// Start with a device in proximity.
ProvideConnectionInfo({-20, 4, 4});
// Start with a device out of proximity.
ProvideConnectionInfo({2 * kRssiThreshold, 4, 4});
EXPECT_FALSE(monitor_.IsUnlockAllowed());
EXPECT_FALSE(monitor_.IsInRssiRange());
// Simulate readings for the remote device entering proximity.
ProvideConnectionInfo({-15, 4, 4});
......@@ -448,18 +259,15 @@ TEST_F(ProximityAuthProximityMonitorImplTest,
ProvideConnectionInfo({0, 4, 4});
EXPECT_TRUE(monitor_.IsUnlockAllowed());
EXPECT_TRUE(monitor_.IsInRssiRange());
}
TEST_F(ProximityAuthProximityMonitorImplTest,
ProximityState_DeviceNotKnownToAdapter) {
monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_RSSI);
IsUnlockAllowed_DeviceNotKnownToAdapter) {
monitor_.Start();
// Start with the device known to the adapter and in proximity.
ProvideConnectionInfo({0, 4, 4});
EXPECT_TRUE(monitor_.IsUnlockAllowed());
EXPECT_TRUE(monitor_.IsInRssiRange());
// Simulate it being forgotten.
ON_CALL(*bluetooth_adapter_, GetDevice(kBluetoothAddress))
......@@ -468,18 +276,15 @@ TEST_F(ProximityAuthProximityMonitorImplTest,
RunPendingTasks();
EXPECT_FALSE(monitor_.IsUnlockAllowed());
EXPECT_FALSE(monitor_.IsInRssiRange());
}
TEST_F(ProximityAuthProximityMonitorImplTest,
ProximityState_DeviceNotConnected) {
monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_RSSI);
IsUnlockAllowed_DeviceNotConnected) {
monitor_.Start();
// Start with the device connected and in proximity.
ProvideConnectionInfo({0, 4, 4});
EXPECT_TRUE(monitor_.IsUnlockAllowed());
EXPECT_TRUE(monitor_.IsInRssiRange());
// Simulate it disconnecting.
ON_CALL(remote_bluetooth_device_, IsConnected()).WillByDefault(Return(false));
......@@ -487,19 +292,14 @@ TEST_F(ProximityAuthProximityMonitorImplTest,
RunPendingTasks();
EXPECT_FALSE(monitor_.IsUnlockAllowed());
EXPECT_FALSE(monitor_.IsInRssiRange());
}
TEST_F(ProximityAuthProximityMonitorImplTest,
ProximityState_ConnectionInfoReceivedAfterStopping) {
monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_RSSI);
IsUnlockAllowed_ConnectionInfoReceivedAfterStopping) {
monitor_.Start();
monitor_.Stop();
ProvideConnectionInfo({0, 4, 4});
EXPECT_FALSE(monitor_.IsUnlockAllowed());
EXPECT_FALSE(monitor_.IsInRssiRange());
}
TEST_F(ProximityAuthProximityMonitorImplTest,
......@@ -515,10 +315,6 @@ TEST_F(ProximityAuthProximityMonitorImplTest,
monitor_.RecordProximityMetricsOnAuthSuccess();
histogram_tester.ExpectUniqueSample("EasyUnlock.AuthProximity.RollingRssi",
-6, 1);
histogram_tester.ExpectUniqueSample(
"EasyUnlock.AuthProximity.TransmitPowerDelta", -1, 1);
histogram_tester.ExpectUniqueSample(
"EasyUnlock.AuthProximity.TimeSinceLastZeroRssi", 304, 1);
histogram_tester.ExpectUniqueSample(
"EasyUnlock.AuthProximity.RemoteDeviceModelHash",
1881443083 /* hash of "LGE Nexus 5" */, 1);
......@@ -533,20 +329,18 @@ TEST_F(ProximityAuthProximityMonitorImplTest,
monitor_.RecordProximityMetricsOnAuthSuccess();
histogram_tester.ExpectUniqueSample("EasyUnlock.AuthProximity.RollingRssi",
-100, 1);
histogram_tester.ExpectUniqueSample(
"EasyUnlock.AuthProximity.TransmitPowerDelta", 50, 1);
}
TEST_F(ProximityAuthProximityMonitorImplTest,
RecordProximityMetricsOnAuthSuccess_UnknownValues) {
// Note: A device without a recorded name will have its Bluetooth address as
// its name.
// Note: A device without a recorded name will have "Unknown" as its name.
cryptauth::RemoteDevice unnamed_remote_device(
kRemoteDeviceUserId, kBluetoothAddress, kRemoteDevicePublicKey,
kRemoteDeviceUserId, "" /* name */, kRemoteDevicePublicKey,
kBluetoothAddress, kPersistentSymmetricKey, std::string());
cryptauth::FakeConnection connection(unnamed_remote_device);
std::unique_ptr<base::TickClock> clock(new base::SimpleTestTickClock());
ProximityMonitorImpl monitor(unnamed_remote_device, std::move(clock));
ProximityMonitorImpl monitor(&connection, std::move(clock));
monitor.AddObserver(&observer_);
monitor.Start();
ProvideConnectionInfo({127, 127, 127});
......@@ -555,11 +349,6 @@ TEST_F(ProximityAuthProximityMonitorImplTest,
monitor.RecordProximityMetricsOnAuthSuccess();
histogram_tester.ExpectUniqueSample("EasyUnlock.AuthProximity.RollingRssi",
127, 1);
histogram_tester.ExpectUniqueSample(
"EasyUnlock.AuthProximity.TransmitPowerDelta", 127, 1);
histogram_tester.ExpectUniqueSample(
"EasyUnlock.AuthProximity.TimeSinceLastZeroRssi",
base::TimeDelta::FromSeconds(10).InMilliseconds(), 1);
histogram_tester.ExpectUniqueSample(
"EasyUnlock.AuthProximity.RemoteDeviceModelHash",
-1808066424 /* hash of "Unknown" */, 1);
......
......@@ -6,6 +6,7 @@
#define COMPONENTS_PROXIMITY_AUTH_REMOTE_DEVICE_LIFE_CYCLE_H
#include "base/macros.h"
#include "components/cryptauth/connection.h"
#include "components/cryptauth/remote_device.h"
namespace proximity_auth {
......@@ -57,6 +58,9 @@ class RemoteDeviceLifeCycle {
// Returns the RemoteDevice instance that this life cycle manages.
virtual cryptauth::RemoteDevice GetRemoteDevice() const = 0;
// Returns the current Connection, or null if the device is not yet connected.
virtual cryptauth::Connection* GetConnection() const = 0;
// Returns the current state of in the life cycle.
virtual State GetState() const = 0;
......
......@@ -62,6 +62,14 @@ cryptauth::RemoteDevice RemoteDeviceLifeCycleImpl::GetRemoteDevice() const {
return remote_device_;
}
cryptauth::Connection* RemoteDeviceLifeCycleImpl::GetConnection() const {
if (connection_)
return connection_.get();
if (messenger_)
return messenger_->GetConnection();
return nullptr;
}
RemoteDeviceLifeCycle::State RemoteDeviceLifeCycleImpl::GetState() const {
return state_;
}
......
......@@ -41,6 +41,7 @@ class RemoteDeviceLifeCycleImpl : public RemoteDeviceLifeCycle,
// RemoteDeviceLifeCycle:
void Start() override;
cryptauth::RemoteDevice GetRemoteDevice() const override;
cryptauth::Connection* GetConnection() const override;
RemoteDeviceLifeCycle::State GetState() const override;
Messenger* GetMessenger() override;
void AddObserver(Observer* observer) override;
......
......@@ -141,7 +141,6 @@ void UnlockManagerImpl::SetRemoteDeviceLifeCycle(
life_cycle_ = life_cycle;
if (life_cycle_) {
proximity_monitor_ = CreateProximityMonitor(life_cycle->GetRemoteDevice());
SetWakingUpState(true);
} else {
proximity_monitor_.reset();
......@@ -156,8 +155,12 @@ void UnlockManagerImpl::OnLifeCycleStateChanged() {
<< static_cast<int>(state);
remote_screenlock_state_.reset();
if (state == RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED)
if (state == RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED) {
DCHECK(life_cycle_->GetConnection());
DCHECK(GetMessenger());
proximity_monitor_ = CreateProximityMonitor(life_cycle_->GetConnection());
GetMessenger()->AddObserver(this);
}
if (state == RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED)
SetWakingUpState(false);
......@@ -320,9 +323,9 @@ void UnlockManagerImpl::OnAuthAttempted(
}
std::unique_ptr<ProximityMonitor> UnlockManagerImpl::CreateProximityMonitor(
const cryptauth::RemoteDevice& remote_device) {
cryptauth::Connection* connection) {
return base::MakeUnique<ProximityMonitorImpl>(
remote_device, base::WrapUnique(new base::DefaultTickClock()));
connection, base::WrapUnique(new base::DefaultTickClock()));
}
void UnlockManagerImpl::SendSignInChallenge() {
......@@ -356,7 +359,10 @@ ScreenlockState UnlockManagerImpl::GetScreenlockState() {
RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED)
return ScreenlockState::PHONE_NOT_AUTHENTICATED;
if (is_waking_up_)
if (is_waking_up_ ||
life_cycle_->GetState() == RemoteDeviceLifeCycle::State::AUTHENTICATING ||
life_cycle_->GetState() ==
RemoteDeviceLifeCycle::State::FINDING_CONNECTION)
return ScreenlockState::BLUETOOTH_CONNECTING;
if (!bluetooth_adapter_ || !bluetooth_adapter_->IsPowered())
......@@ -370,8 +376,7 @@ ScreenlockState UnlockManagerImpl::GetScreenlockState() {
// If the RSSI is too low, then the remote device is nowhere near the local
// device. This message should take priority over messages about screen lock
// states.
if (!proximity_monitor_->IsUnlockAllowed() &&
!proximity_monitor_->IsInRssiRange())
if (!proximity_monitor_->IsUnlockAllowed())
return ScreenlockState::RSSI_TOO_LOW;
if (remote_screenlock_state_) {
......@@ -380,11 +385,6 @@ ScreenlockState UnlockManagerImpl::GetScreenlockState() {
return ScreenlockState::PHONE_NOT_LOCKABLE;
case RemoteScreenlockState::LOCKED:
if (proximity_monitor_->GetStrategy() ==
ProximityMonitor::Strategy::CHECK_TRANSMIT_POWER &&
!proximity_monitor_->IsUnlockAllowed()) {
return ScreenlockState::PHONE_LOCKED_AND_TX_POWER_TOO_HIGH;
}
return ScreenlockState::PHONE_LOCKED;
case RemoteScreenlockState::UNKNOWN:
......@@ -396,18 +396,6 @@ ScreenlockState UnlockManagerImpl::GetScreenlockState() {
}
}
if (!proximity_monitor_->IsUnlockAllowed()) {
ProximityMonitor::Strategy strategy = proximity_monitor_->GetStrategy();
if (strategy != ProximityMonitor::Strategy::CHECK_TRANSMIT_POWER) {
// CHECK_RSSI should have been handled above, and no other states should
// prevent unlocking.
PA_LOG(ERROR) << "[Unlock] Invalid ProximityMonitor strategy: "
<< static_cast<int>(strategy);
return ScreenlockState::NO_PHONE;
}
return ScreenlockState::TX_POWER_TOO_HIGH;
}
return ScreenlockState::NO_PHONE;
}
......
......@@ -52,10 +52,10 @@ class UnlockManagerImpl : public UnlockManager,
ScreenlockBridge::LockHandler::AuthType auth_type) override;
protected:
// Creates a ProximityMonitor instance for the given |remote_device|.
// Creates a ProximityMonitor instance for the given |connection|.
// Exposed for testing.
virtual std::unique_ptr<ProximityMonitor> CreateProximityMonitor(
const cryptauth::RemoteDevice& remote_device);
cryptauth::Connection* connection);
private:
// The possible lock screen states for the remote device.
......
......@@ -13,9 +13,11 @@
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "components/cryptauth/cryptauth_test_util.h"
#include "components/cryptauth/fake_connection.h"
#include "components/cryptauth/fake_secure_context.h"
#include "components/cryptauth/secure_context.h"
#include "components/proximity_auth/fake_lock_handler.h"
#include "components/proximity_auth/fake_remote_device_life_cycle.h"
#include "components/proximity_auth/logging/logging.h"
#include "components/proximity_auth/messenger.h"
#include "components/proximity_auth/mock_proximity_auth_client.h"
......@@ -66,6 +68,7 @@ class MockRemoteDeviceLifeCycle : public RemoteDeviceLifeCycle {
MOCK_CONST_METHOD0(GetRemoteDevice, cryptauth::RemoteDevice());
MOCK_CONST_METHOD0(GetState, State());
MOCK_METHOD0(GetMessenger, Messenger*());
MOCK_CONST_METHOD0(GetConnection, cryptauth::Connection*());
MOCK_METHOD1(AddObserver, void(Observer*));
MOCK_METHOD1(RemoveObserver, void(Observer*));
};
......@@ -82,6 +85,7 @@ class MockMessenger : public Messenger {
MOCK_METHOD1(RequestDecryption, void(const std::string& challenge));
MOCK_METHOD0(RequestUnlock, void());
MOCK_CONST_METHOD0(GetSecureContext, cryptauth::SecureContext*());
MOCK_CONST_METHOD0(GetConnection, cryptauth::Connection*());
private:
DISALLOW_COPY_AND_ASSIGN(MockMessenger);
......@@ -89,24 +93,25 @@ class MockMessenger : public Messenger {
class MockProximityMonitor : public ProximityMonitor {
public:
MockProximityMonitor() {
ON_CALL(*this, GetStrategy())
.WillByDefault(Return(ProximityMonitor::Strategy::NONE));
MockProximityMonitor() : started_(false), stopped_(false) {
ON_CALL(*this, IsUnlockAllowed()).WillByDefault(Return(true));
ON_CALL(*this, IsInRssiRange()).WillByDefault(Return(false));
}
~MockProximityMonitor() override {}
MOCK_METHOD0(Start, void());
MOCK_METHOD0(Stop, void());
MOCK_CONST_METHOD0(GetStrategy, Strategy());
void Start() override { started_ = true; }
void Stop() override { stopped_ = true; }
MOCK_CONST_METHOD0(IsUnlockAllowed, bool());
MOCK_CONST_METHOD0(IsInRssiRange, bool());
MOCK_METHOD0(RecordProximityMetricsOnAuthSuccess, void());
MOCK_METHOD1(AddObserver, void(ProximityMonitorObserver*));
MOCK_METHOD1(RemoveObserver, void(ProximityMonitorObserver*));
bool started() { return started_; }
bool stopped() { return stopped_; }
private:
bool started_;
bool stopped_;
DISALLOW_COPY_AND_ASSIGN(MockProximityMonitor);
};
......@@ -132,8 +137,9 @@ class TestUnlockManager : public UnlockManagerImpl {
private:
std::unique_ptr<ProximityMonitor> CreateProximityMonitor(
const cryptauth::RemoteDevice& remote_device) override {
EXPECT_EQ(cryptauth::kTestRemoteDevicePublicKey, remote_device.public_key);
cryptauth::Connection* connection) override {
EXPECT_EQ(cryptauth::kTestRemoteDevicePublicKey,
connection->remote_device().public_key);
std::unique_ptr<MockProximityMonitor> proximity_monitor(
new NiceMock<MockProximityMonitor>());
proximity_monitor_ = proximity_monitor.get();
......@@ -162,17 +168,18 @@ class ProximityAuthUnlockManagerImplTest : public testing::Test {
public:
ProximityAuthUnlockManagerImplTest()
: remote_device_(cryptauth::CreateClassicRemoteDeviceForTest()),
life_cycle_(remote_device_),
connection_(remote_device_),
bluetooth_adapter_(CreateAndRegisterMockBluetoothAdapter()),
task_runner_(new base::TestSimpleTaskRunner()),
thread_task_runner_handle_(task_runner_) {
ON_CALL(*bluetooth_adapter_, IsPowered()).WillByDefault(Return(true));
ON_CALL(life_cycle_, GetMessenger()).WillByDefault(Return(&messenger_));
ON_CALL(life_cycle_, GetRemoteDevice())
.WillByDefault(Return(remote_device_));
ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(true));
ON_CALL(messenger_, GetSecureContext())
.WillByDefault(Return(&secure_context_));
life_cycle_.set_connection(&connection_);
life_cycle_.set_messenger(&messenger_);
ScreenlockBridge::Get()->SetLockHandler(&lock_handler_);
#if defined(OS_CHROMEOS)
......@@ -207,15 +214,10 @@ class ProximityAuthUnlockManagerImplTest : public testing::Test {
}
void SimulateUserPresentState() {
ON_CALL(life_cycle_, GetState())
.WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED));
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
ON_CALL(life_cycle_, GetState())
.WillByDefault(
Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
life_cycle_.ChangeState(
RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
unlock_manager_->OnLifeCycleStateChanged();
unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked);
}
......@@ -227,12 +229,13 @@ class ProximityAuthUnlockManagerImplTest : public testing::Test {
protected:
cryptauth::RemoteDevice remote_device_;
FakeRemoteDeviceLifeCycle life_cycle_;
cryptauth::FakeConnection connection_;
// Mock used for verifying interactions with the Bluetooth subsystem.
scoped_refptr<device::MockBluetoothAdapter> bluetooth_adapter_;
NiceMock<MockProximityAuthClient> proximity_auth_client_;
NiceMock<MockRemoteDeviceLifeCycle> life_cycle_;
NiceMock<MockMessenger> messenger_;
std::unique_ptr<TestUnlockManager> unlock_manager_;
cryptauth::FakeSecureContext secure_context_;
......@@ -253,10 +256,10 @@ TEST_F(ProximityAuthUnlockManagerImplTest,
IsUnlockAllowed_SessionLock_AllGood) {
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
ON_CALL(life_cycle_, GetState())
.WillByDefault(
Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
life_cycle_.ChangeState(
RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
unlock_manager_->OnLifeCycleStateChanged();
unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked);
EXPECT_TRUE(unlock_manager_->IsUnlockAllowed());
......@@ -264,14 +267,10 @@ TEST_F(ProximityAuthUnlockManagerImplTest,
TEST_F(ProximityAuthUnlockManagerImplTest, IsUnlockAllowed_SignIn_AllGood) {
CreateUnlockManager(ProximityAuthSystem::SIGN_IN);
ON_CALL(life_cycle_, GetState())
.WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED));
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
ON_CALL(life_cycle_, GetState())
.WillByDefault(
Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
life_cycle_.ChangeState(
RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
unlock_manager_->OnLifeCycleStateChanged();
ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(true));
......@@ -283,14 +282,10 @@ TEST_F(ProximityAuthUnlockManagerImplTest, IsUnlockAllowed_SignIn_AllGood) {
TEST_F(ProximityAuthUnlockManagerImplTest,
IsUnlockAllowed_SignIn_MessengerDoesNotSupportSignIn) {
CreateUnlockManager(ProximityAuthSystem::SIGN_IN);
ON_CALL(life_cycle_, GetState())
.WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED));
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
ON_CALL(life_cycle_, GetState())
.WillByDefault(
Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
life_cycle_.ChangeState(
RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
unlock_manager_->OnLifeCycleStateChanged();
ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(false));
......@@ -299,31 +294,17 @@ TEST_F(ProximityAuthUnlockManagerImplTest,
EXPECT_FALSE(unlock_manager_->IsUnlockAllowed());
}
TEST_F(ProximityAuthUnlockManagerImplTest,
IsUnlockAllowed_SignIn_MessengerIsNull) {
CreateUnlockManager(ProximityAuthSystem::SIGN_IN);
ON_CALL(life_cycle_, GetState())
.WillByDefault(
Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
ON_CALL(life_cycle_, GetMessenger()).WillByDefault(Return(nullptr));
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked);
EXPECT_FALSE(unlock_manager_->IsUnlockAllowed());
}
TEST_F(ProximityAuthUnlockManagerImplTest,
IsUnlockAllowed_DisallowedByProximityMonitor) {
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
ON_CALL(life_cycle_, GetState())
.WillByDefault(
Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked);
life_cycle_.ChangeState(
RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
unlock_manager_->OnLifeCycleStateChanged();
ON_CALL(*proximity_monitor(), IsUnlockAllowed()).WillByDefault(Return(false));
unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked);
EXPECT_FALSE(unlock_manager_->IsUnlockAllowed());
}
......@@ -331,9 +312,9 @@ TEST_F(ProximityAuthUnlockManagerImplTest,
IsUnlockAllowed_SecureChannelNotEstablished) {
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
ON_CALL(life_cycle_, GetState())
.WillByDefault(Return(RemoteDeviceLifeCycle::State::AUTHENTICATING));
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::AUTHENTICATING);
unlock_manager_->OnLifeCycleStateChanged();
unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenUnlocked);
EXPECT_FALSE(unlock_manager_->IsUnlockAllowed());
......@@ -353,10 +334,10 @@ TEST_F(ProximityAuthUnlockManagerImplTest,
IsUnlockAllowed_RemoteScreenlockStateLocked) {
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
ON_CALL(life_cycle_, GetState())
.WillByDefault(
Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
life_cycle_.ChangeState(
RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
unlock_manager_->OnLifeCycleStateChanged();
unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenLocked);
EXPECT_FALSE(unlock_manager_->IsUnlockAllowed());
......@@ -366,10 +347,10 @@ TEST_F(ProximityAuthUnlockManagerImplTest,
IsUnlockAllowed_RemoteScreenlockStateUnknown) {
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
ON_CALL(life_cycle_, GetState())
.WillByDefault(
Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
life_cycle_.ChangeState(
RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
unlock_manager_->OnLifeCycleStateChanged();
unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenlockStateUnknown);
EXPECT_FALSE(unlock_manager_->IsUnlockAllowed());
......@@ -379,10 +360,10 @@ TEST_F(ProximityAuthUnlockManagerImplTest,
IsUnlockAllowed_RemoteScreenlockStateDisabled) {
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
ON_CALL(life_cycle_, GetState())
.WillByDefault(
Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
life_cycle_.ChangeState(
RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
unlock_manager_->OnLifeCycleStateChanged();
unlock_manager_->OnRemoteStatusUpdate(kRemoteScreenlockDisabled);
EXPECT_FALSE(unlock_manager_->IsUnlockAllowed());
......@@ -392,10 +373,10 @@ TEST_F(ProximityAuthUnlockManagerImplTest,
IsUnlockAllowed_RemoteScreenlockStateNotYetReceived) {
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
ON_CALL(life_cycle_, GetState())
.WillByDefault(
Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
life_cycle_.ChangeState(
RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
unlock_manager_->OnLifeCycleStateChanged();
EXPECT_FALSE(unlock_manager_->IsUnlockAllowed());
}
......@@ -418,20 +399,6 @@ TEST_F(ProximityAuthUnlockManagerImplTest,
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
}
TEST_F(ProximityAuthUnlockManagerImplTest,
SetRemoteDeviceLifeCycle_NullThenExistingRemoteDeviceLifeCycle) {
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
SimulateUserPresentState();
EXPECT_CALL(proximity_auth_client_,
UpdateScreenlockState(ScreenlockState::INACTIVE));
unlock_manager_->SetRemoteDeviceLifeCycle(nullptr);
EXPECT_CALL(proximity_auth_client_,
UpdateScreenlockState(ScreenlockState::AUTHENTICATED));
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
}
TEST_F(ProximityAuthUnlockManagerImplTest,
SetRemoteDeviceLifeCycle_AuthenticationFailed) {
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
......@@ -439,9 +406,8 @@ TEST_F(ProximityAuthUnlockManagerImplTest,
unlock_manager_->SetRemoteDeviceLifeCycle(nullptr);
ON_CALL(life_cycle_, GetState())
.WillByDefault(
Return(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED));
life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED);
EXPECT_CALL(proximity_auth_client_,
UpdateScreenlockState(ScreenlockState::PHONE_NOT_AUTHENTICATED));
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
......@@ -453,8 +419,8 @@ TEST_F(ProximityAuthUnlockManagerImplTest, SetRemoteDeviceLifeCycle_WakingUp) {
unlock_manager_->SetRemoteDeviceLifeCycle(nullptr);
ON_CALL(life_cycle_, GetState())
.WillByDefault(Return(RemoteDeviceLifeCycle::State::FINDING_CONNECTION));
life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::FINDING_CONNECTION);
EXPECT_CALL(proximity_auth_client_,
UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING));
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
......@@ -473,27 +439,23 @@ TEST_F(
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
SimulateUserPresentState();
ON_CALL(life_cycle_, GetState())
.WillByDefault(Return(RemoteDeviceLifeCycle::State::FINDING_CONNECTION));
EXPECT_CALL(*proximity_monitor(), Stop()).Times(AtLeast(1));
unlock_manager_->OnLifeCycleStateChanged();
life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::FINDING_CONNECTION);
unlock_manager_->OnLifeCycleStateChanged();
EXPECT_TRUE(proximity_monitor()->stopped());
}
TEST_F(
ProximityAuthUnlockManagerImplTest,
SetRemoteDeviceLifeCycle_ConnectedRemoteDeviceLifeCycle_StartsProximityMonitor) {
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
ON_CALL(life_cycle_, GetState())
.WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED));
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
ON_CALL(life_cycle_, GetState())
.WillByDefault(
Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
EXPECT_CALL(*proximity_monitor(), Start()).Times(AtLeast(1));
unlock_manager_->OnLifeCycleStateChanged();
life_cycle_.ChangeState(
RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
unlock_manager_->OnLifeCycleStateChanged();
EXPECT_TRUE(proximity_monitor()->started());
}
TEST_F(ProximityAuthUnlockManagerImplTest,
......@@ -508,7 +470,7 @@ TEST_F(ProximityAuthUnlockManagerImplTest,
OnLifeCycleStateChanged_StartsProximityMonitor) {
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
SimulateUserPresentState();
EXPECT_CALL(*proximity_monitor(), Start()).Times(AtLeast(1));
EXPECT_TRUE(proximity_monitor()->started());
unlock_manager_->OnLifeCycleStateChanged();
}
......@@ -517,12 +479,10 @@ TEST_F(ProximityAuthUnlockManagerImplTest,
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
SimulateUserPresentState();
ON_CALL(life_cycle_, GetState())
.WillByDefault(
Return(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED));
EXPECT_CALL(*proximity_monitor(), Stop()).Times(AtLeast(1));
unlock_manager_->OnLifeCycleStateChanged();
life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED);
unlock_manager_->OnLifeCycleStateChanged();
EXPECT_TRUE(proximity_monitor()->stopped());
}
TEST_F(ProximityAuthUnlockManagerImplTest,
......@@ -530,11 +490,9 @@ TEST_F(ProximityAuthUnlockManagerImplTest,
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
SimulateUserPresentState();
ON_CALL(life_cycle_, GetState())
.WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED));
EXPECT_CALL(proximity_auth_client_,
UpdateScreenlockState(ScreenlockState::INACTIVE));
life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::STOPPED);
unlock_manager_->OnLifeCycleStateChanged();
}
......@@ -543,44 +501,31 @@ TEST_F(ProximityAuthUnlockManagerImplTest,
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
SimulateUserPresentState();
ON_CALL(life_cycle_, GetState())
.WillByDefault(
Return(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED));
EXPECT_CALL(proximity_auth_client_,
UpdateScreenlockState(ScreenlockState::PHONE_NOT_AUTHENTICATED));
life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED);
unlock_manager_->OnLifeCycleStateChanged();
}
TEST_F(ProximityAuthUnlockManagerImplTest,
OnLifeCycleStateChanged_FindingConnection_UpdatesScreenlockState) {
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
ON_CALL(life_cycle_, GetState())
.WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED));
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
ON_CALL(life_cycle_, GetState())
.WillByDefault(Return(RemoteDeviceLifeCycle::State::FINDING_CONNECTION));
EXPECT_CALL(proximity_auth_client_,
UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING));
life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::FINDING_CONNECTION);
unlock_manager_->OnLifeCycleStateChanged();
}
TEST_F(ProximityAuthUnlockManagerImplTest,
OnLifeCycleStateChanged_Authenticating_UpdatesScreenlockState) {
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
ON_CALL(life_cycle_, GetState())
.WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED));
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
ON_CALL(life_cycle_, GetState())
.WillByDefault(Return(RemoteDeviceLifeCycle::State::AUTHENTICATING));
EXPECT_CALL(proximity_auth_client_,
UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING));
life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::AUTHENTICATING);
unlock_manager_->OnLifeCycleStateChanged();
}
......@@ -588,17 +533,12 @@ TEST_F(
ProximityAuthUnlockManagerImplTest,
OnLifeCycleStateChanged_SecureChannelEstablished_UpdatesScreenlockState) {
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
ON_CALL(life_cycle_, GetState())
.WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED));
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
ON_CALL(life_cycle_, GetState())
.WillByDefault(
Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
EXPECT_CALL(proximity_auth_client_,
UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING));
life_cycle_.ChangeState(
RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
unlock_manager_->OnLifeCycleStateChanged();
}
......@@ -606,10 +546,8 @@ TEST_F(ProximityAuthUnlockManagerImplTest,
OnDisconnected_UnregistersAsObserver) {
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
SimulateUserPresentState();
ON_CALL(life_cycle_, GetState())
.WillByDefault(
Return(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED));
life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED);
unlock_manager_->OnLifeCycleStateChanged();
EXPECT_CALL(messenger_, RemoveObserver(unlock_manager_.get()))
.Times(testing::AtLeast(1));
......@@ -622,27 +560,23 @@ TEST_F(ProximityAuthUnlockManagerImplTest,
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
SimulateUserPresentState();
EXPECT_CALL(*proximity_monitor(), Stop());
unlock_manager_.get()->OnScreenDidUnlock(
ScreenlockBridge::LockHandler::LOCK_SCREEN);
EXPECT_TRUE(proximity_monitor()->stopped());
}
TEST_F(ProximityAuthUnlockManagerImplTest,
OnScreenDidLock_StartsProximityMonitor) {
CreateUnlockManager(ProximityAuthSystem::SESSION_LOCK);
ON_CALL(life_cycle_, GetState())
.WillByDefault(Return(RemoteDeviceLifeCycle::State::STOPPED));
unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
ON_CALL(life_cycle_, GetState())
.WillByDefault(
Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
unlock_manager_->OnLifeCycleStateChanged();
EXPECT_CALL(*proximity_monitor(), Start());
unlock_manager_.get()->OnScreenDidLock(
ScreenlockBridge::LockHandler::LOCK_SCREEN);
life_cycle_.ChangeState(
RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
unlock_manager_->OnLifeCycleStateChanged();
EXPECT_TRUE(proximity_monitor()->started());
}
TEST_F(ProximityAuthUnlockManagerImplTest, OnScreenDidLock_SetsWakingUpState) {
......@@ -652,14 +586,11 @@ TEST_F(ProximityAuthUnlockManagerImplTest, OnScreenDidLock_SetsWakingUpState) {
unlock_manager_.get()->OnScreenDidUnlock(
ScreenlockBridge::LockHandler::LOCK_SCREEN);
ON_CALL(life_cycle_, GetState())
.WillByDefault(Return(RemoteDeviceLifeCycle::State::FINDING_CONNECTION));
unlock_manager_->OnLifeCycleStateChanged();
EXPECT_CALL(proximity_auth_client_,
UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING));
unlock_manager_.get()->OnScreenDidLock(
ScreenlockBridge::LockHandler::LOCK_SCREEN);
life_cycle_.ChangeState(RemoteDeviceLifeCycle::State::FINDING_CONNECTION);
unlock_manager_->OnLifeCycleStateChanged();
}
TEST_F(ProximityAuthUnlockManagerImplTest,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment