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

Commit 779b8f87 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

leaudio: Fix getting first device.

In case weak pointer is expired, we should check if there is another
valid one

Sponsor: jpawlowski@
Bug: 150670922
Test: atest --host bluetooth_le_audio_test
bluetooth_le_audio_client_test

Change-Id: Iec45914a56d53f1b08742d027e8b1f0d4a3b0d0a
parent 0d33ffe0
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -108,10 +108,12 @@ void LeAudioDeviceGroup::Deactivate(void) {
}

LeAudioDevice* LeAudioDeviceGroup::GetFirstDevice(void) {
  auto d = leAudioDevices_.front();
  if (d.expired()) return nullptr;
  auto iter = std::find_if(leAudioDevices_.begin(), leAudioDevices_.end(),
                           [](auto& iter) { return !iter.expired(); });

  if (iter == leAudioDevices_.end()) return nullptr;

  return (d.lock()).get();
  return (iter->lock()).get();
}

LeAudioDevice* LeAudioDeviceGroup::GetFirstDeviceWithActiveContext(