From 2116dbf94fbc00da999ac629c78627983f599a26 Mon Sep 17 00:00:00 2001 From: Andre Eisenbach Date: Fri, 17 Mar 2017 04:47:41 +0000 Subject: [PATCH] Revert "jni: introduce ScopedBtAddr" Causes crash on Fugu. Reverting for now until further investigation. This reverts commit 2b233628767c0bf6ff21ae2acdeada8bea94e583. Change-Id: I21daf6b75312695d7ccb83ae603aaeffc3c9e770 --- jni/Android.mk | 3 +- jni/com_android_bluetooth.h | 4 +- jni/com_android_bluetooth_a2dp.cpp | 21 ++- jni/com_android_bluetooth_a2dp_sink.cpp | 31 +++- jni/com_android_bluetooth_avrcp.cpp | 161 ++++++++++++++++----- jni/com_android_bluetooth_avrcp_controller.cpp | 114 +++++++++++---- ..._android_bluetooth_btservice_AdapterService.cpp | 69 +++++++-- jni/com_android_bluetooth_hdp.cpp | 11 +- jni/com_android_bluetooth_hfp.cpp | 130 ++++++++++++----- jni/com_android_bluetooth_hfpclient.cpp | 55 ++++--- jni/com_android_bluetooth_hid.cpp | 50 +++++-- jni/com_android_bluetooth_hidd.cpp | 33 ++++- jni/com_android_bluetooth_pan.cpp | 22 ++- jni/com_android_bluetooth_sdp.cpp | 6 +- jni/scoped_bt_addr.cpp | 48 ------ jni/scoped_bt_addr.h | 45 ------ 16 files changed, 536 insertions(+), 267 deletions(-) delete mode 100644 jni/scoped_bt_addr.cpp delete mode 100644 jni/scoped_bt_addr.h diff --git a/jni/Android.mk b/jni/Android.mk index 2f92611a..971b6149 100644 --- a/jni/Android.mk +++ b/jni/Android.mk @@ -15,8 +15,7 @@ LOCAL_SRC_FILES:= \ com_android_bluetooth_hdp.cpp \ com_android_bluetooth_pan.cpp \ com_android_bluetooth_gatt.cpp \ - com_android_bluetooth_sdp.cpp \ - scoped_bt_addr.cpp + com_android_bluetooth_sdp.cpp LOCAL_C_INCLUDES += \ $(JNI_H_INCLUDE) \ diff --git a/jni/com_android_bluetooth.h b/jni/com_android_bluetooth.h index 8a688470..50b4968f 100644 --- a/jni/com_android_bluetooth.h +++ b/jni/com_android_bluetooth.h @@ -62,9 +62,7 @@ public: return mCallbackEnv; } - const char* method_name() { return mName; } - - private: +private: JNIEnv *mCallbackEnv; const char *mName; diff --git a/jni/com_android_bluetooth_a2dp.cpp b/jni/com_android_bluetooth_a2dp.cpp index 32e89631..a2928ff5 100644 --- a/jni/com_android_bluetooth_a2dp.cpp +++ b/jni/com_android_bluetooth_a2dp.cpp @@ -21,7 +21,6 @@ #include "android_runtime/AndroidRuntime.h" #include "com_android_bluetooth.h" #include "hardware/bt_av.h" -#include "scoped_bt_addr.h" #include "utils/Log.h" #include @@ -54,9 +53,15 @@ static void bta2dp_connection_state_callback(btav_connection_state_t state, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for connection state"); + return; + } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onConnectionStateChanged, (jint)state, addr.get()); } @@ -67,9 +72,15 @@ static void bta2dp_audio_state_callback(btav_audio_state_t state, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for connection state"); + return; + } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAudioStateChanged, (jint)state, addr.get()); } diff --git a/jni/com_android_bluetooth_a2dp_sink.cpp b/jni/com_android_bluetooth_a2dp_sink.cpp index 4048b593..185fc699 100644 --- a/jni/com_android_bluetooth_a2dp_sink.cpp +++ b/jni/com_android_bluetooth_a2dp_sink.cpp @@ -21,7 +21,6 @@ #include "android_runtime/AndroidRuntime.h" #include "com_android_bluetooth.h" #include "hardware/bt_av.h" -#include "scoped_bt_addr.h" #include "utils/Log.h" #include @@ -40,9 +39,15 @@ static void bta2dp_connection_state_callback(btav_connection_state_t state, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for connection state"); + return; + } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onConnectionStateChanged, (jint)state, addr.get()); } @@ -53,9 +58,15 @@ static void bta2dp_audio_state_callback(btav_audio_state_t state, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for connection state"); + return; + } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAudioStateChanged, (jint)state, addr.get()); } @@ -67,9 +78,15 @@ static void bta2dp_audio_config_callback(bt_bdaddr_t* bd_addr, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for connection state"); + return; + } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAudioConfigChanged, addr.get(), (jint)sample_rate, (jint)channel_count); diff --git a/jni/com_android_bluetooth_avrcp.cpp b/jni/com_android_bluetooth_avrcp.cpp index 6cb23ae5..1e7af74a 100644 --- a/jni/com_android_bluetooth_avrcp.cpp +++ b/jni/com_android_bluetooth_avrcp.cpp @@ -21,7 +21,6 @@ #include "android_runtime/AndroidRuntime.h" #include "com_android_bluetooth.h" #include "hardware/bt_rc.h" -#include "scoped_bt_addr.h" #include "utils/Log.h" #include @@ -69,9 +68,15 @@ static void btavrcp_remote_features_callback(bt_bdaddr_t* bd_addr, return; } - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Unable to allocate byte array for bd_addr"); + return; + } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->CallVoidMethod(mCallbacksObj, method_getRcFeatures, addr.get(), (jint)features); } @@ -87,8 +92,15 @@ static void btavrcp_get_play_status_callback(bt_bdaddr_t* bd_addr) { return; } - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for get_play_status command"); + return; + } + + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->CallVoidMethod(mCallbacksObj, method_getPlayStatus, addr.get()); } @@ -104,8 +116,12 @@ static void btavrcp_get_element_attr_callback(uint8_t num_attr, return; } - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for get_element_attr command"); + return; + } ScopedLocalRef attrs( sCallbackEnv.get(), (jintArray)sCallbackEnv->NewIntArray(num_attr)); @@ -116,6 +132,8 @@ static void btavrcp_get_element_attr_callback(uint8_t num_attr, sCallbackEnv->SetIntArrayRegion(attrs.get(), 0, num_attr, (jint*)p_attrs); + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->CallVoidMethod(mCallbacksObj, method_getElementAttr, addr.get(), (jbyte)num_attr, attrs.get()); } @@ -131,9 +149,15 @@ static void btavrcp_register_notification_callback(btrc_event_id_t event_id, return; } - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for register_notification command"); + return; + } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->CallVoidMethod(mCallbacksObj, method_registerNotification, addr.get(), (jint)event_id, (jint)param); } @@ -149,8 +173,15 @@ static void btavrcp_volume_change_callback(uint8_t volume, uint8_t ctype, return; } - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for volume_change command"); + return; + } + + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->CallVoidMethod(mCallbacksObj, method_volumeChangeCallback, addr.get(), (jint)volume, (jint)ctype); @@ -167,8 +198,14 @@ static void btavrcp_passthrough_command_callback(int id, int pressed, return; } - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for passthrough_command command"); + return; + } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->CallVoidMethod(mCallbacksObj, method_handlePassthroughCmd, addr.get(), (jint)id, (jint)pressed); @@ -185,9 +222,15 @@ static void btavrcp_set_addressed_player_callback(uint16_t player_id, return; } - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for set_addressed_player command"); + return; + } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->CallVoidMethod(mCallbacksObj, method_setAddressedPlayerCallback, addr.get(), (jint)player_id); } @@ -202,8 +245,14 @@ static void btavrcp_set_browsed_player_callback(uint16_t player_id, return; } - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for set_browsed_player command"); + return; + } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->CallVoidMethod(mCallbacksObj, method_setBrowsedPlayerCallback, addr.get(), (jint)player_id); @@ -221,11 +270,17 @@ static void btavrcp_get_folder_items_callback( return; } - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for get_folder_items command"); + return; + } uint32_t* puiAttr = (uint32_t*)p_attr_ids; ScopedLocalRef attr_ids(sCallbackEnv.get(), NULL); + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); /* check number of attributes requested by remote device */ if ((num_attr != BTRC_NUM_ATTR_ALL) && (num_attr != BTRC_NUM_ATTR_NONE)) { @@ -256,9 +311,6 @@ static void btavrcp_change_path_callback(uint8_t direction, uint8_t* folder_uid, return; } - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; - ScopedLocalRef attrs(sCallbackEnv.get(), sCallbackEnv->NewByteArray(BTRC_UID_SIZE)); if (!attrs.get()) { @@ -266,6 +318,15 @@ static void btavrcp_change_path_callback(uint8_t direction, uint8_t* folder_uid, return; } + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for change_path command"); + return; + } + + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->SetByteArrayRegion( attrs.get(), 0, sizeof(uint8_t) * BTRC_UID_SIZE, (jbyte*)folder_uid); sCallbackEnv->CallVoidMethod(mCallbacksObj, method_changePathCallback, @@ -286,9 +347,6 @@ static void btavrcp_get_item_attr_callback(uint8_t scope, uint8_t* uid, return; } - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; - ScopedLocalRef attr_uid( sCallbackEnv.get(), sCallbackEnv->NewByteArray(BTRC_UID_SIZE)); if (!attr_uid.get()) { @@ -296,6 +354,13 @@ static void btavrcp_get_item_attr_callback(uint8_t scope, uint8_t* uid, return; } + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for get_item_attr command"); + return; + } + ScopedLocalRef attrs( sCallbackEnv.get(), (jintArray)sCallbackEnv->NewIntArray(num_attr)); if (!attrs.get()) { @@ -303,6 +368,8 @@ static void btavrcp_get_item_attr_callback(uint8_t scope, uint8_t* uid, return; } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->SetIntArrayRegion(attrs.get(), 0, num_attr, (jint*)p_attrs); sCallbackEnv->SetByteArrayRegion( attr_uid.get(), 0, sizeof(uint8_t) * BTRC_UID_SIZE, (jbyte*)uid); @@ -321,9 +388,6 @@ static void btavrcp_play_item_callback(uint8_t scope, uint16_t uid_counter, return; } - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; - ScopedLocalRef attrs(sCallbackEnv.get(), sCallbackEnv->NewByteArray(BTRC_UID_SIZE)); if (!attrs.get()) { @@ -331,6 +395,15 @@ static void btavrcp_play_item_callback(uint8_t scope, uint16_t uid_counter, return; } + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for play_item command"); + return; + } + + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->SetByteArrayRegion( attrs.get(), 0, sizeof(uint8_t) * BTRC_UID_SIZE, (jbyte*)uid); sCallbackEnv->CallVoidMethod(mCallbacksObj, method_playItemCallback, @@ -347,9 +420,15 @@ static void btavrcp_get_total_num_items_callback(uint8_t scope, return; } - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for get_total_num_items command"); + return; + } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->CallVoidMethod(mCallbacksObj, method_getTotalNumOfItemsCallback, addr.get(), (jbyte)scope); } @@ -363,9 +442,6 @@ static void btavrcp_search_callback(uint16_t charset_id, uint16_t str_len, return; } - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; - ScopedLocalRef attrs(sCallbackEnv.get(), sCallbackEnv->NewByteArray(str_len)); if (!attrs.get()) { @@ -373,6 +449,15 @@ static void btavrcp_search_callback(uint16_t charset_id, uint16_t str_len, return; } + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for search command"); + return; + } + + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->SetByteArrayRegion(attrs.get(), 0, str_len * sizeof(uint8_t), (jbyte*)p_str); sCallbackEnv->CallVoidMethod(mCallbacksObj, method_searchCallback, addr.get(), @@ -389,8 +474,12 @@ static void btavrcp_add_to_play_list_callback(uint8_t scope, uint8_t* uid, return; } - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for add_to_play_list command"); + return; + } ScopedLocalRef attrs(sCallbackEnv.get(), sCallbackEnv->NewByteArray(BTRC_UID_SIZE)); @@ -399,6 +488,8 @@ static void btavrcp_add_to_play_list_callback(uint8_t scope, uint8_t* uid, return; } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->SetByteArrayRegion( attrs.get(), 0, sizeof(uint8_t) * BTRC_UID_SIZE, (jbyte*)uid); sCallbackEnv->CallVoidMethod(mCallbacksObj, method_addToPlayListCallback, diff --git a/jni/com_android_bluetooth_avrcp_controller.cpp b/jni/com_android_bluetooth_avrcp_controller.cpp index be9b11c4..cd2f8885 100644 --- a/jni/com_android_bluetooth_avrcp_controller.cpp +++ b/jni/com_android_bluetooth_avrcp_controller.cpp @@ -21,7 +21,6 @@ #include "android_runtime/AndroidRuntime.h" #include "com_android_bluetooth.h" #include "hardware/bt_rc.h" -#include "scoped_bt_addr.h" #include "utils/Log.h" #include @@ -60,9 +59,15 @@ static void btavrcp_passthrough_response_callback(bt_bdaddr_t* bd_addr, int id, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for passthrough response"); + return; + } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handlePassthroughRsp, (jint)id, (jint)pressed, addr.get()); } @@ -82,9 +87,15 @@ static void btavrcp_connection_state_callback(bool rc_connect, bool br_connect, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for connection state"); + return; + } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->CallVoidMethod(sCallbacksObj, method_onConnectionStateChanged, (jboolean)rc_connect, (jboolean)br_connect, addr.get()); @@ -96,9 +107,15 @@ static void btavrcp_get_rcfeatures_callback(bt_bdaddr_t* bd_addr, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr "); + return; + } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->CallVoidMethod(sCallbacksObj, method_getRcFeatures, addr.get(), (jint)features); } @@ -109,9 +126,15 @@ static void btavrcp_setplayerapplicationsetting_rsp_callback( CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr "); + return; + } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->CallVoidMethod(sCallbacksObj, method_setplayerappsettingrsp, addr.get(), (jint)accepted); } @@ -123,9 +146,14 @@ static void btavrcp_playerapplicationsetting_callback( CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; - + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr "); + return; + } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); /* TODO ext attrs * Flattening defined attributes: */ @@ -165,8 +193,14 @@ static void btavrcp_playerapplicationsetting_changed_callback( CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to get new array "); + return; + } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); int arraylen = p_vals->num_attr * 2; ScopedLocalRef playerattribs( @@ -197,9 +231,15 @@ static void btavrcp_set_abs_vol_cmd_callback(bt_bdaddr_t* bd_addr, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to get new array "); + return; + } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleSetAbsVolume, addr.get(), (jbyte)abs_vol, (jbyte)label); } @@ -210,9 +250,15 @@ static void btavrcp_register_notification_absvol_callback(bt_bdaddr_t* bd_addr, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to get new array "); + return; + } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleRegisterNotificationAbsVol, addr.get(), (jbyte)label); @@ -229,8 +275,12 @@ static void btavrcp_track_changed_callback(bt_bdaddr_t* bd_addr, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to get new array "); + return; + } ScopedLocalRef attribIds(sCallbackEnv.get(), sCallbackEnv->NewIntArray(num_attr)); @@ -238,6 +288,8 @@ static void btavrcp_track_changed_callback(bt_bdaddr_t* bd_addr, ALOGE(" failed to set new array for attribIds"); return; } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); jclass strclazz = sCallbackEnv->FindClass("java/lang/String"); ScopedLocalRef stringArray( @@ -273,9 +325,14 @@ static void btavrcp_play_position_changed_callback(bt_bdaddr_t* bd_addr, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; - + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to get new array "); + return; + } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleplaypositionchanged, addr.get(), (jint)(song_len), (jint)song_pos); } @@ -286,9 +343,14 @@ static void btavrcp_play_status_changed_callback( CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; - + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to get new array "); + return; + } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleplaystatuschanged, addr.get(), (jbyte)play_status); } diff --git a/jni/com_android_bluetooth_btservice_AdapterService.cpp b/jni/com_android_bluetooth_btservice_AdapterService.cpp index 7bc5d6fd..02efa330 100644 --- a/jni/com_android_bluetooth_btservice_AdapterService.cpp +++ b/jni/com_android_bluetooth_btservice_AdapterService.cpp @@ -21,7 +21,6 @@ #include "cutils/properties.h" #include "hardware/bt_sock.h" #include "nativehelper/ScopedLocalFrame.h" -#include "scoped_bt_addr.h" #include "utils/Log.h" #include "utils/misc.h" @@ -193,8 +192,15 @@ static void remote_device_properties_callback(bt_status_t status, return; } - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Error while allocation byte array in %s", __func__); + return; + } + + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); jintArray typesPtr = types.get(); jobjectArray propsPtr = props.get(); @@ -212,15 +218,24 @@ static void device_found_callback(int num_properties, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, NULL); + ScopedLocalRef addr(sCallbackEnv.get(), NULL); int addr_index; for (int i = 0; i < num_properties; i++) { if (properties[i].type == BT_PROPERTY_BDADDR) { - addr.reset((bt_bdaddr_t*)properties[i].val); + addr.reset(sCallbackEnv->NewByteArray(properties[i].len)); + if (!addr.get()) { + ALOGE("Address is NULL (unable to allocate) in %s", __func__); + return; + } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, properties[i].len, + (jbyte*)properties[i].val); addr_index = i; } } - if (!addr.get()) return; + if (!addr.get()) { + ALOGE("Address is NULL in %s", __func__); + return; + } ALOGV("%s: Properties: %d, Address: %s", __func__, num_properties, (const char*)properties[addr_index].val); @@ -244,8 +259,14 @@ static void bond_state_changed_callback(bt_status_t status, return; } - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Address allocation failed in %s", __func__); + return; + } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->CallVoidMethod(sJniCallbacksObj, method_bondStateChangeCallback, (jint)status, addr.get(), (jint)state); @@ -261,8 +282,14 @@ static void acl_state_changed_callback(bt_status_t status, bt_bdaddr_t* bd_addr, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Address allocation failed in %s", __func__); + return; + } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->CallVoidMethod(sJniCallbacksObj, method_aclStateChangeCallback, (jint)status, addr.get(), (jint)state); @@ -288,8 +315,15 @@ static void pin_request_callback(bt_bdaddr_t* bd_addr, bt_bdname_t* bdname, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Error while allocating in: %s", __func__); + return; + } + + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); ScopedLocalRef devname( sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdname_t))); @@ -315,8 +349,15 @@ static void ssp_request_callback(bt_bdaddr_t* bd_addr, bt_bdname_t* bdname, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Error while allocating in: %s", __func__); + return; + } + + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); ScopedLocalRef devname( sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdname_t))); diff --git a/jni/com_android_bluetooth_hdp.cpp b/jni/com_android_bluetooth_hdp.cpp index 86642fe7..c49854eb 100644 --- a/jni/com_android_bluetooth_hdp.cpp +++ b/jni/com_android_bluetooth_hdp.cpp @@ -21,7 +21,6 @@ #include "android_runtime/AndroidRuntime.h" #include "com_android_bluetooth.h" #include "hardware/bt_hl.h" -#include "scoped_bt_addr.h" #include "utils/Log.h" #include @@ -48,8 +47,12 @@ static void channel_state_callback(int app_id, bt_bdaddr_t* bd_addr, bthl_channel_state_t state, int fd) { CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for channel state"); + return; + } // TODO(BT) check if fd is only valid for BTHH_CONN_STATE_CONNECTED state jobject fileDescriptor = NULL; @@ -61,6 +64,8 @@ static void channel_state_callback(int app_id, bt_bdaddr_t* bd_addr, } } + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onChannelStateChanged, app_id, addr.get(), mdep_cfg_index, channel_id, (jint)state, fileDescriptor); diff --git a/jni/com_android_bluetooth_hfp.cpp b/jni/com_android_bluetooth_hfp.cpp index 0c6a7040..f5556efb 100644 --- a/jni/com_android_bluetooth_hfp.cpp +++ b/jni/com_android_bluetooth_hfp.cpp @@ -21,7 +21,6 @@ #include "android_runtime/AndroidRuntime.h" #include "com_android_bluetooth.h" #include "hardware/bt_hf.h" -#include "scoped_bt_addr.h" #include "utils/Log.h" #include @@ -51,13 +50,27 @@ static jmethodID method_onAtBiev; static const bthf_interface_t* sBluetoothHfpInterface = NULL; static jobject mCallbacksObj = NULL; +static jbyteArray marshall_bda(bt_bdaddr_t* bd_addr) { + CallbackEnv sCallbackEnv(__func__); + if (!sCallbackEnv.valid()) return NULL; + + jbyteArray addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); + if (!addr) { + ALOGE("Fail to new jbyteArray bd addr"); + return NULL; + } + sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); + return addr; +} + static void connection_state_callback(bthf_connection_state_t state, bt_bdaddr_t* bd_addr) { ALOGI("%s", __func__); CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); if (!addr.get()) return; sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onConnectionStateChanged, @@ -68,7 +81,7 @@ static void audio_state_callback(bthf_audio_state_t state, bt_bdaddr_t* bd_addr) { CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); if (!addr.get()) return; sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAudioStateChanged, @@ -79,8 +92,11 @@ static void voice_recognition_callback(bthf_vr_state_t state, bt_bdaddr_t* bd_addr) { CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for audio state"); + return; + } sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onVrStateChanged, (jint)state, addr.get()); @@ -89,8 +105,11 @@ static void voice_recognition_callback(bthf_vr_state_t state, static void answer_call_callback(bt_bdaddr_t* bd_addr) { CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for audio state"); + return; + } sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAnswerCall, addr.get()); } @@ -98,8 +117,11 @@ static void answer_call_callback(bt_bdaddr_t* bd_addr) { static void hangup_call_callback(bt_bdaddr_t* bd_addr) { CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for audio state"); + return; + } sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onHangupCall, addr.get()); } @@ -108,8 +130,11 @@ static void volume_control_callback(bthf_volume_type_t type, int volume, bt_bdaddr_t* bd_addr) { CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for audio state"); + return; + } sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onVolumeChanged, (jint)type, (jint)volume, addr.get()); @@ -118,8 +143,11 @@ static void volume_control_callback(bthf_volume_type_t type, int volume, static void dial_call_callback(char* number, bt_bdaddr_t* bd_addr) { CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for audio state"); + return; + } ScopedLocalRef js_number(sCallbackEnv.get(), sCallbackEnv->NewStringUTF(number)); @@ -130,8 +158,11 @@ static void dial_call_callback(char* number, bt_bdaddr_t* bd_addr) { static void dtmf_cmd_callback(char dtmf, bt_bdaddr_t* bd_addr) { CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for audio state"); + return; + } // TBD dtmf has changed from int to char sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onSendDtmf, dtmf, @@ -141,8 +172,11 @@ static void dtmf_cmd_callback(char dtmf, bt_bdaddr_t* bd_addr) { static void noice_reduction_callback(bthf_nrec_t nrec, bt_bdaddr_t* bd_addr) { CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for audio state"); + return; + } sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onNoiceReductionEnable, nrec == BTHF_NREC_START, addr.get()); } @@ -151,8 +185,8 @@ static void wbs_callback(bthf_wbs_config_t wbs_config, bt_bdaddr_t* bd_addr) { CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); + if (addr.get() == NULL) return; sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onWBS, wbs_config, addr.get()); @@ -161,8 +195,12 @@ static void wbs_callback(bthf_wbs_config_t wbs_config, bt_bdaddr_t* bd_addr) { static void at_chld_callback(bthf_chld_type_t chld, bt_bdaddr_t* bd_addr) { CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for audio state"); + return; + } sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), (jbyte*)bd_addr); @@ -173,8 +211,11 @@ static void at_chld_callback(bthf_chld_type_t chld, bt_bdaddr_t* bd_addr) { static void at_cnum_callback(bt_bdaddr_t* bd_addr) { CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for audio state"); + return; + } sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAtCnum, addr.get()); } @@ -182,8 +223,11 @@ static void at_cnum_callback(bt_bdaddr_t* bd_addr) { static void at_cind_callback(bt_bdaddr_t* bd_addr) { CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for audio state"); + return; + } sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAtCind, addr.get()); } @@ -191,8 +235,11 @@ static void at_cind_callback(bt_bdaddr_t* bd_addr) { static void at_cops_callback(bt_bdaddr_t* bd_addr) { CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for audio state"); + return; + } sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAtCops, addr.get()); } @@ -200,8 +247,11 @@ static void at_cops_callback(bt_bdaddr_t* bd_addr) { static void at_clcc_callback(bt_bdaddr_t* bd_addr) { CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for audio state"); + return; + } sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAtClcc, addr.get()); } @@ -209,8 +259,11 @@ static void at_clcc_callback(bt_bdaddr_t* bd_addr) { static void unknown_at_callback(char* at_string, bt_bdaddr_t* bd_addr) { CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for audio state"); + return; + } ScopedLocalRef js_at_string(sCallbackEnv.get(), sCallbackEnv->NewStringUTF(at_string)); @@ -221,8 +274,11 @@ static void unknown_at_callback(char* at_string, bt_bdaddr_t* bd_addr) { static void key_pressed_callback(bt_bdaddr_t* bd_addr) { CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for audio state"); + return; + } sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onKeyPressed, addr.get()); } @@ -231,8 +287,8 @@ static void at_bind_callback(char* at_string, bt_bdaddr_t* bd_addr) { CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); + if (addr.get() == NULL) return; ScopedLocalRef js_at_string(sCallbackEnv.get(), sCallbackEnv->NewStringUTF(at_string)); @@ -246,8 +302,8 @@ static void at_biev_callback(bthf_hf_ind_type_t ind_id, int ind_value, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); + if (addr.get() == NULL) return; sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAtBiev, ind_id, (jint)ind_value, addr.get()); diff --git a/jni/com_android_bluetooth_hfpclient.cpp b/jni/com_android_bluetooth_hfpclient.cpp index 987fcd6d..9ae7d85d 100644 --- a/jni/com_android_bluetooth_hfpclient.cpp +++ b/jni/com_android_bluetooth_hfpclient.cpp @@ -21,7 +21,6 @@ #include "android_runtime/AndroidRuntime.h" #include "com_android_bluetooth.h" #include "hardware/bt_hf_client.h" -#include "scoped_bt_addr.h" #include "utils/Log.h" namespace android { @@ -51,6 +50,20 @@ static jmethodID method_onInBandRing; static jmethodID method_onLastVoiceTagNumber; static jmethodID method_onRingIndication; +static jbyteArray marshall_bda(const bt_bdaddr_t* bd_addr) { + CallbackEnv sCallbackEnv(__func__); + if (!sCallbackEnv.valid()) return NULL; + + jbyteArray addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); + if (!addr) { + ALOGE("Fail to new jbyteArray bd addr"); + return NULL; + } + sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); + return addr; +} + static void connection_state_cb(const bt_bdaddr_t* bd_addr, bthf_client_connection_state_t state, unsigned int peer_feat, @@ -58,7 +71,7 @@ static void connection_state_cb(const bt_bdaddr_t* bd_addr, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); if (!addr.get()) return; ALOGD("%s: state %d peer_feat %d chld_feat %d", __func__, state, peer_feat, chld_feat); @@ -72,7 +85,7 @@ static void audio_state_cb(const bt_bdaddr_t* bd_addr, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); if (!addr.get()) return; sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAudioStateChanged, @@ -92,7 +105,7 @@ static void network_state_cb(const bt_bdaddr_t* bd_addr, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); if (!addr.get()) return; sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onNetworkState, @@ -103,7 +116,7 @@ static void network_roaming_cb(const bt_bdaddr_t* bd_addr, bthf_client_service_type_t type) { CallbackEnv sCallbackEnv(__func__); - ScopedBtAddr addr(&sCallbackEnv, bd_addr); + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); if (!addr.get()) return; sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onNetworkRoaming, @@ -114,7 +127,7 @@ static void network_signal_cb(const bt_bdaddr_t* bd_addr, int signal) { CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); if (!addr.get()) return; sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onNetworkSignal, @@ -125,7 +138,7 @@ static void battery_level_cb(const bt_bdaddr_t* bd_addr, int level) { CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); if (!addr.get()) return; sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onBatteryLevel, @@ -136,7 +149,7 @@ static void current_operator_cb(const bt_bdaddr_t* bd_addr, const char* name) { CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); if (!addr.get()) return; ScopedLocalRef js_name(sCallbackEnv.get(), @@ -149,7 +162,7 @@ static void call_cb(const bt_bdaddr_t* bd_addr, bthf_client_call_t call) { CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); if (!addr.get()) return; sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onCall, (jint)call, @@ -161,7 +174,7 @@ static void callsetup_cb(const bt_bdaddr_t* bd_addr, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); if (!addr.get()) return; ALOGD("callsetup_cb bdaddr %02x:%02x:%02x:%02x:%02x:%02x", @@ -177,7 +190,7 @@ static void callheld_cb(const bt_bdaddr_t* bd_addr, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); if (!addr.get()) return; sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onCallHeld, (jint)callheld, @@ -189,7 +202,7 @@ static void resp_and_hold_cb(const bt_bdaddr_t* bd_addr, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); if (!addr.get()) return; sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onRespAndHold, @@ -200,7 +213,7 @@ static void clip_cb(const bt_bdaddr_t* bd_addr, const char* number) { CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); if (!addr.get()) return; ScopedLocalRef js_number(sCallbackEnv.get(), @@ -213,7 +226,7 @@ static void call_waiting_cb(const bt_bdaddr_t* bd_addr, const char* number) { CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); if (!addr.get()) return; ScopedLocalRef js_number(sCallbackEnv.get(), sCallbackEnv->NewStringUTF(number)); @@ -229,7 +242,7 @@ static void current_calls_cb(const bt_bdaddr_t* bd_addr, int index, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); if (!addr.get()) return; ScopedLocalRef js_number(sCallbackEnv.get(), sCallbackEnv->NewStringUTF(number)); @@ -242,7 +255,7 @@ static void volume_change_cb(const bt_bdaddr_t* bd_addr, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); if (!addr.get()) return; sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onVolumeChange, (jint)type, (jint)volume, addr.get()); @@ -253,7 +266,7 @@ static void cmd_complete_cb(const bt_bdaddr_t* bd_addr, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); if (!addr.get()) return; sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onCmdResult, (jint)type, (jint)cme, addr.get()); @@ -264,7 +277,7 @@ static void subscriber_info_cb(const bt_bdaddr_t* bd_addr, const char* name, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); if (!addr.get()) return; ScopedLocalRef js_name(sCallbackEnv.get(), sCallbackEnv->NewStringUTF(name)); @@ -277,7 +290,7 @@ static void in_band_ring_cb(const bt_bdaddr_t* bd_addr, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); if (!addr.get()) return; sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onInBandRing, (jint)in_band, addr.get()); @@ -288,7 +301,7 @@ static void last_voice_tag_number_cb(const bt_bdaddr_t* bd_addr, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); if (!addr.get()) return; ScopedLocalRef js_number(sCallbackEnv.get(), sCallbackEnv->NewStringUTF(number)); @@ -300,7 +313,7 @@ static void ring_indication_cb(const bt_bdaddr_t* bd_addr) { CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); if (!addr.get()) return; sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onRingIndication, addr.get()); diff --git a/jni/com_android_bluetooth_hid.cpp b/jni/com_android_bluetooth_hid.cpp index feb58ed7..fe34ff60 100644 --- a/jni/com_android_bluetooth_hid.cpp +++ b/jni/com_android_bluetooth_hid.cpp @@ -21,7 +21,6 @@ #include "android_runtime/AndroidRuntime.h" #include "com_android_bluetooth.h" #include "hardware/bt_hh.h" -#include "scoped_bt_addr.h" #include "utils/Log.h" #include @@ -37,6 +36,20 @@ static jmethodID method_onVirtualUnplug; static const bthh_interface_t* sBluetoothHidInterface = NULL; static jobject mCallbacksObj = NULL; +static jbyteArray marshall_bda(bt_bdaddr_t* bd_addr) { + CallbackEnv sCallbackEnv(__func__); + if (!sCallbackEnv.valid()) return NULL; + + jbyteArray addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); + if (!addr) { + ALOGE("Fail to new jbyteArray bd addr"); + return NULL; + } + sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); + return addr; +} + static void connection_state_callback(bt_bdaddr_t* bd_addr, bthh_connection_state_t state) { CallbackEnv sCallbackEnv(__func__); @@ -45,8 +58,11 @@ static void connection_state_callback(bt_bdaddr_t* bd_addr, ALOGE("%s: mCallbacksObj is null", __func__); return; } - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for HID channel state"); + return; + } sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onConnectStateChanged, addr.get(), (jint)state); @@ -66,8 +82,11 @@ static void get_protocol_mode_callback(bt_bdaddr_t* bd_addr, return; } - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for get protocal mode callback"); + return; + } sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onGetProtocolMode, addr.get(), (jint)mode); @@ -86,8 +105,11 @@ static void get_report_callback(bt_bdaddr_t* bd_addr, bthh_status_t hh_status, return; } - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for get report callback"); + return; + } ScopedLocalRef data(sCallbackEnv.get(), sCallbackEnv->NewByteArray(rpt_size)); if (!data.get()) { @@ -109,8 +131,11 @@ static void virtual_unplug_callback(bt_bdaddr_t* bd_addr, ALOGE("%s: mCallbacksObj is null", __func__); return; } - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for HID channel state"); + return; + } sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onVirtualUnplug, addr.get(), (jint)hh_status); } @@ -123,8 +148,11 @@ static void handshake_callback(bt_bdaddr_t* bd_addr, bthh_status_t hh_status) { return; } - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); + if (!addr.get()) { + ALOGE("Fail to new jbyteArray bd addr for handshake callback"); + return; + } sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onHandshake, addr.get(), (jint)hh_status); } diff --git a/jni/com_android_bluetooth_hidd.cpp b/jni/com_android_bluetooth_hidd.cpp index d3025057..5b0beec3 100644 --- a/jni/com_android_bluetooth_hidd.cpp +++ b/jni/com_android_bluetooth_hidd.cpp @@ -21,7 +21,6 @@ #include "android_runtime/AndroidRuntime.h" #include "com_android_bluetooth.h" #include "hardware/bt_hd.h" -#include "scoped_bt_addr.h" #include "utils/Log.h" #include @@ -39,6 +38,20 @@ static jmethodID method_onVirtualCableUnplug; static const bthd_interface_t* sHiddIf = NULL; static jobject mCallbacksObj = NULL; +static jbyteArray marshall_bda(bt_bdaddr_t* bd_addr) { + CallbackEnv sCallbackEnv(__func__); + if (!sCallbackEnv.valid()) return NULL; + + jbyteArray addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); + if (!addr) { + ALOGE("Fail to new jbyteArray bd addr"); + return NULL; + } + sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); + return addr; +} + static void application_state_callback(bt_bdaddr_t* bd_addr, bthd_application_state_t state) { jboolean registered = JNI_FALSE; @@ -49,8 +62,15 @@ static void application_state_callback(bt_bdaddr_t* bd_addr, registered = JNI_TRUE; } - // Note: it is ok for bd_addr to be null here. - ScopedBtAddr addr(&sCallbackEnv, bd_addr); + ScopedLocalRef addr(sCallbackEnv.get(), NULL); + + if (bd_addr) { + addr.reset(marshall_bda(bd_addr)); + if (!addr.get()) { + ALOGE("%s: failed to allocate storage for bt_addr", __FUNCTION__); + return; + } + } sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onApplicationStateChanged, addr.get(), registered); @@ -60,8 +80,11 @@ static void connection_state_callback(bt_bdaddr_t* bd_addr, bthd_connection_state_t state) { CallbackEnv sCallbackEnv(__func__); - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); + if (!addr.get()) { + ALOGE("%s: failed to allocate storage for bt_addr", __FUNCTION__); + return; + } sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onConnectStateChanged, addr.get(), (jint)state); diff --git a/jni/com_android_bluetooth_pan.cpp b/jni/com_android_bluetooth_pan.cpp index c249a316..2786a80c 100644 --- a/jni/com_android_bluetooth_pan.cpp +++ b/jni/com_android_bluetooth_pan.cpp @@ -21,7 +21,6 @@ #include "android_runtime/AndroidRuntime.h" #include "com_android_bluetooth.h" #include "hardware/bt_pan.h" -#include "scoped_bt_addr.h" #include "utils/Log.h" #include @@ -45,6 +44,20 @@ static jmethodID method_onControlStateChanged; static const btpan_interface_t* sPanIf = NULL; static jobject mCallbacksObj = NULL; +static jbyteArray marshall_bda(const bt_bdaddr_t* bd_addr) { + CallbackEnv sCallbackEnv(__func__); + if (!sCallbackEnv.valid()) return NULL; + + jbyteArray addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); + if (!addr) { + ALOGE("Fail to new jbyteArray bd addr"); + return NULL; + } + sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); + return addr; +} + static void control_state_callback(btpan_control_state_t state, int local_role, bt_status_t error, const char* ifname) { debug("state:%d, local_role:%d, ifname:%s", state, local_role, ifname); @@ -73,8 +86,11 @@ static void connection_state_callback(btpan_connection_state_t state, } CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); - if (!addr.get()) return; + ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr)); + if (!addr.get()) { + error("Fail to new jbyteArray bd addr for PAN channel state"); + return; + } sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onConnectStateChanged, addr.get(), (jint)state, (jint)error, (jint)local_role, (jint)remote_role); diff --git a/jni/com_android_bluetooth_sdp.cpp b/jni/com_android_bluetooth_sdp.cpp index 053bafca..fb68f47f 100644 --- a/jni/com_android_bluetooth_sdp.cpp +++ b/jni/com_android_bluetooth_sdp.cpp @@ -21,7 +21,6 @@ #include "android_runtime/AndroidRuntime.h" #include "com_android_bluetooth.h" #include "hardware/bt_sdp.h" -#include "scoped_bt_addr.h" #include "utils/Log.h" #include @@ -153,13 +152,16 @@ static void sdp_search_callback(bt_status_t status, bt_bdaddr_t* bd_addr, CallbackEnv sCallbackEnv(__func__); if (!sCallbackEnv.valid()) return; - ScopedBtAddr addr(&sCallbackEnv, bd_addr); + ScopedLocalRef addr( + sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t))); if (!addr.get()) return; ScopedLocalRef uuid( sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_uuid_t))); if (!uuid.get()) return; + sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(bt_bdaddr_t), + (jbyte*)bd_addr); sCallbackEnv->SetByteArrayRegion(uuid.get(), 0, sizeof(bt_uuid_t), (jbyte*)uuid_in); diff --git a/jni/scoped_bt_addr.cpp b/jni/scoped_bt_addr.cpp deleted file mode 100644 index 03438fec..00000000 --- a/jni/scoped_bt_addr.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "scoped_bt_addr.h" -#include "utils/Log.h" - -namespace android { - -ScopedBtAddr::ScopedBtAddr(CallbackEnv* env, const bt_bdaddr_t* bd_addr) - : mEnv(env) { - reset(bd_addr); -} - -ScopedBtAddr::~ScopedBtAddr() { reset(); } - -void ScopedBtAddr::reset(const bt_bdaddr_t* addr /* = NULL */) { - if (addr == nullptr) { - if (mAddr != nullptr) { - (*mEnv)->DeleteLocalRef(mAddr); - mAddr = nullptr; - } - return; - } - if (mAddr == nullptr) { - mAddr = (*mEnv)->NewByteArray(sizeof(bt_bdaddr_t)); - if (mAddr == nullptr) { - ALOGE("%s: Can't allocate array for bd_addr!", mEnv->method_name()); - return; - } - } - (*mEnv)->SetByteArrayRegion(mAddr, 0, sizeof(bt_bdaddr_t), (jbyte*)addr); -} - -jbyteArray ScopedBtAddr::get() { return mAddr; } -} diff --git a/jni/scoped_bt_addr.h b/jni/scoped_bt_addr.h deleted file mode 100644 index c92e2502..00000000 --- a/jni/scoped_bt_addr.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef SCOPED_BT_ADDR_H -#define SCOPED_BT_ADDR_H - -#include "com_android_bluetooth.h" - -namespace android { - -/** Helper class for automatically marshalling and releasing a BT Address. - * Attempts to be as similar to ScopedLocalRef as possible with automatic - * copy of a bt_bdaddr_t correctly. - */ -class ScopedBtAddr { - public: - ScopedBtAddr(CallbackEnv* env, const bt_bdaddr_t* bd_addr); - ~ScopedBtAddr(); - - // (Re)set the address pointed to, releasing the local reference if necessary. - void reset(const bt_bdaddr_t* addr = nullptr); - - // Get the pointer to the allocated array, for calling java methods. - jbyteArray get(); - - private: - CallbackEnv* mEnv; - jbyteArray mAddr; -}; -} - -#endif // SCOPED_BT_ADDR_H -- 2.11.0