mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
Attach vendor ID to ShareTarget.
PiperOrigin-RevId: 636621178
This commit is contained in:
committed by
Copybara-Service
parent
76a99ec941
commit
7164bc98f6
@@ -3912,6 +3912,7 @@ std::optional<ShareTarget> NearbySharingServiceImpl::CreateShareTarget(
|
||||
target.device_name = std::move(*device_name);
|
||||
target.is_incoming = is_incoming;
|
||||
target.device_id = GetDeviceId(endpoint_id, certificate);
|
||||
target.vendor_id = advertisement.vendor_id();
|
||||
if (certificate.has_value()) {
|
||||
target.for_self_share = certificate->for_self_share();
|
||||
|
||||
@@ -3928,6 +3929,10 @@ std::optional<ShareTarget> NearbySharingServiceImpl::CreateShareTarget(
|
||||
target.image_url = std::nullopt;
|
||||
}
|
||||
}
|
||||
// Always prefer the certificate's vendor ID if available.
|
||||
if (certificate->unencrypted_metadata().has_vendor_id()) {
|
||||
target.vendor_id = certificate->unencrypted_metadata().vendor_id();
|
||||
}
|
||||
target.is_known = true;
|
||||
}
|
||||
ShareTargetInfo& info = GetOrCreateShareTargetInfo(target, endpoint_id);
|
||||
|
||||
@@ -4457,6 +4457,7 @@ TEST_F(NearbySharingServiceImplTest, CreateShareTarget) {
|
||||
ASSERT_TRUE(share_target.has_value());
|
||||
EXPECT_EQ(kDeviceName, share_target->device_name);
|
||||
EXPECT_EQ(kDeviceType, share_target->type);
|
||||
EXPECT_EQ(kVendorId, share_target->vendor_id);
|
||||
EXPECT_FALSE(share_target->for_self_share);
|
||||
}
|
||||
|
||||
|
||||
@@ -150,6 +150,7 @@ std::string ShareTarget::ToString() const {
|
||||
fmt.push_back(absl::StrFormat("is_known: %d", is_known));
|
||||
fmt.push_back(absl::StrFormat("is_incoming: %d", is_incoming));
|
||||
fmt.push_back(absl::StrFormat("for_self_share: %d", for_self_share));
|
||||
fmt.push_back(absl::StrFormat("vendor_id: %d", vendor_id));
|
||||
|
||||
return absl::StrCat("ShareTarget<", absl::StrJoin(fmt, ", "), ">");
|
||||
}
|
||||
|
||||
@@ -70,6 +70,8 @@ struct ShareTarget {
|
||||
std::optional<std::string> device_id;
|
||||
// True if the remote device is also owned by the current user.
|
||||
bool for_self_share = false;
|
||||
// Vendor ID of the target. This can change over the lifetime of the target.
|
||||
uint8_t vendor_id = 0;
|
||||
};
|
||||
|
||||
} // namespace sharing
|
||||
|
||||
@@ -56,13 +56,13 @@ std::vector<ShareTargetToStringTestData> GetTestData() {
|
||||
"ShareTarget<id: 1, device_name: , "
|
||||
"file_attachments_size: 0, text_attachments_size: 0, "
|
||||
"wifi_credentials_attachments_size: 0, is_known: 0, is_incoming: 0, "
|
||||
"for_self_share: 0>"},
|
||||
"for_self_share: 0, vendor_id: 0>"},
|
||||
{share_target2,
|
||||
"ShareTarget<id: 2, device_name: test_name, full_name: "
|
||||
"test_full_name, image_url: ://:0, device_id: test_device_id, "
|
||||
"file_attachments_size: 0, text_attachments_size: 0, "
|
||||
"wifi_credentials_attachments_size: 0, is_known: 0, is_incoming: 1, "
|
||||
"for_self_share: 1>"},
|
||||
"for_self_share: 1, vendor_id: 0>"},
|
||||
});
|
||||
|
||||
return *kShareTargetToStringTestData;
|
||||
|
||||
Reference in New Issue
Block a user