Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aaa61606 authored by Krzysztof Kopyściński's avatar Krzysztof Kopyściński
Browse files

has_client.cc: fix single device disconnection

Before BTA_GATTC_Close is called, DoDisconnectCleanUp() and
devices_.erase() shall be called, preventing second call of disconnect
from GATT.

Bug: 370405555
Bug: 361014973
Test: atest --host --no-bazel-mode HasClientTest
Flag: com.android.bluetooth.flags.hap_connect_only_requested_device
Change-Id: Id1c1944b0ea15a6c0caa10be38092997c98f1cb9
parent a7391758
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -224,6 +224,10 @@ public:
              std::find_if(devices_.begin(), devices_.end(), HasDevice::MatchAddress(address));
      auto conn_id = device->conn_id;
      auto is_connecting_actively = device->is_connecting_actively;

      DoDisconnectCleanUp(*device);
      devices_.erase(device);

      if (conn_id != GATT_INVALID_CONN_ID) {
        BTA_GATTC_Close(conn_id);
        callbacks_->OnConnectionState(ConnectionState::DISCONNECTED, address);
+21 −0
Original line number Diff line number Diff line
@@ -19,8 +19,10 @@
#include <base/functional/bind.h>
#include <base/strings/string_number_conversions.h>
#include <bluetooth/log.h>
#include <com_android_bluetooth_flags.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <log/log.h>
#include <osi/include/alarm.h>
#include <sys/socket.h>

@@ -622,6 +624,7 @@ protected:
  }

  void SetUp(void) override {
    __android_log_set_minimum_priority(ANDROID_LOG_VERBOSE);
    reset_mock_function_count_map();
    bluetooth::manager::SetMockBtmInterface(&btm_interface);
    bluetooth::storage::SetMockBtifStorageInterface(&btif_storage_interface_);
@@ -1129,6 +1132,7 @@ class HasClientTest : public HasClientTestBase {
    TestAppRegister();
  }
  void TearDown(void) override {
    com::android::bluetooth::flags::provider_->reset_flags();
    TestAppUnregister();
    HasClientTestBase::TearDown();
  }
@@ -1213,7 +1217,24 @@ TEST_F(HasClientTest, test_has_connected) {
  TestConnect(test_address);
}

TEST_F(HasClientTest, test_disconnect_connected_without_hap_connect_only_requested_device_flag) {
  /* TODO: this test shall be removed b/370405555 */
  com::android::bluetooth::flags::provider_->hap_connect_only_requested_device(false);
  const RawAddress test_address = GetTestAddress(1);
  /* Minimal possible HA device (only feature flags) */
  SetSampleDatabaseHasNoPresetChange(test_address,
                                     bluetooth::has::kFeatureBitHearingAidTypeBinaural);

  EXPECT_CALL(*callbacks, OnConnectionState(ConnectionState::CONNECTED, test_address)).Times(1);
  TestConnect(test_address);

  EXPECT_CALL(*callbacks, OnConnectionState(ConnectionState::DISCONNECTED, test_address)).Times(1);
  EXPECT_CALL(gatt_queue, Clean(1)).Times(1);
  TestDisconnect(test_address, 1);
}

TEST_F(HasClientTest, test_disconnect_connected) {
  com::android::bluetooth::flags::provider_->hap_connect_only_requested_device(true);
  const RawAddress test_address = GetTestAddress(1);
  /* Minimal possible HA device (only feature flags) */
  SetSampleDatabaseHasNoPresetChange(test_address,