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

Commit b1f2f5d9 authored by Cheney Ni's avatar Cheney Ni
Browse files

A2DP: don't apply codec preference if service disabled

Because the codec preference is saved at upper-layer, it was timing that
JNI callbacks were reset by BT turning off while querying the
preference. In order to prevent NPE, this CL checks whether A2DP is
still enabled, and uses a JNI variable to store those callbacks.

Tag: #stability
Fixes: 182756107
Test: atest net_test_btif
Change-Id: Iacfb9fee0e69a47ca7c7ed7c5fc8b4782b647f84
parent 7898ae38
Loading
Loading
Loading
Loading
+16 −12
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@
#include <vector>

#include "audio_hal_interface/a2dp_encoding.h"
#include "audio_hal_interface/hearing_aid_software_encoding.h"
#include "bta/av/bta_av_int.h"
#include "btif/include/btif_a2dp.h"
#include "btif/include/btif_a2dp_control.h"
@@ -2457,8 +2456,16 @@ static void btif_av_report_sink_audio_config_state(
static void btif_av_query_mandatory_codec_priority(
    const RawAddress& peer_address) {
  auto query_priority = [](const RawAddress& peer_address) {
    if (!btif_av_source.Enabled()) {
      LOG_WARN("BTIF AV Source is not enabled");
      return;
    }
    btav_source_callbacks_t* callbacks = btif_av_source.Callbacks();
    bool preferred = callbacks != nullptr &&
                     callbacks->mandatory_codec_preferred_cb(peer_address);
    if (preferred) {
      auto apply_priority = [](const RawAddress& peer_address, bool preferred) {
      BtifAvPeer* peer = btif_av_source_find_peer(peer_address);
        BtifAvPeer* peer = btif_av_find_peer(peer_address);
        if (peer == nullptr) {
          BTIF_TRACE_WARNING(
              "btif_av_query_mandatory_codec_priority: peer is null");
@@ -2466,9 +2473,6 @@ static void btif_av_query_mandatory_codec_priority(
        }
        peer->SetMandatoryCodecPreferred(preferred);
      };
    bool preferred =
        btif_av_source.Callbacks()->mandatory_codec_preferred_cb(peer_address);
    if (preferred) {
      do_in_main_thread(
          FROM_HERE, base::BindOnce(apply_priority, peer_address, preferred));
    }