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

Commit 4d281478 authored by Jakub Tyszkowski's avatar Jakub Tyszkowski
Browse files

VolumeControl: Fix canceling opportunistic connect

Opportunistic connect is considered a direct connect therefor
it needs to be canceled by direct connect cancel.

Bug: 373377157
Test: atest bluetooth_vc_test
Flag: EXEMPT; Bug fix covered with unit test
Change-Id: Ifb4de1a9571ba6b22a8ea915a903c6a0293015cb
parent a411fa9a
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -99,10 +99,12 @@ public:

    stream << "    volume: " << +volume << "\n"
           << "    mute: " << +mute << "\n"
           << "    change_counter: " << +change_counter << "\n"
           << "    flags: " << +flags << "\n"
           << "    device read: " << device_ready << "\n"
           << "    device ready: " << device_ready << "\n"
           << "    connecting_actively: " << connecting_actively << "\n"
           << "    change_counter: " << +change_counter << "\n";
           << "    is encrypted: " << IsEncryptionEnabled() << "\n"
           << "    GATT operations pending: " << handles_pending.size() << "\n";

    dprintf(fd, "%s", stream.str().c_str());
    audio_offsets.Dump(fd);
+4 −6
Original line number Diff line number Diff line
@@ -195,7 +195,7 @@ public:
    /* Make sure to remove device from background connect.
     * It will be added back if needed, when device got disconnected
     */
    BTA_GATTC_CancelOpen(gatt_if_, address, false);
    BTA_GATTC_CancelOpen(gatt_if_, address, true);

    if (device->IsEncryptionEnabled()) {
      OnEncryptionComplete(address, tBTM_STATUS::BTM_SUCCESS);
@@ -810,14 +810,14 @@ public:
    bluetooth::log::info("{}", address);

    /* Removes all registrations for connection. */
    BTA_GATTC_CancelOpen(gatt_if_, address, false);
    BTA_GATTC_CancelOpen(gatt_if_, address, true);

    Disconnect(address);
    volume_control_devices_.Remove(address);
  }

  void OnGattDisconnected(tCONN_ID connection_id, tGATT_IF /*client_if*/, RawAddress remote_bda,
                          tGATT_DISCONN_REASON reason) {
                          tGATT_DISCONN_REASON /*reason*/) {
    VolumeControlDevice* device = volume_control_devices_.FindByConnId(connection_id);
    if (!device) {
      bluetooth::log::error("Skipping unknown device disconnect, connection_id={:#x}",
@@ -838,10 +838,8 @@ public:
    bool notify = device->IsReady() || device->connecting_actively;
    device_cleanup_helper(device, notify);

    if (reason != GATT_CONN_TERMINATE_LOCAL_HOST && device->connecting_actively) {
    StartOpportunisticConnect(remote_bda);
  }
  }

  void RemoveDeviceFromOperationList(const RawAddress& addr) {
    if (ongoing_operations_.empty()) {
+3 −2
Original line number Diff line number Diff line
@@ -572,7 +572,7 @@ protected:
  }

  void TestRemove(const RawAddress& address, uint16_t conn_id) {
    EXPECT_CALL(gatt_interface, CancelOpen(gatt_if, address, false));
    EXPECT_CALL(gatt_interface, CancelOpen(gatt_if, address, true));
    if (conn_id) {
      EXPECT_CALL(gatt_interface, Close(conn_id));
    } else {
@@ -899,7 +899,7 @@ TEST_F(VolumeControlTest, test_reconnect_after_timeout) {
  // Disconnect not connected device - upper layer times out and needs a
  // disconnection event to leave the transient Connecting state
  EXPECT_CALL(callbacks, OnConnectionState(ConnectionState::DISCONNECTED, address));
  EXPECT_CALL(gatt_interface, CancelOpen(gatt_if, address, false)).Times(0);
  EXPECT_CALL(gatt_interface, CancelOpen(gatt_if, address, _)).Times(0);
  TestDisconnect(address, 0);

  // Above the device was not connected and we got Disconnect request from the
@@ -984,6 +984,7 @@ TEST_F(VolumeControlTest, test_disconnected_while_autoconnect) {
  TestAppRegister();
  TestAddFromStorage(test_address);
  GetConnectedEvent(test_address, 1);
  Mock::VerifyAndClearExpectations(&gatt_interface);
  // autoconnect - don't indicate disconnection
  EXPECT_CALL(callbacks, OnConnectionState(ConnectionState::DISCONNECTED, test_address)).Times(0);
  GetDisconnectedEvent(test_address, 1);