diff options
Diffstat (limited to 'chromium/components/cryptauth')
10 files changed, 210 insertions, 86 deletions
diff --git a/chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection.cc b/chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection.cc index d0f0466642a..c3da0c48fbe 100644 --- a/chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection.cc +++ b/chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection.cc @@ -55,14 +55,16 @@ BluetoothLowEnergyWeaveClientConnection::Factory* std::unique_ptr<Connection> BluetoothLowEnergyWeaveClientConnection::Factory::NewInstance( const RemoteDevice& remote_device, - const std::string& device_address, scoped_refptr<device::BluetoothAdapter> adapter, - const device::BluetoothUUID remote_service_uuid) { + const device::BluetoothUUID remote_service_uuid, + device::BluetoothDevice* bluetooth_device, + bool should_set_low_connection_latency) { if (!factory_instance_) { factory_instance_ = new Factory(); } - return factory_instance_->BuildInstance(remote_device, device_address, - adapter, remote_service_uuid); + return factory_instance_->BuildInstance(remote_device, adapter, + remote_service_uuid, bluetooth_device, + should_set_low_connection_latency); } // static @@ -74,11 +76,13 @@ void BluetoothLowEnergyWeaveClientConnection::Factory::SetInstanceForTesting( std::unique_ptr<Connection> BluetoothLowEnergyWeaveClientConnection::Factory::BuildInstance( const RemoteDevice& remote_device, - const std::string& device_address, scoped_refptr<device::BluetoothAdapter> adapter, - const device::BluetoothUUID remote_service_uuid) { + const device::BluetoothUUID remote_service_uuid, + device::BluetoothDevice* bluetooth_device, + bool should_set_low_connection_latency) { return base::MakeUnique<BluetoothLowEnergyWeaveClientConnection>( - remote_device, device_address, adapter, remote_service_uuid); + remote_device, adapter, remote_service_uuid, bluetooth_device, + should_set_low_connection_latency); } // static @@ -131,11 +135,13 @@ std::string BluetoothLowEnergyWeaveClientConnection::SubStatusToString( BluetoothLowEnergyWeaveClientConnection:: BluetoothLowEnergyWeaveClientConnection( const RemoteDevice& device, - const std::string& device_address, scoped_refptr<device::BluetoothAdapter> adapter, - const device::BluetoothUUID remote_service_uuid) + const device::BluetoothUUID remote_service_uuid, + device::BluetoothDevice* bluetooth_device, + bool should_set_low_connection_latency) : Connection(device), - device_address_(device_address), + bluetooth_device_(bluetooth_device), + should_set_low_connection_latency_(should_set_low_connection_latency), adapter_(adapter), remote_service_({remote_service_uuid, std::string()}), packet_generator_( @@ -160,6 +166,15 @@ BluetoothLowEnergyWeaveClientConnection:: void BluetoothLowEnergyWeaveClientConnection::Connect() { DCHECK(sub_status() == SubStatus::DISCONNECTED); + + if (should_set_low_connection_latency_) + SetConnectionLatency(); + else + CreateGattConnection(); +} + +void BluetoothLowEnergyWeaveClientConnection::SetConnectionLatency() { + DCHECK(sub_status() == SubStatus::DISCONNECTED); SetSubStatus(SubStatus::WAITING_CONNECTION_LATENCY); device::BluetoothDevice* bluetooth_device = GetBluetoothDevice(); @@ -182,7 +197,8 @@ void BluetoothLowEnergyWeaveClientConnection::Connect() { } void BluetoothLowEnergyWeaveClientConnection::CreateGattConnection() { - DCHECK(sub_status() == SubStatus::WAITING_CONNECTION_LATENCY); + DCHECK(sub_status() == SubStatus::DISCONNECTED || + sub_status() == SubStatus::WAITING_CONNECTION_LATENCY); SetSubStatus(SubStatus::WAITING_GATT_CONNECTION); device::BluetoothDevice* bluetooth_device = GetBluetoothDevice(); @@ -717,12 +733,12 @@ std::string BluetoothLowEnergyWeaveClientConnection::GetDeviceAddress() { // |gatt_connection_|. Unpaired BLE device addresses are ephemeral and are // expected to change periodically. return gatt_connection_ ? gatt_connection_->GetDeviceAddress() - : device_address_; + : bluetooth_device_->GetAddress(); } device::BluetoothDevice* BluetoothLowEnergyWeaveClientConnection::GetBluetoothDevice() { - return adapter_->GetDevice(GetDeviceAddress()); + return bluetooth_device_; } device::BluetoothRemoteGattService* diff --git a/chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection.h b/chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection.h index 1a74e45c6a9..2ae20e4e015 100644 --- a/chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection.h +++ b/chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection.h @@ -57,17 +57,19 @@ class BluetoothLowEnergyWeaveClientConnection public: static std::unique_ptr<Connection> NewInstance( const RemoteDevice& remote_device, - const std::string& device_address, scoped_refptr<device::BluetoothAdapter> adapter, - const device::BluetoothUUID remote_service_uuid); + const device::BluetoothUUID remote_service_uuid, + device::BluetoothDevice* bluetooth_device, + bool should_set_low_connection_latency); static void SetInstanceForTesting(Factory* factory); protected: virtual std::unique_ptr<Connection> BuildInstance( const RemoteDevice& remote_device, - const std::string& device_address, scoped_refptr<device::BluetoothAdapter> adapter, - const device::BluetoothUUID remote_service_uuid); + const device::BluetoothUUID remote_service_uuid, + device::BluetoothDevice* bluetooth_device, + bool should_set_low_connection_latency); private: static Factory* factory_instance_; @@ -89,9 +91,10 @@ class BluetoothLowEnergyWeaveClientConnection // necessary to initiate the BLE connection. BluetoothLowEnergyWeaveClientConnection( const RemoteDevice& remote_device, - const std::string& device_address, scoped_refptr<device::BluetoothAdapter> adapter, - const device::BluetoothUUID remote_service_uuid); + const device::BluetoothUUID remote_service_uuid, + device::BluetoothDevice* bluetooth_device, + bool should_set_low_connection_latency); ~BluetoothLowEnergyWeaveClientConnection() override; @@ -134,6 +137,10 @@ class BluetoothLowEnergyWeaveClientConnection device::BluetoothRemoteGattCharacteristic* characteristic, const Packet& value) override; + bool should_set_low_connection_latency() { + return should_set_low_connection_latency_; + } + private: enum WriteRequestType { REGULAR, @@ -217,10 +224,10 @@ class BluetoothLowEnergyWeaveClientConnection // connection. std::string GetReasonForClose(); - // The device to which to connect. This is the starting value, but the device - // address may change during the connection because BLE addresses are - // ephemeral. Use GetDeviceAddress() to get the most up-to-date address. - const std::string device_address_; + // The device to which to connect. + device::BluetoothDevice* bluetooth_device_; + + bool should_set_low_connection_latency_; scoped_refptr<device::BluetoothAdapter> adapter_; RemoteAttribute remote_service_; diff --git a/chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection_unittest.cc b/chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection_unittest.cc index 87333d3ddb7..c8a00920387 100644 --- a/chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection_unittest.cc +++ b/chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection_unittest.cc @@ -210,16 +210,24 @@ class TestBluetoothLowEnergyWeaveClientConnection public: TestBluetoothLowEnergyWeaveClientConnection( const RemoteDevice& remote_device, - const std::string& device_address, scoped_refptr<device::BluetoothAdapter> adapter, - const device::BluetoothUUID remote_service_uuid) - : BluetoothLowEnergyWeaveClientConnection(remote_device, - device_address, - adapter, - remote_service_uuid) {} + const device::BluetoothUUID remote_service_uuid, + device::MockBluetoothDevice* mock_bluetooth_device, + bool should_set_low_connection_latency) + : BluetoothLowEnergyWeaveClientConnection( + remote_device, + adapter, + remote_service_uuid, + mock_bluetooth_device, + should_set_low_connection_latency) {} ~TestBluetoothLowEnergyWeaveClientConnection() override {} + bool should_set_low_connection_latency() { + return BluetoothLowEnergyWeaveClientConnection:: + should_set_low_connection_latency(); + } + MOCK_METHOD2( CreateCharacteristicsFinder, BluetoothLowEnergyCharacteristicsFinder*( @@ -364,15 +372,15 @@ class CryptAuthBluetoothLowEnergyWeaveClientConnectionTest // Creates a BluetoothLowEnergyWeaveClientConnection and verifies it's in // DISCONNECTED state. - std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> - CreateConnection() { + std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> CreateConnection( + bool should_set_low_connection_latency) { EXPECT_CALL(*adapter_, AddObserver(_)); EXPECT_CALL(*adapter_, RemoveObserver(_)); std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( new TestBluetoothLowEnergyWeaveClientConnection( - remote_device_, kTestRemoteDeviceBluetoothAddress, adapter_, - service_uuid_)); + remote_device_, adapter_, service_uuid_, + mock_bluetooth_device_.get(), should_set_low_connection_latency)); EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED); EXPECT_EQ(connection->status(), Connection::DISCONNECTED); @@ -396,11 +404,13 @@ class CryptAuthBluetoothLowEnergyWeaveClientConnectionTest // Transitions |connection| from DISCONNECTED to WAITING_CHARACTERISTICS // state, without an existing GATT connection. void ConnectGatt(TestBluetoothLowEnergyWeaveClientConnection* connection) { - EXPECT_CALL(*mock_bluetooth_device_, - SetConnectionLatency( - device::BluetoothDevice::CONNECTION_LATENCY_LOW, _, _)) - .WillOnce(DoAll(SaveArg<1>(&connection_latency_callback_), - SaveArg<2>(&connection_latency_error_callback_))); + if (connection->should_set_low_connection_latency()) { + EXPECT_CALL(*mock_bluetooth_device_, + SetConnectionLatency( + device::BluetoothDevice::CONNECTION_LATENCY_LOW, _, _)) + .WillOnce(DoAll(SaveArg<1>(&connection_latency_callback_), + SaveArg<2>(&connection_latency_error_callback_))); + } // Preparing |connection| for a CreateGattConnection call. EXPECT_CALL(*mock_bluetooth_device_, CreateGattConnection(_, _)) @@ -409,12 +419,15 @@ class CryptAuthBluetoothLowEnergyWeaveClientConnectionTest connection->Connect(); - // Handle setting the connection latency. - EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_CONNECTION_LATENCY); - EXPECT_EQ(connection->status(), Connection::IN_PROGRESS); - ASSERT_FALSE(connection_latency_callback_.is_null()); - ASSERT_FALSE(connection_latency_error_callback_.is_null()); - connection_latency_callback_.Run(); + if (connection->should_set_low_connection_latency()) { + // Handle setting the connection latency. + EXPECT_EQ(connection->sub_status(), + SubStatus::WAITING_CONNECTION_LATENCY); + EXPECT_EQ(connection->status(), Connection::IN_PROGRESS); + ASSERT_FALSE(connection_latency_callback_.is_null()); + ASSERT_FALSE(connection_latency_error_callback_.is_null()); + connection_latency_callback_.Run(); + } EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_GATT_CONNECTION); EXPECT_EQ(connection->status(), Connection::IN_PROGRESS); @@ -605,21 +618,21 @@ class CryptAuthBluetoothLowEnergyWeaveClientConnectionTest TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, CreateAndDestroyWithoutConnectCallDoesntCrash) { BluetoothLowEnergyWeaveClientConnection connection( - remote_device_, kTestRemoteDeviceBluetoothAddress, adapter_, - service_uuid_); + remote_device_, adapter_, service_uuid_, mock_bluetooth_device_.get(), + true /* should_set_low_connection_latency */); } TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, DisconnectWithoutConnectDoesntCrash) { std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( - CreateConnection()); + CreateConnection(true /* should_set_low_connection_latency */)); Disconnect(connection.get()); } TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ConnectSuccess) { std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( - CreateConnection()); + CreateConnection(true /* should_set_low_connection_latency */)); ConnectGatt(connection.get()); CharacteristicsFound(connection.get()); NotifySessionStarted(connection.get()); @@ -629,7 +642,16 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ConnectSuccessDisconnect) { std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( - CreateConnection()); + CreateConnection(true /* should_set_low_connection_latency */)); + InitializeConnection(connection.get(), kDefaultMaxPacketSize); + EXPECT_EQ(connection->sub_status(), SubStatus::CONNECTED); + Disconnect(connection.get()); +} + +TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, + ConnectSuccessDisconnect_DoNotSetLowLatency) { + std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( + CreateConnection(false /* should_set_low_connection_latency */)); InitializeConnection(connection.get(), kDefaultMaxPacketSize); EXPECT_EQ(connection->sub_status(), SubStatus::CONNECTED); Disconnect(connection.get()); @@ -638,7 +660,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ConnectIncompleteDisconnectFromWaitingCharacteristicsState) { std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( - CreateConnection()); + CreateConnection(true /* should_set_low_connection_latency */)); ConnectGatt(connection.get()); Disconnect(connection.get()); } @@ -646,7 +668,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ConnectIncompleteDisconnectFromWaitingNotifySessionState) { std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( - CreateConnection()); + CreateConnection(true /* should_set_low_connection_latency */)); ConnectGatt(connection.get()); CharacteristicsFound(connection.get()); Disconnect(connection.get()); @@ -655,7 +677,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ConnectIncompleteDisconnectFromWaitingConnectionResponseState) { std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( - CreateConnection()); + CreateConnection(true /* should_set_low_connection_latency */)); ConnectGatt(connection.get()); CharacteristicsFound(connection.get()); NotifySessionStarted(connection.get()); @@ -665,7 +687,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ConnectFailsCharacteristicsNotFound) { std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( - CreateConnection()); + CreateConnection(true /* should_set_low_connection_latency */)); ConnectGatt(connection.get()); EXPECT_CALL(*rx_characteristic_, StartNotifySession(_, _)).Times(0); @@ -683,7 +705,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ConnectFailsCharacteristicsFoundThenUnavailable) { std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( - CreateConnection()); + CreateConnection(true /* should_set_low_connection_latency */)); ConnectGatt(connection.get()); // Simulate the inability to fetch the characteristic after it was received. @@ -705,7 +727,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ConnectFailsNotifySessionError) { std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( - CreateConnection()); + CreateConnection(true /* should_set_low_connection_latency */)); ConnectGatt(connection.get()); CharacteristicsFound(connection.get()); @@ -723,7 +745,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ConnectFailsErrorSendingConnectionRequest) { std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( - CreateConnection()); + CreateConnection(true /* should_set_low_connection_latency */)); ConnectGatt(connection.get()); CharacteristicsFound(connection.get()); NotifySessionStarted(connection.get()); @@ -756,7 +778,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ReceiveMessageSmallerThanCharacteristicSize) { std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( - CreateConnection()); + CreateConnection(true /* should_set_low_connection_latency */)); InitializeConnection(connection.get(), kDefaultMaxPacketSize); std::string received_bytes; @@ -772,7 +794,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ReceiveMessageLargerThanCharacteristicSize) { std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( - CreateConnection()); + CreateConnection(true /* should_set_low_connection_latency */)); InitializeConnection(connection.get(), kLargeMaxPacketSize); @@ -792,7 +814,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, SendMessageSmallerThanCharacteristicSize) { std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( - CreateConnection()); + CreateConnection(true /* should_set_low_connection_latency */)); InitializeConnection(connection.get(), kDefaultMaxPacketSize); // Expecting a first call of WriteRemoteCharacteristic, after SendMessage is @@ -818,7 +840,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, SendMessageLargerThanCharacteristicSize) { std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( - CreateConnection()); + CreateConnection(true /* should_set_low_connection_latency */)); InitializeConnection(connection.get(), kLargeMaxPacketSize); @@ -862,7 +884,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, SendMessageKeepsFailing) { std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( - CreateConnection()); + CreateConnection(true /* should_set_low_connection_latency */)); InitializeConnection(connection.get(), kDefaultMaxPacketSize); EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic(_, _, _)) @@ -899,7 +921,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ReceiveCloseConnectionTest) { std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( - CreateConnection()); + CreateConnection(true /* should_set_low_connection_latency */)); InitializeConnection(connection.get(), kDefaultMaxPacketSize); connection->GattCharacteristicValueChanged( @@ -913,7 +935,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ReceiverErrorTest) { std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( - CreateConnection()); + CreateConnection(true /* should_set_low_connection_latency */)); InitializeConnection(connection.get(), kDefaultMaxPacketSize); @@ -938,7 +960,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ReceiverErrorWithPendingWritesTest) { std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( - CreateConnection()); + CreateConnection(true /* should_set_low_connection_latency */)); InitializeConnection(connection.get(), kLargeMaxPacketSize); @@ -977,7 +999,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ObserverDeletesConnectionOnDisconnect) { TestBluetoothLowEnergyWeaveClientConnection* connection = - CreateConnection().release(); + CreateConnection(true /* should_set_low_connection_latency */).release(); connection_observer_->set_delete_on_disconnect(true); InitializeConnection(connection, kDefaultMaxPacketSize); @@ -1005,7 +1027,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ObserverDeletesConnectionOnMessageSent) { TestBluetoothLowEnergyWeaveClientConnection* connection = - CreateConnection().release(); + CreateConnection(true /* should_set_low_connection_latency */).release(); connection_observer_->set_delete_on_message_sent(true); InitializeConnection(connection, kDefaultMaxPacketSize); @@ -1033,7 +1055,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, WriteConnectionCloseMaxNumberOfTimes) { std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( - CreateConnection()); + CreateConnection(true /* should_set_low_connection_latency */)); InitializeConnection(connection.get(), kDefaultMaxPacketSize); EXPECT_EQ(connection->sub_status(), SubStatus::CONNECTED); @@ -1072,7 +1094,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ConnectAfterADelayWhenThrottled) { std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( - CreateConnection()); + CreateConnection(true /* should_set_low_connection_latency */)); EXPECT_CALL(*mock_bluetooth_device_, SetConnectionLatency( @@ -1118,7 +1140,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, SetConnectionLatencyError) { std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( - CreateConnection()); + CreateConnection(true /* should_set_low_connection_latency */)); EXPECT_CALL(*mock_bluetooth_device_, SetConnectionLatency( @@ -1156,7 +1178,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, Timeout_ConnectionLatency) { std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( - CreateConnection()); + CreateConnection(true /* should_set_low_connection_latency */)); EXPECT_CALL(*mock_bluetooth_device_, SetConnectionLatency( @@ -1181,7 +1203,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, Timeout_GattConnection) { std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( - CreateConnection()); + CreateConnection(true /* should_set_low_connection_latency */)); EXPECT_CALL(*mock_bluetooth_device_, SetConnectionLatency( @@ -1216,7 +1238,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, Timeout_GattCharacteristics) { std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( - CreateConnection()); + CreateConnection(true /* should_set_low_connection_latency */)); ConnectGatt(connection.get()); EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_CHARACTERISTICS); EXPECT_EQ(connection->status(), Connection::IN_PROGRESS); @@ -1231,7 +1253,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, Timeout_NotifySession) { std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( - CreateConnection()); + CreateConnection(true /* should_set_low_connection_latency */)); ConnectGatt(connection.get()); CharacteristicsFound(connection.get()); EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_NOTIFY_SESSION); @@ -1247,7 +1269,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, Timeout_ConnectionResponse) { std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection( - CreateConnection()); + CreateConnection(true /* should_set_low_connection_latency */)); ConnectGatt(connection.get()); CharacteristicsFound(connection.get()); NotifySessionStarted(connection.get()); diff --git a/chromium/components/cryptauth/cryptauth_test_util.cc b/chromium/components/cryptauth/cryptauth_test_util.cc index 60b31f8ecff..4d0be8586e9 100644 --- a/chromium/components/cryptauth/cryptauth_test_util.cc +++ b/chromium/components/cryptauth/cryptauth_test_util.cc @@ -12,6 +12,8 @@ const char kTestRemoteDeviceName[] = "remote device"; const char kTestRemoteDevicePublicKey[] = "public key"; const char kTestRemoteDeviceBluetoothAddress[] = "AA:BB:CC:DD:EE:FF"; const char kTestRemoteDevicePSK[] = "remote device psk"; -const char kTestRemoteDeviceSignInChallenge[] = "sign-in challenge"; +const bool kTestRemoteDeviceUnlockKey = true; +const bool kTestRemoteDeviceSupportsMobileHotspot = true; +const int64_t kTestRemoteDeviceLastUpdateTimeMillis = 0L; } // namespace cryptauth diff --git a/chromium/components/cryptauth/cryptauth_test_util.h b/chromium/components/cryptauth/cryptauth_test_util.h index 4c43b810e62..3ef00122a7f 100644 --- a/chromium/components/cryptauth/cryptauth_test_util.h +++ b/chromium/components/cryptauth/cryptauth_test_util.h @@ -15,14 +15,18 @@ extern const char kTestRemoteDeviceName[]; extern const char kTestRemoteDevicePublicKey[]; extern const char kTestRemoteDeviceBluetoothAddress[]; extern const char kTestRemoteDevicePSK[]; -extern const char kTestRemoteDeviceSignInChallenge[]; +extern const bool kTestRemoteDeviceUnlockKey; +extern const bool kTestRemoteDeviceSupportsMobileHotspot; +extern const int64_t kTestRemoteDeviceLastUpdateTimeMillis; // Returns a BLE RemoteDevice used for tests. inline RemoteDevice CreateLERemoteDeviceForTest() { return RemoteDevice(kTestRemoteDeviceUserId, kTestRemoteDeviceName, kTestRemoteDevicePublicKey, kTestRemoteDeviceBluetoothAddress, kTestRemoteDevicePSK, - kTestRemoteDeviceSignInChallenge); + kTestRemoteDeviceUnlockKey, + kTestRemoteDeviceSupportsMobileHotspot, + kTestRemoteDeviceLastUpdateTimeMillis); } // Returns a classic Bluetooth RemoteDevice used for tests. @@ -30,7 +34,9 @@ inline RemoteDevice CreateClassicRemoteDeviceForTest() { return RemoteDevice(kTestRemoteDeviceUserId, kTestRemoteDeviceName, kTestRemoteDevicePublicKey, kTestRemoteDeviceBluetoothAddress, kTestRemoteDevicePSK, - kTestRemoteDeviceSignInChallenge); + kTestRemoteDeviceUnlockKey, + kTestRemoteDeviceSupportsMobileHotspot, + kTestRemoteDeviceLastUpdateTimeMillis); } } // namespace cryptauth diff --git a/chromium/components/cryptauth/mock_foreground_eid_generator.h b/chromium/components/cryptauth/mock_foreground_eid_generator.h index c9b328d041e..ef7232c898d 100644 --- a/chromium/components/cryptauth/mock_foreground_eid_generator.h +++ b/chromium/components/cryptauth/mock_foreground_eid_generator.h @@ -39,7 +39,7 @@ class MockForegroundEidGenerator : public ForegroundEidGenerator { possible_advertisements_ = std::move(possible_advertisements); } - void set_identified_device(RemoteDevice* identified_device) { + void set_identified_device(const RemoteDevice* identified_device) { identified_device_ = identified_device; } diff --git a/chromium/components/cryptauth/remote_device.cc b/chromium/components/cryptauth/remote_device.cc index b9556956e57..7a176026d24 100644 --- a/chromium/components/cryptauth/remote_device.cc +++ b/chromium/components/cryptauth/remote_device.cc @@ -32,20 +32,27 @@ bool AreBeaconSeedsEqual(const std::vector<BeaconSeed> beacon_seeds1, } // namespace -RemoteDevice::RemoteDevice() {} +RemoteDevice::RemoteDevice() + : unlock_key(false), + supports_mobile_hotspot(false), + last_update_time_millis(0L) {} RemoteDevice::RemoteDevice(const std::string& user_id, const std::string& name, const std::string& public_key, const std::string& bluetooth_address, const std::string& persistent_symmetric_key, - std::string sign_in_challenge) + bool unlock_key, + bool supports_mobile_hotspot, + int64_t last_update_time_millis) : user_id(user_id), name(name), public_key(public_key), bluetooth_address(bluetooth_address), persistent_symmetric_key(persistent_symmetric_key), - sign_in_challenge(sign_in_challenge) {} + unlock_key(unlock_key), + supports_mobile_hotspot(supports_mobile_hotspot), + last_update_time_millis(last_update_time_millis) {} RemoteDevice::RemoteDevice(const RemoteDevice& other) = default; @@ -82,7 +89,10 @@ bool RemoteDevice::operator==(const RemoteDevice& other) const { public_key == other.public_key && bluetooth_address == other.bluetooth_address && persistent_symmetric_key == other.persistent_symmetric_key && - sign_in_challenge == other.sign_in_challenge && are_beacon_seeds_equal; + unlock_key == other.unlock_key && + supports_mobile_hotspot == other.supports_mobile_hotspot && + last_update_time_millis == other.last_update_time_millis && + are_beacon_seeds_equal; } bool RemoteDevice::operator<(const RemoteDevice& other) const { diff --git a/chromium/components/cryptauth/remote_device.h b/chromium/components/cryptauth/remote_device.h index 7662b1a38c7..abdd4db15cb 100644 --- a/chromium/components/cryptauth/remote_device.h +++ b/chromium/components/cryptauth/remote_device.h @@ -19,7 +19,9 @@ struct RemoteDevice { std::string public_key; std::string bluetooth_address; std::string persistent_symmetric_key; - std::string sign_in_challenge; + bool unlock_key; + bool supports_mobile_hotspot; + int64_t last_update_time_millis; // Note: To save space, the BeaconSeeds may not necessarily be included in // this object. @@ -32,7 +34,9 @@ struct RemoteDevice { const std::string& public_key, const std::string& bluetooth_address, const std::string& persistent_symmetric_key, - std::string sign_in_challenge); + bool unlock_key, + bool supports_mobile_hotspot, + int64_t last_update_time_millis); RemoteDevice(const RemoteDevice& other); ~RemoteDevice(); diff --git a/chromium/components/cryptauth/remote_device_loader.cc b/chromium/components/cryptauth/remote_device_loader.cc index 705a1262d84..a9fc03543a7 100644 --- a/chromium/components/cryptauth/remote_device_loader.cc +++ b/chromium/components/cryptauth/remote_device_loader.cc @@ -106,7 +106,8 @@ void RemoteDeviceLoader::OnPSKDerived( cryptauth::RemoteDevice remote_device( user_id_, device.friendly_device_name(), device.public_key(), - device.bluetooth_address(), psk, std::string()); + device.bluetooth_address(), psk, device.unlock_key(), + device.mobile_hotspot_supported(), device.last_update_time_millis()); if (should_load_beacon_seeds_) { std::vector<BeaconSeed> beacon_seeds; diff --git a/chromium/components/cryptauth/remote_device_loader_unittest.cc b/chromium/components/cryptauth/remote_device_loader_unittest.cc index 3f538d383aa..3aa71fb89c4 100644 --- a/chromium/components/cryptauth/remote_device_loader_unittest.cc +++ b/chromium/components/cryptauth/remote_device_loader_unittest.cc @@ -153,6 +153,62 @@ TEST_F(CryptAuthRemoteDeviceLoaderTest, LoadDevicesWithAndWithoutBeaconSeeds) { remote_device_without_beacon_seed); } +TEST_F(CryptAuthRemoteDeviceLoaderTest, BooleanAttributes) { + cryptauth::ExternalDeviceInfo first = CreateDeviceInfo("0"); + first.set_unlock_key(true); + first.set_mobile_hotspot_supported(true); + + cryptauth::ExternalDeviceInfo second = CreateDeviceInfo("1"); + second.set_unlock_key(false); + second.set_mobile_hotspot_supported(false); + + std::vector<cryptauth::ExternalDeviceInfo> device_infos{first, second}; + + RemoteDeviceLoader loader(device_infos, user_private_key_, kUserId, + std::move(secure_message_delegate_)); + + std::vector<cryptauth::RemoteDevice> result; + EXPECT_CALL(*this, LoadCompleted()); + loader.Load( + false, base::Bind(&CryptAuthRemoteDeviceLoaderTest::OnRemoteDevicesLoaded, + base::Unretained(this))); + + EXPECT_EQ(2u, remote_devices_.size()); + + EXPECT_FALSE(remote_devices_[0].persistent_symmetric_key.empty()); + EXPECT_TRUE(remote_devices_[0].unlock_key); + EXPECT_TRUE(remote_devices_[0].supports_mobile_hotspot); + + EXPECT_FALSE(remote_devices_[1].persistent_symmetric_key.empty()); + EXPECT_FALSE(remote_devices_[1].unlock_key); + EXPECT_FALSE(remote_devices_[1].supports_mobile_hotspot); +} + +TEST_F(CryptAuthRemoteDeviceLoaderTest, LastUpdateTimeMillis) { + cryptauth::ExternalDeviceInfo first = CreateDeviceInfo("0"); + first.set_last_update_time_millis(1000); + + cryptauth::ExternalDeviceInfo second = CreateDeviceInfo("1"); + second.set_last_update_time_millis(2000); + + std::vector<cryptauth::ExternalDeviceInfo> device_infos{first, second}; + + RemoteDeviceLoader loader(device_infos, user_private_key_, kUserId, + std::move(secure_message_delegate_)); + + std::vector<cryptauth::RemoteDevice> result; + EXPECT_CALL(*this, LoadCompleted()); + loader.Load( + false, base::Bind(&CryptAuthRemoteDeviceLoaderTest::OnRemoteDevicesLoaded, + base::Unretained(this))); + + EXPECT_EQ(2u, remote_devices_.size()); + + EXPECT_EQ(1000, remote_devices_[0].last_update_time_millis); + + EXPECT_EQ(2000, remote_devices_[1].last_update_time_millis); +} + TEST_F(CryptAuthRemoteDeviceLoaderTest, LoadOneDeviceWithAddress) { std::vector<cryptauth::ExternalDeviceInfo> device_infos(1, CreateDeviceInfo("0")); |