Loading android/app/jni/com_android_bluetooth_gatt.cpp +35 −1 Original line number Diff line number Diff line Loading @@ -158,6 +158,7 @@ static jmethodID method_onGetDescriptor; static jmethodID method_onGetIncludedService; static jmethodID method_onRegisterForNotifications; static jmethodID method_onReadRemoteRssi; static jmethodID method_onClientListen; /** * Server callback methods Loading Loading @@ -422,6 +423,14 @@ void btgattc_remote_rssi_cb(int client_if,bt_bdaddr_t* bda, int rssi, int status checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); } void btgattc_listen_cb(int status, int client_if) { CHECK_CALLBACK_ENV sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onClientListen , status, client_if); checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); } static const btgatt_client_callbacks_t sGattClientCallbacks = { btgattc_register_app_cb, btgattc_scan_result_cb, Loading @@ -439,7 +448,8 @@ static const btgatt_client_callbacks_t sGattClientCallbacks = { btgattc_read_descriptor_cb, btgattc_write_descriptor_cb, btgattc_execute_write_cb, btgattc_remote_rssi_cb btgattc_remote_rssi_cb, btgattc_listen_cb }; Loading Loading @@ -670,6 +680,7 @@ static void classInitNative(JNIEnv* env, jclass clazz) { method_onAttributeRead= env->GetMethodID(clazz, "onAttributeRead", "(Ljava/lang/String;IIIIZ)V"); method_onAttributeWrite= env->GetMethodID(clazz, "onAttributeWrite", "(Ljava/lang/String;IIIIIZZ[B)V"); method_onExecuteWrite= env->GetMethodID(clazz, "onExecuteWrite", "(Ljava/lang/String;III)V"); method_onClientListen = env->GetMethodID(clazz, "onClientListen", "(II)V"); info("classInitNative: Success!"); } Loading Loading @@ -1042,6 +1053,27 @@ static void gattClientReadRemoteRssiNative(JNIEnv* env, jobject object, jint cli sGattIf->client->read_remote_rssi(clientif, &bda); } static void gattClientListenNative(JNIEnv *env, jobject object, jint client_if, jboolean start) { if (!sGattIf) return; sGattIf->client->listen(client_if, start); } static void gattSetAdvDataNative(JNIEnv *env, jobject object, jint client_if, jboolean setScanRsp, jboolean inclName, jboolean inclTxPower, jint minInterval, jint maxInterval, jint appearance, jbyteArray manufacturerData) { if (!sGattIf) return; jbyte* arr_data = env->GetByteArrayElements(manufacturerData, 0); uint16_t arr_len = (uint16_t) env->GetArrayLength(manufacturerData); sGattIf->client->set_adv_data(client_if, setScanRsp, inclName, inclTxPower, minInterval, maxInterval, appearance, arr_len, (char*)arr_data); env->ReleaseByteArrayElements(manufacturerData, arr_data, JNI_ABORT); } /** * Native server functions Loading Loading @@ -1255,6 +1287,7 @@ static JNINativeMethod sMethods[] = { {"gattClientExecuteWriteNative", "(IZ)V", (void *) gattClientExecuteWriteNative}, {"gattClientRegisterForNotificationsNative", "(ILjava/lang/String;IIJJIJJZ)V", (void *) gattClientRegisterForNotificationsNative}, {"gattClientReadRemoteRssiNative", "(ILjava/lang/String;)V", (void *) gattClientReadRemoteRssiNative}, {"gattClientListenNative", "(IZ)V", (void *) gattClientListenNative}, {"gattServerRegisterAppNative", "(JJ)V", (void *) gattServerRegisterAppNative}, {"gattServerUnregisterAppNative", "(I)V", (void *) gattServerUnregisterAppNative}, Loading @@ -1271,6 +1304,7 @@ static JNINativeMethod sMethods[] = { {"gattServerSendNotificationNative", "(III[B)V", (void *) gattServerSendNotificationNative}, {"gattServerSendResponseNative", "(IIIIII[BI)V", (void *) gattServerSendResponseNative}, {"gattSetAdvDataNative", "(IZZZIII[B)V", (void *) gattSetAdvDataNative}, {"gattTestNative", "(IJJLjava/lang/String;IIIII)V", (void *) gattTestNative}, }; Loading android/app/src/com/android/bluetooth/gatt/GattService.java +44 −0 Original line number Diff line number Diff line Loading @@ -286,6 +286,12 @@ public class GattService extends ProfileService { service.clientDisconnect(clientIf, address); } public void clientListen(int clientIf, boolean start) { GattService service = getService(); if (service == null) return; service.clientListen(clientIf, start); } public void refreshDevice(int clientIf, String address) { GattService service = getService(); if (service == null) return; Loading Loading @@ -471,6 +477,14 @@ public class GattService extends ProfileService { srvcId.getUuid(), charInstanceId, charId.getUuid(), confirm, value); } public void setAdvData(int serverIf, boolean setScanRsp, boolean inclName, boolean inclTxPower, int minInterval, int maxInterval, int appearance, byte[] manufacturerData) { GattService service = getService(); if (service == null) return; service.setAdvData(serverIf, setScanRsp, inclName, inclTxPower, minInterval, maxInterval, appearance, manufacturerData); } }; /************************************************************************** Loading Loading @@ -820,6 +834,16 @@ public class GattService extends ProfileService { } } void onClientListen(int status, int clientIf) throws RemoteException { if (DBG) Log.d(TAG, "onClientListen() status=" + status); ClientMap.App app = mClientMap.getById(clientIf); if (app == null) return; app.callback.onListen(status); } /************************************************************************** * GATT Service functions - Shared CLIENT/SERVER *************************************************************************/ Loading Loading @@ -945,6 +969,11 @@ public class GattService extends ProfileService { gattClientDisconnectNative(clientIf, address, connId != null ? connId : 0); } void clientListen(int clientIf, boolean start) { if (DBG) Log.d(TAG, "clientListen() - start=" + start); gattClientListenNative(clientIf, start); } List<String> getConnectedDevices() { enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); Loading Loading @@ -1104,6 +1133,15 @@ public class GattService extends ProfileService { gattClientReadRemoteRssiNative(clientIf, address); } void setAdvData(int serverIf, boolean setScanRsp, boolean inclName, boolean inclTxPower, int minInterval, int maxInterval, int appearance, byte[] manufacturerData) { if (DBG) Log.d(TAG, "setAdvData() - setScanRsp=" + setScanRsp); if (minInterval == 0) maxInterval = 0; gattSetAdvDataNative(serverIf, setScanRsp, inclName, inclTxPower, minInterval, maxInterval, appearance, manufacturerData); } /************************************************************************** * Callback functions - SERVER *************************************************************************/ Loading Loading @@ -1734,6 +1772,12 @@ public class GattService extends ProfileService { private native void gattClientReadRemoteRssiNative(int clientIf, String address); private native void gattClientListenNative(int client_if, boolean start); private native void gattSetAdvDataNative(int serverIf, boolean setScanRsp, boolean inclName, boolean inclTxPower, int minInterval, int maxInterval, int appearance, byte[] manufacturerData); private native void gattServerRegisterAppNative(long app_uuid_lsb, long app_uuid_msb); Loading Loading
android/app/jni/com_android_bluetooth_gatt.cpp +35 −1 Original line number Diff line number Diff line Loading @@ -158,6 +158,7 @@ static jmethodID method_onGetDescriptor; static jmethodID method_onGetIncludedService; static jmethodID method_onRegisterForNotifications; static jmethodID method_onReadRemoteRssi; static jmethodID method_onClientListen; /** * Server callback methods Loading Loading @@ -422,6 +423,14 @@ void btgattc_remote_rssi_cb(int client_if,bt_bdaddr_t* bda, int rssi, int status checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); } void btgattc_listen_cb(int status, int client_if) { CHECK_CALLBACK_ENV sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onClientListen , status, client_if); checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); } static const btgatt_client_callbacks_t sGattClientCallbacks = { btgattc_register_app_cb, btgattc_scan_result_cb, Loading @@ -439,7 +448,8 @@ static const btgatt_client_callbacks_t sGattClientCallbacks = { btgattc_read_descriptor_cb, btgattc_write_descriptor_cb, btgattc_execute_write_cb, btgattc_remote_rssi_cb btgattc_remote_rssi_cb, btgattc_listen_cb }; Loading Loading @@ -670,6 +680,7 @@ static void classInitNative(JNIEnv* env, jclass clazz) { method_onAttributeRead= env->GetMethodID(clazz, "onAttributeRead", "(Ljava/lang/String;IIIIZ)V"); method_onAttributeWrite= env->GetMethodID(clazz, "onAttributeWrite", "(Ljava/lang/String;IIIIIZZ[B)V"); method_onExecuteWrite= env->GetMethodID(clazz, "onExecuteWrite", "(Ljava/lang/String;III)V"); method_onClientListen = env->GetMethodID(clazz, "onClientListen", "(II)V"); info("classInitNative: Success!"); } Loading Loading @@ -1042,6 +1053,27 @@ static void gattClientReadRemoteRssiNative(JNIEnv* env, jobject object, jint cli sGattIf->client->read_remote_rssi(clientif, &bda); } static void gattClientListenNative(JNIEnv *env, jobject object, jint client_if, jboolean start) { if (!sGattIf) return; sGattIf->client->listen(client_if, start); } static void gattSetAdvDataNative(JNIEnv *env, jobject object, jint client_if, jboolean setScanRsp, jboolean inclName, jboolean inclTxPower, jint minInterval, jint maxInterval, jint appearance, jbyteArray manufacturerData) { if (!sGattIf) return; jbyte* arr_data = env->GetByteArrayElements(manufacturerData, 0); uint16_t arr_len = (uint16_t) env->GetArrayLength(manufacturerData); sGattIf->client->set_adv_data(client_if, setScanRsp, inclName, inclTxPower, minInterval, maxInterval, appearance, arr_len, (char*)arr_data); env->ReleaseByteArrayElements(manufacturerData, arr_data, JNI_ABORT); } /** * Native server functions Loading Loading @@ -1255,6 +1287,7 @@ static JNINativeMethod sMethods[] = { {"gattClientExecuteWriteNative", "(IZ)V", (void *) gattClientExecuteWriteNative}, {"gattClientRegisterForNotificationsNative", "(ILjava/lang/String;IIJJIJJZ)V", (void *) gattClientRegisterForNotificationsNative}, {"gattClientReadRemoteRssiNative", "(ILjava/lang/String;)V", (void *) gattClientReadRemoteRssiNative}, {"gattClientListenNative", "(IZ)V", (void *) gattClientListenNative}, {"gattServerRegisterAppNative", "(JJ)V", (void *) gattServerRegisterAppNative}, {"gattServerUnregisterAppNative", "(I)V", (void *) gattServerUnregisterAppNative}, Loading @@ -1271,6 +1304,7 @@ static JNINativeMethod sMethods[] = { {"gattServerSendNotificationNative", "(III[B)V", (void *) gattServerSendNotificationNative}, {"gattServerSendResponseNative", "(IIIIII[BI)V", (void *) gattServerSendResponseNative}, {"gattSetAdvDataNative", "(IZZZIII[B)V", (void *) gattSetAdvDataNative}, {"gattTestNative", "(IJJLjava/lang/String;IIIII)V", (void *) gattTestNative}, }; Loading
android/app/src/com/android/bluetooth/gatt/GattService.java +44 −0 Original line number Diff line number Diff line Loading @@ -286,6 +286,12 @@ public class GattService extends ProfileService { service.clientDisconnect(clientIf, address); } public void clientListen(int clientIf, boolean start) { GattService service = getService(); if (service == null) return; service.clientListen(clientIf, start); } public void refreshDevice(int clientIf, String address) { GattService service = getService(); if (service == null) return; Loading Loading @@ -471,6 +477,14 @@ public class GattService extends ProfileService { srvcId.getUuid(), charInstanceId, charId.getUuid(), confirm, value); } public void setAdvData(int serverIf, boolean setScanRsp, boolean inclName, boolean inclTxPower, int minInterval, int maxInterval, int appearance, byte[] manufacturerData) { GattService service = getService(); if (service == null) return; service.setAdvData(serverIf, setScanRsp, inclName, inclTxPower, minInterval, maxInterval, appearance, manufacturerData); } }; /************************************************************************** Loading Loading @@ -820,6 +834,16 @@ public class GattService extends ProfileService { } } void onClientListen(int status, int clientIf) throws RemoteException { if (DBG) Log.d(TAG, "onClientListen() status=" + status); ClientMap.App app = mClientMap.getById(clientIf); if (app == null) return; app.callback.onListen(status); } /************************************************************************** * GATT Service functions - Shared CLIENT/SERVER *************************************************************************/ Loading Loading @@ -945,6 +969,11 @@ public class GattService extends ProfileService { gattClientDisconnectNative(clientIf, address, connId != null ? connId : 0); } void clientListen(int clientIf, boolean start) { if (DBG) Log.d(TAG, "clientListen() - start=" + start); gattClientListenNative(clientIf, start); } List<String> getConnectedDevices() { enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); Loading Loading @@ -1104,6 +1133,15 @@ public class GattService extends ProfileService { gattClientReadRemoteRssiNative(clientIf, address); } void setAdvData(int serverIf, boolean setScanRsp, boolean inclName, boolean inclTxPower, int minInterval, int maxInterval, int appearance, byte[] manufacturerData) { if (DBG) Log.d(TAG, "setAdvData() - setScanRsp=" + setScanRsp); if (minInterval == 0) maxInterval = 0; gattSetAdvDataNative(serverIf, setScanRsp, inclName, inclTxPower, minInterval, maxInterval, appearance, manufacturerData); } /************************************************************************** * Callback functions - SERVER *************************************************************************/ Loading Loading @@ -1734,6 +1772,12 @@ public class GattService extends ProfileService { private native void gattClientReadRemoteRssiNative(int clientIf, String address); private native void gattClientListenNative(int client_if, boolean start); private native void gattSetAdvDataNative(int serverIf, boolean setScanRsp, boolean inclName, boolean inclTxPower, int minInterval, int maxInterval, int appearance, byte[] manufacturerData); private native void gattServerRegisterAppNative(long app_uuid_lsb, long app_uuid_msb); Loading