From 397964b5daebc523e2af794d263446c70d854e32 Mon Sep 17 00:00:00 2001 From: Guogang Li Date: Wed, 7 Sep 2022 12:13:40 -0700 Subject: [PATCH] Fixed the crash after sending a file from windows device PiperOrigin-RevId: 472782884 --- .../analytics/analytics_recorder.cc | 29 +++++-- .../analytics/analytics_recorder_test.cc | 78 ++++++++++--------- 2 files changed, 62 insertions(+), 45 deletions(-) diff --git a/connections/implementation/analytics/analytics_recorder.cc b/connections/implementation/analytics/analytics_recorder.cc index 796cecfa..e96abd6e 100644 --- a/connections/implementation/analytics/analytics_recorder.cc +++ b/connections/implementation/analytics/analytics_recorder.cc @@ -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 &logical_connection = pair.mapped(); + logical_connection->GetEstablisedConnections(); - std::vector 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 &logical_connection = + // pair.mapped(); + + // std::vector connections = + // logical_connection->GetEstablisedConnections(); + // auto established_connections = + // current_strategy_session_->mutable_established_connection(); + // for (auto &connection : connections) { + // established_connections->Add(std::move(connection)); + // } } } diff --git a/connections/implementation/analytics/analytics_recorder_test.cc b/connections/implementation/analytics/analytics_recorder_test.cc index 9380cc78..6101c9b2 100644 --- a/connections/implementation/analytics/analytics_recorder_test.cc +++ b/connections/implementation/analytics/analytics_recorder_test.cc @@ -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) {