diff options
author | Mike Lockwood <lockwood@google.com> | 2014-05-21 15:49:09 +0000 |
---|---|---|
committer | Android Partner Code Review <android-gerrit-partner@google.com> | 2014-05-21 15:49:09 +0000 |
commit | d74ba4930e66087ecfe7e307f1a27e895df31d97 (patch) | |
tree | 74b4c2e6225fbdaef4bed78ec64d1a396ba062b3 /jni | |
parent | b16d4b64de7643ba9c28fc62f768463cde1f9420 (diff) | |
parent | e013986fbc8796db569587afa5c6b34e53d7a31b (diff) | |
download | android_packages_apps_Bluetooth-d74ba4930e66087ecfe7e307f1a27e895df31d97.tar.gz android_packages_apps_Bluetooth-d74ba4930e66087ecfe7e307f1a27e895df31d97.tar.bz2 android_packages_apps_Bluetooth-d74ba4930e66087ecfe7e307f1a27e895df31d97.zip |
Merge "[4/4] Add Support for AVRCP Controller Feature" into klp-wireless-dev
Diffstat (limited to 'jni')
-rw-r--r-- | jni/com_android_bluetooth_avrcp.cpp | 74 |
1 files changed, 72 insertions, 2 deletions
diff --git a/jni/com_android_bluetooth_avrcp.cpp b/jni/com_android_bluetooth_avrcp.cpp index 8f342f19f..049d0d2df 100644 --- a/jni/com_android_bluetooth_avrcp.cpp +++ b/jni/com_android_bluetooth_avrcp.cpp @@ -32,6 +32,8 @@ static jmethodID method_getElementAttr; static jmethodID method_registerNotification; static jmethodID method_volumeChangeCallback; static jmethodID method_handlePassthroughCmd; +static jmethodID method_handlePassthroughRsp; +static jmethodID method_onConnectionStateChanged; static const btrc_interface_t *sBluetoothAvrcpInterface = NULL; static jobject mCallbacksObj = NULL; @@ -142,6 +144,46 @@ static void btavrcp_passthrough_command_callback(int id, int pressed) { checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); } +static void btavrcp_passthrough_response_callback(int id, int pressed) { + ALOGI("%s", __FUNCTION__); + ALOGI("id: %d, pressed: %d", id, pressed); + + if (!checkCallbackThread()) { + ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__); + return; + } + + sCallbackEnv->CallVoidMethod(mCallbacksObj, method_handlePassthroughRsp, (jint)id, + (jint)pressed); + checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); +} + +static void btavrcp_connection_state_callback(int state, bt_bdaddr_t* bd_addr) { + jbyteArray addr; + + ALOGI("%s", __FUNCTION__); + ALOGI("conn state: %d", state); + + if (!checkCallbackThread()) { \ + ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__); \ + return; \ + } + + addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); + if (!addr) { + ALOGE("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_onConnectionStateChanged, (jint) state, + addr); + checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); + sCallbackEnv->DeleteLocalRef(addr); +} + + static btrc_callbacks_t sBluetoothAvrcpCallbacks = { sizeof(sBluetoothAvrcpCallbacks), btavrcp_remote_features_callback, @@ -155,7 +197,9 @@ static btrc_callbacks_t sBluetoothAvrcpCallbacks = { btavrcp_get_element_attr_callback, btavrcp_register_notification_callback, btavrcp_volume_change_callback, - btavrcp_passthrough_command_callback + btavrcp_passthrough_command_callback, + btavrcp_passthrough_response_callback, + btavrcp_connection_state_callback }; static void classInitNative(JNIEnv* env, jclass clazz) { @@ -176,6 +220,12 @@ static void classInitNative(JNIEnv* env, jclass clazz) { method_handlePassthroughCmd = env->GetMethodID(clazz, "handlePassthroughCmd", "(II)V"); + method_handlePassthroughRsp = + env->GetMethodID(clazz, "handlePassthroughRsp", "(II)V"); + + method_onConnectionStateChanged = + env->GetMethodID(clazz, "onConnectionStateChanged", "(I[B)V"); + ALOGI("%s: succeeds", __FUNCTION__); } @@ -395,6 +445,24 @@ static jboolean setVolumeNative(JNIEnv *env, jobject object, jint volume) { return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; } +static jboolean sendPassThroughCommandNative(JNIEnv *env, jobject object, + jint key_code, jint key_state) { + bt_status_t status; + + if (!sBluetoothAvrcpInterface) return JNI_FALSE; + + ALOGI("%s: sBluetoothAvrcpInterface: %p", __FUNCTION__, sBluetoothAvrcpInterface); + + ALOGI("key_code: %d, key_state: %d", key_code, key_state); + + if ((status = sBluetoothAvrcpInterface->send_pass_through_cmd((uint8_t)key_code, + (uint8_t)key_state))!= BT_STATUS_SUCCESS) { + ALOGE("Failed sending passthru command, status: %d", status); + } + + return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; +} + static JNINativeMethod sMethods[] = { {"classInitNative", "()V", (void *) classInitNative}, {"initNative", "()V", (void *) initNative}, @@ -408,7 +476,9 @@ static JNINativeMethod sMethods[] = { {"registerNotificationRspPlayPosNative", "(II)Z", (void *) registerNotificationRspPlayPosNative}, {"setVolumeNative", "(I)Z", - (void *) setVolumeNative} + (void *) setVolumeNative}, + {"sendPassThroughCommandNative", "(II)Z", + (void *) sendPassThroughCommandNative}, }; int register_com_android_bluetooth_avrcp(JNIEnv* env) |