mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
analytics: Add GetNextAdvertisingUpdateIndex() and GetNextDiscoveryUpdateIndex() in AnalyticsRecorder, II
PiperOrigin-RevId: 704893011
This commit is contained in:
committed by
Copybara-Service
parent
8979083e31
commit
35c1cb7bcf
@@ -206,6 +206,17 @@ void AnalyticsRecorder::ResetClientSessionLoggingResoucesLocked() {
|
||||
current_discovery_phase_ = nullptr;
|
||||
}
|
||||
|
||||
int AnalyticsRecorder::GetLatestUpdateIndexLocked(
|
||||
const std::vector<ConnectionsLog::OperationResultWithMedium> &list) {
|
||||
int latest_update_index = 0;
|
||||
for (const auto &operation_result_with_medium : list) {
|
||||
if (operation_result_with_medium.update_index() > latest_update_index) {
|
||||
latest_update_index = operation_result_with_medium.update_index();
|
||||
}
|
||||
}
|
||||
return latest_update_index;
|
||||
}
|
||||
|
||||
void AnalyticsRecorder::OnStartAdvertising(
|
||||
connections::Strategy strategy, const std::vector<Medium> &mediums,
|
||||
AdvertisingMetadataParams *advertising_metadata_params) {
|
||||
@@ -255,6 +266,19 @@ void AnalyticsRecorder::OnStopAdvertising() {
|
||||
RecordAdvertisingPhaseDurationAndReasonLocked(/* on_stop= */ true);
|
||||
}
|
||||
|
||||
int AnalyticsRecorder::GetNextAdvertisingUpdateIndex() {
|
||||
MutexLock lock(&mutex_);
|
||||
|
||||
if (current_advertising_phase_ == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
return GetLatestUpdateIndexLocked(
|
||||
std::vector<ConnectionsLog::OperationResultWithMedium>(
|
||||
current_advertising_phase_->adv_dis_result().begin(),
|
||||
current_advertising_phase_->adv_dis_result().end())) +
|
||||
1;
|
||||
}
|
||||
|
||||
void AnalyticsRecorder::OnStartDiscovery(
|
||||
connections::Strategy strategy, const std::vector<Medium> &mediums,
|
||||
DiscoveryMetadataParams *discovery_metadata_params) {
|
||||
@@ -304,6 +328,18 @@ void AnalyticsRecorder::OnStopDiscovery() {
|
||||
RecordDiscoveryPhaseDurationAndReasonLocked(/*on_stop=*/true);
|
||||
}
|
||||
|
||||
int AnalyticsRecorder::GetNextDiscoveryUpdateIndex() {
|
||||
MutexLock lock(&mutex_);
|
||||
if (current_discovery_phase_ == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
return GetLatestUpdateIndexLocked(
|
||||
std::vector<ConnectionsLog::OperationResultWithMedium>(
|
||||
current_discovery_phase_->adv_dis_result().begin(),
|
||||
current_discovery_phase_->adv_dis_result().end())) +
|
||||
1;
|
||||
}
|
||||
|
||||
void AnalyticsRecorder::OnStartedIncomingConnectionListening(
|
||||
connections::Strategy strategy) {
|
||||
MutexLock lock(&mutex_);
|
||||
|
||||
@@ -57,6 +57,12 @@ class AnalyticsRecorder {
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
void OnStopAdvertising() ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
// In case the client calls the {@link BasePcp#updateAdvertisingOptions()}
|
||||
// multiple times, adds one index value to group the mediums results within
|
||||
// the same UpdateAdvertisingOptions call, this API is to return the largest
|
||||
// index value in current_advertising_phase.
|
||||
int GetNextAdvertisingUpdateIndex() ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
// Connection listening
|
||||
void OnStartedIncomingConnectionListening(connections::Strategy strategy)
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
@@ -69,6 +75,12 @@ class AnalyticsRecorder {
|
||||
DiscoveryMetadataParams *discovery_metadata_params)
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
void OnStopDiscovery() ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
// In case the client calls the {@link BasePcp#updateDiscoveryOptions()}
|
||||
// multiple times, adds one index value to group the medium results within the
|
||||
// same UpdateDiscoveryOptions call, this
|
||||
// API is to return the latest index value in current_discovery_phase.
|
||||
int GetNextDiscoveryUpdateIndex() ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
void OnEndpointFound(location::nearby::proto::connections::Medium medium)
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
@@ -441,6 +453,11 @@ class AnalyticsRecorder {
|
||||
void ResetClientSessionLoggingResoucesLocked()
|
||||
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
int GetLatestUpdateIndexLocked(
|
||||
const std::vector<location::nearby::analytics::proto::ConnectionsLog::
|
||||
OperationResultWithMedium> &list)
|
||||
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
location::nearby::proto::connections::ConnectionsStrategy
|
||||
StrategyToConnectionStrategy(connections::Strategy strategy);
|
||||
location::nearby::proto::connections::PayloadType
|
||||
|
||||
@@ -1364,8 +1364,8 @@ P2pClusterPcpHandler::StartListeningForIncomingConnectionsImpl(
|
||||
std::vector<Medium> started_mediums;
|
||||
std::vector<ConnectionsLog::OperationResultWithMedium>
|
||||
operation_result_with_mediums;
|
||||
// TODO(edwinwu): Modify the update_index with a new function.
|
||||
int update_index = 1;
|
||||
int update_index =
|
||||
client_proxy->GetAnalyticsRecorder().GetNextAdvertisingUpdateIndex();
|
||||
if (options.enable_bluetooth_listening &&
|
||||
!bluetooth_medium_.IsAcceptingConnections(std::string(service_id))) {
|
||||
ErrorOr<bool> bluetooth_result =
|
||||
@@ -1550,9 +1550,8 @@ P2pClusterPcpHandler::UpdateAdvertisingOptionsImpl(
|
||||
std::vector<Medium> restarted_mediums;
|
||||
std::vector<ConnectionsLog::OperationResultWithMedium>
|
||||
operation_result_with_mediums;
|
||||
// TODO(edwinwu): Modify the update_index with a new function :
|
||||
// client->GetAnalyticsRecorder()->GetNextAdvertisingUpdateIndex();
|
||||
int update_index = 1;
|
||||
int update_index =
|
||||
client->GetAnalyticsRecorder().GetNextAdvertisingUpdateIndex();
|
||||
Status status = {Status::kSuccess};
|
||||
WebRtcState web_rtc_state = webrtc_medium_.IsAvailable()
|
||||
? WebRtcState::kConnectable
|
||||
|
||||
Reference in New Issue
Block a user