mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Merge remote-tracking branch 'google/main'
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#define THIRD_PARTY_NEARBY_CONNECTIONS_IMPLEMENTATION_FLAGS_NEARBY_CONNECTIONS_FEATURE_FLAGS_H_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/flags/flag.h"
|
||||
|
||||
@@ -52,10 +53,10 @@ constexpr auto kEnableSafeToDisconnect =
|
||||
constexpr auto kEnablePayloadReceivedAck =
|
||||
flags::Flag<bool>(kConfigPackage, "45425840", false);
|
||||
|
||||
// Support 1. safe-to-disconnect 2. reserved 3. auto-reconnect
|
||||
// Support 0. disabled all. 1. safe-to-disconnect 2. reserved 3. auto-reconnect
|
||||
// 4. auto-resume for dev device 5. payload_ack
|
||||
constexpr auto kSafeToDisconnectVersion =
|
||||
flags::Flag<int64_t>(kConfigPackage, "45425841", 2);
|
||||
flags::Flag<int64_t>(kConfigPackage, "45425841", 0);
|
||||
|
||||
} // namespace nearby_connections_feature
|
||||
} // namespace config_package_nearby
|
||||
|
||||
@@ -269,7 +269,7 @@ TEST(OfflineFramesTest, CanGenerateConnectionResponse) {
|
||||
status: 1
|
||||
response: REJECT
|
||||
os_info { type: LINUX }
|
||||
safe_to_disconnect_version: 2
|
||||
safe_to_disconnect_version: 0
|
||||
>
|
||||
>)pb";
|
||||
|
||||
|
||||
@@ -120,6 +120,7 @@ cc_library(
|
||||
"//internal/network:__subpackages__",
|
||||
"//internal/platform:__pkg__",
|
||||
"//internal/platform/implementation:__subpackages__",
|
||||
"//location/nearby/analytics/cpp:__subpackages__",
|
||||
"//location/nearby/cpp/sharing:__subpackages__",
|
||||
"//third_party/nearby/sharing:__subpackages__",
|
||||
],
|
||||
|
||||
@@ -205,10 +205,13 @@ static char *const kGNCBLEGATTServerQueueLabel = "com.nearby.GNCBLEGATTServer";
|
||||
NSData *value = [serviceData objectForKey:serviceUUID];
|
||||
NSString *encoded = [value webSafeBase64EncodedString];
|
||||
|
||||
// Base64 encoding increases the size of the data so we must truncate it to 22 bytes to ensure
|
||||
// it fits in the advertisement alongside an assumed 16-bit serviceUUID.
|
||||
if (encoded.length > 22) {
|
||||
encoded = [encoded substringToIndex:22];
|
||||
// Apple only "guarantees" (best effort) 28 bytes of advertisement data. Base64 encoding
|
||||
// increases the size of the original data so we must truncate it to ensure it still meets the
|
||||
// 28 byte limit. Since we have a 2-byte service UUID and the header for local name and service
|
||||
// UUID is 2 bytes each, that leaves us with a maximum of 22 bytes for the local name. However,
|
||||
// it seems in practice we can only reliably advertise a 20-byte local name on iOS.
|
||||
if (encoded.length > 20) {
|
||||
encoded = [encoded substringToIndex:20];
|
||||
}
|
||||
|
||||
_advertisementData = @{
|
||||
|
||||
-2
@@ -284,8 +284,6 @@ static NSTimeInterval gKBTCrashLoopMaxTimeBetweenResetting = 15.f;
|
||||
|
||||
GTMLoggerInfo(@"Start advertising: %@", advertisementData);
|
||||
_advertisementInProgressData = [advertisementData copy];
|
||||
[_cbPeripheralManager stopAdvertising];
|
||||
[_cbPeripheralManager startAdvertising:_advertisementInProgressData];
|
||||
}
|
||||
|
||||
#pragma mark - Private
|
||||
|
||||
@@ -431,7 +431,7 @@ static NSString *const kCharacteristicUUID2 = @"00000000-0000-3000-8000-00000000
|
||||
[self waitForExpectations:@[ expectation ] timeout:3];
|
||||
}
|
||||
|
||||
- (void)testStartAdvertising22ByteServiceData {
|
||||
- (void)testStartAdvertising20ByteServiceData {
|
||||
GNCFakePeripheralManager *fakePeripheralManager = [[GNCFakePeripheralManager alloc] init];
|
||||
|
||||
GNCBLEGATTServer *gattServer =
|
||||
@@ -443,14 +443,14 @@ static NSString *const kCharacteristicUUID2 = @"00000000-0000-3000-8000-00000000
|
||||
[[XCTestExpectation alloc] initWithDescription:@"Start advertising."];
|
||||
|
||||
[gattServer startAdvertisingData:@{
|
||||
[CBUUID UUIDWithString:@"FEF3"] : [@"0123456789012345" dataUsingEncoding:NSUTF8StringEncoding],
|
||||
[CBUUID UUIDWithString:@"FEF3"] : [@"012345678901234" dataUsingEncoding:NSUTF8StringEncoding],
|
||||
}
|
||||
completionHandler:^(NSError *error) {
|
||||
XCTAssertNil(error);
|
||||
XCTAssertTrue(fakePeripheralManager.isAdvertising);
|
||||
NSDictionary<NSString *, id> *data = fakePeripheralManager.advertisementData;
|
||||
XCTAssertEqualObjects(data[CBAdvertisementDataLocalNameKey],
|
||||
@"MDEyMzQ1Njc4OTAxMjM0NQ");
|
||||
@"MDEyMzQ1Njc4OTAxMjM0");
|
||||
XCTAssertEqualObjects(data[CBAdvertisementDataServiceUUIDsKey][0],
|
||||
[CBUUID UUIDWithString:@"FEF3"]);
|
||||
[expectation fulfill];
|
||||
@@ -479,7 +479,7 @@ static NSString *const kCharacteristicUUID2 = @"00000000-0000-3000-8000-00000000
|
||||
XCTAssertNil(error);
|
||||
XCTAssertTrue(fakePeripheralManager.isAdvertising);
|
||||
NSDictionary<NSString *, id> *data = fakePeripheralManager.advertisementData;
|
||||
XCTAssertEqualObjects(data[CBAdvertisementDataLocalNameKey], @"MDEyMzQ1Njc4OTAxMjM0NT");
|
||||
XCTAssertEqualObjects(data[CBAdvertisementDataLocalNameKey], @"MDEyMzQ1Njc4OTAxMjM0");
|
||||
XCTAssertEqualObjects(data[CBAdvertisementDataServiceUUIDsKey][0],
|
||||
[CBUUID UUIDWithString:@"FEF3"]);
|
||||
[expectation fulfill];
|
||||
|
||||
@@ -143,11 +143,8 @@ class BleMedium : public api::ble_v2::BleMedium {
|
||||
api::ble_v2::BleMedium::GetRemotePeripheralCallback callback) override;
|
||||
|
||||
private:
|
||||
void HandleAdvertisementFound(
|
||||
id<GNCPeripheral> peripheral, NSDictionary<CBUUID *, NSData *> *serviceData,
|
||||
absl::AnyInvocable<void(api::ble_v2::BlePeripheral &peripheral,
|
||||
api::ble_v2::BleAdvertisementData advertisement_data)>
|
||||
callback);
|
||||
void HandleAdvertisementFound(id<GNCPeripheral> peripheral,
|
||||
NSDictionary<CBUUID *, NSData *> *serviceData);
|
||||
|
||||
GNCBLEMedium *medium_;
|
||||
|
||||
@@ -155,9 +152,17 @@ class BleMedium : public api::ble_v2::BleMedium {
|
||||
absl::flat_hash_map<api::ble_v2::BlePeripheral::UniqueId, std::unique_ptr<BlePeripheral>>
|
||||
peripherals_ ABSL_GUARDED_BY(peripherals_mutex_);
|
||||
|
||||
std::unique_ptr<EmptyBlePeripheral> local_peripheral_;
|
||||
|
||||
GNSPeripheralServiceManager *socketPeripheralServiceManager_;
|
||||
GNSPeripheralManager *socketPeripheralManager_;
|
||||
GNSCentralManager *socketCentralManager_;
|
||||
|
||||
// Used for the blocking version of StartAdvertising and only has an advertisement found callback.
|
||||
api::ble_v2::BleMedium::ScanCallback scan_cb_;
|
||||
// Used for the async version of StartAdvertising and has both an advertisement found and result
|
||||
// callback.
|
||||
api::ble_v2::BleMedium::ScanningCallback scanning_cb_;
|
||||
};
|
||||
|
||||
} // namespace apple
|
||||
|
||||
@@ -65,6 +65,8 @@ std::unique_ptr<api::ble_v2::BleMedium::AdvertisingSession> BleMedium::StartAdve
|
||||
|
||||
__block api::ble_v2::BleMedium::AdvertisingCallback blockCallback = std::move(callback);
|
||||
|
||||
[socketPeripheralManager_ start];
|
||||
|
||||
[medium_ startAdvertisingData:serviceData
|
||||
completionHandler:^(NSError *error) {
|
||||
blockCallback.start_advertising_result(
|
||||
@@ -82,6 +84,8 @@ bool BleMedium::StartAdvertising(const api::ble_v2::BleAdvertisementData &advert
|
||||
NSMutableDictionary<CBUUID *, NSData *> *serviceData =
|
||||
ObjCServiceDataFromCPP(advertising_data.service_data);
|
||||
|
||||
[socketPeripheralManager_ start];
|
||||
|
||||
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
|
||||
__block NSError *blockError = nil;
|
||||
[medium_ startAdvertisingData:serviceData
|
||||
@@ -97,6 +101,8 @@ bool BleMedium::StartAdvertising(const api::ble_v2::BleAdvertisementData &advert
|
||||
}
|
||||
|
||||
bool BleMedium::StopAdvertising() {
|
||||
[socketPeripheralManager_ stop];
|
||||
|
||||
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
|
||||
__block NSError *blockError = nil;
|
||||
[medium_ stopAdvertisingWithCompletionHandler:^(NSError *error) {
|
||||
@@ -110,11 +116,8 @@ bool BleMedium::StopAdvertising() {
|
||||
return blockError == nil;
|
||||
}
|
||||
|
||||
void BleMedium::HandleAdvertisementFound(
|
||||
id<GNCPeripheral> peripheral, NSDictionary<CBUUID *, NSData *> *serviceData,
|
||||
absl::AnyInvocable<void(api::ble_v2::BlePeripheral &peripheral,
|
||||
api::ble_v2::BleAdvertisementData advertisement_data)>
|
||||
callback) {
|
||||
void BleMedium::HandleAdvertisementFound(id<GNCPeripheral> peripheral,
|
||||
NSDictionary<CBUUID *, NSData *> *serviceData) {
|
||||
absl::MutexLock lock(&peripherals_mutex_);
|
||||
[socketCentralManager_ retrievePeripheralWithIdentifier:peripheral.identifier
|
||||
advertisementData:@{}];
|
||||
@@ -131,14 +134,19 @@ void BleMedium::HandleAdvertisementFound(
|
||||
if (it == peripherals_.end()) {
|
||||
peripherals_[unique_id] = std::move(ble_peripheral);
|
||||
}
|
||||
callback(*peripherals_[unique_id], data);
|
||||
if (scanning_cb_.advertisement_found_cb) {
|
||||
scanning_cb_.advertisement_found_cb(*peripherals_[unique_id], data);
|
||||
}
|
||||
if (scan_cb_.advertisement_found_cb) {
|
||||
scan_cb_.advertisement_found_cb(*peripherals_[unique_id], data);
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<api::ble_v2::BleMedium::ScanningSession> BleMedium::StartScanning(
|
||||
const Uuid &service_uuid, api::ble_v2::TxPowerLevel tx_power_level,
|
||||
api::ble_v2::BleMedium::ScanningCallback callback) {
|
||||
CBUUID *serviceUUID = CBUUID128FromCPP(service_uuid);
|
||||
__block api::ble_v2::BleMedium::ScanningCallback blockCallback = std::move(callback);
|
||||
scanning_cb_ = std::move(callback);
|
||||
|
||||
socketCentralManager_ = [[GNSCentralManager alloc] initWithSocketServiceUUID:serviceUUID];
|
||||
[socketCentralManager_ startNoScanModeWithAdvertisedServiceUUIDs:@[ serviceUUID ]];
|
||||
@@ -146,13 +154,14 @@ std::unique_ptr<api::ble_v2::BleMedium::ScanningSession> BleMedium::StartScannin
|
||||
[medium_ startScanningForService:serviceUUID
|
||||
advertisementFoundHandler:^(id<GNCPeripheral> peripheral,
|
||||
NSDictionary<CBUUID *, NSData *> *serviceData) {
|
||||
HandleAdvertisementFound(peripheral, serviceData,
|
||||
std::move(blockCallback.advertisement_found_cb));
|
||||
HandleAdvertisementFound(peripheral, serviceData);
|
||||
}
|
||||
completionHandler:^(NSError *error) {
|
||||
blockCallback.start_scanning_result(
|
||||
error == nil ? absl::OkStatus()
|
||||
: absl::InternalError(error.localizedDescription.UTF8String));
|
||||
if (scanning_cb_.start_scanning_result) {
|
||||
scanning_cb_.start_scanning_result(
|
||||
error == nil ? absl::OkStatus()
|
||||
: absl::InternalError(error.localizedDescription.UTF8String));
|
||||
}
|
||||
}];
|
||||
|
||||
return std::make_unique<ScanningSession>(ScanningSession{.stop_scanning = [this] {
|
||||
@@ -163,7 +172,7 @@ std::unique_ptr<api::ble_v2::BleMedium::ScanningSession> BleMedium::StartScannin
|
||||
bool BleMedium::StartScanning(const Uuid &service_uuid, api::ble_v2::TxPowerLevel tx_power_level,
|
||||
api::ble_v2::BleMedium::ScanCallback callback) {
|
||||
CBUUID *serviceUUID = CBUUID128FromCPP(service_uuid);
|
||||
__block api::ble_v2::BleMedium::ScanCallback blockCallback = std::move(callback);
|
||||
scan_cb_ = std::move(callback);
|
||||
|
||||
socketCentralManager_ = [[GNSCentralManager alloc] initWithSocketServiceUUID:serviceUUID];
|
||||
[socketCentralManager_ startNoScanModeWithAdvertisedServiceUUIDs:@[ serviceUUID ]];
|
||||
@@ -173,8 +182,7 @@ bool BleMedium::StartScanning(const Uuid &service_uuid, api::ble_v2::TxPowerLeve
|
||||
[medium_ startScanningForService:serviceUUID
|
||||
advertisementFoundHandler:^(id<GNCPeripheral> peripheral,
|
||||
NSDictionary<CBUUID *, NSData *> *serviceData) {
|
||||
HandleAdvertisementFound(peripheral, serviceData,
|
||||
std::move(blockCallback.advertisement_found_cb));
|
||||
HandleAdvertisementFound(peripheral, serviceData);
|
||||
}
|
||||
completionHandler:^(NSError *error) {
|
||||
if (error != nil) {
|
||||
@@ -188,6 +196,8 @@ bool BleMedium::StartScanning(const Uuid &service_uuid, api::ble_v2::TxPowerLeve
|
||||
}
|
||||
|
||||
bool BleMedium::StopScanning() {
|
||||
[socketCentralManager_ stopNoScanMode];
|
||||
|
||||
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
|
||||
__block NSError *blockError = nil;
|
||||
[medium_ stopScanningWithCompletionHandler:^(NSError *error) {
|
||||
@@ -255,7 +265,8 @@ std::unique_ptr<api::ble_v2::GattClient> BleMedium::ConnectToGattServer(
|
||||
// TODO(b/293336684): Old Weave code that need to be deleted once shared Weave is complete.
|
||||
std::unique_ptr<api::ble_v2::BleServerSocket> BleMedium::OpenServerSocket(
|
||||
const std::string &service_id) {
|
||||
__block auto server_socket = std::make_unique<BleServerSocket>();
|
||||
auto server_socket = std::make_unique<BleServerSocket>();
|
||||
__block auto server_socket_ptr = server_socket.get();
|
||||
socketPeripheralServiceManager_ = [[GNSPeripheralServiceManager alloc]
|
||||
initWithBleServiceUUID:[CBUUID UUIDWithString:kWeaveServiceUUID]
|
||||
addPairingCharacteristic:NO
|
||||
@@ -263,13 +274,17 @@ std::unique_ptr<api::ble_v2::BleServerSocket> BleMedium::OpenServerSocket(
|
||||
GNCMWaitForConnection(socket, ^(BOOL didConnect) {
|
||||
GNCMBleConnection *connection =
|
||||
[GNCMBleConnection connectionWithSocket:socket
|
||||
serviceID:@(service_id.c_str())
|
||||
// This must be nil as the advertiser even though we
|
||||
// have a service ID available to us.
|
||||
serviceID:nil
|
||||
expectedIntroPacket:YES
|
||||
callbackQueue:dispatch_get_main_queue()];
|
||||
|
||||
auto socket = std::make_unique<BleSocket>(connection);
|
||||
connection.connectionHandlers = socket->GetInputStream().GetConnectionHandlers();
|
||||
server_socket->Connect(std::move(socket));
|
||||
if (server_socket_ptr) {
|
||||
server_socket_ptr->Connect(std::move(socket));
|
||||
}
|
||||
});
|
||||
return YES;
|
||||
}];
|
||||
@@ -363,6 +378,13 @@ bool BleMedium::GetRemotePeripheral(const std::string &mac_address,
|
||||
|
||||
bool BleMedium::GetRemotePeripheral(api::ble_v2::BlePeripheral::UniqueId unique_id,
|
||||
api::ble_v2::BleMedium::GetRemotePeripheralCallback callback) {
|
||||
// If the unique_id is 0, that means it's the local/empty peripheral. We must return "true"
|
||||
// otherwise the connection will be considered invalid and the application will crash.
|
||||
if (unique_id == 0) {
|
||||
callback(*local_peripheral_);
|
||||
return true;
|
||||
}
|
||||
|
||||
BlePeripheral *peripheral;
|
||||
{
|
||||
absl::MutexLock lock(&peripherals_mutex_);
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include <string>
|
||||
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/prng.h"
|
||||
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCPeripheral.h"
|
||||
|
||||
@@ -29,7 +28,7 @@ namespace apple {
|
||||
|
||||
#pragma mark - EmptyBlePeripheral
|
||||
|
||||
EmptyBlePeripheral::EmptyBlePeripheral() : unique_id_(Prng().NextInt64()) {}
|
||||
EmptyBlePeripheral::EmptyBlePeripheral() : unique_id_(0) {}
|
||||
|
||||
std::string EmptyBlePeripheral::GetAddress() const { return ""; }
|
||||
|
||||
|
||||
@@ -68,7 +68,15 @@ api::DeviceInfo::DeviceType DeviceInfo::GetDeviceType() const {
|
||||
#endif
|
||||
}
|
||||
|
||||
api::DeviceInfo::OsType DeviceInfo::GetOsType() const { return api::DeviceInfo::OsType::kIos; }
|
||||
api::DeviceInfo::OsType DeviceInfo::GetOsType() const {
|
||||
#if TARGET_OS_OSX
|
||||
return api::DeviceInfo::OsType::kMacOS;
|
||||
#elif TARGET_OS_IPHONE
|
||||
return api::DeviceInfo::OsType::kIos;
|
||||
#else
|
||||
return api::DeviceInfo::OsType::kUnknown;
|
||||
#endif
|
||||
}
|
||||
|
||||
std::optional<std::u16string> DeviceInfo::GetFullName() const { return std::nullopt; }
|
||||
std::optional<std::u16string> DeviceInfo::GetGivenName() const { return std::nullopt; }
|
||||
|
||||
@@ -28,8 +28,15 @@ namespace api {
|
||||
class DeviceInfo {
|
||||
public:
|
||||
enum class ScreenStatus { kUndetermined = 0, kLocked, kUnlocked };
|
||||
enum class DeviceType { kUnknown = 0, kPhone, kTablet, kLaptop, kDesktop };
|
||||
enum class OsType { kUnknown = 0, kAndroid, kChromeOs, kIos, kWindows, kLinux };
|
||||
enum class DeviceType { kUnknown = 0, kPhone, kTablet, kLaptop };
|
||||
enum class OsType {
|
||||
kUnknown = 0,
|
||||
kAndroid,
|
||||
kChromeOs,
|
||||
kIos,
|
||||
kWindows,
|
||||
kMacOS
|
||||
};
|
||||
|
||||
virtual ~DeviceInfo() = default;
|
||||
|
||||
|
||||
@@ -321,6 +321,9 @@ message ConnectionsLog {
|
||||
|
||||
// The end status of the payload transfer.
|
||||
optional location.nearby.proto.connections.PayloadStatus status = 6;
|
||||
|
||||
// The number of successful auto resume.
|
||||
optional int32 num_successful_auto_resume = 7;
|
||||
}
|
||||
|
||||
// An attempt to upgrade an existing connection from one medium to another.
|
||||
|
||||
@@ -66,6 +66,7 @@ message Metadata {
|
||||
}
|
||||
|
||||
// The type of the device.
|
||||
// LINT.IfChange
|
||||
enum DeviceType {
|
||||
// The type of the device is unknown.
|
||||
DEVICE_TYPE_UNKNOWN = 0;
|
||||
@@ -94,7 +95,14 @@ enum DeviceType {
|
||||
|
||||
// The device is a foldable.
|
||||
DEVICE_TYPE_FOLDABLE = 8;
|
||||
|
||||
// The device is an automotive.
|
||||
DEVICE_TYPE_AUTOMOTIVE = 9;
|
||||
|
||||
// The device is a speaker.
|
||||
DEVICE_TYPE_SPEAKER = 10;
|
||||
}
|
||||
// LINT.ThenChange(//depot/google3/java/com/google/android/gmscore/integ/client/nearby/src/com/google/android/gms/nearby/presence/PresenceDevice.java)
|
||||
|
||||
// The instance type of the metadata.
|
||||
// LINT.IfChange
|
||||
|
||||
@@ -496,6 +496,7 @@ enum ServerActionName {
|
||||
UPLOAD_CONTACTS_AND_CERTIFICATES = 8;
|
||||
LIST_REACHABLE_PHONE_NUMBERS = 9;
|
||||
LIST_MY_DEVICES = 10;
|
||||
LIST_CONTACT_PEOPLE = 11;
|
||||
}
|
||||
|
||||
// The Fast Share server response state.
|
||||
|
||||
Reference in New Issue
Block a user