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

Commit 98aefcbc authored by Sandeep Samdaria's avatar Sandeep Samdaria
Browse files

SetActivePeer should only update the active peer

Problem: While creating a peer, FindOrCreatePeer assigns the
active peer if there is no active peer device assigned. As a
result SetActivePeer results in a no-op.

Solution: FindOrCreatePeer should not assign the active peer
until the device is connected. Once AVDTP connection is connected,
then only the active peer should be updated.

Test: m seahawk-userdebug.
Test: atest bluetooth_test_gd_unit
Bug: 305110114
Change-Id: I53b22aa7dcad65be9ecb6ad45fe5df88bf4739a6
parent a0316f9e
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -725,6 +725,8 @@ class BtifAvSink {
      // cannot set promise but need to be handled within restart_session
      return false;
    }
    LOG(INFO) << "Setting the active peer to peer address %s"
              << ADDRESS_TO_LOGGABLE_STR(peer_address);
    active_peer_ = peer_address;
    return true;
  }
@@ -1508,9 +1510,6 @@ BtifAvPeer* BtifAvSink::FindOrCreatePeer(const RawAddress& peer_address,
  peer = new BtifAvPeer(peer_address, AVDT_TSEP_SRC, bta_handle, peer_id);
  peers_.insert(std::make_pair(peer_address, peer));
  peer->Init();
  if (active_peer_.IsEmpty()) {
    active_peer_ = peer_address;
  }
  return peer;
}

@@ -3591,11 +3590,12 @@ static void set_active_peer_int(uint8_t peer_sep,
  if (peer_sep == AVDT_TSEP_SRC) {
    if (!btif_av_src_sink_coexist_enabled() || (btif_av_src_sink_coexist_enabled() &&
      btif_av_both_enable() && (btif_av_source.FindPeer(peer_address) == nullptr))) {
      btif_av_sink.SetActivePeer(peer_address,
                                    std::move(peer_ready_promise));
      if (!btif_av_sink.SetActivePeer(peer_address,
                                      std::move(peer_ready_promise))) {
        BTIF_TRACE_ERROR("%s: Error setting %s as active Source peer", __func__,
                         ADDRESS_TO_LOGGABLE_CSTR(peer_address));
      }
    }
    return;
  }
  // If reached here, we could not set the active peer