}
JNIEnv* getCallbackEnv() {
- return callbackEnv;
+ return callbackEnv;
}
void checkAndClearExceptionFromCallback(JNIEnv* env,
jbyteArray propVal;
for (int i = 0; i < num_properties; i++) {
- /* The higher layers expect rssi as a short int value, while the value is sent as a byte
- * to jni. Converting rssi value to the expected format.*/
- if (properties[i].type == BT_PROPERTY_REMOTE_RSSI)
- {
- jbyte rssi = *((jbyte *) properties[i].val);
- short rssiValue = rssi;
- properties[i].len = sizeof(rssiValue);
- properties[i].val = &rssiValue;
- }
-
- propVal = callbackEnv->NewByteArray(properties[i].len);
- if (propVal == NULL) goto Fail;
-
- callbackEnv->SetByteArrayRegion(propVal, 0, properties[i].len,
- (jbyte*)properties[i].val);
- callbackEnv->SetObjectArrayElement(*props, i, propVal);
- // Delete reference to propVal
- callbackEnv->DeleteLocalRef(propVal);
- callbackEnv->SetIntArrayRegion(*types, i, 1, (jint *)&properties[i].type);
+ /* The higher layers expect rssi as a short int value, while the value is sent as a byte
+ * to jni. Converting rssi value to the expected format.*/
+ if (properties[i].type == BT_PROPERTY_REMOTE_RSSI)
+ {
+ jbyte rssi = *((jbyte *) properties[i].val);
+ short rssiValue = rssi;
+ properties[i].len = sizeof(rssiValue);
+ properties[i].val = &rssiValue;
+ }
+
+ propVal = callbackEnv->NewByteArray(properties[i].len);
+ if (propVal == NULL) goto Fail;
+
+ callbackEnv->SetByteArrayRegion(propVal, 0, properties[i].len,
+ (jbyte*)properties[i].val);
+ callbackEnv->SetObjectArrayElement(*props, i, propVal);
+ // Delete reference to propVal
+ callbackEnv->DeleteLocalRef(propVal);
+ callbackEnv->SetIntArrayRegion(*types, i, 1, (jint *)&properties[i].type);
}
return 0;
Fail:
if (event == ASSOCIATE_JVM) {
JavaVMAttachArgs args;
char name[] = "BT Service Callback Thread";
- //TODO(BT)
- //args.version = nat->envVer;
+ args.version = JNI_VERSION_1_6;
args.name = name;
args.group = NULL;
vm->AttachCurrentThread(&callbackEnv, &args);
}
int ret = sBluetoothInterface->create_bond((bt_bdaddr_t *)addr);
- env->ReleaseByteArrayElements(address, addr, NULL);
+ env->ReleaseByteArrayElements(address, addr, 0);
result = (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
return result;
}
int ret = sBluetoothInterface->remove_bond((bt_bdaddr_t *)addr);
- env->ReleaseByteArrayElements(address, addr, NULL);
+ env->ReleaseByteArrayElements(address, addr, 0);
result = (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
return result;
}
int ret = sBluetoothInterface->cancel_bond((bt_bdaddr_t *)addr);
- env->ReleaseByteArrayElements(address, addr, NULL);
+ env->ReleaseByteArrayElements(address, addr, 0);
result = (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
return result;
pinPtr = env->GetByteArrayElements(pinArray, NULL);
if (pinPtr == NULL) {
jniThrowIOException(env, EINVAL);
- env->ReleaseByteArrayElements(address, addr, NULL);
+ env->ReleaseByteArrayElements(address, addr, 0);
return result;
}
}
int ret = sBluetoothInterface->pin_reply((bt_bdaddr_t*)addr, accept, len,
(bt_pin_code_t *) pinPtr);
- env->ReleaseByteArrayElements(address, addr, NULL);
- env->ReleaseByteArrayElements(pinArray, pinPtr, NULL);
+ env->ReleaseByteArrayElements(address, addr, 0);
+ env->ReleaseByteArrayElements(pinArray, pinPtr, 0);
result = (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
return result;
int ret = sBluetoothInterface->ssp_reply((bt_bdaddr_t *)addr,
(bt_ssp_variant_t) type, accept, passkey);
- env->ReleaseByteArrayElements(address, addr, NULL);
+ env->ReleaseByteArrayElements(address, addr, 0);
result = (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
return result;
prop.val = val;
int ret = sBluetoothInterface->set_adapter_property(&prop);
- env->ReleaseByteArrayElements(value, val, NULL);
+ env->ReleaseByteArrayElements(value, val, 0);
result = (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
return result;
int ret = sBluetoothInterface->get_remote_device_property((bt_bdaddr_t *)addr,
(bt_property_type_t) type);
- env->ReleaseByteArrayElements(address, addr, NULL);
+ env->ReleaseByteArrayElements(address, addr, 0);
result = (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
return result;
addr = env->GetByteArrayElements(address, NULL);
if (addr == NULL) {
- env->ReleaseByteArrayElements(value, val, NULL);
+ env->ReleaseByteArrayElements(value, val, 0);
jniThrowIOException(env, EINVAL);
return result;
}
prop.val = val;
int ret = sBluetoothInterface->set_remote_device_property((bt_bdaddr_t *)addr, &prop);
- env->ReleaseByteArrayElements(value, val, NULL);
- env->ReleaseByteArrayElements(address, addr, NULL);
+ env->ReleaseByteArrayElements(value, val, 0);
+ env->ReleaseByteArrayElements(address, addr, 0);
result = (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
int ret = sBluetoothInterface->get_remote_services((bt_bdaddr_t *)addr);
- env->ReleaseByteArrayElements(address, addr, NULL);
+ env->ReleaseByteArrayElements(address, addr, 0);
result = (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
return result;
}
int socket_fd;
bt_status_t status;
- if (!sBluetoothSocketInterface) return NULL;
+ if (!sBluetoothSocketInterface) return -1;
addr = env->GetByteArrayElements(address, NULL);
if (!addr) {
}
static int createSocketChannelNative(JNIEnv *env, jobject object, jint type,
- jstring name_str, jbyteArray uuidObj, jint channel, jint flag) {
+ jstring name_str, jbyteArray uuidObj, jint channel, jint flag) {
const char *service_name;
jbyte *uuid = NULL;
int socket_fd;
bt_status_t status;
- if (!sBluetoothSocketInterface) return NULL;
+ if (!sBluetoothSocketInterface) return -1;
service_name = env->GetStringUTFChars(name_str, NULL);
}
static JNINativeMethod sMethods[] = {
- /* name, signature, funcPtr */
+ /* name, signature, funcPtr */
{"classInitNative", "()V", (void *) classInitNative},
{"initNative", "()Z", (void *) initNative},
{"cleanupNative", "()V", (void*) cleanupNative},
*/
jint JNI_OnLoad(JavaVM *jvm, void *reserved)
{
- JNIEnv *e;
- int status;
-
- ALOGV("Bluetooth Adapter Service : loading JNI\n");
-
- // Check JNI version
- if(jvm->GetEnv((void **)&e, JNI_VERSION_1_6)) {
- ALOGE("JNI version mismatch error");
- return JNI_ERR;
- }
-
- if ((status = android::register_com_android_bluetooth_btservice_AdapterService(e)) < 0) {
- ALOGE("jni adapter service registration failure, status: %d", status);
- return JNI_ERR;
- }
-
- if ((status = android::register_com_android_bluetooth_hfp(e)) < 0) {
- ALOGE("jni hfp registration failure, status: %d", status);
- return JNI_ERR;
- }
-
- if ((status = android::register_com_android_bluetooth_a2dp(e)) < 0) {
- ALOGE("jni a2dp registration failure: %d", status);
- return JNI_ERR;
- }
-
- if ((status = android::register_com_android_bluetooth_hid(e)) < 0) {
- ALOGE("jni hid registration failure: %d", status);
- return JNI_ERR;
- }
-
- if ((status = android::register_com_android_bluetooth_hdp(e)) < 0) {
- ALOGE("jni hdp registration failure: %d", status);
- return JNI_ERR;
- }
-
- if ((status = android::register_com_android_bluetooth_pan(e)) < 0) {
- ALOGE("jni pan registration failure: %d", status);
- return JNI_ERR;
- }
-
- if ((status = android::register_com_android_bluetooth_gatt(e)) < 0) {
- ALOGE("jni gatt registration failure: %d", status);
- return JNI_ERR;
- }
- return JNI_VERSION_1_6;
+ JNIEnv *e;
+ int status;
+
+ ALOGV("Bluetooth Adapter Service : loading JNI\n");
+
+ // Check JNI version
+ if (jvm->GetEnv((void **)&e, JNI_VERSION_1_6)) {
+ ALOGE("JNI version mismatch error");
+ return JNI_ERR;
+ }
+
+ if ((status = android::register_com_android_bluetooth_btservice_AdapterService(e)) < 0) {
+ ALOGE("jni adapter service registration failure, status: %d", status);
+ return JNI_ERR;
+ }
+
+ if ((status = android::register_com_android_bluetooth_hfp(e)) < 0) {
+ ALOGE("jni hfp registration failure, status: %d", status);
+ return JNI_ERR;
+ }
+
+ if ((status = android::register_com_android_bluetooth_a2dp(e)) < 0) {
+ ALOGE("jni a2dp registration failure: %d", status);
+ return JNI_ERR;
+ }
+
+ if ((status = android::register_com_android_bluetooth_hid(e)) < 0) {
+ ALOGE("jni hid registration failure: %d", status);
+ return JNI_ERR;
+ }
+
+ if ((status = android::register_com_android_bluetooth_hdp(e)) < 0) {
+ ALOGE("jni hdp registration failure: %d", status);
+ return JNI_ERR;
+ }
+
+ if ((status = android::register_com_android_bluetooth_pan(e)) < 0) {
+ ALOGE("jni pan registration failure: %d", status);
+ return JNI_ERR;
+ }
+
+ if ((status = android::register_com_android_bluetooth_gatt(e)) < 0) {
+ ALOGE("jni gatt registration failure: %d", status);
+ return JNI_ERR;
+ }
+ return JNI_VERSION_1_6;
}