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 OIC_LOG(ERROR, TAG, "[EDR] getRemoteAddress: jni_mid_getRemoteDevice is null");
67 jobject jni_obj_remoteBTDevice = (*env)->CallObjectMethod(env, bluetoothSocketObj,
68 jni_mid_getRemoteDevice);
69 if (!jni_obj_remoteBTDevice)
71 OIC_LOG(ERROR, TAG, "[EDR] getRemoteAddress: jni_obj_remoteBTDevice is null");
75 jclass jni_cid_BTDevice = (*env)->FindClass(env, CLASSPATH_BT_DEVICE);
76 if (!jni_cid_BTDevice)
78 OIC_LOG(ERROR, TAG, "[EDR] getRemoteAddress: jni_cid_BTDevice is null");
81 jmethodID j_mid_getAddress = (*env)->GetMethodID(env, jni_cid_BTDevice, "getAddress",
82 METHODID_STRINGNONPARAM);
83 if (!j_mid_getAddress)
85 OIC_LOG(ERROR, TAG, "[EDR] getRemoteAddress: j_mid_getAddress is null");
89 jstring j_str_address = (*env)->CallObjectMethod(env, jni_obj_remoteBTDevice, j_mid_getAddress);
92 OIC_LOG(ERROR, TAG, "[EDR] getRemoteAddress: j_str_address is null");
99 jstring CAEDRNativeGetLocalDeviceAddress(JNIEnv* env)
101 jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADPATER);
102 if (!jni_cid_BTAdapter)
104 OIC_LOG(ERROR, TAG, "[EDR][Native] getAddress: jni_cid_BTAdapter is null");
108 jmethodID jni_mid_getDefaultAdapter = (*env)->GetStaticMethodID(env, jni_cid_BTAdapter,
110 METHODID_OBJECTNONPARAM);
111 if (!jni_mid_getDefaultAdapter)
113 OIC_LOG(ERROR, TAG, "[EDR][Native] getAddress: jni_mid_getDefaultAdapter is null");
117 jmethodID jni_mid_getAddress = (*env)->GetMethodID(env, jni_cid_BTAdapter, "getAddress",
118 METHODID_STRINGNONPARAM);
119 if (!jni_mid_getAddress)
121 OIC_LOG(ERROR, TAG, "[EDR][Native] getAddress: jni_mid_getAddress is null");
125 jobject jni_obj_BTAdapter = (*env)->CallStaticObjectMethod(env, jni_cid_BTAdapter,
126 jni_mid_getDefaultAdapter);
127 if (!jni_obj_BTAdapter)
129 OIC_LOG(ERROR, TAG, "[EDR][Native] getAddress: jni_obj_BTAdapter is null");
133 jstring jni_str_address = (jstring)(*env)->CallObjectMethod(env, jni_obj_BTAdapter,
135 if (!jni_str_address)
137 OIC_LOG(ERROR, TAG, "[EDR][Native] getAddress: jni_str_address is null");
141 return jni_str_address;
144 jobjectArray CAEDRNativeGetBondedDevices(JNIEnv *env)
146 jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADPATER);
147 if (!jni_cid_BTAdapter)
149 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_cid_BTAdapter is null");
153 jmethodID jni_mid_getDefaultAdapter = (*env)->GetStaticMethodID(env, jni_cid_BTAdapter,
155 METHODID_OBJECTNONPARAM);
156 if (!jni_mid_getDefaultAdapter)
158 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: default adapter is null");
162 jobject jni_obj_BTAdapter = (*env)->CallStaticObjectMethod(env, jni_cid_BTAdapter,
163 jni_mid_getDefaultAdapter);
164 if (!jni_obj_BTAdapter)
166 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: bluetooth adapter is null");
170 // Get a list of currently paired devices
171 jmethodID jni_mid_getBondedDevices = (*env)->GetMethodID(env, jni_cid_BTAdapter,
173 "()Ljava/util/Set;");
174 if (!jni_mid_getBondedDevices)
176 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_mid_getBondedDevicesr is null");
180 jobject jni_obj_setPairedDevices = (*env)->CallObjectMethod(env, jni_obj_BTAdapter,
181 jni_mid_getBondedDevices);
182 if (!jni_obj_setPairedDevices)
184 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_obj_setPairedDevices is null");
188 // Convert the set to an object array
189 // object[] array = Set<BluetoothDevice>.toArray();
190 jclass jni_cid_Set = (*env)->FindClass(env, "java/util/Set");
193 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_cid_Set is null");
196 jmethodID jni_mid_toArray = (*env)->GetMethodID(env, jni_cid_Set, "toArray",
197 "()[Ljava/lang/Object;");
199 if (!jni_mid_toArray)
201 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_mid_toArray is null");
205 jobjectArray jni_arrayPairedDevices = (jobjectArray)(
206 (*env)->CallObjectMethod(env, jni_obj_setPairedDevices, jni_mid_toArray));
207 if (!jni_arrayPairedDevices)
209 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_arrayPairedDevices is null");
213 return jni_arrayPairedDevices;
216 jint CAEDRNativeGetBTStateOnInfo(JNIEnv *env)
218 jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADPATER);
219 if (!jni_cid_BTAdapter)
221 OIC_LOG(ERROR, TAG, "[EDR][Native] getBTStateOnInfo: jni_cid_BTAdapter is null");
225 jfieldID jni_fid_stateon = (*env)->GetStaticFieldID(env, jni_cid_BTAdapter, "STATE_ON", "I");
226 if (jni_fid_stateon == 0)
228 OIC_LOG(ERROR, TAG, "[EDR][Native] get_field_state is 0");
231 jint jni_int_val = (*env)->GetStaticIntField(env, jni_cid_BTAdapter, jni_fid_stateon);
233 OIC_LOG_V(DEBUG, TAG, "[EDR][Native] bluetooth state integer value : %d", jni_int_val);
238 jboolean CAEDRNativeIsEnableBTAdapter(JNIEnv *env)
240 jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADPATER);
241 if (!jni_cid_BTAdapter)
243 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_cid_BTAdapter: jni_cid_BTAdapter is null");
247 jmethodID jni_mid_getDefaultAdapter = (*env)->GetStaticMethodID(env, jni_cid_BTAdapter,
249 METHODID_OBJECTNONPARAM);
250 if (!jni_mid_getDefaultAdapter)
252 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_mid_getDefaultAdapter is null");
256 jobject jni_obj_BTAdapter = (*env)->CallStaticObjectMethod(env, jni_cid_BTAdapter,
257 jni_mid_getDefaultAdapter);
258 if (!jni_obj_BTAdapter)
260 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_obj_BTAdapter is null");
265 jmethodID jni_mid_isEnable = (*env)->GetMethodID(env, jni_cid_BTAdapter, "isEnabled", "()Z");
266 if (!jni_mid_isEnable)
268 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_mid_isEnable is null");
272 jboolean jni_isEnable = (*env)->CallBooleanMethod(env, jni_obj_BTAdapter, jni_mid_isEnable);
273 OIC_LOG_V(DEBUG, TAG, "[EDR][Native] adapter state is %d", jni_isEnable);
278 jstring CAEDRNativeGetAddressFromBTDevice(JNIEnv *env, jobject bluetoothDevice)
280 if (!bluetoothDevice)
282 OIC_LOG(ERROR, TAG, "[EDR][Native] bluetoothDevice is null");
285 jclass jni_cid_device_list = (*env)->FindClass(env, "android/bluetooth/BluetoothDevice");
286 if (!jni_cid_device_list)
288 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_cid_device_list is null");
292 jmethodID jni_mid_getAddress = (*env)->GetMethodID(env, jni_cid_device_list, "getAddress",
293 METHODID_STRINGNONPARAM);
294 if (!jni_mid_getAddress)
296 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_mid_getAddress is null");
300 jstring jni_address = (jstring)(*env)->CallObjectMethod(env, bluetoothDevice,
304 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_address is null");
313 void CAEDRNativeCreateDeviceStateList()
315 OIC_LOG(DEBUG, TAG, "[EDR][Native] CAEDRNativeCreateDeviceStateList");
317 // create new object array
318 if (NULL == g_deviceStateList)
320 OIC_LOG(DEBUG, TAG, "Create device list");
322 g_deviceStateList = u_arraylist_create();
326 void CAEDRUpdateDeviceState(CAConnectedState_t state, const char *address)
330 OIC_LOG(ERROR, TAG, "[EDR][Native] address is null");
333 state_t *newstate = (state_t*) OICCalloc(1, sizeof(state_t));
336 OIC_LOG(ERROR, TAG, "[EDR][Native] newstate is null");
339 OICStrcpy(newstate->address, sizeof(newstate->address), address);
340 newstate->state = state;
342 CAEDRNativeAddDeviceStateToList(newstate);
345 void CAEDRNativeAddDeviceStateToList(state_t *state)
349 OIC_LOG(ERROR, TAG, "[EDR][Native] device is null");
353 if (!g_deviceStateList)
355 OIC_LOG(ERROR, TAG, "[EDR][Native] gdevice_list is null");
359 if (CAEDRNativeIsDeviceInList(state->address))
361 CAEDRNativeRemoveDevice(state->address); // delete previous state for update new state
363 u_arraylist_add(g_deviceStateList, state); // update new state
364 OIC_LOG_V(DEBUG, TAG, "Set State Info to List : %d", state->state);
367 bool CAEDRNativeIsDeviceInList(const char* remoteAddress)
372 OIC_LOG(ERROR, TAG, "[EDR][Native] remoteAddress is null");
376 jint length = u_arraylist_length(g_deviceStateList);
377 for (index = 0; index < length; index++)
379 state_t* state = (state_t*) u_arraylist_get(g_deviceStateList, index);
382 OIC_LOG(ERROR, TAG, "[EDR][Native] state_t object is null");
386 if (!strcmp(remoteAddress, state->address))
388 OIC_LOG(DEBUG, TAG, "the device is already set");
397 OIC_LOG(DEBUG, TAG, "there are no the device in list.");
401 void CAEDRNativeRemoveAllDeviceState()
403 OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveAllDevices");
405 if (!g_deviceStateList)
407 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceStateList is null");
412 jint length = u_arraylist_length(g_deviceStateList);
413 for (index = 0; index < length; index++)
415 state_t* state = (state_t*) u_arraylist_get(g_deviceStateList, index);
418 OIC_LOG(DEBUG, TAG, "[EDR][Native] jarrayObj is null");
424 OICFree(g_deviceStateList);
425 g_deviceStateList = NULL;
429 void CAEDRNativeRemoveDevice(const char *remoteAddress)
431 OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveDeviceforStateList");
433 if (!g_deviceStateList)
435 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceStateList is null");
440 OIC_LOG(ERROR, TAG, "[EDR][Native] remoteAddress is null");
445 jint length = u_arraylist_length(g_deviceStateList);
446 for (index = 0; index < length; index++)
448 state_t* state = (state_t*) u_arraylist_get(g_deviceStateList, index);
451 OIC_LOG(DEBUG, TAG, "[EDR][Native] state_t object is null");
455 if (!strcmp(state->address, remoteAddress))
457 OIC_LOG_V(DEBUG, TAG, "[EDR][Native] remove state : %s", remoteAddress);
460 CAEDRReorderingDeviceList(index);
467 CAConnectedState_t CAEDRIsConnectedDevice(const char *remoteAddress)
469 OIC_LOG(DEBUG, TAG, "CAEDRIsConnectedDevice");
473 OIC_LOG(ERROR, TAG, "[EDR][Native] remoteAddress is null");
474 return STATE_DISCONNECTED;
477 if (!g_deviceStateList)
479 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceStateList is null");
480 return STATE_DISCONNECTED;
484 jint length = u_arraylist_length(g_deviceStateList);
485 for (index = 0; index < length; index++)
487 state_t* state = (state_t*) u_arraylist_get(g_deviceStateList, index);
490 OIC_LOG(DEBUG, TAG, "[EDR][Native] state_t object is null");
494 if (!strcmp(state->address, remoteAddress))
496 OIC_LOG(DEBUG, TAG, "[EDR][Native] check whether it is connected or not");
501 return STATE_DISCONNECTED;
504 void CAEDRReorderingDeviceList(uint32_t index)
506 if (index >= g_deviceStateList->length)
511 if (index < g_deviceStateList->length - 1)
513 memmove(&g_deviceStateList->data[index], &g_deviceStateList->data[index + 1],
514 (g_deviceStateList->length - index - 1) * sizeof(void *));
517 g_deviceStateList->size--;
518 g_deviceStateList->length--;
522 * Device Socket Object List
524 void CAEDRNativeCreateDeviceSocketList()
526 OIC_LOG(DEBUG, TAG, "[EDR][Native] CAEDRNativeCreateDeviceSocketList");
528 // create new object array
529 if (NULL == g_deviceObjectList)
531 OIC_LOG(DEBUG, TAG, "Create Device object list");
533 g_deviceObjectList = u_arraylist_create();
537 void CAEDRNativeAddDeviceSocketToList(JNIEnv *env, jobject deviceSocket)
539 OIC_LOG(DEBUG, TAG, "[EDR][Native] CANativeAddDeviceobjToList");
543 OIC_LOG(ERROR, TAG, "[EDR][Native] Device is null");
547 if (!g_deviceObjectList)
549 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
553 jstring jni_remoteAddress = CAEDRNativeGetAddressFromDeviceSocket(env, deviceSocket);
554 if (!jni_remoteAddress)
556 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_remoteAddress is null");
560 const char* remoteAddress = (*env)->GetStringUTFChars(env, jni_remoteAddress, NULL);
562 if (!CAEDRNativeIsDeviceSocketInList(env, remoteAddress))
564 jobject gDeviceSocker = (*env)->NewGlobalRef(env, deviceSocket);
565 u_arraylist_add(g_deviceObjectList, gDeviceSocker);
566 OIC_LOG(DEBUG, TAG, "Set Socket Object to Array");
568 (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress);
571 bool CAEDRNativeIsDeviceSocketInList(JNIEnv *env, const char* remoteAddress)
573 OIC_LOG(DEBUG, TAG, "[EDR][Native] CANativeIsDeviceObjInList");
577 OIC_LOG(ERROR, TAG, "[EDR][Native] remoteAddress is null");
581 jint length = u_arraylist_length(g_deviceStateList);
582 for (index = 0; index < length; index++)
585 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
588 OIC_LOG(DEBUG, TAG, "[EDR][Native] jarrayObj is null");
592 jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj);
595 OIC_LOG(DEBUG, TAG, "[EDR][Native] jni_setAddress is null");
599 const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL);
602 OIC_LOG(DEBUG, TAG, "[EDR][Native] setAddress is null");
606 if (!strcmp(remoteAddress, setAddress))
608 OIC_LOG(DEBUG, TAG, "the device is already set");
609 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
614 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
619 OIC_LOG(DEBUG, TAG, "there are no the Device obejct in list. we can add");
623 void CAEDRNativeSocketCloseToAll(JNIEnv *env)
625 OIC_LOG(DEBUG, TAG, "[EDR][Native] CAEDRNativeSocketCloseToAll");
627 if (!g_deviceObjectList)
629 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
633 jclass jni_cid_BTSocket = (*env)->FindClass(env, CLASSPATH_BT_SOCKET);
634 if (!jni_cid_BTSocket)
636 OIC_LOG(ERROR, TAG, "[EDR][Native] close: jni_cid_BTSocket is null");
640 jmethodID jni_mid_close = (*env)->GetMethodID(env, jni_cid_BTSocket, "close", "()V");
643 OIC_LOG(ERROR, TAG, "[EDR][Native] close: jni_mid_close is null");
648 jint length = u_arraylist_length(g_deviceStateList);
649 for (index = 0; index < length; index++)
651 jobject jni_obj_socket = (jobject) u_arraylist_get(g_deviceObjectList, index);
654 OIC_LOG(ERROR, TAG, "[EDR][Native] socket obj is null");
658 (*env)->CallVoidMethod(env, jni_obj_socket, jni_mid_close);
660 if ((*env)->ExceptionCheck(env))
662 OIC_LOG(ERROR, TAG, "[EDR][Native] close: close is Failed!!!");
663 (*env)->ExceptionDescribe(env);
664 (*env)->ExceptionClear(env);
670 void CAEDRNativeRemoveAllDeviceSocket(JNIEnv *env)
672 OIC_LOG(DEBUG, TAG, "CANativeRemoveAllDeviceObjsList");
674 if (!g_deviceObjectList)
676 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
681 jint length = u_arraylist_length(g_deviceStateList);
682 for (index = 0; index < length; index++)
684 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
687 OIC_LOG(ERROR, TAG, "[EDR][Native] jarrayObj is null");
690 (*env)->DeleteGlobalRef(env, jarrayObj);
693 OICFree(g_deviceObjectList);
694 g_deviceObjectList = NULL;
698 void CAEDRNativeRemoveDeviceSocket(JNIEnv *env, jobject deviceSocket)
700 OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveDeviceSocket");
702 if (!g_deviceObjectList)
704 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
709 jint length = u_arraylist_length(g_deviceStateList);
710 for (index = 0; index < length; index++)
712 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
715 OIC_LOG(DEBUG, TAG, "[EDR][Native] jarrayObj is null");
719 jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj);
722 OIC_LOG(DEBUG, TAG, "[EDR][Native] jni_setAddress is null");
726 jstring jni_remoteAddress = CAEDRNativeGetAddressFromDeviceSocket(env, deviceSocket);
727 if (!jni_remoteAddress)
729 OIC_LOG(DEBUG, TAG, "[EDR][Native] jni_remoteAddress is null");
733 const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL);
734 const char* remoteAddress = (*env)->GetStringUTFChars(env, jni_remoteAddress, NULL);
736 if (!strcmp(setAddress, remoteAddress))
738 OIC_LOG_V(DEBUG, TAG, "[EDR][Native] remove object : %s", remoteAddress);
739 (*env)->DeleteGlobalRef(env, jarrayObj);
740 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
741 (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress);
743 CAEDRReorderingDeviceSocketList(index);
746 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
747 (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress);
750 OIC_LOG(DEBUG, TAG, "[EDR][Native] there are no target object");
754 void CAEDRNativeRemoveDeviceSocketBaseAddr(JNIEnv *env, jstring address)
756 OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveDeviceSocket");
758 if (!g_deviceObjectList)
760 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
765 jint length = u_arraylist_length(g_deviceStateList);
766 for (index = 0; index < length; index++)
768 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
771 OIC_LOG(DEBUG, TAG, "[EDR][Native] jarrayObj is null");
775 jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj);
778 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_setAddress is null");
781 const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL);
782 const char* remoteAddress = (*env)->GetStringUTFChars(env, address, NULL);
784 if (!strcmp(setAddress, remoteAddress))
786 OIC_LOG_V(ERROR, TAG, "[EDR][Native] remove object : %s", remoteAddress);
787 (*env)->DeleteGlobalRef(env, jarrayObj);
788 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
789 (*env)->ReleaseStringUTFChars(env, address, remoteAddress);
791 CAEDRReorderingDeviceSocketList(index);
794 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
795 (*env)->ReleaseStringUTFChars(env, address, remoteAddress);
798 OIC_LOG(DEBUG, TAG, "[EDR][Native] there are no target object");
802 jobject CAEDRNativeGetDeviceSocket(uint32_t idx)
804 OIC_LOG(DEBUG, TAG, "CAEDRNativeGetDeviceSocket");
806 if (!g_deviceObjectList)
808 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
812 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, idx);
815 OIC_LOG(ERROR, TAG, "[EDR][Native] jarrayObj is not available");
821 jobject CAEDRNativeGetDeviceSocketBaseAddr(JNIEnv *env, const char* remoteAddress)
823 OIC_LOG(DEBUG, TAG, "CAEDRNativeGetDeviceSocket");
825 if (!g_deviceObjectList)
827 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
832 jint length = u_arraylist_length(g_deviceStateList);
833 for (index = 0; index < length; index++)
835 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
838 OIC_LOG(ERROR, TAG, "[EDR][Native] jarrayObj is null");
842 jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj);
845 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_setAddress is null");
848 const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL);
850 if (!strcmp(setAddress, remoteAddress))
852 OIC_LOG_V(ERROR, TAG, "[EDR][Native] remove object : %s", remoteAddress);
853 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
856 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
862 uint32_t CAEDRGetSocketListLength()
864 if (!g_deviceObjectList)
866 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
870 uint32_t length = u_arraylist_length(g_deviceObjectList);
875 void CAEDRReorderingDeviceSocketList(uint32_t index)
877 if (index >= g_deviceObjectList->length)
882 if (index < g_deviceObjectList->length - 1)
884 memmove(&g_deviceObjectList->data[index], &g_deviceObjectList->data[index + 1],
885 (g_deviceObjectList->length - index - 1) * sizeof(void *));
888 g_deviceObjectList->size--;
889 g_deviceObjectList->length--;