Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9f6f882d authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "gatt: Fix incorrect write to the descriptor." am: 2a6173b6 am:...

Merge "gatt: Fix incorrect write to the descriptor." am: 2a6173b6 am: 83702c97 am: 8b73951c am: 467cefed am: a603f45c

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2133661



Change-Id: Iff3b9942ec3b9708a556b9d5c16c83cb6bf05400
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents fdd6358a a603f45c
Loading
Loading
Loading
Loading
+4 −16
Original line number Original line Diff line number Diff line
@@ -312,14 +312,8 @@ void btgattc_write_characteristic_cb(int conn_id, int status, uint16_t handle,
  if (!sCallbackEnv.valid()) return;
  if (!sCallbackEnv.valid()) return;


  ScopedLocalRef<jbyteArray> jb(sCallbackEnv.get(), NULL);
  ScopedLocalRef<jbyteArray> jb(sCallbackEnv.get(), NULL);
  if (status == 0) {  // Success
  jb.reset(sCallbackEnv->NewByteArray(len));
  jb.reset(sCallbackEnv->NewByteArray(len));
  sCallbackEnv->SetByteArrayRegion(jb.get(), 0, len, (jbyte*)value);
  sCallbackEnv->SetByteArrayRegion(jb.get(), 0, len, (jbyte*)value);
  } else {
    uint8_t value = 0;
    jb.reset(sCallbackEnv->NewByteArray(1));
    sCallbackEnv->SetByteArrayRegion(jb.get(), 0, 1, (jbyte*)&value);
  }
  sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onWriteCharacteristic,
  sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onWriteCharacteristic,
                               conn_id, status, handle, jb.get());
                               conn_id, status, handle, jb.get());
}
}
@@ -356,14 +350,8 @@ void btgattc_write_descriptor_cb(int conn_id, int status, uint16_t handle,
  if (!sCallbackEnv.valid()) return;
  if (!sCallbackEnv.valid()) return;


  ScopedLocalRef<jbyteArray> jb(sCallbackEnv.get(), NULL);
  ScopedLocalRef<jbyteArray> jb(sCallbackEnv.get(), NULL);
  if (status == 0) {  // Success
  jb.reset(sCallbackEnv->NewByteArray(len));
  jb.reset(sCallbackEnv->NewByteArray(len));
  sCallbackEnv->SetByteArrayRegion(jb.get(), 0, len, (jbyte*)value);
  sCallbackEnv->SetByteArrayRegion(jb.get(), 0, len, (jbyte*)value);
  } else {
    uint8_t value = 0;
    jb.reset(sCallbackEnv->NewByteArray(1));
    sCallbackEnv->SetByteArrayRegion(jb.get(), 0, 1, (jbyte*)&value);
  }
  sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onWriteDescriptor, conn_id,
  sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onWriteDescriptor, conn_id,
                               status, handle, jb.get());
                               status, handle, jb.get());
}
}
+20 −5
Original line number Original line Diff line number Diff line
@@ -991,13 +991,28 @@ static void bta_gattc_write_cmpl(tBTA_GATTC_CLCB* p_clcb,
  GATT_WRITE_OP_CB cb = p_clcb->p_q_cmd->api_write.write_cb;
  GATT_WRITE_OP_CB cb = p_clcb->p_q_cmd->api_write.write_cb;
  void* my_cb_data = p_clcb->p_q_cmd->api_write.write_cb_data;
  void* my_cb_data = p_clcb->p_q_cmd->api_write.write_cb_data;


  osi_free_and_reset((void**)&p_clcb->p_q_cmd);

  if (cb) {
  if (cb) {
    if (p_data->status == 0 &&
        p_clcb->p_q_cmd->api_write.write_type == BTA_GATTC_WRITE_PREPARE) {
      LOG_DEBUG("Handling prepare write success response: handle 0x%04x",
                p_data->p_cmpl->att_value.handle);
      /* If this is successful Prepare write, lets provide to the callback the
       * data provided by server */
      cb(p_clcb->bta_conn_id, p_data->status, p_data->p_cmpl->att_value.handle,
      cb(p_clcb->bta_conn_id, p_data->status, p_data->p_cmpl->att_value.handle,
         p_data->p_cmpl->att_value.len, p_data->p_cmpl->att_value.value,
         p_data->p_cmpl->att_value.len, p_data->p_cmpl->att_value.value,
         my_cb_data);
         my_cb_data);
    } else {
      LOG_DEBUG("Handling write response type: %d: handle 0x%04x",
                p_clcb->p_q_cmd->api_write.write_type,
                p_data->p_cmpl->att_value.handle);
      /* Otherwise, provide data which were intended to write. */
      cb(p_clcb->bta_conn_id, p_data->status, p_data->p_cmpl->att_value.handle,
         p_clcb->p_q_cmd->api_write.len, p_clcb->p_q_cmd->api_write.p_value,
         my_cb_data);
    }
  }
  }

  osi_free_and_reset((void**)&p_clcb->p_q_cmd);
}
}


/** execute write complete */
/** execute write complete */
+32 −3
Original line number Original line Diff line number Diff line
@@ -72,6 +72,15 @@ extern const btgatt_callbacks_t* bt_gatt_callbacks;
/*******************************************************************************
/*******************************************************************************
 *  Constants & Macros
 *  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, ...)                                         \
#define CLI_CBACK_IN_JNI(P_CBACK, ...)                                         \
  do {                                                                         \
  do {                                                                         \
@@ -500,8 +509,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,
void write_char_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle,
                   uint16_t len, const uint8_t* value, void* data) {
                   uint16_t len, const uint8_t* value, void* data) {
  CLI_CBACK_IN_JNI(write_characteristic_cb, conn_id, status, handle, len,
  std::vector<uint8_t> val(value, value + len);
                   value);
  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,
static bt_status_t btif_gattc_write_char(int conn_id, uint16_t handle,
@@ -520,7 +538,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,
void write_descr_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle,
                    uint16_t len, const uint8_t* value, void* data) {
                    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,
static bt_status_t btif_gattc_write_char_descr(int conn_id, uint16_t handle,