summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jakub Pawłowski <jpawlowski@google.com> 2025-03-20 06:06:50 -0700
committer Android (Google) Code Review <android-gerrit@google.com> 2025-03-20 06:06:50 -0700
commit91d6a6e9ea34cf3d61b32a042d741a2a7cc71a8c (patch)
treee6cece3e49d8ff15b6f6b5b9319c430932e58267
parent8a2598786fc0b355fad3e9f8dd0536450597c348 (diff)
parentf9c76eb959adee5650306ec4851b50eb2b424bb5 (diff)
Merge "Remove flag improve_create_connection_for_already_connecting_device" into main
-rw-r--r--flags/connectivity.aconfig10
-rw-r--r--system/gd/hci/acl_manager/le_impl.h15
-rw-r--r--system/gd/hci/acl_manager/le_impl_test.cc303
3 files changed, 133 insertions, 195 deletions
diff --git a/flags/connectivity.aconfig b/flags/connectivity.aconfig
index 482c7e68e8..35af7382ec 100644
--- a/flags/connectivity.aconfig
+++ b/flags/connectivity.aconfig
@@ -16,16 +16,6 @@ flag {
}
flag {
- name: "improve_create_connection_for_already_connecting_device"
- namespace: "bluetooth"
- description: "Make sure to not stop controller with create connection cancel when not needed"
- bug: "356593752"
- metadata {
- purpose: PURPOSE_BUGFIX
- }
-}
-
-flag {
name: "allow_gatt_connect_from_the_apps_without_making_leaudio_device_active"
namespace: "bluetooth"
description: "Allows for GATT connection without making LeAudio device active after connection"
diff --git a/system/gd/hci/acl_manager/le_impl.h b/system/gd/hci/acl_manager/le_impl.h
index ef5bfb0d7d..122f76525e 100644
--- a/system/gd/hci/acl_manager/le_impl.h
+++ b/system/gd/hci/acl_manager/le_impl.h
@@ -1063,15 +1063,12 @@ public:
add_device_to_accept_list(address_with_type);
}
- if (com::android::bluetooth::flags::
- improve_create_connection_for_already_connecting_device()) {
- bool in_accept_list_due_to_direct_connect =
- direct_connections_.find(address_with_type) != direct_connections_.end();
-
- if (already_in_accept_list && (in_accept_list_due_to_direct_connect || !is_direct)) {
- log::info("Device {} already in accept list. Stop here.", address_with_type);
- return;
- }
+ bool in_accept_list_due_to_direct_connect =
+ direct_connections_.find(address_with_type) != direct_connections_.end();
+
+ if (already_in_accept_list && (in_accept_list_due_to_direct_connect || !is_direct)) {
+ log::info("Device {} already in accept list. Stop here.", address_with_type);
+ return;
}
if (is_direct) {
diff --git a/system/gd/hci/acl_manager/le_impl_test.cc b/system/gd/hci/acl_manager/le_impl_test.cc
index 274b6827c9..f54d316d30 100644
--- a/system/gd/hci/acl_manager/le_impl_test.cc
+++ b/system/gd/hci/acl_manager/le_impl_test.cc
@@ -284,164 +284,6 @@ protected:
hci_layer_->IncomingEvent(LeSetRandomAddressCompleteBuilder::Create(0x01, ErrorCode::SUCCESS));
}
- void test_direct_connection_after_background_connection() {
- set_random_device_address_policy();
-
- hci::AddressWithType address({0x21, 0x22, 0x23, 0x24, 0x25, 0x26},
- AddressType::PUBLIC_DEVICE_ADDRESS);
-
- // arrange: Create background connection. Remember that acl_manager adds device background list
- le_impl_->add_device_to_background_connection_list(address);
- le_impl_->create_le_connection(address, true, /* is_direct */ false);
- hci_layer_->GetCommand(OpCode::LE_ADD_DEVICE_TO_FILTER_ACCEPT_LIST);
- hci_layer_->IncomingEvent(
- LeAddDeviceToFilterAcceptListCompleteBuilder::Create(0x01, ErrorCode::SUCCESS));
- auto raw_bg_create_connection = hci_layer_->GetCommand(OpCode::LE_CREATE_CONNECTION);
- hci_layer_->IncomingEvent(LeCreateConnectionStatusBuilder::Create(ErrorCode::SUCCESS, 0x01));
- sync_handler();
-
- // act: Create direct connection
- le_impl_->create_le_connection(address, true, /* is_direct */ true);
- auto cancel_connection = hci_layer_->GetCommand(OpCode::LE_CREATE_CONNECTION_CANCEL);
- if (cancel_connection.IsValid()) {
- hci_layer_->IncomingEvent(
- LeCreateConnectionCancelCompleteBuilder::Create(0x01, ErrorCode::SUCCESS));
- hci_layer_->IncomingLeMetaEvent(LeConnectionCompleteBuilder::Create(
- ErrorCode::UNKNOWN_CONNECTION, kHciHandle, Role::CENTRAL,
- AddressType::PUBLIC_DEVICE_ADDRESS, Address::kEmpty, 0x0000, 0x0000, 0x0000,
- ClockAccuracy::PPM_30));
- }
- auto raw_direct_create_connection = hci_layer_->GetCommand(OpCode::LE_CREATE_CONNECTION);
-
- // assert
- auto bg_create_connection =
- LeCreateConnectionView::Create(LeConnectionManagementCommandView::Create(
- AclCommandView::Create(raw_bg_create_connection)));
- EXPECT_TRUE(bg_create_connection.IsValid());
- auto direct_create_connection =
- LeCreateConnectionView::Create(LeConnectionManagementCommandView::Create(
- AclCommandView::Create(raw_direct_create_connection)));
- EXPECT_TRUE(direct_create_connection.IsValid());
- log::info("Scan Interval {}", direct_create_connection.GetLeScanInterval());
- ASSERT_NE(direct_create_connection.GetLeScanInterval(),
- bg_create_connection.GetLeScanInterval());
-
- hci_layer_->IncomingEvent(LeCreateConnectionStatusBuilder::Create(ErrorCode::SUCCESS, 0x01));
- sync_handler();
-
- // Check state is ARMED
- ASSERT_EQ(ConnectabilityState::ARMED, le_impl_->connectability_state_);
-
- // Simulate timeout on direct connect. Verify background connect is still in place
- EXPECT_CALL(mock_le_connection_callbacks_,
- OnLeConnectFail(_, ErrorCode::CONNECTION_ACCEPT_TIMEOUT))
- .Times(1);
- le_impl_->on_create_connection_timeout(address);
- sync_handler();
- cancel_connection = hci_layer_->GetCommand(OpCode::LE_CREATE_CONNECTION_CANCEL);
- hci_layer_->IncomingEvent(
- LeCreateConnectionCancelCompleteBuilder::Create(0x01, ErrorCode::SUCCESS));
- hci_layer_->IncomingLeMetaEvent(LeConnectionCompleteBuilder::Create(
- ErrorCode::UNKNOWN_CONNECTION, kHciHandle, Role::CENTRAL,
- AddressType::PUBLIC_DEVICE_ADDRESS, Address::kEmpty, 0x0000, 0x0000, 0x0000,
- ClockAccuracy::PPM_30));
- EXPECT_TRUE(cancel_connection.IsValid());
- raw_bg_create_connection = hci_layer_->GetCommand(OpCode::LE_CREATE_CONNECTION);
- bg_create_connection = LeCreateConnectionView::Create(LeConnectionManagementCommandView::Create(
- AclCommandView::Create(raw_bg_create_connection)));
- EXPECT_TRUE(bg_create_connection.IsValid());
- sync_handler();
- ASSERT_TRUE(le_impl_->create_connection_timeout_alarms_.empty());
-
- hci_layer_->IncomingEvent(LeCreateConnectionStatusBuilder::Create(ErrorCode::SUCCESS, 0x01));
- sync_handler();
-
- // Check state is ARMED
- ASSERT_EQ(ConnectabilityState::ARMED, le_impl_->connectability_state_);
- }
-
- void test_direct_connect_after_direct_connect() {
- set_random_device_address_policy();
-
- hci::AddressWithType address({0x21, 0x22, 0x23, 0x24, 0x25, 0x26},
- AddressType::PUBLIC_DEVICE_ADDRESS);
-
- // Create first direct connection
- le_impl_->create_le_connection(address, true, /* is_direct */ true);
- hci_layer_->GetCommand(OpCode::LE_ADD_DEVICE_TO_FILTER_ACCEPT_LIST);
- hci_layer_->IncomingEvent(
- LeAddDeviceToFilterAcceptListCompleteBuilder::Create(0x01, ErrorCode::SUCCESS));
- auto raw_direct_1_create_connection = hci_layer_->GetCommand(OpCode::LE_CREATE_CONNECTION);
- hci_layer_->IncomingEvent(LeCreateConnectionStatusBuilder::Create(ErrorCode::SUCCESS, 0x01));
- sync_handler();
-
- // Check state is ARMED
- ASSERT_EQ(ConnectabilityState::ARMED, le_impl_->connectability_state_);
-
- // assert
- auto direct_1_create_connection =
- LeCreateConnectionView::Create(LeConnectionManagementCommandView::Create(
- AclCommandView::Create(raw_direct_1_create_connection)));
- EXPECT_TRUE(direct_1_create_connection.IsValid());
-
- log::info("Second direct connect to the same device");
-
- // Create second direct connection
- le_impl_->create_le_connection(address, true, /* is_direct */ true);
- sync_handler();
-
- CommandView cancel_connection = CommandView::Create(
- PacketView<packet::kLittleEndian>(std::make_shared<std::vector<uint8_t>>()));
-
- if (!com::android::bluetooth::flags::
- improve_create_connection_for_already_connecting_device()) {
- cancel_connection = hci_layer_->GetCommand(OpCode::LE_CREATE_CONNECTION_CANCEL);
- if (cancel_connection.IsValid()) {
- hci_layer_->IncomingEvent(
- LeCreateConnectionCancelCompleteBuilder::Create(0x01, ErrorCode::SUCCESS));
- hci_layer_->IncomingLeMetaEvent(LeConnectionCompleteBuilder::Create(
- ErrorCode::UNKNOWN_CONNECTION, kHciHandle, Role::CENTRAL,
- AddressType::PUBLIC_DEVICE_ADDRESS, Address::kEmpty, 0x0000, 0x0000, 0x0000,
- ClockAccuracy::PPM_30));
- }
-
- auto raw_direct_2_create_connection = hci_layer_->GetCommand(OpCode::LE_CREATE_CONNECTION);
-
- auto direct_2_create_connection =
- LeCreateConnectionView::Create(LeConnectionManagementCommandView::Create(
- AclCommandView::Create(raw_direct_2_create_connection)));
- EXPECT_TRUE(direct_2_create_connection.IsValid());
- hci_layer_->IncomingEvent(LeCreateConnectionStatusBuilder::Create(ErrorCode::SUCCESS, 0x01));
- sync_handler();
- } else {
- hci_layer_->AssertNoQueuedCommand();
- }
-
- log::info("Simulate timeout");
-
- EXPECT_CALL(mock_le_connection_callbacks_,
- OnLeConnectFail(_, ErrorCode::CONNECTION_ACCEPT_TIMEOUT))
- .Times(1);
- le_impl_->on_create_connection_timeout(address);
- sync_handler();
- cancel_connection = hci_layer_->GetCommand(OpCode::LE_CREATE_CONNECTION_CANCEL);
- EXPECT_TRUE(cancel_connection.IsValid());
- hci_layer_->IncomingEvent(
- LeCreateConnectionCancelCompleteBuilder::Create(0x01, ErrorCode::SUCCESS));
- hci_layer_->IncomingLeMetaEvent(LeConnectionCompleteBuilder::Create(
- ErrorCode::UNKNOWN_CONNECTION, kHciHandle, Role::CENTRAL,
- AddressType::PUBLIC_DEVICE_ADDRESS, Address::kEmpty, 0x0000, 0x0000, 0x0000,
- ClockAccuracy::PPM_30));
- sync_handler();
- ASSERT_TRUE(le_impl_->create_connection_timeout_alarms_.empty());
-
- hci_layer_->GetCommand(OpCode::LE_REMOVE_DEVICE_FROM_FILTER_ACCEPT_LIST);
- hci_layer_->IncomingEvent(
- LeRemoveDeviceFromFilterAcceptListCompleteBuilder::Create(0x01, ErrorCode::SUCCESS));
- hci_layer_->AssertNoQueuedCommand();
- ASSERT_EQ(ConnectabilityState::DISARMED, le_impl_->connectability_state_);
- }
-
// Need to store the LeAclConnection so it is not immediately dropped => disconnected
std::unique_ptr<LeAclConnection> create_enhanced_connection(std::string remote_address_string,
int handle) {
@@ -1693,29 +1535,138 @@ TEST_F(LeImplTest, DisconnectionAcceptlistCallback) {
}
TEST_F(LeImplTest, direct_connection_after_background_connection) {
- // TODO b/356593752 - remove when test removing flag
- com::android::bluetooth::flags::provider_
- ->improve_create_connection_for_already_connecting_device(false);
- test_direct_connection_after_background_connection();
-}
+ set_random_device_address_policy();
+
+ hci::AddressWithType address({0x21, 0x22, 0x23, 0x24, 0x25, 0x26},
+ AddressType::PUBLIC_DEVICE_ADDRESS);
+
+ // arrange: Create background connection. Remember that acl_manager adds device background list
+ le_impl_->add_device_to_background_connection_list(address);
+ le_impl_->create_le_connection(address, true, /* is_direct */ false);
+ hci_layer_->GetCommand(OpCode::LE_ADD_DEVICE_TO_FILTER_ACCEPT_LIST);
+ hci_layer_->IncomingEvent(
+ LeAddDeviceToFilterAcceptListCompleteBuilder::Create(0x01, ErrorCode::SUCCESS));
+ auto raw_bg_create_connection = hci_layer_->GetCommand(OpCode::LE_CREATE_CONNECTION);
+ hci_layer_->IncomingEvent(LeCreateConnectionStatusBuilder::Create(ErrorCode::SUCCESS, 0x01));
+ sync_handler();
-TEST_F(LeImplTest, direct_connection_after_background_connection_with_improvement) {
- com::android::bluetooth::flags::provider_
- ->improve_create_connection_for_already_connecting_device(true);
- test_direct_connection_after_background_connection();
+ // act: Create direct connection
+ le_impl_->create_le_connection(address, true, /* is_direct */ true);
+ auto cancel_connection = hci_layer_->GetCommand(OpCode::LE_CREATE_CONNECTION_CANCEL);
+ if (cancel_connection.IsValid()) {
+ hci_layer_->IncomingEvent(
+ LeCreateConnectionCancelCompleteBuilder::Create(0x01, ErrorCode::SUCCESS));
+ hci_layer_->IncomingLeMetaEvent(LeConnectionCompleteBuilder::Create(
+ ErrorCode::UNKNOWN_CONNECTION, kHciHandle, Role::CENTRAL,
+ AddressType::PUBLIC_DEVICE_ADDRESS, Address::kEmpty, 0x0000, 0x0000, 0x0000,
+ ClockAccuracy::PPM_30));
+ }
+ auto raw_direct_create_connection = hci_layer_->GetCommand(OpCode::LE_CREATE_CONNECTION);
+
+ // assert
+ auto bg_create_connection =
+ LeCreateConnectionView::Create(LeConnectionManagementCommandView::Create(
+ AclCommandView::Create(raw_bg_create_connection)));
+ EXPECT_TRUE(bg_create_connection.IsValid());
+ auto direct_create_connection =
+ LeCreateConnectionView::Create(LeConnectionManagementCommandView::Create(
+ AclCommandView::Create(raw_direct_create_connection)));
+ EXPECT_TRUE(direct_create_connection.IsValid());
+ log::info("Scan Interval {}", direct_create_connection.GetLeScanInterval());
+ ASSERT_NE(direct_create_connection.GetLeScanInterval(), bg_create_connection.GetLeScanInterval());
+
+ hci_layer_->IncomingEvent(LeCreateConnectionStatusBuilder::Create(ErrorCode::SUCCESS, 0x01));
+ sync_handler();
+
+ // Check state is ARMED
+ ASSERT_EQ(ConnectabilityState::ARMED, le_impl_->connectability_state_);
+
+ // Simulate timeout on direct connect. Verify background connect is still in place
+ EXPECT_CALL(mock_le_connection_callbacks_,
+ OnLeConnectFail(_, ErrorCode::CONNECTION_ACCEPT_TIMEOUT))
+ .Times(1);
+ le_impl_->on_create_connection_timeout(address);
+ sync_handler();
+ cancel_connection = hci_layer_->GetCommand(OpCode::LE_CREATE_CONNECTION_CANCEL);
+ hci_layer_->IncomingEvent(
+ LeCreateConnectionCancelCompleteBuilder::Create(0x01, ErrorCode::SUCCESS));
+ hci_layer_->IncomingLeMetaEvent(LeConnectionCompleteBuilder::Create(
+ ErrorCode::UNKNOWN_CONNECTION, kHciHandle, Role::CENTRAL,
+ AddressType::PUBLIC_DEVICE_ADDRESS, Address::kEmpty, 0x0000, 0x0000, 0x0000,
+ ClockAccuracy::PPM_30));
+ EXPECT_TRUE(cancel_connection.IsValid());
+ raw_bg_create_connection = hci_layer_->GetCommand(OpCode::LE_CREATE_CONNECTION);
+ bg_create_connection = LeCreateConnectionView::Create(LeConnectionManagementCommandView::Create(
+ AclCommandView::Create(raw_bg_create_connection)));
+ EXPECT_TRUE(bg_create_connection.IsValid());
+ sync_handler();
+ ASSERT_TRUE(le_impl_->create_connection_timeout_alarms_.empty());
+
+ hci_layer_->IncomingEvent(LeCreateConnectionStatusBuilder::Create(ErrorCode::SUCCESS, 0x01));
+ sync_handler();
+
+ // Check state is ARMED
+ ASSERT_EQ(ConnectabilityState::ARMED, le_impl_->connectability_state_);
}
TEST_F(LeImplTest, direct_connection_after_direct_connection) {
- // TODO b/356593752 - remove when test removing flag
- com::android::bluetooth::flags::provider_
- ->improve_create_connection_for_already_connecting_device(false);
- test_direct_connect_after_direct_connect();
-}
+ set_random_device_address_policy();
-TEST_F(LeImplTest, direct_connection_after_direct_connection_with_improvement) {
- com::android::bluetooth::flags::provider_
- ->improve_create_connection_for_already_connecting_device(true);
- test_direct_connect_after_direct_connect();
+ hci::AddressWithType address({0x21, 0x22, 0x23, 0x24, 0x25, 0x26},
+ AddressType::PUBLIC_DEVICE_ADDRESS);
+
+ // Create first direct connection
+ le_impl_->create_le_connection(address, true, /* is_direct */ true);
+ hci_layer_->GetCommand(OpCode::LE_ADD_DEVICE_TO_FILTER_ACCEPT_LIST);
+ hci_layer_->IncomingEvent(
+ LeAddDeviceToFilterAcceptListCompleteBuilder::Create(0x01, ErrorCode::SUCCESS));
+ auto raw_direct_1_create_connection = hci_layer_->GetCommand(OpCode::LE_CREATE_CONNECTION);
+ hci_layer_->IncomingEvent(LeCreateConnectionStatusBuilder::Create(ErrorCode::SUCCESS, 0x01));
+ sync_handler();
+
+ // Check state is ARMED
+ ASSERT_EQ(ConnectabilityState::ARMED, le_impl_->connectability_state_);
+
+ // assert
+ auto direct_1_create_connection =
+ LeCreateConnectionView::Create(LeConnectionManagementCommandView::Create(
+ AclCommandView::Create(raw_direct_1_create_connection)));
+ EXPECT_TRUE(direct_1_create_connection.IsValid());
+
+ log::info("Second direct connect to the same device");
+
+ // Create second direct connection
+ le_impl_->create_le_connection(address, true, /* is_direct */ true);
+ sync_handler();
+
+ CommandView cancel_connection = CommandView::Create(
+ PacketView<packet::kLittleEndian>(std::make_shared<std::vector<uint8_t>>()));
+
+ hci_layer_->AssertNoQueuedCommand();
+
+ log::info("Simulate timeout");
+
+ EXPECT_CALL(mock_le_connection_callbacks_,
+ OnLeConnectFail(_, ErrorCode::CONNECTION_ACCEPT_TIMEOUT))
+ .Times(1);
+ le_impl_->on_create_connection_timeout(address);
+ sync_handler();
+ cancel_connection = hci_layer_->GetCommand(OpCode::LE_CREATE_CONNECTION_CANCEL);
+ EXPECT_TRUE(cancel_connection.IsValid());
+ hci_layer_->IncomingEvent(
+ LeCreateConnectionCancelCompleteBuilder::Create(0x01, ErrorCode::SUCCESS));
+ hci_layer_->IncomingLeMetaEvent(LeConnectionCompleteBuilder::Create(
+ ErrorCode::UNKNOWN_CONNECTION, kHciHandle, Role::CENTRAL,
+ AddressType::PUBLIC_DEVICE_ADDRESS, Address::kEmpty, 0x0000, 0x0000, 0x0000,
+ ClockAccuracy::PPM_30));
+ sync_handler();
+ ASSERT_TRUE(le_impl_->create_connection_timeout_alarms_.empty());
+
+ hci_layer_->GetCommand(OpCode::LE_REMOVE_DEVICE_FROM_FILTER_ACCEPT_LIST);
+ hci_layer_->IncomingEvent(
+ LeRemoveDeviceFromFilterAcceptListCompleteBuilder::Create(0x01, ErrorCode::SUCCESS));
+ hci_layer_->AssertNoQueuedCommand();
+ ASSERT_EQ(ConnectabilityState::DISARMED, le_impl_->connectability_state_);
}
TEST_F(LeImplTest, direct_connection_cancel_but_connected) {