isAttached = true;
}
+ jmethodID mid_getApplicationContext = CAGetJNIMethodID(env, "android/content/Context",
+ "getApplicationContext",
+ "()Landroid/content/Context;");
+
+ if (!mid_getApplicationContext)
+ {
+ OIC_LOG(ERROR, TAG, "Could not get getApplicationContext method");
+ return CA_STATUS_FAILED;
+ }
+
+ jobject jApplicationContext = (*env)->CallObjectMethod(env, g_context,
+ mid_getApplicationContext);
+ if (!jApplicationContext)
+ {
+ OIC_LOG(ERROR, TAG, "Could not get application context");
+ return CA_STATUS_FAILED;
+ }
+
jclass jni_LEInterface = (*env)->FindClass(env, "org/iotivity/ca/CaLeClientInterface");
if (!jni_LEInterface)
{
goto error_exit;
}
- (*env)->NewObject(env, jni_LEInterface, LeInterfaceConstructorMethod, g_context);
+ (*env)->NewObject(env, jni_LEInterface, LeInterfaceConstructorMethod, jApplicationContext);
OIC_LOG(DEBUG, TAG, "Create instance for CaLeClientInterface");
if (isAttached)
VERIFY_NON_NULL_RET(gatt, TAG, "gatt is null", NULL);
VERIFY_NON_NULL_RET(env, TAG, "env is null", NULL);
- jmethodID jni_mid_getDevice = CALEGetJNIMethodID(env, CLASSPATH_BT_GATT, "getDevice",
- "()Landroid/bluetooth/BluetoothDevice;");
+ jmethodID jni_mid_getDevice = CAGetJNIMethodID(env, CLASSPATH_BT_GATT, "getDevice",
+ "()Landroid/bluetooth/BluetoothDevice;");
if (!jni_mid_getDevice)
{
OIC_LOG(ERROR, TAG, "jni_mid_getDevice is null");
// get BluetoothGatt method
OIC_LOG(DEBUG, TAG, "get BluetoothGatt method");
- jmethodID jni_mid_closeGatt = CALEGetJNIMethodID(env, CLASSPATH_BT_GATT, "close", "()V");
+ jmethodID jni_mid_closeGatt = CAGetJNIMethodID(env, CLASSPATH_BT_GATT, "close", "()V");
if (!jni_mid_closeGatt)
{
OIC_LOG(ERROR, TAG, "jni_mid_closeGatt is null");
// 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;");
+ jmethodID jni_mid_connectGatt = CAGetJNIMethodID(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");
// get BluetoothGatt method
OIC_LOG(DEBUG, TAG, "get gatt disconnect method");
- jmethodID jni_mid_disconnectGatt = CALEGetJNIMethodID(env, CLASSPATH_BT_GATT,
- "disconnect", "()V");
+ jmethodID jni_mid_disconnectGatt = CAGetJNIMethodID(env, CLASSPATH_BT_GATT,
+ "disconnect", "()V");
if (!jni_mid_disconnectGatt)
{
OIC_LOG(ERROR, TAG, "jni_mid_disconnectGatt is null");
// get BluetoothGatt.discoverServices method
OIC_LOG(DEBUG, TAG, "get BluetoothGatt.discoverServices method");
- jmethodID jni_mid_discoverServices = CALEGetJNIMethodID(env, CLASSPATH_BT_GATT,
- "discoverServices", "()Z");
+ jmethodID jni_mid_discoverServices = CAGetJNIMethodID(env, CLASSPATH_BT_GATT,
+ "discoverServices", "()Z");
if (!jni_mid_discoverServices)
{
OIC_LOG(ERROR, TAG, "jni_mid_discoverServices is null");
// get BluetoothGatt.write characteristic method
OIC_LOG(DEBUG, TAG, "write characteristic method");
- jmethodID jni_mid_writeCharacteristic = CALEGetJNIMethodID(env, CLASSPATH_BT_GATT,
- "writeCharacteristic",
- "(Landroid/bluetooth/"
- "BluetoothGattCharacteristic;)Z");
+ jmethodID jni_mid_writeCharacteristic = CAGetJNIMethodID(env, CLASSPATH_BT_GATT,
+ "writeCharacteristic",
+ "(Landroid/bluetooth/"
+ "BluetoothGattCharacteristic;)Z");
if (!jni_mid_writeCharacteristic)
{
OIC_LOG(ERROR, TAG, "jni_mid_writeCharacteristic is null");
}
OIC_LOG(DEBUG, TAG, "read characteristic method");
- jmethodID jni_mid_readCharacteristic = CALEGetJNIMethodID(env, CLASSPATH_BT_GATT,
- "readCharacteristic",
- "(Landroid/bluetooth/"
- "BluetoothGattCharacteristic;)Z");
+ jmethodID jni_mid_readCharacteristic = CAGetJNIMethodID(env, CLASSPATH_BT_GATT,
+ "readCharacteristic",
+ "(Landroid/bluetooth/"
+ "BluetoothGattCharacteristic;)Z");
if (!jni_mid_readCharacteristic)
{
OIC_LOG(ERROR, TAG, "jni_mid_readCharacteristic is null");
// get BluetoothGatt.setCharacteristicNotification method
OIC_LOG(DEBUG, TAG, "CALEClientSetCharacteristicNotification");
- jmethodID jni_mid_setNotification = CALEGetJNIMethodID(env, CLASSPATH_BT_GATT,
- "setCharacteristicNotification",
- "(Landroid/bluetooth/"
- "BluetoothGattCharacteristic;Z)Z");
+ jmethodID jni_mid_setNotification = CAGetJNIMethodID(env, CLASSPATH_BT_GATT,
+ "setCharacteristicNotification",
+ "(Landroid/bluetooth/"
+ "BluetoothGattCharacteristic;Z)Z");
if (!jni_mid_setNotification)
{
OIC_LOG(ERROR, TAG, "jni_mid_getService is null");
// 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;");
+ jmethodID jni_mid_getService = CAGetJNIMethodID(env, CLASSPATH_BT_GATT,
+ "getService",
+ "(Ljava/util/UUID;)Landroid/bluetooth/"
+ "BluetoothGattService;");
if (!jni_mid_getService)
{
OIC_LOG(ERROR, TAG, "jni_mid_getService is null");
}
// get bluetooth gatt service method
- 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_getValue = CALEGetJNIMethodID(env, "android/bluetooth/"
- "BluetoothGattCharacteristic",
- "getValue", "()[B");
+ jmethodID jni_mid_getValue = CAGetJNIMethodID(env, "android/bluetooth/"
+ "BluetoothGattCharacteristic",
+ "getValue", "()[B");
if (!jni_mid_getValue)
{
OIC_LOG(ERROR, TAG, "jni_mid_getValue is null");
}
OIC_LOG(DEBUG, TAG, "CALEClientSetUUIDToDescriptor");
- jmethodID jni_mid_getDescriptor = CALEGetJNIMethodID(env, "android/bluetooth/"
- "BluetoothGattCharacteristic",
- "getDescriptor",
- "(Ljava/util/UUID;)Landroid/bluetooth/"
- "BluetoothGattDescriptor;");
+ jmethodID jni_mid_getDescriptor = CAGetJNIMethodID(env, "android/bluetooth/"
+ "BluetoothGattCharacteristic",
+ "getDescriptor",
+ "(Ljava/util/UUID;)Landroid/bluetooth/"
+ "BluetoothGattDescriptor;");
if (!jni_mid_getDescriptor)
{
OIC_LOG(ERROR, TAG, "jni_mid_getDescriptor is null");
return CA_STATUS_FAILED;
}
- jmethodID jni_mid_writeDescriptor = CALEGetJNIMethodID(env, "android/bluetooth/BluetoothGatt",
- "writeDescriptor",
- "(Landroid/bluetooth/"
- "BluetoothGattDescriptor;)Z");
+ jmethodID jni_mid_writeDescriptor = CAGetJNIMethodID(env, "android/bluetooth/BluetoothGatt",
+ "writeDescriptor",
+ "(Landroid/bluetooth/"
+ "BluetoothGattDescriptor;)Z");
if (!jni_mid_writeDescriptor)
{
OIC_LOG(ERROR, TAG, "jni_mid_writeDescriptor is null");
}
// get method ID of getDevice()
- 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");
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");