From 8c09bf68d99848c81166a5989349d48630731746 Mon Sep 17 00:00:00 2001 From: igapchuck Date: Fri, 16 Nov 2018 17:42:34 +0200 Subject: [PATCH] Feature/CloseApplication RPC. This PR provides a new RPC called CloseApplication, which can be used by an app to send itself into HMI_NONE. A registered application sends CloseApplicationRequest to SDL. SDL will checks if specified application is registered and it is not in HMI level NONE. After that, SDL will sends ActivateAppRequest to HMI with HMI level parameter as NONE. When SDL will received ActivateAppResponse from HMI, if result code will be as SUCCESS or WARNING, SDL will sets application(which has sent this request) HMI level NONE and sends OnHMIStatusNotification to Mobile with HMI level NONE. After that SDL will sends CloseApplicationResponse to Mobile. --- src/appMain/sdl_preloaded_pt.json | 6 + .../mobile/close_application_request.h | 102 ++++++++++++ .../mobile/close_application_response.h | 79 +++++++++ .../mobile/close_application_request.cc | 155 ++++++++++++++++++ .../mobile/close_application_response.cc | 61 +++++++ .../src/mobile_command_factory.cc | 8 + src/components/interfaces/MOBILE_API.xml | 22 +++ 7 files changed, 433 insertions(+) create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/close_application_request.h create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/close_application_response.h create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/close_application_request.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/close_application_response.cc diff --git a/src/appMain/sdl_preloaded_pt.json b/src/appMain/sdl_preloaded_pt.json index d503ae34e53..77104ae56e0 100644 --- a/src/appMain/sdl_preloaded_pt.json +++ b/src/appMain/sdl_preloaded_pt.json @@ -58,6 +58,12 @@ "LIMITED", "NONE"] }, + "CloseApplication": { + "hmi_levels": ["BACKGROUND", + "FULL", + "LIMITED", + "NONE"] + }, "CreateInteractionChoiceSet": { "hmi_levels": ["BACKGROUND", "FULL", diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/close_application_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/close_application_request.h new file mode 100644 index 00000000000..60bd8f56842 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/close_application_request.h @@ -0,0 +1,102 @@ +/* + + Copyright (c) 2018, Ford Motor Company + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following + disclaimer in the documentation and/or other materials provided with the + distribution. + + Neither the name of the Ford Motor Company nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_CLOSE_APPLICATION_REQUEST_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_CLOSE_APPLICATION_REQUEST_H_ + +#include + +#include "application_manager/commands/command_request_impl.h" +#include "application_manager/event_engine/event_observer.h" +#include "utils/macro.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +/** + * @brief CloseApplicationRequest command class + */ +class CloseApplicationRequest : public app_mngr::commands::CommandRequestImpl { + public: + /** + * @brief CloseApplicationRequest class constructor + * + * @param message Incoming SmartObject message + */ + CloseApplicationRequest(const app_mngr::commands::MessageSharedPtr& message, + app_mngr::ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler); + /** + * @brief CloseApplicationRequest class destructor + */ + ~CloseApplicationRequest() FINAL; + + /** + * @brief Execute command + */ + void Run() FINAL; + + /** + * @brief Interface method that is called whenever new event received + * + * @param event The received event + */ + void on_event(const app_mngr::event_engine::Event& event) FINAL; + + private: + DISALLOW_COPY_AND_ASSIGN(CloseApplicationRequest); + + /** + * @brief Send Basic Communication Request to HMI. + * + * @param app - Application which have to set specified HMI level. + * @param hmi_level - New HMI level for specified application. + * @param send_policy_priority - Defines whether to send "priority" field + * with request + * @param activate_app_corr_id - Variable for detting ActivateAppRequest + * correlation id. + * @return - True if command is executed, otherwise return false. + */ + bool SendBCActivateApp(app_mngr::ApplicationConstSharedPtr app, + const hmi_apis::Common_HMILevel::eType hmi_level, + const bool send_policy_priority); +}; + +} // namespace commands +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_CLOSE_APPLICATION_REQUEST_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/close_application_response.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/close_application_response.h new file mode 100644 index 00000000000..0c4540efaab --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/close_application_response.h @@ -0,0 +1,79 @@ +/* + + Copyright (c) 2018, Ford Motor Company + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following + disclaimer in the documentation and/or other materials provided with the + distribution. + + Neither the name of the Ford Motor Company nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_CLOSE_APPLICATION_RESPONSE_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_CLOSE_APPLICATION_RESPONSE_H_ + +#include "application_manager/commands/command_response_impl.h" +#include "utils/macro.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +/** + * @brief CloseApplicationResponse command class + **/ +class CloseApplicationResponse + : public app_mngr::commands::CommandResponseImpl { + public: + /** + * @brief CloseApplicationResponse class constructor + * + * @param message - Incoming SmartObject message + **/ + CloseApplicationResponse(const app_mngr::commands::MessageSharedPtr& message, + app_mngr::ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler); + + /** + * @brief CloseApplicationResponse class destructor + **/ + ~CloseApplicationResponse() FINAL; + + /** + * @brief Execute command + **/ + void Run() FINAL; + + private: + DISALLOW_COPY_AND_ASSIGN(CloseApplicationResponse); +}; + +} // namespace commands +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_CLOSE_APPLICATION_RESPONSE_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/close_application_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/close_application_request.cc new file mode 100644 index 00000000000..77c3e88fd5a --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/close_application_request.cc @@ -0,0 +1,155 @@ +/* + + Copyright (c) 2018, Ford Motor Company + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following + disclaimer in the documentation and/or other materials provided with the + distribution. + + Neither the name of the Ford Motor Company nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + */ + +#include "sdl_rpc_plugin/commands/mobile/close_application_request.h" +#include "application_manager/rpc_service.h" +#include "application_manager/message_helper.h" +#include "utils/include/utils/helpers.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; + +namespace commands { + +CloseApplicationRequest::CloseApplicationRequest( + const app_mngr::commands::MessageSharedPtr& message, + app_mngr::ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : CommandRequestImpl(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +CloseApplicationRequest::~CloseApplicationRequest() {} + +void CloseApplicationRequest::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + auto application = application_manager_.application(connection_key()); + + if (!application) { + LOG4CXX_ERROR(logger_, "No such application registered."); + SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED); + return; + } + + const auto app_hmi_level = application->hmi_level(); + + if (mobile_apis::HMILevel::HMI_NONE == app_hmi_level) { + LOG4CXX_DEBUG(logger_, + "Application with id " << connection_key() + << " is already in hmi_level NONE."); + SendResponse(false, mobile_apis::Result::IGNORED); + return; + } + + const bool sent_success = + SendBCActivateApp(application, hmi_apis::Common_HMILevel::NONE, true); + + if (!sent_success) { + LOG4CXX_ERROR(logger_, "Unable to send BC.ActivateApp"); + SendResponse(false, mobile_apis::Result::INVALID_DATA); + } +} + +void CloseApplicationRequest::on_event(const event_engine::Event& event) { + using namespace helpers; + LOG4CXX_AUTO_TRACE(logger_); + const auto message = event.smart_object(); + + if (hmi_apis::FunctionID::BasicCommunication_ActivateApp != event.id()) { + LOG4CXX_ERROR(logger_, "Received unknown event" << event.id()); + return; + } + + const auto hmi_result = static_cast( + message[strings::params][hmi_response::code].asInt()); + + const auto mobile_result = MessageHelper::HMIToMobileResult(hmi_result); + const bool success = Compare( + hmi_result, + hmi_apis::Common_Result::SUCCESS, + hmi_apis::Common_Result::WARNINGS); + + if (success) { + auto application = application_manager_.application(connection_key()); + if (!application) { + LOG4CXX_DEBUG(logger_, "No such application registered"); + SendResponse(false, mobile_apis::Result::INVALID_DATA); + return; + } + application->set_hmi_level(mobile_apis::HMILevel::HMI_NONE); + LOG4CXX_DEBUG(logger_, + "Application with id " << application->app_id() + << " has switched to HMI_level NONE."); + } else { + LOG4CXX_WARN(logger_, "Application hasn't switched to HMI_level NONE."); + } + SendResponse(success, mobile_result); +} + +bool CloseApplicationRequest::SendBCActivateApp( + ApplicationConstSharedPtr app, + const hmi_apis::Common_HMILevel::eType hmi_level, + const bool send_policy_priority) { + LOG4CXX_AUTO_TRACE(logger_); + auto bc_activate_app_request = MessageHelper::GetBCActivateAppRequestToHMI( + app, + application_manager_.connection_handler().get_session_observer(), + application_manager_.GetPolicyHandler(), + hmi_level, + send_policy_priority, + application_manager_); + if (!bc_activate_app_request) { + LOG4CXX_ERROR(logger_, "Unable to create BC.ActivateAppRequest"); + return false; + } + + if (!application_manager_.GetRPCService().ManageHMICommand( + bc_activate_app_request)) { + LOG4CXX_ERROR(logger_, "Unable to send BC.ActivateAppRequest"); + return false; + } + const auto activate_app_corr_id = + (*bc_activate_app_request)[strings::params][strings::correlation_id] + .asUInt(); + subscribe_on_event(hmi_apis::FunctionID::BasicCommunication_ActivateApp, + activate_app_corr_id); + return true; +} + +} // namespace commands +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/close_application_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/close_application_response.cc new file mode 100644 index 00000000000..7138edd416b --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/close_application_response.cc @@ -0,0 +1,61 @@ +/* + Copyright (c) 2018, Ford Motor Company + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following + disclaimer in the documentation and/or other materials provided with the + distribution. + + Neither the name of the Ford Motor Company nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + */ + +#include "sdl_rpc_plugin/commands/mobile/close_application_response.h" +#include "application_manager/commands/command_response_impl.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; +namespace commands { + +CloseApplicationResponse::CloseApplicationResponse( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + rpc_service::RPCService& rpc_service, + HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : CommandResponseImpl(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +CloseApplicationResponse::~CloseApplicationResponse() {} + +void CloseApplicationResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + rpc_service_.SendMessageToMobile(message_); +} + +} // commands +} // sdl_rpc_plugins diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/mobile_command_factory.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/mobile_command_factory.cc index 5207c7e4328..03a2dce003a 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/mobile_command_factory.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/mobile_command_factory.cc @@ -124,6 +124,8 @@ #include "sdl_rpc_plugin/commands/mobile/dial_number_response.h" #include "sdl_rpc_plugin/commands/mobile/send_haptic_data_request.h" #include "sdl_rpc_plugin/commands/mobile/send_haptic_data_response.h" +#include "sdl_rpc_plugin/commands/mobile/close_application_request.h" +#include "sdl_rpc_plugin/commands/mobile/close_application_response.h" #include "interfaces/MOBILE_API.h" CREATE_LOGGERPTR_GLOBAL(logger_, "ApplicationManager") @@ -396,6 +398,12 @@ CommandCreator& MobileCommandFactory::get_creator_factory( using app_mngr::commands::Command; return factory.GetCreator(); } + case mobile_apis::FunctionID::CloseApplicationID: { + using app_mngr::commands::Command; + return Command::CommandSource::SOURCE_MOBILE == source + ? factory.GetCreator() + : factory.GetCreator(); + } break; default: { return factory.GetCreator(); } } } diff --git a/src/components/interfaces/MOBILE_API.xml b/src/components/interfaces/MOBILE_API.xml index 76fc6ef2d1e..30b658fea02 100644 --- a/src/components/interfaces/MOBILE_API.xml +++ b/src/components/interfaces/MOBILE_API.xml @@ -2608,6 +2608,7 @@ +