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;
+}
+
+jobject CALEGetParcelUuidFromString(JNIEnv *env, const char* uuid)
+{
+ VERIFY_NON_NULL_RET(env, TAG, "env is null", NULL);
+ VERIFY_NON_NULL_RET(uuid, TAG, "uuid is null", NULL);
+
+ jclass jni_cid_ParcelUuid = (*env)->FindClass(env, "android/os/ParcelUuid");
+ if (!jni_cid_ParcelUuid)
+ {
+ OIC_LOG(ERROR, TAG, "jni_cid_ParcelUuid is not available");
+ goto error_exit;
+ }
+
+ jmethodID jni_mid_fromString = (*env)->GetStaticMethodID(env, jni_cid_ParcelUuid,
+ "fromString",
+ "(Ljava/lang/String;)"
+ "Landroid/os/ParcelUuid;");
+ if (!jni_mid_fromString)
+ {
+ OIC_LOG(ERROR, TAG, "jni_mid_fromString is not available");
+ goto error_exit;
+ }
+
+ jstring str_uuid = (*env)->NewStringUTF(env, uuid);
+ if (!str_uuid)
+ {
+ OIC_LOG(ERROR, TAG, "str_uuid is not available");
+ goto error_exit;
+ }
+
+ jobject jni_obj_parcelUuid = (*env)->CallStaticObjectMethod(env, jni_cid_ParcelUuid,
+ jni_mid_fromString,
+ str_uuid);
+ if (!jni_obj_parcelUuid)
+ {
+ OIC_LOG(ERROR, TAG, "Fail to get jni uuid object");
+ goto error_exit;
+ }
+
+ return jni_obj_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);
+ (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
return jni_isEnable;
}
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)
{
- OIC_LOG(DEBUG, TAG, "IN - CALEGetRemoteDevice");
+ OIC_LOG(DEBUG, TAG, "CALEGetRemoteDevice");
VERIFY_NON_NULL_RET(env, TAG, "env is null", NULL);
VERIFY_NON_NULL_RET(address, TAG, "address is null", NULL);
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)
{
- OIC_LOG(DEBUG, TAG, "IN - CALEGetAddressFromGatt");
+ OIC_LOG(DEBUG, TAG, "CALEGetAddressFromGatt");
VERIFY_NON_NULL_RET(env, TAG, "env is null", NULL);
VERIFY_NON_NULL_RET(gatt, TAG, "gatt is null", NULL);
if (!jni_obj_device)
{
OIC_LOG(ERROR, TAG, "jni_obj_device is null");
+ CACheckJNIException(env);
return NULL;
}
return NULL;
}
- OIC_LOG(DEBUG, TAG, "OUT - CALEGetAddressFromGatt");
return jni_address;
}