From 546e0528e7847ef4adb148d01813faf51c57cbed Mon Sep 17 00:00:00 2001 From: "Olha Vorobiova (GitHub)" <86727408+OlhaVorobiova@users.noreply.github.com> Date: Tue, 21 Jun 2022 02:40:00 +0200 Subject: Move subscribe_on_event before sending BCActivateAppRequest (#3915) --- .../application_manager/state_controller_impl.h | 7 +++-- .../src/state_controller_impl.cc | 34 +++++++++------------- .../test/state_controller/state_controller_test.cc | 6 +++- 3 files changed, 23 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/components/application_manager/include/application_manager/state_controller_impl.h b/src/components/application_manager/include/application_manager/state_controller_impl.h index 6845851f97..e0200f55af 100644 --- a/src/components/application_manager/include/application_manager/state_controller_impl.h +++ b/src/components/application_manager/include/application_manager/state_controller_impl.h @@ -136,9 +136,10 @@ class StateControllerImpl : public event_engine::EventObserver, PostponedActivationController& GetPostponedActivationController() OVERRIDE; private: - int64_t RequestHMIStateChange(ApplicationConstSharedPtr app, - hmi_apis::Common_HMILevel::eType level, - bool send_policy_priority); + void RequestHMIStateChange(ApplicationConstSharedPtr app, + HmiStatePtr resolved_state, + hmi_apis::Common_HMILevel::eType level, + bool send_policy_priority); /** * @brief The HmiLevelConflictResolver struct diff --git a/src/components/application_manager/src/state_controller_impl.cc b/src/components/application_manager/src/state_controller_impl.cc index 28146a1adc..9880edb4a1 100644 --- a/src/components/application_manager/src/state_controller_impl.cc +++ b/src/components/application_manager/src/state_controller_impl.cc @@ -112,20 +112,7 @@ void StateControllerImpl::SetRegularState(ApplicationSharedPtr app, resolved_state->hmi_level()); if (request_hmi_state_change) { - const int64_t result = RequestHMIStateChange(app, hmi_level, true); - if (-1 != result) { - const uint32_t corr_id = static_cast(result); - - subscribe_on_event( - hmi_apis::FunctionID::BasicCommunication_CloseApplication, corr_id); - subscribe_on_event(hmi_apis::FunctionID::BasicCommunication_ActivateApp, - corr_id); - - waiting_for_response_[app->app_id()] = resolved_state; - app_mngr_.set_application_id(corr_id, app->hmi_app_id()); - return; - } - SDL_LOG_ERROR("Unable to send BC.ActivateApp"); + RequestHMIStateChange(app, resolved_state, hmi_level, true); return; } ApplyRegularState(app, window_id, resolved_state); @@ -1104,8 +1091,9 @@ void StateControllerImpl::OnAppWindowAdded( OnStateChanged(app, window_id, initial_state, new_state); } -int64_t StateControllerImpl::RequestHMIStateChange( +void StateControllerImpl::RequestHMIStateChange( ApplicationConstSharedPtr app, + HmiStatePtr resolved_state, hmi_apis::Common_HMILevel::eType level, bool send_policy_priority) { SDL_LOG_AUTO_TRACE(); @@ -1122,15 +1110,21 @@ int64_t StateControllerImpl::RequestHMIStateChange( } if (!request) { SDL_LOG_ERROR("Unable to create request"); - return -1; + return; } + + const uint32_t corr_id = + (*request)[strings::params][strings::correlation_id].asUInt(); + subscribe_on_event(hmi_apis::FunctionID::BasicCommunication_CloseApplication, + corr_id); + subscribe_on_event(hmi_apis::FunctionID::BasicCommunication_ActivateApp, + corr_id); + waiting_for_response_[app->app_id()] = resolved_state; + app_mngr_.set_application_id(corr_id, app->hmi_app_id()); + if (!app_mngr_.GetRPCService().ManageHMICommand(request)) { SDL_LOG_ERROR("Unable to send request"); - return -1; } - const uint32_t corr_id = - (*request)[strings::params][strings::correlation_id].asUInt(); - return static_cast(corr_id); } void StateControllerImpl::ApplyPostponedStateForApp(ApplicationSharedPtr app) { diff --git a/src/components/application_manager/test/state_controller/state_controller_test.cc b/src/components/application_manager/test/state_controller/state_controller_test.cc index b6ec4fc8ef..f255223136 100644 --- a/src/components/application_manager/test/state_controller/state_controller_test.cc +++ b/src/components/application_manager/test/state_controller/state_controller_test.cc @@ -3654,7 +3654,11 @@ TEST_F(StateControllerImplTest, static_cast(new_state->hmi_level()), kCorrID); - smart_objects::SmartObjectSPtr bc_activate_app_request; + smart_objects::SmartObjectSPtr bc_activate_app_request = + std::make_shared(); + (*bc_activate_app_request)[am::strings::params][am::strings::correlation_id] = + kCorrID; + EXPECT_CALL(message_helper_mock_, GetBCActivateAppRequestToHMI(_, _, _, _, _)) .WillOnce(Return(bc_activate_app_request)); EXPECT_CALL(*simple_app_ptr_, SetRegularState(_, _)).Times(0); -- cgit v1.2.1