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

Commit 7e369d9a authored by Alice Kuo's avatar Alice Kuo
Browse files

Fix the wrong conversion of tags

1. Concatenate tags by ";"
2. Avoid to add the redundant concatenated char in the end

Bug: 274106369
Test: atest bluetooth_le_audio_client_test
Change-Id: Ie37a63fa8ca3e1a27e09b998eb4f71bbd798867d
parent e976df30
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -115,8 +115,8 @@ ndk::ScopedAStatus BluetoothAudioPortImpl::updateSourceMetadata(
    if (num_of_tags != 0) {
      int copied_size = 0;
      int max_tags_size = sizeof(desc_track.tags);
      for (auto tag : track.tags) {
        int string_len = tag.length();
      for (size_t i = 0; i < num_of_tags - 1; i++) {
        int string_len = track.tags[i].length();

        if ((copied_size >= max_tags_size) ||
            (copied_size + string_len >= max_tags_size)) {
@@ -125,10 +125,19 @@ ndk::ScopedAStatus BluetoothAudioPortImpl::updateSourceMetadata(
          break;
        }

        tag.copy(desc_track.tags + copied_size, string_len, 0);
        strncat(desc_track.tags, ",", 1);
        track.tags[i].copy(desc_track.tags + copied_size, string_len, 0);
        strncat(desc_track.tags, ";", 1);
        copied_size += string_len + 1;
      }

      int string_len = track.tags[num_of_tags - 1].length();
      if ((copied_size >= max_tags_size) ||
          (copied_size + string_len >= max_tags_size)) {
        LOG(ERROR) << __func__ << "Too many tags, copied size: " << copied_size;
      } else {
        track.tags[num_of_tags - 1].copy(desc_track.tags + copied_size,
                                         string_len, 0);
      }
    } else {
      memset(desc_track.tags, 0, sizeof(desc_track.tags));
    }