1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
23 #include <android/log.h>
24 #include "caedrutils.h"
26 #include "oic_malloc.h"
27 #include "oic_string.h"
28 #include "cathreadpool.h"
29 #include "uarraylist.h"
31 #define ERROR_CODE (-1)
32 #define TAG PCF("CA_EDR_UTILS")
34 static const char METHODID_OBJECTNONPARAM[] = "()Landroid/bluetooth/BluetoothAdapter;";
35 static const char METHODID_STRINGNONPARAM[] = "()Ljava/lang/String;";
36 static const char CLASSPATH_BT_ADPATER[] = "android/bluetooth/BluetoothAdapter";
37 static const char CLASSPATH_BT_DEVICE[] = "android/bluetooth/BluetoothDevice";
38 static const char CLASSPATH_BT_SOCKET[] = "android/bluetooth/BluetoothSocket";
40 static u_arraylist_t *g_deviceStateList = NULL;
41 static u_arraylist_t *g_deviceObjectList = NULL;
43 // get address from bluetooth socket
44 jstring CAEDRNativeGetAddressFromDeviceSocket(JNIEnv *env, jobject bluetoothSocketObj)
46 if (!bluetoothSocketObj)
48 OIC_LOG(ERROR, TAG, "[EDR] getRemoteAddress: bluetoothSocketObj is null");
52 jclass jni_cid_BTSocket = (*env)->FindClass(env, CLASSPATH_BT_SOCKET);
53 if (!jni_cid_BTSocket)
55 OIC_LOG(ERROR, TAG, "[EDR] getRemoteAddress: jni_cid_BTSocket is null");
59 jmethodID jni_mid_getRemoteDevice = (*env)->GetMethodID(
60 env, jni_cid_BTSocket, "getRemoteDevice", "()Landroid/bluetooth/BluetoothDevice;");
61 if (!jni_mid_getRemoteDevice)
63 (*env)->DeleteLocalRef(env, jni_cid_BTSocket);
65 OIC_LOG(ERROR, TAG, "[EDR] getRemoteAddress: jni_mid_getRemoteDevice is null");
69 jobject jni_obj_remoteBTDevice = (*env)->CallObjectMethod(env, bluetoothSocketObj,
70 jni_mid_getRemoteDevice);
71 if (!jni_obj_remoteBTDevice)
73 (*env)->DeleteLocalRef(env, jni_cid_BTSocket);
75 OIC_LOG(ERROR, TAG, "[EDR] getRemoteAddress: jni_obj_remoteBTDevice is null");
79 jclass jni_cid_BTDevice = (*env)->FindClass(env, CLASSPATH_BT_DEVICE);
80 if (!jni_cid_BTDevice)
82 (*env)->DeleteLocalRef(env, jni_obj_remoteBTDevice);
83 (*env)->DeleteLocalRef(env, jni_cid_BTSocket);
85 OIC_LOG(ERROR, TAG, "[EDR] getRemoteAddress: jni_cid_BTDevice is null");
88 jmethodID j_mid_getAddress = (*env)->GetMethodID(env, jni_cid_BTDevice, "getAddress",
89 METHODID_STRINGNONPARAM);
90 if (!j_mid_getAddress)
92 (*env)->DeleteLocalRef(env, jni_obj_remoteBTDevice);
93 (*env)->DeleteLocalRef(env, jni_cid_BTDevice);
94 (*env)->DeleteLocalRef(env, jni_cid_BTSocket);
96 OIC_LOG(ERROR, TAG, "[EDR] getRemoteAddress: j_mid_getAddress is null");
100 jstring j_str_address = (*env)->CallObjectMethod(env, jni_obj_remoteBTDevice, j_mid_getAddress);
103 (*env)->DeleteLocalRef(env, jni_obj_remoteBTDevice);
104 (*env)->DeleteLocalRef(env, jni_cid_BTDevice);
105 (*env)->DeleteLocalRef(env, jni_cid_BTSocket);
107 OIC_LOG(ERROR, TAG, "[EDR] getRemoteAddress: j_str_address is null");
111 (*env)->DeleteLocalRef(env, jni_obj_remoteBTDevice);
112 (*env)->DeleteLocalRef(env, jni_cid_BTDevice);
113 (*env)->DeleteLocalRef(env, jni_cid_BTSocket);
115 return j_str_address;
118 jstring CAEDRNativeGetLocalDeviceAddress(JNIEnv* env)
120 jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADPATER);
121 if (!jni_cid_BTAdapter)
123 OIC_LOG(ERROR, TAG, "[EDR][Native] getAddress: jni_cid_BTAdapter is null");
127 jmethodID jni_mid_getDefaultAdapter = (*env)->GetStaticMethodID(env, jni_cid_BTAdapter,
129 METHODID_OBJECTNONPARAM);
130 if (!jni_mid_getDefaultAdapter)
132 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
134 OIC_LOG(ERROR, TAG, "[EDR][Native] getAddress: jni_mid_getDefaultAdapter is null");
138 jmethodID jni_mid_getAddress = (*env)->GetMethodID(env, jni_cid_BTAdapter, "getAddress",
139 METHODID_STRINGNONPARAM);
140 if (!jni_mid_getAddress)
142 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
144 OIC_LOG(ERROR, TAG, "[EDR][Native] getAddress: jni_mid_getAddress is null");
148 jobject jni_obj_BTAdapter = (*env)->CallStaticObjectMethod(env, jni_cid_BTAdapter,
149 jni_mid_getDefaultAdapter);
150 if (!jni_obj_BTAdapter)
152 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
154 OIC_LOG(ERROR, TAG, "[EDR][Native] getAddress: jni_obj_BTAdapter is null");
158 jstring jni_str_address = (jstring)(*env)->CallObjectMethod(env, jni_obj_BTAdapter,
160 if (!jni_str_address)
162 (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
163 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
165 OIC_LOG(ERROR, TAG, "[EDR][Native] getAddress: jni_str_address is null");
169 (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
170 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
172 return jni_str_address;
175 jobjectArray CAEDRNativeGetBondedDevices(JNIEnv *env)
177 jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADPATER);
178 if (!jni_cid_BTAdapter)
180 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_cid_BTAdapter is null");
184 jmethodID jni_mid_getDefaultAdapter = (*env)->GetStaticMethodID(env, jni_cid_BTAdapter,
186 METHODID_OBJECTNONPARAM);
187 if (!jni_mid_getDefaultAdapter)
189 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
191 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: default adapter is null");
195 jobject jni_obj_BTAdapter = (*env)->CallStaticObjectMethod(env, jni_cid_BTAdapter,
196 jni_mid_getDefaultAdapter);
197 if (!jni_obj_BTAdapter)
199 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
201 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: bluetooth adapter is null");
205 // Get a list of currently paired devices
206 jmethodID jni_mid_getBondedDevices = (*env)->GetMethodID(env, jni_cid_BTAdapter,
208 "()Ljava/util/Set;");
209 if (!jni_mid_getBondedDevices)
211 (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
212 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
214 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_mid_getBondedDevicesr is null");
218 jobject jni_obj_setPairedDevices = (*env)->CallObjectMethod(env, jni_obj_BTAdapter,
219 jni_mid_getBondedDevices);
220 if (!jni_obj_setPairedDevices)
222 (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
223 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
225 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_obj_setPairedDevices is null");
229 // Convert the set to an object array
230 // object[] array = Set<BluetoothDevice>.toArray();
231 jclass jni_cid_Set = (*env)->FindClass(env, "java/util/Set");
234 (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
235 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
237 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_cid_Set is null");
240 jmethodID jni_mid_toArray = (*env)->GetMethodID(env, jni_cid_Set, "toArray",
241 "()[Ljava/lang/Object;");
243 if (!jni_mid_toArray)
245 (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
246 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
248 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_mid_toArray is null");
252 jobjectArray jni_arrayPairedDevices = (jobjectArray)(
253 (*env)->CallObjectMethod(env, jni_obj_setPairedDevices, jni_mid_toArray));
254 if (!jni_arrayPairedDevices)
256 (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
257 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
259 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_arrayPairedDevices is null");
263 (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
264 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
266 return jni_arrayPairedDevices;
269 jint CAEDRNativeGetBTStateOnInfo(JNIEnv *env)
271 jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADPATER);
272 if (!jni_cid_BTAdapter)
274 OIC_LOG(ERROR, TAG, "[EDR][Native] getBTStateOnInfo: jni_cid_BTAdapter is null");
278 jfieldID jni_fid_stateon = (*env)->GetStaticFieldID(env, jni_cid_BTAdapter, "STATE_ON", "I");
279 if (jni_fid_stateon == 0)
281 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
283 OIC_LOG(ERROR, TAG, "[EDR][Native] get_field_state is 0");
286 jint jni_int_val = (*env)->GetStaticIntField(env, jni_cid_BTAdapter, jni_fid_stateon);
288 OIC_LOG_V(DEBUG, TAG, "[EDR][Native] bluetooth state integer value : %d", jni_int_val);
290 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
295 jboolean CAEDRNativeIsEnableBTAdapter(JNIEnv *env)
297 jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADPATER);
298 if (!jni_cid_BTAdapter)
300 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_cid_BTAdapter: jni_cid_BTAdapter is null");
304 jmethodID jni_mid_getDefaultAdapter = (*env)->GetStaticMethodID(env, jni_cid_BTAdapter,
306 METHODID_OBJECTNONPARAM);
307 if (!jni_mid_getDefaultAdapter)
309 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
311 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_mid_getDefaultAdapter is null");
315 jobject jni_obj_BTAdapter = (*env)->CallStaticObjectMethod(env, jni_cid_BTAdapter,
316 jni_mid_getDefaultAdapter);
317 if (!jni_obj_BTAdapter)
319 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
321 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_obj_BTAdapter is null");
326 jmethodID jni_mid_isEnable = (*env)->GetMethodID(env, jni_cid_BTAdapter, "isEnabled", "()Z");
327 if (!jni_mid_isEnable)
329 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
330 (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
332 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_mid_isEnable is null");
336 jboolean jni_isEnable = (*env)->CallBooleanMethod(env, jni_obj_BTAdapter, jni_mid_isEnable);
337 OIC_LOG_V(DEBUG, TAG, "[EDR][Native] adapter state is %d", jni_isEnable);
339 (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
340 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
345 jstring CAEDRNativeGetAddressFromBTDevice(JNIEnv *env, jobject bluetoothDevice)
347 if (!bluetoothDevice)
349 OIC_LOG(ERROR, TAG, "[EDR][Native] bluetoothDevice is null");
352 jclass jni_cid_device_list = (*env)->FindClass(env, "android/bluetooth/BluetoothDevice");
353 if (!jni_cid_device_list)
355 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_cid_device_list is null");
359 jmethodID jni_mid_getAddress = (*env)->GetMethodID(env, jni_cid_device_list, "getAddress",
360 METHODID_STRINGNONPARAM);
361 if (!jni_mid_getAddress)
363 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_mid_getAddress is null");
367 jstring jni_address = (jstring)(*env)->CallObjectMethod(env, bluetoothDevice,
371 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_address is null");
380 void CAEDRNativeCreateDeviceStateList()
382 OIC_LOG(DEBUG, TAG, "[EDR][Native] CAEDRNativeCreateDeviceStateList");
384 // create new object array
385 if (NULL == g_deviceStateList)
387 OIC_LOG(DEBUG, TAG, "Create device list");
389 g_deviceStateList = u_arraylist_create();
393 void CAEDRUpdateDeviceState(CAConnectedState_t state, const char *address)
397 OIC_LOG(ERROR, TAG, "[EDR][Native] address is null");
400 state_t *newstate = (state_t*) OICCalloc(1, sizeof(state_t));
403 OIC_LOG(ERROR, TAG, "[EDR][Native] newstate is null");
406 OICStrcpy((char*) newstate->address, sizeof(newstate->address), address);
407 newstate->state = state;
409 CAEDRNativeAddDeviceStateToList(newstate);
412 void CAEDRNativeAddDeviceStateToList(state_t *state)
416 OIC_LOG(ERROR, TAG, "[EDR][Native] device is null");
420 if (!g_deviceStateList)
422 OIC_LOG(ERROR, TAG, "[EDR][Native] gdevice_list is null");
426 if (CAEDRNativeIsDeviceInList((const char*) state->address))
428 // delete previous state for update new state
429 CAEDRNativeRemoveDevice((const char*) state->address);
431 u_arraylist_add(g_deviceStateList, state); // update new state
432 OIC_LOG_V(DEBUG, TAG, "Set State Info to List : %d", state->state);
435 bool CAEDRNativeIsDeviceInList(const char* remoteAddress)
440 OIC_LOG(ERROR, TAG, "[EDR][Native] remoteAddress is null");
444 jint length = u_arraylist_length(g_deviceStateList);
445 for (index = 0; index < length; index++)
447 state_t* state = (state_t*) u_arraylist_get(g_deviceStateList, index);
450 OIC_LOG(ERROR, TAG, "[EDR][Native] state_t object is null");
454 if (!strcmp(remoteAddress, (const char*) state->address))
456 OIC_LOG(DEBUG, TAG, "the device is already set");
465 OIC_LOG(DEBUG, TAG, "there are no the device in list.");
469 void CAEDRNativeRemoveAllDeviceState()
471 OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveAllDevices");
473 if (!g_deviceStateList)
475 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceStateList is null");
480 jint length = u_arraylist_length(g_deviceStateList);
481 for (index = 0; index < length; index++)
483 state_t* state = (state_t*) u_arraylist_get(g_deviceStateList, index);
486 OIC_LOG(DEBUG, TAG, "[EDR][Native] jarrayObj is null");
492 OICFree(g_deviceStateList);
493 g_deviceStateList = NULL;
497 void CAEDRNativeRemoveDevice(const char *remoteAddress)
499 OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveDeviceforStateList");
501 if (!g_deviceStateList)
503 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceStateList is null");
508 OIC_LOG(ERROR, TAG, "[EDR][Native] remoteAddress is null");
513 jint length = u_arraylist_length(g_deviceStateList);
514 for (index = 0; index < length; index++)
516 state_t* state = (state_t*) u_arraylist_get(g_deviceStateList, index);
519 OIC_LOG(DEBUG, TAG, "[EDR][Native] state_t object is null");
523 if (!strcmp((const char*) state->address, remoteAddress))
525 OIC_LOG_V(DEBUG, TAG, "[EDR][Native] remove state : %s", remoteAddress);
528 u_arraylist_remove(g_deviceStateList, index);
535 CAConnectedState_t CAEDRIsConnectedDevice(const char *remoteAddress)
537 OIC_LOG(DEBUG, TAG, "CAEDRIsConnectedDevice");
541 OIC_LOG(ERROR, TAG, "[EDR][Native] remoteAddress is null");
542 return STATE_DISCONNECTED;
545 if (!g_deviceStateList)
547 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceStateList is null");
548 return STATE_DISCONNECTED;
552 jint length = u_arraylist_length(g_deviceStateList);
553 for (index = 0; index < length; index++)
555 state_t* state = (state_t*) u_arraylist_get(g_deviceStateList, index);
558 OIC_LOG(DEBUG, TAG, "[EDR][Native] state_t object is null");
562 if (!strcmp((const char*) state->address, remoteAddress))
564 OIC_LOG(DEBUG, TAG, "[EDR][Native] check whether it is connected or not");
569 return STATE_DISCONNECTED;
573 * Device Socket Object List
575 void CAEDRNativeCreateDeviceSocketList()
577 OIC_LOG(DEBUG, TAG, "[EDR][Native] CAEDRNativeCreateDeviceSocketList");
579 // create new object array
580 if (NULL == g_deviceObjectList)
582 OIC_LOG(DEBUG, TAG, "Create Device object list");
584 g_deviceObjectList = u_arraylist_create();
588 void CAEDRNativeAddDeviceSocketToList(JNIEnv *env, jobject deviceSocket)
590 OIC_LOG(DEBUG, TAG, "[EDR][Native] CANativeAddDeviceobjToList");
594 OIC_LOG(ERROR, TAG, "[EDR][Native] Device is null");
598 if (!g_deviceObjectList)
600 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
604 jstring jni_remoteAddress = CAEDRNativeGetAddressFromDeviceSocket(env, deviceSocket);
605 if (!jni_remoteAddress)
607 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_remoteAddress is null");
611 const char* remoteAddress = (*env)->GetStringUTFChars(env, jni_remoteAddress, NULL);
613 if (!CAEDRNativeIsDeviceSocketInList(env, remoteAddress))
615 jobject gDeviceSocker = (*env)->NewGlobalRef(env, deviceSocket);
616 u_arraylist_add(g_deviceObjectList, gDeviceSocker);
617 OIC_LOG(DEBUG, TAG, "Set Socket Object to Array");
619 (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress);
622 bool CAEDRNativeIsDeviceSocketInList(JNIEnv *env, const char* remoteAddress)
624 OIC_LOG(DEBUG, TAG, "[EDR][Native] CANativeIsDeviceObjInList");
628 OIC_LOG(ERROR, TAG, "[EDR][Native] remoteAddress is null");
632 jint length = u_arraylist_length(g_deviceStateList);
633 for (index = 0; index < length; index++)
636 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
639 OIC_LOG(DEBUG, TAG, "[EDR][Native] jarrayObj is null");
643 jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj);
646 OIC_LOG(DEBUG, TAG, "[EDR][Native] jni_setAddress is null");
650 const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL);
653 OIC_LOG(DEBUG, TAG, "[EDR][Native] setAddress is null");
657 if (!strcmp(remoteAddress, setAddress))
659 OIC_LOG(DEBUG, TAG, "the device is already set");
660 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
665 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
670 OIC_LOG(DEBUG, TAG, "there are no the Device obejct in list. we can add");
674 void CAEDRNativeSocketCloseToAll(JNIEnv *env)
676 OIC_LOG(DEBUG, TAG, "[EDR][Native] CAEDRNativeSocketCloseToAll");
678 if (!g_deviceObjectList)
680 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
684 jclass jni_cid_BTSocket = (*env)->FindClass(env, CLASSPATH_BT_SOCKET);
685 if (!jni_cid_BTSocket)
687 OIC_LOG(ERROR, TAG, "[EDR][Native] close: jni_cid_BTSocket is null");
691 jmethodID jni_mid_close = (*env)->GetMethodID(env, jni_cid_BTSocket, "close", "()V");
694 OIC_LOG(ERROR, TAG, "[EDR][Native] close: jni_mid_close is null");
699 jint length = u_arraylist_length(g_deviceStateList);
700 for (index = 0; index < length; index++)
702 jobject jni_obj_socket = (jobject) u_arraylist_get(g_deviceObjectList, index);
705 OIC_LOG(ERROR, TAG, "[EDR][Native] socket obj is null");
709 (*env)->CallVoidMethod(env, jni_obj_socket, jni_mid_close);
711 if ((*env)->ExceptionCheck(env))
713 OIC_LOG(ERROR, TAG, "[EDR][Native] close: close is Failed!!!");
714 (*env)->ExceptionDescribe(env);
715 (*env)->ExceptionClear(env);
721 void CAEDRNativeRemoveAllDeviceSocket(JNIEnv *env)
723 OIC_LOG(DEBUG, TAG, "CANativeRemoveAllDeviceObjsList");
725 if (!g_deviceObjectList)
727 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
732 jint length = u_arraylist_length(g_deviceStateList);
733 for (index = 0; index < length; index++)
735 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
738 OIC_LOG(ERROR, TAG, "[EDR][Native] jarrayObj is null");
741 (*env)->DeleteGlobalRef(env, jarrayObj);
744 OICFree(g_deviceObjectList);
745 g_deviceObjectList = NULL;
749 void CAEDRNativeRemoveDeviceSocket(JNIEnv *env, jobject deviceSocket)
751 OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveDeviceSocket");
753 if (!g_deviceObjectList)
755 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
760 jint length = u_arraylist_length(g_deviceStateList);
761 for (index = 0; index < length; index++)
763 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
766 OIC_LOG(DEBUG, TAG, "[EDR][Native] jarrayObj is null");
770 jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj);
773 OIC_LOG(DEBUG, TAG, "[EDR][Native] jni_setAddress is null");
777 jstring jni_remoteAddress = CAEDRNativeGetAddressFromDeviceSocket(env, deviceSocket);
778 if (!jni_remoteAddress)
780 OIC_LOG(DEBUG, TAG, "[EDR][Native] jni_remoteAddress is null");
784 const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL);
785 const char* remoteAddress = (*env)->GetStringUTFChars(env, jni_remoteAddress, NULL);
787 if (!strcmp(setAddress, remoteAddress))
789 OIC_LOG_V(DEBUG, TAG, "[EDR][Native] remove object : %s", remoteAddress);
790 (*env)->DeleteGlobalRef(env, jarrayObj);
791 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
792 (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress);
794 u_arraylist_remove(g_deviceObjectList, index);
797 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
798 (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress);
801 OIC_LOG(DEBUG, TAG, "[EDR][Native] there are no target object");
805 void CAEDRNativeRemoveDeviceSocketBaseAddr(JNIEnv *env, jstring address)
807 OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveDeviceSocket");
809 if (!g_deviceObjectList)
811 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
816 jint length = u_arraylist_length(g_deviceStateList);
817 for (index = 0; index < length; index++)
819 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
822 OIC_LOG(DEBUG, TAG, "[EDR][Native] jarrayObj is null");
826 jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj);
829 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_setAddress is null");
832 const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL);
833 const char* remoteAddress = (*env)->GetStringUTFChars(env, address, NULL);
835 if (!strcmp(setAddress, remoteAddress))
837 OIC_LOG_V(ERROR, TAG, "[EDR][Native] remove object : %s", remoteAddress);
838 (*env)->DeleteGlobalRef(env, jarrayObj);
839 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
840 (*env)->ReleaseStringUTFChars(env, address, remoteAddress);
842 u_arraylist_remove(g_deviceObjectList, index);
845 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
846 (*env)->ReleaseStringUTFChars(env, address, remoteAddress);
849 OIC_LOG(DEBUG, TAG, "[EDR][Native] there are no target object");
853 jobject CAEDRNativeGetDeviceSocket(uint32_t idx)
855 OIC_LOG(DEBUG, TAG, "CAEDRNativeGetDeviceSocket");
857 if (!g_deviceObjectList)
859 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
863 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, idx);
866 OIC_LOG(ERROR, TAG, "[EDR][Native] jarrayObj is not available");
872 jobject CAEDRNativeGetDeviceSocketBaseAddr(JNIEnv *env, const char* remoteAddress)
874 OIC_LOG(DEBUG, TAG, "CAEDRNativeGetDeviceSocket");
876 if (!g_deviceObjectList)
878 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
883 jint length = u_arraylist_length(g_deviceStateList);
884 for (index = 0; index < length; index++)
886 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
889 OIC_LOG(ERROR, TAG, "[EDR][Native] jarrayObj is null");
893 jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj);
896 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_setAddress is null");
899 const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL);
901 if (!strcmp(setAddress, remoteAddress))
903 OIC_LOG_V(ERROR, TAG, "[EDR][Native] remove object : %s", remoteAddress);
904 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
907 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
913 uint32_t CAEDRGetSocketListLength()
915 if (!g_deviceObjectList)
917 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
921 uint32_t length = u_arraylist_length(g_deviceObjectList);