Added flag to control whether enable base64 in BLE advertisement header

PiperOrigin-RevId: 513924031
This commit is contained in:
Guogang Li
2023-03-06 07:03:30 -08:00
committed by Copybara-Service
parent 2eff1c383c
commit 4f7b61ad79
2 changed files with 15 additions and 4 deletions
@@ -22,6 +22,8 @@
#include "absl/strings/str_cat.h"
#include "internal/platform/base64_utils.h"
#include "internal/platform/base_input_stream.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/feature_flags.h"
#include "internal/platform/logging.h"
namespace nearby {
@@ -57,10 +59,12 @@ BleAdvertisementHeader::BleAdvertisementHeader(
ByteArray advertisement_header_bytes =
Base64Utils::Decode(ble_advertisement_header_bytes.AsStringView());
if (advertisement_header_bytes.Empty()) {
// The BLE advertisement header is not encoded in base64, but still try to
// parse it as raw bytes.
NEARBY_LOG(
ERROR,
WARNING,
"Cannot deserialize BLEAdvertisementHeader: failed Base64 decoding");
return;
advertisement_header_bytes = ble_advertisement_header_bytes;
}
if (advertisement_header_bytes.size() < kMinAdvertisementHeaderLength) {
@@ -138,8 +142,13 @@ BleAdvertisementHeader::operator ByteArray() const {
std::string(advertisement_hash_),
std::string(psm_bytes));
// clang-format on
return ByteArray(Base64Utils::Encode(ByteArray(std::move(out))));
if (FeatureFlags::GetInstance()
.GetFlags()
.enable_ble_v2_advertisement_base64_encoding) {
return ByteArray(Base64Utils::Encode(ByteArray(std::move(out))));
} else {
return ByteArray(std::move(out));
}
}
bool BleAdvertisementHeader::operator==(
+2
View File
@@ -47,6 +47,8 @@ class FeatureFlags {
bool support_multiple_bwu_mediums = true;
// Ble v2/v1 switch flag: the flag will be removed once v2 refactor is done.
bool support_ble_v2 = false;
// Controls BLE advertisement data format in base64 or not.
bool enable_ble_v2_advertisement_base64_encoding = false;
// Allows the code to change the bluetooth radio state
bool enable_set_radio_state = false;
// If the feature is enabled, medium connection will timeout when cannot