Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fast Initiation Advertisement invocation and compilation errors fixes. #1

Open
wants to merge 2 commits into
base: fast_initiation
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion a_wasdk_app/DevicesPage.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
12 changes: 9 additions & 3 deletions a_win32_dll/fast_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ namespace device {

bool BluetoothAdvertisementWinrt::Initialize(
std::unique_ptr<BluetoothAdvertisement::Data> advertisement_data) {
if (advertisement_data->service_uuids()) {
/*if (advertisement_data->service_uuids()) {
BLUETOOTH_LOG(ERROR)
<< "Windows does not support advertising Service UUIDs.";
return false;
Expand All @@ -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) {
Expand All @@ -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<uint8_t>& data = pair.second;

Expand Down Expand Up @@ -442,6 +442,12 @@ namespace device {
adapter_->Initialize([this]() {
AdapterInitialized();
});

BluetoothAdapter* adapter =
std::move(adapter_);
std::vector<AdapterCallback> callbacks = std::move(adapter_callbacks_);
for (auto& callback : callbacks)
std::move(callback)(adapter);
return;
}

Expand Down
19 changes: 17 additions & 2 deletions a_win32_dll/fast_initiation_advertiser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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<uint8_t>(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<uint16_t, std::vector<uint8_t>>(
manufacturerId, payload1));

advertisement_data->set_manufacturer_data(manufacturer_data);

adapter_->RegisterAdvertisement(
std::move(advertisement_data),
[this, callback](device::BluetoothAdvertisement* advertisement) {
Expand Down
8 changes: 4 additions & 4 deletions a_win32_dll/nearby_sharing_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,22 @@ 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(
device::BluetoothAdapter* adapter)
{
bluetooth_adapter_ = nullptr;
bluetooth_adapter_ = std::unique_ptr<device::BluetoothAdapter>(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
Expand Down
2 changes: 2 additions & 0 deletions a_win32_dll/nearby_sharing_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ class NearbySharingServiceImpl

void GetBluetoothAdapter();

void OnGetBluetoothAdapter(device::BluetoothAdapter* adapter);


NearbySharingDecoder* const decoder_;

Expand Down