diff --git a/presence/implementation/scan_manager.cc b/presence/implementation/scan_manager.cc index 96e92764..31b98bf9 100644 --- a/presence/implementation/scan_manager.cc +++ b/presence/implementation/scan_manager.cc @@ -117,7 +117,15 @@ void ScanManager::NotifyFoundBle(ScanSessionId id, BleAdvertisementData data, // fully implemented internal::Metadata metadata; metadata.set_bluetooth_mac_address(std::string(remote_address)); - it->second.callback.on_discovered_cb(PresenceDevice(metadata)); + PresenceDevice device{metadata}; + device.AddExtendedProperties(advert->data_elements); + for (const auto& data_element : advert->data_elements) { + if (data_element.GetType() == DataElement::kActionFieldType) { + device.AddAction(PresenceAction(static_cast( + static_cast(data_element.GetValue()[0])))); + } + } + it->second.callback.on_discovered_cb(std::move(device)); } } @@ -126,6 +134,14 @@ void ScanManager::FetchCredentials(ScanSessionId id, std::vector credential_selectors = AdvertisementDecoder::GetCredentialSelectors(scan_request); for (const CredentialSelector& selector : credential_selectors) { + // Not fetching for PUBLIC. + if (selector.identity_type == internal::IDENTITY_TYPE_UNSPECIFIED || + selector.identity_type == internal::IDENTITY_TYPE_PUBLIC) { + NEARBY_LOGS(INFO) << __func__ + << ": skip feteching creds for identity type: " + << selector.identity_type; + continue; + } credential_manager_->GetPublicCredentials( selector, PublicCredentialType::kRemotePublicCredential, {.credentials_fetched_cb = diff --git a/presence/implementation/scan_manager_test.cc b/presence/implementation/scan_manager_test.cc index b59f62fb..73172b54 100644 --- a/presence/implementation/scan_manager_test.cc +++ b/presence/implementation/scan_manager_test.cc @@ -47,6 +47,8 @@ using AdvertisingCallback = using ::nearby::SingleThreadExecutor; using CountDownLatch = ::nearby::CountDownLatch; +// using ::testing::UnorderedElementsAre; +using ::testing::Contains; class ScanManagerTest : public testing::Test { protected: @@ -199,6 +201,22 @@ TEST_F(ScanManagerTest, PresenceMetadataIsRetained) { .on_discovered_cb = [this, &address](PresenceDevice pd) { if (pd.GetMetadata().bluetooth_mac_address() == address) { + EXPECT_THAT( + pd.GetExtendedProperties(), + Contains( + DataElement(DataElement::kPublicIdentityFieldType, "")) + .Times(1)); + // MakeDefaultScanRequest() used kPresenceManagerAction for + // broadcasting. Thus verify DE and action got it recorded. + EXPECT_THAT( + pd.GetExtendedProperties(), + Contains(DataElement(ActionBit::kPresenceManagerAction)) + .Times(1)); + EXPECT_THAT(pd.GetActions(), + Contains(PresenceAction{ + (int)ActionBit::kPresenceManagerAction}) + .Times(1)); + found_latch_.CountDown(); } }};