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