scan_manager clean up.

PiperOrigin-RevId: 523538897
This commit is contained in:
Hai Shang
2023-04-11 16:39:55 -07:00
committed by Copybara-Service
parent 30917e6160
commit 97fe0be263
2 changed files with 35 additions and 1 deletions
+17 -1
View File
@@ -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<int>(
static_cast<uint8_t>(data_element.GetValue()[0]))));
}
}
it->second.callback.on_discovered_cb(std::move(device));
}
}
@@ -126,6 +134,14 @@ void ScanManager::FetchCredentials(ScanSessionId id,
std::vector<CredentialSelector> 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 =
@@ -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();
}
}};