mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Log advanced protection state in SendAttachement log message.
PiperOrigin-RevId: 808750701
This commit is contained in:
committed by
Copybara-Service
parent
d6da1706c9
commit
e3e3822610
@@ -344,6 +344,7 @@ cc_library(
|
||||
"//sharing/internal/base",
|
||||
"//sharing/internal/public:logging",
|
||||
"//sharing/internal/public:nearby_context",
|
||||
"//sharing/internal/public:pref_names",
|
||||
"//sharing/internal/public:types",
|
||||
"//sharing/local_device_data",
|
||||
"//sharing/proto:enums_cc_proto",
|
||||
@@ -833,6 +834,7 @@ cc_test(
|
||||
"//sharing/certificates:test_support",
|
||||
"//sharing/common:enum",
|
||||
"//sharing/proto:wire_format_cc_proto",
|
||||
"//sharing/proto/analytics:sharing_log_cc_proto",
|
||||
"@com_github_protobuf_matchers//protobuf-matchers",
|
||||
"@com_google_absl//absl/strings:string_view",
|
||||
"@com_google_absl//absl/time",
|
||||
|
||||
@@ -588,7 +588,8 @@ void AnalyticsRecorder::NewSendAttachmentsEnd(
|
||||
|
||||
void AnalyticsRecorder::NewSendAttachmentsStart(
|
||||
int64_t session_id, const AttachmentContainer& attachments,
|
||||
int transfer_position, int concurrent_connections) {
|
||||
int transfer_position, int concurrent_connections,
|
||||
bool advanced_protection_enabled, bool advanced_protection_mismatch) {
|
||||
std::unique_ptr<SharingLog> sharing_log = CreateSharingLog(
|
||||
EventCategory::SENDING_EVENT, EventType::SEND_ATTACHMENTS_START);
|
||||
|
||||
@@ -598,6 +599,10 @@ void AnalyticsRecorder::NewSendAttachmentsStart(
|
||||
attachments);
|
||||
send_attachments_start->set_transfer_position(transfer_position);
|
||||
send_attachments_start->set_concurrent_connections(concurrent_connections);
|
||||
send_attachments_start->set_advanced_protection_enabled(
|
||||
advanced_protection_enabled);
|
||||
send_attachments_start->set_advanced_protection_mismatch(
|
||||
advanced_protection_mismatch);
|
||||
|
||||
LogEvent(*sharing_log);
|
||||
}
|
||||
|
||||
@@ -140,7 +140,9 @@ class AnalyticsRecorder {
|
||||
void NewSendAttachmentsStart(int64_t session_id,
|
||||
const AttachmentContainer& attachments,
|
||||
int transfer_position,
|
||||
int concurrent_connections);
|
||||
int concurrent_connections,
|
||||
bool advanced_protection_enabled,
|
||||
bool advanced_protection_mismatch);
|
||||
|
||||
void NewSendFastInitialization();
|
||||
|
||||
|
||||
@@ -616,10 +616,14 @@ TEST_F(AnalyticsRecorderTest, NewSendAttachmentsStart) {
|
||||
0);
|
||||
EXPECT_EQ(log.send_attachments_start().transfer_position(), 100);
|
||||
EXPECT_EQ(log.send_attachments_start().concurrent_connections(), 200);
|
||||
EXPECT_EQ(log.send_attachments_start().advanced_protection_enabled(),
|
||||
true);
|
||||
EXPECT_EQ(log.send_attachments_start().advanced_protection_mismatch(),
|
||||
true);
|
||||
});
|
||||
|
||||
analytics_recoder().NewSendAttachmentsStart(1, AttachmentContainer(), 100,
|
||||
200);
|
||||
200, true, true);
|
||||
}
|
||||
|
||||
TEST_F(AnalyticsRecorderTest, NewSendFastInitialization) {
|
||||
|
||||
@@ -76,6 +76,7 @@
|
||||
#include "sharing/internal/public/connectivity_manager.h"
|
||||
#include "sharing/internal/public/context.h"
|
||||
#include "sharing/internal/public/logging.h"
|
||||
#include "sharing/internal/public/pref_names.h"
|
||||
#include "sharing/local_device_data/nearby_share_local_device_data_manager.h"
|
||||
#include "sharing/local_device_data/nearby_share_local_device_data_manager_impl.h"
|
||||
#include "sharing/nearby_connection.h"
|
||||
@@ -154,9 +155,9 @@ constexpr size_t kDeviceIdLength = 10;
|
||||
// Possible characters used in a randomly generated device ID. This agrees with
|
||||
// the GmsCore implementation.
|
||||
constexpr std::array<char, 36> kAlphaNumericChars = {
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
|
||||
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
|
||||
'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
|
||||
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
|
||||
'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
|
||||
|
||||
bool ShouldBlockSurfaceRegistration(BlockedVendorId registering_vendor_id,
|
||||
BlockedVendorId blocked_vendor_id) {
|
||||
@@ -620,9 +621,8 @@ void NearbySharingServiceImpl::RegisterReceiveSurface(
|
||||
} else if (!IsBluetoothPowered()) {
|
||||
LOG(WARNING) << __func__ << ": Bluetooth is not powered.";
|
||||
} else {
|
||||
VLOG(1)
|
||||
<< __func__ << ": This device's MAC address is: "
|
||||
<< context_->GetBluetoothAdapter().GetAddress().ToString();
|
||||
VLOG(1) << __func__ << ": This device's MAC address is: "
|
||||
<< context_->GetBluetoothAdapter().GetAddress().ToString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1183,23 +1183,23 @@ std::string NearbySharingServiceImpl::Dump() const {
|
||||
sstream << " Download public certificates: "
|
||||
<< ConvertToReadableSchedule(
|
||||
preference_manager_,
|
||||
prefs::kNearbySharingSchedulerDownloadPublicCertificatesName)
|
||||
PrefNames::kSchedulerDownloadPublicCertificates)
|
||||
<< std::endl;
|
||||
sstream
|
||||
<< " Upload local device certificates: "
|
||||
<< ConvertToReadableSchedule(
|
||||
preference_manager_,
|
||||
prefs::kNearbySharingSchedulerUploadLocalDeviceCertificatesName)
|
||||
PrefNames::kSchedulerUploadLocalDeviceCertificates)
|
||||
<< std::endl;
|
||||
sstream << " Private certificates expiration: "
|
||||
<< ConvertToReadableSchedule(
|
||||
preference_manager_,
|
||||
prefs::kNearbySharingSchedulerPrivateCertificateExpirationName)
|
||||
PrefNames::kSchedulerPrivateCertificateExpiration)
|
||||
<< std::endl;
|
||||
sstream << " Public certificates expiration: "
|
||||
<< ConvertToReadableSchedule(
|
||||
preference_manager_,
|
||||
prefs::kNearbySharingSchedulerPublicCertificateExpirationName)
|
||||
PrefNames::kSchedulerPublicCertificateExpiration)
|
||||
<< std::endl;
|
||||
|
||||
// Dump certificates information.
|
||||
@@ -1218,13 +1218,13 @@ std::string NearbySharingServiceImpl::Dump() const {
|
||||
// Private methods for NearbyShareSettings::Observer.
|
||||
void NearbySharingServiceImpl::OnSettingChanged(absl::string_view key,
|
||||
const Data& data) {
|
||||
if (key == prefs::kNearbySharingDataUsageName) {
|
||||
if (key == PrefNames::kDataUsage) {
|
||||
DataUsage data_usage = static_cast<DataUsage>(data.value.as_int64);
|
||||
OnDataUsageChanged(data_usage);
|
||||
} else if (key == prefs::kNearbySharingCustomSavePath) {
|
||||
} else if (key == PrefNames::kCustomSavePath) {
|
||||
absl::string_view custom_save_path = data.value.as_string;
|
||||
OnCustomSavePathChanged(custom_save_path);
|
||||
} else if (key == prefs::kNearbySharingBackgroundVisibilityName) {
|
||||
} else if (key == PrefNames::kVisibility) {
|
||||
DeviceVisibility visibility =
|
||||
static_cast<DeviceVisibility>(data.value.as_int64);
|
||||
OnVisibilityChanged(visibility);
|
||||
@@ -1649,15 +1649,15 @@ void NearbySharingServiceImpl::FinishEndpointDiscoveryEvent() {
|
||||
void NearbySharingServiceImpl::LogShareTargetDiscovered(
|
||||
const ShareTarget& share_target) {
|
||||
analytics_recorder_.NewDiscoverShareTarget(
|
||||
share_target, scanning_session_id_,
|
||||
absl::ToInt64Milliseconds(context_->GetClock()->Now() -
|
||||
scanning_start_timestamp_),
|
||||
/*flow_id=*/1, /*referrer_package=*/std::nullopt,
|
||||
share_foreground_send_surface_start_timestamp_ == absl::InfinitePast()
|
||||
? -1
|
||||
: absl::ToInt64Milliseconds(
|
||||
context_->GetClock()->Now() -
|
||||
share_foreground_send_surface_start_timestamp_));
|
||||
share_target, scanning_session_id_,
|
||||
absl::ToInt64Milliseconds(context_->GetClock()->Now() -
|
||||
scanning_start_timestamp_),
|
||||
/*flow_id=*/1, /*referrer_package=*/std::nullopt,
|
||||
share_foreground_send_surface_start_timestamp_ == absl::InfinitePast()
|
||||
? -1
|
||||
: absl::ToInt64Milliseconds(
|
||||
context_->GetClock()->Now() -
|
||||
share_foreground_send_surface_start_timestamp_));
|
||||
}
|
||||
|
||||
void NearbySharingServiceImpl::NotifyShareTargetDiscovered(
|
||||
@@ -2649,10 +2649,21 @@ void NearbySharingServiceImpl::OnOutgoingConnectionKeyVerificationDone(
|
||||
return;
|
||||
}
|
||||
// Auto Accept if key verification is successful or skip sender confirmation.
|
||||
if (session->token().empty() ||
|
||||
NearbyFlags::GetInstance().GetBoolFlag(
|
||||
bool be_advanced_protection_enabled =
|
||||
preference_manager_.GetBoolean(PrefNames::kAdvancedProtectionEnabled,
|
||||
/*default_value=*/false);
|
||||
bool mendel_advanced_protection_enabled =
|
||||
!NearbyFlags::GetInstance().GetBoolFlag(
|
||||
config_package_nearby::nearby_sharing_feature::
|
||||
kSenderSkipsConfirmation)) {
|
||||
kSenderSkipsConfirmation);
|
||||
bool advanced_protection_mismatch =
|
||||
(be_advanced_protection_enabled != mendel_advanced_protection_enabled);
|
||||
// Continue to use mendel flag until we have confidence that the Nearby BE
|
||||
// flag has the same value.
|
||||
session->SetAdvancedProtectionStatus(mendel_advanced_protection_enabled,
|
||||
advanced_protection_mismatch);
|
||||
if (session->token().empty() || !mendel_advanced_protection_enabled) {
|
||||
// Auto accept if no token or if advanced protection is disabled.
|
||||
OutgoingSessionAccept(*session);
|
||||
} else {
|
||||
session->UpdateTransferMetadata(
|
||||
@@ -3202,8 +3213,7 @@ void NearbySharingServiceImpl::MoveToDiscoveryCache(std::string endpoint_id,
|
||||
VLOG(1) << "discovery_cache entry: " << endpoint_id << " timeout after "
|
||||
<< expiry_ms << "ms"
|
||||
<< ": [Dedupped] NotifyShareTargetLost to all surfaces for "
|
||||
<< "share_target: "
|
||||
<< share_target.ToString();
|
||||
<< "share_target: " << share_target.ToString();
|
||||
});
|
||||
// Send ShareTarget update to set receive disabled to true.
|
||||
NotifyShareTargetUpdated(cache_entry.share_target);
|
||||
@@ -3457,7 +3467,7 @@ void NearbySharingServiceImpl::ResetAllSettings(bool logout) {
|
||||
} else {
|
||||
// on login generate a new device id
|
||||
std::string device_id = GenerateDeviceId();
|
||||
preference_manager_.SetString(prefs::kNearbySharingDeviceIdName, device_id);
|
||||
preference_manager_.SetString(PrefNames::kDeviceId, device_id);
|
||||
|
||||
// should clear scheduled task to make it works immediately
|
||||
settings_->RemoveSettingsObserver(this);
|
||||
|
||||
@@ -198,7 +198,7 @@ void OutgoingShareSession::CreateWifiCredentialsPayloads() {
|
||||
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_password(attachment.password());
|
||||
wifi_credentials.set_hidden_ssid(attachment.is_hidden());
|
||||
|
||||
std::vector<uint8_t> bytes(wifi_credentials.ByteSizeLong());
|
||||
@@ -255,12 +255,12 @@ bool OutgoingShareSession::FillIntroductionFrame(
|
||||
const FileAttachment& file = file_attachments[i];
|
||||
auto* file_metadata = introduction->add_file_metadata();
|
||||
file_metadata->set_id(file.id());
|
||||
file_metadata->set_name(std::string(file.file_name()));
|
||||
file_metadata->set_name(file.file_name());
|
||||
file_metadata->set_payload_id(file_payloads_[i].id);
|
||||
file_metadata->set_type(file.type());
|
||||
file_metadata->set_mime_type(std::string(file.mime_type()));
|
||||
file_metadata->set_mime_type(file.mime_type());
|
||||
file_metadata->set_size(file.size());
|
||||
file_metadata->set_parent_folder(std::string(file.parent_folder()));
|
||||
file_metadata->set_parent_folder(file.parent_folder());
|
||||
}
|
||||
|
||||
// Write introduction of text payloads.
|
||||
@@ -270,7 +270,7 @@ bool OutgoingShareSession::FillIntroductionFrame(
|
||||
const TextAttachment& text = text_attachments[i];
|
||||
auto* text_metadata = introduction->add_text_metadata();
|
||||
text_metadata->set_id(text.id());
|
||||
text_metadata->set_text_title(std::string(text.text_title()));
|
||||
text_metadata->set_text_title(text.text_title());
|
||||
text_metadata->set_type(text.type());
|
||||
text_metadata->set_size(text.size());
|
||||
text_metadata->set_payload_id(text_payloads_[i].id);
|
||||
@@ -285,7 +285,7 @@ bool OutgoingShareSession::FillIntroductionFrame(
|
||||
auto* wifi_credentials_metadata =
|
||||
introduction->add_wifi_credentials_metadata();
|
||||
wifi_credentials_metadata->set_id(wifi_credentials.id());
|
||||
wifi_credentials_metadata->set_ssid(std::string(wifi_credentials.ssid()));
|
||||
wifi_credentials_metadata->set_ssid(wifi_credentials.ssid());
|
||||
wifi_credentials_metadata->set_security_type(
|
||||
wifi_credentials.security_type());
|
||||
wifi_credentials_metadata->set_payload_id(wifi_credentials_payloads_[i].id);
|
||||
@@ -337,10 +337,11 @@ void OutgoingShareSession::SendPayloads(
|
||||
frames_reader()->ReadFrame(std::move(frame_read_callback));
|
||||
|
||||
// Log analytics event of sending attachment start.
|
||||
analytics_recorder().NewSendAttachmentsStart(session_id(),
|
||||
attachment_container(),
|
||||
/*transfer_position=*/1,
|
||||
/*concurrent_connections=*/1);
|
||||
analytics_recorder().NewSendAttachmentsStart(
|
||||
session_id(), attachment_container(),
|
||||
/*transfer_position=*/1,
|
||||
/*concurrent_connections=*/1, advanced_protection_enabled_,
|
||||
advanced_protection_mismatch_);
|
||||
VLOG(1) << "The connection was accepted. Payloads are now being sent.";
|
||||
InitializePayloadTracker(std::move(payload_transder_update_callback));
|
||||
SendNextPayload();
|
||||
|
||||
@@ -163,6 +163,12 @@ class OutgoingShareSession : public ShareSession {
|
||||
|
||||
std::optional<TransferMetadata> ProcessPayloadTransferUpdates();
|
||||
|
||||
void SetAdvancedProtectionStatus(bool advanced_protection_enabled,
|
||||
bool advanced_protection_mismatch) {
|
||||
advanced_protection_enabled_ = advanced_protection_enabled;
|
||||
advanced_protection_mismatch_ = advanced_protection_mismatch;
|
||||
}
|
||||
|
||||
protected:
|
||||
void InvokeTransferUpdateCallback(const TransferMetadata& metadata) override;
|
||||
void OnConnectionDisconnected() override;
|
||||
@@ -191,6 +197,8 @@ class OutgoingShareSession : public ShareSession {
|
||||
absl::Time connection_start_time_;
|
||||
// Timeout waiting for remote disconnect in order to complete transfer.
|
||||
std::unique_ptr<ThreadTimer> disconnection_timeout_;
|
||||
bool advanced_protection_enabled_ = false;
|
||||
bool advanced_protection_mismatch_ = false;
|
||||
};
|
||||
|
||||
} // namespace nearby::sharing
|
||||
|
||||
@@ -45,6 +45,8 @@
|
||||
#include "sharing/nearby_connections_types.h"
|
||||
#include "sharing/nearby_file_handler.h"
|
||||
#include "sharing/paired_key_verification_runner.h"
|
||||
#include "sharing/proto/analytics/nearby_sharing_log.pb.h"
|
||||
#include "sharing/proto/analytics/nearby_sharing_log.proto.static_reflection.h"
|
||||
#include "sharing/proto/wire_format.pb.h"
|
||||
#include "sharing/share_target.h"
|
||||
#include "sharing/text_attachment.h"
|
||||
@@ -60,10 +62,7 @@ using ::location::nearby::proto::sharing::EventCategory;
|
||||
using ::location::nearby::proto::sharing::EventType;
|
||||
using ::location::nearby::proto::sharing::OSType;
|
||||
using ::nearby::analytics::HasCategory;
|
||||
using ::nearby::analytics::HasDurationMillis;
|
||||
using ::nearby::analytics::HasEventType;
|
||||
using ::nearby::analytics::HasSessionId;
|
||||
using ::nearby::analytics::SharingLogHasStatus;
|
||||
using ::nearby::sharing::analytics::proto::SharingLog;
|
||||
using ::nearby::sharing::service::proto::ConnectionResponseFrame;
|
||||
using ::nearby::sharing::service::proto::Frame;
|
||||
@@ -73,16 +72,15 @@ using ::nearby::sharing::service::proto::WifiCredentials;
|
||||
using ::testing::_;
|
||||
using ::testing::AllOf;
|
||||
using ::testing::Eq;
|
||||
using ::testing::Invoke;
|
||||
using ::testing::IsEmpty;
|
||||
using ::testing::IsFalse;
|
||||
using ::testing::IsTrue;
|
||||
using ::testing::Matcher;
|
||||
using ::testing::MockFunction;
|
||||
using ::testing::Not;
|
||||
using ::testing::Property;
|
||||
using ::testing::SizeIs;
|
||||
using ::testing::StrictMock;
|
||||
using ::testing::proto::ProtoField;
|
||||
|
||||
constexpr absl::string_view kEndpointId = "ABCD";
|
||||
|
||||
@@ -114,11 +112,10 @@ class OutgoingShareSessionTest : public ::testing::Test {
|
||||
|
||||
void InitSendAttachments(
|
||||
std::unique_ptr<AttachmentContainer> attachment_container) {
|
||||
EXPECT_CALL(
|
||||
mock_event_logger_,
|
||||
Log(Matcher<const SharingLog&>(AllOf((
|
||||
HasCategory(EventCategory::SENDING_EVENT),
|
||||
HasEventType(EventType::SEND_START))))));
|
||||
EXPECT_CALL(mock_event_logger_,
|
||||
Log(Matcher<const SharingLog&>(
|
||||
AllOf((HasCategory(EventCategory::SENDING_EVENT),
|
||||
HasEventType(EventType::SEND_START))))));
|
||||
session_.InitiateSendAttachments(std::move(attachment_container));
|
||||
}
|
||||
|
||||
@@ -365,15 +362,13 @@ TEST_F(OutgoingShareSessionTest, OnConnectResultSuccessLogsSessionDuration) {
|
||||
fake_clock_.FastForward(absl::Seconds(10));
|
||||
EXPECT_CALL(
|
||||
mock_event_logger_,
|
||||
Log(Matcher<const SharingLog&>(AllOf((
|
||||
HasCategory(EventCategory::SENDING_EVENT),
|
||||
HasEventType(EventType::ESTABLISH_CONNECTION),
|
||||
Property(&SharingLog::establish_connection, HasSessionId(1234)),
|
||||
Property(&SharingLog::establish_connection, HasDurationMillis(10000)),
|
||||
Property(
|
||||
&SharingLog::establish_connection,
|
||||
SharingLogHasStatus(
|
||||
EstablishConnectionStatus::CONNECTION_STATUS_SUCCESS)))))));
|
||||
Log(Matcher<const SharingLog&>(
|
||||
AllOf((HasCategory(EventCategory::SENDING_EVENT),
|
||||
HasEventType(EventType::ESTABLISH_CONNECTION),
|
||||
ProtoField<"establish_connection", "session_id">(1234),
|
||||
ProtoField<"establish_connection", "duration_millis">(10000),
|
||||
ProtoField<"establish_connection", "status">(
|
||||
EstablishConnectionStatus::CONNECTION_STATUS_SUCCESS))))));
|
||||
|
||||
EXPECT_THAT(session_.OnConnectResult(&nearby_connection, Status::kSuccess),
|
||||
IsTrue());
|
||||
@@ -392,15 +387,13 @@ TEST_F(OutgoingShareSessionTest, OnConnectResultFailureLogsSessionDuration) {
|
||||
fake_clock_.FastForward(absl::Seconds(10));
|
||||
EXPECT_CALL(
|
||||
mock_event_logger_,
|
||||
Log(Matcher<const SharingLog&>(AllOf((
|
||||
HasCategory(EventCategory::SENDING_EVENT),
|
||||
HasEventType(EventType::ESTABLISH_CONNECTION),
|
||||
Property(&SharingLog::establish_connection, HasSessionId(1234)),
|
||||
Property(&SharingLog::establish_connection, HasDurationMillis(10000)),
|
||||
Property(
|
||||
&SharingLog::establish_connection,
|
||||
SharingLogHasStatus(
|
||||
EstablishConnectionStatus::CONNECTION_STATUS_FAILURE)))))));
|
||||
Log(Matcher<const SharingLog&>(
|
||||
AllOf((HasCategory(EventCategory::SENDING_EVENT),
|
||||
HasEventType(EventType::ESTABLISH_CONNECTION),
|
||||
ProtoField<"establish_connection", "session_id">(1234),
|
||||
ProtoField<"establish_connection", "duration_millis">(10000),
|
||||
ProtoField<"establish_connection", "status">(
|
||||
EstablishConnectionStatus::CONNECTION_STATUS_FAILURE))))));
|
||||
EXPECT_CALL(transfer_metadata_callback_,
|
||||
Call(_, AllOf(HasStatus(TransferMetadata::Status::kTimedOut),
|
||||
IsFinalStatus())));
|
||||
@@ -428,19 +421,18 @@ TEST_F(OutgoingShareSessionTest, SendIntroductionSuccess) {
|
||||
session_.CreateFilePayloads(file_infos);
|
||||
session_.CreateTextPayloads();
|
||||
session_.CreateWifiCredentialsPayloads();
|
||||
EXPECT_CALL(
|
||||
mock_event_logger_,
|
||||
Log(Matcher<const SharingLog&>(AllOf(
|
||||
(HasCategory(EventCategory::SENDING_EVENT),
|
||||
HasEventType(EventType::SEND_INTRODUCTION),
|
||||
Property(&SharingLog::send_introduction, HasSessionId(1234)))))));
|
||||
EXPECT_CALL(mock_event_logger_,
|
||||
Log(Matcher<const SharingLog&>(AllOf(
|
||||
(HasCategory(EventCategory::SENDING_EVENT),
|
||||
HasEventType(EventType::SEND_INTRODUCTION),
|
||||
ProtoField<"send_introduction", "session_id">(1234))))));
|
||||
std::vector<uint8_t> frame_data;
|
||||
connections_manager_.set_send_payload_callback(
|
||||
[&](std::unique_ptr<Payload> payload,
|
||||
std::weak_ptr<NearbyConnectionsManager::PayloadStatusListener>
|
||||
listener) {
|
||||
frame_data = std::move(payload->content.bytes_payload.bytes);
|
||||
});
|
||||
std::weak_ptr<NearbyConnectionsManager::PayloadStatusListener>
|
||||
listener) {
|
||||
frame_data = std::move(payload->content.bytes_payload.bytes);
|
||||
});
|
||||
|
||||
EXPECT_THAT(session_.SendIntroduction([]() {}), IsTrue());
|
||||
|
||||
@@ -501,12 +493,11 @@ TEST_F(OutgoingShareSessionTest, SendIntroductionTimeout) {
|
||||
NearbyConnectionImpl connection(device_info_);
|
||||
ConnectionSuccess(&connection);
|
||||
session_.CreateTextPayloads();
|
||||
EXPECT_CALL(
|
||||
mock_event_logger_,
|
||||
Log(Matcher<const SharingLog&>(AllOf(
|
||||
(HasCategory(EventCategory::SENDING_EVENT),
|
||||
HasEventType(EventType::SEND_INTRODUCTION),
|
||||
Property(&SharingLog::send_introduction, HasSessionId(1234)))))));
|
||||
EXPECT_CALL(mock_event_logger_,
|
||||
Log(Matcher<const SharingLog&>(AllOf(
|
||||
(HasCategory(EventCategory::SENDING_EVENT),
|
||||
HasEventType(EventType::SEND_INTRODUCTION),
|
||||
ProtoField<"send_introduction", "session_id">(1234))))));
|
||||
|
||||
bool accept_timeout_called = false;
|
||||
EXPECT_THAT(session_.SendIntroduction(
|
||||
@@ -528,12 +519,11 @@ TEST_F(OutgoingShareSessionTest, SendIntroductionTimeoutCancelled) {
|
||||
NearbyConnectionImpl connection(device_info_);
|
||||
ConnectionSuccess(&connection);
|
||||
session_.CreateTextPayloads();
|
||||
EXPECT_CALL(
|
||||
mock_event_logger_,
|
||||
Log(Matcher<const SharingLog&>(AllOf(
|
||||
(HasCategory(EventCategory::SENDING_EVENT),
|
||||
HasEventType(EventType::SEND_INTRODUCTION),
|
||||
Property(&SharingLog::send_introduction, HasSessionId(1234)))))));
|
||||
EXPECT_CALL(mock_event_logger_,
|
||||
Log(Matcher<const SharingLog&>(AllOf(
|
||||
(HasCategory(EventCategory::SENDING_EVENT),
|
||||
HasEventType(EventType::SEND_INTRODUCTION),
|
||||
ProtoField<"send_introduction", "session_id">(1234))))));
|
||||
|
||||
bool accept_timeout_called = false;
|
||||
EXPECT_THAT(session_.SendIntroduction(
|
||||
@@ -579,12 +569,11 @@ TEST_F(OutgoingShareSessionTest, AcceptTransferSuccess) {
|
||||
NearbyConnectionImpl connection(device_info_);
|
||||
ConnectionSuccess(&connection);
|
||||
session_.CreateTextPayloads();
|
||||
EXPECT_CALL(
|
||||
mock_event_logger_,
|
||||
Log(Matcher<const SharingLog&>(AllOf(
|
||||
(HasCategory(EventCategory::SENDING_EVENT),
|
||||
HasEventType(EventType::SEND_INTRODUCTION),
|
||||
Property(&SharingLog::send_introduction, HasSessionId(1234)))))));
|
||||
EXPECT_CALL(mock_event_logger_,
|
||||
Log(Matcher<const SharingLog&>(AllOf(
|
||||
(HasCategory(EventCategory::SENDING_EVENT),
|
||||
HasEventType(EventType::SEND_INTRODUCTION),
|
||||
ProtoField<"send_introduction", "session_id">(1234))))));
|
||||
EXPECT_THAT(session_.SendIntroduction([]() {}), IsTrue());
|
||||
EXPECT_CALL(
|
||||
transfer_metadata_callback_,
|
||||
@@ -698,23 +687,76 @@ TEST_F(OutgoingShareSessionTest, SendPayloads) {
|
||||
connections_manager_.set_send_payload_callback(
|
||||
send_payload_callback.AsStdFunction());
|
||||
EXPECT_CALL(send_payload_callback, Call(_, _))
|
||||
.WillOnce(Invoke(
|
||||
.WillOnce(
|
||||
[this](
|
||||
std::unique_ptr<Payload> payload,
|
||||
std::weak_ptr<NearbyConnectionsManager::PayloadStatusListener>) {
|
||||
payload->id = session_.attachment_payload_map().at(file1_.id());
|
||||
}));
|
||||
EXPECT_CALL(mock_event_logger_,
|
||||
Log(Matcher<const SharingLog&>(
|
||||
AllOf((HasCategory(EventCategory::SENDING_EVENT),
|
||||
HasEventType(EventType::SEND_ATTACHMENTS_START),
|
||||
Property(&SharingLog::send_attachments_start,
|
||||
HasSessionId(1234)))))));
|
||||
});
|
||||
EXPECT_CALL(
|
||||
mock_event_logger_,
|
||||
Log(Matcher<const SharingLog&>(AllOf(
|
||||
(HasCategory(EventCategory::SENDING_EVENT),
|
||||
HasEventType(EventType::SEND_ATTACHMENTS_START),
|
||||
ProtoField<"send_attachments_start", "session_id">(1234),
|
||||
ProtoField<"send_attachments_start", "advanced_protection_enabled">(
|
||||
false),
|
||||
ProtoField<"send_attachments_start", "advanced_protection_mismatch">(
|
||||
false))))));
|
||||
|
||||
NearbyConnectionImpl connection(device_info_);
|
||||
ConnectionSuccess(&connection);
|
||||
|
||||
session_.SendPayloads([](std::optional<V1Frame> frame) {},
|
||||
payload_transder_update_callback.AsStdFunction());
|
||||
payload_transder_update_callback.AsStdFunction());
|
||||
|
||||
auto payload_listener = session_.payload_tracker().lock();
|
||||
EXPECT_THAT(payload_listener, IsTrue());
|
||||
}
|
||||
|
||||
TEST_F(OutgoingShareSessionTest, SendPayloadsSetsAdvancedProtectionFlags) {
|
||||
InitSendAttachments(CreateDefaultAttachmentContainer());
|
||||
session_.set_session_id(1234);
|
||||
std::vector<NearbyFileHandler::FileInfo> file_infos;
|
||||
file_infos.push_back({
|
||||
.size = 12355L,
|
||||
.file_path = file1_.file_path().value(),
|
||||
});
|
||||
session_.CreateFilePayloads(file_infos);
|
||||
session_.CreateTextPayloads();
|
||||
session_.CreateWifiCredentialsPayloads();
|
||||
MockFunction<void()> payload_transder_update_callback;
|
||||
StrictMock<MockFunction<void(
|
||||
std::unique_ptr<Payload>,
|
||||
std::weak_ptr<NearbyConnectionsManager::PayloadStatusListener>)>>
|
||||
send_payload_callback;
|
||||
connections_manager_.set_send_payload_callback(
|
||||
send_payload_callback.AsStdFunction());
|
||||
EXPECT_CALL(send_payload_callback, Call(_, _))
|
||||
.WillOnce(
|
||||
[this](
|
||||
std::unique_ptr<Payload> payload,
|
||||
std::weak_ptr<NearbyConnectionsManager::PayloadStatusListener>) {
|
||||
payload->id = session_.attachment_payload_map().at(file1_.id());
|
||||
});
|
||||
EXPECT_CALL(
|
||||
mock_event_logger_,
|
||||
Log(Matcher<const SharingLog&>(AllOf(
|
||||
(HasCategory(EventCategory::SENDING_EVENT),
|
||||
HasEventType(EventType::SEND_ATTACHMENTS_START),
|
||||
ProtoField<"send_attachments_start", "session_id">(1234),
|
||||
ProtoField<"send_attachments_start", "advanced_protection_enabled">(
|
||||
true),
|
||||
ProtoField<"send_attachments_start", "advanced_protection_mismatch">(
|
||||
true))))));
|
||||
|
||||
NearbyConnectionImpl connection(device_info_);
|
||||
ConnectionSuccess(&connection);
|
||||
|
||||
session_.SetAdvancedProtectionStatus(/*advanced_protection_enabled=*/true,
|
||||
/*advanced_protection_mismatch=*/true);
|
||||
session_.SendPayloads([](std::optional<V1Frame> frame) {},
|
||||
payload_transder_update_callback.AsStdFunction());
|
||||
|
||||
auto payload_listener = session_.payload_tracker().lock();
|
||||
EXPECT_THAT(payload_listener, IsTrue());
|
||||
@@ -740,49 +782,53 @@ TEST_F(OutgoingShareSessionTest, SendNextPayload) {
|
||||
send_payload_callback.AsStdFunction());
|
||||
|
||||
EXPECT_CALL(send_payload_callback, Call(_, _))
|
||||
.WillOnce(Invoke(
|
||||
.WillOnce(
|
||||
[this](
|
||||
std::unique_ptr<Payload> payload,
|
||||
std::weak_ptr<NearbyConnectionsManager::PayloadStatusListener>) {
|
||||
payload->id = session_.attachment_payload_map().at(file1_.id());
|
||||
}));
|
||||
EXPECT_CALL(mock_event_logger_,
|
||||
Log(Matcher<const SharingLog&>(
|
||||
AllOf((HasCategory(EventCategory::SENDING_EVENT),
|
||||
HasEventType(EventType::SEND_ATTACHMENTS_START),
|
||||
Property(&SharingLog::send_attachments_start,
|
||||
HasSessionId(1234)))))));
|
||||
});
|
||||
EXPECT_CALL(
|
||||
mock_event_logger_,
|
||||
Log(Matcher<const SharingLog&>(AllOf(
|
||||
(HasCategory(EventCategory::SENDING_EVENT),
|
||||
HasEventType(EventType::SEND_ATTACHMENTS_START),
|
||||
ProtoField<"send_attachments_start", "session_id">(1234),
|
||||
ProtoField<"send_attachments_start", "advanced_protection_enabled">(
|
||||
false),
|
||||
ProtoField<"send_attachments_start", "advanced_protection_mismatch">(
|
||||
false))))));
|
||||
NearbyConnectionImpl connection(device_info_);
|
||||
ConnectionSuccess(&connection);
|
||||
|
||||
session_.SendPayloads([](std::optional<V1Frame> frame) {},
|
||||
payload_transder_update_callback.AsStdFunction());
|
||||
payload_transder_update_callback.AsStdFunction());
|
||||
|
||||
EXPECT_CALL(send_payload_callback, Call(_, _))
|
||||
.WillOnce(Invoke(
|
||||
.WillOnce(
|
||||
[this](
|
||||
std::unique_ptr<Payload> payload,
|
||||
std::weak_ptr<NearbyConnectionsManager::PayloadStatusListener>) {
|
||||
payload->id = session_.attachment_payload_map().at(text1_.id());
|
||||
}));
|
||||
});
|
||||
session_.SendNextPayload();
|
||||
|
||||
EXPECT_CALL(send_payload_callback, Call(_, _))
|
||||
.WillOnce(Invoke(
|
||||
.WillOnce(
|
||||
[this](
|
||||
std::unique_ptr<Payload> payload,
|
||||
std::weak_ptr<NearbyConnectionsManager::PayloadStatusListener>) {
|
||||
payload->id = session_.attachment_payload_map().at(text2_.id());
|
||||
}));
|
||||
});
|
||||
session_.SendNextPayload();
|
||||
|
||||
EXPECT_CALL(send_payload_callback, Call(_, _))
|
||||
.WillOnce(Invoke(
|
||||
.WillOnce(
|
||||
[this](
|
||||
std::unique_ptr<Payload> payload,
|
||||
std::weak_ptr<NearbyConnectionsManager::PayloadStatusListener>) {
|
||||
payload->id = session_.attachment_payload_map().at(wifi1_.id());
|
||||
}));
|
||||
});
|
||||
session_.SendNextPayload();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user