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

Commit 3893896c authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

leaudio: Improve removing autoconnect from the LeAudio set

If e.g. one of the earbud is in the box and is in autoconnect mode, and
user disconnectes the other device, which clears autoconnect flag on
that device, stack shall also remove from autoconnect the other set
members.

Bug: 263069663
Test: atest BluetoothInstrumentationTests
Test: connect to 2 earbuds, put one into box, disconnect the other
Tag: #feature

Merged-In: Ibec9c9d1c3938c029a672db6135dc277ec5b59c5
Change-Id: Ibec9c9d1c3938c029a672db6135dc277ec5b59c5
(cherry picked from commit afb96f8b)
parent 2322ebd8
Loading
Loading
Loading
Loading
+24 −3
Original line number Diff line number Diff line
@@ -1282,12 +1282,33 @@ class LeAudioClientImpl : public LeAudioClient {
    BTA_GATTC_CancelOpen(0, address, false);

    if (leAudioDevice->conn_id_ != GATT_INVALID_CONN_ID) {
      /* User is disconnecting the device, we shall remove the autoconnect flag
      /* User is disconnecting the device, we shall remove the autoconnect
       * flag for this device and all others
       */
      LOG_INFO("Removing autoconnect flag for group_id %d",
               leAudioDevice->group_id_);

      auto group = aseGroups_.FindById(leAudioDevice->group_id_);

      if (leAudioDevice->autoconnect_flag_) {
        btif_storage_set_leaudio_autoconnect(address, false);
        leAudioDevice->autoconnect_flag_ = false;
      }

      if (group) {
        /* Remove devices from auto connect mode */
        for (auto dev = group->GetFirstDevice(); dev;
             dev = group->GetNextDevice(dev)) {
          if (dev->GetConnectionState() ==
              DeviceConnectState::CONNECTING_AUTOCONNECT) {
            btif_storage_set_leaudio_autoconnect(address, false);
            dev->autoconnect_flag_ = false;
            BTA_GATTC_CancelOpen(gatt_if_, address, false);
            dev->SetConnectionState(DeviceConnectState::DISCONNECTED);
          }
        }
      }

      auto group = aseGroups_.FindById(leAudioDevice->group_id_);
      if (group &&
          group->GetState() ==
              le_audio::types::AseState::BTA_LE_AUDIO_ASE_STATE_STREAMING) {