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

Commit 6b426900 authored by Pavlin Radoslavov's avatar Pavlin Radoslavov
Browse files

Initialize max number of connected A2DP devices in the native stack via JNI

Pass the maximum number of connected A2DP devices from Java to the
native stack as a parameter to the init() call.

Bug: 72351654
Test: Manual: Connect to multiple A2DP devices, check the log messages
Change-Id: Ida39267038e225e7a83a563dee2b7f862c02a851
parent 2a1b62e2
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -259,6 +259,7 @@ static std::vector<btav_a2dp_codec_config_t> prepareCodecPreferences(
}

static void initNative(JNIEnv* env, jobject object,
                       jint maxConnectedAudioDevices,
                       jobjectArray codecConfigArray) {
  std::unique_lock<std::shared_timed_mutex> interface_lock(interface_mutex);
  std::unique_lock<std::shared_timed_mutex> callbacks_lock(callbacks_mutex);
@@ -305,8 +306,8 @@ static void initNative(JNIEnv* env, jobject object,
  std::vector<btav_a2dp_codec_config_t> codec_priorities =
      prepareCodecPreferences(env, object, codecConfigArray);

  bt_status_t status =
      sBluetoothA2dpInterface->init(&sBluetoothA2dpCallbacks, codec_priorities);
  bt_status_t status = sBluetoothA2dpInterface->init(
      &sBluetoothA2dpCallbacks, maxConnectedAudioDevices, codec_priorities);
  if (status != BT_STATUS_SUCCESS) {
    ALOGE("%s: Failed to initialize Bluetooth A2DP, status: %d", __func__,
          status);
@@ -444,7 +445,7 @@ static jboolean setCodecConfigPreferenceNative(JNIEnv* env, jobject object,

static JNINativeMethod sMethods[] = {
    {"classInitNative", "()V", (void*)classInitNative},
    {"initNative", "([Landroid/bluetooth/BluetoothCodecConfig;)V",
    {"initNative", "(I[Landroid/bluetooth/BluetoothCodecConfig;)V",
     (void*)initNative},
    {"cleanupNative", "()V", (void*)cleanupNative},
    {"connectA2dpNative", "([B)Z", (void*)connectA2dpNative},
+6 −3
Original line number Diff line number Diff line
@@ -70,11 +70,13 @@ public class A2dpNativeInterface {
    /**
     * Initializes the native interface.
     *
     * @param maxConnectedAudioDevices maximum number of A2DP Sink devices that can be connected
     * simultaneously
     * @param codecConfigPriorities an array with the codec configuration
     * priorities to configure.
     */
    public void init(BluetoothCodecConfig[] codecConfigPriorities) {
        initNative(codecConfigPriorities);
    public void init(int maxConnectedAudioDevices, BluetoothCodecConfig[] codecConfigPriorities) {
        initNative(maxConnectedAudioDevices, codecConfigPriorities);
    }

    /**
@@ -192,7 +194,8 @@ public class A2dpNativeInterface {

    // Native methods that call into the JNI interface
    private static native void classInitNative();
    private native void initNative(BluetoothCodecConfig[] codecConfigPriorities);
    private native void initNative(int maxConnectedAudioDevices,
                                   BluetoothCodecConfig[] codecConfigPriorities);
    private native void cleanupNative();
    private native boolean connectA2dpNative(byte[] address);
    private native boolean disconnectA2dpNative(byte[] address);
+2 −1
Original line number Diff line number Diff line
@@ -125,7 +125,8 @@ public class A2dpService extends ProfileService {
        mA2dpCodecConfig = new A2dpCodecConfig(this, mA2dpNativeInterface);

        // Step 6: Initialize native interface
        mA2dpNativeInterface.init(mA2dpCodecConfig.codecConfigPriorities());
        mA2dpNativeInterface.init(mMaxConnectedAudioDevices,
                                  mA2dpCodecConfig.codecConfigPriorities());

        // Step 7: Setup broadcast receivers
        IntentFilter filter = new IntentFilter();