mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 07:36:10 -04:00
Add vendor_id field to Advertisement class
PiperOrigin-RevId: 635569993
This commit is contained in:
committed by
Copybara-Service
parent
1ab16fda46
commit
d9ee5ac253
@@ -100,7 +100,8 @@ bool ParseHasDeviceName(uint8_t b) {
|
||||
// static
|
||||
std::unique_ptr<Advertisement> Advertisement::NewInstance(
|
||||
std::vector<uint8_t> salt, std::vector<uint8_t> encrypted_metadata_key,
|
||||
ShareTargetType device_type, std::optional<std::string> device_name) {
|
||||
ShareTargetType device_type, std::optional<std::string> 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> Advertisement::NewInstance(
|
||||
// Using `new` to access a non-public constructor.
|
||||
return std::make_unique<Advertisement>(
|
||||
/* 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<uint8_t> Advertisement::ToEndpointInfo() {
|
||||
@@ -201,19 +202,21 @@ std::unique_ptr<Advertisement> 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<uint8_t> salt,
|
||||
std::vector<uint8_t> encrypted_metadata_key,
|
||||
ShareTargetType device_type,
|
||||
std::optional<std::string> device_name)
|
||||
std::optional<std::string> 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
|
||||
|
||||
@@ -39,12 +39,13 @@ class Advertisement {
|
||||
|
||||
static std::unique_ptr<Advertisement> NewInstance(
|
||||
std::vector<uint8_t> salt, std::vector<uint8_t> encrypted_metadata_key,
|
||||
ShareTargetType device_type, std::optional<std::string> device_name);
|
||||
ShareTargetType device_type, std::optional<std::string> device_name,
|
||||
int32_t vendor_id);
|
||||
|
||||
Advertisement(int version, std::vector<uint8_t> salt,
|
||||
std::vector<uint8_t> encrypted_metadata_key,
|
||||
ShareTargetType device_type,
|
||||
std::optional<std::string> device_name);
|
||||
std::optional<std::string> 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<std::string>& 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<Advertisement> FromEndpointInfo(
|
||||
absl::Span<const uint8_t> endpoint_info);
|
||||
@@ -85,6 +87,10 @@ class Advertisement {
|
||||
|
||||
// The human-readable name of the remote device.
|
||||
std::optional<std::string> 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
|
||||
|
||||
@@ -1551,8 +1551,9 @@ NearbySharingServiceImpl::CreateEndpointInfo(
|
||||
ShareTargetType device_type =
|
||||
static_cast<ShareTargetType>(device_info_.GetDeviceType());
|
||||
|
||||
std::unique_ptr<Advertisement> advertisement = Advertisement::NewInstance(
|
||||
std::move(salt), std::move(encrypted_key), device_type, device_name);
|
||||
std::unique_ptr<Advertisement> advertisement =
|
||||
Advertisement::NewInstance(std::move(salt), std::move(encrypted_key),
|
||||
device_type, device_name, /*vendor_id=*/0);
|
||||
if (advertisement) {
|
||||
return advertisement->ToEndpointInfo();
|
||||
} else {
|
||||
|
||||
@@ -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 = 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.
|
||||
|
||||
Reference in New Issue
Block a user