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

Commit 24056c0e authored by Yuyang Huang's avatar Yuyang Huang
Browse files

add usage of HFP StartSession and StopSession

Bug: 294134504
Bug: 315234036
Test: m .
Change-Id: I4dca7382716d1d1a15fc27c8ddfb00c843cc405a
parent 0af94ba1
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
 *
 ******************************************************************************/

#include <android_bluetooth_flags.h>
#include <base/logging.h>

#include <string>
@@ -458,6 +459,11 @@ void bta_ag_api_disable() {
    }
  }

  if (IS_FLAG_ENABLED(is_sco_managed_by_audio)) {
    // Stop session if not done
    bta_clear_active_device();
  }

  if (!do_dereg) {
    /* Done, send callback evt to app */
    (*bta_ag_cb.p_cback)(BTA_AG_DISABLE_EVT, nullptr);
+34 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@

#include <cstdint>

#include "audio_hal_interface/hfp_client_interface.h"
#include "bta/ag/bta_ag_int.h"
#include "bta_ag_swb_aptx.h"
#include "common/init_flags.h"
@@ -45,6 +46,8 @@

extern tBTM_CB btm_cb;

using HfpInterface = bluetooth::audio::hfp::HfpClientInterface;

/* Codec negotiation timeout */
#ifndef BTA_AG_CODEC_NEGOTIATION_TIMEOUT_MS
#define BTA_AG_CODEC_NEGOTIATION_TIMEOUT_MS (3 * 1000) /* 3 seconds */
@@ -60,6 +63,8 @@ extern tBTM_CB btm_cb;

static bool sco_allowed = true;
static RawAddress active_device_addr = {};
static std::unique_ptr<HfpInterface> hfp_client_interface;
static std::unique_ptr<HfpInterface::Offload> hfp_offload_interface;

/* sco events */
enum {
@@ -1554,6 +1559,11 @@ const RawAddress& bta_ag_get_active_device() { return active_device_addr; }

void bta_clear_active_device() {
  LOG_DEBUG("Set bta active device to null");
  if (IS_FLAG_ENABLED(is_sco_managed_by_audio)) {
    if (hfp_offload_interface && !active_device_addr.IsEmpty()) {
      hfp_offload_interface->StopSession();
    }
  }
  active_device_addr = RawAddress::kEmpty;
}

@@ -1562,5 +1572,29 @@ void bta_ag_api_set_active_device(const RawAddress& new_active_device) {
    LOG_ERROR("%s: empty device", __func__);
    return;
  }

  if (IS_FLAG_ENABLED(is_sco_managed_by_audio)) {
    if (!hfp_client_interface) {
      hfp_client_interface = std::unique_ptr<HfpInterface>(HfpInterface::Get());
      if (!hfp_client_interface) {
        LOG_ERROR("could not acquire audio source interface");
        return;
      }
    }

    if (!hfp_offload_interface) {
      hfp_offload_interface = std::unique_ptr<HfpInterface::Offload>(
          hfp_client_interface->GetOffload(get_main_thread()));
      if (!hfp_offload_interface) {
        LOG_WARN("could not get offload interface");
      } else {
        // start audio session if there was no previous active device
        // if there was an active device, java layer would call disconnectAudio
        if (active_device_addr.IsEmpty()) {
          hfp_offload_interface->StartSession();
        }
      }
    }
  }
  active_device_addr = new_active_device;
}