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

Commit b6523f3a authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

leaudio: Fix for removing data path

This patch fixes this.

< HCI Command: LE Remove Isochro.. (0x08|0x006f) plen 3  #27653 10:42:28.301675
        Connection Handle: 96
        Data Path Direction: 0x03
          Input (Host to Controller)
          Output (Controller to Host)
> HCI Event: Command Complete (0x0e) plen 6              #27654 10:42:28.302108
      LE Remove Isochronous Data Path (0x08|0x006f) ncmd 1
        Status: Command Disallowed (0x0c)
        Connection handle: 96

It could happen after switching from Music -> Phonecall -> Music -> Phonecall.
Android incorrectly tries to clear two directions but only one was set.
This could result in no properly released stream.

Also this patch handle Command Disallowed for the data path operation.
Since Data Path is removed on CIS disconnection, Android ignores the
error code and continues with dropping stream.

Bug: 233962131
Test: manual Music->Phonecall->Music->Phonecall
Test: atest BluetoothInstrumentationTests
Tag: #feature
Change-Id: I8486c15472ff886fa3e9156bbf2ad80b67251875
parent ae347b2e
Loading
Loading
Loading
Loading
+17 −13
Original line number Diff line number Diff line
@@ -487,11 +487,11 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
                                        uint8_t status,
                                        uint16_t conn_hdl) override {
    if (status != HCI_SUCCESS) {
      LOG(ERROR) << __func__ << ", failed to remove ISO data path, reason: "
                 << loghex(status);
      StopStream(group);

      return;
      LOG_ERROR(
          "failed to remove ISO data path, reason: 0x%0x - contining stream "
          "closing",
          status);
      /* Just continue - disconnecting CIS removes data path as well.*/
    }

    bool do_disconnect = false;
@@ -740,14 +740,18 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
  static void RemoveDataPathByCisHandle(LeAudioDevice* leAudioDevice,
                                        uint16_t cis_conn_hdl) {
    auto ases_pair = leAudioDevice->GetAsesByCisConnHdl(cis_conn_hdl);
    IsoManager::GetInstance()->RemoveIsoDataPath(
        cis_conn_hdl,
        (ases_pair.sink
             ? bluetooth::hci::iso_manager::kRemoveIsoDataPathDirectionInput
             : 0x00) |
            (ases_pair.source ? bluetooth::hci::iso_manager::
                                    kRemoveIsoDataPathDirectionOutput
                              : 0x00));
    uint8_t value = 0;

    if (ases_pair.sink && ases_pair.sink->data_path_state ==
                              AudioStreamDataPathState::CIS_ESTABLISHED) {
      value |= bluetooth::hci::iso_manager::kRemoveIsoDataPathDirectionInput;
    }

    if (ases_pair.source && ases_pair.source->data_path_state ==
                              AudioStreamDataPathState::CIS_ESTABLISHED) {
      value |= bluetooth::hci::iso_manager::kRemoveIsoDataPathDirectionOutput;
    }
    IsoManager::GetInstance()->RemoveIsoDataPath(cis_conn_hdl, value);
  }

  void ProcessHciNotifCisDisconnected(