From 5fb7f698304b1599a6b3c49bf55059146b16dab6 Mon Sep 17 00:00:00 2001 From: Nick Bourdakos Date: Tue, 23 Jan 2024 08:01:14 -0800 Subject: [PATCH] Expose `NearbyFlags` through Objective-C package so BLE v2 can more easily be enabled in the Swift SDK PiperOrigin-RevId: 600790011 --- connections/swift/NearbyCoreAdapter/BUILD | 4 ++- .../NearbyCoreAdapter/Sources/GNCFlags.mm | 36 +++++++++++++++++++ .../Public/NearbyCoreAdapter/GNCFlags.h | 23 ++++++++++++ .../NearbyCoreAdapter/NearbyCoreAdapter.h | 1 + 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 connections/swift/NearbyCoreAdapter/Sources/GNCFlags.mm create mode 100644 connections/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/GNCFlags.h diff --git a/connections/swift/NearbyCoreAdapter/BUILD b/connections/swift/NearbyCoreAdapter/BUILD index e6103c51..7b588d83 100644 --- a/connections/swift/NearbyCoreAdapter/BUILD +++ b/connections/swift/NearbyCoreAdapter/BUILD @@ -12,9 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +load("//third_party/nearby:minimum_os.bzl", "IOS_LATEST_TEST_RUNNER", "IOS_MINIMUM_OS") load("//tools/build_defs/apple:ios.bzl", "ios_unit_test") load("//tools/build_defs/swift:swift_library.bzl", "swift_library") -load("//third_party/nearby:minimum_os.bzl", "IOS_LATEST_TEST_RUNNER", "IOS_MINIMUM_OS") licenses(["notice"]) @@ -33,6 +33,8 @@ objc_library( deps = [ "//connections:core", "//connections:core_types", + "//connections/implementation/flags:connections_flags", + "//internal/flags:nearby_flags", "//internal/platform:base", "//internal/platform/implementation/apple", # buildcleaner: keep "//third_party/apple_frameworks:Foundation", diff --git a/connections/swift/NearbyCoreAdapter/Sources/GNCFlags.mm b/connections/swift/NearbyCoreAdapter/Sources/GNCFlags.mm new file mode 100644 index 00000000..7b5cb6ba --- /dev/null +++ b/connections/swift/NearbyCoreAdapter/Sources/GNCFlags.mm @@ -0,0 +1,36 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import "connections/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/GNCFlags.h" + +#import + +#include + +#include "connections/implementation/flags/nearby_connections_feature_flags.h" +#include "internal/flags/nearby_flags.h" + +@implementation GNCFlags + ++ (BOOL)enableBLEV2 { + return nearby::NearbyFlags::GetInstance().GetBoolFlag( + nearby::connections::config_package_nearby::nearby_connections_feature::kEnableBleV2); +} + ++ (void)setEnableBLEV2:(BOOL)value { + nearby::NearbyFlags::GetInstance().OverrideBoolFlagValue( + nearby::connections::config_package_nearby::nearby_connections_feature::kEnableBleV2, value); +} + +@end diff --git a/connections/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/GNCFlags.h b/connections/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/GNCFlags.h new file mode 100644 index 00000000..19b953a5 --- /dev/null +++ b/connections/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/GNCFlags.h @@ -0,0 +1,23 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import + +/** A utility class for accessing and overriding Nearby feature flags. */ +@interface GNCFlags : NSObject + +/** Whether BLE v2 is enabled in the Nearby Connections SDK. */ +@property(nonatomic, class) BOOL enableBLEV2; + +@end diff --git a/connections/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/NearbyCoreAdapter.h b/connections/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/NearbyCoreAdapter.h index 26d37bbc..1c034feb 100644 --- a/connections/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/NearbyCoreAdapter.h +++ b/connections/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/NearbyCoreAdapter.h @@ -19,6 +19,7 @@ #import "GNCDiscoveryDelegate.h" #import "GNCDiscoveryOptions.h" #import "GNCError.h" +#import "GNCFlags.h" #import "GNCPayload.h" #import "GNCPayloadDelegate.h" #import "GNCStrategy.h"