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

Commit 7e8e1c63 authored by Chienyuan's avatar Chienyuan Committed by Chienyuan Huang
Browse files

Add function to check flag exist or not

Bug: 238400713
Test: gd/cert/run
Tag: #refactor
Change-Id: I5598e5c56b0e5a7dbe58fc3d62d4c358a41aaf44
Merged-In: I5598e5c56b0e5a7dbe58fc3d62d4c358a41aaf44
(cherry picked from commit 237731bb)
parent 42439c34
Loading
Loading
Loading
Loading
+21 −39
Original line number Diff line number Diff line
@@ -650,6 +650,15 @@ struct LeAdvertisingManager::impl : public bluetooth::hci::LeAddressManagerCallb
    }
  }

  bool data_has_flags(std::vector<GapData> data) {
    for (auto& gap_data : data) {
      if (gap_data.data_type_ == GapDataType::FLAGS) {
        return true;
      }
    }
    return false;
  }

  bool check_advertising_data(std::vector<GapData> data, bool include_flag) {
    uint16_t data_len = 0;
    // check data size
@@ -659,18 +668,9 @@ struct LeAdvertisingManager::impl : public bluetooth::hci::LeAddressManagerCallb

    // The Flags data type shall be included when any of the Flag bits are non-zero and the advertising packet
    // is connectable. It will be added by set_data() function, we should count it here.
    if (include_flag) {
      bool flag_exist = false;
      for (auto& gap_data : data) {
        if (gap_data.data_type_ == GapDataType::FLAGS) {
          flag_exist = true;
          break;
        }
      }
      if (!flag_exist) {
    if (include_flag && !data_has_flags(data)) {
      data_len += kLenOfFlags;
    }
    }

    if (data_len > le_maximum_advertising_data_length_) {
      LOG_WARN(
@@ -695,18 +695,9 @@ struct LeAdvertisingManager::impl : public bluetooth::hci::LeAddressManagerCallb

    // The Flags data type shall be included when any of the Flag bits are non-zero and the advertising packet
    // is connectable. It will be added by set_data() function, we should count it here.
    if (include_flag) {
      bool flag_exist = false;
      for (auto& gap_data : data) {
        if (gap_data.data_type_ == GapDataType::FLAGS) {
          flag_exist = true;
          break;
        }
      }
      if (!flag_exist) {
    if (include_flag && !data_has_flags(data)) {
      data_len += kLenOfFlags;
    }
    }

    if (data_len > le_maximum_advertising_data_length_) {
      LOG_WARN(
@@ -721,15 +712,7 @@ struct LeAdvertisingManager::impl : public bluetooth::hci::LeAddressManagerCallb
  void set_data(AdvertiserId advertiser_id, bool set_scan_rsp, std::vector<GapData> data) {
    // The Flags data type shall be included when any of the Flag bits are non-zero and the advertising packet
    // is connectable.
    if (!set_scan_rsp && advertising_sets_[advertiser_id].connectable) {
      bool flag_exist = false;
      for (auto& gap_data : data) {
        if (gap_data.data_type_ == GapDataType::FLAGS) {
          flag_exist = true;
          break;
        }
      }
      if (!flag_exist) {
    if (!set_scan_rsp && advertising_sets_[advertiser_id].connectable && !data_has_flags(data)) {
      GapData gap_data;
      gap_data.data_type_ = GapDataType::FLAGS;
      if (advertising_sets_[advertiser_id].duration == 0) {
@@ -739,7 +722,6 @@ struct LeAdvertisingManager::impl : public bluetooth::hci::LeAddressManagerCallb
      }
      data.insert(data.begin(), gap_data);
    }
    }

    // Find and fill TX Power with the correct value.
    for (auto& gap_data : data) {