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

Commit ab85bb12 authored by Yuyang Huang's avatar Yuyang Huang
Browse files

start HFP offload session when active device becomes not null

Previously, offload session only started when it is null. This causes issue when offload session is not null, but session is stopped. Then, it won't start session again

Bug: 348671524
Bug: 315234036
Flag: com::android::bluetooth::flags::is_sco_managed_by_audio
Test: atest net_test_bta
Change-Id: I8f3cc8d941bab0b0d917e9b1257d7e0aedded855
parent e010dcab
Loading
Loading
Loading
Loading
+13 −10
Original line number Diff line number Diff line
@@ -1615,7 +1615,8 @@ void bta_ag_stream_suspended() {
const RawAddress& bta_ag_get_active_device() { return active_device_addr; }

void bta_clear_active_device() {
  log::debug("Set bta active device to null");
  log::debug("Set bta active device to null, current active device:{}",
             active_device_addr);
  if (bta_ag_is_sco_managed_by_audio()) {
    if (hfp_offload_interface && !active_device_addr.IsEmpty()) {
      hfp_offload_interface->StopSession();
@@ -1625,6 +1626,8 @@ void bta_clear_active_device() {
}

void bta_ag_api_set_active_device(const RawAddress& new_active_device) {
  log::info("active_device_addr{}, new_active_device:{}", active_device_addr,
            new_active_device);
  if (new_active_device.IsEmpty()) {
    log::error("empty device");
    return;
@@ -1635,24 +1638,24 @@ void bta_ag_api_set_active_device(const RawAddress& new_active_device) {
      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) {
    if (hfp_client_interface && !hfp_offload_interface) {
      hfp_offload_interface = std::unique_ptr<HfpInterface::Offload>(
          hfp_client_interface->GetOffload(get_main_thread()));
      sco_config_map = hfp_offload_interface->GetHfpScoConfig();
      if (!hfp_offload_interface) {
        log::warn("could not get offload interface");
      } else {
      }
    }

    if (hfp_offload_interface) {
      sco_config_map = hfp_offload_interface->GetHfpScoConfig();
      // 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;
}