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

Commit df016840 authored by Rongxuan Liu's avatar Rongxuan Liu Committed by Gerrit Code Review
Browse files

Merge "[le audio] remove the ending null bytes in native broadcast code" into main

parents 75196b9f 1d2f1cad
Loading
Loading
Loading
Loading
+4 −7
Original line number Diff line number Diff line
@@ -1045,16 +1045,14 @@ jobject prepareBluetoothLeBroadcastMetadataObject(
    return nullptr;
  }

  // Skip the leading null char bytes
  // Remove the ending null char bytes
  int nativeCodeSize = 16;
  int nativeCodeLeadingZeros = 0;
  if (broadcast_metadata.broadcast_code) {
    auto& nativeCode = broadcast_metadata.broadcast_code.value();
    nativeCodeLeadingZeros =
    nativeCodeSize =
        std::find_if(nativeCode.cbegin(), nativeCode.cend(),
                     [](int x) { return x != 0x00; }) -
                     [](int x) { return x == 0x00; }) -
        nativeCode.cbegin();
    nativeCodeSize = nativeCode.size() - nativeCodeLeadingZeros;
  }

  ScopedLocalRef<jbyteArray> code(env, env->NewByteArray(nativeCodeSize));
@@ -1066,8 +1064,7 @@ jobject prepareBluetoothLeBroadcastMetadataObject(
  if (broadcast_metadata.broadcast_code) {
    env->SetByteArrayRegion(
        code.get(), 0, nativeCodeSize,
        (const jbyte*)broadcast_metadata.broadcast_code->data() +
            nativeCodeLeadingZeros);
        (const jbyte*)broadcast_metadata.broadcast_code->data());
    CHECK(!env->ExceptionCheck());
  }