From 52e71b1fc6dd3a9a2addb1e059c11735d87be9bf Mon Sep 17 00:00:00 2001 From: Bhavana Nimma Date: Wed, 10 Apr 2024 11:37:45 +0530 Subject: [PATCH 1/2] Fix for Fast Initiation compilation errors --- a_wasdk_app/DevicesPage.xaml.cpp | 3 ++- a_win32_dll/fast_init.cpp | 12 +++++++++--- a_win32_dll/fast_initiation_advertiser.cc | 19 +++++++++++++++++-- a_win32_dll/nearby_sharing_service_impl.cc | 8 ++++---- a_win32_dll/nearby_sharing_service_impl.h | 2 ++ 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/a_wasdk_app/DevicesPage.xaml.cpp b/a_wasdk_app/DevicesPage.xaml.cpp index 67edcee586..24802d647e 100644 --- a/a_wasdk_app/DevicesPage.xaml.cpp +++ b/a_wasdk_app/DevicesPage.xaml.cpp @@ -223,8 +223,9 @@ namespace winrt::a_wasdk_app::implementation auto work = []() { g_nearby = new NearbyShareAPI(); g_nearby->InitializeNearby(); + //g_nearby->StartFastInitiationAdvertising(); g_nearby->StartScanning2(PhoneDeviceAdded); - + while (true) { Sleep(100); } diff --git a/a_win32_dll/fast_init.cpp b/a_win32_dll/fast_init.cpp index 239f96bcc5..aa45d590ff 100644 --- a/a_win32_dll/fast_init.cpp +++ b/a_win32_dll/fast_init.cpp @@ -209,7 +209,7 @@ namespace device { bool BluetoothAdvertisementWinrt::Initialize( std::unique_ptr advertisement_data) { - if (advertisement_data->service_uuids()) { + /*if (advertisement_data->service_uuids()) { BLUETOOTH_LOG(ERROR) << "Windows does not support advertising Service UUIDs."; return false; @@ -225,7 +225,7 @@ namespace device { BLUETOOTH_LOG(ERROR) << "Windows does not support advertising Service Data."; return false; - } + }*/ auto manufacturer_data = advertisement_data->manufacturer_data(); if (!manufacturer_data) { @@ -251,7 +251,7 @@ namespace device { return false; } - for (const auto& pair : *manufacturer_data) { + for (const auto& pair : *manufacturer_data) { uint16_t manufacturer = pair.first; const std::vector& data = pair.second; @@ -442,6 +442,12 @@ namespace device { adapter_->Initialize([this]() { AdapterInitialized(); }); + + BluetoothAdapter* adapter = + std::move(adapter_); + std::vector callbacks = std::move(adapter_callbacks_); + for (auto& callback : callbacks) + std::move(callback)(adapter); return; } diff --git a/a_win32_dll/fast_initiation_advertiser.cc b/a_win32_dll/fast_initiation_advertiser.cc index 12cbc07a7a..7cba638bf6 100644 --- a/a_win32_dll/fast_initiation_advertiser.cc +++ b/a_win32_dll/fast_initiation_advertiser.cc @@ -64,10 +64,10 @@ void FastInitiationAdvertiser::StartAdvertising( FastInitType type, OnceClosure callback, OnceClosure error_callback) { - if (!(adapter_->IsPresent() && adapter_->IsPowered())) + /*if (!(adapter_->IsPresent() && adapter_->IsPowered())) { return; - } + }*/ //DCHECK(!advertisement_); RegisterAdvertisement(type, std::move(callback), std::move(error_callback)); } @@ -100,6 +100,21 @@ void FastInitiationAdvertiser::RegisterAdvertisement( kFastInitiationServiceUuid, payload)); advertisement_data->set_service_data(std::move(service_data)); + // Construct Manufacturer data + device::BluetoothAdvertisement::ManufacturerData manufacturer_data; + uint16_t manufacturerId = 0x0006; // Placeholder value for manufacturer ID + + auto payload1 = std::vector(std::begin(kFastInitiationServiceId), + std::end(kFastInitiationServiceId)); + payload1.insert(std::end(payload1), std::begin(kFastInitiationModelId), std::end(kFastInitiationModelId)); + auto metadata1 = GenerateFastInitV1Metadata(type); + payload1.insert(std::end(payload1), std::begin(metadata1), std::end(metadata1)); + + manufacturer_data.insert(std::pair>( + manufacturerId, payload1)); + + advertisement_data->set_manufacturer_data(manufacturer_data); + adapter_->RegisterAdvertisement( std::move(advertisement_data), [this, callback](device::BluetoothAdvertisement* advertisement) { diff --git a/a_win32_dll/nearby_sharing_service_impl.cc b/a_win32_dll/nearby_sharing_service_impl.cc index 5d2bf49a7e..d17e23a47e 100644 --- a/a_win32_dll/nearby_sharing_service_impl.cc +++ b/a_win32_dll/nearby_sharing_service_impl.cc @@ -170,13 +170,13 @@ void NearbySharingServiceImpl::GetBluetoothAdapter() OnGetBluetoothAdapter(adapter); }); - base::SequencedTaskRunner::GetCurrentDefault()->PostTask( + /*base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce( &device::BluetoothAdapterFactory::GetAdapter, base::Unretained(adapter_factory), base::BindOnce(&NearbySharingServiceImpl::OnGetBluetoothAdapter, - weak_ptr_factory_.GetWeakPtr()))); + weak_ptr_factory_.GetWeakPtr())));*/ } void NearbySharingServiceImpl::OnGetBluetoothAdapter( @@ -184,8 +184,8 @@ void NearbySharingServiceImpl::OnGetBluetoothAdapter( { bluetooth_adapter_ = nullptr; bluetooth_adapter_ = std::unique_ptr(adapter); - bluetooth_adapter_->AddObserver(this); - fast_initiation_scanning_metrics_->SetBluetoothAdapter(adapter); + //bluetooth_adapter_->AddObserver(this); + //fast_initiation_scanning_metrics_->SetBluetoothAdapter(adapter); // TODO(crbug/1147652): The call to update the advertising interval is // removed to prevent a Bluez crash. We need to either reduce the global diff --git a/a_win32_dll/nearby_sharing_service_impl.h b/a_win32_dll/nearby_sharing_service_impl.h index e18b485146..eddeb97f8b 100644 --- a/a_win32_dll/nearby_sharing_service_impl.h +++ b/a_win32_dll/nearby_sharing_service_impl.h @@ -244,6 +244,8 @@ class NearbySharingServiceImpl void GetBluetoothAdapter(); + void OnGetBluetoothAdapter(device::BluetoothAdapter* adapter); + NearbySharingDecoder* const decoder_; From 731e4f5f32066b4fb064bc20f0e83992bd0ccde4 Mon Sep 17 00:00:00 2001 From: Bhavana Nimma Date: Wed, 10 Apr 2024 12:28:29 +0530 Subject: [PATCH 2/2] Added Fast Initiation Advertiseing --- a_wasdk_app/DevicesPage.xaml.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/a_wasdk_app/DevicesPage.xaml.cpp b/a_wasdk_app/DevicesPage.xaml.cpp index 24802d647e..e860949e28 100644 --- a/a_wasdk_app/DevicesPage.xaml.cpp +++ b/a_wasdk_app/DevicesPage.xaml.cpp @@ -223,7 +223,7 @@ namespace winrt::a_wasdk_app::implementation auto work = []() { g_nearby = new NearbyShareAPI(); g_nearby->InitializeNearby(); - //g_nearby->StartFastInitiationAdvertising(); + g_nearby->StartFastInitiationAdvertising(); g_nearby->StartScanning2(PhoneDeviceAdded); while (true) {