Loading system/bta/csis/csis_client.cc +6 −0 Original line number Diff line number Diff line Loading @@ -1930,6 +1930,12 @@ class CsisClientImpl : public CsisClient { return; } /* verify encryption enabled */ if (!BTM_IsEncrypted(device->addr, BT_TRANSPORT_LE)) { LOG_WARN("Device not yet bonded - waiting for encryption"); return; } /* Ignore if our service data is valid (discovery initiated by someone * else?) */ if (!device->is_gatt_service_valid) { Loading system/bta/csis/csis_client_test.cc +40 −17 Original line number Diff line number Diff line Loading @@ -342,6 +342,9 @@ class CsisClientTest : public ::testing::Test { SetMockCsisLockCallback(&csis_lock_cb); callbacks.reset(new MockCsisCallbacks()); ON_CALL(btm_interface, BTM_IsEncrypted(_, _)) .WillByDefault(DoAll(Return(true))); ON_CALL(gatt_interface, GetCharacteristic(_, _)) .WillByDefault( Invoke([&](uint16_t conn_id, Loading Loading @@ -427,11 +430,11 @@ class CsisClientTest : public ::testing::Test { gatt_callback = nullptr; } void TestConnect(const RawAddress& address) { void TestConnect(const RawAddress& address, bool encrypted = true) { // by default indicate link as encrypted ON_CALL(btm_interface, GetSecurityFlagsByTransport(address, NotNull(), _)) .WillByDefault( DoAll(SetArgPointee<1>(BTM_SEC_FLAG_ENCRYPTED), Return(true))); DoAll(SetArgPointee<1>(BTM_SEC_FLAG_ENCRYPTED), Return(encrypted))); EXPECT_CALL(gatt_interface, Open(gatt_if, address, BTM_BLE_DIRECT_CONNECTION, _)); Loading Loading @@ -543,21 +546,6 @@ class CsisClientTest : public ::testing::Test { gatt_callback(BTA_GATTC_CLOSE_EVT, (tBTA_GATTC*)&event_data); } void SetEncryptionResult(const RawAddress& address, uint16_t conn_id, bool success) { ON_CALL(btm_interface, BTM_IsEncrypted(address, _)) .WillByDefault(DoAll(Return(success))); ON_CALL(btm_interface, SetEncryption(address, _, _, _, _)) .WillByDefault( Invoke([&](const RawAddress& bd_addr, tBT_TRANSPORT transport, tBTM_SEC_CALLBACK* p_callback, void* p_ref_data, tBTM_BLE_SEC_ACT sec_act) -> tBTM_STATUS { InjectEncryptionEvent(bd_addr, conn_id); return BTM_SUCCESS; })); } void SetSampleDatabaseCsis(uint16_t conn_id, uint8_t rank, uint8_t sirk_msb = 1) { set_sample_database(conn_id, true, false, rank, sirk_msb); Loading Loading @@ -759,6 +747,41 @@ TEST_F(CsisClientTest, test_get_group_id) { TestAppUnregister(); } TEST_F(CsisClientTest, test_search_complete_before_encryption) { SetSampleDatabaseCsis(1, 1); TestAppRegister(); TestConnect(test_address, false); EXPECT_CALL(*callbacks, OnConnectionState(test_address, ConnectionState::CONNECTED)) .Times(0); EXPECT_CALL(*callbacks, OnDeviceAvailable(test_address, _, _, _, _)).Times(0); ON_CALL(btm_interface, BTM_IsEncrypted(test_address, _)) .WillByDefault(DoAll(Return(false))); InjectConnectedEvent(test_address, 1); GetSearchCompleteEvent(1); Mock::VerifyAndClearExpectations(callbacks.get()); /* Incject encryption and expect device connection */ EXPECT_CALL(*callbacks, OnConnectionState(test_address, ConnectionState::CONNECTED)) .Times(1); EXPECT_CALL(*callbacks, OnDeviceAvailable(test_address, _, _, _, _)).Times(1); ON_CALL(btm_interface, BTM_IsEncrypted(test_address, _)) .WillByDefault(DoAll(Return(true))); EXPECT_CALL(gatt_interface, ServiceSearchRequest(_, _)).Times(1); InjectEncryptionEvent(test_address, 1); GetSearchCompleteEvent(1); Mock::VerifyAndClearExpectations(&gatt_interface); Mock::VerifyAndClearExpectations(callbacks.get()); TestAppUnregister(); } TEST_F(CsisClientTest, test_is_group_empty) { std::list<std::shared_ptr<CsisGroup>> csis_groups_; auto g_1 = std::make_shared<CsisGroup>(666, bluetooth::Uuid::kEmpty); Loading system/bta/has/has_client.cc +6 −0 Original line number Diff line number Diff line Loading @@ -1920,6 +1920,12 @@ class HasClientImpl : public HasClient { DLOG(INFO) << __func__; /* verify link is encrypted */ if (!BTM_IsEncrypted(device->addr, BT_TRANSPORT_LE)) { LOG_WARN("Device not yet bonded - waiting for encryption"); return; } /* Ignore if our service data is valid (service discovery initiated by * someone else?) */ Loading system/bta/has/has_client_test.cc +31 −0 Original line number Diff line number Diff line Loading @@ -1291,6 +1291,37 @@ TEST_F(HasClientTest, test_encryption_failed) { TestConnect(test_address); } TEST_F(HasClientTest, test_service_discovery_complete_before_encryption) { const RawAddress test_address = GetTestAddress(1); SetSampleDatabaseHasPresetsNtf( test_address, bluetooth::has::kFeatureBitHearingAidTypeBinaural); EXPECT_CALL(*callbacks, OnConnectionState(ConnectionState::DISCONNECTED, test_address)) .Times(0); EXPECT_CALL(*callbacks, OnConnectionState(ConnectionState::CONNECTED, test_address)) .Times(0); SetEncryptionResult(test_address, false); ON_CALL(btm_interface, SetEncryption(_, _, _, _, _)) .WillByDefault(Return(BTM_SUCCESS)); TestConnect(test_address); auto test_conn_id = GetTestConnId(test_address); InjectSearchCompleteEvent(test_conn_id); Mock::VerifyAndClearExpectations(callbacks.get()); EXPECT_CALL(*callbacks, OnConnectionState(ConnectionState::CONNECTED, test_address)) .Times(1); SetEncryptionResult(test_address, true); InjectEncryptionEvent(test_address); Mock::VerifyAndClearExpectations(callbacks.get()); } TEST_F(HasClientTest, test_reconnect_after_encryption_failed) { const RawAddress test_address = GetTestAddress(1); SetSampleDatabaseHasNoPresetChange( Loading system/bta/le_audio/client.cc +5 −0 Original line number Diff line number Diff line Loading @@ -2483,6 +2483,11 @@ class LeAudioClientImpl : public LeAudioClient { return; } if (!leAudioDevice->encrypted_) { LOG_WARN("Device not yet bonded - waiting for encryption"); return; } const std::list<gatt::Service>* services = BTA_GATTC_GetServices(conn_id); const gatt::Service* pac_svc = nullptr; Loading Loading
system/bta/csis/csis_client.cc +6 −0 Original line number Diff line number Diff line Loading @@ -1930,6 +1930,12 @@ class CsisClientImpl : public CsisClient { return; } /* verify encryption enabled */ if (!BTM_IsEncrypted(device->addr, BT_TRANSPORT_LE)) { LOG_WARN("Device not yet bonded - waiting for encryption"); return; } /* Ignore if our service data is valid (discovery initiated by someone * else?) */ if (!device->is_gatt_service_valid) { Loading
system/bta/csis/csis_client_test.cc +40 −17 Original line number Diff line number Diff line Loading @@ -342,6 +342,9 @@ class CsisClientTest : public ::testing::Test { SetMockCsisLockCallback(&csis_lock_cb); callbacks.reset(new MockCsisCallbacks()); ON_CALL(btm_interface, BTM_IsEncrypted(_, _)) .WillByDefault(DoAll(Return(true))); ON_CALL(gatt_interface, GetCharacteristic(_, _)) .WillByDefault( Invoke([&](uint16_t conn_id, Loading Loading @@ -427,11 +430,11 @@ class CsisClientTest : public ::testing::Test { gatt_callback = nullptr; } void TestConnect(const RawAddress& address) { void TestConnect(const RawAddress& address, bool encrypted = true) { // by default indicate link as encrypted ON_CALL(btm_interface, GetSecurityFlagsByTransport(address, NotNull(), _)) .WillByDefault( DoAll(SetArgPointee<1>(BTM_SEC_FLAG_ENCRYPTED), Return(true))); DoAll(SetArgPointee<1>(BTM_SEC_FLAG_ENCRYPTED), Return(encrypted))); EXPECT_CALL(gatt_interface, Open(gatt_if, address, BTM_BLE_DIRECT_CONNECTION, _)); Loading Loading @@ -543,21 +546,6 @@ class CsisClientTest : public ::testing::Test { gatt_callback(BTA_GATTC_CLOSE_EVT, (tBTA_GATTC*)&event_data); } void SetEncryptionResult(const RawAddress& address, uint16_t conn_id, bool success) { ON_CALL(btm_interface, BTM_IsEncrypted(address, _)) .WillByDefault(DoAll(Return(success))); ON_CALL(btm_interface, SetEncryption(address, _, _, _, _)) .WillByDefault( Invoke([&](const RawAddress& bd_addr, tBT_TRANSPORT transport, tBTM_SEC_CALLBACK* p_callback, void* p_ref_data, tBTM_BLE_SEC_ACT sec_act) -> tBTM_STATUS { InjectEncryptionEvent(bd_addr, conn_id); return BTM_SUCCESS; })); } void SetSampleDatabaseCsis(uint16_t conn_id, uint8_t rank, uint8_t sirk_msb = 1) { set_sample_database(conn_id, true, false, rank, sirk_msb); Loading Loading @@ -759,6 +747,41 @@ TEST_F(CsisClientTest, test_get_group_id) { TestAppUnregister(); } TEST_F(CsisClientTest, test_search_complete_before_encryption) { SetSampleDatabaseCsis(1, 1); TestAppRegister(); TestConnect(test_address, false); EXPECT_CALL(*callbacks, OnConnectionState(test_address, ConnectionState::CONNECTED)) .Times(0); EXPECT_CALL(*callbacks, OnDeviceAvailable(test_address, _, _, _, _)).Times(0); ON_CALL(btm_interface, BTM_IsEncrypted(test_address, _)) .WillByDefault(DoAll(Return(false))); InjectConnectedEvent(test_address, 1); GetSearchCompleteEvent(1); Mock::VerifyAndClearExpectations(callbacks.get()); /* Incject encryption and expect device connection */ EXPECT_CALL(*callbacks, OnConnectionState(test_address, ConnectionState::CONNECTED)) .Times(1); EXPECT_CALL(*callbacks, OnDeviceAvailable(test_address, _, _, _, _)).Times(1); ON_CALL(btm_interface, BTM_IsEncrypted(test_address, _)) .WillByDefault(DoAll(Return(true))); EXPECT_CALL(gatt_interface, ServiceSearchRequest(_, _)).Times(1); InjectEncryptionEvent(test_address, 1); GetSearchCompleteEvent(1); Mock::VerifyAndClearExpectations(&gatt_interface); Mock::VerifyAndClearExpectations(callbacks.get()); TestAppUnregister(); } TEST_F(CsisClientTest, test_is_group_empty) { std::list<std::shared_ptr<CsisGroup>> csis_groups_; auto g_1 = std::make_shared<CsisGroup>(666, bluetooth::Uuid::kEmpty); Loading
system/bta/has/has_client.cc +6 −0 Original line number Diff line number Diff line Loading @@ -1920,6 +1920,12 @@ class HasClientImpl : public HasClient { DLOG(INFO) << __func__; /* verify link is encrypted */ if (!BTM_IsEncrypted(device->addr, BT_TRANSPORT_LE)) { LOG_WARN("Device not yet bonded - waiting for encryption"); return; } /* Ignore if our service data is valid (service discovery initiated by * someone else?) */ Loading
system/bta/has/has_client_test.cc +31 −0 Original line number Diff line number Diff line Loading @@ -1291,6 +1291,37 @@ TEST_F(HasClientTest, test_encryption_failed) { TestConnect(test_address); } TEST_F(HasClientTest, test_service_discovery_complete_before_encryption) { const RawAddress test_address = GetTestAddress(1); SetSampleDatabaseHasPresetsNtf( test_address, bluetooth::has::kFeatureBitHearingAidTypeBinaural); EXPECT_CALL(*callbacks, OnConnectionState(ConnectionState::DISCONNECTED, test_address)) .Times(0); EXPECT_CALL(*callbacks, OnConnectionState(ConnectionState::CONNECTED, test_address)) .Times(0); SetEncryptionResult(test_address, false); ON_CALL(btm_interface, SetEncryption(_, _, _, _, _)) .WillByDefault(Return(BTM_SUCCESS)); TestConnect(test_address); auto test_conn_id = GetTestConnId(test_address); InjectSearchCompleteEvent(test_conn_id); Mock::VerifyAndClearExpectations(callbacks.get()); EXPECT_CALL(*callbacks, OnConnectionState(ConnectionState::CONNECTED, test_address)) .Times(1); SetEncryptionResult(test_address, true); InjectEncryptionEvent(test_address); Mock::VerifyAndClearExpectations(callbacks.get()); } TEST_F(HasClientTest, test_reconnect_after_encryption_failed) { const RawAddress test_address = GetTestAddress(1); SetSampleDatabaseHasNoPresetChange( Loading
system/bta/le_audio/client.cc +5 −0 Original line number Diff line number Diff line Loading @@ -2483,6 +2483,11 @@ class LeAudioClientImpl : public LeAudioClient { return; } if (!leAudioDevice->encrypted_) { LOG_WARN("Device not yet bonded - waiting for encryption"); return; } const std::list<gatt::Service>* services = BTA_GATTC_GetServices(conn_id); const gatt::Service* pac_svc = nullptr; Loading