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

Commit dc69b26e authored by Jakub Pawłowski's avatar Jakub Pawłowski Committed by Gerrit Code Review
Browse files

Merge "DID event -> DID callback" into main

parents 2eae98e5 8d4ab54a
Loading
Loading
Loading
Loading
+6 −15
Original line number Diff line number Diff line
@@ -729,14 +729,9 @@ static void bta_dm_sdp_result(tBTA_DM_MSG* p_data) {
    tSDP_DI_GET_RECORD di_record;
    if (get_legacy_stack_sdp_api()->device_id.SDP_GetDiRecord(
            1, &di_record, bta_dm_search_cb.p_sdp_db) == SDP_SUCCESS) {
      tBTA_DM_SEARCH result;
      result.did_res.bd_addr = bta_dm_search_cb.peer_bdaddr;
      result.did_res.vendor_id_src = di_record.rec.vendor_id_source;
      result.did_res.vendor_id = di_record.rec.vendor;
      result.did_res.product_id = di_record.rec.product;
      result.did_res.version = di_record.rec.version;
      bta_dm_search_cb.service_search_cbacks.legacy(BTA_DM_DID_RES_EVT,
                                                    &result);
      bta_dm_search_cb.service_search_cbacks.on_did_received(
          bta_dm_search_cb.peer_bdaddr, di_record.rec.vendor_id_source,
          di_record.rec.vendor, di_record.rec.product, di_record.rec.version);
    }
#endif

@@ -842,13 +837,9 @@ static void bta_dm_read_dis_cmpl(const RawAddress& addr,
  if (!p_dis_value) {
    log::warn("read DIS failed");
  } else {
    tBTA_DM_SEARCH result;
    result.did_res.bd_addr = addr;
    result.did_res.vendor_id_src = p_dis_value->pnp_id.vendor_id_src;
    result.did_res.vendor_id = p_dis_value->pnp_id.vendor_id;
    result.did_res.product_id = p_dis_value->pnp_id.product_id;
    result.did_res.version = p_dis_value->pnp_id.product_version;
    bta_dm_search_cb.service_search_cbacks.legacy(BTA_DM_DID_RES_EVT, &result);
    bta_dm_search_cb.service_search_cbacks.on_did_received(
        addr, p_dis_value->pnp_id.vendor_id_src, p_dis_value->pnp_id.vendor_id,
        p_dis_value->pnp_id.product_id, p_dis_value->pnp_id.product_version);
  }

  bta_dm_execute_queued_request();
+10 −16
Original line number Diff line number Diff line
@@ -221,10 +221,9 @@ typedef enum : uint8_t {
      3,                    /* GATT services over LE transport discovered */
  BTA_DM_DISC_CMPL_EVT = 4, /* Discovery complete. */
  BTA_DM_SEARCH_CANCEL_CMPL_EVT = 5, /* Search cancelled */
  BTA_DM_DID_RES_EVT = 6,            /* Vendor/Product ID search result */
  BTA_DM_GATT_OVER_SDP_RES_EVT = 7,  /* GATT services over SDP discovered */
  BTA_DM_NAME_READ_EVT = 8,          /* Name read complete. */
  BTA_DM_OBSERVE_CMPL_EVT = 9,       /* Observe complete. */
  BTA_DM_GATT_OVER_SDP_RES_EVT = 6,  /* GATT services over SDP discovered */
  BTA_DM_NAME_READ_EVT = 7,          /* Name read complete. */
  BTA_DM_OBSERVE_CMPL_EVT = 8,       /* Observe complete. */
} tBTA_DM_SEARCH_EVT;

inline std::string bta_dm_search_evt_text(const tBTA_DM_SEARCH_EVT& event) {
@@ -235,7 +234,6 @@ inline std::string bta_dm_search_evt_text(const tBTA_DM_SEARCH_EVT& event) {
    CASE_RETURN_TEXT(BTA_DM_GATT_OVER_LE_RES_EVT);
    CASE_RETURN_TEXT(BTA_DM_DISC_CMPL_EVT);
    CASE_RETURN_TEXT(BTA_DM_SEARCH_CANCEL_CMPL_EVT);
    CASE_RETURN_TEXT(BTA_DM_DID_RES_EVT);
    CASE_RETURN_TEXT(BTA_DM_GATT_OVER_SDP_RES_EVT);
    CASE_RETURN_TEXT(BTA_DM_NAME_READ_EVT);
    CASE_RETURN_TEXT(BTA_DM_OBSERVE_CMPL_EVT);
@@ -297,31 +295,27 @@ typedef struct {
      services; /* GATT based Services UUID found on peer device. */
} tBTA_DM_DISC_BLE_RES;

/* Structure associated with tBTA_DM_DID_RES */
typedef struct {
  RawAddress bd_addr; /* BD address peer device. */
  uint8_t vendor_id_src;
  uint16_t vendor_id;
  uint16_t product_id;
  uint16_t version;
} tBTA_DM_DID_RES;

/* Union of all search callback structures */
typedef union {
  tBTA_DM_INQ_RES inq_res;   /* Inquiry result for a peer device. */
  tBTA_DM_DISC_RES disc_res; /* Discovery result for a peer device. */
  tBTA_DM_DISC_BLE_RES
      disc_ble_res; /* discovery result for GATT based service */
  tBTA_DM_DID_RES did_res;      /* Vendor and Product ID of peer device */
  tBTA_DM_OBSERVE_CMPL observe_cmpl; /* Observe complete. */
} tBTA_DM_SEARCH;

/* Search callback */
typedef void(tBTA_DM_SEARCH_CBACK)(tBTA_DM_SEARCH_EVT event,
                                   tBTA_DM_SEARCH* p_data);

typedef void(tBTA_DM_DID_RES_CBACK)(RawAddress bd_addr, uint8_t vendor_id_src,
                                    uint16_t vendor_id, uint16_t product_id,
                                    uint16_t version);

struct service_discovery_callbacks {
  /* legacy callback I'll tear apart and get rid of */
  tBTA_DM_SEARCH_CBACK* legacy;
  tBTA_DM_DID_RES_CBACK* on_did_received;
};

/* Execute call back */
+6 −6
Original line number Diff line number Diff line
@@ -238,22 +238,22 @@ TEST_F(BtaInitializedTest, bta_dm_disc_stop_device_discovery) {
TEST_F(BtaInitializedTest,
       bta_dm_disc_start_service_discovery__BT_TRANSPORT_AUTO) {
  bta_dm_disc_start_service_discovery(
      {[](tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH* p_data) {}}, kRawAddress,
      BT_TRANSPORT_AUTO);
      {[](tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH* p_data) {}, nullptr},
      kRawAddress, BT_TRANSPORT_AUTO);
}

TEST_F(BtaInitializedTest,
       bta_dm_disc_start_service_discovery__BT_TRANSPORT_BR_EDR) {
  bta_dm_disc_start_service_discovery(
      {[](tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH* p_data) {}}, kRawAddress,
      BT_TRANSPORT_BR_EDR);
      {[](tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH* p_data) {}, nullptr},
      kRawAddress, BT_TRANSPORT_BR_EDR);
}

TEST_F(BtaInitializedTest,
       bta_dm_disc_start_service_discovery__BT_TRANSPORT_LE) {
  bta_dm_disc_start_service_discovery(
      {[](tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH* p_data) {}}, kRawAddress,
      BT_TRANSPORT_LE);
      {[](tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH* p_data) {}, nullptr},
      kRawAddress, BT_TRANSPORT_LE);
}

TEST_F(BtaInitializedTest,
+0 −1
Original line number Diff line number Diff line
@@ -537,7 +537,6 @@ TEST_F(BtaDmTest, bta_dm_search_evt_text) {
      std::make_pair(BTA_DM_DISC_CMPL_EVT, "BTA_DM_DISC_CMPL_EVT"),
      std::make_pair(BTA_DM_SEARCH_CANCEL_CMPL_EVT,
                     "BTA_DM_SEARCH_CANCEL_CMPL_EVT"),
      std::make_pair(BTA_DM_DID_RES_EVT, "BTA_DM_DID_RES_EVT"),
      std::make_pair(BTA_DM_GATT_OVER_SDP_RES_EVT,
                     "BTA_DM_GATT_OVER_SDP_RES_EVT"),
      std::make_pair(BTA_DM_NAME_READ_EVT, "BTA_DM_NAME_READ_EVT"),
+26 −24
Original line number Diff line number Diff line
@@ -2081,29 +2081,6 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
          BT_STATUS_SUCCESS, bd_addr, num_properties, prop);
    } break;

    case BTA_DM_DID_RES_EVT: {
      bt_property_t prop_did;
      RawAddress& bd_addr = p_data->did_res.bd_addr;
      bt_vendor_product_info_t vp_info;

      vp_info.vendor_id_src = p_data->did_res.vendor_id_src;
      vp_info.vendor_id = p_data->did_res.vendor_id;
      vp_info.product_id = p_data->did_res.product_id;
      vp_info.version = p_data->did_res.version;

      prop_did.type = BT_PROPERTY_VENDOR_PRODUCT_INFO;
      prop_did.val = &vp_info;
      prop_did.len = sizeof(vp_info);

      bt_status_t ret =
          btif_storage_set_remote_device_property(&bd_addr, &prop_did);
      ASSERTC(ret == BT_STATUS_SUCCESS, "storing remote services failed", ret);

      /* Send the event to the BTIF */
      GetInterfaceToProfiles()->events->invoke_remote_device_properties_cb(
          BT_STATUS_SUCCESS, bd_addr, 1, &prop_did);
    } break;

    case BTA_DM_NAME_READ_EVT: {
      if (IS_FLAG_ENABLED(rnr_present_during_service_discovery)) {
        const tBTA_DM_DISC_RES& disc_res = p_data->disc_res;
@@ -2146,6 +2123,30 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
  }
}

void btif_on_did_received(RawAddress bd_addr, uint8_t vendor_id_src,
                          uint16_t vendor_id, uint16_t product_id,
                          uint16_t version) {
  bt_property_t prop_did;
  bt_vendor_product_info_t vp_info;

  vp_info.vendor_id_src = vendor_id_src;
  vp_info.vendor_id = vendor_id;
  vp_info.product_id = product_id;
  vp_info.version = version;

  prop_did.type = BT_PROPERTY_VENDOR_PRODUCT_INFO;
  prop_did.val = &vp_info;
  prop_did.len = sizeof(vp_info);

  bt_status_t ret =
      btif_storage_set_remote_device_property(&bd_addr, &prop_did);
  ASSERTC(ret == BT_STATUS_SUCCESS, "storing remote services failed", ret);

  /* Send the event to the BTIF */
  GetInterfaceToProfiles()->events->invoke_remote_device_properties_cb(
      BT_STATUS_SUCCESS, bd_addr, 1, &prop_did);
}

static void btif_dm_update_allowlisted_media_players() {
  uint8_t i = 0, buf_len = 0;
  bt_property_t wlplayers_prop;
@@ -3142,7 +3143,8 @@ void btif_dm_get_remote_services(RawAddress remote_addr, const int transport) {
      base::StringPrintf("transport:%s", bt_transport_text(transport).c_str()));

  BTA_DmDiscover(remote_addr,
                 service_discovery_callbacks{btif_dm_search_services_evt},
                 service_discovery_callbacks{btif_dm_search_services_evt,
                                             btif_on_did_received},
                 transport);
}