there was no method to call unregisterReceiver.
Change-Id: I7ceb5bc73d4a25a1e93cbbf6e3e167c0d9f5c98f
Signed-off-by: jihwan.seo <jihwan.seo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4047
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jaehong Jo <jaehong.jo@samsung.com>
Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com>
import android.content.IntentFilter;
public class CaEdrInterface {
+ private static Context mContext;
private CaEdrInterface(Context context) {
-
- registerIntentFilter(context);
+ mContext = context;
+ registerIntentFilter();
}
- private static IntentFilter registerIntentFilter(Context context) {
+ private static IntentFilter registerIntentFilter() {
IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
- context.registerReceiver(mReceiver, filter);
+ mContext.registerReceiver(mReceiver, filter);
return filter;
}
+ public static void destroyEdrInterface() {
+ mContext.unregisterReceiver(mReceiver);
+ }
+
// Network Monitor
private native static void caEdrStateChangedCallback(int state);
private static String SERVICE_UUID = "ADE3D529-C784-4F63-A987-EB69F70EE816";
private static String TAG = "Sample_Service : CaLeClientInterface";
+ private static Context mContext;
private CaLeClientInterface(Context context) {
-
caLeRegisterLeScanCallback(mLeScanCallback);
caLeRegisterGattCallback(mGattCallback);
-
- registerIntentFilter(context);
+ mContext = context;
+ registerIntentFilter();
}
public static void getLeScanCallback() {
caLeRegisterGattCallback(mGattCallback);
}
- private static IntentFilter registerIntentFilter(Context context) {
+ private static IntentFilter registerIntentFilter() {
IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
- context.registerReceiver(mReceiver, filter);
+ mContext.registerReceiver(mReceiver, filter);
return filter;
}
+ public static void destroyLeInterface() {
+ mContext.unregisterReceiver(mReceiver);
+ }
+
private native static void caLeRegisterLeScanCallback(BluetoothAdapter.LeScanCallback callback);
private native static void caLeRegisterGattCallback(BluetoothGattCallback callback);
import android.content.IntentFilter;
public class CaEdrInterface {
+ private static Context mContext;
private CaEdrInterface(Context context) {
-
- registerIntentFilter(context);
+ mContext = context;
+ registerIntentFilter();
}
- private static IntentFilter registerIntentFilter(Context context) {
+ private static IntentFilter registerIntentFilter() {
IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
- context.registerReceiver(mReceiver, filter);
+ mContext.registerReceiver(mReceiver, filter);
return filter;
}
+ public static void destroyEdrInterface() {
+ mContext.unregisterReceiver(mReceiver);
+ }
+
// Network Monitor
private native static void caEdrStateChangedCallback(int state);
private static String SERVICE_UUID = "ADE3D529-C784-4F63-A987-EB69F70EE816";
private static String TAG = "Sample_Service : CaLeClientInterface";
+ private static Context mContext;
private CaLeClientInterface(Context context) {
-
caLeRegisterLeScanCallback(mLeScanCallback);
caLeRegisterGattCallback(mGattCallback);
-
- registerIntentFilter(context);
+ mContext = context;
+ registerIntentFilter();
}
public static void getLeScanCallback() {
caLeRegisterGattCallback(mGattCallback);
}
- private static IntentFilter registerIntentFilter(Context context) {
+ private static IntentFilter registerIntentFilter() {
IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
- context.registerReceiver(mReceiver, filter);
+ mContext.registerReceiver(mReceiver, filter);
return filter;
}
+ public static void destroyLeInterface() {
+ mContext.unregisterReceiver(mReceiver);
+ }
+
private native static void caLeRegisterLeScanCallback(BluetoothAdapter.LeScanCallback callback);
private native static void caLeRegisterGattCallback(BluetoothGattCallback callback);
CAEDRNativeRemoveAllDeviceState();
CAEDRNativeRemoveAllDeviceSocket(env);
+ CAEDRDestroyJniInterface();
+}
+
+CAResult_t CAEDRDestroyJniInterface()
+{
+ OIC_LOG(DEBUG, TAG, "CAEDRDestroyJniInterface");
+
+ if (!g_jvm)
+ {
+ OIC_LOG(ERROR, TAG, "g_jvm is null");
+ return CA_STATUS_FAILED;
+ }
+
+ bool isAttached = false;
+ JNIEnv* env;
+ jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
+ if (JNI_OK != res)
+ {
+ OIC_LOG(INFO, TAG, "Could not get JNIEnv pointer");
+ res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
+
+ if (JNI_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
+ return CA_STATUS_FAILED;
+ }
+ isAttached = true;
+ }
+
+ jclass jni_EDRJniInterface = (*env)->FindClass(env, CLASSPATH_BT_INTERFACE);
+ if (!jni_EDRJniInterface)
+ {
+ OIC_LOG(ERROR, TAG, "Could not get CaEdrInterface class");
+ goto error_exit;
+ }
+
+ jmethodID jni_EDRInterfaceDestroyMethod = (*env)->GetStaticMethodID(env, jni_EDRJniInterface,
+ "destroyEdrInterface",
+ "()V");
+ if (!jni_EDRInterfaceDestroyMethod)
+ {
+ OIC_LOG(ERROR, TAG, "Could not get CaEdrInterface destroy method");
+ goto error_exit;
+ }
+
+ (*env)->CallStaticVoidMethod(env, jni_EDRJniInterface, jni_EDRInterfaceDestroyMethod);
+
+ if ((*env)->ExceptionCheck(env))
+ {
+ OIC_LOG(ERROR, TAG, "destroyEdrInterface has failed");
+ (*env)->ExceptionDescribe(env);
+ (*env)->ExceptionClear(env);
+ goto error_exit;
+ }
+
+ OIC_LOG(DEBUG, TAG, "Destroy instance for CaEdrInterface");
+
+ if (isAttached)
+ {
+ (*g_jvm)->DetachCurrentThread(g_jvm);
+ }
+
+ return CA_STATUS_OK;
+
+error_exit:
+
+ if (isAttached)
+ {
+ (*g_jvm)->DetachCurrentThread(g_jvm);
+ }
+
+ return CA_STATUS_FAILED;
}
void CAEDRCoreJniInit()
void CAEDRTerminate();
/**
+ * destroy interface object and terminate the interface.
+ * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+CAResult_t CAEDRDestroyJniInterface();
+
+/**
* Initialize JNI object.
*/
void CAEDRCoreJniInit();
CALEClientSetSendFinishFlag(false);
CALEClientTerminateGattMutexVariables();
+ CALEClientDestroyJniInterface();
ca_cond_free(g_deviceDescCond);
ca_cond_free(g_threadCond);
}
}
+CAResult_t CALEClientDestroyJniInterface()
+{
+ OIC_LOG(DEBUG, TAG, "CALEClientDestroyJniInterface");
+
+ if (!g_jvm)
+ {
+ OIC_LOG(ERROR, TAG, "g_jvm is null");
+ return CA_STATUS_FAILED;
+ }
+
+ bool isAttached = false;
+ JNIEnv* env;
+ jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
+ if (JNI_OK != res)
+ {
+ OIC_LOG(INFO, TAG, "Could not get JNIEnv pointer");
+ res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
+
+ if (JNI_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
+ return CA_STATUS_FAILED;
+ }
+ isAttached = true;
+ }
+
+ jclass jni_LeInterface = (*env)->FindClass(env, "org/iotivity/ca/CaLeClientInterface");
+ if (!jni_LeInterface)
+ {
+ OIC_LOG(ERROR, TAG, "Could not get CaLeClientInterface class");
+ goto error_exit;
+ }
+
+ jmethodID jni_InterfaceDestroyMethod = (*env)->GetStaticMethodID(env, jni_LeInterface,
+ "destroyLeInterface",
+ "()V");
+ if (!jni_InterfaceDestroyMethod)
+ {
+ OIC_LOG(ERROR, TAG, "Could not get CaLeClientInterface destroy method");
+ goto error_exit;
+ }
+
+ (*env)->CallStaticVoidMethod(env, jni_LeInterface, jni_InterfaceDestroyMethod);
+
+ if ((*env)->ExceptionCheck(env))
+ {
+ OIC_LOG(ERROR, TAG, "destroyLeInterface has failed");
+ (*env)->ExceptionDescribe(env);
+ (*env)->ExceptionClear(env);
+ goto error_exit;
+ }
+
+ OIC_LOG(DEBUG, TAG, "Destroy instance for CaLeClientInterface");
+
+ if (isAttached)
+ {
+ (*g_jvm)->DetachCurrentThread(g_jvm);
+ }
+
+ return CA_STATUS_OK;
+
+error_exit:
+
+ if (isAttached)
+ {
+ (*g_jvm)->DetachCurrentThread(g_jvm);
+ }
+
+ return CA_STATUS_FAILED;
+}
+
void CALEClientSendFinish(JNIEnv *env, jobject gatt)
{
OIC_LOG(DEBUG, TAG, "CALEClientSendFinish");
void CALEClientTerminate();
/**
+ * destroy interface object and terminate the interface.
+ * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+CAResult_t CALEClientDestroyJniInterface();
+
+/**
* for destroy sending routine.
* @param[in] env JNI interface pointer.
* @param[in] gatt Gatt profile object.