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