mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Cleanup payload creation.
PiperOrigin-RevId: 644155481
This commit is contained in:
committed by
Copybara-Service
parent
15f669b3d9
commit
9ea59a98dc
+59
-14
@@ -170,9 +170,45 @@ cc_library(
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "nearby_sharing_service",
|
||||
name = "share_target_info",
|
||||
srcs = [
|
||||
"incoming_share_target_info.cc",
|
||||
"nearby_file_handler.cc",
|
||||
"outgoing_share_target_info.cc",
|
||||
"payload_tracker.cc",
|
||||
"share_target_info.cc",
|
||||
],
|
||||
hdrs = [
|
||||
"incoming_share_target_info.h",
|
||||
"nearby_file_handler.h",
|
||||
"outgoing_share_target_info.h",
|
||||
"payload_tracker.h",
|
||||
"share_target_info.h",
|
||||
],
|
||||
deps = [
|
||||
":attachments",
|
||||
":connection_types",
|
||||
":incoming_frame_reader",
|
||||
":paired_key_verification_runner",
|
||||
":transfer_metadata",
|
||||
":types",
|
||||
"//internal/base:files",
|
||||
"//internal/platform:types",
|
||||
"//proto:sharing_enums_cc_proto",
|
||||
"//sharing/certificates",
|
||||
"//sharing/common:compatible_u8_string",
|
||||
"//sharing/internal/public:logging",
|
||||
"//sharing/internal/public:types",
|
||||
"@com_google_absl//absl/container:flat_hash_map",
|
||||
"@com_google_absl//absl/strings:string_view",
|
||||
"@com_google_absl//absl/time",
|
||||
"@com_google_absl//absl/types:span",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "nearby_sharing_service",
|
||||
srcs = [
|
||||
"nearby_connection_impl.cc",
|
||||
"nearby_connections_manager.cc",
|
||||
"nearby_connections_manager_factory.cc",
|
||||
@@ -180,7 +216,6 @@ cc_library(
|
||||
"nearby_connections_service.cc",
|
||||
"nearby_connections_service_impl.cc",
|
||||
"nearby_connections_stream_buffer_manager.cc",
|
||||
"nearby_file_handler.cc",
|
||||
"nearby_share_profile_info_provider_impl.cc",
|
||||
"nearby_sharing_service.cc",
|
||||
"nearby_sharing_service_extension.cc",
|
||||
@@ -188,23 +223,18 @@ cc_library(
|
||||
"nearby_sharing_service_impl.cc",
|
||||
"nearby_sharing_settings.cc",
|
||||
"nearby_sharing_util.cc",
|
||||
"outgoing_share_target_info.cc",
|
||||
"payload_tracker.cc",
|
||||
"share_target_info.cc",
|
||||
"transfer_manager.cc",
|
||||
"wrapped_share_target_discovered_callback.cc",
|
||||
],
|
||||
hdrs = [
|
||||
"connection_lifecycle_listener.h",
|
||||
"endpoint_discovery_listener.h",
|
||||
"incoming_share_target_info.h",
|
||||
"nearby_connection_impl.h",
|
||||
"nearby_connections_manager_factory.h",
|
||||
"nearby_connections_manager_impl.h",
|
||||
"nearby_connections_service.h",
|
||||
"nearby_connections_service_impl.h",
|
||||
"nearby_connections_stream_buffer_manager.h",
|
||||
"nearby_file_handler.h",
|
||||
"nearby_share_profile_info_provider_impl.h",
|
||||
"nearby_sharing_service.h",
|
||||
"nearby_sharing_service_extension.h",
|
||||
@@ -212,11 +242,8 @@ cc_library(
|
||||
"nearby_sharing_service_impl.h",
|
||||
"nearby_sharing_settings.h",
|
||||
"nearby_sharing_util.h",
|
||||
"outgoing_share_target_info.h",
|
||||
"payload_listener.h",
|
||||
"payload_tracker.h",
|
||||
"share_target_discovered_callback.h",
|
||||
"share_target_info.h",
|
||||
"transfer_manager.h",
|
||||
"transfer_update_callback.h",
|
||||
"wrapped_share_target_discovered_callback.h",
|
||||
@@ -236,6 +263,7 @@ cc_library(
|
||||
":incoming_frame_reader",
|
||||
":nearby_sharing_decoder_impl",
|
||||
":paired_key_verification_runner",
|
||||
":share_target_info",
|
||||
":transfer_metadata",
|
||||
":types",
|
||||
"//connections:core",
|
||||
@@ -244,7 +272,6 @@ cc_library(
|
||||
"//internal/analytics:event_logger",
|
||||
"//internal/base",
|
||||
"//internal/base:bluetooth_address",
|
||||
"//internal/base:files",
|
||||
"//internal/flags:nearby_flags",
|
||||
"//internal/network:url",
|
||||
"//internal/platform:base",
|
||||
@@ -465,6 +492,7 @@ cc_test(
|
||||
":attachments",
|
||||
":connection_types",
|
||||
":nearby_sharing_service",
|
||||
":share_target_info",
|
||||
":test_support",
|
||||
":transfer_metadata",
|
||||
":types",
|
||||
@@ -534,7 +562,7 @@ cc_test(
|
||||
name = "nearby_file_handler_test",
|
||||
srcs = ["nearby_file_handler_test.cc"],
|
||||
deps = [
|
||||
":nearby_sharing_service",
|
||||
":share_target_info",
|
||||
"//internal/base:files",
|
||||
"//internal/platform/implementation/g3", # fixdeps: keep
|
||||
"@com_github_protobuf_matchers//protobuf-matchers",
|
||||
@@ -603,7 +631,7 @@ cc_test(
|
||||
deps = [
|
||||
":attachments",
|
||||
":connection_types",
|
||||
":nearby_sharing_service",
|
||||
":share_target_info",
|
||||
":transfer_metadata",
|
||||
":types",
|
||||
"//internal/platform/implementation/g3", # fixdeps: keep
|
||||
@@ -673,8 +701,8 @@ cc_test(
|
||||
srcs = ["share_target_info_test.cc"],
|
||||
deps = [
|
||||
":nearby_sharing_decoder_impl",
|
||||
":nearby_sharing_service",
|
||||
":paired_key_verification_runner",
|
||||
":share_target_info",
|
||||
":test_support",
|
||||
":transfer_metadata",
|
||||
":types",
|
||||
@@ -710,3 +738,20 @@ cc_test(
|
||||
"@com_google_googletest//:gtest_main",
|
||||
],
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "outgoing_share_target_info_test",
|
||||
srcs = ["outgoing_share_target_info_test.cc"],
|
||||
deps = [
|
||||
":attachments",
|
||||
":connection_types",
|
||||
":share_target_info",
|
||||
":transfer_metadata",
|
||||
":types",
|
||||
"//internal/platform/implementation/g3", # fixdeps: keep
|
||||
"//sharing/proto:wire_format_cc_proto",
|
||||
"@com_github_protobuf_matchers//protobuf-matchers",
|
||||
"@com_google_absl//absl/strings:string_view",
|
||||
"@com_google_googletest//:gtest_main",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -14,16 +14,14 @@
|
||||
|
||||
#include "sharing/attachment_info.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace nearby {
|
||||
namespace sharing {
|
||||
namespace nearby::sharing {
|
||||
|
||||
AttachmentInfo::AttachmentInfo() = default;
|
||||
AttachmentInfo::~AttachmentInfo() = default;
|
||||
|
||||
AttachmentInfo::AttachmentInfo(const AttachmentInfo&) = default;
|
||||
AttachmentInfo& AttachmentInfo::operator=(const AttachmentInfo&) = default;
|
||||
AttachmentInfo::AttachmentInfo(AttachmentInfo&&) = default;
|
||||
AttachmentInfo& AttachmentInfo::operator=(AttachmentInfo&&) = default;
|
||||
|
||||
} // namespace sharing
|
||||
} // namespace nearby
|
||||
} // namespace nearby::sharing
|
||||
|
||||
@@ -21,14 +21,15 @@
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace nearby {
|
||||
namespace sharing {
|
||||
namespace nearby::sharing {
|
||||
|
||||
// Ties associated information to an Attachment.
|
||||
struct AttachmentInfo {
|
||||
AttachmentInfo();
|
||||
~AttachmentInfo();
|
||||
|
||||
AttachmentInfo(const AttachmentInfo&);
|
||||
AttachmentInfo& operator=(const AttachmentInfo&);
|
||||
AttachmentInfo(AttachmentInfo&&);
|
||||
AttachmentInfo& operator=(AttachmentInfo&&);
|
||||
|
||||
@@ -37,7 +38,6 @@ struct AttachmentInfo {
|
||||
std::filesystem::path file_path;
|
||||
};
|
||||
|
||||
} // namespace sharing
|
||||
} // namespace nearby
|
||||
} // namespace nearby::sharing
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_SHARING_ATTACHMENT_INFO_H_
|
||||
|
||||
@@ -71,16 +71,5 @@ std::string NearbyConnectionsManager::ConnectionsStatusToString(
|
||||
}
|
||||
// LINT.ThenChange()
|
||||
|
||||
NearbyConnectionsManager::PayloadStatusListener::PayloadStatusListener() =
|
||||
default;
|
||||
|
||||
NearbyConnectionsManager::PayloadStatusListener::~PayloadStatusListener() =
|
||||
default;
|
||||
|
||||
std::weak_ptr<NearbyConnectionsManager::PayloadStatusListener>
|
||||
NearbyConnectionsManager::PayloadStatusListener::GetWeakPtr() {
|
||||
return this->weak_from_this();
|
||||
}
|
||||
|
||||
} // namespace sharing
|
||||
} // namespace nearby
|
||||
|
||||
@@ -77,10 +77,12 @@ class NearbyConnectionsManager {
|
||||
class PayloadStatusListener
|
||||
: public std::enable_shared_from_this<PayloadStatusListener> {
|
||||
public:
|
||||
PayloadStatusListener();
|
||||
virtual ~PayloadStatusListener();
|
||||
PayloadStatusListener() = default;
|
||||
virtual ~PayloadStatusListener() = default;
|
||||
|
||||
std::weak_ptr<PayloadStatusListener> GetWeakPtr();
|
||||
std::weak_ptr<PayloadStatusListener> GetWeakPtr() {
|
||||
return weak_from_this();
|
||||
}
|
||||
|
||||
// Note: `upgraded_medium` is passed in for use in metrics, and it is
|
||||
// absl::nullopt if the bandwidth has not upgraded yet or if the upgrade
|
||||
|
||||
@@ -112,15 +112,13 @@
|
||||
#include "sharing/wifi_credentials_attachment.h"
|
||||
#include "sharing/wrapped_share_target_discovered_callback.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace sharing {
|
||||
namespace nearby::sharing {
|
||||
namespace {
|
||||
|
||||
using BlockedVendorId = ::nearby::sharing::Advertisement::BlockedVendorId;
|
||||
using ::nearby::sharing::api::SharingPlatform;
|
||||
using ::nearby::sharing::proto::DataUsage;
|
||||
using ::nearby::sharing::proto::DeviceVisibility;
|
||||
using ::nearby::sharing::proto::FastInitiationNotificationState;
|
||||
using Type = ::nearby::sharing::service::proto::TextMetadata;
|
||||
using ::location::nearby::proto::sharing::AttachmentTransmissionStatus;
|
||||
using ::location::nearby::proto::sharing::EstablishConnectionStatus;
|
||||
@@ -794,7 +792,6 @@ void NearbySharingServiceImpl::SendAttachments(
|
||||
/*concurrent_connections=*/GetConnectedShareTargetCount(),
|
||||
info->share_target());
|
||||
|
||||
send_attachments_timestamp_ = context_->GetClock()->Now();
|
||||
OnTransferStarted(/*is_incoming=*/false);
|
||||
is_connecting_ = true;
|
||||
InvalidateSendSurfaceState();
|
||||
@@ -807,8 +804,8 @@ void NearbySharingServiceImpl::SendAttachments(
|
||||
.build());
|
||||
|
||||
CreatePayloads(*info, [this, endpoint_info = std::move(*endpoint_info)](
|
||||
int64_t share_target_id, bool success) {
|
||||
OnCreatePayloads(std::move(endpoint_info), share_target_id, success);
|
||||
OutgoingShareTargetInfo& info, bool success) {
|
||||
OnCreatePayloads(std::move(endpoint_info), info, success);
|
||||
});
|
||||
|
||||
std::move(status_codes_callback)(StatusCodes::kOk);
|
||||
@@ -2829,75 +2826,67 @@ void NearbySharingServiceImpl::SendIntroduction(
|
||||
|
||||
void NearbySharingServiceImpl::CreatePayloads(
|
||||
OutgoingShareTargetInfo& info,
|
||||
std::function<void(int64_t, bool)> callback) {
|
||||
std::function<void(OutgoingShareTargetInfo&, bool)> callback) {
|
||||
int64_t share_target_id = info.share_target().id;
|
||||
if (!info.file_payloads().empty() || !info.text_payloads().empty() ||
|
||||
!info.wifi_credentials_payloads().empty()) {
|
||||
// We may have already created the payloads in the case of retry, so we can
|
||||
// skip this step.
|
||||
std::move(callback)(share_target_id, /*success=*/false);
|
||||
std::move(callback)(info, /*success=*/false);
|
||||
return;
|
||||
}
|
||||
const AttachmentContainer& container = info.attachment_container();
|
||||
info.set_text_payloads(CreateTextPayloads(container.GetTextAttachments()));
|
||||
info.set_wifi_credentials_payloads(
|
||||
CreateWifiCredentialsPayloads(container.GetWifiCredentialsAttachments()));
|
||||
if (container.GetFileAttachments().empty()) {
|
||||
std::move(callback)(share_target_id, /*success=*/true);
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<std::filesystem::path> file_paths;
|
||||
file_paths.reserve(container.GetFileAttachments().size());
|
||||
for (const FileAttachment& attachment : container.GetFileAttachments()) {
|
||||
file_paths.push_back(*attachment.file_path());
|
||||
}
|
||||
|
||||
info.CreateTextPayloads();
|
||||
info.CreateWifiCredentialsPayloads();
|
||||
file_handler_.OpenFiles(
|
||||
std::move(file_paths),
|
||||
info.GetFilePaths(),
|
||||
[this, share_target_id, callback = std::move(callback)](
|
||||
std::vector<NearbyFileHandler::FileInfo> file_infos) {
|
||||
RunOnNearbySharingServiceThread(
|
||||
"open_files",
|
||||
[this, share_target_id, callback = std::move(callback),
|
||||
file_infos = std::move(file_infos)]() {
|
||||
OnOpenFiles(share_target_id, std::move(callback),
|
||||
std::move(file_infos));
|
||||
OutgoingShareTargetInfo* info =
|
||||
GetOutgoingShareTargetInfo(share_target_id);
|
||||
if (info == nullptr) {
|
||||
return;
|
||||
}
|
||||
bool result = info->CreateFilePayloads(file_infos);
|
||||
attachment_info_map_ = info->attachment_payload_map();
|
||||
std::move(callback)(*info, result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void NearbySharingServiceImpl::OnCreatePayloads(
|
||||
std::vector<uint8_t> endpoint_info, int64_t share_target_id, bool success) {
|
||||
OutgoingShareTargetInfo* info = GetOutgoingShareTargetInfo(share_target_id);
|
||||
bool has_payloads = info && (!info->text_payloads().empty() ||
|
||||
!info->file_payloads().empty() ||
|
||||
!info->wifi_credentials_payloads().empty());
|
||||
std::vector<uint8_t> endpoint_info, OutgoingShareTargetInfo& info,
|
||||
bool success) {
|
||||
bool has_payloads = !info.text_payloads().empty() ||
|
||||
!info.file_payloads().empty() ||
|
||||
!info.wifi_credentials_payloads().empty();
|
||||
if (!success || !has_payloads) {
|
||||
NL_LOG(WARNING) << __func__
|
||||
<< ": Failed to send file to remote ShareTarget. Failed to "
|
||||
"create payloads.";
|
||||
if (info) {
|
||||
info->UpdateTransferMetadata(
|
||||
TransferMetadataBuilder()
|
||||
.set_status(TransferMetadata::Status::kMediaUnavailable)
|
||||
.build());
|
||||
}
|
||||
info.UpdateTransferMetadata(
|
||||
TransferMetadataBuilder()
|
||||
.set_status(TransferMetadata::Status::kMediaUnavailable)
|
||||
.build());
|
||||
return;
|
||||
}
|
||||
// Log analytics event of describing attachments.
|
||||
analytics_recorder_->NewDescribeAttachments(info->attachment_container());
|
||||
analytics_recorder_->NewDescribeAttachments(info.attachment_container());
|
||||
|
||||
std::optional<std::vector<uint8_t>> bluetooth_mac_address =
|
||||
GetBluetoothMacAddressForShareTarget(share_target_id);
|
||||
GetBluetoothMacAddressForShareTarget(info);
|
||||
|
||||
// For metrics.
|
||||
all_cancelled_share_target_ids_.clear();
|
||||
|
||||
int64_t share_target_id = info.share_target().id;
|
||||
nearby_connections_manager_->Connect(
|
||||
std::move(endpoint_info), info->endpoint_id(),
|
||||
std::move(endpoint_info), info.endpoint_id(),
|
||||
std::move(bluetooth_mac_address), settings_->GetDataUsage(),
|
||||
GetTransportType(info->attachment_container()),
|
||||
GetTransportType(info.attachment_container()),
|
||||
[this, share_target_id](NearbyConnection* connection, Status status) {
|
||||
OutgoingShareTargetInfo* info =
|
||||
GetOutgoingShareTargetInfo(share_target_id);
|
||||
@@ -2928,69 +2917,6 @@ void NearbySharingServiceImpl::OnCreatePayloads(
|
||||
});
|
||||
}
|
||||
|
||||
void NearbySharingServiceImpl::OnOpenFiles(
|
||||
int64_t share_target_id, std::function<void(int64_t, bool)> callback,
|
||||
std::vector<NearbyFileHandler::FileInfo> files) {
|
||||
OutgoingShareTargetInfo* info = GetOutgoingShareTargetInfo(share_target_id);
|
||||
AttachmentContainer& container = info->mutable_attachment_container();
|
||||
if (!info || files.size() != container.GetFileAttachments().size()) {
|
||||
std::move(callback)(share_target_id, /*success=*/false);
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<Payload> payloads;
|
||||
payloads.reserve(files.size());
|
||||
|
||||
for (size_t i = 0; i < files.size(); ++i) {
|
||||
FileAttachment& attachment = container.GetMutableFileAttachment(i);
|
||||
attachment.set_size(files[i].size);
|
||||
InputFile input_file;
|
||||
input_file.path = files[i].file_path;
|
||||
Payload payload(input_file, attachment.parent_folder());
|
||||
payload.content.file_payload.size = files[i].size;
|
||||
SetAttachmentPayloadId(attachment, payload.id);
|
||||
payloads.push_back(std::move(payload));
|
||||
}
|
||||
|
||||
info->set_file_payloads(std::move(payloads));
|
||||
std::move(callback)(share_target_id, /*success=*/true);
|
||||
}
|
||||
|
||||
std::vector<Payload> NearbySharingServiceImpl::CreateTextPayloads(
|
||||
const std::vector<TextAttachment>& attachments) {
|
||||
std::vector<Payload> payloads;
|
||||
payloads.reserve(attachments.size());
|
||||
for (const TextAttachment& attachment : attachments) {
|
||||
absl::string_view body = attachment.text_body();
|
||||
std::vector<uint8_t> bytes(body.begin(), body.end());
|
||||
|
||||
Payload payload{bytes};
|
||||
SetAttachmentPayloadId(attachment, payload.id);
|
||||
payloads.push_back(std::move(payload));
|
||||
}
|
||||
return payloads;
|
||||
}
|
||||
|
||||
std::vector<Payload> NearbySharingServiceImpl::CreateWifiCredentialsPayloads(
|
||||
const std::vector<WifiCredentialsAttachment>& attachments) {
|
||||
std::vector<Payload> payloads;
|
||||
payloads.reserve(attachments.size());
|
||||
for (const WifiCredentialsAttachment& attachment : attachments) {
|
||||
nearby::sharing::service::proto::WifiCredentials wifi_credentials;
|
||||
wifi_credentials.set_password(std::string(attachment.password()));
|
||||
wifi_credentials.set_hidden_ssid(attachment.is_hidden());
|
||||
|
||||
std::vector<uint8_t> bytes(wifi_credentials.ByteSizeLong());
|
||||
wifi_credentials.SerializeToArray(bytes.data(),
|
||||
wifi_credentials.ByteSizeLong());
|
||||
|
||||
Payload payload{bytes};
|
||||
SetAttachmentPayloadId(attachment, payload.id);
|
||||
payloads.push_back(std::move(payload));
|
||||
}
|
||||
return payloads;
|
||||
}
|
||||
|
||||
void NearbySharingServiceImpl::WriteResponseFrame(
|
||||
NearbyConnection& connection,
|
||||
nearby::sharing::service::proto::ConnectionResponseFrame::Status
|
||||
@@ -4374,19 +4300,12 @@ NearbyConnection* NearbySharingServiceImpl::GetConnection(
|
||||
|
||||
std::optional<std::vector<uint8_t>>
|
||||
NearbySharingServiceImpl::GetBluetoothMacAddressForShareTarget(
|
||||
int64_t share_target_id) {
|
||||
ShareTargetInfo* info = GetShareTargetInfo(share_target_id);
|
||||
if (!info) {
|
||||
NL_LOG(ERROR) << __func__ << ": No ShareTargetInfo found for "
|
||||
<< "share target id: " << share_target_id;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
OutgoingShareTargetInfo& info) {
|
||||
const std::optional<NearbyShareDecryptedPublicCertificate>& certificate =
|
||||
info->certificate();
|
||||
info.certificate();
|
||||
if (!certificate) {
|
||||
NL_LOG(ERROR) << __func__ << ": No decrypted public certificate found for "
|
||||
<< "share target id: " << share_target_id;
|
||||
<< "share target id: " << info.share_target().id;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
@@ -4788,5 +4707,4 @@ void NearbySharingServiceImpl::UpdateFilePathsInProgress(
|
||||
<< ": Update file paths in progress: " << update_file_paths;
|
||||
}
|
||||
|
||||
} // namespace sharing
|
||||
} // namespace nearby
|
||||
} // namespace nearby::sharing
|
||||
|
||||
@@ -79,14 +79,11 @@
|
||||
#include "sharing/share_target.h"
|
||||
#include "sharing/share_target_discovered_callback.h"
|
||||
#include "sharing/share_target_info.h"
|
||||
#include "sharing/text_attachment.h"
|
||||
#include "sharing/transfer_metadata.h"
|
||||
#include "sharing/transfer_update_callback.h"
|
||||
#include "sharing/wifi_credentials_attachment.h"
|
||||
#include "sharing/wrapped_share_target_discovered_callback.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace sharing {
|
||||
namespace nearby::sharing {
|
||||
|
||||
class NearbyShareContactManager;
|
||||
|
||||
@@ -334,17 +331,11 @@ class NearbySharingServiceImpl
|
||||
void SendIntroduction(OutgoingShareTargetInfo& info,
|
||||
std::optional<std::string> four_digit_token);
|
||||
|
||||
void CreatePayloads(OutgoingShareTargetInfo& info,
|
||||
std::function<void(int64_t, bool)> callback);
|
||||
void CreatePayloads(
|
||||
OutgoingShareTargetInfo& info,
|
||||
std::function<void(OutgoingShareTargetInfo&, bool)> callback);
|
||||
void OnCreatePayloads(std::vector<uint8_t> endpoint_info,
|
||||
int64_t share_target_id, bool success);
|
||||
void OnOpenFiles(int64_t share_target_id,
|
||||
std::function<void(int64_t, bool)> callback,
|
||||
std::vector<NearbyFileHandler::FileInfo> files);
|
||||
std::vector<Payload> CreateTextPayloads(
|
||||
const std::vector<TextAttachment>& attachments);
|
||||
std::vector<Payload> CreateWifiCredentialsPayloads(
|
||||
const std::vector<WifiCredentialsAttachment>& attachments);
|
||||
OutgoingShareTargetInfo& info, bool success);
|
||||
|
||||
void WriteResponseFrame(
|
||||
NearbyConnection& connection,
|
||||
@@ -432,7 +423,7 @@ class NearbySharingServiceImpl
|
||||
|
||||
NearbyConnection* GetConnection(int64_t share_target_id);
|
||||
std::optional<std::vector<uint8_t>> GetBluetoothMacAddressForShareTarget(
|
||||
int64_t share_target_id);
|
||||
OutgoingShareTargetInfo& info);
|
||||
|
||||
void ClearOutgoingShareTargetInfoMap();
|
||||
void SetAttachmentPayloadId(const Attachment& attachment, int64_t payload_id);
|
||||
@@ -621,10 +612,6 @@ class NearbySharingServiceImpl
|
||||
absl::Time scanning_start_timestamp_;
|
||||
// True when we are advertising with a device name visible to everyone.
|
||||
std::atomic_bool in_high_visibility_{false};
|
||||
// The time attachments are sent after a share target is selected. This is
|
||||
// used to time the process from selecting a share target to writing the
|
||||
// introduction frame (last frame before receiver gets notified).
|
||||
absl::Time send_attachments_timestamp_;
|
||||
// Whether an incoming share has been accepted, and we are waiting to log the
|
||||
// time from acceptance to the start of payload transfer.
|
||||
bool is_waiting_to_record_accept_to_transfer_start_metric_ = false;
|
||||
@@ -672,7 +659,6 @@ class NearbySharingServiceImpl
|
||||
std::unique_ptr<nearby::api::AppInfo> app_info_;
|
||||
};
|
||||
|
||||
} // namespace sharing
|
||||
} // namespace nearby
|
||||
} // namespace nearby::sharing
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_SHARING_NEARBY_SHARING_SERVICE_IMPL_H_
|
||||
|
||||
@@ -584,13 +584,13 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
}
|
||||
|
||||
NearbySharingService::StatusCodes SendAttachments(
|
||||
const ShareTarget& share_target,
|
||||
int64_t share_target_id,
|
||||
std::unique_ptr<AttachmentContainer> attachment_container) {
|
||||
NearbySharingService::StatusCodes result =
|
||||
NearbySharingService::StatusCodes::kError;
|
||||
absl::Notification notification;
|
||||
service_->SendAttachments(
|
||||
share_target.id, std::move(attachment_container),
|
||||
share_target_id, std::move(attachment_container),
|
||||
[&](NearbySharingService::StatusCodes status_codes) {
|
||||
result = status_codes;
|
||||
notification.Notify();
|
||||
@@ -781,7 +781,7 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
FlushTesting();
|
||||
}
|
||||
|
||||
ShareTarget SetUpIncomingConnection(
|
||||
int64_t SetUpIncomingConnection(
|
||||
NiceMock<MockTransferUpdateCallback>& callback, bool is_foreground = true,
|
||||
bool for_self_share = false) {
|
||||
fake_nearby_connections_manager_->SetRawAuthenticationToken(kEndpointId,
|
||||
@@ -793,7 +793,7 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
|
||||
SetUpIntroductionFrameDecoder(/*return_empty_introduction_frame=*/false);
|
||||
|
||||
ShareTarget share_target;
|
||||
int64_t share_target_id;
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
absl::Notification notification;
|
||||
|
||||
@@ -813,7 +813,7 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
}
|
||||
|
||||
EXPECT_EQ(metadata.status(), expected_status);
|
||||
share_target = incoming_share_target;
|
||||
share_target_id = incoming_share_target.id;
|
||||
notification.Notify();
|
||||
}));
|
||||
|
||||
@@ -833,10 +833,10 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
fake_nearby_connections_manager_->DidUpgradeBandwidth(kEndpointId));
|
||||
|
||||
EXPECT_TRUE(notification.WaitForNotificationWithTimeout(kWaitTimeout));
|
||||
return share_target;
|
||||
return share_target_id;
|
||||
}
|
||||
|
||||
ShareTarget SetUpOutgoingShareTarget(
|
||||
int64_t SetUpOutgoingShareTarget(
|
||||
MockTransferUpdateCallback& transfer_callback,
|
||||
MockShareTargetDiscoveredCallback& discovery_callback) {
|
||||
SetUpKeyVerification(
|
||||
@@ -849,7 +849,7 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
return DiscoverShareTarget(transfer_callback, discovery_callback);
|
||||
}
|
||||
|
||||
ShareTarget DiscoverShareTarget(
|
||||
int64_t DiscoverShareTarget(
|
||||
MockTransferUpdateCallback& transfer_callback,
|
||||
MockShareTargetDiscoveredCallback& discovery_callback) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
@@ -866,11 +866,11 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
NearbySharingService::StatusCodes::kOk);
|
||||
EXPECT_TRUE(fake_nearby_connections_manager_->IsDiscovering());
|
||||
|
||||
ShareTarget discovered_target;
|
||||
int64_t discovered_target_id;
|
||||
// Discover a new endpoint, with fields set up a valid certificate.
|
||||
EXPECT_CALL(discovery_callback, OnShareTargetDiscovered)
|
||||
.WillOnce([&discovered_target](ShareTarget share_target) {
|
||||
discovered_target = share_target;
|
||||
.WillOnce([&discovered_target_id](ShareTarget share_target) {
|
||||
discovered_target_id = share_target.id;
|
||||
});
|
||||
|
||||
auto endpoint_info = std::make_unique<DiscoveredEndpointInfo>(
|
||||
@@ -880,7 +880,7 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
FlushTesting();
|
||||
ProcessLatestPublicCertificateDecryption(/*expected_num_calls=*/1,
|
||||
/*success=*/true);
|
||||
return discovered_target;
|
||||
return discovered_target_id;
|
||||
}
|
||||
|
||||
Frame GetWrittenFrame() {
|
||||
@@ -977,27 +977,25 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
// Optionally, |new_share_target| is updated with the ShareTargets sent to
|
||||
// OnTransferUpdate() calls.
|
||||
void ExpectTransferUpdates(
|
||||
MockTransferUpdateCallback& transfer_callback, const ShareTarget& target,
|
||||
MockTransferUpdateCallback& transfer_callback, int64_t share_target_id,
|
||||
const std::vector<TransferMetadata::Status>& updates,
|
||||
std::function<void()> callback, ShareTarget* new_share_target = nullptr) {
|
||||
std::function<void()> callback) {
|
||||
expect_transfer_updates_count_ = 0;
|
||||
expect_transfer_updates_callback_ = std::move(callback);
|
||||
auto& expectation =
|
||||
EXPECT_CALL(transfer_callback, OnTransferUpdate).Times(updates.size());
|
||||
|
||||
for (TransferMetadata::Status status : updates) {
|
||||
expectation.WillOnce(
|
||||
testing::Invoke([=](const ShareTarget& share_target,
|
||||
const AttachmentContainer& container,
|
||||
const TransferMetadata& metadata) {
|
||||
EXPECT_EQ(share_target.id, target.id);
|
||||
expectation.WillOnce(testing::Invoke(
|
||||
[this, share_target_id, status, update_size = updates.size()](
|
||||
const ShareTarget& share_target,
|
||||
const AttachmentContainer& container,
|
||||
const TransferMetadata& metadata) {
|
||||
EXPECT_EQ(share_target.id, share_target_id);
|
||||
EXPECT_EQ(metadata.status(), status);
|
||||
if (new_share_target) {
|
||||
*new_share_target = share_target;
|
||||
}
|
||||
|
||||
++expect_transfer_updates_count_;
|
||||
if (expect_transfer_updates_count_ == updates.size()) {
|
||||
if (expect_transfer_updates_count_ == update_size) {
|
||||
expect_transfer_updates_callback_();
|
||||
}
|
||||
}));
|
||||
@@ -1005,22 +1003,19 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
}
|
||||
|
||||
// Returns the modified ShareTarget received from a TransferUpdate.
|
||||
std::optional<ShareTarget> SetUpOutgoingConnectionUntilAccept(
|
||||
MockTransferUpdateCallback& transfer_callback,
|
||||
const ShareTarget& target) {
|
||||
ShareTarget new_share_target;
|
||||
ExpectTransferUpdates(
|
||||
transfer_callback, target,
|
||||
{TransferMetadata::Status::kConnecting,
|
||||
TransferMetadata::Status::kAwaitingLocalConfirmation,
|
||||
TransferMetadata::Status::kAwaitingRemoteAcceptance},
|
||||
[] {}, &new_share_target);
|
||||
void SetUpOutgoingConnectionUntilAccept(
|
||||
MockTransferUpdateCallback& transfer_callback, int64_t share_target_id) {
|
||||
ExpectTransferUpdates(transfer_callback, share_target_id,
|
||||
{TransferMetadata::Status::kConnecting,
|
||||
TransferMetadata::Status::kAwaitingLocalConfirmation,
|
||||
TransferMetadata::Status::kAwaitingRemoteAcceptance},
|
||||
[] {});
|
||||
|
||||
absl::Notification send_notification;
|
||||
NearbySharingServiceImpl::StatusCodes send_result;
|
||||
EXPECT_CALL(*mock_app_info_, SetActiveFlag());
|
||||
service_->SendAttachments(
|
||||
target.id, CreateTextAttachments({kTextPayload}),
|
||||
share_target_id, CreateTextAttachments({kTextPayload}),
|
||||
[&](NearbySharingServiceImpl::StatusCodes status_codes) {
|
||||
send_result = status_codes;
|
||||
send_notification.Notify();
|
||||
@@ -1030,20 +1025,19 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
send_notification.WaitForNotificationWithTimeout(kTaskWaitTimeout));
|
||||
EXPECT_EQ(send_result, NearbySharingServiceImpl::StatusCodes::kOk);
|
||||
|
||||
FlushTesting();
|
||||
// Verify data sent to the remote device so far.
|
||||
if (!ExpectPairedKeyEncryptionFrame()) {
|
||||
return std::nullopt;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ExpectPairedKeyResultFrame()) {
|
||||
return std::nullopt;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ExpectIntroductionFrame().has_value()) {
|
||||
return std::nullopt;
|
||||
return;
|
||||
}
|
||||
|
||||
return new_share_target;
|
||||
}
|
||||
|
||||
struct PayloadInfo {
|
||||
@@ -1053,7 +1047,7 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
|
||||
PayloadInfo AcceptAndSendPayload(
|
||||
MockTransferUpdateCallback& transfer_callback,
|
||||
const ShareTarget& target) {
|
||||
int64_t share_target_id) {
|
||||
PayloadInfo info = {};
|
||||
fake_nearby_connections_manager_->set_send_payload_callback(
|
||||
[&](std::unique_ptr<Payload> payload,
|
||||
@@ -1068,7 +1062,7 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
|
||||
// We're now waiting for the remote device to respond with the accept
|
||||
// result.
|
||||
ExpectTransferUpdates(transfer_callback, target,
|
||||
ExpectTransferUpdates(transfer_callback, share_target_id,
|
||||
{TransferMetadata::Status::kInProgress}, [] {});
|
||||
|
||||
// Kick off send process by accepting the transfer from the remote device.
|
||||
@@ -1077,10 +1071,10 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
}
|
||||
|
||||
void FinishOutgoingTransfer(MockTransferUpdateCallback& transfer_callback,
|
||||
const ShareTarget& target,
|
||||
int64_t share_target_id,
|
||||
const PayloadInfo& info) {
|
||||
// Simulate a successful transfer via Nearby Connections.
|
||||
ExpectTransferUpdates(transfer_callback, target,
|
||||
ExpectTransferUpdates(transfer_callback, share_target_id,
|
||||
{TransferMetadata::Status::kComplete}, [] {});
|
||||
|
||||
sharing_service_task_runner_->PostTask([info = info]() {
|
||||
@@ -1127,7 +1121,7 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
// required to simulate a successful incoming transfer.
|
||||
void SuccessfullyReceiveTransfer() {
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
ShareTarget share_target = SetUpIncomingConnection(callback);
|
||||
int64_t share_target_id = SetUpIncomingConnection(callback);
|
||||
|
||||
absl::Notification notification;
|
||||
EXPECT_CALL(callback, OnTransferUpdate(testing::_, testing::_, testing::_))
|
||||
@@ -1139,7 +1133,7 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
TransferMetadata::Status::kAwaitingRemoteAcceptance);
|
||||
}));
|
||||
|
||||
service_->Accept(share_target.id,
|
||||
service_->Accept(share_target_id,
|
||||
[&](NearbySharingServiceImpl::StatusCodes status_code) {
|
||||
EXPECT_EQ(status_code,
|
||||
NearbySharingServiceImpl::StatusCodes::kOk);
|
||||
@@ -1150,7 +1144,7 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
|
||||
// Fail to accept again.
|
||||
service_->Accept(
|
||||
share_target.id,
|
||||
share_target_id,
|
||||
[&](NearbySharingServiceImpl::StatusCodes status_code) {
|
||||
EXPECT_EQ(status_code,
|
||||
NearbySharingServiceImpl::StatusCodes::kOutOfOrderApiCall);
|
||||
@@ -1644,7 +1638,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
RegisterSendSurfaceAlreadyReceivingNotDiscovering) {
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
ShareTarget share_target = SetUpIncomingConnection(callback);
|
||||
SetUpIncomingConnection(callback);
|
||||
EXPECT_FALSE(connection_.IsClosed());
|
||||
|
||||
MockTransferUpdateCallback send_callback;
|
||||
@@ -2625,7 +2619,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, IncomingConnectionTimedOut) {
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
ShareTarget share_target = SetUpIncomingConnection(callback);
|
||||
SetUpIncomingConnection(callback);
|
||||
EXPECT_FALSE(connection_.IsClosed());
|
||||
|
||||
EXPECT_CALL(callback, OnTransferUpdate(testing::_, testing::_, testing::_))
|
||||
@@ -2646,7 +2640,7 @@ TEST_F(NearbySharingServiceImplTest, IncomingConnectionTimedOut) {
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
IncomingConnectionClosedWaitingLocalConfirmation) {
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
ShareTarget share_target = SetUpIncomingConnection(callback);
|
||||
SetUpIncomingConnection(callback);
|
||||
|
||||
EXPECT_CALL(callback, OnTransferUpdate(testing::_, testing::_, testing::_))
|
||||
.WillOnce(testing::Invoke(
|
||||
@@ -2874,10 +2868,9 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, AcceptInvalidShareTarget) {
|
||||
ShareTarget share_target;
|
||||
absl::Notification notification;
|
||||
service_->Accept(
|
||||
share_target.id, [&](NearbySharingServiceImpl::StatusCodes status_code) {
|
||||
98765L, [&](NearbySharingServiceImpl::StatusCodes status_code) {
|
||||
EXPECT_EQ(status_code,
|
||||
NearbySharingServiceImpl::StatusCodes::kInvalidArgument);
|
||||
notification.Notify();
|
||||
@@ -2888,7 +2881,7 @@ TEST_F(NearbySharingServiceImplTest, AcceptInvalidShareTarget) {
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, AcceptValidShareTarget) {
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
ShareTarget share_target = SetUpIncomingConnection(callback);
|
||||
int64_t share_target_id = SetUpIncomingConnection(callback);
|
||||
|
||||
absl::Notification notification;
|
||||
EXPECT_CALL(callback, OnTransferUpdate(testing::_, testing::_, testing::_))
|
||||
@@ -2901,7 +2894,7 @@ TEST_F(NearbySharingServiceImplTest, AcceptValidShareTarget) {
|
||||
}));
|
||||
|
||||
service_->Accept(
|
||||
share_target.id, [&](NearbySharingServiceImpl::StatusCodes status_code) {
|
||||
share_target_id, [&](NearbySharingServiceImpl::StatusCodes status_code) {
|
||||
EXPECT_EQ(status_code, NearbySharingServiceImpl::StatusCodes::kOk);
|
||||
notification.Notify();
|
||||
});
|
||||
@@ -2930,7 +2923,7 @@ TEST_F(NearbySharingServiceImplTest, AcceptValidShareTargetPayloadSuccessful) {
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
AcceptValidShareTargetPayloadSuccessfulIncomingPayloadNotFound) {
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
ShareTarget share_target = SetUpIncomingConnection(callback);
|
||||
int64_t share_target_id = SetUpIncomingConnection(callback);
|
||||
|
||||
absl::Notification notification;
|
||||
EXPECT_CALL(callback, OnTransferUpdate(testing::_, testing::_, testing::_))
|
||||
@@ -2943,7 +2936,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
}));
|
||||
|
||||
service_->Accept(
|
||||
share_target.id, [&](NearbySharingServiceImpl::StatusCodes status_code) {
|
||||
share_target_id, [&](NearbySharingServiceImpl::StatusCodes status_code) {
|
||||
EXPECT_EQ(status_code, NearbySharingServiceImpl::StatusCodes::kOk);
|
||||
notification.Notify();
|
||||
});
|
||||
@@ -3036,7 +3029,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, AcceptValidShareTargetPayloadFailed) {
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
ShareTarget share_target = SetUpIncomingConnection(callback);
|
||||
int64_t share_target_id = SetUpIncomingConnection(callback);
|
||||
|
||||
absl::Notification notification;
|
||||
EXPECT_CALL(callback, OnTransferUpdate(testing::_, testing::_, testing::_))
|
||||
@@ -3049,7 +3042,7 @@ TEST_F(NearbySharingServiceImplTest, AcceptValidShareTargetPayloadFailed) {
|
||||
}));
|
||||
|
||||
service_->Accept(
|
||||
share_target.id, [&](NearbySharingServiceImpl::StatusCodes status_code) {
|
||||
share_target_id, [&](NearbySharingServiceImpl::StatusCodes status_code) {
|
||||
EXPECT_EQ(status_code, NearbySharingServiceImpl::StatusCodes::kOk);
|
||||
notification.Notify();
|
||||
});
|
||||
@@ -3103,7 +3096,7 @@ TEST_F(NearbySharingServiceImplTest, AcceptValidShareTargetPayloadFailed) {
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, AcceptValidShareTargetPayloadCancelled) {
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
ShareTarget share_target = SetUpIncomingConnection(callback);
|
||||
int64_t share_target_id = SetUpIncomingConnection(callback);
|
||||
|
||||
absl::Notification notification;
|
||||
EXPECT_CALL(callback, OnTransferUpdate(testing::_, testing::_, testing::_))
|
||||
@@ -3116,7 +3109,7 @@ TEST_F(NearbySharingServiceImplTest, AcceptValidShareTargetPayloadCancelled) {
|
||||
}));
|
||||
|
||||
service_->Accept(
|
||||
share_target.id, [&](NearbySharingServiceImpl::StatusCodes status_code) {
|
||||
share_target_id, [&](NearbySharingServiceImpl::StatusCodes status_code) {
|
||||
EXPECT_EQ(status_code, NearbySharingServiceImpl::StatusCodes::kOk);
|
||||
notification.Notify();
|
||||
});
|
||||
@@ -3168,10 +3161,9 @@ TEST_F(NearbySharingServiceImplTest, AcceptValidShareTargetPayloadCancelled) {
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, RejectInvalidShareTarget) {
|
||||
ShareTarget share_target;
|
||||
absl::Notification notification;
|
||||
service_->Reject(
|
||||
share_target.id, [&](NearbySharingServiceImpl::StatusCodes status_code) {
|
||||
98456L, [&](NearbySharingServiceImpl::StatusCodes status_code) {
|
||||
EXPECT_EQ(status_code,
|
||||
NearbySharingServiceImpl::StatusCodes::kInvalidArgument);
|
||||
notification.Notify();
|
||||
@@ -3182,7 +3174,7 @@ TEST_F(NearbySharingServiceImplTest, RejectInvalidShareTarget) {
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, RejectValidShareTarget) {
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
ShareTarget share_target = SetUpIncomingConnection(callback);
|
||||
int64_t share_target_id = SetUpIncomingConnection(callback);
|
||||
|
||||
absl::Notification notification;
|
||||
EXPECT_CALL(callback, OnTransferUpdate(testing::_, testing::_, testing::_))
|
||||
@@ -3194,7 +3186,7 @@ TEST_F(NearbySharingServiceImplTest, RejectValidShareTarget) {
|
||||
}));
|
||||
|
||||
service_->Reject(
|
||||
share_target.id, [&](NearbySharingServiceImpl::StatusCodes status_code) {
|
||||
share_target_id, [&](NearbySharingServiceImpl::StatusCodes status_code) {
|
||||
EXPECT_EQ(status_code, NearbySharingServiceImpl::StatusCodes::kOk);
|
||||
notification.Notify();
|
||||
});
|
||||
@@ -3395,7 +3387,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, RegisterReceiveSurfaceAlreadyReceiving) {
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
ShareTarget share_target = SetUpIncomingConnection(callback);
|
||||
SetUpIncomingConnection(callback);
|
||||
EXPECT_FALSE(connection_.IsClosed());
|
||||
|
||||
EXPECT_EQ(
|
||||
@@ -3426,10 +3418,10 @@ TEST_F(NearbySharingServiceImplTest, RegisterReceiveSurfaceWhileDiscovering) {
|
||||
TEST_F(NearbySharingServiceImplTest, SendAttachmentsWithoutAttachments) {
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
ShareTarget target =
|
||||
int64_t target_id =
|
||||
DiscoverShareTarget(transfer_callback, discovery_callback);
|
||||
|
||||
EXPECT_EQ(SendAttachments(target, /*attachment_container=*/nullptr),
|
||||
EXPECT_EQ(SendAttachments(target_id, /*attachment_container=*/nullptr),
|
||||
NearbySharingServiceImpl::StatusCodes::kInvalidArgument);
|
||||
|
||||
UnregisterSendSurface(&transfer_callback);
|
||||
@@ -3438,17 +3430,17 @@ TEST_F(NearbySharingServiceImplTest, SendAttachmentsWithoutAttachments) {
|
||||
TEST_F(NearbySharingServiceImplTest, RegisterReceiveSurfaceWhileSending) {
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
ShareTarget target =
|
||||
int64_t target_id =
|
||||
SetUpOutgoingShareTarget(transfer_callback, discovery_callback);
|
||||
|
||||
absl::Notification notification;
|
||||
ExpectTransferUpdates(transfer_callback, target,
|
||||
ExpectTransferUpdates(transfer_callback, target_id,
|
||||
{TransferMetadata::Status::kConnecting,
|
||||
TransferMetadata::Status::kAwaitingLocalConfirmation,
|
||||
TransferMetadata::Status::kAwaitingRemoteAcceptance},
|
||||
[&]() { notification.Notify(); });
|
||||
EXPECT_CALL(*mock_app_info_, SetActiveFlag());
|
||||
EXPECT_EQ(SendAttachments(target, CreateTextAttachments({kTextPayload})),
|
||||
EXPECT_EQ(SendAttachments(target_id, CreateTextAttachments({kTextPayload})),
|
||||
NearbySharingServiceImpl::StatusCodes::kOk);
|
||||
EXPECT_TRUE(notification.WaitForNotificationWithTimeout(kWaitTimeout));
|
||||
|
||||
@@ -3463,30 +3455,29 @@ TEST_F(NearbySharingServiceImplTest, RegisterReceiveSurfaceWhileSending) {
|
||||
TEST_F(NearbySharingServiceImplTest, SendTextAlreadySending) {
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
ShareTarget target =
|
||||
int64_t target_id =
|
||||
SetUpOutgoingShareTarget(transfer_callback, discovery_callback);
|
||||
|
||||
absl::Notification notification;
|
||||
ExpectTransferUpdates(transfer_callback, target,
|
||||
ExpectTransferUpdates(transfer_callback, target_id,
|
||||
{TransferMetadata::Status::kConnecting,
|
||||
TransferMetadata::Status::kAwaitingLocalConfirmation,
|
||||
TransferMetadata::Status::kAwaitingRemoteAcceptance},
|
||||
[&]() { notification.Notify(); });
|
||||
EXPECT_CALL(*mock_app_info_, SetActiveFlag());
|
||||
EXPECT_EQ(SendAttachments(target, CreateTextAttachments({kTextPayload})),
|
||||
EXPECT_EQ(SendAttachments(target_id, CreateTextAttachments({kTextPayload})),
|
||||
NearbySharingServiceImpl::StatusCodes::kOk);
|
||||
EXPECT_TRUE(notification.WaitForNotificationWithTimeout(kWaitTimeout));
|
||||
|
||||
// We're now in the sending state, try to send again should fail
|
||||
EXPECT_EQ(SendAttachments(target, CreateTextAttachments({kTextPayload})),
|
||||
EXPECT_EQ(SendAttachments(target_id, CreateTextAttachments({kTextPayload})),
|
||||
NearbySharingServiceImpl::StatusCodes::kError);
|
||||
|
||||
UnregisterSendSurface(&transfer_callback);
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, SendTextWithoutScanning) {
|
||||
ShareTarget target;
|
||||
EXPECT_EQ(SendAttachments(target, CreateTextAttachments({kTextPayload})),
|
||||
EXPECT_EQ(SendAttachments(325626L, CreateTextAttachments({kTextPayload})),
|
||||
NearbySharingServiceImpl::StatusCodes::kError);
|
||||
}
|
||||
|
||||
@@ -3495,8 +3486,7 @@ TEST_F(NearbySharingServiceImplTest, SendTextUnknownTarget) {
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
DiscoverShareTarget(transfer_callback, discovery_callback);
|
||||
|
||||
ShareTarget target;
|
||||
EXPECT_EQ(SendAttachments(target, CreateTextAttachments({kTextPayload})),
|
||||
EXPECT_EQ(SendAttachments(12345L, CreateTextAttachments({kTextPayload})),
|
||||
NearbySharingServiceImpl::StatusCodes::kInvalidArgument);
|
||||
UnregisterSendSurface(&transfer_callback);
|
||||
}
|
||||
@@ -3507,10 +3497,10 @@ TEST_F(NearbySharingServiceImplTest, SendTextFailedCreateEndpointInfo) {
|
||||
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
ShareTarget target =
|
||||
int64_t target_id =
|
||||
DiscoverShareTarget(transfer_callback, discovery_callback);
|
||||
|
||||
EXPECT_EQ(SendAttachments(target, CreateTextAttachments({kTextPayload})),
|
||||
EXPECT_EQ(SendAttachments(target_id, CreateTextAttachments({kTextPayload})),
|
||||
NearbySharingServiceImpl::StatusCodes::kError);
|
||||
|
||||
UnregisterSendSurface(&transfer_callback);
|
||||
@@ -3521,18 +3511,18 @@ TEST_F(NearbySharingServiceImplTest, SendTextFailedToConnect) {
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
// Call DiscoverShareTarget() instead of SetUpOutgoingShareTarget() as we want
|
||||
// to fail before key verification is done.
|
||||
ShareTarget target =
|
||||
int64_t target_id =
|
||||
DiscoverShareTarget(transfer_callback, discovery_callback);
|
||||
|
||||
absl::Notification notification;
|
||||
ExpectTransferUpdates(
|
||||
transfer_callback, target,
|
||||
transfer_callback, target_id,
|
||||
{TransferMetadata::Status::kConnecting,
|
||||
TransferMetadata::Status::kFailedToInitiateOutgoingConnection},
|
||||
[&]() { notification.Notify(); });
|
||||
EXPECT_CALL(*mock_app_info_, SetActiveFlag());
|
||||
|
||||
EXPECT_EQ(SendAttachments(target, CreateTextAttachments({kTextPayload})),
|
||||
EXPECT_EQ(SendAttachments(target_id, CreateTextAttachments({kTextPayload})),
|
||||
NearbySharingServiceImpl::StatusCodes::kOk);
|
||||
EXPECT_TRUE(notification.WaitForNotificationWithTimeout(kWaitTimeout));
|
||||
|
||||
@@ -3542,12 +3532,12 @@ TEST_F(NearbySharingServiceImplTest, SendTextFailedToConnect) {
|
||||
TEST_F(NearbySharingServiceImplTest, SendTextFailedKeyVerification) {
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
ShareTarget target =
|
||||
int64_t target_id =
|
||||
DiscoverShareTarget(transfer_callback, discovery_callback);
|
||||
|
||||
absl::Notification notification;
|
||||
ExpectTransferUpdates(
|
||||
transfer_callback, target,
|
||||
transfer_callback, target_id,
|
||||
{TransferMetadata::Status::kConnecting,
|
||||
TransferMetadata::Status::kPairedKeyVerificationFailed},
|
||||
[&]() { notification.Notify(); });
|
||||
@@ -3558,7 +3548,7 @@ TEST_F(NearbySharingServiceImplTest, SendTextFailedKeyVerification) {
|
||||
fake_nearby_connections_manager_->set_nearby_connection(&connection_);
|
||||
EXPECT_CALL(*mock_app_info_, SetActiveFlag());
|
||||
|
||||
EXPECT_EQ(SendAttachments(target, CreateTextAttachments({kTextPayload})),
|
||||
EXPECT_EQ(SendAttachments(target_id, CreateTextAttachments({kTextPayload})),
|
||||
NearbySharingServiceImpl::StatusCodes::kOk);
|
||||
EXPECT_TRUE(notification.WaitForNotificationWithTimeout(kWaitTimeout));
|
||||
|
||||
@@ -3568,11 +3558,11 @@ TEST_F(NearbySharingServiceImplTest, SendTextFailedKeyVerification) {
|
||||
TEST_F(NearbySharingServiceImplTest, SendTextUnableToVerifyKey) {
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
ShareTarget target =
|
||||
int64_t target_id =
|
||||
DiscoverShareTarget(transfer_callback, discovery_callback);
|
||||
|
||||
absl::Notification notification;
|
||||
ExpectTransferUpdates(transfer_callback, target,
|
||||
ExpectTransferUpdates(transfer_callback, target_id,
|
||||
{TransferMetadata::Status::kConnecting,
|
||||
TransferMetadata::Status::kAwaitingLocalConfirmation,
|
||||
TransferMetadata::Status::kAwaitingRemoteAcceptance},
|
||||
@@ -3584,7 +3574,7 @@ TEST_F(NearbySharingServiceImplTest, SendTextUnableToVerifyKey) {
|
||||
fake_nearby_connections_manager_->set_nearby_connection(&connection_);
|
||||
EXPECT_CALL(*mock_app_info_, SetActiveFlag());
|
||||
|
||||
EXPECT_EQ(SendAttachments(target, CreateTextAttachments({kTextPayload})),
|
||||
EXPECT_EQ(SendAttachments(target_id, CreateTextAttachments({kTextPayload})),
|
||||
NearbySharingServiceImpl::StatusCodes::kOk);
|
||||
EXPECT_TRUE(notification.WaitForNotificationWithTimeout(kWaitTimeout));
|
||||
|
||||
@@ -3598,18 +3588,18 @@ INSTANTIATE_TEST_SUITE_P(NearbySharingServiceImplSendFailureTest,
|
||||
TEST_P(NearbySharingServiceImplSendFailureTest, SendTextRemoteFailure) {
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
ShareTarget target =
|
||||
int64_t target_id =
|
||||
SetUpOutgoingShareTarget(transfer_callback, discovery_callback);
|
||||
|
||||
absl::Notification notification;
|
||||
ExpectTransferUpdates(transfer_callback, target,
|
||||
ExpectTransferUpdates(transfer_callback, target_id,
|
||||
{TransferMetadata::Status::kConnecting,
|
||||
TransferMetadata::Status::kAwaitingLocalConfirmation,
|
||||
TransferMetadata::Status::kAwaitingRemoteAcceptance},
|
||||
[&]() { notification.Notify(); });
|
||||
EXPECT_CALL(*mock_app_info_, SetActiveFlag());
|
||||
|
||||
EXPECT_EQ(SendAttachments(target, CreateTextAttachments({kTextPayload})),
|
||||
EXPECT_EQ(SendAttachments(target_id, CreateTextAttachments({kTextPayload})),
|
||||
NearbySharingServiceImpl::StatusCodes::kOk);
|
||||
EXPECT_TRUE(notification.WaitForNotificationWithTimeout(kWaitTimeout));
|
||||
|
||||
@@ -3620,7 +3610,8 @@ TEST_P(NearbySharingServiceImplSendFailureTest, SendTextRemoteFailure) {
|
||||
|
||||
// We're now waiting for the remote device to respond with the accept
|
||||
absl::Notification reject_notification;
|
||||
ExpectTransferUpdates(transfer_callback, target, {GetParam().expected_status},
|
||||
ExpectTransferUpdates(transfer_callback, target_id,
|
||||
{GetParam().expected_status},
|
||||
[&]() { reject_notification.Notify(); });
|
||||
|
||||
// Cancel the transfer by rejecting it.
|
||||
@@ -3635,21 +3626,21 @@ TEST_P(NearbySharingServiceImplSendFailureTest, SendTextRemoteFailure) {
|
||||
TEST_P(NearbySharingServiceImplSendFailureTest, SendFilesRemoteFailure) {
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
ShareTarget target =
|
||||
int64_t target_id =
|
||||
SetUpOutgoingShareTarget(transfer_callback, discovery_callback);
|
||||
|
||||
std::vector<uint8_t> test_data = {'T', 'e', 's', 't'};
|
||||
std::filesystem::path path = CreateTestFile("text.txt", test_data);
|
||||
|
||||
absl::Notification notification;
|
||||
ExpectTransferUpdates(transfer_callback, target,
|
||||
ExpectTransferUpdates(transfer_callback, target_id,
|
||||
{TransferMetadata::Status::kConnecting,
|
||||
TransferMetadata::Status::kAwaitingLocalConfirmation,
|
||||
TransferMetadata::Status::kAwaitingRemoteAcceptance},
|
||||
[&]() { notification.Notify(); });
|
||||
EXPECT_CALL(*mock_app_info_, SetActiveFlag());
|
||||
|
||||
EXPECT_EQ(SendAttachments(target, CreateFileAttachments({path})),
|
||||
EXPECT_EQ(SendAttachments(target_id, CreateFileAttachments({path})),
|
||||
NearbySharingServiceImpl::StatusCodes::kOk);
|
||||
EXPECT_TRUE(notification.WaitForNotificationWithTimeout(kWaitTimeout));
|
||||
|
||||
@@ -3660,7 +3651,8 @@ TEST_P(NearbySharingServiceImplSendFailureTest, SendFilesRemoteFailure) {
|
||||
|
||||
// We're now waiting for the remote device to respond with the accept
|
||||
absl::Notification reject_notification;
|
||||
ExpectTransferUpdates(transfer_callback, target, {GetParam().expected_status},
|
||||
ExpectTransferUpdates(transfer_callback, target_id,
|
||||
{GetParam().expected_status},
|
||||
[&]() { reject_notification.Notify(); });
|
||||
|
||||
// Cancel the transfer by rejecting it.
|
||||
@@ -3678,18 +3670,18 @@ TEST_F(NearbySharingServiceImplTest, SendTextSuccess) {
|
||||
AccountManager::Account account;
|
||||
account.id = kTestAccountId;
|
||||
account_manager().SetAccount(account);
|
||||
ShareTarget target =
|
||||
int64_t target_id =
|
||||
SetUpOutgoingShareTarget(transfer_callback, discovery_callback);
|
||||
|
||||
absl::Notification notification;
|
||||
ExpectTransferUpdates(transfer_callback, target,
|
||||
ExpectTransferUpdates(transfer_callback, target_id,
|
||||
{TransferMetadata::Status::kConnecting,
|
||||
TransferMetadata::Status::kAwaitingLocalConfirmation,
|
||||
TransferMetadata::Status::kAwaitingRemoteAcceptance},
|
||||
[&]() { notification.Notify(); });
|
||||
EXPECT_CALL(*mock_app_info_, SetActiveFlag());
|
||||
|
||||
EXPECT_EQ(SendAttachments(target, CreateTextAttachments({kTextPayload})),
|
||||
EXPECT_EQ(SendAttachments(target_id, CreateTextAttachments({kTextPayload})),
|
||||
NearbySharingServiceImpl::StatusCodes::kOk);
|
||||
EXPECT_TRUE(notification.WaitForNotificationWithTimeout(kWaitTimeout));
|
||||
|
||||
@@ -3720,8 +3712,8 @@ TEST_F(NearbySharingServiceImplTest, SendTextSuccess) {
|
||||
EXPECT_EQ(advertisement->encrypted_metadata_key(),
|
||||
test_metadata_key.encrypted_key());
|
||||
|
||||
PayloadInfo info = AcceptAndSendPayload(transfer_callback, target);
|
||||
FinishOutgoingTransfer(transfer_callback, target, info);
|
||||
PayloadInfo info = AcceptAndSendPayload(transfer_callback, target_id);
|
||||
FinishOutgoingTransfer(transfer_callback, target_id, info);
|
||||
|
||||
// We should not have called disconnect yet as we want to wait for 1 minute to
|
||||
// make sure all outgoing packets have been sent properly.
|
||||
@@ -3742,11 +3734,11 @@ TEST_F(NearbySharingServiceImplTest, SendTextSuccess) {
|
||||
TEST_F(NearbySharingServiceImplTest, SendTextSuccessClosedConnection) {
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
ShareTarget target =
|
||||
int64_t target_id =
|
||||
SetUpOutgoingShareTarget(transfer_callback, discovery_callback);
|
||||
SetUpOutgoingConnectionUntilAccept(transfer_callback, target);
|
||||
PayloadInfo info = AcceptAndSendPayload(transfer_callback, target);
|
||||
FinishOutgoingTransfer(transfer_callback, target, info);
|
||||
SetUpOutgoingConnectionUntilAccept(transfer_callback, target_id);
|
||||
PayloadInfo info = AcceptAndSendPayload(transfer_callback, target_id);
|
||||
FinishOutgoingTransfer(transfer_callback, target_id, info);
|
||||
|
||||
// We should not have called disconnect yet as we want to wait for 1 minute
|
||||
// to make sure all outgoing packets have been sent properly.
|
||||
@@ -3772,7 +3764,7 @@ TEST_F(NearbySharingServiceImplTest, SendTextSuccessClosedConnection) {
|
||||
TEST_F(NearbySharingServiceImplTest, SendFilesSuccess) {
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
ShareTarget target =
|
||||
int64_t target_id =
|
||||
SetUpOutgoingShareTarget(transfer_callback, discovery_callback);
|
||||
|
||||
std::vector<uint8_t> test_data = {'T', 'e', 's', 't'};
|
||||
@@ -3780,14 +3772,14 @@ TEST_F(NearbySharingServiceImplTest, SendFilesSuccess) {
|
||||
std::filesystem::path path = CreateTestFile(file_name, test_data);
|
||||
|
||||
absl::Notification introduction_notification;
|
||||
ExpectTransferUpdates(transfer_callback, target,
|
||||
ExpectTransferUpdates(transfer_callback, target_id,
|
||||
{TransferMetadata::Status::kConnecting,
|
||||
TransferMetadata::Status::kAwaitingLocalConfirmation,
|
||||
TransferMetadata::Status::kAwaitingRemoteAcceptance},
|
||||
[&]() { introduction_notification.Notify(); });
|
||||
EXPECT_CALL(*mock_app_info_, SetActiveFlag());
|
||||
|
||||
EXPECT_EQ(SendAttachments(target, CreateFileAttachments({path})),
|
||||
EXPECT_EQ(SendAttachments(target_id, CreateFileAttachments({path})),
|
||||
NearbySharingServiceImpl::StatusCodes::kOk);
|
||||
EXPECT_TRUE(
|
||||
introduction_notification.WaitForNotificationWithTimeout(kWaitTimeout));
|
||||
@@ -3821,7 +3813,7 @@ TEST_F(NearbySharingServiceImplTest, SendFilesSuccess) {
|
||||
// We're now waiting for the remote device to respond with the accept
|
||||
// result.
|
||||
absl::Notification accept_notification;
|
||||
ExpectTransferUpdates(transfer_callback, target,
|
||||
ExpectTransferUpdates(transfer_callback, target_id,
|
||||
{TransferMetadata::Status::kInProgress},
|
||||
[&]() { accept_notification.Notify(); });
|
||||
|
||||
@@ -3842,18 +3834,18 @@ TEST_F(NearbySharingServiceImplTest, SendWifiCredentialsSuccess) {
|
||||
true);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
ShareTarget target =
|
||||
int64_t target_id =
|
||||
SetUpOutgoingShareTarget(transfer_callback, discovery_callback);
|
||||
|
||||
absl::Notification introduction_notification;
|
||||
ExpectTransferUpdates(transfer_callback, target,
|
||||
ExpectTransferUpdates(transfer_callback, target_id,
|
||||
{TransferMetadata::Status::kConnecting,
|
||||
TransferMetadata::Status::kAwaitingLocalConfirmation,
|
||||
TransferMetadata::Status::kAwaitingRemoteAcceptance},
|
||||
[&]() { introduction_notification.Notify(); });
|
||||
EXPECT_CALL(*mock_app_info_, SetActiveFlag());
|
||||
|
||||
EXPECT_EQ(SendAttachments(target, CreateWifiCredentialAttachments(
|
||||
EXPECT_EQ(SendAttachments(target_id, CreateWifiCredentialAttachments(
|
||||
"GoogleGuest", "password")),
|
||||
NearbySharingServiceImpl::StatusCodes::kOk);
|
||||
EXPECT_TRUE(
|
||||
@@ -3892,7 +3884,7 @@ TEST_F(NearbySharingServiceImplTest, SendWifiCredentialsSuccess) {
|
||||
// We're now waiting for the remote device to respond with the accept
|
||||
// result.
|
||||
absl::Notification accept_notification;
|
||||
ExpectTransferUpdates(transfer_callback, target,
|
||||
ExpectTransferUpdates(transfer_callback, target_id,
|
||||
{TransferMetadata::Status::kInProgress},
|
||||
[&]() { accept_notification.Notify(); });
|
||||
|
||||
@@ -3909,13 +3901,10 @@ TEST_F(NearbySharingServiceImplTest, SendWifiCredentialsSuccess) {
|
||||
TEST_F(NearbySharingServiceImplTest, CancelSenderInitiator) {
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
ShareTarget target =
|
||||
int64_t target_id =
|
||||
SetUpOutgoingShareTarget(transfer_callback, discovery_callback);
|
||||
std::optional<ShareTarget> outgoing_share_target =
|
||||
SetUpOutgoingConnectionUntilAccept(transfer_callback, target);
|
||||
ASSERT_TRUE(outgoing_share_target.has_value());
|
||||
target = *outgoing_share_target;
|
||||
PayloadInfo info = AcceptAndSendPayload(transfer_callback, target);
|
||||
SetUpOutgoingConnectionUntilAccept(transfer_callback, target_id);
|
||||
PayloadInfo info = AcceptAndSendPayload(transfer_callback, target_id);
|
||||
|
||||
// After we stop scanning, we check back in after kInvalidateDelay
|
||||
// milliseconds to make sure that we stopped in order to send a file and
|
||||
@@ -3930,14 +3919,14 @@ TEST_F(NearbySharingServiceImplTest, CancelSenderInitiator) {
|
||||
.WillOnce(testing::Invoke(
|
||||
[&](const ShareTarget& share_target,
|
||||
const AttachmentContainer& container, TransferMetadata metadata) {
|
||||
EXPECT_EQ(share_target.id, target.id);
|
||||
EXPECT_EQ(share_target.id, target_id);
|
||||
EXPECT_EQ(metadata.status(), TransferMetadata::Status::kCancelled);
|
||||
}));
|
||||
EXPECT_FALSE(
|
||||
fake_nearby_connections_manager_->WasPayloadCanceled(info.payload_id));
|
||||
// The initiator of the cancellation explicitly calls Cancel().
|
||||
service_->Cancel(
|
||||
target.id, [&](NearbySharingServiceImpl::StatusCodes status_code) {
|
||||
target_id, [&](NearbySharingServiceImpl::StatusCodes status_code) {
|
||||
EXPECT_EQ(status_code, NearbySharingServiceImpl::StatusCodes::kOk);
|
||||
notification.Notify();
|
||||
});
|
||||
@@ -3962,13 +3951,10 @@ TEST_F(NearbySharingServiceImplTest, CancelSenderInitiator) {
|
||||
TEST_F(NearbySharingServiceImplTest, CancelSenderNoninitiator) {
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
ShareTarget target =
|
||||
int64_t target_id =
|
||||
SetUpOutgoingShareTarget(transfer_callback, discovery_callback);
|
||||
std::optional<ShareTarget> outgoing_share_target =
|
||||
SetUpOutgoingConnectionUntilAccept(transfer_callback, target);
|
||||
ASSERT_TRUE(outgoing_share_target.has_value());
|
||||
target = *outgoing_share_target;
|
||||
PayloadInfo info = AcceptAndSendPayload(transfer_callback, target);
|
||||
SetUpOutgoingConnectionUntilAccept(transfer_callback, target_id);
|
||||
PayloadInfo info = AcceptAndSendPayload(transfer_callback, target_id);
|
||||
|
||||
absl::Notification notification;
|
||||
EXPECT_CALL(transfer_callback,
|
||||
@@ -3976,7 +3962,7 @@ TEST_F(NearbySharingServiceImplTest, CancelSenderNoninitiator) {
|
||||
.WillOnce(testing::Invoke(
|
||||
[&](const ShareTarget& share_target,
|
||||
const AttachmentContainer& container, TransferMetadata metadata) {
|
||||
EXPECT_EQ(share_target.id, target.id);
|
||||
EXPECT_EQ(share_target.id, target_id);
|
||||
EXPECT_EQ(metadata.status(), TransferMetadata::Status::kCancelled);
|
||||
notification.Notify();
|
||||
}));
|
||||
@@ -3995,7 +3981,7 @@ TEST_F(NearbySharingServiceImplTest, CancelSenderNoninitiator) {
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, CancelReceiverInitiator) {
|
||||
NiceMock<MockTransferUpdateCallback> transfer_callback;
|
||||
ShareTarget target = SetUpIncomingConnection(transfer_callback);
|
||||
int64_t target_id = SetUpIncomingConnection(transfer_callback);
|
||||
ASSERT_TRUE(ExpectPairedKeyEncryptionFrame());
|
||||
ASSERT_TRUE(ExpectPairedKeyResultFrame());
|
||||
|
||||
@@ -4005,14 +3991,14 @@ TEST_F(NearbySharingServiceImplTest, CancelReceiverInitiator) {
|
||||
.WillOnce(testing::Invoke([&](const ShareTarget& share_target,
|
||||
const AttachmentContainer& container,
|
||||
TransferMetadata metadata) {
|
||||
EXPECT_EQ(share_target.id, target.id);
|
||||
EXPECT_EQ(share_target.id, target_id);
|
||||
EXPECT_EQ(metadata.status(), TransferMetadata::Status::kCancelled);
|
||||
}));
|
||||
EXPECT_FALSE(
|
||||
fake_nearby_connections_manager_->WasPayloadCanceled(kFilePayloadId));
|
||||
// The initiator of the cancellation explicitly calls Cancel().
|
||||
service_->Cancel(
|
||||
target.id, [&](NearbySharingServiceImpl::StatusCodes status_code) {
|
||||
target_id, [&](NearbySharingServiceImpl::StatusCodes status_code) {
|
||||
EXPECT_EQ(NearbySharingServiceImpl::StatusCodes::kOk, status_code);
|
||||
notification.Notify();
|
||||
});
|
||||
@@ -4035,7 +4021,7 @@ TEST_F(NearbySharingServiceImplTest, CancelReceiverInitiator) {
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, CancelReceiverNoninitiator) {
|
||||
NiceMock<MockTransferUpdateCallback> transfer_callback;
|
||||
ShareTarget target = SetUpIncomingConnection(transfer_callback);
|
||||
int64_t target_id = SetUpIncomingConnection(transfer_callback);
|
||||
ExpectPairedKeyEncryptionFrame();
|
||||
ExpectPairedKeyResultFrame();
|
||||
|
||||
@@ -4045,7 +4031,7 @@ TEST_F(NearbySharingServiceImplTest, CancelReceiverNoninitiator) {
|
||||
.WillOnce(testing::Invoke(
|
||||
[&](const ShareTarget& share_target,
|
||||
const AttachmentContainer& container, TransferMetadata metadata) {
|
||||
EXPECT_EQ(target.id, share_target.id);
|
||||
EXPECT_EQ(target_id, share_target.id);
|
||||
EXPECT_EQ(TransferMetadata::Status::kCancelled, metadata.status());
|
||||
notification.Notify();
|
||||
}));
|
||||
@@ -4729,12 +4715,12 @@ TEST_F(NearbySharingServiceImplTest, SelfShareAutoAccept) {
|
||||
// similar to other tests (see "AcceptValidShareTarget") but without the
|
||||
// explicit call to service_->Accept().
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
ShareTarget share_target = SetUpIncomingConnection(
|
||||
int64_t share_target_id = SetUpIncomingConnection(
|
||||
callback, /*is_foreground=*/false, /*for_self_share=*/true);
|
||||
|
||||
// Should fail to call accept.
|
||||
service_->Accept(
|
||||
share_target.id, [&](NearbySharingServiceImpl::StatusCodes status_code) {
|
||||
share_target_id, [&](NearbySharingServiceImpl::StatusCodes status_code) {
|
||||
EXPECT_EQ(status_code,
|
||||
NearbySharingServiceImpl::StatusCodes::kOutOfOrderApiCall);
|
||||
});
|
||||
@@ -4755,14 +4741,14 @@ TEST_F(NearbySharingServiceImplTest, SelfShareAutoAccept) {
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, SelfShareNoAutoAcceptInForeground) {
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
ShareTarget share_target = SetUpIncomingConnection(
|
||||
int64_t share_target_id = SetUpIncomingConnection(
|
||||
callback, /*is_foreground=*/true, /*for_self_share=*/true);
|
||||
|
||||
EXPECT_CALL(callback, OnTransferUpdate(testing::_, testing::_, testing::_))
|
||||
.Times(0);
|
||||
|
||||
service_->Accept(
|
||||
share_target.id, [&](NearbySharingServiceImpl::StatusCodes status_code) {
|
||||
share_target_id, [&](NearbySharingServiceImpl::StatusCodes status_code) {
|
||||
EXPECT_EQ(status_code,
|
||||
NearbySharingServiceImpl::StatusCodes::kOutOfOrderApiCall);
|
||||
});
|
||||
|
||||
@@ -14,21 +14,29 @@
|
||||
|
||||
#include "sharing/outgoing_share_target_info.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <filesystem> // NOLINT
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "sharing/attachment_container.h"
|
||||
#include "sharing/file_attachment.h"
|
||||
#include "sharing/internal/public/logging.h"
|
||||
#include "sharing/nearby_connection.h"
|
||||
#include "sharing/nearby_connections_types.h"
|
||||
#include "sharing/nearby_file_handler.h"
|
||||
#include "sharing/share_target.h"
|
||||
#include "sharing/share_target_info.h"
|
||||
#include "sharing/text_attachment.h"
|
||||
#include "sharing/transfer_metadata.h"
|
||||
#include "sharing/wifi_credentials_attachment.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace sharing {
|
||||
namespace nearby::sharing {
|
||||
|
||||
OutgoingShareTargetInfo::OutgoingShareTargetInfo(
|
||||
std::string endpoint_id, const ShareTarget& share_target,
|
||||
@@ -68,6 +76,83 @@ bool OutgoingShareTargetInfo::OnNewConnection(NearbyConnection* connection) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<std::filesystem::path> OutgoingShareTargetInfo::GetFilePaths()
|
||||
const {
|
||||
std::vector<std::filesystem::path> file_paths;
|
||||
file_paths.reserve(attachment_container().GetFileAttachments().size());
|
||||
for (const FileAttachment& file_attachment :
|
||||
attachment_container().GetFileAttachments()) {
|
||||
// All file attachments must have a file path.
|
||||
// That is verified in SendAttachments().
|
||||
file_paths.push_back(*file_attachment.file_path());
|
||||
}
|
||||
return file_paths;
|
||||
}
|
||||
|
||||
void OutgoingShareTargetInfo::CreateTextPayloads() {
|
||||
const std::vector<TextAttachment> attachments =
|
||||
attachment_container().GetTextAttachments();
|
||||
if (attachments.empty()) {
|
||||
return;
|
||||
}
|
||||
text_payloads_.clear();
|
||||
text_payloads_.reserve(attachments.size());
|
||||
for (const TextAttachment& attachment : attachments) {
|
||||
absl::string_view body = attachment.text_body();
|
||||
std::vector<uint8_t> bytes(body.begin(), body.end());
|
||||
text_payloads_.emplace_back(bytes);
|
||||
SetAttachmentPayloadId(attachment.id(), text_payloads_.back().id);
|
||||
}
|
||||
}
|
||||
|
||||
void OutgoingShareTargetInfo::CreateWifiCredentialsPayloads() {
|
||||
const std::vector<WifiCredentialsAttachment> attachments =
|
||||
attachment_container().GetWifiCredentialsAttachments();
|
||||
if (attachments.empty()) {
|
||||
return;
|
||||
}
|
||||
wifi_credentials_payloads_.clear();
|
||||
wifi_credentials_payloads_.reserve(attachments.size());
|
||||
for (const WifiCredentialsAttachment& attachment : attachments) {
|
||||
nearby::sharing::service::proto::WifiCredentials wifi_credentials;
|
||||
wifi_credentials.set_password(std::string(attachment.password()));
|
||||
wifi_credentials.set_hidden_ssid(attachment.is_hidden());
|
||||
|
||||
std::vector<uint8_t> bytes(wifi_credentials.ByteSizeLong());
|
||||
wifi_credentials.SerializeToArray(bytes.data(),
|
||||
wifi_credentials.ByteSizeLong());
|
||||
wifi_credentials_payloads_.emplace_back(bytes);
|
||||
SetAttachmentPayloadId(attachment.id(),
|
||||
wifi_credentials_payloads_.back().id);
|
||||
}
|
||||
}
|
||||
|
||||
bool OutgoingShareTargetInfo::CreateFilePayloads(
|
||||
const std::vector<NearbyFileHandler::FileInfo>& files) {
|
||||
AttachmentContainer& container = mutable_attachment_container();
|
||||
if (files.size() != container.GetFileAttachments().size()) {
|
||||
return false;
|
||||
}
|
||||
if (files.empty()) {
|
||||
return true;
|
||||
}
|
||||
file_payloads_.clear();
|
||||
file_payloads_.reserve(files.size());
|
||||
|
||||
for (size_t i = 0; i < files.size(); ++i) {
|
||||
const NearbyFileHandler::FileInfo& file_info = files[i];
|
||||
FileAttachment& attachment = container.GetMutableFileAttachment(i);
|
||||
attachment.set_size(file_info.size);
|
||||
InputFile input_file;
|
||||
input_file.path = file_info.file_path;
|
||||
Payload payload(input_file, attachment.parent_folder());
|
||||
payload.content.file_payload.size = file_info.size;
|
||||
file_payloads_.push_back(std::move(payload));
|
||||
SetAttachmentPayloadId(attachment.id(), file_payloads_.back().id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<Payload> OutgoingShareTargetInfo::ExtractTextPayloads() {
|
||||
return std::move(text_payloads_);
|
||||
}
|
||||
@@ -98,5 +183,4 @@ std::optional<Payload> OutgoingShareTargetInfo::ExtractNextPayload() {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
} // namespace sharing
|
||||
} // namespace nearby
|
||||
} // namespace nearby::sharing
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#ifndef THIRD_PARTY_NEARBY_SHARING_OUTGOING_SHARE_TARGET_INFO_H_
|
||||
#define THIRD_PARTY_NEARBY_SHARING_OUTGOING_SHARE_TARGET_INFO_H_
|
||||
|
||||
#include <filesystem> // NOLINT
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
@@ -23,12 +24,12 @@
|
||||
|
||||
#include "sharing/nearby_connection.h"
|
||||
#include "sharing/nearby_connections_types.h"
|
||||
#include "sharing/nearby_file_handler.h"
|
||||
#include "sharing/share_target.h"
|
||||
#include "sharing/share_target_info.h"
|
||||
#include "sharing/transfer_metadata.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace sharing {
|
||||
namespace nearby::sharing {
|
||||
|
||||
// A description of the outgoing connection to a remote device.
|
||||
class OutgoingShareTargetInfo : public ShareTargetInfo {
|
||||
@@ -54,30 +55,29 @@ class OutgoingShareTargetInfo : public ShareTargetInfo {
|
||||
|
||||
const std::vector<Payload>& text_payloads() const { return text_payloads_; }
|
||||
|
||||
void set_text_payloads(std::vector<Payload> payloads) {
|
||||
text_payloads_ = std::move(payloads);
|
||||
}
|
||||
|
||||
const std::vector<Payload>& wifi_credentials_payloads() const {
|
||||
return wifi_credentials_payloads_;
|
||||
}
|
||||
|
||||
void set_wifi_credentials_payloads(std::vector<Payload> payloads) {
|
||||
wifi_credentials_payloads_ = std::move(payloads);
|
||||
}
|
||||
|
||||
const std::vector<Payload>& file_payloads() const { return file_payloads_; }
|
||||
|
||||
void set_file_payloads(std::vector<Payload> payloads) {
|
||||
file_payloads_ = std::move(payloads);
|
||||
}
|
||||
|
||||
Status connection_layer_status() const { return connection_layer_status_; }
|
||||
|
||||
void set_connection_layer_status(Status status) {
|
||||
connection_layer_status_ = status;
|
||||
}
|
||||
|
||||
std::vector<std::filesystem::path> GetFilePaths() const;
|
||||
|
||||
void CreateTextPayloads();
|
||||
void CreateWifiCredentialsPayloads();
|
||||
// Create file payloads and update the file size of all file attachments.
|
||||
// The list of file infos must be sorted in the same order as the file
|
||||
// attachments in the share target.
|
||||
// Returns true if all file payloads are created successfully.
|
||||
bool CreateFilePayloads(
|
||||
const std::vector<NearbyFileHandler::FileInfo>& files);
|
||||
|
||||
std::vector<Payload> ExtractTextPayloads();
|
||||
std::vector<Payload> ExtractFilePayloads();
|
||||
std::vector<Payload> ExtractWifiCredentialsPayloads();
|
||||
@@ -90,6 +90,7 @@ class OutgoingShareTargetInfo : public ShareTargetInfo {
|
||||
|
||||
private:
|
||||
std::optional<std::string> obfuscated_gaia_id_;
|
||||
// All payloads are in the same order as the attachments in the share target.
|
||||
std::vector<Payload> text_payloads_;
|
||||
std::vector<Payload> file_payloads_;
|
||||
std::vector<Payload> wifi_credentials_payloads_;
|
||||
@@ -98,7 +99,6 @@ class OutgoingShareTargetInfo : public ShareTargetInfo {
|
||||
transfer_update_callback_;
|
||||
};
|
||||
|
||||
} // namespace sharing
|
||||
} // namespace nearby
|
||||
} // namespace nearby::sharing
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_SHARING_OUTGOING_SHARE_TARGET_INFO_H_
|
||||
|
||||
@@ -0,0 +1,217 @@
|
||||
// Copyright 2024 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "sharing/outgoing_share_target_info.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "protobuf-matchers/protocol-buffer-matchers.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "sharing/attachment_container.h"
|
||||
#include "sharing/file_attachment.h"
|
||||
#include "sharing/nearby_connections_types.h"
|
||||
#include "sharing/nearby_file_handler.h"
|
||||
#include "sharing/proto/wire_format.pb.h"
|
||||
#include "sharing/share_target.h"
|
||||
#include "sharing/text_attachment.h"
|
||||
#include "sharing/transfer_metadata.h"
|
||||
#include "sharing/wifi_credentials_attachment.h"
|
||||
|
||||
namespace nearby::sharing {
|
||||
namespace {
|
||||
using ::nearby::sharing::service::proto::WifiCredentials;
|
||||
using ::testing::Eq;
|
||||
using ::testing::IsEmpty;
|
||||
using ::testing::IsFalse;
|
||||
using ::testing::IsTrue;
|
||||
using ::testing::SizeIs;
|
||||
|
||||
constexpr absl::string_view kEndpointId = "ABCD";
|
||||
|
||||
class OutgoingShareTargetInfoTest : public ::testing::Test {
|
||||
public:
|
||||
OutgoingShareTargetInfoTest()
|
||||
: info_(std::string(kEndpointId), share_target_,
|
||||
[](OutgoingShareTargetInfo&, const TransferMetadata&) {}),
|
||||
text1_(nearby::sharing::service::proto::TextMetadata::URL,
|
||||
"A bit of text body", "Some text title", "text/html"),
|
||||
text2_(nearby::sharing::service::proto::TextMetadata::ADDRESS,
|
||||
"A bit of text body 2", "Some text title 2", "text/plain"),
|
||||
file1_("/usr/local/tmp/someFileName.jpg", "/usr/local/parent"),
|
||||
file2_("/usr/local/tmp/someFileName2.jpg", "/usr/local/parent2"),
|
||||
wifi1_(
|
||||
"GoogleGuest",
|
||||
nearby::sharing::service::proto::WifiCredentialsMetadata::WPA_PSK,
|
||||
"somepassword", /*is_hidden=*/true) {
|
||||
AttachmentContainer container(
|
||||
std::vector<TextAttachment>{text1_, text2_},
|
||||
std::vector<FileAttachment>{file1_},
|
||||
std::vector<WifiCredentialsAttachment>{wifi1_});
|
||||
info_.SetAttachmentContainer(std::move(container));
|
||||
}
|
||||
|
||||
protected:
|
||||
ShareTarget share_target_;
|
||||
OutgoingShareTargetInfo info_;
|
||||
TextAttachment text1_;
|
||||
TextAttachment text2_;
|
||||
FileAttachment file1_;
|
||||
FileAttachment file2_;
|
||||
WifiCredentialsAttachment wifi1_;
|
||||
};
|
||||
|
||||
TEST_F(OutgoingShareTargetInfoTest, GetFilePaths) {
|
||||
OutgoingShareTargetInfo info(
|
||||
std::string(kEndpointId), share_target_,
|
||||
[](OutgoingShareTargetInfo&, const TransferMetadata&) {});
|
||||
AttachmentContainer container(std::vector<TextAttachment>{},
|
||||
std::vector<FileAttachment>{file1_, file2_},
|
||||
std::vector<WifiCredentialsAttachment>{});
|
||||
info.SetAttachmentContainer(std::move(container));
|
||||
|
||||
auto file_paths = info.GetFilePaths();
|
||||
|
||||
ASSERT_THAT(file_paths, SizeIs(2));
|
||||
EXPECT_THAT(file_paths[0], Eq(file1_.file_path()));
|
||||
EXPECT_THAT(file_paths[1], Eq(file2_.file_path()));
|
||||
}
|
||||
|
||||
TEST_F(OutgoingShareTargetInfoTest, CreateTextPayloadsWithNoTextAttachments) {
|
||||
OutgoingShareTargetInfo info(
|
||||
std::string(kEndpointId), share_target_,
|
||||
[](OutgoingShareTargetInfo&, const TransferMetadata&) {});
|
||||
info.CreateTextPayloads();
|
||||
const std::vector<Payload>& payloads = info.text_payloads();
|
||||
|
||||
EXPECT_THAT(payloads, IsEmpty());
|
||||
}
|
||||
|
||||
TEST_F(OutgoingShareTargetInfoTest, CreateTextPayloads) {
|
||||
info_.CreateTextPayloads();
|
||||
const std::vector<Payload>& payloads = info_.text_payloads();
|
||||
auto& attachment_payload_map = info_.attachment_payload_map();
|
||||
|
||||
ASSERT_THAT(payloads, SizeIs(2));
|
||||
EXPECT_THAT(payloads[0].content.type, Eq(PayloadContent::Type::kBytes));
|
||||
EXPECT_THAT(payloads[1].content.type, Eq(PayloadContent::Type::kBytes));
|
||||
EXPECT_THAT(payloads[0].content.bytes_payload.bytes,
|
||||
Eq(std::vector<uint8_t>(text1_.text_body().begin(),
|
||||
text1_.text_body().end())));
|
||||
EXPECT_THAT(payloads[1].content.bytes_payload.bytes,
|
||||
Eq(std::vector<uint8_t>(text2_.text_body().begin(),
|
||||
text2_.text_body().end())));
|
||||
|
||||
ASSERT_THAT(attachment_payload_map, SizeIs(2));
|
||||
ASSERT_THAT(attachment_payload_map.contains(text1_.id()), IsTrue());
|
||||
ASSERT_THAT(attachment_payload_map.at(text1_.id()).payload_id.has_value(),
|
||||
IsTrue());
|
||||
EXPECT_THAT(attachment_payload_map.at(text1_.id()).payload_id.value(),
|
||||
Eq(payloads[0].id));
|
||||
ASSERT_THAT(attachment_payload_map.contains(text2_.id()), IsTrue());
|
||||
ASSERT_THAT(attachment_payload_map.at(text2_.id()).payload_id.has_value(),
|
||||
IsTrue());
|
||||
EXPECT_THAT(attachment_payload_map.at(text2_.id()).payload_id.value(),
|
||||
Eq(payloads[1].id));
|
||||
}
|
||||
|
||||
TEST_F(OutgoingShareTargetInfoTest, CreateFilePayloadsWithNoFileAttachments) {
|
||||
OutgoingShareTargetInfo info(
|
||||
std::string(kEndpointId), share_target_,
|
||||
[](OutgoingShareTargetInfo&, const TransferMetadata&) {});
|
||||
|
||||
EXPECT_THAT(
|
||||
info.CreateFilePayloads(std::vector<NearbyFileHandler::FileInfo>()),
|
||||
IsTrue());
|
||||
const std::vector<Payload>& payloads = info.file_payloads();
|
||||
|
||||
EXPECT_THAT(payloads, IsEmpty());
|
||||
}
|
||||
|
||||
TEST_F(OutgoingShareTargetInfoTest, CreateFilePayloadsWithWrongFileInfo) {
|
||||
EXPECT_THAT(
|
||||
info_.CreateFilePayloads(std::vector<NearbyFileHandler::FileInfo>()),
|
||||
IsFalse());
|
||||
const std::vector<Payload>& payloads = info_.file_payloads();
|
||||
|
||||
EXPECT_THAT(payloads, IsEmpty());
|
||||
}
|
||||
|
||||
TEST_F(OutgoingShareTargetInfoTest, CreateFilePayloads) {
|
||||
std::vector<NearbyFileHandler::FileInfo> file_infos;
|
||||
file_infos.push_back({
|
||||
.size = 12355L,
|
||||
.file_path = file1_.file_path().value(),
|
||||
});
|
||||
info_.CreateFilePayloads(file_infos);
|
||||
const std::vector<Payload>& payloads = info_.file_payloads();
|
||||
auto& attachment_payload_map = info_.attachment_payload_map();
|
||||
|
||||
ASSERT_THAT(payloads, SizeIs(1));
|
||||
EXPECT_THAT(payloads[0].content.type, Eq(PayloadContent::Type::kFile));
|
||||
EXPECT_THAT(payloads[0].content.file_payload.size, Eq(12355L));
|
||||
EXPECT_THAT(payloads[0].content.file_payload.parent_folder,
|
||||
Eq(file1_.parent_folder()));
|
||||
EXPECT_THAT(payloads[0].content.file_payload.file.path,
|
||||
Eq(file1_.file_path()));
|
||||
|
||||
EXPECT_THAT(attachment_payload_map, SizeIs(1));
|
||||
ASSERT_THAT(attachment_payload_map.contains(file1_.id()), IsTrue());
|
||||
ASSERT_THAT(attachment_payload_map.at(file1_.id()).payload_id.has_value(),
|
||||
IsTrue());
|
||||
EXPECT_THAT(attachment_payload_map.at(file1_.id()).payload_id.value(),
|
||||
Eq(payloads[0].id));
|
||||
|
||||
EXPECT_THAT(info_.attachment_container().GetFileAttachments()[0].size(),
|
||||
Eq(12355L));
|
||||
}
|
||||
|
||||
TEST_F(OutgoingShareTargetInfoTest, CreateWifiPayloadsWithNoWifiAttachments) {
|
||||
OutgoingShareTargetInfo info(
|
||||
std::string(kEndpointId), share_target_,
|
||||
[](OutgoingShareTargetInfo&, const TransferMetadata&) {});
|
||||
info.CreateWifiCredentialsPayloads();
|
||||
const std::vector<Payload>& payloads = info.file_payloads();
|
||||
|
||||
EXPECT_THAT(payloads, IsEmpty());
|
||||
}
|
||||
|
||||
TEST_F(OutgoingShareTargetInfoTest, CreateWifiCredentialsPayloads) {
|
||||
info_.CreateWifiCredentialsPayloads();
|
||||
const std::vector<Payload>& payloads = info_.wifi_credentials_payloads();
|
||||
auto& attachment_payload_map = info_.attachment_payload_map();
|
||||
|
||||
ASSERT_THAT(payloads, SizeIs(1));
|
||||
EXPECT_THAT(payloads[0].content.type, Eq(PayloadContent::Type::kBytes));
|
||||
WifiCredentials wifi_credentials;
|
||||
EXPECT_THAT(wifi_credentials.ParseFromArray(
|
||||
payloads[0].content.bytes_payload.bytes.data(),
|
||||
payloads[0].content.bytes_payload.bytes.size()),
|
||||
IsTrue());
|
||||
EXPECT_THAT(wifi_credentials.password(), Eq(wifi1_.password()));
|
||||
EXPECT_THAT(wifi_credentials.has_hidden_ssid(), Eq(wifi1_.is_hidden()));
|
||||
|
||||
ASSERT_THAT(attachment_payload_map, SizeIs(1));
|
||||
ASSERT_THAT(attachment_payload_map.contains(wifi1_.id()), IsTrue());
|
||||
ASSERT_THAT(attachment_payload_map.at(wifi1_.id()).payload_id.has_value(),
|
||||
IsTrue());
|
||||
EXPECT_THAT(attachment_payload_map.at(wifi1_.id()).payload_id.value(),
|
||||
Eq(payloads[0].id));
|
||||
}
|
||||
} // namespace
|
||||
} // namespace nearby::sharing
|
||||
@@ -126,4 +126,9 @@ void ShareTargetInfo::OnDisconnect() {
|
||||
connection_ = nullptr;
|
||||
}
|
||||
|
||||
void ShareTargetInfo::SetAttachmentPayloadId(int64_t attachment_id,
|
||||
int64_t payload_id) {
|
||||
attachment_payload_map_[attachment_id].payload_id = payload_id;
|
||||
}
|
||||
|
||||
} // namespace nearby::sharing
|
||||
|
||||
@@ -23,9 +23,11 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "proto/sharing_enums.pb.h"
|
||||
#include "sharing/attachment_container.h"
|
||||
#include "sharing/attachment_info.h"
|
||||
#include "sharing/certificates/nearby_share_certificate_manager.h"
|
||||
#include "sharing/certificates/nearby_share_decrypted_public_certificate.h"
|
||||
#include "sharing/incoming_frames_reader.h"
|
||||
@@ -38,8 +40,7 @@
|
||||
#include "sharing/share_target.h"
|
||||
#include "sharing/transfer_metadata.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace sharing {
|
||||
namespace nearby::sharing {
|
||||
|
||||
// Additional information about the connection to a remote device.
|
||||
class ShareTargetInfo {
|
||||
@@ -136,7 +137,14 @@ class ShareTargetInfo {
|
||||
return attachment_container_;
|
||||
}
|
||||
|
||||
const absl::flat_hash_map<int64_t, AttachmentInfo>& attachment_payload_map()
|
||||
const {
|
||||
return attachment_payload_map_;
|
||||
}
|
||||
|
||||
protected:
|
||||
void SetAttachmentPayloadId(int64_t attachment_id, int64_t payload_id);
|
||||
|
||||
virtual void InvokeTransferUpdateCallback(
|
||||
const TransferMetadata& metadata) = 0;
|
||||
virtual bool OnNewConnection(NearbyConnection* connection) = 0;
|
||||
@@ -161,9 +169,9 @@ class ShareTargetInfo {
|
||||
TransferMetadata::Status disconnect_status_ =
|
||||
TransferMetadata::Status::kUnknown;
|
||||
AttachmentContainer attachment_container_;
|
||||
absl::flat_hash_map<int64_t, AttachmentInfo> attachment_payload_map_;
|
||||
};
|
||||
|
||||
} // namespace sharing
|
||||
} // namespace nearby
|
||||
} // namespace nearby::sharing
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_SHARING_SHARE_TARGET_INFO_H_
|
||||
|
||||
Reference in New Issue
Block a user