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

Commit af36e8fd authored by Rahul Arya's avatar Rahul Arya
Browse files

Avoid blocking main thread on HID operations

`fixed_queue_try_dequeue` is what we want here, `fixed_queue_dequeue` is a blocking operation if the queue is empty.

Change-Id: Icd1acd1fd246f4a9a62891ad7f0d53eda37700f9
Test: atest pts-bot:HID/HOS/HDT/BV-02-I
Bug: 213440208
Tag: #stability
parent 9054db7e
Loading
Loading
Loading
Loading
+18 −4
Original line number Diff line number Diff line
@@ -157,7 +157,12 @@ static int uhid_read_event(btif_hh_device_t* p_dev) {
      if (p_dev->get_rpt_id_queue) {
        uint32_t* get_rpt_id = (uint32_t*)osi_malloc(sizeof(uint32_t));
        *get_rpt_id = ev.u.feature.id;
        fixed_queue_enqueue(p_dev->get_rpt_id_queue, (void*)get_rpt_id);
        auto ok = fixed_queue_try_enqueue(p_dev->get_rpt_id_queue, (void*)get_rpt_id);
        if (!ok) {
            LOG_ERROR("get_rpt_id_queue is full, dropping event %d", *get_rpt_id);
            osi_free(get_rpt_id);
            return -EFAULT;
        }
      }
      if (ev.u.feature.rtype == UHID_FEATURE_REPORT)
        btif_hh_getreport(p_dev, BTHH_FEATURE_REPORT, ev.u.feature.rnum, 0);
@@ -196,7 +201,12 @@ static int uhid_read_event(btif_hh_device_t* p_dev) {
      if (sent && p_dev->set_rpt_id_queue) {
        uint32_t* set_rpt_id = (uint32_t*)osi_malloc(sizeof(uint32_t));
        *set_rpt_id = ev.u.set_report.id;
        fixed_queue_enqueue(p_dev->set_rpt_id_queue, (void*)set_rpt_id);
        auto ok = fixed_queue_try_enqueue(p_dev->set_rpt_id_queue, (void*)set_rpt_id);
        if (!ok) {
            LOG_ERROR("set_rpt_id_queue is full, dropping event %d", *set_rpt_id);
            osi_free(set_rpt_id);
            return -EFAULT;
        }
      }
      break;
    }
@@ -604,7 +614,7 @@ void bta_hh_co_set_rpt_rsp(uint8_t dev_handle, uint8_t status) {
  // Send the HID set report reply to the kernel.
  if (p_dev->fd >= 0) {
    uint32_t* set_rpt_id =
        (uint32_t*)fixed_queue_dequeue(p_dev->set_rpt_id_queue);
        (uint32_t*)fixed_queue_try_dequeue(p_dev->set_rpt_id_queue);
    if (set_rpt_id) {
      struct uhid_event ev = {};

@@ -654,7 +664,11 @@ void bta_hh_co_get_rpt_rsp(uint8_t dev_handle, uint8_t status, uint8_t* p_rpt,
  // Send the HID report to the kernel.
  if (p_dev->fd >= 0 && p_dev->get_rpt_snt > 0 && p_dev->get_rpt_snt--) {
    uint32_t* get_rpt_id =
        (uint32_t*)fixed_queue_dequeue(p_dev->get_rpt_id_queue);
        (uint32_t*)fixed_queue_try_dequeue(p_dev->get_rpt_id_queue);
    if (get_rpt_id == nullptr) {
      APPL_TRACE_WARNING("%s: Error: UHID_GET_REPORT queue is empty", __func__);
      return;
    }
    memset(&ev, 0, sizeof(ev));
    ev.type = UHID_FEATURE_ANSWER;
    ev.u.feature_answer.id = *get_rpt_id;