|
21 | 21 | #include "absl/strings/escaping.h" |
22 | 22 | #include "absl/strings/str_cat.h" |
23 | 23 | #include "absl/strings/string_view.h" |
24 | | -#include "connections/implementation/base_pcp_handler.h" |
25 | 24 | #include "connections/implementation/pcp.h" |
| 25 | +#include "connections/implementation/webrtc_state.h" |
26 | 26 | #include "internal/platform/base64_utils.h" |
27 | 27 | #include "internal/platform/byte_array.h" |
28 | 28 | #include "internal/platform/logging.h" |
@@ -58,6 +58,14 @@ BluetoothDeviceName::BluetoothDeviceName(Version version, Pcp pcp, |
58 | 58 | endpoint_info_ = endpoint_info; |
59 | 59 | uwb_address_ = uwb_address; |
60 | 60 | web_rtc_state_ = web_rtc_state; |
| 61 | + if (endpoint_info_.size() > kMaxEndpointInfoLength) { |
| 62 | + LOG(INFO) |
| 63 | + << "While constructing bluetooth device name, truncating Endpoint Info " |
| 64 | + << absl::BytesToHexString(std::string(endpoint_info_)) << " (" |
| 65 | + << endpoint_info_.size() << " bytes) down to " << kMaxEndpointInfoLength |
| 66 | + << " bytes"; |
| 67 | + endpoint_info_ = ByteArray(endpoint_info_.data(), kMaxEndpointInfoLength); |
| 68 | + } |
61 | 69 | } |
62 | 70 |
|
63 | 71 | BluetoothDeviceName::BluetoothDeviceName( |
@@ -154,6 +162,14 @@ BluetoothDeviceName::BluetoothDeviceName( |
154 | 162 | return; |
155 | 163 | } |
156 | 164 | endpoint_info_ = *endpoint_info_bytes; |
| 165 | + if (endpoint_info_.size() > kMaxEndpointInfoLength) { |
| 166 | + LOG(INFO) << "While deserializing bluetooth device name, truncating " |
| 167 | + "Endpoint Info " |
| 168 | + << absl::BytesToHexString(std::string(endpoint_info_)) << " (" |
| 169 | + << endpoint_info_.size() << " bytes) down to " |
| 170 | + << kMaxEndpointInfoLength << " bytes"; |
| 171 | + endpoint_info_ = ByteArray(endpoint_info_.data(), kMaxEndpointInfoLength); |
| 172 | + } |
157 | 173 |
|
158 | 174 | // If the input stream has extra bytes, it's for UWB address. The first byte |
159 | 175 | // is the address length. It can be 2-byte short address or 8-byte extended |
@@ -203,23 +219,14 @@ BluetoothDeviceName::operator std::string() const { |
203 | 219 |
|
204 | 220 | ByteArray reserved_bytes{kReservedLength}; |
205 | 221 |
|
206 | | - ByteArray usable_endpoint_info(endpoint_info_); |
207 | | - if (endpoint_info_.size() > kMaxEndpointInfoLength) { |
208 | | - LOG(INFO) << "While serializing Advertisement, truncating Endpoint Name " |
209 | | - << absl::BytesToHexString(endpoint_info_.data()) << " (" |
210 | | - << endpoint_info_.size() << " bytes) down to " |
211 | | - << kMaxEndpointInfoLength << " bytes"; |
212 | | - usable_endpoint_info.SetData(endpoint_info_.data(), kMaxEndpointInfoLength); |
213 | | - } |
214 | | - |
215 | 222 | // clang-format off |
216 | 223 | std::string out = absl::StrCat(std::string(1, version_and_pcp_byte), |
217 | 224 | endpoint_id_, |
218 | 225 | std::string(service_id_hash_), |
219 | 226 | std::string(1, field_byte), |
220 | 227 | std::string(reserved_bytes), |
221 | | - std::string(1, usable_endpoint_info.size()), |
222 | | - std::string(usable_endpoint_info)); |
| 228 | + std::string(1, endpoint_info_.size()), |
| 229 | + std::string(endpoint_info_)); |
223 | 230 | // clang-format on |
224 | 231 |
|
225 | 232 | // If UWB address is available, attach it at the end. |
|
0 commit comments