mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
Added flag to control GATT enable/disable
PiperOrigin-RevId: 538631107
This commit is contained in:
committed by
Copybara-Service
parent
72b249474d
commit
df31f7810c
@@ -35,6 +35,10 @@ constexpr auto kEnableHotspotWin32Socket =
|
||||
constexpr auto kEnablePlatformThreadToNetwork =
|
||||
flags::Flag<bool>(kConfigPackage, "45412711", true);
|
||||
|
||||
// Disable/Enable GATT feature in BLE V2.
|
||||
constexpr auto kEnableBleV2Gatt =
|
||||
flags::Flag<bool>(kConfigPackage, "45415180", true);
|
||||
|
||||
} // namespace nearby_platform_feature
|
||||
} // namespace config_package_nearby
|
||||
} // namespace platform
|
||||
|
||||
@@ -33,7 +33,9 @@
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "internal/flags/nearby_flags.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/flags/nearby_platform_feature_flags.h"
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/windows/utils.h"
|
||||
#include "internal/platform/logging.h"
|
||||
@@ -109,6 +111,13 @@ BleGattClient::~BleGattClient() {
|
||||
|
||||
bool BleGattClient::DiscoverServiceAndCharacteristics(
|
||||
const Uuid& service_uuid, const std::vector<Uuid>& characteristic_uuids) {
|
||||
if (!NearbyFlags::GetInstance().GetBoolFlag(
|
||||
platform::config_package_nearby::nearby_platform_feature::
|
||||
kEnableBleV2Gatt)) {
|
||||
NEARBY_LOGS(WARNING) << __func__ << ": GATT is disabled.";
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string flat_characteristics =
|
||||
absl::StrJoin(characteristic_uuids, ",", [](std::string* out, Uuid uuid) {
|
||||
absl::StrAppend(out, std::string(uuid));
|
||||
|
||||
@@ -29,10 +29,12 @@
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "internal/flags/nearby_flags.h"
|
||||
#include "internal/platform/bluetooth_adapter.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/cancellation_flag_listener.h"
|
||||
#include "internal/platform/flags/nearby_platform_feature_flags.h"
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/windows/ble_gatt_client.h"
|
||||
#include "internal/platform/implementation/windows/ble_gatt_server.h"
|
||||
@@ -369,6 +371,13 @@ std::unique_ptr<api::ble_v2::GattServer> BleV2Medium::StartGattServer(
|
||||
api::ble_v2::ServerGattConnectionCallback callback) {
|
||||
NEARBY_LOGS(INFO) << __func__ << ": Start GATT server.";
|
||||
|
||||
if (!NearbyFlags::GetInstance().GetBoolFlag(
|
||||
platform::config_package_nearby::nearby_platform_feature::
|
||||
kEnableBleV2Gatt)) {
|
||||
NEARBY_LOGS(WARNING) << __func__ << ": GATT is disabled.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto gatt_server =
|
||||
std::make_unique<BleGattServer>(adapter_, std::move(callback));
|
||||
|
||||
@@ -383,6 +392,14 @@ std::unique_ptr<api::ble_v2::GattClient> BleV2Medium::ConnectToGattServer(
|
||||
NEARBY_LOGS(INFO) << "ConnectToGattServer is called, address: "
|
||||
<< peripheral.GetAddress()
|
||||
<< ", power:" << TxPowerLevelToName(tx_power_level);
|
||||
|
||||
if (!NearbyFlags::GetInstance().GetBoolFlag(
|
||||
platform::config_package_nearby::nearby_platform_feature::
|
||||
kEnableBleV2Gatt)) {
|
||||
NEARBY_LOGS(WARNING) << __func__ << ": GATT is disabled.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
try {
|
||||
BluetoothLEDevice ble_device =
|
||||
BluetoothLEDevice::FromBluetoothAddressAsync(
|
||||
|
||||
Reference in New Issue
Block a user