diff --git a/sharing/advertisement.cc b/sharing/advertisement.cc index d9e41231..9c69408e 100644 --- a/sharing/advertisement.cc +++ b/sharing/advertisement.cc @@ -100,7 +100,8 @@ bool ParseHasDeviceName(uint8_t b) { // static std::unique_ptr Advertisement::NewInstance( std::vector salt, std::vector encrypted_metadata_key, - ShareTargetType device_type, std::optional device_name) { + ShareTargetType device_type, std::optional device_name, + int32_t vendor_id) { if (salt.size() != Advertisement::kSaltSize) { NL_LOG(ERROR) << "Failed to create advertisement because the salt did " "not match the expected length " @@ -127,7 +128,7 @@ std::unique_ptr Advertisement::NewInstance( // Using `new` to access a non-public constructor. return std::make_unique( /* version= */ 0, std::move(salt), std::move(encrypted_metadata_key), - device_type, std::move(device_name)); + device_type, std::move(device_name), vendor_id); } std::vector Advertisement::ToEndpointInfo() { @@ -201,19 +202,21 @@ std::unique_ptr Advertisement::FromEndpointInfo( return Advertisement::NewInstance( std::move(salt), std::move(encrypted_metadata_key), device_type, - std::move(optional_device_name)); + std::move(optional_device_name), /*vendor_id=*/0); } // private Advertisement::Advertisement(int version, std::vector salt, std::vector encrypted_metadata_key, ShareTargetType device_type, - std::optional device_name) + std::optional device_name, + int32_t vendor_id) : version_(version), salt_(std::move(salt)), encrypted_metadata_key_(std::move(encrypted_metadata_key)), device_type_(device_type), - device_name_(std::move(device_name)) {} + device_name_(std::move(device_name)), + vendor_id_(vendor_id) {} } // namespace sharing } // namespace nearby diff --git a/sharing/advertisement.h b/sharing/advertisement.h index 7936915f..af75a225 100644 --- a/sharing/advertisement.h +++ b/sharing/advertisement.h @@ -39,12 +39,13 @@ class Advertisement { static std::unique_ptr NewInstance( std::vector salt, std::vector encrypted_metadata_key, - ShareTargetType device_type, std::optional device_name); + ShareTargetType device_type, std::optional device_name, + int32_t vendor_id); Advertisement(int version, std::vector salt, std::vector encrypted_metadata_key, ShareTargetType device_type, - std::optional device_name); + std::optional device_name, int32_t vendor_id); ~Advertisement() = default; Advertisement(const Advertisement&) = default; Advertisement& operator=(const Advertisement&) = default; @@ -61,6 +62,7 @@ class Advertisement { ShareTargetType device_type() const { return device_type_; } const std::optional& device_name() const { return device_name_; } bool HasDeviceName() const { return device_name_.has_value(); } + int32_t vendor_id() const { return vendor_id_; } static std::unique_ptr FromEndpointInfo( absl::Span endpoint_info); @@ -85,6 +87,10 @@ class Advertisement { // The human-readable name of the remote device. std::optional device_name_ = std::nullopt; + + // The vendor identifier of the remote device. Reference for vendor ID: + // google3/java/com/google/android/gmscore/integ/client/nearby/src/com/google/android/gms/nearby/sharing/SharingOptions.java + const int32_t vendor_id_; }; } // namespace sharing diff --git a/sharing/nearby_sharing_service_impl.cc b/sharing/nearby_sharing_service_impl.cc index 43978a7e..90c3b0ae 100644 --- a/sharing/nearby_sharing_service_impl.cc +++ b/sharing/nearby_sharing_service_impl.cc @@ -1551,8 +1551,9 @@ NearbySharingServiceImpl::CreateEndpointInfo( ShareTargetType device_type = static_cast(device_info_.GetDeviceType()); - std::unique_ptr advertisement = Advertisement::NewInstance( - std::move(salt), std::move(encrypted_key), device_type, device_name); + std::unique_ptr advertisement = + Advertisement::NewInstance(std::move(salt), std::move(encrypted_key), + device_type, device_name, /*vendor_id=*/0); if (advertisement) { return advertisement->ToEndpointInfo(); } else { diff --git a/sharing/nearby_sharing_service_impl_test.cc b/sharing/nearby_sharing_service_impl_test.cc index a4a7fce4..a3cd6b7e 100644 --- a/sharing/nearby_sharing_service_impl_test.cc +++ b/sharing/nearby_sharing_service_impl_test.cc @@ -175,6 +175,7 @@ constexpr char kEndpointId[] = "test_endpoint_id"; constexpr char kTextPayload[] = "Test text payload"; constexpr char kFourDigitToken[] = "1953"; constexpr absl::string_view kTestAccountId = "test_account"; +constexpr int32_t kVendorId = 0; constexpr int64_t kFreeDiskSpace = 10000; @@ -709,7 +710,7 @@ class NearbySharingServiceImplTest : public testing::Test { return Advertisement::NewInstance( GetNearbyShareTestEncryptedMetadataKey().salt(), GetNearbyShareTestEncryptedMetadataKey().encrypted_key(), - kDeviceType, device_name); + kDeviceType, device_name, kVendorId); })); } @@ -4367,7 +4368,7 @@ TEST_F(NearbySharingServiceImplTest, CreateShareTarget) { std::unique_ptr advertisement = Advertisement::NewInstance( GetNearbyShareTestEncryptedMetadataKey().salt(), GetNearbyShareTestEncryptedMetadataKey().encrypted_key(), kDeviceType, - kDeviceName); + kDeviceName, kVendorId); // Flip |for_self_share| to true to ensure the resulting ShareTarget picks // this up.