diff options
author | Kausik Sinnaswamy <kausik@broadcom.com> | 2012-04-20 00:24:28 +0530 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-07-16 22:00:36 -0700 |
commit | ac234ef0ddd67471d82f77c41535a5ea1b68b443 (patch) | |
tree | f1b8725eafcf594f9ecb2d8d3a23045003721eea /jni/com_android_bluetooth_a2dp.cpp | |
parent | bbbfba6398ac613896a4456fae1c9bf909c28bf2 (diff) | |
download | android_packages_apps_Bluetooth-ac234ef0ddd67471d82f77c41535a5ea1b68b443.tar.gz android_packages_apps_Bluetooth-ac234ef0ddd67471d82f77c41535a5ea1b68b443.tar.bz2 android_packages_apps_Bluetooth-ac234ef0ddd67471d82f77c41535a5ea1b68b443.zip |
Added support to handle A2DP audio state changed events and broadcast
A2dp API intents
Change-Id: I1938e5e0acbbaf602239e14e1dfd3c890712930a
Diffstat (limited to 'jni/com_android_bluetooth_a2dp.cpp')
-rw-r--r-- | jni/com_android_bluetooth_a2dp.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/jni/com_android_bluetooth_a2dp.cpp b/jni/com_android_bluetooth_a2dp.cpp index 710530e29..1dbbd6149 100644 --- a/jni/com_android_bluetooth_a2dp.cpp +++ b/jni/com_android_bluetooth_a2dp.cpp @@ -14,6 +14,7 @@ namespace android { static jmethodID method_onConnectionStateChanged; +static jmethodID method_onAudioStateChanged; static const btav_interface_t *sBluetoothA2dpInterface = NULL; static jobject mCallbacksObj = NULL; @@ -56,9 +57,33 @@ static void bta2dp_connection_state_callback(btav_connection_state_t state, bt_b sCallbackEnv->DeleteLocalRef(addr); } +static void bta2dp_audio_state_callback(btav_audio_state_t state, bt_bdaddr_t* bd_addr) { + jbyteArray addr; + + LOGI("%s", __FUNCTION__); + + if (!checkCallbackThread()) { \ + LOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__); \ + return; \ + } + addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); + if (!addr) { + LOGE("Fail to new jbyteArray bd addr for connection state"); + checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); + return; + } + + sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), (jbyte*) bd_addr); + sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAudioStateChanged, (jint) state, + addr); + checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); + sCallbackEnv->DeleteLocalRef(addr); +} + static btav_callbacks_t sBluetoothA2dpCallbacks = { sizeof(sBluetoothA2dpCallbacks), bta2dp_connection_state_callback, + bta2dp_audio_state_callback }; static void classInitNative(JNIEnv* env, jclass clazz) { @@ -69,6 +94,8 @@ static void classInitNative(JNIEnv* env, jclass clazz) { method_onConnectionStateChanged = env->GetMethodID(clazz, "onConnectionStateChanged", "(I[B)V"); + method_onAudioStateChanged = + env->GetMethodID(clazz, "onAudioStateChanged", "(I[B)V"); /* if ( (btInf = getBluetoothInterface()) == NULL) { LOGE("Bluetooth module is not loaded"); |