From afda8e5ea71c04199bbf9f21ae8a65e4ee42abf0 Mon Sep 17 00:00:00 2001 From: "jihwan.seo" Date: Mon, 18 Apr 2016 17:25:14 +0900 Subject: [PATCH] added to checking connection state from CALEGetConstantsValue dynamic. - it is about BLE server. - added null checker for some global variable. Change-Id: I04444e3dac5ab2fb374ee5fdaf0842d4d2034f6d Signed-off-by: jihwan.seo Reviewed-on: https://gerrit.iotivity.org/gerrit/7803 Tested-by: jenkins-iotivity Reviewed-by: Jon A. Cruz --- .../src/bt_le_adapter/android/caleserver.c | 32 ++++++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/resource/csdk/connectivity/src/bt_le_adapter/android/caleserver.c b/resource/csdk/connectivity/src/bt_le_adapter/android/caleserver.c index 3327161..c25157a 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/android/caleserver.c +++ b/resource/csdk/connectivity/src/bt_le_adapter/android/caleserver.c @@ -38,6 +38,7 @@ #define TAG PCF("OIC_CA_LE_SERVER") #define WAIT_TIME_WRITE_CHARACTERISTIC 10000000 +#define INVALID_STATE -1 static JavaVM *g_jvm = NULL; static jobject g_context = NULL; @@ -67,6 +68,9 @@ static ca_mutex g_threadSendNotifyMutex = NULL; static ca_cond g_threadSendNotifyCond = NULL; static bool g_isSignalSetFlag = false; +static jint g_state_connected = INVALID_STATE; +static jint g_state_disconnected = INVALID_STATE; + static const char CLASSPATH_BT_ADVERTISE_CB[] = "android/bluetooth/le/AdvertiseCallback"; static const char CLASSPATH_BT_GATTSERVER[] = "android/bluetooth/BluetoothGattServer"; @@ -293,7 +297,13 @@ CAResult_t CALEServerSendResponseData(JNIEnv *env, jobject device, jobject respo return CA_ADAPTER_NOT_ENABLED; } - if (STATE_CONNECTED != CALEServerGetConnectionState(env, device)) + if (!g_bluetoothGattServer) + { + OIC_LOG(ERROR, TAG, "g_bluetoothGattServer is not available"); + return CA_STATUS_FAILED; + } + + if (g_state_connected != CALEServerGetConnectionState(env, device)) { OIC_LOG(ERROR, TAG, "it is not connected state"); return CA_STATUS_FAILED; @@ -358,6 +368,12 @@ CAResult_t CALEServerSendResponse(JNIEnv *env, jobject device, jint requestId, j return CA_ADAPTER_NOT_ENABLED; } + if (!g_bluetoothGattServer) + { + OIC_LOG(ERROR, TAG, "g_bluetoothGattServer is not available"); + return CA_STATUS_FAILED; + } + jmethodID jni_mid_sendResponse = CAGetJNIMethodID(env, CLASSPATH_BT_GATTSERVER, "sendResponse", "(Landroid/bluetooth/BluetoothDevice;" @@ -1695,6 +1711,10 @@ CAResult_t CALEServerStartMulticastServer() OIC_LOG(ERROR, TAG, "CALEServerStartAdvertise has failed"); } + // get Constants Value from Android Platform + g_state_connected = CALEGetConstantsValue(env, CLASSPATH_BT_PROFILE, "STATE_CONNECTED"); + g_state_disconnected = CALEGetConstantsValue(env, CLASSPATH_BT_PROFILE, "STATE_DISCONNECTED"); + if (isAttached) { (*g_jvm)->DetachCurrentThread(g_jvm); @@ -2208,13 +2228,7 @@ Java_org_iotivity_ca_CaLeServerInterface_caLeGattServerConnectionStateChangeCall VERIFY_NON_NULL_VOID(obj, TAG, "obj"); VERIFY_NON_NULL_VOID(device, TAG, "device"); - // STATE_CONNECTED - jint state_connected = CALEGetConstantsValue(env, CLASSPATH_BT_PROFILE, "STATE_CONNECTED"); - - // STATE_DISCONNECTED - jint state_disconnected = CALEGetConstantsValue(env, CLASSPATH_BT_PROFILE, "STATE_DISCONNECTED"); - - if (newState == state_connected) + if (newState == g_state_connected) { OIC_LOG(DEBUG, TAG, "LE CONNECTED"); @@ -2240,7 +2254,7 @@ Java_org_iotivity_ca_CaLeServerInterface_caLeGattServerConnectionStateChangeCall } (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress); } - else if (newState == state_disconnected) + else if (newState == g_state_disconnected) { OIC_LOG(DEBUG, TAG, "LE DISCONNECTED"); -- 2.7.4