if (!jni_midID)
{
OIC_LOG_V(ERROR, CA_ADAPTER_UTILS_TAG, "jni_midID [%s] is null", methodName);
+ (*env)->DeleteLocalRef(env, jni_cid);
return NULL;
}
+ (*env)->DeleteLocalRef(env, jni_cid);
return jni_midID;
}
static const char METHODID_OBJECTNONPARAM[] = "()Landroid/bluetooth/BluetoothAdapter;";
static const char CLASSPATH_BT_ADPATER[] = "android/bluetooth/BluetoothAdapter";
static const char CLASSPATH_BT_UUID[] = "java/util/UUID";
+static const char CLASSPATH_BT_SERVER_SOCKET[] = "android/bluetooth/BluetoothServerSocket";
+static const char CLASSPATH_BT_SOCKET[] = "android/bluetooth/BluetoothSocket";
static ca_thread_pool_t g_threadPoolHandle = NULL;
}
// start to read through InputStream
- jclass jni_cid_BTsocket = (*env)->FindClass(env, "android/bluetooth/BluetoothSocket");
- if (!jni_cid_BTsocket)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_BTsocket is null");
- return CA_STATUS_FAILED;
- }
- jmethodID jni_mid_getInputStream = (*env)->GetMethodID(env, jni_cid_BTsocket,
- "getInputStream",
- "()Ljava/io/InputStream;");
+ jmethodID jni_mid_getInputStream = CAGetJNIMethodID(env,
+ CLASSPATH_BT_SOCKET,
+ "getInputStream",
+ "()Ljava/io/InputStream;");
jobject jni_obj_inputStream = (*env)->CallObjectMethod(env, jni_obj_socket,
jni_mid_getInputStream);
if (!jni_obj_inputStream)
{
OIC_LOG(ERROR, TAG, "jni_obj_inputStream is null");
- (*env)->DeleteLocalRef(env, jni_cid_BTsocket);
return CA_STATUS_FAILED;
}
{
OIC_LOG(ERROR, TAG, "jni_cid_InputStream is null");
(*env)->DeleteLocalRef(env, jni_obj_inputStream);
- (*env)->DeleteLocalRef(env, jni_cid_BTsocket);
return CA_STATUS_FAILED;
}
}
(*env)->DeleteLocalRef(env, jni_cid_InputStream);
(*env)->DeleteLocalRef(env, jni_obj_inputStream);
- (*env)->DeleteLocalRef(env, jni_cid_BTsocket);
return CA_STATUS_OK;
exit:
(*env)->DeleteLocalRef(env, jni_cid_InputStream);
(*env)->DeleteLocalRef(env, jni_obj_inputStream);
- (*env)->DeleteLocalRef(env, jni_cid_BTsocket);
return CA_STATUS_FAILED;
}
if (NULL != serverSocketObject)
{
- jclass jni_cid_BTServerSocket = (*env)->FindClass(
- env, "android/bluetooth/BluetoothServerSocket");
- if (!jni_cid_BTServerSocket)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_BTServerSocket is null");
- return;
- }
-
- jmethodID jni_mid_accept = (*env)->GetMethodID(env, jni_cid_BTServerSocket, "accept",
- "()Landroid/bluetooth/BluetoothSocket;");
+ jmethodID jni_mid_accept = CAGetJNIMethodID(env, CLASSPATH_BT_SERVER_SOCKET,
+ "accept",
+ "()Landroid/bluetooth/BluetoothSocket;");
if (!jni_mid_accept)
{
OIC_LOG(ERROR, TAG, "jni_mid_accept is null");
{
OIC_LOG(DEBUG, TAG, "Accept Resource will be close");
- jclass jni_cid_BTServerSocket = (*env)->FindClass(
- env, "android/bluetooth/BluetoothServerSocket");
- if (!jni_cid_BTServerSocket)
+ jmethodID jni_mid_close = CAGetJNIMethodID(env, CLASSPATH_BT_SERVER_SOCKET,
+ "close", "()V");
+ if (!jni_mid_close)
{
- OIC_LOG(ERROR, TAG, "jni_cid_BTServerSocket is null");
+ OIC_LOG(ERROR, TAG, "jni_mid_close is null");
return;
}
- jmethodID jni_mid_accept = (*env)->GetMethodID(env, jni_cid_BTServerSocket,
- "close", "()V");
- if (!jni_mid_accept)
- {
- OIC_LOG(ERROR, TAG, "jni_mid_accept is null");
- return;
- }
- (*env)->CallVoidMethod(env, g_serverSocket, jni_mid_accept);
+ (*env)->CallVoidMethod(env, g_serverSocket, jni_mid_close);
(*env)->DeleteGlobalRef(env, g_serverSocket);
g_serverSocket = NULL;
#include "oic_string.h"
#include "cathreadpool.h"
#include "uarraylist.h"
+#include "caadapterutils.h"
#define ERROR_CODE (-1)
#define TAG PCF("OIC_CA_EDR_UTILS")
return NULL;
}
- jclass jni_cid_BTSocket = (*env)->FindClass(env, CLASSPATH_BT_SOCKET);
- if (!jni_cid_BTSocket)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_BTSocket is null");
- return NULL;
- }
-
- jmethodID jni_mid_getRemoteDevice = (*env)->GetMethodID(
- env, jni_cid_BTSocket, "getRemoteDevice", "()Landroid/bluetooth/BluetoothDevice;");
+ jmethodID jni_mid_getRemoteDevice = CAGetJNIMethodID(
+ env, CLASSPATH_BT_SOCKET, "getRemoteDevice", "()Landroid/bluetooth/BluetoothDevice;");
if (!jni_mid_getRemoteDevice)
{
OIC_LOG(ERROR, TAG, "jni_mid_getRemoteDevice is null");
- (*env)->DeleteLocalRef(env, jni_cid_BTSocket);
return NULL;
}
if (!jni_obj_remoteBTDevice)
{
OIC_LOG(ERROR, TAG, "jni_obj_remoteBTDevice is null");
- (*env)->DeleteLocalRef(env, jni_cid_BTSocket);
return NULL;
}
- jclass jni_cid_BTDevice = (*env)->FindClass(env, CLASSPATH_BT_DEVICE);
- if (!jni_cid_BTDevice)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_BTDevice is null");
- (*env)->DeleteLocalRef(env, jni_obj_remoteBTDevice);
- (*env)->DeleteLocalRef(env, jni_cid_BTSocket);
- return NULL;
- }
- jmethodID j_mid_getAddress = (*env)->GetMethodID(env, jni_cid_BTDevice, "getAddress",
- METHODID_STRINGNONPARAM);
+ jmethodID j_mid_getAddress = CAGetJNIMethodID(env, CLASSPATH_BT_DEVICE,
+ "getAddress",
+ METHODID_STRINGNONPARAM);
if (!j_mid_getAddress)
{
OIC_LOG(ERROR, TAG, "j_mid_getAddress is null");
(*env)->DeleteLocalRef(env, jni_obj_remoteBTDevice);
- (*env)->DeleteLocalRef(env, jni_cid_BTDevice);
- (*env)->DeleteLocalRef(env, jni_cid_BTSocket);
return NULL;
}
{
OIC_LOG(ERROR, TAG, "j_str_address is null");
(*env)->DeleteLocalRef(env, jni_obj_remoteBTDevice);
- (*env)->DeleteLocalRef(env, jni_cid_BTDevice);
- (*env)->DeleteLocalRef(env, jni_cid_BTSocket);
return NULL;
}
(*env)->DeleteLocalRef(env, jni_obj_remoteBTDevice);
- (*env)->DeleteLocalRef(env, jni_cid_BTDevice);
- (*env)->DeleteLocalRef(env, jni_cid_BTSocket);
return j_str_address;
}
// Convert the set to an object array
// object[] array = Set<BluetoothDevice>.toArray();
- jclass jni_cid_Set = (*env)->FindClass(env, "java/util/Set");
- if (!jni_cid_Set)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_Set is null");
- goto exit;
- }
- jmethodID jni_mid_toArray = (*env)->GetMethodID(env, jni_cid_Set, "toArray",
- "()[Ljava/lang/Object;");
-
+ jmethodID jni_mid_toArray = CAGetJNIMethodID(env, "java/util/Set",
+ "toArray", "()[Ljava/lang/Object;");
if (!jni_mid_toArray)
{
OIC_LOG(ERROR, TAG, "jni_mid_toArray is null");
OIC_LOG(ERROR, TAG, "bluetoothDevice is null");
return NULL;
}
- jclass jni_cid_device_list = (*env)->FindClass(env, "android/bluetooth/BluetoothDevice");
- if (!jni_cid_device_list)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_device_list is null");
- return NULL;
- }
- jmethodID jni_mid_getAddress = (*env)->GetMethodID(env, jni_cid_device_list, "getAddress",
- METHODID_STRINGNONPARAM);
+ jmethodID jni_mid_getAddress = CAGetJNIMethodID(env,
+ CLASSPATH_BT_DEVICE,
+ "getAddress",
+ METHODID_STRINGNONPARAM);
if (!jni_mid_getAddress)
{
OIC_LOG(ERROR, TAG, "jni_mid_getAddress is null");
return;
}
- jclass jni_cid_BTSocket = (*env)->FindClass(env, CLASSPATH_BT_SOCKET);
- if (!jni_cid_BTSocket)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_BTSocket is null");
- return;
- }
-
- jmethodID jni_mid_close = (*env)->GetMethodID(env, jni_cid_BTSocket, "close", "()V");
+ jmethodID jni_mid_close = CAGetJNIMethodID(env, CLASSPATH_BT_SOCKET,
+ "close", "()V");
if (!jni_mid_close)
{
OIC_LOG(ERROR, TAG, "jni_mid_close is null");
VERIFY_NON_NULL_RET(env, TAG, "env", -1);
VERIFY_NON_NULL_RET(device, TAG, "device", -1);
- jmethodID jni_mid_getConnectionState = CALEGetJNIMethodID(env, "android/bluetooth/BluetoothManager",
- "getConnectionState",
- "(Landroid/bluetooth/BluetoothDevice"
- ";I)I");
+ jmethodID jni_mid_getConnectionState = CAGetJNIMethodID(env, "android/bluetooth"
+ "/BluetoothManager",
+ "getConnectionState",
+ "(Landroid/bluetooth/BluetoothDevice"
+ ";I)I");
if (!jni_mid_getConnectionState)
{
OIC_LOG(ERROR, TAG, "jni_mid_getConnectionState is null");
}
OIC_LOG(DEBUG, TAG, "CALEServerSetResponseData");
- jmethodID jni_mid_getService = CALEGetJNIMethodID(env, CLASSPATH_BT_GATTSERVER,
- "getService",
- "(Ljava/util/UUID;)Landroid/bluetooth/"
- "BluetoothGattService;");
+ jmethodID jni_mid_getService = CAGetJNIMethodID(env, CLASSPATH_BT_GATTSERVER,
+ "getService",
+ "(Ljava/util/UUID;)Landroid/bluetooth/"
+ "BluetoothGattService;");
if (!jni_mid_getService)
{
OIC_LOG(ERROR, TAG, "jni_mid_getService is null");
return NULL;
}
- jmethodID jni_mid_getCharacteristic = CALEGetJNIMethodID(env, "android/bluetooth/"
- "BluetoothGattService",
- "getCharacteristic",
- "(Ljava/util/UUID;)"
- "Landroid/bluetooth/"
- "BluetoothGattCharacteristic;");
+ jmethodID jni_mid_getCharacteristic = CAGetJNIMethodID(env, "android/bluetooth/"
+ "BluetoothGattService",
+ "getCharacteristic",
+ "(Ljava/util/UUID;)"
+ "Landroid/bluetooth/"
+ "BluetoothGattCharacteristic;");
if (!jni_mid_getCharacteristic)
{
OIC_LOG(ERROR, TAG, "jni_mid_getCharacteristic is null");
return NULL;
}
- jmethodID jni_mid_setValue = CALEGetJNIMethodID(env, "android/bluetooth/"
- "BluetoothGattCharacteristic",
- "setValue", "([B)Z");
+ jmethodID jni_mid_setValue = CAGetJNIMethodID(env, "android/bluetooth/"
+ "BluetoothGattCharacteristic",
+ "setValue", "([B)Z");
if (!jni_mid_setValue)
{
OIC_LOG(ERROR, TAG, "jni_mid_setValue is null");
return CA_STATUS_FAILED;
}
- jmethodID jni_mid_notifyCharacteristicChanged = CALEGetJNIMethodID(env,
+ jmethodID jni_mid_notifyCharacteristicChanged = CAGetJNIMethodID(env,
CLASSPATH_BT_GATTSERVER,
"notifyCharacteristicChanged",
"(Landroid/bluetooth/BluetoothDevice;"
return CA_ADAPTER_NOT_ENABLED;
}
- jmethodID jni_mid_sendResponse = CALEGetJNIMethodID(env, CLASSPATH_BT_GATTSERVER,
- "sendResponse",
- "(Landroid/bluetooth/BluetoothDevice;"
- "III[B)Z");
+ jmethodID jni_mid_sendResponse = CAGetJNIMethodID(env, CLASSPATH_BT_GATTSERVER,
+ "sendResponse",
+ "(Landroid/bluetooth/BluetoothDevice;"
+ "III[B)Z");
if (!jni_mid_sendResponse)
{
OIC_LOG(ERROR, TAG, "jni_mid_sendResponse is null");
return CA_STATUS_FAILED;
}
- jmethodID jni_mid_startAdvertising = CALEGetJNIMethodID(env, "android/bluetooth/le/"
- "BluetoothLeAdvertiser",
- "startAdvertising",
- "(Landroid/bluetooth/le/"
- "AdvertiseSettings;Landroid/bluetooth/"
- "le/AdvertiseData;Landroid/bluetooth/"
- "le/AdvertiseData;Landroid/bluetooth/"
- "le/AdvertiseCallback;)V");
+ jmethodID jni_mid_startAdvertising = CAGetJNIMethodID(env, "android/bluetooth/le/"
+ "BluetoothLeAdvertiser",
+ "startAdvertising",
+ "(Landroid/bluetooth/le/"
+ "AdvertiseSettings;Landroid/bluetooth/"
+ "le/AdvertiseData;Landroid/bluetooth/"
+ "le/AdvertiseData;Landroid/bluetooth/"
+ "le/AdvertiseCallback;)V");
if (!jni_mid_startAdvertising)
{
OIC_LOG(ERROR, TAG, "jni_mid_startAdvertising is null");
return CA_STATUS_FAILED;
}
- jmethodID jni_mid_stopAdvertising = CALEGetJNIMethodID(env, "android/bluetooth/le/"
- "BluetoothLeAdvertiser",
- "stopAdvertising",
- "(Landroid/bluetooth/le/"
- "AdvertiseCallback;)V");
+ jmethodID jni_mid_stopAdvertising = CAGetJNIMethodID(env, "android/bluetooth/le/"
+ "BluetoothLeAdvertiser",
+ "stopAdvertising",
+ "(Landroid/bluetooth/le/"
+ "AdvertiseCallback;)V");
if (!jni_mid_stopAdvertising)
{
OIC_LOG(ERROR, TAG, "jni_mid_stopAdvertising is null");
return NULL;
}
- jmethodID jni_mid_openGattServer = CALEGetJNIMethodID(env, "android/bluetooth/"
- "BluetoothManager",
- "openGattServer",
- "(Landroid/content/Context;"
- "Landroid/bluetooth/"
- "BluetoothGattServerCallback;)"
- "Landroid/bluetooth/"
- "BluetoothGattServer;");
+ jmethodID jni_mid_openGattServer = CAGetJNIMethodID(env, "android/bluetooth/"
+ "BluetoothManager",
+ "openGattServer",
+ "(Landroid/content/Context;"
+ "Landroid/bluetooth/"
+ "BluetoothGattServerCallback;)"
+ "Landroid/bluetooth/"
+ "BluetoothGattServer;");
if (!jni_mid_openGattServer)
{
OIC_LOG(ERROR, TAG, "jni_mid_openGattServer is null");
return CA_ADAPTER_NOT_ENABLED;
}
- jmethodID jni_mid_addService = CALEGetJNIMethodID(env, CLASSPATH_BT_GATTSERVER,
- "addService",
- "(Landroid/bluetooth/BluetoothGattService;)"
- "Z");
+ jmethodID jni_mid_addService = CAGetJNIMethodID(env, CLASSPATH_BT_GATTSERVER,
+ "addService",
+ "(Landroid/bluetooth/BluetoothGattService;)"
+ "Z");
if (!jni_mid_addService)
{
OIC_LOG(ERROR, TAG, "jni_mid_addService is null");
return CA_ADAPTER_NOT_ENABLED;
}
- jmethodID jni_mid_connect = CALEGetJNIMethodID(env, CLASSPATH_BT_GATTSERVER,
- "connect",
- "(Landroid/bluetooth/BluetoothDevice;Z)Z");
+ jmethodID jni_mid_connect = CAGetJNIMethodID(env, CLASSPATH_BT_GATTSERVER,
+ "connect",
+ "(Landroid/bluetooth/BluetoothDevice;Z)Z");
if (!jni_mid_connect)
{
OIC_LOG(ERROR, TAG, "jni_mid_connect is null");
return CA_ADAPTER_NOT_ENABLED;
}
- jmethodID jni_mid_cancelConnection = CALEGetJNIMethodID(env, CLASSPATH_BT_GATTSERVER,
- "cancelConnection",
- "(Landroid/bluetooth/BluetoothDevice;)"
- "V");
+ jmethodID jni_mid_cancelConnection = CAGetJNIMethodID(env, CLASSPATH_BT_GATTSERVER,
+ "cancelConnection",
+ "(Landroid/bluetooth/BluetoothDevice;)"
+ "V");
if (!jni_mid_cancelConnection)
{
OIC_LOG(ERROR, TAG, "jni_mid_cancelConnection is null");
// get BluetoothGatt class
OIC_LOG(DEBUG, TAG, "get BluetoothGatt class");
- jmethodID jni_mid_closeGatt = CALEGetJNIMethodID(env, CLASSPATH_BT_GATTSERVER,
- "close", "()V");
+ jmethodID jni_mid_closeGatt = CAGetJNIMethodID(env, CLASSPATH_BT_GATTSERVER,
+ "close", "()V");
if (!jni_mid_closeGatt)
{
OIC_LOG(ERROR, TAG, "jni_mid_closeGatt is null");
#define TAG PCF("OIC_CA_LE_UTILS")
-jmethodID CALEGetJNIMethodID(JNIEnv *env, const char* className,
- const char* methodName,
- const char* methodFormat)
-{
- VERIFY_NON_NULL_RET(env, TAG, "env", NULL);
- VERIFY_NON_NULL_RET(className, TAG, "className", NULL);
- VERIFY_NON_NULL_RET(methodName, TAG, "methodName", NULL);
- VERIFY_NON_NULL_RET(methodFormat, TAG, "methodFormat", NULL);
-
- jclass jni_cid = (*env)->FindClass(env, className);
- if (!jni_cid)
- {
- OIC_LOG_V(ERROR, TAG, "jni_cid [%s] is null", className);
- return NULL;
- }
-
- jmethodID jni_midID = (*env)->GetMethodID(env, jni_cid, methodName, methodFormat);
- if (!jni_midID)
- {
- OIC_LOG_V(ERROR, TAG, "jni_midID [%s] is null", methodName);
- return NULL;
- }
-
- return jni_midID;
-}
-
jobject CALEGetUuidFromString(JNIEnv *env, const char* uuid)
{
VERIFY_NON_NULL_RET(uuid, TAG, "uuid is null", NULL);
VERIFY_NON_NULL_RET(env, TAG, "env is null", false);
VERIFY_NON_NULL_RET(bluetoothDevice, TAG, "bluetoothDevice is null", false);
- jmethodID jni_mid_getBondState = CALEGetJNIMethodID(env, "android/bluetooth/BluetoothDevice",
- "getBondState",
- "()I");
+ jmethodID jni_mid_getBondState = CAGetJNIMethodID(env, "android/bluetooth/BluetoothDevice",
+ "getBondState",
+ "()I");
if (!jni_mid_getBondState)
{
OIC_LOG(ERROR, TAG, "jni_mid_getBondState is null");
return NULL;
}
- jmethodID jni_mid_toArray = CALEGetJNIMethodID(env, "java/util/Set", "toArray",
- "()[Ljava/lang/Object;");
+ jmethodID jni_mid_toArray = CAGetJNIMethodID(env, "java/util/Set", "toArray",
+ "()[Ljava/lang/Object;");
if (!jni_mid_toArray)
{
OIC_LOG(ERROR, TAG, "getBondedDevices: jni_mid_toArray is null");
VERIFY_NON_NULL_RET(env, TAG, "env is null", NULL);
VERIFY_NON_NULL_RET(bluetoothDevice, TAG, "bluetoothDevice is null", NULL);
- jmethodID jni_mid_getAddress = CALEGetJNIMethodID(env, "android/bluetooth/BluetoothDevice",
- "getAddress",
- "()Ljava/lang/String;");
+ jmethodID jni_mid_getAddress = CAGetJNIMethodID(env, "android/bluetooth/BluetoothDevice",
+ "getAddress",
+ "()Ljava/lang/String;");
if (!jni_mid_getAddress)
{
OIC_LOG(ERROR, TAG, "jni_mid_getAddress is null");
VERIFY_NON_NULL_RET(env, TAG, "env is null", NULL);
VERIFY_NON_NULL_RET(gatt, TAG, "gatt is null", NULL);
- jmethodID jni_mid_getDevice = CALEGetJNIMethodID(env, CLASSPATH_BT_GATT, "getDevice",
- METHODID_BT_DEVICE);
+ jmethodID jni_mid_getDevice = CAGetJNIMethodID(env, CLASSPATH_BT_GATT, "getDevice",
+ METHODID_BT_DEVICE);
if (!jni_mid_getDevice)
{
OIC_LOG(ERROR, TAG, "jni_mid_getDevice is null");
static const uint16_t STATE_DISCONNECTED = 1;
/**
- * get method ID for method Name and class
- * @param[in] env JNI interface pointer.
- * @param[in] className android class.
- * @param[in] methodName android method name.
- * @param[in] methodFormat method type of methodName.
- * @return jmethodID of the method.
- */
-jmethodID CALEGetJNIMethodID(JNIEnv *env, const char* className,
- const char* methodName,
- const char* methodFormat);
-
-/**
* get uuid(jni object) from uuid(character).
* @param[in] env JNI interface pointer.
* @param[in] uuid uuid(character).
return CA_STATUS_FAILED;\r
}\r
\r
- jclass jni_NfcInterface = (*env)->FindClass(env, "org/iotivity/ca/CaNfcInterface");\r
+ jclass jni_NfcInterface = (*env)->FindClass(env, CLASS_NFCINTERFACE);\r
if (!jni_NfcInterface)\r
{\r
OIC_LOG(ERROR, TAG, "Could not get CaNfcInterface class");\r
isAttached = true;\r
}\r
\r
- jclass jni_NfcInterface = (*env)->FindClass(env, "org/iotivity/ca/CaNfcInterface");\r
+ jclass jni_NfcInterface = (*env)->FindClass(env, CLASS_NFCINTERFACE);\r
if (!jni_NfcInterface)\r
{\r
OIC_LOG(ERROR, TAG, "Could not get CaNFCClientInterface class");\r
return NULL;\r
}\r
\r
- jclass cid_string = (*env)->FindClass(env, "java/lang/String");\r
- if (!cid_string)\r
- {\r
- OIC_LOG(ERROR, TAG, "Could not get NfcAdapter class for cid_string");\r
- return NULL;\r
- }\r
-\r
- jmethodID mid_getBytes = (*env)->GetMethodID(env, cid_string, "getBytes",\r
- "(Ljava/lang/String;)[B");\r
+ jmethodID mid_getBytes = CAGetJNIMethodID(env, "java/lang/String", "getBytes",\r
+ "(Ljava/lang/String;)[B");\r
if (!mid_getBytes)\r
{\r
OIC_LOG(ERROR, TAG, "Could not get methodId for mid_getBytes");\r