Commit 9a7a50d6 authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Commit Bot

[CrOS Tether] Provide extra data to BleConnectionManager observers.

This CL adds an extra StateChangeDetail parameter to the
Observer::OnSecureChannelStatusChanged() function. This parameter is
currently unused, but it will be used by a future CL to better handle
connection retries.

Bug: 805218, 672263
Change-Id: I4dc80f324d74a6df54113b058dec0bb07459ae3f
Reviewed-on: https://chromium-review.googlesource.com/888038Reviewed-by: default avatarJeremy Klein <jlklein@chromium.org>
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532510}
parent f9a22f3e
...@@ -20,7 +20,32 @@ namespace chromeos { ...@@ -20,7 +20,32 @@ namespace chromeos {
namespace tether { namespace tether {
namespace { namespace {
const char kTetherFeature[] = "magic_tether"; const char kTetherFeature[] = "magic_tether";
std::string StateChangeDetailToString(
BleConnectionManager::StateChangeDetail state_change_detail) {
switch (state_change_detail) {
case BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE:
return "[none]";
case BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_COULD_NOT_ATTEMPT_CONNECTION:
return "[could not attempt connection]";
case BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_GATT_CONNECTION_WAS_ATTEMPTED:
return "[GATT connection was attempted]";
case BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_INTERRUPTED_BY_HIGHER_PRIORITY:
return "[attempt interrupted by higher priority]";
case BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_DEVICE_WAS_UNREGISTERED:
return "[device was unregistered]";
default:
NOTREACHED();
return std::string();
}
}
} // namespace } // namespace
const int64_t BleConnectionManager::kAdvertisingTimeoutMillis = 12000; const int64_t BleConnectionManager::kAdvertisingTimeoutMillis = 12000;
...@@ -158,13 +183,18 @@ void BleConnectionManager::ConnectionMetadata::OnSecureChannelStatusChanged( ...@@ -158,13 +183,18 @@ void BleConnectionManager::ConnectionMetadata::OnSecureChannelStatusChanged(
const cryptauth::SecureChannel::Status old_status_copy = old_status; const cryptauth::SecureChannel::Status old_status_copy = old_status;
const cryptauth::SecureChannel::Status new_status_copy = new_status; const cryptauth::SecureChannel::Status new_status_copy = new_status;
StateChangeDetail state_change_detail =
StateChangeDetail::STATE_CHANGE_DETAIL_NONE;
if (new_status == cryptauth::SecureChannel::Status::DISCONNECTED) { if (new_status == cryptauth::SecureChannel::Status::DISCONNECTED) {
secure_channel_->RemoveObserver(this); secure_channel_->RemoveObserver(this);
secure_channel_.reset(); secure_channel_.reset();
state_change_detail =
StateChangeDetail::STATE_CHANGE_DETAIL_GATT_CONNECTION_WAS_ATTEMPTED;
} }
manager_->OnSecureChannelStatusChanged(device_id_, old_status_copy, manager_->OnSecureChannelStatusChanged(device_id_, old_status_copy,
new_status_copy); new_status_copy, state_change_detail);
} }
void BleConnectionManager::ConnectionMetadata::OnMessageReceived( void BleConnectionManager::ConnectionMetadata::OnMessageReceived(
...@@ -177,7 +207,7 @@ void BleConnectionManager::ConnectionMetadata::OnMessageReceived( ...@@ -177,7 +207,7 @@ void BleConnectionManager::ConnectionMetadata::OnMessageReceived(
return; return;
} }
manager_->SendMessageReceivedEvent(device_id_, payload); manager_->NotifyMessageReceived(device_id_, payload);
} }
void BleConnectionManager::ConnectionMetadata::OnMessageSent( void BleConnectionManager::ConnectionMetadata::OnMessageSent(
...@@ -187,7 +217,7 @@ void BleConnectionManager::ConnectionMetadata::OnMessageSent( ...@@ -187,7 +217,7 @@ void BleConnectionManager::ConnectionMetadata::OnMessageSent(
PA_LOG(INFO) << "Message sent successfully to device with ID \"" PA_LOG(INFO) << "Message sent successfully to device with ID \""
<< cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id_) << cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id_)
<< "\"; message sequence number: " << sequence_number; << "\"; message sequence number: " << sequence_number;
manager_->SendMessageSentEvent(sequence_number); manager_->NotifyMessageSent(sequence_number);
} }
void BleConnectionManager::ConnectionMetadata:: void BleConnectionManager::ConnectionMetadata::
...@@ -272,9 +302,10 @@ void BleConnectionManager::UnregisterRemoteDevice( ...@@ -272,9 +302,10 @@ void BleConnectionManager::UnregisterRemoteDevice(
if (status_before_disconnect != if (status_before_disconnect !=
cryptauth::SecureChannel::Status::DISCONNECTED) { cryptauth::SecureChannel::Status::DISCONNECTED) {
// Send a status update for the disconnection. // Send a status update for the disconnection.
SendSecureChannelStatusChangeEvent( NotifySecureChannelStatusChanged(
device_id_copy, status_before_disconnect, device_id_copy, status_before_disconnect,
cryptauth::SecureChannel::Status::DISCONNECTED); cryptauth::SecureChannel::Status::DISCONNECTED,
StateChangeDetail::STATE_CHANGE_DETAIL_DEVICE_WAS_UNREGISTERED);
} }
} }
...@@ -425,7 +456,9 @@ void BleConnectionManager::UpdateConnectionAttempts() { ...@@ -425,7 +456,9 @@ void BleConnectionManager::UpdateConnectionAttempts() {
<< cryptauth::RemoteDevice::TruncateDeviceIdForLogs( << cryptauth::RemoteDevice::TruncateDeviceIdForLogs(
device_id_to_stop) device_id_to_stop)
<< "\" interrupted by higher-priority connection."; << "\" interrupted by higher-priority connection.";
EndUnsuccessfulAttempt(device_id_to_stop); EndUnsuccessfulAttempt(
device_id_to_stop,
StateChangeDetail::STATE_CHANGE_DETAIL_INTERRUPTED_BY_HIGHER_PRIORITY);
} }
for (const auto& device_id : should_advertise_to) { for (const auto& device_id : should_advertise_to) {
...@@ -479,22 +512,24 @@ void BleConnectionManager::StartConnectionAttempt( ...@@ -479,22 +512,24 @@ void BleConnectionManager::StartConnectionAttempt(
// Send a "disconnected => connecting" update to alert clients that a // Send a "disconnected => connecting" update to alert clients that a
// connection attempt for |device_id| is underway. // connection attempt for |device_id| is underway.
SendSecureChannelStatusChangeEvent( NotifySecureChannelStatusChanged(
device_id, cryptauth::SecureChannel::Status::DISCONNECTED, device_id, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING); cryptauth::SecureChannel::Status::CONNECTING,
StateChangeDetail::STATE_CHANGE_DETAIL_NONE);
} }
void BleConnectionManager::EndUnsuccessfulAttempt( void BleConnectionManager::EndUnsuccessfulAttempt(
const std::string& device_id) { const std::string& device_id,
StateChangeDetail state_change_detail) {
GetConnectionMetadata(device_id)->StopConnectionAttemptTimer(); GetConnectionMetadata(device_id)->StopConnectionAttemptTimer();
StopConnectionAttemptAndMoveToEndOfQueue(device_id); StopConnectionAttemptAndMoveToEndOfQueue(device_id);
device_id_to_advertising_start_time_map_[device_id] = base::Time(); device_id_to_advertising_start_time_map_[device_id] = base::Time();
// Send a "connecting => disconnected" update to alert clients that a // Send a "connecting => disconnected" update to alert clients that a
// connection attempt for |device_id| has failed. // connection attempt for |device_id| has failed.
SendSecureChannelStatusChangeEvent( NotifySecureChannelStatusChanged(
device_id, cryptauth::SecureChannel::Status::CONNECTING, device_id, cryptauth::SecureChannel::Status::CONNECTING,
cryptauth::SecureChannel::Status::DISCONNECTED); cryptauth::SecureChannel::Status::DISCONNECTED, state_change_detail);
} }
void BleConnectionManager::StopConnectionAttemptAndMoveToEndOfQueue( void BleConnectionManager::StopConnectionAttemptAndMoveToEndOfQueue(
...@@ -509,15 +544,19 @@ void BleConnectionManager::OnConnectionAttemptTimeout( ...@@ -509,15 +544,19 @@ void BleConnectionManager::OnConnectionAttemptTimeout(
PA_LOG(INFO) << "Connection attempt timeout - Device ID \"" PA_LOG(INFO) << "Connection attempt timeout - Device ID \""
<< cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id) << cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id)
<< "\"."; << "\".";
EndUnsuccessfulAttempt(device_id); EndUnsuccessfulAttempt(
device_id,
StateChangeDetail::STATE_CHANGE_DETAIL_COULD_NOT_ATTEMPT_CONNECTION);
UpdateConnectionAttempts(); UpdateConnectionAttempts();
} }
void BleConnectionManager::OnSecureChannelStatusChanged( void BleConnectionManager::OnSecureChannelStatusChanged(
const std::string& device_id, const std::string& device_id,
const cryptauth::SecureChannel::Status& old_status, const cryptauth::SecureChannel::Status& old_status,
const cryptauth::SecureChannel::Status& new_status) { const cryptauth::SecureChannel::Status& new_status,
SendSecureChannelStatusChangeEvent(device_id, old_status, new_status); StateChangeDetail state_change_detail) {
NotifySecureChannelStatusChanged(device_id, old_status, new_status,
state_change_detail);
UpdateConnectionAttempts(); UpdateConnectionAttempts();
} }
...@@ -530,8 +569,8 @@ void BleConnectionManager::OnGattCharacteristicsNotAvailable( ...@@ -530,8 +569,8 @@ void BleConnectionManager::OnGattCharacteristicsNotAvailable(
ad_hoc_ble_advertisement_->RequestGattServicesForDevice(device_id); ad_hoc_ble_advertisement_->RequestGattServicesForDevice(device_id);
} }
void BleConnectionManager::SendMessageReceivedEvent(std::string device_id, void BleConnectionManager::NotifyMessageReceived(std::string device_id,
std::string payload) { std::string payload) {
PA_LOG(INFO) << "Message received - Device ID: \"" PA_LOG(INFO) << "Message received - Device ID: \""
<< cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id) << cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id)
<< "\", Message: \"" << payload << "\"."; << "\", Message: \"" << payload << "\".";
...@@ -539,15 +578,17 @@ void BleConnectionManager::SendMessageReceivedEvent(std::string device_id, ...@@ -539,15 +578,17 @@ void BleConnectionManager::SendMessageReceivedEvent(std::string device_id,
observer.OnMessageReceived(device_id, payload); observer.OnMessageReceived(device_id, payload);
} }
void BleConnectionManager::SendSecureChannelStatusChangeEvent( void BleConnectionManager::NotifySecureChannelStatusChanged(
std::string device_id, std::string device_id,
cryptauth::SecureChannel::Status old_status, cryptauth::SecureChannel::Status old_status,
cryptauth::SecureChannel::Status new_status) { cryptauth::SecureChannel::Status new_status,
StateChangeDetail state_change_detail) {
PA_LOG(INFO) << "Status change - Device ID: \"" PA_LOG(INFO) << "Status change - Device ID: \""
<< cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id) << cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id)
<< "\": " << cryptauth::SecureChannel::StatusToString(old_status) << "\": " << cryptauth::SecureChannel::StatusToString(old_status)
<< " => " << " => " << cryptauth::SecureChannel::StatusToString(new_status)
<< cryptauth::SecureChannel::StatusToString(new_status); << ", State change detail: "
<< StateChangeDetailToString(state_change_detail);
if (new_status == cryptauth::SecureChannel::Status::CONNECTING) { if (new_status == cryptauth::SecureChannel::Status::CONNECTING) {
device_id_to_advertising_start_time_map_[device_id] = clock_->Now(); device_id_to_advertising_start_time_map_[device_id] = clock_->Now();
...@@ -558,11 +599,13 @@ void BleConnectionManager::SendSecureChannelStatusChangeEvent( ...@@ -558,11 +599,13 @@ void BleConnectionManager::SendSecureChannelStatusChangeEvent(
RecordConnectionToAuthenticationDuration(device_id); RecordConnectionToAuthenticationDuration(device_id);
} }
for (auto& observer : observer_list_) for (auto& observer : observer_list_) {
observer.OnSecureChannelStatusChanged(device_id, old_status, new_status); observer.OnSecureChannelStatusChanged(device_id, old_status, new_status,
state_change_detail);
}
} }
void BleConnectionManager::SendMessageSentEvent(int sequence_number) { void BleConnectionManager::NotifyMessageSent(int sequence_number) {
for (auto& observer : observer_list_) for (auto& observer : observer_list_)
observer.OnMessageSent(sequence_number); observer.OnMessageSent(sequence_number);
} }
......
...@@ -64,12 +64,24 @@ class BleConnectionManager : public BleScanner::Observer { ...@@ -64,12 +64,24 @@ class BleConnectionManager : public BleScanner::Observer {
public: public:
static std::string MessageTypeToString(const MessageType& reason); static std::string MessageTypeToString(const MessageType& reason);
// Extra data about a state change which is passed to observers in
// OnSecureChannelStatusChanged(). If no extra data applies to the state
// change, STATE_CHANGE_DETAIL_NONE is used.
enum class StateChangeDetail {
STATE_CHANGE_DETAIL_NONE,
STATE_CHANGE_DETAIL_COULD_NOT_ATTEMPT_CONNECTION,
STATE_CHANGE_DETAIL_GATT_CONNECTION_WAS_ATTEMPTED,
STATE_CHANGE_DETAIL_INTERRUPTED_BY_HIGHER_PRIORITY,
STATE_CHANGE_DETAIL_DEVICE_WAS_UNREGISTERED
};
class Observer { class Observer {
public: public:
virtual void OnSecureChannelStatusChanged( virtual void OnSecureChannelStatusChanged(
const std::string& device_id, const std::string& device_id,
const cryptauth::SecureChannel::Status& old_status, const cryptauth::SecureChannel::Status& old_status,
const cryptauth::SecureChannel::Status& new_status) = 0; const cryptauth::SecureChannel::Status& new_status,
StateChangeDetail state_change_detail) = 0;
virtual void OnMessageReceived(const std::string& device_id, virtual void OnMessageReceived(const std::string& device_id,
const std::string& payload) = 0; const std::string& payload) = 0;
...@@ -124,12 +136,13 @@ class BleConnectionManager : public BleScanner::Observer { ...@@ -124,12 +136,13 @@ class BleConnectionManager : public BleScanner::Observer {
device::BluetoothDevice* bluetooth_device) override; device::BluetoothDevice* bluetooth_device) override;
protected: protected:
void SendMessageReceivedEvent(std::string device_id, std::string payload); void NotifyMessageReceived(std::string device_id, std::string payload);
void SendSecureChannelStatusChangeEvent( void NotifySecureChannelStatusChanged(
std::string device_id, std::string device_id,
cryptauth::SecureChannel::Status old_status, cryptauth::SecureChannel::Status old_status,
cryptauth::SecureChannel::Status new_status); cryptauth::SecureChannel::Status new_status,
void SendMessageSentEvent(int sequence_number); StateChangeDetail state_change_detail);
void NotifyMessageSent(int sequence_number);
private: private:
friend class BleConnectionManagerTest; friend class BleConnectionManagerTest;
...@@ -197,14 +210,16 @@ class BleConnectionManager : public BleScanner::Observer { ...@@ -197,14 +210,16 @@ class BleConnectionManager : public BleScanner::Observer {
void UpdateAdvertisementQueue(); void UpdateAdvertisementQueue();
void StartConnectionAttempt(const std::string& device_id); void StartConnectionAttempt(const std::string& device_id);
void EndUnsuccessfulAttempt(const std::string& device_id); void EndUnsuccessfulAttempt(const std::string& device_id,
StateChangeDetail state_change_detail);
void StopConnectionAttemptAndMoveToEndOfQueue(const std::string& device_id); void StopConnectionAttemptAndMoveToEndOfQueue(const std::string& device_id);
void OnConnectionAttemptTimeout(const std::string& device_id); void OnConnectionAttemptTimeout(const std::string& device_id);
void OnSecureChannelStatusChanged( void OnSecureChannelStatusChanged(
const std::string& device_id, const std::string& device_id,
const cryptauth::SecureChannel::Status& old_status, const cryptauth::SecureChannel::Status& old_status,
const cryptauth::SecureChannel::Status& new_status); const cryptauth::SecureChannel::Status& new_status,
StateChangeDetail state_change_detail);
void OnGattCharacteristicsNotAvailable(const std::string& device_id); void OnGattCharacteristicsNotAvailable(const std::string& device_id);
void SetTestDoubles(std::unique_ptr<base::Clock> test_clock, void SetTestDoubles(std::unique_ptr<base::Clock> test_clock,
......
...@@ -48,14 +48,20 @@ constexpr base::TimeDelta kStatusAuthenticatedTime = ...@@ -48,14 +48,20 @@ constexpr base::TimeDelta kStatusAuthenticatedTime =
base::TimeDelta::FromSeconds(3); base::TimeDelta::FromSeconds(3);
struct SecureChannelStatusChange { struct SecureChannelStatusChange {
SecureChannelStatusChange(const std::string& device_id, SecureChannelStatusChange(
const cryptauth::SecureChannel::Status& old_status, const std::string& device_id,
const cryptauth::SecureChannel::Status& new_status) const cryptauth::SecureChannel::Status& old_status,
: device_id(device_id), old_status(old_status), new_status(new_status) {} const cryptauth::SecureChannel::Status& new_status,
BleConnectionManager::StateChangeDetail status_change_detail)
: device_id(device_id),
old_status(old_status),
new_status(new_status),
status_change_detail(status_change_detail) {}
std::string device_id; std::string device_id;
cryptauth::SecureChannel::Status old_status; cryptauth::SecureChannel::Status old_status;
cryptauth::SecureChannel::Status new_status; cryptauth::SecureChannel::Status new_status;
BleConnectionManager::StateChangeDetail status_change_detail;
}; };
struct ReceivedMessage { struct ReceivedMessage {
...@@ -84,9 +90,10 @@ class TestObserver final : public BleConnectionManager::Observer { ...@@ -84,9 +90,10 @@ class TestObserver final : public BleConnectionManager::Observer {
void OnSecureChannelStatusChanged( void OnSecureChannelStatusChanged(
const std::string& device_id, const std::string& device_id,
const cryptauth::SecureChannel::Status& old_status, const cryptauth::SecureChannel::Status& old_status,
const cryptauth::SecureChannel::Status& new_status) override { const cryptauth::SecureChannel::Status& new_status,
connection_status_changes_.push_back( BleConnectionManager::StateChangeDetail status_change_detail) override {
SecureChannelStatusChange(device_id, old_status, new_status)); connection_status_changes_.emplace_back(device_id, old_status, new_status,
status_change_detail);
} }
void OnMessageReceived(const std::string& device_id, void OnMessageReceived(const std::string& device_id,
...@@ -129,7 +136,8 @@ class UnregisteringObserver : public BleConnectionManager::Observer { ...@@ -129,7 +136,8 @@ class UnregisteringObserver : public BleConnectionManager::Observer {
void OnSecureChannelStatusChanged( void OnSecureChannelStatusChanged(
const std::string& device_id, const std::string& device_id,
const cryptauth::SecureChannel::Status& old_status, const cryptauth::SecureChannel::Status& old_status,
const cryptauth::SecureChannel::Status& new_status) override { const cryptauth::SecureChannel::Status& new_status,
BleConnectionManager::StateChangeDetail status_change_detail) override {
manager_->UnregisterRemoteDevice(device_id, connection_reason_); manager_->UnregisterRemoteDevice(device_id, connection_reason_);
} }
...@@ -319,6 +327,9 @@ class BleConnectionManagerTest : public testing::Test { ...@@ -319,6 +327,9 @@ class BleConnectionManagerTest : public testing::Test {
test_observer_->connection_status_changes()[i].old_status); test_observer_->connection_status_changes()[i].old_status);
EXPECT_EQ(verified_status_changes_[i].new_status, EXPECT_EQ(verified_status_changes_[i].new_status,
test_observer_->connection_status_changes()[i].new_status); test_observer_->connection_status_changes()[i].new_status);
EXPECT_EQ(
verified_status_changes_[i].status_change_detail,
test_observer_->connection_status_changes()[i].status_change_detail);
} }
} }
...@@ -428,7 +439,8 @@ class BleConnectionManagerTest : public testing::Test { ...@@ -428,7 +439,8 @@ class BleConnectionManagerTest : public testing::Test {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{remote_device.GetDeviceId(), {remote_device.GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
FakeSecureChannel* channel = FakeSecureChannel* channel =
ConnectChannel(remote_device, bluetooth_address); ConnectChannel(remote_device, bluetooth_address);
...@@ -478,13 +490,16 @@ class BleConnectionManagerTest : public testing::Test { ...@@ -478,13 +490,16 @@ class BleConnectionManagerTest : public testing::Test {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{remote_device.GetDeviceId(), {remote_device.GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING, cryptauth::SecureChannel::Status::CONNECTING,
cryptauth::SecureChannel::Status::CONNECTED}, cryptauth::SecureChannel::Status::CONNECTED,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE},
{remote_device.GetDeviceId(), {remote_device.GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTED, cryptauth::SecureChannel::Status::CONNECTED,
cryptauth::SecureChannel::Status::AUTHENTICATING}, cryptauth::SecureChannel::Status::AUTHENTICATING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE},
{remote_device.GetDeviceId(), {remote_device.GetDeviceId(),
cryptauth::SecureChannel::Status::AUTHENTICATING, cryptauth::SecureChannel::Status::AUTHENTICATING,
cryptauth::SecureChannel::Status::AUTHENTICATED}}); cryptauth::SecureChannel::Status::AUTHENTICATED,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
} }
void VerifyLastMessageSent(FakeSecureChannel* channel, void VerifyLastMessageSent(FakeSecureChannel* channel,
...@@ -552,7 +567,8 @@ TEST_F(BleConnectionManagerTest, TestCannotScan) { ...@@ -552,7 +567,8 @@ TEST_F(BleConnectionManagerTest, TestCannotScan) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
VerifyAdvertisingToConnectionDurationMetricNotRecorded(); VerifyAdvertisingToConnectionDurationMetricNotRecorded();
VerifyConnectionToAuthenticationDurationMetricNotRecorded(); VerifyConnectionToAuthenticationDurationMetricNotRecorded();
...@@ -567,7 +583,8 @@ TEST_F(BleConnectionManagerTest, TestCannotAdvertise) { ...@@ -567,7 +583,8 @@ TEST_F(BleConnectionManagerTest, TestCannotAdvertise) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
VerifyAdvertisingToConnectionDurationMetricNotRecorded(); VerifyAdvertisingToConnectionDurationMetricNotRecorded();
VerifyConnectionToAuthenticationDurationMetricNotRecorded(); VerifyConnectionToAuthenticationDurationMetricNotRecorded();
...@@ -580,7 +597,8 @@ TEST_F(BleConnectionManagerTest, TestRegistersButNoResult) { ...@@ -580,7 +597,8 @@ TEST_F(BleConnectionManagerTest, TestRegistersButNoResult) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
VerifyAdvertisingToConnectionDurationMetricNotRecorded(); VerifyAdvertisingToConnectionDurationMetricNotRecorded();
VerifyConnectionToAuthenticationDurationMetricNotRecorded(); VerifyConnectionToAuthenticationDurationMetricNotRecorded();
...@@ -593,14 +611,17 @@ TEST_F(BleConnectionManagerTest, TestRegistersAndUnregister_NoConnection) { ...@@ -593,14 +611,17 @@ TEST_F(BleConnectionManagerTest, TestRegistersAndUnregister_NoConnection) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
manager_->UnregisterRemoteDevice(test_devices_[0].GetDeviceId(), manager_->UnregisterRemoteDevice(test_devices_[0].GetDeviceId(),
MessageType::TETHER_AVAILABILITY_REQUEST); MessageType::TETHER_AVAILABILITY_REQUEST);
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING, cryptauth::SecureChannel::Status::CONNECTING,
cryptauth::SecureChannel::Status::DISCONNECTED}}); cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_DEVICE_WAS_UNREGISTERED}});
VerifyAdvertisingToConnectionDurationMetricNotRecorded(); VerifyAdvertisingToConnectionDurationMetricNotRecorded();
VerifyConnectionToAuthenticationDurationMetricNotRecorded(); VerifyConnectionToAuthenticationDurationMetricNotRecorded();
...@@ -613,7 +634,8 @@ TEST_F(BleConnectionManagerTest, TestAdHocBleAdvertiser) { ...@@ -613,7 +634,8 @@ TEST_F(BleConnectionManagerTest, TestAdHocBleAdvertiser) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
// Simulate the channel failing to find GATT services and disconnecting. // Simulate the channel failing to find GATT services and disconnecting.
FakeSecureChannel* channel = FakeSecureChannel* channel =
...@@ -623,10 +645,13 @@ TEST_F(BleConnectionManagerTest, TestAdHocBleAdvertiser) { ...@@ -623,10 +645,13 @@ TEST_F(BleConnectionManagerTest, TestAdHocBleAdvertiser) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING, cryptauth::SecureChannel::Status::CONNECTING,
cryptauth::SecureChannel::Status::DISCONNECTED}, cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_GATT_CONNECTION_WAS_ATTEMPTED},
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
// A GATT services workaround should have been requested for that device. // A GATT services workaround should have been requested for that device.
EXPECT_EQ(std::vector<std::string>{test_devices_[0].GetDeviceId()}, EXPECT_EQ(std::vector<std::string>{test_devices_[0].GetDeviceId()},
...@@ -640,23 +665,29 @@ TEST_F(BleConnectionManagerTest, TestRegisterWithNoConnection_TimeoutOccurs) { ...@@ -640,23 +665,29 @@ TEST_F(BleConnectionManagerTest, TestRegisterWithNoConnection_TimeoutOccurs) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
FireTimerForDevice(test_devices_[0]); FireTimerForDevice(test_devices_[0]);
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING, cryptauth::SecureChannel::Status::CONNECTING,
cryptauth::SecureChannel::Status::DISCONNECTED}, cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_COULD_NOT_ATTEMPT_CONNECTION},
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
manager_->UnregisterRemoteDevice(test_devices_[0].GetDeviceId(), manager_->UnregisterRemoteDevice(test_devices_[0].GetDeviceId(),
MessageType::TETHER_AVAILABILITY_REQUEST); MessageType::TETHER_AVAILABILITY_REQUEST);
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING, cryptauth::SecureChannel::Status::CONNECTING,
cryptauth::SecureChannel::Status::DISCONNECTED}}); cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_DEVICE_WAS_UNREGISTERED}});
VerifyAdvertisingToConnectionDurationMetricNotRecorded(); VerifyAdvertisingToConnectionDurationMetricNotRecorded();
VerifyConnectionToAuthenticationDurationMetricNotRecorded(); VerifyConnectionToAuthenticationDurationMetricNotRecorded();
...@@ -669,7 +700,8 @@ TEST_F(BleConnectionManagerTest, TestSuccessfulConnection_FailsAuthentication) { ...@@ -669,7 +700,8 @@ TEST_F(BleConnectionManagerTest, TestSuccessfulConnection_FailsAuthentication) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
fake_secure_channel_factory_->SetExpectedDeviceAddress(kBluetoothAddress1); fake_secure_channel_factory_->SetExpectedDeviceAddress(kBluetoothAddress1);
NotifyReceivedAdvertisementFromDevice(kBluetoothAddress1, test_devices_[0]); NotifyReceivedAdvertisementFromDevice(kBluetoothAddress1, test_devices_[0]);
...@@ -683,23 +715,28 @@ TEST_F(BleConnectionManagerTest, TestSuccessfulConnection_FailsAuthentication) { ...@@ -683,23 +715,28 @@ TEST_F(BleConnectionManagerTest, TestSuccessfulConnection_FailsAuthentication) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING, cryptauth::SecureChannel::Status::CONNECTING,
cryptauth::SecureChannel::Status::CONNECTED}}); cryptauth::SecureChannel::Status::CONNECTED,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
channel->ChangeStatus(cryptauth::SecureChannel::Status::AUTHENTICATING); channel->ChangeStatus(cryptauth::SecureChannel::Status::AUTHENTICATING);
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTED, cryptauth::SecureChannel::Status::CONNECTED,
cryptauth::SecureChannel::Status::AUTHENTICATING}}); cryptauth::SecureChannel::Status::AUTHENTICATING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
// Fail authentication, which should automatically start a retry. // Fail authentication, which should automatically start a retry.
channel->ChangeStatus(cryptauth::SecureChannel::Status::DISCONNECTED); channel->ChangeStatus(cryptauth::SecureChannel::Status::DISCONNECTED);
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::AUTHENTICATING, cryptauth::SecureChannel::Status::AUTHENTICATING,
cryptauth::SecureChannel::Status::DISCONNECTED}, cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_GATT_CONNECTION_WAS_ATTEMPTED},
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
VerifyConnectionToAuthenticationDurationMetricNotRecorded(); VerifyConnectionToAuthenticationDurationMetricNotRecorded();
} }
...@@ -730,7 +767,9 @@ TEST_F(BleConnectionManagerTest, TestSuccessfulConnection_SendAndReceive) { ...@@ -730,7 +767,9 @@ TEST_F(BleConnectionManagerTest, TestSuccessfulConnection_SendAndReceive) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::AUTHENTICATED, cryptauth::SecureChannel::Status::AUTHENTICATED,
cryptauth::SecureChannel::Status::DISCONNECTED}}); cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_DEVICE_WAS_UNREGISTERED}});
VerifyDeviceNotRegistered(test_devices_[0]); VerifyDeviceNotRegistered(test_devices_[0]);
} }
...@@ -743,7 +782,8 @@ TEST_F(BleConnectionManagerTest, ...@@ -743,7 +782,8 @@ TEST_F(BleConnectionManagerTest,
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
fake_secure_channel_factory_->SetExpectedDeviceAddress(kBluetoothAddress1); fake_secure_channel_factory_->SetExpectedDeviceAddress(kBluetoothAddress1);
...@@ -782,7 +822,9 @@ TEST_F(BleConnectionManagerTest, ...@@ -782,7 +822,9 @@ TEST_F(BleConnectionManagerTest,
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::AUTHENTICATED, cryptauth::SecureChannel::Status::AUTHENTICATED,
cryptauth::SecureChannel::Status::DISCONNECTED}}); cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_DEVICE_WAS_UNREGISTERED}});
VerifyDeviceNotRegistered(test_devices_[0]); VerifyDeviceNotRegistered(test_devices_[0]);
} }
...@@ -799,7 +841,8 @@ TEST_F(BleConnectionManagerTest, TestGetStatusForDevice) { ...@@ -799,7 +841,8 @@ TEST_F(BleConnectionManagerTest, TestGetStatusForDevice) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
// Should be CONNECTING at this point. // Should be CONNECTING at this point.
EXPECT_TRUE( EXPECT_TRUE(
...@@ -819,7 +862,8 @@ TEST_F(BleConnectionManagerTest, TestGetStatusForDevice) { ...@@ -819,7 +862,8 @@ TEST_F(BleConnectionManagerTest, TestGetStatusForDevice) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING, cryptauth::SecureChannel::Status::CONNECTING,
cryptauth::SecureChannel::Status::CONNECTED}}); cryptauth::SecureChannel::Status::CONNECTED,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
EXPECT_TRUE( EXPECT_TRUE(
manager_->GetStatusForDevice(test_devices_[0].GetDeviceId(), &status)); manager_->GetStatusForDevice(test_devices_[0].GetDeviceId(), &status));
EXPECT_EQ(cryptauth::SecureChannel::Status::CONNECTED, status); EXPECT_EQ(cryptauth::SecureChannel::Status::CONNECTED, status);
...@@ -828,7 +872,8 @@ TEST_F(BleConnectionManagerTest, TestGetStatusForDevice) { ...@@ -828,7 +872,8 @@ TEST_F(BleConnectionManagerTest, TestGetStatusForDevice) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTED, cryptauth::SecureChannel::Status::CONNECTED,
cryptauth::SecureChannel::Status::AUTHENTICATING}}); cryptauth::SecureChannel::Status::AUTHENTICATING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
EXPECT_TRUE( EXPECT_TRUE(
manager_->GetStatusForDevice(test_devices_[0].GetDeviceId(), &status)); manager_->GetStatusForDevice(test_devices_[0].GetDeviceId(), &status));
EXPECT_EQ(cryptauth::SecureChannel::Status::AUTHENTICATING, status); EXPECT_EQ(cryptauth::SecureChannel::Status::AUTHENTICATING, status);
...@@ -837,7 +882,8 @@ TEST_F(BleConnectionManagerTest, TestGetStatusForDevice) { ...@@ -837,7 +882,8 @@ TEST_F(BleConnectionManagerTest, TestGetStatusForDevice) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::AUTHENTICATING, cryptauth::SecureChannel::Status::AUTHENTICATING,
cryptauth::SecureChannel::Status::AUTHENTICATED}}); cryptauth::SecureChannel::Status::AUTHENTICATED,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
EXPECT_TRUE( EXPECT_TRUE(
manager_->GetStatusForDevice(test_devices_[0].GetDeviceId(), &status)); manager_->GetStatusForDevice(test_devices_[0].GetDeviceId(), &status));
EXPECT_EQ(cryptauth::SecureChannel::Status::AUTHENTICATED, status); EXPECT_EQ(cryptauth::SecureChannel::Status::AUTHENTICATED, status);
...@@ -849,7 +895,9 @@ TEST_F(BleConnectionManagerTest, TestGetStatusForDevice) { ...@@ -849,7 +895,9 @@ TEST_F(BleConnectionManagerTest, TestGetStatusForDevice) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::AUTHENTICATED, cryptauth::SecureChannel::Status::AUTHENTICATED,
cryptauth::SecureChannel::Status::DISCONNECTED}}); cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_DEVICE_WAS_UNREGISTERED}});
EXPECT_FALSE( EXPECT_FALSE(
manager_->GetStatusForDevice(test_devices_[0].GetDeviceId(), &status)); manager_->GetStatusForDevice(test_devices_[0].GetDeviceId(), &status));
} }
...@@ -864,10 +912,13 @@ TEST_F(BleConnectionManagerTest, ...@@ -864,10 +912,13 @@ TEST_F(BleConnectionManagerTest,
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::AUTHENTICATED, cryptauth::SecureChannel::Status::AUTHENTICATED,
cryptauth::SecureChannel::Status::DISCONNECTED}, cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_GATT_CONNECTION_WAS_ATTEMPTED},
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
} }
TEST_F(BleConnectionManagerTest, TwoDevices_NeitherCanScan) { TEST_F(BleConnectionManagerTest, TwoDevices_NeitherCanScan) {
...@@ -878,7 +929,8 @@ TEST_F(BleConnectionManagerTest, TwoDevices_NeitherCanScan) { ...@@ -878,7 +929,8 @@ TEST_F(BleConnectionManagerTest, TwoDevices_NeitherCanScan) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
manager_->RegisterRemoteDevice(test_devices_[1].GetDeviceId(), manager_->RegisterRemoteDevice(test_devices_[1].GetDeviceId(),
MessageType::TETHER_AVAILABILITY_REQUEST); MessageType::TETHER_AVAILABILITY_REQUEST);
...@@ -886,7 +938,8 @@ TEST_F(BleConnectionManagerTest, TwoDevices_NeitherCanScan) { ...@@ -886,7 +938,8 @@ TEST_F(BleConnectionManagerTest, TwoDevices_NeitherCanScan) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[1].GetDeviceId(), {test_devices_[1].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
} }
TEST_F(BleConnectionManagerTest, TwoDevices_NeitherCanAdvertise) { TEST_F(BleConnectionManagerTest, TwoDevices_NeitherCanAdvertise) {
...@@ -898,7 +951,8 @@ TEST_F(BleConnectionManagerTest, TwoDevices_NeitherCanAdvertise) { ...@@ -898,7 +951,8 @@ TEST_F(BleConnectionManagerTest, TwoDevices_NeitherCanAdvertise) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
manager_->RegisterRemoteDevice(test_devices_[1].GetDeviceId(), manager_->RegisterRemoteDevice(test_devices_[1].GetDeviceId(),
MessageType::TETHER_AVAILABILITY_REQUEST); MessageType::TETHER_AVAILABILITY_REQUEST);
...@@ -906,7 +960,8 @@ TEST_F(BleConnectionManagerTest, TwoDevices_NeitherCanAdvertise) { ...@@ -906,7 +960,8 @@ TEST_F(BleConnectionManagerTest, TwoDevices_NeitherCanAdvertise) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[1].GetDeviceId(), {test_devices_[1].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
VerifyAdvertisingToConnectionDurationMetricNotRecorded(); VerifyAdvertisingToConnectionDurationMetricNotRecorded();
VerifyConnectionToAuthenticationDurationMetricNotRecorded(); VerifyConnectionToAuthenticationDurationMetricNotRecorded();
...@@ -921,7 +976,8 @@ TEST_F(BleConnectionManagerTest, ...@@ -921,7 +976,8 @@ TEST_F(BleConnectionManagerTest,
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
// Register device 1. // Register device 1.
manager_->RegisterRemoteDevice(test_devices_[1].GetDeviceId(), manager_->RegisterRemoteDevice(test_devices_[1].GetDeviceId(),
...@@ -930,27 +986,34 @@ TEST_F(BleConnectionManagerTest, ...@@ -930,27 +986,34 @@ TEST_F(BleConnectionManagerTest,
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[1].GetDeviceId(), {test_devices_[1].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
// Simulate timeout for device 0 by firing timeout. // Simulate timeout for device 0 by firing timeout.
FireTimerForDevice(test_devices_[0]); FireTimerForDevice(test_devices_[0]);
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING, cryptauth::SecureChannel::Status::CONNECTING,
cryptauth::SecureChannel::Status::DISCONNECTED}, cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_COULD_NOT_ATTEMPT_CONNECTION},
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
// Simulate timeout for device 1 by firing timeout. // Simulate timeout for device 1 by firing timeout.
FireTimerForDevice(test_devices_[1]); FireTimerForDevice(test_devices_[1]);
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[1].GetDeviceId(), {test_devices_[1].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING, cryptauth::SecureChannel::Status::CONNECTING,
cryptauth::SecureChannel::Status::DISCONNECTED}, cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_COULD_NOT_ATTEMPT_CONNECTION},
{test_devices_[1].GetDeviceId(), {test_devices_[1].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
// Unregister device 0. // Unregister device 0.
manager_->UnregisterRemoteDevice(test_devices_[0].GetDeviceId(), manager_->UnregisterRemoteDevice(test_devices_[0].GetDeviceId(),
...@@ -958,7 +1021,9 @@ TEST_F(BleConnectionManagerTest, ...@@ -958,7 +1021,9 @@ TEST_F(BleConnectionManagerTest,
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING, cryptauth::SecureChannel::Status::CONNECTING,
cryptauth::SecureChannel::Status::DISCONNECTED}}); cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_DEVICE_WAS_UNREGISTERED}});
// Unregister device 1. // Unregister device 1.
manager_->UnregisterRemoteDevice(test_devices_[1].GetDeviceId(), manager_->UnregisterRemoteDevice(test_devices_[1].GetDeviceId(),
...@@ -966,7 +1031,9 @@ TEST_F(BleConnectionManagerTest, ...@@ -966,7 +1031,9 @@ TEST_F(BleConnectionManagerTest,
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[1].GetDeviceId(), {test_devices_[1].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING, cryptauth::SecureChannel::Status::CONNECTING,
cryptauth::SecureChannel::Status::DISCONNECTED}}); cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_DEVICE_WAS_UNREGISTERED}});
VerifyAdvertisingToConnectionDurationMetricNotRecorded(); VerifyAdvertisingToConnectionDurationMetricNotRecorded();
VerifyConnectionToAuthenticationDurationMetricNotRecorded(); VerifyConnectionToAuthenticationDurationMetricNotRecorded();
...@@ -984,17 +1051,21 @@ TEST_F(BleConnectionManagerTest, TwoDevices_OneConnects) { ...@@ -984,17 +1051,21 @@ TEST_F(BleConnectionManagerTest, TwoDevices_OneConnects) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[1].GetDeviceId(), {test_devices_[1].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
// Simulate timeout for device 1 by firing timeout. // Simulate timeout for device 1 by firing timeout.
FireTimerForDevice(test_devices_[1]); FireTimerForDevice(test_devices_[1]);
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[1].GetDeviceId(), {test_devices_[1].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING, cryptauth::SecureChannel::Status::CONNECTING,
cryptauth::SecureChannel::Status::DISCONNECTED}, cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_COULD_NOT_ATTEMPT_CONNECTION},
{test_devices_[1].GetDeviceId(), {test_devices_[1].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
// Unregister device 0. // Unregister device 0.
manager_->UnregisterRemoteDevice(test_devices_[0].GetDeviceId(), manager_->UnregisterRemoteDevice(test_devices_[0].GetDeviceId(),
...@@ -1002,7 +1073,9 @@ TEST_F(BleConnectionManagerTest, TwoDevices_OneConnects) { ...@@ -1002,7 +1073,9 @@ TEST_F(BleConnectionManagerTest, TwoDevices_OneConnects) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::AUTHENTICATED, cryptauth::SecureChannel::Status::AUTHENTICATED,
cryptauth::SecureChannel::Status::DISCONNECTED}}); cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_DEVICE_WAS_UNREGISTERED}});
// Unregister device 1. // Unregister device 1.
manager_->UnregisterRemoteDevice(test_devices_[1].GetDeviceId(), manager_->UnregisterRemoteDevice(test_devices_[1].GetDeviceId(),
...@@ -1010,7 +1083,9 @@ TEST_F(BleConnectionManagerTest, TwoDevices_OneConnects) { ...@@ -1010,7 +1083,9 @@ TEST_F(BleConnectionManagerTest, TwoDevices_OneConnects) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[1].GetDeviceId(), {test_devices_[1].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING, cryptauth::SecureChannel::Status::CONNECTING,
cryptauth::SecureChannel::Status::DISCONNECTED}}); cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_DEVICE_WAS_UNREGISTERED}});
} }
TEST_F(BleConnectionManagerTest, TwoDevices_BothConnectSendAndReceive) { TEST_F(BleConnectionManagerTest, TwoDevices_BothConnectSendAndReceive) {
...@@ -1059,7 +1134,9 @@ TEST_F(BleConnectionManagerTest, TwoDevices_BothConnectSendAndReceive) { ...@@ -1059,7 +1134,9 @@ TEST_F(BleConnectionManagerTest, TwoDevices_BothConnectSendAndReceive) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::AUTHENTICATED, cryptauth::SecureChannel::Status::AUTHENTICATED,
cryptauth::SecureChannel::Status::DISCONNECTED}}); cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_DEVICE_WAS_UNREGISTERED}});
VerifyDeviceNotRegistered(test_devices_[0]); VerifyDeviceNotRegistered(test_devices_[0]);
manager_->UnregisterRemoteDevice(test_devices_[1].GetDeviceId(), manager_->UnregisterRemoteDevice(test_devices_[1].GetDeviceId(),
...@@ -1067,7 +1144,9 @@ TEST_F(BleConnectionManagerTest, TwoDevices_BothConnectSendAndReceive) { ...@@ -1067,7 +1144,9 @@ TEST_F(BleConnectionManagerTest, TwoDevices_BothConnectSendAndReceive) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[1].GetDeviceId(), {test_devices_[1].GetDeviceId(),
cryptauth::SecureChannel::Status::AUTHENTICATED, cryptauth::SecureChannel::Status::AUTHENTICATED,
cryptauth::SecureChannel::Status::DISCONNECTED}}); cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_DEVICE_WAS_UNREGISTERED}});
VerifyDeviceNotRegistered(test_devices_[1]); VerifyDeviceNotRegistered(test_devices_[1]);
} }
...@@ -1091,10 +1170,12 @@ TEST_F(BleConnectionManagerTest, FourDevices_ComprehensiveTest) { ...@@ -1091,10 +1170,12 @@ TEST_F(BleConnectionManagerTest, FourDevices_ComprehensiveTest) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}, cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE},
{test_devices_[1].GetDeviceId(), {test_devices_[1].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
// Device 0 connects successfully. // Device 0 connects successfully.
FakeSecureChannel* channel0 = FakeSecureChannel* channel0 =
...@@ -1105,7 +1186,8 @@ TEST_F(BleConnectionManagerTest, FourDevices_ComprehensiveTest) { ...@@ -1105,7 +1186,8 @@ TEST_F(BleConnectionManagerTest, FourDevices_ComprehensiveTest) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[2].GetDeviceId(), {test_devices_[2].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
// Meanwhile, device 1 fails to connect, so the timeout fires. The advertising // Meanwhile, device 1 fails to connect, so the timeout fires. The advertising
// slot left by device 1 creates space for device 3 to start connecting. // slot left by device 1 creates space for device 3 to start connecting.
...@@ -1115,10 +1197,13 @@ TEST_F(BleConnectionManagerTest, FourDevices_ComprehensiveTest) { ...@@ -1115,10 +1197,13 @@ TEST_F(BleConnectionManagerTest, FourDevices_ComprehensiveTest) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[1].GetDeviceId(), {test_devices_[1].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING, cryptauth::SecureChannel::Status::CONNECTING,
cryptauth::SecureChannel::Status::DISCONNECTED}, cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_COULD_NOT_ATTEMPT_CONNECTION},
{test_devices_[3].GetDeviceId(), {test_devices_[3].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
// Now, device 0 authenticates and sends and receives a message. // Now, device 0 authenticates and sends and receives a message.
AuthenticateChannel(test_devices_[0]); AuthenticateChannel(test_devices_[0]);
...@@ -1137,7 +1222,9 @@ TEST_F(BleConnectionManagerTest, FourDevices_ComprehensiveTest) { ...@@ -1137,7 +1222,9 @@ TEST_F(BleConnectionManagerTest, FourDevices_ComprehensiveTest) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::AUTHENTICATED, cryptauth::SecureChannel::Status::AUTHENTICATED,
cryptauth::SecureChannel::Status::DISCONNECTED}}); cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_DEVICE_WAS_UNREGISTERED}});
// Device 2 fails to connect, so the timeout fires. Device 1 takes its spot. // Device 2 fails to connect, so the timeout fires. Device 1 takes its spot.
FireTimerForDevice(test_devices_[2]); FireTimerForDevice(test_devices_[2]);
...@@ -1146,10 +1233,13 @@ TEST_F(BleConnectionManagerTest, FourDevices_ComprehensiveTest) { ...@@ -1146,10 +1233,13 @@ TEST_F(BleConnectionManagerTest, FourDevices_ComprehensiveTest) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[2].GetDeviceId(), {test_devices_[2].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING, cryptauth::SecureChannel::Status::CONNECTING,
cryptauth::SecureChannel::Status::DISCONNECTED}, cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_COULD_NOT_ATTEMPT_CONNECTION},
{test_devices_[1].GetDeviceId(), {test_devices_[1].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
// Device 3 connects successfully. // Device 3 connects successfully.
FakeSecureChannel* channel3 = FakeSecureChannel* channel3 =
...@@ -1159,7 +1249,8 @@ TEST_F(BleConnectionManagerTest, FourDevices_ComprehensiveTest) { ...@@ -1159,7 +1249,8 @@ TEST_F(BleConnectionManagerTest, FourDevices_ComprehensiveTest) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[2].GetDeviceId(), {test_devices_[2].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}}); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE}});
// Now, device 3 authenticates and sends and receives a message. // Now, device 3 authenticates and sends and receives a message.
AuthenticateChannel(test_devices_[3]); AuthenticateChannel(test_devices_[3]);
...@@ -1186,13 +1277,19 @@ TEST_F(BleConnectionManagerTest, FourDevices_ComprehensiveTest) { ...@@ -1186,13 +1277,19 @@ TEST_F(BleConnectionManagerTest, FourDevices_ComprehensiveTest) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[3].GetDeviceId(), {test_devices_[3].GetDeviceId(),
cryptauth::SecureChannel::Status::AUTHENTICATED, cryptauth::SecureChannel::Status::AUTHENTICATED,
cryptauth::SecureChannel::Status::DISCONNECTED}, cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_DEVICE_WAS_UNREGISTERED},
{test_devices_[1].GetDeviceId(), {test_devices_[1].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING, cryptauth::SecureChannel::Status::CONNECTING,
cryptauth::SecureChannel::Status::DISCONNECTED}, cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_DEVICE_WAS_UNREGISTERED},
{test_devices_[2].GetDeviceId(), {test_devices_[2].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING, cryptauth::SecureChannel::Status::CONNECTING,
cryptauth::SecureChannel::Status::DISCONNECTED}}); cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_DEVICE_WAS_UNREGISTERED}});
} }
// Regression test for crbug.com/733360. This bug caused a crash when there were // Regression test for crbug.com/733360. This bug caused a crash when there were
...@@ -1230,7 +1327,9 @@ TEST_F(BleConnectionManagerTest, ObserverUnregisters) { ...@@ -1230,7 +1327,9 @@ TEST_F(BleConnectionManagerTest, ObserverUnregisters) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::AUTHENTICATED, cryptauth::SecureChannel::Status::AUTHENTICATED,
cryptauth::SecureChannel::Status::DISCONNECTED}}); cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_DEVICE_WAS_UNREGISTERED}});
VerifyDeviceNotRegistered(test_devices_[0]); VerifyDeviceNotRegistered(test_devices_[0]);
// Now, register the device again. This should cause a "disconnected => // Now, register the device again. This should cause a "disconnected =>
...@@ -1244,10 +1343,13 @@ TEST_F(BleConnectionManagerTest, ObserverUnregisters) { ...@@ -1244,10 +1343,13 @@ TEST_F(BleConnectionManagerTest, ObserverUnregisters) {
VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED, cryptauth::SecureChannel::Status::DISCONNECTED,
cryptauth::SecureChannel::Status::CONNECTING}, cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE},
{test_devices_[0].GetDeviceId(), {test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING, cryptauth::SecureChannel::Status::CONNECTING,
cryptauth::SecureChannel::Status::DISCONNECTED}}); cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_DEVICE_WAS_UNREGISTERED}});
VerifyDeviceNotRegistered(test_devices_[0]); VerifyDeviceNotRegistered(test_devices_[0]);
} }
......
...@@ -32,6 +32,8 @@ namespace { ...@@ -32,6 +32,8 @@ namespace {
const char kTestSsid[] = "testSsid"; const char kTestSsid[] = "testSsid";
const char kTestPassword[] = "testPassword"; const char kTestPassword[] = "testPassword";
const size_t kMaxConnectionAttemptsPerDevice = 3;
constexpr base::TimeDelta kConnectTetheringResponseTime = constexpr base::TimeDelta kConnectTetheringResponseTime =
base::TimeDelta::FromSeconds(15); base::TimeDelta::FromSeconds(15);
...@@ -276,21 +278,8 @@ TEST_F(ConnectTetheringOperationTest, TestCannotConnect) { ...@@ -276,21 +278,8 @@ TEST_F(ConnectTetheringOperationTest, TestCannotConnect) {
.Times(0); .Times(0);
// Simulate the device failing to connect. // Simulate the device failing to connect.
fake_ble_connection_manager_->SetDeviceStatus( fake_ble_connection_manager_->SimulateFailedConnectionAttempts(
test_device_.GetDeviceId(), cryptauth::SecureChannel::Status::CONNECTING); test_device_.GetDeviceId(), kMaxConnectionAttemptsPerDevice);
fake_ble_connection_manager_->SetDeviceStatus(
test_device_.GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED);
fake_ble_connection_manager_->SetDeviceStatus(
test_device_.GetDeviceId(), cryptauth::SecureChannel::Status::CONNECTING);
fake_ble_connection_manager_->SetDeviceStatus(
test_device_.GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED);
fake_ble_connection_manager_->SetDeviceStatus(
test_device_.GetDeviceId(), cryptauth::SecureChannel::Status::CONNECTING);
fake_ble_connection_manager_->SetDeviceStatus(
test_device_.GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED);
// The maximum number of connection failures has occurred. // The maximum number of connection failures has occurred.
EXPECT_TRUE(test_observer_->has_received_failure()); EXPECT_TRUE(test_observer_->has_received_failure());
......
...@@ -34,7 +34,8 @@ FakeBleConnectionManager::~FakeBleConnectionManager() = default; ...@@ -34,7 +34,8 @@ FakeBleConnectionManager::~FakeBleConnectionManager() = default;
void FakeBleConnectionManager::SetDeviceStatus( void FakeBleConnectionManager::SetDeviceStatus(
const std::string& device_id, const std::string& device_id,
const cryptauth::SecureChannel::Status& status) { const cryptauth::SecureChannel::Status& status,
BleConnectionManager::StateChangeDetail state_change_detail) {
const auto iter = device_id_map_.find(device_id); const auto iter = device_id_map_.find(device_id);
DCHECK(iter != device_id_map_.end()); DCHECK(iter != device_id_map_.end());
...@@ -45,18 +46,31 @@ void FakeBleConnectionManager::SetDeviceStatus( ...@@ -45,18 +46,31 @@ void FakeBleConnectionManager::SetDeviceStatus(
} }
iter->second.status = status; iter->second.status = status;
SendSecureChannelStatusChangeEvent(device_id, old_status, status); NotifySecureChannelStatusChanged(device_id, old_status, status,
state_change_detail);
} }
void FakeBleConnectionManager::ReceiveMessage(const std::string& device_id, void FakeBleConnectionManager::ReceiveMessage(const std::string& device_id,
const std::string& payload) { const std::string& payload) {
DCHECK(device_id_map_.find(device_id) != device_id_map_.end()); DCHECK(device_id_map_.find(device_id) != device_id_map_.end());
SendMessageReceivedEvent(device_id, payload); NotifyMessageReceived(device_id, payload);
} }
void FakeBleConnectionManager::SetMessageSent(int sequence_number) { void FakeBleConnectionManager::SetMessageSent(int sequence_number) {
DCHECK(sequence_number < next_sequence_number_); DCHECK(sequence_number < next_sequence_number_);
SendMessageSentEvent(sequence_number); NotifyMessageSent(sequence_number);
}
void FakeBleConnectionManager::SimulateFailedConnectionAttempts(
const std::string& device_id,
size_t num_attempts) {
for (size_t i = 0; i < num_attempts; ++i) {
SetDeviceStatus(device_id, cryptauth::SecureChannel::Status::CONNECTING,
StateChangeDetail::STATE_CHANGE_DETAIL_NONE);
SetDeviceStatus(
device_id, cryptauth::SecureChannel::Status::DISCONNECTED,
StateChangeDetail::STATE_CHANGE_DETAIL_COULD_NOT_ATTEMPT_CONNECTION);
}
} }
bool FakeBleConnectionManager::IsRegistered(const std::string& device_id) { bool FakeBleConnectionManager::IsRegistered(const std::string& device_id) {
......
...@@ -26,11 +26,19 @@ class FakeBleConnectionManager : public BleConnectionManager { ...@@ -26,11 +26,19 @@ class FakeBleConnectionManager : public BleConnectionManager {
std::string message; std::string message;
}; };
void SetDeviceStatus(const std::string& device_id, void SetDeviceStatus(
const cryptauth::SecureChannel::Status& status); const std::string& device_id,
const cryptauth::SecureChannel::Status& status,
BleConnectionManager::StateChangeDetail state_change_detail);
void ReceiveMessage(const std::string& device_id, const std::string& payload); void ReceiveMessage(const std::string& device_id, const std::string& payload);
void SetMessageSent(int sequence_number); void SetMessageSent(int sequence_number);
// Simulates |num_attempts| consecutive failed connection attempts for the
// device with ID |device_id|. Specifically, this function updates the
// device's status to CONNECTING then DISCONNECTED on each attempt.
void SimulateFailedConnectionAttempts(const std::string& device_id,
size_t num_attempts);
std::vector<SentMessage>& sent_messages() { return sent_messages_; } std::vector<SentMessage>& sent_messages() { return sent_messages_; }
// Returns -1 if no sequence numbers have been used yet. // Returns -1 if no sequence numbers have been used yet.
int last_sequence_number() { return next_sequence_number_ - 1; } int last_sequence_number() { return next_sequence_number_ - 1; }
......
...@@ -30,6 +30,8 @@ namespace tether { ...@@ -30,6 +30,8 @@ namespace tether {
namespace { namespace {
const size_t kMaxConnectionAttemptsPerDevice = 3;
const char kDefaultCarrier[] = "Google Fi"; const char kDefaultCarrier[] = "Google Fi";
constexpr base::TimeDelta kTetherAvailabilityResponseTime = constexpr base::TimeDelta kTetherAvailabilityResponseTime =
...@@ -373,24 +375,8 @@ TEST_F(HostScannerOperationTest, TestMultipleDevices) { ...@@ -373,24 +375,8 @@ TEST_F(HostScannerOperationTest, TestMultipleDevices) {
kTetherAvailabilityResponseTime, 2); kTetherAvailabilityResponseTime, 2);
// Simulate device 1 failing to connect. // Simulate device 1 failing to connect.
fake_ble_connection_manager_->SetDeviceStatus( fake_ble_connection_manager_->SimulateFailedConnectionAttempts(
test_devices_[1].GetDeviceId(), test_devices_[1].GetDeviceId(), kMaxConnectionAttemptsPerDevice);
cryptauth::SecureChannel::Status::CONNECTING);
fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[1].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED);
fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[1].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING);
fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[1].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED);
fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[1].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING);
fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[1].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED);
// The scan should still not be over, and no new scan results should have // The scan should still not be over, and no new scan results should have
// come in. // come in.
...@@ -398,24 +384,8 @@ TEST_F(HostScannerOperationTest, TestMultipleDevices) { ...@@ -398,24 +384,8 @@ TEST_F(HostScannerOperationTest, TestMultipleDevices) {
EXPECT_EQ(2u, test_observer_->scanned_devices_so_far().size()); EXPECT_EQ(2u, test_observer_->scanned_devices_so_far().size());
// Simulate device 3 failing to connect. // Simulate device 3 failing to connect.
fake_ble_connection_manager_->SetDeviceStatus( fake_ble_connection_manager_->SimulateFailedConnectionAttempts(
test_devices_[3].GetDeviceId(), test_devices_[3].GetDeviceId(), kMaxConnectionAttemptsPerDevice);
cryptauth::SecureChannel::Status::CONNECTING);
fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[3].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED);
fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[3].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING);
fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[3].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED);
fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[3].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING);
fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[3].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED);
// The scan should still not be over, and no new scan results should have // The scan should still not be over, and no new scan results should have
// come in. // come in.
......
...@@ -22,6 +22,8 @@ namespace tether { ...@@ -22,6 +22,8 @@ namespace tether {
namespace { namespace {
const size_t kMaxConnectionAttemptsPerDevice = 3;
constexpr base::TimeDelta kKeepAliveTickleResponseTime = constexpr base::TimeDelta kKeepAliveTickleResponseTime =
base::TimeDelta::FromSeconds(3); base::TimeDelta::FromSeconds(3);
...@@ -140,21 +142,8 @@ TEST_F(KeepAliveOperationTest, TestSendsKeepAliveTickleAndReceivesResponse) { ...@@ -140,21 +142,8 @@ TEST_F(KeepAliveOperationTest, TestSendsKeepAliveTickleAndReceivesResponse) {
TEST_F(KeepAliveOperationTest, TestCannotConnect) { TEST_F(KeepAliveOperationTest, TestCannotConnect) {
// Simulate the device failing to connect. // Simulate the device failing to connect.
fake_ble_connection_manager_->SetDeviceStatus( fake_ble_connection_manager_->SimulateFailedConnectionAttempts(
test_device_.GetDeviceId(), cryptauth::SecureChannel::Status::CONNECTING); test_device_.GetDeviceId(), kMaxConnectionAttemptsPerDevice);
fake_ble_connection_manager_->SetDeviceStatus(
test_device_.GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED);
fake_ble_connection_manager_->SetDeviceStatus(
test_device_.GetDeviceId(), cryptauth::SecureChannel::Status::CONNECTING);
fake_ble_connection_manager_->SetDeviceStatus(
test_device_.GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED);
fake_ble_connection_manager_->SetDeviceStatus(
test_device_.GetDeviceId(), cryptauth::SecureChannel::Status::CONNECTING);
fake_ble_connection_manager_->SetDeviceStatus(
test_device_.GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED);
// The maximum number of connection failures has occurred. // The maximum number of connection failures has occurred.
EXPECT_TRUE(test_observer_->has_run_callback()); EXPECT_TRUE(test_observer_->has_run_callback());
......
...@@ -99,7 +99,8 @@ void MessageTransferOperation::Initialize() { ...@@ -99,7 +99,8 @@ void MessageTransferOperation::Initialize() {
void MessageTransferOperation::OnSecureChannelStatusChanged( void MessageTransferOperation::OnSecureChannelStatusChanged(
const std::string& device_id, const std::string& device_id,
const cryptauth::SecureChannel::Status& old_status, const cryptauth::SecureChannel::Status& old_status,
const cryptauth::SecureChannel::Status& new_status) { const cryptauth::SecureChannel::Status& new_status,
BleConnectionManager::StateChangeDetail status_change_detail) {
cryptauth::RemoteDevice* remote_device = GetRemoteDevice(device_id); cryptauth::RemoteDevice* remote_device = GetRemoteDevice(device_id);
if (!remote_device) { if (!remote_device) {
// If the device whose status has changed does not correspond to any of the // If the device whose status has changed does not correspond to any of the
...@@ -108,6 +109,9 @@ void MessageTransferOperation::OnSecureChannelStatusChanged( ...@@ -108,6 +109,9 @@ void MessageTransferOperation::OnSecureChannelStatusChanged(
return; return;
} }
// TODO(khorimoto): Use |status_change_detail| to provide better retry
// handling. See https://crbug.com/805218.
if (new_status == cryptauth::SecureChannel::Status::AUTHENTICATED) { if (new_status == cryptauth::SecureChannel::Status::AUTHENTICATED) {
StartTimerForDevice(*remote_device); StartTimerForDevice(*remote_device);
OnDeviceAuthenticated(*remote_device); OnDeviceAuthenticated(*remote_device);
......
...@@ -35,7 +35,8 @@ class MessageTransferOperation : public BleConnectionManager::Observer { ...@@ -35,7 +35,8 @@ class MessageTransferOperation : public BleConnectionManager::Observer {
void OnSecureChannelStatusChanged( void OnSecureChannelStatusChanged(
const std::string& device_id, const std::string& device_id,
const cryptauth::SecureChannel::Status& old_status, const cryptauth::SecureChannel::Status& old_status,
const cryptauth::SecureChannel::Status& new_status) override; const cryptauth::SecureChannel::Status& new_status,
BleConnectionManager::StateChangeDetail status_change_detail) override;
void OnMessageReceived(const std::string& device_id, void OnMessageReceived(const std::string& device_id,
const std::string& payload) override; const std::string& payload) override;
void OnMessageSent(int sequence_number) override {} void OnMessageSent(int sequence_number) override {}
......
...@@ -21,6 +21,8 @@ namespace tether { ...@@ -21,6 +21,8 @@ namespace tether {
namespace { namespace {
const size_t kMaxConnectionAttemptsPerDevice = 3;
// Arbitrarily chosen value. The MessageType used in this test does not matter // Arbitrarily chosen value. The MessageType used in this test does not matter
// except that it must be consistent throughout the test. // except that it must be consistent throughout the test.
const MessageType kTestMessageType = MessageType::TETHER_AVAILABILITY_REQUEST; const MessageType kTestMessageType = MessageType::TETHER_AVAILABILITY_REQUEST;
...@@ -194,16 +196,20 @@ class MessageTransferOperationTest : public testing::Test { ...@@ -194,16 +196,20 @@ class MessageTransferOperationTest : public testing::Test {
fake_ble_connection_manager_->SetDeviceStatus( fake_ble_connection_manager_->SetDeviceStatus(
remote_device.GetDeviceId(), remote_device.GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE);
fake_ble_connection_manager_->SetDeviceStatus( fake_ble_connection_manager_->SetDeviceStatus(
remote_device.GetDeviceId(), remote_device.GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTED); cryptauth::SecureChannel::Status::CONNECTED,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE);
fake_ble_connection_manager_->SetDeviceStatus( fake_ble_connection_manager_->SetDeviceStatus(
remote_device.GetDeviceId(), remote_device.GetDeviceId(),
cryptauth::SecureChannel::Status::AUTHENTICATING); cryptauth::SecureChannel::Status::AUTHENTICATING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE);
fake_ble_connection_manager_->SetDeviceStatus( fake_ble_connection_manager_->SetDeviceStatus(
remote_device.GetDeviceId(), remote_device.GetDeviceId(),
cryptauth::SecureChannel::Status::AUTHENTICATED); cryptauth::SecureChannel::Status::AUTHENTICATED,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE);
} }
base::MockTimer* GetTimerForDevice( base::MockTimer* GetTimerForDevice(
...@@ -243,20 +249,26 @@ TEST_F(MessageTransferOperationTest, TestCannotConnectAndReachesRetryLimit) { ...@@ -243,20 +249,26 @@ TEST_F(MessageTransferOperationTest, TestCannotConnectAndReachesRetryLimit) {
// Try to connect and fail. The device should still be registered. // Try to connect and fail. The device should still be registered.
fake_ble_connection_manager_->SetDeviceStatus( fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[0].GetDeviceId(), test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE);
fake_ble_connection_manager_->SetDeviceStatus( fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[0].GetDeviceId(), test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED); cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_COULD_NOT_ATTEMPT_CONNECTION);
EXPECT_TRUE(fake_ble_connection_manager_->IsRegistered( EXPECT_TRUE(fake_ble_connection_manager_->IsRegistered(
test_devices_[0].GetDeviceId())); test_devices_[0].GetDeviceId()));
// Try and fail again. The device should still be registered. // Try and fail again. The device should still be registered.
fake_ble_connection_manager_->SetDeviceStatus( fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[0].GetDeviceId(), test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE);
fake_ble_connection_manager_->SetDeviceStatus( fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[0].GetDeviceId(), test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED); cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_COULD_NOT_ATTEMPT_CONNECTION);
EXPECT_TRUE(fake_ble_connection_manager_->IsRegistered( EXPECT_TRUE(fake_ble_connection_manager_->IsRegistered(
test_devices_[0].GetDeviceId())); test_devices_[0].GetDeviceId()));
...@@ -264,10 +276,13 @@ TEST_F(MessageTransferOperationTest, TestCannotConnectAndReachesRetryLimit) { ...@@ -264,10 +276,13 @@ TEST_F(MessageTransferOperationTest, TestCannotConnectAndReachesRetryLimit) {
// so the device should be unregistered. // so the device should be unregistered.
fake_ble_connection_manager_->SetDeviceStatus( fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[0].GetDeviceId(), test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE);
fake_ble_connection_manager_->SetDeviceStatus( fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[0].GetDeviceId(), test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED); cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_COULD_NOT_ATTEMPT_CONNECTION);
EXPECT_FALSE(fake_ble_connection_manager_->IsRegistered( EXPECT_FALSE(fake_ble_connection_manager_->IsRegistered(
test_devices_[0].GetDeviceId())); test_devices_[0].GetDeviceId()));
VerifyOperationStartedAndFinished(true /* has_started */, VerifyOperationStartedAndFinished(true /* has_started */,
...@@ -286,10 +301,13 @@ TEST_F(MessageTransferOperationTest, TestFailsThenConnects) { ...@@ -286,10 +301,13 @@ TEST_F(MessageTransferOperationTest, TestFailsThenConnects) {
// Try to connect and fail. The device should still be registered. // Try to connect and fail. The device should still be registered.
fake_ble_connection_manager_->SetDeviceStatus( fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[0].GetDeviceId(), test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING); cryptauth::SecureChannel::Status::CONNECTING,
BleConnectionManager::StateChangeDetail::STATE_CHANGE_DETAIL_NONE);
fake_ble_connection_manager_->SetDeviceStatus( fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[0].GetDeviceId(), test_devices_[0].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED); cryptauth::SecureChannel::Status::DISCONNECTED,
BleConnectionManager::StateChangeDetail::
STATE_CHANGE_DETAIL_COULD_NOT_ATTEMPT_CONNECTION);
EXPECT_TRUE(fake_ble_connection_manager_->IsRegistered( EXPECT_TRUE(fake_ble_connection_manager_->IsRegistered(
test_devices_[0].GetDeviceId())); test_devices_[0].GetDeviceId()));
...@@ -547,24 +565,8 @@ TEST_F(MessageTransferOperationTest, MultipleDevices) { ...@@ -547,24 +565,8 @@ TEST_F(MessageTransferOperationTest, MultipleDevices) {
// Fail 3 times to connect to |test_devices_[1]|. // Fail 3 times to connect to |test_devices_[1]|.
test_timer_factory_->set_device_id_for_next_timer( test_timer_factory_->set_device_id_for_next_timer(
test_devices_[1].GetDeviceId()); test_devices_[1].GetDeviceId());
fake_ble_connection_manager_->SetDeviceStatus( fake_ble_connection_manager_->SimulateFailedConnectionAttempts(
test_devices_[1].GetDeviceId(), test_devices_[1].GetDeviceId(), kMaxConnectionAttemptsPerDevice);
cryptauth::SecureChannel::Status::CONNECTING);
fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[1].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED);
fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[1].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING);
fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[1].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED);
fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[1].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING);
fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[1].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED);
EXPECT_FALSE(operation_->HasDeviceAuthenticated(test_devices_[1])); EXPECT_FALSE(operation_->HasDeviceAuthenticated(test_devices_[1]));
EXPECT_FALSE(fake_ble_connection_manager_->IsRegistered( EXPECT_FALSE(fake_ble_connection_manager_->IsRegistered(
test_devices_[1].GetDeviceId())); test_devices_[1].GetDeviceId()));
...@@ -582,24 +584,8 @@ TEST_F(MessageTransferOperationTest, MultipleDevices) { ...@@ -582,24 +584,8 @@ TEST_F(MessageTransferOperationTest, MultipleDevices) {
// Fail 3 times to connect to |test_devices_[3]|. // Fail 3 times to connect to |test_devices_[3]|.
test_timer_factory_->set_device_id_for_next_timer( test_timer_factory_->set_device_id_for_next_timer(
test_devices_[3].GetDeviceId()); test_devices_[3].GetDeviceId());
fake_ble_connection_manager_->SetDeviceStatus( fake_ble_connection_manager_->SimulateFailedConnectionAttempts(
test_devices_[3].GetDeviceId(), test_devices_[3].GetDeviceId(), kMaxConnectionAttemptsPerDevice);
cryptauth::SecureChannel::Status::CONNECTING);
fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[3].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED);
fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[3].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING);
fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[3].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED);
fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[3].GetDeviceId(),
cryptauth::SecureChannel::Status::CONNECTING);
fake_ble_connection_manager_->SetDeviceStatus(
test_devices_[3].GetDeviceId(),
cryptauth::SecureChannel::Status::DISCONNECTED);
EXPECT_FALSE(operation_->HasDeviceAuthenticated(test_devices_[3])); EXPECT_FALSE(operation_->HasDeviceAuthenticated(test_devices_[3]));
EXPECT_FALSE(fake_ble_connection_manager_->IsRegistered( EXPECT_FALSE(fake_ble_connection_manager_->IsRegistered(
test_devices_[3].GetDeviceId())); test_devices_[3].GetDeviceId()));
......
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