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

Commit 725f5e43 authored by Yuyang Huang's avatar Yuyang Huang
Browse files

add implementation for getAdvertisementServiceData

This targets to expose ASHA service data to settingLib

Test: manual
Tag: #feature
Bug: 265027285
Change-Id: Ibf94d864c74c773bcf4c88722f787d401703d3ad
parent c6449d01
Loading
Loading
Loading
Loading
+56 −2
Original line number Diff line number Diff line
@@ -320,6 +320,56 @@ bt_status_t btif_in_execute_service_request(tBTA_SERVICE_ID service_id,
  return GetInterfaceToProfiles()->toggleProfile(service_id, b_enable);
}

/**
 * Helper method to get asha advertising service data
 * @param inq_res {@code tBTA_DM_INQ_RES} inquiry result
 * @param asha_capability value will be updated as non-negative if found,
 * otherwise return -1
 * @param asha_truncated_hi_sync_id value will be updated if found, otherwise no
 * change
 */
static void get_asha_service_data(const tBTA_DM_INQ_RES& inq_res,
                                  int16_t& asha_capability,
                                  uint32_t& asha_truncated_hi_sync_id) {
  asha_capability = -1;
  if (inq_res.p_eir) {
    const RawAddress& bdaddr = inq_res.bd_addr;

    // iterate through advertisement service data
    const uint8_t* p_service_data = inq_res.p_eir;
    uint8_t service_data_len = 0;
    while ((p_service_data = AdvertiseDataParser::GetFieldByType(
                p_service_data + service_data_len,
                inq_res.eir_len - (p_service_data - inq_res.p_eir) -
                    service_data_len,
                BTM_BLE_AD_TYPE_SERVICE_DATA_TYPE, &service_data_len))) {
      if (service_data_len < 2) {
        continue;
      }
      uint16_t uuid;
      const uint8_t* p_uuid = p_service_data;
      STREAM_TO_UINT16(uuid, p_uuid);

      if (uuid == 0xfdf0 /* ASHA service*/) {
        LOG_INFO("ASHA found in %s", ADDRESS_TO_LOGGABLE_CSTR(bdaddr));

        // ASHA advertisement service data length should be at least 8
        if (service_data_len < 8) {
          LOG_WARN("ASHA device service_data_len too short");
        } else {
          // It is intended to save ASHA capability byte to int16_t
          asha_capability = p_service_data[3];
          LOG_INFO("asha_capability: %d", asha_capability);

          const uint8_t* p_truncated_hisyncid = &(p_service_data[4]);
          STREAM_TO_UINT32(asha_truncated_hi_sync_id, p_truncated_hisyncid);
        }
        break;
      }
    }
  }
}

/*******************************************************************************
 *
 * Function         check_eir_remote_name
@@ -1381,13 +1431,17 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event,
                                   &(p_search_data->inq_res.include_rsi));
        num_properties++;

        // a non-negative value contains ASHA capability information
        // because ASHA's capability is 1 byte, so int16_t is large enough
        // The default negative value means ASHA capability not found.
        // A non-negative value represents ASHA capability information is valid.
        // Because ASHA's capability is 1 byte, so int16_t is large enough.
        int16_t asha_capability = -1;

        // contains ASHA truncated HiSyncId if asha_capability is non-negative
        uint32_t asha_truncated_hi_sync_id = 0;

        get_asha_service_data(p_search_data->inq_res, asha_capability,
                              asha_truncated_hi_sync_id);

        BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
                                   BT_PROPERTY_REMOTE_ASHA_CAPABILITY,
                                   sizeof(int16_t), &asha_capability);