mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Use DCT flag to control BLE encoding
PiperOrigin-RevId: 756496067
This commit is contained in:
committed by
Copybara-Service
parent
e1c072e797
commit
f7e96e518c
@@ -423,6 +423,7 @@ let package = Package(
|
||||
"internal/weave/sockets/BUILD",
|
||||
"internal/platform/flags/BUILD",
|
||||
"internal/platform/implementation/shared/BUILD",
|
||||
"internal/platform/implementation/apple/Flags/BUILD",
|
||||
"internal/platform/implementation/apple/Mediums/BUILD",
|
||||
"internal/platform/implementation/apple/Mediums/Ble/Sockets/BUILD",
|
||||
"internal/platform/implementation/apple/Tests/BUILD",
|
||||
|
||||
@@ -118,6 +118,7 @@ objc_library(
|
||||
"//internal/platform:cancellation_flag",
|
||||
"//internal/platform:uuid",
|
||||
"//internal/platform/implementation:comm",
|
||||
"//internal/platform/implementation/apple/Flags",
|
||||
"//internal/platform/implementation/apple/Mediums",
|
||||
"//internal/platform/implementation/apple/Mediums/Ble/Sockets:Central",
|
||||
"//internal/platform/implementation/apple/Mediums/Ble/Sockets:Peripheral",
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
# Copyright 2025 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.
|
||||
licenses(["notice"])
|
||||
|
||||
package(default_visibility = [
|
||||
"//internal/platform/implementation/apple:__subpackages__",
|
||||
])
|
||||
|
||||
objc_library(
|
||||
name = "Flags",
|
||||
srcs = ["GNCFeatureFlags.mm"],
|
||||
hdrs = ["GNCFeatureFlags.h"],
|
||||
deps = [
|
||||
"//connections/implementation/flags:connections_flags",
|
||||
"//internal/flags:nearby_flags",
|
||||
"//third_party/apple_frameworks:Foundation",
|
||||
],
|
||||
)
|
||||
@@ -0,0 +1,23 @@
|
||||
// Copyright 2025 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 <Foundation/Foundation.h>
|
||||
|
||||
/** A utility class for accessing and overriding Nearby feature flags. */
|
||||
@interface GNCFeatureFlags : NSObject
|
||||
|
||||
/** Checks whether DCT is enabled in the Nearby Connections SDK. */
|
||||
@property(nonatomic, class, readonly) BOOL dctEnabled;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright 2025 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 "internal/platform/implementation/apple/Flags/GNCFeatureFlags.h"
|
||||
|
||||
#include "connections/implementation/flags/nearby_connections_feature_flags.h"
|
||||
#include "internal/flags/nearby_flags.h"
|
||||
|
||||
@implementation GNCFeatureFlags
|
||||
|
||||
+ (BOOL)dctEnabled {
|
||||
return nearby::NearbyFlags::GetInstance().GetBoolFlag(
|
||||
nearby::connections::config_package_nearby::nearby_connections_feature::kEnableDct);
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -17,6 +17,7 @@
|
||||
#import <CoreBluetooth/CoreBluetooth.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "internal/platform/implementation/apple/Flags/GNCFeatureFlags.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCBLEError.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCBLEGATTCharacteristic.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCPeripheralManager.h"
|
||||
@@ -204,11 +205,8 @@ static char *const kGNCBLEGATTServerQueueLabel = "com.nearby.GNCBLEGATTServer";
|
||||
// data is unavailable.
|
||||
CBUUID *serviceUUID = [serviceData.allKeys objectAtIndex:0];
|
||||
NSData *value = [serviceData objectForKey:serviceUUID];
|
||||
#if defined(NC_IOS_SDK)
|
||||
NSString *encoded = [value base85EncodedString];
|
||||
#else
|
||||
NSString *encoded = [value webSafeBase64EncodedString];
|
||||
#endif // defined(NC_IOS_SDK)
|
||||
NSString *encoded = GNCFeatureFlags.dctEnabled ? [value base85EncodedString]
|
||||
: [value webSafeBase64EncodedString];
|
||||
|
||||
// 23 bytes is the standard length which we used in the NC protocol with PSM. The BLE v2
|
||||
// advertisement header is default with psm value included so the length is always 23 bytes.
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#import <CoreBluetooth/CoreBluetooth.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "internal/platform/implementation/apple/Flags/GNCFeatureFlags.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCBLEError.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCBLEGATTClient.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCBLEGATTServer.h"
|
||||
@@ -283,11 +284,10 @@ static GNCBLEL2CAPServer *_Nonnull CreateL2CapServer(
|
||||
if (!localName) {
|
||||
return @{};
|
||||
}
|
||||
#if defined(NC_IOS_SDK)
|
||||
NSData *data = [[NSData alloc] initWithBase85EncodedString:localName];
|
||||
#else
|
||||
NSData *data = [[NSData alloc] initWithWebSafeBase64EncodedString:localName];
|
||||
#endif // defined(NC_IOS_SDK)
|
||||
|
||||
NSData *data = GNCFeatureFlags.dctEnabled
|
||||
? [[NSData alloc] initWithBase85EncodedString:localName]
|
||||
: [[NSData alloc] initWithWebSafeBase64EncodedString:localName];
|
||||
|
||||
// A Nearby Apple advertisement should only have a single service, so simply grab the first one if
|
||||
// it exists.
|
||||
|
||||
@@ -79,6 +79,7 @@ objc_library(
|
||||
deps = [
|
||||
"//internal/encoding:base85",
|
||||
"//internal/platform/implementation/apple:Shared",
|
||||
"//internal/platform/implementation/apple/Flags",
|
||||
"//internal/platform/implementation/apple/Mediums/Ble/Sockets:Shared",
|
||||
"//proto/mediums:ble_frames_cc_proto",
|
||||
"//third_party/apple_frameworks:CoreBluetooth",
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
|
||||
#import "internal/platform/implementation/apple/Flags/GNCFeatureFlags.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCBLEGATTClient.h"
|
||||
#import "internal/platform/implementation/apple/ble_utils.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
@@ -128,15 +129,15 @@ bool GattClient::SetCharacteristicSubscription(
|
||||
}
|
||||
|
||||
void GattClient::Disconnect() {
|
||||
// There seems to be an issue between some iOS<>Android device pairs where the Android device will
|
||||
// not connect to the iOS device if the iOS device disconnects and then attempts to reconnect.
|
||||
// Because of this, we no-op here instead of calling `[gatt_client_ disconnect]`.
|
||||
// See: b/375176623
|
||||
#if defined(NC_IOS_SDK)
|
||||
// Avoid to impact GTV functionality, put the disconnect for NC iOS SDK only, so thatGATT client
|
||||
// can reconnect to the GATT server.
|
||||
[gatt_client_ disconnect];
|
||||
#endif
|
||||
// There seems to be an issue between some iOS<>Android device pairs where the Android device will
|
||||
// not connect to the iOS device if the iOS device disconnects and then attempts to reconnect.
|
||||
// Because of this, we no-op here instead of calling `[gatt_client_ disconnect]`.
|
||||
// See: b/375176623
|
||||
if (GNCFeatureFlags.dctEnabled) {
|
||||
// Avoid to impact GTV functionality, put the disconnect for NC iOS SDK only, so thatGATT client
|
||||
// can reconnect to the GATT server.
|
||||
[gatt_client_ disconnect];
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace apple
|
||||
|
||||
Reference in New Issue
Block a user