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

Commit 0161d636 authored by David Duarte's avatar David Duarte Committed by Gerrit Code Review
Browse files

Merge "android/app/jni: Migrate to libbluetooth_log" into main

parents de2fca6a a5dfb900
Loading
Loading
Loading
Loading
+9 −10
Original line number Diff line number Diff line
@@ -15,15 +15,16 @@
 * limitations under the License.
 */

#ifndef COM_ANDROID_BLUETOOTH_H
#define COM_ANDROID_BLUETOOTH_H
#pragma once

#include <bluetooth/log.h>

#include "hardware/bluetooth.h"
#include "hardware/hardware.h"
#include "jni.h"
#include "jni_logging.h"
#include "nativehelper/ScopedLocalRef.h"
#include "utils/Log.h"

namespace log = bluetooth::log;

namespace android {

@@ -38,15 +39,15 @@ public:

    ~CallbackEnv() {
      if (mCallbackEnv && mCallbackEnv->ExceptionCheck()) {
          ALOGE("An exception was thrown by callback '%s'.", mName);
          LOGE_EX(mCallbackEnv);
        log::error("An exception was thrown by callback '{}'.", mName);
        jniLogException(mCallbackEnv, ANDROID_LOG_ERROR, LOG_TAG);
        mCallbackEnv->ExceptionClear();
      }
    }

    bool valid() const {
      if (!mCallbackEnv || !isCallbackThread()) {
        ALOGE("%s: Callback env fail", mName);
        log::error("{}: Callback env fail", mName);
        return false;
      }
      return true;
@@ -184,5 +185,3 @@ void jniGetMethodsOrDie(JNIEnv* env, const char* className,
    jniGetMethodsOrDie(env, classname, methodsArray, NELEM(methodsArray))

}  // namespace android

#endif /* COM_ANDROID_BLUETOOTH_H */
+11 −12
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ class BluetoothQualityReportCallbacksImpl
  void bqr_delivery_callback(const RawAddress bd_addr, uint8_t lmp_ver,
                             uint16_t lmp_subver, uint16_t manufacturer_id,
                             std::vector<uint8_t> bqr_raw_data) override {
    ALOGI("%s", __func__);
    log::info("");
    std::shared_lock<std::shared_timed_mutex> lock(callbacks_mutex);

    CallbackEnv sCallbackEnv(__func__);
@@ -57,7 +57,7 @@ class BluetoothQualityReportCallbacksImpl
    ScopedLocalRef<jbyteArray> addr(
        sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
    if (!addr.get()) {
      ALOGE("Error while allocation byte array for addr in %s", __func__);
      log::error("Error while allocation byte array for addr");
      return;
    }

@@ -67,8 +67,7 @@ class BluetoothQualityReportCallbacksImpl
    ScopedLocalRef<jbyteArray> raw_data(
        sCallbackEnv.get(), sCallbackEnv->NewByteArray(bqr_raw_data.size()));
    if (!raw_data.get()) {
      ALOGE("Error while allocation byte array for bqr raw data in %s",
            __func__);
      log::error("Error while allocation byte array for bqr raw data");
      return;
    }
    sCallbackEnv->SetByteArrayRegion(raw_data.get(), 0, bqr_raw_data.size(),
@@ -93,32 +92,32 @@ static void initNative(JNIEnv* env, jobject object) {

  const bt_interface_t* btInf = getBluetoothInterface();
  if (btInf == nullptr) {
    LOG(ERROR) << "Bluetooth module is not loaded";
    log::error("Bluetooth module is not loaded");
    return;
  }

  if (sBluetoothQualityReportInterface != nullptr) {
    LOG(INFO) << "Cleaning up BluetoothQualityReport Interface before "
                 "initializing...";
    log::info(
        "Cleaning up BluetoothQualityReport Interface before initializing...");
    sBluetoothQualityReportInterface = nullptr;
  }

  if (mCallbacksObj != nullptr) {
    LOG(INFO) << "Cleaning up BluetoothQualityReport callback object";
    log::info("Cleaning up BluetoothQualityReport callback object");
    env->DeleteGlobalRef(mCallbacksObj);
    mCallbacksObj = nullptr;
  }

  if ((mCallbacksObj = env->NewGlobalRef(object)) == nullptr) {
    LOG(ERROR)
        << "Failed to allocate Global Ref for BluetoothQualityReport Callbacks";
    log::error(
        "Failed to allocate Global Ref for BluetoothQualityReport Callbacks");
    return;
  }

  sBluetoothQualityReportInterface =
      (BluetoothQualityReportInterface*)btInf->get_profile_interface(BT_BQR_ID);
  if (sBluetoothQualityReportInterface == nullptr) {
    LOG(ERROR) << "Failed to get BluetoothQualityReport Interface";
    log::error("Failed to get BluetoothQualityReport Interface");
    return;
  }

@@ -131,7 +130,7 @@ static void cleanupNative(JNIEnv* env, jobject /* object */) {

  const bt_interface_t* btInf = getBluetoothInterface();
  if (btInf == nullptr) {
    LOG(ERROR) << "Bluetooth module is not loaded";
    log::error("Bluetooth module is not loaded");
    return;
  }

+40 −41
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ static std::shared_timed_mutex callbacks_mutex;
static void bta2dp_connection_state_callback(const RawAddress& bd_addr,
                                             btav_connection_state_t state,
                                             const btav_error_t& /* error */) {
  ALOGI("%s", __func__);
  log::info("");

  std::shared_lock<std::shared_timed_mutex> lock(callbacks_mutex);
  CallbackEnv sCallbackEnv(__func__);
@@ -62,7 +62,7 @@ static void bta2dp_connection_state_callback(const RawAddress& bd_addr,
  ScopedLocalRef<jbyteArray> addr(
      sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
  if (!addr.get()) {
    ALOGE("%s: Fail to new jbyteArray bd addr", __func__);
    log::error("Fail to new jbyteArray bd addr");
    return;
  }

@@ -75,7 +75,7 @@ static void bta2dp_connection_state_callback(const RawAddress& bd_addr,

static void bta2dp_audio_state_callback(const RawAddress& bd_addr,
                                        btav_audio_state_t state) {
  ALOGI("%s", __func__);
  log::info("");

  std::shared_lock<std::shared_timed_mutex> lock(callbacks_mutex);
  CallbackEnv sCallbackEnv(__func__);
@@ -84,7 +84,7 @@ static void bta2dp_audio_state_callback(const RawAddress& bd_addr,
  ScopedLocalRef<jbyteArray> addr(
      sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
  if (!addr.get()) {
    ALOGE("%s: Fail to new jbyteArray bd addr", __func__);
    log::error("Fail to new jbyteArray bd addr");
    return;
  }

@@ -99,7 +99,7 @@ static void bta2dp_audio_config_callback(
    const RawAddress& bd_addr, btav_a2dp_codec_config_t codec_config,
    std::vector<btav_a2dp_codec_config_t> codecs_local_capabilities,
    std::vector<btav_a2dp_codec_config_t> codecs_selectable_capabilities) {
  ALOGI("%s", __func__);
  log::info("");

  std::shared_lock<std::shared_timed_mutex> lock(callbacks_mutex);
  CallbackEnv sCallbackEnv(__func__);
@@ -151,7 +151,7 @@ static void bta2dp_audio_config_callback(
  ScopedLocalRef<jbyteArray> addr(
      sCallbackEnv.get(), sCallbackEnv->NewByteArray(RawAddress::kLength));
  if (!addr.get()) {
    ALOGE("%s: Fail to new jbyteArray bd addr", __func__);
    log::error("Fail to new jbyteArray bd addr");
    return;
  }
  sCallbackEnv->SetByteArrayRegion(
@@ -165,7 +165,7 @@ static void bta2dp_audio_config_callback(

static bool bta2dp_mandatory_codec_preferred_callback(
    const RawAddress& bd_addr) {
  ALOGI("%s", __func__);
  log::info("");

  std::shared_lock<std::shared_timed_mutex> lock(callbacks_mutex);
  CallbackEnv sCallbackEnv(__func__);
@@ -174,7 +174,7 @@ static bool bta2dp_mandatory_codec_preferred_callback(
  ScopedLocalRef<jbyteArray> addr(
      sCallbackEnv.get(), sCallbackEnv->NewByteArray(RawAddress::kLength));
  if (!addr.get()) {
    ALOGE("%s: Fail to new jbyteArray bd addr", __func__);
    log::error("Fail to new jbyteArray bd addr");
    return false;
  }
  sCallbackEnv->SetByteArrayRegion(
@@ -202,7 +202,7 @@ static std::vector<btav_a2dp_codec_config_t> prepareCodecPreferences(
    if (jcodecConfig == nullptr) continue;
    if (!env->IsInstanceOf(jcodecConfig,
                           android_bluetooth_BluetoothCodecConfig.clazz)) {
      ALOGE("%s: Invalid BluetoothCodecConfig instance", __func__);
      log::error("Invalid BluetoothCodecConfig instance");
      continue;
    }
    jint codecType = env->CallIntMethod(
@@ -252,32 +252,31 @@ static void initNative(JNIEnv* env, jobject object,

  const bt_interface_t* btInf = getBluetoothInterface();
  if (btInf == nullptr) {
    ALOGE("%s: Bluetooth module is not loaded", __func__);
    log::error("Bluetooth module is not loaded");
    return;
  }

  if (sBluetoothA2dpInterface != nullptr) {
    ALOGW("%s: Cleaning up A2DP Interface before initializing...", __func__);
    log::warn("Cleaning up A2DP Interface before initializing...");
    sBluetoothA2dpInterface->cleanup();
    sBluetoothA2dpInterface = nullptr;
  }

  if (mCallbacksObj != nullptr) {
    ALOGW("%s: Cleaning up A2DP callback object", __func__);
    log::warn("Cleaning up A2DP callback object");
    env->DeleteGlobalRef(mCallbacksObj);
    mCallbacksObj = nullptr;
  }

  if ((mCallbacksObj = env->NewGlobalRef(object)) == nullptr) {
    ALOGE("%s: Failed to allocate Global Ref for A2DP Callbacks", __func__);
    log::error("Failed to allocate Global Ref for A2DP Callbacks");
    return;
  }

  android_bluetooth_BluetoothCodecConfig.clazz = (jclass)env->NewGlobalRef(
      env->FindClass("android/bluetooth/BluetoothCodecConfig"));
  if (android_bluetooth_BluetoothCodecConfig.clazz == nullptr) {
    ALOGE("%s: Failed to allocate Global Ref for BluetoothCodecConfig class",
          __func__);
    log::error("Failed to allocate Global Ref for BluetoothCodecConfig class");
    return;
  }

@@ -285,7 +284,7 @@ static void initNative(JNIEnv* env, jobject object,
      (btav_source_interface_t*)btInf->get_profile_interface(
          BT_PROFILE_ADVANCED_AUDIO_ID);
  if (sBluetoothA2dpInterface == nullptr) {
    ALOGE("%s: Failed to get Bluetooth A2DP Interface", __func__);
    log::error("Failed to get Bluetooth A2DP Interface");
    return;
  }

@@ -299,8 +298,8 @@ static void initNative(JNIEnv* env, jobject object,
      &sBluetoothA2dpCallbacks, maxConnectedAudioDevices, codec_priorities,
      codec_offloading, &supported_codecs);
  if (status != BT_STATUS_SUCCESS) {
    ALOGE("%s: Failed to initialize Bluetooth A2DP, status: %d", __func__,
          status);
    log::error("Failed to initialize Bluetooth A2DP, status: {}",
               bt_status_text(status));
    sBluetoothA2dpInterface = nullptr;
    return;
  }
@@ -312,7 +311,7 @@ static void cleanupNative(JNIEnv* env, jobject /* object */) {

  const bt_interface_t* btInf = getBluetoothInterface();
  if (btInf == nullptr) {
    ALOGE("%s: Bluetooth module is not loaded", __func__);
    log::error("Bluetooth module is not loaded");
    return;
  }

@@ -331,13 +330,12 @@ static void cleanupNative(JNIEnv* env, jobject /* object */) {
}

static jobjectArray getSupportedCodecTypesNative(JNIEnv* env) {
  ALOGI("%s: %p", __func__, sBluetoothA2dpInterface);
  log::info("{}", fmt::ptr(sBluetoothA2dpInterface));

  jclass android_bluetooth_BluetoothCodecType_clazz = (jclass)env->NewGlobalRef(
      env->FindClass("android/bluetooth/BluetoothCodecType"));
  if (android_bluetooth_BluetoothCodecType_clazz == nullptr) {
    ALOGE("%s: Failed to allocate Global Ref for BluetoothCodecType class",
          __func__);
    log::error("Failed to allocate Global Ref for BluetoothCodecType class");
    return nullptr;
  }

@@ -345,8 +343,7 @@ static jobjectArray getSupportedCodecTypesNative(JNIEnv* env) {
                                    "<init>", "(IJLjava/lang/String;)V");

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

@@ -355,8 +352,7 @@ static jobjectArray getSupportedCodecTypesNative(JNIEnv* env) {
                          android_bluetooth_BluetoothCodecType_clazz, nullptr);

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

@@ -374,10 +370,10 @@ static jobjectArray getSupportedCodecTypesNative(JNIEnv* env) {

static jboolean connectA2dpNative(JNIEnv* env, jobject /* object */,
                                  jbyteArray address) {
  ALOGI("%s: sBluetoothA2dpInterface: %p", __func__, sBluetoothA2dpInterface);
  log::info("sBluetoothA2dpInterface: {}", fmt::ptr(sBluetoothA2dpInterface));
  std::shared_lock<std::shared_timed_mutex> lock(interface_mutex);
  if (!sBluetoothA2dpInterface) {
    ALOGE("%s: Failed to get the Bluetooth A2DP Interface", __func__);
    log::error("Failed to get the Bluetooth A2DP Interface");
    return JNI_FALSE;
  }

@@ -391,7 +387,7 @@ static jboolean connectA2dpNative(JNIEnv* env, jobject /* object */,
  bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
  bt_status_t status = sBluetoothA2dpInterface->connect(bd_addr);
  if (status != BT_STATUS_SUCCESS) {
    ALOGE("%s: Failed A2DP connection, status: %d", __func__, status);
    log::error("Failed A2DP connection, status: {}", bt_status_text(status));
  }
  env->ReleaseByteArrayElements(address, addr, 0);
  return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
@@ -399,10 +395,10 @@ static jboolean connectA2dpNative(JNIEnv* env, jobject /* object */,

static jboolean disconnectA2dpNative(JNIEnv* env, jobject /* object */,
                                     jbyteArray address) {
  ALOGI("%s: sBluetoothA2dpInterface: %p", __func__, sBluetoothA2dpInterface);
  log::info("sBluetoothA2dpInterface: {}", fmt::ptr(sBluetoothA2dpInterface));
  std::shared_lock<std::shared_timed_mutex> lock(interface_mutex);
  if (!sBluetoothA2dpInterface) {
    ALOGE("%s: Failed to get the Bluetooth A2DP Interface", __func__);
    log::error("Failed to get the Bluetooth A2DP Interface");
    return JNI_FALSE;
  }

@@ -416,7 +412,7 @@ static jboolean disconnectA2dpNative(JNIEnv* env, jobject /* object */,
  bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
  bt_status_t status = sBluetoothA2dpInterface->disconnect(bd_addr);
  if (status != BT_STATUS_SUCCESS) {
    ALOGE("%s: Failed A2DP disconnection, status: %d", __func__, status);
    log::error("Failed A2DP disconnection, status: {}", bt_status_text(status));
  }
  env->ReleaseByteArrayElements(address, addr, 0);
  return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
@@ -424,10 +420,10 @@ static jboolean disconnectA2dpNative(JNIEnv* env, jobject /* object */,

static jboolean setSilenceDeviceNative(JNIEnv* env, jobject /* object */,
                                       jbyteArray address, jboolean silence) {
  ALOGI("%s: sBluetoothA2dpInterface: %p", __func__, sBluetoothA2dpInterface);
  log::info("sBluetoothA2dpInterface: {}", fmt::ptr(sBluetoothA2dpInterface));
  std::shared_lock<std::shared_timed_mutex> lock(interface_mutex);
  if (!sBluetoothA2dpInterface) {
    ALOGE("%s: Failed to get the Bluetooth A2DP Interface", __func__);
    log::error("Failed to get the Bluetooth A2DP Interface");
    return JNI_FALSE;
  }

@@ -443,7 +439,8 @@ static jboolean setSilenceDeviceNative(JNIEnv* env, jobject /* object */,
  bt_status_t status =
      sBluetoothA2dpInterface->set_silence_device(bd_addr, silence);
  if (status != BT_STATUS_SUCCESS) {
    ALOGE("%s: Failed A2DP set_silence_device, status: %d", __func__, status);
    log::error("Failed A2DP set_silence_device, status: {}",
               bt_status_text(status));
  }
  env->ReleaseByteArrayElements(address, addr, 0);
  return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
@@ -451,10 +448,10 @@ static jboolean setSilenceDeviceNative(JNIEnv* env, jobject /* object */,

static jboolean setActiveDeviceNative(JNIEnv* env, jobject /* object */,
                                      jbyteArray address) {
  ALOGI("%s: sBluetoothA2dpInterface: %p", __func__, sBluetoothA2dpInterface);
  log::info("sBluetoothA2dpInterface: {}", fmt::ptr(sBluetoothA2dpInterface));
  std::shared_lock<std::shared_timed_mutex> lock(interface_mutex);
  if (!sBluetoothA2dpInterface) {
    ALOGE("%s: Failed to get the Bluetooth A2DP Interface", __func__);
    log::error("Failed to get the Bluetooth A2DP Interface");
    return JNI_FALSE;
  }

@@ -466,7 +463,8 @@ static jboolean setActiveDeviceNative(JNIEnv* env, jobject /* object */,
  }
  bt_status_t status = sBluetoothA2dpInterface->set_active_device(bd_addr);
  if (status != BT_STATUS_SUCCESS) {
    ALOGE("%s: Failed A2DP set_active_device, status: %d", __func__, status);
    log::error("Failed A2DP set_active_device, status: {}",
               bt_status_text(status));
  }
  env->ReleaseByteArrayElements(address, addr, 0);
  return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
@@ -475,10 +473,10 @@ static jboolean setActiveDeviceNative(JNIEnv* env, jobject /* object */,
static jboolean setCodecConfigPreferenceNative(JNIEnv* env, jobject object,
                                               jbyteArray address,
                                               jobjectArray codecConfigArray) {
  ALOGI("%s: sBluetoothA2dpInterface: %p", __func__, sBluetoothA2dpInterface);
  log::info("sBluetoothA2dpInterface: {}", fmt::ptr(sBluetoothA2dpInterface));
  std::shared_lock<std::shared_timed_mutex> lock(interface_mutex);
  if (!sBluetoothA2dpInterface) {
    ALOGE("%s: Failed to get the Bluetooth A2DP Interface", __func__);
    log::error("Failed to get the Bluetooth A2DP Interface");
    return JNI_FALSE;
  }

@@ -496,7 +494,8 @@ static jboolean setCodecConfigPreferenceNative(JNIEnv* env, jobject object,
  bt_status_t status =
      sBluetoothA2dpInterface->config_codec(bd_addr, codec_preferences);
  if (status != BT_STATUS_SUCCESS) {
    ALOGE("%s: Failed codec configuration, status: %d", __func__, status);
    log::error("Failed codec configuration, status: {}",
               bt_status_text(status));
  }
  env->ReleaseByteArrayElements(address, addr, 0);
  return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
+19 −17
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ static std::shared_timed_mutex callbacks_mutex;
static void a2dp_sink_connection_state_callback(
    const RawAddress& bd_addr, btav_connection_state_t state,
    const btav_error_t& /* error */) {
  ALOGI("%s", __func__);
  log::info("");
  std::shared_lock<std::shared_timed_mutex> lock(callbacks_mutex);
  if (!mCallbacksObj) return;

@@ -47,7 +47,7 @@ static void a2dp_sink_connection_state_callback(
  ScopedLocalRef<jbyteArray> addr(
      sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
  if (!addr.get()) {
    ALOGE("Fail to new jbyteArray bd addr for connection state");
    log::error("Fail to new jbyteArray bd addr for connection state");
    return;
  }

@@ -59,7 +59,7 @@ static void a2dp_sink_connection_state_callback(

static void a2dp_sink_audio_state_callback(const RawAddress& bd_addr,
                                           btav_audio_state_t state) {
  ALOGI("%s", __func__);
  log::info("");
  std::shared_lock<std::shared_timed_mutex> lock(callbacks_mutex);
  if (!mCallbacksObj) return;

@@ -69,7 +69,7 @@ static void a2dp_sink_audio_state_callback(const RawAddress& bd_addr,
  ScopedLocalRef<jbyteArray> addr(
      sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
  if (!addr.get()) {
    ALOGE("Fail to new jbyteArray bd addr for connection state");
    log::error("Fail to new jbyteArray bd addr for connection state");
    return;
  }

@@ -82,7 +82,7 @@ static void a2dp_sink_audio_state_callback(const RawAddress& bd_addr,
static void a2dp_sink_audio_config_callback(const RawAddress& bd_addr,
                                            uint32_t sample_rate,
                                            uint8_t channel_count) {
  ALOGI("%s", __func__);
  log::info("");
  std::shared_lock<std::shared_timed_mutex> lock(callbacks_mutex);
  if (!mCallbacksObj) return;

@@ -92,7 +92,7 @@ static void a2dp_sink_audio_config_callback(const RawAddress& bd_addr,
  ScopedLocalRef<jbyteArray> addr(
      sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
  if (!addr.get()) {
    ALOGE("Fail to new jbyteArray bd addr for connection state");
    log::error("Fail to new jbyteArray bd addr for connection state");
    return;
  }

@@ -116,18 +116,18 @@ static void initNative(JNIEnv* env, jobject object,

  const bt_interface_t* btInf = getBluetoothInterface();
  if (btInf == NULL) {
    ALOGE("Bluetooth module is not loaded");
    log::error("Bluetooth module is not loaded");
    return;
  }

  if (sBluetoothA2dpInterface != NULL) {
    ALOGW("Cleaning up A2DP Interface before initializing...");
    log::warn("Cleaning up A2DP Interface before initializing...");
    sBluetoothA2dpInterface->cleanup();
    sBluetoothA2dpInterface = NULL;
  }

  if (mCallbacksObj != NULL) {
    ALOGW("Cleaning up A2DP callback object");
    log::warn("Cleaning up A2DP callback object");
    env->DeleteGlobalRef(mCallbacksObj);
    mCallbacksObj = NULL;
  }
@@ -136,14 +136,15 @@ static void initNative(JNIEnv* env, jobject object,
      (btav_sink_interface_t*)btInf->get_profile_interface(
          BT_PROFILE_ADVANCED_AUDIO_SINK_ID);
  if (sBluetoothA2dpInterface == NULL) {
    ALOGE("Failed to get Bluetooth A2DP Sink Interface");
    log::error("Failed to get Bluetooth A2DP Sink Interface");
    return;
  }

  bt_status_t status = sBluetoothA2dpInterface->init(&sBluetoothA2dpCallbacks,
                                                     maxConnectedAudioDevices);
  if (status != BT_STATUS_SUCCESS) {
    ALOGE("Failed to initialize Bluetooth A2DP Sink, status: %d", status);
    log::error("Failed to initialize Bluetooth A2DP Sink, status: {}",
               bt_status_text(status));
    sBluetoothA2dpInterface = NULL;
    return;
  }
@@ -156,7 +157,7 @@ static void cleanupNative(JNIEnv* env, jobject /* object */) {
  const bt_interface_t* btInf = getBluetoothInterface();

  if (btInf == NULL) {
    ALOGE("Bluetooth module is not loaded");
    log::error("Bluetooth module is not loaded");
    return;
  }

@@ -173,7 +174,7 @@ static void cleanupNative(JNIEnv* env, jobject /* object */) {

static jboolean connectA2dpNative(JNIEnv* env, jobject /* object */,
                                  jbyteArray address) {
  ALOGI("%s: sBluetoothA2dpInterface: %p", __func__, sBluetoothA2dpInterface);
  log::info("sBluetoothA2dpInterface: {}", fmt::ptr(sBluetoothA2dpInterface));
  if (!sBluetoothA2dpInterface) return JNI_FALSE;

  jbyte* addr = env->GetByteArrayElements(address, NULL);
@@ -186,7 +187,7 @@ static jboolean connectA2dpNative(JNIEnv* env, jobject /* object */,
  bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
  bt_status_t status = sBluetoothA2dpInterface->connect(bd_addr);
  if (status != BT_STATUS_SUCCESS) {
    ALOGE("Failed HF connection, status: %d", status);
    log::error("Failed HF connection, status: {}", bt_status_text(status));
  }
  env->ReleaseByteArrayElements(address, addr, 0);
  return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
@@ -206,7 +207,7 @@ static jboolean disconnectA2dpNative(JNIEnv* env, jobject /* object */,
  bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
  bt_status_t status = sBluetoothA2dpInterface->disconnect(bd_addr);
  if (status != BT_STATUS_SUCCESS) {
    ALOGE("Failed HF disconnection, status: %d", status);
    log::error("Failed HF disconnection, status: {}", bt_status_text(status));
  }
  env->ReleaseByteArrayElements(address, addr, 0);
  return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
@@ -228,7 +229,7 @@ static jboolean setActiveDeviceNative(JNIEnv* env, jobject /* object */,
                                      jbyteArray address) {
  if (!sBluetoothA2dpInterface) return JNI_FALSE;

  ALOGI("%s: sBluetoothA2dpInterface: %p", __func__, sBluetoothA2dpInterface);
  log::info("sBluetoothA2dpInterface: {}", fmt::ptr(sBluetoothA2dpInterface));

  jbyte* addr = env->GetByteArrayElements(address, NULL);
  if (!addr) {
@@ -240,7 +241,8 @@ static jboolean setActiveDeviceNative(JNIEnv* env, jobject /* object */,
  rawAddress.FromOctets((uint8_t*)addr);
  bt_status_t status = sBluetoothA2dpInterface->set_active_device(rawAddress);
  if (status != BT_STATUS_SUCCESS) {
    ALOGE("Failed sending passthru command, status: %d", status);
    log::error("Failed sending passthru command, status: {}",
               bt_status_text(status));
  }
  env->ReleaseByteArrayElements(address, addr, 0);

+127 −110

File changed.

Preview size limit exceeded, changes collapsed.

Loading