summaryrefslogtreecommitdiff
path: root/system/btif/src/btif_gatt_client.cc
diff options
context:
space:
mode:
Diffstat (limited to 'system/btif/src/btif_gatt_client.cc')
-rw-r--r--system/btif/src/btif_gatt_client.cc35
1 files changed, 32 insertions, 3 deletions
diff --git a/system/btif/src/btif_gatt_client.cc b/system/btif/src/btif_gatt_client.cc
index 08e4431ff9..905179d560 100644
--- a/system/btif/src/btif_gatt_client.cc
+++ b/system/btif/src/btif_gatt_client.cc
@@ -106,6 +106,15 @@ extern const btgatt_callbacks_t* bt_gatt_callbacks;
/*******************************************************************************
* Constants & Macros
******************************************************************************/
+#define CLI_CBACK_WRAP_IN_JNI(P_CBACK, P_CBACK_WRAP) \
+ do { \
+ if (bt_gatt_callbacks && bt_gatt_callbacks->client->P_CBACK) { \
+ BTIF_TRACE_API("HAL bt_gatt_callbacks->client->%s", #P_CBACK); \
+ do_in_jni_thread(P_CBACK_WRAP); \
+ } else { \
+ ASSERTC(0, "Callback is NULL", 0); \
+ } \
+ } while (0)
#define CLI_CBACK_IN_JNI(P_CBACK, ...) \
do { \
@@ -534,8 +543,17 @@ static bt_status_t btif_gattc_read_char_descr(int conn_id, uint16_t handle,
void write_char_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle,
uint16_t len, const uint8_t* value, void* data) {
- CLI_CBACK_IN_JNI(write_characteristic_cb, conn_id, status, handle, len,
- value);
+ std::vector<uint8_t> val(value, value + len);
+ CLI_CBACK_WRAP_IN_JNI(
+ write_characteristic_cb,
+ base::BindOnce(
+ [](write_characteristic_callback cb, uint16_t conn_id,
+ tGATT_STATUS status, uint16_t handle,
+ std::vector<uint8_t> moved_value) {
+ cb(conn_id, status, handle, moved_value.size(), moved_value.data());
+ },
+ bt_gatt_callbacks->client->write_characteristic_cb, conn_id, status,
+ handle, std::move(val)));
}
static bt_status_t btif_gattc_write_char(int conn_id, uint16_t handle,
@@ -554,7 +572,18 @@ static bt_status_t btif_gattc_write_char(int conn_id, uint16_t handle,
void write_descr_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle,
uint16_t len, const uint8_t* value, void* data) {
- CLI_CBACK_IN_JNI(write_descriptor_cb, conn_id, status, handle, len, value);
+ std::vector<uint8_t> val(value, value + len);
+
+ CLI_CBACK_WRAP_IN_JNI(
+ write_descriptor_cb,
+ base::BindOnce(
+ [](write_descriptor_callback cb, uint16_t conn_id,
+ tGATT_STATUS status, uint16_t handle,
+ std::vector<uint8_t> moved_value) {
+ cb(conn_id, status, handle, moved_value.size(), moved_value.data());
+ },
+ bt_gatt_callbacks->client->write_descriptor_cb, conn_id, status,
+ handle, std::move(val)));
}
static bt_status_t btif_gattc_write_char_descr(int conn_id, uint16_t handle,