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

Commit 2bf4c772 authored by William Escande's avatar William Escande
Browse files

Format: apply clang rules

Restore SpacesBeforeTrailingComments to 2 to match current style

Then run clang-format -i **/**.{c,h,cc,cpp,hpp}
Then fix a bunch of typo (reported by gerrit)
Then fix unnecessary multiline string
Then fix whitespace for disabled clang format (reported by cpplint)

This is no-op

Bug: 311772251
Test: mmm packages/modules/Bluetooth
Flag: Exempt Format only
Change-Id: If135447803a40a2a07d4630ba2195e08ef8d250c
parent ace0cd51
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -32,7 +32,8 @@ AccessModifierOffset: -2 # vs -1 Should be -4 when updating IndentWidth to 4
Standard: c++20 # vs Auto
AllowShortIfStatementsOnASingleLine: Never # vs WithoutElse
AllowShortLoopsOnASingleLine: false # vs true
SpacesBeforeTrailingComments: 1 # vs 2
# AOSP suggest 1, but ask to follow clang-format settings. CppLint ask for 2
# SpacesBeforeTrailingComments: 1 # vs 2

# Allow clang-format to automatically fix more things
RemoveSemicolon: true
+81 −88
Original line number Diff line number Diff line
@@ -33,9 +33,7 @@ bool isCallbackThread();

class CallbackEnv {
public:
    CallbackEnv(const char *methodName) : mName(methodName) {
        mCallbackEnv = getCallbackEnv();
    }
  CallbackEnv(const char* methodName) : mName(methodName) { mCallbackEnv = getCallbackEnv(); }

  ~CallbackEnv() {
    if (mCallbackEnv && mCallbackEnv->ExceptionCheck()) {
@@ -112,13 +110,9 @@ public:
    return true;
  }

    JNIEnv *operator-> () const {
        return mCallbackEnv;
    }
  JNIEnv* operator->() const { return mCallbackEnv; }

    JNIEnv *get() const {
        return mCallbackEnv;
    }
  JNIEnv* get() const { return mCallbackEnv; }

private:
  JNIEnv* mCallbackEnv;
@@ -166,8 +160,7 @@ int register_com_android_bluetooth_vc(JNIEnv* env);

int register_com_android_bluetooth_csip_set_coordinator(JNIEnv* env);

int register_com_android_bluetooth_btservice_BluetoothQualityReport(
    JNIEnv* env);
int register_com_android_bluetooth_btservice_BluetoothQualityReport(JNIEnv* env);

struct JNIJavaMethod {
  const char* name;
@@ -176,8 +169,8 @@ struct JNIJavaMethod {
  bool is_static{false};
};

void jniGetMethodsOrDie(JNIEnv* env, const char* className,
                        const JNIJavaMethod* methods, int nMethods);
void jniGetMethodsOrDie(JNIEnv* env, const char* className, const JNIJavaMethod* methods,
                        int nMethods);

#define REGISTER_NATIVE_METHODS(env, classname, methodsArray) \
  jniRegisterNativeMethods(env, classname, methodsArray, NELEM(methodsArray))
+31 −37
Original line number Diff line number Diff line
@@ -30,41 +30,43 @@ using bluetooth::bqr::BluetoothQualityReportInterface;
namespace android {
static jmethodID method_bqrDeliver;

static BluetoothQualityReportInterface* sBluetoothQualityReportInterface =
    nullptr;
static BluetoothQualityReportInterface* sBluetoothQualityReportInterface = nullptr;
static std::shared_timed_mutex interface_mutex;

static jobject mCallbacksObj = nullptr;
static std::shared_timed_mutex callbacks_mutex;

class BluetoothQualityReportCallbacksImpl
    : public bluetooth::bqr::BluetoothQualityReportCallbacks {
class BluetoothQualityReportCallbacksImpl : public bluetooth::bqr::BluetoothQualityReportCallbacks {
public:
  ~BluetoothQualityReportCallbacksImpl() = default;

  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 {
  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 {
    log::info("");
    std::shared_lock<std::shared_timed_mutex> lock(callbacks_mutex);

    CallbackEnv sCallbackEnv(__func__);
    if (!sCallbackEnv.valid()) return;
    if (method_bqrDeliver == NULL) return;
    if (mCallbacksObj == nullptr) return;
    if (!sCallbackEnv.valid()) {
      return;
    }
    if (method_bqrDeliver == NULL) {
      return;
    }
    if (mCallbacksObj == nullptr) {
      return;
    }

    ScopedLocalRef<jbyteArray> addr(
        sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
    ScopedLocalRef<jbyteArray> addr(sCallbackEnv.get(),
                                    sCallbackEnv->NewByteArray(sizeof(RawAddress)));
    if (!addr.get()) {
      log::error("Error while allocation byte array for addr");
      return;
    }

    sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
                                     (jbyte*)bd_addr.address);
    sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress), (jbyte*)bd_addr.address);

    ScopedLocalRef<jbyteArray> raw_data(
        sCallbackEnv.get(), sCallbackEnv->NewByteArray(bqr_raw_data.size()));
    ScopedLocalRef<jbyteArray> raw_data(sCallbackEnv.get(),
                                        sCallbackEnv->NewByteArray(bqr_raw_data.size()));
    if (!raw_data.get()) {
      log::error("Error while allocation byte array for bqr raw data");
      return;
@@ -72,9 +74,8 @@ class BluetoothQualityReportCallbacksImpl
    sCallbackEnv->SetByteArrayRegion(raw_data.get(), 0, bqr_raw_data.size(),
                                     (jbyte*)bqr_raw_data.data());

    sCallbackEnv->CallVoidMethod(mCallbacksObj, method_bqrDeliver, addr.get(),
                                 (jint)lmp_ver, (jint)lmp_subver,
                                 (jint)manufacturer_id, raw_data.get());
    sCallbackEnv->CallVoidMethod(mCallbacksObj, method_bqrDeliver, addr.get(), (jint)lmp_ver,
                                 (jint)lmp_subver, (jint)manufacturer_id, raw_data.get());
  }
};

@@ -91,8 +92,7 @@ static void initNative(JNIEnv* env, jobject object) {
  }

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

@@ -103,8 +103,7 @@ static void initNative(JNIEnv* env, jobject object) {
  }

  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;
  }

@@ -138,16 +137,13 @@ static void cleanupNative(JNIEnv* env, jobject /* object */) {
  }
}

int register_com_android_bluetooth_btservice_BluetoothQualityReport(
    JNIEnv* env) {
int register_com_android_bluetooth_btservice_BluetoothQualityReport(JNIEnv* env) {
  const JNINativeMethod methods[] = {
          {"initNative", "()V", (void*)initNative},
          {"cleanupNative", "()V", (void*)cleanupNative},
  };
  const int result = REGISTER_NATIVE_METHODS(
      env,
      "com/android/bluetooth/btservice/BluetoothQualityReportNativeInterface",
      methods);
          env, "com/android/bluetooth/btservice/BluetoothQualityReportNativeInterface", methods);
  if (result != 0) {
    return result;
  }
@@ -155,9 +151,7 @@ int register_com_android_bluetooth_btservice_BluetoothQualityReport(
  const JNIJavaMethod javaMethods[] = {
          {"bqrDeliver", "([BIII[B)V", &method_bqrDeliver},
  };
  GET_JAVA_METHODS(
      env,
      "com/android/bluetooth/btservice/BluetoothQualityReportNativeInterface",
  GET_JAVA_METHODS(env, "com/android/bluetooth/btservice/BluetoothQualityReportNativeInterface",
                   javaMethods);

  return 0;
+165 −201

File changed.

Preview size limit exceeded, changes collapsed.

+60 −64
Original line number Diff line number Diff line
@@ -34,18 +34,22 @@ static jmethodID method_onAudioConfigChanged;
static jobject mCallbacksObj = NULL;
static std::shared_timed_mutex callbacks_mutex;

static void a2dp_sink_connection_state_callback(
    const RawAddress& bd_addr, btav_connection_state_t state,
static void a2dp_sink_connection_state_callback(const RawAddress& bd_addr,
                                                btav_connection_state_t state,
                                                const btav_error_t& /* error */) {
  log::info("");
  std::shared_lock<std::shared_timed_mutex> lock(callbacks_mutex);
  if (!mCallbacksObj) return;
  if (!mCallbacksObj) {
    return;
  }

  CallbackEnv sCallbackEnv(__func__);
  if (!sCallbackEnv.valid()) return;
  if (!sCallbackEnv.valid()) {
    return;
  }

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

  sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
                                   (const jbyte*)bd_addr.address);
  sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onConnectionStateChanged,
                               addr.get(), (jint)state);
  sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onConnectionStateChanged, addr.get(),
                               (jint)state);
}

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

  CallbackEnv sCallbackEnv(__func__);
  if (!sCallbackEnv.valid()) return;
  if (!sCallbackEnv.valid()) {
    return;
  }

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

  sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
                                   (const jbyte*)bd_addr.address);
  sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAudioStateChanged,
                               addr.get(), (jint)state);
  sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAudioStateChanged, addr.get(), (jint)state);
}

static void a2dp_sink_audio_config_callback(const RawAddress& bd_addr,
                                            uint32_t sample_rate,
static void a2dp_sink_audio_config_callback(const RawAddress& bd_addr, uint32_t sample_rate,
                                            uint8_t channel_count) {
  log::info("");
  std::shared_lock<std::shared_timed_mutex> lock(callbacks_mutex);
  if (!mCallbacksObj) return;
  if (!mCallbacksObj) {
    return;
  }

  CallbackEnv sCallbackEnv(__func__);
  if (!sCallbackEnv.valid()) return;
  if (!sCallbackEnv.valid()) {
    return;
  }

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

  sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
                                   (const jbyte*)bd_addr.address);
  sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAudioConfigChanged,
                               addr.get(), (jint)sample_rate,
                               (jint)channel_count);
  sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAudioConfigChanged, addr.get(),
                               (jint)sample_rate, (jint)channel_count);
}

static btav_sink_callbacks_t sBluetoothA2dpCallbacks = {
@@ -110,8 +118,7 @@ static btav_sink_callbacks_t sBluetoothA2dpCallbacks = {
        a2dp_sink_audio_config_callback,
};

static void initNative(JNIEnv* env, jobject object,
                       jint maxConnectedAudioDevices) {
static void initNative(JNIEnv* env, jobject object, jint maxConnectedAudioDevices) {
  std::unique_lock<std::shared_timed_mutex> lock(callbacks_mutex);

  const bt_interface_t* btInf = getBluetoothInterface();
@@ -128,11 +135,9 @@ static void initNative(JNIEnv* env, jobject object,
    mCallbacksObj = NULL;
  }

  bt_status_t status =
      btif_av_sink_init(&sBluetoothA2dpCallbacks, maxConnectedAudioDevices);
  bt_status_t status = btif_av_sink_init(&sBluetoothA2dpCallbacks, maxConnectedAudioDevices);
  if (status != BT_STATUS_SUCCESS) {
    log::error("Failed to initialize Bluetooth A2DP Sink, status: {}",
               bt_status_text(status));
    log::error("Failed to initialize Bluetooth A2DP Sink, status: {}", bt_status_text(status));
    return;
  }

@@ -156,8 +161,7 @@ static void cleanupNative(JNIEnv* env, jobject /* object */) {
  }
}

static jboolean connectA2dpNative(JNIEnv* env, jobject /* object */,
                                  jbyteArray address) {
static jboolean connectA2dpNative(JNIEnv* env, jobject /* object */, jbyteArray address) {
  jbyte* addr = env->GetByteArrayElements(address, NULL);
  if (!addr) {
    jniThrowIOException(env, EINVAL);
@@ -177,8 +181,7 @@ static jboolean connectA2dpNative(JNIEnv* env, jobject /* object */,
  return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}

static jboolean disconnectA2dpNative(JNIEnv* env, jobject /* object */,
                                     jbyteArray address) {
static jboolean disconnectA2dpNative(JNIEnv* env, jobject /* object */, jbyteArray address) {
  jbyte* addr = env->GetByteArrayElements(address, NULL);
  if (!addr) {
    jniThrowIOException(env, EINVAL);
@@ -198,18 +201,15 @@ static jboolean disconnectA2dpNative(JNIEnv* env, jobject /* object */,
  return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}

static void informAudioFocusStateNative(JNIEnv* /* env */, jobject /* object */,
                                        jint focus_state) {
static void informAudioFocusStateNative(JNIEnv* /* env */, jobject /* object */, jint focus_state) {
  btif_av_sink_set_audio_focus_state((uint8_t)focus_state);
}

static void informAudioTrackGainNative(JNIEnv* /* env */, jobject /* object */,
                                       jfloat gain) {
static void informAudioTrackGainNative(JNIEnv* /* env */, jobject /* object */, jfloat gain) {
  btif_av_sink_set_audio_track_gain((float)gain);
}

static jboolean setActiveDeviceNative(JNIEnv* env, jobject /* object */,
                                      jbyteArray address) {
static jboolean setActiveDeviceNative(JNIEnv* env, jobject /* object */, jbyteArray address) {
  jbyte* addr = env->GetByteArrayElements(address, NULL);
  if (!addr) {
    jniThrowIOException(env, EINVAL);
@@ -222,8 +222,7 @@ static jboolean setActiveDeviceNative(JNIEnv* env, jobject /* object */,
  log::info("{}", rawAddress);
  bt_status_t status = btif_av_sink_set_active_device(rawAddress);
  if (status != BT_STATUS_SUCCESS) {
    log::error("Failed sending passthru command, status: {}",
               bt_status_text(status));
    log::error("Failed sending passthru command, status: {}", bt_status_text(status));
  }

  env->ReleaseByteArrayElements(address, addr, 0);
@@ -236,8 +235,7 @@ int register_com_android_bluetooth_a2dp_sink(JNIEnv* env) {
          {"cleanupNative", "()V", (void*)cleanupNative},
          {"connectA2dpNative", "([B)Z", (void*)connectA2dpNative},
          {"disconnectA2dpNative", "([B)Z", (void*)disconnectA2dpNative},
      {"informAudioFocusStateNative", "(I)V",
       (void*)informAudioFocusStateNative},
          {"informAudioFocusStateNative", "(I)V", (void*)informAudioFocusStateNative},
          {"informAudioTrackGainNative", "(F)V", (void*)informAudioTrackGainNative},
          {"setActiveDeviceNative", "([B)Z", (void*)setActiveDeviceNative},
  };
@@ -252,10 +250,8 @@ int register_com_android_bluetooth_a2dp_sink(JNIEnv* env) {
          {"onAudioStateChanged", "([BI)V", &method_onAudioStateChanged},
          {"onAudioConfigChanged", "([BII)V", &method_onAudioConfigChanged},
  };
  GET_JAVA_METHODS(env,
                   "com/android/bluetooth/a2dpsink/A2dpSinkNativeInterface",
                   javaMethods);
  GET_JAVA_METHODS(env, "com/android/bluetooth/a2dpsink/A2dpSinkNativeInterface", javaMethods);

  return 0;
}
}
}  // namespace android
Loading