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

Commit 7f71c4d0 authored by Jakub Tyszkowski's avatar Jakub Tyszkowski Committed by Automerger Merge Worker
Browse files

leaudio: Rework selecting Broadcast Audio stream parameters am: 742dc966

parents 31a330e9 742dc966
Loading
Loading
Loading
Loading
+2 −4
Original line number Original line Diff line number Diff line
@@ -25,7 +25,6 @@
#include "com_android_bluetooth.h"
#include "com_android_bluetooth.h"
#include "hardware/bt_le_audio.h"
#include "hardware/bt_le_audio.h"


using bluetooth::le_audio::BroadcastAudioProfile;
using bluetooth::le_audio::BroadcastId;
using bluetooth::le_audio::BroadcastId;
using bluetooth::le_audio::BroadcastState;
using bluetooth::le_audio::BroadcastState;
using bluetooth::le_audio::btle_audio_codec_config_t;
using bluetooth::le_audio::btle_audio_codec_config_t;
@@ -1125,7 +1124,7 @@ static void BroadcasterCleanupNative(JNIEnv* env, jobject object) {
}
}


static void CreateBroadcastNative(JNIEnv* env, jobject object,
static void CreateBroadcastNative(JNIEnv* env, jobject object,
                                  jbyteArray metadata, jint audio_profile,
                                  jbyteArray metadata,
                                  jbyteArray broadcast_code) {
                                  jbyteArray broadcast_code) {
  LOG(INFO) << __func__;
  LOG(INFO) << __func__;
  std::shared_lock<std::shared_timed_mutex> lock(sBroadcasterInterfaceMutex);
  std::shared_lock<std::shared_timed_mutex> lock(sBroadcasterInterfaceMutex);
@@ -1140,7 +1139,6 @@ static void CreateBroadcastNative(JNIEnv* env, jobject object,
  jbyte* meta = env->GetByteArrayElements(metadata, nullptr);
  jbyte* meta = env->GetByteArrayElements(metadata, nullptr);
  sLeAudioBroadcasterInterface->CreateBroadcast(
  sLeAudioBroadcasterInterface->CreateBroadcast(
      std::vector<uint8_t>(meta, meta + env->GetArrayLength(metadata)),
      std::vector<uint8_t>(meta, meta + env->GetArrayLength(metadata)),
      static_cast<BroadcastAudioProfile>(audio_profile),
      broadcast_code ? std::optional<std::array<uint8_t, 16>>(code_array)
      broadcast_code ? std::optional<std::array<uint8_t, 16>>(code_array)
                     : std::nullopt);
                     : std::nullopt);
  env->ReleaseByteArrayElements(metadata, meta, 0);
  env->ReleaseByteArrayElements(metadata, meta, 0);
@@ -1200,7 +1198,7 @@ static JNINativeMethod sBroadcasterMethods[] = {
    {"initNative", "()V", (void*)BroadcasterInitNative},
    {"initNative", "()V", (void*)BroadcasterInitNative},
    {"stopNative", "()V", (void*)BroadcasterStopNative},
    {"stopNative", "()V", (void*)BroadcasterStopNative},
    {"cleanupNative", "()V", (void*)BroadcasterCleanupNative},
    {"cleanupNative", "()V", (void*)BroadcasterCleanupNative},
    {"createBroadcastNative", "([BI[B)V", (void*)CreateBroadcastNative},
    {"createBroadcastNative", "([B[B)V", (void*)CreateBroadcastNative},
    {"updateMetadataNative", "(I[B)V", (void*)UpdateMetadataNative},
    {"updateMetadataNative", "(I[B)V", (void*)UpdateMetadataNative},
    {"startBroadcastNative", "(I)V", (void*)StartBroadcastNative},
    {"startBroadcastNative", "(I)V", (void*)StartBroadcastNative},
    {"stopBroadcastNative", "(I)V", (void*)StopBroadcastNative},
    {"stopBroadcastNative", "(I)V", (void*)StopBroadcastNative},
+3 −4
Original line number Original line Diff line number Diff line
@@ -169,12 +169,11 @@ public class LeAudioBroadcasterNativeInterface {
     * Creates LeAudio Broadcast instance.
     * Creates LeAudio Broadcast instance.
     *
     *
     * @param metadata metadata buffer with TLVs
     * @param metadata metadata buffer with TLVs
     * @param audioProfile broadcast audio profile
     * @param broadcastCode optional code if broadcast should be encrypted
     * @param broadcastCode optional code if broadcast should be encrypted
     */
     */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    public void createBroadcast(byte[] metadata, int audioProfile, byte[] broadcastCode) {
    public void createBroadcast(byte[] metadata, byte[] broadcastCode) {
        createBroadcastNative(metadata, audioProfile, broadcastCode);
        createBroadcastNative(metadata, broadcastCode);
    }
    }


    /**
    /**
@@ -241,7 +240,7 @@ public class LeAudioBroadcasterNativeInterface {
    private native void initNative();
    private native void initNative();
    private native void stopNative();
    private native void stopNative();
    private native void cleanupNative();
    private native void cleanupNative();
    private native void createBroadcastNative(byte[] metadata, int profile, byte[] broadcastCode);
    private native void createBroadcastNative(byte[] metadata, byte[] broadcastCode);
    private native void updateMetadataNative(int broadcastId, byte[] metadata);
    private native void updateMetadataNative(int broadcastId, byte[] metadata);
    private native void startBroadcastNative(int broadcastId);
    private native void startBroadcastNative(int broadcastId);
    private native void stopBroadcastNative(int broadcastId);
    private native void stopBroadcastNative(int broadcastId);
+1 −9
Original line number Original line Diff line number Diff line
@@ -105,12 +105,6 @@ public class LeAudioService extends ProfileService {
     */
     */
    private static final int ACTIVE_CONTEXTS_NONE = 0;
    private static final int ACTIVE_CONTEXTS_NONE = 0;


    /*
     * Brodcast profile used by the lower layers
     */
    private static final int BROADCAST_PROFILE_SONIFICATION = 0;
    private static final int BROADCAST_PROFILE_MEDIA = 1;

    private AdapterService mAdapterService;
    private AdapterService mAdapterService;
    private DatabaseManager mDatabaseManager;
    private DatabaseManager mDatabaseManager;
    private HandlerThread mStateMachinesThread;
    private HandlerThread mStateMachinesThread;
@@ -664,8 +658,6 @@ public class LeAudioService extends ProfileService {
    /**
    /**
     * Creates LeAudio Broadcast instance.
     * Creates LeAudio Broadcast instance.
     * @param metadata metadata buffer with TLVs
     * @param metadata metadata buffer with TLVs
     * @param audioProfile broadcast audio profile
     * @param broadcastCode optional code if broadcast should be encrypted
     */
     */
    public void createBroadcast(BluetoothLeAudioContentMetadata metadata, byte[] broadcastCode) {
    public void createBroadcast(BluetoothLeAudioContentMetadata metadata, byte[] broadcastCode) {
        if (mLeAudioBroadcasterNativeInterface == null) {
        if (mLeAudioBroadcasterNativeInterface == null) {
@@ -673,7 +665,7 @@ public class LeAudioService extends ProfileService {
            return;
            return;
        }
        }
        mLeAudioBroadcasterNativeInterface.createBroadcast(metadata.getRawMetadata(),
        mLeAudioBroadcasterNativeInterface.createBroadcast(metadata.getRawMetadata(),
                BROADCAST_PROFILE_MEDIA, broadcastCode);
                broadcastCode);
    }
    }


    /**
    /**
+2 −3
Original line number Original line Diff line number Diff line
@@ -239,7 +239,7 @@ public class LeAudioBroadcastServiceTest {
            BluetoothLeAudioContentMetadata meta) {
            BluetoothLeAudioContentMetadata meta) {
        mService.createBroadcast(meta, code);
        mService.createBroadcast(meta, code);


        verify(mNativeInterface, times(1)).createBroadcast(eq(meta.getRawMetadata()), eq(1),
        verify(mNativeInterface, times(1)).createBroadcast(eq(meta.getRawMetadata()),
                eq(code));
                eq(code));


        // Check if broadcast is started automatically when created
        // Check if broadcast is started automatically when created
@@ -321,8 +321,7 @@ public class LeAudioBroadcastServiceTest {
        BluetoothLeAudioContentMetadata meta = meta_builder.build();
        BluetoothLeAudioContentMetadata meta = meta_builder.build();
        mService.createBroadcast(meta, code);
        mService.createBroadcast(meta, code);


        verify(mNativeInterface, times(1)).createBroadcast(eq(meta.getRawMetadata()), eq(1),
        verify(mNativeInterface, times(1)).createBroadcast(eq(meta.getRawMetadata()), eq(code));
                eq(code));


        LeAudioStackEvent create_event =
        LeAudioStackEvent create_event =
                new LeAudioStackEvent(LeAudioStackEvent.EVENT_TYPE_BROADCAST_CREATED);
                new LeAudioStackEvent(LeAudioStackEvent.EVENT_TYPE_BROADCAST_CREATED);
+4 −4
Original line number Original line Diff line number Diff line
@@ -1222,7 +1222,7 @@ public class BluetoothProxy {


            switchToPreviousPresetMethod.invoke(bluetoothHapClient, device);
            switchToPreviousPresetMethod.invoke(bluetoothHapClient, device);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            // Do nothing
            return false;
        }
        }
        return true;
        return true;
    }
    }
@@ -1239,7 +1239,7 @@ public class BluetoothProxy {


            switchToNextPresetMethod.invoke(bluetoothHapClient, device);
            switchToNextPresetMethod.invoke(bluetoothHapClient, device);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            // Do nothing
            return false;
        }
        }
        return true;
        return true;
    }
    }
@@ -1256,7 +1256,7 @@ public class BluetoothProxy {


            switchToPreviousPresetForGroupMethod.invoke(bluetoothHapClient, group_id);
            switchToPreviousPresetForGroupMethod.invoke(bluetoothHapClient, group_id);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            // Do nothing
            return false;
        }
        }
        return true;
        return true;
    }
    }
@@ -1273,7 +1273,7 @@ public class BluetoothProxy {


            switchToNextPresetForGroupMethod.invoke(bluetoothHapClient, group_id);
            switchToNextPresetForGroupMethod.invoke(bluetoothHapClient, group_id);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            // Do nothing
            return false;
        }
        }
        return true;
        return true;
    }
    }
Loading