Loading jni/com_android_bluetooth_a2dp.cpp +30 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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) { Loading Loading @@ -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__); } Loading src/com/android/bluetooth/a2dp/A2dpNativeInterface.java +16 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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, Loading Loading
jni/com_android_bluetooth_a2dp.cpp +30 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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) { Loading Loading @@ -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__); } Loading
src/com/android/bluetooth/a2dp/A2dpNativeInterface.java +16 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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, Loading