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) \
return mCallbackEnv;
}
- const char* method_name() { return mName; }
-
- private:
+private:
JNIEnv *mCallbackEnv;
const char *mName;
#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 <string.h>
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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());
}
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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());
}
#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 <string.h>
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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());
}
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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());
}
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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);
#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 <string.h>
return;
}
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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);
}
return;
}
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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());
}
return;
}
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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<jintArray> attrs(
sCallbackEnv.get(), (jintArray)sCallbackEnv->NewIntArray(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());
}
return;
}
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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);
}
return;
}
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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);
return;
}
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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);
return;
}
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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);
}
return;
}
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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);
return;
}
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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<jintArray> 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)) {
return;
}
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
-
ScopedLocalRef<jbyteArray> attrs(sCallbackEnv.get(),
sCallbackEnv->NewByteArray(BTRC_UID_SIZE));
if (!attrs.get()) {
return;
}
+ ScopedLocalRef<jbyteArray> 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,
return;
}
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
-
ScopedLocalRef<jbyteArray> attr_uid(
sCallbackEnv.get(), sCallbackEnv->NewByteArray(BTRC_UID_SIZE));
if (!attr_uid.get()) {
return;
}
+ ScopedLocalRef<jbyteArray> 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<jintArray> attrs(
sCallbackEnv.get(), (jintArray)sCallbackEnv->NewIntArray(num_attr));
if (!attrs.get()) {
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);
return;
}
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
-
ScopedLocalRef<jbyteArray> attrs(sCallbackEnv.get(),
sCallbackEnv->NewByteArray(BTRC_UID_SIZE));
if (!attrs.get()) {
return;
}
+ ScopedLocalRef<jbyteArray> 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,
return;
}
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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);
}
return;
}
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
-
ScopedLocalRef<jbyteArray> attrs(sCallbackEnv.get(),
sCallbackEnv->NewByteArray(str_len));
if (!attrs.get()) {
return;
}
+ ScopedLocalRef<jbyteArray> 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(),
return;
}
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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<jbyteArray> attrs(sCallbackEnv.get(),
sCallbackEnv->NewByteArray(BTRC_UID_SIZE));
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,
#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 <string.h>
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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());
}
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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());
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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);
}
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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);
}
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
-
+ ScopedLocalRef<jbyteArray> 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: <id,num_values,values[]>
*/
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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<jbyteArray> playerattribs(
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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);
}
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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);
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> addr(
+ sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)));
+ if (!addr.get()) {
+ ALOGE("Fail to get new array ");
+ return;
+ }
ScopedLocalRef<jintArray> attribIds(sCallbackEnv.get(),
sCallbackEnv->NewIntArray(num_attr));
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<jobjectArray> stringArray(
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
-
+ ScopedLocalRef<jbyteArray> 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);
}
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
-
+ ScopedLocalRef<jbyteArray> 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);
}
#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"
return;
}
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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();
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, NULL);
+ ScopedLocalRef<jbyteArray> 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);
return;
}
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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);
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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);
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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<jbyteArray> devname(
sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdname_t)));
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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<jbyteArray> devname(
sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdname_t)));
#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 <string.h>
bthl_channel_state_t state, int fd) {
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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;
}
}
+ 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);
#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 <string.h>
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<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
if (!addr.get()) return;
sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onConnectionStateChanged,
bt_bdaddr_t* bd_addr) {
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
+ ScopedLocalRef<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
if (!addr.get()) return;
sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAudioStateChanged,
bt_bdaddr_t* bd_addr) {
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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());
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<jbyteArray> 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());
}
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<jbyteArray> 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());
}
bt_bdaddr_t* bd_addr) {
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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());
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<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
+ if (!addr.get()) {
+ ALOGE("Fail to new jbyteArray bd addr for audio state");
+ return;
+ }
ScopedLocalRef<jstring> js_number(sCallbackEnv.get(),
sCallbackEnv->NewStringUTF(number));
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<jbyteArray> 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,
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<jbyteArray> 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());
}
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
+ if (addr.get() == NULL) return;
sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onWBS, wbs_config,
addr.get());
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<jbyteArray> 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);
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<jbyteArray> 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());
}
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<jbyteArray> 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());
}
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<jbyteArray> 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());
}
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<jbyteArray> 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());
}
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<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
+ if (!addr.get()) {
+ ALOGE("Fail to new jbyteArray bd addr for audio state");
+ return;
+ }
ScopedLocalRef<jstring> js_at_string(sCallbackEnv.get(),
sCallbackEnv->NewStringUTF(at_string));
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<jbyteArray> 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());
}
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
+ if (addr.get() == NULL) return;
ScopedLocalRef<jstring> js_at_string(sCallbackEnv.get(),
sCallbackEnv->NewStringUTF(at_string));
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
+ if (addr.get() == NULL) return;
sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAtBiev, ind_id,
(jint)ind_value, addr.get());
#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 {
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,
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
+ ScopedLocalRef<jbyteArray> 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);
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
+ ScopedLocalRef<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
if (!addr.get()) return;
sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAudioStateChanged,
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
+ ScopedLocalRef<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
if (!addr.get()) return;
sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onNetworkState,
bthf_client_service_type_t type) {
CallbackEnv sCallbackEnv(__func__);
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
+ ScopedLocalRef<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
if (!addr.get()) return;
sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onNetworkRoaming,
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
+ ScopedLocalRef<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
if (!addr.get()) return;
sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onNetworkSignal,
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
+ ScopedLocalRef<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
if (!addr.get()) return;
sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onBatteryLevel,
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
+ ScopedLocalRef<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
if (!addr.get()) return;
ScopedLocalRef<jstring> js_name(sCallbackEnv.get(),
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
+ ScopedLocalRef<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
if (!addr.get()) return;
sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onCall, (jint)call,
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
+ ScopedLocalRef<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
if (!addr.get()) return;
ALOGD("callsetup_cb bdaddr %02x:%02x:%02x:%02x:%02x:%02x",
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
+ ScopedLocalRef<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
if (!addr.get()) return;
sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onCallHeld, (jint)callheld,
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
+ ScopedLocalRef<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
if (!addr.get()) return;
sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onRespAndHold,
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
+ ScopedLocalRef<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
if (!addr.get()) return;
ScopedLocalRef<jstring> js_number(sCallbackEnv.get(),
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
+ ScopedLocalRef<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
if (!addr.get()) return;
ScopedLocalRef<jstring> js_number(sCallbackEnv.get(),
sCallbackEnv->NewStringUTF(number));
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
+ ScopedLocalRef<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
if (!addr.get()) return;
ScopedLocalRef<jstring> js_number(sCallbackEnv.get(),
sCallbackEnv->NewStringUTF(number));
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
+ ScopedLocalRef<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
if (!addr.get()) return;
sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onVolumeChange, (jint)type,
(jint)volume, addr.get());
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
+ ScopedLocalRef<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
if (!addr.get()) return;
sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onCmdResult, (jint)type,
(jint)cme, addr.get());
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
+ ScopedLocalRef<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
if (!addr.get()) return;
ScopedLocalRef<jstring> js_name(sCallbackEnv.get(),
sCallbackEnv->NewStringUTF(name));
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
+ ScopedLocalRef<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
if (!addr.get()) return;
sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onInBandRing,
(jint)in_band, addr.get());
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
+ ScopedLocalRef<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
if (!addr.get()) return;
ScopedLocalRef<jstring> js_number(sCallbackEnv.get(),
sCallbackEnv->NewStringUTF(number));
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
+ ScopedLocalRef<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
if (!addr.get()) return;
sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onRingIndication,
addr.get());
#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 <string.h>
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__);
ALOGE("%s: mCallbacksObj is null", __func__);
return;
}
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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);
return;
}
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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);
return;
}
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> addr(sCallbackEnv.get(), marshall_bda(bd_addr));
+ if (!addr.get()) {
+ ALOGE("Fail to new jbyteArray bd addr for get report callback");
+ return;
+ }
ScopedLocalRef<jbyteArray> data(sCallbackEnv.get(),
sCallbackEnv->NewByteArray(rpt_size));
if (!data.get()) {
ALOGE("%s: mCallbacksObj is null", __func__);
return;
}
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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);
}
return;
}
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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);
}
#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 <string.h>
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;
registered = JNI_TRUE;
}
- // Note: it is ok for bd_addr to be null here.
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
+ ScopedLocalRef<jbyteArray> 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);
bthd_connection_state_t state) {
CallbackEnv sCallbackEnv(__func__);
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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);
#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 <string.h>
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);
}
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
- if (!addr.get()) return;
+ ScopedLocalRef<jbyteArray> 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);
#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 <string.h>
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
- ScopedBtAddr addr(&sCallbackEnv, bd_addr);
+ ScopedLocalRef<jbyteArray> addr(
+ sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)));
if (!addr.get()) return;
ScopedLocalRef<jbyteArray> 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);
+++ /dev/null
-/*
- * 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; }
-}
+++ /dev/null
-/*
- * 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