diff options
author | Veronica Veremjova <vveremjova@luxoft.com> | 2016-12-30 16:19:18 +0200 |
---|---|---|
committer | Veronica Veremjova <vveremjova@luxoft.com> | 2016-12-30 16:19:18 +0200 |
commit | 49ecee220a3d22e08af4f84432a3a954af625c43 (patch) | |
tree | e1d9eb55ec53d2a7c70e0899b13cc5e3dfbd36d4 /src/components/application_manager | |
parent | e111b1e5f88baa3ece694fc2856f54ddd42068ec (diff) | |
download | sdl_core-49ecee220a3d22e08af4f84432a3a954af625c43.tar.gz |
Fix Activation after DEACTIVATE_HMI
According APPLINK-16172 SDL.ActivateApp should be rejected after DEACTIVATE_HMI
Added error response for HMI
Related to APPLINK-21868
Diffstat (limited to 'src/components/application_manager')
3 files changed, 63 insertions, 29 deletions
diff --git a/src/components/application_manager/include/application_manager/commands/hmi/request_from_hmi.h b/src/components/application_manager/include/application_manager/commands/hmi/request_from_hmi.h index 0f3b8bf1e4..ee500f047b 100644 --- a/src/components/application_manager/include/application_manager/commands/hmi/request_from_hmi.h +++ b/src/components/application_manager/include/application_manager/commands/hmi/request_from_hmi.h @@ -63,9 +63,28 @@ class RequestFromHMI : public CommandImpl, public event_engine::EventObserver { const hmi_apis::FunctionID::eType function_id, const hmi_apis::Common_Result::eType result_code); - void FillCommonParametersOfSO(smart_objects::SmartObject* message, - uint32_t correlation_id, - hmi_apis::FunctionID::eType function_id); + /** + * @brief SendResponse allows to send error response to hmi + * @param correlation_id the correlation id for the response. + * @param function_id the function id for which response will be sent + * @param result_code the result code. + */ + void SendErrorResponse(const uint32_t correlation_id, + const hmi_apis::FunctionID::eType function_id, + const hmi_apis::Common_Result::eType result_code, + std::string error_message); + + private: + /** + * @brief Fills common parameters for SO + * @param Contains SO for filling + * @param correlation_id the correlation id for the response. + * @param function_id the function id for which response will be sent + */ + void FillCommonParametersOfSO( + NsSmartDeviceLink::NsSmartObjects::SmartObjectSPtr& message, + uint32_t correlation_id, + hmi_apis::FunctionID::eType function_id); private: DISALLOW_COPY_AND_ASSIGN(RequestFromHMI); diff --git a/src/components/application_manager/src/commands/hmi/request_from_hmi.cc b/src/components/application_manager/src/commands/hmi/request_from_hmi.cc index be3cd6314c..18268a00e8 100644 --- a/src/components/application_manager/src/commands/hmi/request_from_hmi.cc +++ b/src/components/application_manager/src/commands/hmi/request_from_hmi.cc @@ -60,13 +60,13 @@ void RequestFromHMI::Run() {} void RequestFromHMI::on_event(const event_engine::Event& event) {} -void RequestFromHMI::SendResponse( - const bool success, - const uint32_t correlation_id, - const hmi_apis::FunctionID::eType function_id, - const hmi_apis::Common_Result::eType result_code) { - smart_objects::SmartObject* message = - new smart_objects::SmartObject(smart_objects::SmartType_Map); +void RequestFromHMI::SendResponse(bool success, + uint32_t correlation_id, + hmi_apis::FunctionID::eType function_id, + hmi_apis::Common_Result::eType result_code) { + smart_objects::SmartObjectSPtr message = + ::utils::MakeShared<smart_objects::SmartObject>( + smart_objects::SmartType_Map); FillCommonParametersOfSO(message, correlation_id, function_id); (*message)[strings::params][strings::message_type] = MessageType::kResponse; (*message)[strings::params][hmi_response::code] = 0; @@ -76,24 +76,26 @@ void RequestFromHMI::SendResponse( application_manager_.ManageHMICommand(message); } -// void RequestFromHMI::SendErrorResponse(uint32_t correlation_id, -// hmi_apis::FunctionID::eType -// function_id, -// hmi_apis::Common_Result::eType -// result_code) { -// smart_objects::SmartObject* message = new smart_objects::SmartObject( -// smart_objects::SmartType_Map); -// FillCommonParametersOfSO(message, correlation_id, function_id); -// (*message)[strings::params][strings::message_type] = -// MessageType::kErrorResponse; -// (*message)[strings::params][hmi_response::code] = result_code; -// (*message)[strings::params][strings::error_msg] = "HMIDeactivate is active"; - -// application_manager_.ManageHMICommand(message); -//} +void RequestFromHMI::SendErrorResponse( + uint32_t correlation_id, + hmi_apis::FunctionID::eType function_id, + hmi_apis::Common_Result::eType result_code, + std::string error_message) { + smart_objects::SmartObjectSPtr message = + ::utils::MakeShared<smart_objects::SmartObject>( + smart_objects::SmartType_Map); + FillCommonParametersOfSO(message, correlation_id, function_id); + (*message)[strings::params][strings::message_type] = + MessageType::kErrorResponse; + (*message)[strings::params][hmi_response::code] = result_code; + + (*message)[strings::params][strings::error_msg] = error_message; + + application_manager_.ManageHMICommand(message); +} void RequestFromHMI::FillCommonParametersOfSO( - smart_objects::SmartObject* message, + smart_objects::SmartObjectSPtr& message, uint32_t correlation_id, hmi_apis::FunctionID::eType function_id) { (*message)[strings::params][strings::function_id] = function_id; diff --git a/src/components/application_manager/src/commands/hmi/sdl_activate_app_request.cc b/src/components/application_manager/src/commands/hmi/sdl_activate_app_request.cc index 30ea41e0b0..4a501b5449 100644 --- a/src/components/application_manager/src/commands/hmi/sdl_activate_app_request.cc +++ b/src/components/application_manager/src/commands/hmi/sdl_activate_app_request.cc @@ -118,6 +118,18 @@ void SDLActivateAppRequest::Run() { "Found application to activate. Application id is " << app_to_activate->app_id()); + if (application_manager_.state_controller().IsStateActive( + HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) { + LOG4CXX_WARN(logger_, + "DeactivateHmi state is active. " + "Sends response with result code REJECTED"); + SendErrorResponse(correlation_id(), + static_cast<hmi_apis::FunctionID::eType>(function_id()), + hmi_apis::Common_Result::REJECTED, + "HMIDeactivate is active"); + return; + } + if (app_to_activate->IsRegistered()) { LOG4CXX_DEBUG(logger_, "Application is registered. Activating."); application_manager_.GetPolicyHandler().OnActivateApp(application_id, @@ -134,7 +146,8 @@ void SDLActivateAppRequest::Run() { "Can't find regular foreground app with the same " "connection id:" << device_handle); - SendResponse(false, correlation_id(), SDL_ActivateApp, NO_APPS_REGISTERED); + SendErrorResponse( + correlation_id(), SDL_ActivateApp, NO_APPS_REGISTERED, ""); return; } @@ -165,8 +178,8 @@ void SDLActivateAppRequest::onTimeOut() { using namespace hmi_apis::Common_Result; using namespace application_manager; unsubscribe_from_event(BasicCommunication_OnAppRegistered); - SendResponse( - false, correlation_id(), SDL_ActivateApp, APPLICATION_NOT_REGISTERED); + SendErrorResponse( + correlation_id(), SDL_ActivateApp, APPLICATION_NOT_REGISTERED, ""); } void SDLActivateAppRequest::on_event(const event_engine::Event& event) { |