1 /* ****************************************************************
3 * Copyright 2016 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 ******************************************************************/
24 #include "cacommonutil.h"
25 #include "camanagerleutil.h"
26 #include "caleclient.h"
27 #include "caleutils.h"
29 #define TAG "OIC_CA_MANAGER_UTIL"
31 static const char CLASSPATH_CONTENT_PREF[] = "android/content/SharedPreferences";
32 static const char CLASSPATH_CONTENT_PREF_EDITOR[] = "android/content/SharedPreferences$Editor";
33 static const char CLASSPATH_CONTEXT[] = "android/content/Context";
35 static const char PREF_NAME_CONNECTED_DEVICE[] = "PREF_NAME_CONNECTED_DEVICE";
36 static const char PREF_KEY_CONNECTED_DEVICE[] = "PREF_KEY_CONNECTED_DEVICE";
38 static const char METHODID_BOOLEAN_RET_STRING_PARAM[] = "(Ljava/lang/String;)Z";
40 static jobject CAManagerGetAdapterContext(JNIEnv *env)
42 OIC_LOG(DEBUG, TAG, "CAManagerGetAdapterContext");
43 VERIFY_NON_NULL_RET(env, TAG, "env is null", NULL);
45 jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADAPTER);
46 if (!jni_cid_BTAdapter)
48 OIC_LOG(ERROR, TAG, "jni_cid_BTAdapter: jni_cid_BTAdapter is null");
52 jmethodID jni_mid_getDefaultAdapter = (*env)->GetStaticMethodID(env, jni_cid_BTAdapter,
54 METHODID_OBJECTNONPARAM);
55 if (!jni_mid_getDefaultAdapter)
57 OIC_LOG(ERROR, TAG, "jni_mid_getDefaultAdapter is null");
61 jobject jni_obj_BTAdapter = (*env)->CallStaticObjectMethod(env, jni_cid_BTAdapter,
62 jni_mid_getDefaultAdapter);
63 if (!jni_obj_BTAdapter)
65 OIC_LOG(ERROR, TAG, "jni_obj_BTAdapter is null");
68 return jni_obj_BTAdapter;
71 jobject CAManagerGetRemoteDevice(JNIEnv *env, jstring address)
73 OIC_LOG(DEBUG, TAG, "IN - CAManagerGetRemoteDevice");
75 VERIFY_NON_NULL_RET(env, TAG, "env is null", NULL);
76 VERIFY_NON_NULL_RET(address, TAG, "address is null", NULL);
78 jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADAPTER);
79 if (!jni_cid_BTAdapter)
81 OIC_LOG(ERROR, TAG, "jni_cid_BTAdapter is null");
85 // get remote bt adapter method
86 jmethodID jni_mid_getDefaultAdapter = (*env)->GetStaticMethodID(env, jni_cid_BTAdapter,
88 METHODID_OBJECTNONPARAM);
89 if (!jni_mid_getDefaultAdapter)
91 OIC_LOG(ERROR, TAG, "jni_mid_getDefaultAdapter is null");
95 // gat bt adapter object
96 jobject jni_obj_BTAdapter = (*env)->CallStaticObjectMethod(env, jni_cid_BTAdapter,
97 jni_mid_getDefaultAdapter);
98 if (!jni_obj_BTAdapter)
100 OIC_LOG(ERROR, TAG, "jni_obj_BTAdapter is null");
104 jmethodID jni_mid_getRemoteDevice = (*env)->GetMethodID(env, jni_cid_BTAdapter,
106 METHODID_BT_REMOTE_DEVICE);
107 if (!jni_mid_getRemoteDevice)
109 OIC_LOG(ERROR, TAG, "jni_mid_getRemoteDevice is null");
113 jobject jni_obj_device = (*env)->CallObjectMethod(env, jni_obj_BTAdapter,
114 jni_mid_getRemoteDevice,
118 OIC_LOG(ERROR, TAG, "jni_obj_device is null");
122 OIC_LOG(DEBUG, TAG, "OUT - CAManagerGetRemoteDevice");
123 return jni_obj_device;
126 jstring CAManagerGetAddressFromGatt(JNIEnv *env, jobject gatt)
128 OIC_LOG(DEBUG, TAG, "IN - CAManagerGetAddressFromGatt");
130 VERIFY_NON_NULL_RET(env, TAG, "env is null", NULL);
131 VERIFY_NON_NULL_RET(gatt, TAG, "gatt is null", NULL);
133 jclass jni_cid_gattdevice_list = (*env)->FindClass(env, CLASSPATH_BT_GATT);
134 if (!jni_cid_gattdevice_list)
136 OIC_LOG(ERROR, TAG, "jni_cid_gattdevice_list is null");
140 jmethodID jni_mid_getDevice = (*env)->GetMethodID(env, jni_cid_gattdevice_list, "getDevice",
142 if (!jni_mid_getDevice)
144 OIC_LOG(ERROR, TAG, "jni_mid_getDevice is null");
148 jobject jni_obj_device = (*env)->CallObjectMethod(env, gatt, jni_mid_getDevice);
151 OIC_LOG(ERROR, TAG, "jni_obj_device is null");
155 jstring jni_address = CALEGetAddressFromBTDevice(env, jni_obj_device);
158 OIC_LOG(ERROR, TAG, "jni_address is null");
162 OIC_LOG(DEBUG, TAG, "OUT - CAManagerGetAddressFromGatt");
166 bool CAManagerIsDeviceBonded(JNIEnv *env, jobject btDevice)
168 OIC_LOG(DEBUG, TAG, "IN - CAManagerIsDeviceBonded");
170 VERIFY_NON_NULL(env, TAG, "env is null");
171 VERIFY_NON_NULL(btDevice, TAG, "btDevice is null");
173 jclass jni_cid_BTDevice = (*env)->FindClass(env, CLASSPATH_BT_DEVICE);
174 if (!jni_cid_BTDevice)
176 OIC_LOG(ERROR, TAG, "jni_cid_BTDevice is null");
180 jmethodID jni_mid_getBondState = (*env)->GetMethodID(env, jni_cid_BTDevice,
181 "getBondState", "()I");
182 if (!jni_mid_getBondState)
184 OIC_LOG(ERROR, TAG, "jni_mid_getBondState is null");
188 jint jni_bond_state = (*env)->CallIntMethod(env, btDevice, jni_mid_getBondState);
189 OIC_LOG_V(DEBUG, TAG, "bond state is %d", jni_bond_state);
191 // BOND_BONDED - Constant value : 12 (0x0000000c)
192 jfieldID id_bonded = (*env)->GetStaticFieldID(env, jni_cid_BTDevice,
196 OIC_LOG(ERROR, TAG, "id_bonded is null");
200 jint jni_bonded_const = (*env)->GetStaticIntField(env, jni_cid_BTDevice, id_bonded);
202 if (jni_bond_state == jni_bonded_const)
204 OIC_LOG(INFO, TAG, "it is not bonded to each other");
207 OIC_LOG(DEBUG, TAG, "OUT - CAManagerIsDeviceBonded");
211 bool CAManagerControlAdapter(JNIEnv *env, bool control_flag)
213 OIC_LOG(DEBUG, TAG, "IN - CAManagerControlAdapter");
215 VERIFY_NON_NULL_RET(env, TAG, "env", false);
217 jobject jni_obj_BTAdapter = CAManagerGetAdapterContext(env);
218 if (!jni_obj_BTAdapter)
220 OIC_LOG(ERROR, TAG, "jni_obj_BTAdapter is null");
224 jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADAPTER);
225 if (!jni_cid_BTAdapter)
227 OIC_LOG(ERROR, TAG, "jni_cid_BTAdapter: jni_cid_BTAdapter is null");
231 OIC_LOG_V(DEBUG, TAG, "change adapter : %d", control_flag);
232 jmethodID jni_mid_control = NULL;
236 jni_mid_control = (*env)->GetMethodID(env, jni_cid_BTAdapter, "enable", "()Z");
241 jni_mid_control = (*env)->GetMethodID(env, jni_cid_BTAdapter, "disable", "()Z");
244 if (!jni_mid_control)
246 OIC_LOG(ERROR, TAG, "jni_mid_control is null");
250 OIC_LOG(DEBUG, TAG, "CALL API - Adapter Will be Changed");
251 jboolean jni_res = (*env)->CallBooleanMethod(env, jni_obj_BTAdapter, jni_mid_control);
256 CAResult_t CAManagerReadRemoteRssi(JNIEnv *env, jobject bluetoothGatt)
258 OIC_LOG(DEBUG, TAG, "CAManagerReadRemoteRssi");
260 VERIFY_NON_NULL(env, TAG, "env is null");
261 VERIFY_NON_NULL(bluetoothGatt, TAG, "bluetoothGatt is null");
263 if (!CALEIsEnableBTAdapter(env))
265 OIC_LOG(INFO, TAG, "BT adapter is not enabled");
266 return CA_ADAPTER_NOT_ENABLED;
269 // get BluetoothGatt class
270 OIC_LOG(DEBUG, TAG, "get BluetoothGatt class");
271 jclass jni_cid_BluetoothGatt = (*env)->FindClass(env, CLASSPATH_BT_GATT);
272 if (!jni_cid_BluetoothGatt)
274 OIC_LOG(ERROR, TAG, "jni_cid_BluetoothGatt is null");
275 return CA_STATUS_FAILED;
278 OIC_LOG(DEBUG, TAG, "discovery gatt services method");
279 jmethodID jni_mid_readRemoteRssi = (*env)->GetMethodID(env, jni_cid_BluetoothGatt,
280 "readRemoteRssi", "()Z");
281 if (!jni_mid_readRemoteRssi)
283 OIC_LOG(ERROR, TAG, "jni_mid_readRemoteRssi is null");
284 return CA_STATUS_FAILED;
286 // call disconnect gatt method
287 OIC_LOG(DEBUG, TAG, "CALL API - request readremoteRssi");
288 jboolean ret = (*env)->CallBooleanMethod(env, bluetoothGatt, jni_mid_readRemoteRssi);
291 OIC_LOG(ERROR, TAG, "readremoteRssi has not been called");
292 return CA_STATUS_FAILED;
298 jobject CAManagerGetSharedPreference(JNIEnv *env, jobject context, jstring prefName)
300 VERIFY_NON_NULL_RET(env, TAG, "env", NULL);
301 VERIFY_NON_NULL_RET(context, TAG, "context", NULL);
302 VERIFY_NON_NULL_RET(prefName, TAG, "prefName", NULL);
304 jclass jni_cls_context = (*env)->FindClass(env, CLASSPATH_CONTEXT);
305 if (!jni_cls_context)
307 OIC_LOG(ERROR, TAG, "jni_cls_context is null");
311 // getSharedPreferences
312 jmethodID jni_mid_getPref = (*env)->GetMethodID(env, jni_cls_context, "getSharedPreferences",
313 "(Ljava/lang/String;I)"
314 "Landroid/content/SharedPreferences;");
315 if (!jni_mid_getPref)
317 OIC_LOG(ERROR, TAG, "jni_mid_getPref is null");
321 jobject jni_obj_sharedPref = (*env)->CallObjectMethod(env, context,
325 if (!jni_obj_sharedPref)
327 OIC_LOG(ERROR, TAG, "jni_obj_sharedPref is null");
331 return jni_obj_sharedPref;
334 jobject CAManagerGetPrefEditObject(JNIEnv *env, jobject context)
336 OIC_LOG(DEBUG, TAG, "IN-CAManagerGetPrefEditObject");
337 VERIFY_NON_NULL_RET(env, TAG, "env", NULL);
338 VERIFY_NON_NULL_RET(context, TAG, "context", NULL);
340 jstring jni_str_prefName = (*env)->NewStringUTF(env, PREF_NAME_CONNECTED_DEVICE);
341 if (!jni_str_prefName)
343 OIC_LOG(ERROR, TAG, "jni_str_prefName is null");
347 jstring jni_str_prefKey = (*env)->NewStringUTF(env, PREF_KEY_CONNECTED_DEVICE);
348 if (!jni_str_prefKey)
350 OIC_LOG(ERROR, TAG, "jni_str_prefKey is null");
354 // get SharedPreference
355 jobject jni_obj_pref = CAManagerGetSharedPreference(env, context, jni_str_prefName);
358 OIC_LOG(ERROR, TAG, "jni_obj_pref is null");
363 jobject jni_cls_pref = (*env)->FindClass(env, CLASSPATH_CONTENT_PREF);
366 OIC_LOG(ERROR, TAG, "jni_cls_pref is null");
370 jmethodID jni_mid_prefEdit = (*env)->GetMethodID(env, jni_cls_pref, "edit",
371 "()Landroid/content/SharedPreferences$Editor;");
372 if (!jni_mid_prefEdit)
374 OIC_LOG(ERROR, TAG, "jni_mid_prefEdit is null");
378 jobject jni_obj_prefEdit = (*env)->CallObjectMethod(env, jni_obj_pref, jni_mid_prefEdit);
379 if (!jni_obj_prefEdit)
381 OIC_LOG(ERROR, TAG, "jni_obj_prefEdit is null");
385 OIC_LOG(DEBUG, TAG, "OUT-CAManagerGetPrefEditObject");
386 return jni_obj_prefEdit;
389 bool CAManagerUpdatePrefStringSet(JNIEnv *env, jobject context, jobject set)
391 OIC_LOG(DEBUG, TAG, "IN-CAManagerUpdatePrefStringSet");
393 VERIFY_NON_NULL_RET(env, TAG, "env", false);
394 VERIFY_NON_NULL_RET(context, TAG, "context", false);
395 VERIFY_NON_NULL_RET(set, TAG, "set", false);
397 jstring jni_str_prefKey = (*env)->NewStringUTF(env, PREF_KEY_CONNECTED_DEVICE);
398 if (!jni_str_prefKey)
400 OIC_LOG(ERROR, TAG, "jni_str_prefKey is null");
404 jobject jni_obj_prefEdit = CAManagerGetPrefEditObject(env, context);
405 if (!jni_obj_prefEdit)
407 OIC_LOG(ERROR, TAG, "jni_obj_prefEdit is null");
412 jobject jni_cls_edit = (*env)->FindClass(env, CLASSPATH_CONTENT_PREF_EDITOR);
415 OIC_LOG(ERROR, TAG, "jni_cls_edit is null");
419 // get putString method interface
420 jmethodID jni_mid_PrefPutStringSet = (*env)->GetMethodID(env, jni_cls_edit, "putStringSet",
421 "(Ljava/lang/String;Ljava/util/Set;)"
422 "Landroid/content/SharedPreferences"
424 if (!jni_mid_PrefPutStringSet)
426 OIC_LOG(ERROR, TAG, "jni_mid_PrefPutStringSet is null");
430 jobject gSetString = (jobject)(*env)->NewGlobalRef(env, set);
433 OIC_LOG(ERROR, TAG, "gAddress is null");
437 OIC_LOG(DEBUG, TAG, "CALL API - request putString for SharedPreferences.Editor");
438 (*env)->CallObjectMethod(env, jni_obj_prefEdit, jni_mid_PrefPutStringSet,
439 jni_str_prefKey, gSetString);
441 // get commit method interface
442 jmethodID jni_mid_PrefCommit = (*env)->GetMethodID(env, jni_cls_edit, "commit",
444 if (!jni_mid_PrefCommit)
446 OIC_LOG(ERROR, TAG, "jni_mid_PrefCommit is null");
450 jboolean res = (*env)->CallBooleanMethod(env, jni_obj_prefEdit, jni_mid_PrefCommit);
452 OIC_LOG(DEBUG, TAG, "OUT-CAManagerUpdatePrefStringSet");
456 jobject CAManagerGetPrefStringSet(JNIEnv *env, jobject context)
458 OIC_LOG(DEBUG, TAG, "CAManagerGetPrefStringSet");
460 VERIFY_NON_NULL_RET(env, TAG, "env", NULL);
461 VERIFY_NON_NULL_RET(context, TAG, "context", NULL);
463 jstring jni_str_prefName = (*env)->NewStringUTF(env, PREF_NAME_CONNECTED_DEVICE);
464 if (!jni_str_prefName)
466 OIC_LOG(ERROR, TAG, "jni_str_prefName is null");
470 jstring jni_str_prefKey = (*env)->NewStringUTF(env, PREF_KEY_CONNECTED_DEVICE);
471 if (!jni_str_prefKey)
473 OIC_LOG(ERROR, TAG, "jni_str_prefKey is null");
477 // get SharedPreference
478 jobject jni_obj_pref = CAManagerGetSharedPreference(env, context, jni_str_prefName);
481 OIC_LOG(ERROR, TAG, "jni_obj_pref is null");
485 // contains(String key)
486 jobject jni_cls_pref = (*env)->FindClass(env, CLASSPATH_CONTENT_PREF);
489 OIC_LOG(ERROR, TAG, "jni_cls_pref is null");
493 jmethodID jni_mid_getStringSet = (*env)->GetMethodID(env, jni_cls_pref, "getStringSet",
494 "(Ljava/lang/String;Ljava/util/Set;)"
496 if (!jni_mid_getStringSet)
498 OIC_LOG(ERROR, TAG, "jni_mid_getStringSet is null");
502 jobject jni_defSet = CAManagerCreateSetString(env);
505 OIC_LOG(ERROR, TAG, "jni_defSet is null");
509 jobject value = (*env)->CallObjectMethod(env, jni_obj_pref,
510 jni_mid_getStringSet,
517 bool CAManagerContainsPrefStringSet(JNIEnv *env, jobject context)
519 OIC_LOG(DEBUG, TAG, "CAManagerContainsPrefStringSet");
521 VERIFY_NON_NULL_RET(env, TAG, "env", false);
522 VERIFY_NON_NULL_RET(context, TAG, "context", false);
524 jstring jni_str_prefName = (*env)->NewStringUTF(env, PREF_NAME_CONNECTED_DEVICE);
525 if (!jni_str_prefName)
527 OIC_LOG(ERROR, TAG, "jni_str_prefName is null");
531 jstring jni_str_prefKey = (*env)->NewStringUTF(env, PREF_KEY_CONNECTED_DEVICE);
532 if (!jni_str_prefKey)
534 OIC_LOG(ERROR, TAG, "jni_str_prefKey is null");
538 // get SharedPreference
539 jobject jni_obj_pref = CAManagerGetSharedPreference(env, context, jni_str_prefName);
542 OIC_LOG(ERROR, TAG, "jni_obj_pref is null");
546 // contains(String key)
547 jobject jni_cls_pref = (*env)->FindClass(env, CLASSPATH_CONTENT_PREF);
550 OIC_LOG(ERROR, TAG, "jni_cls_pref is null");
554 jmethodID jni_mid_prefContains = (*env)->GetMethodID(env, jni_cls_pref, "contains",
555 METHODID_BOOLEAN_RET_STRING_PARAM);
556 if (!jni_mid_prefContains)
558 OIC_LOG(ERROR, TAG, "jni_mid_prefContains is null");
562 jboolean res = (*env)->CallBooleanMethod(env, jni_obj_pref,
563 jni_mid_prefContains,
566 OIC_LOG_V(DEBUG, TAG, "Preference - contains (%d)", res);
570 bool CAManagerRemovePrefStringSet(JNIEnv *env, jobject context)
572 OIC_LOG(DEBUG, TAG, "CAManagerRemovePrefStringSet");
574 VERIFY_NON_NULL_RET(env, TAG, "env", false);
575 VERIFY_NON_NULL_RET(context, TAG, "context", false);
577 jstring jni_str_prefKey = (*env)->NewStringUTF(env, PREF_KEY_CONNECTED_DEVICE);
578 if (!jni_str_prefKey)
580 OIC_LOG(ERROR, TAG, "jni_str_prefKey is null");
584 jobject jni_obj_prefEdit = CAManagerGetPrefEditObject(env, context);
585 if (!jni_obj_prefEdit)
587 OIC_LOG(ERROR, TAG, "jni_obj_prefEdit is null");
592 jobject jni_cls_edit = (*env)->FindClass(env, CLASSPATH_CONTENT_PREF_EDITOR);
595 OIC_LOG(ERROR, TAG, "jni_cls_edit is null");
599 // get remove method interface
600 jmethodID jni_mid_PrefRemove = (*env)->GetMethodID(env, jni_cls_edit, "remove",
601 "(Ljava/lang/String;)"
602 "Landroid/content/SharedPreferences"
604 if (!jni_mid_PrefRemove)
606 OIC_LOG(ERROR, TAG, "jni_mid_PrefRemove is null");
610 OIC_LOG(DEBUG, TAG, "CALL API - request remove for SharedPreferences.Editor");
611 (*env)->CallObjectMethod(env, jni_obj_prefEdit, jni_mid_PrefRemove, jni_str_prefKey);
613 // get commit method interface
614 jmethodID jni_mid_PrefCommit = (*env)->GetMethodID(env, jni_cls_edit, "commit",
616 if (!jni_mid_PrefCommit)
618 OIC_LOG(ERROR, TAG, "jni_mid_PrefCommit is null");
622 jboolean res = (*env)->CallBooleanMethod(env, jni_obj_prefEdit, jni_mid_PrefCommit);
624 OIC_LOG(DEBUG, TAG, "OUT-CAManagerAddConnectedDeviceAddress");
628 bool CAManagerAddConnectedDeviceAddress(JNIEnv *env, jobject context,
629 jstring address, jobject set)
631 OIC_LOG(DEBUG, TAG, "IN-CAManagerAddConnectedDeviceAddress");
633 VERIFY_NON_NULL_RET(env, TAG, "env", false);
634 VERIFY_NON_NULL_RET(context, TAG, "context", false);
635 VERIFY_NON_NULL_RET(address, TAG, "address", false);
636 VERIFY_NON_NULL_RET(set, TAG, "set", false);
638 if (CAManagerCallFuncSetString(env, address, set, CM_CONTAINS))
640 OIC_LOG(DEBUG, TAG, "it's already done");
644 if (!CAManagerCallFuncSetString(env, address, set, CM_ADD))
646 OIC_LOG(ERROR, TAG, "CAManagerAddSetString has failed");
650 return CAManagerUpdatePrefStringSet(env, context, set);
653 bool CAManagerIsConnectedDeviceAddress(JNIEnv *env, jobject context,
654 jstring address, jobject set)
656 OIC_LOG(DEBUG, TAG, "CAManagerIsConnectedDeviceAddress");
657 VERIFY_NON_NULL_RET(env, TAG, "env", false);
658 VERIFY_NON_NULL_RET(context, TAG, "context", false);
660 return CAManagerCallFuncSetString(env, address, set, CM_CONTAINS);
663 jobject CAManagerGetConnectedDeviceAddress(JNIEnv *env, jobject context)
665 OIC_LOG(DEBUG, TAG, "CAManagerGetConnectedDeviceAddress");
667 if (!CAManagerContainsPrefStringSet(env, context))
669 OIC_LOG(DEBUG, TAG, "there is no set data");
673 return CAManagerGetPrefStringSet(env, context);
676 bool CAManagerRemoveConnectedDeviceAddress(JNIEnv *env, jobject context,
677 jstring address, jobject set)
679 OIC_LOG(DEBUG, TAG, "IN-CAManagerRemoveConnectedDeviceAddress");
681 VERIFY_NON_NULL_RET(env, TAG, "env", false);
682 VERIFY_NON_NULL_RET(context, TAG, "context", false);
683 VERIFY_NON_NULL_RET(address, TAG, "address", false);
684 VERIFY_NON_NULL_RET(set, TAG, "set", false);
686 if (!CAManagerCallFuncSetString(env, address, set, CM_CONTAINS))
688 OIC_LOG(DEBUG, TAG, "it's already done");
692 if (!CAManagerCallFuncSetString(env, address, set, CM_REMOVE))
694 OIC_LOG(ERROR, TAG, "CAManagerAddSetString has failed");
698 return CAManagerUpdatePrefStringSet(env, context, set);
701 jboolean CAManagerCheckBTAddress(JNIEnv *env, jstring address)
703 OIC_LOG(DEBUG, TAG, "CAManagerCheckBTAddress");
705 VERIFY_NON_NULL_RET(env, TAG, "env is null", JNI_FALSE);
706 VERIFY_NON_NULL_RET(address, TAG, "address is null", JNI_FALSE);
708 jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADAPTER);
709 if (!jni_cid_BTAdapter)
711 OIC_LOG(ERROR, TAG, "jni_cid_BTAdapter is null");
715 // get remote bt adapter method
716 jmethodID jni_mid_checkBTAddress =
717 (*env)->GetStaticMethodID(env, jni_cid_BTAdapter,
718 "checkBluetoothAddress",
719 METHODID_BOOLEAN_RET_STRING_PARAM);
720 if (!jni_mid_checkBTAddress)
722 OIC_LOG(ERROR, TAG, "jni_mid_checkBTAddress is null");
726 jboolean jni_obj_isAddress = (*env)->CallStaticBooleanMethod(env, jni_cid_BTAdapter,
727 jni_mid_checkBTAddress,
729 return jni_obj_isAddress;
732 jobject CAManagerCreateSetString(JNIEnv *env)
734 OIC_LOG(DEBUG, TAG, "CAManagerCallFuncSetString");
736 VERIFY_NON_NULL_RET(env, TAG, "env", NULL);
738 jclass jclazzMap = (*env)->FindClass(env, "java/util/HashSet" );
741 OIC_LOG(ERROR, TAG, "jclazzMap is null");
745 jmethodID jinitMap = (*env)->GetMethodID(env, jclazzMap, "<init>", "()V");
748 OIC_LOG(ERROR, TAG, "jinitMap is null");
752 jobject jpropertyMap = (*env)->NewObject(env, jclazzMap, jinitMap);
755 OIC_LOG(ERROR, TAG, "jpropertyMap is null");
762 bool CAManagerCallFuncSetString(JNIEnv *env, jstring address, jobject set,
763 CASetMethod_t method_type)
765 OIC_LOG(DEBUG, TAG, "CAManagerCallFuncSetString");
766 VERIFY_NON_NULL_RET(env, TAG, "env", false);
767 VERIFY_NON_NULL_RET(address, TAG, "address", false);
768 VERIFY_NON_NULL_RET(set, TAG, "set", false);
770 jclass jni_cls_set = (*env)->FindClass(env, "java/util/HashSet");
773 OIC_LOG(ERROR, TAG, "jni_cls_set is null");
777 jmethodID jni_mid_setMethod = NULL;
781 OIC_LOG(DEBUG, TAG, "java/util/HashSet.contains");
782 jni_mid_setMethod = (*env)->GetMethodID(env, jni_cls_set, "contains",
783 "(Ljava/lang/Object;)Z");
786 OIC_LOG(DEBUG, TAG, "java/util/HashSet.add");
787 jni_mid_setMethod = (*env)->GetMethodID(env, jni_cls_set, "add",
788 "(Ljava/lang/Object;)Z");
791 OIC_LOG(DEBUG, TAG, "java/util/HashSet.remove");
792 jni_mid_setMethod = (*env)->GetMethodID(env, jni_cls_set, "remove",
793 "(Ljava/lang/Object;)Z");
798 if (!jni_mid_setMethod)
800 OIC_LOG(ERROR, TAG, "jni_mid_setMethod is null");
804 jboolean res = (*env)->CallBooleanMethod(env, set, jni_mid_setMethod, address);
805 OIC_LOG_V(DEBUG, TAG, "method return result : %d", res);