From: jihwan.seo Date: Tue, 6 Dec 2016 10:42:55 +0000 (+0900) Subject: Add new connectGatt API for Level 23 for android. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a293f2dee13a492799118cc84b30adca70205ba9;p=contrib%2Fiotivity.git Add new connectGatt API for Level 23 for android. Change-Id: I5bb170c92b1df48d767f96dddecdb9b86fc85945 Signed-off-by: jihwan.seo Reviewed-on: https://gerrit.iotivity.org/gerrit/15189 Tested-by: jenkins-iotivity Reviewed-by: Larry Sachs Reviewed-by: Dan Mihai --- diff --git a/resource/csdk/connectivity/src/bt_le_adapter/android/caleclient.c b/resource/csdk/connectivity/src/bt_le_adapter/android/caleclient.c index 18b4f7b..e8e7340 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/android/caleclient.c +++ b/resource/csdk/connectivity/src/bt_le_adapter/android/caleclient.c @@ -1886,36 +1886,73 @@ jobject CALEClientGattConnect(JNIEnv *env, jobject bluetoothDevice, jboolean aut return NULL; } - // get BluetoothDevice method - OIC_LOG(DEBUG, TAG, "get BluetoothDevice method"); - 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"); - return NULL; - } + jobject jni_obj_connectGatt = NULL; + jint jni_int_sdk = CALEGetBuildVersion(env); + OIC_LOG_V(INFO, TAG, "API level is %d", jni_int_sdk); + if (jni_int_sdk >= 23) // upper than API level 23 + { + jmethodID jni_mid_connectGatt = CAGetJNIMethodID(env, "android/bluetooth/BluetoothDevice", + "connectGatt", + "(Landroid/content/Context;ZLandroid/" + "bluetooth/BluetoothGattCallback;I)" + "Landroid/bluetooth/BluetoothGatt;"); + if (!jni_mid_connectGatt) + { + OIC_LOG(ERROR, TAG, "bleConnect: jni_mid_connectGatt is null"); + return NULL; + } - OIC_LOG(INFO, TAG, "CALL API - connectGatt"); - jobject jni_obj_connectGatt = (*env)->CallObjectMethod(env, bluetoothDevice, - jni_mid_connectGatt, - NULL, - autoconnect, g_leGattCallback); - if (!jni_obj_connectGatt) - { - OIC_LOG(ERROR, TAG, "connectGatt was failed..it will be removed"); - CACheckJNIException(env); - CALEClientRemoveDeviceInScanDeviceList(env, jni_address); - CALEClientUpdateSendCnt(env); - return NULL; + jint jni_transport_le = CALEGetConstantsValue(env, CLASSPATH_BT_DEVICE, "TRANSPORT_LE"); + OIC_LOG_V(INFO, TAG, "CALL API - connectGatt with transport LE(%d)", jni_transport_le); + jni_obj_connectGatt = (*env)->CallObjectMethod(env, bluetoothDevice, + jni_mid_connectGatt, NULL, + autoconnect, g_leGattCallback, + jni_transport_le); + if (!jni_obj_connectGatt) + { + OIC_LOG(ERROR, TAG, "connectGatt was failed..it will be removed"); + CACheckJNIException(env); + CALEClientRemoveDeviceInScanDeviceList(env, jni_address); + CALEClientUpdateSendCnt(env); + return NULL; + } + else + { + OIC_LOG(DEBUG, TAG, "le connecting..please wait.."); + } } - else + else // lower than API level 23 { - OIC_LOG(DEBUG, TAG, "le connecting..please wait.."); + 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"); + return NULL; + } + + OIC_LOG(INFO, TAG, "CALL API - connectGatt"); + jni_obj_connectGatt = (*env)->CallObjectMethod(env, bluetoothDevice, + jni_mid_connectGatt, + NULL, + autoconnect, g_leGattCallback); + if (!jni_obj_connectGatt) + { + OIC_LOG(ERROR, TAG, "connectGatt was failed..it will be removed"); + CACheckJNIException(env); + CALEClientRemoveDeviceInScanDeviceList(env, jni_address); + CALEClientUpdateSendCnt(env); + return NULL; + } + else + { + OIC_LOG(DEBUG, TAG, "le connecting..please wait.."); + } } + return jni_obj_connectGatt; }