Fixed the crash after sending a file from windows device

PiperOrigin-RevId: 472782884
This commit is contained in:
Guogang Li
2022-09-07 12:15:32 -07:00
committed by Copybara-Service
parent 4f599a0d3e
commit 397964b5da
2 changed files with 62 additions and 45 deletions
@@ -438,6 +438,11 @@ void AnalyticsRecorder::OnConnectionClosed(const std::string &endpoint_id,
Medium medium,
DisconnectionReason reason) {
MutexLock lock(&mutex_);
NEARBY_LOGS(INFO) << __func__
<< ": OnConnectionClosed is called with endpoint_id:"
<< endpoint_id << ", medium:" << Medium_Name(medium)
<< ", reason:" << DisconnectionReason_Name(reason);
if (!CanRecordAnalyticsLocked("OnConnectionClosed")) {
return;
}
@@ -453,14 +458,24 @@ void AnalyticsRecorder::OnConnectionClosed(const std::string &endpoint_id,
// re-established with a new ConnectionRequest.
auto pair = active_connections_.extract(it);
std::unique_ptr<LogicalConnection> &logical_connection = pair.mapped();
logical_connection->GetEstablisedConnections();
std::vector<ConnectionsLog::EstablishedConnection> connections =
logical_connection->GetEstablisedConnections();
auto established_connections =
current_strategy_session_->mutable_established_connection();
for (auto &connection : connections) {
established_connections->Add(std::move(connection));
}
// TODO(b/245553737): the recent change in protobuf may broken the class of
// RepeatedFieldPtr. Our app will crash after sending file. The app also
// crashes even only print the size of mutable_established_connection. we
// need to reccover the code when protobuf fixes the issue.
// auto pair = active_connections_.extract(it);
// std::unique_ptr<LogicalConnection> &logical_connection =
// pair.mapped();
// std::vector<ConnectionsLog::EstablishedConnection> connections =
// logical_connection->GetEstablisedConnections();
// auto established_connections =
// current_strategy_session_->mutable_established_connection();
// for (auto &connection : connections) {
// established_connections->Add(std::move(connection));
// }
}
}
@@ -771,44 +771,46 @@ TEST(AnalyticsRecorderTest, OutgoingPayloadUpgraded) {
analytics_recorder.LogSession();
ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result());
EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb(
strategy_session <
strategy: P2P_STAR
role: ADVERTISER
advertising_phase <
medium: BLE
medium: BLUETOOTH
advertising_metadata <
supports_extended_ble_advertisements: false
connected_ap_frequency: 0
supports_nfc_technology: false
>
>
established_connection <
medium: BLUETOOTH
sent_payload <
type: FILE
total_size_bytes: 50
num_bytes_transferred: 20
num_chunks: 2
status: MOVED_TO_NEW_MEDIUM
>
disconnection_reason: UPGRADED
connection_token: "connection_token"
>
established_connection <
medium: WIFI_LAN
sent_payload <
type: FILE
total_size_bytes: 50
num_bytes_transferred: 30
num_chunks: 3
status: SUCCESS
>
disconnection_reason: LOCAL_DISCONNECTION
connection_token: "connection_token"
>
>)pb")));
// TODO(b/245553737): recover the codes.
// EXPECT_THAT(event_logger.GetLoggedClientSession(),
// Partially(EqualsProto(R"pb(
// strategy_session <
// strategy: P2P_STAR
// role: ADVERTISER
// advertising_phase <
// medium: BLE
// medium: BLUETOOTH
// advertising_metadata <
// supports_extended_ble_advertisements: false
// connected_ap_frequency: 0
// supports_nfc_technology: false
// >
// >
// established_connection <
// medium: BLUETOOTH
// sent_payload <
// type: FILE
// total_size_bytes: 50
// num_bytes_transferred: 20
// num_chunks: 2
// status: MOVED_TO_NEW_MEDIUM
// >
// disconnection_reason: UPGRADED
// connection_token: "connection_token"
// >
// established_connection <
// medium: WIFI_LAN
// sent_payload <
// type: FILE
// total_size_bytes: 50
// num_bytes_transferred: 30
// num_chunks: 3
// status: SUCCESS
// >
// disconnection_reason: LOCAL_DISCONNECTION
// connection_token: "connection_token"
// >
// >)pb")));
}
TEST(AnalyticsRecorderTest, UpgradeAttemptWorks) {