From 8204458ee0194b8be8636c73de68f4ffca577e3e Mon Sep 17 00:00:00 2001 From: Andriy Byzhynar Date: Wed, 10 Jul 2019 18:28:55 +0300 Subject: Implement BC.OnSystemCapabilitiesUpdated notification from HMI --- ...stem_capability_updated_notification_from_hmi.h | 92 ++++++++++++ ...tem_capability_updated_notification_from_hmi.cc | 117 +++++++++++++++ .../sdl_rpc_plugin/src/hmi_command_factory.cc | 10 +- ...apability_updated_notification_from_hmi_test.cc | 159 +++++++++++++++++++++ .../src/message_helper/message_helper.cc | 3 +- .../src/messagebroker_adapter.cc | 2 +- 6 files changed, 379 insertions(+), 4 deletions(-) create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_bc_system_capability_updated_notification_from_hmi.h create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_bc_system_capability_updated_notification_from_hmi.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_bc_system_capability_updated_notification_from_hmi_test.cc diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_bc_system_capability_updated_notification_from_hmi.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_bc_system_capability_updated_notification_from_hmi.h new file mode 100644 index 0000000000..00fa8efbf4 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_bc_system_capability_updated_notification_from_hmi.h @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2019, 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_BC_SYSTEM_CAPABILITY_UPDATED_NOTIFICATION_FROM_HMI_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_BC_SYSTEM_CAPABILITY_UPDATED_NOTIFICATION_FROM_HMI_H_ + +#include "application_manager/commands/notification_from_hmi.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +/** + * @brief OnBCSystemCapabilityUpdatedNotificationFromHMI command class + **/ +class OnBCSystemCapabilityUpdatedNotificationFromHMI + : public app_mngr::commands::NotificationFromHMI { + public: + /** + * @brief OnBCSystemCapabilityUpdatedNotificationFromHMI class constructor + * @param message Incoming SmartObject message from HMI + * @note all parameters described below required for base class + * @param application_manager Application manager instance to interact with + * related application + * @param rpc_service - service to handle appropriate RPC + * @param hmi_capabilities - HMI capabilities + * @param policy_handle - instance which allows interaction between + * application manager and application policies + **/ + OnBCSystemCapabilityUpdatedNotificationFromHMI( + 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 OnBCSystemCapabilityUpdatedNotificationFromHMI class destructor + **/ + ~OnBCSystemCapabilityUpdatedNotificationFromHMI() FINAL; + + void Run() FINAL; + + private: + /** + * @brief ProcessSystemDisplayCapabilities processes provided display + * capabilities according to its structure + * @param display_capabilities display capabilities to process + * @return true if display capabilities have been processed properly, + * otherwise returns false + */ + bool ProcessSystemDisplayCapabilities( + const smart_objects::SmartObject& display_capabilities); + + DISALLOW_COPY_AND_ASSIGN(OnBCSystemCapabilityUpdatedNotificationFromHMI); +}; + +} // namespace commands + +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_BC_SYSTEM_CAPABILITY_UPDATED_NOTIFICATION_FROM_HMI_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_bc_system_capability_updated_notification_from_hmi.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_bc_system_capability_updated_notification_from_hmi.cc new file mode 100644 index 0000000000..d9bb20ceef --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_bc_system_capability_updated_notification_from_hmi.cc @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2019, 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/on_bc_system_capability_updated_notification_from_hmi.h" + +#include "application_manager/message_helper.h" +#include "interfaces/HMI_API.h" +#include "interfaces/MOBILE_API.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; + +namespace commands { + +OnBCSystemCapabilityUpdatedNotificationFromHMI:: + OnBCSystemCapabilityUpdatedNotificationFromHMI( + 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) {} + +OnBCSystemCapabilityUpdatedNotificationFromHMI:: + ~OnBCSystemCapabilityUpdatedNotificationFromHMI() {} + +bool OnBCSystemCapabilityUpdatedNotificationFromHMI:: + ProcessSystemDisplayCapabilities( + const smart_objects::SmartObject& display_capabilities) { + LOG4CXX_AUTO_TRACE(logger_); + + if (!(*message_)[strings::msg_params].keyExists(strings::app_id)) { + LOG4CXX_DEBUG(logger_, "Updating general display capabilities"); + hmi_capabilities_.set_system_display_capabilities(display_capabilities); + return true; + } + + const auto app_id = + (*message_)[strings::msg_params][strings::app_id].asUInt(); + auto app = application_manager_.application(app_id); + if (!app) { + LOG4CXX_ERROR(logger_, + "Application with app_id " << app_id << " is not registered"); + return false; + } + + LOG4CXX_DEBUG(logger_, "Updating display capabilities for app " << app_id); + app->set_display_capabilities(display_capabilities); + + // Remove app_id from notification to mobile + (*message_)[strings::params][strings::connection_key] = + (*message_)[strings::msg_params][strings::app_id]; + (*message_)[strings::msg_params].erase(strings::app_id); + + return true; +} + +void OnBCSystemCapabilityUpdatedNotificationFromHMI::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + // Prepare SmartObject for mobile factory + (*message_)[strings::params][strings::function_id] = static_cast( + mobile_apis::FunctionID::OnSystemCapabilityUpdatedID); + + const auto& system_capability = + (*message_)[strings::msg_params][strings::system_capability]; + if (mobile_apis::SystemCapabilityType::DISPLAY == + system_capability[strings::system_capability_type].asInt() && + system_capability.keyExists(strings::display_capabilities)) { + if (!ProcessSystemDisplayCapabilities( + system_capability[strings::display_capabilities])) { + LOG4CXX_ERROR(logger_, + "Failed to process display capabilities. Notification will " + "be ignored"); + return; + } + } + + SendNotificationToMobile(message_); +} + +} // 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 d99a65a37f..27768e8a31 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 @@ -253,6 +253,7 @@ #include "sdl_rpc_plugin/commands/hmi/rc_is_ready_response.h" #include "sdl_rpc_plugin/commands/hmi/on_bc_system_capability_updated_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_bc_system_capability_updated_notification_from_hmi.h" namespace sdl_rpc_plugin { using namespace application_manager; @@ -889,8 +890,13 @@ CommandCreator& HMICommandFactory::get_creator_factory( : factory.GetCreator(); } case hmi_apis::FunctionID::BasicCommunication_OnSystemCapabilityUpdated: { - return factory - .GetCreator(); + return (application_manager::commands::Command::CommandSource:: + SOURCE_HMI == source) + ? factory.GetCreator< + commands:: + OnBCSystemCapabilityUpdatedNotificationFromHMI>() + : factory.GetCreator< + commands::OnBCSystemCapabilityUpdatedNotification>(); } default: { return factory.GetCreator(); } } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_bc_system_capability_updated_notification_from_hmi_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_bc_system_capability_updated_notification_from_hmi_test.cc new file mode 100644 index 0000000000..1be3780eca --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_bc_system_capability_updated_notification_from_hmi_test.cc @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2019, 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/on_bc_system_capability_updated_notification_from_hmi.h" + +#include "application_manager/commands/commands_test.h" +#include "gtest/gtest.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace on_bc_system_capability_updated_notification_from_hmi { + +using sdl_rpc_plugin::commands::OnBCSystemCapabilityUpdatedNotificationFromHMI; +using ::testing::_; +using ::testing::Return; + +typedef std::shared_ptr + OnBCSystemCapabilityUpdatedNotificationFromHMIPtr; + +namespace strings = application_manager::strings; +namespace { +const uint32_t kAppId = 1u; +} // namespace + +MATCHER(CheckMessageToMobile, "") { + const auto function_id = mobile_apis::FunctionID::OnSystemCapabilityUpdatedID; + + const bool is_function_id_matched = + function_id == static_cast( + (*arg)[strings::params][strings::function_id].asInt()); + const bool app_id_exist = + (*arg)[strings::msg_params].keyExists(strings::app_id); + bool is_connection_key_correct = true; + if ((*arg)[strings::msg_params].keyExists(strings::connection_key)) { + is_connection_key_correct = + (*arg)[strings::params][strings::connection_key] == kAppId; + } + return is_function_id_matched && !app_id_exist && is_connection_key_correct; +} + +MATCHER_P(CheckDisplayCapabilitiesNotChanged, display_capability, "") { + return display_capability == arg; +} + +class OnBCSystemCapabilityUpdatedNotificationFromHMITest + : public CommandsTest { + protected: + OnBCSystemCapabilityUpdatedNotificationFromHMITest() + : message_(CreateMessage()) + , display_capability_( + (*message_)[am::strings::msg_params][strings::system_capability] + [strings::display_capabilities]) { + command_ = + CreateCommand(message_); + mock_app_ = CreateMockApp(); + } + + OnBCSystemCapabilityUpdatedNotificationFromHMIPtr command_; + MockAppPtr mock_app_; + MessageSharedPtr message_; + const SmartObject display_capability_; +}; + +TEST_F( + OnBCSystemCapabilityUpdatedNotificationFromHMITest, + Run_AppIdNotPresentedInMessage_SetSystemDisplayCapabilitiesToHMICapabilities_SendMessageToMobile) { + (*message_)[am::strings::msg_params][strings::system_capability] + [am::strings::system_capability_type] = + mobile_apis::SystemCapabilityType::DISPLAY; + + EXPECT_CALL(mock_hmi_capabilities_, + set_system_display_capabilities( + CheckDisplayCapabilitiesNotChanged(display_capability_))); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + CheckMessageToMobile(), + ::application_manager::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(Return(true)); + + ASSERT_TRUE(command_->Init()); + command_->Run(); +} + +TEST_F(OnBCSystemCapabilityUpdatedNotificationFromHMITest, + Run_AppNotRegisteredWithPresentedAppIdInMessage_MessageNotSendToMobile) { + (*message_)[am::strings::msg_params][strings::system_capability] + [am::strings::system_capability_type] = + mobile_apis::SystemCapabilityType::DISPLAY; + (*message_)[strings::msg_params][strings::app_id] = kAppId; + ApplicationSharedPtr app; // Empty application shared pointer + + ON_CALL(app_mngr_, application(kAppId)).WillByDefault(Return(app)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + ASSERT_TRUE(command_->Init()); + command_->Run(); +} + +TEST_F( + OnBCSystemCapabilityUpdatedNotificationFromHMITest, + Run_AppRegisteredWithPresentedAppIdInMessage_SetDisplayCapabilitiesToApp_SendMessageToMobile) { + (*message_)[am::strings::msg_params][strings::system_capability] + [am::strings::system_capability_type] = + mobile_apis::SystemCapabilityType::DISPLAY; + (*message_)[strings::msg_params][strings::app_id] = kAppId; + + ON_CALL(app_mngr_, application(kAppId)).WillByDefault(Return(mock_app_)); + + EXPECT_CALL(*mock_app_, + set_display_capabilities( + CheckDisplayCapabilitiesNotChanged(display_capability_))); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + CheckMessageToMobile(), + ::application_manager::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(Return(true)); + + ASSERT_TRUE(command_->Init()); + command_->Run(); +} + +} // namespace on_bc_system_capability_updated_notification_from_hmi +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test 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 b4c1fb9ed2..7512eb2e67 100644 --- a/src/components/application_manager/src/message_helper/message_helper.cc +++ b/src/components/application_manager/src/message_helper/message_helper.cc @@ -378,7 +378,8 @@ void MessageHelper::BroadcastCapabilityUpdate( hmi_apis::FunctionID::BasicCommunication_OnSystemCapabilityUpdated; smart_objects::SmartObjectSPtr hmi_notification = std::make_shared(message); - app_mngr.GetRPCService().ManageHMICommand(hmi_notification); + app_mngr.GetRPCService().ManageHMICommand( + hmi_notification, commands::Command::CommandSource::SOURCE_SDL_TO_HMI); } smart_objects::SmartObject MessageHelper::CreateAppServiceCapabilities( diff --git a/src/components/hmi_message_handler/src/messagebroker_adapter.cc b/src/components/hmi_message_handler/src/messagebroker_adapter.cc index 8e45d4ecd9..52fb3d35df 100644 --- a/src/components/hmi_message_handler/src/messagebroker_adapter.cc +++ b/src/components/hmi_message_handler/src/messagebroker_adapter.cc @@ -139,7 +139,7 @@ void MessageBrokerAdapter::SubscribeTo() { MessageBrokerController::subscribeTo("RC.OnInteriorVehicleData"); MessageBrokerController::subscribeTo("RC.OnRemoteControlSettings"); MessageBrokerController::subscribeTo( - "SystemCapability.OnSystemCapabilityUpdated"); + "BasicCommunication.OnSystemCapabilityUpdated"); LOG4CXX_INFO(logger_, "Subscribed to notifications."); } -- cgit v1.2.1