From c564de8e07c5ff9a2d4139691ff734a01321513d Mon Sep 17 00:00:00 2001 From: JackLivio Date: Thu, 15 Jul 2021 14:17:48 -0400 Subject: [PATCH 01/14] Coverity Github Actions CI (#3737) * Add Coverity CI * Fix syntax * test * test * Add enviroment * Add env * Upload coverity result * Apply only for master branch prs --- .../workflows/sdl_core_github_ci_coverity.yml | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 .github/workflows/sdl_core_github_ci_coverity.yml diff --git a/.github/workflows/sdl_core_github_ci_coverity.yml b/.github/workflows/sdl_core_github_ci_coverity.yml new file mode 100644 index 00000000000..c60482d30f9 --- /dev/null +++ b/.github/workflows/sdl_core_github_ci_coverity.yml @@ -0,0 +1,63 @@ +name: SDL Core Build With Coverity +on: + push: + branches: + - master + pull_request: + branches: + - master +jobs: + build: + environment: Coverity + runs-on: ubuntu-20.04 + steps: + - shell: bash + env: + COVERITY_SECRET: ${{ secrets.COVERITY_TOKEN }} + run: | + echo "$COVERITY_SECRET" && echo ${{ secrets.COVERITY_TOKEN }} && echo "end" + - uses: actions/checkout@v2 + - name: Init Submodules + run: git -C ${{ github.workspace }} submodule update --init --recursive + # Install Dependencies + - name: Apt Get Dependencies + run: sudo apt-get update && sudo apt-get install libssl-dev libbluetooth3 libbluetooth-dev libudev-dev cmake html2text lcov git cmake automake1.11 build-essential libavahi-client-dev sqlite3 libsqlite3-dev libgtest-dev bluez-tools libpulse-dev libusb-1.0.0-dev cppcheck python3-pip python3-setuptools && sudo apt-get install -f clang-format-6.0 + - name: Setup CMAKE + uses: jwlawson/actions-setup-cmake@v1.8 + with: + cmake-version: '3.16.3' + # Build Project + - name: Cache 3rd Party + id: core-3rd-party + uses: actions/cache@v2 + with: + path: ${{ github.workspace }}/core_3rd_party + key: ${{ runner.os }}-core-3rd-party-v3 + - name: Make 3rd Party Directory + if: steps.core-3rd-party.outputs.cache-hit != 'true' + run: mkdir ${{ github.workspace }}/core_3rd_party + - name: Make Directories + run: cd ${{ github.workspace }} && cd ../ && mkdir build && cd build + - name: Set 3rd Party Path + run: echo "THIRD_PARTY_INSTALL_PREFIX=${{ github.workspace }}/core_3rd_party" >> $GITHUB_ENV + - name: Set 3rd Party ARCH Path + run: echo "THIRD_PARTY_INSTALL_PREFIX_ARCH=${{ github.workspace }}/core_3rd_party" >> $GITHUB_ENV + - name: Configure + run: cmake ../sdl_core -DLOGGER_NAME=BOOST + - name: Download Coverity + env: + COVERITY_SECRET: ${{ secrets.COVERITY_TOKEN }} + run: wget https://scan.coverity.com/download/linux64 --post-data "token=${COVERITY_SECRET}&project=smartdevicelink%2Fsdl_core" -O coverity_tool.tgz + - name: unzip + run: tar zxvf coverity_tool.tgz + - name: Build + run: make install-3rd_party && ./cov-analysis-linux64-2020.09/bin/cov-build --dir cov-int make -j `nproc` install + - name: Set Library Path + run: echo "LD_LIBRARY_PATH=$THIRD_PARTY_INSTALL_PREFIX/lib:." >> $GITHUB_ENV + - name: Compress Coverity + run: tar czvf myproject.tgz cov-int + - name: Upload Coverity + env: + COVERITY_SECRET: ${{ secrets.COVERITY_TOKEN }} + run: curl --form token=${COVERITY_SECRET} --form email=jack@livio.io --form file=@myproject.tgz --form version="Version" --form description="Description" https://scan.coverity.com/builds?project=smartdevicelink%2Fsdl_core + From 716cfac5e19673daf6a77e3eb17472fd74201019 Mon Sep 17 00:00:00 2001 From: JackLivio Date: Thu, 15 Jul 2021 14:18:27 -0400 Subject: [PATCH 02/14] Remove Deprecated Methods For SDL Core 8.0.0 (#3735) * Remove deprecated methods * Style * Fix external policy build --- .../app_launch/app_launch_data_json.h | 8 -- .../application_manager/app_service_manager.h | 3 - .../include/application_manager/application.h | 6 -- .../application_manager_impl.h | 13 --- .../hmi_capabilities_impl.h | 3 - .../hmi_language_handler.h | 3 - .../plugin_manager/rpc_plugin.h | 7 -- .../plugin_manager/rpc_plugin_manager_impl.h | 7 -- .../policies/policy_handler.h | 2 - .../resumption/resume_ctrl.h | 3 - .../resumption/resume_ctrl_impl.h | 2 - .../resumption/resumption_data_json.h | 8 -- .../app_service_rpc_plugin.h | 7 -- .../src/app_service_rpc_plugin.cc | 12 --- .../rc_rpc_plugin/rc_consent_manager_impl.h | 6 -- .../include/rc_rpc_plugin/rc_rpc_plugin.h | 6 -- .../rc_rpc_plugin/src/rc_rpc_plugin.cc | 8 -- .../include/sdl_rpc_plugin/sdl_rpc_plugin.h | 7 -- .../sdl_rpc_plugin/src/sdl_rpc_plugin.cc | 12 --- .../vehicle_info_plugin/vehicle_info_plugin.h | 7 -- .../src/vehicle_info_plugin.cc | 19 ---- .../src/application_manager_impl.cc | 101 ------------------ .../src/hmi_capabilities_impl.cc | 2 - .../src/policies/policy_handler.cc | 6 -- .../src/resumption/resume_ctrl_impl.cc | 4 - .../src/resumption/resumption_data_json.cc | 4 - .../mock_hmi_capabilities.h | 3 - .../application_manager/mock_resume_ctrl.h | 3 +- .../application_manager/application_manager.h | 15 --- .../application_manager/hmi_capabilities.h | 3 - .../policies/policy_handler_interface.h | 4 +- .../include/media_manager/media_manager.h | 7 -- .../policy_external/policy/policy_manager.h | 9 -- .../protocol_handler/protocol_handler.h | 16 --- .../include/resumption/last_state.h | 12 --- .../mock_application_manager.h | 15 --- .../application_manager/mock_rpc_plugin.h | 7 -- .../policies/mock_policy_handler_interface.h | 3 - .../test/media_manager/mock_media_manager.h | 6 -- .../include/test/resumption/mock_last_state.h | 4 - .../mock_transport_manager.h | 2 - .../transport_manager/transport_manager.h | 3 - .../audio/from_mic_recorder_adapter.h | 1 - .../media_manager/media_manager_impl.h | 7 -- .../media_manager/src/media_manager_impl.cc | 33 ------ .../include/policy/policy_manager_impl.h | 8 -- .../src/policy_manager_impl.cc | 12 --- .../protocol_handler/protocol_handler_impl.h | 5 - .../src/protocol_handler_impl.cc | 8 -- .../include/resumption/last_state_impl.h | 9 -- .../resumption/src/last_state_impl.cc | 27 ----- .../bluetooth/bluetooth_transport_adapter.h | 4 - .../iap2_emulation/iap2_transport_adapter.h | 11 -- .../tcp/tcp_transport_adapter.h | 5 - .../transport_adapter_impl.h | 11 -- .../transport_manager_default.h | 3 - .../transport_manager_impl.h | 3 - .../transport_manager/usb/usb_aoa_adapter.h | 4 - .../src/transport_manager_default.cc | 4 - .../src/transport_manager_impl.cc | 9 -- .../websocket_server_transport_adapter.cc | 7 +- .../transport_manager/raw_message_matcher.h | 4 - .../mock_transport_adapter_impl.h | 7 -- .../test/transport_manager_default_test.cc | 2 - .../utils/include/utils/file_system.h | 3 - src/components/utils/src/file_system.cc | 19 ---- 66 files changed, 7 insertions(+), 577 deletions(-) diff --git a/src/components/application_manager/include/application_manager/app_launch/app_launch_data_json.h b/src/components/application_manager/include/application_manager/app_launch/app_launch_data_json.h index 9e60183960c..dba2579f8f2 100644 --- a/src/components/application_manager/include/application_manager/app_launch/app_launch_data_json.h +++ b/src/components/application_manager/include/application_manager/app_launch/app_launch_data_json.h @@ -54,10 +54,6 @@ class AppLaunchDataJson : public AppLaunchDataImpl { AppLaunchDataJson(const AppLaunchSettings& settings, resumption::LastStateWrapperPtr last_state_wrapper); - DEPRECATED - AppLaunchDataJson(const AppLaunchSettings& settings, - resumption::LastState& last_state); - /** * @brief allows to destroy AppLaunchDataJson object */ @@ -99,10 +95,6 @@ class AppLaunchDataJson : public AppLaunchDataImpl { int32_t& found_index, Json::Value& dictionary) const; - DEPRECATED - Json::Value& GetApplicationListAndIndex(const ApplicationData& app_data, - int32_t& founded_index) const; - private: /** * @brief update time stamp diff --git a/src/components/application_manager/include/application_manager/app_service_manager.h b/src/components/application_manager/include/application_manager/app_service_manager.h index 94606909c60..e3a5f646028 100644 --- a/src/components/application_manager/include/application_manager/app_service_manager.h +++ b/src/components/application_manager/include/application_manager/app_service_manager.h @@ -65,9 +65,6 @@ class AppServiceManager { AppServiceManager(ApplicationManager& app_manager, resumption::LastStateWrapperPtr last_state); - DEPRECATED AppServiceManager(ApplicationManager& app_manager, - resumption::LastState& last_state); - /** * @brief Class destructor */ diff --git a/src/components/application_manager/include/application_manager/application.h b/src/components/application_manager/include/application_manager/application.h index bc966cd00cf..f25afeb2bc9 100644 --- a/src/components/application_manager/include/application_manager/application.h +++ b/src/components/application_manager/include/application_manager/application.h @@ -371,12 +371,6 @@ class DynamicApplicationData { */ virtual smart_objects::SmartObject FindSubMenu(uint32_t menu_id) const = 0; - /* - * @brief Returns true if sub menu with such name already exist - */ - DEPRECATED virtual bool IsSubMenuNameAlreadyExist( - const std::string& name, const uint32_t parent_id) = 0; - /* * @brief Adds a interaction choice set to the application * diff --git a/src/components/application_manager/include/application_manager/application_manager_impl.h b/src/components/application_manager/include/application_manager/application_manager_impl.h index 9191a06c6bc..a8a41bc23a6 100644 --- a/src/components/application_manager/include/application_manager/application_manager_impl.h +++ b/src/components/application_manager/include/application_manager/application_manager_impl.h @@ -159,10 +159,6 @@ class ApplicationManagerImpl const policy::PolicySettings& policy_settings); ~ApplicationManagerImpl(); - DEPRECATED - bool Init(resumption::LastState&, - media_manager::MediaManager* media_manager) OVERRIDE; - /** * Inits application manager */ @@ -189,8 +185,6 @@ class ApplicationManagerImpl uint32_t hmi_app_id) const OVERRIDE; ApplicationSharedPtr application_by_policy_id( const std::string& policy_app_id) const OVERRIDE; - DEPRECATED ApplicationSharedPtr - application_by_name(const std::string& app_name) const OVERRIDE; ApplicationSharedPtr pending_application_by_policy_id( const std::string& policy_app_id) const OVERRIDE; ApplicationSharedPtr reregister_application_by_policy_id( @@ -858,9 +852,6 @@ class ApplicationManagerImpl */ void EndNaviServices(uint32_t app_id) OVERRIDE; - DEPRECATED - void ForbidStreaming(uint32_t app_id) OVERRIDE; - void ForbidStreaming(uint32_t app_id, protocol_handler::ServiceType service_type) OVERRIDE; @@ -875,10 +866,6 @@ class ApplicationManagerImpl protocol_handler::ServiceType service_type, bool state) OVERRIDE; - void OnAppStreaming(uint32_t app_id, - protocol_handler::ServiceType service_type, - const Application::StreamingState new_state) OVERRIDE; - mobile_api::HMILevel::eType GetDefaultHmiLevel( ApplicationConstSharedPtr application) const; diff --git a/src/components/application_manager/include/application_manager/hmi_capabilities_impl.h b/src/components/application_manager/include/application_manager/hmi_capabilities_impl.h index f646c66ca15..9a22b2a4aaa 100644 --- a/src/components/application_manager/include/application_manager/hmi_capabilities_impl.h +++ b/src/components/application_manager/include/application_manager/hmi_capabilities_impl.h @@ -257,9 +257,6 @@ class HMICapabilitiesImpl : public HMICapabilities { void Init(resumption::LastStateWrapperPtr last_state_wrapper) OVERRIDE; - DEPRECATED - void Init(resumption::LastState* last_state) OVERRIDE; - HMILanguageHandler& get_hmi_language_handler() OVERRIDE; void set_handle_response_for( diff --git a/src/components/application_manager/include/application_manager/hmi_language_handler.h b/src/components/application_manager/include/application_manager/hmi_language_handler.h index 2ef034450df..5db5a844da7 100644 --- a/src/components/application_manager/include/application_manager/hmi_language_handler.h +++ b/src/components/application_manager/include/application_manager/hmi_language_handler.h @@ -96,9 +96,6 @@ class HMILanguageHandler : public event_engine::EventObserver { hmi_apis::Common_Language::eType vr, hmi_apis::Common_Language::eType tts); - DEPRECATED - void Init(resumption::LastState*); - void Init(resumption::LastStateWrapperPtr value); /** diff --git a/src/components/application_manager/include/application_manager/plugin_manager/rpc_plugin.h b/src/components/application_manager/include/application_manager/plugin_manager/rpc_plugin.h index 88f91d14fc0..0c7538e8093 100644 --- a/src/components/application_manager/include/application_manager/plugin_manager/rpc_plugin.h +++ b/src/components/application_manager/include/application_manager/plugin_manager/rpc_plugin.h @@ -86,13 +86,6 @@ class RPCPlugin { policy::PolicyHandlerInterface& policy_handler, resumption::LastStateWrapperPtr last_state) = 0; - DEPRECATED - virtual bool Init(ApplicationManager& app_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler, - resumption::LastState& last_state) = 0; - /** * @brief IsAbleToProcess check if plugin is able to process function * @param function_id RPC identifier diff --git a/src/components/application_manager/include/application_manager/plugin_manager/rpc_plugin_manager_impl.h b/src/components/application_manager/include/application_manager/plugin_manager/rpc_plugin_manager_impl.h index 004d6418f5e..a447034d866 100644 --- a/src/components/application_manager/include/application_manager/plugin_manager/rpc_plugin_manager_impl.h +++ b/src/components/application_manager/include/application_manager/plugin_manager/rpc_plugin_manager_impl.h @@ -59,13 +59,6 @@ class RPCPluginManagerImpl : public RPCPluginManager { policy::PolicyHandlerInterface& policy_handler, resumption::LastStateWrapperPtr last_state); - DEPRECATED - RPCPluginManagerImpl(ApplicationManager& app_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler, - resumption::LastState& last_state); - uint32_t LoadPlugins(const std::string& plugins_path) OVERRIDE; utils::Optional FindPluginToProcess( diff --git a/src/components/application_manager/include/application_manager/policies/policy_handler.h b/src/components/application_manager/include/application_manager/policies/policy_handler.h index acf4ca7819a..662e2558718 100644 --- a/src/components/application_manager/include/application_manager/policies/policy_handler.h +++ b/src/components/application_manager/include/application_manager/policies/policy_handler.h @@ -86,8 +86,6 @@ class PolicyHandler : public PolicyHandlerInterface, bool InitPolicyTable() OVERRIDE; bool ResetPolicyTable() OVERRIDE; bool ClearUserConsent() OVERRIDE; - DEPRECATED bool SendMessageToSDK(const BinaryMessage& pt_string, - const std::string& url) OVERRIDE; bool ReceiveMessageFromSDK(const std::string& file, const BinaryMessage& pt_string) OVERRIDE; bool UnloadPolicyLibrary() OVERRIDE; diff --git a/src/components/application_manager/include/application_manager/resumption/resume_ctrl.h b/src/components/application_manager/include/application_manager/resumption/resume_ctrl.h index 456eccd29c9..4cc42699bc6 100644 --- a/src/components/application_manager/include/application_manager/resumption/resume_ctrl.h +++ b/src/components/application_manager/include/application_manager/resumption/resume_ctrl.h @@ -276,9 +276,6 @@ class ResumeCtrl { */ virtual void RemoveFromResumption(uint32_t app_id) = 0; - DEPRECATED - virtual bool Init(resumption::LastState& last_state) = 0; - /** * @brief Initialization data for Resume controller * @return true if initialization is success otherwise diff --git a/src/components/application_manager/include/application_manager/resumption/resume_ctrl_impl.h b/src/components/application_manager/include/application_manager/resumption/resume_ctrl_impl.h index 9c529b5f9a9..b93b914a489 100644 --- a/src/components/application_manager/include/application_manager/resumption/resume_ctrl_impl.h +++ b/src/components/application_manager/include/application_manager/resumption/resume_ctrl_impl.h @@ -256,8 +256,6 @@ class ResumeCtrlImpl : public ResumeCtrl { */ void RemoveFromResumption(uint32_t app_id) OVERRIDE; - DEPRECATED bool Init(resumption::LastState& last_state) FINAL; - /** * @brief Initialization data for Resume controller * @return true if initialization is success otherwise diff --git a/src/components/application_manager/include/application_manager/resumption/resumption_data_json.h b/src/components/application_manager/include/application_manager/resumption/resumption_data_json.h index 2394fe00dcb..f33ef83a9b5 100644 --- a/src/components/application_manager/include/application_manager/resumption/resumption_data_json.h +++ b/src/components/application_manager/include/application_manager/resumption/resumption_data_json.h @@ -52,11 +52,6 @@ class ResumptionDataJson : public ResumptionData { resumption::LastStateWrapperPtr last_state_wrapper, const application_manager::ApplicationManager& application_manager); - DEPRECATED - ResumptionDataJson( - LastState&, - const application_manager::ApplicationManager& application_manager); - /** * @brief allows to destroy ResumptionDataJson object */ @@ -180,9 +175,6 @@ class ResumptionDataJson : public ResumptionData { */ void Persist() OVERRIDE; - DEPRECATED - resumption::LastState& last_state() const; - private: /** * @brief GetFromSavedOrAppend allows to get existed record about application diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/include/app_service_rpc_plugin/app_service_rpc_plugin.h b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/include/app_service_rpc_plugin/app_service_rpc_plugin.h index 444636ed75c..bae47385248 100644 --- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/include/app_service_rpc_plugin/app_service_rpc_plugin.h +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/include/app_service_rpc_plugin/app_service_rpc_plugin.h @@ -50,13 +50,6 @@ class AppServiceRpcPlugin : public plugins::RPCPlugin { policy::PolicyHandlerInterface& policy_handler, resumption::LastStateWrapperPtr last_state) OVERRIDE; - DEPRECATED - bool Init(app_mngr::ApplicationManager& application_manager, - app_mngr::rpc_service::RPCService& rpc_service, - app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler, - resumption::LastState& last_state); - bool IsAbleToProcess( const int32_t function_id, const app_mngr::commands::Command::CommandSource source) OVERRIDE; diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_rpc_plugin.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_rpc_plugin.cc index e03973614d8..0e805da46ca 100644 --- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_rpc_plugin.cc +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_rpc_plugin.cc @@ -58,18 +58,6 @@ bool AppServiceRpcPlugin::Init( return true; } -bool AppServiceRpcPlugin::Init(app_mngr::ApplicationManager& app_manager, - app_mngr::rpc_service::RPCService& rpc_service, - app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler, - resumption::LastState& last_state) { - UNUSED(last_state); - application_manager_ = &app_manager; - command_factory_.reset(new app_service_rpc_plugin::AppServiceCommandFactory( - app_manager, rpc_service, hmi_capabilities, policy_handler)); - return true; -} - bool AppServiceRpcPlugin::IsAbleToProcess( const int32_t function_id, const commands::Command::CommandSource source) { return command_factory_->IsAbleToProcess(function_id, source); diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_consent_manager_impl.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_consent_manager_impl.h index 5cbc4b977e8..fd8c40405e9 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_consent_manager_impl.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_consent_manager_impl.h @@ -50,12 +50,6 @@ class RCConsentManagerImpl : public RCConsentManager { application_manager::ApplicationManager& application_manager, const uint32_t period_of_consent_expired); - DEPRECATED - RCConsentManagerImpl( - resumption::LastState& last_state, - application_manager::ApplicationManager& application_manager, - const uint32_t period_of_consent_expired); - void SaveModuleConsents( const std::string& policy_app_id, const std::string& mac_address, diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_rpc_plugin.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_rpc_plugin.h index 528e116403f..c1f7339aa31 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_rpc_plugin.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_rpc_plugin.h @@ -65,12 +65,6 @@ class RCRPCPlugin : public plugins::RPCPlugin { policy::PolicyHandlerInterface& policy_handler, resumption::LastStateWrapperPtr last_state) OVERRIDE; - DEPRECATED - bool Init(app_mngr::ApplicationManager& app_manager, - app_mngr::rpc_service::RPCService& rpc_service, - app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler, - resumption::LastState& last_state) OVERRIDE; /** * @param int32_t command id * @param CommandSource source diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc index 87090405e73..8250437e788 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc @@ -86,14 +86,6 @@ bool RCRPCPlugin::Init( return true; } -bool RCRPCPlugin::Init(application_manager::ApplicationManager&, - application_manager::rpc_service::RPCService&, - application_manager::HMICapabilities&, - policy::PolicyHandlerInterface&, - resumption::LastState&) { - return false; -} - bool RCRPCPlugin::IsAbleToProcess( const int32_t function_id, const application_manager::commands::Command::CommandSource diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/sdl_rpc_plugin.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/sdl_rpc_plugin.h index b4ef7e6aedf..ab74ed08fb2 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/sdl_rpc_plugin.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/sdl_rpc_plugin.h @@ -54,13 +54,6 @@ class SDLRPCPlugin : public plugins::RPCPlugin { policy::PolicyHandlerInterface& policy_handler, resumption::LastStateWrapperPtr last_state) OVERRIDE; - DEPRECATED - bool Init(app_mngr::ApplicationManager& app_manager, - app_mngr::rpc_service::RPCService& rpc_service, - app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler, - resumption::LastState& last_state) OVERRIDE; - /** * @brief ProcessResumptionSubscription send appropriate subscribe requests * to HMI diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/sdl_rpc_plugin.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/sdl_rpc_plugin.cc index c5bc79f09da..7cdfc73ed07 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/sdl_rpc_plugin.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/sdl_rpc_plugin.cc @@ -61,18 +61,6 @@ bool SDLRPCPlugin::Init(app_mngr::ApplicationManager& app_manager, return true; } -bool SDLRPCPlugin::Init( - application_manager::ApplicationManager& app_manager, - application_manager::rpc_service::RPCService& rpc_service, - application_manager::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler, - resumption::LastState& last_state) { - UNUSED(last_state); - command_factory_.reset(new sdl_rpc_plugin::SDLCommandFactory( - app_manager, rpc_service, hmi_capabilities, policy_handler)); - return true; -} - bool SDLRPCPlugin::IsAbleToProcess( const int32_t function_id, const app_mngr::commands::Command::CommandSource message_source) { diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_plugin.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_plugin.h index 1910a9efdf0..8c67bc1d101 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_plugin.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_plugin.h @@ -55,13 +55,6 @@ class VehicleInfoPlugin : public plugins::RPCPlugin { policy::PolicyHandlerInterface& policy_handler, resumption::LastStateWrapperPtr last_state) OVERRIDE; - DEPRECATED - bool Init(app_mngr::ApplicationManager& application_manager, - app_mngr::rpc_service::RPCService& rpc_service, - app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler, - resumption::LastState& last_state) OVERRIDE; - bool IsAbleToProcess( const int32_t function_id, const app_mngr::commands::Command::CommandSource source) OVERRIDE; diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc index 1a357a86ee7..b20e52636c6 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc @@ -88,25 +88,6 @@ bool VehicleInfoPlugin::Init( return true; } -bool VehicleInfoPlugin::Init( - application_manager::ApplicationManager& application_manager, - application_manager::rpc_service::RPCService& rpc_service, - application_manager::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler, - resumption::LastState& last_state) { - UNUSED(last_state); - application_manager_ = &application_manager; - custom_vehicle_data_manager_.reset( - new CustomVehicleDataManagerImpl(policy_handler, rpc_service)); - command_factory_.reset(new vehicle_info_plugin::VehicleInfoCommandFactory( - application_manager, - rpc_service, - hmi_capabilities, - policy_handler, - *(custom_vehicle_data_manager_.get()))); - return true; -} - bool VehicleInfoPlugin::IsAbleToProcess( const int32_t function_id, const commands::Command::CommandSource source) { return command_factory_->IsAbleToProcess(function_id, source); diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index d2104dbf1a2..884b5df0eef 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -304,13 +304,6 @@ ApplicationSharedPtr ApplicationManagerImpl::pending_application_by_policy_id( return FindPendingApp(accessor, finder); } -ApplicationSharedPtr ApplicationManagerImpl::application_by_name( - const std::string& app_name) const { - AppNamePredicate finder(app_name); - DataAccessor accessor = applications(); - return FindApp(accessor, finder); -} - ApplicationSharedPtr ApplicationManagerImpl::reregister_application_by_policy_id( const std::string& policy_app_id) const { @@ -2502,11 +2495,6 @@ void ApplicationManagerImpl::RemoveHMIFakeParameters( (*message)[jhs::S_PARAMS][jhs::S_FUNCTION_ID] = mobile_function_id; } -bool ApplicationManagerImpl::Init(resumption::LastState&, - media_manager::MediaManager*) { - return false; -} - bool ApplicationManagerImpl::Init( resumption::LastStateWrapperPtr last_state_wrapper, media_manager::MediaManager* media_manager) { @@ -3515,53 +3503,6 @@ bool ApplicationManagerImpl::CanAppStream( return HMIStateAllowsStreaming(app_id, service_type) && is_allowed; } -void ApplicationManagerImpl::ForbidStreaming(uint32_t app_id) { - using namespace mobile_apis::AppInterfaceUnregisteredReason; - using namespace mobile_apis::Result; - - SDL_LOG_AUTO_TRACE(); - - ApplicationSharedPtr app = application(app_id); - if (!app || (!app->is_navi() && !app->mobile_projection_enabled())) { - SDL_LOG_DEBUG( - "There is no navi or projection application with id: " << app_id); - return; - } - - { - sync_primitives::AutoLock lock(navi_app_to_stop_lock_); - if (navi_app_to_stop_.end() != std::find(navi_app_to_stop_.begin(), - navi_app_to_stop_.end(), - app_id) || - navi_app_to_end_stream_.end() != - std::find(navi_app_to_end_stream_.begin(), - navi_app_to_end_stream_.end(), - app_id)) { - return; - } - } - - bool unregister = false; - { - sync_primitives::AutoLock lock(navi_service_status_lock_); - - NaviServiceStatusMap::iterator it = navi_service_status_.find(app_id); - if (navi_service_status_.end() == it || - (!it->second.first && !it->second.second)) { - unregister = true; - } - } - if (unregister) { - rpc_service_->ManageMobileCommand( - MessageHelper::GetOnAppInterfaceUnregisteredNotificationToMobile( - app_id, PROTOCOL_VIOLATION), - commands::Command::SOURCE_SDL); - UnregisterApplication(app_id, ABORTED); - return; - } - EndNaviServices(app_id); -} - void ApplicationManagerImpl::ForbidStreaming( uint32_t app_id, protocol_handler::ServiceType service_type) { using namespace mobile_apis::AppInterfaceUnregisteredReason; @@ -3645,48 +3586,6 @@ void ApplicationManagerImpl::OnAppStreaming( } } -void ApplicationManagerImpl::OnAppStreaming( - uint32_t app_id, - protocol_handler::ServiceType service_type, - const Application::StreamingState new_state) { - SDL_LOG_AUTO_TRACE(); - - ApplicationSharedPtr app = application(app_id); - if (!app || (!app->is_navi() && !app->mobile_projection_enabled())) { - SDL_LOG_DEBUG( - " There is no navi or projection application with id: " << app_id); - return; - } - DCHECK_OR_RETURN_VOID(media_manager_); - - SDL_LOG_DEBUG("New state for service " << static_cast(service_type) - << " is " - << static_cast(new_state)); - switch (new_state) { - case Application::StreamingState::kStopped: { - // Stop activity in media_manager_ when service is stopped - // State controller has been already notified by kSuspended event - // received before - media_manager_->StopStreaming(app_id, service_type); - break; - } - - case Application::StreamingState::kStarted: { - // Apply temporary streaming state and start activity in media_manager_ - state_ctrl_.OnVideoStreamingStarted(app); - media_manager_->StartStreaming(app_id, service_type); - break; - } - - case Application::StreamingState::kSuspended: { - // Don't stop activity in media_manager_ in that case - // Just cancel the temporary streaming state - state_ctrl_.OnVideoStreamingStopped(app); - break; - } - } -} - void ApplicationManagerImpl::EndNaviServices(uint32_t app_id) { using namespace protocol_handler; SDL_LOG_AUTO_TRACE(); diff --git a/src/components/application_manager/src/hmi_capabilities_impl.cc b/src/components/application_manager/src/hmi_capabilities_impl.cc index f313e0c0a52..a8001eba91b 100644 --- a/src/components/application_manager/src/hmi_capabilities_impl.cc +++ b/src/components/application_manager/src/hmi_capabilities_impl.cc @@ -431,8 +431,6 @@ void HMICapabilitiesImpl::Init( ui_language_, vr_language_, tts_language_); } -void HMICapabilitiesImpl::Init(resumption::LastState*) {} - bool HMICapabilitiesImpl::is_ui_cooperating() const { return is_ui_cooperating_; } diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index c0d61bdd4eb..c8c2a25a6dc 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -1236,12 +1236,6 @@ void PolicyHandler::OnPendingPermissionChange( policy_manager->RemovePendingPermissionChanges(policy_app_id); } -bool PolicyHandler::SendMessageToSDK(const BinaryMessage& pt_string, - const std::string& url) { - const uint32_t app_id = GetAppIdForSending(); - return SendMessageToSDK(pt_string, url, app_id); -} - bool PolicyHandler::SendMessageToSDK(const BinaryMessage& pt_string, const std::string& url, const uint32_t app_id) { diff --git a/src/components/application_manager/src/resumption/resume_ctrl_impl.cc b/src/components/application_manager/src/resumption/resume_ctrl_impl.cc index bc373d48c9e..96870c12c1c 100644 --- a/src/components/application_manager/src/resumption/resume_ctrl_impl.cc +++ b/src/components/application_manager/src/resumption/resume_ctrl_impl.cc @@ -283,10 +283,6 @@ void ResumeCtrlImpl::RemoveFromResumption(uint32_t app_id) { queue_lock_.Release(); } -bool ResumeCtrlImpl::Init(LastState&) { - return false; -} - bool ResumeCtrlImpl::SetAppHMIState( ApplicationSharedPtr application, const mobile_apis::HMILevel::eType hmi_level, diff --git a/src/components/application_manager/src/resumption/resumption_data_json.cc b/src/components/application_manager/src/resumption/resumption_data_json.cc index 1f2d0f116f6..5d6d0089111 100644 --- a/src/components/application_manager/src/resumption/resumption_data_json.cc +++ b/src/components/application_manager/src/resumption/resumption_data_json.cc @@ -573,8 +573,4 @@ void ResumptionDataJson::Persist() { last_state_wrapper_->get_accessor().GetMutableData().SaveToFileSystem(); } -LastState& ResumptionDataJson::last_state() const { - return last_state_wrapper_->get_accessor().GetMutableData(); -} - } // namespace resumption diff --git a/src/components/application_manager/test/include/application_manager/mock_hmi_capabilities.h b/src/components/application_manager/test/include/application_manager/mock_hmi_capabilities.h index e40197cc13f..f0da952d18d 100644 --- a/src/components/application_manager/test/include/application_manager/mock_hmi_capabilities.h +++ b/src/components/application_manager/test/include/application_manager/mock_hmi_capabilities.h @@ -205,9 +205,6 @@ class MockHMICapabilities : public ::application_manager::HMICapabilities { set_seat_location_capability, void(const smart_objects::SmartObject& seat_location_capability)); - DEPRECATED - MOCK_METHOD1(Init, void(resumption::LastState* last_state)); - MOCK_METHOD1(Init, void(resumption::LastStateWrapperPtr last_state_wrapper)); MOCK_CONST_METHOD0(ccpu_version, const std::string&()); diff --git a/src/components/application_manager/test/include/application_manager/mock_resume_ctrl.h b/src/components/application_manager/test/include/application_manager/mock_resume_ctrl.h index c2c02a1d0c6..ed7d08e850d 100644 --- a/src/components/application_manager/test/include/application_manager/mock_resume_ctrl.h +++ b/src/components/application_manager/test/include/application_manager/mock_resume_ctrl.h @@ -86,8 +86,7 @@ class MockResumeCtrl : public resumption::ResumeCtrl { MOCK_METHOD1(OnAppActivated, void(app_mngr::ApplicationSharedPtr application)); MOCK_METHOD1(RemoveFromResumption, void(uint32_t app_id)); - DEPRECATED - MOCK_METHOD1(Init, bool(resumption::LastState& last_state)); + MOCK_METHOD1(Init, bool(resumption::LastStateWrapperPtr last_state)); MOCK_METHOD2(OnAppRegistrationStart, void(const std::string& policy_app_id, diff --git a/src/components/include/application_manager/application_manager.h b/src/components/include/application_manager/application_manager.h index 54f7ab9f058..ef4da3e2d88 100644 --- a/src/components/include/application_manager/application_manager.h +++ b/src/components/include/application_manager/application_manager.h @@ -135,10 +135,6 @@ class ApplicationManager { public: virtual ~ApplicationManager() {} - DEPRECATED - virtual bool Init(resumption::LastState&, - media_manager::MediaManager* media_manager) = 0; - /** * Inits application manager */ @@ -210,9 +206,6 @@ class ApplicationManager { virtual ApplicationSharedPtr application_by_policy_id( const std::string& policy_app_id) const = 0; - DEPRECATED virtual ApplicationSharedPtr application_by_name( - const std::string& app_name) const = 0; - virtual ApplicationSharedPtr pending_application_by_policy_id( const std::string& policy_app_id) const = 0; @@ -867,11 +860,6 @@ class ApplicationManager { protocol_handler::ServiceType service_type, bool state) = 0; - DEPRECATED - virtual void OnAppStreaming(uint32_t app_id, - protocol_handler::ServiceType service_type, - const Application::StreamingState new_state) = 0; - /** * @brief CreateRegularState create regular HMI state for application * @param app Application @@ -899,9 +887,6 @@ class ApplicationManager { virtual bool CanAppStream( uint32_t app_id, protocol_handler::ServiceType service_type) const = 0; - DEPRECATED - virtual void ForbidStreaming(uint32_t app_id) = 0; - /** * @brief ForbidStreaming forbid the stream over the certain application. * @param app_id the application's id which should stop streaming. diff --git a/src/components/include/application_manager/hmi_capabilities.h b/src/components/include/application_manager/hmi_capabilities.h index e7d7aa485b8..93f3db76cb3 100644 --- a/src/components/include/application_manager/hmi_capabilities.h +++ b/src/components/include/application_manager/hmi_capabilities.h @@ -519,9 +519,6 @@ class HMICapabilities { virtual const smart_objects::SmartObjectSPtr seat_location_capability() const = 0; - DEPRECATED - virtual void Init(resumption::LastState* last_state) = 0; - virtual void Init(resumption::LastStateWrapperPtr last_state_wrapper) = 0; /** diff --git a/src/components/include/application_manager/policies/policy_handler_interface.h b/src/components/include/application_manager/policies/policy_handler_interface.h index 7ada7884bf2..d79c059b342 100644 --- a/src/components/include/application_manager/policies/policy_handler_interface.h +++ b/src/components/include/application_manager/policies/policy_handler_interface.h @@ -77,9 +77,7 @@ class PolicyHandlerInterface : public VehicleDataItemProvider { virtual bool InitPolicyTable() = 0; virtual bool ResetPolicyTable() = 0; virtual bool ClearUserConsent() = 0; - // Deprecated in favor of private variant - DEPRECATED virtual bool SendMessageToSDK(const BinaryMessage& pt_string, - const std::string& url) = 0; + virtual bool ReceiveMessageFromSDK(const std::string& file, const BinaryMessage& pt_string) = 0; virtual bool UnloadPolicyLibrary() = 0; diff --git a/src/components/include/media_manager/media_manager.h b/src/components/include/media_manager/media_manager.h index 1ecdb122574..60c93843d1a 100644 --- a/src/components/include/media_manager/media_manager.h +++ b/src/components/include/media_manager/media_manager.h @@ -42,13 +42,6 @@ namespace media_manager { class MediaManager { public: - DEPRECATED virtual void PlayA2DPSource(int32_t application_key) = 0; - DEPRECATED virtual void StopA2DPSource(int32_t application_key) = 0; - - DEPRECATED virtual void StartMicrophoneRecording( - int32_t application_key, - const std::string& outputFileName, - int32_t duration) = 0; virtual void StartMicrophoneRecording( int32_t application_key, const std::string& outputFileName, diff --git a/src/components/include/policy/policy_external/policy/policy_manager.h b/src/components/include/policy/policy_external/policy/policy_manager.h index d9844c153bd..5d57d5ca45c 100644 --- a/src/components/include/policy/policy_external/policy/policy_manager.h +++ b/src/components/include/policy/policy_external/policy/policy_manager.h @@ -752,15 +752,6 @@ class PolicyManager : public usage_statistics::StatisticsManager, */ virtual const PolicySettings& get_settings() const = 0; - /** - * @deprecated Unused in EXTERNAL_PROPRIETARY policies - * @brief Finds the next URL that must be sent on OnSystemRequest retry - * @param urls vector of vectors that contain urls for each application - * @return Pair of policy application id and application url id from the - * urls vector - */ - DEPRECATED virtual AppIdURL GetNextUpdateUrl(const EndpointUrls& urls) = 0; - /** * @brief Assigns new HMI types for specified application * @param device_handle device identifier diff --git a/src/components/include/protocol_handler/protocol_handler.h b/src/components/include/protocol_handler/protocol_handler.h index 011592da499..2cea958bae4 100644 --- a/src/components/include/protocol_handler/protocol_handler.h +++ b/src/components/include/protocol_handler/protocol_handler.h @@ -127,22 +127,6 @@ class ProtocolHandler { virtual const ProtocolHandlerSettings& get_settings() const = 0; virtual SessionObserver& get_session_observer() = 0; - /** - * @brief Called by connection handler to notify the context of - * OnSessionStartedCallback(). - * @param context reference to structure with started session data - * @param rejected_params list of parameters name that are rejected. - * Only valid when generated_session_id is 0. Note, even if - * generated_session_id is 0, the list may be empty. - * @param err_reason string with NACK reason. Only valid when - * generated_session_id is 0. - */ - DEPRECATED - virtual void NotifySessionStarted( - const SessionContext& context, - std::vector& rejected_params, - const std::string err_reason = std::string()) = 0; - /** * @brief Called by connection handler to notify the context of * OnSessionStartedCallback(). diff --git a/src/components/include/resumption/last_state.h b/src/components/include/resumption/last_state.h index b28e5611b79..1f54959ffce 100644 --- a/src/components/include/resumption/last_state.h +++ b/src/components/include/resumption/last_state.h @@ -45,12 +45,6 @@ class LastState { */ virtual ~LastState() {} - /** - * @brief Saves dictionary to filesystem - */ - DEPRECATED - virtual void SaveStateToFileSystem() = 0; - /** * @brief SaveToFileSystem * Saving dictionary to filesystem @@ -63,12 +57,6 @@ class LastState { */ virtual void RemoveFromFileSystem() = 0; - /** - * @brief dictionary Gets internal dictionary - * @return Reference to internal dictionary json value - */ - virtual Json::Value& get_dictionary() = 0; - /** * @brief dictionary Gets internal dictionary * @return Copy of internal dictionary json value diff --git a/src/components/include/test/application_manager/mock_application_manager.h b/src/components/include/test/application_manager/mock_application_manager.h index fd7ddeac15d..50fb168411c 100644 --- a/src/components/include/test/application_manager/mock_application_manager.h +++ b/src/components/include/test/application_manager/mock_application_manager.h @@ -68,10 +68,6 @@ class MockApplicationManager : public application_manager::ApplicationManager { MOCK_METHOD2(Init, bool(resumption::LastStateWrapperPtr last_state, media_manager::MediaManager* media_manager)); - DEPRECATED - MOCK_METHOD2(Init, - bool(resumption::LastState& last_state, - media_manager::MediaManager* media_manager)); MOCK_METHOD0(Stop, bool()); MOCK_METHOD1(set_hmi_message_handler, void(hmi_message_handler::HMIMessageHandler* handler)); @@ -117,9 +113,6 @@ class MockApplicationManager : public application_manager::ApplicationManager { MOCK_CONST_METHOD1(application_by_policy_id, application_manager::ApplicationSharedPtr( const std::string& policy_app_id)); - MOCK_CONST_METHOD1( - application_by_name, - application_manager::ApplicationSharedPtr(const std::string& app_name)); MOCK_CONST_METHOD1(pending_application_by_policy_id, application_manager::ApplicationSharedPtr( const std::string& policy_app_id)); @@ -319,12 +312,6 @@ class MockApplicationManager : public application_manager::ApplicationManager { void(uint32_t app_id, protocol_handler::ServiceType service_type, bool state)); - DEPRECATED - MOCK_METHOD3( - OnAppStreaming, - void(uint32_t app_id, - protocol_handler::ServiceType service_type, - const application_manager::Application::StreamingState new_state)); MOCK_CONST_METHOD6(CreateRegularState, application_manager::HmiStatePtr( application_manager::ApplicationSharedPtr app, @@ -339,8 +326,6 @@ class MockApplicationManager : public application_manager::ApplicationManager { MOCK_CONST_METHOD2(CanAppStream, bool(uint32_t app_id, protocol_handler::ServiceType service_type)); - DEPRECATED - MOCK_METHOD1(ForbidStreaming, void(uint32_t app_id)); MOCK_METHOD2(ForbidStreaming, void(uint32_t app_id, protocol_handler::ServiceType service_type)); diff --git a/src/components/include/test/application_manager/mock_rpc_plugin.h b/src/components/include/test/application_manager/mock_rpc_plugin.h index 26338254284..2dba5367c64 100644 --- a/src/components/include/test/application_manager/mock_rpc_plugin.h +++ b/src/components/include/test/application_manager/mock_rpc_plugin.h @@ -16,13 +16,6 @@ class MockRPCPlugin : public RPCPlugin { HMICapabilities& hmi_capabilities, policy::PolicyHandlerInterface& policy_handler, resumption::LastStateWrapperPtr last_state)); - DEPRECATED - MOCK_METHOD5(Init, - bool(ApplicationManager& app_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler, - resumption::LastState& last_state)); MOCK_METHOD2(IsAbleToProcess, bool(const int32_t function_id, const commands::Command::CommandSource message_source)); diff --git a/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h b/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h index af4019ce214..ca5d25ed4c3 100644 --- a/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h +++ b/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h @@ -53,9 +53,6 @@ class MockPolicyHandlerInterface : public policy::PolicyHandlerInterface { MOCK_METHOD0(InitPolicyTable, bool()); MOCK_METHOD0(ResetPolicyTable, bool()); MOCK_METHOD0(ClearUserConsent, bool()); - MOCK_METHOD2(SendMessageToSDK, - bool(const policy::BinaryMessage& pt_string, - const std::string& url)); MOCK_METHOD2(ReceiveMessageFromSDK, bool(const std::string& file, const policy::BinaryMessage& pt_string)); diff --git a/src/components/include/test/media_manager/mock_media_manager.h b/src/components/include/test/media_manager/mock_media_manager.h index 364c495236d..cfee287d128 100644 --- a/src/components/include/test/media_manager/mock_media_manager.h +++ b/src/components/include/test/media_manager/mock_media_manager.h @@ -41,12 +41,6 @@ namespace media_manager_test { class MockMediaManager : public media_manager::MediaManager { public: - MOCK_METHOD1(PlayA2DPSource, void(int32_t application_key)); - MOCK_METHOD1(StopA2DPSource, void(int32_t application_key)); - MOCK_METHOD3(StartMicrophoneRecording, - void(int32_t application_key, - const std::string& outputFileName, - int32_t duration)); MOCK_METHOD6(StartMicrophoneRecording, void(int32_t application_key, const std::string& outputFileName, diff --git a/src/components/include/test/resumption/mock_last_state.h b/src/components/include/test/resumption/mock_last_state.h index 99c3799a958..c646dcd2861 100644 --- a/src/components/include/test/resumption/mock_last_state.h +++ b/src/components/include/test/resumption/mock_last_state.h @@ -43,10 +43,6 @@ namespace resumption_test { class MockLastState : public resumption::LastState { public: - DEPRECATED - MOCK_METHOD0(SaveStateToFileSystem, void()); - DEPRECATED - MOCK_METHOD0(get_dictionary, Json::Value&()); MOCK_METHOD0(SaveToFileSystem, void()); MOCK_METHOD0(RemoveFromFileSystem, void()); MOCK_CONST_METHOD0(dictionary, Json::Value()); diff --git a/src/components/include/test/transport_manager/mock_transport_manager.h b/src/components/include/test/transport_manager/mock_transport_manager.h index 1920af18a32..7aa70b80619 100644 --- a/src/components/include/test/transport_manager/mock_transport_manager.h +++ b/src/components/include/test/transport_manager/mock_transport_manager.h @@ -57,8 +57,6 @@ class MockTransportManager : public ::transport_manager::TransportManager, transport_manager::TMTelemetryObserver> { public: MOCK_METHOD1(Init, int(resumption::LastStateWrapperPtr last_state)); - DEPRECATED - MOCK_METHOD1(Init, int(resumption::LastState& last_state)); MOCK_METHOD0(Reinit, int()); MOCK_METHOD0(Deinit, void()); MOCK_METHOD0(StopEventsProcessing, void()); diff --git a/src/components/include/transport_manager/transport_manager.h b/src/components/include/transport_manager/transport_manager.h index 4697bf99822..45bb159aa20 100644 --- a/src/components/include/transport_manager/transport_manager.h +++ b/src/components/include/transport_manager/transport_manager.h @@ -53,9 +53,6 @@ class TransportManager { **/ virtual ~TransportManager() {} - DEPRECATED - virtual int Init(resumption::LastState& last_state) = 0; - /** * @brief Initialize transport manager. * @return Error code. diff --git a/src/components/media_manager/include/media_manager/audio/from_mic_recorder_adapter.h b/src/components/media_manager/include/media_manager/audio/from_mic_recorder_adapter.h index 9e0a8b51231..5ecb1a6b4a2 100644 --- a/src/components/media_manager/include/media_manager/audio/from_mic_recorder_adapter.h +++ b/src/components/media_manager/include/media_manager/audio/from_mic_recorder_adapter.h @@ -53,7 +53,6 @@ class FromMicRecorderAdapter : public MediaAdapterImpl { void StopActivity(int32_t application_key); bool is_app_performing_activity(int32_t application_key) const; void set_output_file(const std::string& output_file); - DEPRECATED void set_duration(int32_t duration); void set_config(mobile_apis::SamplingRate::eType sampling_rate, mobile_apis::BitsPerSample::eType bits_per_sample, mobile_apis::AudioType::eType audio_type, diff --git a/src/components/media_manager/include/media_manager/media_manager_impl.h b/src/components/media_manager/include/media_manager/media_manager_impl.h index f8e94cbbb2e..faa51feec91 100644 --- a/src/components/media_manager/include/media_manager/media_manager_impl.h +++ b/src/components/media_manager/include/media_manager/media_manager_impl.h @@ -60,13 +60,6 @@ class MediaManagerImpl : public MediaManager, const MediaManagerSettings& settings); virtual ~MediaManagerImpl(); - DEPRECATED virtual void PlayA2DPSource(int32_t application_key); - DEPRECATED virtual void StopA2DPSource(int32_t application_key); - - DEPRECATED virtual void StartMicrophoneRecording( - int32_t application_key, - const std::string& outputFileName, - int32_t duration); virtual void StartMicrophoneRecording( int32_t application_key, const std::string& outputFileName, diff --git a/src/components/media_manager/src/media_manager_impl.cc b/src/components/media_manager/src/media_manager_impl.cc index 4fc8b38d87d..8a73101b471 100644 --- a/src/components/media_manager/src/media_manager_impl.cc +++ b/src/components/media_manager/src/media_manager_impl.cc @@ -184,39 +184,6 @@ void MediaManagerImpl::Init() { } } -void MediaManagerImpl::PlayA2DPSource(int32_t application_key) { - SDL_LOG_AUTO_TRACE(); - -#if defined(EXTENDED_MEDIA_MODE) - if (!a2dp_player_ && protocol_handler_) { - a2dp_player_ = - new A2DPSourcePlayerAdapter(protocol_handler_->get_session_observer()); - } -#endif - - if (a2dp_player_) { - a2dp_player_->StartActivity(application_key); - } -} - -void MediaManagerImpl::StopA2DPSource(int32_t application_key) { - SDL_LOG_AUTO_TRACE(); - if (a2dp_player_) { - a2dp_player_->StopActivity(application_key); - } -} - -void MediaManagerImpl::StartMicrophoneRecording(int32_t application_key, - const std::string& output_file, - int32_t duration) { - StartMicrophoneRecording(application_key, - output_file, - duration, - mobile_apis::SamplingRate::INVALID_ENUM, - mobile_apis::BitsPerSample::INVALID_ENUM, - mobile_apis::AudioType::INVALID_ENUM); -} - void MediaManagerImpl::StartMicrophoneRecording( int32_t application_key, const std::string& output_file, diff --git a/src/components/policy/policy_external/include/policy/policy_manager_impl.h b/src/components/policy/policy_external/include/policy/policy_manager_impl.h index 813af17b3f6..2be8183bfa5 100644 --- a/src/components/policy/policy_external/include/policy/policy_manager_impl.h +++ b/src/components/policy/policy_external/include/policy/policy_manager_impl.h @@ -790,14 +790,6 @@ class PolicyManagerImpl : public PolicyManager { */ const PolicySettings& get_settings() const OVERRIDE; - /** - * @brief Finds the next URL that must be sent on OnSystemRequest retry - * @param urls vector of vectors that contain urls for each application - * @return Pair of policy application id and application url id from the - * urls vector - */ - DEPRECATED AppIdURL GetNextUpdateUrl(const EndpointUrls& urls) OVERRIDE; - /** * @brief Checks if there is existing URL in the EndpointUrls vector with * index saved in the policy manager and if not, it moves to the next diff --git a/src/components/policy/policy_external/src/policy_manager_impl.cc b/src/components/policy/policy_external/src/policy_manager_impl.cc index b1e1c85490c..75920be58c0 100644 --- a/src/components/policy/policy_external/src/policy_manager_impl.cc +++ b/src/components/policy/policy_external/src/policy_manager_impl.cc @@ -2143,18 +2143,6 @@ void PolicyManagerImpl::SetDecryptedCertificate( cache_->SetDecryptedCertificate(certificate); } -AppIdURL PolicyManagerImpl::GetNextUpdateUrl(const EndpointUrls& urls) { - SDL_LOG_AUTO_TRACE(); - - const AppIdURL next_app_url = RetrySequenceUrl(retry_sequence_url_, urls); - - retry_sequence_url_.url_idx_ = next_app_url.second + 1; - retry_sequence_url_.app_idx_ = next_app_url.first; - retry_sequence_url_.policy_app_id_ = urls[next_app_url.first].app_id; - - return next_app_url; -} - AppIdURL PolicyManagerImpl::RetrySequenceUrl(const struct RetrySequenceURL& rs, const EndpointUrls& urls) const { uint32_t url_idx = rs.url_idx_; diff --git a/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h b/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h index 02c96fc3c7b..b036735216d 100644 --- a/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h +++ b/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h @@ -462,11 +462,6 @@ class ProtocolHandlerImpl * Only valid when generated_session_id is 0. Note, even if * generated_session_id is 0, the list may be empty. */ - DEPRECATED - void NotifySessionStarted(const SessionContext& context, - std::vector& rejected_params, - const std::string err_reason) OVERRIDE; - void NotifySessionStarted(SessionContext& context, std::vector& rejected_params, const std::string err_reason) OVERRIDE; diff --git a/src/components/protocol_handler/src/protocol_handler_impl.cc b/src/components/protocol_handler/src/protocol_handler_impl.cc index 2595b268865..7b5d9901ea6 100644 --- a/src/components/protocol_handler/src/protocol_handler_impl.cc +++ b/src/components/protocol_handler/src/protocol_handler_impl.cc @@ -2128,14 +2128,6 @@ void ProtocolHandlerImpl::NotifySessionStarted( } } -void ProtocolHandlerImpl::NotifySessionStarted( - const SessionContext& context, - std::vector& rejected_params, - const std::string err_reason) { - SessionContext context_copy = context; - NotifySessionStarted(context_copy, rejected_params, err_reason); -} - RESULT_CODE ProtocolHandlerImpl::HandleControlMessageHeartBeat( const ProtocolPacket& packet) { const ConnectionID connection_id = packet.connection_id(); diff --git a/src/components/resumption/include/resumption/last_state_impl.h b/src/components/resumption/include/resumption/last_state_impl.h index 5eb4050d2d8..8495c39d046 100644 --- a/src/components/resumption/include/resumption/last_state_impl.h +++ b/src/components/resumption/include/resumption/last_state_impl.h @@ -57,9 +57,6 @@ class LastStateImpl : public LastState { */ ~LastStateImpl(); - DEPRECATED - void SaveStateToFileSystem(); - /** * @brief Saving dictionary to filesystem */ @@ -76,12 +73,6 @@ class LastStateImpl : public LastState { */ Json::Value dictionary() const OVERRIDE; - /** - * @brief Get the dictionary - * @return Reference to the dictionary - */ - DEPRECATED Json::Value& get_dictionary(); - /** * @brief Resets internal dictionary * @param dictionary New dictionary json value to be set diff --git a/src/components/resumption/src/last_state_impl.cc b/src/components/resumption/src/last_state_impl.cc index 2083369a8e7..9920a1499bb 100644 --- a/src/components/resumption/src/last_state_impl.cc +++ b/src/components/resumption/src/last_state_impl.cc @@ -52,28 +52,6 @@ LastStateImpl::~LastStateImpl() { SaveToFileSystem(); } -void LastStateImpl::SaveStateToFileSystem() { - SDL_LOG_AUTO_TRACE(); - - std::string styled_string; - { - sync_primitives::AutoLock lock(dictionary_lock_); - styled_string = dictionary_.toStyledString(); - } - - const std::string full_path = - !app_storage_folder_.empty() - ? app_storage_folder_ + "/" + app_info_storage_ - : app_info_storage_; - - const std::vector char_vector_pdata(styled_string.begin(), - styled_string.end()); - DCHECK(file_system::CreateDirectoryRecursively(app_storage_folder_)); - SDL_LOG_INFO("LastState::SaveStateToFileSystem[DEPRECATED] " - << full_path << styled_string); - DCHECK(file_system::Write(full_path, char_vector_pdata)); -} - void LastStateImpl::SaveToFileSystem() { SDL_LOG_AUTO_TRACE(); @@ -124,11 +102,6 @@ Json::Value LastStateImpl::dictionary() const { return dictionary_; } -Json::Value& LastStateImpl::get_dictionary() { - sync_primitives::AutoLock lock(dictionary_lock_); - return dictionary_; -} - void LastStateImpl::set_dictionary(const Json::Value& dictionary) { DCHECK(dictionary.type() == Json::objectValue || dictionary.type() == Json::nullValue); diff --git a/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_transport_adapter.h b/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_transport_adapter.h index 5429f50f7fe..6e36877e2d4 100644 --- a/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_transport_adapter.h +++ b/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_transport_adapter.h @@ -52,10 +52,6 @@ class BluetoothTransportAdapter : public TransportAdapterImpl { BluetoothTransportAdapter(resumption::LastStateWrapperPtr last_state_wrapper, const TransportManagerSettings& settings); - DEPRECATED - BluetoothTransportAdapter(resumption::LastState&, - const TransportManagerSettings& settings); - protected: /** * @brief Return type of device. diff --git a/src/components/transport_manager/include/transport_manager/iap2_emulation/iap2_transport_adapter.h b/src/components/transport_manager/include/transport_manager/iap2_emulation/iap2_transport_adapter.h index 3dabfb39cad..4525f6b5d99 100644 --- a/src/components/transport_manager/include/transport_manager/iap2_emulation/iap2_transport_adapter.h +++ b/src/components/transport_manager/include/transport_manager/iap2_emulation/iap2_transport_adapter.h @@ -63,11 +63,6 @@ class IAP2BluetoothEmulationTransportAdapter : public TcpTransportAdapter { resumption::LastStateWrapperPtr last_state_wrapper, const TransportManagerSettings& settings); - DEPRECATED - IAP2BluetoothEmulationTransportAdapter( - const uint16_t port, - resumption::LastState& last_state_wrapper, - const TransportManagerSettings& settings); /** * @brief DeviceSwitched is called during switching from iAP2 Bluetooth to * iAP2 USB transport. @@ -113,12 +108,6 @@ class IAP2USBEmulationTransportAdapter : public TcpTransportAdapter { resumption::LastStateWrapperPtr last_state_wrapper, const TransportManagerSettings& settings); - DEPRECATED - IAP2USBEmulationTransportAdapter(const uint16_t port, - resumption::LastState&, - const TransportManagerSettings& settings) = - delete; - /** * Destructor */ diff --git a/src/components/transport_manager/include/transport_manager/tcp/tcp_transport_adapter.h b/src/components/transport_manager/include/transport_manager/tcp/tcp_transport_adapter.h index c5948062c90..1cd5c1cb7b0 100644 --- a/src/components/transport_manager/include/transport_manager/tcp/tcp_transport_adapter.h +++ b/src/components/transport_manager/include/transport_manager/tcp/tcp_transport_adapter.h @@ -53,11 +53,6 @@ class TcpTransportAdapter : public TransportAdapterImpl { resumption::LastStateWrapperPtr last_state_wrapper, const TransportManagerSettings& settings); - DEPRECATED - TcpTransportAdapter(uint16_t port, - resumption::LastState&, - const TransportManagerSettings& settings) = delete; - /** * @brief Destructor. */ diff --git a/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_impl.h b/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_impl.h index cfc886cb15a..58dd4b16db2 100644 --- a/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_impl.h +++ b/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_impl.h @@ -85,13 +85,6 @@ class TransportAdapterImpl : public TransportAdapter, resumption::LastStateWrapperPtr last_state_wrapper, const TransportManagerSettings& settings); - DEPRECATED - TransportAdapterImpl(DeviceScanner* device_scanner, - ServerConnectionFactory* server_connection_factory, - ClientConnectionListener* client_connection_listener, - resumption::LastState& last_state, - const TransportManagerSettings& settings) = delete; - /** * @brief Destructor. **/ @@ -677,10 +670,6 @@ class TransportAdapterImpl : public TransportAdapter, TMTelemetryObserver* metric_observer_; #endif // TELEMETRY_MONITOR - resumption::LastState& last_state() const { - return last_state_wrapper_->get_accessor().GetMutableData(); - } - /** * @brief Pointer to the device scanner. */ diff --git a/src/components/transport_manager/include/transport_manager/transport_manager_default.h b/src/components/transport_manager/include/transport_manager/transport_manager_default.h index 81fc92dc38d..d9407276b07 100644 --- a/src/components/transport_manager/include/transport_manager/transport_manager_default.h +++ b/src/components/transport_manager/include/transport_manager/transport_manager_default.h @@ -82,9 +82,6 @@ class TransportManagerDefault : public TransportManagerImpl { */ int Init(resumption::LastStateWrapperPtr last_state_wrapper) OVERRIDE; - DEPRECATED - int Init(resumption::LastState& last_state) OVERRIDE; - /** * @brief Destructor. */ diff --git a/src/components/transport_manager/include/transport_manager/transport_manager_impl.h b/src/components/transport_manager/include/transport_manager/transport_manager_impl.h index 85d96bac55b..b45d7cc3792 100644 --- a/src/components/transport_manager/include/transport_manager/transport_manager_impl.h +++ b/src/components/transport_manager/include/transport_manager/transport_manager_impl.h @@ -126,9 +126,6 @@ class TransportManagerImpl */ int Init(resumption::LastStateWrapperPtr last_state_wrapper) OVERRIDE; - DEPRECATED - int Init(resumption::LastState& last_state) OVERRIDE; - /** * Reinitializes transport manager * @return Error code diff --git a/src/components/transport_manager/include/transport_manager/usb/usb_aoa_adapter.h b/src/components/transport_manager/include/transport_manager/usb/usb_aoa_adapter.h index 45c6d4c0e4f..12516e769e4 100644 --- a/src/components/transport_manager/include/transport_manager/usb/usb_aoa_adapter.h +++ b/src/components/transport_manager/include/transport_manager/usb/usb_aoa_adapter.h @@ -47,10 +47,6 @@ class UsbAoaAdapter : public TransportAdapterImpl { UsbAoaAdapter(resumption::LastStateWrapperPtr last_state_wrapper, const TransportManagerSettings& settings); - DEPRECATED - UsbAoaAdapter(resumption::LastState&, - const TransportManagerSettings& settings) = delete; - virtual ~UsbAoaAdapter(); protected: diff --git a/src/components/transport_manager/src/transport_manager_default.cc b/src/components/transport_manager/src/transport_manager_default.cc index 45d0b045288..0ffb8432ea3 100644 --- a/src/components/transport_manager/src/transport_manager_default.cc +++ b/src/components/transport_manager/src/transport_manager_default.cc @@ -190,10 +190,6 @@ int TransportManagerDefault::Init( return E_SUCCESS; } -int TransportManagerDefault::Init(resumption::LastState&) { - return 1; -} - TransportManagerDefault::~TransportManagerDefault() {} } // namespace transport_manager diff --git a/src/components/transport_manager/src/transport_manager_impl.cc b/src/components/transport_manager/src/transport_manager_impl.cc index bb6f3626e12..5f4ddc9d7e3 100644 --- a/src/components/transport_manager/src/transport_manager_impl.cc +++ b/src/components/transport_manager/src/transport_manager_impl.cc @@ -582,15 +582,6 @@ int TransportManagerImpl::Init( return E_SUCCESS; } -int TransportManagerImpl::Init(resumption::LastState& last_state) { - // Last state required to initialize Transport adapters - UNUSED(last_state); - SDL_LOG_TRACE("enter"); - is_initialized_ = true; - SDL_LOG_TRACE("exit with E_SUCCESS"); - return E_SUCCESS; -} - void TransportManagerImpl::Deinit() { SDL_LOG_AUTO_TRACE(); DisconnectAllDevices(); diff --git a/src/components/transport_manager/src/websocket_server/websocket_server_transport_adapter.cc b/src/components/transport_manager/src/websocket_server/websocket_server_transport_adapter.cc index 68f23a6326b..18c6ad9be19 100644 --- a/src/components/transport_manager/src/websocket_server/websocket_server_transport_adapter.cc +++ b/src/components/transport_manager/src/websocket_server/websocket_server_transport_adapter.cc @@ -100,7 +100,9 @@ TransportAdapter::Error WebSocketServerTransportAdapter::Init() { void WebSocketServerTransportAdapter::Store() const { SDL_LOG_AUTO_TRACE(); if (webengine_device_) { - Json::Value& dictionary = last_state().get_dictionary(); + resumption::LastStateAccessor accessor = + last_state_wrapper_->get_accessor(); + Json::Value dictionary = accessor.GetData().dictionary(); if (dictionary["TransportManager"].isMember("WebsocketServerAdapter")) { SDL_LOG_DEBUG( "WebsocketServerAdapter already exists. Storing is skipped"); @@ -119,7 +121,8 @@ void WebSocketServerTransportAdapter::Store() const { bool WebSocketServerTransportAdapter::Restore() { SDL_LOG_AUTO_TRACE(); - const Json::Value& dictionary = last_state().get_dictionary(); + resumption::LastStateAccessor accessor = last_state_wrapper_->get_accessor(); + Json::Value dictionary = accessor.GetData().dictionary(); const Json::Value ws_adapter_dictionary = dictionary["TransportManager"]["WebsocketServerAdapter"]; webengine_device_id_ = diff --git a/src/components/transport_manager/test/include/transport_manager/raw_message_matcher.h b/src/components/transport_manager/test/include/transport_manager/raw_message_matcher.h index 5aedfd58aaf..4f5cbf71eb7 100644 --- a/src/components/transport_manager/test/include/transport_manager/raw_message_matcher.h +++ b/src/components/transport_manager/test/include/transport_manager/raw_message_matcher.h @@ -54,10 +54,6 @@ using namespace ::protocol_handler; class RawMessageMatcher : public MatcherInterface { public: explicit RawMessageMatcher(RawMessagePtr ptr); - - DEPRECATED - virtual bool MatchAndExplain(const RawMessagePtr msg, - MatchResultListener* listener) const; virtual void DescribeTo(std::ostream* os) const; virtual void DescribeNegationTo(std::ostream* os) const; diff --git a/src/components/transport_manager/test/include/transport_manager/transport_adapter/mock_transport_adapter_impl.h b/src/components/transport_manager/test/include/transport_manager/transport_adapter/mock_transport_adapter_impl.h index 7b1d720ba2d..4be51431d70 100644 --- a/src/components/transport_manager/test/include/transport_manager/transport_adapter/mock_transport_adapter_impl.h +++ b/src/components/transport_manager/test/include/transport_manager/transport_adapter/mock_transport_adapter_impl.h @@ -66,13 +66,6 @@ class MockTransportAdapterImpl : public TransportAdapterImpl { last_state_wrapper, settings) {} - DEPRECATED - MockTransportAdapterImpl(DeviceScanner*, - ServerConnectionFactory*, - ClientConnectionListener*, - resumption::LastState&, - const transport_manager::TransportManagerSettings&); - ConnectionSPtr FindStatedConnection(const DeviceUID& device_handle, const ApplicationHandle& app_handle) { return this->FindEstablishedConnection(device_handle, app_handle); diff --git a/src/components/transport_manager/test/transport_manager_default_test.cc b/src/components/transport_manager/test/transport_manager_default_test.cc index 67b4a0a8ba3..66cfa85ef94 100644 --- a/src/components/transport_manager/test/transport_manager_default_test.cc +++ b/src/components/transport_manager/test/transport_manager_default_test.cc @@ -210,8 +210,6 @@ void TestTransportManagerDefault::ExpectationsSettings_TM( .WillByDefault(ReturnRef(kWSServerCACertPath)); ON_CALL(*mock_last_state_, dictionary()) .WillByDefault(Return(custom_dictionary_)); - ON_CALL(*mock_last_state_, get_dictionary()) - .WillByDefault(ReturnRef(custom_dictionary_)); EXPECT_CALL(transport_manager_settings_, use_last_state()) .WillRepeatedly(Return(use_last_state)); diff --git a/src/components/utils/include/utils/file_system.h b/src/components/utils/include/utils/file_system.h index 232d9583b16..382f38e5201 100644 --- a/src/components/utils/include/utils/file_system.h +++ b/src/components/utils/include/utils/file_system.h @@ -257,9 +257,6 @@ bool ReadBinaryFile(const std::string& name, bool ReadFile(const std::string& name, std::string& result); -DEPRECATED -const std::string ConvertPathForURL(const std::string& path); - /** * @brief Create empty file * diff --git a/src/components/utils/src/file_system.cc b/src/components/utils/src/file_system.cc index f0c838a7f98..b2c1f44c53e 100644 --- a/src/components/utils/src/file_system.cc +++ b/src/components/utils/src/file_system.cc @@ -458,25 +458,6 @@ bool file_system::ReadFile(const std::string& name, std::string& result) { return true; } -const std::string file_system::ConvertPathForURL(const std::string& path) { - SDL_LOG_AUTO_TRACE(); - const std::string reserved_symbols = "!#$&'()*+,:;=?@[] "; - std::string converted_path; - - for (const auto symbol : path) { - size_t pos = reserved_symbols.find_first_of(symbol); - if (pos != std::string::npos) { - const size_t size = 100; - char percent_value[size]; - snprintf(percent_value, size, "%%%x", symbol); - converted_path += percent_value; - } else { - converted_path += symbol; - } - } - return converted_path; -} - bool file_system::CreateFile(const std::string& path) { SDL_LOG_AUTO_TRACE(); From 82476469248d60d00f785e0dbd066369db1ffbf0 Mon Sep 17 00:00:00 2001 From: "Andrii Kalinich (GitHub)" Date: Thu, 22 Jul 2021 09:55:14 -0400 Subject: [PATCH 03/14] Fix cmake warning under external flow (#3730) * Established the new policy for CMP0054 and added if and else for different Policy values --- CMakeLists.txt | 1 + src/components/policy/policy_external/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e638310f889..3b53b87e39b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,7 @@ # POSSIBILITY OF SUCH DAMAGE. cmake_minimum_required(VERSION 2.8.11) +cmake_policy(SET CMP0054 NEW) set (PROJECT smartDeviceLinkCore) project (${PROJECT}) diff --git a/src/components/policy/policy_external/CMakeLists.txt b/src/components/policy/policy_external/CMakeLists.txt index 72f7dd7bdb4..0e3735093fd 100644 --- a/src/components/policy/policy_external/CMakeLists.txt +++ b/src/components/policy/policy_external/CMakeLists.txt @@ -132,7 +132,7 @@ if (ENABLE_LOG AND ${LOGGER_NAME} STREQUAL "LOG4CXX") target_link_libraries(Policy log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) endif() -add_custom_target(copy_library_Policy ALL +add_custom_target(copy_policy_library ALL COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/${library_name} ${copy_destination} From 1df399beed9b523323240fb5fe7fcc9309669d2b Mon Sep 17 00:00:00 2001 From: "Andrii Kalinich (GitHub)" Date: Thu, 22 Jul 2021 09:59:04 -0400 Subject: [PATCH 04/14] adding the interface name to the types in HMI_API.xml (#3742) Co-authored-by: Roman Reznichenko --- src/components/interfaces/HMI_API.xml | 144 +++++++++++++------------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/src/components/interfaces/HMI_API.xml b/src/components/interfaces/HMI_API.xml index 92806e73729..b185b88ada7 100644 --- a/src/components/interfaces/HMI_API.xml +++ b/src/components/interfaces/HMI_API.xml @@ -1809,10 +1809,10 @@ uuid of a module. "moduleId + moduleType" uniquely identify a module. - + Location of a module. - + Service area of a module. @@ -1832,7 +1832,7 @@ - + Contains a list of SeatLocation in the vehicle @@ -1880,8 +1880,8 @@ Specify the mode of a massage zone. - - + + @@ -1895,7 +1895,7 @@ The intensity or firmness of a cushion. - + @@ -1914,7 +1914,7 @@ - + @@ -1925,7 +1925,7 @@ Seat control data corresponds to "SEAT" ModuleType. - + @@ -1941,9 +1941,9 @@ - - - + + + @@ -1953,7 +1953,7 @@ It should not be used to identify a module by mobile application. - + Information about a RC module, including its id. @@ -2107,13 +2107,13 @@ Identifies the 4-alpha-character station call sign plus an optional (-FM) extension - + Used for network Application. Consists of Country Code and FCC Facility ID. Identifies the station call sign or other identifying information in the long format. - + Provides the 3-dimensional geographic station location. @@ -2157,7 +2157,7 @@ - + Read-only Station Information Service (SIS) data provides basic information about the station such as call sign, as well as information not displayable to the consumer such as the station identification number @@ -2167,7 +2167,7 @@ The short name or a short description of the radio control module. - + Information about a RC module, including its id. @@ -2293,7 +2293,7 @@ - + @@ -2322,7 +2322,7 @@ The short name or a short description of the climate control module. - + Information about a RC module, including its id. @@ -2437,7 +2437,7 @@ - + In a getter response or a notification, it is the current primary audio source of the system. In a setter request, it is the target audio source that the system shall switch to. @@ -2456,7 +2456,7 @@ Reflects the volume of audio, from 0%-100%. - + Defines the list of supported channels (band) and their current/desired settings on HMI @@ -2468,7 +2468,7 @@ It should not be used to identify a module by mobile application. - + Information about a RC module, including its id. @@ -2605,7 +2605,7 @@ - + Indicates if the status (ON/OFF) can be set remotely. App shall not use read-only values (RAMP_UP/RAMP_DOWN/UNKNOWN/INVALID) in a setInteriorVehicleData request. @@ -2630,25 +2630,25 @@ It should not be used to identify a module by mobile application. - + Information about a RC module, including its id. - + An array of available light names that are controllable. - + The name of a light or a group of lights. - + - + - + An array of LightNames and their current or desired status. No change to the status of the LightNames that are not listed in the array. @@ -2665,9 +2665,9 @@ Corresponds to "HMI_SETTINGS" ModuleType - - - + + + @@ -2677,7 +2677,7 @@ It should not be used to identify a module by mobile application. - + Information about a RC module, including its id. @@ -2702,13 +2702,13 @@ - + - + - + - + @@ -2744,7 +2744,7 @@ The name of the Button from the ButtonName enum - + Information about a RC module, including its id. @@ -2886,8 +2886,8 @@ Currently only predefined window template layouts are defined. - - + + @@ -3280,7 +3280,7 @@ The status of component volume. See ComponentVolumeStatus. - + The status of TPMS according to the particular tire. @@ -3638,7 +3638,7 @@ - + Latitude/Longitude of the location. @@ -3653,10 +3653,10 @@ Phone number of location / establishment. - + Image / icon of intended location. - + Address to be used by navigation engines for search @@ -3708,24 +3708,24 @@ The preferred frame rate per second of the head unit. The mobile application / app library may take other factors into account that constrain the frame rate lower than this value, but it should not perform streaming at a higher frame rate than this value. - + - + Used as a descriptor of what data to expect in this struct. The corresponding param to this enum should be included and the only other param included. - + Describes supported capabilities for video streaming - + An array of ImageFieldName values for which the system supports sending OnFileUpdate notifications. If you send an Image struct for that image field with a name without having uploaded the image data using PutFile that matches that name, the system will request that you upload the data with PutFile at a later point when the HMI needs it. The HMI will then display the image in the appropriate field. If not sent, assume false. @@ -3743,7 +3743,7 @@ Describes the capabilities of a single keyboard layout. - + Number of keys available for special characters, App can customize as per their needs. @@ -3753,7 +3753,7 @@ Availability of capability to mask input characters using keyboard. True: Available, False: Not Available - + Capabilities of supported keyboard layouts by HMI. @@ -3765,13 +3765,13 @@ or omitted for the main window on the main display. - + A set of all fields that support text data. See TextField - + A set of all fields that support images. See ImageField - + Provides information about image types supported by the system. @@ -3780,19 +3780,19 @@ The number of on-window custom presets available (if any); otherwise omitted. - + The number of buttons and the capabilities of each on-window button. - + The number of soft buttons available on-window and the capabilities for each button. An array of available menu layouts. If this parameter is not provided, only the `LIST` layout is assumed to be available - + Contains the head unit's capabilities for dynamic updating features declaring if the module will send dynamic update RPCs. - + See KeyboardCapabilities @@ -3800,12 +3800,12 @@ Contains information about the display capabilities. - + Informs the application how many windows the app is allowed to create per type. - + Contains a list of capabilities of all windows related to the app. Once the app has registered the capabilities of all windows are provided. @@ -3830,39 +3830,39 @@ - + - + - + - + Describes capabilities when the driver is distracted - + If included, the platform supports RC climate controls. For this baseline version, maxsize=1. i.e. only one climate control module is supported. - + If included, the platform supports RC radio controls. For this baseline version, maxsize=1. i.e. only one climate control module is supported. - + If included, the platform supports RC button controls with the included button names. - + If included, the platform supports seat controls. - + If included, the platform supports audio controls. - + If included, the platform supports hmi setting controls. - + If included, the platform supports light controls. @@ -4395,10 +4395,10 @@ - + Contains information about the locations of each seat - + Describes capabilities when the driver is distracted @@ -4471,7 +4471,7 @@ The seek next / skip previous subscription buttons' content - + If the type is TIME, this number of seconds may be present alongside the skip indicator. From 473400504342e0f4271e5bf187c66188eb13fe9f Mon Sep 17 00:00:00 2001 From: "Andrii Kalinich (GitHub)" Date: Thu, 22 Jul 2021 10:53:19 -0400 Subject: [PATCH 05/14] Fix resumption for menuLayout global property (#3733) * Added methods get and set the menuLayout and added to the request on the HMI this field * fixup! Added methods get and set the menuLayout and added to the request on the HMI this field Co-authored-by: Roman Reznichenko --- .../include/application_manager/application.h | 3 +++ .../application_manager/application_data_impl.h | 3 +++ .../mobile/set_global_properties_request.cc | 1 + .../src/application_data_impl.cc | 16 ++++++++++++++++ .../src/helpers/application_helper.cc | 1 + .../src/message_helper/message_helper.cc | 8 +++++++- .../src/resumption/resumption_data.cc | 2 ++ .../test/application_helper_test.cc | 5 +++++ .../application_manager/mock_application.h | 3 +++ 9 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/components/application_manager/include/application_manager/application.h b/src/components/application_manager/include/application_manager/application.h index f25afeb2bc9..2d7006e19a9 100644 --- a/src/components/application_manager/include/application_manager/application.h +++ b/src/components/application_manager/include/application_manager/application.h @@ -203,6 +203,7 @@ class DynamicApplicationData { virtual const smart_objects::SmartObject* keyboard_props() const = 0; virtual const smart_objects::SmartObject* menu_title() const = 0; virtual const smart_objects::SmartObject* menu_icon() const = 0; + virtual const smart_objects::SmartObject* menu_layout() const = 0; virtual smart_objects::SmartObject day_color_scheme() const = 0; virtual smart_objects::SmartObject night_color_scheme() const = 0; virtual std::string display_layout() const = 0; @@ -242,6 +243,8 @@ class DynamicApplicationData { const smart_objects::SmartObject& keyboard_props) = 0; virtual void set_menu_title(const smart_objects::SmartObject& menu_title) = 0; virtual void set_menu_icon(const smart_objects::SmartObject& menu_icon) = 0; + virtual void set_menu_layout( + const smart_objects::SmartObject& menu_layout) = 0; virtual uint32_t audio_stream_retry_number() const = 0; diff --git a/src/components/application_manager/include/application_manager/application_data_impl.h b/src/components/application_manager/include/application_manager/application_data_impl.h index a64e0c8f339..086e71b48ba 100644 --- a/src/components/application_manager/include/application_manager/application_data_impl.h +++ b/src/components/application_manager/include/application_manager/application_data_impl.h @@ -102,6 +102,7 @@ class DynamicApplicationDataImpl : public virtual Application { const smart_objects::SmartObject* keyboard_props() const; const smart_objects::SmartObject* menu_title() const; const smart_objects::SmartObject* menu_icon() const; + const smart_objects::SmartObject* menu_layout() const; smart_objects::SmartObject day_color_scheme() const OVERRIDE; smart_objects::SmartObject night_color_scheme() const OVERRIDE; @@ -141,6 +142,7 @@ class DynamicApplicationDataImpl : public virtual Application { void set_keyboard_props(const smart_objects::SmartObject& keyboard_props); void set_menu_title(const smart_objects::SmartObject& menu_title); void set_menu_icon(const smart_objects::SmartObject& menu_icon); + void set_menu_layout(const smart_objects::SmartObject& menu_layout); void set_day_color_scheme(const smart_objects::SmartObject& color_scheme); void set_night_color_scheme(const smart_objects::SmartObject& color_scheme); void set_display_layout(const std::string& layout); @@ -323,6 +325,7 @@ class DynamicApplicationDataImpl : public virtual Application { smart_objects::SmartObject* keyboard_props_; smart_objects::SmartObject* menu_title_; smart_objects::SmartObject* menu_icon_; + smart_objects::SmartObject* menu_layout_; smart_objects::SmartObject* tbt_show_command_; smart_objects::SmartObjectSPtr display_capabilities_; AppWindowsTemplates window_templates_; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_global_properties_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_global_properties_request.cc index bbce4d2bb35..0aab0003769 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_global_properties_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_global_properties_request.cc @@ -186,6 +186,7 @@ void SetGlobalPropertiesRequest::Run() { msg_params[strings::menu_layout].asUInt()); if (app->menu_layout_supported(menu_layout)) { params[strings::menu_layout] = msg_params[strings::menu_layout]; + app->set_menu_layout(msg_params[strings::menu_layout]); } else { is_menu_layout_available_ = false; } diff --git a/src/components/application_manager/src/application_data_impl.cc b/src/components/application_manager/src/application_data_impl.cc index e190025addf..1d6ea8afe84 100644 --- a/src/components/application_manager/src/application_data_impl.cc +++ b/src/components/application_manager/src/application_data_impl.cc @@ -201,6 +201,7 @@ DynamicApplicationDataImpl::DynamicApplicationDataImpl() , keyboard_props_(nullptr) , menu_title_(nullptr) , menu_icon_(nullptr) + , menu_layout_(nullptr) , tbt_show_command_(nullptr) , commands_() , commands_lock_ptr_(std::make_shared()) @@ -349,6 +350,11 @@ const smart_objects::SmartObject* DynamicApplicationDataImpl::menu_icon() return menu_icon_; } +const smart_objects::SmartObject* DynamicApplicationDataImpl::menu_layout() + const { + return menu_layout_; +} + smart_objects::SmartObject DynamicApplicationDataImpl::day_color_scheme() const { using namespace mobile_apis::PredefinedWindows; @@ -467,6 +473,8 @@ void DynamicApplicationDataImpl::load_global_properties( SetGlobalProperties(properties_so.getElement(strings::menu_icon), &DynamicApplicationData::set_menu_icon); + SetGlobalProperties(properties_so.getElement(strings::menu_layout), + &DynamicApplicationData::set_menu_layout); } void DynamicApplicationDataImpl::set_help_prompt( @@ -560,6 +568,14 @@ void DynamicApplicationDataImpl::set_menu_icon( menu_icon_ = new smart_objects::SmartObject(menu_icon); } +void DynamicApplicationDataImpl::set_menu_layout( + const smart_objects::SmartObject& menu_layout) { + if (menu_layout_) { + delete menu_layout_; + } + menu_layout_ = new smart_objects::SmartObject(menu_layout); +} + void DynamicApplicationDataImpl::set_day_color_scheme( const smart_objects::SmartObject& color_scheme) { using namespace mobile_apis::PredefinedWindows; diff --git a/src/components/application_manager/src/helpers/application_helper.cc b/src/components/application_manager/src/helpers/application_helper.cc index 74810d7e099..863d85a7f0b 100644 --- a/src/components/application_manager/src/helpers/application_helper.cc +++ b/src/components/application_manager/src/helpers/application_helper.cc @@ -87,6 +87,7 @@ void DeleteGlobalProperties(ApplicationSharedPtr app, app->set_keyboard_props(empty_so); app->set_menu_icon(empty_so); app->set_menu_title(empty_so); + app->set_menu_layout(empty_so); MessageHelper::SendResetPropertiesRequest(app, app_manager); } diff --git a/src/components/application_manager/src/message_helper/message_helper.cc b/src/components/application_manager/src/message_helper/message_helper.cc index 301c26a7509..6dbb7b35aed 100644 --- a/src/components/application_manager/src/message_helper/message_helper.cc +++ b/src/components/application_manager/src/message_helper/message_helper.cc @@ -1289,7 +1289,7 @@ MessageHelper::CreateGlobalPropertiesRequestsToHMI( if (can_send_ui && (app->vr_help_title() || app->vr_help() || app->keyboard_props() || - app->menu_title() || app->menu_icon())) { + app->menu_title() || app->menu_icon() || app->menu_layout())) { smart_objects::SmartObjectSPtr ui_global_properties = CreateMessageForHMI( hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID()); if (ui_global_properties) { @@ -1313,6 +1313,9 @@ MessageHelper::CreateGlobalPropertiesRequestsToHMI( if (app->menu_icon()) { ui_msg_params[strings::menu_icon] = (*app->menu_icon()); } + if (app->menu_layout()) { + ui_msg_params[strings::menu_layout] = (*app->menu_layout()); + } ui_msg_params[strings::app_id] = app->app_id(); (*ui_global_properties)[strings::msg_params] = ui_msg_params; @@ -1995,6 +1998,9 @@ smart_objects::SmartObjectList MessageHelper::CreateAddSubMenuRequestsToHMI( msg_params[strings::menu_params][strings::parent_id] = (*i->second)[strings::parent_id]; } + if ((*i->second).keyExists(strings::menu_layout)) { + msg_params[strings::menu_layout] = (*i->second)[strings::menu_layout]; + } msg_params[strings::app_id] = app->app_id(); (*ui_sub_menu)[strings::msg_params] = msg_params; if (((*i->second).keyExists(strings::menu_icon)) && diff --git a/src/components/application_manager/src/resumption/resumption_data.cc b/src/components/application_manager/src/resumption/resumption_data.cc index 95dd331b884..c72231d334d 100644 --- a/src/components/application_manager/src/resumption/resumption_data.cc +++ b/src/components/application_manager/src/resumption/resumption_data.cc @@ -132,6 +132,8 @@ smart_objects::SmartObject ResumptionData::GetApplicationGlobalProperties( PointerToSmartObj(application->menu_title()); global_properties[strings::menu_icon] = PointerToSmartObj(application->menu_icon()); + global_properties[strings::menu_layout] = + PointerToSmartObj(application->menu_layout()); return global_properties; } diff --git a/src/components/application_manager/test/application_helper_test.cc b/src/components/application_manager/test/application_helper_test.cc index 1633b9d29bc..5c6d3b22f61 100644 --- a/src/components/application_manager/test/application_helper_test.cc +++ b/src/components/application_manager/test/application_helper_test.cc @@ -176,6 +176,7 @@ TEST_F(ApplicationHelperTest, RecallApplicationData_ExpectAppDataReset) { app_impl_->set_keyboard_props(dummy_data); app_impl_->set_menu_title(dummy_data); app_impl_->set_menu_icon(dummy_data); + app_impl_->set_menu_layout(dummy_data); const bool persistent = false; const bool downloaded = true; @@ -205,6 +206,8 @@ TEST_F(ApplicationHelperTest, RecallApplicationData_ExpectAppDataReset) { EXPECT_TRUE(menu_title->asString() == some_string); auto menu_icon = app_impl_->menu_icon(); EXPECT_TRUE(menu_icon->asString() == some_string); + auto menu_layout = app_impl_->menu_layout(); + EXPECT_TRUE(menu_layout->asString() == some_string); auto file_ptr = app_impl_->GetFile(filename); EXPECT_TRUE(NULL != file_ptr); EXPECT_TRUE(file_ptr->file_name == filename); @@ -239,6 +242,8 @@ TEST_F(ApplicationHelperTest, RecallApplicationData_ExpectAppDataReset) { EXPECT_FALSE(menu_title->asString() == some_string); menu_icon = app_impl_->menu_icon(); EXPECT_FALSE(menu_icon->asString() == some_string); + menu_layout = app_impl_->menu_layout(); + EXPECT_FALSE(menu_layout->asString() == some_string); file_ptr = app_impl_->GetFile(filename); EXPECT_TRUE(NULL == file_ptr); } diff --git a/src/components/application_manager/test/include/application_manager/mock_application.h b/src/components/application_manager/test/include/application_manager/mock_application.h index 2c9fe688b44..ac2a534929e 100644 --- a/src/components/application_manager/test/include/application_manager/mock_application.h +++ b/src/components/application_manager/test/include/application_manager/mock_application.h @@ -253,6 +253,7 @@ class MockApplication : public ::application_manager::Application { MOCK_CONST_METHOD0(keyboard_props, const smart_objects::SmartObject*()); MOCK_CONST_METHOD0(menu_title, const smart_objects::SmartObject*()); MOCK_CONST_METHOD0(menu_icon, const smart_objects::SmartObject*()); + MOCK_CONST_METHOD0(menu_layout, const smart_objects::SmartObject*()); MOCK_CONST_METHOD0(day_color_scheme, smart_objects::SmartObject()); MOCK_CONST_METHOD0(night_color_scheme, smart_objects::SmartObject()); MOCK_CONST_METHOD0(display_layout, std::string()); @@ -305,6 +306,8 @@ class MockApplication : public ::application_manager::Application { void(const smart_objects::SmartObject& menu_title)); MOCK_METHOD1(set_menu_icon, void(const smart_objects::SmartObject& menu_icon)); + MOCK_METHOD1(set_menu_layout, + void(const smart_objects::SmartObject& menu_layout)); MOCK_METHOD1(set_day_color_scheme, void(const smart_objects::SmartObject& color_scheme)); MOCK_METHOD1(set_night_color_scheme, From e9b3e093980444b57dc6c82d6f9661f965954ae1 Mon Sep 17 00:00:00 2001 From: Jacob Keeler Date: Tue, 27 Jul 2021 17:13:22 -0400 Subject: [PATCH 06/14] Suspend notifications to mobile until HMI state is established (#3675) * Suspend any notifications meant for mobile app until HMI state is properly established --- .../src/application_manager_impl.cc | 1 + .../application_manager/src/rpc_service_impl.cc | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 884b5df0eef..f5dedc0e35c 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -451,6 +451,7 @@ void ApplicationManagerImpl::OnApplicationRegistered(ApplicationSharedPtr app) { sync_primitives::AutoLock lock(applications_list_lock_ptr_); const mobile_apis::HMILevel::eType default_level = GetDefaultHmiLevel(app); state_ctrl_.OnApplicationRegistered(app, default_level); + commands_holder_->Resume(app, CommandHolder::CommandType::kMobileCommand); } void ApplicationManagerImpl::OnApplicationSwitched(ApplicationSharedPtr app) { diff --git a/src/components/application_manager/src/rpc_service_impl.cc b/src/components/application_manager/src/rpc_service_impl.cc index f0cd720e30c..6cb03705abc 100644 --- a/src/components/application_manager/src/rpc_service_impl.cc +++ b/src/components/application_manager/src/rpc_service_impl.cc @@ -138,10 +138,18 @@ bool RPCServiceImpl::ManageMobileCommand( const uint32_t connection_key = static_cast( (*message)[strings::params][strings::connection_key].asUInt()); + const WindowID window_id = MessageHelper::ExtractWindowIdFromSmartObject( + (*message)[strings::msg_params]); + int32_t message_type = + (*message)[strings::params][strings::message_type].asInt(); auto app_ptr = app_manager_.application(connection_key); - if (app_ptr && app_manager_.IsAppInReconnectMode(app_ptr->device(), - app_ptr->policy_app_id())) { + if (app_ptr && + (app_manager_.IsAppInReconnectMode(app_ptr->device(), + app_ptr->policy_app_id()) || + (!app_ptr->WindowIdExists(window_id) && + mobile_apis::PredefinedWindows::DEFAULT_WINDOW == window_id && + mobile_apis::messageType::notification == message_type))) { commands_holder_.Suspend( app_ptr, CommandHolder::CommandType::kMobileCommand, source, message); return true; @@ -209,8 +217,6 @@ bool RPCServiceImpl::ManageMobileCommand( return false; } - int32_t message_type = - (*message)[strings::params][strings::message_type].asInt(); if (message_type == mobile_apis::messageType::response) { if (command->Init() && command->CheckPermissions()) { command->Run(); From be877b5bc3f48199883852f3bb52698d515d3090 Mon Sep 17 00:00:00 2001 From: Collin Date: Thu, 29 Jul 2021 17:17:17 -0400 Subject: [PATCH 07/14] remove reference to ui get capabilities response parameter systemCapabilities.displayCapabilities (#3746) --- .../hmi/ui_get_capabilities_response.cc | 5 ----- .../hmi/ui_get_capabilities_response_test.cc | 19 ------------------- 2 files changed, 24 deletions(-) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_capabilities_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_capabilities_response.cc index 45c5f59326b..128f41e01f4 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_capabilities_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_capabilities_response.cc @@ -151,11 +151,6 @@ void UIGetCapabilitiesResponse::Run() { hmi_capabilities_.set_driver_distraction_supported(true); } } - if (system_capabilities_so.keyExists(strings::display_capabilities)) { - sections_to_update.push_back(strings::display_capabilities); - hmi_capabilities_.set_system_display_capabilities( - system_capabilities_so[strings::display_capabilities]); - } } if (msg_params.keyExists(strings::pcm_stream_capabilities)) { diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_response_test.cc index a1661dc247c..37531b469ab 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_response_test.cc @@ -356,25 +356,6 @@ TEST_F(UIGetCapabilitiesResponseTest, SetVideoStreamingCapability_SUCCESS) { command->Run(); } -TEST_F(UIGetCapabilitiesResponseTest, SetSystemDisplayCapabilities_SUCCESS) { - MessageSharedPtr command_msg = CreateCommandMsg(); - (*command_msg)[strings::msg_params][strings::system_capabilities] = - smart_objects::SmartObject(smart_objects::SmartType_Map); - - ResponseFromHMIPtr command( - CreateCommand(command_msg)); - - const auto& display_capability_so = - (*command_msg)[strings::msg_params][strings::system_capabilities] - [strings::display_capabilities]; - - EXPECT_CALL(mock_hmi_capabilities_, - set_system_display_capabilities(display_capability_so)); - - ASSERT_TRUE(command->Init()); - command->Run(); -} - TEST_F(UIGetCapabilitiesResponseTest, SaveCachedCapabilitiesToFileCall_SUCCESS) { MessageSharedPtr command_msg = CreateCommandMsg(); From c94a3cfb7d0dfc606c96c3cf08a5674b6e7ca1da Mon Sep 17 00:00:00 2001 From: "Iryna Lytvynenko (GitHub)" Date: Wed, 4 Aug 2021 22:28:33 +0300 Subject: [PATCH 08/14] Feature/sdl 0236 tire status mismatch (#3583) * Temporary commit with link to rpc_spec fork * Indicate that the structure is included in the Common interface * Mark the parameters as non mandatory * Update link to rpc_spec fork * Fix Message Helper linkage to VehicleInfoPlugin * Fix versioning for TirePressure param * Bump version up to 8.0 * Add link to rpc_spec fork * Address review comments Co-authored-by: Dmitriy Boltovskiy Co-authored-by: Yana Chernysheva Co-authored-by: Andrii Kalinich --- src/appMain/sdl_preloaded_pt.json | 221 +++++++++++++++++- .../application_manager/message_helper.h | 11 + .../application_manager/smart_object_keys.h | 7 + .../vehicle_info_plugin/CMakeLists.txt | 2 +- .../mobile/get_vehicle_data_request.cc | 6 + .../mobile/on_vehicle_data_notification.cc | 10 +- .../vehicle_info_plugin/test/CMakeLists.txt | 2 +- .../src/message_helper/message_helper.cc | 39 ++++ .../src/smart_object_keys.cc | 7 + .../application_manager/mock_message_helper.h | 4 + .../test/mock_message_helper.cc | 7 + tools/rpc_spec | 2 +- 12 files changed, 306 insertions(+), 12 deletions(-) diff --git a/src/appMain/sdl_preloaded_pt.json b/src/appMain/sdl_preloaded_pt.json index 50bbce6a97b..e018a597f7d 100644 --- a/src/appMain/sdl_preloaded_pt.json +++ b/src/appMain/sdl_preloaded_pt.json @@ -3616,7 +3616,16 @@ "name": "pressureTelltale", "key": "OEM_REF_PRES_TEL", "type": "WarningLightStatus", - "mandatory": true + "mandatory": true, + "since": "2.0", + "until": "8.0" + }, + { + "name": "pressureTelltale", + "key": "OEM_REF_PRES_TEL", + "type": "WarningLightStatus", + "mandatory": false, + "since": "8.0" }, { "name": "leftFront", @@ -3646,7 +3655,40 @@ ], "key": "OEM_REF_LEFT_FR", "type": "Struct", - "mandatory": true + "mandatory": true, + "since": "2.0", + "until": "8.0" + }, + { + "name": "leftFront", + "params": [ + { + "name": "status", + "key": "OEM_REF_LEFT_FR_ST", + "type": "ComponentVolumeStatus", + "mandatory": true + }, + { + "name": "tpms", + "key": "OEM_REF_LEFT_FR_TMPS", + "type": "TPMS", + "mandatory": false, + "since": "5.0" + }, + { + "name": "pressure", + "key": "OEM_REF_LEFT_FR_PRES", + "type": "Float", + "mandatory": false, + "minvalue": 0, + "maxvalue": 2000, + "since": "5.0" + } + ], + "key": "OEM_REF_LEFT_FR", + "type": "Struct", + "mandatory": false, + "since": "8.0" }, { "name": "rightFront", @@ -3676,7 +3718,40 @@ ], "key": "OEM_REF_RIGHT_FR", "type": "Struct", - "mandatory": true + "mandatory": true, + "since": "2.0", + "until": "8.0" + }, + { + "name": "rightFront", + "params": [ + { + "name": "status", + "key": "OEM_REF_RIGHT_FR_ST", + "type": "ComponentVolumeStatus", + "mandatory": true + }, + { + "name": "tpms", + "key": "OEM_REF_RIGHT_FR_TMPS", + "type": "TPMS", + "mandatory": false, + "since": "5.0" + }, + { + "name": "pressure", + "key": "OEM_REF_RIGHT_FR_PRES", + "type": "Float", + "mandatory": false, + "minvalue": 0, + "maxvalue": 2000, + "since": "5.0" + } + ], + "key": "OEM_REF_RIGHT_FR", + "type": "Struct", + "mandatory": false, + "since": "8.0" }, { "name": "leftRear", @@ -3706,7 +3781,40 @@ ], "key": "OEM_REF_LEFT_REAR", "type": "Struct", - "mandatory": true + "mandatory": true, + "since": "2.0", + "until": "8.0" + }, + { + "name": "leftRear", + "params": [ + { + "name": "status", + "key": "OEM_REF_LEFT_REAR_ST", + "type": "ComponentVolumeStatus", + "mandatory": true + }, + { + "name": "tpms", + "key": "OEM_REF_LEFT_REAR_TMPS", + "type": "TPMS", + "mandatory": false, + "since": "5.0" + }, + { + "name": "pressure", + "key": "OEM_REF_LEFT_REAR_PRES", + "type": "Float", + "mandatory": false, + "minvalue": 0, + "maxvalue": 2000, + "since": "5.0" + } + ], + "key": "OEM_REF_LEFT_REAR", + "type": "Struct", + "mandatory": false, + "since": "8.0" }, { "name": "rightRear", @@ -3736,7 +3844,40 @@ ], "key": "OEM_REF_RIGHT_REAR", "type": "Struct", - "mandatory": true + "mandatory": true, + "since": "2.0", + "until": "8.0" + }, + { + "name": "rightRear", + "params": [ + { + "name": "status", + "key": "OEM_REF_RIGHT_REAR_ST", + "type": "ComponentVolumeStatus", + "mandatory": true + }, + { + "name": "tpms", + "key": "OEM_REF_RIGHT_REAR_TMPS", + "type": "TPMS", + "mandatory": false, + "since": "5.0" + }, + { + "name": "pressure", + "key": "OEM_REF_RIGHT_REAR_PRES", + "type": "Float", + "mandatory": false, + "minvalue": 0, + "maxvalue": 2000, + "since": "5.0" + } + ], + "key": "OEM_REF_RIGHT_REAR", + "type": "Struct", + "mandatory": false, + "since": "8.0" }, { "name": "innerLeftRear", @@ -3766,7 +3907,40 @@ ], "key": "OEM_REF_IN_LEFT_REAR", "type": "Struct", - "mandatory": true + "mandatory": true, + "since": "2.0", + "until": "8.0" + }, + { + "name": "innerLeftRear", + "params": [ + { + "name": "status", + "key": "OEM_REF_IN_LEFT_REAR_ST", + "type": "ComponentVolumeStatus", + "mandatory": true + }, + { + "name": "tpms", + "key": "OEM_REF_IN_LEFT_REAR_TMPS", + "type": "TPMS", + "mandatory": false, + "since": "5.0" + }, + { + "name": "pressure", + "key": "OEM_REF_IN_LEFT_REAR_PRES", + "type": "Float", + "mandatory": false, + "minvalue": 0, + "maxvalue": 2000, + "since": "5.0" + } + ], + "key": "OEM_REF_IN_LEFT_REAR", + "type": "Struct", + "mandatory": false, + "since": "8.0" }, { "name": "innerRightRear", @@ -3796,7 +3970,40 @@ ], "key": "OEM_REF_IN_RIGHT_REAR", "type": "Struct", - "mandatory": true + "mandatory": true, + "since": "2.0", + "until": "8.0" + }, + { + "name": "innerRightRear", + "params": [ + { + "name": "status", + "key": "OEM_REF_IN_RIGHT_REAR_ST", + "type": "ComponentVolumeStatus", + "mandatory": true + }, + { + "name": "tpms", + "key": "OEM_REF_IN_RIGHT_REAR_TMPS", + "type": "TPMS", + "mandatory": false, + "since": "5.0" + }, + { + "name": "pressure", + "key": "OEM_REF_IN_RIGHT_REAR_PRES", + "type": "Float", + "mandatory": false, + "minvalue": 0, + "maxvalue": 2000, + "since": "5.0" + } + ], + "key": "OEM_REF_IN_RIGHT_REAR", + "type": "Struct", + "mandatory": false, + "since": "8.0" } ], "key": "OEM_REF_TIRE_PRES", diff --git a/src/components/application_manager/include/application_manager/message_helper.h b/src/components/application_manager/include/application_manager/message_helper.h index 4aea48c0862..2adef91c2ed 100644 --- a/src/components/application_manager/include/application_manager/message_helper.h +++ b/src/components/application_manager/include/application_manager/message_helper.h @@ -1113,6 +1113,17 @@ class MessageHelper { ApplicationManager& app_mngr, const WindowID window_id); + /** + * @brief AddDefaultParamsToTireStatus adds missing default sub-params to + * tirePressure param, if version of related application requires presence of + * all sub-params in response + * @param application shared pointer to related application + * @param response_from_hmi reference to response from HMI + */ + static void AddDefaultParamsToTireStatus( + ApplicationSharedPtr application, + smart_objects::SmartObject& response_from_hmi); + private: /** * @brief Allows to fill SO according to the current permissions. diff --git a/src/components/application_manager/include/application_manager/smart_object_keys.h b/src/components/application_manager/include/application_manager/smart_object_keys.h index 5572dfd55d5..5a79059f1fa 100644 --- a/src/components/application_manager/include/application_manager/smart_object_keys.h +++ b/src/components/application_manager/include/application_manager/smart_object_keys.h @@ -308,6 +308,13 @@ extern const char* vin; extern const char* gearStatus; extern const char* prndl; extern const char* tire_pressure; +extern const char* pressure_telltale; +extern const char* left_front; +extern const char* right_front; +extern const char* left_rear; +extern const char* right_rear; +extern const char* inner_left_rear; +extern const char* inner_right_rear; extern const char* odometer; extern const char* belt_status; extern const char* electronic_park_brake_status; diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/CMakeLists.txt b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/CMakeLists.txt index a741c32129c..e858967619a 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/CMakeLists.txt +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/CMakeLists.txt @@ -45,7 +45,6 @@ collect_sources(VEHICLE_INFO_PLUGIN_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src") set(LIBRARIES HMI_API MOBILE_API - MessageHelper ApplicationManager v4_protocol_v1_2_no_extra SmartObjects @@ -63,6 +62,7 @@ target_link_libraries("vehicle_info_plugin_static" ${LIBRARIES}) add_library(vehicle_info_plugin SHARED "src/vehicle_info_plugin.cc" ) target_link_libraries(vehicle_info_plugin vehicle_info_plugin_static) +target_link_libraries(vehicle_info_plugin MessageHelper) set(INSTALL_DESTINATION bin) diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/get_vehicle_data_request.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/get_vehicle_data_request.cc index 17a450ca897..18149fbe02a 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/get_vehicle_data_request.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/get_vehicle_data_request.cc @@ -126,6 +126,12 @@ void GetVehicleDataRequest::on_event(const event_engine::Event& event) { std::string response_info; GetInfo(message, response_info); + if (message[strings::msg_params].keyExists(strings::tire_pressure)) { + ApplicationSharedPtr app = + application_manager_.application(connection_key()); + MessageHelper::AddDefaultParamsToTireStatus(app, message); + } + auto data_not_available_with_params = [this, &result_code, &message]() { if (hmi_apis::Common_Result::DATA_NOT_AVAILABLE != result_code) { return false; diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/on_vehicle_data_notification.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/on_vehicle_data_notification.cc index e0627282176..0ae38a93982 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/on_vehicle_data_notification.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/on_vehicle_data_notification.cc @@ -89,16 +89,22 @@ void OnVehicleDataNotification::Run() { SDL_LOG_ERROR("NULL pointer"); continue; } + + smart_objects::SmartObject output_message = *message_; + if (strings::tire_pressure == name) { + MessageHelper::AddDefaultParamsToTireStatus(app, output_message); + } + notified_app_it = find(notify_apps.begin(), notify_apps.end(), app); if (notified_app_it == notify_apps.end()) { notify_apps.push_back(app); smart_objects::SmartObject msg_param = smart_objects::SmartObject(smart_objects::SmartType_Map); - msg_param[name] = (*message_)[strings::msg_params][name]; + msg_param[name] = output_message[strings::msg_params][name]; appSO.push_back(msg_param); } else { size_t idx = std::distance(notify_apps.begin(), notified_app_it); - appSO[idx][name] = (*message_)[strings::msg_params][name]; + appSO[idx][name] = output_message[strings::msg_params][name]; } } } diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/CMakeLists.txt b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/CMakeLists.txt index c9697d71f2e..10739743245 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/CMakeLists.txt +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/CMakeLists.txt @@ -64,7 +64,7 @@ set(LIBRARIES HMI_API MOBILE_API connectionHandler - vehicle_info_plugin + vehicle_info_plugin_static SmartObjects formatters jsoncpp diff --git a/src/components/application_manager/src/message_helper/message_helper.cc b/src/components/application_manager/src/message_helper/message_helper.cc index 6dbb7b35aed..dde580adeba 100644 --- a/src/components/application_manager/src/message_helper/message_helper.cc +++ b/src/components/application_manager/src/message_helper/message_helper.cc @@ -62,6 +62,7 @@ #include "utils/file_system.h" #include "utils/logger.h" #include "utils/macro.h" +#include "utils/semantic_version.h" #include "formatters/CFormatterJsonBase.h" #include "formatters/CFormatterJsonSDLRPCv1.h" @@ -3483,4 +3484,42 @@ WindowID MessageHelper::ExtractWindowIdFromSmartObject( return mobile_apis::PredefinedWindows::DEFAULT_WINDOW; } +void MessageHelper::AddDefaultParamsToTireStatus( + ApplicationSharedPtr app, smart_objects::SmartObject& response_from_hmi) { + const utils::SemanticVersion max_version_with_mandatory_params(8, 0, 0); + + if (!app) { + SDL_LOG_ERROR("Application not found"); + return; + } + + if (app->msg_version() >= max_version_with_mandatory_params) { + SDL_LOG_DEBUG( + "Tire status parameters are " + "non-mandatory for this app version, no need in default values"); + return; + } + + smart_objects::SmartObject& tire_status = + response_from_hmi[strings::msg_params][strings::tire_pressure]; + + if (!tire_status.keyExists(strings::pressure_telltale)) { + tire_status[strings::pressure_telltale] = + mobile_apis::WarningLightStatus::WLS_NOT_USED; + } + + const std::vector tires{strings::left_front, + strings::right_front, + strings::left_rear, + strings::right_rear, + strings::inner_left_rear, + strings::inner_right_rear}; + for (const std::string& tire : tires) { + if (!tire_status.keyExists(tire)) { + tire_status[tire][strings::status] = + mobile_apis::ComponentVolumeStatus::CVS_UNKNOWN; + } + } +} + } // namespace application_manager diff --git a/src/components/application_manager/src/smart_object_keys.cc b/src/components/application_manager/src/smart_object_keys.cc index a680653d6cd..b7c40987ade 100644 --- a/src/components/application_manager/src/smart_object_keys.cc +++ b/src/components/application_manager/src/smart_object_keys.cc @@ -275,6 +275,13 @@ const char* vin = "vin"; const char* gearStatus = "gearStatus"; const char* prndl = "prndl"; const char* tire_pressure = "tirePressure"; +const char* pressure_telltale = "pressureTelltale"; +const char* left_front = "leftFront"; +const char* right_front = "rightFront"; +const char* left_rear = "leftRear"; +const char* right_rear = "rightRear"; +const char* inner_left_rear = "innerLeftRear"; +const char* inner_right_rear = "innerRightRear"; const char* odometer = "odometer"; const char* belt_status = "beltStatus"; const char* electronic_park_brake_status = "electronicParkBrakeStatus"; diff --git a/src/components/application_manager/test/include/application_manager/mock_message_helper.h b/src/components/application_manager/test/include/application_manager/mock_message_helper.h index dd84ce4c408..82a0574c7fb 100644 --- a/src/components/application_manager/test/include/application_manager/mock_message_helper.h +++ b/src/components/application_manager/test/include/application_manager/mock_message_helper.h @@ -394,6 +394,10 @@ class MockMessageHelper { application_manager::ApplicationManager& app_mngr, const application_manager::WindowID window_id)); + MOCK_METHOD2(AddDefaultParamsToTireStatus, + void(application_manager::ApplicationSharedPtr application, + smart_objects::SmartObject& response_from_hmi)); + static MockMessageHelper* message_helper_mock(); }; diff --git a/src/components/application_manager/test/mock_message_helper.cc b/src/components/application_manager/test/mock_message_helper.cc index f96a0eca5c7..3cab2be0fb5 100644 --- a/src/components/application_manager/test/mock_message_helper.cc +++ b/src/components/application_manager/test/mock_message_helper.cc @@ -689,4 +689,11 @@ smart_objects::SmartObjectSPtr MessageHelper::CreateResponseMessageFromHmi( return MockMessageHelper::message_helper_mock()->CreateResponseMessageFromHmi( function_id, correlation_id, result_code); } + +void MessageHelper::AddDefaultParamsToTireStatus( + application_manager::ApplicationSharedPtr application, + smart_objects::SmartObject& response_from_hmi) { + return MockMessageHelper::message_helper_mock()->AddDefaultParamsToTireStatus( + application, response_from_hmi); +} } // namespace application_manager diff --git a/tools/rpc_spec b/tools/rpc_spec index 72632f94694..44f0a419c6a 160000 --- a/tools/rpc_spec +++ b/tools/rpc_spec @@ -1 +1 @@ -Subproject commit 72632f946941d63a57ee5e99896e3eae3627f7dd +Subproject commit 44f0a419c6a43815bc095134712eab4fef352ad7 From 595d76585bdcc110ae4093a62f7ff77445aa88e2 Mon Sep 17 00:00:00 2001 From: "Andrii Kalinich (GitHub)" Date: Mon, 9 Aug 2021 12:58:18 -0400 Subject: [PATCH 09/14] Fix handling of RC.SetGlobalProperties response (#3741) * Added result processing and wrote a test for RC_SetGlobalProperties * Apply suggestions from code review Co-authored-by: Shobhit Adlakha * Added result processing and wrote a test for RC_SetGlobalProperties Co-authored-by: Roman Reznichenko Co-authored-by: Shobhit Adlakha --- .../commands/command_request_impl.h | 29 +++++++++++++++ .../mobile/reset_global_properties_request.h | 2 ++ .../mobile/reset_global_properties_request.cc | 31 ++++++++++------ .../mobile/reset_global_properties_test.cc | 36 +++++++++++++++++++ .../src/commands/command_request_impl.cc | 24 +++++++++++++ 5 files changed, 112 insertions(+), 10 deletions(-) diff --git a/src/components/application_manager/include/application_manager/commands/command_request_impl.h b/src/components/application_manager/include/application_manager/commands/command_request_impl.h index 5723de3b08e..084340ad08e 100644 --- a/src/components/application_manager/include/application_manager/commands/command_request_impl.h +++ b/src/components/application_manager/include/application_manager/commands/command_request_impl.h @@ -273,6 +273,22 @@ class CommandRequestImpl : public CommandImpl, bool PrepareResultForMobileResponse(ResponseInfo& out_first, ResponseInfo& out_second) const; + /** + * @brief Checks result code from HMI for splitted RPC + * and returns parameter for sending to mobile app. + * @param out_first Contains result_code from HMI response and + * interface that returns response + * @param out_second Contains result_code from HMI response and + * interface that returns response + * @param out_third Contains result_code from HMI response and + * interface that returns response + * @return true if result code complies successful result code + * otherwise returns false + */ + bool PrepareResultForMobileResponse(ResponseInfo& out_first, + ResponseInfo& out_second, + ResponseInfo& out_third) const; + /** * @brief If message from HMI contains returns this info * or process result code from HMI and checks state of interface @@ -296,6 +312,19 @@ class CommandRequestImpl : public CommandImpl, mobile_apis::Result::eType PrepareResultCodeForResponse( const ResponseInfo& first, const ResponseInfo& second); + /** + * @brief Prepare result code for sending to mobile application + * @param first contains result_code from HMI response and + * interface that returns response + * @param second contains result_code from HMI response and + * interface that returns response. + * @return resulting code for sending to mobile application. + */ + mobile_apis::Result::eType PrepareResultCodeForResponse( + const ResponseInfo& first, + const ResponseInfo& second, + const ResponseInfo& third); + /** * @brief Resolves if the return code must be * UNSUPPORTED_RESOURCE diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/reset_global_properties_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/reset_global_properties_request.h index 7475520889b..760eb09c2d6 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/reset_global_properties_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/reset_global_properties_request.h @@ -105,7 +105,9 @@ class ResetGlobalPropertiesRequest hmi_apis::Common_Result::eType ui_result_; hmi_apis::Common_Result::eType tts_result_; + hmi_apis::Common_Result::eType rc_result_; std::string ui_response_info_; + std::string rc_response_info_; std::string tts_response_info_; }; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/reset_global_properties_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/reset_global_properties_request.cc index f4e07d4b78f..dd5e3d3e88d 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/reset_global_properties_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/reset_global_properties_request.cc @@ -58,7 +58,8 @@ ResetGlobalPropertiesRequest::ResetGlobalPropertiesRequest( hmi_capabilities, policy_handler) , ui_result_(hmi_apis::Common_Result::INVALID_ENUM) - , tts_result_(hmi_apis::Common_Result::INVALID_ENUM) {} + , tts_result_(hmi_apis::Common_Result::INVALID_ENUM) + , rc_result_(hmi_apis::Common_Result::INVALID_ENUM) {} ResetGlobalPropertiesRequest::~ResetGlobalPropertiesRequest() {} @@ -146,6 +147,14 @@ void ResetGlobalPropertiesRequest::on_event(const event_engine::Event& event) { GetInfo(message, tts_response_info_); break; } + case hmi_apis::FunctionID::RC_SetGlobalProperties: { + SDL_LOG_INFO("Received RC_SetGlobalProperties event"); + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_RC); + rc_result_ = static_cast( + message[strings::params][hmi_response::code].asInt()); + GetInfo(message, rc_response_info_); + break; + } default: { SDL_LOG_ERROR("Received unknown event " << event.id()); return; @@ -183,6 +192,8 @@ bool ResetGlobalPropertiesRequest::PrepareResponseParameters( ui_result_, HmiInterfaces::HMI_INTERFACE_UI, application_manager_); app_mngr::commands::ResponseInfo tts_properties_info( tts_result_, HmiInterfaces::HMI_INTERFACE_TTS, application_manager_); + app_mngr::commands::ResponseInfo rc_properties_info( + rc_result_, HmiInterfaces::HMI_INTERFACE_RC, application_manager_); HmiInterfaces::InterfaceState tts_interface_state = application_manager_.hmi_interfaces().GetInterfaceState( @@ -195,14 +206,13 @@ bool ResetGlobalPropertiesRequest::PrepareResponseParameters( out_result_code = mobile_apis::Result::WARNINGS; out_response_info = "Unsupported phoneme type sent in a prompt"; } else { - result = - PrepareResultForMobileResponse(ui_properties_info, tts_properties_info); - out_result_code = - PrepareResultCodeForResponse(ui_properties_info, tts_properties_info); - out_response_info = app_mngr::commands::MergeInfos(tts_properties_info, - tts_response_info_, - ui_properties_info, - ui_response_info_); + result = PrepareResultForMobileResponse( + ui_properties_info, tts_properties_info, rc_properties_info); + out_result_code = PrepareResultCodeForResponse( + ui_properties_info, tts_properties_info, rc_properties_info); + + out_response_info = app_mngr::commands::MergeInfos( + tts_response_info_, ui_response_info_, rc_response_info_); } return result; @@ -210,7 +220,8 @@ bool ResetGlobalPropertiesRequest::PrepareResponseParameters( bool ResetGlobalPropertiesRequest::IsPendingResponseExist() { return IsInterfaceAwaited(HmiInterfaces::HMI_INTERFACE_TTS) || - IsInterfaceAwaited(HmiInterfaces::HMI_INTERFACE_UI); + IsInterfaceAwaited(HmiInterfaces::HMI_INTERFACE_UI) || + IsInterfaceAwaited(HmiInterfaces::HMI_INTERFACE_RC); } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/reset_global_properties_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/reset_global_properties_test.cc index 8ca15f39fe0..f62f6b4682b 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/reset_global_properties_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/reset_global_properties_test.cc @@ -282,6 +282,42 @@ TEST_F(ResetGlobalPropertiesRequestTest, command_->on_event(event); } +TEST_F(ResetGlobalPropertiesRequestTest, + OnEvent_RC_SetGlobalProperties_SUCCESS) { + am::ResetGlobalPropertiesResult result; + result.user_location = true; + + EXPECT_CALL(app_mngr_, ResetGlobalProperties(_, _)).WillOnce(Return(result)); + + smart_objects::SmartObjectSPtr msg_params = + std::make_shared( + smart_objects::SmartType_Map); + + EXPECT_CALL(mock_message_helper_, CreateRCResetGlobalPropertiesRequest(_, _)) + .WillOnce(Return(msg_params)); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs(hmi_apis::FunctionID::RC_SetGlobalProperties), _)) + .WillOnce(Return(true)); + + command_->Run(); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::eType::SUCCESS), + am::commands::Command::SOURCE_SDL)); + + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + + Event event(hmi_apis::FunctionID::RC_SetGlobalProperties); + event.set_smart_object(*msg_); + + command_->on_event(event); +} + TEST_F(ResetGlobalPropertiesResponseTest, Run_Sendmsg_SUCCESS) { MessageSharedPtr message(CreateMessage()); ResetGlobalPropertiesResponsePtr command( diff --git a/src/components/application_manager/src/commands/command_request_impl.cc b/src/components/application_manager/src/commands/command_request_impl.cc index 0bf3716aa98..dad2689f297 100644 --- a/src/components/application_manager/src/commands/command_request_impl.cc +++ b/src/components/application_manager/src/commands/command_request_impl.cc @@ -748,6 +748,17 @@ bool CommandRequestImpl::PrepareResultForMobileResponse( return result; } +bool CommandRequestImpl::PrepareResultForMobileResponse( + ResponseInfo& out_first, + ResponseInfo& out_second, + ResponseInfo& out_third) const { + SDL_LOG_AUTO_TRACE(); + bool result = (PrepareResultForMobileResponse(out_first, out_second) || + PrepareResultForMobileResponse(out_second, out_third)) && + PrepareResultForMobileResponse(out_first, out_third); + return result; +} + void CommandRequestImpl::GetInfo( const smart_objects::SmartObject& response_from_hmi, std::string& out_info) { @@ -787,6 +798,19 @@ mobile_apis::Result::eType CommandRequestImpl::PrepareResultCodeForResponse( return result_code; } +mobile_apis::Result::eType CommandRequestImpl::PrepareResultCodeForResponse( + const ResponseInfo& first, + const ResponseInfo& second, + const ResponseInfo& third) { + SDL_LOG_AUTO_TRACE(); + + const auto first_comparison = PrepareResultCodeForResponse(first, second); + const auto second_comparison = PrepareResultCodeForResponse(second, third); + const auto third_comparison = PrepareResultCodeForResponse(first, third); + + return std::max({first_comparison, second_comparison, third_comparison}); +} + const CommandParametersPermissions& CommandRequestImpl::parameters_permissions() const { return parameters_permissions_; From f51f4fd4c7475b30cbf2c2dbc4507ac13583b7bf Mon Sep 17 00:00:00 2001 From: "Andrii Kalinich (GitHub)" Date: Tue, 10 Aug 2021 10:15:25 -0400 Subject: [PATCH 10/14] Fix sub menues deletion wrong order (#3748) * Fix wrong requests order for recursive deletion The issue which was observed is that SDL sends `DeleteSubMenu` request to HMI for a "parent node" submenu and then sends subsequent `DeleteSubMenu` requests recursively for all child nodes starting from the bottom one. Such order confuses HMI because deletion of parent node may automatically trigger deletion of all its child nodes on HMI side so subsequent requests from SDL for a child nodes might be rejected. To make sure that HMI removes all the hierarchy properly, SDL should start deletion sequence from the bottom nodes and delete the parent node in the end. To resolve that issue, DeleteSubMenu request logic was updated. Currently, SDL recursively iterates through the submenu and command nodes and collects them in a queue. Once queue is ready, SDL sends requests one by one, waiting for a HMI response for each sent request before sending the subsequent. Once the responses to all requests are received, SDL sends the final response to mobile app and finalizes the command. * Updated DeleteSubMenu unit tests to cover new logic --- .../commands/mobile/delete_sub_menu_request.h | 31 +- .../mobile/delete_sub_menu_request.cc | 192 +++++-- .../commands/mobile/delete_sub_menu_test.cc | 498 +++++++++++++----- 3 files changed, 523 insertions(+), 198 deletions(-) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/delete_sub_menu_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/delete_sub_menu_request.h index af2ba4a1ea4..20fff456d53 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/delete_sub_menu_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/delete_sub_menu_request.h @@ -82,34 +82,45 @@ class DeleteSubMenuRequest : public app_mngr::commands::CommandRequestImpl { bool Init() FINAL; private: - /* - * @brief Deletes submenus that have a parentID that matches the parentID - * parameter + /** + * @brief Creates and queues up delete requests for a submenus that have a + * parent ID which matches the parentID parameter * * @param app_id Application ID * @param parentID Parent ID of a nested submenu */ void DeleteNestedSubMenus(app_mngr::ApplicationSharedPtr const app, - uint32_t parentID, + const uint32_t parentID, const app_mngr::SubMenuMap& subMenus); - /* - * @brief Deletes VR commands from SDL for corresponding submenu ID + /** + * @brief Creates and queues up delete requests for each VR command tied to + * the given submenu ID * * @param app_id Application ID * @param parentID Parent ID of a nested submenu */ void DeleteSubMenuVRCommands(app_mngr::ApplicationConstSharedPtr app, - uint32_t parentID); + const uint32_t parentID); - /* - * @brief Deletes UI commands from SDL for corresponding submenu ID + /** + * @brief Creates and queues up delete requests for each UI command tied to + * the given submenu ID * * @param app_id Application ID * @param parentID Parent ID of a nested submenu */ void DeleteSubMenuUICommands(app_mngr::ApplicationSharedPtr const app, - uint32_t parentID); + const uint32_t parentID); + + /** + * @brief Takes the next request in the queue and sends it to HMI + */ + void SendNextRequest(); + + typedef std::list RequestsList; + RequestsList requests_list_; + uint32_t pending_request_corr_id_; DISALLOW_COPY_AND_ASSIGN(DeleteSubMenuRequest); }; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_sub_menu_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_sub_menu_request.cc index 19ec2dfb274..49e76ae327b 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_sub_menu_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_sub_menu_request.cc @@ -56,7 +56,9 @@ DeleteSubMenuRequest::DeleteSubMenuRequest( application_manager, rpc_service, hmi_capabilities, - policy_handler) {} + policy_handler) + , requests_list_() + , pending_request_corr_id_(0) {} DeleteSubMenuRequest::~DeleteSubMenuRequest() {} @@ -82,19 +84,42 @@ void DeleteSubMenuRequest::Run() { return; } + { + const DataAccessor accessor = app->sub_menu_map(); + const SubMenuMap& sub_menus = accessor.GetData(); + DeleteNestedSubMenus(app, menu_id, sub_menus); + } + smart_objects::SmartObject msg_params = smart_objects::SmartObject(smart_objects::SmartType_Map); - msg_params[strings::menu_id] = (*message_)[strings::msg_params][strings::menu_id]; msg_params[strings::app_id] = app->app_id(); + requests_list_.push_back(msg_params); + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); + SendNextRequest(); +} - SendHMIRequest(hmi_apis::FunctionID::UI_DeleteSubMenu, &msg_params, true); +void DeleteSubMenuRequest::SendNextRequest() { + SDL_LOG_AUTO_TRACE(); + + const auto request_params = requests_list_.front(); + auto function_id = hmi_apis::FunctionID::UI_DeleteSubMenu; + + if (request_params.keyExists(strings::cmd_id)) { + function_id = request_params.keyExists(strings::grammar_id) + ? hmi_apis::FunctionID::VR_DeleteCommand + : hmi_apis::FunctionID::UI_DeleteCommand; + } + + pending_request_corr_id_ = SendHMIRequest(function_id, &request_params, true); + SDL_LOG_DEBUG( + "Waiting for response for corr_id = " << pending_request_corr_id_); } void DeleteSubMenuRequest::DeleteNestedSubMenus(ApplicationSharedPtr const app, - uint32_t parentID, + const uint32_t parentID, const SubMenuMap& subMenus) { SDL_LOG_AUTO_TRACE(); @@ -108,26 +133,26 @@ void DeleteSubMenuRequest::DeleteNestedSubMenus(ApplicationSharedPtr const app, } if (parentID == (*it->second)[strings::parent_id].asUInt()) { - uint32_t menuID = (*it->second)[strings::menu_id].asUInt(); + const uint32_t menuID = (*it->second)[strings::menu_id].asUInt(); DeleteNestedSubMenus(app, menuID, subMenus); - DeleteSubMenuVRCommands(app, menuID); - DeleteSubMenuUICommands(app, menuID); + smart_objects::SmartObject msg_params = smart_objects::SmartObject(smart_objects::SmartType_Map); msg_params[strings::menu_id] = menuID; msg_params[strings::app_id] = app->app_id(); - SendHMIRequest(hmi_apis::FunctionID::UI_DeleteSubMenu, &msg_params); - ++it; - SDL_LOG_DEBUG("Removing submenuID: " << menuID); - app->RemoveSubMenu(menuID); - } else { - ++it; + requests_list_.push_back(msg_params); } + + ++it; } + + SDL_LOG_DEBUG("Delete commands with Parent ID: " << parentID); + DeleteSubMenuVRCommands(app, parentID); + DeleteSubMenuUICommands(app, parentID); } void DeleteSubMenuRequest::DeleteSubMenuVRCommands( - ApplicationConstSharedPtr app, uint32_t parentID) { + ApplicationConstSharedPtr app, const uint32_t parentID) { SDL_LOG_AUTO_TRACE(); const DataAccessor accessor = app->commands_map(); @@ -148,7 +173,7 @@ void DeleteSubMenuRequest::DeleteSubMenuVRCommands( msg_params[strings::grammar_id] = app->get_grammar_id(); msg_params[strings::type] = hmi_apis::Common_VRCommandType::Command; - SendHMIRequest(hmi_apis::FunctionID::VR_DeleteCommand, &msg_params); + requests_list_.push_back(msg_params); } } } @@ -175,16 +200,11 @@ void DeleteSubMenuRequest::DeleteSubMenuUICommands( const uint32_t cmd_id = (*it->second)[strings::cmd_id].asUInt(); msg_params[strings::app_id] = app->app_id(); msg_params[strings::cmd_id] = cmd_id; - SDL_LOG_DEBUG("Removing UI Command: " << cmd_id); - app->RemoveCommand(cmd_id); - app->help_prompt_manager().OnVrCommandDeleted(cmd_id, false); - it = commands.begin(); // Can not relay on - // iterators after erase was called - - SendHMIRequest(hmi_apis::FunctionID::UI_DeleteCommand, &msg_params); - } else { - ++it; + + requests_list_.push_back(msg_params); } + + ++it; } } @@ -193,48 +213,110 @@ void DeleteSubMenuRequest::on_event(const event_engine::Event& event) { const smart_objects::SmartObject& message = event.smart_object(); switch (event.id()) { - case hmi_apis::FunctionID::UI_DeleteSubMenu: { - EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); - hmi_apis::Common_Result::eType result_code = - static_cast( - message[strings::params][hmi_response::code].asInt()); - std::string response_info; - GetInfo(message, response_info); - const bool result = PrepareResultForMobileResponse( - result_code, HmiInterfaces::HMI_INTERFACE_UI); - - ApplicationSharedPtr application = - application_manager_.application(connection_key()); - - if (!application) { - SDL_LOG_ERROR("NULL pointer"); - return; + case hmi_apis::FunctionID::UI_DeleteCommand: { + SDL_LOG_DEBUG("Received UI_DeleteCommand response"); + + const auto corr_id = + message[strings::params][strings::correlation_id].asUInt(); + if (pending_request_corr_id_ == corr_id) { + auto msg_params = requests_list_.front(); + + const auto result_code = static_cast( + message[strings::params][hmi_response::code].asInt()); + + auto app = application_manager_.application(connection_key()); + if (!app) { + SDL_LOG_ERROR("Application not found"); + return; + } + + if (IsHMIResultSuccess(result_code)) { + const auto cmd_id = msg_params[strings::cmd_id].asUInt(); + SDL_LOG_DEBUG("Removing UI Command: " << cmd_id); + app->RemoveCommand(cmd_id); + app->help_prompt_manager().OnVrCommandDeleted(cmd_id, false); + } + + requests_list_.pop_front(); } - if (result) { - // delete sub menu items from SDL and HMI - uint32_t parentID = - (*message_)[strings::msg_params][strings::menu_id].asUInt(); - const DataAccessor accessor = application->sub_menu_map(); - const SubMenuMap& subMenus = accessor.GetData(); - DeleteNestedSubMenus(application, parentID, subMenus); - DeleteSubMenuVRCommands(application, parentID); - DeleteSubMenuUICommands(application, parentID); - application->RemoveSubMenu( - (*message_)[strings::msg_params][strings::menu_id].asInt()); + break; + } + + case hmi_apis::FunctionID::VR_DeleteCommand: { + SDL_LOG_DEBUG("Received VR_DeleteCommand response"); + + const auto corr_id = + message[strings::params][strings::correlation_id].asUInt(); + + if (corr_id == pending_request_corr_id_) { + auto app = application_manager_.application(connection_key()); + if (!app) { + SDL_LOG_ERROR("Application not found"); + return; + } + + requests_list_.pop_front(); } - SendResponse(result, - MessageHelper::HMIToMobileResult(result_code), - response_info.empty() ? NULL : response_info.c_str(), - &(message[strings::msg_params])); break; } + + case hmi_apis::FunctionID::UI_DeleteSubMenu: { + SDL_LOG_DEBUG("Received UI_DeleteSubMenu response"); + + const auto corr_id = + message[strings::params][strings::correlation_id].asUInt(); + if (corr_id == pending_request_corr_id_) { + auto msg_params = requests_list_.front(); + + const auto result_code = static_cast( + message[strings::params][hmi_response::code].asInt()); + + auto app = application_manager_.application(connection_key()); + if (!app) { + SDL_LOG_ERROR("Application not found"); + return; + } + + if (IsHMIResultSuccess(result_code)) { + const auto menu_id = msg_params[strings::menu_id].asUInt(); + SDL_LOG_DEBUG("Removing submenuID: " << menu_id); + app->RemoveSubMenu(menu_id); + } + + requests_list_.pop_front(); + } + + break; + } + default: { SDL_LOG_ERROR("Received unknown event" << event.id()); return; } } + + if (!requests_list_.empty()) { + SDL_LOG_DEBUG("Still waiting for another requests"); + SendNextRequest(); + return; + } + + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); + + hmi_apis::Common_Result::eType result_code = + static_cast( + message[strings::params][hmi_response::code].asInt()); + std::string response_info; + GetInfo(message, response_info); + const bool result = PrepareResultForMobileResponse( + result_code, HmiInterfaces::HMI_INTERFACE_UI); + + SendResponse(result, + MessageHelper::HMIToMobileResult(result_code), + response_info.empty() ? NULL : response_info.c_str(), + &(message[strings::msg_params])); } bool DeleteSubMenuRequest::Init() { diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_sub_menu_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_sub_menu_test.cc index f5856a8eda4..975cba89a1e 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_sub_menu_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_sub_menu_test.cc @@ -67,6 +67,7 @@ using sdl_rpc_plugin::commands::DeleteSubMenuResponse; typedef std::shared_ptr DeleteSubMenuRequestPtr; typedef std::shared_ptr DeleteSubMenuResponsePtr; +typedef std::shared_ptr EventPtr; MATCHER_P(CheckMessageResultCode, result_code, "") { return (*arg)[am::strings::msg_params][am::strings::result_code].asInt() == @@ -89,8 +90,9 @@ namespace { const uint32_t kConnectionKey = 2u; const uint32_t kCorrelationId = 10u; const uint32_t kMenuId = 100u; +const uint32_t kMenuIdChild = 101u; const uint32_t kGrammarId = 101u; -const int32_t kCmdId = 102; +const int32_t kCmdId = 102u; } // namespace class DeleteSubMenuRequestTest @@ -107,6 +109,224 @@ class DeleteSubMenuRequestTest std::make_shared()) , app_(CreateMockApp()) {} + /** + * @brief Generates submenu smart object with specified params + * @param menu_id id of the menu + * @param parent_id id of parent menu + * @return generated smart object + */ + smart_objects::SmartObjectSPtr GenerateSubMenuMap(const uint32_t menu_id, + const uint32_t parent_id) { + smart_objects::SmartObjectSPtr smartObjectPtr = + std::make_shared(); + + smart_objects::SmartObject& object = *smartObjectPtr; + + object[am::strings::position] = 1; + object[am::strings::menu_name] = "SubMenu " + std::to_string(menu_id); + object[am::strings::menu_id] = menu_id; + object[am::strings::parent_id] = parent_id; + + return smartObjectPtr; + } + + /** + * @brief Generates UI & VR commands smart object with specified params + * @param cmd_id id of the command + * @param parent_id id of parent command + * @return generated smart object + */ + smart_objects::SmartObjectSPtr GenerateUiVrCommandMapChild( + const uint32_t cmd_id, const uint32_t parent_id) { + smart_objects::SmartObjectSPtr smartObjectPtr = + std::make_shared(); + + smart_objects::SmartObject& object = *smartObjectPtr; + + object[am::strings::cmd_id] = cmd_id; + object[am::strings::grammar_id] = kGrammarId; + object[am::strings::vr_commands] = "VR commands"; + object[am::strings::type] = hmi_apis::Common_VRCommandType::Command; + object[am::strings::menu_params][am::hmi_request::parent_id] = parent_id; + + return smartObjectPtr; + } + + /** + * @brief Sets up expectations for a successful execution of submenu request + * @param next_function_id function id of the next request + */ + void SetUpSubMenuRequestExpectations( + const hmi_apis::FunctionID::eType next_function_id) { + (*message_)[am::strings::msg_params][am::strings::menu_id] = kMenuId; + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*message_)[am::strings::params][am::strings::function_id] = + next_function_id; + + smart_objects::SmartObject sub_menu = + (*message_)[am::strings::msg_params][am::strings::menu_id]; + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app_)); + EXPECT_CALL(*app_, FindSubMenu(kMenuId)).WillOnce(Return(sub_menu)); + + ON_CALL(*app_, sub_menu_map()).WillByDefault(Return(sub_menu_accessor_)); + ON_CALL(*app_, commands_map()).WillByDefault(Return(accessor_)); + + EXPECT_CALL(*app_, app_id()).WillRepeatedly(Return(kConnectionKey)); + EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillOnce(Return(kCorrelationId)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(next_function_id), _)) + .WillOnce(Return(true)); + } + + /** + * @brief Prepares submenu response event with the specified params + * @param correlation_id correlation id + * @param menu_id id of the menu + * @return pointer to prepared event + */ + EventPtr PrepareSubMenuResponseEvent(const uint32_t correlation_id, + const uint32_t menu_id) { + EventPtr menu_event = + std::make_shared(hmi_apis::FunctionID::UI_DeleteSubMenu); + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*message_)[am::strings::msg_params][am::strings::app_id] = kConnectionKey; + (*message_)[am::strings::params][am::strings::correlation_id] = + correlation_id; + (*message_)[am::strings::msg_params][am::strings::menu_id] = menu_id; + menu_event->set_smart_object(*message_); + + return menu_event; + } + + /** + * @brief Sets up expectations for a successful execution of submenu + * subsequent response + * @param event pointer to event representing the response message + * @param next_function_id function id of the next request + */ + void SetUpSubMenuSubsequentResponseExpectations( + EventPtr event, hmi_apis::FunctionID::eType next_function_id) { + const auto& event_so_ref = event->smart_object(); + const auto correlation_id = event->smart_object_correlation_id(); + const auto menu_id = + event_so_ref[am::strings::msg_params][am::strings::menu_id].asUInt(); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app_)); + EXPECT_CALL(*app_, RemoveSubMenu(menu_id)); + + EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillOnce(Return(correlation_id + 1)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(next_function_id), _)) + .WillOnce(Return(true)); + } + + /** + * @brief Prepares VR command response event with the specified params + * @param correlation_id correlation id + * @return pointer to prepared event + */ + EventPtr PrepareVrCommandResponseEvent(const uint32_t correlation_id) { + EventPtr vr_event = + std::make_shared(hmi_apis::FunctionID::VR_DeleteCommand); + (*message_)[am::strings::msg_params][am::strings::app_id] = kConnectionKey; + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*message_)[am::strings::params][am::strings::correlation_id] = + correlation_id; + vr_event->set_smart_object(*message_); + + return vr_event; + } + + /** + * @brief Sets up expectations for a successful execution of VR command + * subsequent response + * @param event pointer to event representing the response message + * @param next_function_id function id of the next request + */ + void SetUpVrCommandSubsequentResponseExpectations( + EventPtr event, hmi_apis::FunctionID::eType next_function_id) { + const auto correlation_id = event->smart_object_correlation_id(); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app_)); + EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillOnce(Return(correlation_id + 1)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(next_function_id), _)) + .WillOnce(Return(true)); + } + + /** + * @brief Prepares UI command response event with the specified params + * @param correlation_id correlation id + * @param cmd_id id of the command + * @return pointer to prepared event + */ + EventPtr PrepareUiCommandResponseEvent(const uint32_t correlation_id, + const uint32_t cmd_id) { + EventPtr ui_event = + std::make_shared(hmi_apis::FunctionID::UI_DeleteCommand); + (*message_)[am::strings::params][am::strings::correlation_id] = + correlation_id; + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*message_)[am::strings::msg_params][am::strings::app_id] = kConnectionKey; + (*message_)[am::strings::msg_params][am::strings::cmd_id] = cmd_id; + ui_event->set_smart_object(*message_); + + return ui_event; + } + + /** + * @brief Sets up expectations for a successful execution of UI command + * subsequent response + * @param event pointer to event representing the response message + * @param next_function_id function id of the next request + */ + void SetUpUiCommandSubsequentResponseExpectations( + EventPtr event, hmi_apis::FunctionID::eType next_function_id) { + const auto correlation_id = event->smart_object_correlation_id(); + const auto& event_so_ref = event->smart_object(); + const auto cmd_id = + event_so_ref[am::strings::msg_params][am::strings::cmd_id].asUInt(); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app_)); + EXPECT_CALL(*app_, RemoveCommand(cmd_id)) + .WillOnce(DeleteCommand(&commands_map_)); + EXPECT_CALL(*app_, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_)); + EXPECT_CALL(*mock_help_prompt_manager_, OnVrCommandDeleted(cmd_id, false)); + + EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillOnce(Return(correlation_id + 1)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(next_function_id), _)) + .WillOnce(Return(true)); + } + + /** + * @brief Sets up expectations for a successful execution of submenu final + * response + * @param event pointer to event representing the response message + */ + void SetUpSubMenuFinalResponseExpectations(EventPtr event) { + const auto& event_so_ref = event->smart_object(); + const auto menu_id = + event_so_ref[am::strings::msg_params][am::strings::menu_id].asUInt(); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app_)); + EXPECT_CALL(*app_, RemoveSubMenu(menu_id)); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), + am::commands::Command::SOURCE_SDL)); + } + am::CommandsMap commands_map_; am::SubMenuMap sub_menu_map_; mutable std::shared_ptr commands_lock_; @@ -215,175 +435,187 @@ TEST_F(DeleteSubMenuRequestTest, Run_FindSubMenuFalse_UNSUCCESS) { command_->Run(); } -TEST_F(DeleteSubMenuRequestTest, Run_SendHMIRequest_SUCCESS) { - (*message_)[am::strings::msg_params][am::strings::menu_id] = kMenuId; - (*message_)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - smart_objects::SmartObject sub_menu = - (*message_)[am::strings::msg_params][am::strings::menu_id]; - EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app_)); - EXPECT_CALL(*app_, FindSubMenu(kMenuId)).WillOnce(Return(sub_menu)); - - EXPECT_CALL(*app_, app_id()).WillOnce(Return(kConnectionKey)); - EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillOnce(Return(kCorrelationId)); - - EXPECT_CALL(mock_rpc_service_, - ManageHMICommand( - HMIResultCodeIs(hmi_apis::FunctionID::UI_DeleteSubMenu), _)) - .WillOnce(Return(true)); - command_->Run(); -} - TEST_F(DeleteSubMenuRequestTest, OnEvent_UnknownEventId_UNSUCCESS) { Event event(hmi_apis::FunctionID::INVALID_ENUM); - EXPECT_CALL(app_mngr_, application(_)).Times(0); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::SOURCE_SDL)) + .Times(0); command_->on_event(event); } TEST_F(DeleteSubMenuRequestTest, OnEvent_InvalidApp_UNSUCCESS) { - Event event(hmi_apis::FunctionID::UI_DeleteSubMenu); - (*message_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::eType::SUCCESS; - event.set_smart_object(*message_); + auto sub_menu_ptr = GenerateSubMenuMap(kMenuId, 0); + sub_menu_map_.insert(std::pair( + kMenuId, sub_menu_ptr.get())); + + SetUpSubMenuRequestExpectations(hmi_apis::FunctionID::UI_DeleteSubMenu); + command_->Run(); + MockAppPtr invalid_app; + EventPtr event = PrepareSubMenuResponseEvent(kCorrelationId, kMenuId); + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(invalid_app)); EXPECT_CALL(*app_, RemoveSubMenu(_)).Times(0); - command_->on_event(event); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::SOURCE_SDL)) + .Times(0); + + command_->on_event(*event); } -TEST_F(DeleteSubMenuRequestTest, OnEvent_DeleteSubmenu_SUCCESS) { - Event event(hmi_apis::FunctionID::UI_DeleteSubMenu); - (*message_)[am::strings::msg_params][am::strings::menu_id] = kMenuId; - (*message_)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - (*message_)[am::strings::msg_params][am::strings::vr_commands] = - "vr_commands"; - (*message_)[am::strings::msg_params][am::strings::cmd_id] = kCmdId; - (*message_)[am::strings::msg_params][am::strings::menu_params] - [am::hmi_request::parent_id] = kMenuId; - const hmi_apis::Common_Result::eType result_code = - hmi_apis::Common_Result::SUCCESS; - (*message_)[am::strings::params][am::hmi_response::code] = result_code; - event.set_smart_object(*message_); +TEST_F(DeleteSubMenuRequestTest, OnEvent_DeleteSubmenuOnly_SUCCESS) { + auto sub_menu_ptr = GenerateSubMenuMap(kMenuId, 0); + sub_menu_map_.insert(std::pair( + kMenuId, sub_menu_ptr.get())); - commands_map_.insert( - std::make_pair(0, &((*message_)[am::strings::msg_params]))); + SetUpSubMenuRequestExpectations(hmi_apis::FunctionID::UI_DeleteSubMenu); + command_->Run(); - smart_objects::SmartObjectSPtr smartObjectPtr = - std::make_shared(); + EventPtr event = PrepareSubMenuResponseEvent(kCorrelationId, kMenuId); + SetUpSubMenuFinalResponseExpectations(event); + command_->on_event(*event); +} - smart_objects::SmartObject& object = *smartObjectPtr; +TEST_F(DeleteSubMenuRequestTest, OnEvent_DeleteSubmenuWithChildMenu_SUCCESS) { + auto sub_menu_ptr = GenerateSubMenuMap(kMenuId, 0); + sub_menu_map_.insert(std::pair( + kMenuId, sub_menu_ptr.get())); - object[am::strings::position] = 1; - object[am::strings::menu_name] = "SubMenu"; + auto sub_menu_child_ptr = GenerateSubMenuMap(kMenuIdChild, kMenuId); + sub_menu_map_.insert(std::pair( + kMenuIdChild, sub_menu_child_ptr.get())); - sub_menu_map_.insert( - std::pair(5, &object)); - EXPECT_CALL(*app_, sub_menu_map()).WillRepeatedly(Return(sub_menu_accessor_)); - EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app_)); + SetUpSubMenuRequestExpectations(hmi_apis::FunctionID::UI_DeleteSubMenu); + command_->Run(); - InSequence seq; - EXPECT_CALL(*app_, commands_map()).WillOnce(Return(accessor_)); - EXPECT_CALL(*app_, app_id()).WillOnce(Return(kConnectionKey)); - EXPECT_CALL(*app_, get_grammar_id()).WillOnce(Return(kGrammarId)); + EventPtr event = PrepareSubMenuResponseEvent(kCorrelationId, kMenuIdChild); + SetUpSubMenuSubsequentResponseExpectations( + event, hmi_apis::FunctionID::UI_DeleteSubMenu); + command_->on_event(*event); - EXPECT_CALL(mock_rpc_service_, - ManageHMICommand( - HMIResultCodeIs(hmi_apis::FunctionID::VR_DeleteCommand), _)) - .WillOnce(Return(true)); - - EXPECT_CALL(*app_, commands_map()).WillOnce(Return(accessor_)); - EXPECT_CALL(*app_, app_id()).WillOnce(Return(kConnectionKey)); - EXPECT_CALL(*app_, RemoveCommand(_)).WillOnce(DeleteCommand(&commands_map_)); - EXPECT_CALL(*app_, help_prompt_manager()) - .WillOnce(ReturnRef(*mock_help_prompt_manager_)); - EXPECT_CALL(*mock_help_prompt_manager_, OnVrCommandDeleted(kCmdId, false)); - EXPECT_CALL(mock_rpc_service_, - ManageHMICommand( - HMIResultCodeIs(hmi_apis::FunctionID::UI_DeleteCommand), _)) - .WillOnce(Return(true)); + EventPtr event_final = + PrepareSubMenuResponseEvent(kCorrelationId + 1, kMenuId); + SetUpSubMenuFinalResponseExpectations(event_final); + command_->on_event(*event_final); +} - EXPECT_CALL(*app_, RemoveSubMenu(_)); - EXPECT_CALL( - mock_rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), - am::commands::Command::SOURCE_SDL)); - EXPECT_CALL(*app_, UpdateHash()); +TEST_F(DeleteSubMenuRequestTest, OnEvent_DeleteSubmenuWithVrAndUi_SUCCESS) { + auto sub_menu_ptr = GenerateSubMenuMap(kMenuId, 0); + sub_menu_map_.insert(std::pair( + kMenuId, sub_menu_ptr.get())); - DeleteSubMenuRequestPtr command = - CreateCommand(message_); + auto command_ptr = GenerateUiVrCommandMapChild(kCmdId, kMenuId); + commands_map_.insert(std::pair( + kCmdId, command_ptr.get())); - command->Init(); - command->on_event(event); -} + SetUpSubMenuRequestExpectations(hmi_apis::FunctionID::VR_DeleteCommand); + command_->Run(); -TEST_F(DeleteSubMenuResponseTest, Run_SUCCESS) { - MessageSharedPtr message(CreateMessage()); - (*message)[am::strings::msg_params][am::strings::connection_key] = - kConnectionKey; - DeleteSubMenuResponsePtr command( - CreateCommand(message)); + EventPtr event_vr = PrepareVrCommandResponseEvent(kCorrelationId); + SetUpVrCommandSubsequentResponseExpectations( + event_vr, hmi_apis::FunctionID::UI_DeleteCommand); + command_->on_event(*event_vr); - EXPECT_CALL( - mock_rpc_service_, - SendMessageToMobile(CheckMessageConnectionKey(kConnectionKey), _)); - command->Run(); + EventPtr event_ui = PrepareUiCommandResponseEvent(kCorrelationId + 1, kCmdId); + SetUpUiCommandSubsequentResponseExpectations( + event_ui, hmi_apis::FunctionID::UI_DeleteSubMenu); + command_->on_event(*event_ui); + + EventPtr event_final = + PrepareSubMenuResponseEvent(kCorrelationId + 2, kMenuId); + SetUpSubMenuFinalResponseExpectations(event_final); + command_->on_event(*event_final); } TEST_F(DeleteSubMenuRequestTest, - DeleteSubmenu_CommandhaventVrCommadsAndMenuParams_DontSendHMIRequest) { - Event event(hmi_apis::FunctionID::UI_DeleteSubMenu); - (*message_)[am::strings::msg_params][am::strings::menu_id] = kMenuId; - (*message_)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - (*message_)[am::strings::params][am::hmi_response::code] = - am::mobile_api::Result::SUCCESS; - event.set_smart_object(*message_); + OnEvent_DeleteSubmenuWithChildVrAndUi_SUCCESS) { + auto sub_menu_ptr = GenerateSubMenuMap(kMenuId, 0); + sub_menu_map_.insert(std::pair( + kMenuId, sub_menu_ptr.get())); - commands_map_.insert( - std::make_pair(0, &((*message_)[am::strings::msg_params]))); + auto sub_menu_child_ptr = GenerateSubMenuMap(kMenuIdChild, kMenuId); + sub_menu_map_.insert(std::pair( + kMenuIdChild, sub_menu_child_ptr.get())); - EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app_)); - EXPECT_CALL(*app_, sub_menu_map()).WillRepeatedly(Return(sub_menu_accessor_)); - EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)).Times(0); - EXPECT_CALL(*app_, commands_map()).Times(2).WillRepeatedly(Return(accessor_)); - EXPECT_CALL(*app_, RemoveCommand(_)).Times(0); + auto command_ptr = GenerateUiVrCommandMapChild(kCmdId, kMenuIdChild); + commands_map_.insert(std::pair( + kCmdId, command_ptr.get())); - EXPECT_CALL( - mock_rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), - am::commands::Command::SOURCE_SDL)); - command_->on_event(event); + SetUpSubMenuRequestExpectations(hmi_apis::FunctionID::VR_DeleteCommand); + command_->Run(); + + EventPtr event_vr = PrepareVrCommandResponseEvent(kCorrelationId); + SetUpVrCommandSubsequentResponseExpectations( + event_vr, hmi_apis::FunctionID::UI_DeleteCommand); + command_->on_event(*event_vr); + + EventPtr event_ui = PrepareUiCommandResponseEvent(kCorrelationId + 1, kCmdId); + SetUpUiCommandSubsequentResponseExpectations( + event_ui, hmi_apis::FunctionID::UI_DeleteSubMenu); + command_->on_event(*event_ui); + + EventPtr event_submenu = + PrepareSubMenuResponseEvent(kCorrelationId + 2, kMenuIdChild); + SetUpSubMenuSubsequentResponseExpectations( + event_submenu, hmi_apis::FunctionID::UI_DeleteSubMenu); + command_->on_event(*event_submenu); + + EventPtr event_final = + PrepareSubMenuResponseEvent(kCorrelationId + 3, kMenuId); + SetUpSubMenuFinalResponseExpectations(event_final); + command_->on_event(*event_final); } TEST_F(DeleteSubMenuRequestTest, - DeleteSubmenu_NotAChildOfMenupartam_DontSendHMIRequest) { - Event event(hmi_apis::FunctionID::UI_DeleteSubMenu); - (*message_)[am::strings::msg_params][am::strings::menu_id] = kMenuId; - (*message_)[am::strings::msg_params][am::strings::menu_params] - [am::hmi_request::parent_id] = kMenuId + 1; - (*message_)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - (*message_)[am::strings::params][am::hmi_response::code] = - am::mobile_api::Result::SUCCESS; - event.set_smart_object(*message_); + OnEvent_DeleteSubmenuVrAndUiWithChild_SUCCESS) { + auto sub_menu_ptr = GenerateSubMenuMap(kMenuId, 0); + sub_menu_map_.insert(std::pair( + kMenuId, sub_menu_ptr.get())); - commands_map_.insert( - std::make_pair(0, &((*message_)[am::strings::msg_params]))); + auto command_ptr = GenerateUiVrCommandMapChild(kCmdId, kMenuId); + commands_map_.insert(std::pair( + kCmdId, command_ptr.get())); - EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app_)); - EXPECT_CALL(*app_, sub_menu_map()).WillRepeatedly(Return(sub_menu_accessor_)); - EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)).Times(0); - EXPECT_CALL(*app_, commands_map()).Times(2).WillRepeatedly(Return(accessor_)); - EXPECT_CALL(*app_, RemoveCommand(_)).Times(0); + auto sub_menu_child_ptr = GenerateSubMenuMap(kMenuIdChild, kMenuId); + sub_menu_map_.insert(std::pair( + kMenuIdChild, sub_menu_child_ptr.get())); + + SetUpSubMenuRequestExpectations(hmi_apis::FunctionID::UI_DeleteSubMenu); + command_->Run(); + + EventPtr event_submenu = + PrepareSubMenuResponseEvent(kCorrelationId, kMenuIdChild); + SetUpSubMenuSubsequentResponseExpectations( + event_submenu, hmi_apis::FunctionID::VR_DeleteCommand); + command_->on_event(*event_submenu); + + EventPtr event_vr = PrepareVrCommandResponseEvent(kCorrelationId + 1); + SetUpVrCommandSubsequentResponseExpectations( + event_vr, hmi_apis::FunctionID::UI_DeleteCommand); + command_->on_event(*event_vr); + + EventPtr event_ui = PrepareUiCommandResponseEvent(kCorrelationId + 2, kCmdId); + SetUpUiCommandSubsequentResponseExpectations( + event_ui, hmi_apis::FunctionID::UI_DeleteSubMenu); + command_->on_event(*event_ui); + + EventPtr event_final = + PrepareSubMenuResponseEvent(kCorrelationId + 3, kMenuId); + SetUpSubMenuFinalResponseExpectations(event_final); + command_->on_event(*event_final); +} + +TEST_F(DeleteSubMenuResponseTest, Run_SUCCESS) { + MessageSharedPtr message(CreateMessage()); + (*message)[am::strings::msg_params][am::strings::connection_key] = + kConnectionKey; + DeleteSubMenuResponsePtr command( + CreateCommand(message)); EXPECT_CALL( mock_rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), - am::commands::Command::SOURCE_SDL)); - command_->on_event(event); + SendMessageToMobile(CheckMessageConnectionKey(kConnectionKey), _)); + command->Run(); } } // namespace delete_sub_menu_request From 50457915a4081e8c135d6a400eb30330f0d37c9d Mon Sep 17 00:00:00 2001 From: "Andrii Kalinich (GitHub)" Date: Wed, 11 Aug 2021 09:12:02 -0400 Subject: [PATCH 11/14] Remove dependency between optional params in OnRemoteControlSettings (#3749) * Removed dependence on allowed when updating accessMode * Update src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_on_remote_control_settings_notification.cc Co-authored-by: Shobhit Adlakha Co-authored-by: Roman Reznichenko Co-authored-by: Shobhit Adlakha --- ...on_remote_control_settings_notification.cc | 37 +++++++++---------- .../on_remote_control_settings_test.cc | 5 ++- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_on_remote_control_settings_notification.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_on_remote_control_settings_notification.cc index 217258b0869..860e18a1052 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_on_remote_control_settings_notification.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_on_remote_control_settings_notification.cc @@ -87,35 +87,34 @@ void RCOnRemoteControlSettingsNotification::DisallowRCFunctionality() { void RCOnRemoteControlSettingsNotification::Run() { SDL_LOG_AUTO_TRACE(); - if (!(*message_)[app_mngr::strings::msg_params].keyExists( - message_params::kAllowed)) { - SDL_LOG_DEBUG("Notification is ignored due to \"allow\" parameter absense"); + if ((*message_)[app_mngr::strings::msg_params].empty()) { + SDL_LOG_DEBUG("Notification is ignored due to absence of any parameters"); SDL_LOG_DEBUG("RC Functionality remains unchanged"); return; } + hmi_apis::Common_RCAccessMode::eType access_mode = + hmi_apis::Common_RCAccessMode::INVALID_ENUM; + if ((*message_)[app_mngr::strings::msg_params].keyExists( + message_params::kAccessMode)) { + access_mode = static_cast( + (*message_)[app_mngr::strings::msg_params][message_params::kAccessMode] + .asUInt()); + SDL_LOG_DEBUG( + "Setting up access mode : " << AccessModeToString(access_mode)); + } else { + access_mode = resource_allocation_manager_.GetAccessMode(); + SDL_LOG_DEBUG("No access mode received. Using last known: " + << AccessModeToString(access_mode)); + } + resource_allocation_manager_.SetAccessMode(access_mode); + const bool is_allowed = (*message_)[app_mngr::strings::msg_params][message_params::kAllowed] .asBool(); if (is_allowed) { - hmi_apis::Common_RCAccessMode::eType access_mode = - hmi_apis::Common_RCAccessMode::INVALID_ENUM; SDL_LOG_DEBUG("Allowing RC Functionality"); resource_allocation_manager_.set_rc_enabled(true); - if ((*message_)[app_mngr::strings::msg_params].keyExists( - message_params::kAccessMode)) { - access_mode = static_cast( - (*message_)[app_mngr::strings::msg_params] - [message_params::kAccessMode] - .asUInt()); - SDL_LOG_DEBUG( - "Setting up access mode : " << AccessModeToString(access_mode)); - } else { - access_mode = resource_allocation_manager_.GetAccessMode(); - SDL_LOG_DEBUG("No access mode received. Using last known: " - << AccessModeToString(access_mode)); - } - resource_allocation_manager_.SetAccessMode(access_mode); } else { SDL_LOG_DEBUG("Disallowing RC Functionality"); DisallowRCFunctionality(); diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/on_remote_control_settings_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/on_remote_control_settings_test.cc index 62b726ac601..7907013fa37 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/on_remote_control_settings_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/on_remote_control_settings_test.cc @@ -145,9 +145,10 @@ TEST_F(RCOnRemoteControlSettingsNotificationTest, MessageSharedPtr mobile_message = CreateBasicMessage(); (*mobile_message)[application_manager::strings::msg_params] [message_params::kAllowed] = false; - - EXPECT_CALL(mock_allocation_manager_, ResetAllAllocations()); + ON_CALL(mock_allocation_manager_, GetAccessMode()) + .WillByDefault(Return(hmi_apis::Common_RCAccessMode::ASK_DRIVER)); EXPECT_CALL(mock_interior_data_manager_, OnDisablingRC()); + EXPECT_CALL(mock_allocation_manager_, ResetAllAllocations()); EXPECT_CALL(mock_rc_consent_manger_, RemoveAllConsents()); // Act From 253280549e45ed726cce9246682fe09263ef5525 Mon Sep 17 00:00:00 2001 From: "Yana Chernysheva (GitHub)" <59469418+ychernysheva@users.noreply.github.com> Date: Wed, 11 Aug 2021 19:56:55 +0300 Subject: [PATCH 12/14] [SDL-0189] Restructuring OnResetTimeout (#3726) * Add Reset Timeout Handler, remove deprecated functionality, create Request Controller interface. * fixup! Add Reset Timeout Handler, remove deprecated functionality, create Request Controller interface. * Fix compilation errors after merge of develop branch * Remove deprecated functions from SubtleAlert request and remove redundant UTs * Add changes to HMI API * Increase timeout in case if SIVD need Consent popup * Increase timeout for ButtonPress request * Restrict timeout for Subtle Alert with soft buttons * update timeout for hmi request * careful stopping of the request controller * Fix OnResetTimeout for Alerts with soft buttons (#192) * Do not manage requests with NULL timeout * Revert double timeouts from core * Apply smaller timeout to requests * Address Livio comments * Add timeout compensation parameter Update default timeout logic accordingly for all commands. Added new file to ini file. * Fix affected unit tests * Address Livio comments * Update rpc_spec * Update rpc_spec one more time Co-authored-by: Yevhenii Co-authored-by: Yevhenii Co-authored-by: Vadym Luchko (gitHub) Co-authored-by: Vadym Luchko (GitHub) <76956836+VadymLuchko@users.noreply.github.com> Co-authored-by: Dmytro Boltovskyi (GitHub) Co-authored-by: Andrii Kalinich --- src/appMain/smartDeviceLink.ini | 2 + .../application_manager_impl.h | 25 +- .../commands/command_request_impl.h | 7 + ...controller.h => request_controller_impl.h} | 179 +++------- .../application_manager/request_info.h | 6 +- .../request_timeout_handler_impl.h | 75 +++++ .../application_manager/smart_object_keys.h | 4 + .../commands/hmi/dummy_hmi_commands_test.cc | 8 +- .../mobile/dummy_mobile_commands_test.cc | 8 +- .../resource_allocation_manager.h | 13 + .../resource_allocation_manager_impl.h | 4 + .../src/commands/rc_command_request.cc | 5 + .../src/resource_allocation_manager_impl.cc | 22 ++ .../commands/button_press_request_test.cc | 2 + ..._get_interior_vehicle_data_consent_test.cc | 15 +- .../set_interior_vehicle_data_request_test.cc | 2 + .../mock/mock_resource_allocation_manager.h | 4 + ...tion.h => on_reset_timeout_notification.h} | 20 +- .../hmi/on_tts_reset_timeout_notification.h | 83 ----- .../hmi/navi_audio_start_stream_request.cc | 6 +- .../commands/hmi/navi_start_stream_request.cc | 6 +- ...on.cc => on_reset_timeout_notification.cc} | 12 +- .../commands/hmi/sdl_activate_app_request.cc | 4 +- .../commands/mobile/alert_maneuver_request.cc | 10 +- .../src/commands/mobile/alert_request.cc | 17 +- .../create_interaction_choice_set_request.cc | 2 +- .../commands/mobile/get_way_points_request.cc | 10 +- .../mobile/perform_audio_pass_thru_request.cc | 12 +- .../mobile/perform_interaction_request.cc | 15 +- .../mobile/scrollable_message_request.cc | 10 +- .../src/commands/mobile/slider_request.cc | 13 +- .../src/commands/mobile/speak_request.cc | 10 +- .../commands/mobile/subtle_alert_request.cc | 17 +- .../sdl_rpc_plugin/src/hmi_command_factory.cc | 10 +- .../commands/hmi/dummy_hmi_commands_test.cc | 14 +- .../commands/hmi/hmi_notifications_test.cc | 34 +- .../hmi/sdl_activate_app_request_test.cc | 5 +- .../commands/mobile/alert_request_test.cc | 21 -- .../create_interaction_choice_set_test.cc | 14 +- .../mobile/dummy_mobile_commands_test.cc | 8 +- .../mobile/get_way_points_request_test.cc | 2 +- .../mobile/perform_audio_pass_thru_test.cc | 32 +- .../register_app_interface_request_test.cc | 3 + .../mobile/scrollable_message_test.cc | 24 +- .../test/commands/mobile/slider_test.cc | 16 - .../commands/mobile/speak_request_test.cc | 12 - .../commands/vi_commands_test.h | 9 +- .../src/application_manager_impl.cc | 41 +-- .../src/commands/command_impl.cc | 4 +- .../src/commands/command_request_impl.cc | 51 ++- .../src/commands/request_from_hmi.cc | 4 +- .../src/hmi_interfaces_impl.cc | 4 +- ...ntroller.cc => request_controller_impl.cc} | 182 +++++++---- .../application_manager/src/request_info.cc | 20 +- .../src/request_timeout_handler_impl.cc | 122 +++++++ .../src/rpc_service_impl.cc | 19 +- .../src/smart_object_keys.cc | 4 + .../application_manager/test/CMakeLists.txt | 1 + .../test/commands/command_impl_test.cc | 4 +- .../test/help_prompt_manager_test.cc | 3 + .../commands/command_request_test.h | 7 +- .../commands/commands_test.h | 14 +- .../message_helper/message_helper_test.cc | 3 +- .../request_controller_test.cc | 34 +- .../test/request_timeout_handler_test.cc | 306 ++++++++++++++++++ .../test/rpc_service_impl_test.cc | 9 +- .../test/zero_request_amount_test.cc | 18 +- .../include/config_profile/profile.h | 7 + src/components/config_profile/src/profile.cc | 17 + .../application_manager/application_manager.h | 13 +- .../application_manager_settings.h | 1 + .../application_manager/request_controller.h | 194 +++++++++++ .../request_timeout_handler.h | 85 +++++ .../mock_application_manager.h | 8 +- .../mock_application_manager_settings.h | 1 + .../mock_request_controller.h | 87 +++++ .../mock_request_timeout_handler.h} | 54 ++-- src/components/interfaces/HMI_API.xml | 42 +-- tools/rpc_spec | 2 +- 79 files changed, 1471 insertions(+), 722 deletions(-) rename src/components/application_manager/include/application_manager/{request_controller.h => request_controller_impl.h} (56%) create mode 100644 src/components/application_manager/include/application_manager/request_timeout_handler_impl.h rename src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/{on_ui_reset_timeout_notification.h => on_reset_timeout_notification.h} (81%) delete mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_tts_reset_timeout_notification.h rename src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/{on_ui_reset_timeout_notification.cc => on_reset_timeout_notification.cc} (88%) rename src/components/application_manager/src/{request_controller.cc => request_controller_impl.cc} (77%) create mode 100644 src/components/application_manager/src/request_timeout_handler_impl.cc create mode 100644 src/components/application_manager/test/request_timeout_handler_test.cc create mode 100644 src/components/include/application_manager/request_controller.h create mode 100644 src/components/include/application_manager/request_timeout_handler.h create mode 100644 src/components/include/test/application_manager/mock_request_controller.h rename src/components/{application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_tts_reset_timeout_notification.cc => include/test/application_manager/mock_request_timeout_handler.h} (56%) diff --git a/src/appMain/smartDeviceLink.ini b/src/appMain/smartDeviceLink.ini index d19f7ef7a1b..56822db0ef2 100644 --- a/src/appMain/smartDeviceLink.ini +++ b/src/appMain/smartDeviceLink.ini @@ -58,6 +58,8 @@ HMICapabilitiesCacheFile = hmi_capabilities_cache.json MaxCmdID = 2000000000 ; SDL respond timeout (in milliseconds) in case of HMI has not respond on a mobile request DefaultTimeout = 10000 +; Extra time to compensate default timeout due to external delays +DefaultTimeoutCompensation = 1000 ; Available disk space in bytes for each application file handling ; Default value is 100 MiB AppDirectoryQuota = 104857600 diff --git a/src/components/application_manager/include/application_manager/application_manager_impl.h b/src/components/application_manager/include/application_manager/application_manager_impl.h index a8a41bc23a6..09f2c7d4df7 100644 --- a/src/components/application_manager/include/application_manager/application_manager_impl.h +++ b/src/components/application_manager/include/application_manager/application_manager_impl.h @@ -53,7 +53,6 @@ #include "application_manager/hmi_interfaces_impl.h" #include "application_manager/message.h" #include "application_manager/message_helper.h" -#include "application_manager/request_controller.h" #include "application_manager/resumption/resume_ctrl.h" #include "application_manager/rpc_handler.h" #include "application_manager/rpc_service.h" @@ -781,14 +780,14 @@ class ApplicationManagerImpl * * @param ptr Reference to shared pointer that point on hmi notification */ - void addNotification(const CommandSharedPtr ptr); + void AddNotification(const CommandSharedPtr ptr); /** * @ Add notification to collection * - * @param ptr Reference to shared pointer that point on hmi notification + * @param notification Pointer that points to hmi notification */ - void removeNotification(const commands::Command* notification); + void RemoveNotification(const commands::Command* notification); /** * @ Updates request timeout @@ -797,7 +796,7 @@ class ApplicationManagerImpl * @param mobile_correlation_id Correlation ID of the mobile request * @param new_timeout_value New timeout in milliseconds to be set */ - void updateRequestTimeout(uint32_t connection_key, + void UpdateRequestTimeout(uint32_t connection_key, uint32_t mobile_correlation_id, uint32_t new_timeout_value) OVERRIDE; @@ -986,6 +985,18 @@ class ApplicationManagerImpl return *rpc_handler_; } + request_controller::RequestTimeoutHandler& get_request_timeout_handler() + const OVERRIDE { + DCHECK(request_timeout_handler_); + return *request_timeout_handler_; + } + + request_controller::RequestController& get_request_controller() + const OVERRIDE { + DCHECK(request_ctrl_); + return *request_ctrl_; + } + void SetRPCService(std::unique_ptr& rpc_service) { rpc_service_ = std::move(rpc_service); } @@ -1589,8 +1600,10 @@ class ApplicationManagerImpl connection_handler::ConnectionHandler* connection_handler_; std::unique_ptr policy_handler_; protocol_handler::ProtocolHandler* protocol_handler_; + std::unique_ptr + request_timeout_handler_; + std::unique_ptr request_ctrl_; std::unique_ptr plugin_manager_; - request_controller::RequestController request_ctrl_; std::unique_ptr app_service_manager_; /** diff --git a/src/components/application_manager/include/application_manager/commands/command_request_impl.h b/src/components/application_manager/include/application_manager/commands/command_request_impl.h index 084340ad08e..727863d16d7 100644 --- a/src/components/application_manager/include/application_manager/commands/command_request_impl.h +++ b/src/components/application_manager/include/application_manager/commands/command_request_impl.h @@ -419,6 +419,13 @@ class CommandRequestImpl : public CommandImpl, */ void AddTimeOutComponentInfoToMessage( smart_objects::SmartObject& response) const; + /** + * @brief AddRequestToTimeoutHandler checks the request and adds it to + * request_timeout_handler map for tracking + * @param request_to_hmi request to HMI + */ + void AddRequestToTimeoutHandler( + const smart_objects::SmartObject& request_to_hmi) const; }; } // namespace commands diff --git a/src/components/application_manager/include/application_manager/request_controller.h b/src/components/application_manager/include/application_manager/request_controller_impl.h similarity index 56% rename from src/components/application_manager/include/application_manager/request_controller.h rename to src/components/application_manager/include/application_manager/request_controller_impl.h index 8a3c90061ee..7277cdc3fa8 100644 --- a/src/components/application_manager/include/application_manager/request_controller.h +++ b/src/components/application_manager/include/application_manager/request_controller_impl.h @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_REQUEST_CONTROLLER_H_ -#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_REQUEST_CONTROLLER_H_ +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_REQUEST_CONTROLLER_IMPL_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_REQUEST_CONTROLLER_IMPL_H_ #include #include @@ -47,6 +47,7 @@ #include "interfaces/HMI_API.h" #include "interfaces/MOBILE_API.h" +#include "application_manager/request_controller.h" #include "application_manager/request_controller_settings.h" #include "application_manager/request_info.h" #include "application_manager/request_tracker.h" @@ -55,165 +56,60 @@ namespace application_manager { namespace request_controller { -/** - * @brief RequestController class is used to control currently active mobile - * requests. - */ -class RequestController { +class RequestControllerImpl : public RequestController { public: - /** - * @brief Result code for addRequest - */ - enum TResult { - SUCCESS = 0, - TOO_MANY_REQUESTS, - TOO_MANY_PENDING_REQUESTS, - NONE_HMI_LEVEL_MANY_REQUESTS, - INVALID_DATA - }; - - /** - * @brief Thread pool state - */ - enum TPoolState { - UNDEFINED = 0, - STARTED, - STOPPED, - }; - - // Methods - /** * @brief Class constructor * */ - RequestController(const RequestControlerSettings& settings); + RequestControllerImpl(const RequestControlerSettings& settings, + RequestTimeoutHandler& request_timeout_handler); - /** - * @brief Class destructor - * - */ - virtual ~RequestController(); + ~RequestControllerImpl(); - /** - * @brief Initialize thread pool - * - */ - void InitializeThreadpool(); + void Stop() OVERRIDE; - /** - * @brief Destroy thread pool - * - */ - void DestroyThreadpool(); + void InitializeThreadpool() OVERRIDE; - /** - * @brief Check if max request amount wasn't exceed and adds request to queue. - * - * @param request Active mobile request - * @param hmi_level Current application hmi_level - * - * @return Result code - * - */ - TResult addMobileRequest(const RequestPtr request, - const mobile_apis::HMILevel::eType& hmi_level); + void DestroyThreadpool() OVERRIDE; - /** - * @brief Store HMI request until response or timeout won't remove it - * - * @param request Active hmi request - * @return Result code - * - */ - TResult addHMIRequest(const RequestPtr request); + TResult AddMobileRequest( + const RequestPtr request, + const mobile_apis::HMILevel::eType& hmi_level) OVERRIDE; - /** - * @ Add notification to collection - * - * @param ptr Reference to shared pointer that point on hmi notification - */ - void addNotification(const RequestPtr ptr); + TResult AddHMIRequest(const RequestPtr request) OVERRIDE; + + void AddNotification(const RequestPtr ptr) OVERRIDE; - /** - * @brief Removes request from queue - * - * @param correlation_id Active request correlation ID, - * @param connection_key Active request connection key (0 for HMI requersts) - * @param function_id Active request function id - * @param force_terminate if true, request controller will terminate - * even if not allowed by request - */ void TerminateRequest(const uint32_t correlation_id, const uint32_t connection_key, const int32_t function_id, - bool force_terminate = false); + const bool force_terminate = false) OVERRIDE; - /** - * @brief Removes request from queue - * - * @param mobile_correlation_id Active mobile request correlation ID - * - */ void OnMobileResponse(const uint32_t mobile_correlation_id, const uint32_t connection_key, - const int32_t function_id); + const int32_t function_id) OVERRIDE; - /** - * @brief Removes request from queue - * - * @param mobile_correlation_id Active mobile request correlation ID - * - */ - void OnHMIResponse(const uint32_t correlation_id, const int32_t function_id); + void OnHMIResponse(const uint32_t correlation_id, + const int32_t function_id) OVERRIDE; - /** - * @ Add notification to collection - * - * @param ptr Reference to shared pointer that point on hmi notification - */ - void removeNotification(const commands::Command* notification); + void RemoveNotification(const commands::Command* notification) OVERRIDE; - /** - * @brief Removes all requests from queue for specified application - * - * @param app_id Mobile application ID (app_id) - * - */ - void terminateAppRequests(const uint32_t& app_id); + void TerminateAppRequests(const uint32_t app_id) OVERRIDE; - /** - * @brief Terminates all requests from HMI - */ - void terminateAllHMIRequests(); + void TerminateAllHMIRequests() OVERRIDE; - /** - * @brief Terminates all requests from Mobile - */ - void terminateAllMobileRequests(); + void TerminateAllMobileRequests() OVERRIDE; - /** - * @brief Updates request timeout - * - * @param app_id Connection key of application - * @param mobile_correlation_id Correlation ID of the mobile request - * @param new_timeout_value New timeout to be set in milliseconds - */ - void updateRequestTimeout(const uint32_t& app_id, - const uint32_t& mobile_correlation_id, - const uint32_t& new_timeout); + void UpdateRequestTimeout(const uint32_t app_id, + const uint32_t mobile_correlation_id, + const uint32_t new_timeout) OVERRIDE; - /* - * @brief Function Should be called when Low Voltage is occured - */ - void OnLowVoltage(); + void OnLowVoltage() OVERRIDE; - /* - * @brief Function Should be called when Low Voltage is occured - */ - void OnWakeUp(); + void OnWakeUp() OVERRIDE; - bool IsLowVoltage(); + bool IsLowVoltage() OVERRIDE; protected: /** @@ -226,8 +122,8 @@ class RequestController { */ void NotifyTimer(); - void terminateWaitingForExecutionAppRequests(const uint32_t& app_id); - void terminateWaitingForResponseAppRequests(const uint32_t& app_id); + void TerminateWaitingForExecutionAppRequests(const uint32_t app_id); + void TerminateWaitingForResponseAppRequests(const uint32_t app_id); /** * @brief Checks whether all constraints are met before adding of request into @@ -246,19 +142,19 @@ class RequestController { * allowed for all applications * @return True if new request could be added, false otherwise */ - bool CheckPendingRequestsAmount(const uint32_t& pending_requests_amount); + bool CheckPendingRequestsAmount(const uint32_t pending_requests_amount); private: class Worker : public threads::ThreadDelegate { public: - explicit Worker(RequestController* requestController); + explicit Worker(RequestControllerImpl* request_controller); virtual ~Worker(); virtual void threadMain(); virtual void exitThreadMain(); protected: private: - RequestController* request_controller_; + RequestControllerImpl* request_controller_; sync_primitives::Lock thread_lock_; volatile bool stop_flag_; }; @@ -310,11 +206,12 @@ class RequestController { bool is_low_voltage_; const RequestControlerSettings& settings_; - DISALLOW_COPY_AND_ASSIGN(RequestController); + RequestTimeoutHandler& request_timeout_handler_; + DISALLOW_COPY_AND_ASSIGN(RequestControllerImpl); }; } // namespace request_controller } // namespace application_manager -#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_REQUEST_CONTROLLER_H_ +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_REQUEST_CONTROLLER_IMPL_H_ diff --git a/src/components/application_manager/include/application_manager/request_info.h b/src/components/application_manager/include/application_manager/request_info.h index c6cf00caeaa..e3d5dfd4911 100644 --- a/src/components/application_manager/include/application_manager/request_info.h +++ b/src/components/application_manager/include/application_manager/request_info.h @@ -127,7 +127,7 @@ struct RequestInfo { } uint64_t hash(); static uint64_t GenerateHash(uint32_t var1, uint32_t var2); - static uint32_t HmiConnectionKey; + static constexpr uint32_t kHmiConnectionKey = 0; protected: RequestPtr request_; @@ -199,7 +199,7 @@ class RequestInfoSet { * @return founded request or shared_ptr with NULL */ RequestInfoPtr Find(const uint32_t connection_key, - const uint32_t correlation_id); + const uint32_t correlation_id) const; /* * @brief Get request with smalest end_time_ @@ -269,7 +269,7 @@ class RequestInfoSet { TimeSortedRequestInfoSet time_sorted_pending_requests_; HashSortedRequestInfoSet hash_sorted_pending_requests_; - sync_primitives::Lock pending_requests_lock_; + mutable sync_primitives::Lock pending_requests_lock_; }; /** diff --git a/src/components/application_manager/include/application_manager/request_timeout_handler_impl.h b/src/components/application_manager/include/application_manager/request_timeout_handler_impl.h new file mode 100644 index 00000000000..c58d09598f9 --- /dev/null +++ b/src/components/application_manager/include/application_manager/request_timeout_handler_impl.h @@ -0,0 +1,75 @@ +/* + * 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_INCLUDE_APPLICATION_MANAGER_REQUEST_TIMEOUT_HANDLER_IMPL_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_REQUEST_TIMEOUT_HANDLER_IMPL_H_ + +#include +#include "application_manager/application_manager.h" +#include "application_manager/event_engine/event_observer.h" +#include "application_manager/request_timeout_handler.h" + +namespace application_manager { + +namespace request_controller { + +class RequestTimeoutHandlerImpl : public event_engine::EventObserver, + public RequestTimeoutHandler { + public: + RequestTimeoutHandlerImpl(ApplicationManager& application_manager); + void AddRequest(const uint32_t hmi_correlation_id, + const Request& request) OVERRIDE; + void RemoveRequest(const uint32_t hmi_correlation_id) OVERRIDE; + void on_event(const event_engine::Event& event) OVERRIDE; + + private: + /** + * @brief Checks whether specified request timeout should be updated or not + * @param request reference to request structure to check + * @param timeout new timeout to apply + * @param method_name name of method to check + * @return true if timeout update is required for this request, otherwise + * returns false + */ + bool IsTimeoutUpdateRequired(const Request& request, + const uint32_t timeout, + const hmi_apis::FunctionID::eType method_name); + + std::map requests_; + ApplicationManager& application_manager_; + mutable sync_primitives::Lock requests_lock_; +}; + +} // namespace request_controller +} // namespace application_manager + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_REQUEST_TIMEOUT_HANDLER_IMPL_H_ diff --git a/src/components/application_manager/include/application_manager/smart_object_keys.h b/src/components/application_manager/include/application_manager/smart_object_keys.h index 5a79059f1fa..b1b3c5f0002 100644 --- a/src/components/application_manager/include/application_manager/smart_object_keys.h +++ b/src/components/application_manager/include/application_manager/smart_object_keys.h @@ -501,6 +501,10 @@ extern const char* const rect; extern const char* const x; extern const char* const y; extern const char* const preferred_fps; + +// OnResetTimeout +extern const char* const request_id; +extern const char* const reset_period; } // namespace strings namespace hmi_interface { diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc index 4236ac23f93..4e79bad8999 100644 --- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc @@ -92,14 +92,10 @@ class HMICommandsTest : public components::commands_test::CommandRequestTest< typedef Command CommandType; void InitCommand(const uint32_t& timeout) OVERRIDE { + CommandRequestTest::InitCommand(timeout); + stream_retry_.first = 0; stream_retry_.second = 0; - EXPECT_CALL(app_mngr_settings_, default_timeout()) - .WillOnce(ReturnRef(timeout)); - ON_CALL(app_mngr_, event_dispatcher()) - .WillByDefault(ReturnRef(event_dispatcher_)); - ON_CALL(app_mngr_, get_settings()) - .WillByDefault(ReturnRef(app_mngr_settings_)); ON_CALL(app_mngr_settings_, start_stream_retry_amount()) .WillByDefault(ReturnRef(stream_retry_)); } diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/commands/mobile/dummy_mobile_commands_test.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/commands/mobile/dummy_mobile_commands_test.cc index 69bff3ad762..3c70028574a 100644 --- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/commands/mobile/dummy_mobile_commands_test.cc +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/commands/mobile/dummy_mobile_commands_test.cc @@ -88,12 +88,8 @@ class MobileCommandsTest : public components::commands_test::CommandRequestTest< typedef Command CommandType; void InitCommand(const uint32_t& timeout) OVERRIDE { - EXPECT_CALL(app_mngr_settings_, default_timeout()) - .WillOnce(ReturnRef(timeout)); - ON_CALL(app_mngr_, event_dispatcher()) - .WillByDefault(ReturnRef(event_dispatcher_)); - ON_CALL(app_mngr_, get_settings()) - .WillByDefault(ReturnRef(app_mngr_settings_)); + CommandRequestTest::InitCommand(timeout); + ON_CALL(app_mngr_settings_, app_icons_folder()) .WillByDefault(ReturnRef(kEmptyString_)); } diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager.h index ee0bd118858..623498dac77 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager.h @@ -129,6 +129,19 @@ class ResourceAllocationManager { virtual bool IsResourceFree(const std::string& module_type, const std::string& module_id) const = 0; + /** + * @brief IsResourceAllocated check if module is allocated by certain + * application + * @param module_type module to be checked + * @param module_id uuid of a resource to be checked + * @param app_id app to be checked + * @return true if module_type is allocated by application with provided + * app_id + */ + virtual bool IsResourceAllocated(const std::string& module_type, + const std::string& module_id, + const uint32_t app_id) = 0; + /** * @brief AcquireResource forces acquiring resource by application * @param module_type resource to acquire diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager_impl.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager_impl.h index 0fd54499125..4361312ddef 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager_impl.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager_impl.h @@ -94,6 +94,10 @@ class ResourceAllocationManagerImpl : public ResourceAllocationManager { bool IsResourceFree(const std::string& module_type, const std::string& module_id) const FINAL; + bool IsResourceAllocated(const std::string& module_type, + const std::string& module_id, + const uint32_t app_id) FINAL; + void SetAccessMode( const hmi_apis::Common_RCAccessMode::eType access_mode) FINAL; diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc index 12608d64c1a..e179c0c0d70 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc @@ -278,6 +278,11 @@ void RCCommandRequest::ProcessConsentResult(const bool is_allowed, SDL_LOG_AUTO_TRACE(); if (is_allowed) { SetResourceState(module_type, ResourceState::BUSY); + const auto default_timeout = + application_manager_.get_settings().default_timeout() + + application_manager_.get_settings().default_timeout_compensation(); + application_manager_.UpdateRequestTimeout( + connection_key(), correlation_id(), default_timeout); Execute(); // run child's logic } else { resource_allocation_manager_.OnDriverDisallowed( diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc index a26cf714480..0c513cb01ec 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc @@ -488,6 +488,28 @@ bool ResourceAllocationManagerImpl::IsResourceFree( return ResourceState::FREE == resource->second; } +bool ResourceAllocationManagerImpl::IsResourceAllocated( + const std::string& module_type, + const std::string& module_id, + const uint32_t app_id) { + ModuleUid module(module_type, module_id); + sync_primitives::AutoLock lock(allocated_resources_lock_); + const auto allocation = allocated_resources_.find(module); + if (allocated_resources_.end() == allocation) { + SDL_LOG_DEBUG("Resource " << module_type << " is not allocated."); + return false; + } + + if (app_id != allocation->second) { + SDL_LOG_DEBUG("Resource " << module_type + << " is allocated by different application " + << allocation->second); + return true; + } + + return false; +} + void ResourceAllocationManagerImpl::SetAccessMode( const hmi_apis::Common_RCAccessMode::eType access_mode) { if (hmi_apis::Common_RCAccessMode::ASK_DRIVER != access_mode) { diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/button_press_request_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/button_press_request_test.cc index 6c0962a557f..3772a25f476 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/button_press_request_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/button_press_request_test.cc @@ -105,6 +105,8 @@ class ButtonPressRequestTest .WillByDefault(Return(true)); ON_CALL(mock_allocation_manager_, is_rc_enabled()) .WillByDefault(Return(true)); + ON_CALL(mock_allocation_manager_, GetAccessMode()) + .WillByDefault(Return(hmi_apis::Common_RCAccessMode::AUTO_ALLOW)); ON_CALL(mock_rc_capabilities_manager_, CheckButtonName(_, _)) .WillByDefault(Return(true)); ON_CALL(mock_rc_capabilities_manager_, CheckIfModuleExistsInCapabilities(_)) diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc index 8fbaeda2f21..15b21481875 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc @@ -39,10 +39,11 @@ #include "application_manager/mock_event_dispatcher.h" #include "application_manager/mock_hmi_capabilities.h" #include "application_manager/mock_request_controller_settings.h" +#include "application_manager/mock_request_timeout_handler.h" #include "application_manager/mock_rpc_plugin.h" #include "application_manager/mock_rpc_plugin_manager.h" #include "application_manager/mock_rpc_protection_manager.h" -#include "application_manager/request_controller.h" +#include "application_manager/request_controller_impl.h" #include "application_manager/rpc_service_impl.h" #include "hmi_message_handler/mock_hmi_message_handler.h" #include "include/test/protocol_handler/mock_protocol_handler.h" @@ -81,6 +82,7 @@ using test::components::application_manager_test::MockApplication; using test::components::application_manager_test::MockCommandFactory; using test::components::application_manager_test::MockHMICapabilities; using test::components::application_manager_test::MockRequestControlerSettings; +using test::components::application_manager_test::MockRequestTimeoutHandler; using test::components::commands_test::CommandRequestTest; using test::components::commands_test::CommandsTestMocks; using test::components::hmi_message_handler_test::MockHMIMessageHandler; @@ -108,9 +110,10 @@ class RCGetInteriorVehicleDataConsentTest , command_holder(app_mngr_) , rc_capabilities_(std::make_shared( smart_objects::SmartType::SmartType_Array)) - , request_controller(mock_request_controler) , rpc_protection_manager_( std::make_shared()) + , request_controller(mock_request_controler, + mock_request_timeout_handler_) , rpc_service_(app_mngr_, request_controller, &mock_protocol_handler, @@ -214,9 +217,10 @@ class RCGetInteriorVehicleDataConsentTest smart_objects::SmartObjectSPtr rc_capabilities_; MockRPCPlugin mock_rpc_plugin; MockCommandFactory mock_command_factory; - am::request_controller::RequestController request_controller; std::shared_ptr rpc_protection_manager_; + MockRequestTimeoutHandler mock_request_timeout_handler_; + am::request_controller::RequestControllerImpl request_controller; am::rpc_service::RPCServiceImpl rpc_service_; RCRPCPlugin rc_plugin_; std::shared_ptr rc_app_extension_; @@ -235,6 +239,8 @@ TEST_F(RCGetInteriorVehicleDataConsentTest, Run_MobileSendButtonPressMessage_HMISendASKDRIVERModeToMobile) { // Arrange auto mobile_message = CreateBasicMessage(); + ON_CALL(mock_allocation_manager_, GetAccessMode()) + .WillByDefault(Return(hmi_apis::Common_RCAccessMode::ASK_DRIVER)); // Expectations EXPECT_CALL(mock_allocation_manager_, AcquireResource(_, _, _)) @@ -279,6 +285,9 @@ TEST_F(RCGetInteriorVehicleDataConsentTest, .WillOnce(ReturnRef(mock_command_factory)); auto mobile_message = CreateBasicMessage(); + ON_CALL(mock_allocation_manager_, GetAccessMode()) + .WillByDefault(Return(hmi_apis::Common_RCAccessMode::AUTO_DENY)); + auto rc_consent_response = CreateRCCommand( mobile_message); diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/set_interior_vehicle_data_request_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/set_interior_vehicle_data_request_test.cc index 9b06ddb1378..9ba959de299 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/set_interior_vehicle_data_request_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/set_interior_vehicle_data_request_test.cc @@ -112,6 +112,8 @@ class SetInteriorVehicleDataRequestTest ON_CALL(mock_rc_capabilities_manager_, GetModuleDataCapabilities(_, _)) .WillByDefault( Return(std::make_pair("", capabilitiesStatus::kSuccess))); + ON_CALL(mock_allocation_manager_, GetAccessMode()) + .WillByDefault(Return(hmi_apis::Common_RCAccessMode::AUTO_ALLOW)); } MessageSharedPtr CreateBasicMessage() { diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_resource_allocation_manager.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_resource_allocation_manager.h index fca6c9c77e3..2f128d64a8f 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_resource_allocation_manager.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_resource_allocation_manager.h @@ -70,6 +70,10 @@ class MockResourceAllocationManager MOCK_CONST_METHOD2(IsResourceFree, bool(const std::string& module_type, const std::string& module_id)); + MOCK_METHOD3(IsResourceAllocated, + bool(const std::string& module_type, + const std::string& module_id, + const uint32_t app_id)); MOCK_METHOD0(ResetAllAllocations, void()); MOCK_METHOD2(SendOnRCStatusNotifications, void(rc_rpc_plugin::NotificationTrigger::eType, diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_ui_reset_timeout_notification.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_reset_timeout_notification.h similarity index 81% rename from src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_ui_reset_timeout_notification.h rename to src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_reset_timeout_notification.h index 1c87f82349c..57c6f55e03a 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_ui_reset_timeout_notification.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_reset_timeout_notification.h @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_UI_RESET_TIMEOUT_NOTIFICATION_H_ -#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_UI_RESET_TIMEOUT_NOTIFICATION_H_ +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_RESET_TIMEOUT_NOTIFICATION_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_RESET_TIMEOUT_NOTIFICATION_H_ #include "application_manager/commands/notification_from_hmi.h" @@ -43,17 +43,17 @@ namespace commands { namespace hmi { /** - * @brief OnUIResetTimeoutNotification command class + * @brief OnResetTimeoutNotification command class **/ -class OnUIResetTimeoutNotification +class OnResetTimeoutNotification : public app_mngr::commands::NotificationFromHMI { public: /** - * @brief OnUIResetTimeoutNotification class constructor + * @brief OnResetTimeoutNotification class constructor * * @param message Incoming SmartObject message **/ - OnUIResetTimeoutNotification( + OnResetTimeoutNotification( const app_mngr::commands::MessageSharedPtr& message, app_mngr::ApplicationManager& application_manager, app_mngr::rpc_service::RPCService& rpc_service, @@ -61,9 +61,9 @@ class OnUIResetTimeoutNotification policy::PolicyHandlerInterface& policy_handle); /** - * @brief OnUIResetTimeoutNotification class destructor + * @brief OnResetTimeoutNotification class destructor **/ - virtual ~OnUIResetTimeoutNotification(); + virtual ~OnResetTimeoutNotification(); /** * @brief Execute command @@ -71,7 +71,7 @@ class OnUIResetTimeoutNotification virtual void Run(); private: - DISALLOW_COPY_AND_ASSIGN(OnUIResetTimeoutNotification); + DISALLOW_COPY_AND_ASSIGN(OnResetTimeoutNotification); }; } // namespace hmi @@ -80,4 +80,4 @@ class OnUIResetTimeoutNotification } // namespace sdl_rpc_plugin -#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_UI_RESET_TIMEOUT_NOTIFICATION_H_ +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_RESET_TIMEOUT_NOTIFICATION_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_tts_reset_timeout_notification.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_tts_reset_timeout_notification.h deleted file mode 100644 index c8bd1590641..00000000000 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_tts_reset_timeout_notification.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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_HMI_ON_TTS_RESET_TIMEOUT_NOTIFICATION_H_ -#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_TTS_RESET_TIMEOUT_NOTIFICATION_H_ - -#include "application_manager/commands/notification_from_hmi.h" - -namespace sdl_rpc_plugin { -namespace app_mngr = application_manager; - -namespace commands { - -namespace hmi { - -/** - * @brief OnTTSResetTimeoutNotification command class - **/ -class OnTTSResetTimeoutNotification - : public app_mngr::commands::NotificationFromHMI { - public: - /** - * @brief OnTTSResetTimeoutNotification class constructor - * - * @param message Incoming SmartObject message - **/ - OnTTSResetTimeoutNotification( - 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_handle); - - /** - * @brief OnTTSResetTimeoutNotification class destructor - **/ - virtual ~OnTTSResetTimeoutNotification(); - - /** - * @brief Execute command - **/ - virtual void Run(); - - private: - DISALLOW_COPY_AND_ASSIGN(OnTTSResetTimeoutNotification); -}; - -} // namespace hmi - -} // namespace commands - -} // namespace sdl_rpc_plugin - -#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_TTS_RESET_TIMEOUT_NOTIFICATION_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/navi_audio_start_stream_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/navi_audio_start_stream_request.cc index 21d62824362..05d0a4e8f2c 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/navi_audio_start_stream_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/navi_audio_start_stream_request.cc @@ -58,9 +58,11 @@ AudioStartStreamRequest::AudioStartStreamRequest( SDL_LOG_AUTO_TRACE(); std::pair stream_retry = application_manager_.get_settings().start_stream_retry_amount(); - default_timeout_ = stream_retry.second; + default_timeout_ = + stream_retry.second + + application_manager_.get_settings().default_timeout_compensation(); retry_number_ = stream_retry.first; - SDL_LOG_DEBUG("default_timeout_ = " << default_timeout_ + SDL_LOG_DEBUG("default_timeout_ = " << stream_retry.second << "; retry_number_ = " << retry_number_); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/navi_start_stream_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/navi_start_stream_request.cc index 973c323ebee..c671b11282b 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/navi_start_stream_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/navi_start_stream_request.cc @@ -58,9 +58,11 @@ NaviStartStreamRequest::NaviStartStreamRequest( SDL_LOG_AUTO_TRACE(); std::pair stream_retry = application_manager_.get_settings().start_stream_retry_amount(); - default_timeout_ = stream_retry.second; + default_timeout_ = + stream_retry.second + + application_manager_.get_settings().default_timeout_compensation(); retry_number_ = stream_retry.first; - SDL_LOG_DEBUG("default_timeout_ = " << default_timeout_ + SDL_LOG_DEBUG("default_timeout_ = " << stream_retry.second << "; retry_number_ = " << retry_number_); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ui_reset_timeout_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_reset_timeout_notification.cc similarity index 88% rename from src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ui_reset_timeout_notification.cc rename to src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_reset_timeout_notification.cc index d8de31cfbc5..ff5b2709c0d 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ui_reset_timeout_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_reset_timeout_notification.cc @@ -29,8 +29,7 @@ * 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/hmi/on_ui_reset_timeout_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_reset_timeout_notification.h" #include "application_manager/event_engine/event.h" #include "interfaces/HMI_API.h" @@ -43,7 +42,7 @@ namespace hmi { SDL_CREATE_LOG_VARIABLE("Commands") -OnUIResetTimeoutNotification::OnUIResetTimeoutNotification( +OnResetTimeoutNotification::OnResetTimeoutNotification( const application_manager::commands::MessageSharedPtr& message, ApplicationManager& application_manager, rpc_service::RPCService& rpc_service, @@ -55,12 +54,13 @@ OnUIResetTimeoutNotification::OnUIResetTimeoutNotification( hmi_capabilities, policy_handle) {} -OnUIResetTimeoutNotification::~OnUIResetTimeoutNotification() {} +OnResetTimeoutNotification::~OnResetTimeoutNotification() {} -void OnUIResetTimeoutNotification::Run() { +void OnResetTimeoutNotification::Run() { SDL_LOG_AUTO_TRACE(); - event_engine::Event event(hmi_apis::FunctionID::UI_OnResetTimeout); + event_engine::Event event( + hmi_apis::FunctionID::BasicCommunication_OnResetTimeout); event.set_smart_object(*message_); event.raise(application_manager_.event_dispatcher()); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_activate_app_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_activate_app_request.cc index 66ac9c458b1..4de8b17b8dc 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_activate_app_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_activate_app_request.cc @@ -142,7 +142,7 @@ void SDLActivateAppRequest::Run() { application_manager_.get_settings(); uint32_t total_retry_timeout = (settings.cloud_app_retry_timeout() * settings.cloud_app_max_retry_attempts()); - application_manager_.updateRequestTimeout( + application_manager_.UpdateRequestTimeout( 0, correlation_id(), default_timeout_ + total_retry_timeout); subscribe_on_event(BasicCommunication_OnAppRegistered); application_manager_.connection_handler().ConnectToDevice(app->device()); @@ -227,7 +227,7 @@ void SDLActivateAppRequest::Run() { application_manager_.get_settings(); uint32_t total_retry_timeout = (settings.cloud_app_retry_timeout() * settings.cloud_app_max_retry_attempts()); - application_manager_.updateRequestTimeout( + application_manager_.UpdateRequestTimeout( 0, correlation_id(), default_timeout_ + total_retry_timeout); subscribe_on_event(BasicCommunication_OnAppRegistered); application_manager_.connection_handler().ConnectToDevice( diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/alert_maneuver_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/alert_maneuver_request.cc index 8728bb44036..0e0d91f05db 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/alert_maneuver_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/alert_maneuver_request.cc @@ -51,9 +51,7 @@ AlertManeuverRequest::AlertManeuverRequest( hmi_capabilities, policy_handler) , tts_speak_result_code_(hmi_apis::Common_Result::INVALID_ENUM) - , navi_alert_maneuver_result_code_(hmi_apis::Common_Result::INVALID_ENUM) { - subscribe_on_event(hmi_apis::FunctionID::TTS_OnResetTimeout); -} + , navi_alert_maneuver_result_code_(hmi_apis::Common_Result::INVALID_ENUM) {} AlertManeuverRequest::~AlertManeuverRequest() {} @@ -179,13 +177,7 @@ void AlertManeuverRequest::on_event(const event_engine::Event& event) { GetInfo(message, info_tts_); break; } - case hmi_apis::FunctionID::TTS_OnResetTimeout: { - SDL_LOG_INFO("Received TTS_OnResetTimeout event"); - application_manager_.updateRequestTimeout( - connection_key(), correlation_id(), default_timeout()); - break; - } default: { SDL_LOG_ERROR("Received unknown event " << event.id()); SendResponse( diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/alert_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/alert_request.cc index 5d1a058f164..26c209bf2a8 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/alert_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/alert_request.cc @@ -65,10 +65,7 @@ AlertRequest::AlertRequest( , awaiting_tts_stop_speaking_response_(false) , is_ui_alert_sent_(false) , alert_result_(hmi_apis::Common_Result::INVALID_ENUM) - , tts_speak_result_(hmi_apis::Common_Result::INVALID_ENUM) { - subscribe_on_event(hmi_apis::FunctionID::UI_OnResetTimeout); - subscribe_on_event(hmi_apis::FunctionID::TTS_OnResetTimeout); -} + , tts_speak_result_(hmi_apis::Common_Result::INVALID_ENUM) {} AlertRequest::~AlertRequest() {} @@ -129,18 +126,6 @@ void AlertRequest::on_event(const event_engine::Event& event) { const smart_objects::SmartObject& message = event.smart_object(); switch (event.id()) { - case hmi_apis::FunctionID::TTS_OnResetTimeout: - case hmi_apis::FunctionID::UI_OnResetTimeout: { - SDL_LOG_INFO( - "Received UI_OnResetTimeout event " - " or TTS_OnResetTimeout event " - << awaiting_tts_speak_response_ << " " - << awaiting_tts_stop_speaking_response_ << " " - << awaiting_ui_alert_response_); - application_manager_.updateRequestTimeout( - connection_key(), correlation_id(), default_timeout()); - break; - } case hmi_apis::FunctionID::UI_Alert: { SDL_LOG_INFO("Received UI_Alert event"); // Unsubscribe from event to avoid unwanted messages diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc index f3e0b679218..2f624efe765 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc @@ -369,7 +369,7 @@ void CreateInteractionChoiceSetRequest::CountReceivedVRResponses() { << expected_chs_count_ - received_chs_count_ << " more to wait."); if (received_chs_count_ < expected_chs_count_) { - application_manager_.updateRequestTimeout( + application_manager_.UpdateRequestTimeout( connection_key(), correlation_id(), default_timeout()); SDL_LOG_DEBUG("Timeout for request was updated"); } else { diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_way_points_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_way_points_request.cc index 54b542d245f..9e156bf7558 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_way_points_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_way_points_request.cc @@ -51,9 +51,7 @@ GetWayPointsRequest::GetWayPointsRequest( application_manager, rpc_service, hmi_capabilities, - policy_handler) { - subscribe_on_event(hmi_apis::FunctionID::UI_OnResetTimeout); -} + policy_handler) {} GetWayPointsRequest::~GetWayPointsRequest() {} @@ -81,12 +79,6 @@ void GetWayPointsRequest::on_event(const event_engine::Event& event) { SDL_LOG_AUTO_TRACE(); const smart_objects::SmartObject& message = event.smart_object(); switch (event.id()) { - case hmi_apis::FunctionID::UI_OnResetTimeout: { - SDL_LOG_INFO("Received UI_OnResetTimeout event"); - application_manager_.updateRequestTimeout( - connection_key(), correlation_id(), default_timeout()); - break; - } case hmi_apis::FunctionID::Navigation_GetWayPoints: { SDL_LOG_INFO("Received Navigation_GetWayPoints event"); EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_Navigation); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_audio_pass_thru_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_audio_pass_thru_request.cc index 0accdd1e76c..74b474f76b3 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_audio_pass_thru_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_audio_pass_thru_request.cc @@ -59,9 +59,7 @@ PerformAudioPassThruRequest::PerformAudioPassThruRequest( hmi_capabilities, policy_handler) , result_tts_speak_(hmi_apis::Common_Result::INVALID_ENUM) - , result_ui_(hmi_apis::Common_Result::INVALID_ENUM) { - subscribe_on_event(hmi_apis::FunctionID::TTS_OnResetTimeout); -} + , result_ui_(hmi_apis::Common_Result::INVALID_ENUM) {} PerformAudioPassThruRequest::~PerformAudioPassThruRequest() {} @@ -183,18 +181,12 @@ void PerformAudioPassThruRequest::on_event(const event_engine::Event& event) { StartMicrophoneRecording(); // update request timeout to get time for perform audio recording - application_manager_.updateRequestTimeout( + application_manager_.UpdateRequestTimeout( connection_key(), correlation_id(), default_timeout()); } break; } - case hmi_apis::FunctionID::TTS_OnResetTimeout: { - SDL_LOG_INFO("Received TTS_OnResetTimeout event"); - application_manager_.updateRequestTimeout( - connection_key(), correlation_id(), default_timeout()); - break; - } default: { SDL_LOG_ERROR("Received unknown event " << event.id()); return; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc index bb990574bd6..da1f744689c 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc @@ -83,7 +83,6 @@ PerformInteractionRequest::PerformInteractionRequest( , ui_result_code_(hmi_apis::Common_Result::INVALID_ENUM) { response_msg_params = smart_objects::SmartObject(smart_objects::SmartType_Map); - subscribe_on_event(hmi_apis::FunctionID::UI_OnResetTimeout); subscribe_on_event(hmi_apis::FunctionID::VR_OnCommand); subscribe_on_event(hmi_apis::FunctionID::Buttons_OnButtonPress); } @@ -236,12 +235,6 @@ void PerformInteractionRequest::on_event(const event_engine::Event& event) { const smart_objects::SmartObject& message = event.smart_object(); switch (event.id()) { - case hmi_apis::FunctionID::UI_OnResetTimeout: { - SDL_LOG_DEBUG("Received UI_OnResetTimeout event"); - application_manager_.updateRequestTimeout( - connection_key(), correlation_id(), default_timeout()); - break; - } case hmi_apis::FunctionID::UI_PerformInteraction: { SDL_LOG_DEBUG("Received UI_PerformInteraction event"); EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); @@ -299,7 +292,7 @@ void PerformInteractionRequest::onTimeOut() { DisablePerformInteraction(); CommandRequestImpl::onTimeOut(); } else { - application_manager_.updateRequestTimeout( + application_manager_.UpdateRequestTimeout( connection_key(), correlation_id(), default_timeout_); } break; @@ -351,8 +344,10 @@ bool PerformInteractionRequest::ProcessVRResponse( SendResponse(false, MessageHelper::HMIToMobileResult(vr_result_code_)); return true; } + SDL_LOG_DEBUG("Update timeout for UI"); - application_manager_.updateRequestTimeout( + application_manager_.UpdateRequestTimeout( + connection_key(), correlation_id(), default_timeout_); return false; } @@ -378,7 +373,7 @@ bool PerformInteractionRequest::ProcessVRResponse( if (mobile_apis::InteractionMode::BOTH == interaction_mode_ || mobile_apis::InteractionMode::MANUAL_ONLY == interaction_mode_) { SDL_LOG_DEBUG("Update timeout for UI"); - application_manager_.updateRequestTimeout( + application_manager_.UpdateRequestTimeout( connection_key(), correlation_id(), default_timeout_); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/scrollable_message_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/scrollable_message_request.cc index 89e77d9d197..7cfe5f54144 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/scrollable_message_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/scrollable_message_request.cc @@ -58,9 +58,7 @@ ScrollableMessageRequest::ScrollableMessageRequest( application_manager, rpc_service, hmi_capabilities, - policy_handler) { - subscribe_on_event(hmi_apis::FunctionID::UI_OnResetTimeout); -} + policy_handler) {} ScrollableMessageRequest::~ScrollableMessageRequest() {} @@ -131,12 +129,6 @@ void ScrollableMessageRequest::on_event(const event_engine::Event& event) { const smart_objects::SmartObject& message = event.smart_object(); switch (event.id()) { - case hmi_apis::FunctionID::UI_OnResetTimeout: { - SDL_LOG_INFO("Received UI_OnResetTimeout event"); - application_manager_.updateRequestTimeout( - connection_key(), correlation_id(), default_timeout()); - break; - } case hmi_apis::FunctionID::UI_ScrollableMessage: { SDL_LOG_INFO("Received UI_ScrollableMessage event"); EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/slider_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/slider_request.cc index 22935e21369..0fdc412572e 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/slider_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/slider_request.cc @@ -55,9 +55,7 @@ SliderRequest::SliderRequest( application_manager, rpc_service, hmi_capabilities, - policy_handler) { - subscribe_on_event(hmi_apis::FunctionID::UI_OnResetTimeout); -} + policy_handler) {} SliderRequest::~SliderRequest() {} @@ -65,8 +63,7 @@ bool SliderRequest::Init() { /* Timeout in milliseconds. If omitted a standard value of 10000 milliseconds is used.*/ if ((*message_)[strings::msg_params].keyExists(strings::timeout)) { - default_timeout_ = - application_manager_.get_settings().default_timeout() + + default_timeout_ += (*message_)[strings::msg_params][strings::timeout].asUInt(); } @@ -134,12 +131,6 @@ void SliderRequest::on_event(const event_engine::Event& event) { const SmartObject& message = event.smart_object(); const event_engine::Event::EventID event_id = event.id(); - if (event_id == FunctionID::UI_OnResetTimeout) { - SDL_LOG_INFO("Received UI_OnResetTimeout event"); - application_manager_.updateRequestTimeout( - connection_key(), correlation_id(), default_timeout()); - return; - } if (event_id != FunctionID::UI_Slider) { SDL_LOG_ERROR("Received unknown event " << event.id()); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/speak_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/speak_request.cc index b8de0538530..f8307f83556 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/speak_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/speak_request.cc @@ -55,9 +55,7 @@ SpeakRequest::SpeakRequest( application_manager, rpc_service, hmi_capabilities, - policy_handler) { - subscribe_on_event(hmi_apis::FunctionID::TTS_OnResetTimeout); -} + policy_handler) {} SpeakRequest::~SpeakRequest() {} @@ -112,13 +110,7 @@ void SpeakRequest::on_event(const event_engine::Event& event) { ProcessTTSSpeakResponse(event.smart_object()); break; } - case hmi_apis::FunctionID::TTS_OnResetTimeout: { - SDL_LOG_INFO("Received TTS_OnResetTimeout event"); - application_manager_.updateRequestTimeout( - connection_key(), correlation_id(), default_timeout()); - break; - } default: { SDL_LOG_ERROR("Received unknown event " << event.id()); break; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/subtle_alert_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/subtle_alert_request.cc index 2a8e2674364..8491a859e64 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/subtle_alert_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/subtle_alert_request.cc @@ -59,10 +59,7 @@ SubtleAlertRequest::SubtleAlertRequest( , is_ui_subtle_alert_sent_(false) , is_tts_stop_speaking_sent_(false) , subtle_alert_result_(hmi_apis::Common_Result::INVALID_ENUM) - , tts_speak_result_(hmi_apis::Common_Result::INVALID_ENUM) { - subscribe_on_event(hmi_apis::FunctionID::UI_OnResetTimeout); - subscribe_on_event(hmi_apis::FunctionID::TTS_OnResetTimeout); -} + , tts_speak_result_(hmi_apis::Common_Result::INVALID_ENUM) {} SubtleAlertRequest::~SubtleAlertRequest() {} @@ -118,18 +115,6 @@ void SubtleAlertRequest::on_event(const event_engine::Event& event) { const smart_objects::SmartObject& message = event.smart_object(); switch (event.id()) { - case hmi_apis::FunctionID::TTS_OnResetTimeout: - case hmi_apis::FunctionID::UI_OnResetTimeout: { - SDL_LOG_INFO( - "Received UI_OnResetTimeout event " - " or TTS_OnResetTimeout event" - << awaiting_tts_speak_response_ << " " - << awaiting_tts_stop_speaking_response_ << " " - << awaiting_ui_subtle_alert_response_); - application_manager_.updateRequestTimeout( - connection_key(), correlation_id(), default_timeout()); - break; - } case hmi_apis::FunctionID::UI_SubtleAlert: { SDL_LOG_INFO("Received UI_SubtleAlert event"); // Unsubscribe from event to avoid unwanted messages diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/hmi_command_factory.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/hmi_command_factory.cc index 642bdc7b118..954ddb4e57c 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/hmi_command_factory.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/hmi_command_factory.cc @@ -218,6 +218,7 @@ #include "sdl_rpc_plugin/commands/hmi/on_ready_notification.h" #include "sdl_rpc_plugin/commands/hmi/on_received_policy_update.h" #include "sdl_rpc_plugin/commands/hmi/on_record_start_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_reset_timeout_notification.h" #include "sdl_rpc_plugin/commands/hmi/on_sdl_close_notification.h" #include "sdl_rpc_plugin/commands/hmi/on_sdl_persistence_complete_notification.h" #include "sdl_rpc_plugin/commands/hmi/on_system_context_notification.h" @@ -225,13 +226,11 @@ #include "sdl_rpc_plugin/commands/hmi/on_system_request_notification.h" #include "sdl_rpc_plugin/commands/hmi/on_system_time_ready_notification.h" #include "sdl_rpc_plugin/commands/hmi/on_tts_language_change_notification.h" -#include "sdl_rpc_plugin/commands/hmi/on_tts_reset_timeout_notification.h" #include "sdl_rpc_plugin/commands/hmi/on_tts_started_notification.h" #include "sdl_rpc_plugin/commands/hmi/on_tts_stopped_notification.h" #include "sdl_rpc_plugin/commands/hmi/on_ui_command_notification.h" #include "sdl_rpc_plugin/commands/hmi/on_ui_keyboard_input_notification.h" #include "sdl_rpc_plugin/commands/hmi/on_ui_language_change_notification.h" -#include "sdl_rpc_plugin/commands/hmi/on_ui_reset_timeout_notification.h" #include "sdl_rpc_plugin/commands/hmi/on_ui_subtle_alert_pressed_notification.h" #include "sdl_rpc_plugin/commands/hmi/on_ui_touch_event_notification.h" #include "sdl_rpc_plugin/commands/hmi/on_ui_update_file_notification.h" @@ -775,8 +774,8 @@ CommandCreator& HMICommandFactory::get_creator_factory( case hmi_apis::FunctionID::UI_OnTouchEvent: { return factory.GetCreator(); } - case hmi_apis::FunctionID::UI_OnResetTimeout: { - return factory.GetCreator(); + case hmi_apis::FunctionID::BasicCommunication_OnResetTimeout: { + return factory.GetCreator(); } case hmi_apis::FunctionID::Navigation_SetVideoConfig: { return hmi_apis::messageType::request == message_type @@ -875,9 +874,6 @@ CommandCreator& HMICommandFactory::get_creator_factory( case hmi_apis::FunctionID::SDL_OnDeviceStateChanged: { return factory.GetCreator(); } - case hmi_apis::FunctionID::TTS_OnResetTimeout: { - return factory.GetCreator(); - } case hmi_apis::FunctionID::BasicCommunication_OnEventChanged: { return factory.GetCreator(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc index 5fa910b2d9e..5e485adb7fb 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc @@ -114,6 +114,7 @@ #include "hmi/on_ready_notification.h" #include "hmi/on_received_policy_update.h" #include "hmi/on_record_start_notification.h" +#include "hmi/on_reset_timeout_notification.h" #include "hmi/on_resume_audio_source_notification.h" #include "hmi/on_sdl_close_notification.h" #include "hmi/on_sdl_consent_needed_notification.h" @@ -125,13 +126,11 @@ #include "hmi/on_system_info_changed_notification.h" #include "hmi/on_system_request_notification.h" #include "hmi/on_tts_language_change_notification.h" -#include "hmi/on_tts_reset_timeout_notification.h" #include "hmi/on_tts_started_notification.h" #include "hmi/on_tts_stopped_notification.h" #include "hmi/on_ui_command_notification.h" #include "hmi/on_ui_keyboard_input_notification.h" #include "hmi/on_ui_language_change_notification.h" -#include "hmi/on_ui_reset_timeout_notification.h" #include "hmi/on_ui_touch_event_notification.h" #include "hmi/on_update_device_list.h" #include "hmi/on_video_data_streaming_notification.h" @@ -258,14 +257,10 @@ class HMICommandsTest : public components::commands_test::CommandRequestTest< typedef Command CommandType; void InitCommand(const uint32_t& timeout) OVERRIDE { + CommandRequestTest::InitCommand(timeout); + stream_retry_.first = 0; stream_retry_.second = 0; - EXPECT_CALL(app_mngr_settings_, default_timeout()) - .WillOnce(ReturnRef(timeout)); - ON_CALL(app_mngr_, event_dispatcher()) - .WillByDefault(ReturnRef(event_dispatcher_)); - ON_CALL(app_mngr_, get_settings()) - .WillByDefault(ReturnRef(app_mngr_settings_)); ON_CALL(app_mngr_settings_, start_stream_retry_amount()) .WillByDefault(ReturnRef(stream_retry_)); } @@ -454,7 +449,6 @@ typedef Types::InitCommand(default_timeout); + app_ = ConfigureApp(&app_ptr_, kAppId_, NOT_MEDIA, NOT_NAVI, NOT_VC); - EXPECT_CALL(app_mngr_, get_settings()) - .WillOnce(ReturnRef(app_mngr_settings_)); - EXPECT_CALL(app_mngr_settings_, default_timeout()) - .WillOnce(ReturnRef(default_timeout)); - ON_CALL(app_mngr_, event_dispatcher()) - .WillByDefault(ReturnRef(mock_event_dispatcher_)); ON_CALL(app_mngr_, application_by_hmi_app(_)).WillByDefault(Return(app_)); ON_CALL(*app_ptr_, app_id()).WillByDefault(Return(kAppId_)); ON_CALL(app_mngr_, application(kConnectionKey)).WillByDefault(Return(app_)); @@ -362,12 +357,10 @@ typedef Types< hmi_apis::FunctionID::BasicCommunication_OnAppDeactivated>, CommandPair, - CommandPair, + CommandPair, CommandPair, CommandPair, - CommandPair, CommandPair, CommandPair > HMIOnNotificationsEventDispatcherTypes; @@ -517,7 +510,8 @@ TEST_F(HMICommandsNotificationsTest, std::shared_ptr command = CreateCommand(message); EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)); - EXPECT_CALL(app_mngr_, event_dispatcher()); + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher_)); EXPECT_CALL(mock_event_dispatcher_, raise_event(_)) .WillOnce(GetEventId(&event_id)); command->Run(); @@ -539,7 +533,8 @@ TEST_F(HMICommandsNotificationsTest, std::shared_ptr command = CreateCommand(message); EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)); - EXPECT_CALL(app_mngr_, event_dispatcher()); + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher_)); EXPECT_CALL(mock_event_dispatcher_, raise_event(_)) .WillOnce(GetEventId(&event_id)); command->Run(); @@ -561,7 +556,8 @@ TEST_F(HMICommandsNotificationsTest, OnButtonPressNotificationEventDispatcher) { CreateCommand(message); EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); - EXPECT_CALL(app_mngr_, event_dispatcher()); + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher_)); EXPECT_CALL(mock_event_dispatcher_, raise_event(_)) .WillOnce(GetEventId(&event_id)); command->Run(); @@ -578,7 +574,8 @@ TEST_F(HMICommandsNotificationsTest, OnReadyNotificationEventDispatcher) { CreateCommand(message); EXPECT_CALL(app_mngr_, OnHMIReady()); - EXPECT_CALL(app_mngr_, event_dispatcher()); + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher_)); EXPECT_CALL(mock_event_dispatcher_, raise_event(_)) .WillOnce(GetEventId(&event_id)); command->Run(); @@ -1298,11 +1295,10 @@ TEST_F(HMICommandsNotificationsTest, EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(app_)); EXPECT_CALL(app_mngr_settings_, max_cmd_id()).WillOnce(ReturnRef(kMaxCmdId)); - EXPECT_CALL(app_mngr_, get_settings()) - .WillOnce(ReturnRef(app_mngr_settings_)); EXPECT_CALL(*app_ptr_, is_perform_interaction_active()) .WillOnce(Return(kIsPerformInteractionActive)); - EXPECT_CALL(app_mngr_, event_dispatcher()); + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher_)); EXPECT_CALL(mock_event_dispatcher_, raise_event(_)) .WillOnce(GetEventId(&event_id)); EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_activate_app_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_activate_app_request_test.cc index 31285f5b177..a2dc705f60c 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_activate_app_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_activate_app_request_test.cc @@ -113,8 +113,9 @@ class SDLActivateAppRequestTest } void InitCommand(const uint32_t& timeout) OVERRIDE { - MockAppPtr mock_app = CreateMockApp(); CommandRequestTest::InitCommand(timeout); + + MockAppPtr mock_app = CreateMockApp(); ON_CALL((*mock_app), app_id()).WillByDefault(Return(kAppID)); ON_CALL(app_mngr_, application_by_hmi_app(kAppID)) .WillByDefault(Return(mock_app)); @@ -486,7 +487,7 @@ TEST_F(SDLActivateAppRequestTest, WaitingCloudApplication_ConnectDevice) { EXPECT_CALL(app_mngr_, get_settings()).WillOnce(ReturnRef(settings)); EXPECT_CALL(app_mngr_, - updateRequestTimeout(0, kCorrelationID, Gt(kMinimumTimeout))); + UpdateRequestTimeout(0, kCorrelationID, Gt(kMinimumTimeout))); MockConnectionHandler connection_handler; EXPECT_CALL(connection_handler, ConnectToDevice(kHandle)); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/alert_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/alert_request_test.cc index 5e1f3e47821..9130fa52a0c 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/alert_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/alert_request_test.cc @@ -403,27 +403,6 @@ TEST_F(AlertRequestTest, OnEvent_InvalidEventId_UNSUCCESS) { command->on_event(event); } -TEST_F(AlertRequestTest, DISABLED_OnEvent_UI_OnResetTimeout_SUCCESS) { - PreConditions(); - Expectations(); - AddAlertTextsToMsg(); - - (*msg_)[am::strings::msg_params][am::strings::duration] = kDefaultTimeout; - - CommandPtr command(CreateCommand(msg_)); - EXPECT_TRUE(command->Init()); - - EXPECT_CALL( - app_mngr_, - updateRequestTimeout(kConnectionKey, kCorrelationId, kDefaultTimeout)); - - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_ENUM); - - Event event(hmi_apis::FunctionID::UI_OnResetTimeout); - event.set_smart_object(*msg_); - command->on_event(event); -} - TEST_F(AlertRequestTest, OnEvent_UIAlertHasHmiResponsesToWait_UNSUCCESS) { Expectations(); AddAlertTextsToMsg(); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc index 80abfec61d8..d77e0588f8e 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc @@ -619,7 +619,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, OnEvent_ValidVrNoError_SUCCESS) { command_->Run(); - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); + EXPECT_CALL(app_mngr_, UpdateRequestTimeout(_, _, _)); EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)).Times(0); event.set_smart_object(*message_); @@ -655,7 +655,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, .WillByDefault(Return(kCorrelationId)); command_->Run(); - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); + EXPECT_CALL(app_mngr_, UpdateRequestTimeout(_, _, _)); EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)).Times(0); event.set_smart_object(*message_); @@ -696,7 +696,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, FillMessageFieldsItem2(message_); - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, UpdateRequestTimeout(_, _, _)).Times(0); EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)); event.set_smart_object(*message_); command_->on_event(event); @@ -751,7 +751,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, command_->Run(); FillMessageFieldsItem2(message_); - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, UpdateRequestTimeout(_, _, _)).Times(0); EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)); Event event(hmi_apis::FunctionID::VR_AddCommand); event.set_smart_object(*message_); @@ -801,7 +801,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, OnTimeOut_InvalidApp_UNSUCCESS) { command_->Run(); FillMessageFieldsItem2(message_); - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, UpdateRequestTimeout(_, _, _)).Times(0); EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)).Times(2); Event event(hmi_apis::FunctionID::VR_AddCommand); event.set_smart_object(*message_); @@ -854,7 +854,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, FillMessageFieldsItem2(message_); - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, UpdateRequestTimeout(_, _, _)).Times(0); resumption_test::MockResumeCtrl mock_resume_ctrl; EXPECT_CALL(app_mngr_, resume_controller()) .WillOnce(ReturnRef(mock_resume_ctrl)); @@ -935,7 +935,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, Run_ErrorFromHmiFalse_UNSUCCESS) { ManageMobileCommand( MobileResultCodeIs(mobile_apis::Result::GENERIC_ERROR), am::commands::Command::SOURCE_SDL)); - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, UpdateRequestTimeout(_, _, _)).Times(0); EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)); event.set_smart_object(*message_); command_->on_event(event); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/dummy_mobile_commands_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/dummy_mobile_commands_test.cc index 8f83a2dd10e..201118eec09 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/dummy_mobile_commands_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/dummy_mobile_commands_test.cc @@ -165,12 +165,8 @@ class MobileCommandsTest : public components::commands_test::CommandRequestTest< typedef Command CommandType; void InitCommand(const uint32_t& timeout) OVERRIDE { - EXPECT_CALL(app_mngr_settings_, default_timeout()) - .WillOnce(ReturnRef(timeout)); - ON_CALL(app_mngr_, event_dispatcher()) - .WillByDefault(ReturnRef(event_dispatcher_)); - ON_CALL(app_mngr_, get_settings()) - .WillByDefault(ReturnRef(app_mngr_settings_)); + CommandRequestTest::InitCommand(timeout); + ON_CALL(app_mngr_settings_, app_icons_folder()) .WillByDefault(ReturnRef(kEmptyString_)); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/get_way_points_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/get_way_points_request_test.cc index 7f7a8b55bdf..fd2bc2e51a5 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/get_way_points_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/get_way_points_request_test.cc @@ -202,7 +202,7 @@ TEST_F(GetWayPointsRequestTest, OnEvent_DefaultCase) { event.set_smart_object(*message_); - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, UpdateRequestTimeout(_, _, _)).Times(0); EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)).Times(0); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/perform_audio_pass_thru_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/perform_audio_pass_thru_test.cc index 2915418d438..c7627b7e55c 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/perform_audio_pass_thru_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/perform_audio_pass_thru_test.cc @@ -626,7 +626,7 @@ TEST_F(PerformAudioPassThruRequestTest, EXPECT_CALL(app_mngr_, BeginAudioPassThru(app_id)); EXPECT_CALL(app_mngr_, StartAudioPassThruThread(_, _, _, _, _, _)); - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); + EXPECT_CALL(app_mngr_, UpdateRequestTimeout(_, _, _)); ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); @@ -654,7 +654,7 @@ TEST_F(PerformAudioPassThruRequestTest, ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); // First call on_event for setting result_tts_speak_ to UNSUPPORTED_RESOURCE - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); + EXPECT_CALL(app_mngr_, UpdateRequestTimeout(_, _, _)); CallOnEvent caller_speak(*command_sptr_, event_speak); caller_speak(); @@ -691,31 +691,7 @@ TEST_F(PerformAudioPassThruRequestTest, app_mngr_, StartAudioPassThruThread(kConnectionKey, kCorrelationId, _, _, _, _)); - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); - ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - CallOnEvent caller(*command_sptr_, event); - caller(); - - EXPECT_EQ(kConnectionKey, msg_params_[am::strings::connection_key].asUInt()); - EXPECT_EQ(kFunctionId, msg_params_[am::strings::function_id].asString()); -} - -TEST_F(PerformAudioPassThruRequestTest, - DISABLED_OnEvent_TTSOnResetTimeout_UpdateTimeout) { - am::event_engine::Event event(hmi_apis::FunctionID::TTS_OnResetTimeout); - - msg_params_[am::strings::connection_key] = kConnectionKey; - msg_params_[am::strings::function_id] = kFunctionId; - - uint32_t app_id = kConnectionKey; - EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)).WillOnce(Return(true)); - EXPECT_CALL(app_mngr_, BeginAudioPassThru(app_id)).WillOnce(Return(true)); - - EXPECT_CALL( - app_mngr_, - StartAudioPassThruThread(kConnectionKey, kCorrelationId, _, _, _, _)); - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); + EXPECT_CALL(app_mngr_, UpdateRequestTimeout(_, _, _)); ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); CallOnEvent caller(*command_sptr_, event); @@ -729,7 +705,7 @@ TEST_F(PerformAudioPassThruRequestTest, OnEvent_DefaultCase) { am::event_engine::Event event(hmi_apis::FunctionID::INVALID_ENUM); uint32_t app_id = kConnectionKey; - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, UpdateRequestTimeout(_, _, _)).Times(0); EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).Times(0); CallOnEvent caller(*command_sptr_, event); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc index 4572a6d9070..99491873bea 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc @@ -416,6 +416,7 @@ TEST_F(RegisterAppInterfaceRequestTest, DefaultTimeout_CheckIfZero_SUCCESS) { TEST_F(RegisterAppInterfaceRequestTest, Run_MinimalData_SUCCESS) { InitBasicMessage(); (*msg_)[am::strings::msg_params][am::strings::hash_id] = kAppId1; + EXPECT_CALL(app_mngr_, WaitForHmiIsReady()).WillOnce(Return(true)); EXPECT_CALL(app_mngr_, IsApplicationForbidden(_, _)).WillOnce(Return(false)); @@ -501,6 +502,7 @@ TEST_F(RegisterAppInterfaceRequestTest, InitBasicMessage(); ON_CALL(app_mngr_, WaitForHmiIsReady()).WillByDefault(Return(true)); + EXPECT_CALL(app_mngr_, IsApplicationForbidden(_, _)).WillOnce(Return(false)); ON_CALL(mock_connection_handler_, @@ -802,6 +804,7 @@ TEST_F(RegisterAppInterfaceRequestTest, (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey2; ON_CALL(app_mngr_, WaitForHmiIsReady()).WillByDefault(Return(true)); + EXPECT_CALL(app_mngr_, IsApplicationForbidden(kConnectionKey2, kAppId1)) .WillOnce(Return(false)); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/scrollable_message_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/scrollable_message_test.cc index 6b17aa238d6..443868168d3 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/scrollable_message_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/scrollable_message_test.cc @@ -173,17 +173,21 @@ TEST_F(ScrollableMessageRequestTest, Init_CorrectTimeout_SUCCESS) { (*msg_)[msg_params][timeout] = kTimeOut; (*msg_)[msg_params][interaction_mode] = mobile_apis::InteractionMode::MANUAL_ONLY; - EXPECT_EQ(kDefaultTimeout_, command_->default_timeout()); + const uint32_t initial_timeout = + kDefaultTimeout_ + kDefaultTimeoutCompensation_; + EXPECT_EQ(initial_timeout, command_->default_timeout()); command_->Init(); - EXPECT_EQ(kTimeOut + kDefaultTimeout_, command_->default_timeout()); + EXPECT_EQ(kTimeOut + initial_timeout, command_->default_timeout()); } TEST_F(ScrollableMessageRequestTest, Init_CorrectTimeout_UNSUCCESS) { (*msg_)[msg_params][interaction_mode] = mobile_apis::InteractionMode::MANUAL_ONLY; - EXPECT_EQ(kDefaultTimeout_, command_->default_timeout()); + const uint32_t initial_timeout = + kDefaultTimeout_ + kDefaultTimeoutCompensation_; + EXPECT_EQ(initial_timeout, command_->default_timeout()); command_->Init(); - EXPECT_EQ(kDefaultTimeout_, command_->default_timeout()); + EXPECT_EQ(initial_timeout, command_->default_timeout()); } TEST_F(ScrollableMessageRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { @@ -240,18 +244,6 @@ TEST_F(ScrollableMessageRequestTest, OnEvent_ReceivedUnknownEvent_UNSUCCESS) { command_->on_event(event); } -TEST_F(ScrollableMessageRequestTest, - OnEvent_ReceivedUIOnResetTimeoutEvent_SUCCESS) { - (*msg_)[params][connection_key] = kConnectionKey; - (*msg_)[params][correlation_id] = kCorrelationId; - EXPECT_CALL( - app_mngr_, - updateRequestTimeout(kConnectionKey, kCorrelationId, kDefaultTimeout_)); - Event event(hmi_apis::FunctionID::UI_OnResetTimeout); - event.set_smart_object(*msg_); - command_->on_event(event); -} - TEST_F(ScrollableMessageRequestTest, DISABLED_OnEvent_ReceivedUIScrollableMessage_SUCCESS) { (*msg_)[params][hmi_response::code] = hmi_apis::Common_Result::SUCCESS; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/slider_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/slider_test.cc index 0450f06ee18..d9bffc6b4ae 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/slider_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/slider_test.cc @@ -274,22 +274,6 @@ TEST_F(SliderRequestTest, Run_SUCCESS) { command->Run(); } -TEST_F(SliderRequestTest, OnEvent_UI_OnResetTimeout_UNSUCCESS) { - PreConditions(); - (*msg_)[am::strings::msg_params][am::strings::timeout] = kDefaultTimeout; - (*msg_)[am::strings::params][am::strings::correlation_id] = kCorrelationId; - - CommandPtr command(CreateCommand(msg_)); - EXPECT_TRUE(command->Init()); - - EXPECT_CALL(app_mngr_, - updateRequestTimeout(kConnectionKey, kCorrelationId, _)); - - Event event(hmi_apis::FunctionID::UI_OnResetTimeout); - event.set_smart_object(*msg_); - command->on_event(event); -} - TEST_F(SliderRequestTest, OnEvent_UI_UnknownEventId_UNSUCCESS) { PreConditions(); EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/speak_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/speak_request_test.cc index 87320d3a7a5..dd082a52a76 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/speak_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/speak_request_test.cc @@ -366,18 +366,6 @@ TEST_F(SpeakRequestTest, OnEvent_TTS_SpeakWithWarning_WarningWithSuccess) { command->on_event(event); } -TEST_F(SpeakRequestTest, OnEvent_TTS_OnResetTimeout_UpdateTimeout) { - Event event(Event::EventID::TTS_OnResetTimeout); - (*request_)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - (*request_)[am::strings::params][am::strings::correlation_id] = kAppId; - CommandPtr command(CreateCommand(request_)); - - EXPECT_CALL(app_mngr_, updateRequestTimeout(kConnectionKey, kAppId, _)); - - command->on_event(event); -} - TEST_F(SpeakRequestTest, OnEvent_ApplicationIsNotRegistered_UNSUCCESS) { const hmi_apis::Common_Result::eType hmi_result = hmi_apis::Common_Result::SUCCESS; diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/include/vehicle_info_plugin/commands/vi_commands_test.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/include/vehicle_info_plugin/commands/vi_commands_test.h index ae25acea87c..e7d73fc4f05 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/include/vehicle_info_plugin/commands/vi_commands_test.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/include/vehicle_info_plugin/commands/vi_commands_test.h @@ -66,7 +66,7 @@ using ::smart_objects::SmartObject; template class VICommandsTest : public CommandsTest { public: - enum { kDefaultTimeout_ = 100 }; + enum { kDefaultTimeout_ = 100, kDefaultTimeoutCompensation_ = 10 }; template std::shared_ptr CreateCommandVI() { @@ -76,7 +76,7 @@ class VICommandsTest : public CommandsTest { template std::shared_ptr CreateCommandVI(MessageSharedPtr& msg) { - InitCommandVI(kDefaultTimeout_); + InitCommandVI(kDefaultTimeout_, kDefaultTimeoutCompensation_); vehicle_info_plugin::VehicleInfoCommandParams params = { CommandsTest::app_mngr_, CommandsTest::mock_rpc_service_, @@ -90,11 +90,14 @@ class VICommandsTest : public CommandsTest { mock_custom_vehicle_data_manager_; protected: - void InitCommandVI(const uint32_t& timeout) { + void InitCommandVI(const uint32_t timeout, const uint32_t compensation) { ON_CALL(CommandsTest::app_mngr_, get_settings()) .WillByDefault(ReturnRef(CommandsTest::app_mngr_settings_)); ON_CALL(CommandsTest::app_mngr_settings_, default_timeout()) .WillByDefault(ReturnRef(timeout)); + ON_CALL(CommandsTest::app_mngr_settings_, + default_timeout_compensation()) + .WillByDefault(ReturnRef(compensation)); } }; } // namespace commands_test diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index f5dedc0e35c..e78d6ee668b 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -51,6 +51,8 @@ #include "application_manager/mobile_message_handler.h" #include "application_manager/plugin_manager/rpc_plugin_manager_impl.h" #include "application_manager/policies/policy_handler.h" +#include "application_manager/request_controller_impl.h" +#include "application_manager/request_timeout_handler_impl.h" #include "application_manager/resumption/resume_ctrl_impl.h" #include "application_manager/rpc_handler_impl.h" #include "application_manager/rpc_protection_manager_impl.h" @@ -170,7 +172,10 @@ ApplicationManagerImpl::ApplicationManagerImpl( , connection_handler_(NULL) , policy_handler_(new policy::PolicyHandler(policy_settings, *this)) , protocol_handler_(NULL) - , request_ctrl_(am_settings) + , request_timeout_handler_( + new request_controller::RequestTimeoutHandlerImpl(*this)) + , request_ctrl_(new request_controller::RequestControllerImpl( + am_settings, *request_timeout_handler_)) , mobile_correlation_id_(0) , correlation_id_(0) , max_correlation_id_(UINT_MAX) @@ -215,7 +220,7 @@ ApplicationManagerImpl::ApplicationManagerImpl( std::make_shared(*policy_handler_); policy_handler_->add_listener(rpc_protection_manager.get()); rpc_service_.reset(new rpc_service::RPCServiceImpl(*this, - request_ctrl_, + *request_ctrl_, protocol_handler_, hmi_handler_, *commands_holder_, @@ -1714,7 +1719,7 @@ void ApplicationManagerImpl::OnDeviceSwitchingStart( } for (const auto& app : wait_list) { - request_ctrl_.terminateAppRequests(app->app_id()); + request_ctrl_->TerminateAppRequests(app->app_id()); resume_ctrl_->SaveApplication(app); } @@ -2476,7 +2481,7 @@ void ApplicationManagerImpl::StartDevicesDiscovery() { void ApplicationManagerImpl::TerminateRequest(const uint32_t connection_key, const uint32_t corr_id, const int32_t function_id) { - request_ctrl_.TerminateRequest(corr_id, connection_key, function_id, true); + request_ctrl_->TerminateRequest(corr_id, connection_key, function_id, true); } void ApplicationManagerImpl::RemoveHMIFakeParameters( @@ -2590,7 +2595,7 @@ bool ApplicationManagerImpl::Stop() { } catch (...) { SDL_LOG_ERROR("An error occurred during unregistering applications."); } - request_ctrl_.DestroyThreadpool(); + request_ctrl_->Stop(); // for PASA customer policy backup should happen :AllApp(SUSPEND) SDL_LOG_DEBUG("Unloading policy library."); @@ -2930,21 +2935,21 @@ void ApplicationManagerImpl::SetTelemetryObserver( } #endif // TELEMETRY_MONITOR -void ApplicationManagerImpl::addNotification(const CommandSharedPtr ptr) { - request_ctrl_.addNotification(ptr); +void ApplicationManagerImpl::AddNotification(const CommandSharedPtr ptr) { + request_ctrl_->AddNotification(ptr); } -void ApplicationManagerImpl::removeNotification( +void ApplicationManagerImpl::RemoveNotification( const commands::Command* notification) { - request_ctrl_.removeNotification(notification); + request_ctrl_->RemoveNotification(notification); } -void ApplicationManagerImpl::updateRequestTimeout( +void ApplicationManagerImpl::UpdateRequestTimeout( uint32_t connection_key, uint32_t mobile_correlation_id, uint32_t new_timeout_value) { SDL_LOG_AUTO_TRACE(); - request_ctrl_.updateRequestTimeout( + request_ctrl_->UpdateRequestTimeout( connection_key, mobile_correlation_id, new_timeout_value); } @@ -2954,7 +2959,7 @@ void ApplicationManagerImpl::IncreaseForwardedRequestTimeout( << get_settings().rpc_pass_through_timeout()); uint32_t new_timeout_value = get_settings().default_timeout() + get_settings().rpc_pass_through_timeout(); - request_ctrl_.updateRequestTimeout( + request_ctrl_->UpdateRequestTimeout( connection_key, mobile_correlation_id, new_timeout_value); } @@ -3176,7 +3181,7 @@ void ApplicationManagerImpl::UnregisterAllApplications() { if (is_ignition_off) { resume_controller().OnIgnitionOff(); } - request_ctrl_.terminateAllHMIRequests(); + request_ctrl_->TerminateAllHMIRequests(); } void ApplicationManagerImpl::RemoveAppsWaitingForRegistration( @@ -3276,11 +3281,10 @@ void ApplicationManagerImpl::UnregisterApplication( } if (!app_to_remove) { SDL_LOG_ERROR("Cant find application with app_id = " << app_id); - // Just to terminate RAI in case of connection is dropped (rare case) // App won't be unregistered since RAI has not been started yet SDL_LOG_DEBUG("Trying to terminate possible RAI request."); - request_ctrl_.terminateAppRequests(app_id); + request_ctrl_->TerminateAppRequests(app_id); return; } @@ -3344,7 +3348,8 @@ void ApplicationManagerImpl::UnregisterApplication( }; plugin_manager_->ForEachPlugin(on_app_unregistered); - request_ctrl_.terminateAppRequests(app_id); + + request_ctrl_->TerminateAppRequests(app_id); const bool is_applications_list_empty = applications().GetData().empty(); if (is_applications_list_empty) { @@ -3429,7 +3434,7 @@ void ApplicationManagerImpl::OnLowVoltage() { is_low_voltage_ = true; resume_ctrl_->SaveLowVoltageTime(); resume_ctrl_->StopSavePersistentDataTimer(); - request_ctrl_.OnLowVoltage(); + request_ctrl_->OnLowVoltage(); } bool ApplicationManagerImpl::IsLowVoltage() const { @@ -3441,7 +3446,7 @@ void ApplicationManagerImpl::OnWakeUp() { SDL_LOG_AUTO_TRACE(); resume_ctrl_->SaveWakeUpTime(); resume_ctrl_->StartSavePersistentDataTimer(); - request_ctrl_.OnWakeUp(); + request_ctrl_->OnWakeUp(); is_low_voltage_ = false; } diff --git a/src/components/application_manager/src/commands/command_impl.cc b/src/components/application_manager/src/commands/command_impl.cc index c7b01efb7f2..c6ad7b79c1c 100644 --- a/src/components/application_manager/src/commands/command_impl.cc +++ b/src/components/application_manager/src/commands/command_impl.cc @@ -81,7 +81,9 @@ CommandImpl::CommandImpl(const MessageSharedPtr& message, HMICapabilities& hmi_capabilities, policy::PolicyHandlerInterface& policy_handler) : message_(message) - , default_timeout_(application_manager.get_settings().default_timeout()) + , default_timeout_( + application_manager.get_settings().default_timeout() + + application_manager.get_settings().default_timeout_compensation()) , allowed_to_terminate_(true) , application_manager_(application_manager) , rpc_service_(rpc_service) diff --git a/src/components/application_manager/src/commands/command_request_impl.cc b/src/components/application_manager/src/commands/command_request_impl.cc index dad2689f297..3b0c6bf98c4 100644 --- a/src/components/application_manager/src/commands/command_request_impl.cc +++ b/src/components/application_manager/src/commands/command_request_impl.cc @@ -44,6 +44,7 @@ #include "smart_objects/smart_object.h" #include "smart_objects/enum_schema_item.h" +#include "utils/helpers.h" namespace application_manager { @@ -468,6 +469,7 @@ uint32_t CommandRequestImpl::SendHMIRequest( const hmi_apis::FunctionID::eType& function_id, const smart_objects::SmartObject* msg_params, bool use_events) { + SDL_LOG_AUTO_TRACE(); smart_objects::SmartObjectSPtr result = std::make_shared(); @@ -493,7 +495,9 @@ uint32_t CommandRequestImpl::SendHMIRequest( subscribe_on_event(function_id, hmi_correlation_id); } if (ProcessHMIInterfacesAvailability(hmi_correlation_id, function_id)) { - if (!rpc_service_.ManageHMICommand(result, SOURCE_SDL_TO_HMI)) { + if (rpc_service_.ManageHMICommand(result, SOURCE_SDL_TO_HMI)) { + AddRequestToTimeoutHandler(request); + } else { SDL_LOG_ERROR("Unable to send request"); SendResponse(false, mobile_apis::Result::OUT_OF_MEMORY); } @@ -913,6 +917,51 @@ void CommandRequestImpl::AddTimeOutComponentInfoToMessage( } } +void CommandRequestImpl::AddRequestToTimeoutHandler( + const smart_objects::SmartObject& request_to_hmi) const { + auto function_id = static_cast( + request_to_hmi[strings::params][strings::function_id].asUInt()); + // SDL must not apply "default timeout for RPCs processing" for + // BasicCommunication.DialNumber RPC (that is, SDL must always wait for HMI + // response to BC.DialNumber as long as it takes and not return GENERIC_ERROR + // to mobile app), so the OnResetTimeout logic is not applicable for + // DialNumber RPC + if (helpers::Compare( + function_id, + hmi_apis::FunctionID::BasicCommunication_DialNumber, + hmi_apis::FunctionID::INVALID_ENUM)) { + SDL_LOG_DEBUG( + "Current RPC is DialNumber or Invalid, OnResetTimeout " + "logic is not applicable in this case"); + return; + } + + // If soft buttons are present in Alert or SubtleAlert RPC, SDL will not use + // timeout tracking for response, so the OnResetTimeout logic is not + // applicable in this case + if (helpers::Compare( + function_id, + hmi_apis::FunctionID::UI_Alert, + hmi_apis::FunctionID::UI_SubtleAlert)) { + if (request_to_hmi.keyExists(strings::msg_params)) { + if (request_to_hmi[strings::msg_params].keyExists( + strings::soft_buttons)) { + SDL_LOG_DEBUG("Soft buttons are present in " + << EnumToString(function_id) + << " RPC, OnResetTimeout " + "logic is not applicable in this case"); + return; + } + } + } + + const application_manager::request_controller::Request request{ + correlation_id(), connection_key(), static_cast(function_id)}; + application_manager_.get_request_timeout_handler().AddRequest( + request_to_hmi[strings::params][strings::correlation_id].asUInt(), + request); +} + } // namespace commands } // namespace application_manager diff --git a/src/components/application_manager/src/commands/request_from_hmi.cc b/src/components/application_manager/src/commands/request_from_hmi.cc index 835df702021..467001d8dbb 100644 --- a/src/components/application_manager/src/commands/request_from_hmi.cc +++ b/src/components/application_manager/src/commands/request_from_hmi.cc @@ -214,7 +214,7 @@ void RequestFromHMI::SendProviderRequest( if (hmi_destination) { SDL_LOG_DEBUG("Sending Request to HMI Provider"); application_manager_.IncreaseForwardedRequestTimeout( - application_manager::request_controller::RequestInfo::HmiConnectionKey, + application_manager::request_controller::RequestInfo::kHmiConnectionKey, correlation_id()); SendHMIRequest(hmi_function_id, &(*msg)[strings::msg_params], use_events); return; @@ -232,7 +232,7 @@ void RequestFromHMI::SendProviderRequest( SDL_LOG_DEBUG("Sending Request to Mobile Provider"); application_manager_.IncreaseForwardedRequestTimeout( - application_manager::request_controller::RequestInfo::HmiConnectionKey, + application_manager::request_controller::RequestInfo::kHmiConnectionKey, correlation_id()); SendMobileRequest( mobile_function_id, app, &(*msg)[strings::msg_params], use_events); diff --git a/src/components/application_manager/src/hmi_interfaces_impl.cc b/src/components/application_manager/src/hmi_interfaces_impl.cc index e4fa4c936c3..7365e5e081e 100644 --- a/src/components/application_manager/src/hmi_interfaces_impl.cc +++ b/src/components/application_manager/src/hmi_interfaces_impl.cc @@ -132,7 +132,8 @@ generate_function_to_interface_convert_map() { convert_map[TTS_GetSupportedLanguages] = HmiInterfaces::HMI_INTERFACE_TTS; convert_map[TTS_GetLanguage] = HmiInterfaces::HMI_INTERFACE_TTS; convert_map[TTS_SetGlobalProperties] = HmiInterfaces::HMI_INTERFACE_TTS; - convert_map[TTS_OnResetTimeout] = HmiInterfaces::HMI_INTERFACE_TTS; + convert_map[BasicCommunication_OnResetTimeout] = + HmiInterfaces::HMI_INTERFACE_BasicCommunication; convert_map[UI_Alert] = HmiInterfaces::HMI_INTERFACE_UI; convert_map[UI_SubtleAlert] = HmiInterfaces::HMI_INTERFACE_UI; convert_map[UI_Show] = HmiInterfaces::HMI_INTERFACE_UI; @@ -165,7 +166,6 @@ generate_function_to_interface_convert_map() { convert_map[UI_EndAudioPassThru] = HmiInterfaces::HMI_INTERFACE_UI; convert_map[UI_IsReady] = HmiInterfaces::HMI_INTERFACE_UI; convert_map[UI_ClosePopUp] = HmiInterfaces::HMI_INTERFACE_UI; - convert_map[UI_OnResetTimeout] = HmiInterfaces::HMI_INTERFACE_UI; convert_map[UI_SendHapticData] = HmiInterfaces::HMI_INTERFACE_UI; convert_map[Navigation_IsReady] = HmiInterfaces::HMI_INTERFACE_Navigation; convert_map[Navigation_SendLocation] = diff --git a/src/components/application_manager/src/request_controller.cc b/src/components/application_manager/src/request_controller_impl.cc similarity index 77% rename from src/components/application_manager/src/request_controller.cc rename to src/components/application_manager/src/request_controller_impl.cc index d94bb0e4df9..10f0f64b4ea 100644 --- a/src/components/application_manager/src/request_controller.cc +++ b/src/components/application_manager/src/request_controller_impl.cc @@ -34,7 +34,7 @@ #include "application_manager/commands/command_request_impl.h" #include "application_manager/commands/request_to_hmi.h" -#include "application_manager/request_controller.h" +#include "application_manager/request_controller_impl.h" #include "utils/timer_task_impl.h" @@ -46,37 +46,50 @@ using namespace sync_primitives; SDL_CREATE_LOG_VARIABLE("RequestController") -RequestController::RequestController(const RequestControlerSettings& settings) - : pool_state_(UNDEFINED) +RequestControllerImpl::RequestControllerImpl( + const RequestControlerSettings& settings, + RequestTimeoutHandler& request_timeout_handler) + : pool_state_(TPoolState::UNDEFINED) , pool_size_(settings.thread_pool_size()) , request_tracker_(settings) , duplicate_message_count_() , timer_("AM RequestCtrlTimer", - new timer::TimerTaskImpl( - this, &RequestController::TimeoutThread)) + new timer::TimerTaskImpl( + this, &RequestControllerImpl::TimeoutThread)) , timer_stop_flag_(false) , is_low_voltage_(false) - , settings_(settings) { + , settings_(settings) + , request_timeout_handler_(request_timeout_handler) { SDL_LOG_AUTO_TRACE(); InitializeThreadpool(); timer_.Start(0, timer::kSingleShot); } -RequestController::~RequestController() { +RequestControllerImpl::~RequestControllerImpl() { SDL_LOG_AUTO_TRACE(); + Stop(); +} + +void RequestControllerImpl::Stop() { + SDL_LOG_AUTO_TRACE(); + { sync_primitives::AutoLock auto_lock(timer_lock); timer_stop_flag_ = true; timer_condition_.Broadcast(); } - timer_.Stop(); + if (pool_state_ != TPoolState::STOPPED) { DestroyThreadpool(); } + + SDL_LOG_DEBUG("Stopping timeout tracker"); + timer_.Stop(); } -void RequestController::InitializeThreadpool() { +void RequestControllerImpl::InitializeThreadpool() { SDL_LOG_AUTO_TRACE(); + // TODO(DK): Consider lazy loading threads instead of creating all at once pool_state_ = TPoolState::STARTED; char name[50]; @@ -88,7 +101,7 @@ void RequestController::InitializeThreadpool() { } } -void RequestController::DestroyThreadpool() { +void RequestControllerImpl::DestroyThreadpool() { SDL_LOG_AUTO_TRACE(); { AutoLock auto_lock(mobile_request_list_lock_); @@ -105,12 +118,12 @@ void RequestController::DestroyThreadpool() { pool_.clear(); } -RequestController::TResult RequestController::CheckPosibilitytoAdd( +RequestControllerImpl::TResult RequestControllerImpl::CheckPosibilitytoAdd( const RequestPtr request, const mobile_apis::HMILevel::eType level) { SDL_LOG_AUTO_TRACE(); if (!CheckPendingRequestsAmount(settings_.pending_requests_amount())) { SDL_LOG_ERROR("Too many pending request"); - return RequestController::TOO_MANY_PENDING_REQUESTS; + return RequestController::TResult::TOO_MANY_PENDING_REQUESTS; } const TrackResult track_result = @@ -118,25 +131,26 @@ RequestController::TResult RequestController::CheckPosibilitytoAdd( if (TrackResult::kNoneLevelMaxRequestsExceeded == track_result) { SDL_LOG_ERROR("Too many application requests in hmi level NONE"); - return RequestController::NONE_HMI_LEVEL_MANY_REQUESTS; + return RequestController::TResult::NONE_HMI_LEVEL_MANY_REQUESTS; } if (TrackResult::kMaxRequestsExceeded == track_result) { SDL_LOG_ERROR("Too many application requests"); - return RequestController::TOO_MANY_REQUESTS; + return RequestController::TResult::TOO_MANY_REQUESTS; } if (IsLowVoltage()) { SDL_LOG_ERROR("Impossible to add request due to Low Voltage is active"); - return RequestController::INVALID_DATA; + return RequestController::TResult::INVALID_DATA; } - return SUCCESS; + return TResult::SUCCESS; } -bool RequestController::CheckPendingRequestsAmount( - const uint32_t& pending_requests_amount) { +bool RequestControllerImpl::CheckPendingRequestsAmount( + const uint32_t pending_requests_amount) { SDL_LOG_AUTO_TRACE(); + if (pending_requests_amount > 0) { const size_t pending_requests_size = mobile_request_list_.size(); const bool available_to_add = @@ -152,19 +166,19 @@ bool RequestController::CheckPendingRequestsAmount( return true; } -RequestController::TResult RequestController::addMobileRequest( +RequestController::TResult RequestControllerImpl::AddMobileRequest( const RequestPtr request, const mobile_apis::HMILevel::eType& hmi_level) { SDL_LOG_AUTO_TRACE(); if (!request) { SDL_LOG_ERROR("Null Pointer request"); cond_var_.NotifyOne(); - return INVALID_DATA; + return TResult::INVALID_DATA; } SDL_LOG_DEBUG("correlation_id : " << request->correlation_id() << "connection_key : " << request->connection_key()); RequestController::TResult result = CheckPosibilitytoAdd(request, hmi_level); - if (SUCCESS == result) { + if (TResult::SUCCESS == result) { AutoLock auto_lock_list(mobile_request_list_lock_); mobile_request_list_.push_back(request); SDL_LOG_DEBUG("Waiting for execution: " << mobile_request_list_.size()); @@ -174,13 +188,13 @@ RequestController::TResult RequestController::addMobileRequest( return result; } -RequestController::TResult RequestController::addHMIRequest( +RequestController::TResult RequestControllerImpl::AddHMIRequest( const RequestPtr request) { SDL_LOG_AUTO_TRACE(); if (request.use_count() == 0) { SDL_LOG_ERROR("HMI request pointer is invalid"); - return RequestController::INVALID_DATA; + return RequestController::TResult::INVALID_DATA; } SDL_LOG_DEBUG(" correlation_id : " << request->correlation_id()); @@ -197,18 +211,19 @@ RequestController::TResult RequestController::addHMIRequest( if (IsLowVoltage()) { SDL_LOG_ERROR("Impossible to add request due to Low Voltage is active"); - return RequestController::INVALID_DATA; + return RequestController::TResult::INVALID_DATA; } waiting_for_response_.Add(request_info_ptr); SDL_LOG_DEBUG("Waiting for response count:" << waiting_for_response_.Size()); NotifyTimer(); - return RequestController::SUCCESS; + return RequestController::TResult::SUCCESS; } -void RequestController::addNotification(const RequestPtr ptr) { +void RequestControllerImpl::AddNotification(const RequestPtr ptr) { SDL_LOG_AUTO_TRACE(); + if (IsLowVoltage()) { SDL_LOG_ERROR( "Impossible to add notification due to Low Voltage is active"); @@ -217,7 +232,7 @@ void RequestController::addNotification(const RequestPtr ptr) { notification_list_.push_back(ptr); } -void RequestController::removeNotification( +void RequestControllerImpl::RemoveNotification( const commands::Command* notification) { SDL_LOG_AUTO_TRACE(); std::list::iterator it = notification_list_.begin(); @@ -233,15 +248,16 @@ void RequestController::removeNotification( SDL_LOG_DEBUG("Cannot find notification"); } -void RequestController::TerminateRequest(const uint32_t correlation_id, - const uint32_t connection_key, - const int32_t function_id, - bool force_terminate) { +void RequestControllerImpl::TerminateRequest(const uint32_t correlation_id, + const uint32_t connection_key, + const int32_t function_id, + bool force_terminate) { SDL_LOG_AUTO_TRACE(); SDL_LOG_DEBUG("correlation_id = " << correlation_id << " connection_key = " << connection_key << " function_id = " << function_id << " force_terminate = " << force_terminate); + { AutoLock auto_lock(duplicate_message_count_lock_); auto dup_it = duplicate_message_count_.find(correlation_id); @@ -269,27 +285,32 @@ void RequestController::TerminateRequest(const uint32_t correlation_id, } if (force_terminate || request->request()->AllowedToTerminate()) { waiting_for_response_.RemoveRequest(request); + if (RequestInfo::HMIRequest == request->request_type()) { + request_timeout_handler_.RemoveRequest(request->requestId()); + } + } else { SDL_LOG_WARN("Request was not terminated"); } NotifyTimer(); } -void RequestController::OnMobileResponse(const uint32_t mobile_correlation_id, - const uint32_t connection_key, - const int32_t function_id) { +void RequestControllerImpl::OnMobileResponse( + const uint32_t mobile_correlation_id, + const uint32_t connection_key, + const int32_t function_id) { SDL_LOG_AUTO_TRACE(); TerminateRequest(mobile_correlation_id, connection_key, function_id); } -void RequestController::OnHMIResponse(const uint32_t correlation_id, - const int32_t function_id) { +void RequestControllerImpl::OnHMIResponse(const uint32_t correlation_id, + const int32_t function_id) { SDL_LOG_AUTO_TRACE(); - TerminateRequest(correlation_id, RequestInfo::HmiConnectionKey, function_id); + TerminateRequest(correlation_id, RequestInfo::kHmiConnectionKey, function_id); } -void RequestController::terminateWaitingForExecutionAppRequests( - const uint32_t& app_id) { +void RequestControllerImpl::TerminateWaitingForExecutionAppRequests( + const uint32_t app_id) { SDL_LOG_AUTO_TRACE(); SDL_LOG_DEBUG("app_id: " << app_id << "Waiting for execution" << mobile_request_list_.size()); @@ -306,15 +327,15 @@ void RequestController::terminateWaitingForExecutionAppRequests( SDL_LOG_DEBUG("Waiting for execution " << mobile_request_list_.size()); } -void RequestController::terminateWaitingForResponseAppRequests( - const uint32_t& app_id) { +void RequestControllerImpl::TerminateWaitingForResponseAppRequests( + const uint32_t app_id) { SDL_LOG_AUTO_TRACE(); waiting_for_response_.RemoveByConnectionKey(app_id); SDL_LOG_DEBUG( "Waiting for response count : " << waiting_for_response_.Size()); } -void RequestController::terminateAppRequests(const uint32_t& app_id) { +void RequestControllerImpl::TerminateAppRequests(const uint32_t app_id) { SDL_LOG_AUTO_TRACE(); SDL_LOG_DEBUG("app_id : " << app_id << "Requests waiting for execution count : " @@ -322,18 +343,19 @@ void RequestController::terminateAppRequests(const uint32_t& app_id) { << "Requests waiting for response count : " << waiting_for_response_.Size()); - terminateWaitingForExecutionAppRequests(app_id); - terminateWaitingForResponseAppRequests(app_id); + TerminateWaitingForExecutionAppRequests(app_id); + TerminateWaitingForResponseAppRequests(app_id); NotifyTimer(); } -void RequestController::terminateAllHMIRequests() { +void RequestControllerImpl::TerminateAllHMIRequests() { SDL_LOG_AUTO_TRACE(); - terminateWaitingForResponseAppRequests(RequestInfo::HmiConnectionKey); + TerminateWaitingForResponseAppRequests(RequestInfo::kHmiConnectionKey); } -void RequestController::terminateAllMobileRequests() { +void RequestControllerImpl::TerminateAllMobileRequests() { SDL_LOG_AUTO_TRACE(); + waiting_for_response_.RemoveMobileRequests(); SDL_LOG_DEBUG("Mobile Requests waiting for response cleared"); AutoLock waiting_execution_auto_lock(mobile_request_list_lock_); @@ -342,21 +364,30 @@ void RequestController::terminateAllMobileRequests() { NotifyTimer(); } -void RequestController::updateRequestTimeout(const uint32_t& app_id, - const uint32_t& correlation_id, - const uint32_t& new_timeout) { +void RequestControllerImpl::UpdateRequestTimeout(const uint32_t app_id, + const uint32_t correlation_id, + const uint32_t new_timeout) { SDL_LOG_AUTO_TRACE(); - SDL_LOG_DEBUG("app_id : " << app_id << " mobile_correlation_id : " << correlation_id << " new_timeout : " << new_timeout); - SDL_LOG_DEBUG( - "New_timeout is NULL. RequestCtrl will " - "not manage this request any more"); + + if (new_timeout == 0) { + SDL_LOG_DEBUG( + "New_timeout is NULL. RequestCtrl will " + "not manage this request any more"); + } RequestInfoPtr request_info = waiting_for_response_.Find(app_id, correlation_id); if (request_info) { + if (0 == request_info->timeout_msec()) { + SDL_LOG_INFO( + "Request with zero timeout is not updating, " + "manual control is assumed"); + return; + } + waiting_for_response_.RemoveRequest(request_info); request_info->updateTimeOut(new_timeout); waiting_for_response_.Add(request_info); @@ -371,26 +402,32 @@ void RequestController::updateRequestTimeout(const uint32_t& app_id, } } -void RequestController::OnLowVoltage() { +void RequestControllerImpl::OnLowVoltage() { SDL_LOG_AUTO_TRACE(); is_low_voltage_ = true; } -void RequestController::OnWakeUp() { +void RequestControllerImpl::OnWakeUp() { SDL_LOG_AUTO_TRACE(); - terminateAllHMIRequests(); - terminateAllMobileRequests(); + TerminateAllHMIRequests(); + TerminateAllMobileRequests(); is_low_voltage_ = false; SDL_LOG_DEBUG("Terminate old requests done"); } -bool RequestController::IsLowVoltage() { +bool RequestControllerImpl::IsLowVoltage() { SDL_LOG_TRACE("result: " << is_low_voltage_); return is_low_voltage_; } -void RequestController::TimeoutThread() { +void RequestControllerImpl::TimeoutThread() { SDL_LOG_AUTO_TRACE(); + + if (TPoolState::STOPPED == pool_state_) { + SDL_LOG_DEBUG("Thread pool has been stopped. Skipping timer restart"); + return; + } + SDL_LOG_DEBUG( "ENTER Waiting fore response count: " << waiting_for_response_.Size()); sync_primitives::AutoLock auto_lock(timer_lock); @@ -427,18 +464,21 @@ void RequestController::TimeoutThread() { << " request id: " << probably_expired->requestId() << " connection_key: " << probably_expired->app_id() << " is expired"); - const uint32_t experied_request_id = probably_expired->requestId(); - const uint32_t experied_app_id = probably_expired->app_id(); + const uint32_t expired_request_id = probably_expired->requestId(); + const uint32_t expired_app_id = probably_expired->app_id(); probably_expired->request()->onTimeOut(); - if (RequestInfo::HmiConnectionKey == probably_expired->app_id()) { + if (RequestInfo::kHmiConnectionKey == probably_expired->app_id()) { SDL_LOG_DEBUG("Erase HMI request: " << probably_expired->requestId()); waiting_for_response_.RemoveRequest(probably_expired); + if (RequestInfo::HMIRequest == probably_expired->request_type()) { + request_timeout_handler_.RemoveRequest(expired_request_id); + } } probably_expired = waiting_for_response_.FrontWithNotNullTimeout(); if (probably_expired) { - if (experied_request_id == probably_expired->requestId() && - experied_app_id == probably_expired->app_id()) { + if (expired_request_id == probably_expired->requestId() && + expired_app_id == probably_expired->app_id()) { SDL_LOG_DEBUG("Expired request wasn't removed"); break; } @@ -448,12 +488,12 @@ void RequestController::TimeoutThread() { "EXIT Waiting for response count : " << waiting_for_response_.Size()); } -RequestController::Worker::Worker(RequestController* requestController) - : request_controller_(requestController), stop_flag_(false) {} +RequestControllerImpl::Worker::Worker(RequestControllerImpl* request_controller) + : request_controller_(request_controller), stop_flag_(false) {} -RequestController::Worker::~Worker() {} +RequestControllerImpl::Worker::~Worker() {} -void RequestController::Worker::threadMain() { +void RequestControllerImpl::Worker::threadMain() { SDL_LOG_AUTO_TRACE(); AutoLock auto_lock(thread_lock_); while (!stop_flag_) { @@ -531,13 +571,13 @@ void RequestController::Worker::threadMain() { } } -void RequestController::Worker::exitThreadMain() { +void RequestControllerImpl::Worker::exitThreadMain() { stop_flag_ = true; // setup stop flag and whit while threadMain will be finished correctly // FIXME (dchmerev@luxoft.com): There is no waiting } -void RequestController::NotifyTimer() { +void RequestControllerImpl::NotifyTimer() { SDL_LOG_AUTO_TRACE(); timer_condition_.NotifyOne(); } diff --git a/src/components/application_manager/src/request_info.cc b/src/components/application_manager/src/request_info.cc index b1c1d68eaac..6770e839b3a 100644 --- a/src/components/application_manager/src/request_info.cc +++ b/src/components/application_manager/src/request_info.cc @@ -42,12 +42,12 @@ namespace request_controller { SDL_CREATE_LOG_VARIABLE("RequestController") -uint32_t RequestInfo::HmiConnectionKey = 0; +constexpr uint32_t RequestInfo::kHmiConnectionKey; HMIRequestInfo::HMIRequestInfo(RequestPtr request, const uint64_t timeout_msec) : RequestInfo(request, HMIRequest, timeout_msec) { correlation_id_ = request_->correlation_id(); - app_id_ = RequestInfo::HmiConnectionKey; + app_id_ = RequestInfo::kHmiConnectionKey; } HMIRequestInfo::HMIRequestInfo(RequestPtr request, @@ -55,7 +55,7 @@ HMIRequestInfo::HMIRequestInfo(RequestPtr request, const uint64_t timeout_msec) : RequestInfo(request, HMIRequest, start_time, timeout_msec) { correlation_id_ = request_->correlation_id(); - app_id_ = RequestInfo::HmiConnectionKey; + app_id_ = RequestInfo::kHmiConnectionKey; } MobileRequestInfo::MobileRequestInfo(RequestPtr request, @@ -132,13 +132,13 @@ bool RequestInfoSet::Add(RequestInfoPtr request_info) { << request_info->requestId()); sync_primitives::AutoLock lock(pending_requests_lock_); CheckSetSizes(); - const std::pair& insert_resilt = + const std::pair& insert_result = hash_sorted_pending_requests_.insert(request_info); - if (insert_resilt.second == true) { - const std::pair& insert_resilt = + if (insert_result.second == true) { + const std::pair& insert_result = time_sorted_pending_requests_.insert(request_info); - DCHECK(insert_resilt.second); - if (!insert_resilt.second) { + DCHECK(insert_result.second); + if (!insert_result.second) { return false; } CheckSetSizes(); @@ -153,7 +153,7 @@ bool RequestInfoSet::Add(RequestInfoPtr request_info) { } RequestInfoPtr RequestInfoSet::Find(const uint32_t connection_key, - const uint32_t correlation_id) { + const uint32_t correlation_id) const { RequestInfoPtr result; // Request info for searching in request info set by log_n time @@ -259,7 +259,7 @@ uint32_t RequestInfoSet::RemoveByConnectionKey(uint32_t connection_key) { uint32_t RequestInfoSet::RemoveMobileRequests() { SDL_LOG_AUTO_TRACE(); return RemoveRequests(AppIdCompararator(AppIdCompararator::NotEqual, - RequestInfo::HmiConnectionKey)); + RequestInfo::kHmiConnectionKey)); } const size_t RequestInfoSet::Size() { diff --git a/src/components/application_manager/src/request_timeout_handler_impl.cc b/src/components/application_manager/src/request_timeout_handler_impl.cc new file mode 100644 index 00000000000..f246693d569 --- /dev/null +++ b/src/components/application_manager/src/request_timeout_handler_impl.cc @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2020, 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 "application_manager/request_timeout_handler_impl.h" +#include "application_manager/message_helper.h" +#include "application_manager/request_info.h" +#include "utils/logger.h" + +SDL_CREATE_LOG_VARIABLE("RequestTimeoutHandler") + +namespace application_manager { +namespace request_controller { + +RequestTimeoutHandlerImpl::RequestTimeoutHandlerImpl( + ApplicationManager& application_manager) + : EventObserver(application_manager.event_dispatcher()) + , application_manager_(application_manager) { + subscribe_on_event(hmi_apis::FunctionID::BasicCommunication_OnResetTimeout); +} + +void RequestTimeoutHandlerImpl::AddRequest(const uint32_t hmi_correlation_id, + const Request& request) { + requests_.insert(std::make_pair(hmi_correlation_id, request)); +} + +void RequestTimeoutHandlerImpl::RemoveRequest( + const uint32_t hmi_correlation_id) { + SDL_LOG_AUTO_TRACE(); + sync_primitives::AutoLock lock(requests_lock_); + auto it = requests_.find(hmi_correlation_id); + if (it != requests_.end()) { + requests_.erase(it); + }; +} + +bool RequestTimeoutHandlerImpl::IsTimeoutUpdateRequired( + const Request& request, + const uint32_t timeout, + const hmi_apis::FunctionID::eType method_name) { + if (0 == timeout) { + SDL_LOG_WARN("Zero timeout ignored"); + return false; + } + + if (static_cast(request.hmi_function_id_) != + method_name) { + SDL_LOG_WARN("Method name does not match the hmi function id"); + return false; + } + + return true; +} + +void RequestTimeoutHandlerImpl::on_event(const event_engine::Event& event) { + SDL_LOG_AUTO_TRACE(); + const auto event_id = event.id(); + if (hmi_apis::FunctionID::BasicCommunication_OnResetTimeout == event_id) { + const smart_objects::SmartObject& message = event.smart_object(); + const auto method_name = StringToEnum( + message[strings::msg_params][strings::method_name].asString()); + + if (hmi_apis::FunctionID::INVALID_ENUM == method_name) { + SDL_LOG_WARN( + "Wrong method name received: " + << message[strings::msg_params][strings::method_name].asString()); + return; + } + uint32_t timeout = application_manager_.get_settings().default_timeout(); + if (message[strings::msg_params].keyExists(strings::reset_period)) { + timeout = message[strings::msg_params][strings::reset_period].asUInt(); + } + const auto hmi_corr_id = + message[strings::msg_params][strings::request_id].asUInt(); + auto it = requests_.find(hmi_corr_id); + if (it != requests_.end()) { + const auto& request = it->second; + if (IsTimeoutUpdateRequired(request, timeout, method_name)) { + // Add compensation time + timeout += + application_manager_.get_settings().default_timeout_compensation(); + application_manager_.UpdateRequestTimeout( + request.connection_key_, request.mob_correlation_id_, timeout); + application_manager_.UpdateRequestTimeout( + RequestInfo::kHmiConnectionKey, hmi_corr_id, timeout); + } + } else { + SDL_LOG_WARN("Timeout reset failed by " << hmi_corr_id + << ", no such mobile command"); + } + } +} +} // namespace request_controller +} // namespace application_manager diff --git a/src/components/application_manager/src/rpc_service_impl.cc b/src/components/application_manager/src/rpc_service_impl.cc index 6cb03705abc..67ff7cb6f0d 100644 --- a/src/components/application_manager/src/rpc_service_impl.cc +++ b/src/components/application_manager/src/rpc_service_impl.cc @@ -36,6 +36,7 @@ #include "application_manager/app_service_manager.h" #include "application_manager/command_factory.h" #include "application_manager/commands/command.h" +#include "application_manager/commands/command_impl.h" #include "application_manager/plugin_manager/plugin_keys.h" namespace application_manager { @@ -225,11 +226,11 @@ bool RPCServiceImpl::ManageMobileCommand( return true; } if (message_type == mobile_apis::messageType::notification) { - request_ctrl_.addNotification(command); + request_ctrl_.AddNotification(command); if (command->Init() && command->CheckPermissions()) { command->Run(); if (command->CleanUp()) { - request_ctrl_.removeNotification(command.get()); + request_ctrl_.RemoveNotification(command.get()); } // If CleanUp returned false notification should remove it self. } @@ -260,11 +261,11 @@ bool RPCServiceImpl::ManageMobileCommand( // commands will be launched from request_ctrl const request_controller::RequestController::TResult result = - request_ctrl_.addMobileRequest(command, app_hmi_level); + request_ctrl_.AddMobileRequest(command, app_hmi_level); - if (result == request_controller::RequestController::SUCCESS) { + if (result == request_controller::RequestController::TResult::SUCCESS) { SDL_LOG_DEBUG("Perform request"); - } else if (result == request_controller::RequestController:: + } else if (result == request_controller::RequestController::TResult:: TOO_MANY_PENDING_REQUESTS) { SDL_LOG_ERROR("RET Unable top perform request: " << "TOO_MANY_PENDING_REQUESTS"); @@ -283,8 +284,8 @@ bool RPCServiceImpl::ManageMobileCommand( SendMessageToMobile(response); return false; - } else if (result == - request_controller::RequestController::TOO_MANY_REQUESTS) { + } else if (result == request_controller::RequestController::TResult:: + TOO_MANY_REQUESTS) { SDL_LOG_ERROR("RET Unable to perform request: " << "TOO_MANY_REQUESTS"); @@ -303,7 +304,7 @@ bool RPCServiceImpl::ManageMobileCommand( app_ptr->usage_report().RecordRemovalsForBadBehavior(); } return false; - } else if (result == request_controller::RequestController:: + } else if (result == request_controller::RequestController::TResult:: NONE_HMI_LEVEL_MANY_REQUESTS) { SDL_LOG_ERROR("RET Unable to perform request: " << "REQUEST_WHILE_IN_NONE_HMI_LEVEL"); @@ -391,7 +392,7 @@ bool RPCServiceImpl::ManageHMICommand(const commands::MessageSharedPtr message, if (kRequest == message_type) { SDL_LOG_DEBUG("ManageHMICommand"); command->set_warning_info(warning_info); - request_ctrl_.addHMIRequest(command); + request_ctrl_.AddHMIRequest(command); } if (command->Init()) { diff --git a/src/components/application_manager/src/smart_object_keys.cc b/src/components/application_manager/src/smart_object_keys.cc index b7c40987ade..1490f9f5b1b 100644 --- a/src/components/application_manager/src/smart_object_keys.cc +++ b/src/components/application_manager/src/smart_object_keys.cc @@ -461,6 +461,10 @@ const char* const rect = "rect"; const char* const x = "x"; const char* const y = "y"; const char* const preferred_fps = "preferredFPS"; + +// OnResetTimeout +const char* const request_id = "requestID"; +const char* const reset_period = "resetPeriod"; } // namespace strings namespace hmi_interface { diff --git a/src/components/application_manager/test/CMakeLists.txt b/src/components/application_manager/test/CMakeLists.txt index cdaa770155f..596d11cfa98 100755 --- a/src/components/application_manager/test/CMakeLists.txt +++ b/src/components/application_manager/test/CMakeLists.txt @@ -72,6 +72,7 @@ set(testSources ${AM_TEST_DIR}/application_helper_test.cc ${AM_TEST_DIR}/rpc_service_impl_test.cc ${AM_TEST_DIR}/command_holder_test.cc + ${AM_TEST_DIR}/request_timeout_handler_test.cc ) set(testSourcesMockHmi diff --git a/src/components/application_manager/test/commands/command_impl_test.cc b/src/components/application_manager/test/commands/command_impl_test.cc index 734a7d91b81..b7b0801167f 100644 --- a/src/components/application_manager/test/commands/command_impl_test.cc +++ b/src/components/application_manager/test/commands/command_impl_test.cc @@ -150,7 +150,9 @@ TEST_F(CommandImplTest, GetMethods_SUCCESS) { (*msg)[strings::params][strings::function_id] = kFunctionId; (*msg)[strings::params][strings::connection_key] = kConnectionKey; - EXPECT_EQ(kDefaultTimeout_, command->default_timeout()); + const uint32_t expected_timeout = + kDefaultTimeout_ + kDefaultTimeoutCompensation_; + EXPECT_EQ(expected_timeout, command->default_timeout()); EXPECT_EQ(kCorrelationId, command->correlation_id()); EXPECT_EQ(kConnectionKey, command->connection_key()); EXPECT_EQ(kFunctionId, command->function_id()); diff --git a/src/components/application_manager/test/help_prompt_manager_test.cc b/src/components/application_manager/test/help_prompt_manager_test.cc index caff56f675d..d9fb0b82d95 100644 --- a/src/components/application_manager/test/help_prompt_manager_test.cc +++ b/src/components/application_manager/test/help_prompt_manager_test.cc @@ -57,6 +57,7 @@ const uint32_t kAppId = 10u; const uint32_t kCmdId = 1u; const std::string kPolicyAppId = "fake_app_id"; const uint32_t kTimeout = 10000u; +const uint32_t kTimeoutCompensation = 1000u; const std::string kText = "one"; const uint32_t kPosition = 1u; const std::string kFirstVrCommand = "first"; @@ -168,6 +169,8 @@ void HelpPromptManagerTest::SetUp() { .WillByDefault(ReturnRef(mock_event_dispatcher_)); ON_CALL(app_mngr_settings_, default_timeout()) .WillByDefault(ReturnRef(kTimeout)); + ON_CALL(app_mngr_settings_, default_timeout_compensation()) + .WillByDefault(ReturnRef(kTimeoutCompensation)); ON_CALL(app_mngr_settings_, app_icons_folder()) .WillByDefault(ReturnRef(kDirectoryName)); ON_CALL(app_mngr_settings_, app_storage_folder()) diff --git a/src/components/application_manager/test/include/application_manager/commands/command_request_test.h b/src/components/application_manager/test/include/application_manager/commands/command_request_test.h index 3a44d7b3ff6..b252d37181a 100644 --- a/src/components/application_manager/test/include/application_manager/commands/command_request_test.h +++ b/src/components/application_manager/test/include/application_manager/commands/command_request_test.h @@ -38,6 +38,7 @@ #include "gtest/gtest.h" #include "application_manager/commands/command_request_impl.h" +#include "application_manager/mock_request_timeout_handler.h" #include "application_manager/smart_object_keys.h" #include "application_manager/test/include/application_manager/commands/commands_test.h" #include "application_manager/test/include/application_manager/mock_event_dispatcher.h" @@ -59,6 +60,7 @@ namespace am = ::application_manager; using am::commands::Command; using am::commands::CommandRequestImpl; using am::event_engine::Event; +using test::components::application_manager_test::MockRequestTimeoutHandler; class CallRun { public: @@ -112,14 +114,17 @@ class CommandRequestTest : public CommandsTest { } MockEventDisp event_dispatcher_; + MockRequestTimeoutHandler mock_request_timeout_handler_; protected: CommandRequestTest() : CommandsTest() {} - virtual void InitCommand(const uint32_t& default_timeout) OVERRIDE { + void InitCommand(const uint32_t& default_timeout) OVERRIDE { CommandsTest::InitCommand(default_timeout); ON_CALL(CommandsTest::app_mngr_, event_dispatcher()) .WillByDefault(ReturnRef(event_dispatcher_)); + ON_CALL(CommandsTest::app_mngr_, get_request_timeout_handler()) + .WillByDefault(ReturnRef(mock_request_timeout_handler_)); } }; diff --git a/src/components/application_manager/test/include/application_manager/commands/commands_test.h b/src/components/application_manager/test/include/application_manager/commands/commands_test.h index 18afa01a883..2087ef8f289 100644 --- a/src/components/application_manager/test/include/application_manager/commands/commands_test.h +++ b/src/components/application_manager/test/include/application_manager/commands/commands_test.h @@ -146,7 +146,7 @@ class CommandsTest : public ::testing::Test { mock_policy_handler_); } - enum { kDefaultTimeout_ = 100 }; + enum { kDefaultTimeout_ = 100, kDefaultTimeoutCompensation_ = 10 }; MockAppManager app_mngr_; MockRPCService mock_rpc_service_; @@ -160,16 +160,25 @@ class CommandsTest : public ::testing::Test { protected: virtual void InitCommand(const uint32_t& timeout) { + this->InitCommand(timeout, kDefaultTimeoutCompensation_); + } + + virtual void InitCommand(const uint32_t timeout, + const uint32_t compensation) { timeout_ = timeout; + timeout_compensation_ = compensation; ON_CALL(app_mngr_, get_settings()) .WillByDefault(ReturnRef(app_mngr_settings_)); ON_CALL(app_mngr_settings_, default_timeout()) .WillByDefault(ReturnRef(timeout_)); + ON_CALL(app_mngr_settings_, default_timeout_compensation()) + .WillByDefault(ReturnRef(timeout_compensation_)); } CommandsTest() : mock_message_helper_(*am::MockMessageHelper::message_helper_mock()) - , timeout_(0) { + , timeout_(0) + , timeout_compensation_(0) { ON_CALL(app_mngr_, hmi_interfaces()) .WillByDefault(ReturnRef(mock_hmi_interfaces_)); ON_CALL(mock_hmi_interfaces_, GetInterfaceFromFunction(_)) @@ -254,6 +263,7 @@ class CommandsTest : public ::testing::Test { private: uint32_t timeout_; + uint32_t timeout_compensation_; }; MATCHER_P(MobileResultCodeIs, result_code, "") { diff --git a/src/components/application_manager/test/message_helper/message_helper_test.cc b/src/components/application_manager/test/message_helper/message_helper_test.cc index d2dc8f3528b..4b36647a112 100644 --- a/src/components/application_manager/test/message_helper/message_helper_test.cc +++ b/src/components/application_manager/test/message_helper/message_helper_test.cc @@ -37,7 +37,6 @@ #include "gmock/gmock.h" #include "utils/macro.h" -#include "application_manager/commands/command_impl.h" #include "application_manager/event_engine/event_dispatcher.h" #include "application_manager/mock_application.h" #include "application_manager/mock_application_manager.h" @@ -53,6 +52,7 @@ #include "utils/custom_string.h" #include "utils/lock.h" +#include "application_manager/commands/command_impl.h" #include "policy/policy_table/types.h" #include "rpc_base/rpc_base_json_inl.h" @@ -650,7 +650,6 @@ class MessageHelperTest : public ::testing::Test { const StringArray function_id_strings; const StringArray events_id_strings; const StringArray hmi_level_strings; - const size_t delta_from_functions_id; }; diff --git a/src/components/application_manager/test/request_controller/request_controller_test.cc b/src/components/application_manager/test/request_controller/request_controller_test.cc index 992bf8e303e..ccb7788b3d5 100644 --- a/src/components/application_manager/test/request_controller/request_controller_test.cc +++ b/src/components/application_manager/test/request_controller/request_controller_test.cc @@ -33,7 +33,7 @@ #include #include "application_manager/mock_request.h" -#include "application_manager/request_controller.h" +#include "application_manager/request_controller_impl.h" #include "application_manager/request_info.h" #include "gtest/gtest.h" @@ -43,8 +43,11 @@ #include "smart_objects/smart_object.h" #include "application_manager/event_engine/event_dispatcher.h" +#include "application_manager/mock_application_manager.h" + #include "application_manager/mock_application_manager.h" #include "application_manager/mock_request_controller_settings.h" +#include "application_manager/mock_request_timeout_handler.h" #include "application_manager/policies/policy_handler.h" #include "application_manager/resumption/resume_ctrl.h" #include "application_manager/state_controller.h" @@ -56,7 +59,9 @@ namespace components { namespace request_controller_test { using ::application_manager::request_controller::RequestController; +using ::application_manager::request_controller::RequestControllerImpl; using ::application_manager::request_controller::RequestInfo; +using test::components::application_manager_test::MockRequestTimeoutHandler; using ::testing::_; using ::testing::NiceMock; @@ -65,7 +70,7 @@ using ::testing::ReturnRef; typedef NiceMock MRequest; typedef std::shared_ptr RequestPtr; -typedef std::shared_ptr RequestControllerSPtr; +typedef std::shared_ptr RequestControllerSPtr; namespace { const size_t kNumberOfRequests = 10u; @@ -103,8 +108,8 @@ class RequestControllerTestClass : public ::testing::Test { RequestControllerTestClass() { ON_CALL(mock_request_controller_settings_, thread_pool_size()) .WillByDefault(Return(kThreadPoolSize)); - request_ctrl_ = - std::make_shared(mock_request_controller_settings_); + request_ctrl_ = std::make_shared( + mock_request_controller_settings_, mock_request_timeout_handler_); } RequestPtr GetMockRequest( @@ -126,10 +131,10 @@ class RequestControllerTestClass : public ::testing::Test { const mobile_apis::HMILevel::eType& hmi_level = mobile_apis::HMILevel::INVALID_ENUM) { if (RequestInfo::RequestType::HMIRequest == request_type) { - return request_ctrl_->addHMIRequest(request); + return request_ctrl_->AddHMIRequest(request); } CallSettings(settings); - return request_ctrl_->addMobileRequest(request, hmi_level); + return request_ctrl_->AddMobileRequest(request, hmi_level); } void CallSettings(const TestSettings& settings) const { @@ -154,6 +159,7 @@ class RequestControllerTestClass : public ::testing::Test { NiceMock mock_request_controller_settings_; + MockRequestTimeoutHandler mock_request_timeout_handler_; RequestControllerSPtr request_ctrl_; RequestPtr empty_mock_request_; const TestSettings default_settings_; @@ -169,7 +175,7 @@ TEST_F(RequestControllerTestClass, .Times(1) .WillRepeatedly(NotifyTestAsyncWaiter(waiter_valid)); - EXPECT_EQ(RequestController::SUCCESS, + EXPECT_EQ(RequestController::TResult::SUCCESS, AddRequest(default_settings_, request_valid, RequestInfo::RequestType::MobileRequest, @@ -185,7 +191,7 @@ TEST_F(RequestControllerTestClass, ON_CALL(*request_dup_corr_id, Run()) .WillByDefault(NotifyTestAsyncWaiter(waiter_dup)); - EXPECT_EQ(RequestController::SUCCESS, + EXPECT_EQ(RequestController::TResult::SUCCESS, AddRequest(default_settings_, request_dup_corr_id, RequestInfo::RequestType::MobileRequest, @@ -200,7 +206,7 @@ TEST_F(RequestControllerTestClass, // app_hmi_level_none_time_scale_max_requests_ equals 0 // (in the default settings they setted to 0) for (size_t i = 0; i < kMaxRequestAmount; ++i) { - EXPECT_EQ(RequestController::SUCCESS, + EXPECT_EQ(RequestController::TResult::SUCCESS, AddRequest(default_settings_, GetMockRequest(i), RequestInfo::RequestType::MobileRequest, @@ -247,7 +253,7 @@ TEST_F(RequestControllerTestClass, IsLowVoltage_SetOnWakeUp_FALSE) { } TEST_F(RequestControllerTestClass, AddMobileRequest_SetValidData_SUCCESS) { - EXPECT_EQ(RequestController::SUCCESS, + EXPECT_EQ(RequestController::TResult::SUCCESS, AddRequest(default_settings_, GetMockRequest(), RequestInfo::RequestType::MobileRequest, @@ -256,7 +262,7 @@ TEST_F(RequestControllerTestClass, AddMobileRequest_SetValidData_SUCCESS) { TEST_F(RequestControllerTestClass, AddMobileRequest_SetInvalidData_INVALID_DATA) { - EXPECT_EQ(RequestController::INVALID_DATA, + EXPECT_EQ(RequestController::TResult::INVALID_DATA, AddRequest(default_settings_, empty_mock_request_, RequestInfo::RequestType::MobileRequest, @@ -264,14 +270,14 @@ TEST_F(RequestControllerTestClass, } TEST_F(RequestControllerTestClass, AddHMIRequest_AddRequest_SUCCESS) { - EXPECT_EQ(RequestController::SUCCESS, + EXPECT_EQ(RequestController::TResult::SUCCESS, AddRequest(default_settings_, GetMockRequest(), RequestInfo::RequestType::HMIRequest)); } TEST_F(RequestControllerTestClass, AddHMIRequest_AddInvalidData_INVALID_DATA) { - EXPECT_EQ(RequestController::INVALID_DATA, + EXPECT_EQ(RequestController::TResult::INVALID_DATA, AddRequest(default_settings_, empty_mock_request_, RequestInfo::RequestType::HMIRequest)); @@ -283,7 +289,7 @@ TEST_F(RequestControllerTestClass, OnTimer_SUCCESS) { kDefaultCorrelationID, kDefaultConnectionKey, request_timeout); auto waiter = TestAsyncWaiter::createInstance(); - EXPECT_EQ(RequestController::SUCCESS, + EXPECT_EQ(RequestController::TResult::SUCCESS, AddRequest(default_settings_, mock_request, RequestInfo::RequestType::MobileRequest)); diff --git a/src/components/application_manager/test/request_timeout_handler_test.cc b/src/components/application_manager/test/request_timeout_handler_test.cc new file mode 100644 index 00000000000..c045a653aa0 --- /dev/null +++ b/src/components/application_manager/test/request_timeout_handler_test.cc @@ -0,0 +1,306 @@ +/* + * Copyright (c) 2020, 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 "application_manager/request_timeout_handler_impl.h" + +#include +#include + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_event_dispatcher.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/mock_request_controller.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/request_info.h" +#include "sdl_rpc_plugin/commands/hmi/on_reset_timeout_notification.h" +#include "sdl_rpc_plugin/commands/mobile/subscribe_way_points_request.h" +#include "sdl_rpc_plugin/commands/mobile/unsubscribe_way_points_request.h" + +namespace test { +namespace components { +namespace request_timeout_handler_test { + +using application_manager::event_engine::Event; +using ::testing::_; +using ::testing::Mock; +using ::testing::Return; +using ::testing::ReturnRef; +using namespace application_manager::commands; +using namespace application_manager::strings; +using namespace application_manager::request_controller; +using application_manager_test::MockRequestController; +using sdl_rpc_plugin::commands::SubscribeWayPointsRequest; +using sdl_rpc_plugin::commands::UnsubscribeWayPointsRequest; + +namespace { +const uint32_t kDefaultTimeout = 10000u; +const uint32_t kDefaultTimeoutCompensation = 1000u; +const uint32_t kTimeout = 13000u; +const uint32_t kRequestId = 22; +const std::string kMethodNameSubscribeWayPoints = + "Navigation.SubscribeWayPoints"; +const std::string kMethodNameUnsubscribeWayPoints = + "Navigation.UnsubscribeWayPoints"; +const uint32_t kConnectionKey = 3u; +} // namespace + +class RequestTimeoutHandlerTest + : public commands_test::CommandRequestTest< + commands_test::CommandsTestMocks::kIsNice> { + public: + RequestTimeoutHandlerTest() + : mock_message_helper_( + application_manager::MockMessageHelper::message_helper_mock()) {} + + protected: + void SetUp() OVERRIDE { + ON_CALL(app_mngr_, event_dispatcher()) + .WillByDefault(ReturnRef(event_dispatcher_)); + ON_CALL(app_mngr_, get_request_controller()) + .WillByDefault(ReturnRef(mock_request_controller_)); + request_timeout_handler_ = + std::make_shared(app_mngr_); + Mock::VerifyAndClearExpectations(&mock_message_helper_); + } + + void TearDown() OVERRIDE { + Mock::VerifyAndClearExpectations(&mock_message_helper_); + } + + template + std::unique_ptr CreateCommand() { + ON_CALL(app_mngr_, get_settings()) + .WillByDefault(ReturnRef(app_mngr_settings_)); + ON_CALL(app_mngr_settings_, default_timeout()) + .WillByDefault(ReturnRef(kDefaultTimeout)); + ON_CALL(app_mngr_settings_, default_timeout_compensation()) + .WillByDefault(ReturnRef(kDefaultTimeoutCompensation)); + + std::shared_ptr msg = + std::make_shared( + smart_objects::SmartType_Null); + + std::unique_ptr command(new Command(msg, + app_mngr_, + mock_rpc_service_, + mock_hmi_capabilities_, + mock_policy_handler_)); + return command; + } + + application_manager::MockMessageHelper* mock_message_helper_; + MockRequestController mock_request_controller_; + std::shared_ptr request_timeout_handler_; + testing::NiceMock + mock_hmi_capabilities_; + policy_test::MockPolicyHandlerInterface mock_policy_handler_; +}; + +TEST_F(RequestTimeoutHandlerTest, OnEvent_OnResetTimeout_SUCCESS) { + // RequestTimeoutHandler works with all the commands. + // But just for testing, only SubscribeWayPointsRequest was chosen in current + // test. + std::unique_ptr command = + CreateCommand(); + MockAppPtr mock_app = CreateMockApp(); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); + ON_CALL(app_mngr_, IsAppSubscribedForWayPoints(Ref(*mock_app))) + .WillByDefault(Return(false)); + ON_CALL(app_mngr_, IsAnyAppSubscribedForWayPoints()) + .WillByDefault(Return(false)); + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kRequestId)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)).WillOnce(Return(true)); + + Event event(hmi_apis::FunctionID::BasicCommunication_OnResetTimeout); + smart_objects::SmartObject notification_msg; + notification_msg[msg_params][reset_period] = kTimeout; + notification_msg[msg_params][request_id] = kRequestId; + notification_msg[msg_params][method_name] = kMethodNameSubscribeWayPoints; + event.set_smart_object(notification_msg); + + ON_CALL(app_mngr_, get_settings()) + .WillByDefault(ReturnRef(app_mngr_settings_)); + ON_CALL(app_mngr_settings_, default_timeout()) + .WillByDefault(ReturnRef(kDefaultTimeout)); + ON_CALL(app_mngr_settings_, default_timeout_compensation()) + .WillByDefault(ReturnRef(kDefaultTimeoutCompensation)); + + EXPECT_CALL(app_mngr_, get_request_timeout_handler()) + .WillOnce(ReturnRef(*request_timeout_handler_)); + + EXPECT_CALL(app_mngr_, + UpdateRequestTimeout(mock_app->app_id(), + command->correlation_id(), + kTimeout + kDefaultTimeoutCompensation)); + EXPECT_CALL(app_mngr_, + UpdateRequestTimeout(RequestInfo::kHmiConnectionKey, + kRequestId, + kTimeout + kDefaultTimeoutCompensation)); + + ASSERT_TRUE(command->Init()); + command->Run(); + request_timeout_handler_->on_event(event); +} + +TEST_F(RequestTimeoutHandlerTest, OnEvent_OnResetTimeout_MissedResetPeriod) { + // RequestTimeoutHandler works with all the commands. + // But just for testing, only SubscribeWayPointsRequest was chosen in current + // test. + + std::unique_ptr command = + CreateCommand(); + MockAppPtr mock_app = CreateMockApp(); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); + ON_CALL(app_mngr_, IsAppSubscribedForWayPoints(Ref(*mock_app))) + .WillByDefault(Return(false)); + ON_CALL(app_mngr_, IsAnyAppSubscribedForWayPoints()) + .WillByDefault(Return(false)); + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kRequestId)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)).WillOnce(Return(true)); + + Event event(hmi_apis::FunctionID::BasicCommunication_OnResetTimeout); + smart_objects::SmartObject notification_msg; + notification_msg[msg_params][request_id] = kRequestId; + notification_msg[msg_params][method_name] = kMethodNameSubscribeWayPoints; + event.set_smart_object(notification_msg); + + ON_CALL(app_mngr_, get_settings()) + .WillByDefault(ReturnRef(app_mngr_settings_)); + ON_CALL(app_mngr_settings_, default_timeout()) + .WillByDefault(ReturnRef(kDefaultTimeout)); + ON_CALL(app_mngr_settings_, default_timeout_compensation()) + .WillByDefault(ReturnRef(kDefaultTimeoutCompensation)); + + EXPECT_CALL(app_mngr_, get_request_timeout_handler()) + .WillOnce(ReturnRef(*request_timeout_handler_)); + EXPECT_CALL( + app_mngr_, + UpdateRequestTimeout(mock_app->app_id(), + command->correlation_id(), + kDefaultTimeout + kDefaultTimeoutCompensation)); + EXPECT_CALL( + app_mngr_, + UpdateRequestTimeout(RequestInfo::kHmiConnectionKey, + kRequestId, + kDefaultTimeout + kDefaultTimeoutCompensation)); + + ASSERT_TRUE(command->Init()); + command->Run(); + request_timeout_handler_->on_event(event); +} + +TEST_F(RequestTimeoutHandlerTest, OnEvent_OnResetTimeout_InvalidRequestId) { + // RequestTimeoutHandler works with all the commands. + // But just for testing, only SubscribeWayPointsRequest was chosen in + // current test. + std::unique_ptr command = + CreateCommand(); + MockAppPtr mock_app = CreateMockApp(); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); + ON_CALL(app_mngr_, IsAppSubscribedForWayPoints(Ref(*mock_app))) + .WillByDefault(Return(false)); + ON_CALL(app_mngr_, IsAnyAppSubscribedForWayPoints()) + .WillByDefault(Return(false)); + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kRequestId)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)).WillOnce(Return(true)); + + Event event(hmi_apis::FunctionID::BasicCommunication_OnResetTimeout); + smart_objects::SmartObject notification_msg; + notification_msg[msg_params][reset_period] = kTimeout; + notification_msg[msg_params][method_name] = kMethodNameSubscribeWayPoints; + notification_msg[msg_params][request_id] = 0u; + event.set_smart_object(notification_msg); + + ON_CALL(app_mngr_, get_settings()) + .WillByDefault(ReturnRef(app_mngr_settings_)); + ON_CALL(app_mngr_settings_, default_timeout()) + .WillByDefault(ReturnRef(kDefaultTimeout)); + ON_CALL(app_mngr_settings_, default_timeout_compensation()) + .WillByDefault(ReturnRef(kDefaultTimeoutCompensation)); + + EXPECT_CALL(app_mngr_, get_request_timeout_handler()) + .WillOnce(ReturnRef(*request_timeout_handler_)); + EXPECT_CALL(app_mngr_, UpdateRequestTimeout(_, _, _)).Times(0); + + ASSERT_TRUE(command->Init()); + command->Run(); + request_timeout_handler_->on_event(event); +} + +TEST_F(RequestTimeoutHandlerTest, OnEvent_OnResetTimeout_InvalidMethodName) { + // RequestTimeoutHandler works with all the commands. + // But just for testing, only SubscribeWayPointsRequest was chosen in + // current test. + std::unique_ptr command = + CreateCommand(); + MockAppPtr mock_app = CreateMockApp(); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); + ON_CALL(app_mngr_, IsAppSubscribedForWayPoints(Ref(*mock_app))) + .WillByDefault(Return(false)); + ON_CALL(app_mngr_, IsAnyAppSubscribedForWayPoints()) + .WillByDefault(Return(false)); + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kRequestId)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)).WillOnce(Return(true)); + + Event event(hmi_apis::FunctionID::BasicCommunication_OnResetTimeout); + smart_objects::SmartObject notification_msg; + notification_msg[msg_params][reset_period] = kTimeout; + notification_msg[msg_params][method_name] = " "; + notification_msg[msg_params][request_id] = kRequestId; + event.set_smart_object(notification_msg); + + ON_CALL(app_mngr_, get_settings()) + .WillByDefault(ReturnRef(app_mngr_settings_)); + ON_CALL(app_mngr_settings_, default_timeout()) + .WillByDefault(ReturnRef(kDefaultTimeout)); + ON_CALL(app_mngr_settings_, default_timeout_compensation()) + .WillByDefault(ReturnRef(kDefaultTimeoutCompensation)); + + EXPECT_CALL(app_mngr_, get_request_timeout_handler()) + .WillOnce(ReturnRef(*request_timeout_handler_)); + EXPECT_CALL(app_mngr_, UpdateRequestTimeout(_, _, _)).Times(0); + + ASSERT_TRUE(command->Init()); + command->Run(); + request_timeout_handler_->on_event(event); +} +} // namespace request_timeout_handler_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/test/rpc_service_impl_test.cc b/src/components/application_manager/test/rpc_service_impl_test.cc index 0a7cff031d0..76f1f053420 100644 --- a/src/components/application_manager/test/rpc_service_impl_test.cc +++ b/src/components/application_manager/test/rpc_service_impl_test.cc @@ -46,11 +46,13 @@ #include "application_manager/mock_message_helper.h" #include "application_manager/mock_request.h" #include "application_manager/mock_request_controller_settings.h" +#include "application_manager/mock_request_timeout_handler.h" #include "application_manager/mock_rpc_plugin.h" #include "application_manager/mock_rpc_plugin_manager.h" #include "application_manager/mock_rpc_protection_manager.h" #include "application_manager/plugin_manager/plugin_keys.h" #include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/request_controller_impl.h" #include "connection_handler/mock_connection_handler.h" #include "hmi_message_handler/mock_hmi_message_handler.h" #include "include/test/protocol_handler/mock_protocol_handler.h" @@ -66,6 +68,7 @@ using test::components::protocol_handler_test::MockProtocolHandler; typedef smart_objects::SmartObjectSPtr MessageSharedPtr; typedef utils::Optional PluginOpt; using test::components::application_manager_test::MockAppServiceManager; +using test::components::application_manager_test::MockRequestTimeoutHandler; using ::testing::_; using ::testing::NiceMock; using ::testing::Return; @@ -86,7 +89,8 @@ const int32_t kConnectionSessionsCount = 2; class RPCServiceImplTest : public ::testing::Test { public: RPCServiceImplTest() - : request_controller_(mock_request_controler_) + : request_controller_(mock_request_controler_, + mock_request_timeout_handler_) , mock_rpc_protection_manager_( std::make_shared< testing::NiceMock >()) @@ -145,7 +149,7 @@ class RPCServiceImplTest : public ::testing::Test { testing::NiceMock mock_app_mngr_; testing::NiceMock mock_request_controler_; testing::NiceMock mock_protocol_handler_; - am::request_controller::RequestController request_controller_; + am::request_controller::RequestControllerImpl request_controller_; testing::NiceMock mock_hmi_handler_; testing::NiceMock mock_command_holder_; std::shared_ptr mock_rpc_protection_manager_; @@ -157,6 +161,7 @@ class RPCServiceImplTest : public ::testing::Test { mock_rpc_plugin_manager_; testing::NiceMock mock_rpc_plugin_; testing::NiceMock mock_command_factory_; + MockRequestTimeoutHandler mock_request_timeout_handler_; }; TEST_F(RPCServiceImplTest, ManageMobileCommand_MessageIsNullPtr_False) { diff --git a/src/components/application_manager/test/zero_request_amount_test.cc b/src/components/application_manager/test/zero_request_amount_test.cc index 0166c036c15..4f943176c00 100644 --- a/src/components/application_manager/test/zero_request_amount_test.cc +++ b/src/components/application_manager/test/zero_request_amount_test.cc @@ -99,19 +99,19 @@ TEST(RequestControlTest, ZeroValuePendingRequestsAmount) { RequestController request_ctrl_; commands::Command* reg = RegisterApplication(); - request_ctrl_.addMobileRequest(reg, mobile_apis::HMILevel::HMI_FULL); + request_ctrl_.AddMobileRequest(reg, mobile_apis::HMILevel::HMI_FULL); for (uint32_t i = 0; i < big_count_of_requests_for_test_; ++i) { correlation_id = i; commands::Command* testCommand = PutFileCommand(correlation_id, connection_key); - result = request_ctrl_.addMobileRequest(testCommand, + result = request_ctrl_.AddMobileRequest(testCommand, mobile_apis::HMILevel::HMI_FULL); EXPECT_EQ(RequestController::SUCCESS, result); } commands::Command* unreg = UnregisterApplication(); - request_ctrl_.addMobileRequest(unreg, mobile_apis::HMILevel::HMI_FULL); + request_ctrl_.AddMobileRequest(unreg, mobile_apis::HMILevel::HMI_FULL); } TEST(RequestControlTest, ZeroValueAppRequestsTimeScale) { @@ -124,19 +124,19 @@ TEST(RequestControlTest, ZeroValueAppRequestsTimeScale) { RequestController request_ctrl_; commands::Command* reg = RegisterApplication(); - request_ctrl_.addMobileRequest(reg, mobile_apis::HMILevel::HMI_FULL); + request_ctrl_.AddMobileRequest(reg, mobile_apis::HMILevel::HMI_FULL); for (uint32_t i = 0; i < big_count_of_requests_for_test_; ++i) { correlation_id = i; commands::Command* testCommand = PutFileCommand(correlation_id, connection_key); - result = request_ctrl_.addMobileRequest(testCommand, + result = request_ctrl_.AddMobileRequest(testCommand, mobile_apis::HMILevel::HMI_FULL); EXPECT_EQ(RequestController::SUCCESS, result); } commands::Command* unreg = UnregisterApplication(); - request_ctrl_.addMobileRequest(unreg, mobile_apis::HMILevel::HMI_FULL); + request_ctrl_.AddMobileRequest(unreg, mobile_apis::HMILevel::HMI_FULL); } TEST(RequestControlTest, ZeroValueAppTimeScaleMaxRequests) { @@ -149,19 +149,19 @@ TEST(RequestControlTest, ZeroValueAppTimeScaleMaxRequests) { RequestController request_ctrl_; commands::Command* reg = RegisterApplication(); - request_ctrl_.addMobileRequest(reg, mobile_apis::HMILevel::HMI_FULL); + request_ctrl_.AddMobileRequest(reg, mobile_apis::HMILevel::HMI_FULL); for (uint32_t i = 0; i < big_count_of_requests_for_test_; ++i) { correlation_id = i; commands::Command* testCommand = PutFileCommand(correlation_id, connection_key); - result = request_ctrl_.addMobileRequest(testCommand, + result = request_ctrl_.AddMobileRequest(testCommand, mobile_apis::HMILevel::HMI_FULL); EXPECT_EQ(RequestController::SUCCESS, result); } commands::Command* unreg = UnregisterApplication(); - request_ctrl_.addMobileRequest(unreg, mobile_apis::HMILevel::HMI_FULL); + request_ctrl_.AddMobileRequest(unreg, mobile_apis::HMILevel::HMI_FULL); } } // namespace application_manager_test diff --git a/src/components/config_profile/include/config_profile/profile.h b/src/components/config_profile/include/config_profile/profile.h index 48ffd30ff37..bb7762721fc 100644 --- a/src/components/config_profile/include/config_profile/profile.h +++ b/src/components/config_profile/include/config_profile/profile.h @@ -249,6 +249,12 @@ class Profile : public protocol_handler::ProtocolHandlerSettings, */ const uint32_t& default_timeout() const; + /** + * @brief Default timeout compensation for waiting some extra time for + * response to mobile app + */ + const uint32_t& default_timeout_compensation() const; + /** * @brief Default timeout for waiting for resuming */ @@ -1012,6 +1018,7 @@ class Profile : public protocol_handler::ProtocolHandlerSettings, bool is_redecoding_enabled_; uint32_t max_cmd_id_; uint32_t default_timeout_; + uint32_t default_timeout_compensation_; uint32_t app_resuming_timeout_; uint32_t app_resumption_save_persistent_data_timeout_; std::string vr_help_title_; diff --git a/src/components/config_profile/src/profile.cc b/src/components/config_profile/src/profile.cc index c12deb44c87..ad624a22a9b 100644 --- a/src/components/config_profile/src/profile.cc +++ b/src/components/config_profile/src/profile.cc @@ -181,6 +181,7 @@ const char* kDeleteFileRequestKey = "DeleteFileRequest"; const char* kListFilesRequestKey = "ListFilesRequest"; const char* kListFilesResponseSizeKey = "ListFilesResponseSize"; const char* kDefaultTimeoutKey = "DefaultTimeout"; +const char* kDefaultTimeoutCompensationKey = "DefaultTimeoutCompensation"; const char* kAppResumingTimeoutKey = "ApplicationResumingTimeout"; const char* kAppSavePersistentDataTimeoutKey = "AppSavePersistentDataTimeout"; const char* kResumptionDelayBeforeIgnKey = "ResumptionDelayBeforeIgn"; @@ -359,6 +360,7 @@ const uint32_t kDefaultPutFileRequestInNone = 5; const uint32_t kDefaultDeleteFileRequestInNone = 5; const uint32_t kDefaultListFilesRequestInNone = 5; const uint32_t kDefaultTimeout = 10000; +const uint32_t kDefaultTimeoutCompensation = 1000; const uint32_t kDefaultAppResumingTimeout = 3000; const uint32_t kDefaultAppSavePersistentDataTimeout = 10000; const uint32_t kDefaultResumptionDelayBeforeIgn = 30; @@ -482,6 +484,7 @@ Profile::Profile() , is_redecoding_enabled_(false) , max_cmd_id_(kDefaultMaxCmdId) , default_timeout_(kDefaultTimeout) + , default_timeout_compensation_(kDefaultTimeoutCompensation) , app_resuming_timeout_(kDefaultAppResumingTimeout) , app_resumption_save_persistent_data_timeout_( kDefaultAppSavePersistentDataTimeout) @@ -685,6 +688,10 @@ const uint32_t& Profile::default_timeout() const { return default_timeout_; } +const uint32_t& Profile::default_timeout_compensation() const { + return default_timeout_compensation_; +} + const uint32_t& Profile::app_resuming_timeout() const { return app_resuming_timeout_; } @@ -1725,6 +1732,16 @@ void Profile::UpdateValues() { LOG_UPDATED_VALUE(default_timeout_, kDefaultTimeoutKey, kMainSection); + // Default timeout compensation + ReadUIntValue(&default_timeout_compensation_, + kDefaultTimeoutCompensation, + kMainSection, + kDefaultTimeoutCompensationKey); + + LOG_UPDATED_VALUE(default_timeout_compensation_, + kDefaultTimeoutCompensationKey, + kMainSection); + // Application resuming timeout ReadUIntValue(&app_resuming_timeout_, kDefaultAppResumingTimeout, diff --git a/src/components/include/application_manager/application_manager.h b/src/components/include/application_manager/application_manager.h index ef4da3e2d88..708bf8b0480 100644 --- a/src/components/include/application_manager/application_manager.h +++ b/src/components/include/application_manager/application_manager.h @@ -48,6 +48,8 @@ #include "application_manager/application_manager_settings.h" #include "application_manager/hmi_interfaces.h" #include "application_manager/plugin_manager/rpc_plugin_manager.h" +#include "application_manager/request_controller.h" +#include "application_manager/request_timeout_handler.h" #include "application_manager/state_controller.h" #include "policy/policy_types.h" @@ -87,7 +89,10 @@ class RPCService; namespace rpc_handler { class RPCHandler; } - +namespace request_controller { +class RequestTimeoutHandler; +class RequestController; +} // namespace request_controller class Application; class AppServiceManager; class StateControllerImpl; @@ -495,6 +500,10 @@ class ApplicationManager { virtual rpc_service::RPCService& GetRPCService() const = 0; virtual rpc_handler::RPCHandler& GetRPCHandler() const = 0; + virtual request_controller::RequestTimeoutHandler& + get_request_timeout_handler() const = 0; + virtual request_controller::RequestController& get_request_controller() + const = 0; virtual bool is_stopping() const = 0; virtual bool is_audio_pass_thru_active() const = 0; @@ -717,7 +726,7 @@ class ApplicationManager { * @param mobile_correlation_id Correlation ID of the mobile request * @param new_timeout_value New timeout in milliseconds to be set */ - virtual void updateRequestTimeout(uint32_t connection_key, + virtual void UpdateRequestTimeout(uint32_t connection_key, uint32_t mobile_correlation_id, uint32_t new_timeout_value) = 0; diff --git a/src/components/include/application_manager/application_manager_settings.h b/src/components/include/application_manager/application_manager_settings.h index 02cd79aa8ed..c7ab634ad02 100644 --- a/src/components/include/application_manager/application_manager_settings.h +++ b/src/components/include/application_manager/application_manager_settings.h @@ -63,6 +63,7 @@ class ApplicationManagerSettings : public RequestControlerSettings, virtual uint16_t tts_global_properties_timeout() const = 0; virtual uint16_t max_supported_protocol_version() const = 0; virtual const uint32_t& default_timeout() const = 0; + virtual const uint32_t& default_timeout_compensation() const = 0; virtual const uint32_t& max_cmd_id() const = 0; virtual bool launch_hmi() const = 0; virtual const uint32_t& delete_file_in_none() const = 0; diff --git a/src/components/include/application_manager/request_controller.h b/src/components/include/application_manager/request_controller.h new file mode 100644 index 00000000000..287493926b3 --- /dev/null +++ b/src/components/include/application_manager/request_controller.h @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2020, 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_INCLUDE_APPLICATION_MANAGER_REQUEST_CONTROLLER_H_ +#define SRC_COMPONENTS_INCLUDE_APPLICATION_MANAGER_REQUEST_CONTROLLER_H_ + +#include "application_manager/commands/command.h" + +#include + +namespace application_manager { +namespace request_controller { + +typedef std::shared_ptr RequestPtr; +/** + * @brief RequestController class is used to control currently active mobile + * requests. + */ +class RequestController { + public: + /** + * @brief Result code for addRequest + */ + enum class TResult { + SUCCESS = 0, + TOO_MANY_REQUESTS, + TOO_MANY_PENDING_REQUESTS, + NONE_HMI_LEVEL_MANY_REQUESTS, + INVALID_DATA + }; + + /** + * @brief Thread pool state + */ + enum class TPoolState { + UNDEFINED = 0, + STARTED, + STOPPED, + }; + + /** + * @brief Class destructor + */ + virtual ~RequestController() {} + + /** + * @brief Stop request controller internal activities + */ + virtual void Stop() = 0; + + /** + * @brief Initialize thread pool + */ + virtual void InitializeThreadpool() = 0; + + /** + * @brief Destroy thread pool + */ + virtual void DestroyThreadpool() = 0; + + /** + * @brief Check if max request amount wasn't exceed and adds request to queue. + * @param request Active request to mobile + * @param hmi_level Current application hmi_level + * @return Result code + */ + virtual TResult AddMobileRequest( + const RequestPtr request, + const mobile_apis::HMILevel::eType& hmi_level) = 0; + + /** + * @brief Store HMI request until response or timeout won't remove it + * @param request Active request to hmi + * @return Result code + */ + virtual TResult AddHMIRequest(const RequestPtr request) = 0; + + /** + * @brief Add notification to collection + * @param ptr Reference to shared pointer that point on hmi notification + */ + virtual void AddNotification(const RequestPtr ptr) = 0; + + /** + * @brief Removes request from queue + * @param correlation_id Active request correlation ID, + * @param connection_key Active request connection key (0 for HMI requests) + * @param function_id Active request function id + * @param force_terminate if true, request controller will terminate + * even if not allowed by request + */ + virtual void TerminateRequest(const uint32_t correlation_id, + const uint32_t connection_key, + const int32_t function_id, + const bool force_terminate = false) = 0; + + /** + * @brief Removes request from queue + * @param mobile_correlation_id Active mobile request correlation ID + * @param connection_key Active request connection key (0 for HMI requests) + * @param function_id Active request function ID + */ + virtual void OnMobileResponse(const uint32_t mobile_correlation_id, + const uint32_t connection_key, + const int32_t function_id) = 0; + + /** + * @brief Removes request from queue + * @param mobile_correlation_id Active mobile request correlation ID + * @param function_id Active request function ID + */ + virtual void OnHMIResponse(const uint32_t correlation_id, + const int32_t function_id) = 0; + + /** + * @ Add notification to collection + * @param notification Pointer that points to hmi notification + */ + virtual void RemoveNotification(const commands::Command* notification) = 0; + + /** + * @brief Removes all requests from queue for specified application + * @param app_id Mobile application ID (app_id) + */ + virtual void TerminateAppRequests(const uint32_t app_id) = 0; + + /** + * @brief Terminates all requests from HMI + */ + virtual void TerminateAllHMIRequests() = 0; + + /** + * @brief Terminates all requests from Mobile + */ + virtual void TerminateAllMobileRequests() = 0; + + /** + * @brief Updates request timeout + * @param app_id Connection key of application + * @param mobile_correlation_id Correlation ID of the mobile request + * @param new_timeout_value New timeout to be set in milliseconds + */ + virtual void UpdateRequestTimeout(const uint32_t app_id, + const uint32_t mobile_correlation_id, + const uint32_t new_timeout) = 0; + /** + * @brief Function Should be called when Low Voltage is occured + */ + virtual void OnLowVoltage() = 0; + + /** + * @brief Function Should be called when WakeUp occures after Low Voltage + */ + virtual void OnWakeUp() = 0; + + /** + * @return true if low voltage state is active + */ + virtual bool IsLowVoltage() = 0; +}; + +} // namespace request_controller +} // namespace application_manager + +#endif // SRC_COMPONENTS_INCLUDE_APPLICATION_MANAGER_REQUEST_CONTROLLER_H_ diff --git a/src/components/include/application_manager/request_timeout_handler.h b/src/components/include/application_manager/request_timeout_handler.h new file mode 100644 index 00000000000..ef646d8a941 --- /dev/null +++ b/src/components/include/application_manager/request_timeout_handler.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2020, 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_INCLUDE_APPLICATION_MANAGER_REQUEST_TIMEOUT_HANDLER_H_ +#define SRC_COMPONENTS_INCLUDE_APPLICATION_MANAGER_REQUEST_TIMEOUT_HANDLER_H_ + +#include + +namespace application_manager { +namespace request_controller { + +/* + * @brief Structure for active mobile request + * that is waiting for a response from the HMI. + * Used for OnResetTimeout logic. + */ +struct Request { + Request(const uint32_t mob_correlation_id, + const uint32_t connection_key, + const uint32_t hmi_function_id) + : mob_correlation_id_(mob_correlation_id) + , connection_key_(connection_key) + , hmi_function_id_(hmi_function_id) {} + + uint32_t mob_correlation_id_; + uint32_t connection_key_; + uint32_t hmi_function_id_; +}; + +/** + * @brief The RequestTimeoutHandler class + * handles OnResetTimeout notification from HMI, + * reset timeout for mobile request + */ +class RequestTimeoutHandler { + public: + /** + * @brief AddRequest adds request that waits for response + * @param hmi_correlation_id hmi correlation id + * @param request active mobile request + */ + virtual void AddRequest(const uint32_t hmi_correlation_id, + const Request& request) = 0; + /** + * @brief RemoveRequest removes processed request + * @param hmi_correlation_id hmi correlation id + */ + virtual void RemoveRequest(const uint32_t hmi_correlation_id) = 0; + + virtual ~RequestTimeoutHandler() {} +}; + +} // namespace request_controller +} // namespace application_manager + +#endif // SRC_COMPONENTS_INCLUDE_APPLICATION_MANAGER_REQUEST_TIMEOUT_HANDLER_H_ diff --git a/src/components/include/test/application_manager/mock_application_manager.h b/src/components/include/test/application_manager/mock_application_manager.h index 50fb168411c..525197cb499 100644 --- a/src/components/include/test/application_manager/mock_application_manager.h +++ b/src/components/include/test/application_manager/mock_application_manager.h @@ -188,6 +188,12 @@ class MockApplicationManager : public application_manager::ApplicationManager { application_manager::rpc_service::RPCService&()); MOCK_CONST_METHOD0(GetRPCHandler, application_manager::rpc_handler::RPCHandler&()); + MOCK_CONST_METHOD0( + get_request_timeout_handler, + application_manager::request_controller::RequestTimeoutHandler&()); + MOCK_CONST_METHOD0( + get_request_controller, + application_manager::request_controller::RequestController&()); MOCK_CONST_METHOD0(is_stopping, bool()); MOCK_CONST_METHOD0(is_audio_pass_thru_active, bool()); MOCK_METHOD0(GetNextHMICorrelationID, uint32_t()); @@ -262,7 +268,7 @@ class MockApplicationManager : public application_manager::ApplicationManager { void(const connection_handler::DeviceHandle)); MOCK_METHOD4(UnregisterApplication, void(const uint32_t&, mobile_apis::Result::eType, bool, bool)); - MOCK_METHOD3(updateRequestTimeout, + MOCK_METHOD3(UpdateRequestTimeout, void(uint32_t connection_key, uint32_t mobile_correlation_id, uint32_t new_timeout_value)); diff --git a/src/components/include/test/application_manager/mock_application_manager_settings.h b/src/components/include/test/application_manager/mock_application_manager_settings.h index 9a70a374a7c..b30fc098306 100644 --- a/src/components/include/test/application_manager/mock_application_manager_settings.h +++ b/src/components/include/test/application_manager/mock_application_manager_settings.h @@ -70,6 +70,7 @@ class MockApplicationManagerSettings MOCK_CONST_METHOD0(tts_global_properties_timeout, uint16_t()); MOCK_CONST_METHOD0(max_supported_protocol_version, uint16_t()); MOCK_CONST_METHOD0(default_timeout, const uint32_t&()); + MOCK_CONST_METHOD0(default_timeout_compensation, const uint32_t&()); MOCK_CONST_METHOD0(max_cmd_id, const uint32_t&()); MOCK_CONST_METHOD0(launch_hmi, bool()); MOCK_CONST_METHOD0(delete_file_in_none, const uint32_t&()); diff --git a/src/components/include/test/application_manager/mock_request_controller.h b/src/components/include/test/application_manager/mock_request_controller.h new file mode 100644 index 00000000000..5ed726b3010 --- /dev/null +++ b/src/components/include/test/application_manager/mock_request_controller.h @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2020, 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_INCLUDE_TEST_APPLICATION_MANAGER_MOCK_REQUEST_CONTROLLER_H_ +#define SRC_COMPONENTS_INCLUDE_TEST_APPLICATION_MANAGER_MOCK_REQUEST_CONTROLLER_H_ + +#include "application_manager/request_controller.h" + +namespace test { +namespace components { +namespace application_manager_test { + +class MockRequestController + : public application_manager::request_controller::RequestController { + public: + MOCK_METHOD0(Stop, void()); + MOCK_METHOD0(InitializeThreadpool, void()); + MOCK_METHOD0(DestroyThreadpool, void()); + MOCK_METHOD2( + AddMobileRequest, + TResult(const application_manager::request_controller::RequestPtr request, + const mobile_apis::HMILevel::eType& hmi_level)); + MOCK_METHOD1(AddHMIRequest, + TResult(const application_manager::request_controller::RequestPtr + request)); + MOCK_METHOD1( + AddNotification, + void(const application_manager::request_controller::RequestPtr request)); + MOCK_METHOD4(TerminateRequest, + void(const uint32_t correlation_id, + const uint32_t connection_key, + const int32_t function_id, + bool force_terminate)); + MOCK_METHOD3(OnMobileResponse, + void(const uint32_t mobile_correlation_id, + const uint32_t connection_key, + const int32_t function_id)); + MOCK_METHOD2(OnHMIResponse, + void(const uint32_t correlation_id, const int32_t function_id)); + MOCK_METHOD1( + RemoveNotification, + void(const application_manager::commands::Command* notification)); + MOCK_METHOD1(TerminateAppRequests, void(const uint32_t app_id)); + MOCK_METHOD0(TerminateAllHMIRequests, void()); + MOCK_METHOD0(TerminateAllMobileRequests, void()); + MOCK_METHOD3(UpdateRequestTimeout, + void(const uint32_t app_id, + const uint32_t mobile_correlation_id, + const uint32_t new_timeout)); + MOCK_METHOD0(OnLowVoltage, void()); + MOCK_METHOD0(OnWakeUp, void()); + MOCK_METHOD0(IsLowVoltage, bool()); +}; +} // namespace application_manager_test +} // namespace components +} // namespace test + +#endif // SRC_COMPONENTS_INCLUDE_TEST_APPLICATION_MANAGER_MOCK_REQUEST_CONTROLLER_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_tts_reset_timeout_notification.cc b/src/components/include/test/application_manager/mock_request_timeout_handler.h similarity index 56% rename from src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_tts_reset_timeout_notification.cc rename to src/components/include/test/application_manager/mock_request_timeout_handler.h index 96f6c5cd5b5..b1492a9812d 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_tts_reset_timeout_notification.cc +++ b/src/components/include/test/application_manager/mock_request_timeout_handler.h @@ -29,43 +29,29 @@ * 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/hmi/on_tts_reset_timeout_notification.h" -#include "application_manager/event_engine/event.h" -#include "interfaces/HMI_API.h" -namespace sdl_rpc_plugin { -using namespace application_manager; +#ifndef SRC_COMPONENTS_INCLUDE_TEST_APPLICATION_MANAGER_MOCK_REQUEST_TIMEOUT_HANDLER_H_ +#define SRC_COMPONENTS_INCLUDE_TEST_APPLICATION_MANAGER_MOCK_REQUEST_TIMEOUT_HANDLER_H_ -namespace commands { +#include "application_manager/request_timeout_handler.h" +#include "gmock/gmock.h" -namespace hmi { +namespace test { +namespace components { +namespace application_manager_test { -SDL_CREATE_LOG_VARIABLE("Commands") +class MockRequestTimeoutHandler + : public application_manager::request_controller::RequestTimeoutHandler { + public: + MOCK_METHOD2( + AddRequest, + void(const uint32_t hmi_correlation_id, + const application_manager::request_controller::Request& request)); + MOCK_METHOD1(RemoveRequest, void(const uint32_t hmi_correlation_id)); +}; -OnTTSResetTimeoutNotification::OnTTSResetTimeoutNotification( - const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle) - : NotificationFromHMI(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handle) {} +} // namespace application_manager_test +} // namespace components +} // namespace test -OnTTSResetTimeoutNotification::~OnTTSResetTimeoutNotification() {} - -void OnTTSResetTimeoutNotification::Run() { - SDL_LOG_AUTO_TRACE(); - - event_engine::Event event(hmi_apis::FunctionID::TTS_OnResetTimeout); - event.set_smart_object(*message_); - event.raise(application_manager_.event_dispatcher()); -} - -} // namespace hmi - -} // namespace commands - -} // namespace sdl_rpc_plugin +#endif // SRC_COMPONENTS_INCLUDE_TEST_APPLICATION_MANAGER_MOCK_REQUEST_TIMEOUT_HANDLER_H_ diff --git a/src/components/interfaces/HMI_API.xml b/src/components/interfaces/HMI_API.xml index b185b88ada7..9b09f239fe1 100644 --- a/src/components/interfaces/HMI_API.xml +++ b/src/components/interfaces/HMI_API.xml @@ -4783,6 +4783,27 @@ + + + HMI must send this notification to SDL for method instance for which timeout needs to be reset + + + + Id between HMI and SDL which SDL used to send the request for method in question, for which timeout needs to be reset. + + + + + Name of the function for which timeout needs to be reset + + + + + Timeout period in milliseconds, for the method for which timeout needs to be reset. + If omitted, timeout would be reset by defaultTimeout specified in smartDeviceLink.ini + + + @@ -5317,18 +5338,6 @@ - - - Sender: HMI->SDL. HMI must send this notification every 10 sec. in case the 'methodName' - results long processing on HMI - - - Id of application that concerns the 'methodName'. - - - The name of the method, the renew of timeout is required for - - @@ -6028,15 +6037,6 @@ Provides the result of operation. - - HMI must provide SDL with notifications specific to the current Turn-By-Turn client status on the module - - Id of application that invoked notifcation. - - - Currently used method name on which was triggered action - - Issued by SDL to notify HMI about capturing mic data should be started diff --git a/tools/rpc_spec b/tools/rpc_spec index 44f0a419c6a..12c2d1dacc4 160000 --- a/tools/rpc_spec +++ b/tools/rpc_spec @@ -1 +1 @@ -Subproject commit 44f0a419c6a43815bc095134712eab4fef352ad7 +Subproject commit 12c2d1dacc4315be22bbc1f5e655f4464d9fae44 From 036b1851c93bb89375e82786e4a7bd1b3848b89c Mon Sep 17 00:00:00 2001 From: collin Date: Thu, 12 Aug 2021 14:25:51 -0400 Subject: [PATCH 13/14] Squashed commit of the following: commit ce9fc4455093d4914dfec55a6e5003da3c28fc83 Author: Andrii Kalinich Date: Thu Aug 5 18:50:33 2021 -0400 Update CUSTOM_BUTTON logic commit 237562b555dc78322f6c6dd5b9c83ded0226998d Author: Andrii Kalinich Date: Thu Aug 5 09:10:59 2021 -0400 fixup! Address Livio comments commit 16142947000f2ed54279306468a6c4cb1594805f Author: Andrii Kalinich Date: Wed Aug 4 17:17:17 2021 -0400 Address Livio comments commit daa1060833441f38a7219d8a852c6d44e852e76e Author: Andrii Kalinich Date: Tue Jul 27 20:15:06 2021 -0400 Address Livio comments commit a327f0694db958a1925b6526e8d25ce9c86bd735 Author: Olha Vorobiova Date: Tue Jul 20 16:40:27 2021 +0300 Add unit tests for subscribe and unsubscribe button commit dce94e5d84698f5d85bddbc8b5324518d4c1f9f4 Merge: f78f0c82ea 82703c98bb Author: Andrii Kalinich (GitHub) Date: Fri Jul 16 19:12:45 2021 -0400 Merge pull request #206 from LuxoftSDL/impl/sdl_0192_fix_resumption_of_button_subscriptions Separate subscription processing logic for mobile requests and resumption commit 82703c98bb2b68c11bfc642bc976d7b29be416c8 Author: Andrii Kalinich Date: Fri Jul 16 15:07:15 2021 -0400 Return on_event() back to HMI subscription request commit f78f0c82ea495376298dae5efda25dde05a7ec7b Merge: 94c770b314 e7e1ebf3ce Author: Andrii Kalinich (GitHub) Date: Fri Jul 16 19:00:15 2021 -0400 Merge pull request #205 from LuxoftSDL/fix/sdl_0192_fix_custom_button_subscription_logic Fix CUSTOM_BUTTON subscription logic commit e7e1ebf3ce7b49139f3ddfb77046a642d049294e Author: Andrii Kalinich Date: Fri Jul 16 13:02:46 2021 -0400 Fix affected unit tests commit d156a9f0067a61b32323b1e0eae680e488780045 Author: Yana Chernysheva Date: Fri Jul 16 16:09:27 2021 +0300 Separate subscription processing for mobile requests and resumption commit 9e461d05d2843dedb4a3e3945d907d6e8a376311 Author: Andrii Kalinich Date: Fri Jul 16 01:31:05 2021 -0400 Fix CUSTOM_BUTTON subscription logic Was removed subscription to custom button by default. Also, added check if app is actually subscribed to CUSTOM_BUTTON like for all other buttons. commit 94c770b314659a33555d81bd47e4c76325c322eb Author: Yana Chernysheva Date: Wed Jul 14 15:32:40 2021 +0300 Revert expired button requests if response was received after timeout commit de6c7aac0650d6ac823cd3e6cc0ff4ff9d96eef9 Merge: 0343ea4e9f eaec9b47a5 Author: Yana Chernysheva Date: Thu Jul 15 15:23:10 2021 +0300 Merge branch 'develop' into feature/sdl_0192_button_subscription_response_from_hmi commit 0343ea4e9f2ef844aa096f76b85719f66eb6db36 Author: Yana Chernysheva Date: Mon Jul 5 14:46:21 2021 +0300 Add shared base class for mobile button notifications commit 3d7d670476634bf687271dd5a5ebc95b907cab05 Author: Yana Chernysheva Date: Fri Jul 9 16:13:21 2021 +0300 Unify approach to result codes processing commit e5dfa88fbddd3ec71c05e3e49f68379470e24233 Author: Yana Chernysheva Date: Thu Jul 8 11:40:13 2021 +0300 Remove OnButtonSubscription notification commit 06dc97859063cfc8a654365db3396a8752cb4f9b Author: Yana Chernysheva Date: Wed Jul 7 13:39:12 2021 +0300 Resume button subscriptions commit 4cf9954b46c0496356200ce0d2c4a96ace5e0b6d Author: Vadym Luchko (GitHub) <76956836+VadymLuchko@users.noreply.github.com> Date: Fri Jul 9 14:09:43 2021 +0300 unsubscribe buttons implementation (#197) commit 13045471a9de73b8a37d081efbbe31b1552aa159 Author: Yana Chernysheva Date: Wed Jun 30 17:16:30 2021 +0300 Add SubscribeButtonRequest and SubscribeButtonResponse classes --- .../include/application_manager/application.h | 3 + .../application_manager_impl.h | 16 ++ .../commands/button_notification_to_mobile.h | 109 +++++++++ .../commands/command_impl.h | 27 +++ .../commands/command_request_impl.h | 18 -- .../commands/request_from_hmi.h | 6 - .../application_manager/message_helper.h | 76 +++--- .../resumption_data_processor_impl.h | 11 + ...s_get_app_service_data_request_from_hmi.cc | 7 +- ...pp_service_interaction_request_from_hmi.cc | 3 +- .../mobile/get_app_service_data_request.cc | 2 +- ...perform_app_service_interaction_request.cc | 2 +- .../commands/hmi/subscribe_button_request.h | 87 +++++++ ...fication.h => subscribe_button_response.h} | 43 ++-- .../commands/hmi/unsubscribe_button_request.h | 75 ++++++ .../hmi/unsubscribe_button_response.h} | 43 ++-- .../mobile/on_button_event_notification.h | 12 +- .../mobile/on_button_press_notification.h | 12 +- .../mobile/subscribe_button_request.h | 12 +- .../mobile/unsubscribe_button_request.h | 25 +- .../commands/hmi/subscribe_button_request.cc | 164 +++++++++++++ .../commands/hmi/subscribe_button_response.cc | 97 ++++++++ .../hmi/unsubscribe_button_request.cc | 125 ++++++++++ .../hmi/unsubscribe_button_response.cc | 98 ++++++++ .../commands/mobile/create_window_request.cc | 3 +- .../delete_interaction_choice_set_request.cc | 2 +- .../commands/mobile/delete_window_request.cc | 3 +- .../mobile/on_button_event_notification.cc | 144 +----------- .../mobile/on_button_press_notification.cc | 153 +----------- .../mobile/register_app_interface_request.cc | 8 +- .../mobile/subscribe_button_request.cc | 80 +++++-- .../mobile/unsubscribe_button_request.cc | 72 ++++-- .../sdl_rpc_plugin/src/hmi_command_factory.cc | 22 +- .../commands/hmi/dummy_hmi_commands_test.cc | 12 +- .../commands/hmi/hmi_notifications_test.cc | 2 - .../hmi/subscribe_button_request_test.cc | 213 +++++++++++++++++ .../hmi/subscribe_button_response_test.cc | 145 ++++++++++++ .../hmi/unsubscribe_button_request_test.cc | 180 ++++++++++++++ .../hmi/unsubscribe_button_response_test.cc | 145 ++++++++++++ .../on_button_notification_commands_test.cc | 50 +++- .../register_app_interface_request_test.cc | 30 +-- .../mobile/subscribe_button_request_test.cc | 71 +++--- .../mobile/unsubscribe_button_request_test.cc | 27 --- .../src/application_impl.cc | 3 +- .../src/application_manager_impl.cc | 37 +++ .../commands/button_notification_to_mobile.cc | 219 ++++++++++++++++++ .../src/commands/command_impl.cc | 38 +++ .../src/commands/command_request_impl.cc | 42 +--- .../src/commands/request_from_hmi.cc | 37 --- .../src/commands/request_to_hmi.cc | 34 +-- .../src/helpers/application_helper.cc | 14 +- .../src/hmi_interfaces_impl.cc | 4 +- .../src/message_helper/message_helper.cc | 187 +++++++-------- .../resumption_data_processor_impl.cc | 67 ++++-- .../test/application_helper_test.cc | 9 - .../test/application_impl_test.cc | 6 +- .../application_manager/mock_message_helper.h | 31 +-- .../test/mock_message_helper.cc | 39 ++-- .../test/resumption/resume_ctrl_test.cc | 14 +- .../application_manager/application_manager.h | 34 +++ .../mock_application_manager.h | 9 + src/components/interfaces/HMI_API.xml | 30 ++- 62 files changed, 2395 insertions(+), 894 deletions(-) create mode 100644 src/components/application_manager/include/application_manager/commands/button_notification_to_mobile.h create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/subscribe_button_request.h rename src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/{on_button_subscription_notification.h => subscribe_button_response.h} (64%) create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/unsubscribe_button_request.h rename src/components/application_manager/rpc_plugins/sdl_rpc_plugin/{src/commands/hmi/on_button_subscription_notification.cc => include/sdl_rpc_plugin/commands/hmi/unsubscribe_button_response.h} (57%) create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/subscribe_button_request.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/subscribe_button_response.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/unsubscribe_button_request.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/unsubscribe_button_response.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/subscribe_button_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/subscribe_button_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/unsubscribe_button_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/unsubscribe_button_response_test.cc create mode 100644 src/components/application_manager/src/commands/button_notification_to_mobile.cc diff --git a/src/components/application_manager/include/application_manager/application.h b/src/components/application_manager/include/application_manager/application.h index 2d7006e19a9..86b26f24efe 100644 --- a/src/components/application_manager/include/application_manager/application.h +++ b/src/components/application_manager/include/application_manager/application.h @@ -46,6 +46,7 @@ #include "application_manager/hmi_state.h" #include "application_manager/message.h" #include "connection_handler/device.h" +#include "interfaces/HMI_API.h" #include "interfaces/MOBILE_API.h" #include "protocol_handler/protocol_handler.h" #include "smart_objects/smart_object.h" @@ -106,6 +107,8 @@ struct AppFile { mobile_apis::FileType::eType file_type; }; typedef std::map AppFilesMap; +typedef std::map + ButtonSubscriptionsMap; class InitialApplicationData { public: virtual ~InitialApplicationData() {} diff --git a/src/components/application_manager/include/application_manager/application_manager_impl.h b/src/components/application_manager/include/application_manager/application_manager_impl.h index 09f2c7d4df7..c64ae2bbd2f 100644 --- a/src/components/application_manager/include/application_manager/application_manager_impl.h +++ b/src/components/application_manager/include/application_manager/application_manager_impl.h @@ -120,6 +120,9 @@ enum VRTTSSessionChanging { kVRSessionChanging = 0, kTTSSessionChanging }; typedef std::map > ServiceStreamingStatusMap; +typedef std::map + ExpiredButtonRequestsMap; + struct CommandParametersPermissions; typedef std::map DeviceTypes; @@ -1542,6 +1545,16 @@ class ApplicationManagerImpl static std::vector ConvertRejectedParamList( const std::vector& input); + void AddExpiredButtonRequest( + const uint32_t app_id, + const int32_t corr_id, + const hmi_apis::Common_ButtonName::eType button_name) OVERRIDE; + + utils::Optional GetExpiredButtonRequestData( + const int32_t corr_id) const OVERRIDE; + + void DeleteExpiredButtonRequest(const int32_t corr_id) OVERRIDE; + private: const ApplicationManagerSettings& settings_; /** @@ -1705,6 +1718,9 @@ class ApplicationManagerImpl ServiceStreamingStatusMap streaming_application_services_; sync_primitives::Lock streaming_services_lock_; + mutable sync_primitives::Lock expired_button_requests_lock_; + mutable ExpiredButtonRequestsMap expired_button_requests_; + #ifdef BUILD_TESTS public: /** diff --git a/src/components/application_manager/include/application_manager/commands/button_notification_to_mobile.h b/src/components/application_manager/include/application_manager/commands/button_notification_to_mobile.h new file mode 100644 index 00000000000..66a26831334 --- /dev/null +++ b/src/components/application_manager/include/application_manager/commands/button_notification_to_mobile.h @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2021, 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_INCLUDE_APPLICATION_MANAGER_COMMANDS_BUTTON_NOTIFICATION_TO_MOBILE_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMANDS_BUTTON_NOTIFICATION_TO_MOBILE_H_ + +#include "application_manager/application.h" +#include "command_notification_impl.h" +#include "interfaces/MOBILE_API.h" + +namespace application_manager { +namespace commands { +namespace app_mngr = application_manager; + +/** + * @brief Class is intended to encapsulate shared button notification logic in + * base class. Entities defined in this file do not conform to any version of + * HMI or mobile API, and exist only to remove duplication in OnButtonPress and + * OnButtonEvent notifications. + **/ +class ButtonNotificationToMobile + : public app_mngr::commands::CommandNotificationImpl { + public: + /** + * @brief ButtonNotificationToMobile class constructor + **/ + ButtonNotificationToMobile( + 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 ButtonNotificationToMobile class destructor + **/ + ~ButtonNotificationToMobile(); + + /** + * @brief Execute command + **/ + void Run() OVERRIDE; + + protected: + virtual void SendButtonNotification(app_mngr::ApplicationSharedPtr app) = 0; + + /** + * @brief HandleCustomButton handle event for custom buttons + * @param app pointer to application data. + **/ + void HandleCustomButton(app_mngr::ApplicationSharedPtr app); + + /** + * @brief HandleOKButton handle event for OK button + * @param app pointer to application data. + **/ + void HandleOKButton(app_mngr::ApplicationSharedPtr app); + + /** + * @brief HandleMediaButton handle event for media buttons + * @param app pointer to application data. + **/ + void HandleMediaButton(app_mngr::ApplicationSharedPtr app); + + /** + * @brief DoesParamExist check whether param is exists in msg_params + * @param param_name name of parameter to find + **/ + bool DoesParamExist(const std::string& param_name) const; + + /** + * @brief SubscribedApps get subscribed apps for btn id received in message + * @return Return applications list subscribed to current button + **/ + std::vector SubscribedApps() const; +}; +} // namespace commands +} // namespace application_manager + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMANDS_BUTTON_NOTIFICATION_TO_MOBILE_H_ diff --git a/src/components/application_manager/include/application_manager/commands/command_impl.h b/src/components/application_manager/include/application_manager/commands/command_impl.h index 1b4db7e8885..6105f7c5d6a 100644 --- a/src/components/application_manager/include/application_manager/commands/command_impl.h +++ b/src/components/application_manager/include/application_manager/commands/command_impl.h @@ -69,6 +69,23 @@ struct CommandParametersPermissions { }; namespace commands { + +/** + * @brief Checks Mobile result code for single RPC + * @param result_code contains result code from response to Mobile + * @return true if result code complies to successful result codes, + * false otherwise. + */ +bool IsMobileResultSuccess(const mobile_apis::Result::eType result_code); + +/** + * @brief Checks HMI result code for single RPC + * @param result_code contains result code from HMI response + * @return true if result code complies to successful result codes, + * false otherwise. + */ +bool IsHMIResultSuccess(const hmi_apis::Common_Result::eType result_code); + /** * @brief Class is intended to encapsulate RPC as an object **/ @@ -183,6 +200,16 @@ class CommandImpl : public Command { */ bool CheckSyntax(const std::string& str, bool allow_empty_line = false) const; + /** + * @brief Checks HMI result code for single RPC + * @param result_code contains result code from HMI response + * @param interface to check availability + * @return true if result code complies to successful result codes, + * false otherwise. + */ + bool IsHMIResultSuccess(hmi_apis::Common_Result::eType result_code, + HmiInterfaces::InterfaceID interface) const; + // members static const int32_t hmi_protocol_type_; static const int32_t mobile_protocol_type_; diff --git a/src/components/application_manager/include/application_manager/commands/command_request_impl.h b/src/components/application_manager/include/application_manager/commands/command_request_impl.h index 727863d16d7..e2c95a085ba 100644 --- a/src/components/application_manager/include/application_manager/commands/command_request_impl.h +++ b/src/components/application_manager/include/application_manager/commands/command_request_impl.h @@ -206,24 +206,6 @@ class CommandRequestImpl : public CommandImpl, mobile_apis::Result::eType GetMobileResultCode( const hmi_apis::Common_Result::eType& hmi_code) const; - /** - * @brief Checks Mobile result code for single RPC - * @param result_code contains result code from response to Mobile - * @return true if result code complies to successful result codes, - * false otherwise. - */ - static bool IsMobileResultSuccess( - const mobile_apis::Result::eType result_code); - - /** - * @brief Checks HMI result code for single RPC - * @param result_code contains result code from HMI response - * @return true if result code complies to successful result codes, - * false otherwise. - */ - static bool IsHMIResultSuccess( - const hmi_apis::Common_Result::eType result_code); - protected: /** * @brief Checks message permissions and parameters according to policy table diff --git a/src/components/application_manager/include/application_manager/commands/request_from_hmi.h b/src/components/application_manager/include/application_manager/commands/request_from_hmi.h index 44640561753..0e03b31e74e 100644 --- a/src/components/application_manager/include/application_manager/commands/request_from_hmi.h +++ b/src/components/application_manager/include/application_manager/commands/request_from_hmi.h @@ -106,12 +106,6 @@ class RequestFromHMI : public CommandImpl, public event_engine::EventObserver { const uint32_t hmi_correlation_id, const hmi_apis::FunctionID::eType& function_id); - protected: - bool IsMobileResultSuccess(mobile_apis::Result::eType result_code) const; - - bool IsHMIResultSuccess(hmi_apis::Common_Result::eType result_code, - HmiInterfaces::InterfaceID interface) const; - private: /** * @brief Fills common parameters for SO diff --git a/src/components/application_manager/include/application_manager/message_helper.h b/src/components/application_manager/include/application_manager/message_helper.h index 2adef91c2ed..88200d65930 100644 --- a/src/components/application_manager/include/application_manager/message_helper.h +++ b/src/components/application_manager/include/application_manager/message_helper.h @@ -273,52 +273,46 @@ class MessageHelper { const std::string& path_to_icon, uint32_t app_id); /** - * @brief Sends button subscription notification - * @param app_id Application ID - * @param button Enum with button name - * @param is_subscribed true if subscribed, false otherwise + * @brief Creates button subscription requests for buttons + * that application is subscribed on + * @param app application to be subscribed for button + * @param button_subscriptions collection of subscribed buttons + * @param function_id function ID * @param app_mngr reference to application manager + * @return list of all buttons subscription requests ready to be sent to hmi + * @note for every button separate request is created in the list */ - static void SendOnButtonSubscriptionNotification( - const uint32_t app_id, - const hmi_apis::Common_ButtonName::eType button, - const bool is_subscribed, + static smart_objects::SmartObjectList + CreateButtonSubscriptionsHandlingRequestsList( + ApplicationConstSharedPtr app, + const ButtonSubscriptions& button_subscriptions, + const hmi_apis::FunctionID::eType function_id, ApplicationManager& app_mngr); /** - * @brief Creates button subscription notification - * @param app_id Application ID - * @param button Enum with button name - * @param is_subscribed true if subscribed, false otherwise - * @return notification message in SmartObject format - */ - static smart_objects::SmartObjectSPtr CreateOnButtonSubscriptionNotification( - const uint32_t app_id, - const hmi_apis::Common_ButtonName::eType button, - const bool is_subscribed); - - /** - * @brief Sends button subscription notifications for all buttons - * that application is subscribed on + * @brief Creates button subscription request to mobile * @param app shared pointer to application instance - * @param app_mngr reference to application manager + * @param source_message source message + * @return Smart object with fulfilled request */ - static void SendAllOnButtonSubscriptionNotificationsForApp( - ApplicationConstSharedPtr app, ApplicationManager& app_mngr); + static smart_objects::SmartObjectSPtr CreateButtonNotificationToMobile( + ApplicationSharedPtr app, + const smart_objects::SmartObject& source_message); /** - * @brief Creates button subscription notifications for buttons - * that application is subscribed on - * @param app shared pointer to application instance + * @brief Creates button subscription request to hmi + * @param app_id id of application for which request should be created + * @param button_name button to be subscribed + * @param function_id function ID * @param app_mngr reference to application manager - * @param button_subscriptions collection of subscribed buttons - * @return list of notification messages in SmartObject format + * @return Smart object with fulfilled request */ - static smart_objects::SmartObjectList - CreateOnButtonSubscriptionNotificationsForApp( - ApplicationConstSharedPtr app, - ApplicationManager& app_mngr, - const ButtonSubscriptions& button_subscriptions); + static smart_objects::SmartObjectSPtr + CreateButtonSubscriptionHandlingRequestToHmi( + const uint32_t app_id, + const hmi_apis::Common_ButtonName::eType button_name, + const hmi_apis::FunctionID::eType function_id, + ApplicationManager& app_mngr); static void SendAppDataToHMI(ApplicationConstSharedPtr app, ApplicationManager& app_man); @@ -992,18 +986,6 @@ class MessageHelper { static void SendResetPropertiesRequest(ApplicationSharedPtr application, ApplicationManager& app_mngr); - /** - * @brief SendUnsubscribeButtonNotification sends notification to HMI to - * remove button subscription for application - * @param button Button type - * @param application Application to unsubscribe - * @param app_mngr Application manager - */ - static void SendUnsubscribeButtonNotification( - mobile_apis::ButtonName::eType button, - ApplicationSharedPtr application, - ApplicationManager& app_mngr); - /** * @brief Sends HMI status notification to mobile * @param application application with changed HMI status diff --git a/src/components/application_manager/include/application_manager/resumption/resumption_data_processor_impl.h b/src/components/application_manager/include/application_manager/resumption/resumption_data_processor_impl.h index c2040852cae..edb35817375 100644 --- a/src/components/application_manager/include/application_manager/resumption/resumption_data_processor_impl.h +++ b/src/components/application_manager/include/application_manager/resumption/resumption_data_processor_impl.h @@ -367,6 +367,17 @@ class ResumptionDataProcessorImpl const smart_objects::SmartObject& request, const smart_objects::SmartObject& response) const; + /** + * @brief Checks whether SubscribeButton response successful or not and + * subscribes application if successful + * @param app_id application id + * @param request reference to request SO + * @param response reference to response SO + */ + void ProcessSubscribeButtonResponse( + const uint32_t app_id, + const smart_objects::SmartObject& request, + const smart_objects::SmartObject& response); app_mngr::ApplicationManager& application_manager_; /** diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_from_hmi.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_from_hmi.cc index 989c606085b..25f389abd03 100644 --- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_from_hmi.cc +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_from_hmi.cc @@ -240,8 +240,8 @@ void ASGetAppServiceDataRequestFromHMI::on_event( hmi_apis::Common_Result::eType result = static_cast( event_message[strings::params][hmi_response::code].asInt()); - bool success = - IsHMIResultSuccess(result, HmiInterfaces::HMI_INTERFACE_AppService); + bool success = CommandImpl::IsHMIResultSuccess( + result, HmiInterfaces::HMI_INTERFACE_AppService); if (ValidateResponse(msg_params)) { SendResponse(success, correlation_id(), @@ -263,7 +263,8 @@ void ASGetAppServiceDataRequestFromHMI::on_event( msg_params[strings::result_code].asInt()); hmi_apis::Common_Result::eType result = MessageHelper::MobileToHMIResult(mobile_result); - bool success = IsMobileResultSuccess(mobile_result); + bool success = + application_manager::commands::IsMobileResultSuccess(mobile_result); if (ValidateResponse(msg_params)) { SendResponse(success, diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_perform_app_service_interaction_request_from_hmi.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_perform_app_service_interaction_request_from_hmi.cc index f5a1aac05c5..315d06b85ff 100644 --- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_perform_app_service_interaction_request_from_hmi.cc +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_perform_app_service_interaction_request_from_hmi.cc @@ -140,7 +140,8 @@ void ASPerformAppServiceInteractionRequestFromHMI::on_event( msg_params[strings::result_code].asInt()); hmi_apis::Common_Result::eType result = MessageHelper::MobileToHMIResult(mobile_result); - bool success = IsMobileResultSuccess(mobile_result); + bool success = + application_manager::commands::IsMobileResultSuccess(mobile_result); SendResponse(success, correlation_id(), hmi_apis::FunctionID::AppService_PerformAppServiceInteraction, diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_request.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_request.cc index 719856625dc..b0063a327f4 100644 --- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_request.cc +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_request.cc @@ -96,7 +96,7 @@ void GetAppServiceDataRequest::on_event( mobile_apis::Result::eType result = static_cast( msg_params[strings::result_code].asInt()); - bool success = IsMobileResultSuccess(result); + bool success = application_manager::commands::IsMobileResultSuccess(result); if (success) { HandleSubscribe(); } diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_request.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_request.cc index c303e6d99f3..64110a8e237 100644 --- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_request.cc +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_request.cc @@ -181,7 +181,7 @@ void PerformAppServiceInteractionRequest::on_event( : NULL; mobile_apis::Result::eType result = static_cast( msg_params[strings::result_code].asInt()); - bool success = IsMobileResultSuccess(result); + bool success = application_manager::commands::IsMobileResultSuccess(result); SendResponse(success, result, info, &msg_params); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/subscribe_button_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/subscribe_button_request.h new file mode 100644 index 00000000000..f3e08d0a230 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/subscribe_button_request.h @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2021, 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_HMI_SUBSCRIBE_BUTTON_REQUEST_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_SUBSCRIBE_BUTTON_REQUEST_H_ + +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/event_engine/event.h" +#include "utils/macro.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { +namespace hmi { +/** + * @brief SubscribeButtonRequest command class + **/ +class SubscribeButtonRequest : public app_mngr::commands::RequestToHMI, + public app_mngr::event_engine::EventObserver { + public: + /** + * @brief SubscribeButtonRequest class constructor + * @param message Incoming SmartObject message + **/ + SubscribeButtonRequest(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_handle); + + /** + * @brief SubscribeButtonRequest class destructor + **/ + ~SubscribeButtonRequest(); + + /** + * @brief Execute command + **/ + void Run() OVERRIDE; + + void onTimeOut() OVERRIDE; + + void on_event(const application_manager::event_engine::Event& event) OVERRIDE; + + private: + app_mngr::ApplicationSharedPtr GetApplicationPtr(); + + DISALLOW_COPY_AND_ASSIGN(SubscribeButtonRequest); + + hmi_apis::Common_ButtonName::eType button_name_; +}; + +} // namespace hmi +} // namespace commands +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_SUBSCRIBE_BUTTON_REQUEST_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_button_subscription_notification.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/subscribe_button_response.h similarity index 64% rename from src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_button_subscription_notification.h rename to src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/subscribe_button_response.h index 0a0a8c3c5d4..14c9753d0cc 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_button_subscription_notification.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/subscribe_button_response.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Ford Motor Company + * Copyright (c) 2021, Ford Motor Company * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -30,54 +30,49 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_BUTTON_SUBSCRIPTION_NOTIFICATION_H_ -#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_BUTTON_SUBSCRIPTION_NOTIFICATION_H_ +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_SUBSCRIBE_BUTTON_RESPONSE_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_SUBSCRIBE_BUTTON_RESPONSE_H_ -#include "application_manager/commands/notification_to_hmi.h" +#include "application_manager/application_manager.h" +#include "application_manager/commands/response_from_hmi.h" +#include "utils/macro.h" namespace sdl_rpc_plugin { namespace app_mngr = application_manager; namespace commands { - namespace hmi { - /** - * @brief OnButtonSubscriptionNotification command class + * @brief SubscribeButtonResponse command class **/ -class OnButtonSubscriptionNotification - : public app_mngr::commands::NotificationToHMI { +class SubscribeButtonResponse : public app_mngr::commands::ResponseFromHMI { public: /** - * @brief OnButtonSubscriptionNotification class constructor - * + * @brief SubscribeButtonResponse class constructor * @param message Incoming SmartObject message **/ - OnButtonSubscriptionNotification( - 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_handle); + SubscribeButtonResponse(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_handle); /** - * @brief OnButtonSubscriptionNotification class destructor + * @brief SubscribeButtonResponse class destructor **/ - virtual ~OnButtonSubscriptionNotification(); + ~SubscribeButtonResponse(); /** * @brief Execute command **/ - virtual void Run(); + void Run() OVERRIDE; private: - DISALLOW_COPY_AND_ASSIGN(OnButtonSubscriptionNotification); + DISALLOW_COPY_AND_ASSIGN(SubscribeButtonResponse); }; } // namespace hmi - } // namespace commands - } // namespace sdl_rpc_plugin -#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_BUTTON_SUBSCRIPTION_NOTIFICATION_H_ +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_SUBSCRIBE_BUTTON_RESPONSE_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/unsubscribe_button_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/unsubscribe_button_request.h new file mode 100644 index 00000000000..b377a536cbd --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/unsubscribe_button_request.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2021, 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_HMI_UNSUBSCRIBE_BUTTON_REQUEST_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_UNSUBSCRIBE_BUTTON_REQUEST_H_ + +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/event_engine/event.h" +#include "utils/macro.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +namespace hmi { + +class UnsubscribeButtonRequest : public app_mngr::commands::RequestToHMI, + public app_mngr::event_engine::EventObserver { + public: + UnsubscribeButtonRequest(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_handle); + + ~UnsubscribeButtonRequest(); + + void Run() OVERRIDE; + + void onTimeOut() OVERRIDE; + + void on_event(const application_manager::event_engine::Event& event) OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(UnsubscribeButtonRequest); + + hmi_apis::Common_ButtonName::eType button_name_; +}; + +} // namespace hmi +} // namespace commands + +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_UNSUBSCRIBE_BUTTON_REQUEST_H_ \ No newline at end of file diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_button_subscription_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/unsubscribe_button_response.h similarity index 57% rename from src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_button_subscription_notification.cc rename to src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/unsubscribe_button_response.h index c8d36407b83..5697fa05848 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_button_subscription_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/unsubscribe_button_response.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Ford Motor Company + * Copyright (c) 2021, Ford Motor Company * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -30,39 +30,40 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include "sdl_rpc_plugin/commands/hmi/on_button_subscription_notification.h" +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_UNSUBSCRIBE_BUTTON_RESPONSE_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_UNSUBSCRIBE_BUTTON_RESPONSE_H_ + +#include "application_manager/application_manager.h" +#include "application_manager/commands/response_from_hmi.h" +#include "utils/macro.h" namespace sdl_rpc_plugin { -using namespace application_manager; +namespace app_mngr = application_manager; namespace commands { namespace hmi { -SDL_CREATE_LOG_VARIABLE("Commands") - -OnButtonSubscriptionNotification::OnButtonSubscriptionNotification( - const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle) - : NotificationToHMI(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handle) {} +class UnsubscribeButtonResponse : public app_mngr::commands::ResponseFromHMI { + public: + UnsubscribeButtonResponse(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_handle); -OnButtonSubscriptionNotification::~OnButtonSubscriptionNotification() {} + ~UnsubscribeButtonResponse(); -void OnButtonSubscriptionNotification::Run() { - SDL_LOG_AUTO_TRACE(); + void Run() OVERRIDE; - SendNotification(); -} + private: + DISALLOW_COPY_AND_ASSIGN(UnsubscribeButtonResponse); +}; } // namespace hmi } // namespace commands } // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_UNSUBSCRIBE_BUTTON_RESPONSE_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/on_button_event_notification.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/on_button_event_notification.h index afde9bac92f..f1ca0f546c6 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/on_button_event_notification.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/on_button_event_notification.h @@ -35,6 +35,7 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_ON_BUTTON_EVENT_NOTIFICATION_H_ #include "application_manager/application.h" +#include "application_manager/commands/button_notification_to_mobile.h" #include "application_manager/commands/command_notification_impl.h" #include "utils/macro.h" @@ -50,7 +51,7 @@ namespace mobile { * to mobile device that some button was pressed on HMI. **/ class OnButtonEventNotification - : public app_mngr::commands::CommandNotificationImpl { + : public app_mngr::commands::ButtonNotificationToMobile { public: /** * @brief OnButtonEventNotification class constructor @@ -68,18 +69,13 @@ class OnButtonEventNotification **/ virtual ~OnButtonEventNotification(); - /** - * @brief Execute command - **/ - virtual void Run(); - - private: + protected: /* * @brief Sends button event notification to mobile device * * @param app Application to receive notification */ - void SendButtonEvent(app_mngr::ApplicationConstSharedPtr app); + void SendButtonNotification(app_mngr::ApplicationSharedPtr app) OVERRIDE; DISALLOW_COPY_AND_ASSIGN(OnButtonEventNotification); }; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/on_button_press_notification.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/on_button_press_notification.h index 57fda49be74..89f5d48f1a1 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/on_button_press_notification.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/on_button_press_notification.h @@ -35,6 +35,7 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_ON_BUTTON_PRESS_NOTIFICATION_H_ #include "application_manager/application.h" +#include "application_manager/commands/button_notification_to_mobile.h" #include "application_manager/commands/command_notification_impl.h" #include "utils/macro.h" @@ -50,7 +51,7 @@ namespace mobile { * to mobile device that some button was pressed on HMI. **/ class OnButtonPressNotification - : public app_mngr::commands::CommandNotificationImpl { + : public app_mngr::commands::ButtonNotificationToMobile { public: /** * @brief OnButtonPressNotification class constructor @@ -66,12 +67,7 @@ class OnButtonPressNotification /** * @brief OnButtonEventCommand class destructor **/ - virtual ~OnButtonPressNotification(); - - /** - * @brief Execute command - **/ - virtual void Run(); + ~OnButtonPressNotification(); private: /* @@ -79,7 +75,7 @@ class OnButtonPressNotification * * @param app Application to receive notification */ - void SendButtonPress(app_mngr::ApplicationConstSharedPtr app); + void SendButtonNotification(app_mngr::ApplicationSharedPtr app) OVERRIDE; DISALLOW_COPY_AND_ASSIGN(OnButtonPressNotification); }; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/subscribe_button_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/subscribe_button_request.h index 2b9887daad2..ecb390095ea 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/subscribe_button_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/subscribe_button_request.h @@ -74,6 +74,12 @@ class SubscribeButtonRequest : public app_mngr::commands::CommandRequestImpl { */ bool Init() 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: /** * @brief Checks if button subscription allowed. In case non-media @@ -88,12 +94,6 @@ class SubscribeButtonRequest : public app_mngr::commands::CommandRequestImpl { bool IsSubscriptionAllowed(app_mngr::ApplicationSharedPtr app, const mobile_apis::ButtonName::eType btn_id); - /** - * @brief Sends ButtonSubscription notification - * to notify HMI that app subscribed on the button. - */ - void SendSubscribeButtonNotification(); - DISALLOW_COPY_AND_ASSIGN(SubscribeButtonRequest); }; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/unsubscribe_button_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/unsubscribe_button_request.h index 51c10642cf2..5adecb4d7a7 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/unsubscribe_button_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/unsubscribe_button_request.h @@ -42,44 +42,23 @@ namespace app_mngr = application_manager; namespace commands { -/** - * @brief UnsubscribeButtonRequest command class - **/ class UnsubscribeButtonRequest : public app_mngr::commands::CommandRequestImpl { public: - /** - * @brief UnsubscribeButtonRequest class constructor - * - * @param message Incoming SmartObject message - **/ UnsubscribeButtonRequest(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 UnsubscribeButtonRequest class destructor - **/ ~UnsubscribeButtonRequest() FINAL; - /** - * @brief Execute command - **/ void Run() FINAL; - /** - * @brief Init sets hash update mode for request - */ bool Init() FINAL; - private: - /** - * @brief Sends ButtonSubscription notification - * to notify HMI that app unsubscribed from the button. - */ - void SendUnsubscribeButtonNotification(); + void on_event(const app_mngr::event_engine::Event& event) FINAL; + private: DISALLOW_COPY_AND_ASSIGN(UnsubscribeButtonRequest); }; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/subscribe_button_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/subscribe_button_request.cc new file mode 100644 index 00000000000..b1699534bc0 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/subscribe_button_request.cc @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2021, 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/hmi/subscribe_button_request.h" +#include "application_manager/message_helper.h" +#include "application_manager/resumption/resume_ctrl.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; + +namespace commands { + +SDL_CREATE_LOG_VARIABLE("Commands") + +namespace hmi { + +SubscribeButtonRequest::SubscribeButtonRequest( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + rpc_service::RPCService& rpc_service, + HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handle) + : RequestToHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handle) + , EventObserver(application_manager.event_dispatcher()) { + hmi_apis::Common_ButtonName::eType button_name = + static_cast( + (*message_)[app_mngr::strings::msg_params] + [app_mngr::strings::button_name] + .asInt()); + + button_name_ = button_name; +} + +SubscribeButtonRequest::~SubscribeButtonRequest() {} + +app_mngr::ApplicationSharedPtr SubscribeButtonRequest::GetApplicationPtr() { + const uint32_t app_id = + (*message_)[strings::msg_params][strings::app_id].asUInt(); + + return application_manager_.application_by_hmi_app(app_id); +} + +void SubscribeButtonRequest::Run() { + SDL_LOG_AUTO_TRACE(); + + // Specific case when app subscribes to CUSTOM_BUTTON upon registration and no + // explicit mobile request exist when response arrives. In this case event + // should be catched by HMI request itself. + if (hmi_apis::Common_ButtonName::CUSTOM_BUTTON == button_name_) { + ApplicationSharedPtr app = GetApplicationPtr(); + if (app) { + // Application should also be subscribed to CUSTOM_BUTTON even before + // response is received + app->SubscribeToButton(mobile_apis::ButtonName::CUSTOM_BUTTON); + } + + subscribe_on_event(hmi_apis::FunctionID::Buttons_SubscribeButton, + correlation_id()); + } + + SendRequest(); +} + +void SubscribeButtonRequest::on_event(const event_engine::Event& event) { + SDL_LOG_AUTO_TRACE(); + using namespace helpers; + + if (hmi_apis::FunctionID::Buttons_SubscribeButton != event.id()) { + SDL_LOG_ERROR("Unexpected event id received: " << event.id()); + return; + } + + unsubscribe_from_event(hmi_apis::FunctionID::Buttons_SubscribeButton); + + const smart_objects::SmartObject& message = event.smart_object(); + ApplicationSharedPtr app = GetApplicationPtr(); + + if (!app) { + SDL_LOG_ERROR("NULL pointer."); + return; + } + + const auto hmi_result = static_cast( + message[strings::params][hmi_response::code].asInt()); + + if (CommandImpl::IsHMIResultSuccess(hmi_result, + HmiInterfaces::HMI_INTERFACE_Buttons)) { + SDL_LOG_DEBUG("Subscription to " + << button_name_ << " was successful. Subscribing internally"); + app->SubscribeToButton( + static_cast(button_name_)); + } else if (hmi_apis::Common_ButtonName::CUSTOM_BUTTON == button_name_) { + // SDL should revert subscription in a specific case related to custom + // button because it was subscribed when the request is sent to HMI + SDL_LOG_ERROR( + "Subscription to custom button was failed. Revert the internal " + "subscription"); + app->UnsubscribeFromButton( + static_cast(button_name_)); + } +} + +void SubscribeButtonRequest::onTimeOut() { + SDL_LOG_AUTO_TRACE(); + + application_manager_.AddExpiredButtonRequest( + application_id(), correlation_id(), button_name_); + + if (hmi_apis::Common_ButtonName::CUSTOM_BUTTON == button_name_) { + ApplicationSharedPtr app = GetApplicationPtr(); + + if (app) { + // SDL should revert subscription in a specific case related to custom + // button because it was subscribed when the request is sent to HMI + SDL_LOG_ERROR( + "Subscription to custom button was timed out. Revert the internal " + "subscription"); + app->UnsubscribeFromButton( + static_cast(button_name_)); + } + } + + auto& resume_ctrl = application_manager_.resume_controller(); + resume_ctrl.HandleOnTimeOut( + correlation_id(), + static_cast(function_id())); +} + +} // namespace hmi +} // namespace commands +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/subscribe_button_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/subscribe_button_response.cc new file mode 100644 index 00000000000..202cde29c63 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/subscribe_button_response.cc @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2021, 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/hmi/subscribe_button_response.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/message_helper.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; +namespace commands { + +SDL_CREATE_LOG_VARIABLE("Commands") + +namespace hmi { +SubscribeButtonResponse::SubscribeButtonResponse( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + rpc_service::RPCService& rpc_service, + HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handle) + : ResponseFromHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handle) {} + +SubscribeButtonResponse::~SubscribeButtonResponse() {} + +void SubscribeButtonResponse::Run() { + SDL_LOG_AUTO_TRACE(); + + hmi_apis::Common_Result::eType hmi_result = + static_cast( + (*message_) + .getElement(strings::params) + .getElement(hmi_response::code) + .asInt()); + + const auto expired_request_data = + application_manager_.GetExpiredButtonRequestData(correlation_id()); + if (expired_request_data) { + const uint32_t app_id = (*expired_request_data).app_id_; + const auto button_name = (*expired_request_data).button_name_; + application_manager_.DeleteExpiredButtonRequest(correlation_id()); + + if (!CommandImpl::IsHMIResultSuccess( + hmi_result, HmiInterfaces::HMI_INTERFACE_Buttons)) { + return; + } + + smart_objects::SmartObjectSPtr msg = + MessageHelper::CreateButtonSubscriptionHandlingRequestToHmi( + app_id, + button_name, + hmi_apis::FunctionID::Buttons_UnsubscribeButton, + application_manager_); + + rpc_service_.SendMessageToHMI(msg); + return; + } + + event_engine::Event event(hmi_apis::FunctionID::Buttons_SubscribeButton); + event.set_smart_object(*message_); + event.raise(application_manager_.event_dispatcher()); +} + +} // namespace hmi +} // namespace commands +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/unsubscribe_button_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/unsubscribe_button_request.cc new file mode 100644 index 00000000000..dbebf79018c --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/unsubscribe_button_request.cc @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2021, 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/hmi/unsubscribe_button_request.h" +#include "application_manager/event_engine/event_dispatcher_impl.h" +#include "application_manager/message_helper.h" +#include "application_manager/resumption/resume_ctrl.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; + +namespace commands { +SDL_CREATE_LOG_VARIABLE("Commands") + +namespace hmi { + +UnsubscribeButtonRequest::UnsubscribeButtonRequest( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + rpc_service::RPCService& rpc_service, + HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handle) + : RequestToHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handle) + , EventObserver(application_manager.event_dispatcher()) { + hmi_apis::Common_ButtonName::eType button_name = + static_cast( + (*message_)[app_mngr::strings::msg_params] + [app_mngr::strings::button_name] + .asInt()); + + button_name_ = button_name; +} + +UnsubscribeButtonRequest::~UnsubscribeButtonRequest() {} + +void UnsubscribeButtonRequest::Run() { + SDL_LOG_AUTO_TRACE(); + + subscribe_on_event(hmi_apis::FunctionID::Buttons_UnsubscribeButton, + correlation_id()); + SendRequest(); +} + +void UnsubscribeButtonRequest::onTimeOut() { + SDL_LOG_AUTO_TRACE(); + + application_manager_.AddExpiredButtonRequest( + application_id(), correlation_id(), button_name_); + + auto& resume_ctrl = application_manager_.resume_controller(); + resume_ctrl.HandleOnTimeOut( + correlation_id(), + static_cast(function_id())); +} + +void UnsubscribeButtonRequest::on_event(const event_engine::Event& event) { + SDL_LOG_AUTO_TRACE(); + + if (hmi_apis::FunctionID::Buttons_UnsubscribeButton != event.id()) { + SDL_LOG_ERROR("Unexpected event id received: " << event.id()); + return; + } + + unsubscribe_from_event(hmi_apis::FunctionID::Buttons_UnsubscribeButton); + + ApplicationSharedPtr app = + application_manager_.application_by_hmi_app(application_id()); + + const smart_objects::SmartObject& message = event.smart_object(); + + if (!app) { + SDL_LOG_ERROR("NULL pointer."); + return; + } + + hmi_apis::Common_Result::eType hmi_result = + static_cast( + message[strings::params][hmi_response::code].asInt()); + + if (CommandImpl::IsHMIResultSuccess(hmi_result, + HmiInterfaces::HMI_INTERFACE_Buttons)) { + const mobile_apis::ButtonName::eType btn_id = + static_cast( + (*message_)[strings::msg_params][strings::button_name].asInt()); + app->UnsubscribeFromButton( + static_cast(btn_id)); + } +} + +} // namespace hmi +} // namespace commands +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/unsubscribe_button_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/unsubscribe_button_response.cc new file mode 100644 index 00000000000..68b3663ca7b --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/unsubscribe_button_response.cc @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2021, 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/hmi/unsubscribe_button_response.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/message_helper.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; +namespace commands { + +SDL_CREATE_LOG_VARIABLE("Commands") + +namespace hmi { + +UnsubscribeButtonResponse::UnsubscribeButtonResponse( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + rpc_service::RPCService& rpc_service, + HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handle) + : ResponseFromHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handle) {} + +UnsubscribeButtonResponse::~UnsubscribeButtonResponse() {} + +void UnsubscribeButtonResponse::Run() { + SDL_LOG_AUTO_TRACE(); + + hmi_apis::Common_Result::eType hmi_result = + static_cast( + (*message_) + .getElement(strings::params) + .getElement(hmi_response::code) + .asInt()); + + const auto expired_request_data = + application_manager_.GetExpiredButtonRequestData(correlation_id()); + if (expired_request_data) { + const uint32_t app_id = (*expired_request_data).app_id_; + const auto button_name = (*expired_request_data).button_name_; + application_manager_.DeleteExpiredButtonRequest(correlation_id()); + + if (!CommandImpl::IsHMIResultSuccess( + hmi_result, HmiInterfaces::HMI_INTERFACE_Buttons)) { + return; + } + + smart_objects::SmartObjectSPtr msg = + MessageHelper::CreateButtonSubscriptionHandlingRequestToHmi( + app_id, + button_name, + hmi_apis::FunctionID::Buttons_SubscribeButton, + application_manager_); + + rpc_service_.SendMessageToHMI(msg); + return; + } + + event_engine::Event event(hmi_apis::FunctionID::Buttons_UnsubscribeButton); + event.set_smart_object(*message_); + event.raise(application_manager_.event_dispatcher()); +} + +} // namespace hmi +} // namespace commands +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_window_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_window_request.cc index 2a0ca4ddb38..8febbf4f608 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_window_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_window_request.cc @@ -218,7 +218,8 @@ void CreateWindowRequest::on_event(const event_engine::Event& event) { static_cast( response_message[strings::params][hmi_response::code].asInt())); - const bool is_success = IsMobileResultSuccess(result_code); + const bool is_success = + app_mngr::commands::IsMobileResultSuccess(result_code); std::string response_info; GetInfo(response_message, response_info); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_interaction_choice_set_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_interaction_choice_set_request.cc index 05347435d77..b675042d16a 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_interaction_choice_set_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_interaction_choice_set_request.cc @@ -204,7 +204,7 @@ void DeleteInteractionChoiceSetRequest:: continue; } - if (!IsHMIResultSuccess(code)) { + if (!application_manager::commands::IsHMIResultSuccess(code)) { result_code = code; } } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_window_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_window_request.cc index 214a9c2bab2..6f36f99c6cc 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_window_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_window_request.cc @@ -134,7 +134,8 @@ void DeleteWindowRequest::on_event(const event_engine::Event& event) { static_cast( response_message[strings::params][hmi_response::code].asInt())); - const bool is_success = IsMobileResultSuccess(result_code); + const bool is_success = + app_mngr::commands::IsMobileResultSuccess(result_code); std::string response_info; GetInfo(response_message, response_info); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_event_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_event_notification.cc index 14787d0a089..234c33214c4 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_event_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_event_notification.cc @@ -34,6 +34,7 @@ #include "sdl_rpc_plugin/commands/mobile/on_button_event_notification.h" #include "application_manager/application_impl.h" +#include "application_manager/message_helper.h" #include "interfaces/MOBILE_API.h" namespace sdl_rpc_plugin { @@ -51,146 +52,23 @@ OnButtonEventNotification::OnButtonEventNotification( rpc_service::RPCService& rpc_service, HMICapabilities& hmi_capabilities, policy::PolicyHandlerInterface& policy_handler) - : CommandNotificationImpl(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handler) {} + : ButtonNotificationToMobile(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} OnButtonEventNotification::~OnButtonEventNotification() {} -void OnButtonEventNotification::Run() { +void OnButtonEventNotification::SendButtonNotification( + ApplicationSharedPtr app) { SDL_LOG_AUTO_TRACE(); - const uint32_t btn_id = static_cast( - (*message_)[strings::msg_params][hmi_response::button_name].asInt()); - - const bool is_app_id_exists = - (*message_)[strings::msg_params].keyExists(strings::app_id); - ApplicationSharedPtr app; - - // CUSTOM_BUTTON notification - if (static_cast(mobile_apis::ButtonName::CUSTOM_BUTTON) == btn_id) { - // app_id is mandatory for CUSTOM_BUTTON notification - if (!is_app_id_exists) { - SDL_LOG_ERROR("CUSTOM_BUTTON OnButtonEvent without app_id."); - return; - } - - app = application_manager_.application( - (*message_)[strings::msg_params][strings::app_id].asUInt()); - - // custom_button_id is mandatory for CUSTOM_BUTTON notification - if (false == (*message_)[strings::msg_params].keyExists( - hmi_response::custom_button_id)) { - SDL_LOG_ERROR("CUSTOM_BUTTON OnButtonEvent without custom_button_id."); - return; - } - - if (!app) { - SDL_LOG_ERROR("Application doesn't exist."); - return; - } - - uint32_t custom_btn_id = 0; - custom_btn_id = - (*message_)[strings::msg_params][hmi_response::custom_button_id] - .asUInt(); - - if (false == app->IsSubscribedToSoftButton(custom_btn_id)) { - SDL_LOG_ERROR("Application doesn't subscribed to this custom_button_id."); - return; - } - - const auto window_id = app->GetSoftButtonWindowID(custom_btn_id); - (*message_)[strings::msg_params][strings::window_id] = window_id; - const auto window_hmi_level = app->hmi_level(window_id); - if ((mobile_api::HMILevel::HMI_NONE == window_hmi_level)) { - SDL_LOG_WARN( - "CUSTOM_BUTTON OnButtonEvent notification is not allowed in " - "NONE hmi level"); - return; - } - - SendButtonEvent(app); - return; - } - - const std::vector& subscribed_apps = - application_manager_.applications_by_button(btn_id); - - std::vector::const_iterator it = - subscribed_apps.begin(); - for (; subscribed_apps.end() != it; ++it) { - ApplicationSharedPtr subscribed_app = *it; - if (!subscribed_app) { - SDL_LOG_WARN("Null pointer to subscribed app."); - continue; - } - - // Send ButtonEvent notification only in HMI_FULL or HMI_LIMITED mode - const mobile_apis::HMILevel::eType app_hmi_level = - subscribed_app->hmi_level( - mobile_apis::PredefinedWindows::DEFAULT_WINDOW); - if ((mobile_api::HMILevel::HMI_FULL != app_hmi_level) && - (mobile_api::HMILevel::HMI_LIMITED != app_hmi_level)) { - SDL_LOG_WARN("OnButtonEvent notification is allowed only" - << "in FULL or LIMITED hmi level"); - continue; - } - // if OK button and "app_id" absent send notification only in HMI_FULL mode - // otherwise send to subscribed apps in limited - if (is_app_id_exists || hmi_apis::Common_ButtonName::OK != btn_id || - subscribed_app->IsFullscreen()) { - SendButtonEvent(subscribed_app); - } - } -} - -void OnButtonEventNotification::SendButtonEvent(ApplicationConstSharedPtr app) { - if (!app) { - SDL_LOG_ERROR("OnButtonEvent NULL pointer"); - return; - } - - smart_objects::SmartObjectSPtr on_btn_event = - std::make_shared(); - - if (!on_btn_event) { - SDL_LOG_ERROR("OnButtonEvent NULL pointer"); - return; - } - - (*on_btn_event)[strings::params][strings::connection_key] = app->app_id(); - - (*on_btn_event)[strings::params][strings::function_id] = - static_cast(mobile_apis::FunctionID::eType::OnButtonEventID); - - mobile_apis::ButtonName::eType btn_id = - static_cast( - (*message_)[strings::msg_params][hmi_response::button_name].asInt()); - - if (btn_id == mobile_apis::ButtonName::PLAY_PAUSE && - app->msg_version() < utils::rpc_version_5) { - btn_id = mobile_apis::ButtonName::OK; - } - - (*on_btn_event)[strings::msg_params][strings::button_name] = btn_id; - (*on_btn_event)[strings::msg_params][strings::button_event_mode] = - (*message_)[strings::msg_params][hmi_response::button_mode]; - - if ((*message_)[strings::msg_params].keyExists( - hmi_response::custom_button_id)) { - (*on_btn_event)[strings::msg_params][strings::custom_button_id] = - (*message_)[strings::msg_params][strings::custom_button_id]; - } + (*message_)[strings::params][strings::function_id] = + mobile_apis::FunctionID::eType::OnButtonEventID; - if ((*message_)[strings::msg_params].keyExists(strings::window_id)) { - (*on_btn_event)[strings::msg_params][strings::window_id] = - (*message_)[strings::msg_params][strings::window_id]; - } + message_ = MessageHelper::CreateButtonNotificationToMobile(app, *message_); - message_ = on_btn_event; SendNotification(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_press_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_press_notification.cc index 4444f0d156d..90bf618c35c 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_press_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_press_notification.cc @@ -34,6 +34,7 @@ #include "sdl_rpc_plugin/commands/mobile/on_button_press_notification.h" #include "application_manager/application_impl.h" +#include "application_manager/message_helper.h" #include "interfaces/MOBILE_API.h" #include "utils/semantic_version.h" @@ -52,155 +53,23 @@ OnButtonPressNotification::OnButtonPressNotification( rpc_service::RPCService& rpc_service, HMICapabilities& hmi_capabilities, policy::PolicyHandlerInterface& policy_handler) - : CommandNotificationImpl(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handler) {} + : ButtonNotificationToMobile(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} OnButtonPressNotification::~OnButtonPressNotification() {} -void OnButtonPressNotification::Run() { +void OnButtonPressNotification::SendButtonNotification( + ApplicationSharedPtr app) { SDL_LOG_AUTO_TRACE(); - const uint32_t btn_id = static_cast( - (*message_)[strings::msg_params][hmi_response::button_name].asInt()); - - const bool is_app_id_exists = - (*message_)[strings::msg_params].keyExists(strings::app_id); - ApplicationSharedPtr app; - if (is_app_id_exists) { - app = application_manager_.application( - (*message_)[strings::msg_params][strings::app_id].asUInt()); - } - - // CUSTOM_BUTTON notification - if (static_cast(mobile_apis::ButtonName::CUSTOM_BUTTON) == btn_id) { - // app_id is mandatory for CUSTOM_BUTTON notification - if (!is_app_id_exists) { - SDL_LOG_ERROR("CUSTOM_BUTTON OnButtonPress without app_id."); - return; - } - - // custom_button_id is mandatory for CUSTOM_BUTTON notification - if (false == (*message_)[strings::msg_params].keyExists( - hmi_response::custom_button_id)) { - SDL_LOG_ERROR("CUSTOM_BUTTON OnButtonPress without custom_button_id."); - return; - } - - if (!app) { - SDL_LOG_ERROR("Application doesn't exist."); - return; - } - - uint32_t custom_btn_id = 0; - custom_btn_id = - (*message_)[strings::msg_params][hmi_response::custom_button_id] - .asUInt(); - - if (false == app->IsSubscribedToSoftButton(custom_btn_id)) { - SDL_LOG_ERROR("Application doesn't subscribed to this custom_button_id."); - return; - } - - // Send ButtonPress notification only in HMI_FULL or HMI_LIMITED mode - const auto window_id = app->GetSoftButtonWindowID(custom_btn_id); - app->hmi_level(mobile_apis::PredefinedWindows::DEFAULT_WINDOW); - (*message_)[strings::msg_params][strings::window_id] = window_id; - const auto window_hmi_level = app->hmi_level(window_id); - if ((mobile_api::HMILevel::HMI_NONE == window_hmi_level)) { - SDL_LOG_WARN( - "CUSTOM_BUTTON OnButtonPress notification is not allowed in " - "NONE hmi level"); - return; - } - - SendButtonPress(app); - return; - } - - const std::vector& subscribed_apps = - application_manager_.applications_by_button(btn_id); - - std::vector::const_iterator it = - subscribed_apps.begin(); - for (; subscribed_apps.end() != it; ++it) { - ApplicationSharedPtr subscribed_app = *it; - if (!subscribed_app) { - SDL_LOG_WARN("Null pointer to subscribed app."); - continue; - } - - // Send ButtonPress notification only in HMI_FULL or HMI_LIMITED mode - const mobile_apis::HMILevel::eType app_hmi_level = - subscribed_app->hmi_level( - mobile_apis::PredefinedWindows::DEFAULT_WINDOW); - if ((mobile_api::HMILevel::HMI_FULL != app_hmi_level) && - (mobile_api::HMILevel::HMI_LIMITED != app_hmi_level)) { - SDL_LOG_WARN("OnButtonPress notification is allowed only " - << "in FULL or LIMITED hmi level"); - continue; - } - // if "appID" is present, send it to named app only if its FULL or - // LIMITED - if (app.use_count() != 0) { - if (app->app_id() == subscribed_app->app_id()) { - SendButtonPress(subscribed_app); - } - } else if (hmi_apis::Common_ButtonName::OK != btn_id || - subscribed_app->IsFullscreen()) { - // if No "appID" and OK button - send it FULL apps only. - // if not OK button, send to LIMITED subscribed apps - SendButtonPress(subscribed_app); - } - } -} - -void OnButtonPressNotification::SendButtonPress(ApplicationConstSharedPtr app) { - if (!app) { - SDL_LOG_ERROR("OnButtonPress NULL pointer"); - return; - } - - smart_objects::SmartObjectSPtr on_btn_press = - std::make_shared(); - - if (!on_btn_press) { - SDL_LOG_ERROR("OnButtonPress NULL pointer"); - return; - } - - (*on_btn_press)[strings::params][strings::connection_key] = app->app_id(); - - (*on_btn_press)[strings::params][strings::function_id] = - static_cast(mobile_apis::FunctionID::eType::OnButtonPressID); - - mobile_apis::ButtonName::eType btn_id = - static_cast( - (*message_)[strings::msg_params][hmi_response::button_name].asInt()); - - if (btn_id == mobile_apis::ButtonName::PLAY_PAUSE && - app->msg_version() < utils::rpc_version_5) { - btn_id = mobile_apis::ButtonName::OK; - } - - (*on_btn_press)[strings::msg_params][strings::button_name] = btn_id; - (*on_btn_press)[strings::msg_params][strings::button_press_mode] = - (*message_)[strings::msg_params][hmi_response::button_mode]; - - if ((*message_)[strings::msg_params].keyExists( - hmi_response::custom_button_id)) { - (*on_btn_press)[strings::msg_params][strings::custom_button_id] = - (*message_)[strings::msg_params][strings::custom_button_id]; - } + (*message_)[strings::params][strings::function_id] = + mobile_apis::FunctionID::eType::OnButtonPressID; - if ((*message_)[strings::msg_params].keyExists(strings::window_id)) { - (*on_btn_press)[strings::msg_params][strings::window_id] = - (*message_)[strings::msg_params][strings::window_id]; - } + message_ = MessageHelper::CreateButtonNotificationToMobile(app, *message_); - message_ = on_btn_press; SendNotification(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc index c095081f2a3..a43603294ad 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc @@ -1462,13 +1462,13 @@ void RegisterAppInterfaceRequest::CheckResponseVehicleTypeParam( } void RegisterAppInterfaceRequest::SendSubscribeCustomButtonNotification() { + SDL_LOG_AUTO_TRACE(); using namespace smart_objects; SmartObject msg_params = SmartObject(SmartType_Map); msg_params[strings::app_id] = connection_key(); - msg_params[strings::name] = hmi_apis::Common_ButtonName::CUSTOM_BUTTON; - msg_params[strings::is_suscribed] = true; - CreateHMINotification(hmi_apis::FunctionID::Buttons_OnButtonSubscription, - msg_params); + msg_params[strings::button_name] = hmi_apis::Common_ButtonName::CUSTOM_BUTTON; + SendHMIRequest( + hmi_apis::FunctionID::Buttons_SubscribeButton, &msg_params, false); } bool RegisterAppInterfaceRequest::IsApplicationSwitched() { diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/subscribe_button_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/subscribe_button_request.cc index 42cb3c60c9a..723a1ececa5 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/subscribe_button_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/subscribe_button_request.cc @@ -32,6 +32,7 @@ */ #include "sdl_rpc_plugin/commands/mobile/subscribe_button_request.h" +#include "application_manager/message_helper.h" #include "utils/semantic_version.h" namespace sdl_rpc_plugin { @@ -104,11 +105,11 @@ void SubscribeButtonRequest::Run() { return; } - app->SubscribeToButton(static_cast(btn_id)); - SendSubscribeButtonNotification(); - - const bool is_succeeded = true; - SendResponse(is_succeeded, mobile_apis::Result::SUCCESS); + (*message_)[str::msg_params][str::app_id] = app->app_id(); + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_Buttons); + SendHMIRequest(hmi_apis::FunctionID::Buttons_SubscribeButton, + &(*message_)[app_mngr::strings::msg_params], + true); } bool SubscribeButtonRequest::Init() { @@ -116,6 +117,59 @@ bool SubscribeButtonRequest::Init() { return true; } +void SubscribeButtonRequest::on_event(const event_engine::Event& event) { + SDL_LOG_AUTO_TRACE(); + + const smart_objects::SmartObject& message = event.smart_object(); + + if (hmi_apis::FunctionID::Buttons_SubscribeButton != event.id()) { + SDL_LOG_ERROR("Received unknown event."); + return; + } + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_Buttons); + ApplicationSharedPtr app = + application_manager_.application(CommandRequestImpl::connection_key()); + + if (!app) { + SDL_LOG_ERROR("NULL pointer."); + return; + } + + hmi_apis::Common_Result::eType hmi_result = + static_cast( + message[strings::params][hmi_response::code].asInt()); + std::string response_info; + GetInfo(message, response_info); + const bool result = PrepareResultForMobileResponse( + hmi_result, HmiInterfaces::HMI_INTERFACE_Buttons); + + if (result) { + const auto btn_id = static_cast( + (*message_)[str::msg_params][str::button_name].asInt()); + app->SubscribeToButton(btn_id); + } + mobile_apis::Result::eType result_code = + MessageHelper::HMIToMobileResult(hmi_result); + + SendResponse(result, + result_code, + response_info.empty() ? nullptr : response_info.c_str(), + &(message[strings::msg_params])); +} + +bool IsPresetButton(const mobile_apis::ButtonName::eType btn_id) { + return (mobile_apis::ButtonName::PRESET_0 == btn_id) || + (mobile_apis::ButtonName::PRESET_1 == btn_id) || + (mobile_apis::ButtonName::PRESET_2 == btn_id) || + (mobile_apis::ButtonName::PRESET_3 == btn_id) || + (mobile_apis::ButtonName::PRESET_4 == btn_id) || + (mobile_apis::ButtonName::PRESET_5 == btn_id) || + (mobile_apis::ButtonName::PRESET_6 == btn_id) || + (mobile_apis::ButtonName::PRESET_7 == btn_id) || + (mobile_apis::ButtonName::PRESET_8 == btn_id) || + (mobile_apis::ButtonName::PRESET_9 == btn_id); +} + bool SubscribeButtonRequest::IsSubscriptionAllowed( ApplicationSharedPtr app, mobile_apis::ButtonName::eType btn_id) { if (!app->is_media_application() && @@ -123,7 +177,8 @@ bool SubscribeButtonRequest::IsSubscriptionAllowed( (mobile_apis::ButtonName::SEEKLEFT == btn_id) || (mobile_apis::ButtonName::SEEKRIGHT == btn_id) || (mobile_apis::ButtonName::TUNEUP == btn_id) || - (mobile_apis::ButtonName::TUNEDOWN == btn_id))) { + (mobile_apis::ButtonName::TUNEDOWN == btn_id) || + IsPresetButton(btn_id))) { return false; } @@ -149,19 +204,6 @@ bool SubscribeButtonRequest::IsSubscriptionAllowed( return true; } -void SubscribeButtonRequest::SendSubscribeButtonNotification() { - using namespace smart_objects; - using namespace hmi_apis; - - // send OnButtonSubscription notification - SmartObject msg_params = SmartObject(SmartType_Map); - msg_params[strings::app_id] = connection_key(); - msg_params[strings::name] = static_cast( - (*message_)[strings::msg_params][strings::button_name].asUInt()); - msg_params[strings::is_suscribed] = true; - CreateHMINotification(FunctionID::Buttons_OnButtonSubscription, msg_params); -} - } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/unsubscribe_button_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/unsubscribe_button_request.cc index 69f85568ebb..09de35773a5 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/unsubscribe_button_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/unsubscribe_button_request.cc @@ -1,6 +1,5 @@ /* - - Copyright (c) 2018, Ford Motor Company + Copyright (c) 2021, Ford Motor Company All rights reserved. Redistribution and use in source and binary forms, with or without @@ -34,6 +33,8 @@ #include "sdl_rpc_plugin/commands/mobile/unsubscribe_button_request.h" #include "application_manager/application_impl.h" +#include "application_manager/message_helper.h" +#include "utils/helpers.h" #include "utils/semantic_version.h" namespace sdl_rpc_plugin { @@ -93,15 +94,59 @@ void UnsubscribeButtonRequest::Run() { return; } - if (!app->UnsubscribeFromButton( - static_cast(btn_id))) { - SDL_LOG_ERROR("App doesn't subscribe to button " << btn_id); + if (!app->IsSubscribedToButton(btn_id)) { + SDL_LOG_ERROR("App is not subscribed to button " << btn_id); + SendResponse(false, mobile_apis::Result::IGNORED); + return; + } + + if (mobile_apis::ButtonName::CUSTOM_BUTTON == btn_id) { + SDL_LOG_ERROR("App cannot unsubscribe from CUSTOM_BUTTON"); SendResponse(false, mobile_apis::Result::IGNORED); return; } - SendUnsubscribeButtonNotification(); - SendResponse(true, mobile_apis::Result::SUCCESS); + (*message_)[str::msg_params][str::app_id] = app->app_id(); + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_Buttons); + SendHMIRequest(hmi_apis::FunctionID::Buttons_UnsubscribeButton, + &(*message_)[app_mngr::strings::msg_params], + true); +} + +void UnsubscribeButtonRequest::on_event(const event_engine::Event& event) { + SDL_LOG_AUTO_TRACE(); + using namespace helpers; + + const smart_objects::SmartObject& message = event.smart_object(); + + if (hmi_apis::FunctionID::Buttons_UnsubscribeButton != event.id()) { + SDL_LOG_ERROR("Received unknown event."); + return; + } + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_Buttons); + ApplicationSharedPtr app = + application_manager_.application(CommandRequestImpl::connection_key()); + + if (!app) { + SDL_LOG_ERROR("NULL pointer."); + return; + } + + hmi_apis::Common_Result::eType hmi_result = + static_cast( + message[strings::params][hmi_response::code].asInt()); + std::string response_info; + GetInfo(message, response_info); + const bool result = PrepareResultForMobileResponse( + hmi_result, HmiInterfaces::HMI_INTERFACE_Buttons); + + mobile_apis::Result::eType result_code = + MessageHelper::HMIToMobileResult(hmi_result); + + SendResponse(result, + result_code, + response_info.empty() ? nullptr : response_info.c_str(), + &(message[strings::msg_params])); } bool UnsubscribeButtonRequest::Init() { @@ -109,19 +154,6 @@ bool UnsubscribeButtonRequest::Init() { return true; } -void UnsubscribeButtonRequest::SendUnsubscribeButtonNotification() { - using namespace smart_objects; - using namespace hmi_apis; - - // send OnButtonSubscription notification - SmartObject msg_params = SmartObject(SmartType_Map); - msg_params[strings::app_id] = connection_key(); - msg_params[strings::name] = static_cast( - (*message_)[strings::msg_params][strings::button_name].asInt()); - msg_params[strings::is_suscribed] = false; - CreateHMINotification(FunctionID::Buttons_OnButtonSubscription, msg_params); -} - } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/hmi_command_factory.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/hmi_command_factory.cc index 954ddb4e57c..c66e0b6950b 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/hmi_command_factory.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/hmi_command_factory.cc @@ -77,6 +77,8 @@ #include "sdl_rpc_plugin/commands/hmi/sdl_get_status_update_response.h" #include "sdl_rpc_plugin/commands/hmi/sdl_get_user_friendly_message_request.h" #include "sdl_rpc_plugin/commands/hmi/sdl_get_user_friendly_message_response.h" +#include "sdl_rpc_plugin/commands/hmi/subscribe_button_request.h" +#include "sdl_rpc_plugin/commands/hmi/subscribe_button_response.h" #include "sdl_rpc_plugin/commands/hmi/tts_change_registration_request.h" #include "sdl_rpc_plugin/commands/hmi/tts_change_registration_response.h" #include "sdl_rpc_plugin/commands/hmi/tts_get_capabilities_request.h" @@ -137,6 +139,8 @@ #include "sdl_rpc_plugin/commands/hmi/ui_slider_response.h" #include "sdl_rpc_plugin/commands/hmi/ui_subtle_alert_request.h" #include "sdl_rpc_plugin/commands/hmi/ui_subtle_alert_response.h" +#include "sdl_rpc_plugin/commands/hmi/unsubscribe_button_request.h" +#include "sdl_rpc_plugin/commands/hmi/unsubscribe_button_response.h" #include "sdl_rpc_plugin/commands/hmi/update_app_list_request.h" #include "sdl_rpc_plugin/commands/hmi/update_app_list_response.h" #include "sdl_rpc_plugin/commands/hmi/update_device_list_request.h" @@ -207,7 +211,6 @@ #include "sdl_rpc_plugin/commands/hmi/on_app_unregistered_notification.h" #include "sdl_rpc_plugin/commands/hmi/on_button_event_notification.h" #include "sdl_rpc_plugin/commands/hmi/on_button_press_notification.h" -#include "sdl_rpc_plugin/commands/hmi/on_button_subscription_notification.h" #include "sdl_rpc_plugin/commands/hmi/on_device_chosen_notification.h" #include "sdl_rpc_plugin/commands/hmi/on_device_state_changed_notification.h" #include "sdl_rpc_plugin/commands/hmi/on_driver_distraction_notification.h" @@ -680,6 +683,19 @@ CommandCreator& HMICommandFactory::get_creator_factory( : factory .GetCreator(); } + case hmi_apis::FunctionID::Buttons_SubscribeButton: { + return hmi_apis::messageType::request == message_type + ? factory.GetCreator() + : factory.GetCreator(); + } + + case hmi_apis::FunctionID::Buttons_UnsubscribeButton: { + return hmi_apis::messageType::request == message_type + ? factory.GetCreator() + : factory + .GetCreator(); + } + case hmi_apis::FunctionID::SDL_OnAllowSDLFunctionality: { return factory .GetCreator(); @@ -761,10 +777,6 @@ CommandCreator& HMICommandFactory::get_creator_factory( case hmi_apis::FunctionID::Buttons_OnButtonPress: { return factory.GetCreator(); } - case hmi_apis::FunctionID::Buttons_OnButtonSubscription: { - return factory - .GetCreator(); - } case hmi_apis::FunctionID::Navigation_OnTBTClientState: { return factory.GetCreator(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc index 5e485adb7fb..2a0eda2b10a 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc @@ -97,7 +97,6 @@ #include "hmi/on_audio_data_streaming_notification.h" #include "hmi/on_button_event_notification.h" #include "hmi/on_button_press_notification.h" -#include "hmi/on_button_subscription_notification.h" #include "hmi/on_device_chosen_notification.h" #include "hmi/on_device_state_changed_notification.h" #include "hmi/on_driver_distraction_notification.h" @@ -148,6 +147,8 @@ #include "hmi/sdl_get_user_friendly_message_response.h" #include "hmi/sdl_policy_update.h" #include "hmi/sdl_policy_update_response.h" +#include "hmi/subscribe_button_request.h" +#include "hmi/subscribe_button_response.h" #include "hmi/tts_change_registration_request.h" #include "hmi/tts_change_registration_response.h" #include "hmi/tts_get_capabilities_request.h" @@ -206,6 +207,8 @@ #include "hmi/ui_slider_response.h" #include "hmi/ui_subtle_alert_request.h" #include "hmi/ui_subtle_alert_response.h" +#include "hmi/unsubscribe_button_request.h" +#include "hmi/unsubscribe_button_response.h" #include "hmi/update_app_list_request.h" #include "hmi/update_app_list_response.h" #include "hmi/update_device_list_request.h" @@ -445,7 +448,6 @@ typedef Types + commands::UISubtleAlertRequest, + commands::hmi::UnsubscribeButtonRequest, + commands::hmi::UnsubscribeButtonResponse> HMICommandsListFifth; TYPED_TEST_CASE(HMICommandsTestFirst, HMICommandsListFirst); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc index bb5008654a9..82a5b536a89 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc @@ -45,7 +45,6 @@ #include "sdl_rpc_plugin/commands/hmi/on_audio_data_streaming_notification.h" #include "sdl_rpc_plugin/commands/hmi/on_button_event_notification.h" #include "sdl_rpc_plugin/commands/hmi/on_button_press_notification.h" -#include "sdl_rpc_plugin/commands/hmi/on_button_subscription_notification.h" #include "sdl_rpc_plugin/commands/hmi/on_device_chosen_notification.h" #include "sdl_rpc_plugin/commands/hmi/on_device_state_changed_notification.h" #include "sdl_rpc_plugin/commands/hmi/on_driver_distraction_notification.h" @@ -338,7 +337,6 @@ class HMIOnNotificationsEventDispatcher typedef Types +#include +#include "application_manager/mock_event_dispatcher.h" + +#include "gtest/gtest.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace subscribe_button_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = am::strings; +using am::commands::RequestToHMI; +using am::event_engine::Event; +using sdl_rpc_plugin::commands::hmi::SubscribeButtonRequest; +using ::test::components::application_manager_test::MockApplication; +using ::test::components::event_engine_test::MockEventDispatcher; + +typedef std::shared_ptr MockAppPtr; +typedef std::shared_ptr RequestToHMIPtr; +typedef std::shared_ptr SubscribeButtonRequestPtr; + +namespace { +const uint32_t kCorrelationId = 2u; +const uint32_t kAppId = 1u; +const hmi_apis::Common_ButtonName::eType kCustomButtonName = + hmi_apis::Common_ButtonName::CUSTOM_BUTTON; +const hmi_apis::Common_ButtonName::eType kHmiButtonName = + hmi_apis::Common_ButtonName::SEEKLEFT; +const mobile_apis::ButtonName::eType kMobileButtonName = + mobile_apis::ButtonName::SEEKLEFT; +const mobile_apis::ButtonName::eType kMobileCustomButtonName = + mobile_apis::ButtonName::CUSTOM_BUTTON; +const hmi_apis::FunctionID::eType kFunctionID = + hmi_apis::FunctionID::Buttons_SubscribeButton; +} // namespace + +class HMISubscribeButtonRequestTest + : public CommandRequestTest { + protected: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::app_id] = kAppId; + (*command_msg)[strings::msg_params][strings::button_name] = kHmiButtonName; + (*command_msg)[strings::params][strings::correlation_id] = kCorrelationId; + (*command_msg)[strings::params][strings::function_id] = kFunctionID; + + return command_msg; + } + + void InitCommand(const uint32_t& timeout) OVERRIDE { + mock_app_ = CreateMockApp(); + CommandRequestTest::InitCommand(timeout); + ON_CALL((*mock_app_), hmi_app_id()).WillByDefault(Return(kAppId)); + ON_CALL(app_mngr_, application_by_hmi_app(kAppId)) + .WillByDefault(Return(mock_app_)); + ON_CALL(app_mngr_, application(kAppId)).WillByDefault(Return(mock_app_)); + } + + MockAppPtr mock_app_; +}; + +TEST_F(HMISubscribeButtonRequestTest, Run_SendRequest_SUCCESS) { + MockEventDispatcher mock_event_dispatcher; + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher)); + + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand(command_msg)); + + EXPECT_CALL(mock_event_dispatcher, + add_observer(kFunctionID, kCorrelationId, _)) + .Times(0); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); +} + +TEST_F(HMISubscribeButtonRequestTest, Run_SendRequest_CUSTOM_BUTTON_SUCCESS) { + MockEventDispatcher mock_event_dispatcher; + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher)); + + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][strings::button_name] = kCustomButtonName; + RequestToHMIPtr command(CreateCommand(command_msg)); + + EXPECT_CALL(mock_event_dispatcher, + add_observer(kFunctionID, kCorrelationId, _)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + + ASSERT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(HMISubscribeButtonRequestTest, + onTimeOut_RequestIsExpired_HandleOnTimeout) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand(command_msg)); + + resumption_test::MockResumeCtrl mock_resume_ctrl; + ON_CALL(app_mngr_, resume_controller()) + .WillByDefault(ReturnRef(mock_resume_ctrl)); + EXPECT_CALL(mock_resume_ctrl, HandleOnTimeOut(kCorrelationId, kFunctionID)); + + command->onTimeOut(); +} + +TEST_F(HMISubscribeButtonRequestTest, + OnEvent_SuccessfulResponse_ButtonSubscribed) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][strings::button_name] = kCustomButtonName; + + SubscribeButtonRequestPtr command = + CreateCommand(command_msg); + + MessageSharedPtr event_msg = CreateCommandMsg(); + (*event_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + + Event event(kFunctionID); + event.set_smart_object(*event_msg); + + EXPECT_CALL(*mock_app_, SubscribeToButton(kMobileCustomButtonName)) + .WillOnce(Return(true)); + + command->on_event(event); +} + +TEST_F(HMISubscribeButtonRequestTest, + OnEvent_UnsuccessfulResponse_ButtonNotSubscribed) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][strings::button_name] = kCustomButtonName; + + SubscribeButtonRequestPtr command = + CreateCommand(command_msg); + + MessageSharedPtr event_msg = CreateCommandMsg(); + (*event_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::GENERIC_ERROR; + + Event event(kFunctionID); + event.set_smart_object(*event_msg); + + EXPECT_CALL(*mock_app_, SubscribeToButton(kMobileCustomButtonName)).Times(0); + + command->on_event(event); +} + +TEST_F(HMISubscribeButtonRequestTest, onEvent_App_NULL) { + MessageSharedPtr command_msg = CreateCommandMsg(); + SubscribeButtonRequestPtr command = + CreateCommand(command_msg); + + MessageSharedPtr event_msg = CreateCommandMsg(); + (*event_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + + Event event(kFunctionID); + event.set_smart_object(*event_msg); + + MockAppPtr mock_app = NULL; + EXPECT_CALL(app_mngr_, application_by_hmi_app(kAppId)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(*mock_app_, SubscribeToButton(kMobileButtonName)).Times(0); + + command->on_event(event); +} + +} // namespace subscribe_button_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/subscribe_button_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/subscribe_button_response_test.cc new file mode 100644 index 00000000000..ca4c2ee41bb --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/subscribe_button_response_test.cc @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2021, 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 + +#include "application_manager/mock_event_dispatcher.h" +#include "gtest/gtest.h" +#include "hmi/subscribe_button_response.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace subscribe_button_response { + +namespace am = ::application_manager; +using application_manager::ExpiredButtonRequestData; +using application_manager::commands::ResponseFromHMI; +using sdl_rpc_plugin::commands::hmi::SubscribeButtonResponse; +using ::test::components::event_engine_test::MockEventDispatcher; +typedef std::shared_ptr ResponseFromHMIPtr; + +namespace { +const uint32_t kCorrelationId = 2u; +const uint32_t kAppId = 1u; +const hmi_apis::Common_ButtonName::eType kButtonName = + hmi_apis::Common_ButtonName::SEEKLEFT; +const hmi_apis::FunctionID::eType kFunctionID = + hmi_apis::FunctionID::Buttons_UnsubscribeButton; +} // namespace + +class HMISubscribeButtonResponseTest + : public CommandsTest { + public: + HMISubscribeButtonResponseTest() { + ON_CALL(app_mngr_, event_dispatcher()) + .WillByDefault(ReturnRef(event_dispatcher_)); + } + + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::params][strings::correlation_id] = kCorrelationId; + (*command_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + + return command_msg; + } + + MockEventDispatcher event_dispatcher_; +}; + +TEST_F(HMISubscribeButtonResponseTest, + RUN_ProcessExpiredRequest_SendUnsubscribeRequestToHMI) { + MessageSharedPtr command_msg = CreateCommandMsg(); + ResponseFromHMIPtr command( + CreateCommand(command_msg)); + + ExpiredButtonRequestData expired_data; + expired_data.app_id_ = kAppId; + expired_data.button_name_ = kButtonName; + utils::Optional expired_data_opt = expired_data; + + ON_CALL(app_mngr_, GetExpiredButtonRequestData(kCorrelationId)) + .WillByDefault(Return(expired_data_opt)); + ON_CALL(mock_message_helper_, + CreateButtonSubscriptionHandlingRequestToHmi( + kAppId, kButtonName, kFunctionID, _)) + .WillByDefault(Return(command_msg)); + EXPECT_CALL(event_dispatcher_, raise_event(_)).Times(0); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + + command->Run(); +} + +TEST_F( + HMISubscribeButtonResponseTest, + RUN_ProcessUnsuccessfulExpiredRequest_EventNotRaisedUnsubscribeRequestNotSent) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::GENERIC_ERROR; + + ResponseFromHMIPtr command( + CreateCommand(command_msg)); + + ExpiredButtonRequestData expired_data; + expired_data.app_id_ = kAppId; + expired_data.button_name_ = kButtonName; + utils::Optional expired_data_opt = expired_data; + + ON_CALL(app_mngr_, GetExpiredButtonRequestData(kCorrelationId)) + .WillByDefault(Return(expired_data_opt)); + EXPECT_CALL(event_dispatcher_, raise_event(_)).Times(0); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)).Times(0); + + command->Run(); +} + +TEST_F(HMISubscribeButtonResponseTest, RUN_NoExpiredRequests_EventRaised) { + MessageSharedPtr command_msg = CreateCommandMsg(); + ResponseFromHMIPtr command( + CreateCommand(command_msg)); + + ON_CALL(app_mngr_, GetExpiredButtonRequestData(kCorrelationId)) + .WillByDefault(Return(utils::Optional::EMPTY)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)).Times(0); + EXPECT_CALL(event_dispatcher_, raise_event(_)); + + command->Run(); +} + +} // namespace subscribe_button_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/unsubscribe_button_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/unsubscribe_button_request_test.cc new file mode 100644 index 00000000000..3236987d141 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/unsubscribe_button_request_test.cc @@ -0,0 +1,180 @@ +/* + * Copyright (c) 2021, 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 "hmi/unsubscribe_button_request.h" + +#include +#include + +#include "application_manager/mock_event_dispatcher.h" +#include "gtest/gtest.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace unsubscribe_button_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = am::strings; +using am::commands::RequestToHMI; +using am::event_engine::Event; +using sdl_rpc_plugin::commands::hmi::UnsubscribeButtonRequest; +using ::test::components::application_manager_test::MockApplication; + +typedef std::shared_ptr MockAppPtr; +typedef std::shared_ptr RequestToHMIPtr; +typedef std::shared_ptr UnsubscribeButtonRequestPtr; + +namespace { +const uint32_t kCorrelationId = 2u; +const uint32_t kAppId = 1u; +const hmi_apis::Common_ButtonName::eType kButtonName = + hmi_apis::Common_ButtonName::CUSTOM_BUTTON; +const hmi_apis::FunctionID::eType kFunctionID = + hmi_apis::FunctionID::Buttons_UnsubscribeButton; +const mobile_apis::ButtonName::eType kMobileCustomButtonName = + mobile_apis::ButtonName::CUSTOM_BUTTON; +} // namespace + +class HMIUnsubscribeButtonRequestTest + : public CommandRequestTest { + protected: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::app_id] = kAppId; + (*command_msg)[strings::msg_params][strings::button_name] = kButtonName; + (*command_msg)[strings::params][strings::correlation_id] = kCorrelationId; + (*command_msg)[strings::params][strings::function_id] = kFunctionID; + + return command_msg; + } + + void InitCommand(const uint32_t& timeout) OVERRIDE { + mock_app_ = CreateMockApp(); + CommandRequestTest::InitCommand(timeout); + ON_CALL((*mock_app_), hmi_app_id()).WillByDefault(Return(kAppId)); + ON_CALL(app_mngr_, application_by_hmi_app(kAppId)) + .WillByDefault(Return(mock_app_)); + ON_CALL(app_mngr_, application(kAppId)).WillByDefault(Return(mock_app_)); + } + + MockAppPtr mock_app_; +}; + +TEST_F(HMIUnsubscribeButtonRequestTest, Run_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand(command_msg)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); +} + +TEST_F(HMIUnsubscribeButtonRequestTest, + onTimeOut_RequestIsExpired_HandleOnTimeout) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand(command_msg)); + + resumption_test::MockResumeCtrl mock_resume_ctrl; + ON_CALL(app_mngr_, resume_controller()) + .WillByDefault(ReturnRef(mock_resume_ctrl)); + EXPECT_CALL(mock_resume_ctrl, HandleOnTimeOut(_, _)); + + command->onTimeOut(); +} + +TEST_F(HMIUnsubscribeButtonRequestTest, + OnEvent_SuccessfulResponse_ButtonUnsubscribed) { + MessageSharedPtr command_msg = CreateCommandMsg(); + UnsubscribeButtonRequestPtr command = + CreateCommand(command_msg); + + MessageSharedPtr event_msg = CreateCommandMsg(); + (*event_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + Event event(kFunctionID); + event.set_smart_object(*event_msg); + + EXPECT_CALL(*mock_app_, UnsubscribeFromButton(kMobileCustomButtonName)) + .WillOnce(Return(true)); + + command->on_event(event); +} + +TEST_F(HMIUnsubscribeButtonRequestTest, + OnEvent_UnsuccessfulResponse_ButtonNotUnsubscribed) { + MessageSharedPtr command_msg = CreateCommandMsg(); + UnsubscribeButtonRequestPtr command = + CreateCommand(command_msg); + + MessageSharedPtr event_msg = CreateCommandMsg(); + (*event_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::GENERIC_ERROR; + Event event(kFunctionID); + event.set_smart_object(*event_msg); + + EXPECT_CALL(*mock_app_, UnsubscribeFromButton(kMobileCustomButtonName)) + .Times(0); + + command->on_event(event); +} + +TEST_F(HMIUnsubscribeButtonRequestTest, onEvent_App_NULL) { + MessageSharedPtr command_msg = CreateCommandMsg(); + UnsubscribeButtonRequestPtr command = + CreateCommand(command_msg); + + MessageSharedPtr event_msg = CreateCommandMsg(); + (*event_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + + Event event(kFunctionID); + event.set_smart_object(*event_msg); + + MockAppPtr mock_app = NULL; + EXPECT_CALL(app_mngr_, application_by_hmi_app(kAppId)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(*mock_app_, UnsubscribeFromButton(kMobileCustomButtonName)) + .Times(0); + + command->on_event(event); +} + +} // namespace unsubscribe_button_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/unsubscribe_button_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/unsubscribe_button_response_test.cc new file mode 100644 index 00000000000..3d9572a7431 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/unsubscribe_button_response_test.cc @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2021, 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 + +#include "application_manager/mock_event_dispatcher.h" +#include "gtest/gtest.h" +#include "hmi/unsubscribe_button_response.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace unsubscribe_button_response { + +namespace am = ::application_manager; +using application_manager::ExpiredButtonRequestData; +using application_manager::commands::ResponseFromHMI; +using sdl_rpc_plugin::commands::hmi::UnsubscribeButtonResponse; +using ::test::components::event_engine_test::MockEventDispatcher; +typedef std::shared_ptr ResponseFromHMIPtr; + +namespace { +const uint32_t kCorrelationId = 2u; +const uint32_t kAppId = 1u; +const hmi_apis::Common_ButtonName::eType kButtonName = + hmi_apis::Common_ButtonName::SEEKLEFT; +const hmi_apis::FunctionID::eType kFunctionID = + hmi_apis::FunctionID::Buttons_SubscribeButton; +} // namespace + +class HMIUnsubscribeButtonResponseTest + : public CommandsTest { + public: + HMIUnsubscribeButtonResponseTest() { + ON_CALL(app_mngr_, event_dispatcher()) + .WillByDefault(ReturnRef(event_dispatcher_)); + } + + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::params][strings::correlation_id] = kCorrelationId; + (*command_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + + return command_msg; + } + + MockEventDispatcher event_dispatcher_; +}; + +TEST_F(HMIUnsubscribeButtonResponseTest, + RUN_ProcessExpiredRequest_SendSubscribeRequestToHMI) { + MessageSharedPtr command_msg = CreateCommandMsg(); + + ResponseFromHMIPtr command( + CreateCommand(command_msg)); + + ExpiredButtonRequestData expired_data; + expired_data.app_id_ = kAppId; + expired_data.button_name_ = kButtonName; + utils::Optional expired_data_opt = expired_data; + + ON_CALL(app_mngr_, GetExpiredButtonRequestData(kCorrelationId)) + .WillByDefault(Return(expired_data_opt)); + ON_CALL(mock_message_helper_, + CreateButtonSubscriptionHandlingRequestToHmi( + kAppId, kButtonName, kFunctionID, _)) + .WillByDefault(Return(command_msg)); + EXPECT_CALL(event_dispatcher_, raise_event(_)).Times(0); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + + command->Run(); +} + +TEST_F( + HMIUnsubscribeButtonResponseTest, + RUN_ProcessUnsuccessfulExpiredRequest_EventNotRaisedSubscribeRequestNotSent) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::GENERIC_ERROR; + + ResponseFromHMIPtr command( + CreateCommand(command_msg)); + + ExpiredButtonRequestData expired_data; + expired_data.app_id_ = kAppId; + expired_data.button_name_ = kButtonName; + utils::Optional expired_data_opt = expired_data; + + ON_CALL(app_mngr_, GetExpiredButtonRequestData(kCorrelationId)) + .WillByDefault(Return(expired_data_opt)); + EXPECT_CALL(event_dispatcher_, raise_event(_)).Times(0); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)).Times(0); + + command->Run(); +} + +TEST_F(HMIUnsubscribeButtonResponseTest, RUN_NoExpiredRequests_EventRaised) { + MessageSharedPtr command_msg = CreateCommandMsg(); + ResponseFromHMIPtr command( + CreateCommand(command_msg)); + + ON_CALL(app_mngr_, GetExpiredButtonRequestData(kCorrelationId)) + .WillByDefault(Return(utils::Optional::EMPTY)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)).Times(0); + EXPECT_CALL(event_dispatcher_, raise_event(_)); + command->Run(); +} + +} // namespace unsubscribe_button_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_button_notification_commands_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_button_notification_commands_test.cc index e4536ddeea7..dbab9e18337 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_button_notification_commands_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_button_notification_commands_test.cc @@ -197,6 +197,9 @@ TYPED_TEST(OnButtonNotificationCommandsTest, typename TestFixture::MockAppPtr mock_app = this->CreateMockApp(); EXPECT_CALL(this->app_mngr_, application(kAppId)).WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, + IsSubscribedToButton(mobile_apis::ButtonName::CUSTOM_BUTTON)) + .WillOnce(Return(true)); EXPECT_CALL(*mock_app, IsSubscribedToSoftButton(kCustomButtonId)) .WillOnce(Return(false)); @@ -215,6 +218,13 @@ TYPED_TEST(OnButtonNotificationCommandsTest, Run_CustomButton_SUCCESS) { (*notification_msg)[am::strings::msg_params] [am::hmi_response::custom_button_id] = kCustomButtonId; + auto mock_message_helper = am::MockMessageHelper::message_helper_mock(); + smart_objects::SmartObjectSPtr msg = + std::make_shared(); + (*msg)[strings::params][strings::function_id] = TestFixture::kFunctionId; + EXPECT_CALL(*mock_message_helper, CreateButtonNotificationToMobile(_, _)) + .WillRepeatedly(Return(msg)); + std::shared_ptr command( this->template CreateCommand(notification_msg)); @@ -222,6 +232,9 @@ TYPED_TEST(OnButtonNotificationCommandsTest, Run_CustomButton_SUCCESS) { ON_CALL(*mock_app, hmi_level(kDefaultWindowId)) .WillByDefault(Return(mobile_apis::HMILevel::HMI_FULL)); EXPECT_CALL(this->app_mngr_, application(kAppId)).WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, + IsSubscribedToButton(mobile_apis::ButtonName::CUSTOM_BUTTON)) + .WillOnce(Return(true)); EXPECT_CALL(*mock_app, IsSubscribedToSoftButton(kCustomButtonId)) .WillOnce(Return(true)); EXPECT_CALL(this->mock_rpc_service_, @@ -244,18 +257,30 @@ TYPED_TEST(OnButtonNotificationCommandsTest, (*notification_msg)[am::strings::msg_params] [am::hmi_response::custom_button_id] = kCustomButtonId; + auto mock_message_helper = am::MockMessageHelper::message_helper_mock(); + smart_objects::SmartObjectSPtr msg = + std::make_shared(); + EXPECT_CALL(*mock_message_helper, CreateButtonNotificationToMobile(_, _)) + .WillRepeatedly(Return(msg)); + std::shared_ptr command( this->template CreateCommand(notification_msg)); typename TestFixture::MockAppPtr mock_app = this->CreateMockApp(); - ON_CALL(*mock_app, hmi_level(kDefaultWindowId)) - .WillByDefault(Return(mobile_apis::HMILevel::HMI_BACKGROUND)); + + EXPECT_CALL(*mock_app, GetSoftButtonWindowID(kCustomButtonId)) + .WillOnce(Return(kDefaultWindowId)); + + EXPECT_CALL(*mock_app, hmi_level(kDefaultWindowId)) + .WillOnce(Return(mobile_apis::HMILevel::HMI_BACKGROUND)); + EXPECT_CALL(this->app_mngr_, application(kAppId)).WillOnce(Return(mock_app)); + + EXPECT_CALL(*mock_app, + IsSubscribedToButton(mobile_apis::ButtonName::CUSTOM_BUTTON)) + .WillOnce(Return(true)); EXPECT_CALL(*mock_app, IsSubscribedToSoftButton(kCustomButtonId)) .WillOnce(Return(true)); - EXPECT_CALL(this->mock_rpc_service_, - SendMessageToMobile( - CheckNotificationMessage(TestFixture::kFunctionId), _)); command->Run(); } @@ -343,22 +368,27 @@ TYPED_TEST(OnButtonNotificationCommandsTest, Run_SUCCESS) { std::shared_ptr command( this->template CreateCommand(notification_msg)); - typename TestFixture::MockAppPtr mock_app = this->CreateMockApp(); - std::vector subscribed_apps_list; - subscribed_apps_list.push_back(mock_app); + auto mock_message_helper = am::MockMessageHelper::message_helper_mock(); + smart_objects::SmartObjectSPtr msg = + std::make_shared(); + (*msg)[strings::params][strings::function_id] = TestFixture::kFunctionId; + EXPECT_CALL(*mock_message_helper, CreateButtonNotificationToMobile(_, _)) + .WillRepeatedly(Return(msg)); + typename TestFixture::MockAppPtr mock_app = this->CreateMockApp(); + EXPECT_CALL(*mock_app, IsSubscribedToButton(kButtonName)) + .WillOnce(Return(true)); EXPECT_CALL(*mock_app, hmi_level(kDefaultWindowId)) .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_FULL)); ON_CALL(*mock_app, IsFullscreen()).WillByDefault(Return(true)); ON_CALL(this->app_mngr_, application(kAppId)).WillByDefault(Return(mock_app)); - EXPECT_CALL(this->app_mngr_, applications_by_button(kButtonName)) - .WillOnce(Return(subscribed_apps_list)); EXPECT_CALL(this->mock_rpc_service_, SendMessageToMobile( CheckNotificationMessage(TestFixture::kFunctionId), _)); + EXPECT_CALL(this->app_mngr_, application(kAppId)).WillOnce(Return(mock_app)); command->Run(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc index 99491873bea..5d940c4f4cc 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc @@ -289,8 +289,7 @@ class RegisterAppInterfaceRequestTest EXPECT_CALL( mock_rpc_service_, ManageHMICommand( - HMIResultCodeIs(hmi_apis::FunctionID::Buttons_OnButtonSubscription), - _)) + HMIResultCodeIs(hmi_apis::FunctionID::Buttons_SubscribeButton), _)) .Times(0); EXPECT_CALL( @@ -350,12 +349,6 @@ class RegisterAppInterfaceRequestTest hmi_apis::FunctionID::BasicCommunication_OnAppRegistered), _)) .WillByDefault(Return(true)); - ON_CALL( - mock_rpc_service_, - ManageHMICommand( - HMIResultCodeIs(hmi_apis::FunctionID::Buttons_OnButtonSubscription), - _)) - .WillByDefault(Return(true)); } void SetCommonPreconditionsToCheckWithPolicyData(MockAppPtr mock_app) { @@ -456,11 +449,22 @@ TEST_F(RegisterAppInterfaceRequestTest, Run_MinimalData_SUCCESS) { hmi_apis::FunctionID::BasicCommunication_OnAppRegistered), _)) .WillOnce(Return(true)); + + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState( + application_manager::HmiInterfaces::HMI_INTERFACE_Buttons)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::Buttons_SubscribeButton)) + .WillByDefault( + Return(application_manager::HmiInterfaces::HMI_INTERFACE_Buttons)); + EXPECT_CALL( mock_rpc_service_, ManageHMICommand( - HMIResultCodeIs(hmi_apis::FunctionID::Buttons_OnButtonSubscription), - _)) + HMIResultCodeIs(hmi_apis::FunctionID::Buttons_SubscribeButton), _)) .WillOnce(Return(true)); application_manager::DisplayCapabilitiesBuilder builder(*mock_app); @@ -583,8 +587,7 @@ TEST_F(RegisterAppInterfaceRequestTest, EXPECT_CALL( mock_rpc_service_, ManageHMICommand( - HMIResultCodeIs(hmi_apis::FunctionID::Buttons_OnButtonSubscription), - _)) + HMIResultCodeIs(hmi_apis::FunctionID::Buttons_SubscribeButton), _)) .WillOnce(Return(true)); EXPECT_CALL( mock_rpc_service_, @@ -848,8 +851,7 @@ TEST_F(RegisterAppInterfaceRequestTest, EXPECT_CALL( mock_rpc_service_, ManageHMICommand( - HMIResultCodeIs(hmi_apis::FunctionID::Buttons_OnButtonSubscription), - _)) + HMIResultCodeIs(hmi_apis::FunctionID::Buttons_SubscribeButton), _)) .WillOnce(Return(true)); EXPECT_CALL( mock_rpc_service_, diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/subscribe_button_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/subscribe_button_request_test.cc index f3bfe12ab13..56e07661847 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/subscribe_button_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/subscribe_button_request_test.cc @@ -202,22 +202,19 @@ TEST_F(SubscribeButtonRequestTest, Run_SUCCESS) { EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)) .WillOnce(DoAll(SaveArg<0>(&hmi_result_msg), Return(true))); - MessageSharedPtr mobile_result_msg; - EXPECT_CALL(this->mock_rpc_service_, ManageMobileCommand(_, _)) - .WillOnce(DoAll(SaveArg<0>(&mobile_result_msg), Return(true))); ASSERT_TRUE(command->Init()); command->Run(); - EXPECT_EQ(hmi_apis::FunctionID::Buttons_OnButtonSubscription, + EXPECT_EQ(hmi_apis::FunctionID::Buttons_SubscribeButton, static_cast( (*hmi_result_msg)[am::strings::params][am::strings::function_id] .asInt())); - EXPECT_EQ(mobile_apis::Result::SUCCESS, - static_cast( - (*mobile_result_msg)[am::strings::msg_params] - [am::strings::result_code] - .asInt())); + EXPECT_EQ( + hmi_apis::Common_ButtonName::eType::SEEKLEFT, + static_cast( + (*hmi_result_msg)[am::strings::msg_params][am::strings::button_name] + .asInt())); } TEST_F(SubscribeButtonRequestTest, Run_NAV_SUCCESS) { @@ -249,30 +246,30 @@ TEST_F(SubscribeButtonRequestTest, Run_NAV_SUCCESS) { EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)) .WillOnce(DoAll(SaveArg<0>(&hmi_result_msg), Return(true))); - MessageSharedPtr mobile_result_msg; - EXPECT_CALL(this->mock_rpc_service_, ManageMobileCommand(_, _)) - .WillOnce(DoAll(SaveArg<0>(&mobile_result_msg), Return(true))); ASSERT_TRUE(command->Init()); command->Run(); - EXPECT_EQ(hmi_apis::FunctionID::Buttons_OnButtonSubscription, + EXPECT_EQ(hmi_apis::FunctionID::Buttons_SubscribeButton, static_cast( (*hmi_result_msg)[am::strings::params][am::strings::function_id] .asInt())); - EXPECT_EQ(mobile_apis::Result::SUCCESS, - static_cast( - (*mobile_result_msg)[am::strings::msg_params] - [am::strings::result_code] - .asInt())); + EXPECT_EQ( + hmi_apis::Common_ButtonName::eType::NAV_CENTER_LOCATION, + static_cast( + (*hmi_result_msg)[am::strings::msg_params][am::strings::button_name] + .asInt())); } -TEST_F(SubscribeButtonRequestTest, Run_SUCCESS_App_Base_RPC_Version) { - const mobile_apis::ButtonName::eType kButtonName = - mobile_apis::ButtonName::OK; +TEST_F(SubscribeButtonRequestTest, + Run_App_Version_4_5_and_OK_btn_Expect_PlayPause_btn_sent_to_HMI) { + const mobile_apis::ButtonName::eType button_ok = mobile_apis::ButtonName::OK; - MessageSharedPtr msg(CreateMessage()); - (*msg)[am::strings::msg_params][am::strings::button_name] = kButtonName; + const mobile_apis::ButtonName::eType button_play_pause = + mobile_apis::ButtonName::PLAY_PAUSE; + + MessageSharedPtr msg(CreateMessage(smart_objects::SmartType_Map)); + (*msg)[am::strings::msg_params][am::strings::button_name] = button_ok; CommandPtr command(CreateCommand(msg)); MockAppPtr app(CreateMockApp()); @@ -284,41 +281,33 @@ TEST_F(SubscribeButtonRequestTest, Run_SUCCESS_App_Base_RPC_Version) { .WillByDefault(Return(true)); MessageSharedPtr button_caps_ptr(CreateMessage(smart_objects::SmartType_Map)); - (*button_caps_ptr)[0][am::hmi_response::button_name] = kButtonName; - (*button_caps_ptr)[1][am::hmi_response::button_name] = - mobile_apis::ButtonName::PLAY_PAUSE; + (*button_caps_ptr)[0][am::hmi_response::button_name] = button_ok; + (*button_caps_ptr)[1][am::hmi_response::button_name] = button_play_pause; ON_CALL(mock_hmi_capabilities_, button_capabilities()) .WillByDefault(Return(button_caps_ptr)); - ON_CALL(*app, IsSubscribedToButton(_)).WillByDefault(Return(false)); + ON_CALL(*app, IsSubscribedToButton(button_play_pause)) + .WillByDefault(Return(false)); MessageSharedPtr hmi_result_msg; EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)) .WillOnce(DoAll(SaveArg<0>(&hmi_result_msg), Return(true))); - MessageSharedPtr mobile_result_msg; - EXPECT_CALL(this->mock_rpc_service_, ManageMobileCommand(_, _)) - .WillOnce(DoAll(SaveArg<0>(&mobile_result_msg), Return(true))); ASSERT_TRUE(command->Init()); command->Run(); - EXPECT_EQ(hmi_apis::FunctionID::Buttons_OnButtonSubscription, + EXPECT_EQ(hmi_apis::FunctionID::Buttons_SubscribeButton, static_cast( (*hmi_result_msg)[am::strings::params][am::strings::function_id] .asInt())); - EXPECT_EQ(hmi_apis::Common_ButtonName::PLAY_PAUSE, - static_cast( - (*hmi_result_msg)[am::strings::msg_params][am::strings::name] - .asInt())); - - EXPECT_EQ(mobile_apis::Result::SUCCESS, - static_cast( - (*mobile_result_msg)[am::strings::msg_params] - [am::strings::result_code] - .asInt())); + EXPECT_EQ( + hmi_apis::Common_ButtonName::PLAY_PAUSE, + static_cast( + (*hmi_result_msg)[am::strings::msg_params][am::strings::button_name] + .asInt())); } } // namespace subscribe_button_request diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_button_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_button_request_test.cc index 5735610051e..15795fa1e6a 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_button_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_button_request_test.cc @@ -77,8 +77,6 @@ TEST_F(UnsubscribeButtonRequestTest, .WillOnce(Return(mock_app)); ON_CALL(*mock_app, msg_version()) .WillByDefault(ReturnRef(mock_semantic_version)); - EXPECT_CALL(*mock_app, UnsubscribeFromButton(kButtonId)) - .WillOnce(Return(false)); EXPECT_CALL( mock_rpc_service_, @@ -137,18 +135,6 @@ TEST_F(UnsubscribeButtonRequestTest, Run_SUCCESS) { ON_CALL(*mock_app, msg_version()) .WillByDefault(ReturnRef(mock_semantic_version)); - EXPECT_CALL(*mock_app, UnsubscribeFromButton(kButtonId)) - .WillOnce(Return(true)); - EXPECT_CALL( - mock_rpc_service_, - ManageHMICommand( - HMIResultCodeIs(hmi_apis::FunctionID::Buttons_OnButtonSubscription), - _)); - EXPECT_CALL( - mock_rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _)); - - EXPECT_CALL(*mock_app, UpdateHash()); command->Init(); command->Run(); } @@ -181,19 +167,6 @@ TEST_F(UnsubscribeButtonRequestTest, Run_SUCCESS_Base_RPC_Version) { .WillByDefault(ReturnRef(mock_base_rpc_version)); ON_CALL(*mock_app, is_media_application()).WillByDefault(Return(true)); - EXPECT_CALL(*mock_app, - UnsubscribeFromButton(mobile_apis::ButtonName::PLAY_PAUSE)) - .WillOnce(Return(true)); - EXPECT_CALL( - mock_rpc_service_, - ManageHMICommand( - HMIResultCodeIs(hmi_apis::FunctionID::Buttons_OnButtonSubscription), - _)); - EXPECT_CALL( - mock_rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _)); - - EXPECT_CALL(*mock_app, UpdateHash()); command->Init(); command->Run(); } diff --git a/src/components/application_manager/src/application_impl.cc b/src/components/application_manager/src/application_impl.cc index 2952fd54812..a53141b5bed 100644 --- a/src/components/application_manager/src/application_impl.cc +++ b/src/components/application_manager/src/application_impl.cc @@ -159,8 +159,7 @@ ApplicationImpl::ApplicationImpl( set_name(app_name); MarkUnregistered(); - // subscribe application to custom button by default - SubscribeToButton(mobile_apis::ButtonName::CUSTOM_BUTTON); + // load persistent files LoadPersistentFiles(); diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index e78d6ee668b..c3f3ef4bb36 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -3182,6 +3182,11 @@ void ApplicationManagerImpl::UnregisterAllApplications() { resume_controller().OnIgnitionOff(); } request_ctrl_->TerminateAllHMIRequests(); + + { + sync_primitives::AutoLock lock(expired_button_requests_lock_); + expired_button_requests_.clear(); + } } void ApplicationManagerImpl::RemoveAppsWaitingForRegistration( @@ -5024,4 +5029,36 @@ void ApplicationManagerImpl::ChangeAppsHMILevel( } } +void ApplicationManagerImpl::AddExpiredButtonRequest( + const uint32_t app_id, + const int32_t corr_id, + const hmi_apis::Common_ButtonName::eType button_name) { + SDL_LOG_AUTO_TRACE(); + + sync_primitives::AutoLock lock(expired_button_requests_lock_); + expired_button_requests_[corr_id] = {app_id, button_name}; +} + +utils::Optional +ApplicationManagerImpl::GetExpiredButtonRequestData( + const int32_t corr_id) const { + SDL_LOG_AUTO_TRACE(); + sync_primitives::AutoLock lock(expired_button_requests_lock_); + + auto found_subscription = expired_button_requests_.find(corr_id); + if (found_subscription == expired_button_requests_.end()) { + return utils::Optional::EMPTY; + } + + return utils::Optional(found_subscription->second); +} + +void ApplicationManagerImpl::DeleteExpiredButtonRequest(const int32_t corr_id) { + SDL_LOG_AUTO_TRACE(); + + sync_primitives::AutoLock lock(expired_button_requests_lock_); + auto found_subscription = expired_button_requests_.find(corr_id); + expired_button_requests_.erase(found_subscription); +} + } // namespace application_manager diff --git a/src/components/application_manager/src/commands/button_notification_to_mobile.cc b/src/components/application_manager/src/commands/button_notification_to_mobile.cc new file mode 100644 index 00000000000..a94f4ef6ab9 --- /dev/null +++ b/src/components/application_manager/src/commands/button_notification_to_mobile.cc @@ -0,0 +1,219 @@ +/* + * Copyright (c) 2021, 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 "application_manager/commands/button_notification_to_mobile.h" +#include "interfaces/MOBILE_API.h" +namespace application_manager { + +namespace commands { +namespace app_mngr = application_manager; + +SDL_CREATE_LOG_VARIABLE("ButtonNotificationToMobile") + +ButtonNotificationToMobile::ButtonNotificationToMobile( + 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) + : CommandNotificationImpl(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +ButtonNotificationToMobile::~ButtonNotificationToMobile() {} + +bool ButtonNotificationToMobile::DoesParamExist( + const std::string& param_name) const { + SDL_LOG_AUTO_TRACE(); + using namespace application_manager::strings; + return (*message_)[msg_params].keyExists(param_name); +} + +void ButtonNotificationToMobile::HandleCustomButton( + app_mngr::ApplicationSharedPtr app) { + SDL_LOG_AUTO_TRACE(); + using namespace application_manager::strings; + + if (!app) { + SDL_LOG_ERROR("Application doesn't exist."); + return; + } + + // custom_button_id is mandatory for CUSTOM_BUTTON notification + if (!DoesParamExist(hmi_response::custom_button_id)) { + SDL_LOG_ERROR( + "CUSTOM_BUTTON mobile notification without custom_button_id."); + return; + } + + if (!app->IsSubscribedToButton(mobile_apis::ButtonName::CUSTOM_BUTTON)) { + SDL_LOG_ERROR("Application " << app->app_id() + << " is not subscribed on custom buttons"); + return; + } + + const uint32_t custom_btn_id = + (*message_)[msg_params][hmi_response::custom_button_id].asUInt(); + + if (!app->IsSubscribedToSoftButton(custom_btn_id)) { + SDL_LOG_ERROR("Application doesn't subscribed to this custom_button_id."); + return; + } + + const auto window_id = app->GetSoftButtonWindowID(custom_btn_id); + (*message_)[strings::msg_params][strings::window_id] = window_id; + + if (mobile_api::HMILevel::HMI_NONE == app->hmi_level(window_id)) { + SDL_LOG_WARN("CUSTOM_BUTTON mobile notification is allowed only " + << "in FULL, LIMITED or BACKGROUND hmi level"); + return; + } + + SendButtonNotification(app); + return; +} + +void ButtonNotificationToMobile::HandleOKButton( + app_mngr::ApplicationSharedPtr app) { + SDL_LOG_AUTO_TRACE(); + using namespace application_manager; + SDL_LOG_DEBUG("OK button received"); + + if (app) { + const auto btn_id = static_cast( + (*message_)[strings::msg_params][hmi_response::button_name].asInt()); + + if (app->IsSubscribedToButton(btn_id)) { + SendButtonNotification(app); + } else { + SDL_LOG_ERROR("Application " << app->app_id() + << " is not subscribed to button " + << btn_id); + } + + return; + } + + const auto subscribed_apps = SubscribedApps(); + const auto app_ptr = + std::find_if(subscribed_apps.begin(), + subscribed_apps.end(), + [](const ApplicationSharedPtr subscribed_app) { + return subscribed_app->IsFullscreen(); + }); + + if (app_ptr != subscribed_apps.end()) { + SDL_LOG_DEBUG("Sending button press for app in FULL with app id: " + << (*app_ptr)->app_id()); + SendButtonNotification(*app_ptr); + } else { + SDL_LOG_ERROR("No application found"); + } +} + +std::vector ButtonNotificationToMobile::SubscribedApps() + const { + const uint32_t btn_id = static_cast( + (*message_)[strings::msg_params][hmi_response::button_name].asInt()); + return application_manager_.applications_by_button(btn_id); +} + +void ButtonNotificationToMobile::HandleMediaButton( + app_mngr::ApplicationSharedPtr app) { + SDL_LOG_AUTO_TRACE(); + using namespace application_manager; + + if (app) { + const auto btn_id = static_cast( + (*message_)[strings::msg_params][hmi_response::button_name].asInt()); + + if (app->IsSubscribedToButton(btn_id)) { + SendButtonNotification(app); + } else { + SDL_LOG_ERROR("Application " << app->app_id() + << " is not subscribed to button " + << btn_id); + } + + return; + } + + const auto subscribed_apps = SubscribedApps(); + const auto app_ptr = + std::find_if(subscribed_apps.begin(), + subscribed_apps.end(), + [](const ApplicationSharedPtr subscribed_app) { + return helpers::Compare( + subscribed_app->hmi_level( + mobile_apis::PredefinedWindows::DEFAULT_WINDOW), + mobile_api::HMILevel::HMI_FULL, + mobile_api::HMILevel::HMI_LIMITED); + }); + + if (app_ptr != subscribed_apps.end()) { + SendButtonNotification(*app_ptr); + } else { + SDL_LOG_ERROR("No application found"); + } +} + +void ButtonNotificationToMobile::Run() { + SDL_LOG_AUTO_TRACE(); + using namespace application_manager::strings; + + const uint32_t btn_id = static_cast( + (*message_)[msg_params][hmi_response::button_name].asInt()); + + SDL_LOG_DEBUG("Received button id: " << btn_id); + + ApplicationSharedPtr app; + + if (DoesParamExist(strings::app_id)) { + app = application_manager_.application( + (*message_)[msg_params][app_id].asUInt()); + } + + if (static_cast(mobile_apis::ButtonName::CUSTOM_BUTTON) == btn_id) { + HandleCustomButton(app); + } else if (static_cast(mobile_apis::ButtonName::OK) == btn_id) { + HandleOKButton(app); + } else { + HandleMediaButton(app); + } +} + +} // namespace commands +} // namespace application_manager diff --git a/src/components/application_manager/src/commands/command_impl.cc b/src/components/application_manager/src/commands/command_impl.cc index c6ad7b79c1c..8751823e859 100644 --- a/src/components/application_manager/src/commands/command_impl.cc +++ b/src/components/application_manager/src/commands/command_impl.cc @@ -71,6 +71,30 @@ namespace commands { SDL_CREATE_LOG_VARIABLE("Commands") +bool IsMobileResultSuccess(const mobile_apis::Result::eType result_code) { + using namespace helpers; + return Compare( + result_code, + mobile_apis::Result::SUCCESS, + mobile_apis::Result::WARNINGS, + mobile_apis::Result::WRONG_LANGUAGE, + mobile_apis::Result::RETRY, + mobile_apis::Result::SAVED, + mobile_apis::Result::TRUNCATED_DATA); +} + +bool IsHMIResultSuccess(const hmi_apis::Common_Result::eType result_code) { + using namespace helpers; + return Compare( + result_code, + hmi_apis::Common_Result::SUCCESS, + hmi_apis::Common_Result::WARNINGS, + hmi_apis::Common_Result::WRONG_LANGUAGE, + hmi_apis::Common_Result::RETRY, + hmi_apis::Common_Result::SAVED, + hmi_apis::Common_Result::TRUNCATED_DATA); +} + const int32_t CommandImpl::hmi_protocol_type_ = 1; const int32_t CommandImpl::mobile_protocol_type_ = 0; const int32_t CommandImpl::protocol_version_ = 3; @@ -545,5 +569,19 @@ bool CommandImpl::CheckSyntax(const std::string& str, return true; } +bool CommandImpl::IsHMIResultSuccess( + hmi_apis::Common_Result::eType result_code, + HmiInterfaces::InterfaceID interface) const { + SDL_LOG_AUTO_TRACE(); + if (application_manager::commands::IsHMIResultSuccess(result_code)) { + return true; + } + + const HmiInterfaces::InterfaceState state = + application_manager_.hmi_interfaces().GetInterfaceState(interface); + return hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == result_code && + HmiInterfaces::STATE_NOT_AVAILABLE != state; +} + } // namespace commands } // namespace application_manager diff --git a/src/components/application_manager/src/commands/command_request_impl.cc b/src/components/application_manager/src/commands/command_request_impl.cc index 3b0c6bf98c4..65fbf7e66f4 100644 --- a/src/components/application_manager/src/commands/command_request_impl.cc +++ b/src/components/application_manager/src/commands/command_request_impl.cc @@ -161,7 +161,7 @@ ResponseInfo::ResponseInfo(const hmi_apis::Common_Result::eType result, interface_state = application_manager.hmi_interfaces().GetInterfaceState(hmi_interface); - is_ok = CommandRequestImpl::IsHMIResultSuccess(result_code); + is_ok = IsHMIResultSuccess(result_code); is_not_used = hmi_apis::Common_Result::INVALID_ENUM == result_code; @@ -699,49 +699,11 @@ bool CommandRequestImpl::HasDisallowedParams() const { (!removed_parameters_permissions_.undefined_params.empty())); } -bool CommandRequestImpl::IsMobileResultSuccess( - const mobile_apis::Result::eType result_code) { - SDL_LOG_AUTO_TRACE(); - using namespace helpers; - return Compare( - result_code, - mobile_apis::Result::SUCCESS, - mobile_apis::Result::WARNINGS, - mobile_apis::Result::WRONG_LANGUAGE, - mobile_apis::Result::RETRY, - mobile_apis::Result::SAVED, - mobile_apis::Result::TRUNCATED_DATA); -} - -bool CommandRequestImpl::IsHMIResultSuccess( - const hmi_apis::Common_Result::eType result_code) { - SDL_LOG_AUTO_TRACE(); - using namespace helpers; - return Compare( - result_code, - hmi_apis::Common_Result::SUCCESS, - hmi_apis::Common_Result::WARNINGS, - hmi_apis::Common_Result::WRONG_LANGUAGE, - hmi_apis::Common_Result::RETRY, - hmi_apis::Common_Result::SAVED, - hmi_apis::Common_Result::TRUNCATED_DATA); -} - bool CommandRequestImpl::PrepareResultForMobileResponse( hmi_apis::Common_Result::eType result_code, HmiInterfaces::InterfaceID interface) const { SDL_LOG_AUTO_TRACE(); - if (IsHMIResultSuccess(result_code)) { - return true; - } - - const HmiInterfaces::InterfaceState state = - application_manager_.hmi_interfaces().GetInterfaceState(interface); - if ((hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == result_code) && - (HmiInterfaces::STATE_NOT_AVAILABLE != state)) { - return true; - } - return false; + return IsHMIResultSuccess(result_code, interface); } bool CommandRequestImpl::PrepareResultForMobileResponse( diff --git a/src/components/application_manager/src/commands/request_from_hmi.cc b/src/components/application_manager/src/commands/request_from_hmi.cc index 467001d8dbb..fca48854e23 100644 --- a/src/components/application_manager/src/commands/request_from_hmi.cc +++ b/src/components/application_manager/src/commands/request_from_hmi.cc @@ -143,43 +143,6 @@ void RequestFromHMI::FillCommonParametersOfSO( (message)[strings::params][strings::correlation_id] = correlation_id; } -bool RequestFromHMI::IsMobileResultSuccess( - mobile_apis::Result::eType result_code) const { - SDL_LOG_AUTO_TRACE(); - using namespace helpers; - return Compare( - result_code, - mobile_apis::Result::SUCCESS, - mobile_apis::Result::WARNINGS, - mobile_apis::Result::WRONG_LANGUAGE, - mobile_apis::Result::RETRY, - mobile_apis::Result::SAVED); -} - -bool RequestFromHMI::IsHMIResultSuccess( - hmi_apis::Common_Result::eType result_code, - HmiInterfaces::InterfaceID interface) const { - SDL_LOG_AUTO_TRACE(); - using namespace helpers; - if (Compare( - result_code, - hmi_apis::Common_Result::SUCCESS, - hmi_apis::Common_Result::WARNINGS, - hmi_apis::Common_Result::WRONG_LANGUAGE, - hmi_apis::Common_Result::RETRY, - hmi_apis::Common_Result::SAVED)) { - return true; - } - - const HmiInterfaces::InterfaceState state = - application_manager_.hmi_interfaces().GetInterfaceState(interface); - if ((hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == result_code) && - (HmiInterfaces::STATE_NOT_AVAILABLE != state)) { - return true; - } - return false; -} - void RequestFromHMI::SendProviderRequest( const mobile_apis::FunctionID::eType& mobile_function_id, const hmi_apis::FunctionID::eType& hmi_function_id, diff --git a/src/components/application_manager/src/commands/request_to_hmi.cc b/src/components/application_manager/src/commands/request_to_hmi.cc index 35ac71c8bd5..3c411b1605f 100644 --- a/src/components/application_manager/src/commands/request_to_hmi.cc +++ b/src/components/application_manager/src/commands/request_to_hmi.cc @@ -80,26 +80,6 @@ bool CheckAvailabilityHMIInterfaces(ApplicationManager& application_manager, return HmiInterfaces::STATE_NOT_AVAILABLE != state; } -bool IsResponseCodeSuccess( - const smart_objects::SmartObject& response_from_hmi) { - auto response_code = static_cast( - response_from_hmi[strings::params][hmi_response::code].asInt()); - - using helpers::Compare; - using helpers::EQ; - using helpers::ONE; - - const bool is_result_success = - Compare( - response_code, - hmi_apis::Common_Result::SUCCESS, - hmi_apis::Common_Result::WARNINGS, - hmi_apis::Common_Result::WRONG_LANGUAGE, - hmi_apis::Common_Result::RETRY, - hmi_apis::Common_Result::SAVED); - return is_result_success; -} - bool ChangeInterfaceState(ApplicationManager& application_manager, const smart_objects::SmartObject& response_from_hmi, HmiInterfaces::InterfaceID interface) { @@ -113,12 +93,14 @@ bool ChangeInterfaceState(ApplicationManager& application_manager, return false; } - // Process response with result - if (response_from_hmi[strings::params].keyExists(hmi_response::code) && - !IsResponseCodeSuccess(response_from_hmi)) { - application_manager.hmi_interfaces().SetInterfaceState( - interface, HmiInterfaces::STATE_NOT_AVAILABLE); - return false; + if (response_from_hmi[strings::params].keyExists(hmi_response::code)) { + auto response_code = static_cast( + response_from_hmi[strings::params][hmi_response::code].asInt()); + if (!IsHMIResultSuccess(response_code)) { + application_manager.hmi_interfaces().SetInterfaceState( + interface, HmiInterfaces::STATE_NOT_AVAILABLE); + return false; + } } application_manager.hmi_interfaces().SetInterfaceState( diff --git a/src/components/application_manager/src/helpers/application_helper.cc b/src/components/application_manager/src/helpers/application_helper.cc index 863d85a7f0b..09b8eed6fe7 100644 --- a/src/components/application_manager/src/helpers/application_helper.cc +++ b/src/components/application_manager/src/helpers/application_helper.cc @@ -95,13 +95,19 @@ void DeleteGlobalProperties(ApplicationSharedPtr app, void DeleteButtonSubscriptions(ApplicationSharedPtr app, ApplicationManager& app_manager) { ButtonSubscriptions buttons = app->SubscribedButtons().GetData(); - for (auto button : buttons) { - if (mobile_apis::ButtonName::CUSTOM_BUTTON == button) { + const auto hmi_button = + static_cast(button); + if (hmi_apis::Common_ButtonName::CUSTOM_BUTTON == hmi_button) { continue; } - MessageHelper::SendUnsubscribeButtonNotification(button, app, app_manager); - app->UnsubscribeFromButton(button); + smart_objects::SmartObjectSPtr unsubscribe_request = + MessageHelper::CreateButtonSubscriptionHandlingRequestToHmi( + app->app_id(), + hmi_button, + hmi_apis::FunctionID::Buttons_UnsubscribeButton, + app_manager); + app_manager.GetRPCService().ManageHMICommand(unsubscribe_request); } } diff --git a/src/components/application_manager/src/hmi_interfaces_impl.cc b/src/components/application_manager/src/hmi_interfaces_impl.cc index 7365e5e081e..205585959ba 100644 --- a/src/components/application_manager/src/hmi_interfaces_impl.cc +++ b/src/components/application_manager/src/hmi_interfaces_impl.cc @@ -43,8 +43,8 @@ generate_function_to_interface_convert_map() { convert_map[Buttons_GetCapabilities] = HmiInterfaces::HMI_INTERFACE_Buttons; convert_map[Buttons_OnButtonEvent] = HmiInterfaces::HMI_INTERFACE_Buttons; convert_map[Buttons_OnButtonPress] = HmiInterfaces::HMI_INTERFACE_Buttons; - convert_map[Buttons_OnButtonSubscription] = - HmiInterfaces::HMI_INTERFACE_Buttons; + convert_map[Buttons_SubscribeButton] = HmiInterfaces::HMI_INTERFACE_Buttons; + convert_map[Buttons_UnsubscribeButton] = HmiInterfaces::HMI_INTERFACE_Buttons; convert_map[BasicCommunication_OnReady] = HmiInterfaces::HMI_INTERFACE_BasicCommunication; convert_map[BasicCommunication_OnStartDeviceDiscovery] = diff --git a/src/components/application_manager/src/message_helper/message_helper.cc b/src/components/application_manager/src/message_helper/message_helper.cc index dde580adeba..decdabb55c9 100644 --- a/src/components/application_manager/src/message_helper/message_helper.cc +++ b/src/components/application_manager/src/message_helper/message_helper.cc @@ -819,31 +819,6 @@ void MessageHelper::SendResetPropertiesRequest(ApplicationSharedPtr application, } } -void MessageHelper::SendUnsubscribeButtonNotification( - mobile_apis::ButtonName::eType button, - ApplicationSharedPtr application, - ApplicationManager& app_mngr) { - using namespace smart_objects; - using namespace hmi_apis; - - SmartObject msg_params = SmartObject(SmartType_Map); - msg_params[strings::app_id] = application->app_id(); - msg_params[strings::name] = button; - msg_params[strings::is_suscribed] = false; - - SmartObjectSPtr message = CreateMessageForHMI( - hmi_apis::messageType::notification, app_mngr.GetNextHMICorrelationID()); - DCHECK(message); - - SmartObject& object = *message; - object[strings::params][strings::function_id] = - hmi_apis::FunctionID::Buttons_OnButtonSubscription; - - object[strings::msg_params] = msg_params; - - app_mngr.GetRPCService().ManageHMICommand(message); -} - const VehicleData& MessageHelper::vehicle_data() { return vehicle_data_; } @@ -1098,104 +1073,119 @@ smart_objects::SmartObjectSPtr MessageHelper::CreateSetAppIcon( return set_icon; } -void MessageHelper::SendOnButtonSubscriptionNotification( - uint32_t app_id, - hmi_apis::Common_ButtonName::eType button, - bool is_subscribed, - ApplicationManager& app_mngr) { - using namespace smart_objects; - using namespace hmi_apis; +smart_objects::SmartObjectSPtr MessageHelper::CreateButtonNotificationToMobile( + ApplicationSharedPtr app, + const smart_objects::SmartObject& source_message) { SDL_LOG_AUTO_TRACE(); - SmartObjectSPtr notification_ptr = - std::make_shared(SmartType_Map); - if (!notification_ptr) { - SDL_LOG_ERROR("Memory allocation failed."); - return; + if (!app) { + SDL_LOG_ERROR("application NULL pointer"); + return std::make_shared( + smart_objects::SmartType_Null); } - SmartObject& notification = *notification_ptr; - SmartObject msg_params = SmartObject(SmartType_Map); - msg_params[strings::app_id] = app_id; - msg_params[strings::name] = button; - msg_params[strings::is_suscribed] = is_subscribed; + smart_objects::SmartObjectSPtr msg = + std::make_shared( + smart_objects::SmartType_Map); - notification[strings::params][strings::message_type] = - static_cast(application_manager::MessageType::kNotification); - notification[strings::params][strings::protocol_version] = - commands::CommandImpl::protocol_version_; - notification[strings::params][strings::protocol_type] = - commands::CommandImpl::hmi_protocol_type_; - notification[strings::params][strings::function_id] = - hmi_apis::FunctionID::Buttons_OnButtonSubscription; - notification[strings::msg_params] = msg_params; + smart_objects::SmartObject& ref = *msg; + ref[strings::params][strings::connection_key] = app->app_id(); + + const auto function_id = static_cast( + source_message[strings::params][strings::function_id].asInt()); + ref[strings::params][strings::function_id] = function_id; + + mobile_apis::ButtonName::eType btn_id = mobile_apis::ButtonName::INVALID_ENUM; - if (!app_mngr.GetRPCService().ManageHMICommand(notification_ptr)) { - SDL_LOG_ERROR("Unable to send HMI notification"); + if (source_message[strings::msg_params].keyExists( + hmi_response::button_name)) { + btn_id = static_cast( + source_message[strings::msg_params][hmi_response::button_name].asInt()); + + } else if (source_message[strings::msg_params].keyExists( + strings::button_name)) { + btn_id = static_cast( + source_message[strings::msg_params][strings::button_name].asInt()); } -} -void MessageHelper::SendAllOnButtonSubscriptionNotificationsForApp( - ApplicationConstSharedPtr app, ApplicationManager& app_mngr) { - using namespace smart_objects; - using namespace hmi_apis; - using namespace mobile_apis; - SDL_LOG_AUTO_TRACE(); + if (btn_id == mobile_apis::ButtonName::PLAY_PAUSE && + app->msg_version() <= utils::base_rpc_version) { + btn_id = mobile_apis::ButtonName::OK; + } - if (app.use_count() == 0) { - SDL_LOG_ERROR("Invalid application pointer "); - return; + ref[strings::msg_params][strings::button_name] = btn_id; + + auto get_mode_code = [&source_message]( + const std::string& hmi_param_name, + const std::string& mobile_param_name) -> int64_t { + if (source_message[strings::msg_params].keyExists(hmi_param_name)) { + return source_message[strings::msg_params][hmi_param_name].asInt(); + } + + if (source_message[strings::msg_params].keyExists(mobile_param_name)) { + return source_message[strings::msg_params][mobile_param_name].asInt(); + } + + return -1; + }; + + if (mobile_apis::FunctionID::eType::OnButtonPressID == function_id) { + const auto press_mode = static_cast( + get_mode_code(hmi_response::button_mode, strings::button_press_mode)); + ref[strings::msg_params][strings::button_press_mode] = press_mode; } - const ButtonSubscriptions subscriptions = app->SubscribedButtons().GetData(); - ButtonSubscriptions::iterator it = subscriptions.begin(); - for (; subscriptions.end() != it; ++it) { - SendOnButtonSubscriptionNotification( - app->hmi_app_id(), - static_cast(*it), - true, - app_mngr); + if (mobile_apis::FunctionID::eType::OnButtonEventID == function_id) { + const auto press_mode = static_cast( + get_mode_code(hmi_response::button_mode, strings::button_event_mode)); + ref[strings::msg_params][strings::button_event_mode] = press_mode; } + + if (source_message[strings::msg_params].keyExists( + hmi_response::custom_button_id)) { + ref[strings::msg_params][strings::custom_button_id] = + source_message[strings::msg_params][strings::custom_button_id]; + } + + if (source_message[strings::msg_params].keyExists(strings::window_id)) { + ref[strings::msg_params][strings::window_id] = + source_message[strings::msg_params][strings::window_id]; + } + + return msg; } smart_objects::SmartObjectSPtr -MessageHelper::CreateOnButtonSubscriptionNotification( - uint32_t app_id, - hmi_apis::Common_ButtonName::eType button, - bool is_subscribed) { +MessageHelper::CreateButtonSubscriptionHandlingRequestToHmi( + const uint32_t app_id, + const hmi_apis::Common_ButtonName::eType button_name, + const hmi_apis::FunctionID::eType function_id, + application_manager::ApplicationManager& app_mngr) { using namespace smart_objects; - using namespace hmi_apis; SDL_LOG_AUTO_TRACE(); - SmartObjectSPtr notification_ptr = - std::make_shared(SmartType_Map); - SmartObject& notification = *notification_ptr; + + SmartObjectSPtr request_ptr = CreateMessageForHMI( + hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID()); + + SmartObject& request = *request_ptr; SmartObject msg_params = SmartObject(SmartType_Map); msg_params[strings::app_id] = app_id; - msg_params[strings::name] = button; - msg_params[strings::is_suscribed] = is_subscribed; - notification[strings::params][strings::message_type] = - static_cast(application_manager::MessageType::kNotification); - notification[strings::params][strings::protocol_version] = - commands::CommandImpl::protocol_version_; - notification[strings::params][strings::protocol_type] = - commands::CommandImpl::hmi_protocol_type_; - notification[strings::params][strings::function_id] = - hmi_apis::FunctionID::Buttons_OnButtonSubscription; - notification[strings::msg_params] = msg_params; - return notification_ptr; + msg_params[strings::button_name] = button_name; + request[strings::params][strings::function_id] = function_id; + request[strings::msg_params] = msg_params; + return request_ptr; } smart_objects::SmartObjectList -MessageHelper::CreateOnButtonSubscriptionNotificationsForApp( +MessageHelper::CreateButtonSubscriptionsHandlingRequestsList( ApplicationConstSharedPtr app, - ApplicationManager& app_mngr, - const ButtonSubscriptions& button_subscriptions) { - using namespace smart_objects; + const ButtonSubscriptions& button_subscriptions, + const hmi_apis::FunctionID::eType function_id, + ApplicationManager& app_mngr) { using namespace hmi_apis; - using namespace mobile_apis; SDL_LOG_AUTO_TRACE(); - SmartObjectList button_subscription_requests; + smart_objects::SmartObjectList button_subscription_requests; if (app.use_count() == 0) { SDL_LOG_ERROR("Invalid application pointer "); @@ -1207,7 +1197,8 @@ MessageHelper::CreateOnButtonSubscriptionNotificationsForApp( static_cast(it); button_subscription_requests.push_back( - CreateOnButtonSubscriptionNotification(app->hmi_app_id(), btn, true)); + CreateButtonSubscriptionHandlingRequestToHmi( + app->app_id(), btn, function_id, app_mngr)); } return button_subscription_requests; diff --git a/src/components/application_manager/src/resumption/resumption_data_processor_impl.cc b/src/components/application_manager/src/resumption/resumption_data_processor_impl.cc index 18b1f8a2a3b..598b7a6ccb2 100644 --- a/src/components/application_manager/src/resumption/resumption_data_processor_impl.cc +++ b/src/components/application_manager/src/resumption/resumption_data_processor_impl.cc @@ -162,6 +162,11 @@ void ResumptionDataProcessorImpl::ProcessResumptionStatus( CheckVehicleDataResponse(found_request.message, response, status); } + if (hmi_apis::FunctionID::Buttons_SubscribeButton == + found_request.request_id.function_id) { + ProcessSubscribeButtonResponse(app_id, found_request.message, response); + } + if (hmi_apis::FunctionID::UI_CreateWindow == found_request.request_id.function_id) { CheckCreateWindowResponse(found_request.message, response); @@ -857,6 +862,7 @@ void ResumptionDataProcessorImpl::AddButtonsSubscriptions( const smart_objects::SmartObject& subscriptions = saved_app[strings::application_subscriptions]; + ButtonSubscriptions button_subscriptions; if (subscriptions.keyExists(strings::application_buttons)) { const smart_objects::SmartObject& subscriptions_buttons = subscriptions[strings::application_buttons]; @@ -864,31 +870,20 @@ void ResumptionDataProcessorImpl::AddButtonsSubscriptions( for (size_t i = 0; i < subscriptions_buttons.length(); ++i) { btn = static_cast( (subscriptions_buttons[i]).asInt()); - application->SubscribeToButton(btn); + if (mobile_apis::ButtonName::CUSTOM_BUTTON != btn) { + button_subscriptions.insert(btn); + } } - ButtonSubscriptions button_subscriptions = - GetButtonSubscriptionsToResume(application); - ProcessMessagesToHMI( - MessageHelper::CreateOnButtonSubscriptionNotificationsForApp( - application, application_manager_, button_subscriptions)); + MessageHelper::CreateButtonSubscriptionsHandlingRequestsList( + application, + button_subscriptions, + hmi_apis::FunctionID::Buttons_SubscribeButton, + application_manager_)); } } -ButtonSubscriptions ResumptionDataProcessorImpl::GetButtonSubscriptionsToResume( - ApplicationSharedPtr application) const { - ButtonSubscriptions button_subscriptions = - application->SubscribedButtons().GetData(); - auto it = button_subscriptions.find(mobile_apis::ButtonName::CUSTOM_BUTTON); - - if (it != button_subscriptions.end()) { - button_subscriptions.erase(it); - } - - return button_subscriptions; -} - void ResumptionDataProcessorImpl::AddPluginsSubscriptions( ApplicationSharedPtr application, const smart_objects::SmartObject& saved_app) { @@ -916,11 +911,13 @@ void ResumptionDataProcessorImpl::DeleteButtonsSubscriptions( if (hmi_apis::Common_ButtonName::CUSTOM_BUTTON == hmi_btn) { continue; } - auto notification = MessageHelper::CreateOnButtonSubscriptionNotification( - application->hmi_app_id(), hmi_btn, false); - // is_subscribed = false - ProcessMessageToHMI(notification, false); - application->UnsubscribeFromButton(btn); + smart_objects::SmartObjectSPtr unsubscribe_request = + MessageHelper::CreateButtonSubscriptionHandlingRequestToHmi( + application->app_id(), + hmi_btn, + hmi_apis::FunctionID::Buttons_UnsubscribeButton, + application_manager_); + ProcessMessageToHMI(unsubscribe_request, false); } } @@ -1007,7 +1004,7 @@ bool IsResponseSuccessful(const smart_objects::SmartObject& response) { response[strings::params][application_manager::hmi_response::code] .asInt()); - return commands::CommandRequestImpl::IsHMIResultSuccess(result_code) || + return commands::IsHMIResultSuccess(result_code) || hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == result_code; } @@ -1046,6 +1043,26 @@ void ResumptionDataProcessorImpl::CheckVehicleDataResponse( } } +void ResumptionDataProcessorImpl::ProcessSubscribeButtonResponse( + const uint32_t app_id, + const smart_objects::SmartObject& request, + const smart_objects::SmartObject& response) { + SDL_LOG_AUTO_TRACE(); + if (!IsResponseSuccessful(response)) { + return; + } + + ApplicationSharedPtr app = application_manager_.application(app_id); + if (!app) { + SDL_LOG_ERROR("NULL pointer."); + return; + } + const mobile_apis::ButtonName::eType btn_id = + static_cast( + request[strings::msg_params][strings::button_name].asInt()); + app->SubscribeToButton(btn_id); +} + void ResumptionDataProcessorImpl::CheckModuleDataSubscription( const ns_smart_device_link::ns_smart_objects::SmartObject& request, const ns_smart_device_link::ns_smart_objects::SmartObject& response, diff --git a/src/components/application_manager/test/application_helper_test.cc b/src/components/application_manager/test/application_helper_test.cc index 5c6d3b22f61..1f1a76298c8 100644 --- a/src/components/application_manager/test/application_helper_test.cc +++ b/src/components/application_manager/test/application_helper_test.cc @@ -149,7 +149,6 @@ TEST_F(ApplicationHelperTest, RecallApplicationData_ExpectAppDataReset) { const uint32_t cmd_id = 1; const uint32_t menu_id = 2; const uint32_t choice_set_id = 3; - const mobile_apis::ButtonName::eType button = mobile_apis::ButtonName::AC; smart_objects::SmartObject cmd(smart_objects::SmartType_Map); cmd[strings::msg_params][strings::cmd_id] = cmd_id; @@ -163,8 +162,6 @@ TEST_F(ApplicationHelperTest, RecallApplicationData_ExpectAppDataReset) { app_impl_->AddSubMenu(menu_id, cmd[strings::menu_params]); app_impl_->AddChoiceSet(choice_set_id, cmd[strings::msg_params]); - EXPECT_TRUE(app_impl_->SubscribeToButton(button)); - const std::string some_string = "some_string"; smart_objects::SmartObject dummy_data = smart_objects::SmartObject(smart_objects::SmartType_String); @@ -191,7 +188,6 @@ TEST_F(ApplicationHelperTest, RecallApplicationData_ExpectAppDataReset) { EXPECT_TRUE(smart_objects::SmartType_Null != sub_menu1.getType()); const auto choice_set1 = app_impl_->FindChoiceSet(choice_set_id); EXPECT_TRUE(smart_objects::SmartType_Null != choice_set1.getType()); - EXPECT_TRUE(app_impl_->IsSubscribedToButton(button)); auto help_prompt = app_impl_->help_prompt(); EXPECT_TRUE(help_prompt->asString() == some_string); auto timeout_prompt = app_impl_->timeout_prompt(); @@ -227,7 +223,6 @@ TEST_F(ApplicationHelperTest, RecallApplicationData_ExpectAppDataReset) { EXPECT_TRUE(smart_objects::SmartType_Null == sub_menu2.getType()); const auto choice_set2 = app_impl_->FindChoiceSet(choice_set_id); EXPECT_TRUE(smart_objects::SmartType_Null == choice_set2.getType()); - EXPECT_FALSE(app_impl_->IsSubscribedToButton(button)); help_prompt = app_impl_->help_prompt(); EXPECT_FALSE(help_prompt->asString() == some_string); timeout_prompt = app_impl_->timeout_prompt(); @@ -261,7 +256,6 @@ TEST_F(ApplicationHelperTest, RecallApplicationData_ExpectHMICleanupRequests) { app_impl_->AddCommand(cmd_id, cmd[strings::msg_params]); app_impl_->AddSubMenu(menu_id, cmd[strings::menu_params]); app_impl_->AddChoiceSet(choice_set_id, cmd[strings::msg_params]); - app_impl_->SubscribeToButton(mobile_apis::ButtonName::AC); EXPECT_CALL(*mock_message_helper_, CreateDeleteUICommandRequest(_, _, _)) .WillOnce(Return(std::make_shared())); @@ -275,9 +269,6 @@ TEST_F(ApplicationHelperTest, RecallApplicationData_ExpectHMICleanupRequests) { EXPECT_CALL(*mock_message_helper_, SendResetPropertiesRequest(_, _)); - EXPECT_CALL(*mock_message_helper_, - SendUnsubscribeButtonNotification(_, _, _)); - // Act application_manager::DeleteApplicationData(app_impl_, app_manager_impl_); } diff --git a/src/components/application_manager/test/application_impl_test.cc b/src/components/application_manager/test/application_impl_test.cc index 5f23e973912..1e58ce86360 100644 --- a/src/components/application_manager/test/application_impl_test.cc +++ b/src/components/application_manager/test/application_impl_test.cc @@ -560,9 +560,9 @@ TEST_F(ApplicationImplTest, SubscribeToButton_UnsubscribeFromButton) { EXPECT_FALSE(app_impl->IsSubscribedToButton(ButtonName::PRESET_0)); } -TEST_F(ApplicationImplTest, SubscribeToDefaultButton_UnsubscribeFromButton) { - EXPECT_TRUE(app_impl->IsSubscribedToButton(ButtonName::CUSTOM_BUTTON)); - EXPECT_FALSE(app_impl->SubscribeToButton(ButtonName::CUSTOM_BUTTON)); +TEST_F(ApplicationImplTest, NotSubscribedToDefaultButton_SubscribeToButton) { + EXPECT_FALSE(app_impl->IsSubscribedToButton(ButtonName::CUSTOM_BUTTON)); + EXPECT_TRUE(app_impl->SubscribeToButton(ButtonName::CUSTOM_BUTTON)); } TEST_F(ApplicationImplTest, SubscribeToSoftButton_UnsubscribeFromSoftButton) { diff --git a/src/components/application_manager/test/include/application_manager/mock_message_helper.h b/src/components/application_manager/test/include/application_manager/mock_message_helper.h index 82a0574c7fb..9e69b0bcd6f 100644 --- a/src/components/application_manager/test/include/application_manager/mock_message_helper.h +++ b/src/components/application_manager/test/include/application_manager/mock_message_helper.h @@ -125,11 +125,12 @@ class MockMessageHelper { MOCK_METHOD2(CreateHMIStatusNotification, smart_objects::SmartObjectSPtr(ApplicationSharedPtr application, const WindowID window_id)); - MOCK_METHOD3(CreateOnButtonSubscriptionNotificationsForApp, + MOCK_METHOD4(CreateButtonSubscriptionsHandlingRequestsList, smart_objects::SmartObjectList( ApplicationConstSharedPtr application, - ApplicationManager& app_mngr, - const ButtonSubscriptions& button_subscriptions)); + const ButtonSubscriptions& button_subscriptions, + const hmi_apis::FunctionID::eType function_id, + ApplicationManager& app_mngr)); MOCK_METHOD4(SendPolicyUpdate, void(const std::string& file_path, const uint32_t timeout, @@ -172,9 +173,6 @@ class MockMessageHelper { MOCK_METHOD2(CreateModuleInfoSO, smart_objects::SmartObjectSPtr(uint32_t function_id, ApplicationManager& app_mngr)); - MOCK_METHOD2(SendAllOnButtonSubscriptionNotificationsForApp, - void(ApplicationConstSharedPtr app, - ApplicationManager& app_mngr)); MOCK_METHOD2(CreateUIResetGlobalPropertiesRequest, smart_objects::SmartObjectSPtr( const ResetGlobalPropertiesResult& reset_result, @@ -196,11 +194,18 @@ class MockMessageHelper { MOCK_METHOD1(CreateSubscribeWayPointsMessageToHMI, smart_objects::SmartObjectSPtr(const uint32_t correlation_id)); - MOCK_METHOD3( - CreateOnButtonSubscriptionNotification, - smart_objects::SmartObjectSPtr(uint32_t app_id, - hmi_apis::Common_ButtonName::eType button, - bool is_subscribed)); + MOCK_METHOD4(CreateButtonSubscriptionHandlingRequestToHmi, + smart_objects::SmartObjectSPtr( + const uint32_t app_id, + const hmi_apis::Common_ButtonName::eType button_name, + const hmi_apis::FunctionID::eType function_id, + application_manager::ApplicationManager& app_mngr)); + + MOCK_METHOD2(CreateButtonNotificationToMobile, + smart_objects::SmartObjectSPtr( + ApplicationSharedPtr app, + const smart_objects::SmartObject& source_message)); + MOCK_METHOD2(SendOnResumeAudioSourceToHMI, void(uint32_t app_id, ApplicationManager& app_mngr)); MOCK_METHOD2(CreateAddSubMenuRequestsToHMI, @@ -352,10 +357,6 @@ class MockMessageHelper { MOCK_METHOD2(SendResetPropertiesRequest, void(ApplicationSharedPtr application, ApplicationManager& app_mngr)); - MOCK_METHOD3(SendUnsubscribeButtonNotification, - void(mobile_apis::ButtonName::eType button, - ApplicationSharedPtr application, - ApplicationManager& app_mngr)); MOCK_METHOD1(CreateAppServiceCapabilities, smart_objects::SmartObject( std::vector& all_services)); diff --git a/src/components/application_manager/test/mock_message_helper.cc b/src/components/application_manager/test/mock_message_helper.cc index 3cab2be0fb5..02cf70e3ba3 100644 --- a/src/components/application_manager/test/mock_message_helper.cc +++ b/src/components/application_manager/test/mock_message_helper.cc @@ -269,11 +269,6 @@ MockMessageHelper* MockMessageHelper::message_helper_mock() { static ::testing::NiceMock message_helper_mock; return &message_helper_mock; } -void MessageHelper::SendAllOnButtonSubscriptionNotificationsForApp( - ApplicationConstSharedPtr app, ApplicationManager& app_mngr) { - MockMessageHelper::message_helper_mock() - ->SendAllOnButtonSubscriptionNotificationsForApp(app, app_mngr); -} void MessageHelper::SendOnResumeAudioSourceToHMI(const uint32_t app_id, ApplicationManager& app_mngr) { @@ -600,30 +595,32 @@ MessageHelper::CreateGlobalPropertiesRequestsToHMI( } smart_objects::SmartObjectSPtr -MessageHelper::CreateOnButtonSubscriptionNotification( - uint32_t app_id, - hmi_apis::Common_ButtonName::eType button, - bool is_subscribed) { +MessageHelper::CreateButtonSubscriptionHandlingRequestToHmi( + const uint32_t app_id, + const hmi_apis::Common_ButtonName::eType button_name, + const hmi_apis::FunctionID::eType function_id, + ApplicationManager& app_mngr) { return MockMessageHelper::message_helper_mock() - ->CreateOnButtonSubscriptionNotification(app_id, button, is_subscribed); + ->CreateButtonSubscriptionHandlingRequestToHmi( + app_id, button_name, function_id, app_mngr); } -smart_objects::SmartObjectList -MessageHelper::CreateOnButtonSubscriptionNotificationsForApp( - ApplicationConstSharedPtr application, - ApplicationManager& app_mngr, - const ButtonSubscriptions& button_subscriptions) { +smart_objects::SmartObjectSPtr MessageHelper::CreateButtonNotificationToMobile( + ApplicationSharedPtr app, + const smart_objects::SmartObject& source_message) { return MockMessageHelper::message_helper_mock() - ->CreateOnButtonSubscriptionNotificationsForApp( - application, app_mngr, button_subscriptions); + ->CreateButtonNotificationToMobile(app, source_message); } -void MessageHelper::SendUnsubscribeButtonNotification( - mobile_apis::ButtonName::eType button, - ApplicationSharedPtr application, +smart_objects::SmartObjectList +MessageHelper::CreateButtonSubscriptionsHandlingRequestsList( + ApplicationConstSharedPtr app, + const ButtonSubscriptions& button_subscriptions, + const hmi_apis::FunctionID::eType function_id, ApplicationManager& app_mngr) { return MockMessageHelper::message_helper_mock() - ->SendUnsubscribeButtonNotification(button, application, app_mngr); + ->CreateButtonSubscriptionsHandlingRequestsList( + app, button_subscriptions, function_id, app_mngr); } smart_objects::SmartObject MessageHelper::CreateAppServiceCapabilities( diff --git a/src/components/application_manager/test/resumption/resume_ctrl_test.cc b/src/components/application_manager/test/resumption/resume_ctrl_test.cc index f5ccd99ee0a..1ff04c332c3 100644 --- a/src/components/application_manager/test/resumption/resume_ctrl_test.cc +++ b/src/components/application_manager/test/resumption/resume_ctrl_test.cc @@ -604,19 +604,13 @@ TEST_F(ResumeCtrlTest, StartResumption_AppWithSubscribeOnButtons) { ON_CALL(*mock_app_, SubscribedButtons()) .WillByDefault(Return(button_subscription_accessor)); - smart_objects::SmartObjectList button_subscription_notifications; + smart_objects::SmartObjectList button_subscription_requests_list; ON_CALL(*application_manager::MockMessageHelper::message_helper_mock(), - CreateOnButtonSubscriptionNotificationsForApp(_, _, _)) - .WillByDefault(Return(button_subscription_notifications)); + CreateButtonSubscriptionsHandlingRequestsList(_, _, _, _)) + .WillByDefault(Return(button_subscription_requests_list)); EXPECT_CALL(*mock_app_, set_grammar_id(kTestGrammarId_)); - for (uint32_t i = 0; i < count_of_buttons; ++i) { - EXPECT_CALL( - *mock_app_, - SubscribeToButton(static_cast(i))); - } - std::list extensions; extensions.insert(extensions.begin(), mock_app_extension_); @@ -624,7 +618,7 @@ TEST_F(ResumeCtrlTest, StartResumption_AppWithSubscribeOnButtons) { EXPECT_CALL(*mock_app_extension_, ProcessResumption(saved_app)); EXPECT_CALL(*application_manager::MockMessageHelper::message_helper_mock(), - CreateOnButtonSubscriptionNotificationsForApp(_, _, _)); + CreateButtonSubscriptionsHandlingRequestsList(_, _, _, _)); const bool res = res_ctrl_->StartResumption(mock_app_, kHash_, callback_); EXPECT_TRUE(res); diff --git a/src/components/include/application_manager/application_manager.h b/src/components/include/application_manager/application_manager.h index 708bf8b0480..72a322f3367 100644 --- a/src/components/include/application_manager/application_manager.h +++ b/src/components/include/application_manager/application_manager.h @@ -119,6 +119,11 @@ struct ApplicationsPolicyAppIdSorter { } }; +struct ExpiredButtonRequestData { + uint32_t app_id_; + hmi_apis::Common_ButtonName::eType button_name_; +}; + typedef std::set ApplicationSet; typedef std::set @@ -947,6 +952,35 @@ class ApplicationManager { */ virtual bool UnsubscribeAppFromSoftButtons( const commands::MessageSharedPtr response_message) = 0; + + /** + * @brief Save subscribe/unsubscribe button request after timeout to ensure + * possibility to align mobile subscription/unsubscription status with actual + * subscription/unsubscription status on HMI + * @param app_id Application id from request message + * @param corr_id Correlation id + * @param button_name name of button to subscribe/unsubscribe + */ + virtual void AddExpiredButtonRequest( + const uint32_t app_id, + const int32_t corr_id, + const hmi_apis::Common_ButtonName::eType button_name) = 0; + + /** + * @brief Return optional structure with information regarding + * subscribe/unsubscribe button request data + * @param corr_id Correlation id + * @return optional structure with subscribe/unsubscribe button request data + */ + virtual utils::Optional GetExpiredButtonRequestData( + const int32_t corr_id) const = 0; + + /** + * @brief Delete data about already processed expired subscribe/unsubscribe + * button request in case if HMI send response to expired request + * @param corr_id Correlation id + */ + virtual void DeleteExpiredButtonRequest(const int32_t corr_id) = 0; }; } // namespace application_manager diff --git a/src/components/include/test/application_manager/mock_application_manager.h b/src/components/include/test/application_manager/mock_application_manager.h index 525197cb499..116d758ec40 100644 --- a/src/components/include/test/application_manager/mock_application_manager.h +++ b/src/components/include/test/application_manager/mock_application_manager.h @@ -396,6 +396,15 @@ class MockApplicationManager : public application_manager::ApplicationManager { MOCK_CONST_METHOD0(GetCommandFactory, application_manager::CommandFactory&()); MOCK_CONST_METHOD0(get_current_audio_source, uint32_t()); MOCK_METHOD1(set_current_audio_source, void(const uint32_t)); + MOCK_METHOD3(AddExpiredButtonRequest, + void(const uint32_t app_id, + const int32_t corr_id, + const hmi_apis::Common_ButtonName::eType button_name)); + MOCK_CONST_METHOD1( + GetExpiredButtonRequestData, + utils::Optional( + const int32_t corr_id)); + MOCK_METHOD1(DeleteExpiredButtonRequest, void(const int32_t corr_id)); }; } // namespace application_manager_test diff --git a/src/components/interfaces/HMI_API.xml b/src/components/interfaces/HMI_API.xml index 9b09f239fe1..f5a8ce163de 100644 --- a/src/components/interfaces/HMI_API.xml +++ b/src/components/interfaces/HMI_API.xml @@ -4546,24 +4546,30 @@ - + - Sender: SDL->HMI. Purpose: to notify about button subscription state is changed for the named application + Subscribes to buttons. - - - - Defines whether the named button has status of 'subscribed' or 'unsubscribed': - If "true" - the named button is subscribed. - If "false" - the named button is unsubscribed. - + + The ID of the application requesting this button subscription. + + Name of the button to subscribe. + + + + + + Unsubscribes from buttons. + - - The ID of application that relates to this button-subscription status change. - + The ID of the application requesting this button unsubscription. + + + Name of the button to unsubscribe from. + From 04c02ecf27fbc82060adb9dfc57ea00b8e52a481 Mon Sep 17 00:00:00 2001 From: Collin Date: Thu, 12 Aug 2021 17:19:43 -0400 Subject: [PATCH 14/14] IsHMIResultSuccess was moved (#3754) --- .../src/commands/mobile/delete_sub_menu_request.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_sub_menu_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_sub_menu_request.cc index 49e76ae327b..09346dc20a0 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_sub_menu_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_sub_menu_request.cc @@ -230,7 +230,7 @@ void DeleteSubMenuRequest::on_event(const event_engine::Event& event) { return; } - if (IsHMIResultSuccess(result_code)) { + if (application_manager::commands::IsHMIResultSuccess(result_code)) { const auto cmd_id = msg_params[strings::cmd_id].asUInt(); SDL_LOG_DEBUG("Removing UI Command: " << cmd_id); app->RemoveCommand(cmd_id); @@ -279,7 +279,7 @@ void DeleteSubMenuRequest::on_event(const event_engine::Event& event) { return; } - if (IsHMIResultSuccess(result_code)) { + if (application_manager::commands::IsHMIResultSuccess(result_code)) { const auto menu_id = msg_params[strings::menu_id].asUInt(); SDL_LOG_DEBUG("Removing submenuID: " << menu_id); app->RemoveSubMenu(menu_id);