blob: a753b25dc54c1274a90dc3894a891280ee478c36 [file] [log] [blame]
Nitin Aroraaabc4272013-10-08 16:55:47 -07001/*
2 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#define LOG_TAG "QBluetoothAdapterServiceJni"
31
32#define BD_ADDR_LEN 6
33
34#include "com_android_bluetooth.h"
35#include "utils/Log.h"
36#include "utils/misc.h"
37#include "cutils/properties.h"
38#include "android_runtime/AndroidRuntime.h"
39
40#include <string.h>
41#include <pthread.h>
42
43#include <sys/stat.h>
44#include <fcntl.h>
45
46
47namespace android {
Kiran Kelagerid81255d2013-12-09 17:12:30 -080048static jmethodID method_advEnableCallback;
Nitin Aroraaabc4272013-10-08 16:55:47 -070049static jmethodID method_onLeExtendedScanResultCallback;
50static jmethodID method_onLeLppWriteRssiThreshold;
51static jmethodID method_onLeLppReadRssiThreshold;
52static jmethodID method_onLeLppEnableRssiMonitor;
53static jmethodID method_onLeLppRssiThresholdEvent;
54
Kiran Kelagerid81255d2013-12-09 17:12:30 -080055static const bt_interface_t *qBluetoothInterface = NULL;
56static JNIEnv *qcallbackEnv = NULL;
57static jobject qJniCallbacksObj=NULL;
58static jfieldID qJniCallbacksField;
Nitin Aroraaabc4272013-10-08 16:55:47 -070059
60static void set_uuid(uint8_t* uuid, jlong uuid_msb, jlong uuid_lsb)
61{
62 for (int i = 0; i != 8; ++i)
63 {
64 uuid[i] = (uuid_lsb >> (8 * i)) & 0xFF;
65 uuid[i + 8] = (uuid_msb >> (8 * i)) & 0xFF;
66 }
67}
68
69static void bd_addr_str_to_addr(const char* str, uint8_t *bd_addr)
70{
71 int i;
72 char c;
73
74 c = *str++;
75 for (i = 0; i < BD_ADDR_LEN; i++)
76 {
77 if (c >= '0' && c <= '9')
78 bd_addr[i] = c - '0';
79 else if (c >= 'a' && c <= 'z')
80 bd_addr[i] = c - 'a' + 10;
81 else // (c >= 'A' && c <= 'Z')
82 bd_addr[i] = c - 'A' + 10;
83
84 c = *str++;
85 if (c != ':')
86 {
87 bd_addr[i] <<= 4;
88 if (c >= '0' && c <= '9')
89 bd_addr[i] |= c - '0';
90 else if (c >= 'a' && c <= 'z')
91 bd_addr[i] |= c - 'a' + 10;
92 else // (c >= 'A' && c <= 'Z')
93 bd_addr[i] |= c - 'A' + 10;
94
95 c = *str++;
96 }
97
98 c = *str++;
99 }
100}
101
102static void jstr2bdaddr(JNIEnv* env, bt_bdaddr_t *bda, jstring address)
103{
104 const char* c_bda = env->GetStringUTFChars(address, NULL);
105 if (c_bda != NULL && bda != NULL && strlen(c_bda) == 17)
106 {
107 bd_addr_str_to_addr(c_bda, bda->address);
108 env->ReleaseStringUTFChars(address, c_bda);
109 }
110}
111
112static bool checkCallbackThread() {
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800113 qcallbackEnv = getCallbackEnv();
Nitin Aroraaabc4272013-10-08 16:55:47 -0700114
115 JNIEnv* env = AndroidRuntime::getJNIEnv();
116 if(env==NULL)
117 ALOGE("checkCallbackThread env is NULL");
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800118 if(qcallbackEnv==NULL)
119 ALOGE("checkCallbackThread qcallbackEnv is NULL");
Nitin Aroraaabc4272013-10-08 16:55:47 -0700120
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800121 if(env!=qcallbackEnv)
122 ALOGE("env and qcallbackEnv dont match");
123 if (qcallbackEnv != env || qcallbackEnv == NULL) return false;
Nitin Aroraaabc4272013-10-08 16:55:47 -0700124 return true;
125}
126
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800127static void le_adv_enable_callbacks(uint8_t enable, uint8_t advType) {
128 jbyteArray addr;
129 if (!checkCallbackThread()) {
130 ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__);
131 return;
132 }
133
134 ALOGV("%s: adv enable:%d ", __FUNCTION__, enable);
135
136 qcallbackEnv->CallVoidMethod(qJniCallbacksObj, method_advEnableCallback,
137 (jint)enable, (jint)advType);
138
139 checkAndClearExceptionFromCallback(qcallbackEnv, __FUNCTION__);
140}
Nitin Aroraaabc4272013-10-08 16:55:47 -0700141static void le_extended_scan_result_callbacks(bt_bdaddr_t* bda, int rssi, uint8_t* adv_data)
142{
143 char c_address[32];
144 if (!checkCallbackThread()) {
145 ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__);
146 }
147
148 snprintf(c_address, sizeof(c_address),"%02X:%02X:%02X:%02X:%02X:%02X",
149 bda->address[0], bda->address[1], bda->address[2],
150 bda->address[3], bda->address[4], bda->address[5]);
151
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800152 jstring address = qcallbackEnv->NewStringUTF(c_address);
153 jbyteArray jb = qcallbackEnv->NewByteArray(62);
154 qcallbackEnv->SetByteArrayRegion(jb, 0, 62, (jbyte *) adv_data);
Nitin Aroraaabc4272013-10-08 16:55:47 -0700155
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800156 qcallbackEnv->CallVoidMethod(qJniCallbacksObj, method_onLeExtendedScanResultCallback,
Nitin Aroraaabc4272013-10-08 16:55:47 -0700157 address, rssi, jb);
158
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800159 qcallbackEnv->DeleteLocalRef(address);
160 qcallbackEnv->DeleteLocalRef(jb);
Nitin Aroraaabc4272013-10-08 16:55:47 -0700161
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800162 checkAndClearExceptionFromCallback(qcallbackEnv, __FUNCTION__);
Nitin Aroraaabc4272013-10-08 16:55:47 -0700163}
164
165void le_lpp_write_rssi_thresh_callbacks(bt_bdaddr_t *bda, int status)
166{
167 char c_address[32] = {0};
168 if (!checkCallbackThread()) {
169 ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__);
170 return;
171 }
172
173 snprintf(c_address, sizeof(c_address),"%02X:%02X:%02X:%02X:%02X:%02X",
174 bda->address[0], bda->address[1], bda->address[2],
175 bda->address[3], bda->address[4], bda->address[5]);
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800176 jstring address = qcallbackEnv->NewStringUTF(c_address);
177 qcallbackEnv->CallVoidMethod(qJniCallbacksObj, method_onLeLppWriteRssiThreshold,
Nitin Aroraaabc4272013-10-08 16:55:47 -0700178 address, status);
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800179 qcallbackEnv->DeleteLocalRef(address);
180 checkAndClearExceptionFromCallback(qcallbackEnv, __FUNCTION__);
Nitin Aroraaabc4272013-10-08 16:55:47 -0700181}
182
183void le_lpp_read_rssi_thresh_callbacks(bt_bdaddr_t *bda, int low, int upper,
184 int alert, int status)
185{
186 char c_address[32] = {0};
187 if (!checkCallbackThread()) {
188 ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__);
189 return;
190 }
191 snprintf(c_address, sizeof(c_address),"%02X:%02X:%02X:%02X:%02X:%02X",
192 bda->address[0], bda->address[1], bda->address[2],
193 bda->address[3], bda->address[4], bda->address[5]);
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800194 jstring address = qcallbackEnv->NewStringUTF(c_address);
195 qcallbackEnv->CallVoidMethod(qJniCallbacksObj, method_onLeLppReadRssiThreshold,
Nitin Aroraaabc4272013-10-08 16:55:47 -0700196 address, low, upper, alert, status);
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800197 qcallbackEnv->DeleteLocalRef(address);
198 checkAndClearExceptionFromCallback(qcallbackEnv, __FUNCTION__);
Nitin Aroraaabc4272013-10-08 16:55:47 -0700199}
200
201void le_lpp_enable_rssi_monitor_callbacks(bt_bdaddr_t *bda,
202 int enable, int status)
203{
204 char c_address[32] = {0};
205 if (!checkCallbackThread()) {
206 ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__);
207 return;
208 }
209 snprintf(c_address, sizeof(c_address),"%02X:%02X:%02X:%02X:%02X:%02X",
210 bda->address[0], bda->address[1], bda->address[2],
211 bda->address[3], bda->address[4], bda->address[5]);
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800212 jstring address = qcallbackEnv->NewStringUTF(c_address);
213 qcallbackEnv->CallVoidMethod(qJniCallbacksObj, method_onLeLppEnableRssiMonitor,
Nitin Aroraaabc4272013-10-08 16:55:47 -0700214 address, enable, status);
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800215 qcallbackEnv->DeleteLocalRef(address);
216 checkAndClearExceptionFromCallback(qcallbackEnv, __FUNCTION__);
Nitin Aroraaabc4272013-10-08 16:55:47 -0700217}
218
219void le_lpp_rssi_threshold_evt_callbacks(bt_bdaddr_t *bda,
220 int evt_type, int rssi)
221{
222 char c_address[32] = {0};
223 if (!checkCallbackThread()) {
224 ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__);
225 return;
226 }
227 snprintf(c_address, sizeof(c_address),"%02X:%02X:%02X:%02X:%02X:%02X",
228 bda->address[0], bda->address[1], bda->address[2],
229 bda->address[3], bda->address[4], bda->address[5]);
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800230 jstring address = qcallbackEnv->NewStringUTF(c_address);
231 qcallbackEnv->CallVoidMethod(qJniCallbacksObj, method_onLeLppRssiThresholdEvent,
Nitin Aroraaabc4272013-10-08 16:55:47 -0700232 address, evt_type, rssi);
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800233 qcallbackEnv->DeleteLocalRef(address);
234 checkAndClearExceptionFromCallback(qcallbackEnv, __FUNCTION__);
Nitin Aroraaabc4272013-10-08 16:55:47 -0700235}
236
237bt_callbacks_t sQBluetoothCallbacks = {
238 sizeof(sQBluetoothCallbacks),
239 NULL,
240 NULL,
241 NULL,
242 NULL,
243 NULL,
244 NULL,
245 NULL,
246 NULL,
247 NULL,
248 NULL,
249 NULL,
250 NULL,
Bhasker Netie347e592013-11-08 16:49:22 +0530251 NULL,
Srinu Jellaca690402014-01-10 19:28:39 +0530252 NULL,
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800253 le_adv_enable_callbacks,
Nitin Aroraaabc4272013-10-08 16:55:47 -0700254 le_extended_scan_result_callbacks,
255 le_lpp_write_rssi_thresh_callbacks,
256 le_lpp_read_rssi_thresh_callbacks,
257 le_lpp_enable_rssi_monitor_callbacks,
258 le_lpp_rssi_threshold_evt_callbacks,
259};
260static void classInitNative(JNIEnv* env, jclass clazz) {
261 int err;
262 hw_module_t* module;
263
264 ALOGV("%s:",__FUNCTION__);
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800265 if((qBluetoothInterface=getBluetoothInterface())==NULL){
Nitin Aroraaabc4272013-10-08 16:55:47 -0700266 ALOGE("Bluetooth module is not loaded");
267 return;
268 }
269
270 jclass jniCallbackClass =
271 env->FindClass("com/android/bluetooth/btservice/QJniCallbacks");
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800272 qJniCallbacksField = env->GetFieldID(clazz, "mJniCallbacks",
Nitin Aroraaabc4272013-10-08 16:55:47 -0700273 "Lcom/android/bluetooth/btservice/QJniCallbacks;");
274
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800275 method_advEnableCallback = env->GetMethodID(jniCallbackClass, "advEnableCallback", "(II)V");
276 method_onLeExtendedScanResultCallback = env->GetMethodID(jniCallbackClass, "onLeExtendedScanResult", "(Ljava/lang/String;I[B)V");
Nitin Aroraaabc4272013-10-08 16:55:47 -0700277 method_onLeLppWriteRssiThreshold = env->GetMethodID(jniCallbackClass, "onLeLppWriteRssiThreshold", "(Ljava/lang/String;I)V");
278 method_onLeLppReadRssiThreshold = env->GetMethodID(jniCallbackClass, "onLeLppReadRssiThreshold", "(Ljava/lang/String;IIII)V");
279 method_onLeLppEnableRssiMonitor = env->GetMethodID(jniCallbackClass, "onLeLppEnableRssiMonitor", "(Ljava/lang/String;II)V");
280 method_onLeLppRssiThresholdEvent = env->GetMethodID(jniCallbackClass, "onLeLppRssiThresholdEvent", "(Ljava/lang/String;II)V");
281
282}
283
284static bool initNative(JNIEnv* env, jobject obj) {
285 ALOGV("%s:",__FUNCTION__);
286
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800287 if (qBluetoothInterface) {
288 qJniCallbacksObj = env->NewGlobalRef(env->GetObjectField(obj, qJniCallbacksField));
289 int ret = qBluetoothInterface->initq(&sQBluetoothCallbacks);
Nitin Aroraaabc4272013-10-08 16:55:47 -0700290 if (ret != BT_STATUS_SUCCESS) {
291 ALOGE("Error while setting the callbacks \n");
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800292 qBluetoothInterface = NULL;
Nitin Aroraaabc4272013-10-08 16:55:47 -0700293 return JNI_FALSE;
294 }
295 return JNI_TRUE;
296 }
297 return JNI_FALSE;
298}
299
300static bool cleanupNative(JNIEnv *env, jobject obj) {
301 ALOGV("%s:",__FUNCTION__);
302
303 jboolean result = JNI_FALSE;
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800304 if (!qBluetoothInterface) return result;
Nitin Aroraaabc4272013-10-08 16:55:47 -0700305
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800306 if(qJniCallbacksObj!=NULL){
307 env->DeleteGlobalRef(qJniCallbacksObj);
308 qJniCallbacksObj=NULL;
Nitin Aroraaabc4272013-10-08 16:55:47 -0700309 }
310 return JNI_TRUE;
311}
312
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800313static jboolean setLEAdvModeNative(JNIEnv *env, jobject obj, jint type, jbyteArray value) {
314 ALOGV("%s:",__FUNCTION__);
315
316 jbyte *val;
317 jboolean result = JNI_FALSE;
318 if (!qBluetoothInterface) return result;
319
320 val = env->GetByteArrayElements(value, NULL);
321 bt_property_t prop;
322 prop.type = (bt_property_type_t) type;
323 prop.len = env->GetArrayLength(value);
324 prop.val = val;
325
326 int ret = qBluetoothInterface->set_adapter_property(&prop);
327 env->ReleaseByteArrayElements(value, val, 0);
328 result = (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
329
330 return result;
331}
332
333static jboolean setLEadvMaskNative(JNIEnv *env, jobject obj,jint mask){
334 ALOGV("%s:",__FUNCTION__);
335 jboolean result = JNI_FALSE;
336 if (!qBluetoothInterface) return result;
337 int ret = qBluetoothInterface->le_set_adv_data_mask(mask);
338
339 result = (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
340 return result;
341}
342
343static jboolean setLEscanRespMaskNative(JNIEnv *env, jobject obj,jint mask){
344 ALOGV("%s:",__FUNCTION__);
345 jboolean result = JNI_FALSE;
346 if (!qBluetoothInterface) return result;
347 int ret = qBluetoothInterface->le_set_scan_resp_mask(mask);
348
349 result = (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
350 return result;
351}
352
353static jboolean setLEManuDataNative(JNIEnv *env, jobject obj,jbyteArray buff){
354 ALOGV("%s:",__FUNCTION__);
355 jbyte *manu_data=NULL;
356 uint8_t size=0;
357 jboolean result = JNI_FALSE;
358 manu_data=env->GetByteArrayElements(buff, NULL);
359 size=env->GetArrayLength(buff);
360 if (!qBluetoothInterface) return result;
361 int ret = qBluetoothInterface->le_set_manu_data((uint8_t *)manu_data, size);
362
363 result = (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
364 return result;
365}
366
367static jboolean setLEServiceDataNative(JNIEnv *env, jobject obj,jbyteArray buff){
368 ALOGV("%s:",__FUNCTION__);
369 jbyte *service_data=NULL;
370 uint8_t size=0;
371 jboolean result = JNI_FALSE;
372 service_data=env->GetByteArrayElements(buff, NULL);
373 size=env->GetArrayLength(buff);
374 if (!qBluetoothInterface) return result;
375 int ret = qBluetoothInterface->le_set_service_data((uint8_t *)service_data, size);
376
377 result = (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
378 return result;
379}
380static jboolean setLEAdvParamsNative(JNIEnv *env, jobject obj, jint min_int, jint max_int, jbyteArray address, jint ad_type){
381 ALOGV("%s:",__FUNCTION__);
382
383 jbyte *addr=NULL;
384 jboolean result = JNI_FALSE;
385 addr = env->GetByteArrayElements(address, NULL);
386 if (!qBluetoothInterface) return result;
387 int ret = qBluetoothInterface->le_set_adv_params(min_int, max_int, (bt_bdaddr_t *)addr,ad_type);
388
389 result = (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
390
391 return result;
392}
393
Nitin Aroraaabc4272013-10-08 16:55:47 -0700394static void btLeExtendedScanNative(JNIEnv *env, jobject object,
395 jobjectArray uuids, jboolean start)
396{
397 int i = 0, entries = 0;
398 uint8_t scan_policy = 0x80; /* 0x80 represent only AD whitelist applied*/
399 bt_le_service_t *service_list = 0;
400 entries = env->GetArrayLength(uuids);
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800401 if(qBluetoothInterface && (service_list = (bt_le_service_t*)malloc(entries * sizeof(bt_le_service_t))))
Nitin Aroraaabc4272013-10-08 16:55:47 -0700402 {
403 jclass clazzuuid;
404 jobject uuid;
405 jmethodID getlsb, getmsb, gettype;
406 jlong lsbbits, msbbits;
407 if ((clazzuuid = env->FindClass("android/bluetooth/BluetoothLEServiceUuid")) != NULL &&
408 (getlsb = env->GetMethodID(clazzuuid, "getLeastSignificantBits", "()J")) != NULL &&
409 (getmsb = env->GetMethodID(clazzuuid, "getMostSignificantBits", "()J")) != NULL &&
410 (gettype = env->GetMethodID(clazzuuid, "getType", "()B")) != NULL)
411 {
412 for(i = 0; i < entries; i++)
413 {
414 uuid = env->GetObjectArrayElement(uuids, i);
415 service_list[i].uuidtype = env->CallByteMethod(uuid, gettype);
416 lsbbits = env->CallLongMethod(uuid, getlsb);
417 msbbits = env->CallLongMethod(uuid, getmsb);
418 set_uuid(&service_list[i].uuidval.uu[0], msbbits, lsbbits);
419 }
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800420 qBluetoothInterface->le_extended_scan(service_list, entries, scan_policy, start?1:0);
Nitin Aroraaabc4272013-10-08 16:55:47 -0700421 }
422 }
423 free(service_list);
424}
425
426static void btLeLppWriteRssiThresholdNative(JNIEnv *env, jobject object,
427 jstring address, jbyte min, jbyte max)
428{
429 bt_bdaddr_t bda;
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800430 if (!qBluetoothInterface) return;
Nitin Aroraaabc4272013-10-08 16:55:47 -0700431 jstr2bdaddr(env, &bda, address);
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800432 qBluetoothInterface->le_lpp_write_rssi_threshold(&bda, min, max);
Nitin Aroraaabc4272013-10-08 16:55:47 -0700433}
434
435static void btLeLppEnableRssiMonitorNative(JNIEnv* env, jobject object,
436 jstring address, jboolean enable)
437{
438 bt_bdaddr_t bda;
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800439 if (!qBluetoothInterface) return;
Nitin Aroraaabc4272013-10-08 16:55:47 -0700440 jstr2bdaddr(env, &bda, address);
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800441 qBluetoothInterface->le_lpp_enable_rssi_monitor(&bda, enable);
Nitin Aroraaabc4272013-10-08 16:55:47 -0700442}
443
444static void btLeLppReadRssiThresholdNative(JNIEnv* env, jobject object,
445 jstring address)
446{
447 bt_bdaddr_t bda;
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800448 if (!qBluetoothInterface) return;
Nitin Aroraaabc4272013-10-08 16:55:47 -0700449 jstr2bdaddr(env, &bda, address);
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800450 qBluetoothInterface->le_lpp_read_rssi_threshold(&bda);
Nitin Aroraaabc4272013-10-08 16:55:47 -0700451}
452
453static JNINativeMethod qMethods[] = {
454 /* name, signature, funcPtr */
455 {"classInitNative", "()V", (void *) classInitNative},
456 {"initNative", "()Z", (void *) initNative},
457 {"cleanupNative", "()V", (void*) cleanupNative},
Kiran Kelagerid81255d2013-12-09 17:12:30 -0800458 {"setLEAdvParamsNative","(II[BI)Z", (void*) setLEAdvParamsNative},
459 {"setLEadvMaskNative","(I)Z",(void*) setLEadvMaskNative},
460 {"setLEscanRespMaskNative","(I)Z",(void*) setLEscanRespMaskNative},
461 {"setLEManuDataNative","([B)Z",(void*) setLEManuDataNative},
462 {"setLEServiceDataNative","([B)Z",(void*) setLEServiceDataNative},
463 {"setLEAdvModeNative", "(I[B)Z", (void*) setLEAdvModeNative},
Nitin Aroraaabc4272013-10-08 16:55:47 -0700464 {"btLeExtendedScanNative", "([Landroid/bluetooth/BluetoothLEServiceUuid;Z)V", (void*) btLeExtendedScanNative},
465 {"btLeLppWriteRssiThresholdNative", "(Ljava/lang/String;BB)V", (void*)btLeLppWriteRssiThresholdNative},
466 {"btLeLppEnableRssiMonitorNative", "(Ljava/lang/String;Z)V", (void*)btLeLppEnableRssiMonitorNative},
467 {"btLeLppReadRssiThresholdNative", "(Ljava/lang/String;)V", (void*)btLeLppReadRssiThresholdNative},
468
469};
470
471int register_com_android_bluetooth_btservice_QAdapterService(JNIEnv* env)
472{
473 return jniRegisterNativeMethods(env, "com/android/bluetooth/btservice/QAdapterService",
474 qMethods, NELEM(qMethods));
475}
476
477}