diff --git a/cpp/analytics/analytics_recorder.cc b/cpp/analytics/analytics_recorder.cc index d861b4b2..a79d8b08 100644 --- a/cpp/analytics/analytics_recorder.cc +++ b/cpp/analytics/analytics_recorder.cc @@ -101,8 +101,10 @@ AnalyticsRecorder::~AnalyticsRecorder() { serial_executor_.Shutdown(); } -void AnalyticsRecorder::OnStartAdvertising(connections::Strategy strategy, - const std::vector &mediums) { +void AnalyticsRecorder::OnStartAdvertising( + connections::Strategy strategy, const std::vector &mediums, + bool is_extended_advertisement_supported, int connected_ap_frequency, + bool is_nfc_available) { MutexLock lock(&mutex_); if (!CanRecordAnalyticsLocked("OnStartAdvertising")) { return; @@ -121,6 +123,13 @@ void AnalyticsRecorder::OnStartAdvertising(connections::Strategy strategy, absl::make_unique(); absl::c_copy(mediums, RepeatedFieldBackInserter( current_advertising_phase_->mutable_medium())); + // Set a AdvertisingMetadata. + auto *advertising_metadata = + current_advertising_phase_->mutable_advertising_metadata(); + advertising_metadata->set_supports_extended_ble_advertisements( + is_extended_advertisement_supported); + advertising_metadata->set_connected_ap_frequency(connected_ap_frequency); + advertising_metadata->set_supports_nfc_technology(is_nfc_available); } void AnalyticsRecorder::OnStopAdvertising() { @@ -131,8 +140,10 @@ void AnalyticsRecorder::OnStopAdvertising() { RecordAdvertisingPhaseDurationLocked(); } -void AnalyticsRecorder::OnStartDiscovery(connections::Strategy strategy, - const std::vector &mediums) { +void AnalyticsRecorder::OnStartDiscovery( + connections::Strategy strategy, const std::vector &mediums, + bool is_extended_advertisement_supported, int connected_ap_frequency, + bool is_nfc_available) { MutexLock lock(&mutex_); if (!CanRecordAnalyticsLocked("OnStartDiscovery")) { return; @@ -152,6 +163,13 @@ void AnalyticsRecorder::OnStartDiscovery(connections::Strategy strategy, absl::make_unique(); absl::c_copy(mediums, RepeatedFieldBackInserter( current_discovery_phase_->mutable_medium())); + // Set a DiscoveryMetadata. + auto *discovery_metadata = + current_discovery_phase_->mutable_discovery_metadata(); + discovery_metadata->set_supports_extended_ble_advertisements( + is_extended_advertisement_supported); + discovery_metadata->set_connected_ap_frequency(connected_ap_frequency); + discovery_metadata->set_supports_nfc_technology(is_nfc_available); } void AnalyticsRecorder::OnStopDiscovery() { diff --git a/cpp/analytics/analytics_recorder.h b/cpp/analytics/analytics_recorder.h index 9423e2f6..d58ea990 100644 --- a/cpp/analytics/analytics_recorder.h +++ b/cpp/analytics/analytics_recorder.h @@ -38,17 +38,25 @@ class AnalyticsRecorder { explicit AnalyticsRecorder(EventLogger *event_logger); virtual ~AnalyticsRecorder(); + // TODO(edwinwu): Implement to pass real values for AdvertisingMetadata and + // DiscoveryMetaData: is_extended_advertisement_supported, + // connected_ap_frequency, and is_nfc_available. Set as default values for + // analytics recorder. // Advertising phase void OnStartAdvertising( connections::Strategy strategy, - const std::vector &mediums) + const std::vector &mediums, + bool is_extended_advertisement_supported = false, + int connected_ap_frequency = 0, bool is_nfc_available = false) ABSL_LOCKS_EXCLUDED(mutex_); void OnStopAdvertising() ABSL_LOCKS_EXCLUDED(mutex_); // Discovery phase void OnStartDiscovery( connections::Strategy strategy, - const std::vector &mediums) + const std::vector &mediums, + bool is_extended_advertisement_supported = false, + int connected_ap_frequency = 0, bool is_nfc_available = false) ABSL_LOCKS_EXCLUDED(mutex_); void OnStopDiscovery() ABSL_LOCKS_EXCLUDED(mutex_); void OnEndpointFound(location::nearby::proto::connections::Medium medium) diff --git a/cpp/analytics/analytics_recorder_test.cc b/cpp/analytics/analytics_recorder_test.cc index 700adaeb..bdee3061 100644 --- a/cpp/analytics/analytics_recorder_test.cc +++ b/cpp/analytics/analytics_recorder_test.cc @@ -144,8 +144,23 @@ TEST(AnalyticsRecorderTest, SetFieldsCorrectlyForNestedAdvertisingCalls) { strategy_session < strategy: P2P_STAR role: ADVERTISER - advertising_phase < medium: BLE medium: BLUETOOTH > - advertising_phase < medium: BLUETOOTH > + advertising_phase < + medium: BLE + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + advertising_phase < + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > >)pb"))); } @@ -157,11 +172,11 @@ TEST(AnalyticsRecorderTest, SetFieldsCorrectlyForNestedDiscoveryCalls) { FakeEventLogger event_logger(client_session_done_latch); AnalyticsRecorder analytics_recorder(&event_logger); - analytics_recorder.OnStartDiscovery(strategy, mediums); + analytics_recorder.OnStartDiscovery(strategy, mediums, true, 1, false); analytics_recorder.OnStopDiscovery(); analytics_recorder.OnEndpointFound(BLUETOOTH); analytics_recorder.OnEndpointFound(BLE); - analytics_recorder.OnStartDiscovery(strategy, {BLUETOOTH}); + analytics_recorder.OnStartDiscovery(strategy, {BLUETOOTH}, true, 1, false); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); @@ -175,8 +190,20 @@ TEST(AnalyticsRecorderTest, SetFieldsCorrectlyForNestedDiscoveryCalls) { medium: BLUETOOTH discovered_endpoint < medium: BLUETOOTH > discovered_endpoint < medium: BLE > + discovery_metadata < + supports_extended_ble_advertisements: true + connected_ap_frequency: 1 + supports_nfc_technology: false + > + > + discovery_phase < + medium: BLUETOOTH + discovery_metadata < + supports_extended_ble_advertisements: true + connected_ap_frequency: 1 + supports_nfc_technology: false + > > - discovery_phase < medium: BLUETOOTH > >)pb"))); } @@ -214,12 +241,60 @@ TEST(AnalyticsRecorderTest, strategy: P2P_STAR role: ADVERTISER role: DISCOVERER - discovery_phase < medium: BLE medium: BLUETOOTH > - discovery_phase < medium: BLE medium: BLUETOOTH > - discovery_phase < medium: BLE medium: BLUETOOTH > - advertising_phase < medium: BLE medium: BLUETOOTH > - advertising_phase < medium: BLE medium: BLUETOOTH > - advertising_phase < medium: BLE medium: BLUETOOTH > + discovery_phase < + medium: BLE + medium: BLUETOOTH + discovery_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + discovery_phase < + medium: BLE + medium: BLUETOOTH + discovery_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + discovery_phase < + medium: BLE + medium: BLUETOOTH + discovery_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + advertising_phase < + medium: BLE + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + advertising_phase < + medium: BLE + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + advertising_phase < + medium: BLE + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > >)pb"))); } @@ -262,6 +337,11 @@ TEST(AnalyticsRecorderTest, AdvertiserConnectionRequestsWorks) { advertising_phase < medium: BLE medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > received_connection_request < local_response: ACCEPTED remote_response: ACCEPTED @@ -322,6 +402,11 @@ TEST(AnalyticsRecorderTest, DiscoveryConnectionRequestsWorks) { discovery_phase < medium: BLE medium: BLUETOOTH + discovery_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > sent_connection_request < local_response: ACCEPTED remote_response: ACCEPTED @@ -376,6 +461,11 @@ TEST(AnalyticsRecorderTest, advertising_phase < medium: BLE medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > received_connection_request < local_response: IGNORED remote_response: ACCEPTED @@ -427,6 +517,11 @@ TEST(AnalyticsRecorderTest, discovery_phase < medium: BLE medium: BLUETOOTH + discovery_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > sent_connection_request < local_response: IGNORED remote_response: ACCEPTED @@ -466,7 +561,15 @@ TEST(AnalyticsRecorderTest, SuccessfulIncomingConnectionAttempt) { strategy_session < strategy: P2P_STAR role: ADVERTISER - advertising_phase < medium: BLE medium: BLUETOOTH > + advertising_phase < + medium: BLE + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > connection_attempt < type: INITIAL direction: INCOMING @@ -527,6 +630,11 @@ TEST(AnalyticsRecorderTest, discovery_phase < medium: BLE medium: BLUETOOTH + discovery_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > sent_connection_request < local_response: NOT_SENT remote_response: NOT_SENT @@ -579,7 +687,15 @@ TEST(AnalyticsRecorderTest, UnfinishedEstablishedConnectionsAddedAsUnfinished) { strategy_session < strategy: P2P_STAR role: ADVERTISER - advertising_phase < medium: BLE medium: BLUETOOTH > + 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 disconnection_reason: UPGRADED @@ -628,7 +744,15 @@ TEST(AnalyticsRecorderTest, OutgoingPayloadUpgraded) { strategy_session < strategy: P2P_STAR role: ADVERTISER - advertising_phase < medium: BLE medium: BLUETOOTH > + 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 < @@ -691,7 +815,15 @@ TEST(AnalyticsRecorderTest, UpgradeAttemptWorks) { strategy_session < strategy: P2P_STAR role: ADVERTISER - advertising_phase < medium: BLE medium: BLUETOOTH > + advertising_phase < + medium: BLE + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > upgrade_attempt < direction: INCOMING from_medium: BLE diff --git a/cpp/core/internal/client_proxy.cc b/cpp/core/internal/client_proxy.cc index 031832cb..106d4919 100644 --- a/cpp/core/internal/client_proxy.cc +++ b/cpp/core/internal/client_proxy.cc @@ -128,7 +128,7 @@ void ClientProxy::StartedAdvertising( const std::vector medium_vector(mediums.begin(), mediums.end()); - analytics_recorder_->OnStartAdvertising(strategy, medium_vector); + analytics_recorder_->OnStartAdvertising(strategy, medium_vector, false, 0); } void ClientProxy::StoppedAdvertising() { @@ -175,7 +175,7 @@ void ClientProxy::StartedDiscovery( const std::vector medium_vector(mediums.begin(), mediums.end()); - analytics_recorder_->OnStartDiscovery(strategy, medium_vector); + analytics_recorder_->OnStartDiscovery(strategy, medium_vector, false, 0); } void ClientProxy::StoppedDiscovery() {