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("OIC_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);
236 (*env)->DeleteLocalRef(env, jni_obj_setPairedDevices);
238 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_cid_Set is null");
241 jmethodID jni_mid_toArray = (*env)->GetMethodID(env, jni_cid_Set, "toArray",
242 "()[Ljava/lang/Object;");
244 if (!jni_mid_toArray)
246 (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
247 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
248 (*env)->DeleteLocalRef(env, jni_obj_setPairedDevices);
250 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_mid_toArray is null");
254 jobjectArray jni_arrayPairedDevices = (jobjectArray)(
255 (*env)->CallObjectMethod(env, jni_obj_setPairedDevices, jni_mid_toArray));
256 if (!jni_arrayPairedDevices)
258 (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
259 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
260 (*env)->DeleteLocalRef(env, jni_obj_setPairedDevices);
262 OIC_LOG(ERROR, TAG, "[EDR][Native] getBondedDevices: jni_arrayPairedDevices is null");
266 (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
267 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
268 (*env)->DeleteLocalRef(env, jni_obj_setPairedDevices);
270 return jni_arrayPairedDevices;
273 jint CAEDRNativeGetBTStateOnInfo(JNIEnv *env)
275 jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADPATER);
276 if (!jni_cid_BTAdapter)
278 OIC_LOG(ERROR, TAG, "[EDR][Native] getBTStateOnInfo: jni_cid_BTAdapter is null");
282 jfieldID jni_fid_stateon = (*env)->GetStaticFieldID(env, jni_cid_BTAdapter, "STATE_ON", "I");
283 if (jni_fid_stateon == 0)
285 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
287 OIC_LOG(ERROR, TAG, "[EDR][Native] get_field_state is 0");
290 jint jni_int_val = (*env)->GetStaticIntField(env, jni_cid_BTAdapter, jni_fid_stateon);
292 OIC_LOG_V(DEBUG, TAG, "[EDR][Native] bluetooth state integer value : %d", jni_int_val);
294 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
299 jboolean CAEDRNativeIsEnableBTAdapter(JNIEnv *env)
301 jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADPATER);
302 if (!jni_cid_BTAdapter)
304 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_cid_BTAdapter: jni_cid_BTAdapter is null");
308 jmethodID jni_mid_getDefaultAdapter = (*env)->GetStaticMethodID(env, jni_cid_BTAdapter,
310 METHODID_OBJECTNONPARAM);
311 if (!jni_mid_getDefaultAdapter)
313 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
315 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_mid_getDefaultAdapter is null");
319 jobject jni_obj_BTAdapter = (*env)->CallStaticObjectMethod(env, jni_cid_BTAdapter,
320 jni_mid_getDefaultAdapter);
321 if (!jni_obj_BTAdapter)
323 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
325 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_obj_BTAdapter is null");
330 jmethodID jni_mid_isEnable = (*env)->GetMethodID(env, jni_cid_BTAdapter, "isEnabled", "()Z");
331 if (!jni_mid_isEnable)
333 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
334 (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
336 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_mid_isEnable is null");
340 jboolean jni_isEnable = (*env)->CallBooleanMethod(env, jni_obj_BTAdapter, jni_mid_isEnable);
342 (*env)->DeleteLocalRef(env, jni_obj_BTAdapter);
343 (*env)->DeleteLocalRef(env, jni_cid_BTAdapter);
348 jstring CAEDRNativeGetAddressFromBTDevice(JNIEnv *env, jobject bluetoothDevice)
350 if (!bluetoothDevice)
352 OIC_LOG(ERROR, TAG, "[EDR][Native] bluetoothDevice is null");
355 jclass jni_cid_device_list = (*env)->FindClass(env, "android/bluetooth/BluetoothDevice");
356 if (!jni_cid_device_list)
358 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_cid_device_list is null");
362 jmethodID jni_mid_getAddress = (*env)->GetMethodID(env, jni_cid_device_list, "getAddress",
363 METHODID_STRINGNONPARAM);
364 if (!jni_mid_getAddress)
366 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_mid_getAddress is null");
370 jstring jni_address = (jstring)(*env)->CallObjectMethod(env, bluetoothDevice,
374 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_address is null");
383 void CAEDRNativeCreateDeviceStateList()
385 OIC_LOG(DEBUG, TAG, "[EDR][Native] CAEDRNativeCreateDeviceStateList");
387 // create new object array
388 if (NULL == g_deviceStateList)
390 OIC_LOG(DEBUG, TAG, "Create device list");
392 g_deviceStateList = u_arraylist_create();
396 void CAEDRUpdateDeviceState(CAConnectedState_t state, const char *address)
400 OIC_LOG(ERROR, TAG, "[EDR][Native] address is null");
403 state_t *newstate = (state_t*) OICCalloc(1, sizeof(state_t));
406 OIC_LOG(ERROR, TAG, "[EDR][Native] newstate is null");
409 OICStrcpy((char*) newstate->address, sizeof(newstate->address), address);
410 newstate->state = state;
412 CAEDRNativeAddDeviceStateToList(newstate);
415 void CAEDRNativeAddDeviceStateToList(state_t *state)
419 OIC_LOG(ERROR, TAG, "[EDR][Native] device is null");
423 if (!g_deviceStateList)
425 OIC_LOG(ERROR, TAG, "[EDR][Native] gdevice_list is null");
429 if (CAEDRNativeIsDeviceInList((const char*) state->address))
431 // delete previous state for update new state
432 CAEDRNativeRemoveDevice((const char*) state->address);
434 u_arraylist_add(g_deviceStateList, state); // update new state
435 OIC_LOG_V(DEBUG, TAG, "Set State Info to List : %d", state->state);
438 bool CAEDRNativeIsDeviceInList(const char* remoteAddress)
443 OIC_LOG(ERROR, TAG, "[EDR][Native] remoteAddress is null");
447 jint length = u_arraylist_length(g_deviceStateList);
448 for (index = 0; index < length; index++)
450 state_t* state = (state_t*) u_arraylist_get(g_deviceStateList, index);
453 OIC_LOG(ERROR, TAG, "[EDR][Native] state_t object is null");
457 if (!strcmp(remoteAddress, (const char*) state->address))
459 OIC_LOG(DEBUG, TAG, "the device is already set");
468 OIC_LOG(DEBUG, TAG, "there are no the device in list.");
472 void CAEDRNativeRemoveAllDeviceState()
474 OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveAllDevices");
476 if (!g_deviceStateList)
478 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceStateList is null");
483 jint length = u_arraylist_length(g_deviceStateList);
484 for (index = 0; index < length; index++)
486 state_t* state = (state_t*) u_arraylist_get(g_deviceStateList, index);
489 OIC_LOG(DEBUG, TAG, "[EDR][Native] jarrayObj is null");
495 OICFree(g_deviceStateList);
496 g_deviceStateList = NULL;
500 void CAEDRNativeRemoveDevice(const char *remoteAddress)
502 OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveDeviceforStateList");
504 if (!g_deviceStateList)
506 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceStateList is null");
511 OIC_LOG(ERROR, TAG, "[EDR][Native] remoteAddress is null");
516 jint length = u_arraylist_length(g_deviceStateList);
517 for (index = 0; index < length; index++)
519 state_t* state = (state_t*) u_arraylist_get(g_deviceStateList, index);
522 OIC_LOG(DEBUG, TAG, "[EDR][Native] state_t object is null");
526 if (!strcmp((const char*) state->address, remoteAddress))
528 OIC_LOG_V(DEBUG, TAG, "[EDR][Native] remove state : %s", remoteAddress);
531 u_arraylist_remove(g_deviceStateList, index);
538 CAConnectedState_t CAEDRIsConnectedDevice(const char *remoteAddress)
540 OIC_LOG(DEBUG, TAG, "CAEDRIsConnectedDevice");
544 OIC_LOG(ERROR, TAG, "[EDR][Native] remoteAddress is null");
545 return STATE_DISCONNECTED;
548 if (!g_deviceStateList)
550 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceStateList is null");
551 return STATE_DISCONNECTED;
555 jint length = u_arraylist_length(g_deviceStateList);
556 for (index = 0; index < length; index++)
558 state_t* state = (state_t*) u_arraylist_get(g_deviceStateList, index);
561 OIC_LOG(DEBUG, TAG, "[EDR][Native] state_t object is null");
565 if (!strcmp((const char*) state->address, remoteAddress))
570 return STATE_DISCONNECTED;
574 * Device Socket Object List
576 void CAEDRNativeCreateDeviceSocketList()
578 OIC_LOG(DEBUG, TAG, "[EDR][Native] CAEDRNativeCreateDeviceSocketList");
580 // create new object array
581 if (NULL == g_deviceObjectList)
583 OIC_LOG(DEBUG, TAG, "Create Device object list");
585 g_deviceObjectList = u_arraylist_create();
589 void CAEDRNativeAddDeviceSocketToList(JNIEnv *env, jobject deviceSocket)
591 OIC_LOG(DEBUG, TAG, "[EDR][Native] CANativeAddDeviceobjToList");
595 OIC_LOG(ERROR, TAG, "[EDR][Native] Device is null");
599 if (!g_deviceObjectList)
601 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
605 jstring jni_remoteAddress = CAEDRNativeGetAddressFromDeviceSocket(env, deviceSocket);
606 if (!jni_remoteAddress)
608 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_remoteAddress is null");
612 const char* remoteAddress = (*env)->GetStringUTFChars(env, jni_remoteAddress, NULL);
614 if (!CAEDRNativeIsDeviceSocketInList(env, remoteAddress))
616 jobject gDeviceSocker = (*env)->NewGlobalRef(env, deviceSocket);
617 u_arraylist_add(g_deviceObjectList, gDeviceSocker);
618 OIC_LOG(DEBUG, TAG, "Set Socket Object to Array");
620 (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress);
621 (*env)->DeleteLocalRef(env, jni_remoteAddress);
624 bool CAEDRNativeIsDeviceSocketInList(JNIEnv *env, const char* remoteAddress)
626 OIC_LOG(DEBUG, TAG, "[EDR][Native] CANativeIsDeviceObjInList");
630 OIC_LOG(ERROR, TAG, "[EDR][Native] remoteAddress is null");
634 jint length = u_arraylist_length(g_deviceStateList);
635 for (index = 0; index < length; index++)
638 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
641 OIC_LOG(DEBUG, TAG, "[EDR][Native] jarrayObj is null");
645 jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj);
648 OIC_LOG(DEBUG, TAG, "[EDR][Native] jni_setAddress is null");
652 const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL);
655 OIC_LOG(DEBUG, TAG, "[EDR][Native] setAddress is null");
659 if (!strcmp(remoteAddress, setAddress))
661 OIC_LOG(DEBUG, TAG, "the device is already set");
662 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
667 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
672 OIC_LOG(DEBUG, TAG, "there are no the Device obejct in list. we can add");
676 void CAEDRNativeSocketCloseToAll(JNIEnv *env)
678 OIC_LOG(DEBUG, TAG, "[EDR][Native] CAEDRNativeSocketCloseToAll");
680 if (!g_deviceObjectList)
682 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
686 jclass jni_cid_BTSocket = (*env)->FindClass(env, CLASSPATH_BT_SOCKET);
687 if (!jni_cid_BTSocket)
689 OIC_LOG(ERROR, TAG, "[EDR][Native] close: jni_cid_BTSocket is null");
693 jmethodID jni_mid_close = (*env)->GetMethodID(env, jni_cid_BTSocket, "close", "()V");
696 OIC_LOG(ERROR, TAG, "[EDR][Native] close: jni_mid_close is null");
701 jint length = u_arraylist_length(g_deviceStateList);
702 for (index = 0; index < length; index++)
704 jobject jni_obj_socket = (jobject) u_arraylist_get(g_deviceObjectList, index);
707 OIC_LOG(ERROR, TAG, "[EDR][Native] socket obj is null");
711 (*env)->CallVoidMethod(env, jni_obj_socket, jni_mid_close);
713 if ((*env)->ExceptionCheck(env))
715 OIC_LOG(ERROR, TAG, "[EDR][Native] close: close is Failed!!!");
716 (*env)->ExceptionDescribe(env);
717 (*env)->ExceptionClear(env);
723 void CAEDRNativeRemoveAllDeviceSocket(JNIEnv *env)
725 OIC_LOG(DEBUG, TAG, "CANativeRemoveAllDeviceObjsList");
727 if (!g_deviceObjectList)
729 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
734 jint length = u_arraylist_length(g_deviceStateList);
735 for (index = 0; index < length; index++)
737 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
740 OIC_LOG(ERROR, TAG, "[EDR][Native] jarrayObj is null");
743 (*env)->DeleteGlobalRef(env, jarrayObj);
746 OICFree(g_deviceObjectList);
747 g_deviceObjectList = NULL;
751 void CAEDRNativeRemoveDeviceSocket(JNIEnv *env, jobject deviceSocket)
753 OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveDeviceSocket");
755 if (!g_deviceObjectList)
757 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
762 jint length = u_arraylist_length(g_deviceStateList);
763 for (index = 0; index < length; index++)
765 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
768 OIC_LOG(DEBUG, TAG, "[EDR][Native] jarrayObj is null");
772 jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj);
775 OIC_LOG(DEBUG, TAG, "[EDR][Native] jni_setAddress is null");
779 jstring jni_remoteAddress = CAEDRNativeGetAddressFromDeviceSocket(env, deviceSocket);
780 if (!jni_remoteAddress)
782 OIC_LOG(DEBUG, TAG, "[EDR][Native] jni_remoteAddress is null");
786 const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL);
787 const char* remoteAddress = (*env)->GetStringUTFChars(env, jni_remoteAddress, NULL);
789 if (!strcmp(setAddress, remoteAddress))
791 OIC_LOG_V(DEBUG, TAG, "[EDR][Native] remove object : %s", remoteAddress);
792 (*env)->DeleteGlobalRef(env, jarrayObj);
793 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
794 (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress);
796 u_arraylist_remove(g_deviceObjectList, index);
799 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
800 (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress);
803 OIC_LOG(DEBUG, TAG, "[EDR][Native] there are no target object");
807 void CAEDRNativeRemoveDeviceSocketBaseAddr(JNIEnv *env, jstring address)
809 OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveDeviceSocket");
811 if (!g_deviceObjectList)
813 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
818 jint length = u_arraylist_length(g_deviceStateList);
819 for (index = 0; index < length; index++)
821 jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
824 OIC_LOG(DEBUG, TAG, "[EDR][Native] jarrayObj is null");
828 jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj);
831 OIC_LOG(ERROR, TAG, "[EDR][Native] jni_setAddress is null");
834 const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL);
835 const char* remoteAddress = (*env)->GetStringUTFChars(env, address, NULL);
837 if (!strcmp(setAddress, remoteAddress))
839 OIC_LOG_V(ERROR, TAG, "[EDR][Native] remove object : %s", remoteAddress);
840 (*env)->DeleteGlobalRef(env, jarrayObj);
841 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
842 (*env)->ReleaseStringUTFChars(env, address, remoteAddress);
844 u_arraylist_remove(g_deviceObjectList, index);
847 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
848 (*env)->ReleaseStringUTFChars(env, address, remoteAddress);
851 OIC_LOG(DEBUG, TAG, "[EDR][Native] there are no target object");
855 jobject CAEDRNativeGetDeviceSocket(uint32_t idx)
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);
905 (*env)->DeleteLocalRef(env, jni_setAddress);
908 (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
909 (*env)->DeleteLocalRef(env, jni_setAddress);
915 uint32_t CAEDRGetSocketListLength()
917 if (!g_deviceObjectList)
919 OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
923 uint32_t length = u_arraylist_length(g_deviceObjectList);