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

Commit 610fcc15 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

Leaudio: Fix one earbud no playing when both connected at once

Issue could happen when two devices where connected and attach to the
stream just after enabling Bluetooth. What is happening is that first
connected device start its way to Streaming state but it is not there.
In this time if second device connects, it tries to attach to the stream
but it is not allowed because group is not yet in streaming state.
In such a case we should wait a bit.

Bug: 240892829
Bug: 231084798
Test: atest BluetoothInstrumentationTests
Tag: #feature

Change-Id: I93f5ea912450cf18ad3d419e48c29a7f1acbea16
parent 21e10507
Loading
Loading
Loading
Loading
+30 −1
Original line number Diff line number Diff line
@@ -1999,7 +1999,35 @@ class LeAudioClientImpl : public LeAudioClient {
      return;
    }

    groupStateMachine_->AttachToStream(group, leAudioDevice);
    if (!groupStateMachine_->AttachToStream(group, leAudioDevice)) {
      LOG_WARN("Could not add device %s to the group %d streaming. ",
               leAudioDevice->address_.ToString().c_str(), group->group_id_);
      scheduleAttachDeviceToTheStream(leAudioDevice->address_);
    }
  }

  void restartAttachToTheStream(const RawAddress& addr) {
    LeAudioDevice* leAudioDevice = leAudioDevices_.FindByAddress(addr);
    if (leAudioDevice == nullptr ||
        leAudioDevice->conn_id_ == GATT_INVALID_CONN_ID) {
      LOG_INFO("Device %s not available anymore", addr.ToString().c_str());
      return;
    }
    AttachToStreamingGroupIfNeeded(leAudioDevice);
  }

  void scheduleAttachDeviceToTheStream(const RawAddress& addr) {
    LOG_INFO("Device %s scheduler for stream ", addr.ToString().c_str());
    do_in_main_thread_delayed(
        FROM_HERE,
        base::BindOnce(&LeAudioClientImpl::restartAttachToTheStream,
                       base::Unretained(this), addr),
#if BASE_VER < 931007
        base::TimeDelta::FromMilliseconds(kDeviceAttachDelayMs)
#else
        base::Milliseconds(kDeviceAttachDelayMs)
#endif
    );
  }

  void connectionReady(LeAudioDevice* leAudioDevice) {
@@ -3629,6 +3657,7 @@ class LeAudioClientImpl : public LeAudioClient {
  static constexpr char kAudioSuspentKeepIsoAliveTimeoutMsProp[] =
      "persist.bluetooth.leaudio.audio.suspend.timeoutms";
  alarm_t* suspend_timeout_;
  static constexpr uint64_t kDeviceAttachDelayMs = 500;

  std::vector<int16_t> cached_channel_data_;
  uint32_t cached_channel_timestamp_ = 0;
+7 −0
Original line number Diff line number Diff line
@@ -95,6 +95,13 @@ bt_status_t do_in_main_thread(const base::Location& from_here,
  return BT_STATUS_SUCCESS;
}

bt_status_t do_in_main_thread_delayed(const base::Location& from_here,
                                      base::OnceClosure task,
                                      const base::TimeDelta& delay) {
  /* For testing purpose it is ok to just skip delay */
  return do_in_main_thread(from_here, std::move(task));
}

static base::MessageLoop* message_loop_;
base::MessageLoop* get_main_message_loop() { return message_loop_; }