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

Commit 4d5d871a authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

LE Audio: Return SDP services if GATT discovery on LE transport fails

Right now, if GATT discovery fails, we would prevent any services from
being connected in Settings on dual mode device.

After this patch, if LE GATT discovery fails, we will fall back to
SDP only services, which should keep the audio devices usable.

Bug: 278804760
Test: pair with LE Audio capable device that would fail to establish LE
connection, or time out during GATT service discovery

Change-Id: I734f792cb841d44e04748fd421fbfe458bb4ff41
parent fe1322e6
Loading
Loading
Loading
Loading
+46 −10
Original line number Original line Diff line number Diff line
@@ -756,6 +756,28 @@ bool is_device_le_audio_capable(const RawAddress bd_addr) {
  return false;
  return false;
}
}


/* use to check if device is LE Audio Capable during bonding */
bool is_le_audio_capable_during_service_discovery(const RawAddress& bd_addr) {
  if (!GetInterfaceToProfiles()
           ->profileSpecific_HACK->IsLeAudioClientRunning()) {
    /* If LE Audio profile is not enabled, do nothing. */
    return false;
  }

  if (bd_addr != pairing_cb.bd_addr && bd_addr != pairing_cb.static_bdaddr) {
    return false;
  }

  if (check_cod_le_audio(bd_addr) ||
      metadata_cb.le_audio_cache.contains(bd_addr) ||
      metadata_cb.le_audio_cache.contains(pairing_cb.bd_addr) ||
      BTA_DmCheckLeAudioCapable(bd_addr)) {
    return true;
  }

  return false;
}

/*******************************************************************************
/*******************************************************************************
 *
 *
 * Function         btif_dm_cb_create_bond
 * Function         btif_dm_cb_create_bond
@@ -1718,17 +1740,10 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
       * capable of a2dp, and both sides can do LE Audio, and it haven't
       * capable of a2dp, and both sides can do LE Audio, and it haven't
       * finished GATT over LE yet, then wait for LE service discovery to finish
       * finished GATT over LE yet, then wait for LE service discovery to finish
       * before before passing services to upper layers. */
       * before before passing services to upper layers. */
      if ((bd_addr == pairing_cb.bd_addr ||
      if (a2dp_sink_capable &&
           bd_addr == pairing_cb.static_bdaddr) &&
          a2dp_sink_capable &&
          GetInterfaceToProfiles()
              ->profileSpecific_HACK->IsLeAudioClientRunning() &&
          pairing_cb.gatt_over_le !=
          pairing_cb.gatt_over_le !=
              btif_dm_pairing_cb_t::ServiceDiscoveryState::FINISHED &&
              btif_dm_pairing_cb_t::ServiceDiscoveryState::FINISHED &&
          (check_cod_le_audio(bd_addr) ||
          is_le_audio_capable_during_service_discovery(bd_addr)) {
           metadata_cb.le_audio_cache.contains(bd_addr) ||
           metadata_cb.le_audio_cache.contains(pairing_cb.bd_addr) ||
           BTA_DmCheckLeAudioCapable(bd_addr))) {
        skip_reporting_wait_for_le = true;
        skip_reporting_wait_for_le = true;
      }
      }


@@ -1871,8 +1886,29 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,


      if (uuids.empty()) {
      if (uuids.empty()) {
        LOG_INFO("No well known GATT services discovered");
        LOG_INFO("No well known GATT services discovered");

        /* If services were returned as part of SDP discovery, we will
         * immediately send them with rest of SDP results in BTA_DM_DISC_RES_EVT
         */
        if (event == BTA_DM_GATT_OVER_SDP_RES_EVT) {
          return;
        }

        if (is_le_audio_capable_during_service_discovery(bd_addr)) {
          if (bluetooth::common::init_flags::
                  sdp_return_classic_services_when_le_discovery_fails_is_enabled()) {
            LOG_INFO(
                "Will return Classic SDP results, if done, to unblock bonding");
          } else {
            // LEA device w/o this flag
            // TODO: we might want to remove bond or do some action on
            // half-discovered device
            return;
            return;
          }
          }
        } else {
          return;
        }
      }


      Uuid existing_uuids[BT_MAX_NUM_UUIDS] = {};
      Uuid existing_uuids[BT_MAX_NUM_UUIDS] = {};
      bt_status_t existing_lookup_result =
      bt_status_t existing_lookup_result =
+1 −0
Original line number Original line Diff line number Diff line
@@ -401,6 +401,7 @@ init_flags!(
        subrating = true,
        subrating = true,
        trigger_advertising_callbacks_on_first_resume_after_pause = true,
        trigger_advertising_callbacks_on_first_resume_after_pause = true,
        use_unified_connection_manager,
        use_unified_connection_manager,
        sdp_return_classic_services_when_le_discovery_fails = true,
    }
    }
    // dynamic flags can be updated at runtime and should be accessed directly
    // dynamic flags can be updated at runtime and should be accessed directly
    // to check.
    // to check.
+1 −0
Original line number Original line Diff line number Diff line
@@ -55,6 +55,7 @@ mod ffi {
        fn subrating_is_enabled() -> bool;
        fn subrating_is_enabled() -> bool;
        fn trigger_advertising_callbacks_on_first_resume_after_pause_is_enabled() -> bool;
        fn trigger_advertising_callbacks_on_first_resume_after_pause_is_enabled() -> bool;
        fn use_unified_connection_manager_is_enabled() -> bool;
        fn use_unified_connection_manager_is_enabled() -> bool;
        fn sdp_return_classic_services_when_le_discovery_fails_is_enabled() -> bool;
    }
    }
}
}