diff options
author | mked-luxoft <mked@luxoft.com> | 2019-08-08 23:20:34 +0300 |
---|---|---|
committer | Andriy Byzhynar (GitHub) <AByzhynar@luxoft.com> | 2019-08-20 21:17:13 +0300 |
commit | e96730b471a19d43d5de333de0e5c6af6db2e70a (patch) | |
tree | d32642f57040c98c9fb33bc9ed6166da5540fdf2 | |
parent | 304aa9aad5834b6fdcca03f7d372ad6e26e98cc0 (diff) | |
download | sdl_core-e96730b471a19d43d5de333de0e5c6af6db2e70a.tar.gz |
Check hmi level of relevant window on button notifications
13 files changed, 132 insertions, 19 deletions
diff --git a/src/components/application_manager/include/application_manager/application.h b/src/components/application_manager/include/application_manager/application.h index df6449aa41..eaea69f2c9 100644 --- a/src/components/application_manager/include/application_manager/application.h +++ b/src/components/application_manager/include/application_manager/application.h @@ -170,7 +170,7 @@ typedef std::map<uint32_t, PerformChoice> PerformChoiceSetMap; /** * @brief Defines id of SoftButton */ -typedef std::set<uint32_t> SoftButtonID; +typedef std::set<std::pair<uint32_t, WindowID> > SoftButtonID; /** * @brief Defines set of buttons subscription @@ -919,6 +919,13 @@ class Application : public virtual InitialApplicationData, const SoftButtonID& softbuttons_id) = 0; /** + * @brief Retreives window id on which given button is created + * @param button_id identifier of a button + * @param window id of a widget containing button + */ + virtual WindowID GetSoftButtonWindowID(const uint32_t button_id) = 0; + + /** * @brief Determine the existence of softbutton * @param Softbutton_id contains id of softbutton * @return Returns true if application contains softbutton id otherwise diff --git a/src/components/application_manager/include/application_manager/application_impl.h b/src/components/application_manager/include/application_manager/application_impl.h index 2d9ff2b9c5..1d8f582012 100644 --- a/src/components/application_manager/include/application_manager/application_impl.h +++ b/src/components/application_manager/include/application_manager/application_impl.h @@ -231,6 +231,8 @@ class ApplicationImpl : public virtual Application, bool IsSubscribedToButton(mobile_apis::ButtonName::eType btn_name); bool UnsubscribeFromButton(mobile_apis::ButtonName::eType btn_name); + WindowID GetSoftButtonWindowID(const uint32_t button_id) OVERRIDE; + inline bool IsRegistered() const OVERRIDE; /** 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 db7b39dfe4..44046be523 100644 --- a/src/components/application_manager/include/application_manager/message_helper.h +++ b/src/components/application_manager/include/application_manager/message_helper.h @@ -720,6 +720,23 @@ class MessageHelper { * @param app current application * * @param function_id Unique command id from mobile API + * + * @param window_id window id containing soft buttons + */ + static void SubscribeApplicationToSoftButton( + smart_objects::SmartObject& message_params, + ApplicationSharedPtr app, + int32_t function_id, + const WindowID window_id); + + /* + * @brief subscribe application to softbutton + * + * @param message_params contains data of request + * + * @param app current application + * + * @param function_id Unique command id from mobile API */ static void SubscribeApplicationToSoftButton( smart_objects::SmartObject& message_params, 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 a3a77cd4e2..0bf9b40cb6 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 @@ -102,10 +102,11 @@ void OnButtonEventNotification::Run() { return; } - const mobile_apis::HMILevel::eType app_hmi_level = - 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)) { + 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_FULL != window_hmi_level) && + (mobile_api::HMILevel::HMI_LIMITED != window_hmi_level)) { LOG4CXX_WARN(logger_, "CUSTOM_BUTTON OnButtonEvent notification is allowed only " << "in FULL or LIMITED hmi level"); @@ -184,6 +185,11 @@ void OnButtonEventNotification::SendButtonEvent(ApplicationConstSharedPtr app) { (*message_)[strings::msg_params][strings::custom_button_id]; } + 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_ = 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 f0083586e9..8c22844865 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 @@ -104,10 +104,12 @@ void OnButtonPressNotification::Run() { } // Send ButtonPress notification only in HMI_FULL or HMI_LIMITED mode - const mobile_apis::HMILevel::eType app_hmi_level = - 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)) { + 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_FULL != window_hmi_level) && + (mobile_api::HMILevel::HMI_LIMITED != window_hmi_level)) { LOG4CXX_WARN(logger_, "CUSTOM_BUTTON OnButtonPress notification is allowed only " << "in FULL or LIMITED hmi level"); @@ -192,6 +194,11 @@ void OnButtonPressNotification::SendButtonPress(ApplicationConstSharedPtr app) { (*message_)[strings::msg_params][strings::custom_button_id]; } + 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_ = on_btn_press; SendNotification(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/show_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/show_request.cc index dea2255304..b62a88d7f2 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/show_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/show_request.cc @@ -408,7 +408,7 @@ void ShowRequest::Run() { app->UnsubscribeFromSoftButtons(function_id()); } else { MessageHelper::SubscribeApplicationToSoftButton( - (*message_)[strings::msg_params], app, function_id()); + (*message_)[strings::msg_params], app, function_id(), window_id()); } } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/show_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/show_test.cc index f4648c8f5a..b8cfdd4bfc 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/show_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/show_test.cc @@ -77,6 +77,8 @@ const rgb_color_scheme kCurrentDayColorRGB = {75, 75, 75}; const rgb_color_scheme kCurrentNightColorRGB = {200, 200, 200}; const rgb_color_scheme kNewDayColorRGB = {80, 80, 80}; const rgb_color_scheme kNewNightColorRGB = {222, 222, 222}; +const am::WindowID kDefaultWindowId = + mobile_apis::PredefinedWindows::DEFAULT_WINDOW; } // namespace MATCHER_P2(CheckMessageToMobile, result_code, success, "") { @@ -383,9 +385,9 @@ TEST_F(ShowRequestTest, Run_SoftButtonExists_SUCCESS) { msg_params[am::hmi_request::show_strings] = smart_objects::SmartObject(smart_objects::SmartType_Array); - EXPECT_CALL( - mock_message_helper_, - SubscribeApplicationToSoftButton(creation_msg_params, _, kFunctionID)); + EXPECT_CALL(mock_message_helper_, + SubscribeApplicationToSoftButton( + creation_msg_params, _, kFunctionID, kDefaultWindowId)); EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)); EXPECT_CALL(*mock_app_, set_show_command(msg_params)); @@ -433,7 +435,8 @@ TEST_F(ShowRequestTest, Run_SoftButtonExists_Canceled) { EXPECT_CALL(*mock_app_, app_id()).Times(0); - EXPECT_CALL(mock_message_helper_, SubscribeApplicationToSoftButton(_, _, _)) + EXPECT_CALL(mock_message_helper_, + SubscribeApplicationToSoftButton(_, _, _, kDefaultWindowId)) .Times(0); EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)).Times(0); EXPECT_CALL(*mock_app_, set_show_command(_)).Times(0); diff --git a/src/components/application_manager/src/application_impl.cc b/src/components/application_manager/src/application_impl.cc index 92509aa704..f498ab321a 100644 --- a/src/components/application_manager/src/application_impl.cc +++ b/src/components/application_manager/src/application_impl.cc @@ -1116,21 +1116,58 @@ void ApplicationImpl::SubscribeToSoftButtons( cmd_softbuttonid_[cmd_id] = softbuttons_id; } } else { - cmd_softbuttonid_[cmd_id] = softbuttons_id; + auto& soft_button_ids = cmd_softbuttonid_[cmd_id]; + for (auto& softbutton_item : softbuttons_id) { + soft_button_ids.insert(softbutton_item); + } } } +struct FindSoftButtonId { + uint32_t soft_button_id_; + + FindSoftButtonId(const uint32_t soft_button_id) + : soft_button_id_(soft_button_id) {} + + bool operator()(const std::pair<uint32_t, WindowID>& element) { + return soft_button_id_ == element.first; + } +}; + bool ApplicationImpl::IsSubscribedToSoftButton(const uint32_t softbutton_id) { + LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock lock(cmd_softbuttonid_lock_); CommandSoftButtonID::iterator it = cmd_softbuttonid_.begin(); for (; it != cmd_softbuttonid_.end(); ++it) { - if ((it->second).find(softbutton_id) != (it->second).end()) { + const auto& soft_button_ids = (*it).second; + FindSoftButtonId finder(softbutton_id); + const auto find_res = + std::find_if(soft_button_ids.begin(), soft_button_ids.end(), finder); + if ((soft_button_ids.end() != find_res)) { return true; } } return false; } +WindowID ApplicationImpl::GetSoftButtonWindowID(const uint32_t softbutton_id) { + LOG4CXX_AUTO_TRACE(logger_); + + sync_primitives::AutoLock lock(cmd_softbuttonid_lock_); + CommandSoftButtonID::iterator it = cmd_softbuttonid_.begin(); + for (; it != cmd_softbuttonid_.end(); ++it) { + const auto& soft_button_ids = (*it).second; + FindSoftButtonId finder(softbutton_id); + const auto find_res = + std::find_if(soft_button_ids.begin(), soft_button_ids.end(), finder); + if ((soft_button_ids.end() != find_res)) { + return find_res->second; + } + } + + return mobile_apis::PredefinedWindows::DEFAULT_WINDOW; +} + void ApplicationImpl::UnsubscribeFromSoftButtons(int32_t cmd_id) { sync_primitives::AutoLock lock(cmd_softbuttonid_lock_); CommandSoftButtonID::iterator it = cmd_softbuttonid_.find(cmd_id); 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 adafc47e15..0b1ac9b47a 100644 --- a/src/components/application_manager/src/message_helper/message_helper.cc +++ b/src/components/application_manager/src/message_helper/message_helper.cc @@ -3106,17 +3106,32 @@ mobile_apis::Result::eType MessageHelper::ProcessSoftButtons( void MessageHelper::SubscribeApplicationToSoftButton( smart_objects::SmartObject& message_params, ApplicationSharedPtr app, - int32_t function_id) { + int32_t function_id, + const WindowID window_id) { SoftButtonID softbuttons_id; smart_objects::SmartObject& soft_buttons = message_params[strings::soft_buttons]; unsigned int length = soft_buttons.length(); for (unsigned int i = 0; i < length; ++i) { - softbuttons_id.insert(soft_buttons[i][strings::soft_button_id].asUInt()); + const auto button_id = std::make_pair( + soft_buttons[i][strings::soft_button_id].asUInt(), window_id); + softbuttons_id.insert(button_id); } app->SubscribeToSoftButtons(function_id, softbuttons_id); } +void MessageHelper::SubscribeApplicationToSoftButton( + smart_objects::SmartObject& message_params, + ApplicationSharedPtr app, + int32_t function_id) { + LOG4CXX_AUTO_TRACE(logger_); + SubscribeApplicationToSoftButton( + message_params, + app, + function_id, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW); +} + bool MessageHelper::PrintSmartObject(const smart_objects::SmartObject& object) { #ifdef DEBUG Json::Value tmp; diff --git a/src/components/application_manager/test/application_impl_test.cc b/src/components/application_manager/test/application_impl_test.cc index 080b3f8f6a..7b45d387f7 100644 --- a/src/components/application_manager/test/application_impl_test.cc +++ b/src/components/application_manager/test/application_impl_test.cc @@ -573,7 +573,9 @@ TEST_F(ApplicationImplTest, SubscribeToSoftButton_UnsubscribeFromSoftButton) { SoftButtonID test_button; for (uint i = 0; i < btn_count; i++) { - test_button.insert(i); + test_button.insert(std::make_pair( + i, + static_cast<WindowID>(mobile_apis::PredefinedWindows::DEFAULT_WINDOW))); } app_impl->SubscribeToSoftButtons(FunctionID::ScrollableMessageID, test_button); 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 d4d644160b..7171db7c3e 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 @@ -416,6 +416,8 @@ class MockApplication : public ::application_manager::Application { DataAccessor< ::application_manager::WindowParamsMap>()); MOCK_METHOD0(display_capabilities_builder, application_manager::DisplayCapabilitiesBuilder&()); + MOCK_METHOD1(GetSoftButtonWindowID, + application_manager::WindowID(const uint32_t button_id)); }; } // namespace application_manager_test 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 dff77009b4..6cbe46f9ec 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 @@ -225,6 +225,11 @@ class MockMessageHelper { ApplicationConstSharedPtr app, const policy::PolicyHandlerInterface& policy_handler, ApplicationManager& app_mngr)); + MOCK_METHOD4(SubscribeApplicationToSoftButton, + void(smart_objects::SmartObject& message_params, + ApplicationSharedPtr app, + int32_t function_id, + const application_manager::WindowID window_id)); MOCK_METHOD3(SubscribeApplicationToSoftButton, void(smart_objects::SmartObject& message_params, ApplicationSharedPtr app, diff --git a/src/components/application_manager/test/mock_message_helper.cc b/src/components/application_manager/test/mock_message_helper.cc index 54b7e3c5d9..cccadc5a9d 100644 --- a/src/components/application_manager/test/mock_message_helper.cc +++ b/src/components/application_manager/test/mock_message_helper.cc @@ -409,6 +409,16 @@ mobile_apis::Result::eType MessageHelper::ProcessSoftButtons( void MessageHelper::SubscribeApplicationToSoftButton( smart_objects::SmartObject& message_params, ApplicationSharedPtr app, + int32_t function_id, + const WindowID window_id) { + return MockMessageHelper::message_helper_mock() + ->SubscribeApplicationToSoftButton( + message_params, app, function_id, window_id); +} + +void MessageHelper::SubscribeApplicationToSoftButton( + smart_objects::SmartObject& message_params, + ApplicationSharedPtr app, int32_t function_id) { return MockMessageHelper::message_helper_mock() ->SubscribeApplicationToSoftButton(message_params, app, function_id); |