VERIFY_NON_NULL_RET(gatt, TAG, "gatt is null", NULL);
VERIFY_NON_NULL_RET(env, TAG, "env is null", NULL);
- jclass jni_cid_gattdevice_list = (*env)->FindClass(env, CLASSPATH_BT_GATT);
- if (!jni_cid_gattdevice_list)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_gattdevice_list is null");
- return NULL;
- }
-
- jmethodID jni_mid_getDevice = (*env)->GetMethodID(env, jni_cid_gattdevice_list, "getDevice",
- "()Landroid/bluetooth/BluetoothDevice;");
+ jmethodID jni_mid_getDevice = CALEGetJNIMethodID(env, CLASSPATH_BT_GATT, "getDevice",
+ "()Landroid/bluetooth/BluetoothDevice;");
if (!jni_mid_getDevice)
{
OIC_LOG(ERROR, TAG, "jni_mid_getDevice is null");
VERIFY_NON_NULL(bluetoothGatt, TAG, "bluetoothGatt is null");
VERIFY_NON_NULL(env, TAG, "env is null");
- // get BluetoothGatt class
- OIC_LOG(DEBUG, TAG, "get BluetoothGatt class");
- jclass jni_cid_BluetoothGatt = (*env)->FindClass(env, CLASSPATH_BT_GATT);
- if (!jni_cid_BluetoothGatt)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_BluetoothGatt is null");
- return CA_STATUS_FAILED;
- }
-
- jmethodID jni_mid_closeGatt = (*env)->GetMethodID(env, jni_cid_BluetoothGatt, "close", "()V");
+ // get BluetoothGatt method
+ OIC_LOG(DEBUG, TAG, "get BluetoothGatt method");
+ jmethodID jni_mid_closeGatt = CALEGetJNIMethodID(env, CLASSPATH_BT_GATT, "close", "()V");
if (!jni_mid_closeGatt)
{
OIC_LOG(ERROR, TAG, "jni_mid_closeGatt is null");
return NULL;
}
- // get BluetoothDevice class
- OIC_LOG(DEBUG, TAG, "get BluetoothDevice class");
- jclass jni_cid_BluetoothDevice = (*env)->FindClass(env, "android/bluetooth/BluetoothDevice");
- if (!jni_cid_BluetoothDevice)
- {
- OIC_LOG(ERROR, TAG, "bleConnect: jni_cid_BluetoothDevice is null");
- return NULL;
- }
-
- // get connectGatt method
- OIC_LOG(DEBUG, TAG, "get connectGatt method");
- jmethodID jni_mid_connectGatt = (*env)->GetMethodID(env, jni_cid_BluetoothDevice, "connectGatt",
- "(Landroid/content/Context;ZLandroid/"
- "bluetooth/BluetoothGattCallback;)"
- "Landroid/bluetooth/BluetoothGatt;");
+ // get BluetoothDevice method
+ OIC_LOG(DEBUG, TAG, "get BluetoothDevice method");
+ jmethodID jni_mid_connectGatt = CALEGetJNIMethodID(env, "android/bluetooth/BluetoothDevice",
+ "connectGatt",
+ "(Landroid/content/Context;ZLandroid/"
+ "bluetooth/BluetoothGattCallback;)"
+ "Landroid/bluetooth/BluetoothGatt;");
if (!jni_mid_connectGatt)
{
OIC_LOG(ERROR, TAG, "bleConnect: jni_mid_connectGatt is null");
VERIFY_NON_NULL(env, TAG, "env is null");
VERIFY_NON_NULL(bluetoothGatt, TAG, "bluetoothGatt is null");
- // get BluetoothGatt class
- jclass jni_cid_BluetoothGatt = (*env)->FindClass(env, CLASSPATH_BT_GATT);
- if (!jni_cid_BluetoothGatt)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_BluetoothGatt is null");
- return CA_STATUS_FAILED;
- }
-
+ // get BluetoothGatt method
OIC_LOG(DEBUG, TAG, "get gatt disconnect method");
- jmethodID jni_mid_disconnectGatt = (*env)->GetMethodID(env, jni_cid_BluetoothGatt,
+ jmethodID jni_mid_disconnectGatt = CALEGetJNIMethodID(env, CLASSPATH_BT_GATT,
"disconnect", "()V");
if (!jni_mid_disconnectGatt)
{
return CA_ADAPTER_NOT_ENABLED;
}
- // get BluetoothGatt class
- OIC_LOG(DEBUG, TAG, "get BluetoothGatt class");
- jclass jni_cid_BluetoothGatt = (*env)->FindClass(env, CLASSPATH_BT_GATT);
- if (!jni_cid_BluetoothGatt)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_BluetoothGatt is null");
- return CA_STATUS_FAILED;
- }
-
- OIC_LOG(DEBUG, TAG, "discovery gatt services method");
- jmethodID jni_mid_discoverServices = (*env)->GetMethodID(env, jni_cid_BluetoothGatt,
- "discoverServices", "()Z");
+ // get BluetoothGatt.discoverServices method
+ OIC_LOG(DEBUG, TAG, "get BluetoothGatt.discoverServices method");
+ jmethodID jni_mid_discoverServices = CALEGetJNIMethodID(env, CLASSPATH_BT_GATT,
+ "discoverServices", "()Z");
if (!jni_mid_discoverServices)
{
OIC_LOG(ERROR, TAG, "jni_mid_discoverServices is null");
return CA_STATUS_FAILED;
}
+
// call disconnect gatt method
OIC_LOG(DEBUG, TAG, "CALL API - request discovery gatt services");
jboolean ret = (*env)->CallBooleanMethod(env, bluetoothGatt, jni_mid_discoverServices);
return CA_STATUS_FAILED;
}
- // get BluetoothGatt class
- OIC_LOG(DEBUG, TAG, "get BluetoothGatt class");
- jclass jni_cid_BluetoothGatt = (*env)->FindClass(env, CLASSPATH_BT_GATT);
- if (!jni_cid_BluetoothGatt)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_BluetoothGatt is null");
- return CA_STATUS_FAILED;
- }
-
+ // get BluetoothGatt.write characteristic method
OIC_LOG(DEBUG, TAG, "write characteristic method");
- jmethodID jni_mid_writeCharacteristic = (*env)->GetMethodID(env, jni_cid_BluetoothGatt,
- "writeCharacteristic",
- "(Landroid/bluetooth/"
- "BluetoothGattCharacteristic;)Z");
+ jmethodID jni_mid_writeCharacteristic = CALEGetJNIMethodID(env, CLASSPATH_BT_GATT,
+ "writeCharacteristic",
+ "(Landroid/bluetooth/"
+ "BluetoothGattCharacteristic;)Z");
if (!jni_mid_writeCharacteristic)
{
OIC_LOG(ERROR, TAG, "jni_mid_writeCharacteristic is null");
return CA_STATUS_FAILED;
}
- jclass jni_cid_BluetoothGatt = (*env)->FindClass(env, CLASSPATH_BT_GATT);
- if (!jni_cid_BluetoothGatt)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_BluetoothGatt is null");
- return CA_STATUS_FAILED;
- }
-
jstring jni_uuid = (*env)->NewStringUTF(env, OIC_GATT_CHARACTERISTIC_RESPONSE_UUID);
if (!jni_uuid)
{
}
OIC_LOG(DEBUG, TAG, "read characteristic method");
- jmethodID jni_mid_readCharacteristic = (*env)->GetMethodID(env, jni_cid_BluetoothGatt,
- "readCharacteristic",
- "(Landroid/bluetooth/"
- "BluetoothGattCharacteristic;)Z");
+ jmethodID jni_mid_readCharacteristic = CALEGetJNIMethodID(env, CLASSPATH_BT_GATT,
+ "readCharacteristic",
+ "(Landroid/bluetooth/"
+ "BluetoothGattCharacteristic;)Z");
if (!jni_mid_readCharacteristic)
{
OIC_LOG(ERROR, TAG, "jni_mid_readCharacteristic is null");
return CA_ADAPTER_NOT_ENABLED;
}
- // get BluetoothGatt class
+ // get BluetoothGatt.setCharacteristicNotification method
OIC_LOG(DEBUG, TAG, "CALEClientSetCharacteristicNotification");
- jclass jni_cid_BluetoothGatt = (*env)->FindClass(env, CLASSPATH_BT_GATT);
- if (!jni_cid_BluetoothGatt)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_BluetoothGatt is null");
- return CA_STATUS_FAILED;
- }
-
- // set Characteristic Notification
- jmethodID jni_mid_setNotification = (*env)->GetMethodID(env, jni_cid_BluetoothGatt,
- "setCharacteristicNotification",
- "(Landroid/bluetooth/"
- "BluetoothGattCharacteristic;Z)Z");
+ jmethodID jni_mid_setNotification = CALEGetJNIMethodID(env, CLASSPATH_BT_GATT,
+ "setCharacteristicNotification",
+ "(Landroid/bluetooth/"
+ "BluetoothGattCharacteristic;Z)Z");
if (!jni_mid_setNotification)
{
OIC_LOG(ERROR, TAG, "jni_mid_getService is null");
return NULL;
}
- // get BluetoothGatt class
- OIC_LOG(DEBUG, TAG, "CALEClientGetGattService");
- jclass jni_cid_BluetoothGatt = (*env)->FindClass(env, CLASSPATH_BT_GATT);
- if (!jni_cid_BluetoothGatt)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_BluetoothGatt is null");
- return NULL;
- }
-
- jmethodID jni_mid_getService = (*env)->GetMethodID(
- env, jni_cid_BluetoothGatt, "getService",
- "(Ljava/util/UUID;)Landroid/bluetooth/BluetoothGattService;");
+ // get BluetoothGatt.getService method
+ OIC_LOG(DEBUG, TAG, "BluetoothGatt.getService");
+ jmethodID jni_mid_getService = CALEGetJNIMethodID(env, CLASSPATH_BT_GATT,
+ "getService",
+ "(Ljava/util/UUID;)Landroid/bluetooth/"
+ "BluetoothGattService;");
if (!jni_mid_getService)
{
OIC_LOG(ERROR, TAG, "jni_mid_getService is null");
return NULL;
}
- // get bluetooth gatt service class
- jclass jni_cid_BluetoothGattService = (*env)->FindClass(
- env, "android/bluetooth/BluetoothGattService");
- if (!jni_cid_BluetoothGattService)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_BluetoothGattService is null");
- return NULL;
- }
-
- OIC_LOG(DEBUG, TAG, "get gatt getCharacteristic method");
- jmethodID jni_mid_getCharacteristic = (*env)->GetMethodID(env, jni_cid_BluetoothGattService,
- "getCharacteristic",
- "(Ljava/util/UUID;)"
- "Landroid/bluetooth/"
- "BluetoothGattCharacteristic;");
+ // get bluetooth gatt service method
+ jmethodID jni_mid_getCharacteristic = CALEGetJNIMethodID(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;
}
- jclass jni_cid_BTGattCharacteristic = (*env)->FindClass(env, "android/bluetooth/"
- "BluetoothGattCharacteristic");
- if (!jni_cid_BTGattCharacteristic)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_BTGattCharacteristic is null");
- return NULL;
- }
-
- OIC_LOG(DEBUG, TAG, "get value in Characteristic");
- jmethodID jni_mid_getValue = (*env)->GetMethodID(env, jni_cid_BTGattCharacteristic, "getValue",
- "()[B");
+ jmethodID jni_mid_getValue = CALEGetJNIMethodID(env, "android/bluetooth/"
+ "BluetoothGattCharacteristic",
+ "getValue", "()[B");
if (!jni_mid_getValue)
{
OIC_LOG(ERROR, TAG, "jni_mid_getValue is null");
}
OIC_LOG(DEBUG, TAG, "CALEClientSetUUIDToDescriptor");
- jclass jni_cid_BTGattCharacteristic = (*env)->FindClass(env, "android/bluetooth/"
- "BluetoothGattCharacteristic");
- if (!jni_cid_BTGattCharacteristic)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_BTGattCharacteristic is null");
- return CA_STATUS_FAILED;
- }
-
- OIC_LOG(DEBUG, TAG, "set value in Characteristic");
- jmethodID jni_mid_getDescriptor = (*env)->GetMethodID(env, jni_cid_BTGattCharacteristic,
+ jmethodID jni_mid_getDescriptor = CALEGetJNIMethodID(env, "android/bluetooth/"
+ "BluetoothGattCharacteristic",
"getDescriptor",
"(Ljava/util/UUID;)Landroid/bluetooth/"
"BluetoothGattDescriptor;");
return CA_STATUS_FAILED;
}
- jclass jni_cid_gatt = (*env)->FindClass(env, "android/bluetooth/BluetoothGatt");
- if (!jni_cid_gatt)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_gatt is null");
- return CA_STATUS_FAILED;
- }
-
- OIC_LOG(DEBUG, TAG, "write Descriptor in gatt object");
- jmethodID jni_mid_writeDescriptor = (*env)->GetMethodID(env, jni_cid_gatt, "writeDescriptor",
+ jmethodID jni_mid_writeDescriptor = CALEGetJNIMethodID(env, "android/bluetooth/BluetoothGatt",
+ "writeDescriptor",
"(Landroid/bluetooth/"
"BluetoothGattDescriptor;)Z");
if (!jni_mid_writeDescriptor)
}
// get method ID of getDevice()
- jclass jni_cid_gattdevice_list = (*env)->FindClass(env, CLASSPATH_BT_GATT);
- if (!jni_cid_gattdevice_list)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_gattdevice_list is null");
- (*env)->ReleaseStringUTFChars(env, jni_btTargetAddress, targetAddress);
- return NULL;
- }
-
- jmethodID jni_mid_getDevice = (*env)->GetMethodID(env, jni_cid_gattdevice_list, "getDevice",
- METHODID_BT_DEVICE);
+ jmethodID jni_mid_getDevice = CALEGetJNIMethodID(env, CLASSPATH_BT_GATT,
+ "getDevice", METHODID_BT_DEVICE);
if (!jni_mid_getDevice)
{
OIC_LOG(ERROR, TAG, "jni_mid_getDevice is null");
VERIFY_NON_NULL_RET(env, TAG, "env is null", NULL);
VERIFY_NON_NULL_RET(gatt, TAG, "gatt is null", NULL);
- jclass jni_cid_gattdevice_list = (*env)->FindClass(env, CLASSPATH_BT_GATT);
- if (!jni_cid_gattdevice_list)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_gattdevice_list is null");
- return NULL;
- }
-
- jmethodID jni_mid_getDevice = (*env)->GetMethodID(env, jni_cid_gattdevice_list, "getDevice",
- METHODID_BT_DEVICE);
+ jmethodID jni_mid_getDevice = CALEGetJNIMethodID(env, CLASSPATH_BT_GATT,
+ "getDevice", METHODID_BT_DEVICE);
if (!jni_mid_getDevice)
{
OIC_LOG(ERROR, TAG, "jni_mid_getDevice is null");
static bool g_isSignalSetFlag = false;
static const char CLASSPATH_BT_ADVERTISE_CB[] = "android/bluetooth/le/AdvertiseCallback";
+static const char CLASSPATH_BT_GATTSERVER[] = "android/bluetooth/BluetoothGattServer";
void CALEServerJNISetContext()
{
VERIFY_NON_NULL_RET(env, TAG, "env", -1);
VERIFY_NON_NULL_RET(device, TAG, "device", -1);
- jclass jni_cid_bluetoothManager = (*env)->FindClass(env, "android/bluetooth/BluetoothManager");
- if (!jni_cid_bluetoothManager)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_bluetoothManager is null");
- return -1;
- }
-
- jmethodID jni_mid_getConnectionState = (*env)->GetMethodID(env, jni_cid_bluetoothManager,
- "getConnectionState",
- "(Landroid/bluetooth/BluetoothDevice"
- ";I)I");
+ jmethodID jni_mid_getConnectionState = CALEGetJNIMethodID(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");
-
- jclass jni_cid_bluetoothGattServer = (*env)->FindClass(env,
- "android/bluetooth/BluetoothGattServer");
- if (!jni_cid_bluetoothGattServer)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_bluetoothGattServer is null");
- return NULL;
- }
-
- jclass jni_cid_bluetoothGattService = (*env)->FindClass(env, "android/bluetooth/"
- "BluetoothGattService");
- if (!jni_cid_bluetoothGattService)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_bluetoothGattService is null");
- return NULL;
- }
-
- jclass jni_cid_bluetoothGattCharacteristic = (*env)->FindClass(env, "android/bluetooth/"
- "BluetoothGattCharacteristic");
- if (!jni_cid_bluetoothGattCharacteristic)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_bluetoothGattCharacteristic is null");
- return NULL;
- }
-
- jmethodID jni_mid_getService = (*env)->GetMethodID(env, jni_cid_bluetoothGattServer,
- "getService",
- "(Ljava/util/UUID;)Landroid/bluetooth/"
- "BluetoothGattService;");
+ jmethodID jni_mid_getService = CALEGetJNIMethodID(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 = (*env)->GetMethodID(env, jni_cid_bluetoothGattService,
- "getCharacteristic",
- "(Ljava/util/UUID;)"
- "Landroid/bluetooth/"
- "BluetoothGattCharacteristic;");
+ jmethodID jni_mid_getCharacteristic = CALEGetJNIMethodID(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 = (*env)->GetMethodID(env, jni_cid_bluetoothGattCharacteristic,
- "setValue", "([B)Z");
+ jmethodID jni_mid_setValue = CALEGetJNIMethodID(env, "android/bluetooth/"
+ "BluetoothGattCharacteristic",
+ "setValue", "([B)Z");
if (!jni_mid_setValue)
{
OIC_LOG(ERROR, TAG, "jni_mid_setValue is null");
return CA_STATUS_FAILED;
}
- jclass jni_cid_bluetoothGattServer = (*env)->FindClass(env,
- "android/bluetooth/BluetoothGattServer");
- if (!jni_cid_bluetoothGattServer)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_bluetoothGattServer is null");
- return CA_STATUS_FAILED;
- }
-
- jmethodID jni_mid_notifyCharacteristicChanged = (*env)->GetMethodID(
- env, jni_cid_bluetoothGattServer, "notifyCharacteristicChanged",
- "(Landroid/bluetooth/BluetoothDevice;"
- "Landroid/bluetooth/BluetoothGattCharacteristic;Z)Z");
+ jmethodID jni_mid_notifyCharacteristicChanged = CALEGetJNIMethodID(env,
+ CLASSPATH_BT_GATTSERVER,
+ "notifyCharacteristicChanged",
+ "(Landroid/bluetooth/BluetoothDevice;"
+ "Landroid/bluetooth/"
+ "BluetoothGattCharacteristic;Z)Z");
if (!jni_mid_notifyCharacteristicChanged)
{
OIC_LOG(ERROR, TAG, "jni_mid_notifyCharacteristicChanged is null");
return CA_ADAPTER_NOT_ENABLED;
}
- jclass jni_cid_bluetoothGattServer = (*env)->FindClass(env,
- "android/bluetooth/BluetoothGattServer");
- if (!jni_cid_bluetoothGattServer)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_bluetoothGattServer is null");
- return CA_STATUS_FAILED;
- }
-
- jmethodID jni_mid_sendResponse = (*env)->GetMethodID(env, jni_cid_bluetoothGattServer,
- "sendResponse",
- "(Landroid/bluetooth/BluetoothDevice;"
- "III[B)Z");
+ jmethodID jni_mid_sendResponse = CALEGetJNIMethodID(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;
}
- jclass jni_cid_leAdvertiser = (*env)->FindClass(env,
- "android/bluetooth/le/BluetoothLeAdvertiser");
- if (!jni_cid_leAdvertiser)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_leAdvertiser is null");
- return CA_STATUS_FAILED;
- }
-
- jmethodID jni_mid_startAdvertising = (*env)->GetMethodID(env, jni_cid_leAdvertiser,
- "startAdvertising",
- "(Landroid/bluetooth/le/"
- "AdvertiseSettings;Landroid/bluetooth/"
- "le/AdvertiseData;Landroid/bluetooth/"
- "le/AdvertiseData;Landroid/bluetooth/"
- "le/AdvertiseCallback;)V");
+ 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");
if (!jni_mid_startAdvertising)
{
OIC_LOG(ERROR, TAG, "jni_mid_startAdvertising is null");
return CA_STATUS_FAILED;
}
- jclass jni_cid_leAdvertiser = (*env)->FindClass(env,
- "android/bluetooth/le/BluetoothLeAdvertiser");
- if (!jni_cid_leAdvertiser)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_leAdvertiser is null");
- return CA_STATUS_FAILED;
- }
-
jmethodID jni_mid_getDefaultAdapter = (*env)->GetStaticMethodID(env, jni_cid_BTAdapter,
"getDefaultAdapter",
"()Landroid/bluetooth/"
return CA_STATUS_FAILED;
}
- jmethodID jni_mid_stopAdvertising = (*env)->GetMethodID(env, jni_cid_leAdvertiser,
- "stopAdvertising",
- "(Landroid/bluetooth/le/"
- "AdvertiseCallback;)V");
+ jmethodID jni_mid_stopAdvertising = CALEGetJNIMethodID(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;
}
- jclass jni_cid_bluetoothManager = (*env)->FindClass(env, "android/bluetooth/BluetoothManager");
- if (!jni_cid_bluetoothManager)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_bluetoothManager is null");
- return NULL;
- }
-
jfieldID jni_fid_bluetoothService = (*env)->GetStaticFieldID(env, jni_cid_context,
"BLUETOOTH_SERVICE",
"Ljava/lang/String;");
return NULL;
}
- jmethodID jni_mid_openGattServer = (*env)->GetMethodID(env, jni_cid_bluetoothManager,
- "openGattServer",
- "(Landroid/content/Context;"
- "Landroid/bluetooth/"
- "BluetoothGattServerCallback;)"
- "Landroid/bluetooth/"
- "BluetoothGattServer;");
+ jmethodID jni_mid_openGattServer = CALEGetJNIMethodID(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;
}
- jclass jni_cid_bluetoothGattServer = (*env)->FindClass(env,
- "android/bluetooth/BluetoothGattServer");
- if (!jni_cid_bluetoothGattServer)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_bluetoothGattServer is null");
- return CA_STATUS_FAILED;
- }
-
- jmethodID jni_mid_addService = (*env)->GetMethodID(env, jni_cid_bluetoothGattServer,
- "addService",
- "(Landroid/bluetooth/BluetoothGattService;)"
- "Z");
- if (!jni_mid_addService)
- {
- OIC_LOG(ERROR, TAG, "jni_mid_addService is null");
- return CA_STATUS_FAILED;
- }
+ jmethodID jni_mid_addService = CALEGetJNIMethodID(env, CLASSPATH_BT_GATTSERVER,
+ "addService",
+ "(Landroid/bluetooth/BluetoothGattService;)"
+ "Z");
+ if (!jni_mid_addService)
+ {
+ OIC_LOG(ERROR, TAG, "jni_mid_addService is null");
+ return CA_STATUS_FAILED;
+ }
jboolean jni_boolean_addService = (*env)->CallBooleanMethod(env, bluetoothGattServer,
jni_mid_addService,
return CA_ADAPTER_NOT_ENABLED;
}
- jclass jni_cid_bluetoothGattServer = (*env)->FindClass(env,
- "android/bluetooth/BluetoothGattServer");
- if (!jni_cid_bluetoothGattServer)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_bluetoothGattServer is null");
- return CA_STATUS_FAILED;
- }
-
- jmethodID jni_mid_connect = (*env)->GetMethodID(env, jni_cid_bluetoothGattServer, "connect",
- "(Landroid/bluetooth/BluetoothDevice;Z)Z");
+ jmethodID jni_mid_connect = CALEGetJNIMethodID(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;
}
- jclass jni_cid_bluetoothGattServer = (*env)->FindClass(env,
- "android/bluetooth/BluetoothGattServer");
- if (!jni_cid_bluetoothGattServer)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_bluetoothGattServer is null");
- return CA_STATUS_FAILED;
- }
-
- jmethodID jni_mid_cancelConnection = (*env)->GetMethodID(env, jni_cid_bluetoothGattServer,
- "cancelConnection",
- "(Landroid/bluetooth/BluetoothDevice;)"
- "V");
+ jmethodID jni_mid_cancelConnection = CALEGetJNIMethodID(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");
- jclass jni_cid_BluetoothGatt = (*env)->FindClass(env, "android/bluetooth/BluetoothGattServer");
- if (!jni_cid_BluetoothGatt)
- {
- OIC_LOG(ERROR, TAG, "jni_cid_BluetoothGatt is null");
- return CA_STATUS_FAILED;
- }
-
- jmethodID jni_mid_closeGatt = (*env)->GetMethodID(env, jni_cid_BluetoothGatt, "close", "()V");
+ jmethodID jni_mid_closeGatt = CALEGetJNIMethodID(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);
- 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 false;
- }
-
- jmethodID jni_mid_getBondState = (*env)->GetMethodID(env, jni_cid_device_list, "getBondState",
- "()I");
+ jmethodID jni_mid_getBondState = CALEGetJNIMethodID(env, "android/bluetooth/BluetoothDevice",
+ "getBondState",
+ "()I");
if (!jni_mid_getBondState)
{
OIC_LOG(ERROR, TAG, "jni_mid_getBondState is null");
return NULL;
}
- jclass jni_cid_Set = (*env)->FindClass(env, "java/util/Set");
- if (!jni_cid_Set)
- {
- OIC_LOG(ERROR, TAG, "getBondedDevices : jni_cid_Set is null");
- return NULL;
- }
-
- jmethodID jni_mid_toArray = (*env)->GetMethodID(env, jni_cid_Set, "toArray",
- "()[Ljava/lang/Object;");
+ jmethodID jni_mid_toArray = CALEGetJNIMethodID(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);
- 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",
- "()Ljava/lang/String;");
+ jmethodID jni_mid_getAddress = CALEGetJNIMethodID(env, "android/bluetooth/BluetoothDevice",
+ "getAddress",
+ "()Ljava/lang/String;");
if (!jni_mid_getAddress)
{
OIC_LOG(ERROR, TAG, "jni_mid_getAddress is null");
static const jint STATE_CONNECTED = 2;
static const jint STATE_DISCONNECTED = 0;
+
+/**
+ * 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.