clean up getting methodID from jni
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_le_adapter / android / caleutils.h
1 /* ****************************************************************
2  *
3  * Copyright 2014 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  ******************************************************************/
20
21 /**
22  * @file
23  * This file contains the APIs for BT LE communications.
24  */
25 #ifndef CA_LE_UTILS_H_
26 #define CA_LE_UTILS_H_
27
28 #include "cacommon.h"
29 #include "cathreadpool.h"
30 #include "cagattservice.h"
31 #include "uarraylist.h"
32 #include "jni.h"
33
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #endif
38
39 /* Service UUID */
40 static const char OIC_GATT_SERVICE_UUID[] = CA_GATT_SERVICE_UUID;
41 static const char OIC_GATT_CHARACTERISTIC_REQUEST_UUID[] = CA_GATT_REQUEST_CHRC_UUID;
42 static const char OIC_GATT_CHARACTERISTIC_RESPONSE_UUID[] = CA_GATT_RESPONSE_CHRC_UUID;
43 static const char OIC_GATT_CHARACTERISTIC_CONFIG_UUID[] = "00002902-0000-1000-8000-00805f9b34fb";
44
45 static const char CLASSPATH_BT_PROFILE[] = "android/bluetooth/BluetoothProfile";
46 static const char CLASSPATH_BT_GATT[] = "android/bluetooth/BluetoothGatt";
47 static const char CLASSPATH_BT_ADAPTER[] = "android/bluetooth/BluetoothAdapter";
48 static const char CLASSPATH_BT_DEVICE[] = "android/bluetooth/BluetoothDevice";
49 static const char CLASSPATH_BT_UUID[] = "java/util/UUID";
50
51
52 static const char METHODID_OBJECTNONPARAM[] = "()Landroid/bluetooth/BluetoothAdapter;";
53 static const char METHODID_BT_DEVICE[] = "()Landroid/bluetooth/BluetoothDevice;";
54 static const char METHODID_BT_REMOTE_DEVICE[] = "(Ljava/lang/String;)Landroid/bluetooth/BluetoothDevice;";
55
56 static const jint GATT_PROFILE = 7;
57 static const jint GATT_SUCCESS = 0;
58
59 static const jint BOND_BONDED = 12;
60 static const jint BOND_BONDING = 11;
61 static const jint BOND_NONE = 10;
62
63 static const jint STATE_CONNECTED = 2;
64 static const jint STATE_DISCONNECTED = 0;
65
66 /**
67  * get method ID for method Name and class
68  * @param[in]   env              JNI interface pointer.
69  * @param[in]   className        android class.
70  * @param[in]   methodName       android method name.
71  * @param[in]   methodFormat     method type of methodName.
72  * @return  jmethodID of the method.
73  */
74 jmethodID CALEGetJNIMethodID(JNIEnv *env, const char* className,
75                              const char* methodName,
76                              const char* methodFormat);
77
78 /**
79  * get uuid(jni object) from uuid(character).
80  * @param[in]   env              JNI interface pointer.
81  * @param[in]   uuid             uuid(character).
82  * @return  uuid(jni object).
83  */
84 jobject CALEGetUuidFromString(JNIEnv *env, const char* uuid);
85
86 /**
87  * get parcel uuid object.
88  * @param[in]   env              JNI interface pointer.
89  * @param[in]   uuid             uuid (jni object).
90  * @return  parcel uuid object.
91  */
92 jobject CALEGetParcelUuid(JNIEnv *env, jobject uuid);
93
94 /**
95  * get address from a local device.
96  * @param[in]   env              JNI interface pointer.
97  * @return  local address.
98  */
99 jstring CALEGetLocalDeviceAddress(JNIEnv *env);
100
101 /**
102  * get bonded list.
103  * @param[in]   env              JNI interface pointer.
104  * @return  bonded list.
105  */
106 jobjectArray CALEGetBondedDevices(JNIEnv *env);
107
108 /**
109  * get constants information of bluetooth state-on.
110  * @param[in]   env              JNI interface pointer.
111  * @return  constants information of bluetooth state-on.
112  */
113 jint CALEGetBTStateOnInfo(JNIEnv *env);
114
115 /**
116  * check this device can be supported as BLE client or server.
117  * @param[in]   env              JNI interface pointer.
118  * @param[in]   level            Android API Level to support.
119  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
120  */
121 CAResult_t CALECheckPlatformVersion(JNIEnv *env, uint16_t level);
122
123 /**
124  * get constants information of android.os.Build.VERSION.SDK_INT.
125  * @param[in]   env              JNI interface pointer.
126  * @return  constants information of android.os.Build.VERSION.SDK_INT.
127  */
128 jint CALEGetBuildVersion(JNIEnv *env);
129
130 /**
131  * get constants information of android.os.Build.VERSION_CODES.[VersionName].
132  * @param[in]   env              JNI interface pointer.
133  * @param[in]   versionName      version name (.., KITKAT, LOLLIPOP, ..).
134  * @return  constants information of android.os.Build.VERSION_CODES.[VersionName].
135  */
136 jint CALEGetBuildVersionCodeForName(JNIEnv *env, const char* versionName);
137
138 /**
139  * get bluetooth adapter state information.
140  * @param[in]   env              JNI interface pointer.
141  * @return  JNI_TRUE if the local adapter is turned on.
142  */
143 jboolean CALEIsEnableBTAdapter(JNIEnv *env);
144
145 /**
146  * get address from remote device.
147  * @param[in]   env              JNI interface pointer.
148  * @param[in]   bluetoothDevice  bluetooth device object.
149  * @return  remote address.
150  */
151 jstring CALEGetAddressFromBTDevice(JNIEnv *env, jobject bluetoothDevice);
152
153 /**
154  * get value from selected constants.
155  * @param[in]   env              JNI interface pointer.
156  * @param[in]   classType        class type
157  * @param[in]   name             constants name to get.
158  * @return  remote address.
159  */
160 jint CALEGetConstantsValue(JNIEnv *env, const char* classType, const char* name);
161
162 /**
163  * get bluetooth device object from bluetooth adapter.
164  * @param[in]   env                   JNI interface pointer.
165  * @param[in]   address               bluetooth address.
166  * @return  bluetooth device object.
167  */
168 jobject CALEGetRemoteDevice(JNIEnv *env, jstring address);
169
170 #ifdef __cplusplus
171 } /* extern "C" */
172 #endif
173
174 #endif /* CA_LE_UTILS_H_ */