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

Commit 01f987d1 authored by Henri Chataing's avatar Henri Chataing
Browse files

a2dp: Expose all supported codecs through BluetoothA2dp#getSupportedCodecTypes

this change adds the offloaded codec to the list of returned codecs;
previously the list was populated only with know codecs (SBC, AAC, AptX..)

Bug: 308686081
Bug: 305734815
Test: atest BluetoothA2dpTest#getSupportedCodecTypes
Test: m com.android.btservices
Change-Id: Iaab0a01964e1c5892a24e8abda07f7caf2dcc13a
parent 9d342132
Loading
Loading
Loading
Loading
+16 −18
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ static struct {
} android_bluetooth_BluetoothCodecConfig;

static const btav_source_interface_t* sBluetoothA2dpInterface = nullptr;
static std::vector<btav_a2dp_codec_info_t> supported_codecs;
static std::shared_timed_mutex interface_mutex;

static jobject mCallbacksObj = nullptr;
@@ -296,7 +297,7 @@ static void initNative(JNIEnv* env, jobject object,

  bt_status_t status = sBluetoothA2dpInterface->init(
      &sBluetoothA2dpCallbacks, maxConnectedAudioDevices, codec_priorities,
      codec_offloading);
      codec_offloading, &supported_codecs);
  if (status != BT_STATUS_SUCCESS) {
    ALOGE("%s: Failed to initialize Bluetooth A2DP, status: %d", __func__,
          status);
@@ -340,34 +341,31 @@ static jobjectArray getSupportedCodecTypesNative(JNIEnv* env) {
    return nullptr;
  }

  jmethodID createFromType = env->GetStaticMethodID(
      android_bluetooth_BluetoothCodecType_clazz, "createFromType",
      "(I)Landroid/bluetooth/BluetoothCodecType;");
  if (createFromType == nullptr) {
    ALOGE(
        "%s: Failed to find method createFromType of BluetoothCodecType class",
  jmethodID init = env->GetMethodID(android_bluetooth_BluetoothCodecType_clazz,
                                    "<init>", "(IJLjava/lang/String;)V");

  if (init == nullptr) {
    ALOGE("%s: Failed to find method <init> of BluetoothCodecType class",
          __func__);
    return nullptr;
  }

  std::array<btav_a2dp_codec_index_t, 6> default_supported_codecs = {
      BTAV_A2DP_CODEC_INDEX_SOURCE_SBC,  BTAV_A2DP_CODEC_INDEX_SOURCE_AAC,
      BTAV_A2DP_CODEC_INDEX_SOURCE_APTX, BTAV_A2DP_CODEC_INDEX_SOURCE_APTX_HD,
      BTAV_A2DP_CODEC_INDEX_SOURCE_LDAC, BTAV_A2DP_CODEC_INDEX_SOURCE_OPUS,
  };
  jobjectArray result =
      env->NewObjectArray(default_supported_codecs.size(),
      env->NewObjectArray(supported_codecs.size(),
                          android_bluetooth_BluetoothCodecType_clazz, nullptr);

  if (result == nullptr) {
    ALOGE("%s: Failed to allocate result array of BluetoothCodecType",
          __func__);
    return nullptr;
  }

  for (size_t index = 0; index < default_supported_codecs.size(); index++) {
    jobject codec_type = env->CallStaticObjectMethod(
        android_bluetooth_BluetoothCodecType_clazz, createFromType,
        (jint)default_supported_codecs[index]);
  for (size_t index = 0; index < supported_codecs.size(); index++) {
    jobject codec_type = env->NewObject(
        android_bluetooth_BluetoothCodecType_clazz, init,
        (jint)supported_codecs[index].codec_type,
        (jlong)supported_codecs[index].codec_id,
        env->NewStringUTF(supported_codecs[index].codec_name.c_str()));
    env->SetObjectArrayElement(result, index, codec_type);
  }

+4 −4
Original line number Diff line number Diff line
@@ -199,12 +199,12 @@ bool supports_codec(btav_a2dp_codec_index_t codec_index) {
}

// Return the A2DP capabilities for the selected codec.
bool codec_info(btav_a2dp_codec_index_t codec_index, uint8_t* codec_info,
                btav_a2dp_codec_config_t* codec_config) {
bool codec_info(btav_a2dp_codec_index_t codec_index, uint64_t* codec_id,
                uint8_t* codec_info, btav_a2dp_codec_config_t* codec_config) {
  return (HalVersionManager::GetHalTransport() ==
          BluetoothAudioHalTransport::AIDL)
             ? aidl::a2dp::provider::codec_info(codec_index, codec_info,
                                                codec_config)
             ? aidl::a2dp::provider::codec_info(codec_index, codec_id,
                                                codec_info, codec_config)
             : false;
}

+2 −2
Original line number Diff line number Diff line
@@ -92,8 +92,8 @@ bool supports_codec(btav_a2dp_codec_index_t codec_index);
// Return the A2DP capabilities for the selected codec.
// `codec_info` returns the OTA codec capabilities, `codec_config`
// returns the supported capabilities in a generic format.
bool codec_info(btav_a2dp_codec_index_t codec_index, uint8_t* codec_info,
                btav_a2dp_codec_config_t* codec_config);
bool codec_info(btav_a2dp_codec_index_t codec_index, uint64_t* codec_id,
                uint8_t* codec_info, btav_a2dp_codec_config_t* codec_config);

struct a2dp_configuration {
  int remote_seid;
+2 −2
Original line number Diff line number Diff line
@@ -311,8 +311,8 @@ std::optional<const char*> codec_index_str(
bool supports_codec(btav_a2dp_codec_index_t codec_index) { return false; }

// Return the A2DP capabilities for the selected codec.
bool codec_info(btav_a2dp_codec_index_t codec_index, uint8_t* codec_info,
                btav_a2dp_codec_config_t* codec_config) {
bool codec_info(btav_a2dp_codec_index_t codec_index, uint64_t* codec_id,
                uint8_t* codec_info, btav_a2dp_codec_config_t* codec_config) {
  return false;
}

+2 −2
Original line number Diff line number Diff line
@@ -732,10 +732,10 @@ bool provider::supports_codec(btav_a2dp_codec_index_t codec_index) {
 * Return the A2DP capabilities for the selected codec.
 ***/
bool provider::codec_info(btav_a2dp_codec_index_t codec_index,
                          uint8_t* codec_info,
                          uint64_t* codec_id, uint8_t* codec_info,
                          btav_a2dp_codec_config_t* codec_config) {
  return provider_info ? provider_info->CodecCapabilities(
                             codec_index, codec_info, codec_config)
                             codec_index, codec_id, codec_info, codec_config)
                       : false;
}

Loading