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

Commit a2d7320b authored by Jakub Tyszkowski's avatar Jakub Tyszkowski
Browse files

Broadcaster: Handle short broadcast codes

Bug: 240929404
Tag: #feature
Test: atest BluetoothInstrumentationTests
Change-Id: If76299079e73fd9644b5314cda3f1c109e5c92f7
parent 11320c40
Loading
Loading
Loading
Loading
+9 −2
Original line number Original line Diff line number Diff line
@@ -1130,10 +1130,17 @@ static void CreateBroadcastNative(JNIEnv* env, jobject object,
  std::shared_lock<std::shared_timed_mutex> lock(sBroadcasterInterfaceMutex);
  std::shared_lock<std::shared_timed_mutex> lock(sBroadcasterInterfaceMutex);
  if (!sLeAudioBroadcasterInterface) return;
  if (!sLeAudioBroadcasterInterface) return;


  std::array<uint8_t, 16> code_array{};
  std::array<uint8_t, 16> code_array{0};
  if (broadcast_code) {
  if (broadcast_code) {
    jsize size = env->GetArrayLength(broadcast_code);
    jsize size = env->GetArrayLength(broadcast_code);
    env->GetByteArrayRegion(broadcast_code, 0, size, (jbyte*)code_array.data());
    if (size > 16) {
      ALOGE("%s: broadcast code to long", __func__);
      return;
    }

    // Padding with zeros on LSB positions if code is shorter than 16 octets
    env->GetByteArrayRegion(broadcast_code, code_array.size() - size, size,
                            (jbyte*)code_array.data());
  }
  }


  jbyte* meta = env->GetByteArrayElements(metadata, nullptr);
  jbyte* meta = env->GetByteArrayElements(metadata, nullptr);
+9 −0
Original line number Original line Diff line number Diff line
@@ -664,6 +664,15 @@ public class LeAudioService extends ProfileService {
            Log.w(TAG, "Native interface not available.");
            Log.w(TAG, "Native interface not available.");
            return;
            return;
        }
        }
        boolean isEncrypted = (broadcastCode != null) && (broadcastCode.length != 0);
        if (isEncrypted) {
            if ((broadcastCode.length > 16) || (broadcastCode.length < 4)) {
                Log.e(TAG, "Invalid broadcast code length. Should be from 4 to 16 octets long.");
                return;
            }
        }

        Log.i(TAG, "createBroadcast: isEncrypted=" + (isEncrypted ? "true" : "false"));
        mLeAudioBroadcasterNativeInterface.createBroadcast(metadata.getRawMetadata(),
        mLeAudioBroadcasterNativeInterface.createBroadcast(metadata.getRawMetadata(),
                broadcastCode);
                broadcastCode);
    }
    }
+3 −3
Original line number Original line Diff line number Diff line
@@ -299,7 +299,7 @@ public class LeAudioBroadcastServiceTest {
    @Test
    @Test
    public void testCreateBroadcastNative() {
    public void testCreateBroadcastNative() {
        int broadcastId = 243;
        int broadcastId = 243;
        byte[] code = {0x00, 0x01, 0x00};
        byte[] code = {0x00, 0x01, 0x00, 0x02};


        mService.mBroadcastCallbacks.register(mCallbacks);
        mService.mBroadcastCallbacks.register(mCallbacks);


@@ -314,7 +314,7 @@ public class LeAudioBroadcastServiceTest {
    @Test
    @Test
    public void testCreateBroadcastNativeFailed() {
    public void testCreateBroadcastNativeFailed() {
        int broadcastId = 243;
        int broadcastId = 243;
        byte[] code = {0x00, 0x01, 0x00};
        byte[] code = {0x00, 0x01, 0x00, 0x02};


        mService.mBroadcastCallbacks.register(mCallbacks);
        mService.mBroadcastCallbacks.register(mCallbacks);


@@ -340,7 +340,7 @@ public class LeAudioBroadcastServiceTest {
    @Test
    @Test
    public void testStartStopBroadcastNative() {
    public void testStartStopBroadcastNative() {
        int broadcastId = 243;
        int broadcastId = 243;
        byte[] code = {0x00, 0x01, 0x00};
        byte[] code = {0x00, 0x01, 0x00, 0x02};


        mService.mBroadcastCallbacks.register(mCallbacks);
        mService.mBroadcastCallbacks.register(mCallbacks);