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

Commit 23277fdc authored by Jack He's avatar Jack He Committed by Automerger Merge Worker
Browse files

Merge "bt: Fix persisting appearance for le only device" am: 3eefb7f8

parents 599631e6 3eefb7f8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -139,7 +139,7 @@ void btif_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK* p_key_mask,
                                Octet16* p_er,
                                tBTA_BLE_LOCAL_ID_KEYS* p_id_keys);
void btif_dm_update_ble_remote_properties(const RawAddress& bd_addr,
                                          BD_NAME bd_name,
                                          BD_NAME bd_name, DEV_CLASS dev_class,
                                          tBT_DEVICE_TYPE dev_type);

bool check_cod_hid(const RawAddress& bd_addr);
+11 −9
Original line number Diff line number Diff line
@@ -3279,9 +3279,9 @@ static void btif_dm_ble_key_notif_evt(tBTA_DM_SP_KEY_NOTIF* p_ssp_key_notif) {
  if (!btif_get_device_type(p_ssp_key_notif->bd_addr, &dev_type)) {
    dev_type = BT_DEVICE_TYPE_BLE;
  }
  btif_dm_update_ble_remote_properties(p_ssp_key_notif->bd_addr,
                                       p_ssp_key_notif->bd_name,
                                       (tBT_DEVICE_TYPE)dev_type);
  btif_dm_update_ble_remote_properties(
      p_ssp_key_notif->bd_addr, p_ssp_key_notif->bd_name,
      nullptr /* dev_class */, (tBT_DEVICE_TYPE)dev_type);
  bd_addr = p_ssp_key_notif->bd_addr;
  memcpy(bd_name.name, p_ssp_key_notif->bd_name, BD_NAME_LEN);
  bd_name.name[BD_NAME_LEN] = '\0';
@@ -3517,6 +3517,7 @@ static void btif_dm_ble_sec_req_evt(tBTA_DM_BLE_SEC_REQ* p_ble_req,
    dev_type = BT_DEVICE_TYPE_BLE;
  }
  btif_dm_update_ble_remote_properties(p_ble_req->bd_addr, p_ble_req->bd_name,
                                       nullptr /* dev_class */,
                                       (tBT_DEVICE_TYPE)dev_type);

  RawAddress bd_addr = p_ble_req->bd_addr;
@@ -3556,6 +3557,7 @@ static void btif_dm_ble_passkey_req_evt(tBTA_DM_PIN_REQ* p_pin_req) {
    dev_type = BT_DEVICE_TYPE_BLE;
  }
  btif_dm_update_ble_remote_properties(p_pin_req->bd_addr, p_pin_req->bd_name,
                                       nullptr /* dev_class */,
                                       (tBT_DEVICE_TYPE)dev_type);

  RawAddress bd_addr = p_pin_req->bd_addr;
@@ -3576,7 +3578,7 @@ static void btif_dm_ble_key_nc_req_evt(tBTA_DM_SP_KEY_NOTIF* p_notif_req) {

  /* Remote name update */
  btif_update_remote_properties(p_notif_req->bd_addr, p_notif_req->bd_name,
                                NULL, BT_DEVICE_TYPE_BLE);
                                nullptr /* dev_class */, BT_DEVICE_TYPE_BLE);

  RawAddress bd_addr = p_notif_req->bd_addr;

@@ -3615,7 +3617,7 @@ static void btif_dm_ble_oob_req_evt(tBTA_DM_SP_RMT_OOB* req_oob_type) {

  /* Remote name update */
  btif_update_remote_properties(req_oob_type->bd_addr, req_oob_type->bd_name,
                                NULL, BT_DEVICE_TYPE_BLE);
                                nullptr /* dev_class */, BT_DEVICE_TYPE_BLE);

  bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING);
  pairing_cb.is_ssp = false;
@@ -3672,8 +3674,8 @@ static void btif_dm_ble_sc_oob_req_evt(tBTA_DM_SP_RMT_OOB* req_oob_type) {

  /* Remote name update */
  btif_update_remote_properties(req_oob_type->bd_addr,
                                oob_data_to_use.device_name, NULL,
                                BT_DEVICE_TYPE_BLE);
                                oob_data_to_use.device_name,
                                nullptr /* dev_class */, BT_DEVICE_TYPE_BLE);

  bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING);
  pairing_cb.is_ssp = false;
@@ -3685,9 +3687,9 @@ static void btif_dm_ble_sc_oob_req_evt(tBTA_DM_SP_RMT_OOB* req_oob_type) {
}

void btif_dm_update_ble_remote_properties(const RawAddress& bd_addr,
                                          BD_NAME bd_name,
                                          BD_NAME bd_name, DEV_CLASS dev_class,
                                          tBT_DEVICE_TYPE dev_type) {
  btif_update_remote_properties(bd_addr, bd_name, NULL, dev_type);
  btif_update_remote_properties(bd_addr, bd_name, dev_class, dev_type);
}

void btif_dm_on_disable() {
+18 −6
Original line number Diff line number Diff line
@@ -126,13 +126,17 @@ void btm_ble_process_adv_pkt_cont_for_inquiry(
    uint8_t advertising_sid, int8_t tx_power, int8_t rssi,
    uint16_t periodic_adv_int, std::vector<uint8_t> advertising_data);

void btif_dm_update_ble_remote_properties(const RawAddress& bd_addr,
extern void btif_dm_update_ble_remote_properties(const RawAddress& bd_addr,
                                                 BD_NAME bd_name,
                                                 DEV_CLASS dev_class,
                                                 tBT_DEVICE_TYPE dev_type);

void btm_ble_process_adv_addr(RawAddress& raw_address,
                              tBLE_ADDR_TYPE* address_type);

extern bool btm_ble_get_appearance_as_cod(std::vector<uint8_t> const& data,
                                          DEV_CLASS dev_class);

using bluetooth::shim::BleScannerInterfaceImpl;

void BleScannerInterfaceImpl::Init() {
@@ -758,6 +762,8 @@ void BleScannerInterfaceImpl::handle_remote_properties(
        advertising_data, HCI_EIR_SHORTENED_LOCAL_NAME_TYPE, &remote_name_len);
  }

  bt_bdname_t bdname = {0};

  // update device name
  if (p_eir_remote_name) {
    if (!address_cache_.find(bd_addr)) {
@@ -772,15 +778,21 @@ void BleScannerInterfaceImpl::handle_remote_properties(
          return;
        }

        bt_bdname_t bdname;
        memcpy(bdname.name, p_eir_remote_name, remote_name_len);
        if (remote_name_len < BD_NAME_LEN + 1)
          bdname.name[remote_name_len] = '\0';

        btif_dm_update_ble_remote_properties(bd_addr, bdname.name, device_type);
        btif_dm_update_ble_remote_properties(bd_addr, bdname.name, NULL,
                                             device_type);
      }
    }
  }

  DEV_CLASS dev_class;
  if (btm_ble_get_appearance_as_cod(advertising_data, dev_class)) {
    btif_dm_update_ble_remote_properties(bd_addr, bdname.name, dev_class,
                                         device_type);
  }

  auto* storage_module = bluetooth::shim::GetStorage();
  bluetooth::hci::Address address = ToGdAddress(bd_addr);

+37 −29
Original line number Diff line number Diff line
@@ -2379,6 +2379,42 @@ static void btm_ble_appearance_to_cod(uint16_t appearance, uint8_t* dev_class) {
  };
}

bool btm_ble_get_appearance_as_cod(std::vector<uint8_t> const& data,
                                   DEV_CLASS dev_class) {
  /* Check to see the BLE device has the Appearance UUID in the advertising
   * data. If it does then try to convert the appearance value to a class of
   * device value Fluoride can use. Otherwise fall back to trying to infer if
   * it is a HID device based on the service class.
   */
  uint8_t len;
  const uint8_t* p_uuid16 = AdvertiseDataParser::GetFieldByType(
      data, BTM_BLE_AD_TYPE_APPEARANCE, &len);
  if (p_uuid16 && len == 2) {
    btm_ble_appearance_to_cod((uint16_t)p_uuid16[0] | (p_uuid16[1] << 8),
                              dev_class);
    return true;
  }

  p_uuid16 = AdvertiseDataParser::GetFieldByType(
      data, BTM_BLE_AD_TYPE_16SRV_CMPL, &len);
  if (p_uuid16 == NULL) {
    return false;
  }

  for (uint8_t i = 0; i + 2 <= len; i = i + 2) {
    /* if this BLE device supports HID over LE, set HID Major in class of
     * device */
    if ((p_uuid16[i] | (p_uuid16[i + 1] << 8)) == UUID_SERVCLASS_LE_HID) {
      dev_class[0] = 0;
      dev_class[1] = BTM_COD_MAJOR_PERIPHERAL;
      dev_class[2] = 0;
      return true;
    }
  }

  return false;
}

/**
 * Update adv packet information into inquiry result.
 */
@@ -2427,35 +2463,7 @@ void btm_ble_update_inq_result(tINQ_DB_ENT* p_i, uint8_t addr_type,
      p_cur->flag = *p_flag;
    }

    /* Check to see the BLE device has the Appearance UUID in the advertising
     * data.  If it does
     * then try to convert the appearance value to a class of device value
     * Bluedroid can use.
     * Otherwise fall back to trying to infer if it is a HID device based on the
     * service class.
     */
    const uint8_t* p_uuid16 = AdvertiseDataParser::GetFieldByType(
        data, BTM_BLE_AD_TYPE_APPEARANCE, &len);
    if (p_uuid16 && len == 2) {
      btm_ble_appearance_to_cod((uint16_t)p_uuid16[0] | (p_uuid16[1] << 8),
                                p_cur->dev_class);
    } else {
      p_uuid16 = AdvertiseDataParser::GetFieldByType(
          data, BTM_BLE_AD_TYPE_16SRV_CMPL, &len);
      if (p_uuid16 != NULL) {
        uint8_t i;
        for (i = 0; i + 2 <= len; i = i + 2) {
          /* if this BLE device support HID over LE, set HID Major in class of
           * device */
          if ((p_uuid16[i] | (p_uuid16[i + 1] << 8)) == UUID_SERVCLASS_LE_HID) {
            p_cur->dev_class[0] = 0;
            p_cur->dev_class[1] = BTM_COD_MAJOR_PERIPHERAL;
            p_cur->dev_class[2] = 0;
            break;
          }
        }
      }
    }
    btm_ble_get_appearance_as_cod(data, p_cur->dev_class);

    const uint8_t* p_rsi =
        AdvertiseDataParser::GetFieldByType(data, BTM_BLE_AD_TYPE_RSI, &len);
+1 −1
Original line number Diff line number Diff line
@@ -141,7 +141,7 @@ void btif_dm_ssp_reply(const RawAddress bd_addr, bt_ssp_variant_t variant,
}
void btif_dm_start_discovery(void) { inc_func_call_count(__func__); }
void btif_dm_update_ble_remote_properties(const RawAddress& bd_addr,
                                          BD_NAME bd_name,
                                          BD_NAME bd_name, DEV_CLASS dev_class,
                                          tBT_DEVICE_TYPE dev_type) {
  inc_func_call_count(__func__);
}
Loading