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

Commit a92788cb authored by Jakub Tyszkowski's avatar Jakub Tyszkowski
Browse files

VolumeControl: Fix not notifying about disconnection

When the device was not connecting actively, we did not send the
disconnection event and the upper layer stayed connected even after
the peer device was not.

Bug: 282778469
Test: atest --host VolumeControlTest --no-bazel-mode
Change-Id: Ib3a6407869bd25358714105fd26d60f9083b4541
parent ea9abca0
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -683,7 +683,8 @@ class VolumeControlImpl : public VolumeControl {
      return;
    }

    device_cleanup_helper(device, device->connecting_actively);
    bool notify = device->IsReady() || device->connecting_actively;
    device_cleanup_helper(device, notify);

    if (reason != GATT_CONN_TERMINATE_LOCAL_HOST &&
        device->connecting_actively) {
+44 −0
Original line number Diff line number Diff line
@@ -615,6 +615,50 @@ TEST_F(VolumeControlTest, test_reconnect_after_interrupted_discovery) {
  TestAppUnregister();
}

TEST_F(VolumeControlTest, test_reconnect_after_timeout) {
  const RawAddress address = GetTestAddress(0);

  // Initial connection
  SetSampleDatabaseVOCS(1);
  TestAppRegister();

  EXPECT_CALL(*callbacks,
              OnConnectionState(ConnectionState::CONNECTED, address))
      .Times(0);
  TestConnect(address);

  // 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);
  TestDisconnect(address, 0);

  // Above the device was not connected and we got Disconnect request from the
  // upper layer - it means it has timed-out but still wants to connect, thus
  // native is still doing background or opportunistic connect. Let the remote
  // device reconnect now.
  ON_CALL(gatt_interface, ServiceSearchRequest(_, _))
      .WillByDefault(Invoke(
          [&](uint16_t conn_id, const bluetooth::Uuid* p_srvc_uuid) -> void {
            if (*p_srvc_uuid == kVolumeControlUuid)
              GetSearchCompleteEvent(conn_id);
          }));
  EXPECT_CALL(*callbacks,
              OnConnectionState(ConnectionState::CONNECTED, address));
  EXPECT_CALL(*callbacks, OnDeviceAvailable(address, 2));
  GetConnectedEvent(address, 1);
  Mock::VerifyAndClearExpectations(callbacks.get());

  // Make sure that the upper layer gets the disconnection event even if not
  // connecting actively anymore due to the mentioned time-out mechanism.
  EXPECT_CALL(*callbacks,
              OnConnectionState(ConnectionState::DISCONNECTED, address));
  GetDisconnectedEvent(address, 1);
  Mock::VerifyAndClearExpectations(callbacks.get());
  TestAppUnregister();
}

TEST_F(VolumeControlTest, test_add_from_storage) {
  TestAppRegister();
  TestAddFromStorage(GetTestAddress(0));