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

Commit f2180c81 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "A2DP: Send codec offloading preferences to stack for hybrid mode."

parents 6937cb79 7dcfbf6e
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -259,7 +259,8 @@ static std::vector<btav_a2dp_codec_config_t> prepareCodecPreferences(

static void initNative(JNIEnv* env, jobject object,
                       jint maxConnectedAudioDevices,
                       jobjectArray codecConfigArray) {
                       jobjectArray codecConfigArray,
                       jobjectArray codecOffloadingArray) {
  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,12 @@ static void initNative(JNIEnv* env, jobject object,
  std::vector<btav_a2dp_codec_config_t> codec_priorities =
      prepareCodecPreferences(env, object, codecConfigArray);

  std::vector<btav_a2dp_codec_config_t> codec_offloading =
      prepareCodecPreferences(env, object, codecOffloadingArray);

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

static JNINativeMethod sMethods[] = {
    {"classInitNative", "()V", (void*)classInitNative},
    {"initNative", "(I[Landroid/bluetooth/BluetoothCodecConfig;)V",
    {"initNative",
     "(I[Landroid/bluetooth/BluetoothCodecConfig;[Landroid/bluetooth/BluetoothCodecConfig;)V",
     (void*)initNative},
    {"cleanupNative", "()V", (void*)cleanupNative},
    {"connectA2dpNative", "([B)Z", (void*)connectA2dpNative},
+15 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.media.AudioManager;
import android.util.Log;

import com.android.bluetooth.R;
@@ -51,16 +52,30 @@ class A2dpCodecConfig {
    private @CodecPriority int mA2dpSourceCodecPriorityLdac =
            BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT;

    private BluetoothCodecConfig[] mCodecConfigOffloading = new BluetoothCodecConfig[0];

    A2dpCodecConfig(Context context, A2dpNativeInterface a2dpNativeInterface) {
        mContext = context;
        mA2dpNativeInterface = a2dpNativeInterface;
        mCodecConfigPriorities = assignCodecConfigPriorities();

        AudioManager audioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
        if (audioManager == null) {
          Log.w(TAG, "Can't obtain the codec offloading prefernece from null AudioManager");
          return;
        }
        mCodecConfigOffloading = audioManager.getHwOffloadEncodingFormatsSupportedForA2DP()
                                             .toArray(mCodecConfigOffloading);
    }

    BluetoothCodecConfig[] codecConfigPriorities() {
        return mCodecConfigPriorities;
    }

    BluetoothCodecConfig[] codecConfigOffloading() {
        return mCodecConfigOffloading;
    }

    void setCodecConfigPreference(BluetoothDevice device,
                                  BluetoothCodecStatus codecStatus,
                                  BluetoothCodecConfig newCodecConfig) {
+5 −3
Original line number Diff line number Diff line
@@ -75,8 +75,9 @@ public class A2dpNativeInterface {
     * @param codecConfigPriorities an array with the codec configuration
     * priorities to configure.
     */
    public void init(int maxConnectedAudioDevices, BluetoothCodecConfig[] codecConfigPriorities) {
        initNative(maxConnectedAudioDevices, codecConfigPriorities);
    public void init(int maxConnectedAudioDevices, BluetoothCodecConfig[] codecConfigPriorities,
            BluetoothCodecConfig[] codecConfigOffloading) {
        initNative(maxConnectedAudioDevices, codecConfigPriorities, codecConfigOffloading);
    }

    /**
@@ -205,7 +206,8 @@ public class A2dpNativeInterface {
    // Native methods that call into the JNI interface
    private static native void classInitNative();
    private native void initNative(int maxConnectedAudioDevices,
                                   BluetoothCodecConfig[] codecConfigPriorities);
                                   BluetoothCodecConfig[] codecConfigPriorities,
                                   BluetoothCodecConfig[] codecConfigOffloading);
    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
@@ -129,7 +129,8 @@ public class A2dpService extends ProfileService {

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

        // Step 6: Check if A2DP is in offload mode
        mA2dpOffloadEnabled = mAdapterService.isA2dpOffloadEnabled();