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

Commit 968083cb authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 6469672 from b0c3e827 to rvc-release

Change-Id: Ifecb8d0395ace5b0f0884a45ef5f327e5fb9ca93
parents 0e63859a b0c3e827
Loading
Loading
Loading
Loading
+30 −2
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ namespace android {
static jmethodID method_onConnectionStateChanged;
static jmethodID method_onAudioStateChanged;
static jmethodID method_onCodecConfigChanged;
static jmethodID method_isMandatoryCodecPreferred;

static struct {
  jclass clazz;
@@ -162,9 +163,33 @@ static void bta2dp_audio_config_callback(
      local_capabilities_array, selectable_capabilities_array);
}

static bool bta2dp_mandatory_codec_preferred_callback(
    const RawAddress& bd_addr) {
  ALOGI("%s", __func__);

  std::shared_lock<std::shared_timed_mutex> lock(callbacks_mutex);
  CallbackEnv sCallbackEnv(__func__);
  if (!sCallbackEnv.valid() || mCallbacksObj == nullptr) return false;

  ScopedLocalRef<jbyteArray> addr(
      sCallbackEnv.get(), sCallbackEnv->NewByteArray(RawAddress::kLength));
  if (!addr.get()) {
    ALOGE("%s: Fail to new jbyteArray bd addr", __func__);
    return false;
  }
  sCallbackEnv->SetByteArrayRegion(
      addr.get(), 0, RawAddress::kLength,
      reinterpret_cast<const jbyte*>(bd_addr.address));
  return sCallbackEnv->CallBooleanMethod(
      mCallbacksObj, method_isMandatoryCodecPreferred, addr.get());
}

static btav_source_callbacks_t sBluetoothA2dpCallbacks = {
    sizeof(sBluetoothA2dpCallbacks), bta2dp_connection_state_callback,
    bta2dp_audio_state_callback, bta2dp_audio_config_callback,
    sizeof(sBluetoothA2dpCallbacks),
    bta2dp_connection_state_callback,
    bta2dp_audio_state_callback,
    bta2dp_audio_config_callback,
    bta2dp_mandatory_codec_preferred_callback,
};

static void classInitNative(JNIEnv* env, jclass clazz) {
@@ -203,6 +228,9 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
                       "[Landroid/bluetooth/BluetoothCodecConfig;"
                       "[Landroid/bluetooth/BluetoothCodecConfig;)V");

  method_isMandatoryCodecPreferred =
      env->GetMethodID(clazz, "isMandatoryCodecPreferred", "([B)Z");

  ALOGI("%s: succeeds", __func__);
}

+16 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
 */
package com.android.bluetooth.a2dp;

import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothCodecStatus;
@@ -203,6 +204,21 @@ public class A2dpNativeInterface {
        sendMessageToService(event);
    }

    private boolean isMandatoryCodecPreferred(byte[] address) {
        A2dpService service = A2dpService.getA2dpService();
        if (service != null) {
            int enabled = service.getOptionalCodecsEnabled(getDevice(address));
            if (DBG) {
                Log.d(TAG, "isMandatoryCodecPreferred: optional preference " + enabled);
            }
            // Optional codecs are more preferred if possible
            return enabled == BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED;
        } else {
            Log.w(TAG, "isMandatoryCodecPreferred: service not available");
            return false;
        }
    }

    // Native methods that call into the JNI interface
    private static native void classInitNative();
    private native void initNative(int maxConnectedAudioDevices,