From fb2e7e687b3c73f87c93846f74657e2820463ffd Mon Sep 17 00:00:00 2001 From: Edwin Wu Date: Tue, 10 Dec 2024 20:54:10 -0800 Subject: [PATCH] analytics: Modify OperationResultCode in C++ implementation PiperOrigin-RevId: 704951400 --- .../analytics/analytics_recorder.cc | 15 +++++++-------- .../implementation/analytics/analytics_recorder.h | 2 +- .../implementation/base_endpoint_channel.cc | 2 +- connections/implementation/base_pcp_handler.cc | 2 +- .../internal_payload_factory_test.cc | 12 ++++++------ connections/implementation/mediums/ble.cc | 3 +-- connections/implementation/mediums/ble_v2.cc | 6 ++---- .../implementation/mediums/bluetooth_classic.cc | 14 ++++---------- connections/implementation/mediums/wifi_direct.cc | 3 +-- .../implementation/mediums/wifi_hotspot.cc | 3 +-- connections/implementation/mediums/wifi_lan.cc | 12 ++++-------- 11 files changed, 29 insertions(+), 45 deletions(-) diff --git a/connections/implementation/analytics/analytics_recorder.cc b/connections/implementation/analytics/analytics_recorder.cc index fa138441..217c5002 100644 --- a/connections/implementation/analytics/analytics_recorder.cc +++ b/connections/implementation/analytics/analytics_recorder.cc @@ -107,8 +107,7 @@ using ::nearby::analytics::EventLogger; using SafeDisconnectionResult = ::location::nearby::analytics::proto:: ConnectionsLog::EstablishedConnection::SafeDisconnectionResult; -// TODO(edwinwu): Add ifttt in Android counterpart. -OperationResultCategory ConvertToOperationResultCateory( +OperationResultCategory ConvertToOperationResultCategory( OperationResultCode result_code) { if (result_code == OperationResultCode::DETAIL_SUCCESS) { return OperationResultCategory::CATEGORY_SUCCESS; @@ -537,7 +536,7 @@ void AnalyticsRecorder::OnIncomingConnectionAttemptLocked( std::make_unique(); operation_result_proto->set_result_code( connection_attempt_metadata_params->operation_result_code); - operation_result_proto->set_result_category(ConvertToOperationResultCateory( + operation_result_proto->set_result_category(ConvertToOperationResultCategory( connection_attempt_metadata_params->operation_result_code)); connection_attempt->set_allocated_operation_result( operation_result_proto.release()); @@ -625,7 +624,7 @@ void AnalyticsRecorder::OnOutgoingConnectionAttemptLocked( std::make_unique(); operation_result_proto->set_result_code( connection_attempt_metadata_params->operation_result_code); - operation_result_proto->set_result_category(ConvertToOperationResultCateory( + operation_result_proto->set_result_category(ConvertToOperationResultCategory( connection_attempt_metadata_params->operation_result_code)); connection_attempt->set_allocated_operation_result( operation_result_proto.release()); @@ -1359,7 +1358,7 @@ void AnalyticsRecorder::FinishUpgradeAttemptLocked( std::make_unique(); operation_result_proto->set_result_code(operation_result_code); operation_result_proto->set_result_category( - ConvertToOperationResultCateory(operation_result_code)); + ConvertToOperationResultCategory(operation_result_code)); attempt->set_allocated_operation_result(operation_result_proto.release()); *current_strategy_session_->add_upgrade_attempt() = *attempt; if (erase_item) { @@ -1462,7 +1461,7 @@ ConnectionsLog::Payload AnalyticsRecorder::PendingPayload::GetProtoPayload( std::make_unique(); operation_result_proto->set_result_code(operation_result_code_); operation_result_proto->set_result_category( - ConvertToOperationResultCateory(operation_result_code_)); + ConvertToOperationResultCategory(operation_result_code_)); payload.set_allocated_operation_result(operation_result_proto.release()); return payload; @@ -1732,9 +1731,9 @@ AnalyticsRecorder::LogicalConnection::GetPendingPayloadResultCodeFromReason( } } -OperationResultCategory AnalyticsRecorder::GetOperationResultCateory( +OperationResultCategory AnalyticsRecorder::GetOperationResultCategory( location::nearby::proto::connections::OperationResultCode result_code) { - return ConvertToOperationResultCateory(result_code); + return ConvertToOperationResultCategory(result_code); } void AnalyticsRecorder::Sync() { diff --git a/connections/implementation/analytics/analytics_recorder.h b/connections/implementation/analytics/analytics_recorder.h index eed3b4ea..64bd9b7e 100644 --- a/connections/implementation/analytics/analytics_recorder.h +++ b/connections/implementation/analytics/analytics_recorder.h @@ -227,7 +227,7 @@ class AnalyticsRecorder { bool IsSessionLogged(); location::nearby::proto::connections::OperationResultCategory - GetOperationResultCateory( + GetOperationResultCategory( location::nearby::proto::connections::OperationResultCode result_code); // Waits until all logs are sent to the backend. diff --git a/connections/implementation/base_endpoint_channel.cc b/connections/implementation/base_endpoint_channel.cc index 1213300c..d810d40e 100644 --- a/connections/implementation/base_endpoint_channel.cc +++ b/connections/implementation/base_endpoint_channel.cc @@ -91,7 +91,7 @@ BaseEndpointChannel::BaseEndpointChannel(const std::string& service_id, service_id, channel_name, reader, writer, // TODO(edwinwu): Below values should be retrieved from a base socket, // the #MediumSocket in Android counterpart, from which all the - // derived medium sockets should dervied, and implement the supported + // derived medium sockets should derived, and implement the supported // values and leave the default values in base #MediumSocket. /*ConnectionTechnology*/ location::nearby::proto::connections:: diff --git a/connections/implementation/base_pcp_handler.cc b/connections/implementation/base_pcp_handler.cc index e6e14d1d..42cb5ac7 100644 --- a/connections/implementation/base_pcp_handler.cc +++ b/connections/implementation/base_pcp_handler.cc @@ -1159,7 +1159,7 @@ BasePcpHandler::GetOperationResultWithMediumByResultCode( operation_result_with_medium->set_medium(medium); operation_result_with_medium->set_result_code(operation_result_code); operation_result_with_medium->set_result_category( - client->GetAnalyticsRecorder().GetOperationResultCateory( + client->GetAnalyticsRecorder().GetOperationResultCategory( operation_result_code)); operation_result_with_medium->set_connection_mode(connection_mode); operation_result_with_medium->set_update_index(update_index); diff --git a/connections/implementation/internal_payload_factory_test.cc b/connections/implementation/internal_payload_factory_test.cc index d69e6d7b..46c5c923 100644 --- a/connections/implementation/internal_payload_factory_test.cc +++ b/connections/implementation/internal_payload_factory_test.cc @@ -214,11 +214,11 @@ TEST(InternalPayloadFactoryTest, Payload::Id payload_id = Payload::GenerateId(); CreateFileWithContents(payload_id, contents); InputFile inputFile(payload_id, contents.size()); - ErrorOr> interal_payload_result = + ErrorOr> internal_payload_result = CreateOutgoingInternalPayload(Payload{payload_id, std::move(inputFile)}); - ASSERT_FALSE(interal_payload_result.has_error()); + ASSERT_FALSE(internal_payload_result.has_error()); std::unique_ptr internal_payload = - std::move(interal_payload_result.value()); + std::move(internal_payload_result.value()); EXPECT_NE(internal_payload, nullptr); ExceptionOr result = internal_payload->SkipToOffset(kOffset); @@ -236,11 +236,11 @@ TEST(InternalPayloadFactoryTest, ByteArray contents("0123456789"); constexpr size_t kOffset = 6; auto [input, output] = CreatePipe(); - ErrorOr> interal_payload_result = + ErrorOr> internal_payload_result = CreateOutgoingInternalPayload(Payload(std::move(input))); - ASSERT_FALSE(interal_payload_result.has_error()); + ASSERT_FALSE(internal_payload_result.has_error()); std::unique_ptr internal_payload = - std::move(interal_payload_result.value()); + std::move(internal_payload_result.value()); EXPECT_NE(internal_payload, nullptr); output->Write(contents); diff --git a/connections/implementation/mediums/ble.cc b/connections/implementation/mediums/ble.cc index a864bfb0..8071410f 100644 --- a/connections/implementation/mediums/ble.cc +++ b/connections/implementation/mediums/ble.cc @@ -403,8 +403,7 @@ ErrorOr Ble::Connect(BlePeripheral& peripheral, if (service_id.empty()) { NEARBY_LOGS(INFO) << "Refusing to create BLE socket with empty service_id."; - // TODO(edwinwu): Modify new OperationResultCode - return {Error(OperationResultCode::DETAIL_UNKNOWN)}; + return {Error(OperationResultCode::NEARBY_LOCAL_CLIENT_STATE_WRONG)}; } if (!radio_.IsEnabled()) { diff --git a/connections/implementation/mediums/ble_v2.cc b/connections/implementation/mediums/ble_v2.cc index 20d34b46..f8189d0c 100644 --- a/connections/implementation/mediums/ble_v2.cc +++ b/connections/implementation/mediums/ble_v2.cc @@ -353,8 +353,7 @@ ErrorOr BleV2::StartScanning(const std::string& service_id, if (service_id.empty()) { LOG(INFO) << "Can not start BLE scanning with empty service id."; - // TODO(edwinwu): Modify new OperationResultCode - return {Error(OperationResultCode::DETAIL_UNKNOWN)}; + return {Error(OperationResultCode::NEARBY_LOCAL_CLIENT_STATE_WRONG)}; } if (IsScanningLocked(service_id)) { @@ -612,8 +611,7 @@ ErrorOr BleV2::Connect(const std::string& service_id, if (service_id.empty()) { LOG(INFO) << "Refusing to create client Ble socket because " "service_id is empty."; - // TODO(edwinwu): Modify new OperationResultCode - return {Error(OperationResultCode::DETAIL_UNKNOWN)}; + return {Error(OperationResultCode::NEARBY_LOCAL_CLIENT_STATE_WRONG)}; } if (!IsAvailableLocked()) { diff --git a/connections/implementation/mediums/bluetooth_classic.cc b/connections/implementation/mediums/bluetooth_classic.cc index 3f9d9016..594c6607 100644 --- a/connections/implementation/mediums/bluetooth_classic.cc +++ b/connections/implementation/mediums/bluetooth_classic.cc @@ -132,9 +132,7 @@ ErrorOr BluetoothClassic::TurnOnDiscoverability( LOG(INFO) << "Refusing to turn on BT discoverability; new name='" << device_name << "'; current name='" << adapter_.GetName() << "'"; - // TODO(edwinwu): Modify new OperationResultCode - return {Error( - OperationResultCode::CONNECTIVITY_BLUETOOTH_CHANGE_SCAN_MODE_FAILURE)}; + return {Error(OperationResultCode::CONNECTIVITY_BLUETOOTH_SCAN_FAILURE)}; } if (!ModifyDeviceName(device_name)) { @@ -233,8 +231,7 @@ ErrorOr BluetoothClassic::StartDiscovery( if (serviceId.empty()) { LOG(INFO) << "Refusing to start discovery; service ID is empty."; - // TODO(edwinwu): Modify new OperationResultCode - return {Error(OperationResultCode::DETAIL_UNKNOWN)}; + return {Error(OperationResultCode::NEARBY_LOCAL_CLIENT_STATE_WRONG)}; } if (!radio_.IsEnabled()) { @@ -287,7 +284,6 @@ ErrorOr BluetoothClassic::StartDiscovery( AddDiscoveryCallback(serviceId, std::move(callback)); - // TODO(edwinwu): See if platform code needs to return ErrorOr if (!medium_->StartDiscovery(std::move(medium_callback))) { LOG(INFO) << "Failed to start discovery of BT devices."; RemoveDiscoveryCallback(serviceId); @@ -344,8 +340,7 @@ ErrorOr BluetoothClassic::StartAcceptingConnections( if (service_id.empty()) { LOG(INFO) << "Refusing to start accepting BT connections; service ID is empty."; - // TODO(edwinwu): Modify new OperationResultCode - return {Error(OperationResultCode::DETAIL_UNKNOWN)}; + return {Error(OperationResultCode::NEARBY_LOCAL_CLIENT_STATE_WRONG)}; } if (!radio_.IsEnabled()) { @@ -571,8 +566,7 @@ ErrorOr BluetoothClassic::AttemptToConnect( if (service_id.empty()) { LOG(WARNING) << "Refusing to create client BT socket because service_id is empty."; - // TODO(edwinwu): Modify new OperationResultCode - return {Error(OperationResultCode::DETAIL_UNKNOWN)}; + return {Error(OperationResultCode::NEARBY_LOCAL_CLIENT_STATE_WRONG)}; } if (!radio_.IsEnabled()) { diff --git a/connections/implementation/mediums/wifi_direct.cc b/connections/implementation/mediums/wifi_direct.cc index b33f9870..7a8a16f1 100644 --- a/connections/implementation/mediums/wifi_direct.cc +++ b/connections/implementation/mediums/wifi_direct.cc @@ -269,8 +269,7 @@ ErrorOr WifiDirect::Connect( if (service_id.empty()) { NEARBY_LOGS(INFO) << "Refusing to create client WifiDirect socket because " "service_id is empty."; - // TODO(edwinwu): Modify new OperationResultCode - return {Error(OperationResultCode::DETAIL_UNKNOWN)}; + return {Error(OperationResultCode::NEARBY_LOCAL_CLIENT_STATE_WRONG)}; } if (!IsGCAvailableLocked()) { diff --git a/connections/implementation/mediums/wifi_hotspot.cc b/connections/implementation/mediums/wifi_hotspot.cc index 37db02cf..caaa0cac 100644 --- a/connections/implementation/mediums/wifi_hotspot.cc +++ b/connections/implementation/mediums/wifi_hotspot.cc @@ -268,8 +268,7 @@ ErrorOr WifiHotspot::Connect( if (service_id.empty()) { NEARBY_LOGS(INFO) << "Refusing to create client WifiHotspot socket because " "service_id is empty."; - // TODO(edwinwu): Modify new OperationResultCode - return {Error(OperationResultCode::DETAIL_UNKNOWN)}; + return {Error(OperationResultCode::NEARBY_LOCAL_CLIENT_STATE_WRONG)}; } if (!IsClientAvailableLocked()) { diff --git a/connections/implementation/mediums/wifi_lan.cc b/connections/implementation/mediums/wifi_lan.cc index e36de309..76d4b77e 100644 --- a/connections/implementation/mediums/wifi_lan.cc +++ b/connections/implementation/mediums/wifi_lan.cc @@ -176,8 +176,7 @@ ErrorOr WifiLan::StartDiscovery(const std::string& service_id, if (service_id.empty()) { NEARBY_LOGS(INFO) << "Refusing to start WifiLan discovering with empty service_id."; - // TODO(edwinwu): Modify new OperationResultCode - return {Error(OperationResultCode::DETAIL_UNKNOWN)}; + return {Error(OperationResultCode::NEARBY_LOCAL_CLIENT_STATE_WRONG)}; } if (!IsAvailableLocked()) { @@ -244,8 +243,7 @@ ErrorOr WifiLan::StartAcceptingConnections( if (service_id.empty()) { NEARBY_LOGS(INFO) << "Refusing to start accepting WifiLan connections; " "service_id is empty."; - // TODO(edwinwu): Modify new OperationResultCode - return {Error(OperationResultCode::DETAIL_UNKNOWN)}; + return {Error(OperationResultCode::NEARBY_LOCAL_CLIENT_STATE_WRONG)}; } if (!IsAvailableLocked()) { @@ -438,8 +436,7 @@ ErrorOr WifiLan::Connect(const std::string& service_id, if (service_id.empty()) { NEARBY_LOGS(INFO) << "Refusing to create client WifiLan socket because " "service_id is empty."; - // TODO(edwinwu): Modify new OperationResultCode - return {Error(OperationResultCode::DETAIL_UNKNOWN)}; + return {Error(OperationResultCode::NEARBY_LOCAL_CLIENT_STATE_WRONG)}; } if (!IsAvailableLocked()) { @@ -493,8 +490,7 @@ ErrorOr WifiLan::Connect(const std::string& service_id, if (service_id.empty()) { NEARBY_LOGS(INFO) << "Refusing to create client WifiLan socket because " "service_id is empty."; - // TODO(edwinwu): Modify new OperationResultCode - return {Error(OperationResultCode::DETAIL_UNKNOWN)}; + return {Error(OperationResultCode::NEARBY_LOCAL_CLIENT_STATE_WRONG)}; } if (!IsAvailableLocked()) {