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

Commit 8796e4ec authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add function to check flag exist or not" am: 86daad9b

parents 1f9f5d53 86daad9b
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) {