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

Commit 283a99ff authored by William Escande's avatar William Escande
Browse files

Load external library in the default namespace

Aptx and aptx-Hd are both loaded from system_ext.
In order to load their dependencies from a compatible environement we
need to set the lib as a requirredLibs in the manifest

Fix: 231967310
Test: atest net_test_stack_a2dp_native
Test: Log analyze after bluetooth boot
Tag: #refactor
Ignore-AOSP-First: Apex only on tm and below
Merged-In: I084536b137adde5754eb98d80012bc7fdad1af74
Change-Id: I084536b137adde5754eb98d80012bc7fdad1af74
parent 7f5c7c66
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
{
  "name": "com.android.bluetooth",
  "version": 330090000
  "version": 330090000,
  "requireNativeLibs": [
    "libaptX_encoder.so",
    "libaptXHD_encoder.so"
  ]
}
+0 −3
Original line number Diff line number Diff line
{
    "permittedPaths": [
        "/system_ext/${LIB}"
    ]
}
+10 −17
Original line number Diff line number Diff line
@@ -661,22 +661,15 @@ std::string A2DP_VendorCodecInfoString(const uint8_t* p_codec_info) {
         " codec_id: " + loghex(codec_id);
}

void* A2DP_VendorCodecLoadExternalLib(const std::vector<std::string>& lib_paths,
void* A2DP_VendorCodecLoadExternalLib(const std::string& lib_name,
                                      const std::string& friendly_name) {
  std::string lib_path_error_list = "";
  for (auto lib_path : lib_paths) {
    void* lib_handle = dlopen(lib_path.c_str(), RTLD_NOW);
    if (lib_handle != NULL) {
      LOG(INFO) << __func__ << "Library found: " << friendly_name << " with ["
                << lib_path << "]."
                << " (Tested libs: " << lib_path_error_list << ")";
      return lib_handle;
    }
    lib_path_error_list += "[ Err: ";
    lib_path_error_list += dlerror();
    lib_path_error_list += " ], ";
  }
  LOG(ERROR) << __func__ << "Failed to open library: " << friendly_name
             << ". (Tested libs: " << lib_path_error_list << ")";
  void* lib_handle = dlopen(lib_name.c_str(), RTLD_NOW);
  if (lib_handle == NULL) {
    LOG(ERROR) << __func__
               << ": Failed to load codec library: " << friendly_name
               << ". Err: [" << dlerror() << "]";
    return nullptr;
  }
  LOG(INFO) << __func__ << ": Codec library loaded: " << friendly_name;
  return lib_handle;
}
+1 −10
Original line number Diff line number Diff line
@@ -108,15 +108,6 @@ static size_t aptx_encode_16bit(tAPTX_FRAMING_PARAMS* framing_params,
                                size_t* data_out_index, uint16_t* data16_in,
                                uint8_t* data_out);

static const std::vector<std::string> APTX_ENCODER_LIB_PATHS = {
    APTX_ENCODER_LIB_NAME,
#ifdef __LP64__
    "/system_ext/lib64/" + APTX_ENCODER_LIB_NAME,
#else
    "/system_ext/lib/" + APTX_ENCODER_LIB_NAME,
#endif
};

/*******************************************************************************
 *
 * Function         A2DP_VendorLoadEncoderAptx
@@ -133,7 +124,7 @@ tLOADING_CODEC_STATUS A2DP_VendorLoadEncoderAptx(void) {

  // Open the encoder library
  aptx_encoder_lib_handle =
      A2DP_VendorCodecLoadExternalLib(APTX_ENCODER_LIB_PATHS, "aptX encoder");
      A2DP_VendorCodecLoadExternalLib(APTX_ENCODER_LIB_NAME, "AptX encoder");

  if (!aptx_encoder_lib_handle) return LOAD_ERROR_MISSING_CODEC;

+1 −10
Original line number Diff line number Diff line
@@ -109,15 +109,6 @@ static size_t aptx_hd_encode_24bit(tAPTX_HD_FRAMING_PARAMS* framing_params,
                                   size_t* data_out_index, uint32_t* data32_in,
                                   uint8_t* data_out);

static const std::vector<std::string> APTX_HD_ENCODER_LIB_PATHS = {
    APTX_HD_ENCODER_LIB_NAME,
#ifdef __LP64__
    "/system_ext/lib64/" + APTX_HD_ENCODER_LIB_NAME,
#else
    "/system_ext/lib/" + APTX_HD_ENCODER_LIB_NAME,
#endif
};

/*******************************************************************************
 *
 * Function         A2DP_VendorLoadEncoderAptxHd
@@ -135,7 +126,7 @@ tLOADING_CODEC_STATUS A2DP_VendorLoadEncoderAptxHd(void) {

  // Open the encoder library
  aptx_hd_encoder_lib_handle = A2DP_VendorCodecLoadExternalLib(
      APTX_HD_ENCODER_LIB_PATHS, "aptX-HD encoder");
      APTX_HD_ENCODER_LIB_NAME, "AptX-HD encoder");
  if (!aptx_hd_encoder_lib_handle) return LOAD_ERROR_MISSING_CODEC;

  aptx_hd_api.init_func =
Loading