const char* methodFormat);
/**
+ * check JNI exception occurrence
+ * @param[in] env JNI interface pointer.
+ * @return true(occurrence) or false(no occurrence).
+ */
+bool CACheckJNIException(JNIEnv *env);
+
+/**
* To Delete other Global References
* Called during CATerminate to remove global references
*/
if (!jni_cid)
{
OIC_LOG_V(ERROR, CA_ADAPTER_UTILS_TAG, "jni_cid [%s] is null", className);
+ CACheckJNIException(env);
return NULL;
}
if (!jni_midID)
{
OIC_LOG_V(ERROR, CA_ADAPTER_UTILS_TAG, "jni_midID [%s] is null", methodName);
+ CACheckJNIException(env);
(*env)->DeleteLocalRef(env, jni_cid);
return NULL;
}
return jni_midID;
}
+bool CACheckJNIException(JNIEnv *env)
+{
+ if ((*env)->ExceptionCheck(env))
+ {
+ (*env)->ExceptionDescribe(env);
+ (*env)->ExceptionClear(env);
+ return true;
+ }
+ return false;
+}
+
void CADeleteGlobalReferences(JNIEnv *env)
{
if (g_Context)
if (!jApplicationContext)
{
OIC_LOG(ERROR, TAG, "Could not get application context");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jclass jni_LEInterface = (*env)->FindClass(env, "org/iotivity/ca/CaLeClientInterface");
return CA_STATUS_OK;
error_exit:
-
+ CACheckJNIException(env);
if (isAttached)
{
(*g_jvm)->DetachCurrentThread(g_jvm);
(*env)->CallStaticVoidMethod(env, jni_LeInterface, jni_InterfaceDestroyMethod);
- if ((*env)->ExceptionCheck(env))
+ if (CACheckJNIException(env))
{
OIC_LOG(ERROR, TAG, "destroyLeInterface has failed");
- (*env)->ExceptionDescribe(env);
- (*env)->ExceptionClear(env);
- goto error_exit;
+ goto detach_thread;
}
OIC_LOG(DEBUG, TAG, "Destroy instance for CaLeClientInterface");
return CA_STATUS_OK;
error_exit:
+ CACheckJNIException(env);
+detach_thread:
if (isAttached)
{
(*g_jvm)->DetachCurrentThread(g_jvm);
if (!setAddress)
{
OIC_LOG(ERROR, TAG, "setAddress is null");
+ CACheckJNIException(env);
goto error_exit;
}
g_sendBuffer = NULL;
}
jbyteArray jni_arr = (*env)->NewByteArray(env, dataLen);
+ CACheckJNIException(env);
(*env)->SetByteArrayRegion(env, jni_arr, 0, dataLen, (jbyte*) data);
+ CACheckJNIException(env);
g_sendBuffer = (jbyteArray)(*env)->NewGlobalRef(env, jni_arr);
+ CACheckJNIException(env);
// Target device to send message is just one.
g_targetCnt = 1;
if (!address)
{
OIC_LOG(ERROR, TAG, "address is not available");
+ CACheckJNIException(env);
return CA_STATUS_FAILED;
}
oc_mutex_lock(g_deviceStateListMutex);
if (!jni_obj_device)
{
OIC_LOG(ERROR, TAG, "jni_obj_device is null");
+ CACheckJNIException(env);
return NULL;
}
if (!jni_address)
{
OIC_LOG(ERROR, TAG, "jni_address is null");
+ CACheckJNIException(env);
return NULL;
}
OIC_LOG(DEBUG, TAG, "request to close GATT");
(*env)->CallVoidMethod(env, bluetoothGatt, jni_mid_closeGatt);
- if ((*env)->ExceptionCheck(env))
+ if (CACheckJNIException(env))
{
OIC_LOG(ERROR, TAG, "closeGATT has failed");
- (*env)->ExceptionDescribe(env);
- (*env)->ExceptionClear(env);
return CA_STATUS_FAILED;
}
if (!jni_cid_BTAdapter)
{
OIC_LOG(ERROR, TAG, "getState From BTAdapter: jni_cid_BTAdapter is null");
+ CACheckJNIException(env);
return CA_STATUS_FAILED;
}
if (!jni_mid_getDefaultAdapter)
{
OIC_LOG(ERROR, TAG, "jni_mid_getDefaultAdapter is null");
+ CACheckJNIException(env);
(*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
return CA_STATUS_FAILED;
}
if (!jni_mid_startLeScan)
{
OIC_LOG(ERROR, TAG, "startLeScan: jni_mid_startLeScan is null");
+ CACheckJNIException(env);
(*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
return CA_STATUS_FAILED;
}
if (!jni_obj_BTAdapter)
{
OIC_LOG(ERROR, TAG, "getState From BTAdapter: jni_obj_BTAdapter is null");
+ CACheckJNIException(env);
(*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
return CA_STATUS_FAILED;
}
if (!jni_obj_startLeScan)
{
OIC_LOG(INFO, TAG, "startLeScan has failed");
+ CACheckJNIException(env);
}
else
{
if (!jni_cid_BTAdapter)
{
OIC_LOG(ERROR, TAG, "getState From BTAdapter: jni_cid_BTAdapter is null");
+ CACheckJNIException(env);
return CA_STATUS_FAILED;
}
if (!jni_mid_getDefaultAdapter)
{
OIC_LOG(ERROR, TAG, "jni_mid_getDefaultAdapter is null");
+ CACheckJNIException(env);
(*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
return CA_STATUS_FAILED;
}
if (!jni_mid_startLeScan)
{
OIC_LOG(ERROR, TAG, "startLeScan: jni_mid_startLeScan is null");
+ CACheckJNIException(env);
(*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
return CA_STATUS_FAILED;
}
if (!jni_obj_BTAdapter)
{
OIC_LOG(ERROR, TAG, "getState From BTAdapter: jni_obj_BTAdapter is null");
+ CACheckJNIException(env);
(*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
return CA_STATUS_FAILED;
}
if (!jni_obj_startLeScan)
{
OIC_LOG(INFO, TAG, "startLeScan has failed");
+ CACheckJNIException(env);
}
else
{
if (!jni_cid_uuid)
{
OIC_LOG(ERROR, TAG, "jni_cid_uuid is null");
- return NULL;
+ goto error_exit;
}
jmethodID jni_mid_fromString = (*env)->GetStaticMethodID(env, jni_cid_uuid, "fromString",
if (!jni_mid_fromString)
{
OIC_LOG(ERROR, TAG, "jni_mid_fromString is null");
- return NULL;
+ goto error_exit;
}
jstring jni_uuid = (*env)->NewStringUTF(env, uuid);
+ CACheckJNIException(env);
jobject jni_obj_uuid = (*env)->CallStaticObjectMethod(env, jni_cid_uuid, jni_mid_fromString,
jni_uuid);
if (!jni_obj_uuid)
{
OIC_LOG(ERROR, TAG, "jni_obj_uuid is null");
- return NULL;
+ goto error_exit;
}
return jni_obj_uuid;
+
+error_exit:
+ CACheckJNIException(env);
+ return NULL;
}
CAResult_t CALEClientStopScan()
if (!jni_cid_BTAdapter)
{
OIC_LOG(ERROR, TAG, "getState From BTAdapter: jni_cid_BTAdapter is null");
+ CACheckJNIException(env);
return CA_STATUS_FAILED;
}
if (!jni_mid_getDefaultAdapter)
{
OIC_LOG(ERROR, TAG, "jni_mid_getDefaultAdapter is null");
+ CACheckJNIException(env);
(*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
return CA_STATUS_FAILED;
}
if (!jni_mid_stopLeScan)
{
OIC_LOG(ERROR, TAG, "stopLeScan: jni_mid_stopLeScan is null");
+ CACheckJNIException(env);
(*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
return CA_STATUS_FAILED;
}
if (!jni_obj_BTAdapter)
{
OIC_LOG(ERROR, TAG, "jni_obj_BTAdapter is null");
+ CACheckJNIException(env);
(*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
return CA_STATUS_FAILED;
}
OIC_LOG(INFO, TAG, "CALL API - stopLeScan");
// call start le scan method
(*env)->CallVoidMethod(env, jni_obj_BTAdapter, jni_mid_stopLeScan, callback);
- if ((*env)->ExceptionCheck(env))
+ if (CACheckJNIException(env))
{
OIC_LOG(ERROR, TAG, "stopLeScan has failed");
(*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
(*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
- (*env)->ExceptionDescribe(env);
- (*env)->ExceptionClear(env);
return CA_STATUS_FAILED;
}
if (!address)
{
OIC_LOG(ERROR, TAG, "address is not available");
+ CACheckJNIException(env);
return CA_STATUS_FAILED;
}
if (!address)
{
OIC_LOG(ERROR, TAG, "address is not available");
+ CACheckJNIException(env);
oc_mutex_unlock(g_deviceStateListMutex);
return JNI_FALSE;
}
if (!address)
{
OIC_LOG(ERROR, TAG, "address is not available");
+ CACheckJNIException(env);
oc_mutex_unlock(g_threadSendMutex);
return CA_STATUS_FAILED;
}
if (!jni_obj_connectGatt)
{
OIC_LOG(ERROR, TAG, "connectGatt was failed..it will be removed");
+ CACheckJNIException(env);
CALEClientRemoveDeviceInScanDeviceList(env, jni_address);
CALEClientUpdateSendCnt(env);
return NULL;
if (!jni_cid_BTAdapter)
{
OIC_LOG(ERROR, TAG, "jni_cid_BTAdapter is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
// get remote bt adapter method
if (!jni_mid_getDefaultAdapter)
{
OIC_LOG(ERROR, TAG, "jni_mid_getDefaultAdapter is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
// gat bt adapter object
if (!jni_obj_BTAdapter)
{
OIC_LOG(ERROR, TAG, "jni_obj_BTAdapter is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
// get closeProfileProxy method
if (!jni_mid_closeProfileProxy)
{
OIC_LOG(ERROR, TAG, "jni_mid_closeProfileProxy is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jclass jni_cid_BTProfile = (*env)->FindClass(env, CLASSPATH_BT_PROFILE);
if (!jni_cid_BTProfile)
{
OIC_LOG(ERROR, TAG, "jni_cid_BTProfile is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
// GATT - Constant value : 7 (0x00000007)
if (!id_gatt)
{
OIC_LOG(ERROR, TAG, "id_gatt is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jint jni_gatt = (*env)->GetStaticIntField(env, jni_cid_BTProfile, id_gatt);
+ CACheckJNIException(env);
OIC_LOG(DEBUG, TAG, "CALL API - close the connection of the profile proxy to the Service");
(*env)->CallVoidMethod(env, jni_obj_BTAdapter, jni_mid_closeProfileProxy, jni_gatt, gatt);
- if ((*env)->ExceptionCheck(env))
+ if (CACheckJNIException(env))
{
OIC_LOG(ERROR, TAG, "closeProfileProxy has failed");
- (*env)->ExceptionDescribe(env);
- (*env)->ExceptionClear(env);
return CA_STATUS_FAILED;
}
OIC_LOG(DEBUG, TAG, "OUT - CALEClientCloseProfileProxy");
return CA_STATUS_OK;
+
+error_exit:
+ CACheckJNIException(env);
+ return CA_STATUS_FAILED;
}
// call disconnect gatt method
OIC_LOG(INFO, TAG, "CALL API - disconnect");
(*env)->CallVoidMethod(env, bluetoothGatt, jni_mid_disconnectGatt);
- if ((*env)->ExceptionCheck(env))
+ if (CACheckJNIException(env))
{
OIC_LOG(ERROR, TAG, "disconnect has failed");
- (*env)->ExceptionDescribe(env);
- (*env)->ExceptionClear(env);
return CA_STATUS_FAILED;
}
if (!address)
{
OIC_LOG(ERROR, TAG, "address is null");
+ CACheckJNIException(env);
return CA_STATUS_FAILED;
}
if (!setAddress)
{
OIC_LOG(ERROR, TAG, "setAddress is null");
+ CACheckJNIException(env);
(*env)->ReleaseStringUTFChars(env, remote_address, address);
return CA_STATUS_FAILED;
}
if (!ret)
{
OIC_LOG(ERROR, TAG, "discoverServices has not been started");
+ CACheckJNIException(env);
return CA_STATUS_FAILED;
}
const char* address = (*env)->GetStringUTFChars(env, jni_address, NULL);
if (!address)
{
+ CACheckJNIException(env);
CALEClientSendFinish(env, gatt);
return CA_STATUS_FAILED;
}
VERIFY_NON_NULL(gatt, TAG, "gatt is null");
jobject gattParam = (*env)->NewGlobalRef(env, gatt);
+ CACheckJNIException(env);
if (CA_STATUS_OK != ca_thread_pool_add_task(g_threadPoolHandle,
CALEWriteCharacteristicThread, (void*)gattParam))
{
}
else
{
+ CACheckJNIException(env);
OIC_LOG(ERROR, TAG, "writeCharacteristic has failed");
return CA_STATUS_FAILED;
}
if (!jni_uuid)
{
OIC_LOG(ERROR, TAG, "jni_uuid is null");
+ CACheckJNIException(env);
return CA_STATUS_FAILED;
}
else
{
OIC_LOG(ERROR, TAG, "readCharacteristic has failed");
+ CACheckJNIException(env);
return CA_STATUS_FAILED;
}
else
{
OIC_LOG(ERROR, TAG, "setCharacteristicNotification has failed");
+ CACheckJNIException(env);
return CA_STATUS_FAILED;
}
if (!jni_obj_gattService)
{
OIC_LOG(ERROR, TAG, "jni_obj_gattService is null");
+ CACheckJNIException(env);
return NULL;
}
if (!uuid)
{
OIC_LOG(ERROR, TAG, "uuid is null");
+ CACheckJNIException(env);
return NULL;
}
return NULL;
}
- OIC_LOG(DEBUG, TAG, "request to get Characteristic");
+ OIC_LOG(DEBUG, TAG, "CALL API getCharacteristic");
jobject jni_obj_GattCharacteristic = (*env)->CallObjectMethod(env, jni_obj_gattService,
jni_mid_getCharacteristic,
jni_obj_tx_uuid);
+ if (!jni_obj_GattCharacteristic)
+ {
+ OIC_LOG(ERROR, TAG, "getCharacteristic has failed");
+ CACheckJNIException(env);
+ return NULL;
+ }
(*env)->ReleaseStringUTFChars(env, characterUUID, uuid);
return jni_obj_GattCharacteristic;
if (!jni_uuid)
{
OIC_LOG(ERROR, TAG, "jni_uuid is null");
- return NULL;
+ goto error_exit;
}
jobject jni_obj_GattCharacteristic = CALEClientGetGattService(env, bluetoothGatt, jni_uuid);
if (!jni_cid_BTGattCharacteristic)
{
OIC_LOG(ERROR, TAG, "jni_cid_BTGattCharacteristic is null");
- return NULL;
+ goto error_exit;
}
OIC_LOG(DEBUG, TAG, "set value in Characteristic");
if (!jni_mid_setValue)
{
OIC_LOG(ERROR, TAG, "jni_mid_setValue is null");
- return NULL;
+ goto error_exit;
}
jboolean ret = (*env)->CallBooleanMethod(env, jni_obj_GattCharacteristic, jni_mid_setValue,
else
{
OIC_LOG(ERROR, TAG, "the locally stored value hasn't been set");
- return NULL;
+ goto error_exit;
}
// set Write Type
if (!jni_mid_setWriteType)
{
OIC_LOG(ERROR, TAG, "jni_mid_setWriteType is null");
- return NULL;
+ goto error_exit;
}
jfieldID jni_fid_no_response = (*env)->GetStaticFieldID(env, jni_cid_BTGattCharacteristic,
if (!jni_fid_no_response)
{
OIC_LOG(ERROR, TAG, "jni_fid_no_response is not available");
- return NULL;
+ goto error_exit;
}
jint jni_int_val = (*env)->GetStaticIntField(env, jni_cid_BTGattCharacteristic,
jni_fid_no_response);
+ CACheckJNIException(env);
(*env)->CallVoidMethod(env, jni_obj_GattCharacteristic, jni_mid_setWriteType, jni_int_val);
+ if (CACheckJNIException(env))
+ {
+ OIC_LOG(ERROR, TAG, "setWriteType has failed");
+ }
return jni_obj_GattCharacteristic;
+
+error_exit:
+ CACheckJNIException(env);
+ return NULL;
}
jbyteArray CALEClientGetValueFromCharacteristic(JNIEnv *env, jobject characteristic)
jbyteArray jni_obj_data_array = (*env)->CallObjectMethod(env, characteristic,
jni_mid_getValue);
+ CACheckJNIException(env);
return jni_obj_data_array;
}
if (!jni_cid_uuid_list)
{
OIC_LOG(ERROR, TAG, "jni_cid_uuid_list is null");
+ CACheckJNIException(env);
goto error_exit;
}
if (!jni_obj_uuid_list)
{
OIC_LOG(ERROR, TAG, "jni_obj_uuid_list is null");
+ CACheckJNIException(env);
goto error_exit;
}
(*env)->SetObjectArrayElement(env, jni_obj_uuid_list, 0, jni_obj_uuid);
g_uuidList = (jobjectArray)(*env)->NewGlobalRef(env, jni_obj_uuid_list);
+ CACheckJNIException(env);
if (isAttached)
{
if (!jni_obj_cc_uuid)
{
OIC_LOG(ERROR, TAG, "jni_obj_cc_uuid is null");
- return CA_STATUS_FAILED;
}
OIC_LOG(DEBUG, TAG, "request to get descriptor");
if (!jni_obj_descriptor)
{
OIC_LOG(INFO, TAG, "jni_obj_descriptor is null");
- return CA_NOT_SUPPORTED;
+ goto error_exit;
}
OIC_LOG(DEBUG, TAG, "set value in descriptor");
if (!jni_cid_descriptor)
{
OIC_LOG(ERROR, TAG, "jni_cid_descriptor is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jmethodID jni_mid_setValue = (*env)->GetMethodID(env, jni_cid_descriptor, "setValue", "([B)Z");
if (!jni_mid_setValue)
{
OIC_LOG(ERROR, TAG, "jni_mid_setValue is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jfieldID jni_fid_NotiValue = (*env)->GetStaticFieldID(env, jni_cid_descriptor,
if (!jni_fid_NotiValue)
{
OIC_LOG(ERROR, TAG, "jni_fid_NotiValue is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
OIC_LOG(DEBUG, TAG, "get ENABLE_NOTIFICATION_VALUE");
else
{
OIC_LOG(ERROR, TAG, "setValue has failed");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jmethodID jni_mid_writeDescriptor = CAGetJNIMethodID(env, "android/bluetooth/BluetoothGatt",
else
{
OIC_LOG(ERROR, TAG, "writeDescriptor has failed");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
return CA_STATUS_OK;
+
+error_exit:
+ CACheckJNIException(env);
+ return CA_STATUS_FAILED;
}
void CALEClientCreateScanDeviceList(JNIEnv *env)
if (!remoteAddress)
{
OIC_LOG(ERROR, TAG, "remoteAddress is null");
+ CACheckJNIException(env);
(*env)->DeleteLocalRef(env, jni_remoteAddress);
oc_mutex_unlock(g_deviceListMutex);
return CA_STATUS_FAILED;
if (!CALEClientIsDeviceInScanDeviceList(env, remoteAddress))
{
jobject gdevice = (*env)->NewGlobalRef(env, device);
+ CACheckJNIException(env);
u_arraylist_add(g_deviceList, gdevice);
oc_cond_signal(g_deviceDescCond);
OIC_LOG_V(DEBUG, TAG, "Added a new BT Device in deviceList [%s]", remoteAddress);
if (!setAddress)
{
OIC_LOG(ERROR, TAG, "setAddress is null");
+ CACheckJNIException(env);
(*env)->DeleteLocalRef(env, jni_setAddress);
return true;
}
if (!setAddress)
{
OIC_LOG(ERROR, TAG, "setAddress is null");
+ CACheckJNIException(env);
oc_mutex_unlock(g_deviceListMutex);
return CA_STATUS_FAILED;
}
if (!remoteAddress)
{
OIC_LOG(ERROR, TAG, "remoteAddress is null");
+ CACheckJNIException(env);
(*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
oc_mutex_unlock(g_deviceListMutex);
return CA_STATUS_FAILED;
if (!remoteAddress)
{
OIC_LOG(ERROR, TAG, "remoteAddress is null");
+ CACheckJNIException(env);
(*env)->DeleteLocalRef(env, jni_remoteAddress);
oc_mutex_unlock(g_gattObjectMutex);
return CA_STATUS_FAILED;
if (!setAddress)
{
OIC_LOG(ERROR, TAG, "setAddress is null");
+ CACheckJNIException(env);
(*env)->DeleteLocalRef(env, jni_setAddress);
return true;
}
if (!setAddress)
{
OIC_LOG(ERROR, TAG, "setAddress is null");
+ CACheckJNIException(env);
(*env)->DeleteLocalRef(env, jni_setAddress);
oc_mutex_unlock(g_gattObjectMutex);
return NULL;
if (!setAddress)
{
OIC_LOG(ERROR, TAG, "setAddress is null");
+ CACheckJNIException(env);
oc_mutex_unlock(g_gattObjectMutex);
return CA_STATUS_FAILED;
}
if (!remoteAddress)
{
OIC_LOG(ERROR, TAG, "remoteAddress is null");
+ CACheckJNIException(env);
(*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
oc_mutex_unlock(g_gattObjectMutex);
return CA_STATUS_FAILED;
if (!setAddress)
{
OIC_LOG(ERROR, TAG, "setAddress is null");
+ CACheckJNIException(env);
oc_mutex_unlock(g_gattObjectMutex);
return CA_STATUS_FAILED;
}
if (!targetAddress)
{
OIC_LOG(ERROR, TAG, "targetAddress is not available");
+ CACheckJNIException(env);
return NULL;
}
jobject jni_obj_device = (*env)->CallObjectMethod(env, jarrayObj, jni_mid_getDevice);
if (!jni_obj_device)
{
+ CACheckJNIException(env);
oc_mutex_unlock(g_gattObjectMutex);
OIC_LOG(ERROR, TAG, "jni_obj_device is null");
(*env)->ReleaseStringUTFChars(env, jni_btTargetAddress, targetAddress);
const char* btAddress = (*env)->GetStringUTFChars(env, jni_btAddress, NULL);
if (!btAddress)
{
+ CACheckJNIException(env);
oc_mutex_unlock(g_gattObjectMutex);
OIC_LOG(ERROR, TAG, "btAddress is not available");
(*env)->ReleaseStringUTFChars(env, jni_btTargetAddress, targetAddress);
if (!address)
{
OIC_LOG(ERROR, TAG, "targetAddress is not available");
+ CACheckJNIException(env);
(*env)->DeleteLocalRef(env, jni_Address);
return CA_STATUS_FAILED;
}
VERIFY_NON_NULL_VOID(callback, TAG, "callback is null");
g_leScanCallback = (*env)->NewGlobalRef(env, callback);
+ CACheckJNIException(env);
}
JNIEXPORT void JNICALL
VERIFY_NON_NULL_VOID(callback, TAG, "callback is null");
g_leGattCallback = (*env)->NewGlobalRef(env, callback);
+ CACheckJNIException(env);
}
JNIEXPORT void JNICALL
if (!address)
{
OIC_LOG(ERROR, TAG, "address is null");
+ CACheckJNIException(env);
goto error_exit;
}
OIC_LOG_V(DEBUG, TAG, "CALeGattConnectionStateChangeCallback - address [%s]", address);
const char* address = (*env)->GetStringUTFChars(env, jni_address, NULL);
if (!address)
{
+ CACheckJNIException(env);
CALEClientSendFinish(env, gatt);
return;
}
const char* address = (*env)->GetStringUTFChars(env, jni_address, NULL);
if (!address)
{
+ CACheckJNIException(env);
goto error_exit;
}
if (g_clientErrorCallback)
{
jint length = (*env)->GetArrayLength(env, data);
+ CACheckJNIException(env);
g_clientErrorCallback(address, data, length, CA_SEND_FAILED);
CALogSendStateInfo(CA_ADAPTER_GATT_BTLE, address, 0, length,
false, "writeChar failure");
jboolean isCopy;
jbyte *jni_byte_responseData = (jbyte*) (*env)->GetByteArrayElements(env, data, &isCopy);
+ CACheckJNIException(env);
OIC_LOG_V(DEBUG, TAG, "CALeGattCharacteristicChangedCallback - raw data received : %p",
jni_byte_responseData);
if (!address)
{
OIC_LOG(ERROR, TAG, "address is null");
+ CACheckJNIException(env);
OICFree(receivedData);
return;
}
const char* address = (*env)->GetStringUTFChars(env, jni_address, NULL);
if (!address)
{
+ CACheckJNIException(env);
goto error_exit;
}
if (!address)
{
OIC_LOG(ERROR, TAG, "address is null");
+ CACheckJNIException(env);
return CA_STATUS_FAILED;
}
if (!address)
{
OIC_LOG(ERROR, TAG, "address is null");
+ CACheckJNIException(env);
return;
}
if (!address)
{
OIC_LOG(ERROR, TAG, "address is null");
+ CACheckJNIException(env);
return;
}
jint jni_state = (jint)(*env)->CallIntMethod(env, g_bluetoothManager,
jni_mid_getConnectionState,
device, GATT_PROFILE);
+ if (CACheckJNIException(env))
+ {
+ OIC_LOG(ERROR, TAG, "getConnectionState has failed");
+ return -1;
+ }
+
OIC_LOG_V(INFO, TAG, "connection state is %d", jni_state);
return jni_state;
}
if (!jni_obj_bluetoothGattService)
{
OIC_LOG(ERROR, TAG, "jni_obj_bluetoothGattService is null");
+ CACheckJNIException(env);
return NULL;
}
if (!jni_obj_bluetoothGattCharacteristic)
{
OIC_LOG(ERROR, TAG, "jni_obj_bluetoothGattCharacteristic is null");
+ CACheckJNIException(env);
return NULL;
}
if (JNI_FALSE == jni_boolean_setValue)
{
OIC_LOG(ERROR, TAG, "Fail to set response data");
+ CACheckJNIException(env);
}
OIC_LOG(DEBUG, TAG, "OUT - CALEServerSetResponseData");
if (JNI_FALSE == jni_boolean_notifyCharacteristicChanged)
{
OIC_LOG(ERROR, TAG, "Fail to notify characteristic");
+ CACheckJNIException(env);
return CA_SEND_FAILED;
}
if (JNI_FALSE == jni_boolean_sendResponse)
{
OIC_LOG(ERROR, TAG, "Fail to send response for gatt characteristic write request");
+ CACheckJNIException(env);
return CA_SEND_FAILED;
}
if (!jni_cid_AdvertiseSettings)
{
OIC_LOG(ERROR, TAG, "jni_cid_AdvertiseSettings is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jmethodID jni_mid_AdvertiseSettings = (*env)->GetMethodID(env, jni_cid_AdvertiseSettings,
if (!jni_mid_AdvertiseSettings)
{
OIC_LOG(ERROR, TAG, "jni_mid_AdvertiseSettings is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jobject jni_AdvertiseSettings = (*env)->NewObject(env, jni_cid_AdvertiseSettings,
if (!jni_AdvertiseSettings)
{
OIC_LOG(ERROR, TAG, "jni_AdvertiseSettings is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jmethodID jni_mid_setAdvertiseMode = (*env)->GetMethodID(env, jni_cid_AdvertiseSettings,
if (!jni_mid_setAdvertiseMode)
{
OIC_LOG(ERROR, TAG, "jni_mid_setAdvertiseMode is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
// 0: Low power, 1: Balanced
if (!jni_obj_setAdvertiseMode)
{
OIC_LOG(ERROR, TAG, "jni_obj_setAdvertiseMode is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jmethodID jni_mid_setConnectable = (*env)->GetMethodID(env, jni_cid_AdvertiseSettings,
if (!jni_mid_setConnectable)
{
OIC_LOG(ERROR, TAG, "jni_mid_setConnectable is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jobject jni_obj_setConnectable = (*env)->CallObjectMethod(env, jni_AdvertiseSettings,
if (!jni_obj_setConnectable)
{
OIC_LOG(ERROR, TAG, "jni_obj_setConnectable is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jmethodID jni_mid_setTimeout = (*env)->GetMethodID(env, jni_cid_AdvertiseSettings, "setTimeout",
if (!jni_mid_setTimeout)
{
OIC_LOG(ERROR, TAG, "jni_mid_setTimeout is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
//A value of 0 will disable the time limit
if (!jni_obj_setTimeout)
{
OIC_LOG(ERROR, TAG, "jni_obj_setTimeout is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jclass jni_cid_AdvertiseDataBuilder = (*env)->FindClass(env,
if (!jni_cid_AdvertiseDataBuilder)
{
OIC_LOG(ERROR, TAG, "jni_cid_AdvertiseDataBuilder is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jmethodID jni_mid_AdvertiseDataBuilder = (*env)->GetMethodID(env, jni_cid_AdvertiseDataBuilder,
if (!jni_mid_AdvertiseDataBuilder)
{
OIC_LOG(ERROR, TAG, "jni_mid_AdvertiseDataBuilder is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jobject jni_AdvertiseDataBuilder = (*env)->NewObject(env, jni_cid_AdvertiseDataBuilder,
if (!jni_AdvertiseDataBuilder)
{
OIC_LOG(ERROR, TAG, "jni_AdvertiseDataBuilder is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jobject jni_AdvertiseDataBuilderForScanRsp = (*env)->NewObject(env,
if (!jni_AdvertiseDataBuilderForScanRsp)
{
OIC_LOG(ERROR, TAG, "jni_AdvertiseDataBuilderForScanRsp is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jobject jni_obj_serviceUUID = CALEGetUuidFromString(env, OIC_GATT_SERVICE_UUID);
if (!jni_mid_addServiceUuid)
{
OIC_LOG(ERROR, TAG, "jni_mid_addServiceUuid is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jobject jni_obj_addServiceUuid = (*env)->CallObjectMethod(env, jni_AdvertiseDataBuilder,
if (!jni_obj_addServiceUuid)
{
OIC_LOG(ERROR, TAG, "jni_obj_addServiceUuid is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
// Device name has to be included in advertise packet after Android API 23
if (!jni_mid_setIncludeDeviceName)
{
OIC_LOG(ERROR, TAG, "jni_mid_setIncludeDeviceName is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jobject jni_obj_setIncludeDeviceName = (*env)->CallObjectMethod(env,
if (!jni_obj_setIncludeDeviceName)
{
OIC_LOG(ERROR, TAG, "jni_obj_setIncludeDeviceName is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jclass jni_cid_BTAdapter = (*env)->FindClass(env, "android/bluetooth/BluetoothAdapter");
if (!jni_mid_getDefaultAdapter)
{
OIC_LOG(ERROR, TAG, "jni_mid_getDefaultAdapter is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jobject jni_obj_BTAdapter = (*env)->CallStaticObjectMethod(env, jni_cid_BTAdapter,
if (!jni_obj_BTAdapter)
{
OIC_LOG(ERROR, TAG, "jni_obj_BTAdapter is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jmethodID jni_mid_getBluetoothLeAdvertiser = (*env)->GetMethodID(env, jni_cid_BTAdapter,
if (!jni_mid_getBluetoothLeAdvertiser)
{
OIC_LOG(ERROR, TAG, "jni_mid_getBluetoothLeAdvertiser is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jobject jni_obj_getBluetoothLeAdvertiser = (*env)->CallObjectMethod(
if (!jni_obj_getBluetoothLeAdvertiser)
{
OIC_LOG(ERROR, TAG, "jni_obj_getBluetoothLeAdvertiser is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jmethodID jni_mid_build_LeAdvertiseSettings = (*env)->GetMethodID(env,
if (!jni_mid_build_LeAdvertiseSettings)
{
OIC_LOG(ERROR, TAG, "jni_mid_build_LeAdvertiseSettings is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jobject jni_obj_build_LeAdvertiseSettings = (*env)->CallObjectMethod(
if (!jni_obj_build_LeAdvertiseSettings)
{
OIC_LOG(ERROR, TAG, "jni_obj_build_LeAdvertiseSettings is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jmethodID jni_mid_build_LeAdvertiseData = (*env)->GetMethodID(env, jni_cid_AdvertiseDataBuilder,
if (!jni_mid_build_LeAdvertiseData)
{
OIC_LOG(ERROR, TAG, "jni_mid_build_LeAdvertiseData is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jobject jni_obj_build_LeAdvertiseData = (*env)->CallObjectMethod(env, jni_AdvertiseDataBuilder,
if (!jni_obj_build_LeAdvertiseData)
{
OIC_LOG(ERROR, TAG, "jni_obj_build_LeAdvertiseData is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jobject jni_obj_build_LeAdvertiseDataForScanRsp = (*env)->CallObjectMethod(env,
if (!jni_obj_build_LeAdvertiseDataForScanRsp)
{
OIC_LOG(ERROR, TAG, "jni_obj_build_LeAdvertiseDataForScanRsp is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jmethodID jni_mid_startAdvertising = CAGetJNIMethodID(env, "android/bluetooth/le/"
(*env)->CallVoidMethod(env, jni_obj_getBluetoothLeAdvertiser, jni_mid_startAdvertising,
jni_obj_build_LeAdvertiseSettings, jni_obj_build_LeAdvertiseData,
jni_obj_build_LeAdvertiseDataForScanRsp, advertiseCallback);
-
- if ((*env)->ExceptionCheck(env))
+ if (CACheckJNIException(env))
{
OIC_LOG(ERROR, TAG, "StartAdvertising has failed");
- (*env)->ExceptionDescribe(env);
- (*env)->ExceptionClear(env);
return CA_STATUS_FAILED;
}
OIC_LOG(DEBUG, TAG, "Advertising started!!");
-
OIC_LOG(DEBUG, TAG, "OUT - CALEServerStartAdvertise");
return CA_STATUS_OK;
+
+error_exit:
+ CACheckJNIException(env);
+ return CA_STATUS_FAILED;
}
CAResult_t CALEServerStopAdvertise(JNIEnv *env, jobject advertiseCallback)
if (!jni_cid_BTAdapter)
{
OIC_LOG(ERROR, TAG, "jni_cid_BTAdapter is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jmethodID jni_mid_getDefaultAdapter = (*env)->GetStaticMethodID(env, jni_cid_BTAdapter,
if (!jni_mid_getDefaultAdapter)
{
OIC_LOG(ERROR, TAG, "jni_mid_getDefaultAdapter is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jmethodID jni_mid_getBTLeAdvertiser = (*env)->GetMethodID(env, jni_cid_BTAdapter,
if (!jni_mid_getBTLeAdvertiser)
{
OIC_LOG(ERROR, TAG, "jni_mid_getBTLeAdvertiser is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jmethodID jni_mid_stopAdvertising = CAGetJNIMethodID(env, "android/bluetooth/le/"
if (!jni_mid_stopAdvertising)
{
OIC_LOG(ERROR, TAG, "jni_mid_stopAdvertising is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jobject jni_obj_BTAdapter = (*env)->CallStaticObjectMethod(env, jni_cid_BTAdapter,
if (!jni_obj_BTAdapter)
{
OIC_LOG(ERROR, TAG, "jni_obj_BTAdapter is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jobject jni_obj_getBluetoothLeAdvertiser = (*env)->CallObjectMethod(env, jni_obj_BTAdapter,
if (!jni_obj_getBluetoothLeAdvertiser)
{
OIC_LOG(ERROR, TAG, "jni_obj_getBluetoothLeAdvertiser is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
(*env)->CallVoidMethod(env, jni_obj_getBluetoothLeAdvertiser, jni_mid_stopAdvertising,
advertiseCallback);
- if ((*env)->ExceptionCheck(env))
+ if (CACheckJNIException(env))
{
OIC_LOG(ERROR, TAG, "getBluetoothLeAdvertiser has failed");
- (*env)->ExceptionDescribe(env);
- (*env)->ExceptionClear(env);
return CA_STATUS_FAILED;
}
OIC_LOG(DEBUG, TAG, "Advertising stopped!!");
return CA_STATUS_OK;
+
+error_exit:
+ CACheckJNIException(env);
+ return CA_STATUS_FAILED;
}
CAResult_t CALEServerStartGattServer(JNIEnv *env, jobject gattServerCallback)
if (!CALEIsEnableBTAdapter(env))
{
OIC_LOG(ERROR, TAG, "BT adapter is not enabled");
- return NULL;
+ goto error_exit;
}
jclass jni_cid_context = (*env)->FindClass(env, "android/content/Context");
if (!jni_cid_context)
{
OIC_LOG(ERROR, TAG, "jni_cid_context is null");
- return NULL;
+ goto error_exit;
}
jfieldID jni_fid_bluetoothService = (*env)->GetStaticFieldID(env, jni_cid_context,
if (!jni_fid_bluetoothService)
{
OIC_LOG(ERROR, TAG, "jni_fid_bluetoothService is null");
- return NULL;
+ goto error_exit;
}
jmethodID jni_mid_getSystemService = (*env)->GetMethodID(env, jni_cid_context,
if (!jni_mid_getSystemService)
{
OIC_LOG(ERROR, TAG, "jni_mid_getSystemService is null");
- return NULL;
+ goto error_exit;
}
jmethodID jni_mid_openGattServer = CAGetJNIMethodID(env, "android/bluetooth/"
if (!jni_obj_bluetoothService)
{
OIC_LOG(ERROR, TAG, "jni_obj_bluetoothService is null");
- return NULL;
+ goto error_exit;
}
jobject jni_obj_bluetoothManager = (*env)->CallObjectMethod(env, g_context,
if (!jni_obj_bluetoothManager)
{
OIC_LOG(ERROR, TAG, "jni_obj_bluetoothManager is null");
- return NULL;
+ goto error_exit;
}
if (g_bluetoothManager)
if (!jni_obj_bluetoothGattServer)
{
OIC_LOG(ERROR, TAG, "jni_obj_bluetoothGattServer is null");
- return NULL;
+ goto error_exit;
}
OIC_LOG(DEBUG, TAG, "OUT - CALEServerOpenGattServer");
return jni_obj_bluetoothGattServer;
+
+error_exit:
+ CACheckJNIException(env);
+ return NULL;
}
jobject CALEServerCreateGattService(JNIEnv *env)
if (!jni_cid_bluetoothGattService)
{
OIC_LOG(ERROR, TAG, "jni_cid_bluetoothGattService is null");
- return NULL;
+ goto error_exit;
}
jclass jni_cid_bluetoothGattCharacteristic = (*env)->FindClass(env, "android/bluetooth/"
if (!jni_cid_bluetoothGattCharacteristic)
{
OIC_LOG(ERROR, TAG, "jni_cid_bluetoothGattCharacteristic is null");
- return NULL;
+ goto error_exit;
}
jfieldID jni_fid_serviceType = (*env)->GetStaticFieldID(env, jni_cid_bluetoothGattService,
if (!jni_fid_serviceType)
{
OIC_LOG(ERROR, TAG, "jni_fid_serviceType is null");
- return NULL;
+ goto error_exit;
}
jfieldID jni_fid_readProperties = (*env)->GetStaticFieldID(env,
if (!jni_fid_readProperties)
{
OIC_LOG(ERROR, TAG, "jni_fid_readProperties is null");
- return NULL;
+ goto error_exit;
}
jfieldID jni_fid_writeProperties = (*env)->GetStaticFieldID(env,
if (!jni_fid_writeProperties)
{
OIC_LOG(ERROR, TAG, "jni_fid_writeProperties is null");
- return NULL;
+ goto error_exit;
}
jfieldID jni_fid_readPermissions = (*env)->GetStaticFieldID(env,
if (!jni_fid_readPermissions)
{
OIC_LOG(ERROR, TAG, "jni_fid_readPermissions is null");
- return NULL;
+ goto error_exit;
}
jfieldID jni_fid_writePermissions = (*env)->GetStaticFieldID(
if (!jni_fid_writePermissions)
{
OIC_LOG(ERROR, TAG, "jni_fid_writePermissions is null");
- return NULL;
+ goto error_exit;
}
jmethodID jni_mid_bluetoothGattService = (*env)->GetMethodID(env, jni_cid_bluetoothGattService,
if (!jni_mid_bluetoothGattService)
{
OIC_LOG(ERROR, TAG, "jni_mid_bluetoothGattService is null");
- return NULL;
+ goto error_exit;
}
jmethodID jni_mid_addCharacteristic = (*env)->GetMethodID(env, jni_cid_bluetoothGattService,
if (!jni_mid_addCharacteristic)
{
OIC_LOG(ERROR, TAG, "jni_mid_addCharacteristic is null");
- return NULL;
+ goto error_exit;
}
jmethodID jni_mid_bluetoothGattCharacteristic = (*env)->GetMethodID(
if (!jni_mid_bluetoothGattCharacteristic)
{
OIC_LOG(ERROR, TAG, "jni_mid_bluetoothGattCharacteristic is null");
- return NULL;
+ goto error_exit;
}
jobject jni_obj_serviceUUID = CALEGetUuidFromString(env, OIC_GATT_SERVICE_UUID);
if (!jni_bluetoothGattService)
{
OIC_LOG(ERROR, TAG, "jni_bluetoothGattService is null");
- return NULL;
+ goto error_exit;
}
jobject jni_obj_readUuid = CALEGetUuidFromString(env, OIC_GATT_CHARACTERISTIC_RESPONSE_UUID);
jint jni_int_readProperties = (*env)->GetStaticIntField(env,
jni_cid_bluetoothGattCharacteristic,
jni_fid_readProperties);
+ CACheckJNIException(env);
jint jni_int_readPermissions = (*env)->GetStaticIntField(env,
jni_cid_bluetoothGattCharacteristic,
jni_fid_readPermissions);
+ CACheckJNIException(env);
jint jni_int_writePermissions = (*env)->GetStaticIntField(env,
jni_cid_bluetoothGattCharacteristic,
jni_fid_writePermissions);
+ CACheckJNIException(env);
jobject jni_readCharacteristic = (*env)->NewObject(env, jni_cid_bluetoothGattCharacteristic,
jni_mid_bluetoothGattCharacteristic,
if (!jni_readCharacteristic)
{
OIC_LOG(ERROR, TAG, "jni_readCharacteristic is null");
- return NULL;
+ goto error_exit;
}
jboolean jni_boolean_addReadCharacteristic = (*env)->CallBooleanMethod(
if (!jni_boolean_addReadCharacteristic)
{
OIC_LOG(ERROR, TAG, "jni_boolean_addReadCharacteristic is null");
- return NULL;
+ goto error_exit;
}
jobject jni_obj_writeUuid = CALEGetUuidFromString(env, OIC_GATT_CHARACTERISTIC_REQUEST_UUID);
jint jni_int_writeProperties = (*env)->GetStaticIntField(env,
jni_cid_bluetoothGattCharacteristic,
jni_fid_writeProperties);
+ CACheckJNIException(env);
jobject jni_writeCharacteristic = (*env)->NewObject(env, jni_cid_bluetoothGattCharacteristic,
jni_mid_bluetoothGattCharacteristic,
if (!jni_writeCharacteristic)
{
OIC_LOG(ERROR, TAG, "jni_writeCharacteristic is null");
- return NULL;
+ goto error_exit;
}
jboolean jni_boolean_addWriteCharacteristic = (*env)->CallBooleanMethod(
if (JNI_FALSE == jni_boolean_addWriteCharacteristic)
{
OIC_LOG(ERROR, TAG, "Fail to add jni_boolean_addReadCharacteristic");
- return NULL;
+ goto error_exit;
}
OIC_LOG(DEBUG, TAG, "OUT - CALEServerCreateGattService");
return jni_bluetoothGattService;
+
+error_exit:
+ CACheckJNIException(env);
+ return NULL;
}
CAResult_t CALEServerAddDescriptor(JNIEnv *env, jobject characteristic)
if (!jni_cid_bluetoothGattDescriptor)
{
OIC_LOG(ERROR, TAG, "jni_cid_bluetoothGattDescriptor is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jmethodID jni_mid_bluetoothGattDescriptor = (*env)->GetMethodID(env,
if (!jni_mid_bluetoothGattDescriptor)
{
OIC_LOG(ERROR, TAG, "jni_mid_bluetoothGattDescriptor is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jfieldID jni_fid_readPermissions = (*env)->GetStaticFieldID(env,
if (!jni_fid_readPermissions)
{
OIC_LOG(ERROR, TAG, "jni_fid_readPermissions is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jobject jni_obj_readUuid = CALEGetUuidFromString(env, OIC_GATT_CHARACTERISTIC_CONFIG_UUID);
jint jni_int_readPermissions = (*env)->GetStaticIntField(env, jni_cid_bluetoothGattDescriptor,
jni_fid_readPermissions);
+ CACheckJNIException(env);
OIC_LOG(DEBUG, TAG, "initialize new Descriptor");
if (!jni_readDescriptor)
{
OIC_LOG(ERROR, TAG, "jni_readDescriptor is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jclass jni_cid_GattCharacteristic = (*env)->FindClass(env, "android/bluetooth/"
if (!jni_cid_GattCharacteristic)
{
OIC_LOG(ERROR, TAG, "jni_cid_GattCharacteristic is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jmethodID jni_mid_addDescriptor = (*env)->GetMethodID(env, jni_cid_GattCharacteristic,
if (!jni_mid_addDescriptor)
{
OIC_LOG(ERROR, TAG, "jni_mid_addDescriptor is null");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
jboolean jni_boolean_addDescriptor = (*env)->CallBooleanMethod(env, characteristic,
if (JNI_FALSE == jni_boolean_addDescriptor)
{
OIC_LOG(ERROR, TAG, "addDescriptor has failed");
- return CA_STATUS_FAILED;
+ goto error_exit;
}
else
{
OIC_LOG(DEBUG, TAG, "addDescriptor success");
}
return CA_STATUS_OK;
+
+error_exit:
+ CACheckJNIException(env);
+ return CA_STATUS_FAILED;
}
CAResult_t CALEServerAddGattService(JNIEnv *env, jobject bluetoothGattServer,
if (JNI_FALSE == jni_boolean_addService)
{
OIC_LOG(ERROR, TAG, "Fail to add GATT service");
+ CACheckJNIException(env);
return CA_STATUS_FAILED;
}
if (JNI_FALSE == jni_boolean_connect)
{
OIC_LOG(ERROR, TAG, "Fail to connect");
+ CACheckJNIException(env);
return CA_STATUS_FAILED;
}
(*env)->CallVoidMethod(env, g_bluetoothGattServer, jni_mid_cancelConnection, bluetoothDevice);
- if ((*env)->ExceptionCheck(env))
+ if (CACheckJNIException(env))
{
OIC_LOG(ERROR, TAG, "cancelConnection has failed");
- (*env)->ExceptionDescribe(env);
- (*env)->ExceptionClear(env);
return CA_STATUS_FAILED;
}
OIC_LOG(DEBUG, TAG, "request to close GATT");
(*env)->CallVoidMethod(env, bluetoothGattServer, jni_mid_closeGatt);
- if ((*env)->ExceptionCheck(env))
+ if (CACheckJNIException(env))
{
OIC_LOG(ERROR, TAG, "closeGATT has failed");
- (*env)->ExceptionDescribe(env);
- (*env)->ExceptionClear(env);
return CA_STATUS_FAILED;
}
if (jarrayObj)
{
g_obj_bluetoothDevice = (*env)->NewGlobalRef(env, jarrayObj);
+ CACheckJNIException(env);
}
(*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
break;
if (g_obj_bluetoothDevice)
{
jbyteArray jni_arr = (*env)->NewByteArray(env, dataLen);
+ CACheckJNIException(env);
(*env)->SetByteArrayRegion(env, jni_arr, 0, dataLen, (jbyte*) data);
+ CACheckJNIException(env);
g_sendBuffer = (jbyteArray)(*env)->NewGlobalRef(env, jni_arr);
+ CACheckJNIException(env);
CAResult_t res = CALEServerSend(env, g_obj_bluetoothDevice, g_sendBuffer);
if (CA_STATUS_OK != res)
g_sendBuffer = NULL;
}
jbyteArray jni_arr = (*env)->NewByteArray(env, dataLen);
+ CACheckJNIException(env);
(*env)->SetByteArrayRegion(env, jni_arr, 0, dataLen, (jbyte*) data);
+ CACheckJNIException(env);
g_sendBuffer = (jbyteArray)(*env)->NewGlobalRef(env, jni_arr);
+ CACheckJNIException(env);
uint32_t length = u_arraylist_length(g_connectedDeviceList);
for (uint32_t index = 0; index < length; index++)
// send data for all device
jbyteArray jni_bytearr_data = (*env)->NewByteArray(env, dataLen);
+ CACheckJNIException(env);
(*env)->SetByteArrayRegion(env, jni_bytearr_data, 0, dataLen, (jbyte*) data);
+ CACheckJNIException(env);
jstring jni_address = CALEGetAddressFromBTDevice(env, jarrayObj);
if (!jni_address)
if (jarrayObj)
{
g_obj_bluetoothDevice = (*env)->NewGlobalRef(env, jarrayObj);
+ CACheckJNIException(env);
}
CAResult_t res = CALEServerSend(env, g_obj_bluetoothDevice, jni_bytearr_data);
VERIFY_NON_NULL_VOID(callback, TAG, "callback");
g_bluetoothGattServerCallback = (*env)->NewGlobalRef(env, callback);
+ CACheckJNIException(env);
}
JNIEXPORT void JNICALL
VERIFY_NON_NULL_VOID(callback, TAG, "callback");
g_leAdvertiseCallback = (*env)->NewGlobalRef(env, callback);
+ CACheckJNIException(env);
}
JNIEXPORT void JNICALL
if (!remoteAddress)
{
OIC_LOG(ERROR, TAG, "remoteAddress is null");
+ CACheckJNIException(env);
return;
}
// get Byte Array and covert to uint8_t*
jint length = (*env)->GetArrayLength(env, data);
+ CACheckJNIException(env);
jboolean isCopy;
jbyte *jni_byte_requestData = (jbyte *) (*env)->GetByteArrayElements(env, data, &isCopy);
+ CACheckJNIException(env);
uint8_t* requestData = NULL;
requestData = OICMalloc(length);
if (!address)
{
OIC_LOG(ERROR, TAG, "address is null");
+ CACheckJNIException(env);
OICFree(requestData);
return;
}
if (!jni_cid_UUID)
{
OIC_LOG(ERROR, TAG, "jni_cid_UUID is not available");
- return NULL;
+ goto error_exit;
}
jmethodID jni_mid_fromString = (*env)->GetStaticMethodID(env, jni_cid_UUID, "fromString",
if (!jni_mid_fromString)
{
OIC_LOG(ERROR, TAG, "jni_mid_fromString is not available");
- return NULL;
+ goto error_exit;
}
jstring str_uuid = (*env)->NewStringUTF(env, uuid);
if (!str_uuid)
{
OIC_LOG(ERROR, TAG, "str_uuid is not available");
- return NULL;
+ goto error_exit;
}
jobject jni_obj_uuid = (*env)->CallStaticObjectMethod(env, jni_cid_UUID, jni_mid_fromString,
if (!jni_obj_uuid)
{
OIC_LOG(ERROR, TAG, "Fail to get jni uuid object");
- return NULL;
+ goto error_exit;
}
return jni_obj_uuid;
+
+error_exit:
+ CACheckJNIException(env);
+ return NULL;
}
jobject CALEGetParcelUuid(JNIEnv *env, jobject uuid)
if (!jni_cid_ParcelUuid)
{
OIC_LOG(ERROR, TAG, "jni_cid_ParcelUuid is not available");
- return NULL;
+ goto error_exit;
}
jmethodID jni_mid_ParcelUuid = (*env)->GetMethodID(env, jni_cid_ParcelUuid, "<init>",
if (!jni_mid_ParcelUuid)
{
OIC_LOG(ERROR, TAG, "jni_mid_ParcelUuid is not available");
- return NULL;
+ goto error_exit;
}
jobject jni_ParcelUuid = (*env)->NewObject(env, jni_cid_ParcelUuid, jni_mid_ParcelUuid, uuid);
if (!jni_ParcelUuid)
{
OIC_LOG(ERROR, TAG, "Fail to get jni ParcelUuid");
- return NULL;
+ goto error_exit;
}
return jni_ParcelUuid;
+error_exit:
+ CACheckJNIException(env);
+ return NULL;
}
bool CALEIsBondedDevice(JNIEnv *env, jobject bluetoothDevice)
}
jint jni_bondState = (jint)(*env)->CallIntMethod(env, bluetoothDevice, jni_mid_getBondState);
-
+ CACheckJNIException(env);
OIC_LOG_V(DEBUG, TAG, "bond state is %d", jni_bondState);
if (BOND_BONDED == jni_bondState)
if (!jni_cid_BTAdapter)
{
OIC_LOG(ERROR, TAG, "getBondedDevices: jni_cid_BTAdapter is null");
- return NULL;
+ goto error_exit;
}
jmethodID jni_mid_getDefaultAdapter = (*env)->GetStaticMethodID(env, jni_cid_BTAdapter,
"getDefaultAdapter",
METHODID_OBJECTNONPARAM);
-
+ CACheckJNIException(env);
jobject jni_obj_BTAdapter = (*env)->CallStaticObjectMethod(env, jni_cid_BTAdapter,
jni_mid_getDefaultAdapter);
if (!jni_obj_BTAdapter)
{
OIC_LOG(ERROR, TAG, "getBondedDevices: bluetooth adapter is null");
- return NULL;
+ goto error_exit;
}
// Get a list of currently paired devices
if (!jni_mid_getBondedDevices)
{
OIC_LOG(ERROR, TAG, "getBondedDevices: jni_mid_getBondedDevicesr is null");
- return NULL;
+ goto error_exit;
}
jobject jni_obj_setPairedDevices = (*env)->CallObjectMethod(env, jni_obj_BTAdapter,
if (!jni_obj_setPairedDevices)
{
OIC_LOG(ERROR, TAG, "getBondedDevices: jni_obj_setPairedDevices is null");
- return NULL;
+ goto error_exit;
}
jmethodID jni_mid_toArray = CAGetJNIMethodID(env, "java/util/Set", "toArray",
if (!jni_arrayPairedDevices)
{
OIC_LOG(ERROR, TAG, "getBondedDevices: jni_arrayPairedDevices is null");
- return NULL;
+ goto error_exit;
}
return jni_arrayPairedDevices;
+
+error_exit:
+ CACheckJNIException(env);
+ return NULL;
}
jint CALEGetBTStateOnInfo(JNIEnv *env)
if (!jni_cid_BTAdapter)
{
OIC_LOG(ERROR, TAG, "getBTStateOnInfo: jni_cid_BTAdapter is null");
+ CACheckJNIException(env);
return -1;
}
if (!jni_fid_stateon)
{
OIC_LOG(ERROR, TAG, "get_field_state is not available");
+ CACheckJNIException(env);
return -1;
}
jint jni_int_val = (*env)->GetStaticIntField(env, jni_cid_BTAdapter, jni_fid_stateon);
+ CACheckJNIException(env);
OIC_LOG_V(DEBUG, TAG, "bluetooth.STATE_ON state integer value : %d", jni_int_val);
return jni_int_val;
if (!jni_cls_version)
{
OIC_LOG(ERROR, TAG, "jni_cls_version is null");
+ CACheckJNIException(env);
return -1;
}
if (!jni_fid_sdk)
{
OIC_LOG(ERROR, TAG, "jni_fid_sdk is null");
+ CACheckJNIException(env);
return -1;
}
jint jni_int_sdk = (*env)->GetStaticIntField(env, jni_cls_version, jni_fid_sdk);
+ CACheckJNIException(env);
OIC_LOG_V(DEBUG, TAG, "sdk version is %d", jni_int_sdk);
return jni_int_sdk;
if (!jni_cls_version)
{
OIC_LOG(ERROR, TAG, "jni_cls_version is null");
+ CACheckJNIException(env);
return -1;
}
if (!jni_fid_version)
{
OIC_LOG(ERROR, TAG, "jni_fid_version is null");
+ CACheckJNIException(env);
return -1;
}
jint jni_int_version = (*env)->GetStaticIntField(env, jni_cls_version, jni_fid_version);
+ CACheckJNIException(env);
OIC_LOG_V(DEBUG, TAG, "version [%s] is %d",versionName, jni_int_version);
return jni_int_version;
if (!jni_cid_BTAdapter)
{
OIC_LOG(ERROR, TAG, "jni_cid_BTAdapter: jni_cid_BTAdapter is null");
+ CACheckJNIException(env);
return JNI_FALSE;
}
if (!jni_mid_getDefaultAdapter)
{
OIC_LOG(ERROR, TAG, "jni_mid_getDefaultAdapter is null");
+ CACheckJNIException(env);
(*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
return JNI_FALSE;
}
if (!jni_obj_BTAdapter)
{
OIC_LOG(ERROR, TAG, "jni_obj_BTAdapter is null");
+ CACheckJNIException(env);
(*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
return JNI_FALSE;
}
if (!jni_mid_isEnable)
{
OIC_LOG(ERROR, TAG, "jni_mid_isEnable is null");
+ CACheckJNIException(env);
(*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
(*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
return JNI_FALSE;
}
jboolean jni_isEnable = (*env)->CallBooleanMethod(env, jni_obj_BTAdapter, jni_mid_isEnable);
+ CACheckJNIException(env);
OIC_LOG_V(DEBUG, TAG, "adapter state is %d", jni_isEnable);
(*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
if (!jni_address)
{
OIC_LOG(ERROR, TAG, "jni_address is null");
+ CACheckJNIException(env);
return NULL;
}
if (!jni_cid)
{
OIC_LOG(ERROR, TAG, "jni_cid is null");
+ CACheckJNIException(env);
return -1;
}
if (!jni_fieldID)
{
OIC_LOG(ERROR, TAG, "jni_fieldID is null");
+ CACheckJNIException(env);
return -1;
}
- return (*env)->GetStaticIntField(env, jni_cid, jni_fieldID);
+ jint jni_id = (*env)->GetStaticIntField(env, jni_cid, jni_fieldID);
+ CACheckJNIException(env);
+ return jni_id;
}
jobject CALEGetRemoteDevice(JNIEnv *env, jstring address)
if (!jni_cid_BTAdapter)
{
OIC_LOG(ERROR, TAG, "jni_cid_BTAdapter is null");
- return NULL;
+ goto error_exit;
}
// get remote bt adapter method
if (!jni_mid_getDefaultAdapter)
{
OIC_LOG(ERROR, TAG, "jni_mid_getDefaultAdapter is null");
- return NULL;
+ goto error_exit;
}
// gat bt adapter object
if (!jni_obj_BTAdapter)
{
OIC_LOG(ERROR, TAG, "jni_obj_BTAdapter is null");
- return NULL;
+ goto error_exit;
}
jmethodID jni_mid_getRemoteDevice = (*env)->GetMethodID(env, jni_cid_BTAdapter,
if (!jni_mid_getRemoteDevice)
{
OIC_LOG(ERROR, TAG, "jni_mid_getRemoteDevice is null");
- return NULL;
+ goto error_exit;
}
jobject jni_obj_device = (*env)->CallObjectMethod(env, jni_obj_BTAdapter,
if (!jni_obj_device)
{
OIC_LOG(ERROR, TAG, "jni_obj_device is null");
- return NULL;
+ goto error_exit;
}
OIC_LOG(DEBUG, TAG, "OUT - CALEGetRemoteDevice");
return jni_obj_device;
+
+error_exit:
+ CACheckJNIException(env);
+ return NULL;
}
jstring CALEGetAddressFromGatt(JNIEnv *env, jobject gatt)
if (!jni_obj_device)
{
OIC_LOG(ERROR, TAG, "jni_obj_device is null");
+ CACheckJNIException(env);
return NULL;
}