diff options
Diffstat (limited to 'src/components/application_manager/rpc_plugins')
340 files changed, 21581 insertions, 3685 deletions
diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/CMakeLists.txt b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/CMakeLists.txt index 1e23aac8ee..ef215cdd5a 100644 --- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/CMakeLists.txt +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/CMakeLists.txt @@ -53,22 +53,25 @@ collect_sources(COMMANDS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/commands") set(LIBRARIES HMI_API MOBILE_API + MessageHelper ApplicationManager + Resumption v4_protocol_v1_2_no_extra SmartObjects Utils - sdl_rpc_plugin + sdl_rpc_plugin_static ) if(ENABLE_LOG) list(APPEND LIBRARIES log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) endif() -add_library("app_service_rpc_plugin" SHARED ${PLUGIN_SOURCES} ${MOBILE_COMMANDS} ${HMI_COMMANDS} ${COMMANDS_SOURCES}) -target_link_libraries("app_service_rpc_plugin" ${LIBRARIES}) +add_library("app_service_rpc_plugin_static" ${PLUGIN_SOURCES} ${MOBILE_COMMANDS} ${HMI_COMMANDS}) +target_link_libraries("app_service_rpc_plugin_static" ${LIBRARIES}) + +add_library("app_service_rpc_plugin" SHARED "src/app_service_rpc_plugin.cc") +target_link_libraries("app_service_rpc_plugin" app_service_rpc_plugin_static) -add_library("AppServiceRpcPluginStaticLib" ${PLUGIN_SOURCES} ${MOBILE_COMMANDS} ${HMI_COMMANDS}) -target_link_libraries("AppServiceRpcPluginStaticLib" ${LIBRARIES}) set(INSTALL_DESTINATION bin) diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/include/app_service_rpc_plugin/app_service_hmi_command_factory.h b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/include/app_service_rpc_plugin/app_service_hmi_command_factory.h index c42b64f559..fd96bf0fb6 100644 --- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/include/app_service_rpc_plugin/app_service_hmi_command_factory.h +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/include/app_service_rpc_plugin/app_service_hmi_command_factory.h @@ -34,6 +34,7 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_APP_SERVICE_RPC_PLUGIN_INCLUDE_APP_SERVICE_RPC_PLUGIN_APP_SERVICE_RPC_HMI_COMMAND_FACTORY_H #include "application_manager/application_manager.h" +#include "application_manager/command_factory.h" namespace app_service_rpc_plugin { namespace app_mngr = application_manager; diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/include/app_service_rpc_plugin/app_service_mobile_command_factory.h b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/include/app_service_rpc_plugin/app_service_mobile_command_factory.h index bd1e10f267..a6300dbb3d 100644 --- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/include/app_service_rpc_plugin/app_service_mobile_command_factory.h +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/include/app_service_rpc_plugin/app_service_mobile_command_factory.h @@ -34,6 +34,7 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_APP_SERVICE_RPC_PLUGIN_INCLUDE_APP_SERVICE_RPC_PLUGIN_APP_SERVICE_RPC_MOBILE_COMMAND_FACTORY_H #include "application_manager/application_manager.h" +#include "application_manager/command_factory.h" namespace app_service_rpc_plugin { namespace app_mngr = application_manager; 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 c9cb98cdfb..5d85237899 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 @@ -36,7 +36,6 @@ #include "application_manager/command_factory.h" namespace app_service_rpc_plugin { -// class AppServiceAppExtension; namespace app_mngr = application_manager; namespace plugins = application_manager::plugin_manager; @@ -47,7 +46,15 @@ class AppServiceRpcPlugin : public plugins::RPCPlugin { bool Init(app_mngr::ApplicationManager& application_manager, app_mngr::rpc_service::RPCService& rpc_service, app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) OVERRIDE; + 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, @@ -69,5 +76,6 @@ class AppServiceRpcPlugin : public plugins::RPCPlugin { } // namespace app_service_rpc_plugin extern "C" application_manager::plugin_manager::RPCPlugin* Create(); +extern "C" void Delete(application_manager::plugin_manager::RPCPlugin* data); #endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_APP_SERVICE_PLUGIN_INCLUDE_APP_SERVICE_PLUGIN_APP_SERVICE_PLUGIN_H diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/include/app_service_rpc_plugin/commands/mobile/get_app_service_data_request.h b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/include/app_service_rpc_plugin/commands/mobile/get_app_service_data_request.h index 7c80ec5e03..6971354806 100644 --- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/include/app_service_rpc_plugin/commands/mobile/get_app_service_data_request.h +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/include/app_service_rpc_plugin/commands/mobile/get_app_service_data_request.h @@ -68,6 +68,11 @@ class GetAppServiceDataRequest : public app_mngr::commands::CommandRequestImpl { virtual void Run(); /** + * @brief Init sets hash update mode for request + **/ + bool Init() FINAL; + + /** * @brief Interface method that is called whenever new event received * * @param event The received event diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_app_extension.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_app_extension.cc index 91d57cb952..87f947d250 100644 --- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_app_extension.cc +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_app_extension.cc @@ -103,7 +103,7 @@ void AppServiceAppExtension::ProcessResumption( const smart_objects::SmartObject& subscriptions_app_services = resumption_data[app_service_info]; for (size_t i = 0; i < subscriptions_app_services.length(); ++i) { - std::string service_type = resumption_data[i].asString(); + std::string service_type = subscriptions_app_services[i].asString(); SubscribeToAppService(service_type); } } 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 3b1b0715d4..1c3a9c77c5 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 @@ -49,7 +49,21 @@ bool AppServiceRpcPlugin::Init( application_manager::ApplicationManager& app_manager, application_manager::rpc_service::RPCService& rpc_service, application_manager::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) { + policy::PolicyHandlerInterface& policy_handler, + resumption::LastStateWrapperPtr 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::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)); @@ -93,6 +107,14 @@ void AppServiceRpcPlugin::DeleteSubscriptions( } // namespace app_service_rpc_plugin -extern "C" application_manager::plugin_manager::RPCPlugin* Create() { +extern "C" __attribute__((visibility("default"))) +application_manager::plugin_manager::RPCPlugin* +Create() { return new app_service_rpc_plugin::AppServiceRpcPlugin(); } + +extern "C" __attribute__((visibility("default"))) void Delete( + application_manager::plugin_manager::RPCPlugin* data) { + delete data; + DELETE_THREAD_LOGGER(app_service_rpc_plugin::logger_); +} 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 7c2e62abe2..e3bf40308d 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 @@ -65,6 +65,11 @@ void GetAppServiceDataRequest::Run() { true); } +bool GetAppServiceDataRequest::Init() { + hash_update_mode_ = HashUpdateMode::kDoHashUpdate; + return true; +} + void GetAppServiceDataRequest::HandleSubscribe() { std::string service_type = (*message_)[strings::msg_params][strings::service_type].asString(); diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/CMakeLists.txt b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/CMakeLists.txt index 0b56ddb7e9..1670ba5c22 100644 --- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/CMakeLists.txt +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/CMakeLists.txt @@ -25,16 +25,10 @@ file(GLOB SOURCES set(LIBRARIES gmock - Utils - SmartObjects - HMI_API - MOBILE_API - connectionHandler - app_service_rpc_plugin - sdl_rpc_plugin - jsoncpp - Policy - Resumption + sdl_rpc_plugin_static + app_service_rpc_plugin_static ) create_cotired_test("app_services_commands_test" "${SOURCES}" "${LIBRARIES}" ) + +add_subdirectory("app_service_plugin") diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/app_service_plugin/CMakeLists.txt b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/app_service_plugin/CMakeLists.txt new file mode 100644 index 0000000000..9abe251204 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/app_service_plugin/CMakeLists.txt @@ -0,0 +1,54 @@ +# Copyright (c) 2019, Ford Motor Company, Livio +# 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 copyright holders nor the names of their 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(${CMAKE_SOURCE_DIR}/tools/cmake/helpers/sources.cmake) + + +set(APP_SERVICE_DIR "${COMPONENTS_DIR}/application_manager/rpc_plugins/app_service_rpc_plugin") +set(APP_SERVICE_SRC_DIR "${APP_SERVICE_DIR}/src") +set(APP_SERVICE_INCLUDE_DIR "${APP_SERVICE_DIR}/include/app_service_rpc_plugin") +set(APP_SERVICE_TEST_DIR "${APP_SERVICE_DIR}/test") + +include_directories( + ${GMOCK_INCLUDE_DIRECTORY} + ${APP_SERVICE_INCLUDE_DIR} +) + +set(SOURCES ${APP_SERVICE_TEST_DIR}/app_service_plugin/app_service_app_extension_test.cc + ${COMPONENTS_DIR}/application_manager/test/mock_message_helper.cc +) + +set(LIBRARIES + gmock + sdl_rpc_plugin_static + app_service_rpc_plugin_static +) + +create_test("app_service_plugin_test" "${SOURCES}" "${LIBRARIES}" ) diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/app_service_plugin/app_service_app_extension_test.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/app_service_plugin/app_service_app_extension_test.cc new file mode 100644 index 0000000000..785cdd5200 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/app_service_plugin/app_service_app_extension_test.cc @@ -0,0 +1,211 @@ +/* + * 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 "app_service_rpc_plugin/app_service_app_extension.h" +#include <memory> +#include "app_service_rpc_plugin/app_service_rpc_plugin.h" +#include "application_manager/mock_application.h" +#include "gtest/gtest.h" + +namespace { +const std::string kAppServiceType1 = "AppServiceType1"; +const std::string kAppServiceType2 = "AppServiceType2"; +const std::string kResumptionDataKey = "kResumptionDataKey"; +const std::string kAppServiceInfoKey = "appService"; +} // namespace + +namespace test { +namespace components { +namespace app_service_plugin_test { + +using test::components::application_manager_test::MockApplication; +using ::testing::_; +using ::testing::Mock; +using ::testing::NiceMock; +using ::testing::Return; +using ::testing::ReturnNull; +using ::testing::ReturnRef; +using ::testing::SaveArg; + +using namespace app_service_rpc_plugin; +namespace strings = application_manager::strings; +namespace plugins = application_manager::plugin_manager; + +class AppServiceAppExtensionTest : public ::testing::Test { + public: + AppServiceAppExtensionTest() : mock_app_(new NiceMock<MockApplication>()) {} + + protected: + void SetUp() OVERRIDE { + app_service_app_extension_.reset( + new AppServiceAppExtension(app_service_plugin_, *mock_app_)); + } + + void TearDown() OVERRIDE { + app_service_app_extension_.reset(); + } + + app_service_rpc_plugin::AppServiceRpcPlugin app_service_plugin_; + std::unique_ptr<MockApplication> mock_app_; + std::unique_ptr<AppServiceAppExtension> app_service_app_extension_; +}; + +TEST_F(AppServiceAppExtensionTest, SubscribeToAppService_SUCCESS) { + EXPECT_TRUE( + app_service_app_extension_->SubscribeToAppService(kAppServiceType1)); + const auto& subs = app_service_app_extension_->Subscriptions(); + EXPECT_EQ(1u, subs.size()); + EXPECT_TRUE( + app_service_app_extension_->IsSubscribedToAppService(kAppServiceType1)); +} + +TEST_F(AppServiceAppExtensionTest, + SubscribeToAppService_SubscribeOneAppServiceType_Twice_FAIL) { + ASSERT_TRUE( + app_service_app_extension_->SubscribeToAppService(kAppServiceType1)); + ASSERT_TRUE( + app_service_app_extension_->IsSubscribedToAppService(kAppServiceType1)); + + EXPECT_FALSE( + app_service_app_extension_->SubscribeToAppService(kAppServiceType1)); + EXPECT_TRUE( + app_service_app_extension_->IsSubscribedToAppService(kAppServiceType1)); + const auto& subs = app_service_app_extension_->Subscriptions(); + EXPECT_EQ(1u, subs.size()); +} + +TEST_F( + AppServiceAppExtensionTest, + UnsubscribeFromAppService_AppServiceType1Unsubscribed_AppServiceType2Remains_SUCCESS) { + // Subscribe + ASSERT_TRUE( + app_service_app_extension_->SubscribeToAppService(kAppServiceType1)); + ASSERT_TRUE( + app_service_app_extension_->SubscribeToAppService(kAppServiceType2)); + auto subs = app_service_app_extension_->Subscriptions(); + ASSERT_EQ(2u, subs.size()); + ASSERT_TRUE( + app_service_app_extension_->IsSubscribedToAppService(kAppServiceType1)); + ASSERT_TRUE( + app_service_app_extension_->IsSubscribedToAppService(kAppServiceType2)); + + // Unsubscribe + EXPECT_TRUE( + app_service_app_extension_->UnsubscribeFromAppService(kAppServiceType1)); + EXPECT_FALSE( + app_service_app_extension_->IsSubscribedToAppService(kAppServiceType1)); + EXPECT_TRUE( + app_service_app_extension_->IsSubscribedToAppService(kAppServiceType2)); + subs = app_service_app_extension_->Subscriptions(); + EXPECT_EQ(1u, subs.size()); +} + +TEST_F(AppServiceAppExtensionTest, + UnsubscribeFromAppService_UnsubscribeNotSubscribedAppServiceType_FAIL) { + ASSERT_TRUE( + app_service_app_extension_->SubscribeToAppService(kAppServiceType1)); + ASSERT_EQ(1u, app_service_app_extension_->Subscriptions().size()); + ASSERT_TRUE( + app_service_app_extension_->IsSubscribedToAppService(kAppServiceType1)); + + EXPECT_FALSE( + app_service_app_extension_->UnsubscribeFromAppService(kAppServiceType2)); + EXPECT_TRUE( + app_service_app_extension_->IsSubscribedToAppService(kAppServiceType1)); + EXPECT_EQ(1u, app_service_app_extension_->Subscriptions().size()); +} + +TEST_F(AppServiceAppExtensionTest, + UnsubscribeFromAppService_UnsubscribeAll_SUCCESS) { + auto app_service_types = {kAppServiceType1, kAppServiceType2}; + + for (const auto& app_service_type : app_service_types) { + ASSERT_TRUE( + app_service_app_extension_->SubscribeToAppService(app_service_type)); + ASSERT_TRUE( + app_service_app_extension_->IsSubscribedToAppService(app_service_type)); + } + ASSERT_EQ(2u, app_service_app_extension_->Subscriptions().size()); + + app_service_app_extension_->UnsubscribeFromAppService(); + + for (const auto& app_service_type : app_service_types) { + EXPECT_FALSE( + app_service_app_extension_->IsSubscribedToAppService(app_service_type)); + } + EXPECT_EQ(0u, app_service_app_extension_->Subscriptions().size()); +} + +TEST_F(AppServiceAppExtensionTest, SaveResumptionData_SUCCESS) { + ASSERT_TRUE( + app_service_app_extension_->SubscribeToAppService(kAppServiceType1)); + ASSERT_EQ(1u, app_service_app_extension_->Subscriptions().size()); + ASSERT_TRUE( + app_service_app_extension_->IsSubscribedToAppService(kAppServiceType1)); + + smart_objects::SmartObject resumption_data; + resumption_data[kResumptionDataKey] = "some resumption data"; + + app_service_app_extension_->SaveResumptionData(resumption_data); + + EXPECT_TRUE(resumption_data.keyExists(kResumptionDataKey)); + EXPECT_TRUE(resumption_data.keyExists(kAppServiceInfoKey)); + EXPECT_EQ(kAppServiceType1, + resumption_data[kAppServiceInfoKey][0].asString()); +} + +TEST_F(AppServiceAppExtensionTest, ProcessResumption_SUCCESS) { + app_service_app_extension_->UnsubscribeFromAppService(); + ASSERT_EQ(0u, app_service_app_extension_->Subscriptions().size()); + + smart_objects::SmartObject app_service_data = + smart_objects::SmartObject(smart_objects::SmartType_Array); + app_service_data.asArray()->push_back( + smart_objects::SmartObject(kAppServiceType1)); + app_service_data.asArray()->push_back( + smart_objects::SmartObject(kAppServiceType2)); + + smart_objects::SmartObject resumption_data; + resumption_data[kAppServiceInfoKey] = app_service_data; + + app_service_app_extension_->ProcessResumption(resumption_data); + + for (const auto& app_service_type : {kAppServiceType1, kAppServiceType2}) { + EXPECT_TRUE( + app_service_app_extension_->IsSubscribedToAppService(app_service_type)); + } + EXPECT_EQ(2u, app_service_app_extension_->Subscriptions().size()); +} + +} // namespace app_service_plugin_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/commands/mobile/on_app_service_data_notification_test.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/commands/mobile/on_app_service_data_notification_test.cc index 3e88d4eaf3..6949a3aff0 100644 --- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/commands/mobile/on_app_service_data_notification_test.cc +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/commands/mobile/on_app_service_data_notification_test.cc @@ -41,6 +41,7 @@ #include "gtest/gtest.h" #include "interfaces/MOBILE_API.h" #include "resumption/last_state_impl.h" +#include "resumption/last_state_wrapper_impl.h" namespace am = application_manager; using am::ApplicationSet; @@ -80,7 +81,9 @@ class OnAppServiceDataNotificationTest app_service_plugin_, *mock_app_)) , apps_lock_(std::make_shared<sync_primitives::Lock>()) , apps_da_(apps_, apps_lock_) - , last_state_("app_storage_folder", "app_info_storage") + , last_state_(std::make_shared<resumption::LastStateWrapperImpl>( + std::make_shared<resumption::LastStateImpl>("app_storage_folder", + "app_info_storage"))) , app_service_manager_(app_mngr_, last_state_) { ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kAppId)); ON_CALL(*mock_app_, is_remote_control_supported()) @@ -109,7 +112,7 @@ class OnAppServiceDataNotificationTest application_manager::ApplicationSet apps_; const std::shared_ptr<sync_primitives::Lock> apps_lock_; DataAccessor<application_manager::ApplicationSet> apps_da_; - resumption::LastStateImpl last_state_; + resumption::LastStateWrapperPtr last_state_; MockAppServiceManager app_service_manager_; }; diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/CMakeLists.txt b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/CMakeLists.txt index 00de927b6e..8129e1240d 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/CMakeLists.txt +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/CMakeLists.txt @@ -50,7 +50,10 @@ collect_sources(COMMANDS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/commands") set(LIBRARIES HMI_API MOBILE_API + MessageHelper ApplicationManager + ProtocolHandler + connectionHandler v4_protocol_v1_2_no_extra SmartObjects Utils @@ -60,11 +63,12 @@ if(ENABLE_LOG) list(APPEND LIBRARIES log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) endif() -add_library("rc_rpc_plugin" SHARED ${PLUGIN_SOURCES} ${MOBILE_COMMANDS} ${HMI_COMMANDS} ${COMMANDS_SOURCES}) -target_link_libraries("rc_rpc_plugin" ${LIBRARIES}) +add_library("rc_rpc_plugin_static" ${PLUGIN_SOURCES} ${MOBILE_COMMANDS} ${HMI_COMMANDS}) +target_link_libraries("rc_rpc_plugin_static" ${LIBRARIES}) + +add_library("rc_rpc_plugin" SHARED "src/rc_rpc_plugin.cc") +target_link_libraries("rc_rpc_plugin" rc_rpc_plugin_static) -add_library("RCRpcPluginStaticLib" ${PLUGIN_SOURCES} ${MOBILE_COMMANDS} ${HMI_COMMANDS}) -target_link_libraries("RCRpcPluginStaticLib" ${LIBRARIES}) set(INSTALL_DESTINATION bin) diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/hmi/rc_on_remote_control_settings_notification.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/hmi/rc_on_remote_control_settings_notification.h index 7aa1aa3dba..82e0a8c13b 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/hmi/rc_on_remote_control_settings_notification.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/hmi/rc_on_remote_control_settings_notification.h @@ -69,6 +69,7 @@ class RCOnRemoteControlSettingsNotification private: ResourceAllocationManager& resource_allocation_manager_; InteriorDataManager& interior_data_manager_; + RCConsentManager& rc_consent_manager_; /** * @brief Disalows RC functionality for all RC apps * All registered apps will be unsubsribed from OnInteriorVehicleData diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/hmi/rc_set_global_properties_request.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/hmi/rc_set_global_properties_request.h new file mode 100644 index 0000000000..64b11c3d7b --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/hmi/rc_set_global_properties_request.h @@ -0,0 +1,66 @@ +/* + * 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_RC_SET_GLOBAL_PROPERTIES_REQUEST_H +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_RC_SET_GLOBAL_PROPERTIES_REQUEST_H + +#include "application_manager/commands/request_to_hmi.h" +#include "rc_rpc_plugin/commands/rc_command_request.h" + +namespace rc_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +class RCSetGlobalPropertiesRequest : public app_mngr::commands::RequestToHMI { + public: + /** + * @brief RCSetGlobalPropertiesRequest class constructor + * + * @param message Command message as smart pointer to SmartObject + * @param params structure that contains references to + * parameters used in remote сontrol commands + */ + RCSetGlobalPropertiesRequest( + const app_mngr::commands::MessageSharedPtr& message, + const RCCommandParams& params); + /** + * @brief Execute command + */ + void Run() OVERRIDE; + + ~RCSetGlobalPropertiesRequest(); +}; +} // namespace commands +} // namespace rc_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_RC_SET_GLOBAL_PROPERTIES_REQUEST_H diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/hmi/rc_set_global_properties_response.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/hmi/rc_set_global_properties_response.h new file mode 100644 index 0000000000..2e1494364c --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/hmi/rc_set_global_properties_response.h @@ -0,0 +1,68 @@ +/* + 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_RC_SET_GLOBAL_PROPERTIES_RESPONSE_H +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_RC_SET_GLOBAL_PROPERTIES_RESPONSE_H + +#include "application_manager/commands/response_from_hmi.h" +#include "rc_rpc_plugin/commands/rc_command_request.h" + +namespace rc_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { +class RCSetGlobalPropertiesResponse + : public application_manager::commands::ResponseFromHMI { + public: + /** + * @brief RCSetGlobalPropertiesResponse class constructor + * + * @param message Command message as smart pointer to SmartObject + * @param params Structure that contains references to + * parameters used in remote сontrol commands + */ + RCSetGlobalPropertiesResponse( + const application_manager::commands::MessageSharedPtr& message, + const RCCommandParams& params); + + /** + * @brief Execute command + */ + void Run() OVERRIDE; + + ~RCSetGlobalPropertiesResponse(); +}; + +} // namespace commands +} // namespace rc_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_RC_SET_GLOBAL_PROPERTIES_RESPONSE_H diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/button_press_request.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/button_press_request.h index d6ecfd0128..3946d80508 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/button_press_request.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/button_press_request.h @@ -64,9 +64,11 @@ class ButtonPressRequest : public RCCommandRequest { /** * @brief IsResourceFree check resource state * @param module_type Resource name + * @param module_id Resource id * @return True if free, otherwise - false */ - bool IsResourceFree(const std::string& module_type) const FINAL; + bool IsResourceFree(const std::string& module_type, + const std::string& module_id) const FINAL; /** * @brief SetResourceState changes state of resource @@ -82,12 +84,18 @@ class ButtonPressRequest : public RCCommandRequest { */ void on_event(const app_mngr::event_engine::Event& event) FINAL; - std::string ModuleType() FINAL; + std::string ModuleType() const FINAL; + + std::string ModuleId() const FINAL; /** * @brief ButtonPressRequest class destructor */ ~ButtonPressRequest(); + + private: + const mobile_apis::ButtonName::eType GetButtonId() const; + std::string GetButtonName() const; }; } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/get_interior_vehicle_data_consent_request.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/get_interior_vehicle_data_consent_request.h new file mode 100644 index 0000000000..c41169d027 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/get_interior_vehicle_data_consent_request.h @@ -0,0 +1,123 @@ +/* + * 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_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_COMMANDS_MOBILE_RC_GET_INTERIOR_VEHICLE_DATA_CONSENT_REQUEST_H +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_COMMANDS_MOBILE_RC_GET_INTERIOR_VEHICLE_DATA_CONSENT_REQUEST_H + +#include <string> + +#include "rc_rpc_plugin/commands/rc_command_params.h" +#include "rc_rpc_plugin/commands/rc_command_request.h" +#include "utils/macro.h" + +namespace rc_rpc_plugin { +namespace commands { + +class GetInteriorVehicleDataConsentRequest + : public rc_rpc_plugin::commands::RCCommandRequest { + public: + /** + * @brief GetInteriorVehicleDataConsentRequest constructor + * @param message smart pointer with SmartObject + * @param params structure that contains references to + * parameters used in remote сontrol commands + */ + GetInteriorVehicleDataConsentRequest( + const application_manager::commands::MessageSharedPtr& message, + const RCCommandParams& params); + + /** + * @brief Execute command + */ + void Execute() FINAL; + + void on_event(const app_mngr::event_engine::Event& event) FINAL; + + std::string ModuleType() const FINAL; + + /** + * @brief For this RPC this method isn't correct, because SDL receives array + * of module_ids instead of only one module_id. This method returns empty + * string. + */ + std::string ModuleId() const FINAL; + + ~GetInteriorVehicleDataConsentRequest(); + + private: + /** + * @brief Saves ModuleId consents (saved before moduleids + received moduleId + * consents + date_of_consent) to file. + * + * @param msg_params Message params from response message as SmartObject. + */ + bool SaveModuleIdConsents(std::string& info_out, + const smart_objects::SmartObject& msg_params); + + /** + * @brief Gets calculated vehicle data consent and puts it into provided smart + * object + * @param out_response output smart object + * @return true in case all required consent information was provided in + * output smart object, otherwise returns false + */ + bool GetCalculatedVehicleDataConsent( + smart_objects::SmartObject& out_response) const; + + /** + * @brief Checks whether the user_location is covered by the module's + * serviceArea + * @param module_uid module key(module_type + module_id) + * @return true if the user_location is covered by the module's serviceArea or + * the user is the driver (or if seatLocationCapabilities don't exists) + * otherwise false + */ + bool IsUserLocationValid(const ModuleUid& module_uid) const; + + /** + * @brief Checks whether user should have access to module using the specific + * accessMode's rules + * @param module_uid module key(moudle_type + module_id) + * @param access_mode current HMI accessMode + * @return consent enum value + */ + rc_rpc_types::ModuleConsent GetModuleConsentByAccessMode( + const ModuleUid& module_uid, + const hmi_apis::Common_RCAccessMode::eType access_mode) const; + + smart_objects::SmartObject hmi_request_consents_; +}; + +} // namespace commands +} // namespace rc_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_COMMANDS_MOBILE_RC_GET_INTERIOR_VEHICLE_DATA_CONSENT_REQUEST_H diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/get_interior_vehicle_data_consent_response.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/get_interior_vehicle_data_consent_response.h new file mode 100644 index 0000000000..c163b02a80 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/get_interior_vehicle_data_consent_response.h @@ -0,0 +1,68 @@ +/* + * 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_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_COMMANDS_MOBILE_RC_GET_INTERIOR_VEHICLE_DATA_CONSENT_RESPONSE_H +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_COMMANDS_MOBILE_RC_GET_INTERIOR_VEHICLE_DATA_CONSENT_RESPONSE_H + +#include "application_manager/commands/command_response_impl.h" +#include "rc_rpc_plugin/commands/rc_command_params.h" +#include "utils/macro.h" + +namespace rc_rpc_plugin { + +namespace commands { + +class GetInteriorVehicleDataConsentResponse + : public application_manager::commands::CommandResponseImpl { + public: + /** + * @brief GetInteriorVehicleDataConsentResponse constructor + * + * @param message smart pointer with SmartObject + * @param params structure which contains references for next + * entities: ApplicationManager, RPCService, HMICapabilities, + * PolicyHandlerInterface, ResourceAllocationManager, InteriorDataCache, + * InteriorDataManager. + */ + GetInteriorVehicleDataConsentResponse( + const application_manager::commands::MessageSharedPtr& message, + const RCCommandParams& params); + + void Run() OVERRIDE; + + ~GetInteriorVehicleDataConsentResponse(); +}; + +} // namespace commands +} // namespace rc_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_COMMANDS_MOBILE_RC_GET_INTERIOR_VEHICLE_DATA_CONSENT_RESPONSE_H diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/get_interior_vehicle_data_request.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/get_interior_vehicle_data_request.h index cfb5e72c95..7be37f0756 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/get_interior_vehicle_data_request.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/get_interior_vehicle_data_request.h @@ -63,8 +63,8 @@ class GetInteriorVehicleDataRequest : public RCCommandRequest { ~GetInteriorVehicleDataRequest(); private: - std::vector<application_manager::ApplicationSharedPtr> - AppsSubscribedToModuleType(const std::string& module_type); + std::vector<application_manager::ApplicationSharedPtr> AppsSubscribedToModule( + const ModuleUid& module); /** * @brief Check if app wants to proceed with already setup subscription @@ -87,7 +87,8 @@ class GetInteriorVehicleDataRequest : public RCCommandRequest { */ void RemoveExcessiveSubscription(); - std::string ModuleType() FINAL; + std::string ModuleType() const FINAL; + std::string ModuleId() const FINAL; bool excessive_subscription_occured_; bool ProcessCapabilities(); void ProcessResponseToMobileFromCache(app_mngr::ApplicationSharedPtr app); diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/on_interior_vehicle_data_notification.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/on_interior_vehicle_data_notification.h index 2a7362510d..4663b4b371 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/on_interior_vehicle_data_notification.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/on_interior_vehicle_data_notification.h @@ -53,13 +53,16 @@ class OnInteriorVehicleDataNotification void Run() OVERRIDE; - std::string ModuleType(); + std::string ModuleType() const; + + std::string ModuleId() const; ~OnInteriorVehicleDataNotification(); private: InteriorDataCache& interior_data_cache_; - void AddDataToCache(const std::string& module_type); + RCCapabilitiesManager& rc_capabilities_manager_; + void AddDataToCache(const ModuleUid& module); }; } // namespace commands } // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/release_interior_vehicle_data_module_request.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/release_interior_vehicle_data_module_request.h new file mode 100644 index 0000000000..316dc29a1d --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/release_interior_vehicle_data_module_request.h @@ -0,0 +1,71 @@ +/* + * 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_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_COMMANDS_MOBILE_RELEASE_INTERIOR_VEHICLE_DATA_MODULE_REQUEST_H +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_COMMANDS_MOBILE_RELEASE_INTERIOR_VEHICLE_DATA_MODULE_REQUEST_H + +#include "rc_rpc_plugin/commands/rc_command_params.h" +#include "rc_rpc_plugin/commands/rc_command_request.h" +#include "utils/macro.h" + +namespace rc_rpc_plugin { +namespace commands { + +class ReleaseInteriorVehicleDataModuleRequest + : public rc_rpc_plugin::commands::RCCommandRequest { + public: + /** + * @brief ReleaseInteriorVehicleDataModule constructor + * @param message smart pointer with SmartObject + * @param params structure that contains references to + * parameters used in remote сontrol commands + */ + ReleaseInteriorVehicleDataModuleRequest( + const application_manager::commands::MessageSharedPtr& message, + const RCCommandParams& params); + + void Execute() FINAL; + + std::string ModuleType() const FINAL; + + std::string ModuleId() const FINAL; + + ~ReleaseInteriorVehicleDataModuleRequest(); + + private: + bool ProcessCapabilities(); +}; + +} // namespace commands +} // namespace rc_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_COMMANDS_MOBILE_RELEASE_INTERIOR_VEHICLE_DATA_MODULE_REQUEST_H diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/release_interior_vehicle_data_module_response.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/release_interior_vehicle_data_module_response.h new file mode 100644 index 0000000000..42e0775a83 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/release_interior_vehicle_data_module_response.h @@ -0,0 +1,67 @@ +/* + * 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_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_COMMANDS_MOBILE_RELEASE_INTERIOR_VEHICLE_DATA_MODULE_RESPONSE_H +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_COMMANDS_MOBILE_RELEASE_INTERIOR_VEHICLE_DATA_MODULE_RESPONSE_H + +#include "application_manager/commands/command_response_impl.h" +#include "rc_rpc_plugin/commands/rc_command_params.h" +#include "utils/macro.h" + +namespace rc_rpc_plugin { +namespace commands { + +class ReleaseInteriorVehicleDataModuleResponse + : public application_manager::commands::CommandResponseImpl { + public: + /** + * @brief ReleaseInteriorVehicleDataModuleResponse constructor + * + * @param message smart pointer with SmartObject + * @param params structure which contains references for next + * entities: ApplicationManager, RPCService, HMICapabilities, + * PolicyHandlerInterface, ResourceAllocationManager, InteriorDataCache, + * InteriorDataManager. + */ + ReleaseInteriorVehicleDataModuleResponse( + const application_manager::commands::MessageSharedPtr& message, + const RCCommandParams& params); + + void Run() OVERRIDE; + + ~ReleaseInteriorVehicleDataModuleResponse(); +}; + +} // namespace commands +} // namespace rc_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_COMMANDS_MOBILE_RELEASE_INTERIOR_VEHICLE_DATA_MODULE_RESPONSE_H diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/set_interior_vehicle_data_request.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/set_interior_vehicle_data_request.h index 128c668ee9..bb152a52f8 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/set_interior_vehicle_data_request.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/set_interior_vehicle_data_request.h @@ -40,10 +40,6 @@ namespace app_mngr = application_manager; namespace commands { -enum capabilitiesStatus { success, missedLightName, missedParam, readOnly }; - -typedef std::pair<std::string, capabilitiesStatus> ModuleCapability; - class SetInteriorVehicleDataRequest : public RCCommandRequest { public: SetInteriorVehicleDataRequest( @@ -66,9 +62,11 @@ class SetInteriorVehicleDataRequest : public RCCommandRequest { /** * @brief IsResourceFree check resource state * @param module_type Resource name + * @param module_id Resource id * @return True if free, otherwise - false */ - bool IsResourceFree(const std::string& module_type) const FINAL; + bool IsResourceFree(const std::string& module_type, + const std::string& module_id) const FINAL; /** * @brief SetResourceState changes state of resource @@ -85,28 +83,14 @@ class SetInteriorVehicleDataRequest : public RCCommandRequest { void on_event(const app_mngr::event_engine::Event& event) FINAL; /** - * @brief Method that check if READ_ONLY parameters present - * @param request_params params from received message, - * @param module_data_capabilities info for notification to mobile - * @return true if present , false - otherwise - */ - bool AreReadOnlyParamsPresent(const smart_objects::SmartObject& module_data, - ModuleCapability& module_data_capabilities); - - /** - * @brief Method that check if all request parameters are READ_ONLY - * @param request_params params from received message - * @return true if all are read only , false - otherwise - */ - bool AreAllParamsReadOnly(const smart_objects::SmartObject& module_data); - - /** * @brief Method that cuts-off READ_ONLY parameters * @param module_data params to handle */ void CutOffReadOnlyParams(smart_objects::SmartObject& module_data); - std::string ModuleType() FINAL; + std::string ModuleType() const FINAL; + + std::string ModuleId() const FINAL; /** * @brief SetInteriorVehicleDataRequest class destructor @@ -115,14 +99,6 @@ class SetInteriorVehicleDataRequest : public RCCommandRequest { private: /** - * @brief ControlData - * @param module_data received params - * @return value of module data depending on module type - */ - const smart_objects::SmartObject& ControlData( - const smart_objects::SmartObject& module_data); - - /** * @brief CheckAudioSource check that if app wants to change * the audio source from MOBILE_APP to other types of audio * source without keepContext parameter or with keepContext=false diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/rc_command_params.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/rc_command_params.h index 0ca7789791..3b46b7ea30 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/rc_command_params.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/rc_command_params.h @@ -50,6 +50,8 @@ namespace rc_rpc_plugin { class ResourceAllocationManager; class InteriorDataCache; class InteriorDataManager; +class RCCapabilitiesManager; +class RCConsentManager; struct RCCommandParams { application_manager::ApplicationManager& application_manager_; @@ -59,6 +61,8 @@ struct RCCommandParams { rc_rpc_plugin::ResourceAllocationManager& resource_allocation_manager_; rc_rpc_plugin::InteriorDataCache& interior_data_cache_; rc_rpc_plugin::InteriorDataManager& interior_data_manager_; + rc_rpc_plugin::RCCapabilitiesManager& rc_capabilities_manager_; + rc_rpc_plugin::RCConsentManager& rc_consent_manager_; }; } // namespace rc_rpc_plugin #endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_COMMANDS_RC_COMMAND_PARAMS_H_ diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/rc_command_request.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/rc_command_request.h index b4e34c083e..6bca1017e0 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/rc_command_request.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/rc_command_request.h @@ -37,6 +37,8 @@ #include "rc_rpc_plugin/commands/rc_command_params.h" #include "rc_rpc_plugin/interior_data_cache.h" #include "rc_rpc_plugin/rc_app_extension.h" +#include "rc_rpc_plugin/rc_capabilities_manager.h" +#include "rc_rpc_plugin/rc_consent_manager.h" #include "rc_rpc_plugin/resource_allocation_manager.h" namespace rc_rpc_plugin { @@ -76,6 +78,8 @@ class RCCommandRequest : public app_mngr::commands::CommandRequestImpl { ResourceAllocationManager& resource_allocation_manager_; InteriorDataCache& interior_data_cache_; InteriorDataManager& interior_data_manager_; + RCCapabilitiesManager& rc_capabilities_manager_; + RCConsentManager& rc_consent_manager_; /** * @brief AcquireResource try to allocate resource for application * In case if allocation of resource is not required, return ALLOWED by @@ -94,10 +98,13 @@ class RCCommandRequest : public app_mngr::commands::CommandRequestImpl { * This is default implementation which has to be redefined for RPCs which * need to manage the resources * @param module_type Resource name + * @param module_id Resource id * @return True if free, otherwise - false */ - virtual bool IsResourceFree(const std::string& module_type) const { + virtual bool IsResourceFree(const std::string& module_type, + const std::string& module_id) const { UNUSED(module_type); + UNUSED(module_id); return true; } /** @@ -136,7 +143,24 @@ class RCCommandRequest : public app_mngr::commands::CommandRequestImpl { disallowed_info_ = info; } - virtual std::string ModuleType() = 0; + virtual std::string ModuleType() const = 0; + + /** + * @brief Extracts ModuleId from command message. Each inherited class should + * implement its own functionality + * + * @return ModuleId as string. + */ + virtual std::string ModuleId() const = 0; + + /** + * @brief IsModuleIdProvided checks if moduleId parameter + * is provided in the hmi response + * @param hmi_response response from hmi + * @return true if provided, otherwise - false + */ + + bool IsModuleIdProvided(const smart_objects::SmartObject& hmi_response) const; private: /** @@ -158,9 +182,38 @@ class RCCommandRequest : public app_mngr::commands::CommandRequestImpl { /** * @brief SendGetUserConsent sends consent request to HMI * @param module_type Resource name + * @param module_ids Array of module IDs of the module type that needed user + * consent for acquiring their resources */ - void SendGetUserConsent(const std::string& module_type); + void SendGetUserConsent(const std::string& module_type, + const smart_objects::SmartObject& module_ids); + void ProcessAccessResponse(const app_mngr::event_engine::Event& event); + + /** + * @brief Precesses consents result which has been received from HMI + * If module resource consented, resource state will be switched to state BUSY + * and called method Execute. Otherwise will be sent response to Mobile with + * result code REJECTED. + * @param is_allowed consent result + * @param module_type Module type + * @param module_id Module ID + * @param app_id Application, which has asked for module resource consent. + */ + void ProcessConsentResult(const bool is_allowed, + const std::string& module_type, + const std::string& module_id, + const uint32_t app_id); + /** + * @brief Processes ASK_DRIVE Mode. Tries to retrieve module consents from + * LastState. If consent is absent in LastState, will send + * GetInteriorVehicleDataConsent to HMI. Otherwise will start to process + * consent result. + * @param module_type Module type + * @param module_id Module ID + */ + void ProcessAskDriverMode(const std::string& module_type, + const std::string& module_id); bool IsInterfaceAvailable( const app_mngr::HmiInterfaces::InterfaceID interface) const; diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/interior_data_cache.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/interior_data_cache.h index c7dda761bf..dad37edd1b 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/interior_data_cache.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/interior_data_cache.h @@ -37,8 +37,15 @@ namespace rc_rpc_plugin { /** + * @brief ModuleUid uniquely identify a module + * moduleType + moduleID + */ +typedef std::pair<std::string, std::string> ModuleUid; + +/** * @brief The InteriorDataCache interface for caching data class - * Provide ability to cache module data by module type name and clear cache + * Provide ability to cache module data by module type name and module id + * and clear cache */ class InteriorDataCache { public: @@ -49,32 +56,35 @@ class InteriorDataCache { /** * @brief Add module data to cache - * @param module_type module type name + * @param module module type + module id * @param module_data data to be cached */ - virtual void Add(const std::string& module_type, + virtual void Add(const ModuleUid& module, const smart_objects::SmartObject& module_data) = 0; /** * @brief Retrieve Get cached data - * @param module_type data type to get from cache + * @param module data type to get from cache * @return smart object with cached data, or nulll smart object */ virtual smart_objects::SmartObject Retrieve( + const ModuleUid& module) const = 0; + + virtual std::vector<ModuleUid> GetCachedModulesByType( const std::string& module_type) const = 0; /** * @brief Contains check if data exists in cache - * @param module_type module type name to check in cache + * @param module module name + module id to check in cache * @return true if cached, false otherwize */ - virtual bool Contains(const std::string& module_type) const = 0; + virtual bool Contains(const ModuleUid& module) const = 0; /** * @brief Remove cached data - * @param module_type data type to remove from cache + * @param module data type to remove from cache */ - virtual void Remove(const std::string& module_type) = 0; + virtual void Remove(const ModuleUid& module) = 0; /** * @brief Clear clear all cached data diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/interior_data_cache_impl.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/interior_data_cache_impl.h index b40ce4eb4b..d21b0e4162 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/interior_data_cache_impl.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/interior_data_cache_impl.h @@ -46,16 +46,19 @@ class InteriorDataCacheImpl : public InteriorDataCache { ~InteriorDataCacheImpl(); - void Add(const std::string& module_type, + void Add(const ModuleUid& module, const smart_objects::SmartObject& module_data) OVERRIDE; - smart_objects::SmartObject Retrieve( + smart_objects::SmartObject Retrieve(const ModuleUid& module) const OVERRIDE; + + std::vector<ModuleUid> GetCachedModulesByType( const std::string& module_type) const OVERRIDE; - bool Contains(const std::string& module_type) const OVERRIDE; - void Remove(const std::string& module_type) OVERRIDE; + + bool Contains(const ModuleUid& module) const OVERRIDE; + void Remove(const ModuleUid& module) OVERRIDE; void Clear() OVERRIDE; private: - std::map<std::string, smart_objects::SmartObject> cached_data_; + std::map<ModuleUid, smart_objects::SmartObject> cached_data_; mutable sync_primitives::Lock cached_data_lock_; }; diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/interior_data_manager.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/interior_data_manager.h index 157e031869..c1fe30fa4d 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/interior_data_manager.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/interior_data_manager.h @@ -41,8 +41,15 @@ namespace rc_rpc_plugin { namespace app_mngr = application_manager; namespace plugins = application_manager::plugin_manager; +/** + * @brief ModuleUid uniquely identify a module + * moduleType + moduleID + */ +typedef std::pair<std::string, std::string> ModuleUid; + class InteriorDataManager { public: + virtual ~InteriorDataManager() {} /** * @brief OnPolicyEvent Processes policy related events * @param event Policy event @@ -67,18 +74,19 @@ class InteriorDataManager { /** * @brief StoreRequestToHMITime save information and time stamp of * current interior data subscriptions + * @param module Module resource (module_type + module_id) */ - virtual void StoreRequestToHMITime(const std::string& module_type) = 0; + virtual void StoreRequestToHMITime(const ModuleUid& module) = 0; /** * @brief CheckRequestsToHMIFrequency check that rate limits are not allowed * of bounce during current time frame. calculate amount of requests per - * module type in time frame and checks if it bigger then allowed by ini file - * @param module_type moduletype to calculate frequency on + * module in time frame and checks if it bigger then allowed by ini file + * @param module module to calculate frequency on * @return true if amount of requests was not exceeded, otherwise return * false. */ - virtual bool CheckRequestsToHMIFrequency(const std::string& module_type) = 0; + virtual bool CheckRequestsToHMIFrequency(const ModuleUid& module) = 0; }; } // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/interior_data_manager_impl.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/interior_data_manager_impl.h index b98ba596fb..791016cdcd 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/interior_data_manager_impl.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/interior_data_manager_impl.h @@ -61,9 +61,9 @@ class InteriorDataManagerImpl : public InteriorDataManager { void OnDisablingRC() OVERRIDE; - void StoreRequestToHMITime(const std::string& module_type) OVERRIDE; + void StoreRequestToHMITime(const ModuleUid& module) OVERRIDE; - bool CheckRequestsToHMIFrequency(const std::string& module_type) OVERRIDE; + bool CheckRequestsToHMIFrequency(const ModuleUid& module) OVERRIDE; private: /** @@ -83,18 +83,20 @@ class InteriorDataManagerImpl : public InteriorDataManager { application_manager::Application& app); /** - * @brief UnsubscribeFromInteriorVehicleData remove module_type from cache and + * @brief UnsubscribeFromInteriorVehicleData remove module from cache and * send RC.GetInteriorVehicleData(subscribe=false) to HMI - * @param module_type module type that need to be unsubscribed + * @param module module that needs to be unsubscribed */ - void UnsubscribeFromInteriorVehicleData(const std::string& module_type); + void UnsubscribeFromInteriorVehicleData(const ModuleUid& module); + + void UnsubscribeFromInteriorVehicleDataOfType(const std::string& module_type); void ClearOldRequestsToHMIHistory(); /** * @brief AppsModules mapping from applications to list of modules */ typedef std::map<application_manager::ApplicationSharedPtr, - std::vector<std::string> > + std::vector<ModuleUid> > AppsModules; /** @@ -104,11 +106,16 @@ class InteriorDataManagerImpl : public InteriorDataManager { */ AppsModules AppsSubscribedModules(); + typedef std::map<application_manager::ApplicationSharedPtr, + std::vector<std::string> > + AppsModuleTypes; + AppsModuleTypes AppsSubscribedModuleTypes(); + /** * @brief RequestsToHMIHistory mapping from module type to vector of time * stamps */ - typedef std::map<std::string, std::deque<date_time::TimeDuration> > + typedef std::map<ModuleUid, std::deque<date_time::TimeDuration> > RequestsToHMIHistory; RequestsToHMIHistory requests_to_hmi_history_; mutable sync_primitives::Lock requests_to_hmi_history_lock_; diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_app_extension.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_app_extension.h index 36fe9f5bdb..33271e64fd 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_app_extension.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_app_extension.h @@ -40,6 +40,103 @@ #include "utils/macro.h" namespace rc_rpc_plugin { + +typedef std::pair<std::string, std::string> ModuleUid; + +struct Grid { + int32_t col_; + int32_t row_; + int32_t level_; + int32_t colspan_; + int32_t rowspan_; + int32_t levelspan_; + + Grid() + : col_(0), row_(0), level_(0), colspan_(0), rowspan_(0), levelspan_(0) {} + + Grid(int32_t col, + int32_t row, + int32_t level, + int32_t colspan, + int32_t rowspan, + int32_t levelspan) + : col_(col) + , row_(row) + , level_(level) + , colspan_(colspan) + , rowspan_(rowspan) + , levelspan_(levelspan) {} + + Grid& operator=(const Grid& grid) { + col_ = grid.col_; + row_ = grid.row_; + level_ = grid.level_; + colspan_ = grid.colspan_; + rowspan_ = grid.rowspan_; + levelspan_ = grid.levelspan_; + + return *this; + } + + bool operator==(const Grid& grid) const { + return col_ == grid.col_ && row_ == grid.row_ && level_ == grid.level_ && + colspan_ == grid.colspan_ && rowspan_ == grid.rowspan_ && + levelspan_ == grid.levelspan_; + } + + /** + * @brief LevelIntersectionExists checks if the grids have an + * intersection by levels. + * @param grid with which to check intersection + * @return true if intersection exists, otherwise - false + */ + bool LevelIntersectionExists(const Grid& grid) const { + const int32_t top_level = (level_ + levelspan_) - 1; + const int32_t grid_top_level = (grid.level_ + grid.levelspan_) - 1; + + const int32_t min_level = std::max(level_, grid.level_); + const int32_t max_level = std::min(top_level, grid_top_level); + if ((max_level - min_level) < 0) { + return false; + } + return true; + } + + /** + * @brief IntersectionExists checks if the grids have an + * intersection. Grid can be represented by its bottom-left + * and top-right coordinates like a rectangle. First, the + * coordinates of the intersection are calculated, then checked + * that the rectangle which is formed by the intersections of two + * grids has non-zero width and height. + * @param grid with which to check intersection + * @return true if intersection exists, otherwise - false + */ + bool IntersectionExists(const Grid& grid) const { + if (!LevelIntersectionExists(grid)) { + return false; + } + + const int32_t right_top_col = (col_ + colspan_) - 1; + const int32_t right_top_row = (row_ + rowspan_) - 1; + const int32_t grid_right_top_col = (grid.col_ + grid.colspan_) - 1; + const int32_t grid_right_top_row = (grid.row_ + grid.rowspan_) - 1; + + const int32_t left = std::max(col_, grid.col_); + const int32_t bottom = std::max(row_, grid.row_); + const int32_t right = std::min(right_top_col, grid_right_top_col); + const int32_t top = std::min(right_top_row, grid_right_top_row); + + const int32_t width = right - left; + const int32_t height = top - bottom; + + if ((width < 0) || (height < 0)) { + return false; + } + return true; + } +}; + class RCAppExtension : public application_manager::AppExtension { public: explicit RCAppExtension(application_manager::AppExtensionUID uid); @@ -49,13 +146,15 @@ class RCAppExtension : public application_manager::AppExtension { * @brief Subscribe to OnInteriorVehicleDataNotification * @param module interior data specification(zone, data type) */ - void SubscribeToInteriorVehicleData(const std::string& module_type); + void SubscribeToInteriorVehicleData(const ModuleUid& module); /** * @brief Unsubscribe from OnInteriorVehicleDataNotification * @param module interior data specification(zone, data type) */ - void UnsubscribeFromInteriorVehicleData(const std::string& module_type); + void UnsubscribeFromInteriorVehicleData(const ModuleUid& module); + + void UnsubscribeFromInteriorVehicleDataOfType(const std::string& module_type); /** * @brief UnsubscribeFromInteriorVehicleData removes all subscriptions for @@ -67,16 +166,40 @@ class RCAppExtension : public application_manager::AppExtension { * @brief Check if application subscribed to OnInteriorVehicleDataNotification * @param module interior data specification(zone, data type) */ - bool IsSubscibedToInteriorVehicleData(const std::string& module_type); + bool IsSubscribedToInteriorVehicleData(const ModuleUid& module); + + bool IsSubscribedToInteriorVehicleDataOfType(const std::string& module_type); /** * @brief get list of subscriptions of application * @return list of subscriptions of application */ - std::set<std::string> InteriorVehicleDataSubscriptions() const; + std::set<ModuleUid> InteriorVehicleDataSubscriptions() const; + + /** + * @brief GetUserLocation + * @return grid of user location + */ + Grid GetUserLocation() const; + + /** + * @brief SetUserLocation sets user location + * from object to the grid + * @param user_location smart object for user_location + */ + void SetUserLocation( + const ns_smart_device_link::ns_smart_objects::SmartObject& user_location); + + /** + * @brief SetUserLocation sets user location from grid + * @param grid grid of user_location + */ + void SetUserLocation(const Grid& grid); private: - std::set<std::string> subscribed_interior_vehicle_data_; + std::set<ModuleUid> subscribed_interior_vehicle_data_; + + Grid user_location_; // AppExtension interface public: diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_capabilities_manager.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_capabilities_manager.h new file mode 100644 index 0000000000..36fd8bbbf9 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_capabilities_manager.h @@ -0,0 +1,184 @@ +/* + 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_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_RC_CAPABILITIES_MANAGER_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_RC_CAPABILITIES_MANAGER_H_ +#include "application_manager/application_manager.h" +#include "rc_rpc_plugin/resource_allocation_manager.h" + +namespace rc_rpc_plugin { + +enum capabilitiesStatus { success, missedLightName, missedParam, readOnly }; +typedef std::pair<std::string, capabilitiesStatus> ModuleTypeCapability; + +class RCCapabilitiesManager { + public: + /** + * @brief CheckIfButtonExistInRCCaps checks if the + * specified button exists in rc_capabilities + * @param button button name + * @return true if present, otherwise - false + */ + virtual bool CheckIfButtonExistInRCCaps( + const mobile_apis::ButtonName::eType button) const = 0; + + /** + * @brief CheckButtonName checks if the button + * corresponds to the module_type + * @param module_type resource name + * @param button_name button name + * @return true if they match, otherwise - false + */ + virtual bool CheckButtonName(const std::string& module_type, + const std::string& button_name) const = 0; + + /** + * @brief CheckIfModuleExistsInCapabilities checks + * if the specified module exists in rc_capabilities + * @param module moduleType + moduleId + * @return true if exists, otherwise - false + */ + virtual bool CheckIfModuleExistsInCapabilities( + const ModuleUid& module) const = 0; + + /** + * @brief GetModuleDataCapabilities checks whether rc module data + * capabilities are presented + * @param module_data smart object of module_data + * @param module_id module id + * @return pair of state and capability status - ModuleCapability + */ + virtual ModuleTypeCapability GetModuleDataCapabilities( + const smart_objects::SmartObject& module_data, + const std::string& module_id) const = 0; + + /** + * @brief ControlData retrieves control data + * for specified module type + * @param module_data smart object of module_data + * @param module_type resource name + * @return smart object of control data + */ + virtual const smart_objects::SmartObject& ControlDataForType( + const smart_objects::SmartObject& module_data, + const std::string& module_type) const = 0; + + /** + * @brief AreReadOnlyParamsPresent checks if there are + * any read only params in the module data + * @param module_data smart object of module_data + * @param module_type resource name + * @param module_data_capabilities smart object of capabilities + * @return true if read only params exist, otherwise - false + */ + virtual bool AreReadOnlyParamsPresent( + const smart_objects::SmartObject& module_data, + const std::string& module_type, + ModuleTypeCapability& module_data_capabilities) const = 0; + + /** + * @brief AreAllParamsReadOnly checks that all params from module + * data are read only + * @param module_data smart object of module_data + * @param module_type resource name + * @return true if all params are read only, otherwise - false + */ + virtual bool AreAllParamsReadOnly( + const smart_objects::SmartObject& module_data, + const std::string& module_type) const = 0; + + /** + * @brief GetDefaultModuleIdFromCapabilities returns the moduleId + * from the first item published by xyz-ControlCapabilities + * @param module_type resource name + * @return default module id from HMI capabilities + */ + virtual const std::string GetDefaultModuleIdFromCapabilities( + const std::string& module_type) const = 0; + + /** + * @brief GetResources get list of ModuleUids(moduleType + moduleId) + * of all known resources + * @return vector contains all known moduleUids + */ + virtual const std::vector<ModuleUid> GetResources() const = 0; + + /** + * @brief GetModuleServiceArea retrieves service area of module, + * if module serviceArea is missed in capabilities, serviceArea is + * assumed to be the same as location, if location + * is missed in capabilities, it is assumed that serviceArea covers + * the whole area of vehicle + * @param module module type + module id + * @return Grid of module service area + */ + virtual Grid GetModuleServiceArea(const ModuleUid& module) const = 0; + + /** + * @brief IsMultipleAccessAllowed checks if multiple access allowed + * for requested module + * @param module module type + module id + * @return true if allowed, otherwise - false + */ + virtual bool IsMultipleAccessAllowed(const ModuleUid& module) const = 0; + + /** + * @brief GetDriverLocationFromSeatLocationCapability retrieves the driver's + * location from seat location capabilities + * @return Grid of driver's location + */ + virtual const Grid GetDriverLocationFromSeatLocationCapability() const = 0; + + /** + * @brief IsSeatLocationCapabilityProvided checks whether all necessary + * parameters are provided in seat location capabilities + * @return true if provided, otherwise - false + */ + virtual bool IsSeatLocationCapabilityProvided() const = 0; + + /** + * @brief GetModuleIdForSeatLocation returns the moduleId if request from + * mobile contains the id parameter and doesn't contain the moduleId + * parameter. If the vehicle support at least one seat control, seat control + * capability includes at least two items. SupportedSeat id shall be converted + * to the moduleId according to capabilities: 1st item from capabilities for + * driver’s seat. 2nd item for front passenger’s seat. + * @param id supported seat id + */ + virtual const std::string GetModuleIdForSeatLocation( + mobile_apis::SupportedSeat::eType id) const = 0; + + virtual ~RCCapabilitiesManager() {} +}; + +} // namespace rc_rpc_plugin +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_RC_CAPABILITIES_MANAGER_H_ diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_capabilities_manager_impl.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_capabilities_manager_impl.h new file mode 100644 index 0000000000..844647940f --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_capabilities_manager_impl.h @@ -0,0 +1,200 @@ +/* + 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_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_RC_CAPABILITIES_MANAGER_IMPL_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_RC_CAPABILITIES_MANAGER_IMPL_H_ +#include "application_manager/application_manager.h" +#include "rc_rpc_plugin/rc_capabilities_manager.h" + +namespace rc_rpc_plugin { +class RCCapabilitiesManagerImpl : public RCCapabilitiesManager { + public: + RCCapabilitiesManagerImpl( + application_manager::HMICapabilities& hmi_capabilities); + + bool CheckIfButtonExistInRCCaps( + const mobile_apis::ButtonName::eType button) const FINAL; + + bool CheckButtonName(const std::string& module_type, + const std::string& button_name) const FINAL; + + bool CheckIfModuleExistsInCapabilities(const ModuleUid& module) const FINAL; + + ModuleTypeCapability GetModuleDataCapabilities( + const smart_objects::SmartObject& module_data, + const std::string& module_id) const FINAL; + + const smart_objects::SmartObject& ControlDataForType( + const smart_objects::SmartObject& module_data, + const std::string& module_type) const FINAL; + + bool AreReadOnlyParamsPresent( + const smart_objects::SmartObject& module_data, + const std::string& module_type, + ModuleTypeCapability& module_data_capabilities) const FINAL; + + bool AreAllParamsReadOnly(const smart_objects::SmartObject& module_data, + const std::string& module_type) const FINAL; + + const std::string GetDefaultModuleIdFromCapabilities( + const std::string& module_type) const FINAL; + + const std::vector<ModuleUid> GetResources() const FINAL; + + Grid GetModuleServiceArea(const ModuleUid& module) const FINAL; + + bool IsMultipleAccessAllowed(const ModuleUid& module) const FINAL; + + const Grid GetDriverLocationFromSeatLocationCapability() const FINAL; + + bool IsSeatLocationCapabilityProvided() const FINAL; + + const std::string GetModuleIdForSeatLocation( + mobile_apis::SupportedSeat::eType id) const FINAL; + + private: + const std::map<std::string, std::string> GetLightCapabilitiesMapping() const; + + const std::map<std::string, std::string> GetModuleDataToCapabilitiesMapping() + const; + + /** + * @brief Check whether the exists light data related to correspondent + * capabilities + * @param capabilities smart object of capabilities + * @param control_data smart object of control_data + * @return pair of state and capability status - ModuleTypeCapability + */ + ModuleTypeCapability GetControlDataCapabilities( + const smart_objects::SmartObject& capabilities, + const smart_objects::SmartObject& control_data) const; + + /** + * @brief Check whether the parameter exist in capabilities + * @param capabilities smart object of capabilities + * @param mapping - map of module data and capabilities + * @param request_parameter - string + * @param switched_off_result - ref of mobile_apis::Result + * @return success if the parameter exists in capabilities, + * otherwise - missedParam + */ + capabilitiesStatus GetItemCapability( + const smart_objects::SmartObject& capabilities, + const std::map<std::string, std::string>& mapping, + const std::string& request_parameter, + const mobile_apis::Result::eType& switched_off_result) const; + + /** + * @brief Check whether the capabilities for light are allowed + * @param capabilities smart object of capabilities + * @param control_data smart object of control_data + * @return pair of state and capability status - ModuleTypeCapability + */ + ModuleTypeCapability GetLightDataCapabilities( + const smart_objects::SmartObject& capabilities, + const smart_objects::SmartObject& control_data) const; + + /** + * @brief Check whether the light name exists in capabilities + * @param capabilities_status smart object of capabilities_status + * @param light_data smart object of light_data + * @return pair of state and capability status - ModuleTypeCapability + */ + ModuleTypeCapability GetLightNameCapabilities( + const smart_objects::SmartObject& capabilities_status, + const smart_objects::SmartObject& light_data) const; + + ModuleTypeCapability GetRadioBandByCapabilities( + const smart_objects::SmartObject& capabilities_status, + const smart_objects::SmartObject& request_parameter) const; + + bool CheckReadOnlyParamsForAudio( + const smart_objects::SmartObject& module_type_params) const; + + bool CheckReadOnlyParamsForLight( + const smart_objects::SmartObject& module_type_params) const; + + smart_objects::SmartObject GetCapabilitiesByModuleIdFromArray( + const smart_objects::SmartObject& module_data_capabilities, + const std::string& module_id) const; + + const bool CheckModuleIdWithCapabilities( + const smart_objects::SmartObject& rc_capabilities, + const ModuleUid& module) const; + + const bool CheckModuleIdWithCapabilitiesArrays( + const smart_objects::SmartObject& control_capabilities, + const std::string& module_id) const; + + const bool CheckModuleIdWithCapabilitiesStructure( + const smart_objects::SmartObject& control_capabilities, + const std::string& module_id) const; + + const std::string GetDefaultModuleIdFromCapabilitiesStructure( + const smart_objects::SmartObject& control_capabilities, + const std::string& module_type) const; + + const std::string GetDefaultModuleIdFromCapabilitiesArray( + const smart_objects::SmartObject& control_capabilities, + const std::string& module_type) const; + + const std::vector<std::string> GetCapabilitiesList() const; + + const std::function<std::string(const std::string& control_cap)> + GetCapabilitiesToModuleTypeMapping() const; + + void GetResourcesFromCapabilitiesStructure( + const smart_objects::SmartObject& control_capabilities, + const std::string& capabitity_key, + std::vector<ModuleUid>& out_resources) const; + + void GetResourcesFromCapabilitiesArray( + const smart_objects::SmartObject& control_capabilities, + const std::string& capability_key, + std::vector<ModuleUid>& out_resources) const; + + Grid GetModuleServiceAreaFromControlCapability( + const smart_objects::SmartObject& control_capabilities) const; + + Grid GetModuleLocationFromControlCapability( + const smart_objects::SmartObject& control_capabilities) const; + + bool IsMultipleAccessAllowedInControlCaps( + const smart_objects::SmartObject& control_capabilities) const; + + Grid GetWholeVehicleArea() const; + + application_manager::HMICapabilities& hmi_capabilities_; +}; + +} // namespace rc_rpc_plugin +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_RC_CAPABILITIES_MANAGER_IMPL_H_ diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_consent_manager.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_consent_manager.h new file mode 100644 index 0000000000..c8b99cc724 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_consent_manager.h @@ -0,0 +1,91 @@ +/* + * 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_RC_RPC_PLUGIN_INCLUDE_RC_CONSENT_MANAGER_H +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_CONSENT_MANAGER_H + +#include <string> + +#include "rc_rpc_types.h" + +namespace ns_smart_device_link { +namespace ns_smart_objects { +class SmartObject; +} // namespace ns_smart_objects +} // namespace ns_smart_device_link + +namespace rc_rpc_plugin { + +class RCConsentManager { + public: + /** + * @brief Saves consents (is_consented + date_of_consent) for module resources + * (module_type + module_id) for specified application + * @param policy_app_id Application id which module consents should be saved + * @param mac_address Device mac address + * @param module_consents - Module resources consents + */ + virtual void SaveModuleConsents( + const std::string& policy_app_id, + const std::string& mac_address, + const rc_rpc_types::ModuleIdConsentVector& module_consents) = 0; + + /** + * @brief Retrieves saved consent for specified module resource (module_type + * + module_id) + * @param app_id Application which related to specified module resource + * @param mac_address Device mac address + * @param module_id Module resource (module_type + module_id) + * @return Module consent state + */ + virtual rc_rpc_plugin::rc_rpc_types::ModuleConsent GetModuleConsent( + const std::string& app_id, + const std::string& mac_address, + const rc_rpc_types::ModuleUid& module_id) = 0; + + /** + * @brief Remove modules consents from LastState if they exist + */ + virtual void RemoveAllConsents() = 0; + + /** + * @brief Remove all expired module consents from LastState + * if they exist + */ + virtual void RemoveExpiredConsents() = 0; + + virtual ~RCConsentManager() {} +}; + +} // namespace rc_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_CONSENT_MANAGER_H 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 new file mode 100644 index 0000000000..5cbc4b977e --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_consent_manager_impl.h @@ -0,0 +1,178 @@ +/* + * 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_RC_RPC_PLUGIN_INCLUDE_RC_CONSENT_MANAGER_IMPL_H +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_CONSENT_MANAGER_IMPL_H + +#include "rc_consent_manager.h" +#include "resumption/last_state_wrapper.h" +#include "utils/lock.h" + +namespace Json { +class Value; +} // namespace Json + +namespace rc_rpc_plugin { + +class RCConsentManagerImpl : public RCConsentManager { + public: + RCConsentManagerImpl( + resumption::LastStateWrapperPtr last_state, + 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, + const rc_rpc_types::ModuleIdConsentVector& module_consents) OVERRIDE; + + rc_rpc_types::ModuleConsent GetModuleConsent( + const std::string& app_id, + const std::string& mac_address, + const rc_rpc_types::ModuleUid& module_id) OVERRIDE; + + void RemoveExpiredConsents() OVERRIDE; + + void RemoveAllConsents() OVERRIDE; + + ~RCConsentManagerImpl() OVERRIDE; + + private: + /** + * @brief Saves module consents for specified application + * @param app_module_consents Application consents for which new + * consents should be added or existing ones should be overwritten + * @param consent_to_save module consents which should be saved + */ + void SaveAppModuleConsent( + Json::Value& app_module_consents, + const rc_rpc_types::ModuleIdConsent& consent_to_save); + + /** + * @brief Checks if module consent is expired + * @param module_consent Module consent + * @return ModuleConsentState + */ + rc_rpc_types::ModuleConsentState CheckModuleConsentState( + const Json::Value& module_consent) const; + + /** + * @brief Removes devices expired consents + * @param device Device section in AppConsensts section of LastState in Json + */ + void RemoveDeviceExpiredConsents(Json::Value& device); + + /** + * @brief Remove expired module consents which are related to specified + * application + * @param app_consents Application consents + */ + void RemoveAppExpiredConsents(Json::Value& app_consents); + + /** + * @brief Remove expired module consents which are related to specified + * module type + * @param module_consents Module consents wich should be checked for expired + * consents + */ + void RemoveModuleExpiredConsents(Json::Value& module_consents); + + /** + * @brief Get Remote Control section of LastState. + * In case the section is absent, will be appended a new empty section. + * @return Remote Control section of LastState in Json + */ + Json::Value& GetRemoteControlDataOrAppend(Json::Value& last_state_data); + + /** + * @brief Gets Device applications section for specified device mac adress + * In case the section is absent, will be appended a new empty section. + * @param mac_aress Device MAC adress + * @return Device applications section of LastState in Json + */ + Json::Value& GetDeviceApplicationsOrAppend(const std::string& mac_address, + Json::Value& last_state_data); + + /** + * @brief Get AppConsentsList section of LastState for specified application. + * In case the consent list is absent, will be appended a new empty section. + * @param policy_app_id Application policy ID + * @param mac_address Device MAC address + * @return AppConsentsList of LastState in Json + */ + Json::Value& GetAppConsentsListOrAppend(const std::string& policy_app_id, + const std::string& mac_address, + Json::Value& last_state_data); + + /** + * @brief Get Application consents section of Remote Control section of + * LastState with all consents for all applications. In case if this section + * is absent, will be created a new empty section + * @return AppConsents section of RemoteControl section of LastState in Jason + */ + Json::Value& GetAppsConsentsOrAppend(Json::Value& last_state_data); + + /** + * @brief Get all module resource consents for specified application and + * module type. In case if section with specified module type consents is + * absent, will be created a new empty section + * @param policy_app_id Application id which contains specified module type + * @param mac_adress MAC address of mobile device that needs user consent for + * acquiring resource + * @param module_type Module type with consents + */ + Json::Value& GetModuleTypeConsentsOrAppend(const std::string& policy_app_id, + const std::string& mac_address, + const std::string& module_type, + Json::Value& last_state_data); + + private: + application_manager::ApplicationManager& app_manager_; + resumption::LastStateWrapperPtr last_state_; + const uint32_t period_of_consent_expired_; + mutable sync_primitives::Lock dictionary_control_lock_; + mutable sync_primitives::Lock remote_control_lock_; + mutable sync_primitives::Lock device_applications_lock_; + mutable sync_primitives::Lock applications_lock_; + mutable sync_primitives::Lock app_consents_lock_; + mutable sync_primitives::Lock module_consents_lock_; +}; + +} // namespace rc_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_CONSENT_MANAGER_IMPL_H diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_helpers.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_helpers.h index e85ab758ad..eed860fc7f 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_helpers.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_helpers.h @@ -37,6 +37,7 @@ #include <string> #include "application_manager/application.h" #include "rc_rpc_plugin/rc_app_extension.h" +#include "rc_rpc_plugin/rc_rpc_types.h" namespace rc_rpc_plugin { class RCRPCPlugin; @@ -65,10 +66,10 @@ class RCHelpers { GetModuleTypeToCapabilitiesMapping(); /** - * @brief GetModulesList get list of all known modules - * @return vector contains all known modules + * @brief GetModuleTypesList get list of all known module types + * @return vector contains all known module types */ - static const std::vector<std::string> GetModulesList(); + static const std::vector<std::string> GetModuleTypesList(); /** * @brief GetRCExtension extract RC extension from application @@ -80,7 +81,11 @@ class RCHelpers { application_manager::Application& app); static smart_objects::SmartObjectSPtr CreateUnsubscribeRequestToHMI( - const std::string& module_type, const uint32_t correlation_id); + const ModuleUid& module, const uint32_t correlation_id); + + static std::vector<application_manager::ApplicationSharedPtr> + AppsSubscribedToModule(application_manager::ApplicationManager& app_mngr, + const ModuleUid& module); static std::vector<application_manager::ApplicationSharedPtr> AppsSubscribedToModuleType(application_manager::ApplicationManager& app_mngr, @@ -88,10 +93,51 @@ class RCHelpers { typedef std::map<application_manager::ApplicationSharedPtr, std::vector<std::string> > - AppsModules; - static AppsModules GetApplicationsAllowedModules( + AppsModuleTypes; + + static AppsModuleTypes GetApplicationsAllowedModuleTypes( application_manager::ApplicationManager& app_mngr); + typedef std::map<std::string, mobile_apis::ButtonName::eType> ButtonsMap; + + static const std::vector<std::string> buttons_climate(); + + static const std::vector<std::string> buttons_radio(); + + static const ButtonsMap buttons_map(); + + static std::vector<std::string> GetModuleReadOnlyParams( + const std::string& module_type); + + /** + * @brief Combines module ids and alloweds for these ids and fills vector with + * ModuleConsents + * @param module_type Module type as string + * @param module_ids Modules ids which needed consents from driver + * @param allowed Consents for modules + */ + static rc_rpc_types::ModuleIdConsentVector FillModuleConsents( + const std::string& module_type, + const std::vector<std::string>& module_ids, + const std::vector<bool> allowed); + + /** + * @brief Retrieves module ids from SmartObject. + * @param moduleIds Smartobject which contains collection of module ids + * @return Collection of module ids + */ + static std::vector<std::string> RetrieveModuleIds( + const smart_objects::SmartObject& moduleIds); + + /** + * @brief Retrieves module ids consents from SmartObject. + * @param moduleIds Smartobject which contains collection of module ids + * consents + * @return Collection of module ids consents. + */ + static std::vector<bool> RetrieveModuleConsents( + const smart_objects::SmartObject& consents); + /** * @brief RemoveRedundantGPSDataFromVIDataMsg removes redundant GPS data * params from interior vehicle data response message if one contains radio @@ -100,6 +146,29 @@ class RCHelpers { */ static void RemoveRedundantGPSDataFromIVDataMsg( smart_objects::SmartObject& msg_params); + + /** + * @brief MergeModuleData all keys and values from first parameter and + * update and append keys and values from the second + * @param data1 - initial data + * @param data2 - updated data + * @return updated data1 with data2 keys and values + */ + static smart_objects::SmartObject MergeModuleData( + const smart_objects::SmartObject& data1, + const smart_objects::SmartObject& data2); + + /** + * @brief MergeArray merge two arrays if their elements contain an `id` + * parameter + * @param data1 - initial data + * @param data2 - updated data + * @return updated data1 with any values in data2 if the arrays can be merged, + * otherwise data2 + */ + static smart_objects::SmartObject MergeArray( + const smart_objects::SmartObject& data1, + const smart_objects::SmartObject& data2); }; } // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_module_constants.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_module_constants.h index b9f922a1be..5ee2e0725c 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_module_constants.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_module_constants.h @@ -46,10 +46,43 @@ const char khmiSettingsControlCapabilities[] = "hmiSettingsControlCapabilities"; const char kseatControlCapabilities[] = "seatControlCapabilities"; // RemoteControlCapabilities constants -const char kRadioControlData[] = "radioControlData"; -const char kClimateControlData[] = "climateControlData"; +const char kServiceArea[] = "serviceArea"; +const char kLocation[] = "location"; +const char kCol[] = "col"; +const char kRow[] = "row"; +const char kLevel[] = "level"; +const char kColspan[] = "colspan"; +const char kRowspan[] = "rowspan"; +const char kLevelspan[] = "levelspan"; + +// SeatLocationCapability constants +const char kCols[] = "columns"; +const char kRows[] = "rows"; +const char kLevels[] = "levels"; +const char kSeats[] = "seats"; +const char kGrid[] = "grid"; +// SeatLocationCapability constants + +const char kAllowMultipleAccess[] = "allowMultipleAccess"; + const char kSupportedLights[] = "supportedLights"; +// ClimateControlCapabilities +const char kFanSpeedAvailable[] = "fanSpeedAvailable"; +const char kCurrentTemperatureAvailable[] = "currentTemperatureAvailable"; +const char kDesiredTemperatureAvailable[] = "desiredTemperatureAvailable"; +const char kAcEnableAvailable[] = "acEnableAvailable"; +const char kCirculateAirEnableAvailable[] = "circulateAirEnableAvailable"; +const char kAutoModeEnableAvailable[] = "autoModeEnableAvailable"; +const char kDefrostZoneAvailable[] = "defrostZoneAvailable"; +const char kDualModeEnableAvailable[] = "dualModeEnableAvailable"; +const char kAcMaxEnableAvailable[] = "acMaxEnableAvailable"; +const char kVentilationModeAvailable[] = "ventilationModeAvailable"; +const char kHeatedSteeringWheelAvailable[] = "heatedSteeringWheelAvailable"; +const char kHeatedWindshieldAvailable[] = "heatedWindshieldAvailable"; +const char kHeatedMirrorsAvailable[] = "heatedMirrorsAvailable"; +const char kHeatedRearWindowAvailable[] = "heatedRearWindowAvailable"; + // LightControlCapabilities const char kName[] = "name"; const char kStatusAvailable[] = "statusAvailable"; @@ -57,7 +90,50 @@ const char kDensityAvailable[] = "densityAvailable"; const char kRGBColorSpaceAvailable[] = "rgbColorSpaceAvailable"; // RadioControlCapabilities +const char kRadioBandAvailable[] = "radioBandAvailable"; +const char kRadioFrequencyAvailable[] = "radioFrequencyAvailable"; +const char kRdsDataAvailable[] = "rdsDataAvailable"; +const char kAvailableHDsAvailable[] = "availableHDsAvailable"; +const char kHdRadioEnableAvailable[] = "hdRadioEnableAvailable"; +const char kSignalStrengthAvailable[] = "signalStrengthAvailable"; +const char kSignalChangeThresholdAvailable[] = "signalChangeThresholdAvailable"; +const char kRadioEnableAvailable[] = "radioEnableAvailable"; +const char kStateAvailable[] = "stateAvailable"; +const char kSisDataAvailable[] = "sisDataAvailable"; + const char kSiriusxmRadioAvailable[] = "siriusxmRadioAvailable"; + +// SeatControlCapabilities +const char kHeatingEnabledAvailable[] = "heatingEnabledAvailable"; +const char kCoolingEnabledAvailable[] = "coolingEnabledAvailable"; +const char kHeatingLevelAvailable[] = "heatingLevelAvailable"; +const char kCoolingLevelAvailable[] = "coolingLevelAvailable"; +const char kHorizontalPositionAvailable[] = "horizontalPositionAvailable"; +const char kVerticalPositionAvailable[] = "verticalPositionAvailable"; +const char kFrontVerticalPositionAvailable[] = "frontVerticalPositionAvailable"; +const char kBackVerticalPositionAvailable[] = "backVerticalPositionAvailable"; +const char kBackTiltAngleAvailable[] = "backTiltAngleAvailable"; +const char kHeadSupportHorizontalPositionAvailable[] = + "headSupportHorizontalPositionAvailable"; +const char kHeadSupportVerticalPositionAvailable[] = + "headSupportVerticalPositionAvailable"; +const char kMassageEnabledAvailable[] = "massageEnabledAvailable"; +const char kMassageModeAvailable[] = "massageModeAvailable"; +const char kMassageCushionFirmnessAvailable[] = + "massageCushionFirmnessAvailable"; +const char kMemoryAvailable[] = "memoryAvailable"; + +// AudioControlCapabilities +const char kSourceAvailable[] = "sourceAvailable"; +const char kKeepContextAvailable[] = "keepContextAvailable"; +const char kVolumeAvailable[] = "volumeAvailable"; +const char kEqualizerAvailable[] = "equalizerAvailable"; + +// HmiSettingsCapabilities +const char kDistanceUnitAvailable[] = "distanceUnitAvailable"; +const char kTemperatureUnitAvailable[] = "temperatureUnitAvailable"; +const char kDisplayModeUnitAvailable[] = "displayModeUnitAvailable"; + } // namespace strings namespace result_codes { @@ -106,6 +182,20 @@ namespace message_params { const char kName[] = "name"; const char kId[] = "id"; +// RCConsentManager, ResumptionCtrl, GetInteriorVehicleDataConsent request +const char kModuleId[] = "moduleId"; +const char kModuleInfo[] = "moduleInfo"; +const char kAppConsents[] = "appConsents"; +const char kAppConsentList[] = "appConsentsList"; +const char kConsent[] = "consent"; +const char kConsentDate[] = "consentDate"; +const char kModuleConsents[] = "moduleConsents"; +const char kAppId[] = "appId"; +const char kModuleIds[] = "moduleIds"; +const char kMacAddress[] = "macAddress"; +const char kApplications[] = "applications"; +// RCConsentManager, ResumptionCtrl, GetInteriorVehicleDataConsent request + // SetInteriorVehicleData request const char kModuleData[] = "moduleData"; // SetInteriorVehicleData request @@ -153,6 +243,7 @@ const char kRdsData[] = "rdsData"; const char kHdRadioEnable[] = "hdRadioEnable"; const char kAvailableHDs[] = "availableHDs"; const char kAvailableHdChannels[] = "availableHdChannels"; +const char kAvailableHdChannelsAvailable[] = "availableHdChannelsAvailable"; const char kHdChannel[] = "hdChannel"; const char kSignalStrength[] = "signalStrength"; const char kSignalChangeThreshold[] = "signalChangeThreshold"; @@ -181,6 +272,23 @@ const char kClimateEnable[] = "climateEnable"; const char kClimateEnableAvailable[] = "climateEnableAvailable"; // ClimateControlData struct +// SeatControlData +const char kHeatingEnabled[] = "heatingEnabled"; +const char kCoolingEnabled[] = "coolingEnabled"; +const char kHeatingLevele[] = "heatingLevel"; +const char kCoolingLevel[] = "coolingLevel"; +const char kHorizontalPosition[] = "horizontalPosition"; +const char kVerticalPosition[] = "verticalPosition"; +const char kFrontVerticalPosition[] = "frontVerticalPosition"; +const char kBackVerticalPosition[] = "backVerticalPosition"; +const char kBackTiltAngle[] = "backTiltAngle"; +const char kHeadSupportHorizontalPosition[] = "headSupportHorizontalPosition"; +const char kHeadSupportVerticalPosition[] = "headSupportVerticalPosition"; +const char kMassageEnabled[] = "massageEnabled"; +const char kMassageMode[] = "massageMode"; +const char kMassageCushionFirmness[] = "massageCushionFirmness"; +const char kMemory[] = "memory"; + // LightControlData const char kLightState[] = "lightState"; const char kLightStatus[] = "status"; @@ -189,10 +297,15 @@ const char kLightColor[] = "color"; // AudioControlData const char kSource[] = "source"; +const char kVolume[] = "volume"; const char kKeepContext[] = "keepContext"; const char kEqualizerSettings[] = "equalizerSettings"; const char kChannelName[] = "channelName"; +// HmiSettingsControlData +const char kDistanceUnit[] = "distanceUnit"; +const char kDisplayMode[] = "displayMode"; + // ModuleData struct const char kRadioControlData[] = "radioControlData"; const char kClimateControlData[] = "climateControlData"; @@ -206,6 +319,15 @@ const char kHMIAppID[] = "appID"; const char kHmiLevel[] = "hmiLevel"; const char kSysContext[] = "systemContext"; const char kAudioState[] = "audioStreamingState"; + +// Grid struct +const char kCol[] = "col"; +const char kRow[] = "row"; +const char kLevel[] = "level"; +const char kColspan[] = "colspan"; +const char kRowspan[] = "rowspan"; +const char kLevelspan[] = "levelspan"; + } // namespace message_params namespace enums_value { 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 303b31f857..e12bd88e58 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 @@ -39,6 +39,8 @@ #include "application_manager/plugin_manager/rpc_plugin.h" #include "rc_rpc_plugin/interior_data_cache.h" #include "rc_rpc_plugin/interior_data_manager.h" +#include "rc_rpc_plugin/rc_capabilities_manager.h" +#include "rc_rpc_plugin/rc_consent_manager.h" #include "rc_rpc_plugin/resource_allocation_manager.h" namespace rc_rpc_plugin { @@ -58,7 +60,15 @@ class RCRPCPlugin : public plugins::RPCPlugin { bool Init(app_mngr::ApplicationManager& app_manager, app_mngr::rpc_service::RPCService& rpc_service, app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) OVERRIDE; + 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 @@ -101,13 +111,16 @@ class RCRPCPlugin : public plugins::RPCPlugin { private: application_manager::rpc_service::RPCService* rpc_service_; application_manager::ApplicationManager* app_mngr_; + std::unique_ptr<rc_rpc_plugin::RCConsentManager> rc_consent_manager_; std::unique_ptr<application_manager::CommandFactory> command_factory_; std::unique_ptr<ResourceAllocationManager> resource_allocation_manager_; std::unique_ptr<InteriorDataCache> interior_data_cache_; std::unique_ptr<InteriorDataManager> interior_data_manager_; + std::unique_ptr<RCCapabilitiesManager> rc_capabilities_manager_; }; } // namespace rc_rpc_plugin extern "C" application_manager::plugin_manager::RPCPlugin* Create(); +extern "C" void Delete(application_manager::plugin_manager::RPCPlugin* data); #endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_RC_RPC_PLUGIN_H_ diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_rpc_types.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_rpc_types.h new file mode 100644 index 0000000000..3698728aa6 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_rpc_types.h @@ -0,0 +1,91 @@ +/* + * 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_RC_RPC_PLUGIN_INCLUDE_RC_RPC_TYPES_H +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_RPC_TYPES_H + +#include <ctime> +#include <string> +#include <utility> +#include <vector> + +namespace resumption { +class LastState; +} // namespace resumption + +namespace application_manager { +class ApplicationManager; +} // namespace application_manager + +namespace rc_rpc_plugin { +namespace rc_rpc_types { +/** + * @brief Module resource (module_type(first) + module_id(second)) + */ +typedef std::pair<std::string, std::string> ModuleUid; + +/** + * @brief Module consent enum. + */ +enum class ModuleConsent { + NOT_EXISTS = 0, /**< Consent is absent for specified module resource */ + CONSENTED, /**< Module resource is consented */ + NOT_CONSENTED /**< Module resource isn't consented */ +}; + +enum class ModuleConsentState { + NOT_EXISTS = 0, /**< Consent is absent for specified module resource */ + EXPIRED, /**< Module resource is expired */ + ACTIVE /**< Module resource isn't expired */ +}; + +/** + * @brief Module consent + * @param module_id - Module resource for consent + * @param consent - Is module resource consented by driver + * @param date_of_consent - Date, when module resource has been consented (in + * seconds [UNIX time]) + */ +struct ModuleIdConsent { + ModuleUid module_id; + ModuleConsent consent; + std::time_t date_of_consent; +}; + +/** + * @brief ModuleIdConsent collection + */ +typedef std::vector<ModuleIdConsent> ModuleIdConsentVector; +} // namespace rc_rpc_types +} // namespace rc_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_RPC_TYPES_H 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 6dfc794648..ee0bd11885 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 @@ -69,55 +69,84 @@ enum eType { APP_REGISTRATION = 0, MODULE_ALLOCATION, RC_STATE_CHANGING }; } // namespace NotificationTrigger /** + * Defines result of releasing specified module type resource. + */ +namespace ResourceReleasedState { +/** + * NOT_ALLOCATED Module's resource is not allocated + * IS_ALLOCATED Module's resource is already allocated by + * different application + * IS_RELEASED Module's resource is released. + */ +enum eType { NOT_ALLOCATED = 0, IS_ALLOCATED, IS_RELEASED }; +} // namespace ResourceReleasedState + +/** + * @brief ModuleUid uniquely identify a module + * moduleType + moduleID + */ +typedef std::pair<std::string, std::string> ModuleUid; + +/** * @brief Resources defines list of resources */ -typedef std::vector<std::string> Resources; +typedef std::vector<ModuleUid> Resources; class ResourceAllocationManager { public: /** * @brief AcquireResource acquires resource by application * @param module_type resource to acquire + * @param module_id uuid of a resource * @param app_id application that acquire resource * @return ALLOWED if resource acquired \ * IN_USE if resource already acquired * ASK_DRIVER if driver confirmation is required */ virtual AcquireResult::eType AcquireResource(const std::string& module_type, + const std::string& module_id, const uint32_t app_id) = 0; /** * @brief SetResourceState changes resource state. Resource must be acquired * beforehand. * @param module_type Resource to change its state + * @param module_id uuid of a resource * @param app_id Application aquired resource before * @param state State to set for resource */ virtual void SetResourceState(const std::string& module_type, + const std::string& module_id, const uint32_t app_id, const ResourceState::eType state) = 0; /** * @brief IsResourceFree check resource state * @param module_type Resource name + * @param module_id uuid of a resource * @return True if free, otherwise - false */ - virtual bool IsResourceFree(const std::string& module_type) const = 0; + virtual bool IsResourceFree(const std::string& module_type, + const std::string& module_id) const = 0; /** * @brief AcquireResource forces acquiring resource by application * @param module_type resource to acquire + * @param module_id uuid of a resource * @param app_id application that acquire resource */ virtual void ForceAcquireResource(const std::string& module_type, + const std::string& module_id, const uint32_t app_id) = 0; /** * @brief OnDriverDisallowed callback for rejecting acquiring resource * @param module_type resource type + * @param module_id uuid of a resource * @param app_id application id */ virtual void OnDriverDisallowed(const std::string& module_type, + const std::string& module_id, const uint32_t app_id) = 0; /** @@ -171,6 +200,42 @@ class ResourceAllocationManager { virtual void set_rc_enabled(const bool value) = 0; + /** + * @brief ReleaseResource Releases resource acquired by application + * @param module_type Module name + * @param module_id uuid of a module + * @param application_id Application id + */ + virtual ResourceReleasedState::eType ReleaseResource( + const std::string& module_type, + const std::string& module_id, + const uint32_t application_id) = 0; + + /** + * @brief SetResourceAquired mark resourse as aquired and process logic of + * changing state of aquired resources + * @param module_type resource name + * @param module_id uuid of a resource + * @param app applicastion that aquire resource + */ + virtual void SetResourceAcquired(const std::string& module_type, + const std::string& module_id, + const uint32_t app_id) = 0; + + /** + * @brief Checks if specific resource is already aquired by specific + * application + * @param moduleUid Module resurce (module type + module ID) + * @param app_id Application ID which try to aquire resource + * @return true In case when resource is already aquired by specific + * application + * @return false In case when isn't aquired by specific + * application + */ + virtual bool IsResourceAlreadyAcquiredByApp( + const rc_rpc_plugin::ModuleUid& moduleUid, + const uint32_t app_id) const = 0; + virtual ~ResourceAllocationManager() {} }; 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 c0ef971235..0fd5449912 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 @@ -34,6 +34,7 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_RESOURCE_ALLOCATION_MANAGER_IMPL_H_ #include "application_manager/application_impl.h" #include "rc_rpc_plugin/rc_app_extension.h" +#include "rc_rpc_plugin/rc_capabilities_manager.h" #include "rc_rpc_plugin/resource_allocation_manager.h" #include "utils/lock.h" #include "utils/macro.h" @@ -46,43 +47,52 @@ class ResourceAllocationManagerImpl : public ResourceAllocationManager { public: ResourceAllocationManagerImpl( application_manager::ApplicationManager& app_mngr, - application_manager::rpc_service::RPCService& rpc_service); + application_manager::rpc_service::RPCService& rpc_service, + rc_rpc_plugin::RCCapabilitiesManager& rc_capabilities_manager); ~ResourceAllocationManagerImpl(); /** * @brief AcquireResource forces acquiring resource by application * @param module_type resource to acquire + * @param module_id uuid of a resource * @param app_id application that acquire resourc * @return result of acauiring resources */ AcquireResult::eType AcquireResource(const std::string& module_type, + const std::string& module_id, const uint32_t app_id) OVERRIDE FINAL; /** * @brief ForceAcquireResource forces acquiring resource by application * @param module_type resource to acquire + * @param module_id uuid of a resource * @param app_id application that acquire resource */ void ForceAcquireResource(const std::string& module_type, + const std::string& module_id, const uint32_t app_id) FINAL; /** * @brief SetResourceState changes resource state. Resource must be acquired * beforehand. * @param module_type Resource to change its state + * @param module_id uuid of a resource * @param app_id Application aquired resource before * @param state State to set for resource */ void SetResourceState(const std::string& module_type, + const std::string& module_id, const uint32_t app_id, const ResourceState::eType state) FINAL; /** * @brief IsResourceFree check resource state * @param module_type Resource name + * @param module_id uuid of a resource * @return True if free, otherwise - false */ - bool IsResourceFree(const std::string& module_type) const FINAL; + bool IsResourceFree(const std::string& module_type, + const std::string& module_id) const FINAL; void SetAccessMode( const hmi_apis::Common_RCAccessMode::eType access_mode) FINAL; @@ -90,6 +100,7 @@ class ResourceAllocationManagerImpl : public ResourceAllocationManager { hmi_apis::Common_RCAccessMode::eType GetAccessMode() const FINAL; void OnDriverDisallowed(const std::string& module_type, + const std::string& module_id, const uint32_t app_id) FINAL; /** @@ -118,6 +129,18 @@ class ResourceAllocationManagerImpl : public ResourceAllocationManager { void set_rc_enabled(const bool value) FINAL; + ResourceReleasedState::eType ReleaseResource( + const std::string& module_type, + const std::string& module_id, + const uint32_t application_id) FINAL; + + void SetResourceAcquired(const std::string& module_type, + const std::string& module_id, + const uint32_t app_id) FINAL; + + bool IsResourceAlreadyAcquiredByApp(const rc_rpc_plugin::ModuleUid& moduleUid, + const uint32_t app_id) const FINAL; + private: typedef std::vector<application_manager::ApplicationSharedPtr> Apps; @@ -137,20 +160,23 @@ class ResourceAllocationManagerImpl : public ResourceAllocationManager { * @brief IsModuleTypeRejected check if current resource was rejected by * driver for current application * @param module_type resource to check + * @param module_id uuid of a resource * @param app_id application id * @return true if current resource was rejected by driver for current * application, otherwise - false */ bool IsModuleTypeRejected(const std::string& module_type, + const std::string& module_id, const uint32_t app_id); /** - * @brief ReleaseResource Releases resource acquired by application + * @brief ReleaseModuleType Releases all resources related to + * the corresponding module type acquired by application * @param module_type Module name * @param application_id Application id */ - void ReleaseResource(const std::string& module_type, - const uint32_t application_id); + void ReleaseModuleType(const std::string& module_type, + const uint32_t application_id); /** * @brief GetAcquiredResources Provides resources acquired by particular @@ -161,6 +187,15 @@ class ResourceAllocationManagerImpl : public ResourceAllocationManager { Resources GetAcquiredResources(const uint32_t application_id) const; /** + * @brief GetAcquiredModuleTypes Provides module types acquired by particular + * application currently + * @param application_id Application id + * @return List of acquired module types by specific application + */ + std::set<std::string> GetAcquiredModuleTypes( + const uint32_t application_id) const; + + /** * @brief ProcessApplicationPolicyUpdate Checks if allowed modules list is * changed for registered RC applications and releases in case some modules * now out of the list @@ -175,33 +210,38 @@ class ResourceAllocationManagerImpl : public ResourceAllocationManager { void RemoveAppsSubscriptions(const Apps& apps); /** - * @brief SetResourceAquired mark resourse as aquired and process logic of + * @brief SetResourceFree mark resourse as free and process logic of * changing state of aquired resources * @param module_type resource name + * @param module_id uuid of a resource * @param app applicastion that aquire resource */ - void SetResourceAquired(const std::string& module_type, - const uint32_t app_id); + ResourceReleasedState::eType SetResourceFree(const std::string& module_type, + const std::string& module_id, + const uint32_t app_id); /** - * @brief SetResourceFree mark resourse as free and process logic of - * changing state of aquired resources - * @param module_type resource name - * @param app applicastion that aquire resource + * @brief CheckLocation checks if the user's grid is equal to or is within the + * service area of the module, or user location is driver's seat + * @param module module type + module id + * @return true if the user's grid equals to or is within module service + * area or user location is driver's seat, otherwise - false */ - void SetResourceFree(const std::string& module_type, const uint32_t app_id); + bool IsUserLocationValid(ModuleUid& module, + application_manager::ApplicationSharedPtr app); /** * @brief AllocatedResources contains link between resource and application * owning that resource */ - typedef std::map<std::string, uint32_t> AllocatedResources; + + typedef std::map<ModuleUid, uint32_t> AllocatedResources; AllocatedResources allocated_resources_; mutable sync_primitives::Lock allocated_resources_lock_; /** * @brief ResourcesState contains states of ALLOCATED resources */ - typedef std::map<std::string, ResourceState::eType> ResourcesState; + typedef std::map<ModuleUid, ResourceState::eType> ResourcesState; ResourcesState resources_state_; mutable sync_primitives::Lock resources_state_lock_; @@ -210,13 +250,14 @@ class ResourceAllocationManagerImpl : public ResourceAllocationManager { * driver for application * application_id : [vector of rejected resources] */ - typedef std::map<uint32_t, std::vector<std::string> > RejectedResources; + typedef std::map<uint32_t, std::vector<ModuleUid> > RejectedResources; RejectedResources rejected_resources_for_application_; mutable sync_primitives::Lock rejected_resources_for_application_lock_; hmi_apis::Common_RCAccessMode::eType current_access_mode_; application_manager::ApplicationManager& app_mngr_; application_manager::rpc_service::RPCService& rpc_service_; + rc_rpc_plugin::RCCapabilitiesManager& rc_capabilities_manager_; bool is_rc_enabled_; }; } // namespace rc_rpc_plugin 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 643e98213c..45b0d13582 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 @@ -59,7 +59,8 @@ RCOnRemoteControlSettingsNotification::RCOnRemoteControlSettingsNotification( params.hmi_capabilities_, params.policy_handler_) , resource_allocation_manager_(params.resource_allocation_manager_) - , interior_data_manager_(params.interior_data_manager_) {} + , interior_data_manager_(params.interior_data_manager_) + , rc_consent_manager_(params.rc_consent_manager_) {} RCOnRemoteControlSettingsNotification:: ~RCOnRemoteControlSettingsNotification() {} @@ -132,6 +133,7 @@ void RCOnRemoteControlSettingsNotification::Run() { DisallowRCFunctionality(); resource_allocation_manager_.ResetAllAllocations(); resource_allocation_manager_.set_rc_enabled(false); + rc_consent_manager_.RemoveAllConsents(); } } diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_set_global_properties_request.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_set_global_properties_request.cc new file mode 100644 index 0000000000..2f203afc2d --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_set_global_properties_request.cc @@ -0,0 +1,57 @@ +/* + * 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 "rc_rpc_plugin/commands/hmi/rc_set_global_properties_request.h" + +namespace rc_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +RCSetGlobalPropertiesRequest::RCSetGlobalPropertiesRequest( + const app_mngr::commands::MessageSharedPtr& message, + const RCCommandParams& params) + : app_mngr::commands::RequestToHMI(message, + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) {} + +void RCSetGlobalPropertiesRequest::Run() { + LOG4CXX_AUTO_TRACE(logger_); + SendRequest(); +} + +RCSetGlobalPropertiesRequest::~RCSetGlobalPropertiesRequest() {} + +} // namespace commands +} // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_set_global_properties_response.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_set_global_properties_response.cc new file mode 100644 index 0000000000..c31314ec21 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_set_global_properties_response.cc @@ -0,0 +1,59 @@ +/* + * 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 "rc_rpc_plugin/commands/hmi/rc_set_global_properties_response.h" + +namespace rc_rpc_plugin { +namespace commands { + +RCSetGlobalPropertiesResponse::RCSetGlobalPropertiesResponse( + const app_mngr::commands::MessageSharedPtr& message, + const RCCommandParams& params) + : application_manager::commands::ResponseFromHMI( + message, + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) {} + +void RCSetGlobalPropertiesResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + app_mngr::event_engine::Event event( + hmi_apis::FunctionID::RC_SetGlobalProperties); + event.set_smart_object(*message_); + event.raise(application_manager_.event_dispatcher()); +} + +RCSetGlobalPropertiesResponse::~RCSetGlobalPropertiesResponse() {} +} // namespace commands +} // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/button_press_request.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/button_press_request.cc index b85f092252..3adc48dfbf 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/button_press_request.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/button_press_request.cc @@ -33,6 +33,7 @@ #include "rc_rpc_plugin/commands/mobile/button_press_request.h" #include "interfaces/MOBILE_API.h" #include "json/json.h" +#include "rc_rpc_plugin/rc_helpers.h" #include "rc_rpc_plugin/rc_module_constants.h" #include "smart_objects/enum_schema_item.h" #include "utils/helpers.h" @@ -46,8 +47,6 @@ using namespace message_params; CREATE_LOGGERPTR_GLOBAL(logger_, "RemoteControlModule") -typedef std::map<std::string, mobile_apis::ButtonName::eType> ButtonsMap; - ButtonPressRequest::ButtonPressRequest( const app_mngr::commands::MessageSharedPtr& message, const RCCommandParams& params) @@ -55,147 +54,44 @@ ButtonPressRequest::ButtonPressRequest( ButtonPressRequest::~ButtonPressRequest() {} -const std::vector<std::string> buttons_climate() { - std::vector<std::string> data; - data.push_back(enums_value::kACMax); - data.push_back(enums_value::kAC); - data.push_back(enums_value::kRecirculate); - data.push_back(enums_value::kFanUp); - data.push_back(enums_value::kFanDown); - data.push_back(enums_value::kTempUp); - data.push_back(enums_value::kTempDown); - data.push_back(enums_value::kDefrostMax); - data.push_back(enums_value::kDefrost); - data.push_back(enums_value::kDefrostRear); - data.push_back(enums_value::kUpperVent); - data.push_back(enums_value::kLowerVent); - return data; -} - -const std::vector<std::string> buttons_radio() { - std::vector<std::string> data; - data.push_back(enums_value::kVolumeUp); - data.push_back(enums_value::kVolumeDown); - data.push_back(enums_value::kEject); - data.push_back(enums_value::kSource); - data.push_back(enums_value::kShuffle); - data.push_back(enums_value::kRepeat); - return data; -} - -const ButtonsMap buttons_map() { - using namespace mobile_apis; - - ButtonsMap buttons_map; - buttons_map[enums_value::kACMax] = ButtonName::AC_MAX; - buttons_map[enums_value::kAC] = ButtonName::AC; - buttons_map[enums_value::kRecirculate] = ButtonName::RECIRCULATE; - buttons_map[enums_value::kFanUp] = ButtonName::FAN_UP; - buttons_map[enums_value::kFanDown] = ButtonName::FAN_DOWN; - buttons_map[enums_value::kTempUp] = ButtonName::TEMP_UP; - buttons_map[enums_value::kTempDown] = ButtonName::TEMP_DOWN; - buttons_map[enums_value::kDefrostMax] = ButtonName::DEFROST_MAX; - buttons_map[enums_value::kDefrost] = ButtonName::DEFROST; - buttons_map[enums_value::kDefrostRear] = ButtonName::DEFROST_REAR; - buttons_map[enums_value::kUpperVent] = ButtonName::UPPER_VENT; - buttons_map[enums_value::kLowerVent] = ButtonName::LOWER_VENT; - buttons_map[enums_value::kVolumeUp] = ButtonName::VOLUME_UP; - buttons_map[enums_value::kVolumeDown] = ButtonName::VOLUME_DOWN; - buttons_map[enums_value::kEject] = ButtonName::EJECT; - buttons_map[enums_value::kSource] = ButtonName::SOURCE; - buttons_map[enums_value::kShuffle] = ButtonName::SHUFFLE; - buttons_map[enums_value::kRepeat] = ButtonName::REPEAT; - - return buttons_map; -} - -bool CheckIfButtonExistInRCCaps( - const smart_objects::SmartObject& rc_capabilities, - const mobile_apis::ButtonName::eType button) { - if (rc_capabilities.keyExists(strings::kbuttonCapabilities)) { - const smart_objects::SmartObject& button_caps = - rc_capabilities[strings::kbuttonCapabilities]; - auto it = button_caps.asArray()->begin(); - for (; it != button_caps.asArray()->end(); ++it) { - smart_objects::SmartObject& so = *it; - int64_t current_id = so[message_params::kName].asInt(); - if (-1 == current_id) { - // capabilities received from HMI contains enum values - // capabilities loaded from file contains string values - // TODO : unificate capabilities storing - const std::string& bt_name = so[message_params::kName].asString(); - static ButtonsMap btn_map = buttons_map(); - current_id = btn_map[bt_name]; - } - const mobile_apis::ButtonName::eType current_button = - static_cast<mobile_apis::ButtonName::eType>(current_id); - if (current_button == button) { - LOG4CXX_TRACE( - logger_, - "Button id " << current_button << " exist in capabilities"); - return true; - } - } - } - LOG4CXX_TRACE(logger_, - "Button id " << button << " do not exist in capabilities"); - return false; +std::string ButtonPressRequest::GetButtonName() const { + mobile_apis::ButtonName::eType button_name = + static_cast<mobile_apis::ButtonName::eType>( + (*message_)[app_mngr::strings::msg_params] + [message_params::kButtonName] + .asUInt()); + const char* str; + const bool ok = ns_smart_device_link::ns_smart_objects::EnumConversionHelper< + mobile_apis::ButtonName::eType>::EnumToCString(button_name, &str); + return ok ? str : "unknown"; } -bool CheckButtonName(const std::string& module_type, - const std::string& button_name, - const smart_objects::SmartObject* rc_capabilities) { - LOG4CXX_AUTO_TRACE(logger_); - if (rc_capabilities == NULL) { - LOG4CXX_ERROR(logger_, "No remote controll capabilities available"); - return false; - } - - if (enums_value::kRadio == module_type) { - if (!helpers::in_range(buttons_radio(), button_name)) { - LOG4CXX_WARN(logger_, - "Trying to acceess climate button with module type radio"); - return false; - } - } - - if (enums_value::kClimate == module_type) { - if (!helpers::in_range(buttons_climate(), button_name)) { - LOG4CXX_WARN(logger_, - "Trying to acceess radio button with module type climate"); - return false; - } +const mobile_apis::ButtonName::eType ButtonPressRequest::GetButtonId() const { + const auto button_name = GetButtonName(); + static RCHelpers::ButtonsMap btn_map = RCHelpers::buttons_map(); + mobile_apis::ButtonName::eType button_id = + mobile_apis::ButtonName::INVALID_ENUM; + if (btn_map.end() != btn_map.find(button_name)) { + button_id = btn_map[button_name]; } - return true; + return button_id; } void ButtonPressRequest::Execute() { LOG4CXX_AUTO_TRACE(logger_); - - const char* button_name; - ns_smart_device_link::ns_smart_objects:: - EnumConversionHelper<mobile_apis::ButtonName::eType>::EnumToCString( - static_cast<mobile_apis::ButtonName::eType>( - (*message_)[app_mngr::strings::msg_params] - [message_params::kButtonName] - .asUInt()), - &button_name); - const std::string module_type = ModuleType(); - static ButtonsMap btn_map = buttons_map(); - mobile_apis::ButtonName::eType button_id = - mobile_apis::ButtonName::INVALID_ENUM; - if (btn_map.end() != btn_map.find(button_name)) { - button_id = btn_map[button_name]; - } - const smart_objects::SmartObject* rc_capabilities = - hmi_capabilities_.rc_capability(); const bool button_name_matches_module_type = - CheckButtonName(module_type, button_name, rc_capabilities); - const bool button_id_exist_in_caps = - rc_capabilities && - CheckIfButtonExistInRCCaps(*rc_capabilities, button_id); + rc_capabilities_manager_.CheckButtonName(module_type, GetButtonName()); + + const std::string module_id = ModuleId(); + const ModuleUid module(module_type, module_id); + const bool is_module_exists = + rc_capabilities_manager_.CheckIfModuleExistsInCapabilities(module); + + const bool button_valid_by_caps = + is_module_exists && + rc_capabilities_manager_.CheckIfButtonExistInRCCaps(GetButtonId()); app_mngr::ApplicationSharedPtr app = application_manager_.application(connection_key()); @@ -203,7 +99,9 @@ void ButtonPressRequest::Execute() { (*message_)[app_mngr::strings::msg_params][app_mngr::strings::app_id] = app->app_id(); - if (button_name_matches_module_type && button_id_exist_in_caps) { + if (button_name_matches_module_type && button_valid_by_caps) { + (*message_)[app_mngr::strings::msg_params][message_params::kModuleId] = + module_id; SendHMIRequest(hmi_apis::FunctionID::Buttons_ButtonPress, &(*message_)[app_mngr::strings::msg_params], true); @@ -214,11 +112,12 @@ void ButtonPressRequest::Execute() { mobile_apis::Result::INVALID_DATA, "Request module type and button name mismatch!"); } else { - LOG4CXX_WARN(logger_, "Requested button is not exists in capabilities!"); + LOG4CXX_WARN(logger_, + "Requested button or module does not exist in capabilities!"); SetResourceState(module_type, ResourceState::FREE); SendResponse(false, mobile_apis::Result::UNSUPPORTED_RESOURCE, - "Requested button is not exists in capabilities!"); + "Requested button or module does not exist in capabilities!"); } } @@ -228,13 +127,15 @@ AcquireResult::eType ButtonPressRequest::AcquireResource( const std::string module_type = ModuleType(); app_mngr::ApplicationSharedPtr app = application_manager_.application(CommandRequestImpl::connection_key()); - return resource_allocation_manager_.AcquireResource(module_type, - app->app_id()); + + return resource_allocation_manager_.AcquireResource( + module_type, ModuleId(), app->app_id()); } -bool ButtonPressRequest::IsResourceFree(const std::string& module_type) const { +bool ButtonPressRequest::IsResourceFree(const std::string& module_type, + const std::string& module_id) const { LOG4CXX_AUTO_TRACE(logger_); - return resource_allocation_manager_.IsResourceFree(module_type); + return resource_allocation_manager_.IsResourceFree(module_type, module_id); } void ButtonPressRequest::SetResourceState(const std::string& module_type, @@ -242,8 +143,9 @@ void ButtonPressRequest::SetResourceState(const std::string& module_type, LOG4CXX_AUTO_TRACE(logger_); app_mngr::ApplicationSharedPtr app = application_manager_.application(CommandRequestImpl::connection_key()); + resource_allocation_manager_.SetResourceState( - module_type, app->app_id(), state); + module_type, ModuleId(), app->app_id(), state); } void ButtonPressRequest::on_event(const app_mngr::event_engine::Event& event) { @@ -270,13 +172,43 @@ void ButtonPressRequest::on_event(const app_mngr::event_engine::Event& event) { result = false; result_code = mobile_apis::Result::GENERIC_ERROR; } + + const std::string module_type = ModuleType(); + const std::string module_id = ModuleId(); + + const rc_rpc_types::ModuleUid resource{module_type, module_id}; + auto app = application_manager_.application(connection_key()); + + if (!app) { + LOG4CXX_ERROR(logger_, "NULL pointer."); + SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED, ""); + return; + } + + const auto app_id = app->app_id(); + + bool is_resource_acquired = false; + + if (result && !resource_allocation_manager_.IsResourceAlreadyAcquiredByApp( + resource, app_id)) { + resource_allocation_manager_.SetResourceAcquired( + module_type, module_id, app_id); + + is_resource_acquired = true; + } + std::string response_info; GetInfo(message, response_info); - SetResourceState(ModuleType(), ResourceState::FREE); SendResponse(result, result_code, response_info.c_str()); + + if (is_resource_acquired) { + resource_allocation_manager_.SendOnRCStatusNotifications( + NotificationTrigger::MODULE_ALLOCATION, + std::shared_ptr<application_manager::Application>()); + } } -std::string ButtonPressRequest::ModuleType() { +std::string ButtonPressRequest::ModuleType() const { mobile_apis::ModuleType::eType module_type = static_cast<mobile_apis::ModuleType::eType>( (*message_)[app_mngr::strings::msg_params] @@ -288,5 +220,16 @@ std::string ButtonPressRequest::ModuleType() { return ok ? str : "unknown"; } +std::string ButtonPressRequest::ModuleId() const { + LOG4CXX_AUTO_TRACE(logger_); + auto msg_params = (*message_)[app_mngr::strings::msg_params]; + if (msg_params.keyExists(message_params::kModuleId)) { + return msg_params[message_params::kModuleId].asString(); + } + const std::string module_id = + rc_capabilities_manager_.GetDefaultModuleIdFromCapabilities(ModuleType()); + return module_id; +} + } // namespace commands } // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/get_interior_vehicle_data_consent_request.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/get_interior_vehicle_data_consent_request.cc new file mode 100644 index 0000000000..fd661afd5f --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/get_interior_vehicle_data_consent_request.cc @@ -0,0 +1,472 @@ +/* + * 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 <algorithm> +#include <ctime> +#include <numeric> +#include <vector> + +#include "rc_rpc_plugin/commands/mobile/get_interior_vehicle_data_consent_request.h" +#include "rc_rpc_plugin/rc_helpers.h" +#include "rc_rpc_plugin/rc_module_constants.h" +#include "rc_rpc_plugin/rc_rpc_types.h" +#include "smart_objects/enum_schema_item.h" + +namespace rc_rpc_plugin { +namespace app_mngr = application_manager; +namespace commands { + +GetInteriorVehicleDataConsentRequest::GetInteriorVehicleDataConsentRequest( + const application_manager::commands::MessageSharedPtr& message, + const RCCommandParams& params) + : RCCommandRequest(message, params) {} + +void GetInteriorVehicleDataConsentRequest::Execute() { + LOG4CXX_AUTO_TRACE(logger_); + + auto& msg_params = (*message_)[app_mngr::strings::msg_params]; + + const bool module_ids_exists = + msg_params.keyExists(message_params::kModuleIds); + if (!module_ids_exists) { + SendResponse(false, + mobile_apis::Result::INVALID_DATA, + "ModuleIds collection is absent in request message"); + return; + } + + if (msg_params[message_params::kModuleIds].empty()) { + LOG4CXX_DEBUG(logger_, + "ModuleIds collection is empty. Will be add default " + "module_id from capabilities"); + + const auto module_id = + rc_capabilities_manager_.GetDefaultModuleIdFromCapabilities( + ModuleType()); + + msg_params[message_params::kModuleIds][0] = module_id; + } + + const std::string module_type = ModuleType(); + for (const auto module_id : + *(msg_params[message_params::kModuleIds].asArray())) { + const ModuleUid module(module_type, module_id.asString()); + if (!rc_capabilities_manager_.CheckIfModuleExistsInCapabilities(module)) { + LOG4CXX_WARN(logger_, + "Accessing not supported module: " << module_type << " " + << module_id.asString()); + SetResourceState(module_type, ResourceState::FREE); + SendResponse(false, + mobile_apis::Result::UNSUPPORTED_RESOURCE, + "Accessing not supported module data"); + return; + } + } + + smart_objects::SmartObject response_params; + if (GetCalculatedVehicleDataConsent(response_params)) { + LOG4CXX_DEBUG( + logger_, + "No need to send request to HMI. Sending cached consents to mobile"); + SendResponse(true, mobile_apis::Result::SUCCESS, nullptr, &response_params); + return; + } + + (*message_)[application_manager::strings::msg_params] + [application_manager::strings::app_id] = connection_key(); + + hmi_request_consents_ = + smart_objects::SmartObject(response_params[message_params::kAllowed]); + + LOG4CXX_DEBUG( + logger_, "Filtering out module ids with successfully calculated consent"); + + smart_objects::SmartObject hmi_msg_params(msg_params); + auto module_ids_for_consent = + hmi_msg_params[message_params::kModuleIds].asArray(); + module_ids_for_consent->clear(); + + auto module_ids = msg_params[message_params::kModuleIds].asArray(); + for (uint32_t i = 0; i < module_ids->size(); i++) { + // Only add modules whose consent is unknown(needs to be sent to the hmi) + bool is_consent_undefined = + (*hmi_request_consents_.asArray())[i].getType() == + smart_objects::SmartType::SmartType_Null; + if (is_consent_undefined) { + module_ids_for_consent->push_back((*module_ids)[i]); + } + } + + LOG4CXX_DEBUG(logger_, + "Forwarding request to HMI with moduleIds for modules with " + "unknown consent"); + SendHMIRequest(hmi_apis::FunctionID::RC_GetInteriorVehicleDataConsent, + (&hmi_msg_params), + true); +} + +void GetInteriorVehicleDataConsentRequest::on_event( + const app_mngr::event_engine::Event& event) { + LOG4CXX_AUTO_TRACE(logger_); + + if (event.id() != hmi_apis::FunctionID::RC_GetInteriorVehicleDataConsent) { + LOG4CXX_ERROR(logger_, "Received wrong event. FunctionID: " << event.id()); + return; + } + + auto temp_response = event.smart_object(); + + auto result_code = + GetMobileResultCode(static_cast<hmi_apis::Common_Result::eType>( + temp_response[app_mngr::strings::params][app_mngr::hmi_response::code] + .asUInt())); + + const bool success_result = + helpers::Compare<mobile_apis::Result::eType, helpers::EQ, helpers::ONE>( + result_code, + mobile_apis::Result::SUCCESS, + mobile_apis::Result::WARNINGS); + + if (!success_result) { + std::string info; + GetInfo(temp_response, info); + SendResponse(false, result_code, info.c_str(), nullptr); + return; + } + + if (!temp_response[app_mngr::strings::msg_params].keyExists( + message_params::kAllowed) || + temp_response[app_mngr::strings::msg_params][message_params::kAllowed] + .empty()) { + std::string info_out = + "Collection of consents is absent in HMI response or empty"; + LOG4CXX_ERROR(logger_, info_out); + SendResponse(false, mobile_apis::Result::GENERIC_ERROR, info_out.c_str()); + return; + } + + uint32_t number_of_expected_response_consents = std::accumulate( + hmi_request_consents_.asArray()->begin(), + hmi_request_consents_.asArray()->end(), + uint32_t(0), + [](uint32_t num_consents, smart_objects::SmartObject& consent) { + // Only module ids with valid location consents were sent to the hmi + bool is_consent_undefined = + consent.getType() == smart_objects::SmartType::SmartType_Null; + return (is_consent_undefined) ? num_consents + 1 : num_consents; + }); + + const auto response_consents = + temp_response[app_mngr::strings::msg_params][message_params::kAllowed] + .asArray(); + + if (number_of_expected_response_consents != response_consents->size()) { + std::string info_out = + "HMI response has incorrect number of consents expected: " + + std::to_string(number_of_expected_response_consents) + + ", actual: " + std::to_string(response_consents->size()); + LOG4CXX_ERROR(logger_, info_out); + SendResponse(false, mobile_apis::Result::GENERIC_ERROR, info_out.c_str()); + return; + } + + LOG4CXX_DEBUG(logger_, + "Adding back filtered out module ids for response to mobile"); + uint32_t response_consents_counter = 0; + for (auto& consent : *(hmi_request_consents_.asArray())) { + // Only modify consent for moduleIds allowed by location constraints + bool is_consent_undefined = + consent.getType() == smart_objects::SmartType::SmartType_Null; + if (is_consent_undefined) { + consent = (*response_consents)[response_consents_counter]; + response_consents_counter++; + } + } + + temp_response[app_mngr::strings::msg_params][message_params::kAllowed] = + hmi_request_consents_; + + const auto hmi_response = temp_response; + std::string response_info; + const bool result_of_saving = SaveModuleIdConsents( + response_info, hmi_response[app_mngr::strings::msg_params]); + + if (!result_of_saving) { + LOG4CXX_DEBUG(logger_, "Consent saving failed"); + SendResponse( + false, mobile_apis::Result::GENERIC_ERROR, response_info.c_str()); + return; + } + + smart_objects::SmartObject response_params = + hmi_response[app_mngr::strings::msg_params]; + std::string info; + GetInfo(hmi_response, info); + SendResponse(success_result, result_code, info.c_str(), &response_params); +} + +std::string GetInteriorVehicleDataConsentRequest::ModuleType() const { + mobile_apis::ModuleType::eType module_type = + static_cast<mobile_apis::ModuleType::eType>( + (*message_)[app_mngr::strings::msg_params] + [message_params::kModuleType] + .asUInt()); + + const char* str; + const bool ok = smart_objects::EnumConversionHelper< + mobile_apis::ModuleType::eType>::EnumToCString(module_type, &str); + return ok ? str : "unknown"; +} + +std::string GetInteriorVehicleDataConsentRequest::ModuleId() const { + return std::string(); +} + +GetInteriorVehicleDataConsentRequest::~GetInteriorVehicleDataConsentRequest() {} + +bool GetInteriorVehicleDataConsentRequest::IsUserLocationValid( + const ModuleUid& module_uid) const { + LOG4CXX_AUTO_TRACE(logger_); + + if (!rc_capabilities_manager_.IsSeatLocationCapabilityProvided()) { + return true; + } + const auto app_ptr = application_manager_.application(connection_key()); + const auto extension = RCHelpers::GetRCExtension(*app_ptr); + const auto module_service_area = + rc_capabilities_manager_.GetModuleServiceArea(module_uid); + const auto user_location = extension->GetUserLocation(); + const auto driver = + rc_capabilities_manager_.GetDriverLocationFromSeatLocationCapability(); + const bool is_driver = (user_location == driver); + if (is_driver || user_location.IntersectionExists(module_service_area)) { + return true; + } + return false; +} + +rc_rpc_types::ModuleConsent +GetInteriorVehicleDataConsentRequest::GetModuleConsentByAccessMode( + const ModuleUid& module_uid, + const hmi_apis::Common_RCAccessMode::eType access_mode) const { + LOG4CXX_AUTO_TRACE(logger_); + + auto get_auto_allow_consent = [](const ModuleUid& module_uid) { + return rc_rpc_types::ModuleConsent::CONSENTED; + }; + + auto get_auto_deny_consent = [this](const ModuleUid& module_uid) { + auto app = application_manager_.application(connection_key()); + const uint32_t app_id = app->app_id(); + const bool is_resource_available = + (resource_allocation_manager_.AcquireResource( + module_uid.first, module_uid.second, app_id) == + AcquireResult::ALLOWED); + return (is_resource_available) ? rc_rpc_types::ModuleConsent::CONSENTED + : rc_rpc_types::ModuleConsent::NOT_CONSENTED; + }; + + auto get_ask_driver_consent = [this](const ModuleUid& module_uid) { + auto app = application_manager_.application(connection_key()); + const std::string policy_app_id = app->policy_app_id(); + const std::string mac_address = app->mac_address(); + + auto consent = rc_consent_manager_.GetModuleConsent( + policy_app_id, mac_address, module_uid); + + if (rc_rpc_types::ModuleConsent::NOT_EXISTS == consent) { + auto acquire_result = resource_allocation_manager_.AcquireResource( + module_uid.first, module_uid.second, app->app_id()); + const bool is_resource_available = + (acquire_result == AcquireResult::ALLOWED); + const bool is_resource_rejected = + (acquire_result == AcquireResult::REJECTED); + + if (!is_resource_available && !is_resource_rejected) { + return rc_rpc_types::ModuleConsent::NOT_EXISTS; + } + + return (is_resource_available) + ? rc_rpc_types::ModuleConsent::CONSENTED + : rc_rpc_types::ModuleConsent::NOT_CONSENTED; + } + + const bool is_consent_allowed = + (rc_rpc_types::ModuleConsent::CONSENTED == consent); + return (is_consent_allowed) ? rc_rpc_types::ModuleConsent::CONSENTED + : rc_rpc_types::ModuleConsent::NOT_CONSENTED; + }; + + switch (access_mode) { + case hmi_apis::Common_RCAccessMode::AUTO_ALLOW: { + LOG4CXX_DEBUG(logger_, + "Calculating consent for module(" + << module_uid.first << ", " << module_uid.second + << ") in accessMode: AUTO_ALLOW"); + return get_auto_allow_consent(module_uid); + } + case hmi_apis::Common_RCAccessMode::AUTO_DENY: { + LOG4CXX_DEBUG(logger_, + "Calculating consent for module(" + << module_uid.first << ", " << module_uid.second + << ") in accessMode: AUTO_DENY"); + return get_auto_deny_consent(module_uid); + } + case hmi_apis::Common_RCAccessMode::ASK_DRIVER: { + LOG4CXX_DEBUG(logger_, + "Calculating consent for module(" + << module_uid.first << ", " << module_uid.second + << ") in accessMode: ASK_DRIVER"); + return get_ask_driver_consent(module_uid); + } + default: { + LOG4CXX_DEBUG(logger_, + "Unknown accessMode specified. Denying consent for module(" + << module_uid.first << ", " << module_uid.second + << ")"); + return rc_rpc_types::ModuleConsent::NOT_CONSENTED; + } + } +} + +bool GetInteriorVehicleDataConsentRequest::GetCalculatedVehicleDataConsent( + smart_objects::SmartObject& out_response) const { + LOG4CXX_AUTO_TRACE(logger_); + + out_response = + smart_objects::SmartObject(smart_objects::SmartType::SmartType_Map); + out_response[message_params::kAllowed] = + smart_objects::SmartObject(smart_objects::SmartType::SmartType_Array); + + auto modules_consent_array = out_response[message_params::kAllowed].asArray(); + const auto module_ids = + (*message_)[app_mngr::strings::msg_params][message_params::kModuleIds] + .asArray(); + const std::string module_type = ModuleType(); + bool can_handle_internally = true; + + auto get_disallowed_multiple_access_consent = + [this](const ModuleUid& module_uid) { + auto app = application_manager_.application(connection_key()); + const uint32_t app_id = app->app_id(); + const bool is_resource_available = + (resource_allocation_manager_.AcquireResource( + module_uid.first, module_uid.second, app_id) == + AcquireResult::ALLOWED); + return (is_resource_available) + ? rc_rpc_types::ModuleConsent::CONSENTED + : rc_rpc_types::ModuleConsent::NOT_CONSENTED; + }; + + for (const auto module_id : *(module_ids)) { + const ModuleUid module_uid(module_type, module_id.asString()); + // Check if the user_location is covered by the module's serviceArea + if (!IsUserLocationValid(module_uid)) { + LOG4CXX_DEBUG(logger_, + "User is outside the serviceArea for module(" + << module_uid.first << ", " << module_uid.second + << "). Denying consent"); + modules_consent_array->push_back(smart_objects::SmartObject(false)); + continue; + } + + rc_rpc_types::ModuleConsent module_consent; + + const bool is_multiple_access_allowed = + rc_capabilities_manager_.IsMultipleAccessAllowed(module_uid); + if (!is_multiple_access_allowed) { + LOG4CXX_DEBUG(logger_, + "multipleAccess disallowed for module(" + << module_uid.first << ", " << module_uid.second + << ")"); + module_consent = get_disallowed_multiple_access_consent(module_uid); + modules_consent_array->push_back(smart_objects::SmartObject( + module_consent == rc_rpc_types::ModuleConsent::CONSENTED)); + continue; + } + + const auto access_mode = resource_allocation_manager_.GetAccessMode(); + + module_consent = GetModuleConsentByAccessMode(module_uid, access_mode); + if (module_consent == rc_rpc_types::ModuleConsent::NOT_EXISTS) { + LOG4CXX_DEBUG(logger_, + "Unable to calculate consent for module(" + << module_uid.first << ", " << module_uid.second + << "), should send moduleId to HMI for consent"); + modules_consent_array->push_back(smart_objects::SmartObject()); + can_handle_internally = false; + continue; + } + modules_consent_array->push_back(smart_objects::SmartObject( + module_consent == rc_rpc_types::ModuleConsent::CONSENTED)); + } + return can_handle_internally; +} + +bool GetInteriorVehicleDataConsentRequest::SaveModuleIdConsents( + std::string& info_out, const smart_objects::SmartObject& msg_params) { + LOG4CXX_AUTO_TRACE(logger_); + + const auto& allowed = msg_params[message_params::kAllowed]; + const auto& moduleIds = + (*message_)[app_mngr::strings::msg_params][message_params::kModuleIds]; + + if (allowed.length() != moduleIds.length()) { + info_out = + "The received module_id collection from mobile and received consent " + "collection from HMI are not equal by size."; + LOG4CXX_ERROR(logger_, info_out); + return false; + } + std::string module_type = ModuleType(); + auto module_ids = RCHelpers::RetrieveModuleIds(moduleIds); + auto module_allowed = RCHelpers::RetrieveModuleConsents(allowed); + + auto module_consents = + RCHelpers::FillModuleConsents(module_type, module_ids, module_allowed); + + auto application = application_manager_.application(connection_key()); + if (!application) { + LOG4CXX_ERROR(logger_, + "Application with connection key:" << connection_key() + << " isn't registered"); + return false; + } + std::string policy_app_id = application->policy_app_id(); + const auto mac_address = application->mac_address(); + rc_consent_manager_.SaveModuleConsents( + policy_app_id, mac_address, module_consents); + return true; +} + +} // namespace commands +} // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/get_interior_vehicle_data_consent_response.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/get_interior_vehicle_data_consent_response.cc new file mode 100644 index 0000000000..3e197fbdea --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/get_interior_vehicle_data_consent_response.cc @@ -0,0 +1,57 @@ +/* + * 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 "rc_rpc_plugin/commands/mobile/get_interior_vehicle_data_consent_response.h" + +namespace rc_rpc_plugin { +namespace commands { + +GetInteriorVehicleDataConsentResponse::GetInteriorVehicleDataConsentResponse( + const application_manager::commands::MessageSharedPtr& message, + const RCCommandParams& params) + : application_manager::commands::CommandResponseImpl( + message, + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) {} + +void GetInteriorVehicleDataConsentResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + application_manager_.GetRPCService().SendMessageToMobile(message_); +} + +GetInteriorVehicleDataConsentResponse:: + ~GetInteriorVehicleDataConsentResponse() {} + +} // namespace commands +} // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/get_interior_vehicle_data_request.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/get_interior_vehicle_data_request.cc index ded96461f5..10f6303ac9 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/get_interior_vehicle_data_request.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/get_interior_vehicle_data_request.cc @@ -50,36 +50,21 @@ GetInteriorVehicleDataRequest::GetInteriorVehicleDataRequest( const app_mngr::commands::MessageSharedPtr& message, const RCCommandParams& params) : RCCommandRequest(message, params) - , excessive_subscription_occured_(false) {} -bool CheckIfModuleTypeExistInCapabilities( - const smart_objects::SmartObject& rc_capabilities, - const std::string& module_type) { - LOG4CXX_AUTO_TRACE(logger_); - const auto& mapping = RCHelpers::GetModuleTypeToCapabilitiesMapping(); - const auto& module_list = RCHelpers::GetModulesList(); - bool is_module_type_valid = false; - for (const auto& module : module_list) { - if (module == module_type) { - if (rc_capabilities.keyExists(mapping(module))) { - is_module_type_valid = true; - break; - } - } - } - return is_module_type_valid; -} - bool GetInteriorVehicleDataRequest::ProcessCapabilities() { LOG4CXX_AUTO_TRACE(logger_); const smart_objects::SmartObject* rc_capabilities = hmi_capabilities_.rc_capability(); const std::string module_type = ModuleType(); + const std::string module_id = ModuleId(); + const ModuleUid module(module_type, module_id); if (rc_capabilities && - !CheckIfModuleTypeExistInCapabilities(*rc_capabilities, module_type)) { - LOG4CXX_WARN(logger_, "Accessing not supported module data"); + !rc_capabilities_manager_.CheckIfModuleExistsInCapabilities(module)) { + LOG4CXX_WARN( + logger_, + "Accessing not supported module: " << module_type << " " << module_id); SetResourceState(ModuleType(), ResourceState::FREE); SendResponse(false, mobile_apis::Result::UNSUPPORTED_RESOURCE, @@ -118,14 +103,20 @@ void GetInteriorVehicleDataRequest::ProcessResponseToMobileFromCache( app_mngr::ApplicationSharedPtr app) { LOG4CXX_AUTO_TRACE(logger_); const auto& data_mapping = RCHelpers::GetModuleTypeToDataMapping(); - auto data = interior_data_cache_.Retrieve(ModuleType()); + const std::string module_type = ModuleType(); + const std::string module_id = ModuleId(); + const ModuleUid module(module_type, module_id); + auto data = interior_data_cache_.Retrieve(module); FilterDisabledModuleData(data); auto response_msg_params = smart_objects::SmartObject(smart_objects::SmartType_Map); - response_msg_params[message_params::kModuleData][data_mapping(ModuleType())] = + response_msg_params[message_params::kModuleData][data_mapping(module_type)] = data; response_msg_params[message_params::kModuleData] - [message_params::kModuleType] = ModuleType(); + [message_params::kModuleType] = module_type; + + response_msg_params[message_params::kModuleData][message_params::kModuleId] = + module_id; const auto& request_msg_params = (*message_)[app_mngr::strings::msg_params]; LOG4CXX_DEBUG(logger_, @@ -137,7 +128,7 @@ void GetInteriorVehicleDataRequest::ProcessResponseToMobileFromCache( if (request_msg_params[message_params::kSubscribe].asBool()) { auto extension = RCHelpers::GetRCExtension(*app); DCHECK(extension); - extension->SubscribeToInteriorVehicleData(ModuleType()); + extension->SubscribeToInteriorVehicleData(module); } } SendResponse( @@ -145,13 +136,16 @@ void GetInteriorVehicleDataRequest::ProcessResponseToMobileFromCache( if (AppShouldBeUnsubscribed()) { auto extension = RCHelpers::GetRCExtension(*app); DCHECK(extension); - extension->UnsubscribeFromInteriorVehicleData(ModuleType()); + extension->UnsubscribeFromInteriorVehicleData(module); } } bool GetInteriorVehicleDataRequest::CheckRateLimits() { LOG4CXX_AUTO_TRACE(logger_); - return interior_data_manager_.CheckRequestsToHMIFrequency(ModuleType()); + const std::string module_type = ModuleType(); + const std::string module_id = ModuleId(); + const ModuleUid module(module_type, module_id); + return interior_data_manager_.CheckRequestsToHMIFrequency(module); } bool GetInteriorVehicleDataRequest::AppShouldBeUnsubscribed() { @@ -167,13 +161,16 @@ bool GetInteriorVehicleDataRequest::TheLastAppShouldBeUnsubscribed( app_mngr::ApplicationSharedPtr app) { LOG4CXX_AUTO_TRACE(logger_); if (AppShouldBeUnsubscribed()) { + const std::string module_type = ModuleType(); + const std::string module_id = ModuleId(); + const ModuleUid module(module_type, module_id); const auto subscribed_to_module_type = - RCHelpers::AppsSubscribedToModuleType(application_manager_, - ModuleType()); + RCHelpers::AppsSubscribedToModule(application_manager_, module); if (subscribed_to_module_type.size() == 1 && subscribed_to_module_type.front() == app) { LOG4CXX_DEBUG(logger_, - "The last application unsubscribes from " << ModuleType()); + "The last application unsubscribes from " + << module_type << " " << module_id); return true; } } @@ -189,9 +186,12 @@ void GetInteriorVehicleDataRequest::Execute() { app_mngr::ApplicationSharedPtr app = application_manager_.application(connection_key()); + const std::string module_type = ModuleType(); + const std::string module_id = ModuleId(); + const ModuleUid module(module_type, module_id); if (TheLastAppShouldBeUnsubscribed(app) || - !interior_data_cache_.Contains(ModuleType())) { + !interior_data_cache_.Contains(module)) { if (HasRequestExcessiveSubscription()) { excessive_subscription_occured_ = true; is_subscribed = @@ -204,7 +204,9 @@ void GetInteriorVehicleDataRequest::Execute() { SendResponse(false, mobile_apis::Result::REJECTED); return; } - interior_data_manager_.StoreRequestToHMITime(ModuleType()); + interior_data_manager_.StoreRequestToHMITime(module); + (*message_)[app_mngr::strings::msg_params][message_params::kModuleId] = + ModuleId(); SendHMIRequest(hmi_apis::FunctionID::RC_GetInteriorVehicleData, &(*message_)[app_mngr::strings::msg_params], true); @@ -242,20 +244,32 @@ void GetInteriorVehicleDataRequest::on_event( } if (result) { + if (!IsModuleIdProvided(hmi_response)) { + LOG4CXX_WARN(logger_, + "conditional mandatory parameter " + << message_params::kModuleId + << " missed in hmi response"); + result = false; + result_code = mobile_apis::Result::GENERIC_ERROR; + } app_mngr::ApplicationSharedPtr app = application_manager_.application(connection_key()); DCHECK_OR_RETURN_VOID(app); + const std::string module_type = ModuleType(); + const std::string module_id = ModuleId(); + const ModuleUid module(module_type, module_id); + if (TheLastAppShouldBeUnsubscribed(app)) { - interior_data_cache_.Remove(ModuleType()); + interior_data_cache_.Remove(module); } ProccessSubscription(hmi_response); if (is_subscribed) { const auto& data_mapping = RCHelpers::GetModuleTypeToDataMapping(); const auto module_data = hmi_response[app_mngr::strings::msg_params] - [message_params::kModuleData][data_mapping(ModuleType())]; - interior_data_cache_.Add(ModuleType(), module_data); + [message_params::kModuleData][data_mapping(module_type)]; + interior_data_cache_.Add(module, module_data); } } else { hmi_response[app_mngr::strings::msg_params].erase( @@ -301,8 +315,15 @@ void GetInteriorVehicleDataRequest::ProccessSubscription( [message_params::kModuleType] .asUInt()), &module_type); + + const std::string module_id = + hmi_response[app_mngr::strings::msg_params][message_params::kModuleData] + [message_params::kModuleId] + .asString(); + const ModuleUid module(module_type, module_id); + if (excessive_subscription_occured_) { - is_subscribed = extension->IsSubscibedToInteriorVehicleData(module_type); + is_subscribed = extension->IsSubscribedToInteriorVehicleData(module); temp_hmi_response[app_mngr::strings::msg_params] [message_params::kIsSubscribed] = is_subscribed; return; @@ -317,7 +338,7 @@ void GetInteriorVehicleDataRequest::ProccessSubscription( << message_params::kIsSubscribed << " missed in hmi response"); - is_subscribed = extension->IsSubscibedToInteriorVehicleData(module_type); + is_subscribed = extension->IsSubscribedToInteriorVehicleData(module); temp_hmi_response[app_mngr::strings::msg_params] [message_params::kIsSubscribed] = is_subscribed; return; @@ -348,16 +369,21 @@ void GetInteriorVehicleDataRequest::ProccessSubscription( LOG4CXX_TRACE(logger_, "response_subscribe = " << response_subscribe); if (request_subscribe == response_subscribe) { const std::string module_type = ModuleType(); + const std::string module_id = ModuleId(); + const ModuleUid module(module_type, module_id); + if (response_subscribe) { LOG4CXX_DEBUG(logger_, "SubscribeToInteriorVehicleData " << app->app_id() << " " - << module_type); - extension->SubscribeToInteriorVehicleData(module_type); + << module_type << " " + << module_id); + extension->SubscribeToInteriorVehicleData(module); } else { LOG4CXX_DEBUG(logger_, "UnsubscribeFromInteriorVehicleData " - << app->app_id() << " " << module_type); - extension->UnsubscribeFromInteriorVehicleData(module_type); + << app->app_id() << " " << module_type << " " + << module_id); + extension->UnsubscribeFromInteriorVehicleData(module); } } } @@ -373,8 +399,12 @@ bool GetInteriorVehicleDataRequest::HasRequestExcessiveSubscription() { application_manager_.application(CommandRequestImpl::connection_key()); const auto extension = RCHelpers::GetRCExtension(*app); + const std::string module_type = ModuleType(); + const std::string module_id = ModuleId(); + const ModuleUid module(module_type, module_id); + const bool is_app_already_subscribed = - extension->IsSubscibedToInteriorVehicleData(ModuleType()); + extension->IsSubscribedToInteriorVehicleData(module); const bool app_wants_to_subscribe = (*message_)[app_mngr::strings::msg_params][message_params::kSubscribe] .asBool(); @@ -391,7 +421,8 @@ void GetInteriorVehicleDataRequest::RemoveExcessiveSubscription() { (*message_)[app_mngr::strings::msg_params].erase(message_params::kSubscribe); } -std::string GetInteriorVehicleDataRequest::ModuleType() { +std::string GetInteriorVehicleDataRequest::ModuleType() const { + LOG4CXX_AUTO_TRACE(logger_); mobile_apis::ModuleType::eType module_type = static_cast<mobile_apis::ModuleType::eType>( (*message_)[app_mngr::strings::msg_params] @@ -403,5 +434,16 @@ std::string GetInteriorVehicleDataRequest::ModuleType() { return ok ? str : "unknown"; } +std::string GetInteriorVehicleDataRequest::ModuleId() const { + LOG4CXX_AUTO_TRACE(logger_); + auto msg_params = (*message_)[app_mngr::strings::msg_params]; + if (msg_params.keyExists(message_params::kModuleId)) { + return msg_params[message_params::kModuleId].asString(); + } + const std::string module_id = + rc_capabilities_manager_.GetDefaultModuleIdFromCapabilities(ModuleType()); + return module_id; +} + } // namespace commands } // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/on_interior_vehicle_data_notification.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/on_interior_vehicle_data_notification.cc index 06b5218bb3..91ecbe77eb 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/on_interior_vehicle_data_notification.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/on_interior_vehicle_data_notification.cc @@ -50,27 +50,31 @@ OnInteriorVehicleDataNotification::OnInteriorVehicleDataNotification( params.rpc_service_, params.hmi_capabilities_, params.policy_handler_) - , interior_data_cache_(params.interior_data_cache_) {} + , interior_data_cache_(params.interior_data_cache_) + , rc_capabilities_manager_(params.rc_capabilities_manager_) {} OnInteriorVehicleDataNotification::~OnInteriorVehicleDataNotification() {} void OnInteriorVehicleDataNotification::AddDataToCache( - const std::string& module_type) { + const ModuleUid& module) { const auto& data_mapping = RCHelpers::GetModuleTypeToDataMapping(); const auto module_data = (*message_)[app_mngr::strings::msg_params][message_params::kModuleData] - [data_mapping(module_type)]; - interior_data_cache_.Add(module_type, module_data); + [data_mapping(module.first)]; + interior_data_cache_.Add(module, module_data); } void OnInteriorVehicleDataNotification::Run() { LOG4CXX_AUTO_TRACE(logger_); const std::string module_type = ModuleType(); + const std::string module_id = ModuleId(); + const ModuleUid module(module_type, module_id); + auto apps_subscribed = - RCHelpers::AppsSubscribedToModuleType(application_manager_, module_type); + RCHelpers::AppsSubscribedToModule(application_manager_, module); if (!apps_subscribed.empty()) { - AddDataToCache(module_type); + AddDataToCache(module); } typedef std::vector<application_manager::ApplicationSharedPtr> AppPtrs; AppPtrs apps = RCRPCPlugin::GetRCApplications(application_manager_); @@ -84,17 +88,36 @@ void OnInteriorVehicleDataNotification::Run() { const auto extension = RCHelpers::GetRCExtension(app); DCHECK(extension); LOG4CXX_TRACE(logger_, - "Check subscription for " - << app.app_id() << "and module type " << module_type); - if (extension->IsSubscibedToInteriorVehicleData(module_type)) { + "Check subscription for " << app.app_id() + << "and module type " << module_type + << " " << module_id); + + if (extension->IsSubscribedToInteriorVehicleData(module)) { (*message_)[app_mngr::strings::params] [app_mngr::strings::connection_key] = app.app_id(); + + (*message_)[app_mngr::strings::msg_params][message_params::kModuleData] + [message_params::kModuleId] = module_id; + SendNotification(); } } } -std::string OnInteriorVehicleDataNotification::ModuleType() { +std::string OnInteriorVehicleDataNotification::ModuleId() const { + LOG4CXX_AUTO_TRACE(logger_); + auto msg_params = (*message_)[app_mngr::strings::msg_params]; + if (msg_params[message_params::kModuleData].keyExists( + message_params::kModuleId)) { + return msg_params[message_params::kModuleData][message_params::kModuleId] + .asString(); + } + const std::string module_id = + rc_capabilities_manager_.GetDefaultModuleIdFromCapabilities(ModuleType()); + return module_id; +} + +std::string OnInteriorVehicleDataNotification::ModuleType() const { mobile_apis::ModuleType::eType module_type = static_cast<mobile_apis::ModuleType::eType>( (*message_)[app_mngr::strings::msg_params] diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/release_interior_vehicle_data_module_request.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/release_interior_vehicle_data_module_request.cc new file mode 100644 index 0000000000..e30d7869bd --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/release_interior_vehicle_data_module_request.cc @@ -0,0 +1,194 @@ +/* + * 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 <string> + +#include "application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager.h" +#include "rc_rpc_plugin/commands/mobile/release_interior_vehicle_data_module_request.h" +#include "rc_rpc_plugin/rc_module_constants.h" +#include "smart_objects/enum_schema_item.h" + +namespace rc_rpc_plugin { +using namespace application_manager; +namespace commands { + +namespace { +struct ResponseParams { + std::string response_info; + std::string module_type; + std::string module_id; + mobile_apis::Result::eType result_code; + uint32_t app_id; + bool success_result; +}; + +void PrepareResponseResult( + ResponseParams& response_params_out, + rc_rpc_plugin::ResourceReleasedState::eType& released_result) { + std::stringstream ss; + auto info_inserter = [&ss, response_params_out](std::string info) { + ss << "Module [" << response_params_out.module_type << ":" + << response_params_out.module_id << "] " << info; + }; + switch (released_result) { + case rc_rpc_plugin::ResourceReleasedState::eType::IS_RELEASED: { + response_params_out.success_result = true; + response_params_out.result_code = mobile_apis::Result::eType::SUCCESS; + info_inserter("is released successfully."); + break; + } + case rc_rpc_plugin::ResourceReleasedState::eType::IS_ALLOCATED: { + response_params_out.success_result = false; + response_params_out.result_code = mobile_apis::Result::eType::REJECTED; + info_inserter("is allocated to a different application."); + break; + } + case rc_rpc_plugin::ResourceReleasedState::eType::NOT_ALLOCATED: { + response_params_out.success_result = false; + response_params_out.result_code = mobile_apis::Result::eType::IGNORED; + info_inserter("is not allocated to any application."); + break; + } + } + response_params_out.response_info = ss.str(); +} +} // namespace + +ReleaseInteriorVehicleDataModuleRequest:: + ReleaseInteriorVehicleDataModuleRequest( + const application_manager::commands::MessageSharedPtr& message, + const RCCommandParams& params) + : RCCommandRequest(message, params) {} + +bool ReleaseInteriorVehicleDataModuleRequest::ProcessCapabilities() { + LOG4CXX_AUTO_TRACE(logger_); + const smart_objects::SmartObject* rc_capabilities = + hmi_capabilities_.rc_capability(); + + const std::string module_type = ModuleType(); + const std::string module_id = ModuleId(); + const ModuleUid module(module_type, module_id); + if (rc_capabilities && + !rc_capabilities_manager_.CheckIfModuleExistsInCapabilities(module)) { + LOG4CXX_WARN( + logger_, + "Accessing not supported module: " << module_type << " " << module_id); + SendResponse(false, + mobile_apis::Result::UNSUPPORTED_RESOURCE, + "Accessing not supported module"); + return false; + } + return true; +} + +void ReleaseInteriorVehicleDataModuleRequest::Execute() { + LOG4CXX_AUTO_TRACE(logger_); + + if (!ProcessCapabilities()) { + return; + } + + const std::string module_type = ModuleType(); + const std::string module_id = ModuleId(); + + ApplicationSharedPtr app = application_manager_.application(connection_key()); + + if (!app) { + LOG4CXX_ERROR(logger_, "Application is not registered"); + SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED); + return; + } + + const uint32_t app_id = app->app_id(); + + ResourceReleasedState::eType released_result = + resource_allocation_manager_.ReleaseResource( + module_type, module_id, app_id); + + bool success_result = true; + mobile_apis::Result::eType result_code = mobile_apis::Result::eType::SUCCESS; + std::string response_info; + ResponseParams response_params{response_info, + ModuleType(), + module_id, + result_code, + app_id, + success_result}; + PrepareResponseResult(response_params, released_result); + + if (response_params.success_result) { + resource_allocation_manager_.SendOnRCStatusNotifications( + NotificationTrigger::MODULE_ALLOCATION, app); + } + + LOG4CXX_DEBUG(logger_, + "Resource for module: " + << ModuleType() << " with id: " << module_id + << " was released with result " << std::boolalpha + << response_params.success_result + << " and result_code: " << response_params.result_code); + + SendResponse(response_params.success_result, + response_params.result_code, + response_params.response_info.c_str()); +} + +std::string ReleaseInteriorVehicleDataModuleRequest::ModuleType() const { + LOG4CXX_AUTO_TRACE(logger_); + mobile_apis::ModuleType::eType module_type = + static_cast<mobile_apis::ModuleType::eType>( + (*message_)[app_mngr::strings::msg_params] + [message_params::kModuleType] + .asUInt()); + + const char* str; + const bool ok = ns_smart_device_link::ns_smart_objects::EnumConversionHelper< + mobile_apis::ModuleType::eType>::EnumToCString(module_type, &str); + return ok ? str : "unknown"; +} + +std::string ReleaseInteriorVehicleDataModuleRequest::ModuleId() const { + LOG4CXX_AUTO_TRACE(logger_); + auto msg_params = (*message_)[app_mngr::strings::msg_params]; + if (msg_params.keyExists(message_params::kModuleId)) { + return msg_params[message_params::kModuleId].asString(); + } + const std::string module_id = + rc_capabilities_manager_.GetDefaultModuleIdFromCapabilities(ModuleType()); + return module_id; +} + +ReleaseInteriorVehicleDataModuleRequest:: + ~ReleaseInteriorVehicleDataModuleRequest() {} + +} // namespace commands +} // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/release_interior_vehicle_data_module_response.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/release_interior_vehicle_data_module_response.cc new file mode 100644 index 0000000000..fae792f143 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/release_interior_vehicle_data_module_response.cc @@ -0,0 +1,58 @@ +/* + * 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 "rc_rpc_plugin/commands/mobile/release_interior_vehicle_data_module_response.h" + +namespace rc_rpc_plugin { +namespace commands { + +ReleaseInteriorVehicleDataModuleResponse:: + ReleaseInteriorVehicleDataModuleResponse( + const application_manager::commands::MessageSharedPtr& message, + const RCCommandParams& params) + : application_manager::commands::CommandResponseImpl( + message, + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) {} + +void ReleaseInteriorVehicleDataModuleResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + application_manager_.GetRPCService().SendMessageToMobile(message_); +} + +ReleaseInteriorVehicleDataModuleResponse:: + ~ReleaseInteriorVehicleDataModuleResponse() {} + +} // namespace commands +} // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/set_interior_vehicle_data_request.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/set_interior_vehicle_data_request.cc index 44d302276d..c3e5e807d7 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/set_interior_vehicle_data_request.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/set_interior_vehicle_data_request.cc @@ -45,106 +45,6 @@ namespace commands { using namespace json_keys; using namespace message_params; - -namespace { -std::vector<std::string> GetModuleReadOnlyParams( - const std::string& module_type) { - std::vector<std::string> module_ro_params; - if (enums_value::kClimate == module_type) { - module_ro_params.push_back(kCurrentTemperature); - } else if (enums_value::kRadio == module_type) { - module_ro_params.push_back(kRdsData); - module_ro_params.push_back(kAvailableHDs); - module_ro_params.push_back(kAvailableHdChannels); - module_ro_params.push_back(kSignalStrength); - module_ro_params.push_back(kSignalChangeThreshold); - module_ro_params.push_back(kState); - module_ro_params.push_back(kSisData); - } else if (enums_value::kLight == module_type) { - module_ro_params.push_back(kLightStatus); - } - - return module_ro_params; -} - -const std::map<std::string, std::string> GetLightCapabilitiesMapping() { - std::map<std::string, std::string> mapping = { - {message_params::kId, strings::kName}, - {message_params::kLightStatus, strings::kStatusAvailable}, - {message_params::kLightDensity, strings::kDensityAvailable}, - {message_params::kLightColor, strings::kRGBColorSpaceAvailable}}; - return mapping; -} - -const std::map<std::string, std::string> GetModuleDataToCapabilitiesMapping() { - std::map<std::string, std::string> mapping; - // climate - mapping["fanSpeed"] = "fanSpeedAvailable"; - mapping["currentTemperature"] = "currentTemperatureAvailable"; - mapping["desiredTemperature"] = "desiredTemperatureAvailable"; - mapping["acEnable"] = "acEnableAvailable"; - mapping["circulateAirEnable"] = "circulateAirEnableAvailable"; - mapping["autoModeEnable"] = "autoModeEnableAvailable"; - mapping["defrostZone"] = "defrostZoneAvailable"; - mapping["dualModeEnable"] = "dualModeEnableAvailable"; - mapping["acMaxEnable"] = "acMaxEnableAvailable"; - mapping["ventilationMode"] = "ventilationModeAvailable"; - mapping["heatedSteeringWheelEnable"] = "heatedSteeringWheelAvailable"; - mapping["heatedWindshieldEnable"] = "heatedWindshieldAvailable"; - mapping["heatedMirrorsEnable"] = "heatedMirrorsAvailable"; - mapping["heatedRearWindowEnable"] = "heatedRearWindowAvailable"; - mapping["climateEnable"] = "climateEnableAvailable"; - mapping["climateEnableAvailable"] = "climateEnableAvailable"; - - // radio - mapping["band"] = "radioBandAvailable"; - mapping["frequencyInteger"] = "radioFrequencyAvailable"; - mapping["frequencyFraction"] = "radioFrequencyAvailable"; - mapping["rdsData"] = "rdsDataAvailable"; - mapping["availableHDs"] = "availableHDsAvailable"; - mapping["availableHdChannels"] = "availableHdChannelsAvailable"; - mapping["hdChannel"] = "availableHdChannelsAvailable"; - mapping["hdRadioEnable"] = "hdRadioEnableAvailable"; - mapping["signalStrength"] = "signalStrengthAvailable"; - mapping["signalChangeThreshold"] = "signalChangeThresholdAvailable"; - mapping["radioEnable"] = "radioEnableAvailable"; - mapping["state"] = "stateAvailable"; - mapping["sisData"] = "sisDataAvailable"; - - // seat - mapping["heatingEnabled"] = "heatingEnabledAvailable"; - mapping["coolingEnabled"] = "coolingEnabledAvailable"; - mapping["heatingLevel"] = "heatingLevelAvailable"; - mapping["coolingLevel"] = "coolingLevelAvailable"; - mapping["horizontalPosition"] = "horizontalPositionAvailable"; - mapping["verticalPosition"] = "verticalPositionAvailable"; - mapping["frontVerticalPosition"] = "frontVerticalPositionAvailable"; - mapping["backVerticalPosition"] = "backVerticalPositionAvailable"; - mapping["backTiltAngle"] = "backTiltAngleAvailable"; - mapping["headSupportHorizontalPosition"] = - "headSupportHorizontalPositionAvailable"; - mapping["headSupportVerticalPosition"] = - "headSupportVerticalPositionAvailable"; - mapping["massageEnabled"] = "massageEnabledAvailable"; - mapping["massageMode"] = "massageModeAvailable"; - mapping["massageCushionFirmness"] = "massageCushionFirmnessAvailable"; - mapping["memory"] = "memoryAvailable"; - - // audio - mapping["source"] = "sourceAvailable"; - mapping["keepContext"] = "keepContextAvailable"; - mapping["volume"] = "volumeAvailable"; - mapping["equalizerSettings"] = "equalizerAvailable"; - - // hmi settings - mapping["distanceUnit"] = "distanceUnitAvailable"; - mapping["temperatureUnit"] = "temperatureUnitAvailable"; - mapping["displayMode"] = "displayModeUnitAvailable"; - - return mapping; -} -} // namespace - CREATE_LOGGERPTR_GLOBAL(logger_, "RemoteControlModule") SetInteriorVehicleDataRequest::SetInteriorVehicleDataRequest( @@ -154,250 +54,6 @@ SetInteriorVehicleDataRequest::SetInteriorVehicleDataRequest( SetInteriorVehicleDataRequest::~SetInteriorVehicleDataRequest() {} -const std::string LightName(const smart_objects::SmartObject& light_name) { - const char* name; - const bool ok = ns_smart_device_link::ns_smart_objects:: - EnumConversionHelper<mobile_apis::LightName::eType>::EnumToCString( - static_cast<mobile_apis::LightName::eType>(light_name.asUInt()), - &name); - return ok ? name : "unknown"; -} - -/** - * @brief Check whether the parameter exist in capabilities - * @param smart object of capabilities - * @param mapping - map of module data and capabilities - * @param request_parameter - string - * @param switched_off_result - ref of mobile_apis::Result - * @return success if parameter exist in capabilities missedParam otherwise - */ -capabilitiesStatus GetItemCapability( - const smart_objects::SmartObject& capabilities, - const std::map<std::string, std::string>& mapping, - const std::string& request_parameter, - const mobile_apis::Result::eType& switched_off_result) { - const auto it = mapping.find(request_parameter); - - if (it == mapping.end()) { - LOG4CXX_DEBUG( - logger_, - "Parameter " << request_parameter << " doesn't exist in capabilities."); - return capabilitiesStatus::missedParam; - } - - const std::string& caps_key = it->second; - - LOG4CXX_DEBUG(logger_, - "Checking request parameter " - << request_parameter - << " with capabilities. Appropriate key is " << caps_key); - - if (!capabilities.keyExists(caps_key)) { - LOG4CXX_DEBUG(logger_, - "Capability " << caps_key - << " is missed in RemoteControl capabilities"); - return capabilitiesStatus::missedParam; - } - - if (!capabilities[caps_key].asBool()) { - LOG4CXX_DEBUG(logger_, - "Capability " - << caps_key - << " is switched off in RemoteControl capabilities"); - capabilitiesStatus status = capabilitiesStatus::missedParam; - if (mobile_apis::Result::READ_ONLY == switched_off_result) { - status = capabilitiesStatus::readOnly; - } - return status; - } - - return capabilitiesStatus::success; -} - -/** - * @brief Check whether the cpabilities for light allowed - * @param smart object of capabilities - * @param smart object of control_data - * @return pair of state and capability status - ModuleCapability - */ -ModuleCapability GetLightDataCapabilities( - const smart_objects::SmartObject& capabilities, - const smart_objects::SmartObject& control_data) { - LOG4CXX_AUTO_TRACE(logger_); - std::map<std::string, std::string> mapping = GetLightCapabilitiesMapping(); - - for (auto it = control_data.map_begin(); it != control_data.map_end(); ++it) { - const std::string& request_parameter = it->first; - - if (message_params::kId == request_parameter) { - continue; - } - - const capabilitiesStatus status_item_capability = - GetItemCapability(capabilities, - mapping, - request_parameter, - mobile_apis::Result::READ_ONLY); - - if (capabilitiesStatus::success != status_item_capability) { - return std::make_pair(message_params::kLightState, - status_item_capability); - } - } - - return std::make_pair("", capabilitiesStatus::success); -} - -/** - * @brief Check whether the light name exists in capabilities - * @param smart object of capabilities_status - * @param smart object of light_data - * @return pair of state and capability status - ModuleCapability - */ -ModuleCapability GetLightNameCapabilities( - const smart_objects::SmartObject& capabilities_status, - const smart_objects::SmartObject& light_data) { - LOG4CXX_AUTO_TRACE(logger_); - auto it = capabilities_status.asArray()->begin(); - for (; it != capabilities_status.asArray()->end(); ++it) { - const smart_objects::SmartObject& so = *it; - const int64_t current_id = so[message_params::kName].asInt(); - if (current_id == light_data[message_params::kId].asInt()) { - return GetLightDataCapabilities(so, light_data); - } - } - LOG4CXX_DEBUG(logger_, "There is no such light name in capabilities"); - return std::make_pair(message_params::kLightState, - capabilitiesStatus::missedLightName); -} - -ModuleCapability GetRadioBandByCapabilities( - const smart_objects::SmartObject& capabilities_status, - const smart_objects::SmartObject& request_parameter) { - mobile_apis::RadioBand::eType radio_band = - static_cast<mobile_apis::RadioBand::eType>(request_parameter.asUInt()); - if (mobile_apis::RadioBand::XM == radio_band) { - if (!capabilities_status.keyExists(strings::kSiriusxmRadioAvailable)) { - LOG4CXX_DEBUG(logger_, - "Capability " - << strings::kSiriusxmRadioAvailable - << " is missed in RemoteControl capabilities"); - return std::make_pair(strings::kSiriusxmRadioAvailable, - capabilitiesStatus::missedParam); - } - if (!capabilities_status[strings::kSiriusxmRadioAvailable].asBool()) { - LOG4CXX_DEBUG(logger_, - "Capability " - << strings::kSiriusxmRadioAvailable - << " is switched off in RemoteControl capabilities"); - return std::make_pair(strings::kSiriusxmRadioAvailable, - capabilitiesStatus::missedParam); - } - } - return std::make_pair("", capabilitiesStatus::success); -} - -/** - * @brief Check whether the exists light data related to correspondent - * capabilities - * @param smart object of capabilities - * @param smart object of control_data - * @return pair of state and capability status - ModuleCapability - */ -ModuleCapability GetControlDataCapabilities( - const smart_objects::SmartObject& capabilities, - const smart_objects::SmartObject& control_data) { - LOG4CXX_AUTO_TRACE(logger_); - std::map<std::string, std::string> mapping = - GetModuleDataToCapabilitiesMapping(); - - for (auto it = control_data.map_begin(); it != control_data.map_end(); ++it) { - const std::string& request_parameter = it->first; - if (message_params::kId == request_parameter) { - continue; - } - if (message_params::kLightState == request_parameter) { - auto light_data = control_data[request_parameter].asArray()->begin(); - ModuleCapability light_capability = - std::make_pair("", capabilitiesStatus::success); - - for (; light_data != control_data[request_parameter].asArray()->end(); - ++light_data) { - light_capability = GetLightNameCapabilities( - capabilities[strings::kSupportedLights], *light_data); - - if (capabilitiesStatus::success != light_capability.second) { - return light_capability; - } - } - - return light_capability; - } - if (message_params::kBand == request_parameter) { - ModuleCapability radio_capability = GetRadioBandByCapabilities( - capabilities, control_data[request_parameter]); - if (capabilitiesStatus::success != radio_capability.second) { - return radio_capability; - } - } - - const capabilitiesStatus status_item_capability = - GetItemCapability(capabilities, - mapping, - request_parameter, - mobile_apis::Result::UNSUPPORTED_RESOURCE); - - if (capabilitiesStatus::success != status_item_capability) { - return std::make_pair("", status_item_capability); - } - } - - return std::make_pair("", capabilitiesStatus::success); -} - -/** - * @brief Check whether rc module data capabilities are presented - * @param smart object of rc_capabilities - * @param smart object of module_data - * @return pair of state and capability status - ModuleCapability - */ -ModuleCapability GetModuleDataCapabilities( - const smart_objects::SmartObject& rc_capabilities, - const smart_objects::SmartObject& module_data) { - LOG4CXX_AUTO_TRACE(logger_); - - const auto& all_module_types = RCHelpers::GetModulesList(); - const auto& get_module_data_key = RCHelpers::GetModuleTypeToDataMapping(); - const auto& get_capabilities_key = - RCHelpers::GetModuleTypeToCapabilitiesMapping(); - ModuleCapability module_data_capabilities = - std::make_pair("", capabilitiesStatus::missedParam); - - for (const auto& module_type : all_module_types) { - const auto module_data_key = get_module_data_key(module_type); - const auto capabilities_key = get_capabilities_key(module_type); - if (module_data.keyExists(module_data_key)) { - if (!rc_capabilities.keyExists(capabilities_key)) { - LOG4CXX_DEBUG(logger_, module_data_key << " capabilities not present"); - return module_data_capabilities; - } - const smart_objects::SmartObject& caps = - rc_capabilities[capabilities_key]; - - if (message_params::kHmiSettingsControlData == module_data_key || - message_params::kLightControlData == module_data_key) { - module_data_capabilities = - GetControlDataCapabilities(caps, module_data[module_data_key]); - } else { - module_data_capabilities = - GetControlDataCapabilities(caps[0], module_data[module_data_key]); - } - } - } - - return module_data_capabilities; -} - /** * @brief Clears unrelated module data parameters * @param module type in request @@ -407,7 +63,7 @@ ModuleCapability GetModuleDataCapabilities( bool ClearUnrelatedModuleData(const std::string& module_type, smart_objects::SmartObject& module_data) { LOG4CXX_AUTO_TRACE(logger_); - const auto& all_module_types = RCHelpers::GetModulesList(); + const auto& all_module_types = RCHelpers::GetModuleTypesList(); const auto& data_mapping = RCHelpers::GetModuleTypeToDataMapping(); bool module_type_and_data_match = false; for (const auto& type : all_module_types) { @@ -423,7 +79,7 @@ bool ClearUnrelatedModuleData(const std::string& module_type, } mobile_apis::Result::eType PrepareResultCodeAndInfo( - const ModuleCapability module_data_capabilities, std::string& info) { + const ModuleTypeCapability module_data_capabilities, std::string& info) { mobile_apis::Result::eType result_code = mobile_apis::Result::UNSUPPORTED_RESOURCE; if (message_params::kLightState == module_data_capabilities.first) { @@ -459,25 +115,35 @@ void SetInteriorVehicleDataRequest::Execute() { const std::string module_type = ModuleType(); if (ClearUnrelatedModuleData(module_type, module_data)) { - const smart_objects::SmartObject* rc_capabilities = - hmi_capabilities_.rc_capability(); - ModuleCapability module_data_capabilities; + const std::string module_id = ModuleId(); + const ModuleUid module(module_type, module_id); + if (!rc_capabilities_manager_.CheckIfModuleExistsInCapabilities(module)) { + LOG4CXX_WARN(logger_, + "Accessing not supported module: " << module_type << " " + << module_id); + SetResourceState(ModuleType(), ResourceState::FREE); + SendResponse(false, + mobile_apis::Result::UNSUPPORTED_RESOURCE, + "Accessing not supported module data"); + return; + } - if (rc_capabilities) { - module_data_capabilities = - GetModuleDataCapabilities(*rc_capabilities, module_data); + ModuleTypeCapability module_data_capabilities; + module_data_capabilities = + rc_capabilities_manager_.GetModuleDataCapabilities(module_data, + module_id); - if (capabilitiesStatus::success != module_data_capabilities.second) { - SetResourceState(ModuleType(), ResourceState::FREE); - std::string info; - mobile_apis::Result::eType result = - PrepareResultCodeAndInfo(module_data_capabilities, info); - SendResponse(false, result, info.c_str()); - return; - } + if (capabilitiesStatus::success != module_data_capabilities.second) { + SetResourceState(ModuleType(), ResourceState::FREE); + std::string info; + mobile_apis::Result::eType result = + PrepareResultCodeAndInfo(module_data_capabilities, info); + SendResponse(false, result, info.c_str()); + return; } - if (AreAllParamsReadOnly(module_data)) { + if (rc_capabilities_manager_.AreAllParamsReadOnly(module_data, + module_type)) { LOG4CXX_WARN(logger_, "All request params in module type are READ ONLY!"); SetResourceState(ModuleType(), ResourceState::FREE); SendResponse(false, @@ -488,7 +154,8 @@ void SetInteriorVehicleDataRequest::Execute() { module_data_capabilities = std::make_pair("", capabilitiesStatus::success); - if (AreReadOnlyParamsPresent(module_data, module_data_capabilities)) { + if (rc_capabilities_manager_.AreReadOnlyParamsPresent( + module_data, module_type, module_data_capabilities)) { LOG4CXX_DEBUG(logger_, "Request module type has READ ONLY parameters"); if (enums_value::kLight == module_data_capabilities.first && @@ -535,11 +202,14 @@ void SetInteriorVehicleDataRequest::Execute() { } } + (*message_)[app_mngr::strings::msg_params][message_params::kModuleData] + [message_params::kModuleId] = module_id; SendHMIRequest(hmi_apis::FunctionID::RC_SetInteriorVehicleData, &(*message_)[app_mngr::strings::msg_params], true); } else { LOG4CXX_WARN(logger_, "Request module type & data mismatch!"); + SetResourceState(ModuleType(), ResourceState::FREE); SendResponse(false, mobile_apis::Result::INVALID_DATA, "Request module type & data mismatch!"); @@ -568,13 +238,45 @@ void SetInteriorVehicleDataRequest::on_event( mobile_apis::Result::WARNINGS); smart_objects::SmartObject response_params; + bool is_resource_acquired = false; + if (result) { + if (!IsModuleIdProvided(hmi_response)) { + LOG4CXX_WARN(logger_, + "conditional mandatory parameter " + << message_params::kModuleId + << " missed in hmi response"); + result = false; + result_code = mobile_apis::Result::GENERIC_ERROR; + } response_params = hmi_response[app_mngr::strings::msg_params]; if (enums_value::kAudio == ModuleType()) { CheckAudioSource(( *message_)[app_mngr::strings::msg_params][message_params::kModuleData] [message_params::kAudioControlData]); } + + const std::string module_type = ModuleType(); + const std::string module_id = ModuleId(); + + const rc_rpc_types::ModuleUid resource{module_type, module_id}; + auto app = application_manager_.application(connection_key()); + + if (!app) { + LOG4CXX_ERROR(logger_, "NULL pointer."); + SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED, ""); + return; + } + + const auto app_id = app->app_id(); + + if (!resource_allocation_manager_.IsResourceAlreadyAcquiredByApp(resource, + app_id)) { + resource_allocation_manager_.SetResourceAcquired( + module_type, module_id, app_id); + is_resource_acquired = true; + } + } else { app_mngr::ApplicationSharedPtr app = application_manager_.application(connection_key()); @@ -584,21 +286,12 @@ void SetInteriorVehicleDataRequest::on_event( GetInfo(hmi_response, info); SendResponse( result, result_code, info.c_str(), result ? &response_params : nullptr); -} - -const smart_objects::SmartObject& SetInteriorVehicleDataRequest::ControlData( - const smart_objects::SmartObject& module_data) { - const std::string module_type = ModuleType(); - const auto& all_module_types = RCHelpers::GetModulesList(); - const auto& data_mapping = RCHelpers::GetModuleTypeToDataMapping(); - for (const auto& type : all_module_types) { - if (type == module_type) { - return module_data[data_mapping(type)]; - } + if (is_resource_acquired) { + resource_allocation_manager_.SendOnRCStatusNotifications( + NotificationTrigger::MODULE_ALLOCATION, + std::shared_ptr<application_manager::Application>()); } - NOTREACHED(); - return module_data[0]; } void SetInteriorVehicleDataRequest::CheckAudioSource( @@ -610,116 +303,12 @@ void SetInteriorVehicleDataRequest::CheckAudioSource( } } -bool SetInteriorVehicleDataRequest::AreAllParamsReadOnly( - const smart_objects::SmartObject& module_data) { - LOG4CXX_AUTO_TRACE(logger_); - const smart_objects::SmartObject& module_type_params = - ControlData(module_data); - auto it = module_type_params.map_begin(); - std::vector<std::string> ro_params = GetModuleReadOnlyParams(ModuleType()); - for (; it != module_type_params.map_end(); ++it) { - if (!helpers::in_range(ro_params, it->first)) { - return false; - } - } - - LOG4CXX_DEBUG(logger_, "All params are ReadOnly"); - return true; -} - -bool CheckReadOnlyParamsForAudio( - const smart_objects::SmartObject& module_type_params) { - if (module_type_params.keyExists(message_params::kEqualizerSettings)) { - const auto& equalizer_settings = - module_type_params[message_params::kEqualizerSettings]; - auto it = equalizer_settings.asArray()->begin(); - - for (; it != equalizer_settings.asArray()->end(); ++it) { - if (it->keyExists(message_params::kChannelName)) { - LOG4CXX_DEBUG(logger_, - "READ ONLY parameter. ChannelName = " - << (*it)[message_params::kChannelName].asString()); - return true; - } - } - } - - return false; -} - -bool CheckReadOnlyParamsForLight( - const smart_objects::SmartObject& module_type_params) { - if (module_type_params.keyExists(message_params::kLightState)) { - const auto& light_state = module_type_params[message_params::kLightState]; - auto it = light_state.asArray()->begin(); - - for (; it != light_state.asArray()->end(); ++it) { - if (it->keyExists(message_params::kLightStatus)) { - const mobile_apis::LightStatus::eType light_status = - static_cast<mobile_apis::LightStatus::eType>( - (*it)[message_params::kLightStatus].asUInt()); - - if (helpers::Compare<mobile_apis::LightStatus::eType, - helpers::EQ, - helpers::ONE>(light_status, - mobile_apis::LightStatus::RAMP_UP, - mobile_apis::LightStatus::RAMP_DOWN, - mobile_apis::LightStatus::UNKNOWN, - mobile_apis::LightStatus::INVALID)) { - LOG4CXX_DEBUG(logger_, - "READ ONLY parameter. Status = " - << (*it)[message_params::kLightStatus].asInt()); - return true; - } - } - } - } - - return false; -} - -bool SetInteriorVehicleDataRequest::AreReadOnlyParamsPresent( - const smart_objects::SmartObject& module_data, - ModuleCapability& module_data_capabilities) { - LOG4CXX_AUTO_TRACE(logger_); - const smart_objects::SmartObject& module_type_params = - ControlData(module_data); - const std::string module_type = ModuleType(); - - if (enums_value::kAudio == module_type) { - return CheckReadOnlyParamsForAudio(module_type_params); - } - - if (enums_value::kLight == module_type) { - const bool result = CheckReadOnlyParamsForLight(module_type_params); - - if (result) { - module_data_capabilities = - std::make_pair(module_type, capabilitiesStatus::readOnly); - } - - return result; - } - - const std::vector<std::string> ro_params = - GetModuleReadOnlyParams(module_type); - auto it = module_type_params.map_begin(); - - for (; it != module_type_params.map_end(); ++it) { - if (helpers::in_range(ro_params, it->first)) { - return true; - } - } - - return false; -} - void SetInteriorVehicleDataRequest::CutOffReadOnlyParams( smart_objects::SmartObject& module_data) { LOG4CXX_AUTO_TRACE(logger_); - const smart_objects::SmartObject& module_type_params = - ControlData(module_data); const std::string module_type = ModuleType(); + const auto& module_type_params = + rc_capabilities_manager_.ControlDataForType(module_data, module_type); if (enums_value::kAudio == module_type) { auto& equalizer_settings = module_data[message_params::kAudioControlData] @@ -735,7 +324,8 @@ void SetInteriorVehicleDataRequest::CutOffReadOnlyParams( } } - std::vector<std::string> ro_params = GetModuleReadOnlyParams(module_type); + std::vector<std::string> ro_params = + RCHelpers::GetModuleReadOnlyParams(module_type); const auto& data_mapping = RCHelpers::GetModuleTypeToDataMapping(); for (const auto& param : ro_params) { if (module_type_params.keyExists(param)) { @@ -745,7 +335,8 @@ void SetInteriorVehicleDataRequest::CutOffReadOnlyParams( } } -std::string SetInteriorVehicleDataRequest::ModuleType() { +std::string SetInteriorVehicleDataRequest::ModuleType() const { + LOG4CXX_AUTO_TRACE(logger_); mobile_apis::ModuleType::eType module_type = static_cast<mobile_apis::ModuleType::eType>( (*message_)[app_mngr::strings::msg_params] @@ -757,19 +348,40 @@ std::string SetInteriorVehicleDataRequest::ModuleType() { return ok ? str : "unknown"; } +std::string SetInteriorVehicleDataRequest::ModuleId() const { + LOG4CXX_AUTO_TRACE(logger_); + auto msg_params = (*message_)[app_mngr::strings::msg_params]; + if (msg_params[message_params::kModuleData].keyExists( + message_params::kModuleId)) { + return msg_params[message_params::kModuleData][message_params::kModuleId] + .asString(); + } + if (enums_value::kSeat == ModuleType()) { + const auto id = static_cast<mobile_apis::SupportedSeat::eType>( + msg_params[message_params::kModuleData] + [message_params::kSeatControlData][message_params::kId] + .asUInt()); + return rc_capabilities_manager_.GetModuleIdForSeatLocation(id); + } + const std::string module_id = + rc_capabilities_manager_.GetDefaultModuleIdFromCapabilities(ModuleType()); + return module_id; +} + AcquireResult::eType SetInteriorVehicleDataRequest::AcquireResource( const app_mngr::commands::MessageSharedPtr& message) { LOG4CXX_AUTO_TRACE(logger_); const std::string module_type = ModuleType(); app_mngr::ApplicationSharedPtr app = application_manager_.application(CommandRequestImpl::connection_key()); - return resource_allocation_manager_.AcquireResource(module_type, - app->app_id()); + + return resource_allocation_manager_.AcquireResource( + module_type, ModuleId(), app->app_id()); } bool SetInteriorVehicleDataRequest::IsResourceFree( - const std::string& module_type) const { - return resource_allocation_manager_.IsResourceFree(module_type); + const std::string& module_type, const std::string& module_id) const { + return resource_allocation_manager_.IsResourceFree(module_type, module_id); } void SetInteriorVehicleDataRequest::SetResourceState( @@ -778,7 +390,7 @@ void SetInteriorVehicleDataRequest::SetResourceState( app_mngr::ApplicationSharedPtr app = application_manager_.application(CommandRequestImpl::connection_key()); resource_allocation_manager_.SetResourceState( - module_type, app->app_id(), state); + module_type, ModuleId(), app->app_id(), state); } } // namespace commands 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 065425dd02..885c5ac0dd 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 @@ -31,9 +31,13 @@ */ #include "rc_rpc_plugin/commands/rc_command_request.h" +#include <sstream> #include "application_manager/hmi_interfaces.h" #include "application_manager/message_helper.h" +#include "application_manager/policies/policy_handler_interface.h" +#include "rc_rpc_plugin/commands/rc_command_request.h" #include "rc_rpc_plugin/interior_data_cache.h" +#include "rc_rpc_plugin/rc_helpers.h" #include "rc_rpc_plugin/rc_module_constants.h" #include "smart_objects/enum_schema_item.h" @@ -55,7 +59,9 @@ RCCommandRequest::RCCommandRequest( , auto_allowed_(false) , resource_allocation_manager_(params.resource_allocation_manager_) , interior_data_cache_(params.interior_data_cache_) - , interior_data_manager_(params.interior_data_manager_) {} + , interior_data_manager_(params.interior_data_manager_) + , rc_capabilities_manager_(params.rc_capabilities_manager_) + , rc_consent_manager_(params.rc_consent_manager_) {} RCCommandRequest::~RCCommandRequest() {} @@ -100,6 +106,14 @@ rc_rpc_plugin::TypeAccess RCCommandRequest::CheckModule( : rc_rpc_plugin::TypeAccess::kDisallowed; } +bool RCCommandRequest::IsModuleIdProvided( + const smart_objects::SmartObject& hmi_response) const { + LOG4CXX_AUTO_TRACE(logger_); + return hmi_response[app_mngr::strings::msg_params] + [message_params::kModuleData] + .keyExists(message_params::kModuleId); +} + void RCCommandRequest::SendDisallowed(rc_rpc_plugin::TypeAccess access) { LOG4CXX_AUTO_TRACE(logger_); std::string info; @@ -143,6 +157,15 @@ void RCCommandRequest::Run() { "Remote control is disabled by user"); return; } + auto rc_capabilities = hmi_capabilities_.rc_capability(); + if (!rc_capabilities || rc_capabilities->empty()) { + LOG4CXX_WARN(logger_, "Accessing not supported module: " << ModuleType()); + SetResourceState(ModuleType(), ResourceState::FREE); + SendResponse(false, + mobile_apis::Result::UNSUPPORTED_RESOURCE, + "Accessing not supported module"); + return; + } if (CheckDriverConsent()) { if (AcquireResources()) { @@ -157,8 +180,9 @@ void RCCommandRequest::Run() { bool RCCommandRequest::AcquireResources() { LOG4CXX_AUTO_TRACE(logger_); const std::string module_type = ModuleType(); + const std::string module_id = ModuleId(); - if (!IsResourceFree(module_type)) { + if (!IsResourceFree(module_type, module_id)) { LOG4CXX_WARN(logger_, "Resource is busy."); SendResponse(false, mobile_apis::Result::IN_USE, ""); return false; @@ -175,7 +199,7 @@ bool RCCommandRequest::AcquireResources() { return false; } case AcquireResult::ASK_DRIVER: { - SendGetUserConsent(module_type); + ProcessAskDriverMode(module_type, module_id); return false; } case AcquireResult::REJECTED: { @@ -203,6 +227,7 @@ void RCCommandRequest::ProcessAccessResponse( app_mngr::ApplicationSharedPtr app = application_manager_.application(CommandRequestImpl::connection_key()); const std::string module_type = ModuleType(); + const std::string module_id = ModuleId(); if (!app) { LOG4CXX_ERROR(logger_, "NULL pointer."); SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED, ""); @@ -227,23 +252,18 @@ void RCCommandRequest::ProcessAccessResponse( if (message[app_mngr::strings::msg_params].keyExists( message_params::kAllowed)) { is_allowed = - message[app_mngr::strings::msg_params][message_params::kAllowed] + message[app_mngr::strings::msg_params][message_params::kAllowed][0] .asBool(); } - if (is_allowed) { - resource_allocation_manager_.ForceAcquireResource(module_type, - app->app_id()); - SetResourceState(module_type, ResourceState::BUSY); - Execute(); // run child's logic - } else { - resource_allocation_manager_.OnDriverDisallowed(module_type, - app->app_id()); - SendResponse( - false, - mobile_apis::Result::REJECTED, - "The resource is in use and the driver disallows this remote " - "control RPC"); - } + std::string policy_app_id = app->policy_app_id(); + const auto mac_address = app->mac_address(); + std::vector<std::string> module_ids{module_id}; + std::vector<bool> module_allowed{is_allowed}; + auto module_consents = + RCHelpers::FillModuleConsents(module_type, module_ids, module_allowed); + rc_consent_manager_.SaveModuleConsents( + policy_app_id, mac_address, module_consents); + ProcessConsentResult(is_allowed, module_type, module_id, app->app_id()); } else { std::string response_info; GetInfo(message, response_info); @@ -251,7 +271,56 @@ void RCCommandRequest::ProcessAccessResponse( } } -void RCCommandRequest::SendGetUserConsent(const std::string& module_type) { +void RCCommandRequest::ProcessConsentResult(const bool is_allowed, + const std::string& module_type, + const std::string& module_id, + const uint32_t app_id) { + LOG4CXX_AUTO_TRACE(logger_); + if (is_allowed) { + SetResourceState(module_type, ResourceState::BUSY); + Execute(); // run child's logic + } else { + resource_allocation_manager_.OnDriverDisallowed( + module_type, module_id, app_id); + + std::stringstream ss; + ss << "The resource [" << module_type << ":" << module_id + << "] is in use and the driver disallows this remote " + "control RPC"; + SendResponse(false, mobile_apis::Result::REJECTED, ss.str().c_str()); + } +} + +void RCCommandRequest::ProcessAskDriverMode(const std::string& module_type, + const std::string& module_id) { + LOG4CXX_AUTO_TRACE(logger_); + auto app = + application_manager_.application(CommandRequestImpl::connection_key()); + const std::string policy_app_id = app->policy_app_id(); + const std::string mac_address = app->mac_address(); + + auto consent = rc_consent_manager_.GetModuleConsent( + policy_app_id, mac_address, {module_type, module_id}); + switch (consent) { + case rc_rpc_types::ModuleConsent::NOT_EXISTS: { + smart_objects::SmartObject module_ids( + smart_objects::SmartType::SmartType_Array); + module_ids[0] = module_id; + SendGetUserConsent(module_type, module_ids); + break; + } + case rc_rpc_types::ModuleConsent::NOT_CONSENTED: + case rc_rpc_types::ModuleConsent::CONSENTED: { + const bool is_allowed = rc_rpc_types::ModuleConsent::CONSENTED == consent; + ProcessConsentResult(is_allowed, module_type, module_id, app->app_id()); + break; + } + }; +} + +void RCCommandRequest::SendGetUserConsent( + const std::string& module_type, + const smart_objects::SmartObject& module_ids) { LOG4CXX_AUTO_TRACE(logger_); app_mngr::ApplicationSharedPtr app = application_manager_.application(CommandRequestImpl::connection_key()); @@ -260,6 +329,8 @@ void RCCommandRequest::SendGetUserConsent(const std::string& module_type) { smart_objects::SmartObject(smart_objects::SmartType_Map); msg_params[app_mngr::strings::app_id] = app->app_id(); msg_params[message_params::kModuleType] = module_type; + msg_params[message_params::kModuleIds] = module_ids; + SendHMIRequest(hmi_apis::FunctionID::RC_GetInteriorVehicleDataConsent, &msg_params, true); diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/interior_data_cache_impl.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/interior_data_cache_impl.cc index 2c8683f84a..3e50818210 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/interior_data_cache_impl.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/interior_data_cache_impl.cc @@ -35,6 +35,7 @@ #include <iostream> #include <thread> #include "application_manager/smart_object_keys.h" +#include "rc_rpc_plugin/rc_helpers.h" #include "utils/date_time.h" #include "utils/logger.h" @@ -46,138 +47,72 @@ InteriorDataCacheImpl::InteriorDataCacheImpl() {} InteriorDataCacheImpl::~InteriorDataCacheImpl() {} -/** - * @brief MergeModuleData all keys and values from first parameter and - * update and append keys and values from the second - * @param data1 - initial data - * @param data2 - updated data - * @return updated data1 with data2 keys and values - */ -smart_objects::SmartObject MergeModuleData( - const smart_objects::SmartObject& data1, - const smart_objects::SmartObject& data2); - -/** - * @brief MergeArray merge two arrays if their elements contain an `id` - * parameter - * @param data1 - initial data - * @param data2 - updated data - * @return updated data1 with any values in data2 if the arrays can be merged, - * otherwise data2 - */ -smart_objects::SmartObject MergeArray(const smart_objects::SmartObject& data1, - const smart_objects::SmartObject& data2); - -smart_objects::SmartObject MergeModuleData( - const smart_objects::SmartObject& data1, - const smart_objects::SmartObject& data2) { - smart_objects::SmartObject result = data1; - auto it = data2.map_begin(); - for (; it != data2.map_end(); ++it) { - const std::string& key = it->first; - smart_objects::SmartObject& value = it->second; - if (!result.keyExists(key) || value.getType() != result[key].getType()) { - result[key] = value; - continue; - } - - // Merge maps and arrays with `id` param included, replace other types - if (value.getType() == smart_objects::SmartType::SmartType_Map) { - value = MergeModuleData(result[key], value); - } else if (value.getType() == smart_objects::SmartType::SmartType_Array) { - value = MergeArray(result[key], value); - } - result[key] = value; - } - return result; -} - -smart_objects::SmartObject MergeArray(const smart_objects::SmartObject& data1, - const smart_objects::SmartObject& data2) { - // Merge data only in the case where each value in the array is an Object with - // an ID included, otherwise replace - bool array_contains_objects = - !data2.empty() && - data2.getElement(0).getType() != smart_objects::SmartType::SmartType_Map; - bool can_merge_arrays = - array_contains_objects && - data2.getElement(0).keyExists(application_manager::strings::id); - if (!can_merge_arrays) { - return data2; - } - - smart_objects::SmartObject result = data1; - smart_objects::SmartArray* result_array = result.asArray(); - smart_objects::SmartArray* data_array = data2.asArray(); - auto data_it = data_array->begin(); - auto find_by_id = [](smart_objects::SmartArray* array, - const smart_objects::SmartObject& id) - -> smart_objects::SmartArray::iterator { - auto it = std::find_if(array->begin(), - array->end(), - [&id](smart_objects::SmartObject& obj) -> bool { - return obj[application_manager::strings::id] == id; - }); - return it; - }; - - for (; data_it != data_array->end(); ++data_it) { - const smart_objects::SmartObject element_id = - (*data_it)[application_manager::strings::id]; - auto result_it = find_by_id(result_array, element_id); - - if (result_it != result_array->end()) { - *result_it = MergeModuleData(*result_it, *data_it); - } else { - result_array->push_back(*data_it); - } - } - return result; -} - -void InteriorDataCacheImpl::Add(const std::string& module_type, +void InteriorDataCacheImpl::Add(const ModuleUid& module, const smart_objects::SmartObject& module_data) { - LOG4CXX_TRACE(logger_, "module_type : " << module_type); + LOG4CXX_TRACE( + logger_, + "module_type : " << module.first << " module_id : " << module.second); sync_primitives::AutoLock autolock(cached_data_lock_); - auto it = cached_data_.find(module_type); + auto it = cached_data_.find(module); if (cached_data_.end() == it) { - cached_data_[module_type] = module_data; + cached_data_[module] = module_data; return; } - cached_data_[module_type] = MergeModuleData(it->second, module_data); + cached_data_[module] = RCHelpers::MergeModuleData(it->second, module_data); } smart_objects::SmartObject InteriorDataCacheImpl::Retrieve( - const std::string& module_type) const { + const ModuleUid& module) const { LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock autolock(cached_data_lock_); - auto it = cached_data_.find(module_type); + auto it = cached_data_.find(module); if (it == cached_data_.end()) { LOG4CXX_WARN(logger_, - "Module type " << module_type << " was not found in cache"); + "Module with type: " << module.first + << " and id: " << module.second + << " was not found in cache"); return smart_objects::SmartObject(smart_objects::SmartType_Null); } - LOG4CXX_TRACE(logger_, "module_type : " << module_type); + LOG4CXX_TRACE( + logger_, + "module_type : " << module.first << " module_id : " << module.second); return it->second; } -bool InteriorDataCacheImpl::Contains(const std::string& module_type) const { +std::vector<ModuleUid> InteriorDataCacheImpl::GetCachedModulesByType( + const std::string& module_type) const { + std::vector<ModuleUid> modules; + for (auto& item : cached_data_) { + auto& module = item.first; + if (module_type == module.first) { + modules.push_back(module); + } + } + return modules; +} + +bool InteriorDataCacheImpl::Contains(const ModuleUid& module) const { LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock autolock(cached_data_lock_); - auto it = cached_data_.find(module_type); + auto it = cached_data_.find(module); const bool contains = it != cached_data_.end(); - LOG4CXX_TRACE( - logger_, - "module_type : " << module_type << " " << (contains ? "true" : "false")); + LOG4CXX_TRACE(logger_, + "module_type : " << module.first + << " module_id : " << module.second << " " + << (contains ? "true" : "false")); return contains; } -void InteriorDataCacheImpl::Remove(const std::string& module_type) { - LOG4CXX_TRACE(logger_, "module_type : " << module_type); +void InteriorDataCacheImpl::Remove(const ModuleUid& module) { + LOG4CXX_TRACE( + logger_, + "module_type : " << module.first << " module_id : " << module.second); sync_primitives::AutoLock autolock(cached_data_lock_); - auto it = cached_data_.find(module_type); + auto it = cached_data_.find(module); if (cached_data_.end() == it) { - LOG4CXX_TRACE(logger_, "Not existing module_type : " << module_type); + LOG4CXX_TRACE( + logger_, + "Not existing module : " << module.first << " " << module.second); return; } cached_data_.erase(it); diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/interior_data_manager_impl.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/interior_data_manager_impl.cc index cb800a6081..50568de63a 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/interior_data_manager_impl.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/interior_data_manager_impl.cc @@ -33,7 +33,7 @@ void InteriorDataManagerImpl::OnApplicationEvent( void InteriorDataManagerImpl::OnDisablingRC() { LOG4CXX_AUTO_TRACE(logger_); auto existing_subscription = AppsSubscribedModules(); - std::set<std::string> subscribed_modules; + std::set<ModuleUid> subscribed_modules; for (auto& pair : existing_subscription) { auto& app = pair.first; auto rc_extension = RCHelpers::GetRCExtension(*app); @@ -43,36 +43,37 @@ void InteriorDataManagerImpl::OnDisablingRC() { } } for (auto& module : subscribed_modules) { - LOG4CXX_TRACE(logger_, "unsubscribe " << module); + LOG4CXX_TRACE(logger_, + "unsubscribe from module type: " << module.first + << " id: " << module.second); UnsubscribeFromInteriorVehicleData(module); } } -void InteriorDataManagerImpl::StoreRequestToHMITime( - const std::string& module_type) { +void InteriorDataManagerImpl::StoreRequestToHMITime(const ModuleUid& module) { LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock autolock(requests_to_hmi_history_lock_); - requests_to_hmi_history_[module_type].push_back(date_time::getCurrentTime()); + requests_to_hmi_history_[module].push_back(date_time::getCurrentTime()); } bool InteriorDataManagerImpl::CheckRequestsToHMIFrequency( - const std::string& module_type) { + const ModuleUid& module) { LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock autolock(requests_to_hmi_history_lock_); ClearOldRequestsToHMIHistory(); - const auto& history = requests_to_hmi_history_[module_type]; + const auto& history = requests_to_hmi_history_[module]; const auto limit = app_mngr_.get_settings().get_interior_vehicle_data_frequency().first; return history.size() < limit; } void InteriorDataManagerImpl::UpdateHMISubscriptionsOnPolicyUpdated() { - auto apps_allowed_modules = - RCHelpers::GetApplicationsAllowedModules(app_mngr_); - auto apps_subscribed_modules = AppsSubscribedModules(); - InteriorDataManagerImpl::AppsModules apps_disallowed_modules; - for (auto& pair : apps_subscribed_modules) { - auto& allowed = apps_allowed_modules[pair.first]; + auto apps_allowed_module_types = + RCHelpers::GetApplicationsAllowedModuleTypes(app_mngr_); + auto apps_subscribed_module_types = AppsSubscribedModuleTypes(); + InteriorDataManagerImpl::AppsModuleTypes apps_disallowed_modules; + for (auto& pair : apps_subscribed_module_types) { + auto& allowed = apps_allowed_module_types[pair.first]; auto& subscribed = pair.second; std::vector<std::string> disallowed_modules; std::set_difference(subscribed.begin(), @@ -80,18 +81,25 @@ void InteriorDataManagerImpl::UpdateHMISubscriptionsOnPolicyUpdated() { allowed.begin(), allowed.end(), std::back_inserter(disallowed_modules)); + + std::sort(disallowed_modules.begin(), disallowed_modules.end()); + + auto unique_result = + std::unique(disallowed_modules.begin(), disallowed_modules.end()); + + disallowed_modules.erase(unique_result, disallowed_modules.end()); apps_disallowed_modules[pair.first] = disallowed_modules; } for (auto& pair : apps_disallowed_modules) { auto& app = pair.first; auto rc_extension = RCHelpers::GetRCExtension(*app); - for (const auto& module : pair.second) { - rc_extension->UnsubscribeFromInteriorVehicleData(module); + for (const auto& module_type : pair.second) { + rc_extension->UnsubscribeFromInteriorVehicleDataOfType(module_type); auto apps_subscribed = - RCHelpers::AppsSubscribedToModuleType(app_mngr_, module); + RCHelpers::AppsSubscribedToModuleType(app_mngr_, module_type); if (apps_subscribed.empty()) { - UnsubscribeFromInteriorVehicleData(module); + UnsubscribeFromInteriorVehicleDataOfType(module_type); } } } @@ -104,8 +112,7 @@ void InteriorDataManagerImpl::UpdateHMISubscriptionsOnAppUnregistered( auto subscribed_data = rc_extension->InteriorVehicleDataSubscriptions(); rc_extension->UnsubscribeFromInteriorVehicleData(); for (auto& data : subscribed_data) { - auto apps_subscribed = - RCHelpers::AppsSubscribedToModuleType(app_mngr_, data); + auto apps_subscribed = RCHelpers::AppsSubscribedToModule(app_mngr_, data); if (apps_subscribed.empty()) { UnsubscribeFromInteriorVehicleData(data); } @@ -117,14 +124,31 @@ void InteriorDataManagerImpl::UpdateHMISubscriptionsOnAppUnregistered( } void InteriorDataManagerImpl::UnsubscribeFromInteriorVehicleData( - const std::string& module_type) { - cache_.Remove(module_type); + const ModuleUid& module) { + cache_.Remove(module); auto unsubscribe_request = RCHelpers::CreateUnsubscribeRequestToHMI( - module_type, app_mngr_.GetNextHMICorrelationID()); - LOG4CXX_DEBUG(logger_, "Send Unsubscribe from " << module_type); + module, app_mngr_.GetNextHMICorrelationID()); + LOG4CXX_DEBUG(logger_, + "Send Unsubscribe from module type: " << module.first << " id: " + << module.second); rpc_service_.ManageHMICommand(unsubscribe_request); } +void InteriorDataManagerImpl::UnsubscribeFromInteriorVehicleDataOfType( + const std::string& module_type) { + const auto& modules = cache_.GetCachedModulesByType(module_type); + + for (const auto& module : modules) { + cache_.Remove(module); + auto unsubscribe_request = RCHelpers::CreateUnsubscribeRequestToHMI( + module, app_mngr_.GetNextHMICorrelationID()); + LOG4CXX_DEBUG(logger_, + "Send Unsubscribe from module type: " + << module.first << " id: " << module.second); + rpc_service_.ManageHMICommand(unsubscribe_request); + } +} + void InteriorDataManagerImpl::ClearOldRequestsToHMIHistory() { auto limit = app_mngr_.get_settings().get_interior_vehicle_data_frequency().second; @@ -148,11 +172,30 @@ InteriorDataManagerImpl::AppsSubscribedModules() { for (auto& app_ptr : apps_list) { const auto rc_extension = RCHelpers::GetRCExtension(*app_ptr); auto app_subscriptions = rc_extension->InteriorVehicleDataSubscriptions(); - result[app_ptr] = std::vector<std::string>(app_subscriptions.size()); + result[app_ptr] = std::vector<ModuleUid>(app_subscriptions.size()); std::copy(app_subscriptions.begin(), app_subscriptions.end(), result[app_ptr].begin()); } return result; } + +InteriorDataManagerImpl::AppsModuleTypes +InteriorDataManagerImpl::AppsSubscribedModuleTypes() { + auto apps_list = RCRPCPlugin::GetRCApplications(app_mngr_); + RCHelpers::AppsModuleTypes result; + for (auto& app_ptr : apps_list) { + const auto rc_extension = RCHelpers::GetRCExtension(*app_ptr); + auto app_subscriptions = rc_extension->InteriorVehicleDataSubscriptions(); + std::vector<std::string> app_module_types; + + for (auto& app_subscription : app_subscriptions) { + app_module_types.push_back(app_subscription.first); + } + + std::sort(app_module_types.begin(), app_module_types.end()); + result[app_ptr] = app_module_types; + } + return result; +} } // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_app_extension.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_app_extension.cc index 5282da8d83..ea9c13113c 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_app_extension.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_app_extension.cc @@ -31,29 +31,51 @@ */ #include "rc_rpc_plugin/rc_app_extension.h" +#include <algorithm> +#include "rc_rpc_plugin/rc_module_constants.h" +#include "smart_objects/smart_object.h" namespace rc_rpc_plugin { RCAppExtension::RCAppExtension(application_manager::AppExtensionUID uid) : AppExtension(uid) {} -void RCAppExtension::SubscribeToInteriorVehicleData( - const std::string& module_type) { - subscribed_interior_vehicle_data_.insert(module_type); +void RCAppExtension::SubscribeToInteriorVehicleData(const ModuleUid& module) { + subscribed_interior_vehicle_data_.insert(module); } void RCAppExtension::UnsubscribeFromInteriorVehicleData( + const ModuleUid& module) { + subscribed_interior_vehicle_data_.erase(module); +} + +void RCAppExtension::UnsubscribeFromInteriorVehicleDataOfType( const std::string& module_type) { - subscribed_interior_vehicle_data_.erase(module_type); + for (auto& item : subscribed_interior_vehicle_data_) { + if (module_type == item.first) { + subscribed_interior_vehicle_data_.erase(item); + } + } } void RCAppExtension::UnsubscribeFromInteriorVehicleData() { subscribed_interior_vehicle_data_.clear(); } -bool RCAppExtension::IsSubscibedToInteriorVehicleData( +bool RCAppExtension::IsSubscribedToInteriorVehicleDataOfType( const std::string& module_type) { - std::set<std::string>::iterator it = - subscribed_interior_vehicle_data_.find(module_type); + auto it = std::find_if(subscribed_interior_vehicle_data_.begin(), + subscribed_interior_vehicle_data_.end(), + [&module_type](ModuleUid module) -> bool { + return module_type == module.first; + }); + + return (it != subscribed_interior_vehicle_data_.end()); +} + +bool RCAppExtension::IsSubscribedToInteriorVehicleData( + const ModuleUid& module) { + std::set<ModuleUid>::iterator it = + subscribed_interior_vehicle_data_.find(module); return (it != subscribed_interior_vehicle_data_.end()); } @@ -65,9 +87,29 @@ void RCAppExtension::ProcessResumption( const ns_smart_device_link::ns_smart_objects::SmartObject& resumption_data) {} -std::set<std::string> RCAppExtension::InteriorVehicleDataSubscriptions() const { +std::set<ModuleUid> RCAppExtension::InteriorVehicleDataSubscriptions() const { return subscribed_interior_vehicle_data_; } +Grid RCAppExtension::GetUserLocation() const { + return user_location_; +} + +void RCAppExtension::SetUserLocation( + const ns_smart_device_link::ns_smart_objects::SmartObject& user_location) { + const auto grid = user_location[strings::kGrid]; + const int32_t col = grid[strings::kCol].asInt(); + const int32_t row = grid[strings::kRow].asInt(); + const int32_t level = grid[strings::kLevel].asInt(); + const int32_t colspan = grid[strings::kColspan].asInt(); + const int32_t rowspan = grid[strings::kRowspan].asInt(); + const int32_t levelspan = grid[strings::kLevelspan].asInt(); + user_location_ = Grid(col, row, level, colspan, rowspan, levelspan); +} + +void RCAppExtension::SetUserLocation(const Grid& grid) { + user_location_ = grid; +} + RCAppExtension::~RCAppExtension() {} } // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_capabilities_manager_impl.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_capabilities_manager_impl.cc new file mode 100644 index 0000000000..dbedd0167f --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_capabilities_manager_impl.cc @@ -0,0 +1,925 @@ +/* + 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 copyright holders nor the names of their 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 "rc_rpc_plugin/rc_capabilities_manager_impl.h" +#include "rc_rpc_plugin/rc_helpers.h" +#include "rc_rpc_plugin/rc_module_constants.h" + +namespace rc_rpc_plugin { +CREATE_LOGGERPTR_GLOBAL(logger_, "RemoteControlModule") + +RCCapabilitiesManagerImpl::RCCapabilitiesManagerImpl( + application_manager::HMICapabilities& hmi_capabilities) + : hmi_capabilities_(hmi_capabilities) {} + +const std::string +RCCapabilitiesManagerImpl::GetDefaultModuleIdFromCapabilitiesStructure( + const smart_objects::SmartObject& control_capabilities, + const std::string& module_type) const { + LOG4CXX_AUTO_TRACE(logger_); + if (control_capabilities.keyExists(message_params::kModuleInfo)) { + // moduleId - mandatory param for ModuleInfo structure + const auto module_id = control_capabilities[message_params::kModuleInfo] + [message_params::kModuleId] + .asString(); + LOG4CXX_WARN(logger_, + "Use default moduleId from hmi capabilities: " + << module_id + << " for requested moduleType: " << module_type); + return module_id; + } + LOG4CXX_WARN(logger_, + "There are no moduleInfo in hmi capabilities for requested " + "moduleType " + << module_type); + return ""; +} + +const std::string +RCCapabilitiesManagerImpl::GetDefaultModuleIdFromCapabilitiesArray( + const smart_objects::SmartObject& control_capabilities, + const std::string& module_type) const { + LOG4CXX_AUTO_TRACE(logger_); + for (auto& cap_item : *(control_capabilities.asArray())) { + if (cap_item.keyExists(message_params::kModuleInfo)) { + // moduleId - mandatory param for ModuleInfo structure + const auto module_id = + cap_item[message_params::kModuleInfo][message_params::kModuleId] + .asString(); + LOG4CXX_WARN(logger_, + "Use default moduleId from hmi capabilities: " + << module_id + << " for requested moduleType: " << module_type); + return module_id; + } + } + LOG4CXX_WARN(logger_, + "There are no moduleInfo in hmi capabilities for requested " + "moduleType " + << module_type); + return ""; +} + +const std::string RCCapabilitiesManagerImpl::GetDefaultModuleIdFromCapabilities( + const std::string& module_type) const { + LOG4CXX_AUTO_TRACE(logger_); + auto rc_capabilities = *(hmi_capabilities_.rc_capability()); + const auto& mapping = RCHelpers::GetModuleTypeToCapabilitiesMapping(); + if (!rc_capabilities.keyExists(mapping(module_type))) { + LOG4CXX_WARN( + logger_, + "There is no RC capability for requested module_type " << module_type); + return ""; + } + if (enums_value::kHmiSettings == module_type || + enums_value::kLight == module_type) { + return GetDefaultModuleIdFromCapabilitiesStructure( + rc_capabilities[mapping(module_type)], module_type); + } + return GetDefaultModuleIdFromCapabilitiesArray( + rc_capabilities[mapping(module_type)], module_type); +} + +const bool RCCapabilitiesManagerImpl::CheckModuleIdWithCapabilitiesStructure( + const smart_objects::SmartObject& control_capabilities, + const std::string& module_id) const { + LOG4CXX_AUTO_TRACE(logger_); + if (control_capabilities.keyExists(message_params::kModuleInfo) && + (module_id == control_capabilities[message_params::kModuleInfo] + [message_params::kModuleId] + .asString())) { + return true; + } + LOG4CXX_WARN(logger_, + "There are no moduleInfo in hmi capabilities for requested " + "moduleId " + << module_id); + return false; +} + +const bool RCCapabilitiesManagerImpl::CheckModuleIdWithCapabilitiesArrays( + const smart_objects::SmartObject& control_capabilities, + const std::string& module_id) const { + LOG4CXX_AUTO_TRACE(logger_); + for (auto& cap_item : *(control_capabilities.asArray())) { + if (cap_item.keyExists(message_params::kModuleInfo) && + (module_id == + cap_item[message_params::kModuleInfo][message_params::kModuleId] + .asString())) { + return true; + } + } + LOG4CXX_WARN(logger_, + "There are no moduleInfo in hmi capabilities for requested " + "moduleId " + << module_id); + return false; +} + +const bool RCCapabilitiesManagerImpl::CheckModuleIdWithCapabilities( + const smart_objects::SmartObject& rc_capabilities, + const ModuleUid& module) const { + LOG4CXX_AUTO_TRACE(logger_); + if (module.second.empty()) { + return true; + } + const auto& mapping = RCHelpers::GetModuleTypeToCapabilitiesMapping(); + if (enums_value::kHmiSettings == module.first || + enums_value::kLight == module.first) { + return CheckModuleIdWithCapabilitiesStructure( + rc_capabilities[mapping(module.first)], module.second); + } + return CheckModuleIdWithCapabilitiesArrays( + rc_capabilities[mapping(module.first)], module.second); +} + +bool RCCapabilitiesManagerImpl::CheckIfModuleExistsInCapabilities( + const ModuleUid& module) const { + LOG4CXX_AUTO_TRACE(logger_); + auto rc_capabilities = *(hmi_capabilities_.rc_capability()); + const auto& mapping = RCHelpers::GetModuleTypeToCapabilitiesMapping(); + const auto& resource_list = GetResources(); + bool is_module_type_valid = false; + for (const auto& resource : resource_list) { + if (resource.first == module.first) { + if (rc_capabilities.keyExists(mapping(module.first)) && + CheckModuleIdWithCapabilities(rc_capabilities, module)) { + is_module_type_valid = true; + break; + } + } + } + return is_module_type_valid; +} + +const std::vector<std::string> RCCapabilitiesManagerImpl::GetCapabilitiesList() + const { + using namespace enums_value; + return {strings::kclimateControlCapabilities, + strings::kradioControlCapabilities, + strings::kseatControlCapabilities, + strings::kaudioControlCapabilities, + strings::klightControlCapabilities, + strings::khmiSettingsControlCapabilities}; +} + +const std::function<std::string(const std::string& control_cap)> +RCCapabilitiesManagerImpl::GetCapabilitiesToModuleTypeMapping() const { + auto mapping_lambda = [](const std::string& control_cap) -> std::string { + static std::map<std::string, std::string> mapping = { + {strings::kclimateControlCapabilities, enums_value::kClimate}, + {strings::kradioControlCapabilities, enums_value::kRadio}, + {strings::kseatControlCapabilities, enums_value::kSeat}, + {strings::kaudioControlCapabilities, enums_value::kAudio}, + {strings::klightControlCapabilities, enums_value::kLight}, + {strings::khmiSettingsControlCapabilities, enums_value::kHmiSettings}}; + auto it = mapping.find(control_cap); + if (mapping.end() == it) { + LOG4CXX_ERROR(logger_, "Unknown control capability " << control_cap); + return std::string(); + } + return it->second; + }; + + return mapping_lambda; +} + +void RCCapabilitiesManagerImpl::GetResourcesFromCapabilitiesStructure( + const smart_objects::SmartObject& control_capabilities, + const std::string& capability_key, + std::vector<ModuleUid>& out_resources) const { + const auto& mapping = GetCapabilitiesToModuleTypeMapping(); + if (control_capabilities.keyExists(message_params::kModuleInfo)) { + std::string module_id = control_capabilities[message_params::kModuleInfo] + [message_params::kModuleId] + .asString(); + out_resources.push_back(std::make_pair(mapping(capability_key), module_id)); + } else { + LOG4CXX_WARN(logger_, "There are no moduleId in " << capability_key); + out_resources.push_back(std::make_pair(mapping(capability_key), "")); + } +} + +void RCCapabilitiesManagerImpl::GetResourcesFromCapabilitiesArray( + const smart_objects::SmartObject& control_capabilities, + const std::string& capability_key, + std::vector<ModuleUid>& out_resources) const { + const auto& mapping = GetCapabilitiesToModuleTypeMapping(); + for (auto cap_item : *(control_capabilities.asArray())) { + if (cap_item.keyExists(message_params::kModuleInfo)) { + std::string module_id = + cap_item[message_params::kModuleInfo][message_params::kModuleId] + .asString(); + out_resources.push_back( + std::make_pair(mapping(capability_key), module_id)); + } else { + LOG4CXX_WARN(logger_, + "There are no moduleId for item from " << capability_key); + out_resources.push_back(std::make_pair(mapping(capability_key), "")); + } + } +} + +const std::vector<ModuleUid> RCCapabilitiesManagerImpl::GetResources() const { + LOG4CXX_AUTO_TRACE(logger_); + std::vector<ModuleUid> resources; + auto rc_capabilities = *(hmi_capabilities_.rc_capability()); + const auto& control_caps_list = GetCapabilitiesList(); + for (const auto& capability_key : control_caps_list) { + if (rc_capabilities.keyExists(capability_key)) { + if (strings::khmiSettingsControlCapabilities == capability_key || + strings::klightControlCapabilities == capability_key) { + GetResourcesFromCapabilitiesStructure( + rc_capabilities[capability_key], capability_key, resources); + } else { + GetResourcesFromCapabilitiesArray( + rc_capabilities[capability_key], capability_key, resources); + } + } + } + return resources; +} + +const std::string RCCapabilitiesManagerImpl::GetModuleIdForSeatLocation( + const mobile_apis::SupportedSeat::eType id) const { + LOG4CXX_AUTO_TRACE(logger_); + auto rc_capabilities = *(hmi_capabilities_.rc_capability()); + const auto seat_capabilities = + rc_capabilities[strings::kseatControlCapabilities]; + if (seat_capabilities.length() > 0) { + if (mobile_apis::SupportedSeat::DRIVER == id) { + return seat_capabilities[0][message_params::kModuleInfo] + [message_params::kModuleId] + .asString(); + } + if ((seat_capabilities.length() > 1) && + mobile_apis::SupportedSeat::FRONT_PASSENGER == id) { + return seat_capabilities[1][message_params::kModuleInfo] + [message_params::kModuleId] + .asString(); + } + } + LOG4CXX_DEBUG(logger_, "There are no capabitities for requested id: " << id); + return ""; +} + +bool RCCapabilitiesManagerImpl::CheckIfButtonExistInRCCaps( + const mobile_apis::ButtonName::eType button) const { + auto rc_capabilities = *(hmi_capabilities_.rc_capability()); + if (rc_capabilities.keyExists(strings::kbuttonCapabilities)) { + const smart_objects::SmartObject& button_caps = + rc_capabilities[strings::kbuttonCapabilities]; + for (auto& button_cap : *(button_caps.asArray())) { + int64_t current_id = button_cap[message_params::kName].asInt(); + if (-1 == current_id) { + // capabilities received from HMI contains enum values + // capabilities loaded from file contains string values + // TODO : unificate capabilities storing + const std::string& bt_name = + button_cap[message_params::kName].asString(); + static RCHelpers::ButtonsMap btn_map = RCHelpers::buttons_map(); + current_id = btn_map[bt_name]; + } + const mobile_apis::ButtonName::eType current_button = + static_cast<mobile_apis::ButtonName::eType>(current_id); + if (current_button == button) { + LOG4CXX_TRACE( + logger_, + "Button id " << current_button << " exist in capabilities"); + return true; + } + } + } + LOG4CXX_TRACE(logger_, + "Button id " << button << " do not exist in capabilities"); + return false; +} + +smart_objects::SmartObject +RCCapabilitiesManagerImpl::GetCapabilitiesByModuleIdFromArray( + const smart_objects::SmartObject& module_data_capabilities, + const std::string& module_id) const { + for (auto& cap_item : *(module_data_capabilities.asArray())) { + std::string current_id = + cap_item[message_params::kModuleInfo][message_params::kModuleId] + .asString(); + if (module_id == current_id) { + return cap_item; + } + } + LOG4CXX_WARN(logger_, + "Capabilities for moduleId " << module_id + << " do not exist in capabilities"); + return smart_objects::SmartObject(smart_objects::SmartType_Null); +} + +bool RCCapabilitiesManagerImpl::CheckButtonName( + const std::string& module_type, const std::string& button_name) const { + LOG4CXX_AUTO_TRACE(logger_); + auto rc_capabilities = hmi_capabilities_.rc_capability(); + if (!rc_capabilities) { + LOG4CXX_ERROR(logger_, "No remote controll capabilities available"); + return false; + } + + if (enums_value::kRadio == module_type) { + if (!helpers::in_range(RCHelpers::buttons_radio(), button_name)) { + LOG4CXX_WARN(logger_, + "Trying to acceess climate button with module type radio"); + return false; + } + } + + if (enums_value::kClimate == module_type) { + if (!helpers::in_range(RCHelpers::buttons_climate(), button_name)) { + LOG4CXX_WARN(logger_, + "Trying to acceess radio button with module type climate"); + return false; + } + } + return true; +} + +const std::map<std::string, std::string> +RCCapabilitiesManagerImpl::GetLightCapabilitiesMapping() const { + std::map<std::string, std::string> mapping = { + {message_params::kId, strings::kName}, + {message_params::kLightStatus, strings::kStatusAvailable}, + {message_params::kLightDensity, strings::kDensityAvailable}, + {message_params::kLightColor, strings::kRGBColorSpaceAvailable}}; + return mapping; +} + +const std::map<std::string, std::string> +RCCapabilitiesManagerImpl::GetModuleDataToCapabilitiesMapping() const { + std::map<std::string, std::string> mapping; + using namespace message_params; + using namespace rc_rpc_plugin::strings; + // climate + mapping[kFanSpeed] = kFanSpeedAvailable; + mapping[kCurrentTemperature] = kCurrentTemperatureAvailable; + mapping[kDesiredTemperature] = kDesiredTemperatureAvailable; + mapping[kACEnable] = kAcEnableAvailable; + mapping[kCirculateAirEnable] = kCirculateAirEnableAvailable; + mapping[kAutoModeEnable] = kAutoModeEnableAvailable; + mapping[kDefrostZone] = kDefrostZoneAvailable; + mapping[kDualModeEnable] = kDualModeEnableAvailable; + mapping[kACMaxEnable] = kAcMaxEnableAvailable; + mapping[kVentilationMode] = kVentilationModeAvailable; + mapping[kHeatedSteeringWheelEnable] = kHeatedSteeringWheelAvailable; + mapping[kHeatedWindshieldEnable] = kHeatedWindshieldAvailable; + mapping[kHeatedMirrorsEnable] = kHeatedMirrorsAvailable; + mapping[kHeatedRearWindowEnable] = kHeatedRearWindowAvailable; + mapping[kClimateEnable] = kClimateEnableAvailable; + mapping[kClimateEnableAvailable] = kClimateEnableAvailable; + + // radio + mapping[kBand] = kRadioBandAvailable; + mapping[kFrequencyInteger] = kRadioFrequencyAvailable; + mapping[kFrequencyFraction] = kRadioFrequencyAvailable; + mapping[kRdsData] = kRdsDataAvailable; + mapping[kAvailableHDs] = kAvailableHDsAvailable; + mapping[kAvailableHdChannels] = kAvailableHdChannelsAvailable; + mapping[kHdChannel] = kAvailableHdChannelsAvailable; + mapping[kHdRadioEnable] = kHdRadioEnableAvailable; + mapping[kSignalStrength] = kSignalStrengthAvailable; + mapping[kSignalChangeThreshold] = kSignalChangeThresholdAvailable; + mapping[kRadioEnable] = kRadioEnableAvailable; + mapping[kState] = kStateAvailable; + mapping[kSisData] = kSisDataAvailable; + + // seat + mapping[kHeatingEnabled] = kHeatingEnabledAvailable; + mapping[kCoolingEnabled] = kCoolingEnabledAvailable; + mapping[kHeatingLevele] = kHeatingLevelAvailable; + mapping[kCoolingLevel] = kCoolingLevelAvailable; + mapping[kHorizontalPosition] = kHorizontalPositionAvailable; + mapping[kVerticalPosition] = kVerticalPositionAvailable; + mapping[kFrontVerticalPosition] = kFrontVerticalPositionAvailable; + mapping[kBackVerticalPosition] = kBackVerticalPositionAvailable; + mapping[kBackTiltAngle] = kBackTiltAngleAvailable; + mapping[kHeadSupportHorizontalPosition] = + kHeadSupportHorizontalPositionAvailable; + mapping[kHeadSupportVerticalPosition] = kHeadSupportVerticalPositionAvailable; + mapping[kMassageEnabled] = kMassageEnabledAvailable; + mapping[kMassageMode] = kMassageModeAvailable; + mapping[kMassageCushionFirmness] = kMassageCushionFirmnessAvailable; + mapping[kMemory] = kMemoryAvailable; + + // audio + mapping[kSource] = kSourceAvailable; + mapping[kKeepContext] = kKeepContextAvailable; + mapping[kVolume] = kVolumeAvailable; + mapping[kEqualizerSettings] = kEqualizerAvailable; + + // hmi settings + mapping[kDistanceUnit] = kDistanceUnitAvailable; + mapping[kTemperatureUnit] = kTemperatureUnitAvailable; + mapping[kDisplayMode] = kDisplayModeUnitAvailable; + + return mapping; +} + +ModuleTypeCapability RCCapabilitiesManagerImpl::GetModuleDataCapabilities( + const smart_objects::SmartObject& module_data, + const std::string& module_id) const { + LOG4CXX_AUTO_TRACE(logger_); + auto rc_capabilities = *(hmi_capabilities_.rc_capability()); + + const auto& all_module_types = RCHelpers::GetModuleTypesList(); + const auto& get_module_data_key = RCHelpers::GetModuleTypeToDataMapping(); + const auto& get_capabilities_key = + RCHelpers::GetModuleTypeToCapabilitiesMapping(); + ModuleTypeCapability module_data_capabilities = + std::make_pair("", capabilitiesStatus::missedParam); + + for (const auto& module_type : all_module_types) { + const auto module_data_key = get_module_data_key(module_type); + const auto capabilities_key = get_capabilities_key(module_type); + if (module_data.keyExists(module_data_key)) { + if (!rc_capabilities.keyExists(capabilities_key)) { + LOG4CXX_DEBUG(logger_, module_data_key << " capabilities not present"); + return module_data_capabilities; + } + const auto& caps = rc_capabilities[capabilities_key]; + + if (message_params::kHmiSettingsControlData == module_data_key || + message_params::kLightControlData == module_data_key) { + module_data_capabilities = + GetControlDataCapabilities(caps, module_data[module_data_key]); + } else { + module_data_capabilities = GetControlDataCapabilities( + GetCapabilitiesByModuleIdFromArray(caps, module_id), + module_data[module_data_key]); + } + } + } + + return module_data_capabilities; +} + +ModuleTypeCapability RCCapabilitiesManagerImpl::GetControlDataCapabilities( + const smart_objects::SmartObject& capabilities, + const smart_objects::SmartObject& control_data) const { + LOG4CXX_AUTO_TRACE(logger_); + std::map<std::string, std::string> mapping = + GetModuleDataToCapabilitiesMapping(); + + for (auto it = control_data.map_begin(); it != control_data.map_end(); ++it) { + const std::string& request_parameter = it->first; + if (message_params::kId == request_parameter) { + continue; + } + if (message_params::kLightState == request_parameter) { + ModuleTypeCapability light_capability = + std::make_pair("", capabilitiesStatus::success); + + for (auto& light_data : *(control_data[request_parameter].asArray())) { + light_capability = GetLightNameCapabilities( + capabilities[strings::kSupportedLights], light_data); + + if (capabilitiesStatus::success != light_capability.second) { + return light_capability; + } + } + + return light_capability; + } + if (message_params::kBand == request_parameter) { + ModuleTypeCapability radio_capability = GetRadioBandByCapabilities( + capabilities, control_data[request_parameter]); + if (capabilitiesStatus::success != radio_capability.second) { + return radio_capability; + } + } + + const capabilitiesStatus status_item_capability = + GetItemCapability(capabilities, + mapping, + request_parameter, + mobile_apis::Result::UNSUPPORTED_RESOURCE); + + if (capabilitiesStatus::success != status_item_capability) { + return std::make_pair("", status_item_capability); + } + } + + return std::make_pair("", capabilitiesStatus::success); +} + +capabilitiesStatus RCCapabilitiesManagerImpl::GetItemCapability( + const smart_objects::SmartObject& capabilities, + const std::map<std::string, std::string>& mapping, + const std::string& request_parameter, + const mobile_apis::Result::eType& switched_off_result) const { + const auto it = mapping.find(request_parameter); + + if (it == mapping.end()) { + LOG4CXX_DEBUG( + logger_, + "Parameter " << request_parameter << " doesn't exist in capabilities."); + return capabilitiesStatus::missedParam; + } + + const std::string& caps_key = it->second; + + LOG4CXX_DEBUG(logger_, + "Checking request parameter " + << request_parameter + << " with capabilities. Appropriate key is " << caps_key); + + if (!capabilities.keyExists(caps_key)) { + LOG4CXX_DEBUG(logger_, + "Capability " << caps_key + << " is missed in RemoteControl capabilities"); + return capabilitiesStatus::missedParam; + } + + if (!capabilities[caps_key].asBool()) { + LOG4CXX_DEBUG(logger_, + "Capability " + << caps_key + << " is switched off in RemoteControl capabilities"); + capabilitiesStatus status = capabilitiesStatus::missedParam; + if (mobile_apis::Result::READ_ONLY == switched_off_result) { + status = capabilitiesStatus::readOnly; + } + return status; + } + + return capabilitiesStatus::success; +} + +ModuleTypeCapability RCCapabilitiesManagerImpl::GetLightDataCapabilities( + const smart_objects::SmartObject& capabilities, + const smart_objects::SmartObject& control_data) const { + LOG4CXX_AUTO_TRACE(logger_); + std::map<std::string, std::string> mapping = GetLightCapabilitiesMapping(); + + for (auto it = control_data.map_begin(); it != control_data.map_end(); ++it) { + const std::string& request_parameter = it->first; + + if (message_params::kId == request_parameter) { + continue; + } + + const capabilitiesStatus status_item_capability = + GetItemCapability(capabilities, + mapping, + request_parameter, + mobile_apis::Result::READ_ONLY); + + if (capabilitiesStatus::success != status_item_capability) { + return std::make_pair(message_params::kLightState, + status_item_capability); + } + } + + return std::make_pair("", capabilitiesStatus::success); +} + +ModuleTypeCapability RCCapabilitiesManagerImpl::GetLightNameCapabilities( + const smart_objects::SmartObject& capabilities_status, + const smart_objects::SmartObject& light_data) const { + LOG4CXX_AUTO_TRACE(logger_); + for (auto& so : *(capabilities_status.asArray())) { + const int64_t current_id = so[message_params::kName].asInt(); + if (current_id == light_data[message_params::kId].asInt()) { + return GetLightDataCapabilities(so, light_data); + } + } + LOG4CXX_DEBUG(logger_, "There is no such light name in capabilities"); + return std::make_pair(message_params::kLightState, + capabilitiesStatus::missedLightName); +} + +ModuleTypeCapability RCCapabilitiesManagerImpl::GetRadioBandByCapabilities( + const smart_objects::SmartObject& capabilities_status, + const smart_objects::SmartObject& request_parameter) const { + mobile_apis::RadioBand::eType radio_band = + static_cast<mobile_apis::RadioBand::eType>(request_parameter.asUInt()); + if (mobile_apis::RadioBand::XM == radio_band) { + if (!capabilities_status.keyExists(strings::kSiriusxmRadioAvailable)) { + LOG4CXX_DEBUG(logger_, + "Capability " + << strings::kSiriusxmRadioAvailable + << " is missed in RemoteControl capabilities"); + return std::make_pair(strings::kSiriusxmRadioAvailable, + capabilitiesStatus::missedParam); + } + if (!capabilities_status[strings::kSiriusxmRadioAvailable].asBool()) { + LOG4CXX_DEBUG(logger_, + "Capability " + << strings::kSiriusxmRadioAvailable + << " is switched off in RemoteControl capabilities"); + return std::make_pair(strings::kSiriusxmRadioAvailable, + capabilitiesStatus::missedParam); + } + } + return std::make_pair("", capabilitiesStatus::success); +} + +const smart_objects::SmartObject& RCCapabilitiesManagerImpl::ControlDataForType( + const smart_objects::SmartObject& module_data, + const std::string& module_type) const { + const auto& all_module_types = RCHelpers::GetModuleTypesList(); + const auto& data_mapping = RCHelpers::GetModuleTypeToDataMapping(); + for (const auto& type : all_module_types) { + if (type == module_type) { + return module_data[data_mapping(type)]; + } + } + NOTREACHED(); + return module_data[0]; +} + +bool RCCapabilitiesManagerImpl::CheckReadOnlyParamsForAudio( + const smart_objects::SmartObject& module_type_params) const { + if (module_type_params.keyExists(message_params::kEqualizerSettings)) { + const auto& equalizer_settings = + module_type_params[message_params::kEqualizerSettings]; + + for (auto& so : *(equalizer_settings.asArray())) { + if (so.keyExists(message_params::kChannelName)) { + LOG4CXX_DEBUG(logger_, + "READ ONLY parameter. ChannelName = " + << so[message_params::kChannelName].asString()); + return true; + } + } + } + + return false; +} + +bool RCCapabilitiesManagerImpl::CheckReadOnlyParamsForLight( + const smart_objects::SmartObject& module_type_params) const { + if (module_type_params.keyExists(message_params::kLightState)) { + const auto& light_state = module_type_params[message_params::kLightState]; + + for (auto& light_data : *(light_state.asArray())) { + if (light_data.keyExists(message_params::kLightStatus)) { + const mobile_apis::LightStatus::eType light_status = + static_cast<mobile_apis::LightStatus::eType>( + light_data[message_params::kLightStatus].asUInt()); + + if (helpers::Compare<mobile_apis::LightStatus::eType, + helpers::EQ, + helpers::ONE>(light_status, + mobile_apis::LightStatus::RAMP_UP, + mobile_apis::LightStatus::RAMP_DOWN, + mobile_apis::LightStatus::UNKNOWN, + mobile_apis::LightStatus::INVALID)) { + LOG4CXX_DEBUG( + logger_, + "READ ONLY parameter. Status = " + << light_data[message_params::kLightStatus].asInt()); + return true; + } + } + } + } + + return false; +} + +bool RCCapabilitiesManagerImpl::AreReadOnlyParamsPresent( + const smart_objects::SmartObject& module_data, + const std::string& module_type, + ModuleTypeCapability& module_data_capabilities) const { + LOG4CXX_AUTO_TRACE(logger_); + const smart_objects::SmartObject& module_type_params = + ControlDataForType(module_data, module_type); + + if (enums_value::kAudio == module_type) { + return CheckReadOnlyParamsForAudio(module_type_params); + } + + if (enums_value::kLight == module_type) { + const bool result = CheckReadOnlyParamsForLight(module_type_params); + + if (result) { + module_data_capabilities = + std::make_pair(module_type, capabilitiesStatus::readOnly); + } + return result; + } + + const std::vector<std::string> ro_params = + RCHelpers::GetModuleReadOnlyParams(module_type); + auto it = module_type_params.map_begin(); + + for (; it != module_type_params.map_end(); ++it) { + if (helpers::in_range(ro_params, it->first)) { + return true; + } + } + return false; +} + +bool RCCapabilitiesManagerImpl::AreAllParamsReadOnly( + const smart_objects::SmartObject& module_data, + const std::string& module_type) const { + LOG4CXX_AUTO_TRACE(logger_); + const smart_objects::SmartObject& module_type_params = + ControlDataForType(module_data, module_type); + auto it = module_type_params.map_begin(); + std::vector<std::string> ro_params = + RCHelpers::GetModuleReadOnlyParams(module_type); + for (; it != module_type_params.map_end(); ++it) { + if (!helpers::in_range(ro_params, it->first)) { + return false; + } + } + + LOG4CXX_DEBUG(logger_, "All params are ReadOnly"); + return true; +} + +bool RCCapabilitiesManagerImpl::IsSeatLocationCapabilityProvided() const { + LOG4CXX_AUTO_TRACE(logger_); + auto seat_location_capability = hmi_capabilities_.seat_location_capability(); + if (!seat_location_capability || seat_location_capability->empty()) { + LOG4CXX_DEBUG(logger_, "Seat Location capability is not provided by HMI"); + return false; + } + + if (seat_location_capability->keyExists(strings::kRows) && + seat_location_capability->keyExists(strings::kCols) && + seat_location_capability->keyExists(strings::kLevels) && + seat_location_capability->keyExists(strings::kSeats)) { + const auto* seats = (*seat_location_capability)[strings::kSeats].asArray(); + if (!seats->empty()) { + return true; + } + } + + LOG4CXX_DEBUG( + logger_, + "Seat Location capability doesn't contain all necessary parameters"); + return false; +} + +const Grid +RCCapabilitiesManagerImpl::GetDriverLocationFromSeatLocationCapability() const { + LOG4CXX_AUTO_TRACE(logger_); + Grid grid; + if (IsSeatLocationCapabilityProvided()) { + auto seat_location_capability = + hmi_capabilities_.seat_location_capability(); + const auto* seats = (*seat_location_capability)[strings::kSeats].asArray(); + const auto& driver_seat = (*seats)[0]; + if (driver_seat.keyExists(strings::kGrid)) { + const auto& driver_location = driver_seat[strings::kGrid]; + grid = Grid(driver_location[strings::kCol].asInt(), + driver_location[strings::kRow].asInt(), + driver_location[strings::kLevel].asInt(), + driver_location[strings::kColspan].asInt(), + driver_location[strings::kRowspan].asInt(), + driver_location[strings::kLevelspan].asInt()); + } else { + LOG4CXX_DEBUG(logger_, "Driver's location doesn't provided"); + } + } + return grid; +} + +Grid RCCapabilitiesManagerImpl::GetWholeVehicleArea() const { + auto seat_location_capability = + *(hmi_capabilities_.seat_location_capability()); + int32_t colspan = seat_location_capability.keyExists(strings::kCols) + ? seat_location_capability[strings::kCols].asInt() + : 0; + + int32_t rowspan = seat_location_capability.keyExists(strings::kRows) + ? seat_location_capability[strings::kRows].asInt() + : 0; + + int32_t levelspan = seat_location_capability.keyExists(strings::kLevels) + ? seat_location_capability[strings::kLevels].asInt() + : 0; + return Grid(0, 0, 0, colspan, rowspan, levelspan); +} + +Grid RCCapabilitiesManagerImpl::GetModuleLocationFromControlCapability( + const smart_objects::SmartObject& control_capabilities) const { + if (control_capabilities[message_params::kModuleInfo].keyExists( + strings::kLocation)) { + const auto& location = + control_capabilities[message_params::kModuleInfo][strings::kLocation]; + + return Grid(location[strings::kCol].asInt(), + location[strings::kRow].asInt(), + location[strings::kLevel].asInt(), + location[strings::kColspan].asInt(), + location[strings::kRowspan].asInt(), + location[strings::kLevelspan].asInt()); + } + return GetWholeVehicleArea(); +} + +Grid RCCapabilitiesManagerImpl::GetModuleServiceAreaFromControlCapability( + const smart_objects::SmartObject& control_capabilities) const { + if (control_capabilities.keyExists(message_params::kModuleInfo)) { + if (control_capabilities[message_params::kModuleInfo].keyExists( + strings::kServiceArea)) { + const auto& serviceArea = + control_capabilities[message_params::kModuleInfo] + [strings::kServiceArea]; + + return Grid(serviceArea[strings::kCol].asInt(), + serviceArea[strings::kRow].asInt(), + serviceArea[strings::kLevel].asInt(), + serviceArea[strings::kColspan].asInt(), + serviceArea[strings::kRowspan].asInt(), + serviceArea[strings::kLevelspan].asInt()); + } + } + return GetModuleLocationFromControlCapability(control_capabilities); +} + +Grid RCCapabilitiesManagerImpl::GetModuleServiceArea( + const ModuleUid& module) const { + auto rc_capabilities = *(hmi_capabilities_.rc_capability()); + const auto& mapping = RCHelpers::GetModuleTypeToCapabilitiesMapping(); + const auto& module_type = module.first; + const auto& capabilities_key = mapping(module_type); + if (!rc_capabilities.keyExists(capabilities_key)) { + LOG4CXX_DEBUG(logger_, module_type << "control capabilities not present"); + return Grid(); + } + const auto& caps = rc_capabilities[capabilities_key]; + + if (strings::khmiSettingsControlCapabilities == capabilities_key || + strings::klightControlCapabilities == capabilities_key) { + return GetModuleServiceAreaFromControlCapability(caps); + } else { + const auto& capability_item = + GetCapabilitiesByModuleIdFromArray(caps, module.second); + return GetModuleServiceAreaFromControlCapability(capability_item); + } +} + +bool RCCapabilitiesManagerImpl::IsMultipleAccessAllowedInControlCaps( + const smart_objects::SmartObject& control_capabilities) const { + if (control_capabilities.keyExists(message_params::kModuleInfo) && + control_capabilities[message_params::kModuleInfo].keyExists( + strings::kAllowMultipleAccess)) { + return control_capabilities[message_params::kModuleInfo] + [strings::kAllowMultipleAccess] + .asBool(); + } + return true; +} + +bool RCCapabilitiesManagerImpl::IsMultipleAccessAllowed( + const ModuleUid& module) const { + auto rc_capabilities = *(hmi_capabilities_.rc_capability()); + const auto& mapping = RCHelpers::GetModuleTypeToCapabilitiesMapping(); + const auto& module_type = module.first; + const auto& capabilities_key = mapping(module_type); + if (!rc_capabilities.keyExists(capabilities_key)) { + LOG4CXX_DEBUG(logger_, module_type << "control capabilities not present"); + return false; + } + const auto& caps = rc_capabilities[capabilities_key]; + + if (strings::khmiSettingsControlCapabilities == capabilities_key || + strings::klightControlCapabilities == capabilities_key) { + return IsMultipleAccessAllowedInControlCaps(caps); + } else { + return IsMultipleAccessAllowedInControlCaps( + GetCapabilitiesByModuleIdFromArray(caps, module.second)); + } +} + +} // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_command_factory.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_command_factory.cc index 93c230dfc3..4ca2cf5182 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_command_factory.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_command_factory.cc @@ -39,13 +39,19 @@ #include "rc_rpc_plugin/commands/hmi/rc_get_interior_vehicle_data_response.h" #include "rc_rpc_plugin/commands/hmi/rc_on_interior_vehicle_data_notification.h" #include "rc_rpc_plugin/commands/hmi/rc_on_remote_control_settings_notification.h" +#include "rc_rpc_plugin/commands/hmi/rc_set_global_properties_request.h" +#include "rc_rpc_plugin/commands/hmi/rc_set_global_properties_response.h" #include "rc_rpc_plugin/commands/hmi/rc_set_interior_vehicle_data_request.h" #include "rc_rpc_plugin/commands/hmi/rc_set_interior_vehicle_data_response.h" #include "rc_rpc_plugin/commands/mobile/button_press_request.h" #include "rc_rpc_plugin/commands/mobile/button_press_response.h" +#include "rc_rpc_plugin/commands/mobile/get_interior_vehicle_data_consent_request.h" +#include "rc_rpc_plugin/commands/mobile/get_interior_vehicle_data_consent_response.h" #include "rc_rpc_plugin/commands/mobile/get_interior_vehicle_data_request.h" #include "rc_rpc_plugin/commands/mobile/get_interior_vehicle_data_response.h" #include "rc_rpc_plugin/commands/mobile/on_interior_vehicle_data_notification.h" +#include "rc_rpc_plugin/commands/mobile/release_interior_vehicle_data_module_request.h" +#include "rc_rpc_plugin/commands/mobile/release_interior_vehicle_data_module_response.h" #include "rc_rpc_plugin/commands/mobile/set_interior_vehicle_data_request.h" #include "rc_rpc_plugin/commands/mobile/set_interior_vehicle_data_response.h" #include "rc_rpc_plugin/rc_command_factory.h" @@ -196,6 +202,20 @@ CommandCreator& RCCommandFactory::get_mobile_command_creator( : rc_factory .GetCreator<commands::SetInteriorVehicleDataResponse>(); } + case mobile_apis::FunctionID::ReleaseInteriorVehicleDataModuleID: { + return mobile_apis::messageType::request == message_type + ? rc_factory.GetCreator< + commands::ReleaseInteriorVehicleDataModuleRequest>() + : rc_factory.GetCreator< + commands::ReleaseInteriorVehicleDataModuleResponse>(); + } + case mobile_apis::FunctionID::GetInteriorVehicleDataConsentID: { + return mobile_apis::messageType::request == message_type + ? rc_factory.GetCreator< + commands::GetInteriorVehicleDataConsentRequest>() + : rc_factory.GetCreator< + commands::GetInteriorVehicleDataConsentResponse>(); + } default: {} } return rc_factory.GetCreator<RCInvalidCommand>(); @@ -287,6 +307,13 @@ CommandCreator& RCCommandFactory::get_hmi_creator_factory( return rc_factory .GetCreator<commands::RCOnRemoteControlSettingsNotification>(); } + case hmi_apis::FunctionID::RC_SetGlobalProperties: { + return hmi_apis::messageType::request == message_type + ? rc_factory + .GetCreator<commands::RCSetGlobalPropertiesRequest>() + : rc_factory + .GetCreator<commands::RCSetGlobalPropertiesResponse>(); + } default: { return rc_factory.GetCreator<RCInvalidCommand>(); } } } diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_consent_manager_impl.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_consent_manager_impl.cc new file mode 100644 index 0000000000..1d7db181eb --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_consent_manager_impl.cc @@ -0,0 +1,416 @@ +/* + 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 <algorithm> + +#include "application_manager/application_manager.h" +#include "application_manager/smart_object_keys.h" +#include "json/json.h" +#include "rc_rpc_plugin/rc_consent_manager_impl.h" +#include "rc_rpc_plugin/rc_module_constants.h" +#include "resumption/last_state.h" +#include "smart_objects/smart_object.h" +#include "utils/date_time.h" +#include "utils/logger.h" + +namespace rc_rpc_plugin { +namespace app_mngr = application_manager; + +CREATE_LOGGERPTR_GLOBAL(logger_, "RCConsentManager") + +RCConsentManagerImpl::RCConsentManagerImpl( + resumption::LastStateWrapperPtr last_state, + application_manager::ApplicationManager& application_manager, + const uint32_t period_of_consent_expired) + : app_manager_(application_manager) + , last_state_(last_state) + , period_of_consent_expired_(period_of_consent_expired) {} + +void RCConsentManagerImpl::SaveModuleConsents( + const std::string& policy_app_id, + const std::string& mac_address, + const rc_rpc_types::ModuleIdConsentVector& module_consents) { + LOG4CXX_AUTO_TRACE(logger_); + + for (const auto& consent : module_consents) { + std::string module_type = consent.module_id.first; + + auto last_state_accessor = last_state_->get_accessor(); + auto last_state_dictionary = last_state_accessor.GetData().dictionary(); + + auto& app_module_consents = GetModuleTypeConsentsOrAppend( + policy_app_id, mac_address, module_type, last_state_dictionary); + SaveAppModuleConsent(app_module_consents, consent); + + last_state_accessor.GetMutableData().set_dictionary(last_state_dictionary); + } +} + +rc_rpc_types::ModuleConsent RCConsentManagerImpl::GetModuleConsent( + const std::string& app_id, + const std::string& mac_address, + const rc_rpc_types::ModuleUid& module_id) { + sync_primitives::AutoLock autolock(module_consents_lock_); + + auto last_state_accessor = last_state_->get_accessor(); + auto last_state_dictionary = last_state_accessor.GetData().dictionary(); + + auto& module_consents = GetModuleTypeConsentsOrAppend( + app_id, mac_address, module_id.first, last_state_dictionary); + + last_state_accessor.GetMutableData().set_dictionary(last_state_dictionary); + + if (module_consents.empty()) { + LOG4CXX_DEBUG( + logger_, + "For app: " << app_id << " module type doesn't have any consents"); + return rc_rpc_types::ModuleConsent::NOT_EXISTS; + } + + for (const auto& conset_item : module_consents) { + if (conset_item[message_params::kModuleId].asString() == module_id.second) { + return static_cast<rc_rpc_types::ModuleConsent>( + conset_item[message_params::kConsent].asUInt()); + } + } + + LOG4CXX_DEBUG(logger_, + "For app: " << app_id << " and module resource [" + << module_id.first << ":" << module_id.second + << "] consent is absent"); + + return rc_rpc_types::ModuleConsent::NOT_EXISTS; +} + +void RCConsentManagerImpl::RemoveExpiredConsents() { + LOG4CXX_AUTO_TRACE(logger_); + + auto last_state_accessor = last_state_->get_accessor(); + auto last_state_dictionary = last_state_accessor.GetData().dictionary(); + + auto& remote_control = GetRemoteControlDataOrAppend(last_state_dictionary); + if (remote_control.empty()) { + last_state_accessor.GetMutableData().set_dictionary(last_state_dictionary); + return; + } + + auto& devices = GetAppsConsentsOrAppend(last_state_dictionary); + + sync_primitives::AutoLock autolock(device_applications_lock_); + + for (auto& device_item : devices) { + RemoveDeviceExpiredConsents(device_item); + } + + last_state_accessor.GetMutableData().set_dictionary(last_state_dictionary); +} + +void RCConsentManagerImpl::RemoveAllConsents() { + auto last_state_accessor = last_state_->get_accessor(); + auto last_state_dictionary = last_state_accessor.GetData().dictionary(); + + auto& remote_control = GetRemoteControlDataOrAppend(last_state_dictionary); + remote_control.removeMember(message_params::kAppConsents); + + last_state_accessor.GetMutableData().set_dictionary(last_state_dictionary); +} + +rc_rpc_types::ModuleConsentState RCConsentManagerImpl::CheckModuleConsentState( + const Json::Value& module_consent) const { + if (!module_consent.isMember(message_params::kConsentDate)) { + LOG4CXX_DEBUG(logger_, "Date of consent is absent"); + return rc_rpc_types::ModuleConsentState::NOT_EXISTS; + } + + const uint32_t period_for_expiring = + app_manager_.get_settings().period_for_consent_expiration(); + + const time_t consent_date = static_cast<time_t>( + module_consent[message_params::kConsentDate].asUInt()); + + const auto past_period_in_days = + date_time::calculateAmountDaysFromDate(consent_date); + + LOG4CXX_DEBUG( + logger_, + "Keeping time of consent is: " << past_period_in_days << " days"); + LOG4CXX_DEBUG(logger_, "Period for expired: " << period_for_expiring); + + return (past_period_in_days >= period_for_expiring) + ? rc_rpc_types::ModuleConsentState::EXPIRED + : rc_rpc_types::ModuleConsentState::ACTIVE; +} + +void RCConsentManagerImpl::RemoveDeviceExpiredConsents(Json::Value& device) { + sync_primitives::AutoLock autolock(applications_lock_); + + if (device.isMember(message_params::kApplications)) { + auto& applications = device[message_params::kApplications]; + + for (auto& app : applications) { + if (app.isMember(message_params::kAppConsentList)) { + RemoveAppExpiredConsents(app[message_params::kAppConsentList]); + } + } + } +} + +void RCConsentManagerImpl::RemoveAppExpiredConsents(Json::Value& app_consents) { + for (auto& module : app_consents) { + if (module.isMember(message_params::kModuleConsents)) { + auto& module_consents = module[message_params::kModuleConsents]; + RemoveModuleExpiredConsents(module_consents); + } + } +} + +void RCConsentManagerImpl::RemoveModuleExpiredConsents( + Json::Value& module_consents) { + sync_primitives::AutoLock autolock(module_consents_lock_); + Json::Value temp_consents; + + for (auto& consent : module_consents) { + const bool is_module_id_exists = + consent.isMember(message_params::kModuleId); + + const bool is_expired = rc_rpc_types::ModuleConsentState::EXPIRED == + CheckModuleConsentState(consent); + if (is_expired) { + LOG4CXX_DEBUG(logger_, + "Consent for module resource [" + << consent[message_params::kModuleId].asString() + << "] is expired and will be removed"); + } + + if (is_module_id_exists && !is_expired) { + LOG4CXX_DEBUG(logger_, + "Consent for module resource [" + << consent[message_params::kModuleId].asString() + << "] is actual."); + temp_consents.append(consent); + } + } + + module_consents.clear(); + if (!temp_consents.empty()) { + std::swap(module_consents, temp_consents); + } +} + +Json::Value& RCConsentManagerImpl::GetRemoteControlDataOrAppend( + Json::Value& last_state_data) { + sync_primitives::AutoLock autolock(dictionary_control_lock_); + if (!last_state_data.isMember(app_mngr::strings::remote_control)) { + last_state_data[app_mngr::strings::remote_control] = + Json::Value(Json::objectValue); + LOG4CXX_DEBUG(logger_, "remote_control section is missed"); + } + + Json::Value& remote_control = + last_state_data[app_mngr::strings::remote_control]; + + if (!remote_control.isObject()) { + LOG4CXX_ERROR(logger_, "remote_control type INVALID rewrite"); + remote_control = Json::Value(Json::objectValue); + } + return remote_control; +} + +Json::Value& RCConsentManagerImpl::GetDeviceApplicationsOrAppend( + const std::string& mac_address, Json::Value& last_state_data) { + sync_primitives::AutoLock autolock(device_applications_lock_); + + auto& apps_consents = GetAppsConsentsOrAppend(last_state_data); + + if (!apps_consents.isArray()) { + LOG4CXX_DEBUG(logger_, "applications_consents type INVALID rewrite"); + apps_consents = Json::Value(Json::arrayValue); + } + + for (auto& device_applications_item : apps_consents) { + const bool is_device_section_exists = + device_applications_item.isMember(message_params::kMacAddress); + + if (is_device_section_exists) { + auto saved_mac_adress = + device_applications_item[message_params::kMacAddress].asString(); + + if (saved_mac_adress == mac_address) { + return device_applications_item[message_params::kApplications]; + } + } + } + + auto device_applications = Json::Value(Json::objectValue); + device_applications[message_params::kMacAddress] = Json::Value(mac_address); + device_applications[message_params::kApplications] = + Json::Value(Json::arrayValue); + + apps_consents.append(device_applications); + return apps_consents[apps_consents.size() - 1][message_params::kApplications]; +} + +Json::Value& RCConsentManagerImpl::GetAppConsentsListOrAppend( + const std::string& policy_app_id, + const std::string& mac_address, + Json::Value& last_state_data) { + auto& device_applications = + GetDeviceApplicationsOrAppend(mac_address, last_state_data); + + sync_primitives::AutoLock autolock(applications_lock_); + if (!device_applications.isArray()) { + LOG4CXX_DEBUG(logger_, "applications_consents type INVALID rewrite"); + device_applications = Json::Value(Json::arrayValue); + } + + for (auto& application : device_applications) { + const bool is_app_id_section_exists = + application.isMember(message_params::kAppId); + + if (is_app_id_section_exists) { + auto saved_app_id = application[message_params::kAppId].asString(); + + if (saved_app_id == policy_app_id) { + return application[message_params::kAppConsentList]; + } + } + } + + // In case when specified application section is absent in json file, + // will be created new section and added to dictionary. + auto application = Json::Value(Json::objectValue); + application[message_params::kAppId] = Json::Value(policy_app_id); + application[message_params::kAppConsentList] = Json::Value(Json::arrayValue); + device_applications.append(application); + + // Returns last appended object + return device_applications[device_applications.size() - 1] + [message_params::kAppConsentList]; +} + +Json::Value& RCConsentManagerImpl::GetAppsConsentsOrAppend( + Json::Value& last_state_data) { + Json::Value& remote_control = GetRemoteControlDataOrAppend(last_state_data); + sync_primitives::AutoLock autolock(remote_control_lock_); + + if (!remote_control.isMember(message_params::kAppConsents)) { + LOG4CXX_DEBUG(logger_, "app_consents section is missed"); + remote_control[message_params::kAppConsents] = + Json::Value(Json::arrayValue); + } + + auto& app_consents = remote_control[message_params::kAppConsents]; + if (!app_consents.isArray()) { + LOG4CXX_DEBUG(logger_, "applications_consents type INVALID rewrite"); + app_consents = Json::Value(Json::arrayValue); + } + return app_consents; +} + +Json::Value& RCConsentManagerImpl::GetModuleTypeConsentsOrAppend( + const std::string& policy_app_id, + const std::string& mac_address, + const std::string& module_type, + Json::Value& last_state_data) { + auto& app_consents_list = + GetAppConsentsListOrAppend(policy_app_id, mac_address, last_state_data); + + sync_primitives::AutoLock autolock(app_consents_lock_); + for (auto& module_consents : app_consents_list) { + const bool module_exists = + module_consents.isMember(message_params::kModuleType); + + if (module_exists && + (module_consents[message_params::kModuleType].asString() == + module_type)) { + return module_consents[message_params::kModuleConsents]; + } + } + + // In case of absent specified module_type in section of specified + // application, will be added empty section with this module type. + LOG4CXX_DEBUG( + logger_, + "Section module_type: " << module_type + << " is missed for app_id:" << policy_app_id); + auto consent_item = Json::Value(Json::objectValue); + consent_item[message_params::kModuleType] = module_type; + consent_item[message_params::kModuleConsents] = Json::Value(Json::arrayValue); + + app_consents_list.append(consent_item); + + // Returns last (appended) object + return app_consents_list[app_consents_list.size() - 1] + [message_params::kModuleConsents]; +} + +RCConsentManagerImpl::~RCConsentManagerImpl() {} + +void RCConsentManagerImpl::SaveAppModuleConsent( + Json::Value& app_module_consents, + const rc_rpc_types::ModuleIdConsent& consent_to_save) { + bool is_found = false; + + sync_primitives::AutoLock autolock(app_consents_lock_); + for (auto& consent : app_module_consents) { + const bool is_module_id_exists = + consent.isMember(message_params::kModuleId); + + // In case existing consent of specified ModuelResource (module_type + + // module_id), old value will be rewritten by new value. + + if (is_module_id_exists && (consent[message_params::kModuleId].asString() == + consent_to_save.module_id.second)) { + is_found = true; + consent[message_params::kConsent] = + Json::Value(static_cast<uint32_t>(consent_to_save.consent)); + consent[message_params::kConsentDate] = Json::Value( + static_cast<Json::UInt64>(consent_to_save.date_of_consent)); + } + } + + // Otherwise, new item will be added to the "consents" collection + + if (!is_found) { + auto new_consent = Json::Value(Json::objectValue); + new_consent[message_params::kModuleId] = + Json::Value(consent_to_save.module_id.second); + new_consent[message_params::kConsent] = + Json::Value(static_cast<uint32_t>(consent_to_save.consent)); + new_consent[message_params::kConsentDate] = + Json::Value(static_cast<Json::UInt64>(consent_to_save.date_of_consent)); + + app_module_consents.append(new_consent); + } +} + +} // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_helpers.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_helpers.cc index 5785e58e5b..f344dd15a7 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_helpers.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_helpers.cc @@ -8,6 +8,124 @@ namespace rc_rpc_plugin { CREATE_LOGGERPTR_GLOBAL(logger_, "RemoteControlModule"); +const std::vector<std::string> RCHelpers::buttons_climate() { + std::vector<std::string> data; + data.push_back(enums_value::kACMax); + data.push_back(enums_value::kAC); + data.push_back(enums_value::kRecirculate); + data.push_back(enums_value::kFanUp); + data.push_back(enums_value::kFanDown); + data.push_back(enums_value::kTempUp); + data.push_back(enums_value::kTempDown); + data.push_back(enums_value::kDefrostMax); + data.push_back(enums_value::kDefrost); + data.push_back(enums_value::kDefrostRear); + data.push_back(enums_value::kUpperVent); + data.push_back(enums_value::kLowerVent); + return data; +} + +const std::vector<std::string> RCHelpers::buttons_radio() { + std::vector<std::string> data; + data.push_back(enums_value::kVolumeUp); + data.push_back(enums_value::kVolumeDown); + data.push_back(enums_value::kEject); + data.push_back(enums_value::kSource); + data.push_back(enums_value::kShuffle); + data.push_back(enums_value::kRepeat); + return data; +} + +const RCHelpers::ButtonsMap RCHelpers::buttons_map() { + using namespace mobile_apis; + + ButtonsMap buttons_map; + buttons_map[enums_value::kACMax] = ButtonName::AC_MAX; + buttons_map[enums_value::kAC] = ButtonName::AC; + buttons_map[enums_value::kRecirculate] = ButtonName::RECIRCULATE; + buttons_map[enums_value::kFanUp] = ButtonName::FAN_UP; + buttons_map[enums_value::kFanDown] = ButtonName::FAN_DOWN; + buttons_map[enums_value::kTempUp] = ButtonName::TEMP_UP; + buttons_map[enums_value::kTempDown] = ButtonName::TEMP_DOWN; + buttons_map[enums_value::kDefrostMax] = ButtonName::DEFROST_MAX; + buttons_map[enums_value::kDefrost] = ButtonName::DEFROST; + buttons_map[enums_value::kDefrostRear] = ButtonName::DEFROST_REAR; + buttons_map[enums_value::kUpperVent] = ButtonName::UPPER_VENT; + buttons_map[enums_value::kLowerVent] = ButtonName::LOWER_VENT; + buttons_map[enums_value::kVolumeUp] = ButtonName::VOLUME_UP; + buttons_map[enums_value::kVolumeDown] = ButtonName::VOLUME_DOWN; + buttons_map[enums_value::kEject] = ButtonName::EJECT; + buttons_map[enums_value::kSource] = ButtonName::SOURCE; + buttons_map[enums_value::kShuffle] = ButtonName::SHUFFLE; + buttons_map[enums_value::kRepeat] = ButtonName::REPEAT; + + return buttons_map; +} + +std::vector<std::string> RCHelpers::GetModuleReadOnlyParams( + const std::string& module_type) { + using namespace message_params; + std::vector<std::string> module_ro_params; + if (enums_value::kClimate == module_type) { + module_ro_params.push_back(kCurrentTemperature); + } else if (enums_value::kRadio == module_type) { + module_ro_params.push_back(kRdsData); + module_ro_params.push_back(kAvailableHDs); + module_ro_params.push_back(kAvailableHdChannels); + module_ro_params.push_back(kSignalStrength); + module_ro_params.push_back(kSignalChangeThreshold); + module_ro_params.push_back(kState); + module_ro_params.push_back(kSisData); + } else if (enums_value::kLight == module_type) { + module_ro_params.push_back(kLightStatus); + } + + return module_ro_params; +} + +rc_rpc_types::ModuleIdConsentVector RCHelpers::FillModuleConsents( + const std::string& module_type, + const std::vector<std::string>& module_ids, + const std::vector<bool> allowed) { + using namespace rc_rpc_types; + if (module_ids.size() != allowed.size()) { + return rc_rpc_types::ModuleIdConsentVector(); + } + + rc_rpc_types::ModuleIdConsentVector module_consents; + std::time_t current_date = std::time(0); + size_t array_size = module_ids.size(); + + for (size_t i = 0; i < array_size; ++i) { + rc_rpc_types::ModuleIdConsent module_consent; + module_consent.module_id = {module_type, module_ids[i]}; + module_consent.consent = + allowed[i] ? ModuleConsent::CONSENTED : ModuleConsent::NOT_CONSENTED; + module_consent.date_of_consent = current_date; + + module_consents.push_back(module_consent); + } + return module_consents; +} + +std::vector<std::string> RCHelpers::RetrieveModuleIds( + const ns_smart_device_link::ns_smart_objects::SmartObject& moduleIds) { + std::vector<std::string> module_ids; + for (const auto& module_id : (*moduleIds.asArray())) { + module_ids.push_back(module_id.asString()); + } + return module_ids; +} + +std::vector<bool> RCHelpers::RetrieveModuleConsents( + const ns_smart_device_link::ns_smart_objects::SmartObject& consents) { + std::vector<bool> module_consents; + for (const auto& allowed_item : (*consents.asArray())) { + module_consents.push_back(allowed_item.asBool()); + } + return module_consents; +} + const std::function<std::string(const std::string& module_type)> RCHelpers::GetModuleTypeToDataMapping() { auto mapping_lambda = [](const std::string& module_type) -> std::string { @@ -50,13 +168,14 @@ RCHelpers::GetModuleTypeToCapabilitiesMapping() { return mapping_lambda; } -const std::vector<std::string> RCHelpers::GetModulesList() { +const std::vector<std::string> RCHelpers::GetModuleTypesList() { using namespace enums_value; return {kClimate, kRadio, kSeat, kAudio, kLight, kHmiSettings}; } RCAppExtensionPtr RCHelpers::GetRCExtension( application_manager::Application& app) { + LOG4CXX_AUTO_TRACE(logger_); auto extension_interface = app.QueryInterface(RCRPCPlugin::kRCPluginID); auto extension = std::static_pointer_cast<RCAppExtension>(extension_interface); @@ -64,7 +183,7 @@ RCAppExtensionPtr RCHelpers::GetRCExtension( } smart_objects::SmartObjectSPtr RCHelpers::CreateUnsubscribeRequestToHMI( - const std::string& module_type, const uint32_t correlation_id) { + const ModuleUid& module, const uint32_t correlation_id) { using namespace smart_objects; namespace commands = application_manager::commands; namespace am_strings = application_manager::strings; @@ -82,11 +201,28 @@ smart_objects::SmartObjectSPtr RCHelpers::CreateUnsubscribeRequestToHMI( params[am_strings::function_id] = hmi_apis::FunctionID::RC_GetInteriorVehicleData; msg_params[message_params::kSubscribe] = false; - msg_params[message_params::kModuleType] = module_type; + msg_params[message_params::kModuleType] = module.first; + msg_params[message_params::kModuleId] = module.second; return message; } std::vector<application_manager::ApplicationSharedPtr> +RCHelpers::AppsSubscribedToModule( + application_manager::ApplicationManager& app_mngr, + const ModuleUid& module) { + std::vector<application_manager::ApplicationSharedPtr> result; + auto rc_apps = RCRPCPlugin::GetRCApplications(app_mngr); + for (auto& app : rc_apps) { + auto rc_ext = RCHelpers::GetRCExtension(*app); + DCHECK_OR_RETURN(rc_ext, result); + if (rc_ext->IsSubscribedToInteriorVehicleData(module)) { + result.push_back(app); + } + } + return result; +} + +std::vector<application_manager::ApplicationSharedPtr> RCHelpers::AppsSubscribedToModuleType( application_manager::ApplicationManager& app_mngr, const std::string& module_type) { @@ -95,17 +231,17 @@ RCHelpers::AppsSubscribedToModuleType( for (auto& app : rc_apps) { auto rc_ext = RCHelpers::GetRCExtension(*app); DCHECK_OR_RETURN(rc_ext, result); - if (rc_ext->IsSubscibedToInteriorVehicleData(module_type)) { + if (rc_ext->IsSubscribedToInteriorVehicleDataOfType(module_type)) { result.push_back(app); } } return result; } -RCHelpers::AppsModules RCHelpers::GetApplicationsAllowedModules( +RCHelpers::AppsModuleTypes RCHelpers::GetApplicationsAllowedModuleTypes( app_mngr::ApplicationManager& app_mngr) { auto apps_list = RCRPCPlugin::GetRCApplications(app_mngr); - RCHelpers::AppsModules result; + RCHelpers::AppsModuleTypes result; for (auto& app_ptr : apps_list) { std::vector<std::string> allowed_modules; app_mngr.GetPolicyHandler().GetModuleTypes(app_ptr->policy_app_id(), @@ -122,6 +258,9 @@ void RCHelpers::RemoveRedundantGPSDataFromIVDataMsg( using namespace application_manager::strings; LOG4CXX_AUTO_TRACE(logger_); + if (!msg_params.keyExists(kModuleData)) { + return; + } auto& module_data = msg_params[kModuleData]; if (!module_data.keyExists(kRadioControlData) || !module_data[kRadioControlData].keyExists(kSisData) || @@ -141,4 +280,86 @@ void RCHelpers::RemoveRedundantGPSDataFromIVDataMsg( location_data = new_location_data; } } + +smart_objects::SmartObject RCHelpers::MergeModuleData( + const smart_objects::SmartObject& data1, + const smart_objects::SmartObject& data2) { + if (data1.getType() != smart_objects::SmartType::SmartType_Map || + data2.getType() != smart_objects::SmartType::SmartType_Map) { + return data2; + } + + smart_objects::SmartObject result = data1; + + for (auto it = data2.map_begin(); it != data2.map_end(); ++it) { + const std::string& key = it->first; + smart_objects::SmartObject& value = it->second; + if (!result.keyExists(key) || value.getType() != result[key].getType()) { + result[key] = value; + continue; + } + + // Merge maps and arrays with `id` param included, replace other types + if (value.getType() == smart_objects::SmartType::SmartType_Map) { + value = MergeModuleData(result[key], value); + } else if (value.getType() == smart_objects::SmartType::SmartType_Array) { + value = MergeArray(result[key], value); + } + result[key] = value; + } + return result; +} + +smart_objects::SmartObject RCHelpers::MergeArray( + const smart_objects::SmartObject& data1, + const smart_objects::SmartObject& data2) { + // Merge data only in the case where each value in the array is an Object with + // an ID included, otherwise replace + + if (data1.getType() != smart_objects::SmartType::SmartType_Array || + data2.getType() != smart_objects::SmartType::SmartType_Array || + data2.empty()) { + return data2; + } + + auto& data2_array = *data2.asArray(); + for (const auto& data_item : data2_array) { + if (data_item.getType() != smart_objects::SmartType_Map || + !data_item.keyExists(application_manager::strings::id)) { + return data2; + } + } + + smart_objects::SmartObject result = data1; + smart_objects::SmartArray* result_array = result.asArray(); + + auto find_by_id = [](smart_objects::SmartArray* array, + const smart_objects::SmartObject& id) + -> smart_objects::SmartArray::iterator { + return std::find_if(array->begin(), + array->end(), + [&id](const smart_objects::SmartObject& obj) -> bool { + return id == obj[application_manager::strings::id]; + }); + }; + + auto merge = [&result_array, + &find_by_id](const smart_objects::SmartObject& data) -> void { + auto element_id = data[application_manager::strings::id]; + auto result_it = find_by_id(result_array, element_id); + + if (result_array->end() != result_it) { + *result_it = RCHelpers::MergeModuleData(*result_it, data); + } else { + result_array->push_back(data); + } + }; + + for (const auto& data : data2_array) { + merge(data); + } + + return result; +} + } // namespace rc_rpc_plugin 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 026e03eeff..c2aa639fda 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 @@ -35,7 +35,9 @@ #include "rc_rpc_plugin/interior_data_cache_impl.h" #include "rc_rpc_plugin/interior_data_manager_impl.h" #include "rc_rpc_plugin/rc_app_extension.h" +#include "rc_rpc_plugin/rc_capabilities_manager_impl.h" #include "rc_rpc_plugin/rc_command_factory.h" +#include "rc_rpc_plugin/rc_consent_manager_impl.h" #include "rc_rpc_plugin/rc_helpers.h" #include "rc_rpc_plugin/resource_allocation_manager_impl.h" #include "utils/helpers.h" @@ -49,26 +51,46 @@ bool RCRPCPlugin::Init( application_manager::ApplicationManager& app_manager, application_manager::rpc_service::RPCService& rpc_service, application_manager::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) { + policy::PolicyHandlerInterface& policy_handler, + resumption::LastStateWrapperPtr last_state) { + rc_consent_manager_.reset(new rc_rpc_plugin::RCConsentManagerImpl( + last_state, + app_manager, + app_manager.get_settings().period_for_consent_expiration())); interior_data_cache_.reset(new InteriorDataCacheImpl()); interior_data_manager_.reset(new InteriorDataManagerImpl( *this, *interior_data_cache_, app_manager, rpc_service)); - - resource_allocation_manager_.reset( - new ResourceAllocationManagerImpl(app_manager, rpc_service)); + rc_capabilities_manager_.reset( + new RCCapabilitiesManagerImpl(hmi_capabilities)); + resource_allocation_manager_.reset(new ResourceAllocationManagerImpl( + app_manager, rpc_service, *(rc_capabilities_manager_.get()))); RCCommandParams params{app_manager, rpc_service, hmi_capabilities, policy_handler, *(resource_allocation_manager_.get()), *(interior_data_cache_.get()), - *(interior_data_manager_.get())}; + *(interior_data_manager_.get()), + *(rc_capabilities_manager_.get()), + *(rc_consent_manager_.get())}; command_factory_.reset(new rc_rpc_plugin::RCCommandFactory(params)); rpc_service_ = &rpc_service; app_mngr_ = &app_manager; + + // Check all saved consents and remove expired + rc_consent_manager_->RemoveExpiredConsents(); + 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 @@ -93,15 +115,23 @@ void RCRPCPlugin::OnPolicyEvent( void RCRPCPlugin::OnApplicationEvent( application_manager::plugin_manager::ApplicationEvent event, application_manager::ApplicationSharedPtr application) { + LOG4CXX_AUTO_TRACE(logger_); if (!application->is_remote_control_supported()) { + LOG4CXX_DEBUG( + logger_, + "Remote control is not supported for application with app_id: " + << application->app_id()); return; } switch (event) { case plugins::kApplicationRegistered: { - application->AddExtension( - std::shared_ptr<RCAppExtension>(new RCAppExtension(kRCPluginID))); - resource_allocation_manager_->SendOnRCStatusNotifications( - NotificationTrigger::APP_REGISTRATION, application); + auto extension = + std::shared_ptr<RCAppExtension>(new RCAppExtension(kRCPluginID)); + application->AddExtension(extension); + const auto driver_location = + rc_capabilities_manager_ + ->GetDriverLocationFromSeatLocationCapability(); + extension->SetUserLocation(driver_location); break; } case plugins::kApplicationExit: { @@ -114,6 +144,17 @@ void RCRPCPlugin::OnApplicationEvent( interior_data_manager_->OnApplicationEvent(event, application); break; } + case plugins::kGlobalPropertiesUpdated: { + const auto user_location = application->get_user_location(); + auto extension = RCHelpers::GetRCExtension(*application); + extension->SetUserLocation(user_location); + break; + } + case plugins::kRCStatusChanged: { + resource_allocation_manager_->SendOnRCStatusNotifications( + NotificationTrigger::APP_REGISTRATION, application); + break; + } default: break; } @@ -136,6 +177,14 @@ RCRPCPlugin::Apps RCRPCPlugin::GetRCApplications( } // namespace rc_rpc_plugin -extern "C" application_manager::plugin_manager::RPCPlugin* Create() { +extern "C" __attribute__((visibility("default"))) +application_manager::plugin_manager::RPCPlugin* +Create() { return new rc_rpc_plugin::RCRPCPlugin(); } // namespace rc_rpc_plugin + +extern "C" __attribute__((visibility("default"))) void Delete( + application_manager::plugin_manager::RPCPlugin* data) { + delete data; + DELETE_THREAD_LOGGER(rc_rpc_plugin::logger_); +} 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 cf1df2cb68..049f9a3cf3 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 @@ -49,16 +49,20 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "RemoteControlModule") ResourceAllocationManagerImpl::ResourceAllocationManagerImpl( application_manager::ApplicationManager& app_mngr, - application_manager::rpc_service::RPCService& rpc_service) + application_manager::rpc_service::RPCService& rpc_service, + RCCapabilitiesManager& rc_capabilities_manager) : current_access_mode_(hmi_apis::Common_RCAccessMode::AUTO_ALLOW) , app_mngr_(app_mngr) , rpc_service_(rpc_service) + , rc_capabilities_manager_(rc_capabilities_manager) , is_rc_enabled_(true) {} ResourceAllocationManagerImpl::~ResourceAllocationManagerImpl() {} AcquireResult::eType ResourceAllocationManagerImpl::AcquireResource( - const std::string& module_type, const uint32_t app_id) { + const std::string& module_type, + const std::string& module_id, + const uint32_t app_id) { LOG4CXX_AUTO_TRACE(logger_); const application_manager::ApplicationSharedPtr acquiring_app = app_mngr_.application(app_id); @@ -67,40 +71,57 @@ AcquireResult::eType ResourceAllocationManagerImpl::AcquireResource( return AcquireResult::IN_USE; } + ModuleUid module(module_type, module_id); + + if (rc_capabilities_manager_.IsSeatLocationCapabilityProvided() && + !IsUserLocationValid(module, acquiring_app)) { + LOG4CXX_WARN(logger_, + "Resource acquisition is not allowed " + "according to location verification."); + return AcquireResult::REJECTED; + } + sync_primitives::AutoLock lock(allocated_resources_lock_); const AllocatedResources::const_iterator allocated_it = - allocated_resources_.find(module_type); + allocated_resources_.find(module); if (allocated_resources_.end() == allocated_it) { - SetResourceAquired(module_type, app_id); LOG4CXX_DEBUG(logger_, "Resource is not acquired yet. " << "App: " << app_id << " is allowed to acquire " - << module_type); + << module_type << " " << module_id); return AcquireResult::ALLOWED; } - if (app_id == allocated_resources_[module_type]) { - LOG4CXX_DEBUG( - logger_, - "App: " << app_id << " is already acquired resource " << module_type); + if (app_id == allocated_resources_[module]) { + LOG4CXX_DEBUG(logger_, + "App: " << app_id << " is already acquired resource " + << module_type << " " << module_id); return AcquireResult::ALLOWED; } - if (IsModuleTypeRejected(module_type, app_id)) { - LOG4CXX_DEBUG( - logger_, - "Driver disallowed app: " << app_id << " to acquire " << module_type); + if (IsModuleTypeRejected(module_type, module_id, app_id)) { + LOG4CXX_DEBUG(logger_, + "Driver disallowed app: " << app_id << " to acquire " + << module_type << " " << module_id); return AcquireResult::REJECTED; } const mobile_apis::HMILevel::eType acquiring_app_hmi_level = - acquiring_app->hmi_level(); + acquiring_app->hmi_level(mobile_apis::PredefinedWindows::DEFAULT_WINDOW); if (mobile_apis::HMILevel::HMI_FULL != acquiring_app_hmi_level) { LOG4CXX_DEBUG(logger_, "Aquiring resources is not allowed in HMI level: " << acquiring_app_hmi_level << ". App: " << app_id - << " is disallowed to acquire " << module_type); + << " is disallowed to acquire " << module_type << " " + << module_id); + return AcquireResult::REJECTED; + } + + if (!rc_capabilities_manager_.IsMultipleAccessAllowed(module)) { + LOG4CXX_DEBUG(logger_, + "Multiple access for the: " << module_type << " " << module_id + << " isn't allowed"); return AcquireResult::REJECTED; } @@ -109,34 +130,58 @@ AcquireResult::eType ResourceAllocationManagerImpl::AcquireResource( LOG4CXX_DEBUG(logger_, "Current access_mode is AUTO_DENY. " << "App: " << app_id << " is disallowed to acquire " - << module_type); + << module_type << " " << module_id); return AcquireResult::IN_USE; } case hmi_apis::Common_RCAccessMode::ASK_DRIVER: { LOG4CXX_DEBUG(logger_, "Current access_mode is ASK_DRIVER. " "Driver confirmation is required for app: " - << app_id << " to acquire " << module_type); + << app_id << " to acquire " << module_type << " " + << module_id); return AcquireResult::ASK_DRIVER; } case hmi_apis::Common_RCAccessMode::AUTO_ALLOW: { LOG4CXX_DEBUG(logger_, "Current access_mode is AUTO_ALLOW. " << "App: " << app_id << " is allowed to acquire " - << module_type); - - SetResourceAquired(module_type, app_id); + << module_type << " " << module_id); return AcquireResult::ALLOWED; } default: { DCHECK_OR_RETURN(false, AcquireResult::IN_USE); } } } -void ResourceAllocationManagerImpl::ReleaseResource( +bool ResourceAllocationManagerImpl::IsUserLocationValid( + ModuleUid& module, application_manager::ApplicationSharedPtr app) { + LOG4CXX_AUTO_TRACE(logger_); + const auto extension = RCHelpers::GetRCExtension(*app); + DCHECK_OR_RETURN(extension, false); + const auto user_location = extension->GetUserLocation(); + const auto module_service_area = + rc_capabilities_manager_.GetModuleServiceArea(module); + const auto driver = + rc_capabilities_manager_.GetDriverLocationFromSeatLocationCapability(); + const bool is_driver = user_location == driver; + if (is_driver || user_location.IntersectionExists(module_service_area)) { + return true; + } + LOG4CXX_DEBUG(logger_, "User location is not valid"); + return false; +} + +void ResourceAllocationManagerImpl::ReleaseModuleType( const std::string& module_type, const uint32_t application_id) { LOG4CXX_AUTO_TRACE(logger_); - LOG4CXX_DEBUG(logger_, "Release " << module_type << " by " << application_id); - SetResourceFree(module_type, application_id); + LOG4CXX_DEBUG(logger_, + "Release " << module_type << " " + << " by " << application_id); + Resources allocated_resources = GetAcquiredResources(application_id); + for (const auto& resource : allocated_resources) { + if (module_type == resource.first) { + SetResourceFree(module_type, resource.second, application_id); + } + } } void ResourceAllocationManagerImpl::ProcessApplicationPolicyUpdate() { @@ -147,10 +192,10 @@ void ResourceAllocationManagerImpl::ProcessApplicationPolicyUpdate() { for (; app_list.end() != app; ++app) { application_manager::ApplicationSharedPtr app_ptr = *app; const uint32_t application_id = app_ptr->app_id(); - Resources acquired_modules = GetAcquiredResources(application_id); - std::sort(acquired_modules.begin(), acquired_modules.end()); + std::set<std::string> acquired_modules = + GetAcquiredModuleTypes(application_id); - Resources allowed_modules; + std::vector<std::string> allowed_modules; app_mngr_.GetPolicyHandler().GetModuleTypes((*app)->policy_app_id(), &allowed_modules); std::sort(allowed_modules.begin(), allowed_modules.end()); @@ -160,17 +205,16 @@ void ResourceAllocationManagerImpl::ProcessApplicationPolicyUpdate() { << " , allowed modules: " << allowed_modules.size()); - Resources disallowed_modules; + std::vector<std::string> disallowed_modules; std::set_difference(acquired_modules.begin(), acquired_modules.end(), allowed_modules.begin(), allowed_modules.end(), std::back_inserter(disallowed_modules)); - auto rc_extention = RCHelpers::GetRCExtension(**app); - Resources::const_iterator module = disallowed_modules.begin(); + auto module = disallowed_modules.begin(); for (; disallowed_modules.end() != module; ++module) { - ReleaseResource(*module, application_id); + ReleaseModuleType(*module, application_id); } if (!disallowed_modules.empty()) { SendOnRCStatusNotifications( @@ -190,8 +234,8 @@ EnumType StringToEnum(const std::string& str) { void ConstructOnRCStatusNotificationParams( smart_objects::SmartObject& msg_params, - const std::map<std::string, uint32_t>& allocated_resources, - const std::vector<std::string>& supported_resources, + const std::map<ModuleUid, uint32_t>& allocated_resources, + const std::vector<ModuleUid>& supported_resources, const uint32_t app_id) { namespace strings = application_manager::strings; namespace message_params = rc_rpc_plugin::message_params; @@ -201,12 +245,13 @@ void ConstructOnRCStatusNotificationParams( LOG4CXX_AUTO_TRACE(logger_); auto modules_inserter = [](SmartObject& result_modules) { - return [&result_modules](const std::string& module_name) { + return [&result_modules](const ModuleUid& module) { smart_objects::SmartObject module_data = SmartObject(smart_objects::SmartType_Map); auto module_type = - StringToEnum<mobile_apis::ModuleType::eType>(module_name); + StringToEnum<mobile_apis::ModuleType::eType>(module.first); module_data[message_params::kModuleType] = module_type; + module_data[message_params::kModuleId] = module.second; result_modules.asArray()->push_back(module_data); }; }; @@ -236,10 +281,11 @@ ResourceAllocationManagerImpl::CreateOnRCStatusNotificationToMobile( mobile_apis::FunctionID::OnRCStatusID, app->app_id()); auto& msg_params = (*msg_to_mobile)[application_manager::strings::msg_params]; if (is_rc_enabled()) { - ConstructOnRCStatusNotificationParams(msg_params, - allocated_resources_, - RCHelpers::GetModulesList(), - app->app_id()); + ConstructOnRCStatusNotificationParams( + msg_params, + allocated_resources_, + rc_capabilities_manager_.GetResources(), + app->app_id()); } else { msg_params[message_params::kAllocatedModules] = smart_objects::SmartObject(smart_objects::SmartType_Array); @@ -259,21 +305,12 @@ ResourceAllocationManagerImpl::CreateOnRCStatusNotificationToHmi( auto& msg_params = (*msg_to_hmi)[application_manager::strings::msg_params]; ConstructOnRCStatusNotificationParams(msg_params, allocated_resources_, - RCHelpers::GetModulesList(), + rc_capabilities_manager_.GetResources(), app->app_id()); msg_params[application_manager::strings::app_id] = app->hmi_app_id(); return msg_to_hmi; } -void ResourceAllocationManagerImpl::SetResourceAquired( - const std::string& module_type, const uint32_t app_id) { - LOG4CXX_AUTO_TRACE(logger_); - allocated_resources_[module_type] = app_id; - SendOnRCStatusNotifications( - NotificationTrigger::MODULE_ALLOCATION, - std::shared_ptr<application_manager::Application>()); -} - void ResourceAllocationManagerImpl::SendOnRCStatusNotifications( NotificationTrigger::eType event, application_manager::ApplicationSharedPtr application) { @@ -310,25 +347,81 @@ void ResourceAllocationManagerImpl::set_rc_enabled(const bool value) { std::shared_ptr<application_manager::Application>()); } -void ResourceAllocationManagerImpl::SetResourceFree( - const std::string& module_type, const uint32_t app_id) { +ResourceReleasedState::eType ResourceAllocationManagerImpl::ReleaseResource( + const std::string& module_type, + const std::string& module_id, + const uint32_t application_id) { + LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_DEBUG(logger_, + "Release " << module_type << " " << module_id << " by " + << application_id); + return SetResourceFree(module_type, module_id, application_id); +} + +void ResourceAllocationManagerImpl::SetResourceAcquired( + const std::string& module_type, + const std::string& module_id, + const uint32_t app_id) { + LOG4CXX_AUTO_TRACE(logger_); + ModuleUid module(module_type, module_id); + allocated_resources_[module] = app_id; +} + +bool ResourceAllocationManagerImpl::IsResourceAlreadyAcquiredByApp( + const ModuleUid& moduleUid, const uint32_t app_id) const { + LOG4CXX_AUTO_TRACE(logger_); + + auto allocation = allocated_resources_.find(moduleUid); + + if (allocated_resources_.end() == allocation) { + LOG4CXX_DEBUG(logger_, + "Resource " << moduleUid.first + << " is not allocated for any application."); + return false; + } + + if (allocation->second != app_id) { + LOG4CXX_DEBUG(logger_, + "Resource " + << moduleUid.first + << " is already allocated by app:" << allocation->second + << ". Asquire has been asked for app:" << app_id); + return false; + } + + LOG4CXX_DEBUG(logger_, + "Resource " << moduleUid.first + << " is allocated by app:" << allocation->second); + + return true; +} + +ResourceReleasedState::eType ResourceAllocationManagerImpl::SetResourceFree( + const std::string& module_type, + const std::string& module_id, + const uint32_t app_id) { + ModuleUid module(module_type, module_id); AllocatedResources::const_iterator allocation = - allocated_resources_.find(module_type); + allocated_resources_.find(module); if (allocated_resources_.end() == allocation) { LOG4CXX_DEBUG(logger_, "Resource " << module_type << " is not allocated."); - return; + return ResourceReleasedState::NOT_ALLOCATED; } if (app_id != allocation->second) { LOG4CXX_ERROR(logger_, "Resource " << module_type << " is allocated by different application " << allocation->second); + return ResourceReleasedState::IS_ALLOCATED; } allocated_resources_.erase(allocation); - LOG4CXX_DEBUG(logger_, "Resource " << module_type << " is released."); + LOG4CXX_DEBUG( + logger_, + "Resource " << module_type << ":" << module_id << " is released."); + return ResourceReleasedState::IS_RELEASED; } -std::vector<std::string> ResourceAllocationManagerImpl::GetAcquiredResources( +std::vector<ModuleUid> ResourceAllocationManagerImpl::GetAcquiredResources( const uint32_t application_id) const { LOG4CXX_AUTO_TRACE(logger_); Resources allocated_resources; @@ -347,18 +440,37 @@ std::vector<std::string> ResourceAllocationManagerImpl::GetAcquiredResources( return allocated_resources; } +std::set<std::string> ResourceAllocationManagerImpl::GetAcquiredModuleTypes( + const uint32_t application_id) const { + LOG4CXX_AUTO_TRACE(logger_); + Resources allocated_resources = GetAcquiredResources(application_id); + std::set<std::string> acquired_module_types; + for (const auto& resource : allocated_resources) { + acquired_module_types.insert(resource.first); + } + + LOG4CXX_DEBUG(logger_, + "Application " << application_id << " acquired " + << acquired_module_types.size() + << " module type(s)."); + + return acquired_module_types; +} + void ResourceAllocationManagerImpl::SetResourceState( const std::string& module_type, + const std::string& module_id, const uint32_t app_id, const ResourceState::eType state) { LOG4CXX_AUTO_TRACE(logger_); LOG4CXX_DEBUG(logger_, "Setting state for " << module_type << " by app_id " << app_id << " to state " << state); + ModuleUid module(module_type, module_id); { sync_primitives::AutoLock lock(allocated_resources_lock_); const AllocatedResources::const_iterator allocated_it = - allocated_resources_.find(module_type); + allocated_resources_.find(module); const bool acquired = allocated_resources_.end() != allocated_it; if (acquired) { @@ -374,16 +486,16 @@ void ResourceAllocationManagerImpl::SetResourceState( } sync_primitives::AutoLock lock(resources_state_lock_); - resources_state_[module_type] = state; + resources_state_[module] = state; LOG4CXX_DEBUG(logger_, "Resource " << module_type << " got state " << state); } bool ResourceAllocationManagerImpl::IsResourceFree( - const std::string& module_type) const { + const std::string& module_type, const std::string& module_id) const { LOG4CXX_AUTO_TRACE(logger_); + ModuleUid module(module_type, module_id); sync_primitives::AutoLock lock(resources_state_lock_); - const ResourcesState::const_iterator resource = - resources_state_.find(module_type); + const ResourcesState::const_iterator resource = resources_state_.find(module); if (resources_state_.end() == resource) { LOG4CXX_DEBUG(logger_, "Resource " << module_type << " is free."); @@ -411,15 +523,20 @@ ResourceAllocationManagerImpl::GetAccessMode() const { } void ResourceAllocationManagerImpl::ForceAcquireResource( - const std::string& module_type, const uint32_t app_id) { + const std::string& module_type, + const std::string& module_id, + const uint32_t app_id) { LOG4CXX_DEBUG(logger_, "Force " << app_id << " acquiring " << module_type); sync_primitives::AutoLock lock(allocated_resources_lock_); - SetResourceAquired(module_type, app_id); + SetResourceAcquired(module_type, module_id, app_id); } bool ResourceAllocationManagerImpl::IsModuleTypeRejected( - const std::string& module_type, const uint32_t app_id) { + const std::string& module_type, + const std::string& module_id, + const uint32_t app_id) { LOG4CXX_AUTO_TRACE(logger_); + ModuleUid module(module_type, module_id); sync_primitives::AutoLock lock(rejected_resources_for_application_lock_); RejectedResources::iterator it = rejected_resources_for_application_.find(app_id); @@ -428,24 +545,27 @@ bool ResourceAllocationManagerImpl::IsModuleTypeRejected( return false; } - const std::vector<std::string>& list_of_rejected_resources = + const std::vector<ModuleUid>& list_of_rejected_resources = rejected_resources_for_application_[app_id]; - return helpers::in_range(list_of_rejected_resources, module_type); + return helpers::in_range(list_of_rejected_resources, module); } void ResourceAllocationManagerImpl::OnDriverDisallowed( - const std::string& module_type, const uint32_t app_id) { + const std::string& module_type, + const std::string& module_id, + const uint32_t app_id) { LOG4CXX_AUTO_TRACE(logger_); + ModuleUid module(module_type, module_id); sync_primitives::AutoLock lock(rejected_resources_for_application_lock_); auto it = rejected_resources_for_application_.find(app_id); if (rejected_resources_for_application_.end() == it) { - rejected_resources_for_application_[app_id] = std::vector<std::string>(); + rejected_resources_for_application_[app_id] = std::vector<ModuleUid>(); } - std::vector<std::string>& list_of_rejected_resources = + std::vector<ModuleUid>& list_of_rejected_resources = rejected_resources_for_application_[app_id]; - list_of_rejected_resources.push_back(module_type); + list_of_rejected_resources.push_back(module); } void ResourceAllocationManagerImpl::OnApplicationEvent( @@ -458,10 +578,10 @@ void ResourceAllocationManagerImpl::OnApplicationEvent( if (ApplicationEvent::kApplicationExit == event || ApplicationEvent::kApplicationUnregistered == event) { - Resources acquired_modules = GetAcquiredResources(application->app_id()); - Resources::const_iterator module = acquired_modules.begin(); + auto acquired_modules = GetAcquiredModuleTypes(application->app_id()); + auto module = acquired_modules.begin(); for (; acquired_modules.end() != module; ++module) { - ReleaseResource(*module, application->app_id()); + ReleaseModuleType(*module, application->app_id()); } if (!acquired_modules.empty()) { SendOnRCStatusNotifications( diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/CMakeLists.txt b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/CMakeLists.txt index c1c59d7e78..bd46bdf11f 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/CMakeLists.txt +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/CMakeLists.txt @@ -37,11 +37,14 @@ include_directories ( ${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/test/include/ ${COMPONENTS_DIR}/include/test/application_manager/ ${COMPONENTS_DIR}/rc_rpc_plugin/test/include + ${COMPONENTS_DIR}/resumption/include ) set (RC_TEST_SOURCES -${CMAKE_CURRENT_SOURCE_DIR}/resource_allocation_manager_impl_test.cc ${CMAKE_CURRENT_SOURCE_DIR}/interior_data_cache_test.cc +${CMAKE_CURRENT_SOURCE_DIR}/rc_consent_manager_impl_test.cc +${CMAKE_CURRENT_SOURCE_DIR}/grid_test.cc +${CMAKE_CURRENT_SOURCE_DIR}/rc_helpers_test.cc ) set(RC_COMMANDS_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/commands) @@ -52,17 +55,9 @@ file(GLOB SOURCES ) set(LIBRARIES - RCRpcPluginStaticLib - ApplicationManager - connectionHandler - SmartObjects - ProtocolHandler - MessageHelper - connectionHandler - Utils - jsoncpp + rc_rpc_plugin_static + Resumption gmock_main - dl ) if(ENABLE_LOG) @@ -75,3 +70,4 @@ endif() create_test("rc_commands_test" "${SOURCES}" "${LIBRARIES}" ) create_test("rc_plugin_test" "${RC_TEST_SOURCES}" "${LIBRARIES}") +add_subdirectory(resource_allocation_manager) 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 f2b86f43da..fb8de0bb9c 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 @@ -40,6 +40,8 @@ #include "interfaces/MOBILE_API.h" #include "rc_rpc_plugin/mock/mock_interior_data_cache.h" #include "rc_rpc_plugin/mock/mock_interior_data_manager.h" +#include "rc_rpc_plugin/mock/mock_rc_capabilities_manager.h" +#include "rc_rpc_plugin/mock/mock_rc_consent_manager.h" #include "rc_rpc_plugin/mock/mock_resource_allocation_manager.h" #include "rc_rpc_plugin/rc_app_extension.h" #include "rc_rpc_plugin/rc_command_factory.h" @@ -82,40 +84,9 @@ class ButtonPressRequestTest , rc_app_extention_( std::make_shared<rc_rpc_plugin::RCAppExtension>(kModuleId)) {} - smart_objects::SmartObject ButtonCapability( - const mobile_apis::ButtonName::eType button_name) { - smart_objects::SmartObject button(smart_objects::SmartType_Map); - button["name"] = button_name; - return button; - } - void SetUp() OVERRIDE { - using namespace mobile_apis; - - std::vector<ButtonName::eType> button_names = {ButtonName::AC_MAX, - ButtonName::AC, - ButtonName::RECIRCULATE, - ButtonName::FAN_UP, - ButtonName::FAN_DOWN, - ButtonName::TEMP_UP, - ButtonName::TEMP_DOWN, - ButtonName::DEFROST_MAX, - ButtonName::DEFROST, - ButtonName::DEFROST_REAR, - ButtonName::UPPER_VENT, - ButtonName::LOWER_VENT, - ButtonName::VOLUME_UP, - ButtonName::VOLUME_DOWN, - ButtonName::EJECT, - ButtonName::SOURCE, - ButtonName::SHUFFLE, - ButtonName::REPEAT}; - - smart_objects::SmartObject button_caps(smart_objects::SmartType_Array); - for (size_t i = 0; i < button_names.size(); i++) { - button_caps[i] = ButtonCapability(button_names[i]); - } - rc_capabilities_[strings::kbuttonCapabilities] = button_caps; + smart_objects::SmartObject control_caps((smart_objects::SmartType_Array)); + rc_capabilities_[strings::kradioControlCapabilities] = control_caps; ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); ON_CALL(*mock_app_, QueryInterface(RCRPCPlugin::kRCPluginID)) .WillByDefault(Return(rc_app_extention_)); @@ -133,6 +104,12 @@ class ButtonPressRequestTest .WillByDefault(Return(true)); ON_CALL(mock_allocation_manager_, is_rc_enabled()) .WillByDefault(Return(true)); + ON_CALL(mock_rc_capabilities_manager_, CheckButtonName(_, _)) + .WillByDefault(Return(true)); + ON_CALL(mock_rc_capabilities_manager_, CheckIfModuleExistsInCapabilities(_)) + .WillByDefault(Return(true)); + ON_CALL(mock_rc_capabilities_manager_, CheckIfButtonExistInRCCaps(_)) + .WillByDefault(Return(true)); } MessageSharedPtr CreateBasicMessage() { @@ -156,7 +133,9 @@ class ButtonPressRequestTest mock_policy_handler_, mock_allocation_manager_, mock_interior_data_cache_, - mock_interior_data_manager_}; + mock_interior_data_manager_, + mock_rc_capabilities_manager_, + mock_rc_consent_manger_}; return std::make_shared<Command>(msg ? msg : msg = CreateMessage(), params); } @@ -172,29 +151,36 @@ class ButtonPressRequestTest mock_interior_data_cache_; testing::NiceMock<rc_rpc_plugin_test::MockInteriorDataManager> mock_interior_data_manager_; + testing::NiceMock<rc_rpc_plugin_test::MockRCCapabilitiesManager> + mock_rc_capabilities_manager_; + testing::NiceMock<MockRCConsentManager> mock_rc_consent_manger_; }; TEST_F(ButtonPressRequestTest, Execute_ButtonNameMatchesModuleType_ExpectCorrectMessageSentToHMI) { // Arrange + const std::string resource = "CLIMATE"; + const std::string resource_id = "id1"; MessageSharedPtr mobile_message = CreateBasicMessage(); ns_smart_device_link::ns_smart_objects::SmartObject& msg_params = (*mobile_message)[application_manager::strings::msg_params]; msg_params[message_params::kModuleType] = mobile_apis::ModuleType::CLIMATE; + msg_params[message_params::kModuleId] = resource_id; msg_params[message_params::kButtonName] = mobile_apis::ButtonName::AC; msg_params[message_params::kButtonPressMode] = mobile_apis::ButtonPressMode::SHORT; // Expectations - const std::string resource = "CLIMATE"; ON_CALL(mock_policy_handler_, CheckModule(_, _)).WillByDefault(Return(true)); - EXPECT_CALL(mock_allocation_manager_, IsResourceFree(resource)) + + EXPECT_CALL(mock_allocation_manager_, IsResourceFree(resource, resource_id)) .WillOnce(Return(true)); - EXPECT_CALL(mock_allocation_manager_, AcquireResource(resource, _)) + EXPECT_CALL(mock_allocation_manager_, AcquireResource(resource, _, _)) .WillOnce(Return(rc_rpc_plugin::AcquireResult::ALLOWED)); EXPECT_CALL( mock_allocation_manager_, - SetResourceState(resource, kAppId, rc_rpc_plugin::ResourceState::BUSY)); + SetResourceState( + resource, resource_id, kAppId, rc_rpc_plugin::ResourceState::BUSY)); EXPECT_CALL( mock_rpc_service_, ManageHMICommand( @@ -213,22 +199,27 @@ TEST_F( ButtonPressRequestTest, Execute_ButtonNameDoesNotMatchModuleType_ExpectMessageNotSentToHMI_AndFalseSentToMobile) { // Arrange + const std::string resource = "RADIO"; + const std::string resource_id = "id1"; MessageSharedPtr mobile_message = CreateBasicMessage(); ns_smart_device_link::ns_smart_objects::SmartObject& msg_params = (*mobile_message)[application_manager::strings::msg_params]; msg_params[message_params::kModuleType] = mobile_apis::ModuleType::RADIO; + msg_params[message_params::kModuleId] = resource_id; msg_params[message_params::kButtonName] = mobile_apis::ButtonName::AC; msg_params[message_params::kButtonPressMode] = mobile_apis::ButtonPressMode::SHORT; // Expectations - const std::string resource = "RADIO"; + EXPECT_CALL(mock_rc_capabilities_manager_, CheckButtonName(_, _)) + .WillOnce(Return(false)); ON_CALL(mock_policy_handler_, CheckModule(_, _)).WillByDefault(Return(true)); - EXPECT_CALL(mock_allocation_manager_, IsResourceFree(resource)) + EXPECT_CALL(mock_allocation_manager_, IsResourceFree(resource, resource_id)) .WillOnce(Return(true)); - EXPECT_CALL(mock_allocation_manager_, AcquireResource(resource, _)) + EXPECT_CALL(mock_allocation_manager_, AcquireResource(resource, _, _)) .WillOnce(Return(rc_rpc_plugin::AcquireResult::ALLOWED)); - EXPECT_CALL(mock_allocation_manager_, SetResourceState(resource, kAppId, _)) + EXPECT_CALL(mock_allocation_manager_, + SetResourceState(resource, resource_id, kAppId, _)) .Times(2); EXPECT_CALL( @@ -269,9 +260,10 @@ TEST_F(ButtonPressRequestTest, OnEvent_ExpectSuccessfullResponseSentToMobile) { hmi_msg_params[application_manager::strings::connection_key] = kConnectionKey; // Expectations - EXPECT_CALL(mock_allocation_manager_, - SetResourceState(_, kAppId, rc_rpc_plugin::ResourceState::FREE)) - .Times(2); + EXPECT_CALL( + mock_allocation_manager_, + SetResourceState(_, _, kAppId, rc_rpc_plugin::ResourceState::FREE)) + .Times(1); EXPECT_CALL( mock_rpc_service_, @@ -308,9 +300,10 @@ TEST_F(ButtonPressRequestTest, hmi_msg_params[application_manager::strings::connection_key] = kConnectionKey; // Expectations - EXPECT_CALL(mock_allocation_manager_, - SetResourceState(_, kAppId, rc_rpc_plugin::ResourceState::FREE)) - .Times(2); + EXPECT_CALL( + mock_allocation_manager_, + SetResourceState(_, _, kAppId, rc_rpc_plugin::ResourceState::FREE)) + .Times(1); EXPECT_CALL(mock_rpc_service_, ManageMobileCommand( diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/get_interior_vehicle_data_consent_request_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/get_interior_vehicle_data_consent_request_test.cc new file mode 100644 index 0000000000..29708d05bd --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/get_interior_vehicle_data_consent_request_test.cc @@ -0,0 +1,402 @@ +/* + * 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 <memory> +#include <string> + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include "rc_rpc_plugin/commands/mobile/get_interior_vehicle_data_consent_request.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application.h" +#include "rc_rpc_plugin/mock/mock_interior_data_cache.h" +#include "rc_rpc_plugin/mock/mock_interior_data_manager.h" +#include "rc_rpc_plugin/mock/mock_rc_capabilities_manager.h" +#include "rc_rpc_plugin/mock/mock_rc_consent_manager.h" +#include "rc_rpc_plugin/mock/mock_resource_allocation_manager.h" +#include "rc_rpc_plugin/rc_module_constants.h" + +using application_manager::commands::MessageSharedPtr; +using rc_rpc_plugin_test::MockInteriorDataCache; +using rc_rpc_plugin_test::MockInteriorDataManager; +using rc_rpc_plugin_test::MockRCCapabilitiesManager; +using rc_rpc_plugin_test::MockRCConsentManager; +using rc_rpc_plugin_test::MockResourceAllocationManager; +using test::components::application_manager_test::MockApplication; +using test::components::commands_test::CommandRequestTest; +using test::components::commands_test::CommandsTestMocks; + +using ::testing::_; +using ::testing::DoAll; +using ::testing::NiceMock; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::SaveArg; + +typedef std::shared_ptr< + rc_rpc_plugin::commands::GetInteriorVehicleDataConsentRequest> + GIVDConsentPtr; + +namespace { +const uint32_t kConnectionKey = 1u; +const uint32_t kAppId = 2u; +const std::string kPolicyAppId = "policy_app_id"; +const std::string kMacAddress = "device1"; +const std::string kModuleId_1 = "34045662-a9dc-4823-8435-91056d4c26cb"; +const std::string kModuleId_2 = "eb7739ea-b263-4fe1-af9c-9311d1acac2d"; +const std::string kModuleId_3 = "06cdec22-920e-4865-bf2e-9518463edc68"; +const mobile_apis::ModuleType::eType kModule_Type = + mobile_apis::ModuleType::eType::RADIO; +} // namespace + +namespace rc_rpc_plugin_test { +namespace get_interior_vehicle_data_consent_request_test { +using namespace rc_rpc_plugin; + +class GetInteriorVehicleDataConsentRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + GetInteriorVehicleDataConsentRequestTest() : mock_app_(CreateMockApp()) {} + + void SetUp() OVERRIDE { + TestPrecondition(); + } + + void TestPrecondition() { + message_ = CreateBasicMessage(); + ON_CALL(mock_rc_capabilities_manager_, CheckIfModuleExistsInCapabilities(_)) + .WillByDefault(Return(true)); + ON_CALL(mock_rc_capabilities_manager_, IsMultipleAccessAllowed(_)) + .WillByDefault(Return(true)); + } + + void PrepareNoConsentExistInCache() { + ON_CALL(mock_allocation_manager_, GetAccessMode()) + .WillByDefault(Return(hmi_apis::Common_RCAccessMode::ASK_DRIVER)); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kAppId)); + ON_CALL(*mock_app_, policy_app_id()).WillByDefault(Return(kPolicyAppId)); + ON_CALL(*mock_app_, mac_address()).WillByDefault(ReturnRef(kMacAddress)); + ON_CALL(mock_rc_consent_manger_, + GetModuleConsent(kPolicyAppId, kMacAddress, _)) + .WillByDefault(Return(rc_rpc_types::ModuleConsent::NOT_EXISTS)); + ON_CALL(mock_allocation_manager_, + AcquireResource(_, _, mock_app_->app_id())) + .WillByDefault(Return(AcquireResult::IN_USE)); + } + + void PrepareMobileMessage() { + auto& msg_params = (*message_)[application_manager::strings::msg_params]; + msg_params[message_params::kModuleType] = kModule_Type; + + msg_params[message_params::kModuleIds][0] = kModuleId_1; + msg_params[message_params::kModuleIds][1] = kModuleId_2; + msg_params[message_params::kModuleIds][2] = kModuleId_3; + } + + /** + * @brief CreateBasicMessage creates message for + * GetInteriorVehicleData request for app1 + * @return message shared ptr + */ + MessageSharedPtr CreateBasicMessage() { + MessageSharedPtr message = CreateMessage(); + (*message)[application_manager::strings::params] + [application_manager::strings::function_id] = + mobile_apis::FunctionID::GetInteriorVehicleDataID; + (*message)[application_manager::strings::params] + [application_manager::strings::connection_key] = kConnectionKey; + (*message)[application_manager::strings::params] + [application_manager::strings::app_id] = kAppId; + return message; + } + + template <class Command> + std::shared_ptr<Command> CreateRCCommand(MessageSharedPtr& msg) { + InitCommand(kDefaultTimeout_); + RCCommandParams params{app_mngr_, + mock_rpc_service_, + mock_hmi_capabilities_, + mock_policy_handler_, + mock_allocation_manager_, + mock_interior_data_cache_, + mock_interior_data_manager_, + mock_rc_capabilities_manager_, + mock_rc_consent_manger_}; + return std::make_shared<Command>(msg ? msg : msg = CreateMessage(), params); + } + + protected: + GIVDConsentPtr command_; + MessageSharedPtr message_; + + MockAppPtr mock_app_; + NiceMock<MockResourceAllocationManager> mock_allocation_manager_; + NiceMock<MockInteriorDataCache> mock_interior_data_cache_; + NiceMock<MockInteriorDataManager> mock_interior_data_manager_; + NiceMock<MockRCCapabilitiesManager> mock_rc_capabilities_manager_; + NiceMock<MockRCConsentManager> mock_rc_consent_manger_; +}; + +TEST_F(GetInteriorVehicleDataConsentRequestTest, + ModuleIDReturnsEmptyString_SUCCESS) { + std::string empty_str; + command_ = + CreateRCCommand<commands::GetInteriorVehicleDataConsentRequest>(message_); + + EXPECT_EQ(empty_str, command_->ModuleId()); +} + +TEST_F(GetInteriorVehicleDataConsentRequestTest, + Execute_ModuleIdsIsAbsentInMessage_Response_INVALID_DATA) { + command_ = + CreateRCCommand<commands::GetInteriorVehicleDataConsentRequest>(message_); + + auto response_to_mobile = CreateMessage(); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)).Times(0); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + command_->Execute(); + + const bool result = + (*response_to_mobile)[application_manager::strings::msg_params] + [application_manager::strings::success] + .asBool(); + const auto result_code = static_cast<mobile_apis::Result::eType>( + (*response_to_mobile)[application_manager::strings::msg_params] + [application_manager::strings::result_code] + .asUInt()); + EXPECT_FALSE(result); + EXPECT_EQ(mobile_apis::Result::INVALID_DATA, result_code); +} + +TEST_F(GetInteriorVehicleDataConsentRequestTest, + Execute_ModuleIdsIsEmpty_AddDefaultModuleID) { + (*message_)[application_manager::strings::msg_params] + [message_params::kModuleIds] = smart_objects::SmartObject( + smart_objects::SmartType::SmartType_Array); + (*message_)[application_manager::strings::msg_params] + [message_params::kModuleType] = kModule_Type; + command_ = + CreateRCCommand<commands::GetInteriorVehicleDataConsentRequest>(message_); + + auto message_to_hmi = CreateMessage(); + + const std::string module_type = "RADIO"; + const std::string default_module_id = "34045662-a9dc-4823-8435-91056d4c26cb"; + ON_CALL(mock_rc_capabilities_manager_, + GetDefaultModuleIdFromCapabilities(module_type)) + .WillByDefault(Return(default_module_id)); + + PrepareNoConsentExistInCache(); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)) + .WillOnce(DoAll(SaveArg<0>(&message_to_hmi), Return(true))); + + command_->Execute(); + + ASSERT_FALSE((*message_to_hmi)[application_manager::strings::msg_params] + [message_params::kModuleIds] + .empty()); + const auto sent_module_id = + (*message_to_hmi)[application_manager::strings::msg_params] + [message_params::kModuleIds][0] + .asString(); + EXPECT_EQ(sent_module_id, default_module_id); +} + +TEST_F(GetInteriorVehicleDataConsentRequestTest, + Execute_SDLForwardsMobileMessageToHMI_SUCCESS) { + auto message_to_hmi = CreateMessage(); + + PrepareMobileMessage(); + PrepareNoConsentExistInCache(); + + command_ = + CreateRCCommand<commands::GetInteriorVehicleDataConsentRequest>(message_); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)) + .WillOnce(DoAll(SaveArg<0>(&message_to_hmi), Return(true))); + + command_->Execute(); + + auto outgoing_msg_params = + (*message_to_hmi)[application_manager::strings::msg_params]; + + auto module_type = static_cast<mobile_apis::ModuleType::eType>( + outgoing_msg_params[message_params::kModuleType].asUInt()); + + EXPECT_EQ(kModule_Type, module_type); + EXPECT_EQ(kModuleId_1, + outgoing_msg_params[message_params::kModuleIds][0].asString()); + EXPECT_EQ(kModuleId_2, + outgoing_msg_params[message_params::kModuleIds][1].asString()); + EXPECT_EQ(kModuleId_3, + outgoing_msg_params[message_params::kModuleIds][2].asString()); +} + +TEST_F(GetInteriorVehicleDataConsentRequestTest, + On_Event_ConsentCollectionIsAbsentOrEmpty_Response_GENERIC_ERROR) { + PrepareMobileMessage(); + + command_ = + CreateRCCommand<commands::GetInteriorVehicleDataConsentRequest>(message_); + + // Consent collection in HMI response is absent + auto event_message = CreateMessage(); + application_manager::event_engine::Event event_collection_is_absent( + hmi_apis::FunctionID::RC_GetInteriorVehicleDataConsent); + event_collection_is_absent.set_smart_object(*event_message); + + auto response_to_mobile = CreateMessage(); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + command_->on_event(event_collection_is_absent); + + const auto result_code_is_absent = static_cast<mobile_apis::Result::eType>( + (*response_to_mobile)[application_manager::strings::msg_params] + [application_manager::strings::result_code] + .asUInt()); + EXPECT_EQ(mobile_apis::Result::GENERIC_ERROR, result_code_is_absent); + + // Consent coolection in HMI response isn't absent but is empty + event_message = CreateMessage(); + application_manager::event_engine::MobileEvent event_collection_is_empty( + mobile_apis::FunctionID::GetInteriorVehicleDataConsentID); + (*event_message)[application_manager::strings::msg_params] + [message_params::kAllowed] = smart_objects::SmartObject( + smart_objects::SmartType::SmartType_Array); + event_collection_is_empty.set_smart_object(*event_message); + + response_to_mobile = CreateMessage(); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + command_->on_event(event_collection_is_absent); + + const auto result_code_is_empty = static_cast<mobile_apis::Result::eType>( + (*response_to_mobile)[application_manager::strings::msg_params] + [application_manager::strings::result_code] + .asUInt()); + EXPECT_EQ(mobile_apis::Result::GENERIC_ERROR, result_code_is_empty); +} + +TEST_F(GetInteriorVehicleDataConsentRequestTest, + On_Event_ConsentsSizeIsNotEqualModuleIdsSize_Response_GENERIC_ERROR) { + PrepareMobileMessage(); + PrepareNoConsentExistInCache(); + + // ModuleIds collection will be saved + command_ = + CreateRCCommand<commands::GetInteriorVehicleDataConsentRequest>(message_); + command_->Execute(); + + auto event_message = CreateMessage(); + (*event_message)[application_manager::strings::msg_params] + [message_params::kAllowed] = smart_objects::SmartObject( + smart_objects::SmartType::SmartType_Array); + + // Consent collection will contain only two items in collection + (*event_message)[application_manager::strings::msg_params] + [message_params::kAllowed][0] = true; + (*event_message)[application_manager::strings::msg_params] + [message_params::kAllowed][1] = false; + + application_manager::event_engine::Event event( + hmi_apis::FunctionID::RC_GetInteriorVehicleDataConsent); + event.set_smart_object(*event_message); + + auto response_to_mobile = CreateMessage(); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + command_->on_event(event); + + const auto result_code_is_empty = static_cast<mobile_apis::Result::eType>( + (*response_to_mobile)[application_manager::strings::msg_params] + [application_manager::strings::result_code] + .asUInt()); + EXPECT_EQ(mobile_apis::Result::GENERIC_ERROR, result_code_is_empty); +} + +TEST_F(GetInteriorVehicleDataConsentRequestTest, + On_Event_SaveModuleConsentsToLastState_Response_SUCCESS) { + PrepareMobileMessage(); + PrepareNoConsentExistInCache(); + + // ModuleIds collection will be saved + command_ = + CreateRCCommand<commands::GetInteriorVehicleDataConsentRequest>(message_); + command_->Execute(); + + // Consent collection will have same size as moduelIds collection + auto event_message = CreateMessage(); + (*event_message)[application_manager::strings::msg_params] + [message_params::kAllowed][0] = true; + (*event_message)[application_manager::strings::msg_params] + [message_params::kAllowed][1] = false; + (*event_message)[application_manager::strings::msg_params] + [message_params::kAllowed][2] = false; + + application_manager::event_engine::Event event( + hmi_apis::FunctionID::RC_GetInteriorVehicleDataConsent); + event.set_smart_object(*event_message); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, policy_app_id()).WillByDefault(Return(kPolicyAppId)); + ON_CALL(*mock_app_, mac_address()).WillByDefault(ReturnRef(kMacAddress)); + + EXPECT_CALL(mock_rc_consent_manger_, SaveModuleConsents(kPolicyAppId, _, _)); + + auto response_to_mobile = CreateMessage(); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + command_->on_event(event); + + const auto result_code_is_empty = static_cast<mobile_apis::Result::eType>( + (*response_to_mobile)[application_manager::strings::msg_params] + [application_manager::strings::result_code] + .asUInt()); + EXPECT_EQ(mobile_apis::Result::SUCCESS, result_code_is_empty); +} + +} // namespace get_interior_vehicle_data_consent_request_test +} // namespace rc_rpc_plugin_test diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/get_interior_vehicle_data_request_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/get_interior_vehicle_data_request_test.cc index 123c22b944..532a62df3b 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/get_interior_vehicle_data_request_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/get_interior_vehicle_data_request_test.cc @@ -38,6 +38,8 @@ #include "gtest/gtest.h" #include "rc_rpc_plugin/mock/mock_interior_data_cache.h" #include "rc_rpc_plugin/mock/mock_interior_data_manager.h" +#include "rc_rpc_plugin/mock/mock_rc_capabilities_manager.h" +#include "rc_rpc_plugin/mock/mock_rc_consent_manager.h" #include "rc_rpc_plugin/mock/mock_resource_allocation_manager.h" #include "rc_rpc_plugin/rc_app_extension.h" #include "rc_rpc_plugin/rc_command_factory.h" @@ -74,7 +76,9 @@ const int32_t kConnectionKey = 5u; const uint32_t kAppId = 0u; const uint32_t kAppId2 = 1u; const int kModuleId = 153u; -const auto module_type = mobile_apis::ModuleType::RADIO; +const auto module_eType = mobile_apis::ModuleType::RADIO; +const auto module_type = "RADIO"; +const auto module_id = "eb7739ea-b263-4fe1-af9c-9311d1acac2d"; const int32_t time_frame_of_allowed_requests = 1; const uint32_t max_request_in_time_frame = 5u; } // namespace @@ -91,7 +95,8 @@ class GetInteriorVehicleDataRequestTest , rc_app_extention_(std::make_shared<RCAppExtension>(kModuleId)) , rc_app_extention2_(std::make_shared<RCAppExtension>(kModuleId)) , apps_lock_(std::make_shared<sync_primitives::Lock>()) - , apps_da_(apps_, apps_lock_) { + , apps_da_(apps_, apps_lock_) + , rc_capabilities_(smart_objects::SmartType::SmartType_Array) { ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kAppId)); ON_CALL(*mock_app2_, app_id()).WillByDefault(Return(kAppId2)); ON_CALL(*mock_app_, is_remote_control_supported()) @@ -125,6 +130,8 @@ class GetInteriorVehicleDataRequestTest std::pair<uint32_t, int32_t> frequency; frequency.first = max_request_in_time_frame; frequency.second = time_frame_of_allowed_requests; + smart_objects::SmartObject control_caps((smart_objects::SmartType_Array)); + rc_capabilities_[strings::kradioControlCapabilities] = control_caps; ON_CALL(app_mngr_, get_settings()) .WillByDefault(ReturnRef(app_mngr_settings_)); ON_CALL(app_mngr_settings_, get_interior_vehicle_data_frequency()) @@ -144,7 +151,7 @@ class GetInteriorVehicleDataRequestTest ON_CALL(app_mngr_, hmi_capabilities()) .WillByDefault(ReturnRef(mock_hmi_capabilities_)); ON_CALL(mock_hmi_capabilities_, rc_capability()) - .WillByDefault(Return(nullptr)); + .WillByDefault(Return(&rc_capabilities_)); ON_CALL(mock_policy_handler_, CheckHMIType( _, mobile_apis::AppHMIType::eType::REMOTE_CONTROL, nullptr)) @@ -153,6 +160,8 @@ class GetInteriorVehicleDataRequestTest .WillByDefault(Return(true)); ON_CALL(mock_allocation_manager_, is_rc_enabled()) .WillByDefault(Return(true)); + ON_CALL(mock_rc_capabilities_manager_, CheckIfModuleExistsInCapabilities(_)) + .WillByDefault(Return(true)); } template <class Command> @@ -164,7 +173,9 @@ class GetInteriorVehicleDataRequestTest mock_policy_handler_, mock_allocation_manager_, mock_interior_data_cache_, - mock_interior_data_manager_}; + mock_interior_data_manager_, + mock_rc_capabilities_manager_, + mock_rc_consent_manger_}; return std::make_shared<Command>(msg ? msg : msg = CreateMessage(), params); } @@ -182,6 +193,10 @@ class GetInteriorVehicleDataRequestTest application_manager::ApplicationSet apps_; const std::shared_ptr<sync_primitives::Lock> apps_lock_; DataAccessor<application_manager::ApplicationSet> apps_da_; + testing::NiceMock<rc_rpc_plugin_test::MockRCCapabilitiesManager> + mock_rc_capabilities_manager_; + smart_objects::SmartObject rc_capabilities_; + testing::NiceMock<MockRCConsentManager> mock_rc_consent_manger_; }; TEST_F(GetInteriorVehicleDataRequestTest, @@ -189,14 +204,16 @@ TEST_F(GetInteriorVehicleDataRequestTest, // Arrange MessageSharedPtr mobile_message = CreateBasicMessage(); (*mobile_message)[application_manager::strings::msg_params] - [message_params::kModuleType] = module_type; - ON_CALL(mock_interior_data_cache_, Contains(enums_value::kRadio)) + [message_params::kModuleType] = module_eType; + (*mobile_message)[application_manager::strings::msg_params] + [message_params::kModuleType] = module_id; + const ModuleUid module(module_type, module_id); + ON_CALL(mock_interior_data_cache_, Contains(module)) .WillByDefault(Return(false)); ON_CALL(mock_interior_data_manager_, CheckRequestsToHMIFrequency(_)) .WillByDefault(Return(true)); - std::shared_ptr<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest> - command = CreateRCCommand< - rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( + auto command = + CreateRCCommand<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( mobile_message); // Expectations @@ -216,16 +233,18 @@ TEST_F(GetInteriorVehicleDataRequestTest, // Arrange MessageSharedPtr mobile_message = CreateBasicMessage(); (*mobile_message)[application_manager::strings::msg_params] - [message_params::kModuleType] = module_type; + [message_params::kModuleType] = module_eType; + (*mobile_message)[application_manager::strings::msg_params] + [message_params::kModuleId] = module_id; (*mobile_message)[application_manager::strings::msg_params] [message_params::kSubscribe] = true; - ON_CALL(mock_interior_data_cache_, Contains(enums_value::kRadio)) + const ModuleUid module(module_type, module_id); + ON_CALL(mock_interior_data_cache_, Contains(module)) .WillByDefault(Return(false)); ON_CALL(mock_interior_data_manager_, CheckRequestsToHMIFrequency(_)) .WillByDefault(Return(true)); - std::shared_ptr<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest> - command = CreateRCCommand< - rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( + auto command = + CreateRCCommand<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( mobile_message); // Expectations @@ -243,10 +262,13 @@ TEST_F( GetInteriorVehicleDataRequestTest, Execute_ExpectMessageNotSentToHMI_SuccessSentToMobile_AppSubscribed_DataFromCache) { // Arrange - rc_app_extention_->SubscribeToInteriorVehicleData(enums_value::kRadio); + const ModuleUid module(module_type, module_id); + rc_app_extention_->SubscribeToInteriorVehicleData(module); MessageSharedPtr mobile_message = CreateBasicMessage(); (*mobile_message)[application_manager::strings::msg_params] - [message_params::kModuleType] = module_type; + [message_params::kModuleType] = module_eType; + (*mobile_message)[application_manager::strings::msg_params] + [message_params::kModuleId] = module_id; smart_objects::SmartObject radio_data; smart_objects::SmartObject sis_data; smart_objects::SmartObject gps_data; @@ -261,15 +283,14 @@ TEST_F( radio_data[message_params::kBand] = enums_value::kAM; radio_data[message_params::kSisData] = sis_data; - std::shared_ptr<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest> - command = CreateRCCommand< - rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( + auto command = + CreateRCCommand<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( mobile_message); // Expectations - EXPECT_CALL(mock_interior_data_cache_, Contains(enums_value::kRadio)) + EXPECT_CALL(mock_interior_data_cache_, Contains(module)) .WillOnce(Return(true)); - EXPECT_CALL(mock_interior_data_cache_, Retrieve(enums_value::kRadio)) + EXPECT_CALL(mock_interior_data_cache_, Retrieve(module)) .WillOnce(Return(radio_data)); EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)).Times(0); MessageSharedPtr command_result; @@ -291,13 +312,16 @@ TEST_F( TEST_F( GetInteriorVehicleDataRequestTest, - Execute_ExpectCorrectMessageSentToHMI_LastAppSubscribedUnsubscibe_ClearCache) { + Execute_ExpectCorrectMessageSentToHMI_LastAppSubscribedUnsubscribe_ClearCache) { // Arrange MessageSharedPtr mobile_message = CreateBasicMessage(); (*mobile_message)[application_manager::strings::msg_params] - [message_params::kModuleType] = module_type; + [message_params::kModuleType] = module_eType; (*mobile_message)[application_manager::strings::msg_params] [message_params::kSubscribe] = false; + (*mobile_message)[application_manager::strings::msg_params] + [message_params::kModuleId] = module_id; + const ModuleUid module(module_type, module_id); MessageSharedPtr hmi_response = CreateBasicMessage(); ns_smart_device_link::ns_smart_objects::SmartObject& hmi_msg_params = @@ -306,9 +330,11 @@ TEST_F( hmi_apis::Common_Result::SUCCESS; hmi_msg_params[application_manager::hmi_response::code] = response_code; hmi_msg_params[application_manager::strings::connection_key] = kConnectionKey; + hmi_msg_params[message_params::kModuleData][message_params::kModuleId] = + module_id; apps_.insert(mock_app_); - rc_app_extention_->SubscribeToInteriorVehicleData(enums_value::kRadio); + rc_app_extention_->SubscribeToInteriorVehicleData(module); ON_CALL(app_mngr_, applications()).WillByDefault(Return(apps_da_)); ON_CALL(mock_interior_data_manager_, CheckRequestsToHMIFrequency(_)) .WillByDefault(Return(true)); @@ -324,12 +350,11 @@ TEST_F( ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)) .WillOnce(Return(true)); - EXPECT_CALL(mock_interior_data_cache_, Remove(enums_value::kRadio)); + EXPECT_CALL(mock_interior_data_cache_, Remove(module)); // Act - std::shared_ptr<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest> - command = CreateRCCommand< - rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( + auto command = + CreateRCCommand<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( mobile_message); ASSERT_TRUE(command->Init()); command->Run(); @@ -344,28 +369,30 @@ TEST_F(GetInteriorVehicleDataRequestTest, // Arrange MessageSharedPtr mobile_message = CreateBasicMessage(); (*mobile_message)[application_manager::strings::msg_params] - [message_params::kModuleType] = module_type; + [message_params::kModuleType] = module_eType; (*mobile_message)[application_manager::strings::msg_params] [message_params::kSubscribe] = false; + (*mobile_message)[application_manager::strings::msg_params] + [message_params::kModuleId] = module_id; + const ModuleUid module(module_type, module_id); apps_.insert(mock_app_); apps_.insert(mock_app2_); - rc_app_extention_->SubscribeToInteriorVehicleData(enums_value::kRadio); - rc_app_extention2_->SubscribeToInteriorVehicleData(enums_value::kRadio); + rc_app_extention_->SubscribeToInteriorVehicleData(module); + rc_app_extention2_->SubscribeToInteriorVehicleData(module); smart_objects::SmartObject radio_data; radio_data[message_params::kBand] = enums_value::kAM; ON_CALL(app_mngr_, applications()).WillByDefault(Return(apps_da_)); - std::shared_ptr<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest> - command = CreateRCCommand< - rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( + auto command = + CreateRCCommand<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( mobile_message); // Expectations - EXPECT_CALL(mock_interior_data_cache_, Contains(enums_value::kRadio)) + EXPECT_CALL(mock_interior_data_cache_, Contains(module)) .WillOnce(Return(true)); - EXPECT_CALL(mock_interior_data_cache_, Retrieve(enums_value::kRadio)) + EXPECT_CALL(mock_interior_data_cache_, Retrieve(module)) .WillOnce(Return(radio_data)); EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)).Times(0); @@ -380,8 +407,8 @@ TEST_F(GetInteriorVehicleDataRequestTest, command->Run(); // Assert - EXPECT_FALSE( - rc_app_extention_->IsSubscibedToInteriorVehicleData(enums_value::kRadio)); + EXPECT_FALSE(rc_app_extention_->IsSubscribedToInteriorVehicleDataOfType( + enums_value::kRadio)); EXPECT_EQ((*command_result)[application_manager::strings::msg_params] [message_params::kModuleData] [message_params::kRadioControlData], @@ -395,14 +422,12 @@ TEST_F( MessageSharedPtr mobile_message = CreateBasicMessage(); ns_smart_device_link::ns_smart_objects::SmartObject& msg_params = (*mobile_message)[application_manager::strings::msg_params]; - msg_params[message_params::kModuleType] = mobile_apis::ModuleType::RADIO; - std::shared_ptr<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest> - command = CreateRCCommand< - rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( + msg_params[message_params::kModuleType] = module_eType; + auto command = + CreateRCCommand<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( mobile_message); - smart_objects::SmartObject rc_capabilities; ON_CALL(mock_hmi_capabilities_, rc_capability()) - .WillByDefault(Return(&rc_capabilities)); + .WillByDefault(Return(nullptr)); // Expectations EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)).Times(0); @@ -423,10 +448,9 @@ TEST_F( MessageSharedPtr mobile_message = CreateBasicMessage(); ns_smart_device_link::ns_smart_objects::SmartObject& msg_params = (*mobile_message)[application_manager::strings::msg_params]; - msg_params[message_params::kModuleType] = mobile_apis::ModuleType::RADIO; - std::shared_ptr<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest> - command = CreateRCCommand< - rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( + msg_params[message_params::kModuleType] = module_eType; + auto command = + CreateRCCommand<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( mobile_message); ON_CALL(mock_policy_handler_, CheckModule(_, _)).WillByDefault(Return(false)); @@ -451,12 +475,14 @@ TEST_F(GetInteriorVehicleDataRequestTest, // Arrange MessageSharedPtr mobile_message = CreateBasicMessage(); auto& msg_params = (*mobile_message)[strings::msg_params]; - msg_params[message_params::kModuleType] = module_type; + msg_params[message_params::kModuleType] = module_eType; MessageSharedPtr hmi_response_message = CreateBasicMessage(); auto& hmi_response_params = (*hmi_response_message)[strings::msg_params]; hmi_response_params[hmi_response::code] = hmi_apis::Common_Result::SUCCESS; hmi_response_params[strings::connection_key] = kConnectionKey; + hmi_response_params[message_params::kModuleData][message_params::kModuleId] = + module_id; ON_CALL(mock_interior_data_cache_, Contains(_)).WillByDefault(Return(false)); ON_CALL(mock_interior_data_manager_, CheckRequestsToHMIFrequency(_)) @@ -494,7 +520,7 @@ TEST_F(GetInteriorVehicleDataRequestTest, MessageSharedPtr mobile_message = CreateBasicMessage(); auto& msg_params = (*mobile_message)[application_manager::strings::msg_params]; - msg_params[message_params::kModuleType] = module_type; + msg_params[message_params::kModuleType] = module_eType; MessageSharedPtr hmi_message = CreateBasicMessage(); auto& hmi_msg_params = (*hmi_message)[strings::params]; @@ -526,14 +552,16 @@ TEST_F(GetInteriorVehicleDataRequestTest, } TEST_F(GetInteriorVehicleDataRequestTest, - OnEvent_InvalidHmiResponse_DontUnsubscibeLastApp_NoClearCache) { + OnEvent_InvalidHmiResponse_DontUnsubscribeLastApp_NoClearCache) { // Arrange MessageSharedPtr mobile_message = CreateBasicMessage(); (*mobile_message)[application_manager::strings::msg_params] - [message_params::kModuleType] = module_type; + [message_params::kModuleType] = module_eType; + (*mobile_message)[application_manager::strings::msg_params] + [message_params::kModuleId] = module_id; (*mobile_message)[application_manager::strings::msg_params] [message_params::kSubscribe] = false; - + const ModuleUid module(module_type, module_id); MessageSharedPtr hmi_response = CreateBasicMessage(); ns_smart_device_link::ns_smart_objects::SmartObject& hmi_msg_params = (*hmi_response)[application_manager::strings::params]; @@ -542,7 +570,7 @@ TEST_F(GetInteriorVehicleDataRequestTest, hmi_msg_params[application_manager::strings::connection_key] = kConnectionKey; apps_.insert(mock_app_); - rc_app_extention_->SubscribeToInteriorVehicleData(enums_value::kRadio); + rc_app_extention_->SubscribeToInteriorVehicleData(module); ON_CALL(app_mngr_, applications()).WillByDefault(Return(apps_da_)); ON_CALL(mock_interior_data_manager_, CheckRequestsToHMIFrequency(_)) .WillByDefault(Return(true)); @@ -561,9 +589,8 @@ TEST_F(GetInteriorVehicleDataRequestTest, EXPECT_CALL(mock_interior_data_cache_, Clear()).Times(0); // Act - std::shared_ptr<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest> - command = CreateRCCommand< - rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( + auto command = + CreateRCCommand<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( mobile_message); ASSERT_TRUE(command->Init()); command->Run(); @@ -573,32 +600,33 @@ TEST_F(GetInteriorVehicleDataRequestTest, command->on_event(event); // Assert - EXPECT_TRUE( - rc_app_extention_->IsSubscibedToInteriorVehicleData(enums_value::kRadio)); + EXPECT_TRUE(rc_app_extention_->IsSubscribedToInteriorVehicleData(module)); } TEST_F(GetInteriorVehicleDataRequestTest, Execute_ExpectRejectDuToRequestLimitation_NoCahce) { // Arrange - rc_app_extention_->UnsubscribeFromInteriorVehicleData(enums_value::kRadio); + rc_app_extention_->UnsubscribeFromInteriorVehicleDataOfType( + enums_value::kRadio); MessageSharedPtr mobile_message = CreateBasicMessage(); (*mobile_message)[application_manager::strings::msg_params] - [message_params::kModuleType] = module_type; + [message_params::kModuleType] = module_eType; + (*mobile_message)[application_manager::strings::msg_params] + [message_params::kModuleId] = module_id; smart_objects::SmartObject radio_data; radio_data[message_params::kBand] = enums_value::kAM; - std::shared_ptr<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest> - command = CreateRCCommand< - rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( + auto command = + CreateRCCommand<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( mobile_message); + const ModuleUid module(module_type, module_id); size_t i = 0; for (; i <= max_request_in_time_frame; ++i) { // Expectations EXPECT_CALL(mock_interior_data_manager_, - CheckRequestsToHMIFrequency(enums_value::kRadio)) + CheckRequestsToHMIFrequency(module)) .WillOnce(Return(true)); - EXPECT_CALL(mock_interior_data_manager_, - StoreRequestToHMITime(enums_value::kRadio)); - EXPECT_CALL(mock_interior_data_cache_, Contains(enums_value::kRadio)) + EXPECT_CALL(mock_interior_data_manager_, StoreRequestToHMITime(module)); + EXPECT_CALL(mock_interior_data_cache_, Contains(module)) .WillRepeatedly(Return(false)); EXPECT_CALL( mock_rpc_service_, @@ -612,8 +640,7 @@ TEST_F(GetInteriorVehicleDataRequestTest, } // Expectations - EXPECT_CALL(mock_interior_data_manager_, - CheckRequestsToHMIFrequency(enums_value::kRadio)) + EXPECT_CALL(mock_interior_data_manager_, CheckRequestsToHMIFrequency(module)) .WillOnce(Return(false)); EXPECT_CALL( mock_rpc_service_, diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/on_interior_vehicle_data_notification_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/on_interior_vehicle_data_notification_test.cc index dcf36a34a0..d6771c534d 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/on_interior_vehicle_data_notification_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/on_interior_vehicle_data_notification_test.cc @@ -38,6 +38,8 @@ #include "interfaces/MOBILE_API.h" #include "rc_rpc_plugin/mock/mock_interior_data_cache.h" #include "rc_rpc_plugin/mock/mock_interior_data_manager.h" +#include "rc_rpc_plugin/mock/mock_rc_capabilities_manager.h" +#include "rc_rpc_plugin/mock/mock_rc_consent_manager.h" #include "rc_rpc_plugin/mock/mock_resource_allocation_manager.h" #include "rc_rpc_plugin/rc_module_constants.h" #include "rc_rpc_plugin/rc_rpc_plugin.h" @@ -58,6 +60,8 @@ namespace { const uint32_t kAppId = 0u; const uint32_t kConnectionKey = 1u; const std::string kPolicyAppId = "Test"; +const std::string module_type = "CLIMATE"; +const std::string module_id = "34045662-a9dc-4823-8435-91056d4c26cb"; const int kModuleId = 153u; } // namespace @@ -93,6 +97,8 @@ class OnInteriorVehicleDataNotificationTest (*message)[application_manager::strings::msg_params]; msg_param[message_params::kModuleData][message_params::kModuleType] = mobile_apis::ModuleType::CLIMATE; + msg_param[message_params::kModuleData][message_params::kModuleId] = + module_id; return message; } @@ -105,7 +111,9 @@ class OnInteriorVehicleDataNotificationTest mock_policy_handler_, mock_allocation_manager_, mock_interior_data_cache_, - mock_interior_data_manager_}; + mock_interior_data_manager_, + mock_rc_capabilities_manager_, + mock_rc_consent_manger_}; return ::std::make_shared<Command>(msg ? msg : msg = CreateMessage(), params); } @@ -122,6 +130,9 @@ class OnInteriorVehicleDataNotificationTest application_manager::ApplicationSet apps_; const std::shared_ptr<sync_primitives::Lock> apps_lock_; DataAccessor<application_manager::ApplicationSet> apps_da_; + testing::NiceMock<rc_rpc_plugin_test::MockRCCapabilitiesManager> + mock_rc_capabilities_manager_; + testing::NiceMock<MockRCConsentManager> mock_rc_consent_manger_; }; TEST_F(OnInteriorVehicleDataNotificationTest, @@ -129,11 +140,12 @@ TEST_F(OnInteriorVehicleDataNotificationTest, // Arrange MessageSharedPtr mobile_message = CreateBasicMessage(); apps_.insert(mock_app_); - rc_app_extention_->SubscribeToInteriorVehicleData(enums_value::kClimate); + const ModuleUid module(module_type, module_id); + rc_app_extention_->SubscribeToInteriorVehicleData(module); ON_CALL(app_mngr_, applications()).WillByDefault(Return(apps_da_)); // Expectations - EXPECT_CALL(mock_interior_data_cache_, Add(enums_value::kClimate, _)); + EXPECT_CALL(mock_interior_data_cache_, Add(module, _)); MessageSharedPtr message; EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(_, false)) .WillOnce(SaveArg<0>(&message)); 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 6fbff118a4..62b726ac60 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 @@ -39,6 +39,8 @@ #include "rc_rpc_plugin/commands/hmi/rc_on_remote_control_settings_notification.h" #include "rc_rpc_plugin/mock/mock_interior_data_cache.h" #include "rc_rpc_plugin/mock/mock_interior_data_manager.h" +#include "rc_rpc_plugin/mock/mock_rc_capabilities_manager.h" +#include "rc_rpc_plugin/mock/mock_rc_consent_manager.h" #include "rc_rpc_plugin/mock/mock_resource_allocation_manager.h" #include "rc_rpc_plugin/rc_module_constants.h" #include "rc_rpc_plugin/rc_rpc_plugin.h" @@ -95,7 +97,9 @@ class RCOnRemoteControlSettingsNotificationTest mock_policy_handler_, mock_allocation_manager_, mock_interior_data_cache_, - mock_interior_data_manager_}; + mock_interior_data_manager_, + mock_rc_capabilities_manager_, + mock_rc_consent_manger_}; return std::make_shared<Command>(msg ? msg : msg = CreateMessage(), params); } @@ -107,6 +111,9 @@ class RCOnRemoteControlSettingsNotificationTest mock_interior_data_cache_; testing::NiceMock<rc_rpc_plugin_test::MockInteriorDataManager> mock_interior_data_manager_; + testing::NiceMock<rc_rpc_plugin_test::MockRCCapabilitiesManager> + mock_rc_capabilities_manager_; + testing::NiceMock<MockRCConsentManager> mock_rc_consent_manger_; }; TEST_F(RCOnRemoteControlSettingsNotificationTest, @@ -141,6 +148,7 @@ TEST_F(RCOnRemoteControlSettingsNotificationTest, EXPECT_CALL(mock_allocation_manager_, ResetAllAllocations()); EXPECT_CALL(mock_interior_data_manager_, OnDisablingRC()); + EXPECT_CALL(mock_rc_consent_manger_, RemoveAllConsents()); // Act std::shared_ptr< 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 b28f2c972a..55be43f37b 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 @@ -41,6 +41,7 @@ #include "application_manager/mock_request_controller_settings.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/rpc_service_impl.h" #include "hmi_message_handler/mock_hmi_message_handler.h" @@ -51,6 +52,8 @@ #include "rc_rpc_plugin/commands/mobile/button_press_request.h" #include "rc_rpc_plugin/mock/mock_interior_data_cache.h" #include "rc_rpc_plugin/mock/mock_interior_data_manager.h" +#include "rc_rpc_plugin/mock/mock_rc_capabilities_manager.h" +#include "rc_rpc_plugin/mock/mock_rc_consent_manager.h" #include "rc_rpc_plugin/mock/mock_resource_allocation_manager.h" #include "rc_rpc_plugin/rc_module_constants.h" #include "rc_rpc_plugin/rc_rpc_plugin.h" @@ -91,6 +94,9 @@ namespace { const uint32_t kConnectionKey = 2u; const uint32_t kAppId = 5u; const std::string kResource = "CLIMATE"; +const std::string kResourceId = "34045662-a9dc-4823-8435-91056d4c26cb"; +const std::string kPolicyAppId = "policy_app_id"; +const std::string kMacAddress = "device1"; const uint32_t kPluginID = RCRPCPlugin::kRCPluginID; } // namespace @@ -100,17 +106,25 @@ class RCGetInteriorVehicleDataConsentTest RCGetInteriorVehicleDataConsentTest() : mock_app_(std::make_shared<NiceMock<MockApplication> >()) , command_holder(app_mngr_) + , rc_capabilities_(smart_objects::SmartType::SmartType_Array) , request_controller(mock_request_controler) + , rpc_protection_manager_( + std::make_shared<application_manager::MockRPCProtectionManager>()) , rpc_service_(app_mngr_, request_controller, &mock_protocol_handler, &mock_hmi_handler, - command_holder) + command_holder, + rpc_protection_manager_, + hmi_so_factory_, + mobile_so_factoy_) , rc_app_extention_(std::make_shared<RCAppExtension>(kPluginID)) , mock_rpc_plugin_manager( std::make_shared<NiceMock<MockRPCPluginManager> >()) , rpc_plugin(mock_rpc_plugin) , optional_mock_rpc_plugin(mock_rpc_plugin) { + smart_objects::SmartObject control_caps((smart_objects::SmartType_Array)); + rc_capabilities_[strings::kradioControlCapabilities] = control_caps; ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kAppId)); ON_CALL(app_mngr_, hmi_interfaces()) .WillByDefault(ReturnRef(mock_hmi_interfaces_)); @@ -140,10 +154,16 @@ class RCGetInteriorVehicleDataConsentTest .WillByDefault(ReturnRef(*mock_rpc_plugin_manager)); ON_CALL(*mock_rpc_plugin_manager, FindPluginToProcess(_, _)) .WillByDefault(Return(rpc_plugin)); - ON_CALL(mock_allocation_manager_, IsResourceFree(kResource)) + ON_CALL(mock_allocation_manager_, IsResourceFree(kResource, kResourceId)) .WillByDefault(Return(true)); ON_CALL(mock_allocation_manager_, is_rc_enabled()) .WillByDefault(Return(true)); + ON_CALL(mock_protocol_handler, IsRPCServiceSecure(_)) + .WillByDefault(Return(false)); + ON_CALL(*rpc_protection_manager_, CheckPolicyEncryptionFlag(_, _, _)) + .WillByDefault(Return(false)); + ON_CALL(mock_rc_capabilities_manager_, CheckIfModuleExistsInCapabilities(_)) + .WillByDefault(Return(true)); } template <class Command> @@ -155,7 +175,9 @@ class RCGetInteriorVehicleDataConsentTest mock_policy_handler_, mock_allocation_manager_, mock_interior_data_cache_, - mock_interior_data_manager_}; + mock_interior_data_manager_, + mock_rc_capabilities_manager_, + mock_rc_consent_manger_}; return std::make_shared<Command>(msg ? msg : msg = CreateMessage(), params); } @@ -168,6 +190,10 @@ class RCGetInteriorVehicleDataConsentTest [application_manager::strings::connection_key] = kConnectionKey; (*message)[application_manager::strings::params] [application_manager::strings::connection_key] = kAppId; + ns_smart_device_link::ns_smart_objects::SmartObject& msg_params = + (*message)[application_manager::strings::msg_params]; + msg_params[message_params::kModuleType] = kResource; + msg_params[message_params::kModuleId] = kResourceId; return message; } @@ -187,12 +213,19 @@ class RCGetInteriorVehicleDataConsentTest MockRPCPlugin mock_rpc_plugin; MockCommandFactory mock_command_factory; am::request_controller::RequestController request_controller; + std::shared_ptr<application_manager::MockRPCProtectionManager> + rpc_protection_manager_; am::rpc_service::RPCServiceImpl rpc_service_; std::shared_ptr<RCAppExtension> rc_app_extention_; std::shared_ptr<am::plugin_manager::MockRPCPluginManager> mock_rpc_plugin_manager; utils::Optional<RPCPlugin> rpc_plugin; utils::Optional<MockRPCPlugin> optional_mock_rpc_plugin; + hmi_apis::HMI_API hmi_so_factory_; + mobile_apis::MOBILE_API mobile_so_factoy_; + testing::NiceMock<rc_rpc_plugin_test::MockRCCapabilitiesManager> + mock_rc_capabilities_manager_; + testing::NiceMock<MockRCConsentManager> mock_rc_consent_manger_; }; TEST_F(RCGetInteriorVehicleDataConsentTest, @@ -201,8 +234,17 @@ TEST_F(RCGetInteriorVehicleDataConsentTest, auto mobile_message = CreateBasicMessage(); // Expectations - EXPECT_CALL(mock_allocation_manager_, AcquireResource(_, _)) + EXPECT_CALL(mock_allocation_manager_, AcquireResource(_, _, _)) .WillOnce(Return(rc_rpc_plugin::AcquireResult::ASK_DRIVER)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kAppId)); + ON_CALL(*mock_app_, policy_app_id()).WillByDefault(Return(kPolicyAppId)); + ON_CALL(*mock_app_, mac_address()).WillByDefault(ReturnRef(kMacAddress)); + + rc_rpc_types::ModuleUid moduleUid{kResource, kResourceId}; + EXPECT_CALL(mock_rc_consent_manger_, + GetModuleConsent(kPolicyAppId, _, moduleUid)) + .WillOnce(Return(rc_rpc_types::ModuleConsent::NOT_EXISTS)); + EXPECT_CALL(*optional_mock_rpc_plugin, GetCommandFactory()) .WillOnce(ReturnRef(mock_command_factory)); auto rc_consent_request = @@ -223,15 +265,17 @@ TEST_F(RCGetInteriorVehicleDataConsentTest, TEST_F(RCGetInteriorVehicleDataConsentTest, Run_MobileSendButtonPressMessage_HMISendINUSEModeToMobile) { - // Arrange - auto mobile_message = CreateBasicMessage(); - // Expectations - EXPECT_CALL(mock_allocation_manager_, AcquireResource(_, _)) + EXPECT_CALL(mock_allocation_manager_, AcquireResource(_, _, _)) .WillOnce(Return(rc_rpc_plugin::AcquireResult::IN_USE)); + auto msg_ver = utils::SemanticVersion(); + ON_CALL(*mock_app_, msg_version()).WillByDefault(ReturnRef(msg_ver)); + EXPECT_CALL(*optional_mock_rpc_plugin, GetCommandFactory()) .WillOnce(ReturnRef(mock_command_factory)); + + auto mobile_message = CreateBasicMessage(); auto rc_consent_response = CreateRCCommand<commands::RCGetInteriorVehicleDataConsentResponse>( mobile_message); diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/release_interior_vehicle_data_module_request_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/release_interior_vehicle_data_module_request_test.cc new file mode 100644 index 0000000000..200e458c17 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/release_interior_vehicle_data_module_request_test.cc @@ -0,0 +1,243 @@ +/* + * 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 <memory> +#include <string> + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include "rc_rpc_plugin/commands/mobile/release_interior_vehicle_data_module_request.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application.h" +#include "rc_rpc_plugin/mock/mock_interior_data_cache.h" +#include "rc_rpc_plugin/mock/mock_interior_data_manager.h" +#include "rc_rpc_plugin/mock/mock_rc_capabilities_manager.h" +#include "rc_rpc_plugin/mock/mock_rc_consent_manager.h" +#include "rc_rpc_plugin/mock/mock_resource_allocation_manager.h" +#include "rc_rpc_plugin/rc_module_constants.h" + +using application_manager::commands::MessageSharedPtr; +using rc_rpc_plugin_test::MockInteriorDataCache; +using rc_rpc_plugin_test::MockInteriorDataManager; +using rc_rpc_plugin_test::MockRCCapabilitiesManager; +using rc_rpc_plugin_test::MockRCConsentManager; +using rc_rpc_plugin_test::MockResourceAllocationManager; +using test::components::application_manager_test::MockApplication; +using test::components::commands_test::CommandRequestTest; +using test::components::commands_test::CommandsTestMocks; + +using testing::_; +using ::testing::DoAll; +using ::testing::Mock; +using ::testing::NiceMock; +using ::testing::Return; +using ::testing::SaveArg; + +typedef std::shared_ptr< + rc_rpc_plugin::commands::ReleaseInteriorVehicleDataModuleRequest> + ReleaseCommandPtr; + +namespace { +std::string kPolicyAppID = "app_id"; +std::uint32_t kAppID = 2u; +std::uint32_t kConnectionKey = 1u; +std::string kModuleType = "RADIO"; +std::string kModuleID = "76149d9b-5317-4cf5-9196-b8fac690fec5"; +std::string kDefaultModuleID = "eb7739ea-b263-4fe1-af9c-9311d1acac2d"; +} // namespace + +namespace rc_rpc_plugin_test { +namespace release_interior_vehicle_data_module_request { +using namespace rc_rpc_plugin; + +class ReleaseInteriorVehicleDataModuleRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + ReleaseInteriorVehicleDataModuleRequestTest() : mock_app_(CreateMockApp()) {} + + void SetUp() OVERRIDE { + TestPreCondition(); + ON_CALL(app_mngr_, application(kAppID)).WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kAppID)); + ON_CALL(mock_rc_capabilities_manager_, + GetDefaultModuleIdFromCapabilities(kModuleType)) + .WillByDefault(Return(kDefaultModuleID)); + } + + MessageSharedPtr CreateBasicMessage() { + MessageSharedPtr message = CreateMessage(); + (*message)[application_manager::strings::params] + [application_manager::strings::function_id] = + mobile_apis::FunctionID::ReleaseInteriorVehicleDataModuleID; + (*message)[application_manager::strings::params] + [application_manager::strings::connection_key] = kConnectionKey; + (*message)[application_manager::strings::params] + [application_manager::strings::connection_key] = kAppID; + (*message)[application_manager::strings::msg_params] + [message_params::kModuleType] = mobile_apis::ModuleType::RADIO; + (*message)[application_manager::strings::msg_params] + [message_params::kModuleId] = kModuleID; + return message; + } + + void TestPreCondition() { + message_ = CreateBasicMessage(); + command_ = + CreateRCCommand<commands::ReleaseInteriorVehicleDataModuleRequest>( + message_); + } + + template <class Command> + std::shared_ptr<Command> CreateRCCommand(MessageSharedPtr& msg) { + InitCommand(kDefaultTimeout_); + RCCommandParams params{app_mngr_, + mock_rpc_service_, + mock_hmi_capabilities_, + mock_policy_handler_, + mock_allocation_manager_, + mock_interior_data_cache_, + mock_interior_data_manager_, + mock_rc_capabilities_manager_, + mock_rc_consent_manger_}; + return std::make_shared<Command>(msg ? msg : msg = CreateMessage(), params); + } + + protected: + MessageSharedPtr message_; + ReleaseCommandPtr command_; + + MockAppPtr mock_app_; + NiceMock<MockResourceAllocationManager> mock_allocation_manager_; + MockInteriorDataCache mock_interior_data_cache_; + MockInteriorDataManager mock_interior_data_manager_; + NiceMock<MockRCCapabilitiesManager> mock_rc_capabilities_manager_; + MockRCConsentManager mock_rc_consent_manger_; +}; + +TEST_F(ReleaseInteriorVehicleDataModuleRequestTest, + ModuleIDIsAbsnetInMessage_ReturnsDefaultFromCapabilities) { + (*message_)[application_manager::strings::msg_params].erase( + message_params::kModuleId); + + auto module_id = command_->ModuleId(); + EXPECT_EQ(kDefaultModuleID, module_id); +} + +TEST_F(ReleaseInteriorVehicleDataModuleRequestTest, + ResourceIsNotAllocated_ResponseToMobile_UNSUCCESS_IGNORED) { + ON_CALL(mock_allocation_manager_, + ReleaseResource(kModuleType, kModuleID, kAppID)) + .WillByDefault(Return(ResourceReleasedState::eType::NOT_ALLOCATED)); + + MessageSharedPtr message_to_mobile = CreateMessage(); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + _, application_manager::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&message_to_mobile), Return(true))); + + command_->Execute(); + + const bool success = + (*message_to_mobile)[application_manager::strings::msg_params] + [application_manager::strings::success] + .asBool(); + auto result_code = static_cast<mobile_apis::Result::eType>( + (*message_to_mobile)[application_manager::strings::msg_params] + [application_manager::strings::result_code] + .asUInt()); + + EXPECT_FALSE(success); + EXPECT_EQ(mobile_apis::Result::eType::IGNORED, result_code); +} + +TEST_F(ReleaseInteriorVehicleDataModuleRequestTest, + ResourceIsAllocated_ResponseToMobile_UNSUCCESS_REJECTED) { + ON_CALL(mock_allocation_manager_, + ReleaseResource(kModuleType, kModuleID, kAppID)) + .WillByDefault(Return(ResourceReleasedState::eType::IS_ALLOCATED)); + MessageSharedPtr message_to_mobile = CreateMessage(); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + _, application_manager::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&message_to_mobile), Return(true))); + + command_->Execute(); + + const bool success = + (*message_to_mobile)[application_manager::strings::msg_params] + [application_manager::strings::success] + .asBool(); + auto result_code = static_cast<mobile_apis::Result::eType>( + (*message_to_mobile)[application_manager::strings::msg_params] + [application_manager::strings::result_code] + .asUInt()); + + EXPECT_FALSE(success); + EXPECT_EQ(mobile_apis::Result::eType::REJECTED, result_code); +} + +TEST_F(ReleaseInteriorVehicleDataModuleRequestTest, + ResourceIsReleased_ResponseToMobile_SUCCESS_SUCCESS) { + ON_CALL(mock_allocation_manager_, + ReleaseResource(kModuleType, kModuleID, kAppID)) + .WillByDefault(Return(ResourceReleasedState::eType::IS_RELEASED)); + + MessageSharedPtr message_to_mobile = CreateMessage(); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + _, application_manager::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&message_to_mobile), Return(true))); + + command_->Execute(); + + const bool success = + (*message_to_mobile)[application_manager::strings::msg_params] + [application_manager::strings::success] + .asBool(); + auto result_code = static_cast<mobile_apis::Result::eType>( + (*message_to_mobile)[application_manager::strings::msg_params] + [application_manager::strings::result_code] + .asUInt()); + + EXPECT_TRUE(success); + EXPECT_EQ(mobile_apis::Result::eType::SUCCESS, result_code); +} +} // namespace release_interior_vehicle_data_module_request +} // namespace rc_rpc_plugin_test 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 f7718a7248..5a822a2fe4 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 @@ -37,6 +37,8 @@ #include "interfaces/MOBILE_API.h" #include "rc_rpc_plugin/mock/mock_interior_data_cache.h" #include "rc_rpc_plugin/mock/mock_interior_data_manager.h" +#include "rc_rpc_plugin/mock/mock_rc_capabilities_manager.h" +#include "rc_rpc_plugin/mock/mock_rc_consent_manager.h" #include "rc_rpc_plugin/mock/mock_resource_allocation_manager.h" #include "rc_rpc_plugin/rc_module_constants.h" #include "rc_rpc_plugin/rc_rpc_plugin.h" @@ -71,9 +73,12 @@ class SetInteriorVehicleDataRequestTest public: SetInteriorVehicleDataRequestTest() : mock_app_(std::make_shared<NiceMock<MockApplication> >()) - , rc_app_extention_(std::make_shared<RCAppExtension>(kModuleId)) {} + , rc_app_extention_(std::make_shared<RCAppExtension>(kModuleId)) + , rc_capabilities_(smart_objects::SmartType::SmartType_Array) {} void SetUp() OVERRIDE { + smart_objects::SmartObject control_caps((smart_objects::SmartType_Array)); + rc_capabilities_[strings::kradioControlCapabilities] = control_caps; ON_CALL(app_mngr_, hmi_interfaces()) .WillByDefault(ReturnRef(mock_hmi_interfaces_)); ON_CALL( @@ -86,9 +91,9 @@ class SetInteriorVehicleDataRequestTest .WillByDefault(Return(rc_app_extention_)); ON_CALL(*mock_app_, policy_app_id()).WillByDefault(Return(kPolicyAppId)); - ON_CALL(mock_allocation_manager_, IsResourceFree(_)) + ON_CALL(mock_allocation_manager_, IsResourceFree(_, _)) .WillByDefault(Return(true)); - ON_CALL(mock_allocation_manager_, AcquireResource(_, _)) + ON_CALL(mock_allocation_manager_, AcquireResource(_, _, _)) .WillByDefault(Return(AcquireResult::ALLOWED)); ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kAppId)); ON_CALL(mock_policy_handler_, @@ -96,8 +101,14 @@ class SetInteriorVehicleDataRequestTest mobile_apis::AppHMIType::eType::REMOTE_CONTROL, nullptr)) .WillByDefault(Return(true)); + ON_CALL(mock_hmi_capabilities_, rc_capability()) + .WillByDefault(Return(&rc_capabilities_)); ON_CALL(mock_allocation_manager_, is_rc_enabled()) .WillByDefault(Return(true)); + ON_CALL(mock_rc_capabilities_manager_, CheckIfModuleExistsInCapabilities(_)) + .WillByDefault(Return(true)); + ON_CALL(mock_rc_capabilities_manager_, GetModuleDataCapabilities(_, _)) + .WillByDefault(Return(std::make_pair("", capabilitiesStatus::success))); } MessageSharedPtr CreateBasicMessage() { @@ -121,7 +132,9 @@ class SetInteriorVehicleDataRequestTest mock_policy_handler_, mock_allocation_manager_, mock_interior_data_cache_, - mock_interior_data_manager_}; + mock_interior_data_manager_, + mock_rc_capabilities_manager_, + mock_rc_consent_manger_}; return std::make_shared<Command>(msg ? msg : msg = CreateMessage(), params); } @@ -134,6 +147,10 @@ class SetInteriorVehicleDataRequestTest mock_interior_data_manager_; std::shared_ptr<MockApplication> mock_app_; std::shared_ptr<RCAppExtension> rc_app_extention_; + testing::NiceMock<rc_rpc_plugin_test::MockRCCapabilitiesManager> + mock_rc_capabilities_manager_; + smart_objects::SmartObject rc_capabilities_; + testing::NiceMock<MockRCConsentManager> mock_rc_consent_manger_; }; TEST_F(SetInteriorVehicleDataRequestTest, @@ -153,18 +170,14 @@ TEST_F(SetInteriorVehicleDataRequestTest, EXPECT_CALL(mock_policy_handler_, CheckModule(kPolicyAppId, _)) .WillOnce(Return(rc_rpc_plugin::TypeAccess::kAllowed)); - EXPECT_CALL(mock_hmi_capabilities_, rc_capability()) - .WillOnce(Return(nullptr)); - EXPECT_CALL( mock_rpc_service_, ManageHMICommand( HMIResultCodeIs(hmi_apis::FunctionID::RC_SetInteriorVehicleData), _)) .WillOnce(Return(true)); // Act - std::shared_ptr<rc_rpc_plugin::commands::SetInteriorVehicleDataRequest> - command = CreateRCCommand< - rc_rpc_plugin::commands::SetInteriorVehicleDataRequest>( + auto command = + CreateRCCommand<rc_rpc_plugin::commands::SetInteriorVehicleDataRequest>( mobile_message); ASSERT_TRUE(command->Init()); command->Run(); @@ -190,9 +203,6 @@ TEST_F( EXPECT_CALL(mock_policy_handler_, CheckModule(kPolicyAppId, _)) .WillOnce(Return(rc_rpc_plugin::TypeAccess::kAllowed)); - EXPECT_CALL(mock_hmi_capabilities_, rc_capability()) - .WillOnce(Return(nullptr)); - EXPECT_CALL(app_mngr_, RemoveHMIFakeParameters(_, _)); EXPECT_CALL( @@ -260,9 +270,6 @@ TEST_F(SetInteriorVehicleDataRequestTest, EXPECT_CALL(mock_policy_handler_, CheckModule(kPolicyAppId, _)) .WillOnce(Return(rc_rpc_plugin::TypeAccess::kAllowed)); - EXPECT_CALL(mock_hmi_capabilities_, rc_capability()) - .WillOnce(Return(nullptr)); - MessageSharedPtr message_from_mobile = CreateBasicMessage(); EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)) @@ -306,9 +313,6 @@ TEST_F(SetInteriorVehicleDataRequestTest, EXPECT_CALL(mock_policy_handler_, CheckModule(kPolicyAppId, _)) .WillOnce(Return(rc_rpc_plugin::TypeAccess::kAllowed)); - EXPECT_CALL(mock_hmi_capabilities_, rc_capability()) - .WillOnce(Return(nullptr)); - auto message_from_mobile = CreateBasicMessage(); EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)) diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/grid_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/grid_test.cc new file mode 100644 index 0000000000..b8a0d71203 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/grid_test.cc @@ -0,0 +1,72 @@ +/* + * 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 "gtest/gtest.h" + +#include "rc_rpc_plugin/rc_app_extension.h" + +namespace rc_rpc_plugin_test { +namespace grid_test { +using namespace rc_rpc_plugin; + +TEST(Grid, IsLevelIntersectionExists) { + Grid grid_level0{1, 1, 0, 1, 1, 1}; + Grid grid_level1{1, 1, 1, 1, 1, 1}; + EXPECT_FALSE(grid_level0.LevelIntersectionExists(grid_level1)); + + Grid grid_level1_v2{1, 2, 1, 1, 2, 1}; + EXPECT_TRUE(grid_level1.LevelIntersectionExists(grid_level1_v2)); +} + +TEST(Grid, TwoSameGrisAreEqual) { + Grid grid2{1, 1, 0, 1, 1, 1}; + Grid grid1{1, 1, 0, 1, 1, 1}; + + EXPECT_EQ(grid1, grid2); +} + +TEST(Grid, IsIntersectionExists) { + Grid grid_1{0, 1, 2, 1, 1, 1}; + Grid grid_2{0, 0, 1, 0, 0, 1}; + + // There is intersection but levels missmatch + EXPECT_FALSE(grid_1.IntersectionExists(grid_2)); + + Grid grid_3{1, 0, 2, 0, 0, 0}; + // There isn't intersection but level match + EXPECT_FALSE(grid_1.IntersectionExists(grid_3)); + + Grid grid_4{0, 1, 2, 1, 1, 1}; + EXPECT_TRUE(grid_1.IntersectionExists(grid_4)); +} +} // namespace grid_test +} // namespace rc_rpc_plugin_test diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_interior_data_cache.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_interior_data_cache.h index 45465f96b0..025cef2165 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_interior_data_cache.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_interior_data_cache.h @@ -42,10 +42,14 @@ namespace rc_rpc_plugin_test { class MockInteriorDataCache : public rc_rpc_plugin::InteriorDataCache { public: MOCK_METHOD2(Add, - void(const std::string&, const smart_objects::SmartObject&)); - MOCK_CONST_METHOD1(Retrieve, smart_objects::SmartObject(const std::string&)); - MOCK_CONST_METHOD1(Contains, bool(const std::string&)); - MOCK_METHOD1(Remove, void(const std::string&)); + void(const rc_rpc_plugin::ModuleUid&, + const smart_objects::SmartObject&)); + MOCK_CONST_METHOD1( + Retrieve, smart_objects::SmartObject(const rc_rpc_plugin::ModuleUid&)); + MOCK_CONST_METHOD1(GetCachedModulesByType, + std::vector<rc_rpc_plugin::ModuleUid>(const std::string&)); + MOCK_CONST_METHOD1(Contains, bool(const rc_rpc_plugin::ModuleUid&)); + MOCK_METHOD1(Remove, void(const rc_rpc_plugin::ModuleUid&)); MOCK_METHOD0(Clear, void()); }; diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_interior_data_manager.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_interior_data_manager.h index fc19c6a889..231ac2ae36 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_interior_data_manager.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_interior_data_manager.h @@ -46,8 +46,9 @@ class MockInteriorDataManager : public rc_rpc_plugin::InteriorDataManager { void(application_manager::plugin_manager::ApplicationEvent, application_manager::ApplicationSharedPtr)); MOCK_METHOD0(OnDisablingRC, void()); - MOCK_METHOD1(StoreRequestToHMITime, void(const std::string&)); - MOCK_METHOD1(CheckRequestsToHMIFrequency, bool(const std::string&)); + MOCK_METHOD1(StoreRequestToHMITime, void(const rc_rpc_plugin::ModuleUid&)); + MOCK_METHOD1(CheckRequestsToHMIFrequency, + bool(const rc_rpc_plugin::ModuleUid&)); }; } // namespace rc_rpc_plugin_test diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_rc_capabilities_manager.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_rc_capabilities_manager.h new file mode 100644 index 0000000000..6f1593dcbb --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_rc_capabilities_manager.h @@ -0,0 +1,93 @@ +/* + * 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_RC_RPC_PLUGIN_TEST_INCLUDE_RC_RPC_PLUGIN_MOCK_MOCK_RC_CAPABILITIES_MANAGER_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_TEST_INCLUDE_RC_RPC_PLUGIN_MOCK_MOCK_RC_CAPABILITIES_MANAGER_H_ +#include "gmock/gmock.h" +#include "rc_rpc_plugin/rc_capabilities_manager.h" + +namespace rc_rpc_plugin_test { +class MockRCCapabilitiesManager : public rc_rpc_plugin::RCCapabilitiesManager { + public: + MOCK_CONST_METHOD2(CheckButtonName, + bool(const std::string& module_type, + const std::string& button_name)); + + MOCK_CONST_METHOD1(CheckIfModuleExistsInCapabilities, + bool(const rc_rpc_plugin::ModuleUid& module_type)); + + MOCK_CONST_METHOD2(GetModuleDataCapabilities, + rc_rpc_plugin::ModuleTypeCapability( + const smart_objects::SmartObject& module_data, + const std::string& module_id)); + + MOCK_CONST_METHOD2(ControlDataForType, + const smart_objects::SmartObject&( + const smart_objects::SmartObject& module_data, + const std::string& module_type)); + + MOCK_CONST_METHOD3( + AreReadOnlyParamsPresent, + bool(const smart_objects::SmartObject& module_data, + const std::string& module_type, + rc_rpc_plugin::ModuleTypeCapability& module_data_capabilities)); + + MOCK_CONST_METHOD2(AreAllParamsReadOnly, + bool(const smart_objects::SmartObject& module_data, + const std::string& module_type)); + + MOCK_CONST_METHOD1(GetDefaultModuleIdFromCapabilities, + const std::string(const std::string& module_type)); + + MOCK_CONST_METHOD1(CheckIfButtonExistInRCCaps, + bool(const mobile_apis::ButtonName::eType button)); + + MOCK_CONST_METHOD0(GetResources, + const std::vector<rc_rpc_plugin::ModuleUid>()); + + MOCK_CONST_METHOD1(GetModuleServiceArea, + rc_rpc_plugin::Grid(const rc_rpc_plugin::ModuleUid&)); + + MOCK_CONST_METHOD1(IsMultipleAccessAllowed, + bool(const rc_rpc_plugin::ModuleUid&)); + + MOCK_CONST_METHOD0(GetDriverLocationFromSeatLocationCapability, + const rc_rpc_plugin::Grid()); + + MOCK_CONST_METHOD0(IsSeatLocationCapabilityProvided, bool()); + + MOCK_CONST_METHOD1( + GetModuleIdForSeatLocation, + const std::string(const mobile_apis::SupportedSeat::eType id)); +}; +} // namespace rc_rpc_plugin_test +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_TEST_INCLUDE_RC_RPC_PLUGIN_MOCK_MOCK_RC_СAPABILITIES_MANAGER_H_ diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_rc_consent_manager.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_rc_consent_manager.h new file mode 100644 index 0000000000..a89202b5f5 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_rc_consent_manager.h @@ -0,0 +1,60 @@ +/* + * 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_INCLUDE_APPLICATION_MANAGER_PLUGIN_MANAGER_MOCK_RC_CONSENT_MANAGER_H +#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_PLUGIN_MANAGER_MOCK_RC_CONSENT_MANAGER_H + +#include <string> + +#include "gmock/gmock.h" +#include "rc_rpc_plugin/rc_consent_manager.h" + +namespace rc_rpc_plugin_test { + +class MockRCConsentManager : public rc_rpc_plugin::RCConsentManager { + public: + MOCK_METHOD3(SaveModuleConsents, + void(const std::string&, + const std::string&, + const rc_rpc_plugin::rc_rpc_types::ModuleIdConsentVector&)); + MOCK_METHOD3(GetModuleConsent, + rc_rpc_plugin::rc_rpc_types::ModuleConsent( + const std::string&, + const std::string&, + const rc_rpc_plugin::rc_rpc_types::ModuleUid&)); + MOCK_METHOD0(RemoveExpiredConsents, void()); + MOCK_METHOD0(RemoveAllConsents, void()); +}; + +} // namespace rc_rpc_plugin_test + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_PLUGIN_MANAGER_MOCK_RC_CONSENT_MANAGER_H diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_rc_helpers.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_rc_helpers.h new file mode 100644 index 0000000000..c73472d2a8 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_rc_helpers.h @@ -0,0 +1,97 @@ +/* + * 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_RC_RPC_PLUGINS_RC_RPC_PLUGIN_TEST_INCLUDE_RC_RPC_PLUGIN_MOCK_MOCK_RC_HELPERS_H +#define SRC_COMPONENTS_APPLICATION_MANAGER_RC_RPC_PLUGINS_RC_RPC_PLUGIN_TEST_INCLUDE_RC_RPC_PLUGIN_MOCK_MOCK_RC_HELPERS_H + +#include <functional> +#include <map> +#include <string> +#include "gmock/gmock.h" + +#include "application_manager/application.h" +#include "application_manager/application_manager.h" +#include "rc_rpc_plugin/rc_helpers.h" + +namespace rc_rpc_plugin { + +class MockRCHelpers { + public: + MOCK_METHOD0(GetModuleTypeToDataMapping, + std::function<std::string(const std::string&)>()); + MOCK_METHOD0(GetModuleTypeToCapabilitiesMapping, + std::function<std::string(const std::string&)>()); + MOCK_METHOD0(GetModuleTypesList, const std::vector<std::string>()); + MOCK_METHOD1( + GetRCExtension, + rc_rpc_plugin::RCAppExtensionPtr(application_manager::Application&)); + MOCK_METHOD2(CreateUnsubscribeRequestToHMI, + smart_objects::SmartObjectSPtr(const rc_rpc_plugin::ModuleUid&, + const uint32_t)); + MOCK_METHOD2(AppsSubscribedToModule, + std::vector<application_manager::ApplicationSharedPtr>( + application_manager::ApplicationManager&, + const rc_rpc_plugin::ModuleUid&)); + MOCK_METHOD2(AppsSubscribedToModuleType, + std::vector<application_manager::ApplicationSharedPtr>( + application_manager::ApplicationManager&, + const std::string&)); + MOCK_METHOD1(GetApplicationsAllowedModuleTypes, + rc_rpc_plugin::RCHelpers::AppsModuleTypes( + application_manager::ApplicationManager&)); + MOCK_METHOD0(buttons_climate, const std::vector<std::string>()); + MOCK_METHOD0(buttons_radio, const std::vector<std::string>()); + MOCK_METHOD0(buttons_map, const rc_rpc_plugin::RCHelpers::ButtonsMap()); + MOCK_METHOD1(GetModuleReadOnlyParams, + std::vector<std::string>(const std::string&)); + MOCK_METHOD3( + FillModuleConsents, + rc_rpc_types::ModuleIdConsentVector(const std::string&, + const std::vector<std::string>&, + const std::vector<bool>)); + MOCK_METHOD1(RetrieveModuleIds, + std::vector<std::string>(const smart_objects::SmartObject&)); + MOCK_METHOD1(RetrieveModuleConsents, + std::vector<bool>(const smart_objects::SmartObject& consents)); + MOCK_METHOD1(RemoveRedundantGPSDataFromIVDataMsg, + void(smart_objects::SmartObject& msg_params)); + MOCK_METHOD2( + MergeModuleData, + smart_objects::SmartObject(const smart_objects::SmartObject& data1, + const smart_objects::SmartObject& data2)); + + static MockRCHelpers* rc_helpers_mock(); +}; + +} // namespace rc_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RC_RPC_PLUGINS_RC_RPC_PLUGIN_TEST_INCLUDE_RC_RPC_PLUGIN_MOCK_MOCK_RC_HELPERS_H 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 828e2eea11..fca6c9c77e 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 @@ -41,13 +41,19 @@ namespace rc_rpc_plugin_test { class MockResourceAllocationManager : public rc_rpc_plugin::ResourceAllocationManager { public: - MOCK_METHOD2(AcquireResource, - rc_rpc_plugin::AcquireResult::eType( - const std::string& module_type, const uint32_t app_id)); - MOCK_METHOD2(ForceAcquireResource, - void(const std::string& module_type, const uint32_t app_id)); - MOCK_METHOD2(OnDriverDisallowed, - void(const std::string& module_type, const uint32_t app_id)); + MOCK_METHOD3( + AcquireResource, + rc_rpc_plugin::AcquireResult::eType(const std::string& module_type, + const std::string& module_id, + const uint32_t app_id)); + MOCK_METHOD3(ForceAcquireResource, + void(const std::string& module_type, + const std::string& module_id, + const uint32_t app_id)); + MOCK_METHOD3(OnDriverDisallowed, + void(const std::string& module_type, + const std::string& module_id, + const uint32_t app_id)); MOCK_METHOD2(OnApplicationEvent, void(application_manager::plugin_manager::ApplicationEvent event, application_manager::ApplicationSharedPtr application)); @@ -56,17 +62,32 @@ class MockResourceAllocationManager MOCK_METHOD1(SetAccessMode, void(const hmi_apis::Common_RCAccessMode::eType access_mode)); MOCK_CONST_METHOD0(GetAccessMode, hmi_apis::Common_RCAccessMode::eType()); - MOCK_METHOD3(SetResourceState, + MOCK_METHOD4(SetResourceState, void(const std::string& module_type, + const std::string& module_id, const uint32_t app_id, const rc_rpc_plugin::ResourceState::eType state)); - MOCK_CONST_METHOD1(IsResourceFree, bool(const std::string& module_type)); + MOCK_CONST_METHOD2(IsResourceFree, + bool(const std::string& module_type, + const std::string& module_id)); MOCK_METHOD0(ResetAllAllocations, void()); MOCK_METHOD2(SendOnRCStatusNotifications, void(rc_rpc_plugin::NotificationTrigger::eType, application_manager::ApplicationSharedPtr application)); MOCK_CONST_METHOD0(is_rc_enabled, bool()); MOCK_METHOD1(set_rc_enabled, void(const bool value)); + MOCK_METHOD3(ReleaseResource, + rc_rpc_plugin::ResourceReleasedState::eType( + const std::string& module_type, + const std::string& module_id, + const uint32_t application_id)); + MOCK_METHOD3(SetResourceAcquired, + void(const std::string& module_type, + const std::string& module_id, + const uint32_t app_id)); + MOCK_CONST_METHOD2(IsResourceAlreadyAcquiredByApp, + bool(const rc_rpc_plugin::ModuleUid& moduleUid, + const uint32_t app_id)); }; } // namespace rc_rpc_plugin_test diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/interior_data_cache_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/interior_data_cache_test.cc index b7eb4a554a..40a6bdf41d 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/interior_data_cache_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/interior_data_cache_test.cc @@ -29,6 +29,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +#include "application_manager/smart_object_keys.h" #include "gtest/gtest.h" #include "rc_rpc_plugin/interior_data_cache_impl.h" @@ -38,41 +39,49 @@ class InteriorDataCacheTest : public ::testing::Test {}; namespace { const uint32_t time_frame_alowed_requests = 1; +const std::string kValueKey = "value"; +const std::string kArray = "array"; } // namespace TEST_F(InteriorDataCacheTest, InteriorDataCacheDoesNotContainRandomDataInitialy) { rc_rpc_plugin::InteriorDataCacheImpl cache; std::string module_type_key = "random_module_type"; - EXPECT_FALSE(cache.Contains(module_type_key)); - auto retrieved_data = cache.Retrieve(module_type_key); + std::string module_id = "34045662-a9dc-4823-8435-91056d4c26cb"; + rc_rpc_plugin::ModuleUid module(module_type_key, module_id); + EXPECT_FALSE(cache.Contains(module)); + auto retrieved_data = cache.Retrieve(module); EXPECT_EQ(smart_objects::SmartType_Null, retrieved_data.getType()); } TEST_F(InteriorDataCacheTest, CheckThatCacheContansDataAfterAdding) { rc_rpc_plugin::InteriorDataCacheImpl cache; const std::string module_type_key = "random_module_type"; + std::string module_id = "34045662-a9dc-4823-8435-91056d4c26cb"; + rc_rpc_plugin::ModuleUid module(module_type_key, module_id); smart_objects::SmartObject data; data["key"] = "value"; - cache.Add(module_type_key, data); - EXPECT_TRUE(cache.Contains(module_type_key)); - auto retrieved_data = cache.Retrieve(module_type_key); + cache.Add(module, data); + EXPECT_TRUE(cache.Contains(module)); + auto retrieved_data = cache.Retrieve(module); EXPECT_EQ(data, retrieved_data); } TEST_F(InteriorDataCacheTest, DataDoesNotExistAfterClear) { rc_rpc_plugin::InteriorDataCacheImpl cache; const std::string module_type_key = "random_module_type"; + std::string module_id = "34045662-a9dc-4823-8435-91056d4c26cb"; + rc_rpc_plugin::ModuleUid module(module_type_key, module_id); smart_objects::SmartObject data; data["key"] = "value"; - cache.Add(module_type_key, data); - EXPECT_TRUE(cache.Contains(module_type_key)); - auto Retrieved_data = cache.Retrieve(module_type_key); + cache.Add(module, data); + EXPECT_TRUE(cache.Contains(module)); + auto Retrieved_data = cache.Retrieve(module); EXPECT_EQ(Retrieved_data, data); cache.Clear(); - auto Retrieved_data_after_clear = cache.Retrieve(module_type_key); + auto Retrieved_data_after_clear = cache.Retrieve(module); EXPECT_EQ(smart_objects::SmartType_Null, Retrieved_data_after_clear.getType()); } @@ -81,19 +90,23 @@ TEST_F(InteriorDataCacheTest, MultipleDataCached) { rc_rpc_plugin::InteriorDataCacheImpl cache; const std::string module_type_key1 = "random_module_type"; + std::string module_id1 = "34045662-a9dc-4823-8435-91056d4c26cb"; + rc_rpc_plugin::ModuleUid module1(module_type_key1, module_id1); smart_objects::SmartObject data1; data1["key"] = "value1"; - cache.Add(module_type_key1, data1); - EXPECT_TRUE(cache.Contains(module_type_key1)); - auto retrieved_data1 = cache.Retrieve(module_type_key1); + cache.Add(module1, data1); + EXPECT_TRUE(cache.Contains(module1)); + auto retrieved_data1 = cache.Retrieve(module1); EXPECT_EQ(data1, retrieved_data1); std::string module_type_key2 = "random_module_type2"; + std::string module_id2 = "eb7739ea-b263-4fe1-af9c-9311d1acac2d"; + rc_rpc_plugin::ModuleUid module2(module_type_key2, module_id2); smart_objects::SmartObject data2; data2["key"] = "value2"; - cache.Add(module_type_key2, data2); - EXPECT_TRUE(cache.Contains(module_type_key2)); - auto retrieved_data2 = cache.Retrieve(module_type_key2); + cache.Add(module2, data2); + EXPECT_TRUE(cache.Contains(module2)); + auto retrieved_data2 = cache.Retrieve(module2); EXPECT_EQ(retrieved_data2, data2); ASSERT_TRUE(data1 != data2); @@ -105,30 +118,36 @@ TEST_F(InteriorDataCacheTest, RemoveFromChacheSuccessful) { rc_rpc_plugin::InteriorDataCacheImpl cache; const std::string module_type = "random_module_type"; + std::string module_id = "34045662-a9dc-4823-8435-91056d4c26cb"; + rc_rpc_plugin::ModuleUid module(module_type, module_id); smart_objects::SmartObject data; data["key"] = "value1"; - cache.Add(module_type, data); - EXPECT_TRUE(cache.Contains(module_type)); - auto retrieved_data1 = cache.Retrieve(module_type); + cache.Add(module, data); + EXPECT_TRUE(cache.Contains(module)); + auto retrieved_data1 = cache.Retrieve(module); EXPECT_EQ(data, retrieved_data1); - cache.Remove(module_type); - EXPECT_FALSE(cache.Contains(module_type)); - auto retreived = cache.Retrieve(module_type); + cache.Remove(module); + EXPECT_FALSE(cache.Contains(module)); + auto retreived = cache.Retrieve(module); EXPECT_EQ(smart_objects::SmartType_Null, retreived.getType()); } TEST_F(InteriorDataCacheTest, RemoveNotExistingNoSideEffects) { rc_rpc_plugin::InteriorDataCacheImpl cache; const std::string module_type_key = "random_module_type"; + std::string module_id = "34045662-a9dc-4823-8435-91056d4c26cb"; + rc_rpc_plugin::ModuleUid module(module_type_key, module_id); smart_objects::SmartObject data; data["key"] = "value"; - cache.Add(module_type_key, data); - cache.Remove("some other module_type"); + cache.Add(module, data); + rc_rpc_plugin::ModuleUid other_module("some other module_type", + "some other module id"); + cache.Remove(other_module); - EXPECT_TRUE(cache.Contains(module_type_key)); - auto retrieved_data = cache.Retrieve(module_type_key); + EXPECT_TRUE(cache.Contains(module)); + auto retrieved_data = cache.Retrieve(module); EXPECT_EQ(data, retrieved_data); } @@ -136,25 +155,72 @@ TEST_F(InteriorDataCacheTest, Exist2ModuleTypesRemoveOneAnotherOneLeft) { rc_rpc_plugin::InteriorDataCacheImpl cache; const std::string module_type_key1 = "random_module_type"; + std::string module_id1 = "34045662-a9dc-4823-8435-91056d4c26cb"; + rc_rpc_plugin::ModuleUid module1(module_type_key1, module_id1); smart_objects::SmartObject data1; data1["key"] = "value1"; - cache.Add(module_type_key1, data1); + cache.Add(module1, data1); std::string module_type_key2 = "random_module_type2"; + std::string module_id2 = "eb7739ea-b263-4fe1-af9c-9311d1acac2d"; + rc_rpc_plugin::ModuleUid module2(module_type_key2, module_id2); smart_objects::SmartObject data2; data2["key"] = "value2"; - cache.Add(module_type_key2, data2); + cache.Add(module2, data2); ASSERT_TRUE(data1 != data2); - cache.Remove(module_type_key1); - EXPECT_FALSE(cache.Contains(module_type_key1)); - EXPECT_TRUE(cache.Contains(module_type_key2)); + cache.Remove(module1); + EXPECT_FALSE(cache.Contains(module1)); + EXPECT_TRUE(cache.Contains(module2)); - auto retrieved_data1 = cache.Retrieve(module_type_key1); + auto retrieved_data1 = cache.Retrieve(module1); EXPECT_EQ(smart_objects::SmartType_Null, retrieved_data1.getType()); - auto retrieved_data2 = cache.Retrieve(module_type_key2); + auto retrieved_data2 = cache.Retrieve(module2); EXPECT_EQ(data2, retrieved_data2); } +TEST_F(InteriorDataCacheTest, CheckCacheDataMerge) { + using namespace smart_objects; + const std::string module_type_key = "random_module_type"; + const std::string module_id = "random_module_id"; + rc_rpc_plugin::ModuleUid module(module_type_key, module_id); + + auto gen_smart_object = [](const std::string& id, + const std::string& value) -> SmartObject { + SmartObject result(SmartType_Map); + result[application_manager::strings::id] = id; + result[kValueKey] = value; + return result; + }; + + SmartObject data1; + SmartObject data1_array(SmartType_Array); + (*data1_array.asArray()) = SmartArray{gen_smart_object("id1", "value1"), + gen_smart_object("id2", "value2")}; + data1[kArray] = data1_array; + + SmartObject data2(SmartType_Map); + SmartObject data2_array(SmartType_Array); + (*data2_array.asArray()) = SmartArray{gen_smart_object("id1", "value3"), + gen_smart_object("id3", "value4")}; + data2[kArray] = data2_array; + + SmartObject expected_data(SmartType_Map); + SmartObject expected_array(SmartType_Array); + (*expected_array.asArray()) = SmartArray{gen_smart_object("id1", "value3"), + gen_smart_object("id2", "value2"), + gen_smart_object("id3", "value4")}; + expected_data[kArray] = expected_array; + + rc_rpc_plugin::InteriorDataCacheImpl cache; + cache.Add(module, data1); + cache.Add(module, data2); + + const auto retrieved_data = cache.Retrieve(module); + + EXPECT_TRUE(cache.Contains(module)); + EXPECT_EQ(expected_data, retrieved_data); +} + } // namespace rc_rpc_plugin_test diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/mock_rc_helpers.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/mock_rc_helpers.cc new file mode 100644 index 0000000000..3e60591c6b --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/mock_rc_helpers.cc @@ -0,0 +1,138 @@ +/* + * 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 "rc_rpc_plugin/mock/mock_rc_helpers.h" + +namespace rc_rpc_plugin { + +smart_objects::SmartObject RCHelpers::MergeModuleData( + const smart_objects::SmartObject& data1, + const smart_objects::SmartObject& data2) { + return MockRCHelpers::rc_helpers_mock()->MergeModuleData(data1, data2); +} + +const std::function<std::string(const std::string&)> +rc_rpc_plugin::RCHelpers::GetModuleTypeToDataMapping() { + return MockRCHelpers::rc_helpers_mock()->GetModuleTypeToDataMapping(); +} + +const std::function<std::string(const std::string&)> +rc_rpc_plugin::RCHelpers::GetModuleTypeToCapabilitiesMapping() { + return MockRCHelpers::rc_helpers_mock()->GetModuleTypeToCapabilitiesMapping(); +} + +const std::vector<std::string> rc_rpc_plugin::RCHelpers::GetModuleTypesList() { + return MockRCHelpers::rc_helpers_mock()->GetModuleTypesList(); +} + +rc_rpc_plugin::RCAppExtensionPtr rc_rpc_plugin::RCHelpers::GetRCExtension( + application_manager::Application& app) { + return MockRCHelpers::rc_helpers_mock()->GetRCExtension(app); +} + +smart_objects::SmartObjectSPtr +rc_rpc_plugin::RCHelpers::CreateUnsubscribeRequestToHMI( + const ModuleUid& module, const uint32_t correlation_id) { + return MockRCHelpers::rc_helpers_mock()->CreateUnsubscribeRequestToHMI( + module, correlation_id); +} + +std::vector<application_manager::ApplicationSharedPtr> +rc_rpc_plugin::RCHelpers::AppsSubscribedToModule( + application_manager::ApplicationManager& app_mngr, + const ModuleUid& module) { + return MockRCHelpers::rc_helpers_mock()->AppsSubscribedToModule(app_mngr, + module); +} + +std::vector<application_manager::ApplicationSharedPtr> +rc_rpc_plugin::RCHelpers::AppsSubscribedToModuleType( + application_manager::ApplicationManager& app_mngr, + const std::string& module_type) { + return MockRCHelpers::rc_helpers_mock()->AppsSubscribedToModuleType( + app_mngr, module_type); +} + +rc_rpc_plugin::RCHelpers::AppsModuleTypes +rc_rpc_plugin::RCHelpers::GetApplicationsAllowedModuleTypes( + application_manager::ApplicationManager& app_mngr) { + return MockRCHelpers::rc_helpers_mock()->GetApplicationsAllowedModuleTypes( + app_mngr); +} + +const std::vector<std::string> RCHelpers::buttons_climate() { + return MockRCHelpers::rc_helpers_mock()->buttons_climate(); +} + +const std::vector<std::string> RCHelpers::buttons_radio() { + return MockRCHelpers::rc_helpers_mock()->buttons_radio(); +} + +const rc_rpc_plugin::RCHelpers::ButtonsMap RCHelpers::buttons_map() { + return MockRCHelpers::rc_helpers_mock()->buttons_map(); +} + +std::vector<std::string> RCHelpers::GetModuleReadOnlyParams( + const std::string& module_type) { + return MockRCHelpers::rc_helpers_mock()->GetModuleReadOnlyParams(module_type); +} + +rc_rpc_types::ModuleIdConsentVector RCHelpers::FillModuleConsents( + const std::string& module_type, + const std::vector<std::string>& module_ids, + const std::vector<bool> allowed) { + return MockRCHelpers::rc_helpers_mock()->FillModuleConsents( + module_type, module_ids, allowed); +} + +std::vector<std::string> RCHelpers::RetrieveModuleIds( + const smart_objects::SmartObject& moduleIds) { + return MockRCHelpers::rc_helpers_mock()->RetrieveModuleIds(moduleIds); +} + +std::vector<bool> RCHelpers::RetrieveModuleConsents( + const smart_objects::SmartObject& consents) { + return MockRCHelpers::rc_helpers_mock()->RetrieveModuleConsents(consents); +} + +void RCHelpers::RemoveRedundantGPSDataFromIVDataMsg( + smart_objects::SmartObject& msg_params) { + return MockRCHelpers::rc_helpers_mock()->RemoveRedundantGPSDataFromIVDataMsg( + msg_params); +} + +MockRCHelpers* MockRCHelpers::rc_helpers_mock() { + static ::testing::NiceMock<MockRCHelpers> mock_rc_helpers; + return &mock_rc_helpers; +} + +} // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/rc_consent_manager_impl_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/rc_consent_manager_impl_test.cc new file mode 100644 index 0000000000..a2e9f6d83b --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/rc_consent_manager_impl_test.cc @@ -0,0 +1,346 @@ +/* + * 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 <ctime> +#include <memory> +#include <string> +#include <vector> + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include "application_manager/mock_application_manager_settings.h" +#include "rc_rpc_plugin/rc_consent_manager_impl.h" +#include "resumption/last_state_impl.h" +#include "resumption/last_state_wrapper_impl.h" +#include "utils/date_time.h" +#include "utils/file_system.h" + +#include "application_manager/mock_application_manager.h" + +using test::components::application_manager_test::MockApplicationManager; +using test::components::application_manager_test:: + MockApplicationManagerSettings; + +using ::testing::NiceMock; +using ::testing::Return; +using ::testing::ReturnRef; + +namespace { +const std::string kPolicyApp1Id = "app1_id"; +const std::string kPolicyApp2Id = "app2_id"; +const std::string kMacAddress1 = "device1"; +const std::string kMacAddress2 = "device2"; +const std::string kClimateModule = "CLIMATE"; +const std::string kRadioModule = "RADIO"; +const std::string kAppTestStorageFolder = "app_test_storage_folder"; +const std::string kAppTestInfoStorage = "app_test_info_storage"; +const uint32_t kPeriodOfConsentExpired = 30; // in days +} // namespace + +namespace rc_rpc_plugin_test { +namespace rc_consent_manager_test { +using namespace rc_rpc_plugin::rc_rpc_types; +using namespace rc_rpc_plugin; + +class RCConsentManagerImplTest : public ::testing::Test { + public: + RCConsentManagerImplTest() + : current_date_(0u) + , last_state_(std::make_shared<resumption::LastStateWrapperImpl>( + std::make_shared<resumption::LastStateImpl>(kAppTestStorageFolder, + kAppTestInfoStorage))) + , rc_consent_manager_(new rc_rpc_plugin::RCConsentManagerImpl( + last_state_, mock_app_mngr_, kPeriodOfConsentExpired)) {} + + void SetUp() OVERRIDE { + current_date_ = std::time(0); + RemoveTemproraryTetsFiles(); + + ON_CALL(mock_app_mngr_, get_settings()) + .WillByDefault(ReturnRef(mock_app_mnrg_settings_)); + ON_CALL(mock_app_mnrg_settings_, period_for_consent_expiration()) + .WillByDefault(Return(kPeriodOfConsentExpired)); + } + + void RemoveTemproraryTetsFiles() { + // Remove exists storage file + if (file_system::FileExists(kAppTestInfoStorage)) { + file_system::DeleteFile(kAppTestInfoStorage); + } + + // Remove exists storage folder + if (file_system::DirectoryExists(kAppTestStorageFolder)) { + file_system::RemoveDirectory(kAppTestStorageFolder); + } + + auto last_state_accessor = last_state_->get_accessor(); + last_state_accessor.GetMutableData().set_dictionary(Json::Value()); + } + + void SaveStateToFileSystem() { + auto last_state_accessor = last_state_->get_accessor(); + last_state_accessor.GetMutableData().SaveToFileSystem(); + } + + protected: + time_t current_date_; + NiceMock<MockApplicationManagerSettings> mock_app_mnrg_settings_; + NiceMock<MockApplicationManager> mock_app_mngr_; + resumption::LastStateWrapperPtr last_state_; + std::unique_ptr<rc_rpc_plugin::RCConsentManagerImpl> rc_consent_manager_; +}; + +TEST_F(RCConsentManagerImplTest, SaveAndGetModuleConsents_SUCCESS) { + const std::string radio_moduleId = "eb7739ea-b263-4fe1-af9c-9311d1acac2d"; + const std::string climate_moduleId = "34045662-a9dc-4823-8435-91056d4c26cb"; + + ModuleIdConsent radio_module_consent{ + {kRadioModule, radio_moduleId}, ModuleConsent::CONSENTED, current_date_}; + + ModuleIdConsent climate_module_consent{{kClimateModule, climate_moduleId}, + ModuleConsent::NOT_CONSENTED, + current_date_}; + + ModuleIdConsentVector module_consents{radio_module_consent, + climate_module_consent}; + + rc_consent_manager_->SaveModuleConsents( + kPolicyApp1Id, kMacAddress1, module_consents); + SaveStateToFileSystem(); + + auto radio_consent = rc_consent_manager_->GetModuleConsent( + kPolicyApp1Id, kMacAddress1, {kRadioModule, radio_moduleId}); + auto climate_consent = rc_consent_manager_->GetModuleConsent( + kPolicyApp1Id, kMacAddress1, {kClimateModule, climate_moduleId}); + + EXPECT_EQ(ModuleConsent::CONSENTED, radio_consent); + EXPECT_EQ(ModuleConsent::NOT_CONSENTED, climate_consent); +} + +TEST_F(RCConsentManagerImplTest, ModuleId_NOT_EXISTS) { + const std::string radio_moduleId = "eb7739ea-b263-4fe1-af9c-9311d1acac2d"; + const std::string climate_moduleId = "34045662-a9dc-4823-8435-91056d4c26cb"; + + ModuleIdConsent radio_module_consent{ + {kRadioModule, radio_moduleId}, ModuleConsent::CONSENTED, current_date_}; + ModuleIdConsent climate_module_consent{{kClimateModule, climate_moduleId}, + ModuleConsent::CONSENTED, + current_date_}; + + const std::string uknown_moduleId = "639f1b7f-1d25-4dca-a2ce-00530860adea"; + const std::string uknown_moduleType = "UNKNOWN_TYPE"; + + ModuleUid unknown_module{uknown_moduleId, uknown_moduleType}; + + ModuleIdConsentVector module_consents{radio_module_consent, + climate_module_consent}; + + rc_consent_manager_->SaveModuleConsents( + kPolicyApp1Id, kMacAddress1, module_consents); + SaveStateToFileSystem(); + + ModuleConsent consent = rc_consent_manager_->GetModuleConsent( + kPolicyApp1Id, kMacAddress1, unknown_module); + + EXPECT_EQ(ModuleConsent::NOT_EXISTS, consent); +} + +TEST_F(RCConsentManagerImplTest, ConsentIsExpired) { + time_t expired_date_45_days = + current_date_ - (date_time::SECONDS_IN_DAY * 45); + time_t expired_date_30_days = + current_date_ - (date_time::SECONDS_IN_DAY * 30); + time_t not_expired_date_29_days = + current_date_ - (date_time::SECONDS_IN_DAY * 29); + + const std::string moduleId1 = "dbef7693-adf9-42f1-95c7-5dff314d9985"; + const std::string moduleId2 = "1536b2ac-213f-463f-8589-a11453cd3729"; + const std::string moduleId3 = "e8b8169a-9f29-4499-a60b-2d126a1beffc"; + + ModuleUid module_resource1{kRadioModule, moduleId1}; + ModuleUid module_resource2{kRadioModule, moduleId2}; + ModuleUid module_resource3{kRadioModule, moduleId3}; + + ModuleIdConsent module_consent_expired1{ + module_resource1, ModuleConsent::CONSENTED, expired_date_45_days}; + ModuleIdConsent module_consent_expired2{ + module_resource2, ModuleConsent::CONSENTED, expired_date_30_days}; + + ModuleIdConsent module_consent_not_expired{ + module_resource3, ModuleConsent::CONSENTED, not_expired_date_29_days}; + + ModuleIdConsentVector module_consents{module_consent_expired1, + module_consent_expired2, + module_consent_not_expired}; + rc_consent_manager_->SaveModuleConsents( + kPolicyApp1Id, kMacAddress1, module_consents); + SaveStateToFileSystem(); + + // All consents, which consent has been saved more than 30 days, will be + // removed. + rc_consent_manager_->RemoveExpiredConsents(); + + ModuleConsent expired_consent_45_days = rc_consent_manager_->GetModuleConsent( + kPolicyApp1Id, kMacAddress1, module_resource1); + EXPECT_EQ(ModuleConsent::NOT_EXISTS, expired_consent_45_days); + + ModuleConsent expired_consent_30_days = rc_consent_manager_->GetModuleConsent( + kPolicyApp1Id, kMacAddress1, module_resource2); + EXPECT_EQ(ModuleConsent::NOT_EXISTS, expired_consent_30_days); + + ModuleConsent not_expired_consent = rc_consent_manager_->GetModuleConsent( + kPolicyApp1Id, kMacAddress1, module_resource3); + EXPECT_EQ(ModuleConsent::CONSENTED, not_expired_consent); +} + +TEST_F(RCConsentManagerImplTest, + SaveModuleConsents_SameAppID_DifferentDeviceID_NotReplaced) { + const std::string moduleId = "cef4eae6-e22c-4943-bdc3-60e792414c4c"; + ModuleUid module_resource{kRadioModule, moduleId}; + + ModuleIdConsent radio_module_consent_app1_deviceId1{ + module_resource, ModuleConsent::CONSENTED, current_date_}; + + ModuleIdConsent radio_module_consent_app1_deviceId2{ + module_resource, ModuleConsent::NOT_CONSENTED, current_date_}; + + ModuleIdConsentVector module_consents_app1{ + radio_module_consent_app1_deviceId1}; + ModuleIdConsentVector module_consents_app2{ + radio_module_consent_app1_deviceId2}; + + rc_consent_manager_->SaveModuleConsents( + kPolicyApp1Id, kMacAddress1, module_consents_app1); + + rc_consent_manager_->SaveModuleConsents( + kPolicyApp1Id, kMacAddress2, module_consents_app2); + + SaveStateToFileSystem(); + + // Module consents for same app ids and different device_id (mac_adress) will + // haven't been replaced each other + + ModuleConsent module_consent_deviceID1 = + rc_consent_manager_->GetModuleConsent( + kPolicyApp1Id, kMacAddress1, module_resource); + + ModuleConsent module_consent_deviceID2 = + rc_consent_manager_->GetModuleConsent( + kPolicyApp1Id, kMacAddress2, module_resource); + + EXPECT_EQ(ModuleConsent::CONSENTED, module_consent_deviceID1); + + // // Module consent for app_id2 has different value as has been saved above + EXPECT_EQ(ModuleConsent::NOT_CONSENTED, module_consent_deviceID2); +} + +TEST_F(RCConsentManagerImplTest, + SaveModuleConsents_SameAppID_SameDeviceID_Replaced) { + const std::string moduleId = "194aee9e-26cb-4f48-a775-8841a658002d"; + + ModuleUid radio_module_resource_consented{kRadioModule, moduleId}; + ModuleUid radio_module_resource_not_consented{kRadioModule, moduleId}; + + ModuleIdConsent radio_module_consent_app1_deviceId1{ + radio_module_resource_consented, ModuleConsent::CONSENTED, current_date_}; + + ModuleIdConsent radio_module_consent_app1_deviceId2{ + radio_module_resource_not_consented, + ModuleConsent::NOT_CONSENTED, + current_date_}; + + ModuleIdConsentVector module_consents_app1{ + radio_module_consent_app1_deviceId1}; + ModuleIdConsentVector module_consents_app2{ + radio_module_consent_app1_deviceId2}; + + rc_consent_manager_->SaveModuleConsents( + kPolicyApp1Id, kMacAddress1, module_consents_app1); + + SaveStateToFileSystem(); + + rc_consent_manager_->SaveModuleConsents( + kPolicyApp1Id, kMacAddress1, module_consents_app2); + + SaveStateToFileSystem(); + + // Module consents for same app ids and same device_id (mac_adress) will + // have been replaced each other + + ModuleConsent module_consent = rc_consent_manager_->GetModuleConsent( + kPolicyApp1Id, kMacAddress1, radio_module_resource_not_consented); + + EXPECT_EQ(ModuleConsent::NOT_CONSENTED, module_consent); +} + +TEST_F(RCConsentManagerImplTest, RemoveAllModuleConsents_SUCCESS) { + const std::string moduleId = "1c5408f2-9766-464c-a7bf-d834b62f43fa"; + + ModuleUid module_resource{kRadioModule, moduleId}; + + ModuleIdConsent radio_module_consent_app1_deviceId1{ + module_resource, ModuleConsent::CONSENTED, current_date_}; + + ModuleIdConsent radio_module_consent_app1_deviceId2{ + module_resource, ModuleConsent::NOT_CONSENTED, current_date_}; + + ModuleIdConsentVector module_consents_app1{ + radio_module_consent_app1_deviceId1}; + ModuleIdConsentVector module_consents_app2{ + radio_module_consent_app1_deviceId2}; + + rc_consent_manager_->SaveModuleConsents( + kPolicyApp1Id, kMacAddress1, module_consents_app1); + + rc_consent_manager_->SaveModuleConsents( + kPolicyApp1Id, kMacAddress2, module_consents_app2); + + SaveStateToFileSystem(); + + rc_consent_manager_->RemoveAllConsents(); + + ModuleConsent module_consent_deviceID1 = + rc_consent_manager_->GetModuleConsent( + kPolicyApp1Id, kMacAddress1, module_resource); + + ModuleConsent module_consent_deviceID2 = + rc_consent_manager_->GetModuleConsent( + kPolicyApp1Id, kMacAddress2, module_resource); + + EXPECT_EQ(ModuleConsent::NOT_EXISTS, module_consent_deviceID1); + + EXPECT_EQ(ModuleConsent::NOT_EXISTS, module_consent_deviceID2); +} + +} // namespace rc_consent_manager_test +} // namespace rc_rpc_plugin_test diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/rc_helpers_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/rc_helpers_test.cc new file mode 100644 index 0000000000..21876c4c19 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/rc_helpers_test.cc @@ -0,0 +1,285 @@ +/* + * 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 "rc_rpc_plugin/rc_helpers.h" +#include <map> +#include <memory> +#include <string> +#include <type_traits> +#include <vector> +#include "gtest/gtest.h" +#include "rc_rpc_plugin/rc_module_constants.h" + +namespace { +const std::string kKeyId = "id"; +const std::string kKeyStatus = "status"; +const std::string kKeyDensity = "density"; +const std::string kKeyValue = "value"; +const std::string kArray = "array"; +} // namespace + +namespace rc_rpc_plugin_test { + +using namespace rc_rpc_plugin; +using namespace smart_objects; + +class RCHelpersTest : public ::testing::Test { + public: + /** + * @brief Generates smart object with next structure: + * { + * "status": "status<n>", + * "value": "value<n>", + * "id": "id<n>" + * } + * where <n> is number specified with 'object_number' param. + * + * @param int object_number - number of object + * @param bool use_id_key - defines, whether "id" key must be added to smart + * object + * + * @return smart_objects::SmartObject - generated smart object + */ + smart_objects::SmartObject gen_smart_object(int object_number, + bool use_id_key) { + smart_objects::SmartObject result(smart_objects::SmartType_Map); + result[kKeyStatus] = kKeyStatus + std::to_string(object_number); + result[kKeyValue] = kKeyValue + std::to_string(object_number); + if (use_id_key) { + result[kKeyId] = kKeyId + std::to_string(object_number); + } + return result; + } +}; + +TEST_F(RCHelpersTest, + MergeModuleData_OneOfParamsNotSmartMap_ExpectDataReplacedWithNewOne) { + SmartObject data1(SmartType_Map); + SmartObject data2(SmartType_Array); + + const auto result = RCHelpers::MergeModuleData(data1, data2); + EXPECT_NE(result, data1); + EXPECT_EQ(result, data2); +} + +TEST_F(RCHelpersTest, + MergeModuleData_FirstObjectDontContainKey_ExpectDataAppendedWithNewOne) { + SmartObject data1(SmartType_Map); + SmartObject data2(SmartType_Map); + + std::map<std::string, std::string> expected_keys_values = { + {"key1", "value1"}, {"key2", "value2"}}; + auto it = expected_keys_values.begin(); + + data1[it->first] = it->second; + ++it; + data2[it->first] = it->second; + + const auto result = RCHelpers::MergeModuleData(data1, data2); + for (auto& item : expected_keys_values) { + EXPECT_TRUE(result.keyExists(item.first)); + EXPECT_EQ(result[item.first], expected_keys_values[item.first]); + } +} + +TEST_F( + RCHelpersTest, + MergeModuleData_SecondObjectContainsDifferentValueType_ExpectDataReplacedWithNewOne) { + SmartObject data1(SmartType_Map); + SmartObject data2(SmartType_Map); + + data1["key1"] = "value1"; + data2["key1"] = 30; + + const auto result = RCHelpers::MergeModuleData(data1, data2); + EXPECT_EQ(data2["key1"], result["key1"]); +} + +TEST_F(RCHelpersTest, MergeModuleData_Recursive) { + SmartObject data1(SmartType_Map); + SmartObject data2(SmartType_Map); + + data1["key1"]["subkey1"] = "subvalue1"; + data2["key1"]["subkey2"] = 30; + + const auto result = RCHelpers::MergeModuleData(data1, data2); + EXPECT_EQ(result["key1"]["subkey1"], data1["key1"]["subkey1"]); + EXPECT_EQ(result["key1"]["subkey2"], data2["key1"]["subkey2"]); +} + +TEST_F( + RCHelpersTest, + MergeModuleData_MergeObjectsThatContainArrays_ExpectDataReplacedWithNewOne) { + SmartObject data1(SmartType_Map); + SmartObject data1_array(SmartType_Array); + (*data1_array.asArray()) = + SmartArray{gen_smart_object(1, true), gen_smart_object(2, false)}; + data1[kArray] = data1_array; + + SmartObject data2(SmartType_Map); + SmartObject data2_array(SmartType_Array); + (*data2_array.asArray()) = + SmartArray{gen_smart_object(3, true), gen_smart_object(4, false)}; + data2[kArray] = data2_array; + + SmartObject expected_result(SmartType_Map); + SmartObject expected_result_array(SmartType_Array); + (*expected_result_array.asArray()) = + SmartArray{data2[kArray].getElement(0), data2[kArray].getElement(1)}; + + expected_result[kArray] = expected_result_array; + + const auto result = RCHelpers::MergeModuleData(data1, data2); + EXPECT_EQ(expected_result, result); +} + +TEST_F(RCHelpersTest, + MergeArray_OneOfParamsNotSmartArray_ExpectDataReplacedWithSecond) { + SmartObject data1(SmartType_Array); + SmartObject data2(SmartType_Map); + + const auto result = RCHelpers::MergeArray(data1, data2); + EXPECT_NE(result, data1); + EXPECT_EQ(result, data2); +} + +TEST_F(RCHelpersTest, MergeArray_FirstArrayEmpty_ExpectDataReplacedWithSecond) { + SmartObject data1(SmartType_Array); + SmartObject data2(SmartType_Array); + for (int object : {0, 1}) { + data2.asArray()->emplace(data2.asArray()->begin(), SmartObject(object)); + } + + ASSERT_EQ(0u, data1.length()); + ASSERT_EQ(2u, data2.length()); + + const auto result = RCHelpers::MergeArray(data1, data2); + EXPECT_NE(result, data1); + EXPECT_EQ(result, data2); +} + +TEST_F(RCHelpersTest, + MergeArray_SecondArrayEmpty_ExpectDataReplacedWithSecond) { + SmartObject data1(SmartType_Array); + for (int object : {0, 1}) { + data1.asArray()->emplace(data1.asArray()->begin(), SmartObject(object)); + } + SmartObject data2(SmartType_Array); + + ASSERT_EQ(2u, data1.length()); + ASSERT_EQ(0u, data2.length()); + + const auto result = RCHelpers::MergeArray(data1, data2); + EXPECT_NE(result, data1); + EXPECT_EQ(result, data2); +} + +TEST_F(RCHelpersTest, MergeArray_SimpleArrays_ExpectDataReplacedWithSecond) { + SmartObject data1(SmartType_Array); + for (int object : {0, 1, 2, 3, 4, 5}) { + data1.asArray()->emplace(data1.asArray()->begin(), SmartObject(object)); + } + + SmartObject data2(SmartType_Array); + for (int object : {0, 1}) { + data2.asArray()->emplace(data2.asArray()->begin(), SmartObject(object)); + } + + ASSERT_EQ(6u, data1.length()); + ASSERT_EQ(2u, data2.length()); + + const auto result = RCHelpers::MergeArray(data1, data2); + EXPECT_NE(result, data1); + EXPECT_EQ(result, data2); +} + +TEST_F(RCHelpersTest, + MergeArray_ObjectsHaveNotEqualIds_ExpectDataAppendedWithNewOne) { + SmartObject data1 = gen_smart_object(1, true); + SmartObject data2 = gen_smart_object(2, true); + + SmartObject array1(SmartType_Array); + array1.asArray()->push_back(data1); + SmartObject array2(SmartType_Array); + array2.asArray()->push_back(data2); + + SmartObject expected_array(SmartType_Array); + expected_array.asArray()->push_back(data1); + expected_array.asArray()->push_back(data2); + ASSERT_EQ(2u, expected_array.length()); + + const auto result = RCHelpers::MergeArray(array1, array2); + EXPECT_EQ(expected_array, result); +} + +TEST_F(RCHelpersTest, + MergeArray_SomeObjectsDontHaveIdKey_ExpectDataReplacedWithSecond) { + int object_number = 1; + + SmartObject array1(SmartType_Array); + array1.asArray()->push_back(gen_smart_object(object_number++, true)); + + SmartObject array2(SmartType_Array); + array2.asArray()->push_back(gen_smart_object(object_number++, false)); + array2.asArray()->push_back(gen_smart_object(object_number++, true)); + + const auto result = RCHelpers::MergeArray(array1, array2); + EXPECT_EQ(array2, result); +} + +TEST_F( + RCHelpersTest, + MergeArray_SomeObjectsHaveEqualIds_ExpectDataWithSameIdUpdateValueOnlyNewDataAdded) { + SmartObject temp = gen_smart_object(1, true); + + SmartObject data1(SmartType_Array); + auto& data1_array = *data1.asArray(); + + data1_array.push_back(temp); + data1_array.push_back(gen_smart_object(2, true)); + + SmartObject data2(SmartType_Array); + auto& data2_array = *data2.asArray(); + + temp[kKeyValue] = "CUSTOM VALUE"; + data2_array.push_back(temp); + data2_array.push_back(gen_smart_object(3, true)); + + SmartObject expected_result(SmartType_Array); + expected_result.asArray()->push_back(temp); + expected_result.asArray()->push_back(data1_array[1]); + expected_result.asArray()->push_back(data2_array[1]); + + const auto result = RCHelpers::MergeArray(data1, data2); + EXPECT_EQ(expected_result, result); +} + +} // namespace rc_rpc_plugin_test diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager/CMakeLists.txt b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager/CMakeLists.txt new file mode 100644 index 0000000000..4b10d34643 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager/CMakeLists.txt @@ -0,0 +1,83 @@ +# 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 copyright holders nor the names of their 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(${CMAKE_SOURCE_DIR}/tools/cmake/helpers/sources.cmake) + +include_directories ( + ${GMOCK_INCLUDE_DIRECTORY} + ${COMPONENTS_DIR}/application_manager/test/include + ${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/include + ${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/test/include/ + ${COMPONENTS_DIR}/include/test/application_manager/ + ${COMPONENTS_DIR}/rc_rpc_plugin/test/include +) + +set (RESOURCE_ALLOC_MANAGER_TEST_SOURCES +${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/src/interior_data_manager_impl.cc +${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/src/interior_data_cache_impl.cc +${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc +${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc +${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_app_extension.cc +${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_consent_manager_impl.cc +${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_capabilities_manager_impl.cc +${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_command_factory.cc +${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/test/mock_rc_helpers.cc +${CMAKE_CURRENT_SOURCE_DIR}/resource_allocation_manager_impl_test.cc +) + +set(RC_COMMANDS_TEST_SOURCE_DIR ${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/test/commands) +set(RC_COMMANDS_SOURCE_DIR ${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/src/commands) +collect_sources(COMMANDS_SOURCES "${RC_COMMANDS_SOURCE_DIR}" "${RC_COMMANDS_TEST_SOURCE_DIR}") + +set(LIBRARIES + ApplicationManager + connectionHandler + SmartObjects + ProtocolHandler + MessageHelper + connectionHandler + Utils + Resumption + jsoncpp + gmock_main + dl +) + +if(ENABLE_LOG) + list(APPEND LIBRARIES log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) + list(APPEND LIBRARIES apr-1 -L${APR_LIBS_DIRECTORY}) + list(APPEND LIBRARIES aprutil-1 -L${APR_UTIL_LIBS_DIRECTORY}) + list(APPEND LIBRARIES expat -L${EXPAT_LIBS_DIRECTORY}) +endif() + +list(APPEND COMMANDS_SOURCES ${RESOURCE_ALLOC_MANAGER_TEST_SOURCES}) + +create_test("resource_allocation_manager_test" "${COMMANDS_SOURCES}" "${LIBRARIES}") + diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager_impl_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager/resource_allocation_manager_impl_test.cc index a72b89b9de..70ed832cb1 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager_impl_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager/resource_allocation_manager_impl_test.cc @@ -30,14 +30,18 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include <algorithm> +#include <memory> #include "gtest/gtest.h" #include "application_manager/mock_application.h" #include "application_manager/mock_application_manager.h" +#include "application_manager/mock_hmi_capabilities.h" #include "application_manager/mock_rpc_service.h" #include "application_manager/policies/mock_policy_handler_interface.h" #include "interfaces/HMI_API.h" #include "interfaces/MOBILE_API.h" +#include "rc_rpc_plugin/mock/mock_rc_capabilities_manager.h" +#include "rc_rpc_plugin/mock/mock_rc_helpers.h" #include "rc_rpc_plugin/rc_module_constants.h" #include "rc_rpc_plugin/rc_rpc_plugin.h" #include "rc_rpc_plugin/resource_allocation_manager_impl.h" @@ -50,6 +54,7 @@ using ::application_manager::ApplicationSharedPtr; using ::application_manager::Message; using ::application_manager::MessageType; using ::protocol_handler::MessagePriority; +using ::rc_rpc_plugin::MockRCHelpers; using ::testing::_; using ::testing::DoAll; using ::testing::Eq; @@ -65,6 +70,7 @@ namespace { const bool kDeviceHandle = 1u; const std::string kModuleType1 = "CLIMATE"; const std::string kModuleType2 = "RADIO"; +const std::string kModuleId = "id1"; const int32_t kConnectionKey = 5; const int32_t kCorrelationId = 5; const uint32_t kAppId1 = 11u; @@ -72,12 +78,27 @@ const uint32_t kHMIAppId1 = 1u; const uint32_t kAppId2 = 22u; const std::string policy_app_id_1_ = "policy_id_1"; const uint32_t kSizeOfModules = 6u; +const application_manager::WindowID kDefaultWindowId = + mobile_apis::PredefinedWindows::DEFAULT_WINDOW; +const rc_rpc_plugin::Grid KDefaultUserLocation = {2, 0, 0, 1, 1, 1}; +const rc_rpc_plugin::Grid kDriverLocation = {0, 0, 0, 1, 1, 1}; +const rc_rpc_plugin::Grid kInvalidLocation = {0, 0, 0, 0, 0, 0}; +const std::vector<std::string> kModuleList = { + rc_rpc_plugin::enums_value::kClimate, + rc_rpc_plugin::enums_value::kRadio, + rc_rpc_plugin::enums_value::kSeat, + rc_rpc_plugin::enums_value::kAudio, + rc_rpc_plugin::enums_value::kLight, + rc_rpc_plugin::enums_value::kHmiSettings}; + } // namespace namespace rc_rpc_plugin_test { using namespace rc_rpc_plugin; +typedef std::shared_ptr<MockRCHelpers> MockRCHelpersPtr; + class RAManagerTest : public ::testing::Test { public: RAManagerTest() @@ -86,22 +107,58 @@ class RAManagerTest : public ::testing::Test { , mock_app_1_(std::make_shared<NiceMock<MockApplication> >()) , mock_app_2_(std::make_shared<NiceMock<MockApplication> >()) , apps_lock_ptr_(std::make_shared<sync_primitives::Lock>()) - , apps_da_(apps_, apps_lock_ptr_) { + , apps_da_(apps_, apps_lock_ptr_) + , module_service_area_(0, 0, 0, 3, 2, 1) + , mock_rc_helpers_(MockRCHelpers::rc_helpers_mock()) { ON_CALL(mock_app_mngr_, GetPolicyHandler()) .WillByDefault(ReturnRef(mock_policy_handler_)); auto plugin_id = rc_rpc_plugin::RCRPCPlugin::kRCPluginID; app_ext_ptr_ = std::make_shared<rc_rpc_plugin::RCAppExtension>(plugin_id); ON_CALL(*mock_app_1_, app_id()).WillByDefault(Return(kAppId1)); + PrepareResources(); + ON_CALL(mock_rc_capabilities_manager_, GetResources()) + .WillByDefault(Return(resources_)); + ON_CALL(mock_rc_capabilities_manager_, IsSeatLocationCapabilityProvided()) + .WillByDefault(Return(false)); + ON_CALL(mock_rc_capabilities_manager_, IsMultipleAccessAllowed(_)) + .WillByDefault(Return(true)); + ON_CALL(mock_rc_capabilities_manager_, GetModuleServiceArea(_)) + .WillByDefault(Return(module_service_area_)); + + ON_CALL(mock_app_mngr_, application(kAppId1)) + .WillByDefault(Return(mock_app_1_)); + ON_CALL(*mock_app_1_, + QueryInterface(rc_rpc_plugin::RCRPCPlugin::kRCPluginID)) + .WillByDefault(Return(app_ext_ptr_)); + + ON_CALL(mock_app_mngr_, application(kAppId2)) + .WillByDefault(Return(mock_app_2_)); + ON_CALL(*mock_app_2_, + QueryInterface(rc_rpc_plugin::RCRPCPlugin::kRCPluginID)) + .WillByDefault(Return(app_ext_ptr_)); + OnRCStatusNotificationExpectations(); } + void SetUp() OVERRIDE { + rc_app_extension_ = std::make_shared<rc_rpc_plugin::RCAppExtension>( + static_cast<application_manager::AppExtensionUID>( + rc_rpc_plugin::RCRPCPlugin::kRCPluginID)); + ON_CALL(mock_rc_capabilities_manager_, + GetDriverLocationFromSeatLocationCapability()) + .WillByDefault(Return(kDriverLocation)); + ON_CALL(*mock_rc_helpers_, GetRCExtension(_)) + .WillByDefault(Return(rc_app_extension_)); + } + void CheckResultWithHMILevelAndAccessMode( ResourceAllocationManagerImpl& ra_manager, mobile_apis::HMILevel::eType app_level, const rc_rpc_plugin::AcquireResult::eType expected_result, const hmi_apis::Common_RCAccessMode::eType access_mode); + void PrepareResources(); void OnRCStatusNotificationExpectations(); protected: @@ -117,6 +174,12 @@ class RAManagerTest : public ::testing::Test { application_manager::ApplicationSet apps_; std::shared_ptr<sync_primitives::Lock> apps_lock_ptr_; DataAccessor<application_manager::ApplicationSet> apps_da_; + testing::NiceMock<rc_rpc_plugin_test::MockRCCapabilitiesManager> + mock_rc_capabilities_manager_; + std::vector<ModuleUid> resources_; + Grid module_service_area_; + RCAppExtensionPtr rc_app_extension_; + MockRCHelpers* mock_rc_helpers_; }; void RAManagerTest::CheckResultWithHMILevelAndAccessMode( @@ -131,19 +194,27 @@ void RAManagerTest::CheckResultWithHMILevelAndAccessMode( ra_manager.SetAccessMode(access_mode); EXPECT_EQ(rc_rpc_plugin::AcquireResult::ALLOWED, - ra_manager.AcquireResource(kModuleType1, kAppId1)); + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId1)); + + ra_manager.SetResourceAcquired(kModuleType1, kModuleId, kAppId1); + EXPECT_CALL(mock_app_mngr_, application(kAppId2)) .WillOnce(Return(mock_app_2_)); - EXPECT_CALL(*mock_app_2_, hmi_level()).WillOnce(Return(app_level)); + EXPECT_CALL(*mock_app_2_, hmi_level(kDefaultWindowId)) + .WillOnce(Return(app_level)); // Second app tries to get already acquired resource by 1st app - EXPECT_EQ(expected_result, ra_manager.AcquireResource(kModuleType1, kAppId2)); + EXPECT_EQ(expected_result, + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId2)); +} + +void RAManagerTest::PrepareResources() { + for (auto& module_type : kModuleList) { + ModuleUid module(module_type, kModuleId); + resources_.push_back(module); + } } void RAManagerTest::OnRCStatusNotificationExpectations() { - ON_CALL(mock_app_mngr_, application(kAppId1)) - .WillByDefault(Return(mock_app_1_)); - ON_CALL(*mock_app_1_, QueryInterface(rc_rpc_plugin::RCRPCPlugin::kRCPluginID)) - .WillByDefault(Return(app_ext_ptr_)); apps_.insert(mock_app_1_); ON_CALL(mock_app_mngr_, applications()).WillByDefault(Return(apps_da_)); } @@ -152,19 +223,21 @@ TEST_F(RAManagerTest, AcquireResource_NoAppRegistered_Expect_InUse) { // Arrange EXPECT_CALL(mock_app_mngr_, application(kAppId1)) .WillOnce(Return(ApplicationSharedPtr())); - ResourceAllocationManagerImpl ra_manager(mock_app_mngr_, mock_rpc_service_); + ResourceAllocationManagerImpl ra_manager( + mock_app_mngr_, mock_rpc_service_, mock_rc_capabilities_manager_); // Act & Assert EXPECT_EQ(rc_rpc_plugin::AcquireResult::IN_USE, - ra_manager.AcquireResource(kModuleType1, kAppId1)); + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId1)); } TEST_F(RAManagerTest, AcquireResource_AppRegisteredAnyHmiLevelResourceFree_Expect_Allowed) { // Arrange - ResourceAllocationManagerImpl ra_manager(mock_app_mngr_, mock_rpc_service_); + ResourceAllocationManagerImpl ra_manager( + mock_app_mngr_, mock_rpc_service_, mock_rc_capabilities_manager_); // Act & Assert EXPECT_EQ(rc_rpc_plugin::AcquireResult::ALLOWED, - ra_manager.AcquireResource(kModuleType1, kAppId1)); + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId1)); } TEST_F( @@ -173,14 +246,15 @@ TEST_F( // Arrange EXPECT_CALL(mock_app_mngr_, application(kAppId1)) .WillOnce(Return(mock_app_1_)); - ResourceAllocationManagerImpl ra_manager(mock_app_mngr_, mock_rpc_service_); + ResourceAllocationManagerImpl ra_manager( + mock_app_mngr_, mock_rpc_service_, mock_rc_capabilities_manager_); EXPECT_EQ(rc_rpc_plugin::AcquireResult::ALLOWED, - ra_manager.AcquireResource(kModuleType1, kAppId1)); + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId1)); EXPECT_CALL(mock_app_mngr_, application(kAppId1)) .WillOnce(Return(mock_app_1_)); // Same app tries to get already acquired resource EXPECT_EQ(rc_rpc_plugin::AcquireResult::ALLOWED, - ra_manager.AcquireResource(kModuleType1, kAppId1)); + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId1)); } TEST_F( @@ -193,7 +267,8 @@ TEST_F( const AcquireResult::eType expected_result = AcquireResult::REJECTED; const Common_RCAccessMode::eType access_mode = Common_RCAccessMode::eType::AUTO_ALLOW; - ResourceAllocationManagerImpl ra_manager(mock_app_mngr_, mock_rpc_service_); + ResourceAllocationManagerImpl ra_manager( + mock_app_mngr_, mock_rpc_service_, mock_rc_capabilities_manager_); CheckResultWithHMILevelAndAccessMode( ra_manager, app_level, expected_result, access_mode); } @@ -208,7 +283,8 @@ TEST_F( const AcquireResult::eType expected_result = AcquireResult::IN_USE; const Common_RCAccessMode::eType access_mode = Common_RCAccessMode::eType::AUTO_DENY; - ResourceAllocationManagerImpl ra_manager(mock_app_mngr_, mock_rpc_service_); + ResourceAllocationManagerImpl ra_manager( + mock_app_mngr_, mock_rpc_service_, mock_rc_capabilities_manager_); CheckResultWithHMILevelAndAccessMode( ra_manager, app_level, expected_result, access_mode); } @@ -223,7 +299,8 @@ TEST_F( const AcquireResult::eType expected_result = AcquireResult::ALLOWED; const Common_RCAccessMode::eType access_mode = Common_RCAccessMode::eType::AUTO_ALLOW; - ResourceAllocationManagerImpl ra_manager(mock_app_mngr_, mock_rpc_service_); + ResourceAllocationManagerImpl ra_manager( + mock_app_mngr_, mock_rpc_service_, mock_rc_capabilities_manager_); CheckResultWithHMILevelAndAccessMode( ra_manager, app_level, expected_result, access_mode); } @@ -238,7 +315,8 @@ TEST_F( const AcquireResult::eType expected_result = AcquireResult::ASK_DRIVER; const Common_RCAccessMode::eType access_mode = Common_RCAccessMode::eType::ASK_DRIVER; - ResourceAllocationManagerImpl ra_manager(mock_app_mngr_, mock_rpc_service_); + ResourceAllocationManagerImpl ra_manager( + mock_app_mngr_, mock_rpc_service_, mock_rc_capabilities_manager_); CheckResultWithHMILevelAndAccessMode( ra_manager, app_level, expected_result, access_mode); } @@ -246,32 +324,36 @@ TEST_F( TEST_F(RAManagerTest, AcquireResource_AcquiredModuleIsRejectedForApp2_ExpectApp2Rejected) { // Arrange - ResourceAllocationManagerImpl ra_manager(mock_app_mngr_, mock_rpc_service_); + ResourceAllocationManagerImpl ra_manager( + mock_app_mngr_, mock_rpc_service_, mock_rc_capabilities_manager_); EXPECT_CALL(mock_app_mngr_, application(kAppId1)) .WillRepeatedly(Return(mock_app_1_)); EXPECT_EQ(AcquireResult::ALLOWED, - ra_manager.AcquireResource(kModuleType1, kAppId1)); + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId1)); + + ra_manager.SetResourceAcquired(kModuleType1, kModuleId, kAppId1); // Act - ra_manager.OnDriverDisallowed(kModuleType1, kAppId2); + ra_manager.OnDriverDisallowed(kModuleType1, kModuleId, kAppId2); // Assert EXPECT_CALL(mock_app_mngr_, application(kAppId2)) .WillOnce(Return(mock_app_2_)); EXPECT_EQ(AcquireResult::REJECTED, - ra_manager.AcquireResource(kModuleType1, kAppId2)); + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId2)); } TEST_F(RAManagerTest, AppExit_ReleaseResource) { // Arrange - ResourceAllocationManagerImpl ra_manager(mock_app_mngr_, mock_rpc_service_); + ResourceAllocationManagerImpl ra_manager( + mock_app_mngr_, mock_rpc_service_, mock_rc_capabilities_manager_); ra_manager.SetAccessMode(hmi_apis::Common_RCAccessMode::eType::AUTO_DENY); EXPECT_CALL(mock_app_mngr_, application(kAppId1)) .WillRepeatedly(Return(mock_app_1_)); EXPECT_EQ(rc_rpc_plugin::AcquireResult::ALLOWED, - ra_manager.AcquireResource(kModuleType1, kAppId1)); + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId1)); // Act ra_manager.OnApplicationEvent( @@ -281,19 +363,22 @@ TEST_F(RAManagerTest, AppExit_ReleaseResource) { .WillRepeatedly(Return(mock_app_2_)); EXPECT_EQ(rc_rpc_plugin::AcquireResult::ALLOWED, - ra_manager.AcquireResource(kModuleType1, kAppId2)); + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId2)); } TEST_F(RAManagerTest, AnotherAppExit_NoReleaseResource) { // Arrange - ResourceAllocationManagerImpl ra_manager(mock_app_mngr_, mock_rpc_service_); + ResourceAllocationManagerImpl ra_manager( + mock_app_mngr_, mock_rpc_service_, mock_rc_capabilities_manager_); ra_manager.SetAccessMode(hmi_apis::Common_RCAccessMode::eType::AUTO_DENY); EXPECT_CALL(mock_app_mngr_, application(kAppId1)) .WillOnce(Return(mock_app_1_)); EXPECT_EQ(rc_rpc_plugin::AcquireResult::ALLOWED, - ra_manager.AcquireResource(kModuleType1, kAppId1)); + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId1)); + + ra_manager.SetResourceAcquired(kModuleType1, kModuleId, kAppId1); EXPECT_CALL(mock_app_mngr_, application(kAppId2)) .WillRepeatedly(Return(mock_app_2_)); @@ -306,15 +391,16 @@ TEST_F(RAManagerTest, AnotherAppExit_NoReleaseResource) { EXPECT_CALL(mock_app_mngr_, application(kAppId2)) .WillOnce(Return(mock_app_2_)); - EXPECT_CALL(*mock_app_2_, hmi_level()) + EXPECT_CALL(*mock_app_2_, hmi_level(kDefaultWindowId)) .WillOnce(Return(mobile_apis::HMILevel::HMI_FULL)); EXPECT_EQ(rc_rpc_plugin::AcquireResult::IN_USE, - ra_manager.AcquireResource(kModuleType1, kAppId2)); + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId2)); } TEST_F(RAManagerTest, AppUnregistered_ReleaseResource) { // Arrange - ResourceAllocationManagerImpl ra_manager(mock_app_mngr_, mock_rpc_service_); + ResourceAllocationManagerImpl ra_manager( + mock_app_mngr_, mock_rpc_service_, mock_rc_capabilities_manager_); ra_manager.SetAccessMode(hmi_apis::Common_RCAccessMode::eType::AUTO_DENY); RCAppExtensionPtr rc_extention_ptr = @@ -322,7 +408,7 @@ TEST_F(RAManagerTest, AppUnregistered_ReleaseResource) { rc_rpc_plugin::RCRPCPlugin::kRCPluginID)); EXPECT_EQ(rc_rpc_plugin::AcquireResult::ALLOWED, - ra_manager.AcquireResource(kModuleType1, kAppId1)); + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId1)); // Act application_manager::ApplicationSharedPtr app_ptr(mock_app_1_); @@ -335,18 +421,21 @@ TEST_F(RAManagerTest, AppUnregistered_ReleaseResource) { .WillOnce(Return(mock_app_2_)); EXPECT_EQ(rc_rpc_plugin::AcquireResult::ALLOWED, - ra_manager.AcquireResource(kModuleType1, kAppId2)); + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId2)); } TEST_F(RAManagerTest, AnotherAppUnregistered_NoReleaseResource) { // Arrange - ResourceAllocationManagerImpl ra_manager(mock_app_mngr_, mock_rpc_service_); + ResourceAllocationManagerImpl ra_manager( + mock_app_mngr_, mock_rpc_service_, mock_rc_capabilities_manager_); ra_manager.SetAccessMode(hmi_apis::Common_RCAccessMode::eType::AUTO_DENY); EXPECT_CALL(mock_app_mngr_, application(kAppId1)) .WillOnce(Return(mock_app_1_)); EXPECT_EQ(rc_rpc_plugin::AcquireResult::ALLOWED, - ra_manager.AcquireResource(kModuleType1, kAppId1)); + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId1)); + + ra_manager.SetResourceAcquired(kModuleType1, kModuleId, kAppId1); EXPECT_CALL(mock_app_mngr_, application(kAppId1)) .WillRepeatedly(Return(mock_app_2_)); @@ -360,24 +449,25 @@ TEST_F(RAManagerTest, AnotherAppUnregistered_NoReleaseResource) { EXPECT_CALL(mock_app_mngr_, application(kAppId2)) .WillOnce(Return(mock_app_2_)); - EXPECT_CALL(*mock_app_2_, hmi_level()) + EXPECT_CALL(*mock_app_2_, hmi_level(kDefaultWindowId)) .WillOnce(Return(mobile_apis::HMILevel::HMI_FULL)); EXPECT_EQ(rc_rpc_plugin::AcquireResult::IN_USE, - ra_manager.AcquireResource(kModuleType1, kAppId2)); + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId2)); } TEST_F(RAManagerTest, AppsDisallowed_ReleaseAllResources) { // Arrange - ResourceAllocationManagerImpl ra_manager(mock_app_mngr_, mock_rpc_service_); + ResourceAllocationManagerImpl ra_manager( + mock_app_mngr_, mock_rpc_service_, mock_rc_capabilities_manager_); ra_manager.SetAccessMode(hmi_apis::Common_RCAccessMode::eType::AUTO_DENY); EXPECT_CALL(mock_app_mngr_, application(kAppId1)) .WillRepeatedly(Return(mock_app_1_)); EXPECT_EQ(rc_rpc_plugin::AcquireResult::ALLOWED, - ra_manager.AcquireResource(kModuleType1, kAppId1)); + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId1)); EXPECT_EQ(rc_rpc_plugin::AcquireResult::ALLOWED, - ra_manager.AcquireResource(kModuleType2, kAppId1)); + ra_manager.AcquireResource(kModuleType2, kModuleId, kAppId1)); application_manager::ApplicationSet apps; apps.insert(mock_app_1_); @@ -400,18 +490,19 @@ TEST_F(RAManagerTest, AppsDisallowed_ReleaseAllResources) { EXPECT_CALL(mock_app_mngr_, application(kAppId2)) .WillRepeatedly(Return(mock_app_2_)); - EXPECT_CALL(*mock_app_2_, hmi_level()) + EXPECT_CALL(*mock_app_2_, hmi_level(kDefaultWindowId)) .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_FULL)); EXPECT_EQ(rc_rpc_plugin::AcquireResult::ALLOWED, - ra_manager.AcquireResource(kModuleType1, kAppId2)); + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId2)); EXPECT_EQ(rc_rpc_plugin::AcquireResult::ALLOWED, - ra_manager.AcquireResource(kModuleType2, kAppId2)); + ra_manager.AcquireResource(kModuleType2, kModuleId, kAppId2)); Mock::VerifyAndClearExpectations(&mock_app_mngr_); } TEST_F(RAManagerTest, AppGotRevokedModulesWithPTU_ReleaseRevokedResource) { // Arrange - ResourceAllocationManagerImpl ra_manager(mock_app_mngr_, mock_rpc_service_); + ResourceAllocationManagerImpl ra_manager( + mock_app_mngr_, mock_rpc_service_, mock_rc_capabilities_manager_); ra_manager.SetAccessMode(hmi_apis::Common_RCAccessMode::eType::AUTO_DENY); EXPECT_CALL(mock_app_mngr_, application(kAppId1)) @@ -437,9 +528,13 @@ TEST_F(RAManagerTest, AppGotRevokedModulesWithPTU_ReleaseRevokedResource) { .WillRepeatedly(Return(policy_app_id_1_)); EXPECT_EQ(rc_rpc_plugin::AcquireResult::ALLOWED, - ra_manager.AcquireResource(kModuleType1, kAppId1)); + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId1)); + + ra_manager.SetResourceAcquired(kModuleType1, kModuleId, kAppId1); + EXPECT_EQ(rc_rpc_plugin::AcquireResult::ALLOWED, - ra_manager.AcquireResource(kModuleType2, kAppId1)); + ra_manager.AcquireResource(kModuleType2, kModuleId, kAppId1)); + ra_manager.SetResourceAcquired(kModuleType2, kModuleId, kAppId1); application_manager::ApplicationSet apps; apps.insert(mock_app_1_); @@ -449,29 +544,31 @@ TEST_F(RAManagerTest, AppGotRevokedModulesWithPTU_ReleaseRevokedResource) { EXPECT_CALL(mock_app_mngr_, applications()).WillRepeatedly(Return(apps_da)); - Resources allowed_modules; + std::vector<std::string> allowed_modules; allowed_modules.push_back(kModuleType1); EXPECT_CALL(mock_policy_handler_, GetModuleTypes(policy_app_id_1_, _)) .WillOnce(DoAll(SetArgPointee<1>(allowed_modules), Return(true))); + EXPECT_CALL(mock_app_mngr_, application(kAppId2)) + .WillRepeatedly(Return(mock_app_2_)); + EXPECT_CALL(*mock_app_2_, hmi_level(kDefaultWindowId)) + .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_FULL)); + // Act ra_manager.OnPolicyEvent(application_manager::plugin_manager::PolicyEvent:: kApplicationPolicyUpdated); - EXPECT_CALL(mock_app_mngr_, application(kAppId2)) - .WillRepeatedly(Return(mock_app_2_)); - EXPECT_CALL(*mock_app_2_, hmi_level()) - .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_FULL)); EXPECT_EQ(rc_rpc_plugin::AcquireResult::IN_USE, - ra_manager.AcquireResource(kModuleType1, kAppId2)); + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId2)); EXPECT_EQ(rc_rpc_plugin::AcquireResult::ALLOWED, - ra_manager.AcquireResource(kModuleType2, kAppId2)); + ra_manager.AcquireResource(kModuleType2, kModuleId, kAppId2)); Mock::VerifyAndClearExpectations(&mock_app_mngr_); } TEST_F(RAManagerTest, GetAccessMode_ExpectedSameAsHadSet) { - ResourceAllocationManagerImpl ra_manager(mock_app_mngr_, mock_rpc_service_); + ResourceAllocationManagerImpl ra_manager( + mock_app_mngr_, mock_rpc_service_, mock_rc_capabilities_manager_); ra_manager.SetAccessMode(hmi_apis::Common_RCAccessMode::AUTO_DENY); EXPECT_EQ(hmi_apis::Common_RCAccessMode::AUTO_DENY, @@ -492,7 +589,8 @@ TEST_F(RAManagerTest, GetAccessMode_ExpectedSameAsHadSet) { TEST_F(RAManagerTest, OnRCStatus_AppRegistation_RC_allowed) { // Arrange - ResourceAllocationManagerImpl ra_manager(mock_app_mngr_, mock_rpc_service_); + ResourceAllocationManagerImpl ra_manager( + mock_app_mngr_, mock_rpc_service_, mock_rc_capabilities_manager_); ON_CALL((*mock_app_1_), is_remote_control_supported()) .WillByDefault(Return(true)); ON_CALL((*mock_app_1_), hmi_app_id()).WillByDefault(Return(kHMIAppId1)); @@ -521,7 +619,8 @@ TEST_F(RAManagerTest, OnRCStatus_AppRegistation_RC_allowed) { TEST_F(RAManagerTest, OnRCStatus_AppRegistation_RC_disallowed) { // Arrange - ResourceAllocationManagerImpl ra_manager(mock_app_mngr_, mock_rpc_service_); + ResourceAllocationManagerImpl ra_manager( + mock_app_mngr_, mock_rpc_service_, mock_rc_capabilities_manager_); ra_manager.set_rc_enabled(false); ON_CALL((*mock_app_1_), is_remote_control_supported()) @@ -549,7 +648,8 @@ TEST_F(RAManagerTest, OnRCStatus_AppRegistation_RC_disallowed) { TEST_F(RAManagerTest, OnRCStatus_RCStateChanging_RC_disabling) { // Arrange - ResourceAllocationManagerImpl ra_manager(mock_app_mngr_, mock_rpc_service_); + ResourceAllocationManagerImpl ra_manager( + mock_app_mngr_, mock_rpc_service_, mock_rc_capabilities_manager_); ON_CALL((*mock_app_1_), is_remote_control_supported()) .WillByDefault(Return(true)); ON_CALL((*mock_app_1_), hmi_app_id()).WillByDefault(Return(kHMIAppId1)); @@ -586,7 +686,8 @@ TEST_F(RAManagerTest, OnRCStatus_RCStateChanging_RC_disabling) { TEST_F(RAManagerTest, OnRCStatus_RCStateChanging_RC_enabling) { // Arrange - ResourceAllocationManagerImpl ra_manager(mock_app_mngr_, mock_rpc_service_); + ResourceAllocationManagerImpl ra_manager( + mock_app_mngr_, mock_rpc_service_, mock_rc_capabilities_manager_); ON_CALL((*mock_app_1_), is_remote_control_supported()) .WillByDefault(Return(true)); ON_CALL((*mock_app_1_), hmi_app_id()).WillByDefault(Return(kHMIAppId1)); @@ -623,14 +724,17 @@ TEST_F(RAManagerTest, OnRCStatus_RCStateChanging_RC_enabling) { TEST_F(RAManagerTest, OnRCStatus_ModuleAllocation) { // Arrange - ResourceAllocationManagerImpl ra_manager(mock_app_mngr_, mock_rpc_service_); + ResourceAllocationManagerImpl ra_manager( + mock_app_mngr_, mock_rpc_service_, mock_rc_capabilities_manager_); ON_CALL((*mock_app_1_), is_remote_control_supported()) .WillByDefault(Return(true)); ON_CALL((*mock_app_1_), hmi_app_id()).WillByDefault(Return(kHMIAppId1)); EXPECT_EQ(rc_rpc_plugin::AcquireResult::ALLOWED, - ra_manager.AcquireResource(kModuleType1, kAppId1)); + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId1)); + + ra_manager.SetResourceAcquired(kModuleType1, kModuleId, kAppId1); application_manager::commands::MessageSharedPtr message_to_mob; EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(_, false)) @@ -665,4 +769,118 @@ TEST_F(RAManagerTest, OnRCStatus_ModuleAllocation) { kHMIAppId1); } +// UL - User Location +// If User Location is invalid, in any case AcquireResult will be REJECTED +TEST_F(RAManagerTest, AcquireResource_UL_IsInvalid_REJECTED) { + ResourceAllocationManagerImpl ra_manager( + mock_app_mngr_, mock_rpc_service_, mock_rc_capabilities_manager_); + + ON_CALL(mock_rc_capabilities_manager_, IsSeatLocationCapabilityProvided()) + .WillByDefault(Return(true)); + rc_app_extension_->SetUserLocation(kInvalidLocation); + + EXPECT_EQ(AcquireResult::REJECTED, + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId1)); +} + +// UL - User Location, MA - Multiple Access +TEST_F(RAManagerTest, + AcquireResource_UL_IsValid_ResourceIsFree_MA_False_ALLOWED) { + ResourceAllocationManagerImpl ra_manager( + mock_app_mngr_, mock_rpc_service_, mock_rc_capabilities_manager_); + + ON_CALL(mock_rc_capabilities_manager_, IsSeatLocationCapabilityProvided()) + .WillByDefault(Return(true)); + rc_app_extension_->SetUserLocation(KDefaultUserLocation); + + EXPECT_EQ(AcquireResult::ALLOWED, + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId1)); +} + +// UL - User Location, MA - Multiple Access +TEST_F(RAManagerTest, + AcquireResource_UL_IsValid_ResourceIsAcquired_MA_False_REJECTED) { + ResourceAllocationManagerImpl ra_manager( + mock_app_mngr_, mock_rpc_service_, mock_rc_capabilities_manager_); + + ON_CALL(mock_rc_capabilities_manager_, IsSeatLocationCapabilityProvided()) + .WillByDefault(Return(true)); + rc_app_extension_->SetUserLocation(KDefaultUserLocation); + + EXPECT_EQ(AcquireResult::ALLOWED, + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId1)); + + ra_manager.SetResourceAcquired(kModuleType1, kModuleId, kAppId1); + ON_CALL(*mock_app_2_, hmi_level(kDefaultWindowId)) + .WillByDefault(Return(mobile_apis::HMILevel::HMI_FULL)); + ON_CALL(mock_rc_capabilities_manager_, IsMultipleAccessAllowed(_)) + .WillByDefault(Return(false)); + EXPECT_EQ(AcquireResult::REJECTED, + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId2)); +} + +// UL - User Location, MA - Multiple Access +TEST_F(RAManagerTest, + AcquireResource_UL_IsValid_ResourceIsFree_MA_True_ALLOWED) { + ResourceAllocationManagerImpl ra_manager( + mock_app_mngr_, mock_rpc_service_, mock_rc_capabilities_manager_); + + ON_CALL(mock_rc_capabilities_manager_, IsSeatLocationCapabilityProvided()) + .WillByDefault(Return(true)); + rc_app_extension_->SetUserLocation(KDefaultUserLocation); + + EXPECT_EQ(AcquireResult::ALLOWED, + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId1)); + + ON_CALL(*mock_app_2_, hmi_level(kDefaultWindowId)) + .WillByDefault(Return(mobile_apis::HMILevel::HMI_FULL)); + EXPECT_EQ(AcquireResult::ALLOWED, + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId2)); +} + +// UL - User Location, MA - Multiple Access, AM - Access Mode +TEST_F(RAManagerTest, + AcquireResource_UL_IsValid_ResourceIsAcquired_MA_True_AM_AUTO_DENY) { + ResourceAllocationManagerImpl ra_manager( + mock_app_mngr_, mock_rpc_service_, mock_rc_capabilities_manager_); + + ON_CALL(mock_rc_capabilities_manager_, IsSeatLocationCapabilityProvided()) + .WillByDefault(Return(true)); + rc_app_extension_->SetUserLocation(KDefaultUserLocation); + + EXPECT_EQ(AcquireResult::ALLOWED, + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId1)); + + ra_manager.SetResourceAcquired(kModuleType1, kModuleId, kAppId1); + + ra_manager.SetAccessMode(hmi_apis::Common_RCAccessMode::AUTO_DENY); + + ON_CALL(*mock_app_2_, hmi_level(kDefaultWindowId)) + .WillByDefault(Return(mobile_apis::HMILevel::HMI_FULL)); + EXPECT_EQ(AcquireResult::IN_USE, + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId2)); +} + +TEST_F(RAManagerTest, + AcquireResource_UL_IsValid_ResourceIsAcquired_MA_True_AM_ASK_DRIVER) { + ResourceAllocationManagerImpl ra_manager( + mock_app_mngr_, mock_rpc_service_, mock_rc_capabilities_manager_); + + ON_CALL(mock_rc_capabilities_manager_, IsSeatLocationCapabilityProvided()) + .WillByDefault(Return(true)); + rc_app_extension_->SetUserLocation(KDefaultUserLocation); + + EXPECT_EQ(AcquireResult::ALLOWED, + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId1)); + + ra_manager.SetResourceAcquired(kModuleType1, kModuleId, kAppId1); + + ra_manager.SetAccessMode(hmi_apis::Common_RCAccessMode::ASK_DRIVER); + + ON_CALL(*mock_app_2_, hmi_level(kDefaultWindowId)) + .WillByDefault(Return(mobile_apis::HMILevel::HMI_FULL)); + EXPECT_EQ(AcquireResult::ASK_DRIVER, + ra_manager.AcquireResource(kModuleType1, kModuleId, kAppId2)); +} + } // namespace rc_rpc_plugin_test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/CMakeLists.txt b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/CMakeLists.txt index fdf02b57cb..fe8857b6b1 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/CMakeLists.txt +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/CMakeLists.txt @@ -51,21 +51,27 @@ collect_sources(APP_EXTENSIONS "${EXTENSIONS_SOURCE_DIR}") collect_sources(RPC_PLUGIN_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src") set(LIBRARIES + ApplicationManager HMI_API MOBILE_API - ApplicationManager + MessageHelper + connectionHandler v4_protocol_v1_2_no_extra SmartObjects Utils - Policy + PolicyStatic + jsoncpp ) if(ENABLE_LOG) list(APPEND LIBRARIES log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) endif() -add_library("sdl_rpc_plugin" SHARED ${MOBILE_COMMANDS} ${HMI_COMMANDS} ${RPC_PLUGIN_SOURCES} ${APP_EXTENSIONS}) -target_link_libraries("sdl_rpc_plugin" ${LIBRARIES}) +add_library("sdl_rpc_plugin_static" ${MOBILE_COMMANDS} ${HMI_COMMANDS} ${RPC_PLUGIN_SOURCES} ${APP_EXTENSIONS}) +target_link_libraries("sdl_rpc_plugin_static" ${LIBRARIES}) + +add_library("sdl_rpc_plugin" SHARED "src/sdl_rpc_plugin.cc") +target_link_libraries("sdl_rpc_plugin" sdl_rpc_plugin_static) set(INSTALL_DESTINATION bin) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/bc_get_app_properties_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/bc_get_app_properties_request.h new file mode 100644 index 0000000000..484a82ca4c --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/bc_get_app_properties_request.h @@ -0,0 +1,80 @@ +/* + * 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_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_BC_GET_APP_PROPERTIES_REQUEST_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_BC_GET_APP_PROPERTIES_REQUEST_H_ + +#include "application_manager/commands/request_from_hmi.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +/** + * @brief BCGetAppPropertiesRequest command class + **/ +class BCGetAppPropertiesRequest : public app_mngr::commands::RequestFromHMI { + public: + /** + * @brief BCGetAppPropertiesRequest class constructor + * + * @param message Incoming SmartObject message + **/ + BCGetAppPropertiesRequest(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 BCGetAppPropertiesRequest class destructor + **/ + virtual ~BCGetAppPropertiesRequest() = default; + + /** + * @brief Execute command + **/ + void Run() FINAL; + + private: + void FillAppProperties(const std::string& policy_app_id, + smart_objects::SmartObject& out_properties) const; + + DISALLOW_COPY_AND_ASSIGN(BCGetAppPropertiesRequest); +}; + +} // namespace commands + +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_BC_GET_APP_PROPERTIES_REQUEST_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/get_urls_response.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/bc_get_app_properties_response.h index 06af3c6ea5..5634663254 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/get_urls_response.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/bc_get_app_properties_response.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Ford Motor Company + * Copyright (c) 2020, Ford Motor Company * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -30,43 +30,49 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_GET_URLS_RESPONSE_H_ -#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_GET_URLS_RESPONSE_H_ +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_BC_GET_APP_PROPERTIES_RESPONSE_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_BC_GET_APP_PROPERTIES_RESPONSE_H_ #include "application_manager/commands/response_to_hmi.h" namespace sdl_rpc_plugin { namespace app_mngr = application_manager; + namespace commands { -class GetUrlsResponse : public app_mngr::commands::ResponseToHMI { +/** + * @brief BCGetAppPropertiesResponse command class + **/ +class BCGetAppPropertiesResponse : public app_mngr::commands::ResponseToHMI { public: /** - * @brief GetUrlsResponse class constructor + * @brief BCGetAppPropertiesResponse class constructor * * @param message Incoming SmartObject message **/ - GetUrlsResponse(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); + BCGetAppPropertiesResponse( + 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 GetUrlsResponse class destructor + * @brief BCGetAppPropertiesResponse class destructor **/ - virtual ~GetUrlsResponse(); + virtual ~BCGetAppPropertiesResponse() = default; /** * @brief Execute command **/ - virtual void Run(); + void Run() FINAL; private: - DISALLOW_COPY_AND_ASSIGN(GetUrlsResponse); + DISALLOW_COPY_AND_ASSIGN(BCGetAppPropertiesResponse); }; } // namespace commands + } // namespace sdl_rpc_plugin -#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_GET_URLS_RESPONSE_H_ +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_BC_GET_APP_PROPERTIES_RESPONSE_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/bc_set_app_properties_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/bc_set_app_properties_request.h new file mode 100644 index 0000000000..491d2196e5 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/bc_set_app_properties_request.h @@ -0,0 +1,77 @@ +/* + * 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_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_BC_SET_APP_PROPERTIES_REQUEST_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_BC_SET_APP_PROPERTIES_REQUEST_H_ + +#include "application_manager/commands/request_from_hmi.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +/** + * @brief BCSetAppPropertiesRequest command class + **/ +class BCSetAppPropertiesRequest : public app_mngr::commands::RequestFromHMI { + public: + /** + * @brief BCSetAppPropertiesRequest class constructor + * + * @param message Incoming SmartObject message + **/ + BCSetAppPropertiesRequest(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 BCSetAppPropertiesRequest class destructor + **/ + virtual ~BCSetAppPropertiesRequest() = default; + + /** + * @brief Execute command + **/ + void Run() FINAL; + + private: + DISALLOW_COPY_AND_ASSIGN(BCSetAppPropertiesRequest); +}; + +} // namespace commands + +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_BC_SET_APP_PROPERTIES_REQUEST_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/bc_set_app_properties_response.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/bc_set_app_properties_response.h new file mode 100644 index 0000000000..e9872196c9 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/bc_set_app_properties_response.h @@ -0,0 +1,78 @@ +/* + * 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_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_BC_SET_APP_PROPERTIES_RESPONSE_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_BC_SET_APP_PROPERTIES_RESPONSE_H_ + +#include "application_manager/commands/response_to_hmi.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +/** + * @brief BCSetAppPropertiesResponse command class + **/ +class BCSetAppPropertiesResponse : public app_mngr::commands::ResponseToHMI { + public: + /** + * @brief BCSetAppPropertiesResponse class constructor + * + * @param message Incoming SmartObject message + **/ + BCSetAppPropertiesResponse( + 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 BCSetAppPropertiesResponse class destructor + **/ + virtual ~BCSetAppPropertiesResponse() = default; + + /** + * @brief Execute command + **/ + void Run() FINAL; + + private: + DISALLOW_COPY_AND_ASSIGN(BCSetAppPropertiesResponse); +}; + +} // namespace commands + +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_BC_SET_APP_PROPERTIES_RESPONSE_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_app_properties_change_notification.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_app_properties_change_notification.h new file mode 100644 index 0000000000..7feb2ef85e --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_app_properties_change_notification.h @@ -0,0 +1,79 @@ +/* + * 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_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_APP_PROPERTIES_CHANGE_NOTIFICATION_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_APP_PROPERTIES_CHANGE_NOTIFICATION_H_ + +#include "application_manager/commands/notification_to_hmi.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +/** + * @brief OnAppPropertiesChangeNotification command class + **/ +class OnAppPropertiesChangeNotification + : public app_mngr::commands::NotificationToHMI { + public: + /** + * @brief OnAppPropertiesChangeNotification class constructor + * + * @param message Incoming SmartObject message + **/ + OnAppPropertiesChangeNotification( + 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 OnAppPropertiesChangeNotification class destructor + **/ + virtual ~OnAppPropertiesChangeNotification() = default; + + /** + * @brief Execute command + **/ + void Run() FINAL; + + private: + DISALLOW_COPY_AND_ASSIGN(OnAppPropertiesChangeNotification); +}; + +} // namespace commands + +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_APP_PROPERTIES_CHANGE_NOTIFICATION_H_ 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..39b5c3aee3 --- /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,97 @@ +/* + * 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: + enum ProcessSystemDisplayCapabilitiesResult { + SUCCESS, + FAIL, + CAPABILITIES_CACHED + }; + /** + * @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 + */ + ProcessSystemDisplayCapabilitiesResult 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/include/sdl_rpc_plugin/commands/hmi/on_service_update_notification.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_service_update_notification.h new file mode 100644 index 0000000000..bfa9b6e6ae --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_service_update_notification.h @@ -0,0 +1,82 @@ +/* + * 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_SERVICE_UPDATE_NOTIFICATION_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_SERVICE_UPDATE_NOTIFICATION_H_ + +#include "application_manager/commands/notification_to_hmi.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { +namespace hmi { + +/** + * @brief OnServiceUpdateNotification command class + **/ +class OnServiceUpdateNotification + : public app_mngr::commands::NotificationToHMI { + public: + /** + * @brief OnServiceUpdateNotification class constructor + * @param application_manager ref to application manager + * @param rpc_service ref to rpc service + * @param hmi_capabilities ref to HMI capabilities + * @param policy_handle ref to policy handler + **/ + OnServiceUpdateNotification( + 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 OnServiceUpdateNotification class destructor + **/ + virtual ~OnServiceUpdateNotification() OVERRIDE; + + /** + * @brief Execute command + **/ + void Run() OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(OnServiceUpdateNotification); +}; + +} // 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_SERVICE_UPDATE_NOTIFICATION_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/get_urls.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/sdl_get_policy_configuration_data_request.h index c3f7453583..043a4369c5 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/get_urls.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/sdl_get_policy_configuration_data_request.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Ford Motor Company + * Copyright (c) 2019, Ford Motor Company * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -30,36 +30,38 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_GET_URLS_H_ -#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_GET_URLS_H_ +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_SDL_GET_POLICY_CONFIGURATION_DATA_REQUEST_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_SDL_GET_POLICY_CONFIGURATION_DATA_REQUEST_H_ #include "application_manager/commands/request_from_hmi.h" -#include "policy/policy_types.h" -#include "smart_objects/smart_object.h" namespace sdl_rpc_plugin { namespace app_mngr = application_manager; + namespace commands { + /** - * @brief GetUrls command class + * @brief SDLGetPolicyConfigurationDataRequest command class **/ -class GetUrls : public app_mngr::commands::RequestFromHMI { +class SDLGetPolicyConfigurationDataRequest + : public app_mngr::commands::RequestFromHMI { public: /** - * @brief GetUrls class constructor + * @brief SDLGetPolicyConfigurationDataRequest class constructor * * @param message Incoming SmartObject message **/ - GetUrls(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); + SDLGetPolicyConfigurationDataRequest( + 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 GetUrls class destructor + * @brief SDLGetPolicyConfigurationDataRequest class destructor **/ - virtual ~GetUrls(); + ~SDLGetPolicyConfigurationDataRequest() OVERRIDE; /** * @brief Execute command @@ -67,30 +69,16 @@ class GetUrls : public app_mngr::commands::RequestFromHMI { void Run() OVERRIDE; private: -#ifdef PROPRIETARY_MODE - /** - * @brief Processes URLs collecting for policy service - * @param endpoints Endpoints section of policy table - */ - void ProcessPolicyServiceURLs(const policy::EndpointUrls& endpoints); -#endif // PROPRIETARY_MODE + hmi_apis::Common_Result::eType PrepareResponseParams( + smart_objects::SmartObject& response_out) const; - /** - * @brief Process URLs collecting for service - * @param endpoints Endpoints section of policy table - */ - void ProcessServiceURLs(const policy::EndpointUrls& endpoints); - - /** - * @brief Sends response to HMI - * @param result Result code - */ - void SendResponseToHMI(hmi_apis::Common_Result::eType result); + smart_objects::SmartObject GetValueParam( + const Json::Value& policy_property) const; - DISALLOW_COPY_AND_ASSIGN(GetUrls); + DISALLOW_COPY_AND_ASSIGN(SDLGetPolicyConfigurationDataRequest); }; } // namespace commands } // namespace sdl_rpc_plugin -#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_GET_URLS_H_ +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_SDL_GET_POLICY_CONFIGURATION_DATA_REQUEST_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/sdl_get_policy_configuration_data_response.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/sdl_get_policy_configuration_data_response.h new file mode 100644 index 0000000000..2c22f69281 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/sdl_get_policy_configuration_data_response.h @@ -0,0 +1,78 @@ +/* + * 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_SDL_GET_POLICY_CONFIGURATION_DATA_RESPONSE_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_SDL_GET_POLICY_CONFIGURATION_DATA_RESPONSE_H_ + +#include "application_manager/commands/response_to_hmi.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +/** + * @brief SDLGetPolicyConfigurationDataResponse command class + **/ +class SDLGetPolicyConfigurationDataResponse + : public app_mngr::commands::ResponseToHMI { + public: + /** + * @brief SDLGetPolicyConfigurationDataResponse class constructor + * + * @param message Incoming SmartObject message + **/ + SDLGetPolicyConfigurationDataResponse( + 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 SDLGetPolicyConfigurationDataResponse class destructor + **/ + virtual ~SDLGetPolicyConfigurationDataResponse(); + + /** + * @brief Execute command + **/ + virtual void Run(); + + private: + DISALLOW_COPY_AND_ASSIGN(SDLGetPolicyConfigurationDataResponse); +}; + +} // namespace commands +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_SDL_GET_POLICY_CONFIGURATION_DATA_RESPONSE_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_cancel_interaction_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_cancel_interaction_request.h new file mode 100644 index 0000000000..a637f53df3 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_cancel_interaction_request.h @@ -0,0 +1,79 @@ +/* + * 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_UI_CANCEL_INTERACTION_REQUEST_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_UI_CANCEL_INTERACTION_REQUEST_H_ + +#include "application_manager/commands/request_to_hmi.h" +#include "sdl_rpc_plugin/sdl_rpc_plugin.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +/** + * @brief UICancelInteractionRequest command class + **/ +class UICancelInteractionRequest : public app_mngr::commands::RequestToHMI { + public: + /** + * @brief UICancelInteractionRequest class constructor + * + * @param message Incoming SmartObject message + **/ + UICancelInteractionRequest( + 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 UICancelInteractionRequest class destructor + **/ + virtual ~UICancelInteractionRequest(); + + /** + * @brief Execute command + **/ + virtual void Run(); + + private: + DISALLOW_COPY_AND_ASSIGN(UICancelInteractionRequest); +}; + +} // namespace commands + +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_UI_CANCEL_INTERACTION_REQUEST_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_cancel_interaction_response.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_cancel_interaction_response.h new file mode 100644 index 0000000000..751a2ceef8 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_cancel_interaction_response.h @@ -0,0 +1,78 @@ +/* + * 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_UI_CANCEL_INTERACTION_RESPONSE_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_UI_CANCEL_INTERACTION_RESPONSE_H_ + +#include "application_manager/commands/response_from_hmi.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +/** + * @brief UICancelInteractionResponse command class + **/ +class UICancelInteractionResponse : public app_mngr::commands::ResponseFromHMI { + public: + /** + * @brief UICancelInteractionResponse class constructor + * + * @param message Incoming SmartObject message + **/ + UICancelInteractionResponse( + 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 UICancelInteractionResponse class destructor + **/ + virtual ~UICancelInteractionResponse(); + + /** + * @brief Execute command + **/ + virtual void Run(); + + private: + DISALLOW_COPY_AND_ASSIGN(UICancelInteractionResponse); +}; + +} // namespace commands + +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_UI_CANCEL_INTERACTION_RESPONSE_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_create_window_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_create_window_request.h new file mode 100644 index 0000000000..6fe8e182c4 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_create_window_request.h @@ -0,0 +1,66 @@ +/* + * 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_UI_CREATE_WINDOW_REQUEST_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_UI_CREATE_WINDOW_REQUEST_H_ + +#include "application_manager/commands/request_to_hmi.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +/** + * @brief UI.CreateWindow request command class + **/ +class UICreateWindowRequest : public app_mngr::commands::RequestToHMI { + public: + UICreateWindowRequest(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); + + ~UICreateWindowRequest() FINAL; + + void Run() FINAL; + + private: + DISALLOW_COPY_AND_ASSIGN(UICreateWindowRequest); +}; + +} // namespace commands + +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_UI_CREATE_WINDOW_REQUEST_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_create_window_response.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_create_window_response.h new file mode 100644 index 0000000000..b9452fce1f --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_create_window_response.h @@ -0,0 +1,66 @@ +/* + * 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_UI_CREATE_WINDOW_RESPONSE_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_UI_CREATE_WINDOW_RESPONSE_H_ + +#include "application_manager/commands/response_from_hmi.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +/** + * @brief UI.CreateWindow response command class + **/ +class UICreateWindowResponse : public app_mngr::commands::ResponseFromHMI { + public: + UICreateWindowResponse(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); + + ~UICreateWindowResponse() FINAL; + + void Run() FINAL; + + private: + DISALLOW_COPY_AND_ASSIGN(UICreateWindowResponse); +}; + +} // namespace commands + +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_UI_CREATE_WINDOW_RESPONSE_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_delete_window_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_delete_window_request.h new file mode 100644 index 0000000000..58b2c3989f --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_delete_window_request.h @@ -0,0 +1,66 @@ +/* + * 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_UI_DELETE_WINDOW_REQUEST_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_UI_DELETE_WINDOW_REQUEST_H_ + +#include "application_manager/commands/request_to_hmi.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +/** + * @brief UI.DeleteWindow request command class + **/ +class UIDeleteWindowRequest : public app_mngr::commands::RequestToHMI { + public: + UIDeleteWindowRequest(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); + + ~UIDeleteWindowRequest() FINAL; + + void Run() FINAL; + + private: + DISALLOW_COPY_AND_ASSIGN(UIDeleteWindowRequest); +}; + +} // namespace commands + +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_UI_DELETE_WINDOW_REQUEST_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_delete_window_response.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_delete_window_response.h new file mode 100644 index 0000000000..1500a3f9b2 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_delete_window_response.h @@ -0,0 +1,66 @@ +/* + * 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_UI_DELETE_WINDOW_RESPONSE_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_UI_DELETE_WINDOW_RESPONSE_H_ + +#include "application_manager/commands/response_from_hmi.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +/** + * @brief UI.DeleteWindow response command class + **/ +class UIDeleteWindowResponse : public app_mngr::commands::ResponseFromHMI { + public: + UIDeleteWindowResponse(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); + + ~UIDeleteWindowResponse() FINAL; + + void Run() FINAL; + + private: + DISALLOW_COPY_AND_ASSIGN(UIDeleteWindowResponse); +}; + +} // namespace commands + +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_UI_DELETE_WINDOW_RESPONSE_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/add_sub_menu_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/add_sub_menu_request.h index 2da94ae67e..d99c5dab38 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/add_sub_menu_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/add_sub_menu_request.h @@ -88,6 +88,8 @@ class AddSubMenuRequest : public app_mngr::commands::CommandRequestImpl { */ bool CheckSubMenuName(); + bool is_menu_layout_available_ = true; + DISALLOW_COPY_AND_ASSIGN(AddSubMenuRequest); }; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/cancel_interaction_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/cancel_interaction_request.h new file mode 100644 index 0000000000..0063c07512 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/cancel_interaction_request.h @@ -0,0 +1,85 @@ +/* + 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_MOBILE_CANCEL_INTERACTION_REQUEST_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_CANCEL_INTERACTION_REQUEST_H_ + +#include "application_manager/commands/command_request_impl.h" +#include "sdl_rpc_plugin/sdl_rpc_plugin.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +/** + * @brief CancelInteractionRequest command class + **/ +class CancelInteractionRequest : public app_mngr::commands::CommandRequestImpl { + public: + /** + * @brief CancelInteractionRequest class constructor + * + * @param message Incoming SmartObject message + **/ + CancelInteractionRequest(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 CancelInteractionRequest class destructor + **/ + virtual ~CancelInteractionRequest(); + + /** + * @brief Execute command + **/ + virtual void Run(); + + /** + * @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); + + private: + DISALLOW_COPY_AND_ASSIGN(CancelInteractionRequest); +}; + +} // namespace commands + +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_CANCEL_INTERACTION_REQUEST_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/cancel_interaction_response.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/cancel_interaction_response.h new file mode 100644 index 0000000000..3e8536e617 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/cancel_interaction_response.h @@ -0,0 +1,79 @@ +/* + 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_MOBILE_CANCEL_INTERACTION_RESPONSE_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_CANCEL_INTERACTION_RESPONSE_H_ + +#include "application_manager/commands/command_response_impl.h" +#include "sdl_rpc_plugin/sdl_rpc_plugin.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +/** + * @brief CancelInteractionResponse command class + **/ +class CancelInteractionResponse + : public app_mngr::commands::CommandResponseImpl { + public: + /** + * @brief CancelInteractionResponse class constructor + * + * @param message Incoming SmartObject message + **/ + CancelInteractionResponse(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 CancelInteractionResponse class destructor + **/ + virtual ~CancelInteractionResponse(); + + /** + * @brief Execute command + **/ + virtual void Run(); + + private: + DISALLOW_COPY_AND_ASSIGN(CancelInteractionResponse); +}; + +} // namespace commands + +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_CANCEL_INTERACTION_RESPONSE_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/change_registration_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/change_registration_request.h index 01f20a68e3..f9f780b84b 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/change_registration_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/change_registration_request.h @@ -123,11 +123,12 @@ class ChangeRegistrationRequest /** * @brief Check parameters (name, vr) for * coincidence with already known parameters of registered applications - * + * @param device_id device identifier * @return SUCCESS if there is no coincidence of app.name/VR synonyms, * otherwise appropriate error code returns */ - mobile_apis::Result::eType CheckCoincidence(); + mobile_apis::Result::eType CheckCoincidence( + const connection_handler::DeviceHandle& device_id); /** * @brief Checks if requested name is allowed by policy diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/create_window_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/create_window_request.h new file mode 100644 index 0000000000..cfbfc460b7 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/create_window_request.h @@ -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. + */ + +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_CREATE_WINDOW_REQUEST_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_CREATE_WINDOW_REQUEST_H_ + +#include "application_manager/commands/command_request_impl.h" +#include "application_manager/hmi_state.h" +#include "utils/macro.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +/** + * @brief CreateWindow request command class + **/ +class CreateWindowRequest : public app_mngr::commands::CommandRequestImpl { + public: + CreateWindowRequest(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); + + ~CreateWindowRequest() FINAL; + + app_mngr::WindowID window_id() const FINAL; + + void Run() FINAL; + + void on_event(const app_mngr::event_engine::Event& event) FINAL; + + /** + * @brief Init sets hash update mode for request + */ + bool Init() FINAL; + + private: + /** + * @brief CheckWindowName checks if provided window_name exists and allowed to + * be created + * @param app pointer to application owns affected window + * @param window_name window name to check + * @return true if window_name is valid, otherwise returns false + */ + bool CheckWindowName(app_mngr::ApplicationSharedPtr app, + const app_mngr::WindowID window_id, + const std::string& window_name) const; + + /** + * @brief ValidateWindowCreation checks whether window can be created + * @return true if window can be created, otherwise returns false + */ + bool ValidateWindowCreation(app_mngr::ApplicationSharedPtr app, + const app_mngr::WindowID window_id); + + /** + * @brief IsWindowForAssociatedServiceCreated check whether a window with + * current associated type has already been created + * @return true if window has been created, otherwise returns false + */ + bool IsWindowForAssociatedServiceCreated( + app_mngr::ApplicationSharedPtr app) const; + + /** + * @brief DoesExceedMaxAllowedWindows check wheter max allowed amount of + * windows is exceeded + * @return true if amount us exceeded, otherwise returns false + */ + bool DoesExceedMaxAllowedWindows(app_mngr::ApplicationSharedPtr app) const; + + /** + * @brief ApplyWindowInitialState apply changes related to window HMI state + * initialization + * @param app pointer to application owns affected window + */ + void ApplyWindowInitialState(app_mngr::ApplicationSharedPtr app) const; + + DISALLOW_COPY_AND_ASSIGN(CreateWindowRequest); +}; + +} // namespace commands + +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_CREATE_WINDOW_REQUEST_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/create_window_response.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/create_window_response.h new file mode 100644 index 0000000000..5163293a7c --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/create_window_response.h @@ -0,0 +1,67 @@ +/* + 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_MOBILE_CREATE_WINDOW_RESPONSE_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_CREATE_WINDOW_RESPONSE_H_ + +#include "application_manager/commands/command_response_impl.h" +#include "utils/macro.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +/** + * @brief CreateWindow response command class + **/ +class CreateWindowResponse : public app_mngr::commands::CommandResponseImpl { + public: + CreateWindowResponse(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); + + ~CreateWindowResponse() FINAL; + + void Run() FINAL; + + private: + DISALLOW_COPY_AND_ASSIGN(CreateWindowResponse); +}; + +} // namespace commands + +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_CREATE_WINDOW_RESPONSE_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/delete_window_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/delete_window_request.h new file mode 100644 index 0000000000..b837724d7b --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/delete_window_request.h @@ -0,0 +1,91 @@ +/* + 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_MOBILE_DELETE_WINDOW_REQUEST_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_DELETE_WINDOW_REQUEST_H_ + +#include "application_manager/commands/command_request_impl.h" +#include "application_manager/hmi_state.h" +#include "utils/macro.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +/** + * @brief CreateWindow request command class + **/ +class DeleteWindowRequest : public app_mngr::commands::CommandRequestImpl { + public: + DeleteWindowRequest(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); + + ~DeleteWindowRequest() FINAL; + + void Run() FINAL; + + void on_event(const app_mngr::event_engine::Event& event) FINAL; + + app_mngr::WindowID window_id() const FINAL; + + /** + * @brief Init sets hash update mode for request + */ + bool Init() FINAL; + + private: + /** + * @brief CheckWindowId checks if provided window_id exists and allowed to be + * deleted + * @param app pointer to application owns affected window + * @return true if window_id is valid, otherwise returns false + */ + bool CheckWindowId(app_mngr::ApplicationSharedPtr app) const; + + /** + * @brief DeleteWindow deletes data related to a request window id + * @param app pointer to applications owns affected window + */ + void DeleteWindow(app_mngr::ApplicationSharedPtr app) const; + + DISALLOW_COPY_AND_ASSIGN(DeleteWindowRequest); +}; + +} // namespace commands + +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_DELETE_WINDOW_REQUEST_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/delete_window_response.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/delete_window_response.h new file mode 100644 index 0000000000..279541724a --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/delete_window_response.h @@ -0,0 +1,67 @@ +/* + 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_MOBILE_DELETE_WINDOW_RESPONSE_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_DELETE_WINDOW_RESPONSE_H_ + +#include "application_manager/commands/command_response_impl.h" +#include "utils/macro.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +/** + * @brief DeleteWindow response command class + **/ +class DeleteWindowResponse : public app_mngr::commands::CommandResponseImpl { + public: + DeleteWindowResponse(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); + + ~DeleteWindowResponse() FINAL; + + void Run() FINAL; + + private: + DISALLOW_COPY_AND_ASSIGN(DeleteWindowResponse); +}; + +} // namespace commands + +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_DELETE_WINDOW_RESPONSE_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h index 0572679c85..52a0ad4dc1 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h @@ -93,6 +93,33 @@ class PerformInteractionRequest */ virtual void onTimeOut(); + protected: + /** + * @brief Prepare result code for sending to mobile application + * @param ui_response contains result_code from HMI response and + * interface that returns response + * @param vr_response 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 app_mngr::commands::ResponseInfo& ui_response, + const app_mngr::commands::ResponseInfo& vr_response); + + /** + * @brief Checks result code from HMI for splitted RPC + * and returns parameter for sending to mobile app. + * @param ui_response contains result_code from HMI response and + * interface that returns response + * @param vr_response 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( + app_mngr::commands::ResponseInfo& out_first, + app_mngr::commands::ResponseInfo& out_second) const; + private: /** * @brief Function will be called when VR_OnCommand event @@ -194,7 +221,7 @@ class PerformInteractionRequest * otherwise returns FALSE. */ bool CheckChoiceIDFromResponse(app_mngr::ApplicationSharedPtr app, - int32_t choice_id); + const int32_t choice_id); /** * @brief Checks for a match of choice ID, in @@ -232,7 +259,27 @@ class PerformInteractionRequest */ void SendBothModeResponse(const smart_objects::SmartObject& msg_param); + /** + * @brief Sends UiClosePopUp request to HMI + */ + void SendClosePopupRequestToHMI(); + + /** + * @brief Sets the choice according to the current interaction mode and first + * received choice id (UI or VR). + * + * @param msg_param Message parameters which will be included in the response + * to mobile device. + * @return Returns false, if choice_id received from UI and VR are valid and + * not equal. Otherwise returns true. + */ + bool SetChoiceIdToResponseMsgParams( + smart_objects::SmartObject& msg_param) const; + mobile_apis::InteractionMode::eType interaction_mode_; + std::int32_t ui_choice_id_received_; + std::int32_t vr_choice_id_received_; + bool ui_response_received_; bool vr_response_received_; bool app_pi_was_active_before_; @@ -241,6 +288,7 @@ class PerformInteractionRequest hmi_apis::Common_Result::eType ui_result_code_; std::string ui_info_; std::string vr_info_; + smart_objects::SmartObject response_msg_params; DISALLOW_COPY_AND_ASSIGN(PerformInteractionRequest); }; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/register_app_interface_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/register_app_interface_request.h index 8a80db9cdf..d59964bbc7 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/register_app_interface_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/register_app_interface_request.h @@ -126,7 +126,7 @@ class RegisterAppInterfaceRequest * * @param app application with changed HMI status * @param resumption If true, resumption-related parameters will be sent to - *the HMI + * the HMI * @param need_restore_vr If resumption is true, whether or not VR commands *should be resumed **/ @@ -134,30 +134,39 @@ class RegisterAppInterfaceRequest app_mngr::ApplicationConstSharedPtr app, bool resumption = false, bool need_restore_vr = false); - /* + + /** * @brief Check new ID along with known mobile application ID * * return TRUE if ID is known already, otherwise - FALSE */ bool IsApplicationWithSameAppIdRegistered(); - /* + /** * @brief Check new application parameters (name, tts, vr) for * coincidence with already known parameters of registered applications - * @param out_duplicate_apps In the case other apps was found with duplicate - * names, this field will be filled with a list of said apps * - * return SUCCESS if there is no coincidence of app.name/TTS/VR synonyms, + * @return SUCCESS if there is no coincidence of app.name/TTS/VR synonyms, * otherwise appropriate error code returns */ - mobile_apis::Result::eType CheckCoincidence( + mobile_apis::Result::eType CheckCoincidence(); + + /** + * @brief Search for any apps with the same appName as the one being + * registered + * @param out_duplicate_apps To be filled with a list of all of the apps which + * have duplicate appNames to the app being registered (registered or pending) + * + * @return TRUE if at least one duplicate app was found, otherwise FALSE + */ + bool GetDuplicateNames( std::vector<app_mngr::ApplicationSharedPtr>& out_duplicate_apps); - /* + /** * @brief Predicate for using with CheckCoincidence method to compare with VR * synonym SO * - * return TRUE if there is coincidence of VR, otherwise FALSE + * @return TRUE if there is coincidence of VR, otherwise FALSE */ struct CoincidencePredicateVR { CoincidencePredicateVR(const custom_str::CustomString& newItem) @@ -207,17 +216,31 @@ class RegisterAppInterfaceRequest void SendSubscribeCustomButtonNotification(); /** - * @brief IsApplicationSwitched checks whether application is switched from - * another transport. If application id is found, but not in reconnection + * @brief IsApplicationSwitched checks whether application is switched + * from another transport. If application id is found, but not in reconnection * list, returns 'already registered' code. Otherwise - proceed with * switching. * @return True if application is detected as switched, otherwise false. */ bool IsApplicationSwitched(); + /** + * @brief Information about given Connection Key. + * @param key Unique key used by other components as session identifier + * @param device_id device identifier. + * @param mac_address uniq address + * @return false in case of error or true in case of success + */ + bool GetDataOnSessionKey( + const uint32_t key, + connection_handler::DeviceHandle* device_id = nullptr, + std::string* mac_address = nullptr) const; + private: std::string response_info_; mobile_apis::Result::eType result_code_; + connection_handler::DeviceHandle device_handle_; + std::string device_id_; policy::PolicyHandlerInterface& GetPolicyHandler(); DISALLOW_COPY_AND_ASSIGN(RegisterAppInterfaceRequest); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/set_app_icon_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/set_app_icon_request.h index 86ca2fb126..520f27d8b9 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/set_app_icon_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/set_app_icon_request.h @@ -83,9 +83,11 @@ class SetAppIconRequest : public app_mngr::commands::CommandRequestImpl { private: /** * @brief Copies file to icon storage + * @param policy_app_id application policy app id * @param path_to_file Path to icon */ - void CopyToIconStorage(const std::string& path_to_file) const; + void CopyToIconStorage(const std::string& policy_app_id, + const std::string& path_to_file) const; /** * @brief Remove oldest icons @@ -108,6 +110,11 @@ class SetAppIconRequest : public app_mngr::commands::CommandRequestImpl { * @brief Checks, if icons saving to configured folder is enabled */ bool is_icons_saving_enabled_; + + /** + * @brief Contains full file path to icon + */ + std::string full_file_path_for_hmi_; }; } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/set_global_properties_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/set_global_properties_request.h index e84bf6e5e6..3a32d1b671 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/set_global_properties_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/set_global_properties_request.h @@ -82,7 +82,76 @@ class SetGlobalPropertiesRequest */ bool Init() FINAL; + /** + * @brief Prepares total result for mobile according to three results: + * ui_properties_result, tts_properties_result, rc_properties_result. + * @param first ResponseInfo as first argument + * @param second ResponseInfo as secondargument + * @param third ResponseInfo as third argument + * @return total result + */ + bool PrepareResultForMobileResponse( + const app_mngr::commands::ResponseInfo& first, + const app_mngr::commands::ResponseInfo& second, + const app_mngr::commands::ResponseInfo& third) const; + + /** + * @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. + * * @param third 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 app_mngr::commands::ResponseInfo& first, + const app_mngr::commands::ResponseInfo& second, + const app_mngr::commands::ResponseInfo& third); + + /** + * @brief Resolves if the return code must be + * UNSUPPORTED_RESOURCE + * @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. + * * @param third contains result_code from HMI response and + * interface that returns response. + * @return True, if the communication return code must be + * UNSUPPORTED_RESOURCE, otherwise false. + */ + bool IsResultCodeUnsupported( + const app_mngr::commands::ResponseInfo& first, + const app_mngr::commands::ResponseInfo& second, + const app_mngr::commands::ResponseInfo& third) const; + private: + /** + * @brief MergeInfos merge 2 infos into one string with info + * @param first_info -contains result_code from HMI response and + * interface that returns response + * @param first_str - info string that should be first in result info + * @param second_info -contains result_code from HMI response and + * interface that returns response + * @param second_str - info string that should be second in result info + * @param third_info - contains result_code from HMI response and + * interface that returns response + * @param third_str - info string that should be third in result info + * @return if first_info is not available and second_str and third_info not + * empty return second if second_info is not available and first_str and + * third_info not empty return first if third_info is not available and + * first_str and second_str not empty return first other cases return result + * MergeInfos for 2 params + */ + std::string MergeInfos(const app_mngr::commands::ResponseInfo& first_info, + const std::string& first_str, + const app_mngr::commands::ResponseInfo& second_info, + const std::string& second_str, + const app_mngr::commands::ResponseInfo& third_info, + const std::string& third_str); + // prepare UI sending data (VrHelps, Menus, Keyboard) to SmartObject static void PrepareUIRequestVRHelpData( const app_mngr::ApplicationSharedPtr app, @@ -101,6 +170,9 @@ class SetGlobalPropertiesRequest // Send UI request to HMI void SendUIRequest(const smart_objects::SmartObject& params, bool use_events); + // Send SetGlobalProperties with userLocation parameter + void SendRCRequest(const smart_objects::SmartObject& params, bool use_events); + // VRHelp shall contain sequential positions and start from 1 static bool CheckVrHelpItemsOrder(const smart_objects::SmartObject& vr_help); @@ -140,14 +212,20 @@ class SetGlobalPropertiesRequest bool is_ui_send_; bool is_tts_send_; + bool is_rc_send_; bool is_ui_received_; bool is_tts_received_; + bool is_rc_received_; 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 tts_response_info_; + std::string rc_response_info_; + + bool is_menu_layout_available_ = true; DISALLOW_COPY_AND_ASSIGN(SetGlobalPropertiesRequest); }; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/show_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/show_request.h index 586004b783..26612609a4 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/show_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/show_request.h @@ -90,8 +90,33 @@ class ShowRequest : public app_mngr::commands::CommandRequestImpl { int32_t field_index, smart_objects::SmartObject& msg_params); + /** + * @brief Handle the template configuration information from the + * incoming mobile json message format for specified application + * @param app - application for which configuration should be checked + * @return True if template config can be successfully applied otherwise - + * false + */ + bool CheckTemplateConfigurationForApp(application_manager::Application& app); + + /** + * @brief Applies the template configuration which was set up beforehand + * @param result - result code on which template application is dependent + * @param app - application for which configuration should be applied + */ + void ApplyTemplateConfigurationForApp(mobile_apis::Result::eType result, + application_manager::Application& app); + mobile_apis::Result::eType core_result_code_; std::string core_response_info_; + app_mngr::WindowID current_window_id_; + smart_objects::SmartObject template_config_; + bool layout_change_required_; + + // dcs - abbreviation of Day Color Scheme + bool dcs_change_required_; + // ncd - abbreviation of Night Color Scheme + bool ncs_change_required_; DISALLOW_COPY_AND_ASSIGN(ShowRequest); }; 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 7d482709cb..9c770279ab 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 @@ -47,7 +47,15 @@ class SDLRPCPlugin : public plugins::RPCPlugin { bool Init(app_mngr::ApplicationManager& app_manager, app_mngr::rpc_service::RPCService& rpc_service, app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) OVERRIDE; + 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; bool IsAbleToProcess( const int32_t function_id, @@ -67,5 +75,5 @@ class SDLRPCPlugin : public plugins::RPCPlugin { } // namespace sdl_rpc_plugin extern "C" application_manager::plugin_manager::RPCPlugin* Create(); - +extern "C" void Delete(application_manager::plugin_manager::RPCPlugin* data); #endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_SDL_RPC_PLUGIN_H diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/basic_communication_get_system_time_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/basic_communication_get_system_time_request.cc index fb87612e19..19c9fa91d8 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/basic_communication_get_system_time_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/basic_communication_get_system_time_request.cc @@ -51,7 +51,7 @@ BasicCommunicationGetSystemTimeRequest::BasicCommunicationGetSystemTimeRequest( void BasicCommunicationGetSystemTimeRequest::onTimeOut() { LOG4CXX_AUTO_TRACE(logger_); - application_manager_.protocol_handler().NotifyOnFailedHandshake(); + application_manager_.protocol_handler().NotifyOnGetSystemTimeFailed(); } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/bc_get_app_properties_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/bc_get_app_properties_request.cc new file mode 100644 index 0000000000..0dafa21e33 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/bc_get_app_properties_request.cc @@ -0,0 +1,144 @@ +/* + Copyright (c) 2020, Ford Motor Company, Livio + 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 the copyright holders nor the names of their + 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/bc_get_app_properties_request.h" +#include "application_manager/policies/policy_handler_interface.h" +#include "application_manager/rpc_service.h" +#include "interfaces/MOBILE_API.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; +namespace commands { + +BCGetAppPropertiesRequest::BCGetAppPropertiesRequest( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : RequestFromHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +void BCGetAppPropertiesRequest::FillAppProperties( + const std::string& policy_app_id, + smart_objects::SmartObject& out_properties) const { + LOG4CXX_AUTO_TRACE(logger_); + + policy::AppProperties app_properties; + const bool result = + policy_handler_.GetAppProperties(policy_app_id, app_properties); + + if (!result) { + LOG4CXX_DEBUG( + logger_, + "Failed to get app parameters for policy_app_id: " << policy_app_id); + return; + } + + out_properties[strings::policy_app_id] = policy_app_id; + out_properties[strings::enabled] = app_properties.enabled; + + policy::StringArray nicknames; + policy::StringArray app_hmi_types; + + policy_handler_.GetInitialAppData(policy_app_id, &nicknames, &app_hmi_types); + + smart_objects::SmartObject nicknames_array(smart_objects::SmartType_Array); + size_t i = 0; + for (const auto& nickname : nicknames) { + nicknames_array[i++] = nickname; + } + out_properties[strings::nicknames] = nicknames_array; + + if (!app_properties.auth_token.empty()) { + out_properties[strings::auth_token] = app_properties.auth_token; + } + if (!app_properties.transport_type.empty()) { + out_properties[strings::transport_type] = app_properties.transport_type; + } + if (!app_properties.hybrid_app_preference.empty()) { + out_properties[strings::hybrid_app_preference] = + app_properties.hybrid_app_preference; + } + if (!app_properties.endpoint.empty()) { + out_properties[strings::endpoint] = app_properties.endpoint; + } +} + +void BCGetAppPropertiesRequest::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + const auto& msg_params = (*message_)[strings::msg_params]; + smart_objects::SmartObject response_params(smart_objects::SmartType_Map); + + if (msg_params.keyExists(strings::policy_app_id)) { + const auto policy_app_id = msg_params[strings::policy_app_id].asString(); + smart_objects::SmartObject properties(smart_objects::SmartType_Map); + FillAppProperties(policy_app_id, properties); + if (!properties.empty()) { + response_params[strings::properties][0] = properties; + } + } else { + LOG4CXX_DEBUG(logger_, + "policyAppID was absent in request, all apps properties " + "will be returned."); + const auto app_ids = policy_handler_.GetApplicationPolicyIDs(); + int i = 0; + for (auto& app_id : app_ids) { + smart_objects::SmartObject properties(smart_objects::SmartType_Map); + FillAppProperties(app_id, properties); + response_params[strings::properties][i++] = properties; + } + } + + if (response_params[strings::properties].empty()) { + SendErrorResponse( + (*message_)[strings::params][strings::correlation_id].asUInt(), + hmi_apis::FunctionID::BasicCommunication_GetAppProperties, + hmi_apis::Common_Result::DATA_NOT_AVAILABLE, + "Requested data not available", + application_manager::commands::Command::SOURCE_SDL_TO_HMI); + return; + } + + SendResponse(true, + (*message_)[strings::params][strings::correlation_id].asUInt(), + hmi_apis::FunctionID::BasicCommunication_GetAppProperties, + hmi_apis::Common_Result::SUCCESS, + &response_params); +} + +} // namespace commands +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/bc_get_app_properties_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/bc_get_app_properties_response.cc new file mode 100644 index 0000000000..57949a949b --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/bc_get_app_properties_response.cc @@ -0,0 +1,60 @@ +/* + Copyright (c) 2020, Ford Motor Company, Livio + 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 the copyright holders nor the names of their + 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/bc_get_app_properties_response.h" +#include "application_manager/application_impl.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/rpc_service.h" +#include "interfaces/MOBILE_API.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; +namespace commands { + +BCGetAppPropertiesResponse::BCGetAppPropertiesResponse( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : ResponseToHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +void BCGetAppPropertiesResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + rpc_service_.SendMessageToHMI(message_); +} +} // namespace commands +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/bc_set_app_properties_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/bc_set_app_properties_request.cc new file mode 100644 index 0000000000..a4c5d6b1b4 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/bc_set_app_properties_request.cc @@ -0,0 +1,114 @@ +/* + Copyright (c) 2020, Ford Motor Company, Livio + 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 the copyright holders nor the names of their + 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/bc_set_app_properties_request.h" +#include "application_manager/message_helper.h" +#include "application_manager/policies/policy_handler_interface.h" +#include "application_manager/rpc_service.h" +#include "interfaces/MOBILE_API.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; +namespace commands { + +BCSetAppPropertiesRequest::BCSetAppPropertiesRequest( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : RequestFromHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +void BCSetAppPropertiesRequest::Run() { + LOG4CXX_AUTO_TRACE(logger_); + const auto& properties = + (*message_)[strings::msg_params][strings::properties]; + + const auto policy_app_id(properties[strings::policy_app_id].asString()); + + const auto properties_change_status = + policy_handler_.GetAppPropertiesStatus(properties, policy_app_id); + + using AppPropertiesState = policy::PolicyHandlerInterface::AppPropertiesState; + const bool are_properties_changed = + AppPropertiesState::NO_CHANGES != properties_change_status; + + const bool is_new_app = policy_handler_.IsNewApplication(policy_app_id); + + policy_handler_.OnSetAppProperties(properties); + SendResponse(true, + (*message_)[strings::params][strings::correlation_id].asUInt(), + hmi_apis::FunctionID::BasicCommunication_SetAppProperties, + hmi_apis::Common_Result::SUCCESS); + + if (are_properties_changed || is_new_app) { + const auto notification = + MessageHelper::CreateOnAppPropertiesChangeNotification( + policy_app_id, application_manager_); + application_manager_.GetRPCService().ManageHMICommand(notification); + } + if (is_new_app) { + LOG4CXX_ERROR(logger_, + "Message contains unknow policyAppId: " + << policy_app_id << ", PTU will be triggered"); + policy_handler_.OnLocalAppAdded(); + } + + auto app_enabled = [this]() -> bool { + auto& properties = (*message_)[strings::msg_params][strings::properties]; + if (properties.keyExists(strings::enabled)) { + return properties[strings::enabled].asBool(); + } + return false; + }; + + const bool enable_flag_switch = + AppPropertiesState::ENABLED_FLAG_SWITCH == properties_change_status; + + if (app_enabled() && (enable_flag_switch || is_new_app)) { + application_manager_.CreatePendingLocalApplication(policy_app_id); + application_manager_.SendUpdateAppList(); + return; + } + + if (enable_flag_switch) { + application_manager_.RemovePendingApplication(policy_app_id); + application_manager_.SendUpdateAppList(); + } +} + +} // namespace commands +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/bc_set_app_properties_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/bc_set_app_properties_response.cc new file mode 100644 index 0000000000..928a17d0f8 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/bc_set_app_properties_response.cc @@ -0,0 +1,62 @@ +/* + Copyright (c) 2020, Ford Motor Company, Livio + 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 the copyright holders nor the names of their + 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/bc_set_app_properties_response.h" +#include "application_manager/application_impl.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/policies/policy_handler_interface.h" +#include "application_manager/rpc_service.h" +#include "interfaces/MOBILE_API.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; +namespace commands { + +BCSetAppPropertiesResponse::BCSetAppPropertiesResponse( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : ResponseToHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +void BCSetAppPropertiesResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + rpc_service_.SendMessageToHMI(message_); +} + +} // namespace commands +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/get_system_info_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/get_system_info_response.cc index 3dbdf528a5..baff925a4e 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/get_system_info_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/get_system_info_response.cc @@ -31,6 +31,7 @@ */ #include "sdl_rpc_plugin/commands/hmi/get_system_info_response.h" #include "application_manager/message_helper.h" +#include "application_manager/policies/policy_handler_interface.h" namespace sdl_rpc_plugin { using namespace application_manager; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/get_urls.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/get_urls.cc deleted file mode 100644 index 54a9633a37..0000000000 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/get_urls.cc +++ /dev/null @@ -1,230 +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. - */ - -#include "sdl_rpc_plugin/commands/hmi/get_urls.h" -#include "application_manager/application_manager.h" -#include "application_manager/message.h" -#include "application_manager/policies/policy_handler.h" -#include "application_manager/rpc_service.h" -#include "utils/helpers.h" - -namespace sdl_rpc_plugin { -using namespace application_manager; -namespace commands { - -GetUrls::GetUrls(const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle) - : RequestFromHMI(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handle) {} - -GetUrls::~GetUrls() {} - -void GetUrls::Run() { - LOG4CXX_AUTO_TRACE(logger_); - namespace Common_Result = hmi_apis::Common_Result; - using policy::EndpointUrls; - - if (!policy_handler_.PolicyEnabled()) { - SendResponseToHMI(Common_Result::DATA_NOT_AVAILABLE); - return; - } - - const uint32_t service_to_check = - (*message_)[strings::msg_params][hmi_request::service].asUInt(); - - EndpointUrls endpoints; - policy_handler_.GetUpdateUrls(service_to_check, endpoints); - - if (endpoints.empty()) { - LOG4CXX_ERROR(logger_, "No URLs for service " << service_to_check); - SendResponseToHMI(Common_Result::DATA_NOT_AVAILABLE); - return; - } - -#ifdef PROPRIETARY_MODE - const uint32_t policy_service = 7u; - - if (policy_service == service_to_check) { - ProcessPolicyServiceURLs(endpoints); - return; - } -#endif // PROPRIETARY_MODE - - ProcessServiceURLs(endpoints); -} - -void GetUrls::ProcessServiceURLs(const policy::EndpointUrls& endpoints) { - namespace Common_Result = hmi_apis::Common_Result; - using smart_objects::SmartObject; - - (*message_)[strings::msg_params].erase(hmi_request::service); - SmartObject& urls = (*message_)[strings::msg_params][hmi_response::urls]; - - size_t index = 0; - for (size_t e = 0; e < endpoints.size(); ++e) { - ApplicationSharedPtr app = - application_manager_.application_by_policy_id(endpoints[e].app_id); - -#ifndef PROPRIETARY_MODE - bool registered_not_default = false; - if (policy::kDefaultId != endpoints[e].app_id) { - if (!app) { - LOG4CXX_ERROR(logger_, - "Can't find application with policy id " - << endpoints[e].app_id - << " URLs adding for this application is skipped."); - continue; - } - registered_not_default = true; - } -#endif // EXTERNAL_PROPRIETARY_MODE || HTTP - for (size_t u = 0; u < endpoints[e].url.size(); ++u, ++index) { - const std::string& app_url = endpoints[e].url[u]; - SmartObject& service_info = urls[index]; - - service_info[strings::url] = app_url; -#ifndef PROPRIETARY_MODE - if (registered_not_default) { - service_info[strings::app_id] = app->hmi_app_id(); - } -#else // EXTERNAL_PROPRIETARY_MODE || HTTP - service_info[hmi_response::policy_app_id] = endpoints[e].app_id; -#endif - } - } - SendResponseToHMI(Common_Result::SUCCESS); -} - -void GetUrls::SendResponseToHMI(hmi_apis::Common_Result::eType result) { - (*message_)[strings::params][strings::message_type] = MessageType::kResponse; - (*message_)[strings::params][hmi_response::code] = result; - rpc_service_.ManageHMICommand(message_); -} - -#ifdef PROPRIETARY_MODE -struct PolicyAppIdComparator { - PolicyAppIdComparator(const std::string& policy_app_id) - : policy_app_id_(policy_app_id) {} - - bool operator()(const policy::EndpointData& data) { - return data.app_id == policy_app_id_; - } - std::string policy_app_id_; -}; - -void FillSODefaultUrls(smart_objects::SmartObject& urls, - const policy::EndpointUrls& endpoints) { - using smart_objects::SmartObject; - PolicyAppIdComparator comparator(policy::kDefaultId); - policy::EndpointUrls::const_iterator it = - std::find_if(endpoints.begin(), endpoints.end(), comparator); - if (it == endpoints.end()) { - return; - } - SmartObject service_info = SmartObject(smart_objects::SmartType_Map); - for (size_t i = 0; i < (*it).url.size(); ++i) { - service_info[strings::url] = (*it).url[i]; - urls[i] = service_info; - } -} - -void GetUrls::ProcessPolicyServiceURLs(const policy::EndpointUrls& endpoints) { - LOG4CXX_AUTO_TRACE(logger_); - using namespace smart_objects; - using namespace application_manager; - using namespace strings; - using namespace hmi_apis; - - const uint32_t app_id_to_send_to = policy_handler_.GetAppIdForSending(); - - if (!app_id_to_send_to) { - LOG4CXX_ERROR(logger_, - "There are no available applications for processing."); - SmartObject urls(SmartType_Array); - FillSODefaultUrls(urls, endpoints); - if (!urls.empty()) { - (*message_)[msg_params][hmi_response::urls] = urls; - } - (*message_).erase(hmi_request::service); - SendResponseToHMI(Common_Result::SUCCESS); - return; - } - - ApplicationSharedPtr app = - application_manager_.application(app_id_to_send_to); - - if (app.use_count() == 0) { - LOG4CXX_WARN(logger_, - "There is no registered application with " - "connection key '" - << app_id_to_send_to << "'"); - SendResponseToHMI(Common_Result::DATA_NOT_AVAILABLE); - return; - } - - SmartObject& object = *message_; - object[msg_params].erase(hmi_request::service); - object[msg_params][hmi_response::urls] = SmartObject(SmartType_Array); - SmartObject& urls = object[msg_params][hmi_response::urls]; - const std::string mobile_app_id = app->policy_app_id(); - - size_t index = 0; - for (size_t i = 0; i < endpoints.size(); ++i) { - using namespace helpers; - - const bool to_add = Compare<std::string, EQ, ONE>( - endpoints[i].app_id, mobile_app_id, policy::kDefaultId); - const bool is_default = policy::kDefaultId == endpoints[i].app_id; - - if (to_add) { - for (size_t k = 0; k < endpoints[i].url.size(); ++k) { - if (!is_default) { - urls[index][strings::app_id] = app_id_to_send_to; - } - urls[index][strings::url] = endpoints[i].url[k]; - ++index; - } - } - } - SendResponseToHMI(Common_Result::SUCCESS); - return; -} -#endif // PROPRIETARY_MODE - -} // namespace commands -} // namespace sdl_rpc_plugin 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 371f47a759..47f2f2505e 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 @@ -113,7 +113,7 @@ void AudioStartStreamRequest::on_event(const event_engine::Event& event) { if (hmi_apis::Common_Result::SUCCESS == code) { LOG4CXX_INFO(logger_, "StartAudioStream response SUCCESS"); - if (application_manager_.HMILevelAllowsStreaming(app->app_id(), + if (application_manager_.HMIStateAllowsStreaming(app->app_id(), ServiceType::kAudio)) { app->set_audio_streaming_approved(true); } else { @@ -171,11 +171,11 @@ void AudioStartStreamRequest::RetryStartSession() { } uint32_t curr_retry_number = app->audio_stream_retry_number(); - LOG4CXX_DEBUG( - logger_, "Retry number " << curr_retry_number << " of " << retry_number_); - if (curr_retry_number < retry_number_) { - LOG4CXX_DEBUG(logger_, "Send AudioStartStream retry"); + if (curr_retry_number <= retry_number_) { + LOG4CXX_DEBUG( + logger_, + "Retry number " << curr_retry_number << " of " << retry_number_); MessageHelper::SendAudioStartStream(app->app_id(), application_manager_); app->set_audio_stream_retry_number(++curr_retry_number); } else { 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 7f643d6130..00974085c3 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 @@ -64,8 +64,9 @@ NaviStartStreamRequest::NaviStartStreamRequest( } NaviStartStreamRequest::~NaviStartStreamRequest() { - // unsubscribe_from_all_events() in EventObserver's destructor isn't enough; - // we must unsubscribe before this NaviStartStreamRequest instance is removed + // unsubscribe_from_all_hmi_events() in EventObserver's destructor isn't + // enough; we must unsubscribe before this NaviStartStreamRequest instance is + // removed unsubscribe_from_event(hmi_apis::FunctionID::Navigation_StartStream); } @@ -114,7 +115,7 @@ void NaviStartStreamRequest::on_event(const event_engine::Event& event) { if (hmi_apis::Common_Result::SUCCESS == code) { LOG4CXX_INFO(logger_, "NaviStartStreamResponse SUCCESS"); - if (application_manager_.HMILevelAllowsStreaming( + if (application_manager_.HMIStateAllowsStreaming( app->app_id(), ServiceType::kMobileNav)) { app->set_video_streaming_approved(true); } else { @@ -172,11 +173,11 @@ void NaviStartStreamRequest::RetryStartSession() { } uint32_t curr_retry_number = app->video_stream_retry_number(); - LOG4CXX_DEBUG( - logger_, "Retry number " << curr_retry_number << " of " << retry_number_); - if (curr_retry_number < retry_number_) { - LOG4CXX_DEBUG(logger_, "Send NaviStartStream retry"); + if (curr_retry_number <= retry_number_) { + LOG4CXX_DEBUG( + logger_, + "Retry number " << curr_retry_number << " of " << retry_number_); MessageHelper::SendNaviStartStream(app->app_id(), application_manager_); app->set_video_stream_retry_number(++curr_retry_number); } else { diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_app_properties_change_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_app_properties_change_notification.cc new file mode 100644 index 0000000000..f1fa703bbb --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_app_properties_change_notification.cc @@ -0,0 +1,59 @@ +/* + * 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 "sdl_rpc_plugin/commands/hmi/on_app_properties_change_notification.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; + +namespace commands { + +OnAppPropertiesChangeNotification::OnAppPropertiesChangeNotification( + 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) {} + +void OnAppPropertiesChangeNotification::Run() { + LOG4CXX_AUTO_TRACE(logger_); + SendNotification(); +} + +} // namespace commands + +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_bc_system_capability_updated_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_bc_system_capability_updated_notification.cc index 37dca47793..1a104c0fa1 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_bc_system_capability_updated_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_bc_system_capability_updated_notification.cc @@ -161,6 +161,15 @@ void OnBCSystemCapabilityUpdatedNotification::Run() { [strings::app_services_capabilities] = app_service_caps; break; } + case mobile_apis::SystemCapabilityType::DISPLAYS: { + if (!hmi_capabilities_.system_display_capabilities()) { + LOG4CXX_INFO(logger_, "system_display_capabilities are not available"); + return; + } + msg_params[strings::system_capability][strings::display_capabilities] = + *hmi_capabilities_.system_display_capabilities(); + break; + } default: return; } 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..f32aef1102 --- /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,145 @@ +/* + * 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/display_capabilities_builder.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() {} + +OnBCSystemCapabilityUpdatedNotificationFromHMI:: + ProcessSystemDisplayCapabilitiesResult + 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 ProcessSystemDisplayCapabilitiesResult::SUCCESS; + } + + 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 ProcessSystemDisplayCapabilitiesResult::FAIL; + } + + 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); + if (app->is_resuming() && app->is_app_data_resumption_allowed()) { + LOG4CXX_DEBUG(logger_, "Application is resuming"); + app->display_capabilities_builder().UpdateDisplayCapabilities( + display_capabilities); + return ProcessSystemDisplayCapabilitiesResult::CAPABILITIES_CACHED; + } + + return ProcessSystemDisplayCapabilitiesResult::SUCCESS; +} + +void OnBCSystemCapabilityUpdatedNotificationFromHMI::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + // Prepare SmartObject for mobile factory + (*message_)[strings::params][strings::function_id] = static_cast<int32_t>( + mobile_apis::FunctionID::OnSystemCapabilityUpdatedID); + + const auto& system_capability = + (*message_)[strings::msg_params][strings::system_capability]; + + switch (system_capability[strings::system_capability_type].asInt()) { + case mobile_apis::SystemCapabilityType::DISPLAYS: { + if (system_capability.keyExists(strings::display_capabilities)) { + const auto result = ProcessSystemDisplayCapabilities( + system_capability[strings::display_capabilities]); + if (ProcessSystemDisplayCapabilitiesResult::FAIL == result) { + LOG4CXX_ERROR( + logger_, + "Failed to process display capabilities. Notification will " + "be ignored"); + return; + } else if (ProcessSystemDisplayCapabilitiesResult:: + CAPABILITIES_CACHED == result) { + LOG4CXX_TRACE(logger_, + "Capabilities are being cached for resuming app"); + return; + } + } + break; + } + case mobile_apis::SystemCapabilityType::REMOTE_CONTROL: { + if (system_capability.keyExists(strings::rc_capability)) { + LOG4CXX_DEBUG(logger_, "Updating RC Capabilities"); + hmi_capabilities_.set_rc_capability( + system_capability[strings::rc_capability]); + } + break; + } + } + + SendNotificationToMobile(message_); +} + +} // namespace commands + +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_device_state_changed_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_device_state_changed_notification.cc index 9ddd822b1c..129ba8c9ba 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_device_state_changed_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_device_state_changed_notification.cc @@ -34,6 +34,7 @@ #include <algorithm> #include "application_manager/application_manager.h" #include "application_manager/message_helper.h" +#include "application_manager/policies/policy_handler_interface.h" #include "encryption/hashing.h" #include "interfaces/HMI_API.h" diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_driver_distraction_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_driver_distraction_notification.cc index 4229369acc..a743c58672 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_driver_distraction_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_driver_distraction_notification.cc @@ -35,6 +35,7 @@ #include "application_manager/application_impl.h" #include "application_manager/message_helper.h" +#include "application_manager/policies/policy_handler_interface.h" #include "interfaces/HMI_API.h" #include "interfaces/MOBILE_API.h" @@ -65,7 +66,11 @@ struct OnDriverDistractionProcessor { const RPCParams params; policy::CheckPermissionResult result; application_manager_.GetPolicyHandler().CheckPermissions( - application, stringified_function_id_, params, result); + application, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, + stringified_function_id_, + params, + result); auto& msg_params = message[strings::msg_params]; const bool is_lock_screen_dismissal_exists = msg_params.keyExists( mobile_notification::lock_screen_dismissal_enabled); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_exit_application_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_exit_application_notification.cc index 11647e2140..3eec6c5d1a 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_exit_application_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_exit_application_notification.cc @@ -119,12 +119,7 @@ void OnExitApplicationNotification::Run() { } } - application_manager_.state_controller().SetRegularState( - app_impl, - HMILevel::HMI_NONE, - AudioStreamingState::NOT_AUDIBLE, - VideoStreamingState::NOT_STREAMABLE, - false); + application_manager_.state_controller().ExitDefaultWindow(app_impl); } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ignition_cycle_over_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ignition_cycle_over_notification.cc index 9c2c68989f..1e8da19c0a 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ignition_cycle_over_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ignition_cycle_over_notification.cc @@ -32,6 +32,7 @@ #include "sdl_rpc_plugin/commands/hmi/on_ignition_cycle_over_notification.h" #include "application_manager/application_manager.h" +#include "application_manager/policies/policy_handler_interface.h" namespace sdl_rpc_plugin { using namespace application_manager; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_policy_update.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_policy_update.cc index 67352fbc4a..a0e75371b5 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_policy_update.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_policy_update.cc @@ -32,6 +32,7 @@ #include "sdl_rpc_plugin/commands/hmi/on_policy_update.h" #include "application_manager/application_manager.h" +#include "application_manager/policies/policy_handler_interface.h" namespace sdl_rpc_plugin { using namespace application_manager; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_received_policy_update.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_received_policy_update.cc index 4a8c8df0ee..b2c9151b40 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_received_policy_update.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_received_policy_update.cc @@ -33,6 +33,7 @@ #include "sdl_rpc_plugin/commands/hmi/on_received_policy_update.h" #include <string> #include "application_manager/application_manager.h" +#include "application_manager/policies/policy_handler_interface.h" #include "utils/file_system.h" namespace sdl_rpc_plugin { diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_service_update_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_service_update_notification.cc new file mode 100644 index 0000000000..de03b75214 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_service_update_notification.cc @@ -0,0 +1,63 @@ +/* + * 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_service_update_notification.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; + +namespace commands { + +namespace hmi { + +OnServiceUpdateNotification::OnServiceUpdateNotification( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + rpc_service::RPCService& rpc_service, + HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : NotificationToHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +OnServiceUpdateNotification::~OnServiceUpdateNotification() {} + +void OnServiceUpdateNotification::Run() { + LOG4CXX_AUTO_TRACE(logger_); + SendNotification(); +} + +} // namespace hmi +} // namespace commands +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_context_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_context_notification.cc index 38b87f23d3..bf52492ae1 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_context_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_context_notification.cc @@ -62,13 +62,27 @@ void OnSystemContextNotification::Run() { (*message_)[strings::msg_params][hmi_notification::system_context] .asInt()); + WindowID window_id = mobile_apis::PredefinedWindows::DEFAULT_WINDOW; + if ((*message_)[strings::msg_params].keyExists(strings::window_id)) { + window_id = (*message_)[strings::msg_params][strings::window_id].asInt(); + } + ApplicationSharedPtr app; - if ((mobile_api::SystemContext::SYSCTXT_VRSESSION == system_context) || - (mobile_api::SystemContext::SYSCTXT_MENU == system_context) || - (mobile_api::SystemContext::SYSCTXT_HMI_OBSCURED == system_context)) { + if (helpers:: + Compare<mobile_api::SystemContext::eType, helpers::EQ, helpers::ONE>( + system_context, + mobile_api::SystemContext::SYSCTXT_VRSESSION, + mobile_api::SystemContext::SYSCTXT_MENU, + mobile_api::SystemContext::SYSCTXT_HMI_OBSCURED)) { app = application_manager_.active_application(); - } else if ((mobile_api::SystemContext::SYSCTXT_ALERT == system_context) || - (mobile_api::SystemContext::SYSCTXT_MAIN == system_context)) { + } + + if (mobile_apis::PredefinedWindows::DEFAULT_WINDOW != window_id || + helpers::Compare<mobile_api::SystemContext::eType, + helpers::EQ, + helpers::ONE>(system_context, + mobile_api::SystemContext::SYSCTXT_ALERT, + mobile_api::SystemContext::SYSCTXT_MAIN)) { if ((*message_)[strings::msg_params].keyExists(strings::app_id)) { app = application_manager_.application( (*message_)[strings::msg_params][strings::app_id].asUInt()); @@ -76,8 +90,8 @@ void OnSystemContextNotification::Run() { } if (app && mobile_api::SystemContext::INVALID_ENUM != system_context) { - application_manager_.state_controller().SetRegularState(app, - system_context); + application_manager_.state_controller().SetRegularState( + app, window_id, system_context); } else { LOG4CXX_ERROR(logger_, "Application does not exist"); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_error_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_error_notification.cc index 6a5ee4fce4..9b8523e882 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_error_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_error_notification.cc @@ -32,6 +32,7 @@ #include "sdl_rpc_plugin/commands/hmi/on_system_error_notification.h" #include "application_manager/application_manager.h" +#include "application_manager/policies/policy_handler_interface.h" #include "interfaces/HMI_API.h" namespace sdl_rpc_plugin { diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_info_changed_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_info_changed_notification.cc index b7ba6951fb..171c144055 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_info_changed_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_info_changed_notification.cc @@ -33,6 +33,7 @@ #include "sdl_rpc_plugin/commands/hmi/on_system_info_changed_notification.h" #include "application_manager/application_manager.h" #include "application_manager/message_helper.h" +#include "application_manager/policies/policy_handler_interface.h" namespace sdl_rpc_plugin { using namespace application_manager; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_request_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_request_notification.cc index a9670681b2..4f83e3e653 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_request_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_request_notification.cc @@ -37,6 +37,10 @@ #include "sdl_rpc_plugin/commands/hmi/on_system_request_notification.h" #include "utils/macro.h" +#ifdef EXTERNAL_PROPRIETARY_MODE +#include "policy/ptu_retry_handler.h" +#endif // EXTERNAL_PROPRIETARY_MODE + using policy::PolicyHandlerInterface; namespace sdl_rpc_plugin { @@ -67,6 +71,39 @@ void OnSystemRequestNotification::Run() { params[strings::function_id] = static_cast<int32_t>(mobile_apis::FunctionID::eType::OnSystemRequestID); + using namespace rpc::policy_table_interface_base; + const auto request_type = + static_cast<rpc::policy_table_interface_base::RequestType>( + (*message_)[strings::msg_params][strings::request_type].asUInt()); + +#ifdef PROPRIETARY_MODE + if (RequestType::RT_PROPRIETARY == request_type) { + if (msg_params.keyExists(strings::url)) { + // For backward-compatibility, the URL is cached for retries if provided + // by HMI + policy_handler_.CacheRetryInfo(msg_params.keyExists(strings::app_id) + ? msg_params[strings::app_id].asUInt() + : 0, + msg_params[strings::url].asString(), + msg_params[strings::file_name].asString()); + } else { + // Clear cached retry info + policy_handler_.CacheRetryInfo( + 0, std::string(), msg_params[strings::file_name].asString()); + + // URL and app are chosen by Core for PROPRIETARY mode normally + uint32_t app_id = 0; + msg_params[strings::url] = policy_handler_.GetNextUpdateUrl( + policy::PTUIterationType::DefaultIteration, app_id); + if (0 == app_id) { + LOG4CXX_WARN(logger_, + "Can't select application to forward OnSystemRequest."); + return; + } + msg_params[strings::app_id] = app_id; + } + } +#endif // According to HMI API, this should be HMI unique id, but during processing // messages from HMI this param is replaced by connection key, so below it // will be treated as connection key @@ -81,8 +118,7 @@ void OnSystemRequestNotification::Run() { "Received OnSystemRequest without appID." " One of registered apps will be used."); LOG4CXX_DEBUG(logger_, "Searching registered app to send OnSystemRequest."); - const PolicyHandlerInterface& policy_handler = policy_handler_; - const uint32_t selected_app_id = policy_handler.GetAppIdForSending(); + const uint32_t selected_app_id = policy_handler_.GetAppIdForSending(); if (0 == selected_app_id) { LOG4CXX_WARN(logger_, "Can't select application to forward OnSystemRequest."); @@ -116,6 +152,11 @@ void OnSystemRequestNotification::Run() { "Sending request with application id " << app->policy_app_id()); params[strings::connection_key] = app->app_id(); + + if (helpers::Compare<RequestType, helpers::EQ, helpers::ONE>( + request_type, RequestType::RT_PROPRIETARY, RequestType::RT_HTTP)) { + policy_handler_.OnSystemRequestReceived(); + } SendNotificationToMobile(message_); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_vr_command_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_vr_command_notification.cc index 7680b74426..c4678f69e0 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_vr_command_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_vr_command_notification.cc @@ -65,14 +65,17 @@ void OnVRCommandNotification::Run() { (*message_)[strings::msg_params][strings::cmd_id].asUInt(); uint32_t max_cmd_id = application_manager_.get_settings().max_cmd_id(); - // Check if this is one of standart VR commands (i.e. "Help") + // Check if this is one of standard VR commands (i.e. "Help") if (cmd_id > max_cmd_id + 1) { LOG4CXX_INFO(logger_, "Switched App"); const uint32_t app_id = cmd_id - max_cmd_id; ApplicationSharedPtr app = application_manager_.application(app_id); if (app) { application_manager_.state_controller().SetRegularState( - app, mobile_apis::HMILevel::HMI_FULL, true); + app, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, + mobile_apis::HMILevel::HMI_FULL, + true); } else { LOG4CXX_ERROR(logger_, "Unable to find appication " << app_id); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_vr_language_change_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_vr_language_change_notification.cc index 55c6eb8881..c308af9b92 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_vr_language_change_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_vr_language_change_notification.cc @@ -83,7 +83,10 @@ void OnVRLanguageChangeNotification::Run() { if (static_cast<int32_t>(app->language()) != (*message_)[strings::msg_params][strings::language].asInt()) { application_manager_.state_controller().SetRegularState( - app, mobile_api::HMILevel::HMI_NONE, false); + app, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, + mobile_apis::HMILevel::HMI_NONE, + false); rpc_service_.ManageMobileCommand( MessageHelper::GetOnAppInterfaceUnregisteredNotificationToMobile( diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_get_capabilities_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_get_capabilities_response.cc index f4651ee0cb..128b111c5e 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_get_capabilities_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_get_capabilities_response.cc @@ -54,14 +54,24 @@ void RCGetCapabilitiesResponse::Run() { LOG4CXX_AUTO_TRACE(logger_); HMICapabilities& hmi_capabilities = hmi_capabilities_; - bool capability_exists = + bool rc_capability_exists = (*message_)[strings::msg_params].keyExists(strings::rc_capability); - if (capability_exists) { + if (rc_capability_exists) { hmi_capabilities.set_rc_capability( (*message_)[strings::msg_params][strings::rc_capability]); } - hmi_capabilities.set_rc_supported(capability_exists); + + bool seat_location_capability_exists = + (*message_)[strings::msg_params].keyExists( + strings::seat_location_capability); + + if (seat_location_capability_exists) { + hmi_capabilities.set_seat_location_capability( + (*message_)[strings::msg_params][strings::seat_location_capability]); + } + + hmi_capabilities.set_rc_supported(rc_capability_exists); } } // namespace commands 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 30184be7a1..0a6632fca8 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 @@ -32,6 +32,7 @@ #include "sdl_rpc_plugin/commands/hmi/sdl_activate_app_request.h" #include "application_manager/message_helper.h" +#include "application_manager/policies/policy_handler_interface.h" #include "application_manager/state_controller.h" namespace sdl_rpc_plugin { @@ -153,10 +154,6 @@ void SDLActivateAppRequest::Run() { application_manager_.application(application_id); if (!app_to_activate) { - LOG4CXX_WARN( - logger_, - "Can't find application within regular apps: " << application_id); - // Here is the hack - in fact SDL gets hmi_app_id in appID field and // replaces it with connection_key only for normally registered apps, but // for apps_to_be_registered (waiting) it keeps original value (hmi_app_id) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_get_list_of_permissions_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_get_list_of_permissions_request.cc index 095ffbd9c7..c8266e0f39 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_get_list_of_permissions_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_get_list_of_permissions_request.cc @@ -32,6 +32,7 @@ #include "sdl_rpc_plugin/commands/hmi/sdl_get_list_of_permissions_request.h" #include "application_manager/application_manager.h" +#include "application_manager/policies/policy_handler_interface.h" namespace sdl_rpc_plugin { using namespace application_manager; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_get_policy_configuration_data_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_get_policy_configuration_data_request.cc new file mode 100644 index 0000000000..52b7f83e9b --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_get_policy_configuration_data_request.cc @@ -0,0 +1,157 @@ +/* + * 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/sdl_get_policy_configuration_data_request.h" +#include "application_manager/application_manager.h" +#include "application_manager/policies/policy_handler_interface.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; + +namespace commands { + +SDLGetPolicyConfigurationDataRequest::SDLGetPolicyConfigurationDataRequest( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + rpc_service::RPCService& rpc_service, + HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handle) + : RequestFromHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handle) {} + +SDLGetPolicyConfigurationDataRequest::~SDLGetPolicyConfigurationDataRequest() {} + +void SDLGetPolicyConfigurationDataRequest::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + smart_objects::SmartObject response_value( + smart_objects::SmartType::SmartType_Array); + + hmi_apis::Common_Result::eType result_code = + PrepareResponseParams(response_value); + + if (hmi_apis::Common_Result::SUCCESS != result_code) { + LOG4CXX_ERROR(logger_, "Unable to PrepareResponseParams"); + SendErrorResponse( + correlation_id(), + hmi_apis::FunctionID::SDL_GetPolicyConfigurationData, + result_code, + "", + application_manager::commands::Command::SOURCE_SDL_TO_HMI); + return; + } + + smart_objects::SmartObject response_msg_params( + smart_objects::SmartType::SmartType_Map); + response_msg_params[strings::value] = response_value; + SendResponse(true, + correlation_id(), + hmi_apis::FunctionID::SDL_GetPolicyConfigurationData, + result_code, + &response_msg_params, + application_manager::commands::Command::SOURCE_SDL_TO_HMI); +} + +hmi_apis::Common_Result::eType +SDLGetPolicyConfigurationDataRequest::PrepareResponseParams( + smart_objects::SmartObject& response_out) const { + LOG4CXX_AUTO_TRACE(logger_); + const auto policy_type = + (*message_)[strings::msg_params][strings::policy_type].asString(); + + const auto property = + (*message_)[strings::msg_params][strings::property].asString(); + + auto policy_table_data = policy_handler_.GetPolicyTableData(); + if (!policy_table_data.isMember(policy_type)) { + LOG4CXX_ERROR( + logger_, + "policy_type " << policy_type << " doesn't exist in policy table."); + return hmi_apis::Common_Result::DATA_NOT_AVAILABLE; + } + + auto& policy_section_table_data = policy_table_data[policy_type]; + if (!policy_section_table_data.isMember(property)) { + LOG4CXX_ERROR( + logger_, + "property " << property << " doesn't exist in " << policy_type); + return hmi_apis::Common_Result::DATA_NOT_AVAILABLE; + } + + auto& property_table_data = policy_section_table_data[property]; + response_out = GetValueParam(property_table_data); + + return hmi_apis::Common_Result::SUCCESS; +} + +void clear_new_line_symbol(std::string& str_to_clear) { + str_to_clear.erase( + std::remove_if(str_to_clear.begin(), + str_to_clear.end(), + [](char character) { return '\n' == character; }), + str_to_clear.end()); +} + +smart_objects::SmartObject SDLGetPolicyConfigurationDataRequest::GetValueParam( + const Json::Value& policy_property) const { + LOG4CXX_AUTO_TRACE(logger_); + smart_objects::SmartObject value(smart_objects::SmartType_Array); + + auto put_element_in_value_array = [&value](const Json::Value& element, + const int32_t index) { + Json::StreamWriterBuilder writer_builder; + writer_builder["indentation"] = ""; + std::string str; + if (element.type() == Json::objectValue) { + str = Json::writeString(writer_builder, element); + clear_new_line_symbol(str); + } else { + str = element.asString(); + } + value[index] = str; + }; + + if (policy_property.type() == Json::arrayValue) { + for (Json::ArrayIndex i = 0; i < policy_property.size(); i++) { + put_element_in_value_array(policy_property[i], i); + } + return value; + } + put_element_in_value_array(policy_property, 0); + return value; +} + +} // namespace commands +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/get_urls_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_get_policy_configuration_data_response.cc index 77d90ec8bb..21b7dea41c 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/get_urls_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_get_policy_configuration_data_response.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Ford Motor Company + * Copyright (c) 2019, Ford Motor Company * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -30,14 +30,15 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include "sdl_rpc_plugin/commands/hmi/get_urls_response.h" +#include "sdl_rpc_plugin/commands/hmi/sdl_get_policy_configuration_data_response.h" #include "application_manager/rpc_service.h" namespace sdl_rpc_plugin { using namespace application_manager; + namespace commands { -GetUrlsResponse::GetUrlsResponse( +SDLGetPolicyConfigurationDataResponse::SDLGetPolicyConfigurationDataResponse( const application_manager::commands::MessageSharedPtr& message, ApplicationManager& application_manager, rpc_service::RPCService& rpc_service, @@ -49,13 +50,13 @@ GetUrlsResponse::GetUrlsResponse( hmi_capabilities, policy_handle) {} -GetUrlsResponse::~GetUrlsResponse() {} +SDLGetPolicyConfigurationDataResponse:: + ~SDLGetPolicyConfigurationDataResponse() {} -void GetUrlsResponse::Run() { +void SDLGetPolicyConfigurationDataResponse::Run() { LOG4CXX_AUTO_TRACE(logger_); (*message_)[strings::params][strings::protocol_type] = hmi_protocol_type_; (*message_)[strings::params][strings::protocol_version] = protocol_version_; - rpc_service_.SendMessageToHMI(message_); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_get_status_update_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_get_status_update_request.cc index 7200f6918c..b494be56e8 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_get_status_update_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_get_status_update_request.cc @@ -32,6 +32,7 @@ #include "sdl_rpc_plugin/commands/hmi/sdl_get_status_update_request.h" #include "application_manager/application_manager.h" +#include "application_manager/policies/policy_handler_interface.h" namespace sdl_rpc_plugin { using namespace application_manager; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_get_user_friendly_message_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_get_user_friendly_message_request.cc index 28167df047..f853cf814c 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_get_user_friendly_message_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_get_user_friendly_message_request.cc @@ -32,6 +32,7 @@ #include "sdl_rpc_plugin/commands/hmi/sdl_get_user_friendly_message_request.h" #include "application_manager/message_helper.h" +#include "application_manager/policies/policy_handler_interface.h" namespace sdl_rpc_plugin { using namespace application_manager; @@ -68,7 +69,16 @@ void SDLGetUserFriendlyMessageRequest::Run() { smart_objects::SmartArray::const_iterator it = msg->begin(); smart_objects::SmartArray::const_iterator it_end = msg->end(); for (; it != it_end; ++it) { - msg_codes.push_back((*it).asString()); + std::string str = (*it).asString(); + if (!CheckSyntax(str)) { + LOG4CXX_WARN(logger_, "Invalid data"); + SendErrorResponse(correlation_id(), + static_cast<hmi_apis::FunctionID::eType>(function_id()), + hmi_apis::Common_Result::INVALID_DATA, + "invalid messageCode syntax"); + return; + } + msg_codes.push_back(str); } std::string required_language; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_policy_update_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_policy_update_response.cc index 12cdfb4ad9..bfbf73270e 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_policy_update_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_policy_update_response.cc @@ -31,6 +31,7 @@ */ #include "sdl_rpc_plugin/commands/hmi/sdl_policy_update_response.h" +#include "application_manager/policies/policy_handler_interface.h" namespace sdl_rpc_plugin { using namespace application_manager; @@ -52,7 +53,20 @@ SDLPolicyUpdateResponse::~SDLPolicyUpdateResponse() {} void SDLPolicyUpdateResponse::Run() { LOG4CXX_AUTO_TRACE(logger_); - // TODO(PV): add some logic here + const hmi_apis::Common_Result::eType code = + static_cast<hmi_apis::Common_Result::eType>( + (*message_)[strings::params][hmi_response::code].asInt()); + + if (helpers::Compare<hmi_apis::Common_Result::eType, + helpers::NEQ, + helpers::ALL>(code, + hmi_apis::Common_Result::SUCCESS, + hmi_apis::Common_Result::WARNINGS)) { + LOG4CXX_ERROR(logger_, "Error is returned. PTU won't be started."); + return; + } + + application_manager_.GetPolicyHandler().OnUpdateRequestSentToMobile(); } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_alert_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_alert_request.cc index bf449db808..793e70d9e1 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_alert_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_alert_request.cc @@ -47,7 +47,11 @@ UIAlertRequest::UIAlertRequest( application_manager, rpc_service, hmi_capabilities, - policy_handle) {} + policy_handle) { + const auto& msg_params = (*message_)[strings::msg_params]; + uint32_t request_timeout = msg_params[strings::duration].asUInt(); + default_timeout_ += request_timeout; +} UIAlertRequest::~UIAlertRequest() {} diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_cancel_interaction_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_cancel_interaction_request.cc new file mode 100644 index 0000000000..c186077b1e --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_cancel_interaction_request.cc @@ -0,0 +1,62 @@ +/* + * 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/ui_cancel_interaction_request.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; + +namespace commands { + +UICancelInteractionRequest::UICancelInteractionRequest( + 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) {} + +UICancelInteractionRequest::~UICancelInteractionRequest() {} + +void UICancelInteractionRequest::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + SendRequest(); +} + +} // namespace commands + +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_cancel_interaction_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_cancel_interaction_response.cc new file mode 100644 index 0000000000..2d5db4eecb --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_cancel_interaction_response.cc @@ -0,0 +1,64 @@ +/* + * 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/ui_cancel_interaction_response.h" +#include "application_manager/event_engine/event.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; + +namespace commands { + +UICancelInteractionResponse::UICancelInteractionResponse( + 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) {} + +UICancelInteractionResponse::~UICancelInteractionResponse() {} + +void UICancelInteractionResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + event_engine::Event event(hmi_apis::FunctionID::UI_CancelInteraction); + event.set_smart_object(*message_); + event.raise(application_manager_.event_dispatcher()); +} + +} // namespace commands + +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_create_window_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_create_window_request.cc new file mode 100644 index 0000000000..b354009e3f --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_create_window_request.cc @@ -0,0 +1,62 @@ +/* + * 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/ui_create_window_request.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; + +namespace commands { + +UICreateWindowRequest::UICreateWindowRequest( + 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) {} + +UICreateWindowRequest::~UICreateWindowRequest() {} + +void UICreateWindowRequest::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + SendRequest(); +} + +} // namespace commands + +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_create_window_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_create_window_response.cc new file mode 100644 index 0000000000..c3a323818d --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_create_window_response.cc @@ -0,0 +1,63 @@ +/* + * 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/ui_create_window_response.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; + +namespace commands { + +UICreateWindowResponse::UICreateWindowResponse( + 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) {} + +UICreateWindowResponse::~UICreateWindowResponse() {} + +void UICreateWindowResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + event_engine::Event event(hmi_apis::FunctionID::UI_CreateWindow); + event.set_smart_object(*message_); + event.raise(application_manager_.event_dispatcher()); +} + +} // namespace commands + +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_delete_window_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_delete_window_request.cc new file mode 100644 index 0000000000..7933574d92 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_delete_window_request.cc @@ -0,0 +1,62 @@ +/* + * 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/ui_delete_window_request.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; + +namespace commands { + +UIDeleteWindowRequest::UIDeleteWindowRequest( + 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) {} + +UIDeleteWindowRequest::~UIDeleteWindowRequest() {} + +void UIDeleteWindowRequest::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + SendRequest(); +} + +} // namespace commands + +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_delete_window_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_delete_window_response.cc new file mode 100644 index 0000000000..ba703e18ae --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_delete_window_response.cc @@ -0,0 +1,63 @@ +/* + * 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/ui_delete_window_response.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; + +namespace commands { + +UIDeleteWindowResponse::UIDeleteWindowResponse( + 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) {} + +UIDeleteWindowResponse::~UIDeleteWindowResponse() {} + +void UIDeleteWindowResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + event_engine::Event event(hmi_apis::FunctionID::UI_DeleteWindow); + event.set_smart_object(*message_); + event.raise(application_manager_.event_dispatcher()); +} + +} // namespace commands + +} // namespace sdl_rpc_plugin 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 b18e3e5d89..5405b48027 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 @@ -73,9 +73,17 @@ void UIGetCapabilitiesResponse::Run() { msg_params[hmi_response::soft_button_capabilities]); } - if (msg_params.keyExists(strings::audio_pass_thru_capabilities)) { + // use newer parameter "audioPassThruCapabilitiesList" when available + if (msg_params.keyExists(strings::audio_pass_thru_capabilities_list)) { hmi_capabilities.set_audio_pass_thru_capabilities( - msg_params[strings::audio_pass_thru_capabilities]); + msg_params[strings::audio_pass_thru_capabilities_list]); + } else if (msg_params.keyExists(strings::audio_pass_thru_capabilities)) { + smart_objects::SmartObject audio_pass_thru_capabilities_list( + smart_objects::SmartType_Array); + audio_pass_thru_capabilities_list[0] = + msg_params[strings::audio_pass_thru_capabilities]; + hmi_capabilities.set_audio_pass_thru_capabilities( + audio_pass_thru_capabilities_list); } if (msg_params.keyExists(strings::hmi_capabilities)) { @@ -114,6 +122,7 @@ void UIGetCapabilitiesResponse::Run() { [strings::video_streaming_capability]); } if (msg_params[strings::system_capabilities].keyExists( +<<<<<<< HEAD strings::driver_distraction_capability)) { if (!msg_params[strings::system_capabilities] [strings::driver_distraction_capability] @@ -123,6 +132,12 @@ void UIGetCapabilitiesResponse::Run() { [strings::driver_distraction_capability]); hmi_capabilities.set_driver_distraction_supported(true); } +======= + strings::display_capabilities)) { + hmi_capabilities.set_system_display_capabilities( + msg_params[strings::system_capabilities] + [strings::display_capabilities]); +>>>>>>> origin/develop } } } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_perform_interaction_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_perform_interaction_request.cc index aa5878590b..a07c72cbf4 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_perform_interaction_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_perform_interaction_request.cc @@ -47,7 +47,11 @@ UIPerformInteractionRequest::UIPerformInteractionRequest( application_manager, rpc_service, hmi_capabilities, - policy_handle) {} + policy_handle) { + const auto& msg_params = (*message_)[strings::msg_params]; + uint32_t request_timeout = msg_params[strings::timeout].asUInt(); + default_timeout_ += request_timeout; +} UIPerformInteractionRequest::~UIPerformInteractionRequest() {} diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_scrollable_message_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_scrollable_message_request.cc index de639420fb..cad68e23aa 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_scrollable_message_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_scrollable_message_request.cc @@ -47,7 +47,11 @@ UIScrollableMessageRequest::UIScrollableMessageRequest( application_manager, rpc_service, hmi_capabilities, - policy_handle) {} + policy_handle) { + const auto& msg_params = (*message_)[strings::msg_params]; + uint32_t request_timeout = msg_params[strings::timeout].asUInt(); + default_timeout_ += request_timeout; +} UIScrollableMessageRequest::~UIScrollableMessageRequest() {} diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_slider_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_slider_request.cc index 56fca3d062..eae8cc523c 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_slider_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_slider_request.cc @@ -47,7 +47,11 @@ UISliderRequest::UISliderRequest( application_manager, rpc_service, hmi_capabilities, - policy_handle) {} + policy_handle) { + const auto& msg_params = (*message_)[strings::msg_params]; + uint32_t request_timeout = msg_params[strings::timeout].asUInt(); + default_timeout_ += request_timeout; +} UISliderRequest::~UISliderRequest() {} diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/update_sdl_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/update_sdl_request.cc index 96d454d4ee..a52f03b998 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/update_sdl_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/update_sdl_request.cc @@ -32,6 +32,7 @@ */ #include "sdl_rpc_plugin/commands/hmi/update_sdl_request.h" +#include "application_manager/policies/policy_handler_interface.h" namespace sdl_rpc_plugin { using namespace application_manager; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_perform_interaction_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_perform_interaction_request.cc index ae94019b25..4257158f6a 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_perform_interaction_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_perform_interaction_request.cc @@ -47,7 +47,11 @@ VRPerformInteractionRequest::VRPerformInteractionRequest( application_manager, rpc_service, hmi_capabilities, - policy_handle) {} + policy_handle) { + const auto& msg_params = (*message_)[strings::msg_params]; + uint32_t request_timeout = msg_params[strings::timeout].asUInt(); + default_timeout_ += request_timeout; +} VRPerformInteractionRequest::~VRPerformInteractionRequest() {} diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/add_command_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/add_command_request.cc index a57d222765..1dbfc97458 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/add_command_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/add_command_request.cc @@ -160,7 +160,9 @@ void AddCommandRequest::Run() { return; } - app->AddCommand((*message_)[strings::msg_params][strings::cmd_id].asUInt(), + const uint32_t internal_consecutive_number = application_manager::commands:: + CommandImpl::CalcCommandInternalConsecutiveNumber(app); + app->AddCommand(internal_consecutive_number, (*message_)[strings::msg_params]); smart_objects::SmartObject ui_msg_params = diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/add_sub_menu_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/add_sub_menu_request.cc index 6ef83b4af1..f2d670f0cf 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/add_sub_menu_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/add_sub_menu_request.cc @@ -111,6 +111,17 @@ void AddSubMenuRequest::Run() { smart_objects::SmartObject msg_params = smart_objects::SmartObject(smart_objects::SmartType_Map); + if (received_msg_params.keyExists(strings::menu_layout)) { + auto menu_layout = static_cast<mobile_apis::MenuLayout::eType>( + received_msg_params[strings::menu_layout].asUInt()); + if (app->menu_layout_supported(menu_layout)) { + msg_params[strings::menu_layout] = + received_msg_params[strings::menu_layout]; + } else { + is_menu_layout_available_ = false; + } + } + msg_params[strings::menu_id] = received_msg_params[strings::menu_id]; if (received_msg_params.keyExists(strings::position)) { msg_params[strings::menu_params][strings::position] = @@ -157,11 +168,22 @@ void AddSubMenuRequest::on_event(const event_engine::Event& event) { application->AddSubMenu( (*message_)[strings::msg_params][strings::menu_id].asInt(), (*message_)[strings::msg_params]); + response_info = + "The MenuLayout specified is unsupported, the " + "default MenuLayout will be used." + + response_info; + SendResponse(result, + is_menu_layout_available_ + ? MessageHelper::HMIToMobileResult(result_code) + : mobile_apis::Result::WARNINGS, + is_menu_layout_available_ ? NULL : response_info.c_str(), + &(message[strings::msg_params])); + } else { + SendResponse(result, + MessageHelper::HMIToMobileResult(result_code), + response_info.empty() ? NULL : response_info.c_str(), + &(message[strings::msg_params])); } - SendResponse(result, - MessageHelper::HMIToMobileResult(result_code), - response_info.empty() ? NULL : response_info.c_str(), - &(message[strings::msg_params])); break; } default: { 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 908f31cd51..57912e7087 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 @@ -73,18 +73,15 @@ AlertRequest::~AlertRequest() {} bool AlertRequest::Init() { /* Timeout in milliseconds. - If omitted a standard value of 10000 milliseconds is used.*/ - if ((*message_)[strings::msg_params].keyExists(strings::duration)) { - default_timeout_ = - (*message_)[strings::msg_params][strings::duration].asUInt(); - } else { - const int32_t def_value = 5000; - default_timeout_ = def_value; - } + If omitted a standard value of 10000 milliseconds is used.*/ + auto& msg_params = (*message_)[strings::msg_params]; + uint32_t duration_timeout = msg_params[strings::duration].asUInt(); + + default_timeout_ += duration_timeout; // If soft buttons are present, SDL will not use initiate timeout tracking for // response. - if ((*message_)[strings::msg_params].keyExists(strings::soft_buttons)) { + if (msg_params.keyExists(strings::soft_buttons)) { LOG4CXX_INFO(logger_, "Request contains soft buttons - request timeout " "will be set to 0."); @@ -251,7 +248,8 @@ bool AlertRequest::Validate(uint32_t app_id) { return false; } - if (mobile_apis::HMILevel::HMI_BACKGROUND == app->hmi_level() && + if (mobile_apis::HMILevel::HMI_BACKGROUND == + app->hmi_level(mobile_apis::PredefinedWindows::DEFAULT_WINDOW) && app->AreCommandLimitsExceeded( static_cast<mobile_apis::FunctionID::eType>(function_id()), application_manager::TLimitSource::POLICY_TABLE)) { @@ -321,6 +319,11 @@ void AlertRequest::SendAlertRequest(int32_t app_id) { msg_params[hmi_request::alert_strings] = smart_objects::SmartObject(smart_objects::SmartType_Array); + if ((*message_)[strings::msg_params].keyExists(strings::cancel_id)) { + msg_params[strings::cancel_id] = + (*message_)[strings::msg_params][strings::cancel_id].asInt(); + } + int32_t index = 0; if ((*message_)[strings::msg_params].keyExists(strings::alert_text1)) { msg_params[hmi_request::alert_strings][index][hmi_request::field_name] = @@ -349,6 +352,10 @@ void AlertRequest::SendAlertRequest(int32_t app_id) { (*message_)[strings::msg_params][strings::soft_buttons]; MessageHelper::SubscribeApplicationToSoftButton( (*message_)[strings::msg_params], app, function_id()); + msg_params[strings::duration] = 0; + } else { + msg_params[strings::duration] = + (*message_)[strings::msg_params][strings::duration].asUInt(); } if ((*message_)[strings::msg_params].keyExists(strings::alert_icon)) { @@ -369,7 +376,6 @@ void AlertRequest::SendAlertRequest(int32_t app_id) { // app_id msg_params[strings::app_id] = app_id; - msg_params[strings::duration] = default_timeout_; // NAVI platform progressIndicator if ((*message_)[strings::msg_params].keyExists(strings::progress_indicator)) { diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/cancel_interaction_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/cancel_interaction_request.cc new file mode 100644 index 0000000000..82e0703da1 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/cancel_interaction_request.cc @@ -0,0 +1,117 @@ + +/* +Copyright (c) 2019, Ford Motor Company, Livio +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 the copyright holders nor the names of their +contributors may be used to endorse or promote products derived from this +software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "sdl_rpc_plugin/commands/mobile/cancel_interaction_request.h" +#include "application_manager/application_impl.h" +#include "application_manager/message_helper.h" +#include "interfaces/MOBILE_API.h" +#include "utils/helpers.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; +namespace commands { + +CancelInteractionRequest::CancelInteractionRequest( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : CommandRequestImpl(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +CancelInteractionRequest::~CancelInteractionRequest() {} + +void CancelInteractionRequest::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + auto function_id = static_cast<mobile_apis::FunctionID::eType>( + (*message_)[strings::msg_params][strings::func_id].asInt()); + + if (helpers:: + Compare<mobile_apis::FunctionID::eType, helpers::NEQ, helpers::ALL>( + function_id, + mobile_apis::FunctionID::PerformInteractionID, + mobile_apis::FunctionID::AlertID, + mobile_apis::FunctionID::ScrollableMessageID, + mobile_apis::FunctionID::SliderID)) { + LOG4CXX_ERROR(logger_, "Bad function ID" << function_id); + SendResponse(false, mobile_apis::Result::INVALID_ID); + return; + } + + smart_objects::SmartObject msg_params; + msg_params[strings::app_id] = connection_key(); + msg_params[strings::func_id] = function_id; + + if ((*message_)[strings::msg_params].keyExists(strings::cancel_id)) { + msg_params[strings::cancel_id] = + (*message_)[strings::msg_params][strings::cancel_id].asInt(); + } + + SendHMIRequest(hmi_apis::FunctionID::UI_CancelInteraction, &msg_params, true); +} + +void CancelInteractionRequest::on_event(const event_engine::Event& event) { + LOG4CXX_AUTO_TRACE(logger_); + + if (event.id() != hmi_apis::FunctionID::UI_CancelInteraction) { + LOG4CXX_ERROR(logger_, "Received unknown event" << event.id()); + return; + } + + auto message = event.smart_object(); + + hmi_apis::Common_Result::eType hmi_result = + static_cast<hmi_apis::Common_Result::eType>( + message[strings::params][hmi_response::code].asInt()); + + mobile_apis::Result::eType result = + MessageHelper::HMIToMobileResult(hmi_result); + bool success = PrepareResultForMobileResponse( + hmi_result, HmiInterfaces::HMI_INTERFACE_UI); + + auto msg_params = message[strings::msg_params]; + + const char* info = msg_params.keyExists(strings::info) + ? msg_params[strings::info].asCharArray() + : NULL; + + SendResponse(success, result, info, &msg_params); +} + +} // namespace commands +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/cancel_interaction_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/cancel_interaction_response.cc new file mode 100644 index 0000000000..af73e72a6f --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/cancel_interaction_response.cc @@ -0,0 +1,60 @@ +/* + Copyright (c) 2019, Ford Motor Company, Livio + 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 the copyright holders nor the names of their + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + */ + +#include "sdl_rpc_plugin/commands/mobile/cancel_interaction_response.h" +#include "application_manager/application_impl.h" +#include "interfaces/MOBILE_API.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; +namespace commands { + +CancelInteractionResponse::CancelInteractionResponse( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : CommandResponseImpl(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +CancelInteractionResponse::~CancelInteractionResponse() {} + +void CancelInteractionResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + rpc_service_.SendMessageToMobile(message_); +} + +} // namespace commands +} // namespace sdl_rpc_plugin
\ No newline at end of file diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc index ef81babdd6..50217a9c8a 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc @@ -37,6 +37,7 @@ #include "application_manager/application_impl.h" #include "application_manager/application_manager.h" #include "application_manager/message_helper.h" +#include "application_manager/policies/policy_handler_interface.h" #include "interfaces/HMI_API.h" #include "interfaces/MOBILE_API.h" @@ -49,7 +50,7 @@ struct IsSameNickname { } private: - const custom_str::CustomString& app_id_; + const custom_str::CustomString app_id_; }; } // namespace @@ -160,7 +161,7 @@ void ChangeRegistrationRequest::Run() { return; } - if (mobile_apis::Result::SUCCESS != CheckCoincidence()) { + if (mobile_apis::Result::SUCCESS != CheckCoincidence(app->device())) { SendResponse(false, mobile_apis::Result::DUPLICATE_NAME); return; } @@ -578,36 +579,46 @@ bool ChangeRegistrationRequest::IsWhiteSpaceExist() { return false; } -mobile_apis::Result::eType ChangeRegistrationRequest::CheckCoincidence() { +mobile_apis::Result::eType ChangeRegistrationRequest::CheckCoincidence( + const connection_handler::DeviceHandle& device_id) { LOG4CXX_AUTO_TRACE(logger_); const smart_objects::SmartObject& msg_params = (*message_)[strings::msg_params]; - ApplicationSet accessor = application_manager_.applications().GetData(); + auto compare_tts_name = [](const smart_objects::SmartObject& obj_1, + const smart_objects::SmartObject& obj_2) { + return obj_1[application_manager::strings::text] + .asCustomString() + .CompareIgnoreCase( + obj_2[application_manager::strings::text].asCustomString()); + }; + + const auto& accessor = application_manager_.applications().GetData(); custom_str::CustomString app_name; - uint32_t app_id = connection_key(); + const uint32_t app_id = connection_key(); if (msg_params.keyExists(strings::app_name)) { app_name = msg_params[strings::app_name].asCustomString(); } - ApplicationSetConstIt it = accessor.begin(); - for (; accessor.end() != it; ++it) { - if (app_id == (*it)->app_id()) { + for (const auto& app : accessor) { + if (app->device() != device_id) { + continue; + } + + if (app->app_id() == app_id) { continue; } - const custom_str::CustomString& cur_name = (*it)->name(); + const auto& cur_name = app->name(); if (msg_params.keyExists(strings::app_name)) { if (app_name.CompareIgnoreCase(cur_name)) { LOG4CXX_ERROR(logger_, "Application name is known already."); return mobile_apis::Result::DUPLICATE_NAME; } - - const smart_objects::SmartObject* vr = (*it)->vr_synonyms(); - const std::vector<smart_objects::SmartObject>* curr_vr = NULL; - if (NULL != vr) { - curr_vr = vr->asArray(); + const auto vr = app->vr_synonyms(); + if (vr) { + const auto curr_vr = vr->asArray(); CoincidencePredicateVR v(app_name); if (0 != std::count_if(curr_vr->begin(), curr_vr->end(), v)) { @@ -617,18 +628,37 @@ mobile_apis::Result::eType ChangeRegistrationRequest::CheckCoincidence() { } } - // vr check + // VR check if (msg_params.keyExists(strings::vr_synonyms)) { - const std::vector<smart_objects::SmartObject>* new_vr = - msg_params[strings::vr_synonyms].asArray(); + const auto new_vr = msg_params[strings::vr_synonyms].asArray(); CoincidencePredicateVR v(cur_name); if (0 != std::count_if(new_vr->begin(), new_vr->end(), v)) { LOG4CXX_ERROR(logger_, "vr_synonyms duplicated with app_name ."); return mobile_apis::Result::DUPLICATE_NAME; } - } // end vr check - } // application for end + } // End vr check + + // TTS check + if (msg_params.keyExists(strings::tts_name) && app->tts_name()) { + const auto tts_array = msg_params[strings::tts_name].asArray(); + const auto tts_curr = app->tts_name()->asArray(); + const auto& it_tts = std::find_first_of(tts_array->begin(), + tts_array->end(), + tts_curr->begin(), + tts_curr->end(), + compare_tts_name); + if (it_tts != tts_array->end()) { + LOG4CXX_ERROR( + logger_, + "TTS name: " + << (*it_tts)[strings::text].asCustomString().AsMBString() + << " is known already"); + return mobile_apis::Result::DUPLICATE_NAME; + } + } // End tts check + + } // Application for end return mobile_apis::Result::SUCCESS; } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/close_application_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/close_application_request.cc index 736f0355dc..275f1d82a6 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/close_application_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/close_application_request.cc @@ -101,6 +101,7 @@ void CloseApplicationRequest::on_event(const event_engine::Event& event) { application_manager_.GetPluginManager().ForEachPlugin(on_app_exit); application_manager_.state_controller().SetRegularState( app, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, mobile_apis::HMILevel::HMI_NONE, mobile_apis::AudioStreamingState::NOT_AUDIBLE, mobile_apis::VideoStreamingState::NOT_STREAMABLE, 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 new file mode 100644 index 0000000000..b69b0ee801 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_window_request.cc @@ -0,0 +1,376 @@ +/* + 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/mobile/create_window_request.h" + +#include <algorithm> + +#include "application_manager/application_impl.h" +#include "application_manager/application_state.h" +#include "application_manager/message_helper.h" +#include "utils/helpers.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; +using app_mngr::ApplicationSharedPtr; + +namespace commands { + +CreateWindowRequest::CreateWindowRequest( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + rpc_service::RPCService& rpc_service, + HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : CommandRequestImpl(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +CreateWindowRequest::~CreateWindowRequest() {} + +bool CreateWindowRequest::CheckWindowName( + app_mngr::ApplicationSharedPtr app, + const app_mngr::WindowID window_id, + const std::string& window_name) const { + if (mobile_apis::PredefinedWindows::PRIMARY_WIDGET == window_id) { + LOG4CXX_DEBUG(logger_, + "Window name check is ignored for the primary widgets"); + return true; + } + + const bool names_are_equal = window_name == app->name().c_str(); + if (names_are_equal && + mobile_apis::PredefinedWindows::DEFAULT_WINDOW != window_id) { + LOG4CXX_ERROR(logger_, + "Regular widget can't have the same name as application: " + << window_name); + return false; + } + + const WindowNames window_names = app->GetWindowNames(); + return !helpers::in_range(window_names, window_name); +} + +void CreateWindowRequest::ApplyWindowInitialState( + ApplicationSharedPtr app) const { + const mobile_apis::WindowType::eType window_type = + static_cast<mobile_apis::WindowType::eType>( + (*message_)[strings::msg_params][strings::window_type].asInt()); + + // State should be initialized with INVALID_ENUM value to let state controller + // trigger OnHmiStatus notifiation sending + HmiStatePtr initial_state = application_manager_.CreateRegularState( + app, + window_type, + mobile_apis::HMILevel::INVALID_ENUM, + mobile_apis::AudioStreamingState::INVALID_ENUM, + mobile_apis::VideoStreamingState::INVALID_ENUM, + mobile_api::SystemContext::INVALID_ENUM); + + const WindowID window_id = + (*message_)[strings::msg_params][strings::window_id].asInt(); + const std::string window_name = + (*message_)[strings::msg_params][strings::window_name].asString(); + + smart_objects::SmartObject window_info(smart_objects::SmartType_Map); + if ((*message_)[strings::msg_params].keyExists( + strings::associated_service_type)) { + window_info[strings::associated_service_type] = + (*message_)[strings::msg_params][strings::associated_service_type]; + } + if ((*message_)[strings::msg_params].keyExists( + strings::duplicate_updates_from_window_id)) { + window_info[strings::duplicate_updates_from_window_id] = + (*message_)[strings::msg_params] + [strings::duplicate_updates_from_window_id]; + } + + window_info[strings::window_name] = window_name; + + app->SetWindowInfo(window_id, window_info); + + app->SetInitialState(window_id, window_name, initial_state); + + // Default HMI level for all windows except the main one is always NONE + application_manager_.state_controller().OnAppWindowAdded( + app, window_id, window_type, mobile_apis::HMILevel::HMI_NONE); +} + +app_mngr::WindowID CreateWindowRequest::window_id() const { + return mobile_apis::PredefinedWindows::DEFAULT_WINDOW; +} + +void CreateWindowRequest::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + const auto application = application_manager_.application(connection_key()); + + if (!application) { + LOG4CXX_ERROR(logger_, "Application is not registered"); + SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED); + return; + } + + const auto window_id = + (*message_)[strings::msg_params][strings::window_id].asInt(); + if (application->WindowIdExists(window_id)) { + LOG4CXX_ERROR(logger_, + "Window with id #" << window_id << " does already exist"); + SendResponse(false, mobile_apis::Result::INVALID_ID); + return; + } + + const auto window_type = + (*message_)[strings::msg_params][strings::window_type].asInt(); + + if (mobile_apis::WindowType::eType::MAIN == window_type) { + LOG4CXX_ERROR(logger_, "MAIN application window already exists"); + SendResponse(false, mobile_apis::Result::INVALID_DATA); + return; + } + + if ((*message_)[strings::msg_params].keyExists( + strings::duplicate_updates_from_window_id)) { + const auto duplicate_updates_from_window_id = + (*message_)[strings::msg_params] + [strings::duplicate_updates_from_window_id] + .asInt(); + if (!application->WindowIdExists(duplicate_updates_from_window_id)) { + LOG4CXX_ERROR(logger_, + "Window with id #" << duplicate_updates_from_window_id + << " does not exist"); + SendResponse(false, mobile_apis::Result::INVALID_DATA); + return; + } + } + + const std::string window_name = + (*message_)[strings::msg_params][strings::window_name].asString(); + if (!CheckWindowName(application, window_id, window_name)) { + LOG4CXX_ERROR(logger_, + "Window name \"" << window_name + << "\" is disallowed for window #" + << window_id); + SendResponse(false, mobile_apis::Result::DUPLICATE_NAME); + return; + } + + if (!ValidateWindowCreation(application, window_id)) { + return; + } + + smart_objects::SmartObject msg_params = (*message_)[strings::msg_params]; + msg_params[strings::app_id] = application->hmi_app_id(); + + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); + SendHMIRequest(hmi_apis::FunctionID::UI_CreateWindow, &msg_params, true); +} + +void CreateWindowRequest::on_event(const event_engine::Event& event) { + LOG4CXX_AUTO_TRACE(logger_); + + if (hmi_apis::FunctionID::UI_CreateWindow != event.id()) { + LOG4CXX_ERROR(logger_, "Received unknown event" << event.id()); + return; + } + + auto application = application_manager_.application(connection_key()); + + if (!application) { + LOG4CXX_ERROR(logger_, "Application is not registered"); + SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED); + return; + } + + LOG4CXX_INFO(logger_, "Received CreateWindow event"); + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); + + const smart_objects::SmartObject& response_message = event.smart_object(); + const auto result_code = CommandRequestImpl::GetMobileResultCode( + static_cast<hmi_apis::Common_Result::eType>( + response_message[strings::params][hmi_response::code].asInt())); + + const bool is_success = IsMobileResultSuccess(result_code); + std::string response_info; + GetInfo(response_message, response_info); + + if (!is_success) { + LOG4CXX_ERROR(logger_, "CreateWindow request has failed on HMI side"); + SendResponse(is_success, + result_code, + response_info.empty() ? nullptr : response_info.c_str()); + return; + } + + ApplyWindowInitialState(application); + + SendResponse(is_success, + result_code, + response_info.empty() ? nullptr : response_info.c_str()); +} + +bool CreateWindowRequest::Init() { + hash_update_mode_ = HashUpdateMode::kDoHashUpdate; + return true; +} + +bool CreateWindowRequest::IsWindowForAssociatedServiceCreated( + app_mngr::ApplicationSharedPtr app) const { + LOG4CXX_AUTO_TRACE(logger_); + + const auto window_optional_params_map = + app->window_optional_params_map().GetData(); + + if (!(*message_)[strings::msg_params].keyExists( + strings::associated_service_type)) { + return false; + } + + const auto associated_service_type = + (*message_)[strings::msg_params][strings::associated_service_type] + .asString(); + + const auto find_res = std::find_if( + window_optional_params_map.begin(), + window_optional_params_map.end(), + [&associated_service_type]( + const std::pair<WindowID, smart_objects::SmartObjectSPtr>& element) { + LOG4CXX_DEBUG(logger_, + "Searching for " << associated_service_type + << " in window info for id " + << element.first); + if (element.second->keyExists(strings::associated_service_type) && + associated_service_type == + (*element.second)[strings::associated_service_type] + .asString()) { + return true; + } + + return false; + }); + + return find_res != window_optional_params_map.end(); +} + +bool CreateWindowRequest::DoesExceedMaxAllowedWindows( + app_mngr::ApplicationSharedPtr app) const { + LOG4CXX_AUTO_TRACE(logger_); + + auto get_current_number_of_windows = + [&app](const mobile_apis::WindowType::eType window_type) -> size_t { + switch (window_type) { + case mobile_apis::WindowType::MAIN: { + return 1u; + } + case mobile_apis::WindowType::WIDGET: { + return app->window_optional_params_map().GetData().size(); + } + + default: { + LOG4CXX_WARN(logger_, "Unknown window type"); + return 0u; + } + } + }; + + const auto window_type = static_cast<mobile_apis::WindowType::eType>( + (*message_)[strings::msg_params][strings::window_type].asInt()); + + auto display_capabilities = hmi_capabilities_.system_display_capabilities(); + if (app->display_capabilities()) { + display_capabilities = app->display_capabilities(); + } + + if (!display_capabilities) { + LOG4CXX_WARN(logger_, "Application has no capabilities"); + return false; + } + + MessageHelper::PrintSmartObject(*display_capabilities); + + const auto windowTypeSupported = + (*display_capabilities)[0][strings::window_type_supported].asArray(); + + DCHECK(windowTypeSupported); + + const auto find_res = std::find_if( + windowTypeSupported->begin(), + windowTypeSupported->end(), + [&window_type](const smart_objects::SmartObject& element) { + if (window_type == static_cast<mobile_apis::WindowType::eType>( + element[strings::window_type].asInt())) { + return true; + } + + return false; + }); + + if (find_res == windowTypeSupported->end()) { + LOG4CXX_WARN(logger_, "Requested Window Type is not supported by the HMI"); + return true; + } + + if (get_current_number_of_windows(window_type) + 1 > + (*find_res)[strings::maximum_number_of_windows].asUInt()) { + return true; + } + + return false; +} + +bool CreateWindowRequest::ValidateWindowCreation( + app_mngr::ApplicationSharedPtr app, const WindowID window_id) { + LOG4CXX_AUTO_TRACE(logger_); + + if (DoesExceedMaxAllowedWindows(app)) { + std::string info("Maximum allowed amount of windows is exceeded"); + LOG4CXX_WARN(logger_, info); + SendResponse(false, mobile_apis::Result::REJECTED, info.c_str()); + return false; + } + + if (IsWindowForAssociatedServiceCreated(app)) { + std::string info( + "Window for this associated service type is already created"); + LOG4CXX_WARN(logger_, info); + SendResponse(false, mobile_apis::Result::REJECTED, info.c_str()); + return false; + } + + return true; +} + +} // namespace commands + +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_window_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_window_response.cc new file mode 100644 index 0000000000..0d9bbc2815 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_window_response.cc @@ -0,0 +1,64 @@ +/* + + 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/mobile/create_window_response.h" +#include "application_manager/rpc_service.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; + +namespace commands { + +CreateWindowResponse::CreateWindowResponse( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + rpc_service::RPCService& rpc_service, + HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : CommandResponseImpl(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +CreateWindowResponse::~CreateWindowResponse() {} + +void CreateWindowResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + rpc_service_.SendMessageToMobile(message_); +} + +} // namespace commands + +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_file_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_file_request.cc index b2c9a3377f..46af8353b7 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_file_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_file_request.cc @@ -68,7 +68,9 @@ void DeleteFileRequest::Run() { return; } - if ((mobile_api::HMILevel::HMI_NONE == application->hmi_level()) && + if ((mobile_api::HMILevel::HMI_NONE == + application->hmi_level( + mobile_apis::PredefinedWindows::DEFAULT_WINDOW)) && (application_manager_.get_settings().delete_file_in_none() <= application->delete_file_in_none_count())) { // If application is in the HMI_NONE level the quantity of allowed 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 new file mode 100644 index 0000000000..7f253e25fd --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_window_request.cc @@ -0,0 +1,162 @@ +/* + 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/mobile/delete_window_request.h" + +#include <algorithm> + +namespace sdl_rpc_plugin { +using namespace application_manager; + +namespace commands { + +DeleteWindowRequest::DeleteWindowRequest( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + rpc_service::RPCService& rpc_service, + HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : CommandRequestImpl(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +DeleteWindowRequest::~DeleteWindowRequest() {} + +bool DeleteWindowRequest::CheckWindowId( + app_mngr::ApplicationSharedPtr app) const { + const WindowID window_id = + (*message_)[strings::msg_params][strings::window_id].asInt(); + if (mobile_apis::PredefinedWindows::DEFAULT_WINDOW == window_id) { + LOG4CXX_ERROR(logger_, "Main application window can't be deleted"); + return false; + } + + if (!app->WindowIdExists(window_id)) { + LOG4CXX_ERROR(logger_, + "Window with id #" << window_id << " does not exist"); + return false; + } + + return true; +} + +app_mngr::WindowID DeleteWindowRequest::window_id() const { + return mobile_apis::PredefinedWindows::DEFAULT_WINDOW; +} + +void DeleteWindowRequest::DeleteWindow( + app_mngr::ApplicationSharedPtr app) const { + const WindowID window_id = + (*message_)[strings::msg_params][strings::window_id].asInt(); + app->RemoveWindowInfo(window_id); + app->RemoveHMIState(window_id, HmiState::StateID::STATE_ID_REGULAR); + app->remove_window_capability(window_id); +} + +void DeleteWindowRequest::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + ApplicationSharedPtr application = + application_manager_.application(connection_key()); + + if (!application) { + LOG4CXX_ERROR(logger_, "Application is not registered"); + SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED); + return; + } + + if (!CheckWindowId(application)) { + SendResponse(false, mobile_apis::Result::INVALID_ID); + return; + } + + smart_objects::SmartObject msg_params = (*message_)[strings::msg_params]; + msg_params[strings::app_id] = application->hmi_app_id(); + + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); + SendHMIRequest(hmi_apis::FunctionID::UI_DeleteWindow, &msg_params, true); +} + +void DeleteWindowRequest::on_event(const event_engine::Event& event) { + LOG4CXX_AUTO_TRACE(logger_); + + if (hmi_apis::FunctionID::UI_DeleteWindow != event.id()) { + LOG4CXX_ERROR(logger_, "Received unknown event" << event.id()); + return; + } + + ApplicationSharedPtr application = + application_manager_.application(connection_key()); + + if (!application) { + LOG4CXX_ERROR(logger_, "Application is not registered"); + SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED); + return; + } + + LOG4CXX_INFO(logger_, "Received DeleteWindow event"); + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); + + const smart_objects::SmartObject& response_message = event.smart_object(); + const auto result_code = CommandRequestImpl::GetMobileResultCode( + static_cast<hmi_apis::Common_Result::eType>( + response_message[strings::params][hmi_response::code].asInt())); + + const bool is_success = IsMobileResultSuccess(result_code); + std::string response_info; + GetInfo(response_message, response_info); + + if (!is_success) { + LOG4CXX_ERROR(logger_, "DeleteWindow request has failed on HMI side"); + SendResponse(is_success, + result_code, + response_info.empty() ? nullptr : response_info.c_str()); + return; + } + + DeleteWindow(application); + + SendResponse(is_success, + result_code, + response_info.empty() ? nullptr : response_info.c_str()); +} + +bool DeleteWindowRequest::Init() { + hash_update_mode_ = HashUpdateMode::kDoHashUpdate; + return true; +} + +} // namespace commands + +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_window_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_window_response.cc new file mode 100644 index 0000000000..f9ac9a46d6 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_window_response.cc @@ -0,0 +1,64 @@ +/* + + 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/mobile/delete_window_response.h" +#include "application_manager/rpc_service.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; + +namespace commands { + +DeleteWindowResponse::DeleteWindowResponse( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + rpc_service::RPCService& rpc_service, + HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : CommandResponseImpl(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +DeleteWindowResponse::~DeleteWindowResponse() {} + +void DeleteWindowResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + rpc_service_.SendMessageToMobile(message_); +} + +} // namespace commands + +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_cloud_app_properties_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_cloud_app_properties_request.cc index 34ed30c243..c5e94da378 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_cloud_app_properties_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_cloud_app_properties_request.cc @@ -1,4 +1,5 @@ #include "sdl_rpc_plugin/commands/mobile/get_cloud_app_properties_request.h" +#include "application_manager/policies/policy_handler_interface.h" namespace sdl_rpc_plugin { using namespace application_manager; @@ -32,20 +33,10 @@ void GetCloudAppPropertiesRequest::Run() { std::string policy_app_id = (*message_)[strings::msg_params][strings::app_id].asString(); - bool enabled = true; - std::string endpoint; - std::string auth_token; - std::string certificate; - std::string cloud_transport_type; - std::string hybrid_app_preference; - - bool result = policy_handler_.GetCloudAppParameters(policy_app_id, - enabled, - endpoint, - certificate, - auth_token, - cloud_transport_type, - hybrid_app_preference); + policy::AppProperties app_properties; + + const bool result = + policy_handler_.GetAppProperties(policy_app_id, app_properties); if (!result) { SendResponse(false, @@ -69,19 +60,20 @@ void GetCloudAppPropertiesRequest::Run() { } properties[strings::nicknames] = nicknames_array; properties[strings::app_id] = policy_app_id; - properties[strings::enabled] = enabled; + properties[strings::enabled] = app_properties.enabled; - if (!auth_token.empty()) { - properties[strings::auth_token] = auth_token; + if (!app_properties.auth_token.empty()) { + properties[strings::auth_token] = app_properties.auth_token; } - if (!cloud_transport_type.empty()) { - properties[strings::cloud_transport_type] = cloud_transport_type; + if (!app_properties.transport_type.empty()) { + properties[strings::cloud_transport_type] = app_properties.transport_type; } - if (!hybrid_app_preference.empty()) { - properties[strings::hybrid_app_preference] = hybrid_app_preference; + if (!app_properties.hybrid_app_preference.empty()) { + properties[strings::hybrid_app_preference] = + app_properties.hybrid_app_preference; } - if (!endpoint.empty()) { - properties[strings::endpoint] = endpoint; + if (!app_properties.endpoint.empty()) { + properties[strings::endpoint] = app_properties.endpoint; } response_params[strings::properties] = properties; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_system_capability_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_system_capability_request.cc index 5fa5ba52f8..c659badf87 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_system_capability_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_system_capability_request.cc @@ -133,6 +133,17 @@ void GetSystemCapabilityRequest::Run() { } break; } + case mobile_apis::SystemCapabilityType::SEAT_LOCATION: { + if (hmi_capabilities.seat_location_capability()) { + response_params[strings::system_capability] + [strings::seat_location_capability] = + *hmi_capabilities.seat_location_capability(); + } else { + SendResponse(false, mobile_apis::Result::DATA_NOT_AVAILABLE); + return; + } + break; + } case mobile_apis::SystemCapabilityType::VIDEO_STREAMING: if (hmi_capabilities.video_streaming_capability()) { response_params[strings::system_capability] @@ -152,6 +163,7 @@ void GetSystemCapabilityRequest::Run() { all_services); break; } +<<<<<<< HEAD case mobile_apis::SystemCapabilityType::DRIVER_DISTRACTION: if (hmi_capabilities.driver_distraction_capability() && hmi_capabilities.driver_distraction_supported()) { @@ -163,27 +175,56 @@ void GetSystemCapabilityRequest::Run() { return; } break; +======= + case mobile_apis::SystemCapabilityType::DISPLAYS: { + auto capabilities = hmi_capabilities.system_display_capabilities(); + if (app->display_capabilities()) { + capabilities = app->display_capabilities(); + } + + if (!capabilities) { + SendResponse(false, mobile_apis::Result::DATA_NOT_AVAILABLE); + LOG4CXX_INFO(logger_, "system_display_capabilities are not available"); + return; + } + + response_params[strings::system_capability] + [strings::display_capabilities] = *capabilities; + break; + } +>>>>>>> origin/develop default: // Return unsupported resource SendResponse(false, mobile_apis::Result::UNSUPPORTED_RESOURCE); return; } - if ((*message_)[app_mngr::strings::msg_params].keyExists( - strings::subscribe)) { - auto& ext = SystemCapabilityAppExtension::ExtractExtension(*app); - if ((*message_)[app_mngr::strings::msg_params][strings::subscribe] - .asBool() == true) { - LOG4CXX_DEBUG(logger_, - "Subscribe to system capability: " << response_type); - ext.SubscribeTo(response_type); - } else { - LOG4CXX_DEBUG(logger_, - "Unsubscribe from system capability: " << response_type); - ext.UnsubscribeFrom(response_type); + const char* info = nullptr; + // Ignore subscription/unsubscription for DISPLAYS type + if (mobile_apis::SystemCapabilityType::DISPLAYS != response_type) { + if ((*message_)[app_mngr::strings::msg_params].keyExists( + strings::subscribe)) { + auto& ext = SystemCapabilityAppExtension::ExtractExtension(*app); + if ((*message_)[app_mngr::strings::msg_params][strings::subscribe] + .asBool() == true) { + LOG4CXX_DEBUG(logger_, + "Subscribe to system capability: " << response_type); + ext.SubscribeTo(response_type); + } else { + LOG4CXX_DEBUG(logger_, + "Unsubscribe from system capability: " << response_type); + ext.UnsubscribeFrom(response_type); + } + } + } else { + if ((*message_)[app_mngr::strings::msg_params].keyExists( + strings::subscribe)) { + info = + "Subscribe parameter is ignored. Auto Subscription/Unsubscription is " + "used for DISPLAY capability type."; } } - SendResponse(true, mobile_apis::Result::SUCCESS, NULL, &response_params); + SendResponse(true, mobile_apis::Result::SUCCESS, info, &response_params); } void GetSystemCapabilityRequest::on_event(const event_engine::Event& event) { diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/list_files_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/list_files_request.cc index 46a39513d5..b8714b4784 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/list_files_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/list_files_request.cc @@ -70,7 +70,9 @@ void ListFilesRequest::Run() { return; } - if ((mobile_api::HMILevel::HMI_NONE == application->hmi_level()) && + if ((mobile_api::HMILevel::HMI_NONE == + application->hmi_level( + mobile_apis::PredefinedWindows::DEFAULT_WINDOW)) && (application_manager_.get_settings().list_files_in_none() <= application->list_files_in_none_count())) { // If application is in the HMI_NONE level the quantity of allowed 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 f0368a742d..bca3b20fe0 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,11 +102,13 @@ void OnButtonEventNotification::Run() { return; } - 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_NONE == window_hmi_level)) { LOG4CXX_WARN(logger_, - "CUSTOM_BUTTON OnButtonEvent notification is allowed only " - << "in FULL or LIMITED hmi level"); + "CUSTOM_BUTTON OnButtonEvent notification is not allowed in " + "NONE hmi level"); return; } @@ -127,8 +129,11 @@ void OnButtonEventNotification::Run() { } // Send ButtonEvent notification only in HMI_FULL or HMI_LIMITED mode - if ((mobile_api::HMILevel::HMI_FULL != subscribed_app->hmi_level()) && - (mobile_api::HMILevel::HMI_LIMITED != subscribed_app->hmi_level())) { + 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)) { LOG4CXX_WARN(logger_, "OnButtonEvent notification is allowed only" << "in FULL or LIMITED hmi level"); @@ -179,6 +184,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 7c77e29298..a205660e23 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 @@ -67,6 +67,10 @@ void OnButtonPressNotification::Run() { 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<uint32_t>(mobile_apis::ButtonName::CUSTOM_BUTTON) == btn_id) { @@ -76,9 +80,6 @@ void OnButtonPressNotification::Run() { 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)) { @@ -104,11 +105,14 @@ void OnButtonPressNotification::Run() { } // Send ButtonPress notification only in HMI_FULL or HMI_LIMITED mode - 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_NONE == window_hmi_level)) { LOG4CXX_WARN(logger_, - "CUSTOM_BUTTON OnButtonPress notification is allowed only " - << "in FULL or LIMITED hmi level"); + "CUSTOM_BUTTON OnButtonPress notification is not allowed in " + "NONE hmi level"); return; } @@ -129,8 +133,11 @@ void OnButtonPressNotification::Run() { } // Send ButtonPress notification only in HMI_FULL or HMI_LIMITED mode - if ((mobile_api::HMILevel::HMI_FULL != subscribed_app->hmi_level()) && - (mobile_api::HMILevel::HMI_LIMITED != subscribed_app->hmi_level())) { + 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)) { LOG4CXX_WARN(logger_, "OnButtonPress notification is allowed only" << "in FULL or LIMITED hmi level"); @@ -187,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/on_keyboard_input_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_keyboard_input_notification.cc index 8ec8a86554..1c0609e17d 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_keyboard_input_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_keyboard_input_notification.cc @@ -76,7 +76,8 @@ void OnKeyBoardInputNotification::Run() { break; } - if (mobile_apis::HMILevel::eType::HMI_FULL == app->hmi_level()) { + if (mobile_apis::HMILevel::eType::HMI_FULL == + app->hmi_level(mobile_apis::PredefinedWindows::DEFAULT_WINDOW)) { LOG4CXX_INFO(logger_, "There is application in HMI_FULL level"); app_to_notify = app; } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_capability_updated_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_capability_updated_notification.cc index 515279c5f9..cc6ab7b65b 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_capability_updated_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_capability_updated_notification.cc @@ -2,6 +2,7 @@ #include "application_manager/app_service_manager.h" #include "application_manager/application_manager.h" +#include "application_manager/display_capabilities_builder.h" #include "application_manager/helpers/application_helper.h" #include "application_manager/message_helper.h" #include "sdl_rpc_plugin/extensions/system_capability_app_extension.h" @@ -31,7 +32,7 @@ void OnSystemCapabilityUpdatedNotification::Run() { LOG4CXX_AUTO_TRACE(logger_); smart_objects::SmartObject& msg_params = (*message_)[strings::msg_params]; - mobile_apis::SystemCapabilityType::eType system_capability_type = + const auto system_capability_type = static_cast<mobile_apis::SystemCapabilityType::eType>( msg_params[strings::system_capability] [strings::system_capability_type] @@ -127,8 +128,21 @@ void OnSystemCapabilityUpdatedNotification::Run() { [strings::app_services_capabilities] = app_service_caps; break; } - default: + + case mobile_apis::SystemCapabilityType::DISPLAYS: { + // Display capabilities content will be populated in the code after the + // switch so just breaking here + break; + } + + default: { + LOG4CXX_ERROR(logger_, + "Unknown system capability type: " + << msg_params[strings::system_capability] + [strings::system_capability_type] + .asInt()); return; + } } const char* capability_type_string; @@ -136,11 +150,34 @@ void OnSystemCapabilityUpdatedNotification::Run() { mobile_apis::SystemCapabilityType::eType>:: EnumToCString(system_capability_type, &capability_type_string); + const auto initial_connection_key = + (*message_)[strings::params][strings::connection_key].asUInt(); + auto subscribed_to_capability_predicate = - [&system_capability_type](const ApplicationSharedPtr app) { + [&system_capability_type, + &initial_connection_key](const ApplicationSharedPtr app) { DCHECK_OR_RETURN(app, false); auto& ext = SystemCapabilityAppExtension::ExtractExtension(*app); - return ext.IsSubscribedTo(system_capability_type); + if (!ext.IsSubscribedTo(system_capability_type)) { + LOG4CXX_DEBUG(logger_, + "App " << app->app_id() + << " is not subscribed to this capability type"); + return false; + } + + if (mobile_apis::SystemCapabilityType::DISPLAYS == + system_capability_type && + initial_connection_key > 0) { + LOG4CXX_DEBUG(logger_, + "Display capabilities notification for app " + << initial_connection_key << " only"); + return app->app_id() == initial_connection_key; + } + + LOG4CXX_DEBUG(logger_, + "App " << app->app_id() + << " is subscribed to specified capability type"); + return true; }; const std::vector<ApplicationSharedPtr>& applications = FindAllApps( @@ -167,6 +204,40 @@ void OnSystemCapabilityUpdatedNotification::Run() { ext.UnsubscribeFrom(system_capability_type); continue; } + + if (mobile_apis::SystemCapabilityType::DISPLAYS == system_capability_type) { + LOG4CXX_DEBUG(logger_, "Using common display capabilities"); + auto capabilities = hmi_capabilities_.system_display_capabilities(); + if (app->is_resuming() && app->is_app_data_resumption_allowed()) { + LOG4CXX_DEBUG(logger_, + "Application " + << app->app_id() + << " is resuming. Providing cached capabilities"); + auto display_caps = + app->display_capabilities_builder().display_capabilities(); + capabilities = display_caps; + } else if (app->display_capabilities()) { + LOG4CXX_DEBUG(logger_, + "Application " << app->app_id() + << " has specific display capabilities"); + const WindowID window_id = + msg_params[strings::system_capability] + [strings::display_capabilities][0] + [strings::window_capabilities][0][strings::window_id] + .asInt(); + capabilities = app->display_capabilities(window_id); + } + + if (!capabilities) { + LOG4CXX_WARN(logger_, + "No available display capabilities for sending. Skipping"); + continue; + } + + msg_params[strings::system_capability][strings::display_capabilities] = + *capabilities; + } + LOG4CXX_INFO(logger_, "Sending OnSystemCapabilityUpdated " << capability_type_string << " application id " diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_request_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_request_notification.cc index a85dec10bb..9c868172f5 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_request_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_request_notification.cc @@ -86,8 +86,8 @@ void OnSystemRequestNotification::Run() { static_cast<rpc::policy_table_interface_base::RequestType>( request_type)); - if (!policy_handler.IsRequestTypeAllowed(app->policy_app_id(), - request_type)) { + if (!policy_handler.IsRequestTypeAllowed( + app->device(), app->policy_app_id(), request_type)) { LOG4CXX_WARN(logger_, "Request type " << stringified_request_type << " is not allowed by policies"); @@ -118,22 +118,23 @@ void OnSystemRequestNotification::Run() { mobile_apis::RequestType::OEM_SPECIFIC); BinaryMessage binary_data; - if (binary_data_is_required) { + if (binary_data_is_required && + (*message_)[strings::msg_params].keyExists(strings::file_name)) { const std::string filename = (*message_)[strings::msg_params][strings::file_name].asString(); file_system::ReadBinaryFile(filename, binary_data); + } else if ((*message_)[strings::params].keyExists(strings::binary_data)) { + // Binary data may already be attached to the message + binary_data = (*message_)[strings::params][strings::binary_data].asBinary(); } if (mobile_apis::RequestType::OEM_SPECIFIC == request_type) { (*message_)[strings::params][strings::binary_data] = binary_data; - } - - if (mobile_apis::RequestType::PROPRIETARY == request_type) { + } else if (mobile_apis::RequestType::PROPRIETARY == request_type) { /* According to requirements: "If the requestType = PROPRIETARY, add to mobile API fileType = JSON If the requestType = HTTP, add to mobile API fileType = BINARY" - Also in Genivi SDL we don't save the PT to file - we put it directly in - binary_data */ + Also we don't save the PT to file - we put it directly in binary_data */ #if defined(PROPRIETARY_MODE) AddHeader(binary_data); @@ -144,14 +145,19 @@ void OnSystemRequestNotification::Run() { #endif // PROPRIETARY_MODE (*message_)[strings::msg_params][strings::file_type] = FileType::JSON; - } - - if (mobile_apis::RequestType::HTTP == request_type) { + } else if (mobile_apis::RequestType::HTTP == request_type) { (*message_)[strings::msg_params][strings::file_type] = FileType::BINARY; if ((*message_)[strings::msg_params].keyExists(strings::url)) { (*message_)[strings::msg_params][strings::timeout] = policy_handler.TimeoutExchangeSec(); } + } else if (mobile_apis::RequestType::LOCK_SCREEN_ICON_URL == request_type) { + if (!(*message_)[strings::msg_params].keyExists(strings::url) || + (*message_)[strings::msg_params][strings::url].empty()) { + LOG4CXX_ERROR(logger_, + "discarding LOCK_SCREEN_ICON_URL request without URL"); + return; + } } SendNotification(); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_tbt_client_state_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_tbt_client_state_notification.cc index ccbdab15c9..0a8420b6a3 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_tbt_client_state_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_tbt_client_state_notification.cc @@ -67,7 +67,8 @@ void OnTBTClientStateNotification::Run() { std::vector<ApplicationSharedPtr>::const_iterator it = applications.begin(); for (; applications.end() != it; ++it) { ApplicationSharedPtr app = *it; - if (mobile_apis::HMILevel::eType::HMI_NONE != app->hmi_level()) { + if (mobile_apis::HMILevel::eType::HMI_NONE != + app->hmi_level(mobile_apis::PredefinedWindows::DEFAULT_WINDOW)) { (*message_)[strings::params][strings::connection_key] = app->app_id(); SendNotification(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_way_point_change_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_way_point_change_notification.cc index e89ede53b9..39e0735013 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_way_point_change_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_way_point_change_notification.cc @@ -65,6 +65,7 @@ void OnWayPointChangeNotification::Run() { (*message_)[strings::params][strings::connection_key] = *app_id; SendNotification(); } + application_manager_.SaveWayPointsMessage(message_); } } // namespace commands } // namespace sdl_rpc_plugin 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 8f8e4dbf6f..2f3d38f0b0 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 @@ -87,7 +87,8 @@ void PerformAudioPassThruRequest::Run() { return; } - if (mobile_api::HMILevel::HMI_NONE == app->hmi_level()) { + if (mobile_api::HMILevel::HMI_NONE == + app->hmi_level(mobile_apis::PredefinedWindows::DEFAULT_WINDOW)) { LOG4CXX_ERROR(logger_, "application isn't activated"); SendResponse(false, mobile_apis::Result::REJECTED); return; @@ -286,20 +287,22 @@ void PerformAudioPassThruRequest::SendPerformAudioPassThruRequest() { msg_params[hmi_request::audio_pass_display_texts] = smart_objects::SmartObject(smart_objects::SmartType_Array); + int32_t index = 0; if ((*message_)[str::msg_params].keyExists(str::audio_pass_display_text1)) { - msg_params[hmi_request::audio_pass_display_texts][0] + msg_params[hmi_request::audio_pass_display_texts][index] [hmi_request::field_name] = static_cast<int32_t>( hmi_apis::Common_TextFieldName::audioPassThruDisplayText1); - msg_params[hmi_request::audio_pass_display_texts][0] + msg_params[hmi_request::audio_pass_display_texts][index] [hmi_request::field_text] = (*message_)[str::msg_params][str::audio_pass_display_text1]; + ++index; } if ((*message_)[str::msg_params].keyExists(str::audio_pass_display_text2)) { - msg_params[hmi_request::audio_pass_display_texts][1] + msg_params[hmi_request::audio_pass_display_texts][index] [hmi_request::field_name] = static_cast<int32_t>( hmi_apis::Common_TextFieldName::audioPassThruDisplayText2); - msg_params[hmi_request::audio_pass_display_texts][1] + msg_params[hmi_request::audio_pass_display_texts][index] [hmi_request::field_text] = (*message_)[str::msg_params][str::audio_pass_display_text2]; } 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 6b2f3cbcc5..881c838c1a 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 @@ -32,6 +32,7 @@ */ #include "sdl_rpc_plugin/commands/mobile/perform_interaction_request.h" + #include <string.h> #include <numeric> #include <string> @@ -46,6 +47,10 @@ #include "utils/gen_hash.h" #include "utils/helpers.h" +namespace { +const std::int32_t INVALID_CHOICE_ID = -1; +} + namespace sdl_rpc_plugin { using namespace application_manager; @@ -67,11 +72,15 @@ PerformInteractionRequest::PerformInteractionRequest( hmi_capabilities, policy_handler) , interaction_mode_(mobile_apis::InteractionMode::INVALID_ENUM) + , ui_choice_id_received_(INVALID_CHOICE_ID) + , vr_choice_id_received_(INVALID_CHOICE_ID) , ui_response_received_(false) , vr_response_received_(false) , app_pi_was_active_before_(false) , vr_result_code_(hmi_apis::Common_Result::INVALID_ENUM) , 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); @@ -82,17 +91,18 @@ PerformInteractionRequest::~PerformInteractionRequest() {} bool PerformInteractionRequest::Init() { /* Timeout in milliseconds. If omitted a standard value of 10000 milliseconds is used.*/ - if ((*message_)[strings::msg_params].keyExists(strings::timeout)) { - default_timeout_ = - (*message_)[strings::msg_params][strings::timeout].asUInt(); - } + const auto& msg_params = (*message_)[strings::msg_params]; + uint32_t request_timeout = msg_params[strings::timeout].asUInt(); interaction_mode_ = static_cast<mobile_apis::InteractionMode::eType>( - (*message_)[strings::msg_params][strings::interaction_mode].asInt()); + msg_params[strings::interaction_mode].asInt()); if (mobile_apis::InteractionMode::BOTH == interaction_mode_ || mobile_apis::InteractionMode::MANUAL_ONLY == interaction_mode_) { - default_timeout_ *= 2; + const uint32_t increase_value = 2; + default_timeout_ += request_timeout * increase_value; + } else { + default_timeout_ += request_timeout; } return true; } @@ -226,8 +236,6 @@ void PerformInteractionRequest::Run() { void PerformInteractionRequest::on_event(const event_engine::Event& event) { LOG4CXX_AUTO_TRACE(logger_); const smart_objects::SmartObject& message = event.smart_object(); - smart_objects::SmartObject msg_param = - smart_objects::SmartObject(smart_objects::SmartType_Map); switch (event.id()) { case hmi_apis::FunctionID::UI_OnResetTimeout: { @@ -240,22 +248,24 @@ void PerformInteractionRequest::on_event(const event_engine::Event& event) { LOG4CXX_DEBUG(logger_, "Received UI_PerformInteraction event"); EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); ui_response_received_ = true; + unsubscribe_from_event(hmi_apis::FunctionID::UI_PerformInteraction); ui_result_code_ = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asUInt()); GetInfo(message, ui_info_); - ProcessUIResponse(event.smart_object(), msg_param); + ProcessUIResponse(event.smart_object(), response_msg_params); break; } case hmi_apis::FunctionID::VR_PerformInteraction: { LOG4CXX_DEBUG(logger_, "Received VR_PerformInteraction"); EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VR); vr_response_received_ = true; + unsubscribe_from_event(hmi_apis::FunctionID::VR_PerformInteraction); vr_result_code_ = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asUInt()); GetInfo(message, vr_info_); - if (ProcessVRResponse(event.smart_object(), msg_param)) { + if (ProcessVRResponse(event.smart_object(), response_msg_params)) { return; } break; @@ -267,8 +277,17 @@ void PerformInteractionRequest::on_event(const event_engine::Event& event) { } if (!HasHMIResponsesToWait()) { - LOG4CXX_DEBUG(logger_, "Send response in BOTH iteraction mode"); - SendBothModeResponse(msg_param); + LOG4CXX_DEBUG(logger_, + "Send response in interaction mode " + << static_cast<int32_t>(interaction_mode_)); + if (SetChoiceIdToResponseMsgParams(response_msg_params)) { + SendBothModeResponse(response_msg_params); + } else { + DisablePerformInteraction(); + SendResponse(false, + mobile_apis::Result::GENERIC_ERROR, + "Received two different choice IDs"); + } } } @@ -284,7 +303,7 @@ void PerformInteractionRequest::onTimeOut() { CommandRequestImpl::onTimeOut(); } else { application_manager_.updateRequestTimeout( - connection_key(), correlation_id(), default_timeout()); + connection_key(), correlation_id(), default_timeout_); } break; } @@ -341,10 +360,15 @@ bool PerformInteractionRequest::ProcessVRResponse( } LOG4CXX_DEBUG(logger_, "Update timeout for UI"); application_manager_.updateRequestTimeout( - connection_key(), correlation_id(), default_timeout()); + connection_key(), correlation_id(), default_timeout_); return false; } + if (!ui_response_received_ && + InteractionMode::MANUAL_ONLY != interaction_mode_) { + SendClosePopupRequestToHMI(); + } + const SmartObject& hmi_msg_params = message[strings::msg_params]; if (hmi_msg_params.keyExists(strings::choice_id)) { const int choice_id = hmi_msg_params[strings::choice_id].asInt(); @@ -355,7 +379,14 @@ bool PerformInteractionRequest::ProcessVRResponse( false, Result::GENERIC_ERROR, "Wrong choiceID was received from HMI"); return true; } - msg_params[strings::choice_id] = choice_id; + vr_choice_id_received_ = choice_id; + } + + if (mobile_apis::InteractionMode::BOTH == interaction_mode_ || + mobile_apis::InteractionMode::MANUAL_ONLY == interaction_mode_) { + LOG4CXX_DEBUG(logger_, "Update timeout for UI"); + application_manager_.updateRequestTimeout( + connection_key(), correlation_id(), default_timeout_); } const bool is_vr_result_success = Compare<Common_Result::eType, EQ, ONE>( @@ -389,8 +420,8 @@ void PerformInteractionRequest::ProcessUIResponse( HmiInterfaces::InterfaceState ui_interface_state = application_manager_.hmi_interfaces().GetInterfaceState( HmiInterfaces::HMI_INTERFACE_UI); - bool result = false; - result = Compare<hmi_apis::Common_Result::eType, EQ, ONE>( + + bool result = Compare<hmi_apis::Common_Result::eType, EQ, ONE>( ui_result_code_, hmi_apis::Common_Result::SUCCESS, hmi_apis::Common_Result::WARNINGS); @@ -422,11 +453,14 @@ void PerformInteractionRequest::ProcessUIResponse( // result code must be GENERIC_ERROR in case wrong choice_id if (msg_params.keyExists(strings::choice_id)) { - if (!CheckChoiceIDFromResponse(app, - msg_params[strings::choice_id].asInt())) { + const std::int32_t ui_choice_id = + static_cast<std::int32_t>(msg_params[strings::choice_id].asInt()); + + if (!CheckChoiceIDFromResponse(app, ui_choice_id)) { ui_result_code_ = hmi_apis::Common_Result::GENERIC_ERROR; ui_info_ = "Wrong choiceID was received from HMI"; } else { + ui_choice_id_received_ = ui_choice_id; msg_params[strings::trigger_source] = mobile_apis::TriggerSource::TS_MENU; } @@ -449,6 +483,11 @@ void PerformInteractionRequest::SendUIPerformInteractionRequest( smart_objects::SmartObject msg_params = smart_objects::SmartObject(smart_objects::SmartType_Map); + if ((*message_)[strings::msg_params].keyExists(strings::cancel_id)) { + msg_params[strings::cancel_id] = + (*message_)[strings::msg_params][strings::cancel_id].asInt(); + } + mobile_apis::InteractionMode::eType mode = static_cast<mobile_apis::InteractionMode::eType>( (*message_)[strings::msg_params][strings::interaction_mode].asInt()); @@ -471,12 +510,8 @@ void PerformInteractionRequest::SendUIPerformInteractionRequest( } } - if (mobile_apis::InteractionMode::BOTH == mode || - mobile_apis::InteractionMode::MANUAL_ONLY == mode) { - msg_params[strings::timeout] = default_timeout_ / 2; - } else { - msg_params[strings::timeout] = default_timeout_; - } + msg_params[strings::timeout] = + (*message_)[strings::msg_params][strings::timeout].asUInt(); msg_params[strings::app_id] = app->app_id(); if (mobile_apis::InteractionMode::VR_ONLY != mode) { msg_params[strings::choice_set] = @@ -532,6 +567,11 @@ void PerformInteractionRequest::SendVRPerformInteractionRequest( smart_objects::SmartObject msg_params = smart_objects::SmartObject(smart_objects::SmartType_Map); + if ((*message_)[strings::msg_params].keyExists(strings::cancel_id)) { + msg_params[strings::cancel_id] = + (*message_)[strings::msg_params][strings::cancel_id].asInt(); + } + smart_objects::SmartObject& choice_list = (*message_)[strings::msg_params][strings::interaction_choice_set_id_list]; @@ -652,16 +692,9 @@ void PerformInteractionRequest::SendVRPerformInteractionRequest( return; } - mobile_apis::InteractionMode::eType mode = - static_cast<mobile_apis::InteractionMode::eType>( - (*message_)[strings::msg_params][strings::interaction_mode].asInt()); - - if (mobile_apis::InteractionMode::BOTH == mode || - mobile_apis::InteractionMode::MANUAL_ONLY == mode) { - msg_params[strings::timeout] = default_timeout_ / 2; - } else { - msg_params[strings::timeout] = default_timeout_; - } + msg_params[strings::timeout] = + (*message_)[strings::msg_params][strings::timeout].asUInt(); + ; msg_params[strings::app_id] = app->app_id(); StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VR); SendHMIRequest( @@ -924,15 +957,19 @@ bool PerformInteractionRequest::IsWhiteSpaceExist() { void PerformInteractionRequest::TerminatePerformInteraction() { LOG4CXX_AUTO_TRACE(logger_); + SendClosePopupRequestToHMI(); + DisablePerformInteraction(); +} + +void PerformInteractionRequest::SendClosePopupRequestToHMI() { smart_objects::SmartObject msg_params = smart_objects::SmartObject(smart_objects::SmartType_Map); msg_params[hmi_request::method_name] = "UI.PerformInteraction"; SendHMIRequest(hmi_apis::FunctionID::UI_ClosePopUp, &msg_params); - DisablePerformInteraction(); } bool PerformInteractionRequest::CheckChoiceIDFromResponse( - ApplicationSharedPtr app, int32_t choice_id) { + ApplicationSharedPtr app, const int32_t choice_id) { LOG4CXX_AUTO_TRACE(logger_); const DataAccessor<PerformChoiceSetMap> accessor = app->performinteraction_choice_set_map(); @@ -944,12 +981,14 @@ bool PerformInteractionRequest::CheckChoiceIDFromResponse( const PerformChoice& choice = choice_set_map_it->second; PerformChoice::const_iterator it = choice.begin(); for (; choice.end() != it; ++it) { - const smart_objects::SmartObject& choice_set = - (*it->second).getElement(strings::choice_set); - for (size_t j = 0; j < choice_set.length(); ++j) { - if (choice_id == - choice_set.getElement(j).getElement(strings::choice_id).asInt()) { - return true; + if ((*it->second).keyExists(strings::choice_set)) { + const smart_objects::SmartObject& choice_set = + (*it->second).getElement(strings::choice_set); + for (size_t j = 0; j < choice_set.length(); ++j) { + if (choice_id == + choice_set.getElement(j).getElement(strings::choice_id).asInt()) { + return true; + } } } } @@ -1056,13 +1095,94 @@ void PerformInteractionRequest::SendBothModeResponse( msg_param.empty() ? NULL : &msg_param; std::string info = app_mngr::commands::MergeInfos( ui_perform_info, ui_info_, vr_perform_info, vr_info_); + DisablePerformInteraction(); + SendResponse(result, perform_interaction_result_code, info.empty() ? NULL : info.c_str(), response_params); } -} // namespace commands +mobile_apis::Result::eType +PerformInteractionRequest::PrepareResultCodeForResponse( + const app_mngr::commands::ResponseInfo& ui_response, + const app_mngr::commands::ResponseInfo& vr_response) { + LOG4CXX_DEBUG( + logger_, "InteractionMode = " << static_cast<int32_t>(interaction_mode_)); + + auto mobile_vr_result_code = + MessageHelper::HMIToMobileResult(vr_result_code_); + auto mobile_ui_result_code = + MessageHelper::HMIToMobileResult(ui_result_code_); + + if (mobile_apis::Result::eType::WARNINGS == mobile_vr_result_code) { + if (mobile_apis::Result::eType::SUCCESS == mobile_ui_result_code) { + return mobile_apis::Result::eType::WARNINGS; + } + } else if (mobile_apis::Result::eType::WARNINGS == mobile_ui_result_code) { + if (mobile_apis::Result::eType::SUCCESS == mobile_vr_result_code) { + return mobile_apis::Result::eType::WARNINGS; + } + } + if (mobile_apis::InteractionMode::VR_ONLY == interaction_mode_) { + return mobile_vr_result_code; + } + if (mobile_apis::InteractionMode::MANUAL_ONLY == interaction_mode_) { + return mobile_ui_result_code; + } + + if (INVALID_CHOICE_ID != vr_choice_id_received_) { + return mobile_vr_result_code; + } + if (INVALID_CHOICE_ID != ui_choice_id_received_) { + return mobile_ui_result_code; + } + + return CommandRequestImpl::PrepareResultCodeForResponse(ui_response, + vr_response); +} + +bool PerformInteractionRequest::PrepareResultForMobileResponse( + app_mngr::commands::ResponseInfo& ui_response, + app_mngr::commands::ResponseInfo& vr_response) const { + if (mobile_apis::InteractionMode::VR_ONLY == interaction_mode_) { + return vr_response.is_ok; + } + if (mobile_apis::InteractionMode::MANUAL_ONLY == interaction_mode_) { + return ui_response.is_ok; + } + + return (vr_response.is_ok || ui_response.is_ok); +} + +bool PerformInteractionRequest::SetChoiceIdToResponseMsgParams( + ns_smart_device_link::ns_smart_objects::SmartObject& msg_param) const { + LOG4CXX_AUTO_TRACE(logger_); + + const bool ui_choice_id_valid = INVALID_CHOICE_ID != ui_choice_id_received_; + const bool vr_choice_id_valid = INVALID_CHOICE_ID != vr_choice_id_received_; + + if (ui_choice_id_valid && vr_choice_id_valid && + ui_choice_id_received_ != vr_choice_id_received_) { + return false; + } + + if (mobile_apis::InteractionMode::eType::MANUAL_ONLY == interaction_mode_) { + msg_param[strings::choice_id] = ui_choice_id_received_; + return true; + } + + if (mobile_apis::InteractionMode::eType::VR_ONLY == interaction_mode_) { + msg_param[strings::choice_id] = vr_choice_id_received_; + return true; + } + + msg_param[strings::choice_id] = + ui_choice_id_valid ? ui_choice_id_received_ : vr_choice_id_received_; + return true; +} + +} // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/put_file_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/put_file_request.cc index f68596ce27..e25215fb48 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/put_file_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/put_file_request.cc @@ -94,7 +94,9 @@ void PutFileRequest::Run() { return; } - if (mobile_api::HMILevel::HMI_NONE == application->hmi_level() && + if (mobile_api::HMILevel::HMI_NONE == + application->hmi_level( + mobile_apis::PredefinedWindows::DEFAULT_WINDOW) && application_manager_.get_settings().put_file_in_none() <= application->put_file_in_none_count()) { // If application is in the HMI_NONE level the quantity of allowed 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 597df26d0a..5fb66c25ac 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 @@ -43,6 +43,7 @@ #include "application_manager/application_manager.h" #include "application_manager/helpers/application_helper.h" #include "application_manager/message_helper.h" +#include "application_manager/plugin_manager/plugin_keys.h" #include "application_manager/policies/policy_handler.h" #include "application_manager/policies/policy_handler_interface.h" #include "application_manager/resumption/resume_ctrl.h" @@ -158,13 +159,14 @@ class SmartArrayValueExtractor { }; struct IsSameNickname { - IsSameNickname(const custom_str::CustomString& app_id) : app_id_(app_id) {} + IsSameNickname(const custom_str::CustomString app_name) + : app_name_(app_name) {} bool operator()(const policy::StringArray::value_type& nickname) const { - return app_id_.CompareIgnoreCase(nickname.c_str()); + return app_name_.CompareIgnoreCase(nickname.c_str()); } private: - const custom_str::CustomString& app_id_; + const custom_str::CustomString app_name_; }; } // namespace @@ -184,7 +186,8 @@ RegisterAppInterfaceRequest::RegisterAppInterfaceRequest( rpc_service, hmi_capabilities, policy_handler) - , result_code_(mobile_apis::Result::INVALID_ENUM) {} + , result_code_(mobile_apis::Result::INVALID_ENUM) + , device_handle_(0) {} RegisterAppInterfaceRequest::~RegisterAppInterfaceRequest() {} @@ -224,20 +227,38 @@ void RegisterAppInterfaceRequest::Run() { return; } + // Cache the original app ID (for legacy behavior) + const auto policy_app_id = + application_manager_.GetCorrectMobileIDFromMessage(message_); + + if (application_manager_.IsApplicationForbidden(connection_key(), + policy_app_id)) { + SendResponse(false, mobile_apis::Result::TOO_MANY_PENDING_REQUESTS); + return; + } + + if (!GetDataOnSessionKey(connection_key(), &device_handle_, &device_id_)) { + SendResponse(false, + mobile_apis::Result::GENERIC_ERROR, + "Could not find a session for your connection key!"); + return; + } + + LOG4CXX_DEBUG( + logger_, + "device_handle: " << device_handle_ << " device_id: " << device_id_); + if (IsApplicationSwitched()) { return; } ApplicationSharedPtr application = - application_manager_.application(connection_key()); + application_manager_.application(device_id_, policy_app_id); if (application) { SendResponse(false, mobile_apis::Result::APPLICATION_REGISTERED_ALREADY); return; } - // cache the original app ID (for legacy behavior) - const std::string policy_app_id = - application_manager_.GetCorrectMobileIDFromMessage(message_); const smart_objects::SmartObject& msg_params = (*message_)[strings::msg_params]; @@ -260,11 +281,6 @@ void RegisterAppInterfaceRequest::Run() { ::tolower); (*message_)[strings::msg_params][strings::full_app_id] = new_app_id_full; } - if (application_manager_.IsApplicationForbidden(connection_key(), - policy_app_id)) { - SendResponse(false, mobile_apis::Result::TOO_MANY_PENDING_REQUESTS); - return; - } if (IsApplicationWithSameAppIdRegistered()) { SendResponse(false, mobile_apis::Result::DISALLOWED); @@ -281,50 +297,77 @@ void RegisterAppInterfaceRequest::Run() { return; } + mobile_apis::Result::eType coincidence_result = CheckCoincidence(); + std::vector<ApplicationSharedPtr> duplicate_apps; - mobile_apis::Result::eType coincidence_result = - CheckCoincidence(duplicate_apps); - - if (mobile_apis::Result::DUPLICATE_NAME == coincidence_result && - duplicate_apps.size() == 1) { - ApplicationSharedPtr duplicate_app = duplicate_apps.front(); - bool error_response = true; - if (duplicate_app->is_cloud_app()) { - if (duplicate_app->hybrid_app_preference() == - mobile_apis::HybridAppPreference::MOBILE) { - // Unregister cloud application and allow mobile application to register - // in it's place - application_manager_.UnregisterApplication( - duplicate_app->app_id(), mobile_apis::Result::USER_DISALLOWED); - error_response = false; - } + if (GetDuplicateNames(duplicate_apps)) { + LOG4CXX_ERROR(logger_, + "Found duplicate app names, checking for hybrid apps."); + // Default preference to BOTH + mobile_apis::HybridAppPreference::eType preference = + mobile_apis::HybridAppPreference::BOTH; + ApplicationSharedPtr app = + application_manager_.pending_application_by_policy_id(policy_app_id); + bool is_cloud_app = app.use_count() != 0 && app->is_cloud_app(); + if (is_cloud_app) { + // Retrieve hybrid app preference from registering app + preference = app->hybrid_app_preference(); } else { - ApplicationSharedPtr cloud_app = - application_manager_.pending_application_by_policy_id(policy_app_id); - // If the duplicate name was not because of a mobile/cloud app pair, go - // through the normal process for handling duplicate names - if (cloud_app.use_count() == 0 || !cloud_app->is_cloud_app()) { + if (mobile_apis::Result::DUPLICATE_NAME == coincidence_result) { usage_statistics::AppCounter count_of_rejections_duplicate_name( GetPolicyHandler().GetStatisticManager(), policy_app_id, usage_statistics::REJECTIONS_DUPLICATE_NAME); ++count_of_rejections_duplicate_name; - } else if (cloud_app->hybrid_app_preference() == - mobile_apis::HybridAppPreference::CLOUD) { - // Unregister mobile application and allow cloud application to - // register in it's place - application_manager_.UnregisterApplication( - duplicate_app->app_id(), mobile_apis::Result::USER_DISALLOWED); - error_response = false; + } + // Search for the hybrid app preference in the duplicate app list + for (auto duplicate_app : duplicate_apps) { + if (duplicate_app->is_cloud_app()) { + preference = duplicate_app->hybrid_app_preference(); + break; + } } } - if (error_response) { - LOG4CXX_ERROR(logger_, "Coincidence check failed."); - SendResponse(false, coincidence_result); - return; + if (preference == mobile_apis::HybridAppPreference::MOBILE || + preference == mobile_apis::HybridAppPreference::CLOUD) { + bool cloud_app_exists = is_cloud_app; + bool mobile_app_exists = !is_cloud_app; + for (auto duplicate_app : duplicate_apps) { + cloud_app_exists = cloud_app_exists || (duplicate_app->IsRegistered() && + duplicate_app->is_cloud_app()); + mobile_app_exists = mobile_app_exists || !duplicate_app->is_cloud_app(); + if (is_cloud_app && !duplicate_app->is_cloud_app() && + preference == mobile_apis::HybridAppPreference::CLOUD) { + // Unregister mobile application and allow cloud application to + // register in it's place + LOG4CXX_ERROR( + logger_, + "Unregistering app because a preferred version is registered."); + application_manager_.UnregisterApplication( + duplicate_app->app_id(), + mobile_apis::Result::USER_DISALLOWED, + "App is disabled by user preferences"); + } + } + + bool mobile_app_matches = + !is_cloud_app && + preference == mobile_apis::HybridAppPreference::MOBILE; + bool cloud_app_matches = + is_cloud_app && preference == mobile_apis::HybridAppPreference::CLOUD; + + bool is_preferred_application = mobile_app_matches || cloud_app_matches; + if (mobile_app_exists && cloud_app_exists && !is_preferred_application) { + SendResponse(false, + mobile_apis::Result::USER_DISALLOWED, + "App is disabled by user preferences"); + return; + } } - } else if (mobile_apis::Result::SUCCESS != coincidence_result) { + } + + if (mobile_apis::Result::SUCCESS != coincidence_result) { LOG4CXX_ERROR(logger_, "Coincidence check failed."); SendResponse(false, coincidence_result); return; @@ -443,6 +486,12 @@ void RegisterAppInterfaceRequest::Run() { } } + auto on_app_registered = [application](plugin_manager::RPCPlugin& plugin) { + plugin.OnApplicationEvent(plugin_manager::kApplicationRegistered, + application); + }; + application_manager_.ApplyFunctorForEachPlugin(on_app_registered); + if (msg_params.keyExists(strings::day_color_scheme)) { application->set_day_color_scheme(msg_params[strings::day_color_scheme]); } @@ -502,126 +551,116 @@ RegisterAppInterfaceRequest::GetLockScreenIconUrlNotification( (*message)[strings::msg_params][strings::request_type] = mobile_apis::RequestType::LOCK_SCREEN_ICON_URL; (*message)[strings::msg_params][strings::url] = - GetPolicyHandler().GetLockScreenIconUrl(); + GetPolicyHandler().GetLockScreenIconUrl(app->policy_app_id()); return message; } void FillVRRelatedFields(smart_objects::SmartObject& response_params, const HMICapabilities& hmi_capabilities) { - response_params[strings::language] = hmi_capabilities.active_vr_language(); - if (hmi_capabilities.vr_capabilities()) { - response_params[strings::vr_capabilities] = - *hmi_capabilities.vr_capabilities(); + auto active_vr_lang = hmi_capabilities.active_vr_language(); + if (hmi_apis::Common_Language::INVALID_ENUM != active_vr_lang) { + response_params[strings::language] = active_vr_lang; + } + auto vr_capabilities = hmi_capabilities.vr_capabilities(); + if (vr_capabilities) { + response_params[strings::vr_capabilities] = *vr_capabilities; } } void FillVIRelatedFields(smart_objects::SmartObject& response_params, const HMICapabilities& hmi_capabilities) { - if (hmi_capabilities.vehicle_type()) { - response_params[hmi_response::vehicle_type] = - *hmi_capabilities.vehicle_type(); + auto vehicle_type = hmi_capabilities.vehicle_type(); + if (vehicle_type) { + response_params[hmi_response::vehicle_type] = *vehicle_type; } } void FillTTSRelatedFields(smart_objects::SmartObject& response_params, const HMICapabilities& hmi_capabilities) { - response_params[strings::language] = hmi_capabilities.active_tts_language(); - if (hmi_capabilities.speech_capabilities()) { - response_params[strings::speech_capabilities] = - *hmi_capabilities.speech_capabilities(); + auto active_tts_lang = hmi_capabilities.active_tts_language(); + if (hmi_apis::Common_Language::INVALID_ENUM != active_tts_lang) { + response_params[strings::language] = active_tts_lang; + } + auto speech_capabilities = hmi_capabilities.speech_capabilities(); + if (speech_capabilities) { + response_params[strings::speech_capabilities] = *speech_capabilities; } - if (hmi_capabilities.prerecorded_speech()) { - response_params[strings::prerecorded_speech] = - *(hmi_capabilities.prerecorded_speech()); + auto prerecorded_speech = hmi_capabilities.prerecorded_speech(); + if (prerecorded_speech) { + response_params[strings::prerecorded_speech] = *prerecorded_speech; } } void FillUIRelatedFields(smart_objects::SmartObject& response_params, const HMICapabilities& hmi_capabilities) { - response_params[strings::hmi_display_language] = - hmi_capabilities.active_ui_language(); - if (hmi_capabilities.display_capabilities()) { + auto active_ui_lang = hmi_capabilities.active_ui_language(); + if (hmi_apis::Common_Language::INVALID_ENUM != active_ui_lang) { + response_params[strings::hmi_display_language] = active_ui_lang; + } + + auto display_capabilities = hmi_capabilities.display_capabilities(); + if (display_capabilities) { response_params[hmi_response::display_capabilities] = smart_objects::SmartObject(smart_objects::SmartType_Map); smart_objects::SmartObject& display_caps = response_params[hmi_response::display_capabilities]; - if (hmi_capabilities.display_capabilities()->keyExists( - hmi_response::display_type)) { + if (display_capabilities->keyExists(hmi_response::display_type)) { display_caps[hmi_response::display_type] = - hmi_capabilities.display_capabilities()->getElement( - hmi_response::display_type); + display_capabilities->getElement(hmi_response::display_type); } - if (hmi_capabilities.display_capabilities()->keyExists( - hmi_response::display_name)) { + if (display_capabilities->keyExists(hmi_response::display_name)) { display_caps[hmi_response::display_name] = - hmi_capabilities.display_capabilities()->getElement( - hmi_response::display_name); + display_capabilities->getElement(hmi_response::display_name); } - if (hmi_capabilities.display_capabilities()->keyExists( - hmi_response::text_fields)) { + if (display_capabilities->keyExists(hmi_response::text_fields)) { display_caps[hmi_response::text_fields] = - hmi_capabilities.display_capabilities()->getElement( - hmi_response::text_fields); + display_capabilities->getElement(hmi_response::text_fields); } - if (hmi_capabilities.display_capabilities()->keyExists( - hmi_response::image_fields)) { + if (display_capabilities->keyExists(hmi_response::image_fields)) { display_caps[hmi_response::image_fields] = - hmi_capabilities.display_capabilities()->getElement( - hmi_response::image_fields); + display_capabilities->getElement(hmi_response::image_fields); } - if (hmi_capabilities.display_capabilities()->keyExists( - hmi_response::media_clock_formats)) { + if (display_capabilities->keyExists(hmi_response::media_clock_formats)) { display_caps[hmi_response::media_clock_formats] = - hmi_capabilities.display_capabilities()->getElement( - hmi_response::media_clock_formats); + display_capabilities->getElement(hmi_response::media_clock_formats); } - if (hmi_capabilities.display_capabilities()->keyExists( - hmi_response::templates_available)) { + if (display_capabilities->keyExists(hmi_response::templates_available)) { display_caps[hmi_response::templates_available] = - hmi_capabilities.display_capabilities()->getElement( - hmi_response::templates_available); + display_capabilities->getElement(hmi_response::templates_available); } - if (hmi_capabilities.display_capabilities()->keyExists( - hmi_response::screen_params)) { + if (display_capabilities->keyExists(hmi_response::screen_params)) { display_caps[hmi_response::screen_params] = - hmi_capabilities.display_capabilities()->getElement( - hmi_response::screen_params); + display_capabilities->getElement(hmi_response::screen_params); } - if (hmi_capabilities.display_capabilities()->keyExists( + if (display_capabilities->keyExists( hmi_response::num_custom_presets_available)) { display_caps[hmi_response::num_custom_presets_available] = - hmi_capabilities.display_capabilities()->getElement( + display_capabilities->getElement( hmi_response::num_custom_presets_available); } - if (hmi_capabilities.display_capabilities()->keyExists( - hmi_response::image_capabilities)) { + if (display_capabilities->keyExists(hmi_response::image_capabilities)) { display_caps[hmi_response::graphic_supported] = - (hmi_capabilities.display_capabilities() - ->getElement(hmi_response::image_capabilities) + (display_capabilities->getElement(hmi_response::image_capabilities) .length() > 0); } } - if (hmi_capabilities.audio_pass_thru_capabilities()) { - if (smart_objects::SmartType_Array == - hmi_capabilities.audio_pass_thru_capabilities()->getType()) { - // hmi_capabilities json contains array and HMI response object - response_params[strings::audio_pass_thru_capabilities] = - *hmi_capabilities.audio_pass_thru_capabilities(); - } else { - response_params[strings::audio_pass_thru_capabilities][0] = - *hmi_capabilities.audio_pass_thru_capabilities(); - } + auto audio_pass_thru_capabilities = + hmi_capabilities.audio_pass_thru_capabilities(); + if (audio_pass_thru_capabilities) { + // hmi_capabilities json contains array and HMI response object + response_params[strings::audio_pass_thru_capabilities] = + *audio_pass_thru_capabilities; } response_params[strings::hmi_capabilities] = smart_objects::SmartObject(smart_objects::SmartType_Map); @@ -633,6 +672,11 @@ void FillUIRelatedFields(smart_objects::SmartObject& response_params, hmi_capabilities.video_streaming_supported(); response_params[strings::hmi_capabilities][strings::remote_control] = hmi_capabilities.rc_supported(); + response_params[strings::hmi_capabilities][strings::app_services] = true; + // Apps are automatically subscribed to the SystemCapability: DISPLAYS + response_params[strings::hmi_capabilities][strings::displays] = true; + response_params[strings::hmi_capabilities][strings::seat_location] = + hmi_capabilities.seat_location_capability() ? true : false; } void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile( @@ -714,36 +758,39 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile( FillVIRelatedFields(response_params, hmi_capabilities); } - if (hmi_capabilities.button_capabilities()) { - response_params[hmi_response::button_capabilities] = - *hmi_capabilities.button_capabilities(); + auto button_capabilities = hmi_capabilities.button_capabilities(); + if (button_capabilities) { + response_params[hmi_response::button_capabilities] = *button_capabilities; } - if (hmi_capabilities.soft_button_capabilities()) { + auto soft_button_capabilities = hmi_capabilities.soft_button_capabilities(); + if (soft_button_capabilities) { response_params[hmi_response::soft_button_capabilities] = - *hmi_capabilities.soft_button_capabilities(); + *soft_button_capabilities; } - if (hmi_capabilities.preset_bank_capabilities()) { + auto preset_bank_capabilities = hmi_capabilities.preset_bank_capabilities(); + if (preset_bank_capabilities) { response_params[hmi_response::preset_bank_capabilities] = - *hmi_capabilities.preset_bank_capabilities(); + *preset_bank_capabilities; } - if (hmi_capabilities.hmi_zone_capabilities()) { - if (smart_objects::SmartType_Array == - hmi_capabilities.hmi_zone_capabilities()->getType()) { + auto hmi_zone_capabilities = hmi_capabilities.hmi_zone_capabilities(); + if (hmi_zone_capabilities) { + if (smart_objects::SmartType_Array == hmi_zone_capabilities->getType()) { // hmi_capabilities json contains array and HMI response object response_params[hmi_response::hmi_zone_capabilities] = - *hmi_capabilities.hmi_zone_capabilities(); + *hmi_zone_capabilities; } else { response_params[hmi_response::hmi_zone_capabilities][0] = - *hmi_capabilities.hmi_zone_capabilities(); + *hmi_zone_capabilities; } } - if (hmi_capabilities.pcm_stream_capabilities()) { + auto pcm_stream_capabilities = hmi_capabilities.pcm_stream_capabilities(); + if (pcm_stream_capabilities) { response_params[strings::pcm_stream_capabilities] = - *hmi_capabilities.pcm_stream_capabilities(); + *pcm_stream_capabilities; } const std::vector<uint32_t>& diag_modes = @@ -785,15 +832,16 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile( return; } - bool resumption = + const bool hash_id_present = (*message_)[strings::msg_params].keyExists(strings::hash_id); + const std::string hash_id = + (*message_)[strings::msg_params][strings::hash_id].asString(); + const bool resumption = hash_id_present && !hash_id.empty(); bool need_restore_vr = resumption; - std::string hash_id; std::string add_info; if (resumption) { - hash_id = (*message_)[strings::msg_params][strings::hash_id].asString(); if (!resumer.CheckApplicationHash(application, hash_id)) { LOG4CXX_WARN(logger_, "Hash from RAI does not match to saved resume data."); @@ -807,6 +855,8 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile( need_restore_vr = false; } else { add_info = "Resume succeeded."; + application->set_app_data_resumption_allowance(true); + application->set_is_resuming(true); } } if ((mobile_apis::Result::SUCCESS == result_code) && @@ -815,10 +865,18 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile( result_code = result_code_; } - // in case application exist in resumption we need to send resumeVrgrammars - if (false == resumption) { - resumption = resumer.IsApplicationSaved(application->policy_app_id(), - application->mac_address()); + // In case application exist in resumption we need to send resumeVrgrammars + const bool is_app_saved_in_resumption = resumer.IsApplicationSaved( + application->policy_app_id(), application->mac_address()); + + // If app is in resuming state + // DisplayCapabilitiesBuilder has to collect all the information + // from incoming HMI notifications and send only one notification + // to mobile app, even if hash does not match, which means that app data + // will not be resumed, notification should be sent for default window as + // it will be resumed in any case + if (resumption || is_app_saved_in_resumption) { + resumer.StartWaitingForDisplayCapabilitiesUpdate(application); } AppHmiTypes hmi_types; @@ -835,20 +893,27 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile( } } policy::StatusNotifier notify_upd_manager = GetPolicyHandler().AddApplication( - application->policy_app_id(), hmi_types); + application->mac_address(), application->policy_app_id(), hmi_types); response_params[strings::icon_resumed] = file_system::FileExists(application->app_icon_path()); SendResponse(true, result_code, add_info.c_str(), &response_params); if (msg_params.keyExists(strings::app_hmi_type)) { - GetPolicyHandler().SetDefaultHmiTypes(application->policy_app_id(), + GetPolicyHandler().SetDefaultHmiTypes(application->device(), + application->policy_app_id(), &(msg_params[strings::app_hmi_type])); } // Default HMI level should be set before any permissions validation, since it // relies on HMI level. application_manager_.OnApplicationRegistered(application); + + auto send_rc_status = [application](plugin_manager::RPCPlugin& plugin) { + plugin.OnApplicationEvent(plugin_manager::kRCStatusChanged, application); + }; + application_manager_.ApplyFunctorForEachPlugin(send_rc_status); + SendOnAppRegisteredNotificationToHMI( application, resumption, need_restore_vr); (*notify_upd_manager)(); @@ -856,11 +921,13 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile( // Start PTU after successfull registration // Sends OnPermissionChange notification to mobile right after RAI response // and HMI level set-up - GetPolicyHandler().OnAppRegisteredOnMobile(application->policy_app_id()); + GetPolicyHandler().OnAppRegisteredOnMobile(application->mac_address(), + application->policy_app_id()); - if (result_code != mobile_apis::Result::RESUME_FAILED) { + if (result_code != mobile_apis::Result::RESUME_FAILED && + application->is_app_data_resumption_allowed()) { resumer.StartResumption(application, hash_id); - } else { + } else if (is_app_saved_in_resumption) { resumer.StartResumptionOnlyHMILevel(application); } @@ -955,61 +1022,113 @@ void RegisterAppInterfaceRequest::SendOnAppRegisteredNotificationToHMI( DCHECK(rpc_service_.ManageHMICommand(notification)); } -mobile_apis::Result::eType RegisterAppInterfaceRequest::CheckCoincidence( - std::vector<ApplicationSharedPtr>& out_duplicate_apps) { +mobile_apis::Result::eType RegisterAppInterfaceRequest::CheckCoincidence() { LOG4CXX_AUTO_TRACE(logger_); const smart_objects::SmartObject& msg_params = (*message_)[strings::msg_params]; - ApplicationSet accessor = application_manager_.applications().GetData(); + auto compare_tts_name = [](const smart_objects::SmartObject& obj_1, + const smart_objects::SmartObject& obj_2) { + return obj_1[application_manager::strings::text] + .asCustomString() + .CompareIgnoreCase( + obj_2[application_manager::strings::text].asCustomString()); + }; - ApplicationSetConstIt it = accessor.begin(); - const custom_str::CustomString& app_name = - msg_params[strings::app_name].asCustomString(); + const auto& accessor = application_manager_.applications().GetData(); + const auto& app_name = msg_params[strings::app_name].asCustomString(); - for (; accessor.end() != it; ++it) { - // name check - const custom_str::CustomString& cur_name = (*it)->name(); + for (const auto& app : accessor) { + if (app->device() != device_handle_) { + continue; + } + // Name check + const auto& cur_name = app->name(); if (app_name.CompareIgnoreCase(cur_name)) { LOG4CXX_ERROR(logger_, "Application name is known already."); - out_duplicate_apps.push_back(*it); - continue; + return mobile_apis::Result::DUPLICATE_NAME; } - - const smart_objects::SmartObject* vr = (*it)->vr_synonyms(); - const std::vector<smart_objects::SmartObject>* curr_vr = NULL; - if (NULL != vr) { - curr_vr = vr->asArray(); + const auto vr = app->vr_synonyms(); + if (vr) { + const auto curr_vr = vr->asArray(); CoincidencePredicateVR v(app_name); if (0 != std::count_if(curr_vr->begin(), curr_vr->end(), v)) { LOG4CXX_ERROR(logger_, "Application name is known already."); - out_duplicate_apps.push_back(*it); - continue; + return mobile_apis::Result::DUPLICATE_NAME; } } - // vr check + // VR check if (msg_params.keyExists(strings::vr_synonyms)) { - const std::vector<smart_objects::SmartObject>* new_vr = - msg_params[strings::vr_synonyms].asArray(); + const auto new_vr = msg_params[strings::vr_synonyms].asArray(); CoincidencePredicateVR v(cur_name); if (0 != std::count_if(new_vr->begin(), new_vr->end(), v)) { LOG4CXX_ERROR(logger_, "vr_synonyms duplicated with app_name ."); - out_duplicate_apps.push_back(*it); - continue; + return mobile_apis::Result::DUPLICATE_NAME; } - } // end vr check + } // End vr check + + // TTS check + if (msg_params.keyExists(strings::tts_name) && app->tts_name()) { + const auto tts_array = msg_params[strings::tts_name].asArray(); + const auto tts_curr = app->tts_name()->asArray(); + const auto& it_tts = std::find_first_of(tts_array->begin(), + tts_array->end(), + tts_curr->begin(), + tts_curr->end(), + compare_tts_name); + if (it_tts != tts_array->end()) { + LOG4CXX_ERROR( + logger_, + "TTS name: " + << (*it_tts)[strings::text].asCustomString().AsMBString() + << " is known already"); + return mobile_apis::Result::DUPLICATE_NAME; + } + } // End tts check - } // application for end + } // Application for end - if (!out_duplicate_apps.empty()) { - return mobile_apis::Result::DUPLICATE_NAME; - } return mobile_apis::Result::SUCCESS; } // method end +bool RegisterAppInterfaceRequest::GetDuplicateNames( + std::vector<ApplicationSharedPtr>& out_duplicate_apps) { + LOG4CXX_AUTO_TRACE(logger_); + const smart_objects::SmartObject& msg_params = + (*message_)[strings::msg_params]; + + const auto& app_name = msg_params[strings::app_name].asCustomString(); + { + const auto& accessor = application_manager_.applications().GetData(); + + for (const auto& app : accessor) { + const auto& cur_name = app->name(); + if (app_name.CompareIgnoreCase(cur_name)) { + out_duplicate_apps.push_back(app); + } + } + } + + const std::string policy_app_id = + application_manager_.GetCorrectMobileIDFromMessage(message_); + { + const auto& accessor = + application_manager_.pending_applications().GetData(); + + for (const auto& app : accessor) { + const auto& cur_name = app->name(); + if (app_name.CompareIgnoreCase(cur_name) && + policy_app_id != app->policy_app_id()) { + out_duplicate_apps.push_back(app); + } + } + } + return !out_duplicate_apps.empty(); +} + mobile_apis::Result::eType RegisterAppInterfaceRequest::CheckWithPolicyData() { LOG4CXX_AUTO_TRACE(logger_); // TODO(AOleynik): Check is necessary to allow register application in case @@ -1131,14 +1250,19 @@ bool RegisterAppInterfaceRequest::IsApplicationWithSameAppIdRegistered() { const custom_string::CustomString mobile_app_id( application_manager_.GetCorrectMobileIDFromMessage(message_)); - const ApplicationSet& applications = - application_manager_.applications().GetData(); - - ApplicationSetConstIt it = applications.begin(); - ApplicationSetConstIt it_end = applications.end(); - - for (; it != it_end; ++it) { - if (mobile_app_id.CompareIgnoreCase((*it)->policy_app_id().c_str())) { + const auto& applications = application_manager_.applications().GetData(); + + for (const auto& app : applications) { + if (mobile_app_id.CompareIgnoreCase(app->policy_app_id().c_str())) { + if (app->device() != device_handle_) { + LOG4CXX_DEBUG(logger_, + "These policy_app_id equal, but applications have " + "different device id" + << " mobile_app_id: " << mobile_app_id.c_str() + << " device_handle: " << device_handle_ + << " device_handle: " << app->device()); + continue; + } return true; } } @@ -1308,13 +1432,12 @@ void RegisterAppInterfaceRequest::CheckResponseVehicleTypeParam( void RegisterAppInterfaceRequest::SendSubscribeCustomButtonNotification() { using namespace smart_objects; - using namespace hmi_apis; - SmartObject msg_params = SmartObject(SmartType_Map); msg_params[strings::app_id] = connection_key(); - msg_params[strings::name] = Common_ButtonName::CUSTOM_BUTTON; + msg_params[strings::name] = hmi_apis::Common_ButtonName::CUSTOM_BUTTON; msg_params[strings::is_suscribed] = true; - CreateHMINotification(FunctionID::Buttons_OnButtonSubscription, msg_params); + CreateHMINotification(hmi_apis::FunctionID::Buttons_OnButtonSubscription, + msg_params); } bool RegisterAppInterfaceRequest::IsApplicationSwitched() { @@ -1322,8 +1445,8 @@ bool RegisterAppInterfaceRequest::IsApplicationSwitched() { application_manager_.GetCorrectMobileIDFromMessage(message_); LOG4CXX_DEBUG(logger_, "Looking for application id " << policy_app_id); - - auto app = application_manager_.application_by_policy_id(policy_app_id); + auto app = + application_manager_.reregister_application_by_policy_id(policy_app_id); if (!app) { LOG4CXX_DEBUG( @@ -1334,12 +1457,14 @@ bool RegisterAppInterfaceRequest::IsApplicationSwitched() { LOG4CXX_DEBUG(logger_, "Application with policy id " << policy_app_id << " is found."); - if (!application_manager_.IsAppInReconnectMode(policy_app_id)) { - LOG4CXX_DEBUG( - logger_, - "Policy id " << policy_app_id << " is not found in reconnection list."); + + const auto app_device_handle = app->device(); + if (app_device_handle == device_handle_) { + LOG4CXX_DEBUG(logger_, + "Application " << policy_app_id + << " is already registered from this device."); SendResponse(false, mobile_apis::Result::APPLICATION_REGISTERED_ALREADY); - return false; + return true; } LOG4CXX_DEBUG(logger_, "Application is found in reconnection list."); @@ -1358,13 +1483,61 @@ bool RegisterAppInterfaceRequest::IsApplicationSwitched() { application_manager_.ProcessReconnection(app, connection_key()); SendRegisterAppInterfaceResponseToMobile(app_type); - application_manager_.SendHMIStatusNotification(app); + MessageHelper::SendHMIStatusNotification( + app, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, + application_manager_); application_manager_.OnApplicationSwitched(app); return true; } +bool RegisterAppInterfaceRequest::GetDataOnSessionKey( + const uint32_t key, + connection_handler::DeviceHandle* device_id, + std::string* mac_address) const { + LOG4CXX_AUTO_TRACE(logger_); + + if ((nullptr == mac_address) && (nullptr == device_id)) { + LOG4CXX_ERROR(logger_, + "Can't get data on session key because device id and mac " + "address are empty."); + return false; + } + + connection_handler::DeviceHandle device_handle = 0; + auto& connect_handler = application_manager_.connection_handler(); + + auto result = connect_handler.GetDataOnSessionKey( + connection_key(), nullptr, nullptr, &device_handle); + + if (result) { + LOG4CXX_DEBUG( + logger_, + "Failed to get device info for connection key: " << connection_key()); + return false; + } + + if (mac_address) { + result = connect_handler.get_session_observer().GetDataOnDeviceID( + device_handle, nullptr, nullptr, mac_address, nullptr); + } + + if (result) { + LOG4CXX_DEBUG(logger_, + "Failed get unique address info for connection key: " + << connection_key()); + return false; + } + + if (device_id) { + *device_id = device_handle; + } + + return true; +} + policy::PolicyHandlerInterface& RegisterAppInterfaceRequest::GetPolicyHandler() { return policy_handler_; 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 ffd8a7dc81..a0e178d0e2 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 @@ -198,8 +198,21 @@ bool ResetGlobalPropertiesRequest::ResetHelpPromt( SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED); return false; } + const std::vector<std::string>& help_prompt = + application_manager_.get_settings().help_prompt(); + smart_objects::SmartObject so_help_prompt = smart_objects::SmartObject(smart_objects::SmartType_Array); + + for (size_t i = 0; i < help_prompt.size(); ++i) { + smart_objects::SmartObject help_prompt_item = + smart_objects::SmartObject(smart_objects::SmartType_Map); + help_prompt_item[strings::text] = help_prompt[i]; + help_prompt_item[strings::type] = + hmi_apis::Common_SpeechCapabilities::SC_TEXT; + so_help_prompt[i] = help_prompt_item; + } + app->set_help_prompt(so_help_prompt); return true; } @@ -218,7 +231,7 @@ bool ResetGlobalPropertiesRequest::ResetTimeoutPromt( smart_objects::SmartObject so_time_out_promt = smart_objects::SmartObject(smart_objects::SmartType_Array); - for (uint32_t i = 0; i < time_out_promt.size(); ++i) { + for (size_t i = 0; i < time_out_promt.size(); ++i) { smart_objects::SmartObject timeoutPrompt = smart_objects::SmartObject(smart_objects::SmartType_Map); timeoutPrompt[strings::text] = time_out_promt[i]; @@ -238,8 +251,16 @@ bool ResetGlobalPropertiesRequest::ResetVrHelpTitleItems( SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED); return false; } + + const std::string& vr_help_title = + application_manager_.get_settings().vr_help_title(); + smart_objects::SmartObject so_vr_help_title = + smart_objects::SmartObject(smart_objects::SmartType_String); + so_vr_help_title = vr_help_title; + app->reset_vr_help_title(); app->reset_vr_help(); + app->set_vr_help_title(so_vr_help_title); return true; } 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 c1d02c96d3..90dbb91b5f 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 @@ -65,13 +65,9 @@ ScrollableMessageRequest::~ScrollableMessageRequest() {} bool ScrollableMessageRequest::Init() { /* Timeout in milliseconds. If omitted a standard value of 10000 milliseconds is used.*/ - if ((*message_)[strings::msg_params].keyExists(strings::timeout)) { - default_timeout_ = - (*message_)[strings::msg_params][strings::timeout].asUInt(); - } else { - const int32_t def_value = 30000; - default_timeout_ = def_value; - } + uint32_t request_timeout = + (*message_)[strings::msg_params][strings::timeout].asUInt(); + default_timeout_ += request_timeout; return true; } @@ -110,7 +106,13 @@ void ScrollableMessageRequest::Run() { msg_params[hmi_request::message_text][hmi_request::field_text] = (*message_)[strings::msg_params][strings::scroll_message_body]; msg_params[strings::app_id] = app->app_id(); - msg_params[strings::timeout] = default_timeout_; + msg_params[strings::timeout] = + (*message_)[strings::msg_params][strings::timeout].asUInt(); + + if ((*message_)[strings::msg_params].keyExists(strings::cancel_id)) { + msg_params[strings::cancel_id] = + (*message_)[strings::msg_params][strings::cancel_id].asInt(); + } if ((*message_)[strings::msg_params].keyExists(strings::soft_buttons)) { msg_params[strings::soft_buttons] = diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/send_location_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/send_location_request.cc index 1df4d788d2..805c0f0e41 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/send_location_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/send_location_request.cc @@ -254,10 +254,10 @@ bool SendLocationRequest::CheckHMICapabilities( return false; } - if (hmi_capabilities.display_capabilities()) { - const SmartObject disp_cap = (*hmi_capabilities.display_capabilities()); + auto display_capabilities = hmi_capabilities.display_capabilities(); + if (display_capabilities) { const SmartObject& text_fields = - disp_cap.getElement(hmi_response::text_fields); + display_capabilities->getElement(hmi_response::text_fields); const size_t len = text_fields.length(); for (size_t i = 0; i < len; ++i) { const SmartObject& text_field = text_fields[i]; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_app_icon_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_app_icon_request.cc index b2363e870f..ed77d8a550 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_app_icon_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_app_icon_request.cc @@ -60,6 +60,14 @@ SetAppIconRequest::SetAppIconRequest( , is_icons_saving_enabled_(false) { const std::string path = application_manager_.get_settings().app_icons_folder(); + + if (!file_system::DirectoryExists(path)) { + LOG4CXX_WARN(logger_, "App icons folder doesn't exist."); + if (!file_system::CreateDirectoryRecursively(path)) { + LOG4CXX_ERROR(logger_, "Unable to create app icons directory: " << path); + } + } + is_icons_saving_enabled_ = file_system::IsWritingAllowed(path) && file_system::IsReadingAllowed(path); } @@ -106,25 +114,22 @@ void SetAppIconRequest::Run() { msg_params[strings::sync_file_name] = smart_objects::SmartObject(smart_objects::SmartType_Map); - // Panasonic requres unchanged path value without encoded special characters - const std::string full_file_path_for_hmi = - file_system::ConvertPathForURL(full_file_path); + // For further use in on_event function + full_file_path_for_hmi_ = file_system::ConvertPathForURL(full_file_path); - msg_params[strings::sync_file_name][strings::value] = full_file_path_for_hmi; + msg_params[strings::sync_file_name][strings::value] = full_file_path_for_hmi_; // TODO(VS): research why is image_type hardcoded msg_params[strings::sync_file_name][strings::image_type] = static_cast<int32_t>(SetAppIconRequest::ImageType::DYNAMIC); - // for further use in on_event function - (*message_)[strings::msg_params][strings::sync_file_name] = - msg_params[strings::sync_file_name]; StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); SendHMIRequest(hmi_apis::FunctionID::UI_SetAppIcon, &msg_params, true); } void SetAppIconRequest::CopyToIconStorage( - const std::string& path_to_file) const { + const std::string& policy_app_id, const std::string& path_to_file) const { + LOG4CXX_AUTO_TRACE(logger_); if (!(application_manager_.protocol_handler() .get_settings() .max_supported_protocol_version() >= @@ -146,6 +151,11 @@ void SetAppIconRequest::CopyToIconStorage( application_manager_.get_settings().app_icons_folder_max_size()); const uint64_t file_size = file_system::FileSize(path_to_file); + if (0 == file_size) { + LOG4CXX_ERROR(logger_, "Can't get the icon file size: " << path_to_file); + return; + } + if (storage_max_size < file_size) { LOG4CXX_ERROR(logger_, "Icon size (" << file_size @@ -159,6 +169,7 @@ void SetAppIconRequest::CopyToIconStorage( const uint64_t storage_size = static_cast<uint64_t>(file_system::DirectorySize(icon_storage)); + if (storage_max_size < (file_size + storage_size)) { const uint32_t icons_amount = application_manager_.get_settings().app_icons_amount_to_remove(); @@ -174,23 +185,15 @@ void SetAppIconRequest::CopyToIconStorage( RemoveOldestIcons(icon_storage, icons_amount); } } - ApplicationConstSharedPtr app = - application_manager_.application(connection_key()); - if (!app) { - LOG4CXX_ERROR( - logger_, - "Can't get application for connection key: " << connection_key()); - return; - } + const std::string icon_path = icon_storage + "/" + policy_app_id; - const std::string icon_path = icon_storage + "/" + app->policy_app_id(); if (!file_system::CreateFile(icon_path)) { LOG4CXX_ERROR(logger_, "Can't create icon: " << icon_path); return; } - if (!file_system::Write(icon_path, file_content)) { + if (!file_system::WriteBinaryFile(icon_path, file_content)) { LOG4CXX_ERROR(logger_, "Can't write icon: " << icon_path); return; } @@ -266,21 +269,19 @@ void SetAppIconRequest::on_event(const event_engine::Event& event) { ApplicationSharedPtr app = application_manager_.application(connection_key()); - if ((message_.use_count() == 0) || (app.use_count() == 0)) { - LOG4CXX_ERROR(logger_, "NULL pointer."); + if (!app) { + LOG4CXX_ERROR( + logger_, + "Can't get application for connection key: " << connection_key()); return; } - const std::string& path = - (*message_)[strings::msg_params][strings::sync_file_name] - [strings::value] - .asString(); - - if (is_icons_saving_enabled_) { - CopyToIconStorage(path); + if (is_icons_saving_enabled_ && !full_file_path_for_hmi_.empty()) { + const auto policy_app_id = app->policy_app_id(); + CopyToIconStorage(policy_app_id, full_file_path_for_hmi_); } - app->set_app_icon_path(path); + app->set_app_icon_path(full_file_path_for_hmi_); LOG4CXX_INFO(logger_, "Icon path was set to '" << app->app_icon_path() << "'"); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloud_app_properties_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloud_app_properties_request.cc index 5173be56d6..680429d3b6 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloud_app_properties_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloud_app_properties_request.cc @@ -1,4 +1,6 @@ #include "sdl_rpc_plugin/commands/mobile/set_cloud_app_properties_request.h" +#include "application_manager/message_helper.h" +#include "application_manager/policies/policy_handler_interface.h" namespace sdl_rpc_plugin { using namespace application_manager; @@ -29,9 +31,29 @@ void SetCloudAppPropertiesRequest::Run() { return; } - policy_handler_.OnSetCloudAppProperties(*message_); + const auto& properties = + (*message_)[strings::msg_params][strings::properties]; + + const auto app_id(properties[strings::app_id].asString()); + + const auto properties_change_status = + policy_handler_.GetAppPropertiesStatus(properties, app_id); + + using AppPropertiesState = policy::PolicyHandlerInterface::AppPropertiesState; + const bool is_properties_changed = + AppPropertiesState::NO_CHANGES != properties_change_status; + const bool is_new_app = policy_handler_.IsNewApplication(app_id); + + policy_handler_.OnSetCloudAppProperties(*message_); SendResponse(true, mobile_apis::Result::SUCCESS); + + if (is_properties_changed || is_new_app) { + const auto notification = + MessageHelper::CreateOnAppPropertiesChangeNotification( + app_id, application_manager_); + application_manager_.GetRPCService().ManageHMICommand(notification); + } } void SetCloudAppPropertiesRequest::on_event( @@ -40,4 +62,4 @@ void SetCloudAppPropertiesRequest::on_event( } } // namespace commands -} // namespace sdl_rpc_plugin
\ No newline at end of file +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_display_layout_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_display_layout_request.cc index 2a09a72af2..0cd9f6635c 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_display_layout_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_display_layout_request.cc @@ -75,8 +75,8 @@ void SetDisplayLayoutRequest::Run() { new_layout = msg_params[strings::display_layout].asString(); } - if (new_layout != old_layout && - !new_layout.empty()) { // Template switched, allow any color change + if (new_layout != old_layout && !new_layout.empty()) { + // Template switched, hence allow any color change LOG4CXX_DEBUG(logger_, "SetDisplayLayoutRequest New Layout: " << new_layout); app->set_display_layout(new_layout); @@ -85,22 +85,20 @@ void SetDisplayLayoutRequest::Run() { // Template layout is the same as previous layout // Reject message if colors are set if (msg_params.keyExists(strings::day_color_scheme) && - app->day_color_scheme() != NULL && - !(msg_params[strings::day_color_scheme] == - *(app->day_color_scheme()))) { - // Color scheme param exists and has been previously set, do not allow - // color change + app->day_color_scheme().getType() != smart_objects::SmartType_Null && + msg_params[strings::day_color_scheme] != app->day_color_scheme()) { + // Color scheme param exists and has been previously set, + // hence do not allow color change LOG4CXX_DEBUG(logger_, "Reject Day Color Scheme Change"); SendResponse(false, mobile_apis::Result::REJECTED); return; } if (msg_params.keyExists(strings::night_color_scheme) && - app->night_color_scheme() != NULL && - !(msg_params[strings::night_color_scheme] == - *(app->night_color_scheme()))) { - // Color scheme param exists and has been previously set, do not allow - // color change + app->night_color_scheme().getType() != smart_objects::SmartType_Null && + msg_params[strings::night_color_scheme] != app->night_color_scheme()) { + // Color scheme param exists and has been previously set, + // hence do not allow color change LOG4CXX_DEBUG(logger_, "Reject Night Color Scheme Change"); SendResponse(false, mobile_apis::Result::REJECTED); return; @@ -127,6 +125,14 @@ void SetDisplayLayoutRequest::Run() { void SetDisplayLayoutRequest::on_event(const event_engine::Event& event) { LOG4CXX_AUTO_TRACE(logger_); + ApplicationSharedPtr app = application_manager_.application(connection_key()); + + if (!app) { + LOG4CXX_ERROR(logger_, "Application is not registered"); + SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED); + return; + } + const smart_objects::SmartObject& message = event.smart_object(); switch (event.id()) { case hmi_apis::FunctionID::UI_SetDisplayLayout: { @@ -143,21 +149,35 @@ void SetDisplayLayoutRequest::on_event(const event_engine::Event& event) { if (response_success) { HMICapabilities& hmi_capabilities = hmi_capabilities_; - // in case templates_available is empty copy from hmi capabilities + // In case templates_available is empty copy from hmi capabilities if (msg_params.keyExists(hmi_response::display_capabilities)) { if (0 == msg_params[hmi_response::display_capabilities] [hmi_response::templates_available] .length()) { - msg_params[hmi_response::display_capabilities] - [hmi_response::templates_available] = - hmi_capabilities.display_capabilities()->getElement( - hmi_response::templates_available); + auto display_capabilities = hmi_capabilities.display_capabilities(); + if (display_capabilities) { + msg_params[hmi_response::display_capabilities] + [hmi_response::templates_available] = + display_capabilities->getElement( + hmi_response::templates_available); + } } } + const Version& app_version = app->version(); + if (app_version.max_supported_api_version >= APIVersion::kAPIV6) { + // In case of successful response warn user that this RPC is + // deprecated from 6.0 and higher API versions + result_code = hmi_apis::Common_Result::WARNINGS; + info = + "The RPC is deprecated and will be removed in a future version. " + "The requested display layout is set to the main window. Please " + "use `Show.templateConfiguration` instead."; + } } + SendResponse(response_success, MessageHelper::HMIToMobileResult(result_code), - info.empty() ? NULL : info.c_str(), + info.empty() ? nullptr : info.c_str(), &msg_params); break; } 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 3b13b00968..a567d1b32f 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 @@ -38,6 +38,7 @@ #include "application_manager/message_helper.h" #include "interfaces/HMI_API.h" #include "interfaces/MOBILE_API.h" + #include "utils/helpers.h" namespace sdl_rpc_plugin { @@ -45,6 +46,24 @@ using namespace application_manager; namespace commands { +namespace { +bool IsResultCodeWarning(const app_mngr::commands::ResponseInfo& first, + const app_mngr::commands::ResponseInfo& second, + const app_mngr::commands::ResponseInfo& third) { + const bool first_is_ok_second_is_warn = + (first.is_ok || first.is_not_used) && + (hmi_apis::Common_Result::WARNINGS == second.result_code) && + (hmi_apis::Common_Result::WARNINGS == third.result_code); + + const bool final_warnings = + hmi_apis::Common_Result::WARNINGS == first.result_code && + ((hmi_apis::Common_Result::WARNINGS == second.result_code) && + (hmi_apis::Common_Result::WARNINGS == third.result_code)); + + return first_is_ok_second_is_warn || final_warnings; +} +} // namespace + SetGlobalPropertiesRequest::SetGlobalPropertiesRequest( const application_manager::commands::MessageSharedPtr& message, ApplicationManager& application_manager, @@ -58,10 +77,13 @@ SetGlobalPropertiesRequest::SetGlobalPropertiesRequest( policy_handler) , is_ui_send_(false) , is_tts_send_(false) + , is_rc_send_(false) , is_ui_received_(false) , is_tts_received_(false) + , is_rc_received_(false) , 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) {} SetGlobalPropertiesRequest::~SetGlobalPropertiesRequest() {} @@ -146,6 +168,19 @@ void SetGlobalPropertiesRequest::Run() { return; } + smart_objects::SmartObject params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + if (msg_params.keyExists(strings::menu_layout)) { + auto menu_layout = static_cast<mobile_apis::MenuLayout::eType>( + msg_params[strings::menu_layout].asUInt()); + if (app->menu_layout_supported(menu_layout)) { + params[strings::menu_layout] = msg_params[strings::menu_layout]; + } else { + is_menu_layout_available_ = false; + } + } + /* Need to set flags before sending request to HMI * for correct processing this flags in method on_event */ if (is_help_prompt_present || is_timeout_prompt_present) { @@ -162,9 +197,6 @@ void SetGlobalPropertiesRequest::Run() { return; } - smart_objects::SmartObject params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - PrepareUIRequestVRHelpData(app, msg_params, params); PrepareUIRequestMenuAndKeyboardData(app, msg_params, params); @@ -177,9 +209,6 @@ void SetGlobalPropertiesRequest::Run() { LOG4CXX_DEBUG(logger_, "VRHelp params does not present"); DCHECK_OR_RETURN_VOID(!is_vr_help_title_present && !is_vr_help_present); - smart_objects::SmartObject params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - PrepareUIRequestMenuAndKeyboardData(app, msg_params, params); // Preparing data @@ -191,17 +220,44 @@ void SetGlobalPropertiesRequest::Run() { } } + // Check RC params + const bool is_user_location_present = + msg_params.keyExists(strings::user_location); + if (is_user_location_present) { + if (msg_params[strings::user_location].empty()) { + SendResponse( + false, mobile_apis::Result::INVALID_DATA, "UserLocation is empty"); + return; + } + LOG4CXX_DEBUG(logger_, "Userlocation params presents"); + const auto& user_location = msg_params[strings::user_location]; + app->set_user_location(user_location); + + auto on_global_properties_updated = [app]( + plugin_manager::RPCPlugin& plugin) { + plugin.OnApplicationEvent(plugin_manager::kGlobalPropertiesUpdated, app); + }; + + application_manager_.GetPluginManager().ForEachPlugin( + on_global_properties_updated); + + smart_objects::SmartObject params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + params[strings::app_id] = app->app_id(); + params[strings::user_location] = user_location; + SendRCRequest(params, true); + } + // check TTS params if (is_help_prompt_present || is_timeout_prompt_present) { LOG4CXX_DEBUG(logger_, "TTS params presents"); - smart_objects::SmartObject params = - smart_objects::SmartObject(smart_objects::SmartType_Map); + auto tts_params = smart_objects::SmartObject(smart_objects::SmartType_Map); std::vector<std::string> invalid_params; if (is_help_prompt_present) { smart_objects::SmartObject& help_prompt = (*message_)[strings::msg_params][strings::help_prompt]; - mobile_apis::Result::eType verification_result = + verification_result = MessageHelper::VerifyTtsFiles(help_prompt, app, application_manager_); if (mobile_apis::Result::FILE_NOT_FOUND == verification_result) { @@ -211,16 +267,15 @@ void SetGlobalPropertiesRequest::Run() { invalid_params.push_back("help_prompt"); } else { app->set_help_prompt(help_prompt); - params[strings::help_prompt] = (*app->help_prompt()); + tts_params[strings::help_prompt] = (*app->help_prompt()); } } if (is_timeout_prompt_present) { smart_objects::SmartObject& timeout_prompt = (*message_)[strings::msg_params][strings::timeout_prompt]; - mobile_apis::Result::eType verification_result = - MessageHelper::VerifyTtsFiles( - timeout_prompt, app, application_manager_); + verification_result = MessageHelper::VerifyTtsFiles( + timeout_prompt, app, application_manager_); if (mobile_apis::Result::FILE_NOT_FOUND == verification_result) { LOG4CXX_ERROR( @@ -229,7 +284,7 @@ void SetGlobalPropertiesRequest::Run() { invalid_params.push_back("timeout_prompt"); } else { app->set_timeout_prompt(timeout_prompt); - params[strings::timeout_prompt] = (*app->timeout_prompt()); + tts_params[strings::timeout_prompt] = (*app->timeout_prompt()); } } @@ -247,11 +302,18 @@ void SetGlobalPropertiesRequest::Run() { return; } - params[strings::app_id] = app->app_id(); - SendTTSRequest(params, true); + tts_params[strings::app_id] = app->app_id(); + SendTTSRequest(tts_params, true); auto& help_prompt_manager = app->help_prompt_manager(); - help_prompt_manager.OnSetGlobalPropertiesReceived(params, false); + help_prompt_manager.OnSetGlobalPropertiesReceived(tts_params, false); + } else if (!is_ui_send_ && !is_rc_send_) { + std::string response_info = "There are no parameters present in request."; + if (!is_menu_layout_available_) { + response_info += " The MenuLayout specified is unsupported."; + } + SendResponse( + false, mobile_apis::Result::INVALID_DATA, response_info.c_str()); } } @@ -286,7 +348,7 @@ void SetGlobalPropertiesRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::UI_SetGlobalProperties: { - LOG4CXX_INFO(logger_, "Received UI_SetGlobalProperties event"); + LOG4CXX_DEBUG(logger_, "Received UI_SetGlobalProperties event"); EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); is_ui_received_ = true; ui_result_ = static_cast<hmi_apis::Common_Result::eType>( @@ -299,7 +361,7 @@ void SetGlobalPropertiesRequest::on_event(const event_engine::Event& event) { break; } case hmi_apis::FunctionID::TTS_SetGlobalProperties: { - LOG4CXX_INFO(logger_, "Received TTS_SetGlobalProperties event"); + LOG4CXX_DEBUG(logger_, "Received TTS_SetGlobalProperties event"); EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_TTS); is_tts_received_ = true; tts_result_ = static_cast<hmi_apis::Common_Result::eType>( @@ -311,6 +373,15 @@ void SetGlobalPropertiesRequest::on_event(const event_engine::Event& event) { } break; } + case hmi_apis::FunctionID::RC_SetGlobalProperties: { + LOG4CXX_DEBUG(logger_, "Received RC_SetGlobalProperties event"); + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_RC); + is_rc_received_ = true; + rc_result_ = static_cast<hmi_apis::Common_Result::eType>( + message[strings::params][hmi_response::code].asInt()); + GetInfo(message, rc_response_info_); + break; + } default: { LOG4CXX_ERROR(logger_, "Received unknown event" << event.id()); return; @@ -325,10 +396,21 @@ void SetGlobalPropertiesRequest::on_event(const event_engine::Event& event) { std::string response_info; const bool result = PrepareResponseParameters(result_code, response_info); - SendResponse(result, - result_code, - response_info.empty() ? NULL : response_info.c_str(), - &(message[strings::msg_params])); + if (result && !is_menu_layout_available_) { + response_info = + "The MenuLayout specified is unsupported, the " + "default MenuLayout will be used." + + response_info; + SendResponse(result, + mobile_apis::Result::WARNINGS, + response_info.c_str(), + &(message[strings::msg_params])); + } else { + SendResponse(result, + result_code, + response_info.empty() ? NULL : response_info.c_str(), + &(message[strings::msg_params])); + } } bool SetGlobalPropertiesRequest::Init() { @@ -346,28 +428,173 @@ bool SetGlobalPropertiesRequest::PrepareResponseParameters( app_mngr::commands::ResponseInfo tts_properties_info( tts_result_, HmiInterfaces::HMI_INTERFACE_TTS, application_manager_); - const bool result = - PrepareResultForMobileResponse(ui_properties_info, tts_properties_info); + + app_mngr::commands::ResponseInfo rc_properties_info( + rc_result_, HmiInterfaces::HMI_INTERFACE_RC, application_manager_); + + bool result = false; + + if (!is_rc_send_) { + result = CommandRequestImpl::PrepareResultForMobileResponse( + ui_properties_info, tts_properties_info); + } else { + result = PrepareResultForMobileResponse( + ui_properties_info, tts_properties_info, rc_properties_info); + } if (result && (HmiInterfaces::STATE_AVAILABLE == tts_properties_info.interface_state) && (tts_properties_info.is_unsupported_resource)) { result_code = mobile_apis::Result::WARNINGS; tts_response_info_ = "Unsupported phoneme type sent in a prompt"; - info = app_mngr::commands::MergeInfos(tts_properties_info, - tts_response_info_, - ui_properties_info, - ui_response_info_); + info = MergeInfos(tts_properties_info, + tts_response_info_, + ui_properties_info, + ui_response_info_, + rc_properties_info, + rc_response_info_); return result; } - result_code = - PrepareResultCodeForResponse(ui_properties_info, tts_properties_info); - info = app_mngr::commands::MergeInfos(tts_properties_info, - tts_response_info_, - ui_properties_info, - ui_response_info_); + + if (!is_rc_send_) { + result_code = CommandRequestImpl::PrepareResultCodeForResponse( + ui_properties_info, tts_properties_info); + } else { + result_code = PrepareResultCodeForResponse( + ui_properties_info, tts_properties_info, rc_properties_info); + } + info = MergeInfos(tts_properties_info, + tts_response_info_, + ui_properties_info, + ui_response_info_, + rc_properties_info, + rc_response_info_); return result; } +bool SetGlobalPropertiesRequest::PrepareResultForMobileResponse( + const app_mngr::commands::ResponseInfo& first, + const app_mngr::commands::ResponseInfo& second, + const app_mngr::commands::ResponseInfo& third) const { + LOG4CXX_AUTO_TRACE(logger_); + + app_mngr::commands::ResponseInfo both_info; + std::vector<hmi_apis::Common_Result::eType> success_result_codes{ + 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}; + + both_info.is_ok = + helpers::in_range(success_result_codes, first.result_code) && + helpers::in_range(success_result_codes, second.result_code); + + both_info.is_not_used = + (hmi_apis::Common_Result::INVALID_ENUM == first.result_code) || + (hmi_apis::Common_Result::INVALID_ENUM == second.result_code); + + both_info.is_unsupported_resource = + (hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == first.result_code) || + (hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == second.result_code); + + const bool final_result = CommandRequestImpl::CheckResult(both_info, third) || + CommandRequestImpl::CheckResult(third, both_info); + + return final_result; +} + +mobile_apis::Result::eType +SetGlobalPropertiesRequest::PrepareResultCodeForResponse( + const app_mngr::commands::ResponseInfo& first, + const app_mngr::commands::ResponseInfo& second, + const app_mngr::commands::ResponseInfo& third) { + LOG4CXX_AUTO_TRACE(logger_); + mobile_apis::Result::eType result_code = mobile_apis::Result::INVALID_ENUM; + if (IsResultCodeUnsupported(first, second, third) || + IsResultCodeUnsupported(second, third, first) || + IsResultCodeUnsupported(third, first, second)) { + return mobile_apis::Result::UNSUPPORTED_RESOURCE; + } + if (IsResultCodeWarning(first, second, third) || + IsResultCodeWarning(second, third, first) || + IsResultCodeWarning(third, first, second)) { + return mobile_apis::Result::WARNINGS; + } + // If response contains erroneous result code SDL need return erroneous + // result code. + auto first_result = hmi_apis::Common_Result::INVALID_ENUM; + auto second_result = hmi_apis::Common_Result::INVALID_ENUM; + auto third_result = hmi_apis::Common_Result::INVALID_ENUM; + + if (!first.is_unsupported_resource) { + first_result = first.result_code; + } + if (!second.is_unsupported_resource) { + second_result = second.result_code; + } + if (!third.is_unsupported_resource) { + third_result = third.result_code; + } + + hmi_apis::Common_Result::eType intermediate_result = + std::max(first_result, second_result); + result_code = MessageHelper::HMIToMobileResult( + std::max(intermediate_result, third_result)); + + return result_code; +} + +bool SetGlobalPropertiesRequest::IsResultCodeUnsupported( + const application_manager::commands::ResponseInfo& first, + const application_manager::commands::ResponseInfo& second, + const application_manager::commands::ResponseInfo& third) const { + const bool first_ok_second_or_third_unsupported = + (first.is_ok || first.is_not_used) && + (second.is_unsupported_resource || third.is_unsupported_resource); + const bool final_unsupported = first.is_unsupported_resource && + second.is_unsupported_resource && + third.is_unsupported_resource; + + return first_ok_second_or_third_unsupported || final_unsupported; +} + +std::string SetGlobalPropertiesRequest::MergeInfos( + const app_mngr::commands::ResponseInfo& first_info, + const std::string& first_str, + const app_mngr::commands::ResponseInfo& second_info, + const std::string& second_str, + const app_mngr::commands::ResponseInfo& third_info, + const std::string& third_str) { + if ((first_info.interface_state == HmiInterfaces::STATE_NOT_AVAILABLE) && + + ((second_info.interface_state != HmiInterfaces::STATE_NOT_AVAILABLE) && + !second_str.empty()) && + ((third_info.interface_state != HmiInterfaces::STATE_NOT_AVAILABLE) && + !third_str.empty())) { + return second_str; + } + + if ((second_info.interface_state == HmiInterfaces::STATE_NOT_AVAILABLE) && + ((first_info.interface_state != HmiInterfaces::STATE_NOT_AVAILABLE) && + !first_str.empty()) && + ((third_info.interface_state != HmiInterfaces::STATE_NOT_AVAILABLE) && + !third_str.empty())) { + return first_str; + } + + if ((third_info.interface_state == HmiInterfaces::STATE_NOT_AVAILABLE) && + ((first_info.interface_state != HmiInterfaces::STATE_NOT_AVAILABLE) && + !first_str.empty()) && + ((second_info.interface_state != HmiInterfaces::STATE_NOT_AVAILABLE) && + !second_str.empty())) { + return third_str; + } + + std::string intermediate_result = + app_mngr::commands::MergeInfos(first_str, second_str); + return app_mngr::commands::MergeInfos(intermediate_result, third_str); +} + void SetGlobalPropertiesRequest::PrepareUIRequestVRHelpData( const ApplicationSharedPtr app, const smart_objects::SmartObject& msg_params, @@ -430,8 +657,19 @@ void SetGlobalPropertiesRequest::SendUIRequest( hmi_apis::FunctionID::UI_SetGlobalProperties, ¶ms, use_events); } +void SetGlobalPropertiesRequest::SendRCRequest( + const ns_smart_device_link::ns_smart_objects::SmartObject& params, + bool use_events) { + LOG4CXX_AUTO_TRACE(logger_); + is_rc_send_ = true; + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_RC); + SendHMIRequest( + hmi_apis::FunctionID::RC_SetGlobalProperties, ¶ms, use_events); +} + bool SetGlobalPropertiesRequest::IsPendingResponseExist() { - return is_ui_send_ != is_ui_received_ || is_tts_send_ != is_tts_received_; + return is_ui_send_ != is_ui_received_ || is_tts_send_ != is_tts_received_ || + is_rc_send_ != is_rc_received_; } bool SetGlobalPropertiesRequest::ValidateConditionalMandatoryParameters( @@ -443,7 +681,9 @@ bool SetGlobalPropertiesRequest::ValidateConditionalMandatoryParameters( params.keyExists(strings::vr_help) || params.keyExists(strings::menu_title) || params.keyExists(strings::menu_icon) || - params.keyExists(strings::keyboard_properties); + params.keyExists(strings::keyboard_properties) || + params.keyExists(strings::menu_layout) || + params.keyExists(strings::user_location); } bool SetGlobalPropertiesRequest::IsWhiteSpaceExist() { diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/show_app_menu_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/show_app_menu_request.cc index 2a8dc6cb70..36278168dc 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/show_app_menu_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/show_app_menu_request.cc @@ -68,11 +68,12 @@ void ShowAppMenuRequest::Run() { return; } - if (mobile_apis::HMILevel::HMI_FULL != app->hmi_level() || + if (mobile_apis::HMILevel::HMI_FULL != + app->hmi_level(mobile_apis::PredefinedWindows::DEFAULT_WINDOW) || helpers::Compare<mobile_apis::SystemContext::eType, helpers::NEQ, helpers::ALL>( - app->system_context(), + app->system_context(mobile_apis::PredefinedWindows::DEFAULT_WINDOW), mobile_apis::SystemContext::SYSCTXT_MAIN, mobile_apis::SystemContext::SYSCTXT_MENU)) { LOG4CXX_ERROR( 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 bf26cc62af..84d11f8e09 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 @@ -55,7 +55,12 @@ ShowRequest::ShowRequest( rpc_service, hmi_capabilities, policy_handler) - , core_result_code_(mobile_apis::Result::INVALID_ENUM) {} + , core_result_code_(mobile_apis::Result::INVALID_ENUM) + , current_window_id_(mobile_apis::PredefinedWindows::DEFAULT_WINDOW) + , template_config_(smart_objects::SmartType::SmartType_Null) + , layout_change_required_(false) + , dcs_change_required_(false) + , ncs_change_required_(false) {} ShowRequest::~ShowRequest() {} @@ -94,6 +99,137 @@ void ShowRequest::HandleMetadata(const char* field_id, } } +bool ShowRequest::CheckTemplateConfigurationForApp( + application_manager::Application& app) { + LOG4CXX_AUTO_TRACE(logger_); + + if ((*message_)[strings::msg_params].keyExists(strings::window_id)) { + current_window_id_ = + (*message_)[strings::msg_params][strings::window_id].asInt(); + } + + const auto set_window_layout = [&app, this]() -> bool { + const auto new_template_layout = + template_config_[strings::template_layout].asString(); + const auto old_template_layout = app.window_layout(current_window_id_); + LOG4CXX_DEBUG(logger_, "New layout: " << new_template_layout); + LOG4CXX_DEBUG(logger_, "Old layout: " << old_template_layout); + + const bool layouts_equal = (new_template_layout == old_template_layout); + + if (!new_template_layout.empty() && !layouts_equal) { + // Template switched, hence allow any color change + LOG4CXX_DEBUG(logger_, + "Show Request: Setting new Layout: " << new_template_layout + << " for window ID: " + << current_window_id_); + layout_change_required_ = true; + return true; + } + LOG4CXX_DEBUG(logger_, "Show Request: No Layout Change"); + return false; + }; + + const auto set_day_color_scheme = [&app, this]() -> bool { + if (!template_config_.keyExists(strings::day_color_scheme)) { + return false; + } + if (app.day_color_scheme(current_window_id_).getType() != + smart_objects::SmartType_Null && + template_config_[strings::day_color_scheme] != + app.day_color_scheme(current_window_id_)) { + // Color scheme param exists and has been previously set, + // hence do not allow color change + LOG4CXX_DEBUG(logger_, "Day Color Scheme change is rejected"); + return false; + } + LOG4CXX_DEBUG(logger_, "Day Color Scheme change is allowed"); + dcs_change_required_ = true; + + return true; + }; + + const auto set_night_color_scheme = [&app, this]() -> bool { + if (!template_config_.keyExists(strings::night_color_scheme)) { + return false; + } + if (app.night_color_scheme(current_window_id_).getType() != + smart_objects::SmartType_Null && + template_config_[strings::night_color_scheme] != + app.night_color_scheme(current_window_id_)) { + // Color scheme param exists and has been previously set, + // hence do not allow color change + LOG4CXX_DEBUG(logger_, "Night Color Scheme change is rejected"); + return false; + } + LOG4CXX_DEBUG(logger_, "Night Color Scheme Change is allowed"); + ncs_change_required_ = true; + + return true; + }; + + const bool set_layout_result = set_window_layout(); + + if (set_layout_result) { + set_day_color_scheme(); + set_night_color_scheme(); + return true; + } + + if (!template_config_.keyExists(strings::night_color_scheme) && + !template_config_.keyExists(strings::day_color_scheme)) { + // In case current layout was not changed and day and night color + // schemes are absent in mobile message SDL has to forward message + // to HMI with the only layout even it was not changed + return true; + } + + const bool set_schemes_result = + (set_day_color_scheme() && set_night_color_scheme()); + + return set_schemes_result; +} + +void ShowRequest::ApplyTemplateConfigurationForApp( + mobile_apis::Result::eType result, application_manager::Application& app) { + LOG4CXX_AUTO_TRACE(logger_); + if (helpers::Compare<mobile_apis::Result::eType, helpers::EQ, helpers::ONE>( + result, + mobile_apis::Result::SUCCESS, + mobile_apis::Result::WARNINGS)) { + if (layout_change_required_) { + const std::string new_layout = + template_config_[strings::template_layout].asString(); + LOG4CXX_DEBUG(logger_, "New layout : " << new_layout << " is applied"); + app.set_window_layout(current_window_id_, new_layout); + + if (template_config_.keyExists(strings::day_color_scheme)) { + app.set_day_color_scheme(current_window_id_, + template_config_[strings::day_color_scheme]); + } + + if (template_config_.keyExists(strings::night_color_scheme)) { + app.set_night_color_scheme( + current_window_id_, template_config_[strings::night_color_scheme]); + } + + return; + } + + if (dcs_change_required_) { + LOG4CXX_DEBUG(logger_, "New day color scheme is applied"); + app.set_day_color_scheme(current_window_id_, + template_config_[strings::day_color_scheme]); + } + + if (ncs_change_required_) { + LOG4CXX_DEBUG(logger_, "New night color scheme is applied"); + app.set_night_color_scheme(current_window_id_, + template_config_[strings::night_color_scheme]); + } + } +} + void ShowRequest::Run() { LOG4CXX_AUTO_TRACE(logger_); @@ -272,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()); } } @@ -281,6 +417,33 @@ void ShowRequest::Run() { (*message_)[strings::msg_params][strings::custom_presets]; } + if ((*message_)[strings::msg_params].keyExists(strings::window_id)) { + const auto window_id = + (*message_)[strings::msg_params][strings::window_id].asInt(); + if (!app->WindowIdExists(window_id)) { + LOG4CXX_ERROR(logger_, + "Window with id #" << window_id << " does not exist"); + SendResponse(false, mobile_apis::Result::INVALID_ID); + return; + } + msg_params[strings::window_id] = window_id; + } + + if ((*message_)[strings::msg_params].keyExists( + strings::template_configuration)) { + template_config_ = + (*message_)[strings::msg_params][strings::template_configuration]; + const bool result = CheckTemplateConfigurationForApp(*app); + if (!result) { + const char* info( + "Color schemes can not be changed without a new template set"); + SendResponse(false, mobile_apis::Result::REJECTED, info); + return; + } + msg_params[strings::template_configuration] = + (*message_)[strings::msg_params][strings::template_configuration]; + } + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); SendHMIRequest(hmi_apis::FunctionID::UI_Show, &msg_params, true); @@ -294,6 +457,13 @@ void ShowRequest::on_event(const event_engine::Event& event) { using namespace helpers; const smart_objects::SmartObject& message = event.smart_object(); + ApplicationSharedPtr app = application_manager_.application(connection_key()); + + if (!app) { + LOG4CXX_ERROR(logger_, "Application is not registered"); + SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED); + return; + } switch (event.id()) { case hmi_apis::FunctionID::UI_Show: { @@ -313,6 +483,9 @@ void ShowRequest::on_event(const event_engine::Event& event) { } mobile_apis::Result::eType converted_result_code = MessageHelper::HMIToMobileResult(result_code); + + ApplyTemplateConfigurationForApp(converted_result_code, *app); + if (mobile_apis::Result::SUCCESS == converted_result_code && mobile_apis::Result::INVALID_ENUM != core_result_code_) { converted_result_code = core_result_code_; 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 d80e73ccbf..dd7b426b40 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 @@ -116,6 +116,11 @@ void SliderRequest::Run() { msg_params[strings::timeout] = default_timeout_; } + if ((*message_)[strings::msg_params].keyExists(strings::cancel_id)) { + msg_params[strings::cancel_id] = + (*message_)[strings::msg_params][strings::cancel_id].asInt(); + } + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); SendHMIRequest(hmi_apis::FunctionID::UI_Slider, &msg_params, true); } 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 1acb2a7438..3797913f5b 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 @@ -107,8 +107,8 @@ void SubscribeButtonRequest::Run() { app->SubscribeToButton(static_cast<mobile_apis::ButtonName::eType>(btn_id)); SendSubscribeButtonNotification(); - const bool is_succedeed = true; - SendResponse(is_succedeed, mobile_apis::Result::SUCCESS); + const bool is_succeeded = true; + SendResponse(is_succeeded, mobile_apis::Result::SUCCESS); } bool SubscribeButtonRequest::Init() { diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/system_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/system_request.cc index e70433f29b..033e70a29c 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/system_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/system_request.cc @@ -46,6 +46,7 @@ Copyright (c) 2018, Ford Motor Company #include "utils/custom_string.h" #include "utils/file_system.h" #include "utils/helpers.h" +#include "utils/jsoncpp_reader_wrapper.h" namespace sdl_rpc_plugin { using namespace application_manager; @@ -470,8 +471,8 @@ void SystemRequest::Run() { static_cast<rpc::policy_table_interface_base::RequestType>( request_type)); - if (!policy_handler.IsRequestTypeAllowed(application->policy_app_id(), - request_type)) { + if (!policy_handler.IsRequestTypeAllowed( + application->device(), application->policy_app_id(), request_type)) { LOG4CXX_ERROR(logger_, "RequestType " << stringified_request_type << " is DISALLOWED by policies"); @@ -612,17 +613,21 @@ void SystemRequest::Run() { return; } else if (mobile_apis::RequestType::QUERY_APPS == request_type) { using namespace ns_smart_device_link::ns_json_handler::formatters; + application_manager_.OnQueryAppsRequest(application->device()); - smart_objects::SmartObject sm_object; - Json::Reader reader; + utils::JsonReader reader; std::string json(binary_data.begin(), binary_data.end()); Json::Value root; - if (!reader.parse(json.c_str(), root)) { - LOG4CXX_DEBUG(logger_, "Unable to parse query_app json file."); + + if (!reader.parse(json, &root)) { + LOG4CXX_DEBUG(logger_, "Unable to parse query_app json file. "); return; } + smart_objects::SmartObject sm_object; + CFormatterJsonBase::jsonValueToObj(root, sm_object); + if (!ValidateQueryAppData(sm_object)) { SendResponse(false, mobile_apis::Result::GENERIC_ERROR); return; 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 ebd463d4fa..ec8de68c9e 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 @@ -94,7 +94,7 @@ void UnsubscribeButtonRequest::Run() { if (!app->UnsubscribeFromButton( static_cast<mobile_apis::ButtonName::eType>(btn_id))) { - LOG4CXX_ERROR(logger_, "App doesn't subscibe to button " << btn_id); + LOG4CXX_ERROR(logger_, "App doesn't subscribe to button " << btn_id); SendResponse(false, mobile_apis::Result::IGNORED); return; } 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 fa41e51980..b89a8dbd68 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 @@ -71,6 +71,8 @@ #include "sdl_rpc_plugin/commands/hmi/sdl_activate_app_response.h" #include "sdl_rpc_plugin/commands/hmi/sdl_get_list_of_permissions_request.h" #include "sdl_rpc_plugin/commands/hmi/sdl_get_list_of_permissions_response.h" +#include "sdl_rpc_plugin/commands/hmi/sdl_get_policy_configuration_data_request.h" +#include "sdl_rpc_plugin/commands/hmi/sdl_get_policy_configuration_data_response.h" #include "sdl_rpc_plugin/commands/hmi/sdl_get_status_update_request.h" #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" @@ -99,10 +101,14 @@ #include "sdl_rpc_plugin/commands/hmi/ui_alert_response.h" #include "sdl_rpc_plugin/commands/hmi/ui_change_registration_request.h" #include "sdl_rpc_plugin/commands/hmi/ui_change_registration_response.h" +#include "sdl_rpc_plugin/commands/hmi/ui_create_window_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_create_window_response.h" #include "sdl_rpc_plugin/commands/hmi/ui_delete_command_request.h" #include "sdl_rpc_plugin/commands/hmi/ui_delete_command_response.h" #include "sdl_rpc_plugin/commands/hmi/ui_delete_submenu_request.h" #include "sdl_rpc_plugin/commands/hmi/ui_delete_submenu_response.h" +#include "sdl_rpc_plugin/commands/hmi/ui_delete_window_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_delete_window_response.h" #include "sdl_rpc_plugin/commands/hmi/ui_end_audio_pass_thru_request.h" #include "sdl_rpc_plugin/commands/hmi/ui_end_audio_pass_thru_response.h" #include "sdl_rpc_plugin/commands/hmi/ui_get_capabilities_request.h" @@ -167,8 +173,6 @@ #include "sdl_rpc_plugin/commands/hmi/basic_communication_system_response.h" #include "sdl_rpc_plugin/commands/hmi/dial_number_request.h" #include "sdl_rpc_plugin/commands/hmi/dial_number_response.h" -#include "sdl_rpc_plugin/commands/hmi/get_urls.h" -#include "sdl_rpc_plugin/commands/hmi/get_urls_response.h" #include "sdl_rpc_plugin/commands/hmi/navi_alert_maneuver_request.h" #include "sdl_rpc_plugin/commands/hmi/navi_alert_maneuver_response.h" #include "sdl_rpc_plugin/commands/hmi/navi_audio_start_stream_request.h" @@ -232,6 +236,8 @@ #include "sdl_rpc_plugin/commands/hmi/on_vr_stopped_notification.h" #include "sdl_rpc_plugin/commands/hmi/sdl_policy_update.h" #include "sdl_rpc_plugin/commands/hmi/sdl_policy_update_response.h" +#include "sdl_rpc_plugin/commands/hmi/ui_cancel_interaction_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_cancel_interaction_response.h" #include "sdl_rpc_plugin/commands/hmi/ui_send_haptic_data_request.h" #include "sdl_rpc_plugin/commands/hmi/ui_send_haptic_data_response.h" #include "sdl_rpc_plugin/commands/hmi/ui_set_display_layout_request.h" @@ -241,12 +247,20 @@ #include "sdl_rpc_plugin/commands/hmi/bc_get_file_path_request.h" #include "sdl_rpc_plugin/commands/hmi/bc_get_file_path_response.h" +#include "sdl_rpc_plugin/commands/hmi/on_service_update_notification.h" #include "sdl_rpc_plugin/commands/hmi/rc_get_capabilities_request.h" #include "sdl_rpc_plugin/commands/hmi/rc_get_capabilities_response.h" #include "sdl_rpc_plugin/commands/hmi/rc_is_ready_request.h" #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" + +#include "sdl_rpc_plugin/commands/hmi/bc_get_app_properties_request.h" +#include "sdl_rpc_plugin/commands/hmi/bc_get_app_properties_response.h" +#include "sdl_rpc_plugin/commands/hmi/bc_set_app_properties_request.h" +#include "sdl_rpc_plugin/commands/hmi/bc_set_app_properties_response.h" +#include "sdl_rpc_plugin/commands/hmi/on_app_properties_change_notification.h" namespace sdl_rpc_plugin { using namespace application_manager; @@ -350,11 +364,6 @@ CommandCreator& HMICommandFactory::get_creator_factory( ? factory.GetCreator<commands::SDLPolicyUpdate>() : factory.GetCreator<commands::SDLPolicyUpdateResponse>(); } - case hmi_apis::FunctionID::SDL_GetURLS: { - return hmi_apis::messageType::request == message_type - ? factory.GetCreator<commands::GetUrls>() - : factory.GetCreator<commands::GetUrlsResponse>(); - } case hmi_apis::FunctionID::SDL_OnAppPermissionChanged: { return factory.GetCreator<commands::OnAppPermissionChangedNotification>(); } @@ -377,6 +386,13 @@ CommandCreator& HMICommandFactory::get_creator_factory( ? factory.GetCreator<commands::SDLGetStatusUpdateRequest>() : factory.GetCreator<commands::SDLGetStatusUpdateResponse>(); } + case hmi_apis::FunctionID::SDL_GetPolicyConfigurationData: { + return hmi_apis::messageType::request == message_type + ? factory.GetCreator< + commands::SDLGetPolicyConfigurationDataRequest>() + : factory.GetCreator< + commands::SDLGetPolicyConfigurationDataResponse>(); + } case hmi_apis::FunctionID::SDL_OnStatusUpdate: { return factory.GetCreator<commands::OnStatusUpdateNotification>(); } @@ -396,6 +412,11 @@ CommandCreator& HMICommandFactory::get_creator_factory( ? factory.GetCreator<commands::UIAddCommandRequest>() : factory.GetCreator<commands::UIAddCommandResponse>(); } + case hmi_apis::FunctionID::UI_CancelInteraction: { + return hmi_apis::messageType::request == message_type + ? factory.GetCreator<commands::UICancelInteractionRequest>() + : factory.GetCreator<commands::UICancelInteractionResponse>(); + } case hmi_apis::FunctionID::UI_DeleteCommand: { return hmi_apis::messageType::request == message_type ? factory.GetCreator<commands::UIDeleteCommandRequest>() @@ -416,6 +437,11 @@ CommandCreator& HMICommandFactory::get_creator_factory( ? factory.GetCreator<commands::UIShowAppMenuRequest>() : factory.GetCreator<commands::UIShowAppMenuResponse>(); } + case hmi_apis::FunctionID::UI_DeleteWindow: { + return hmi_apis::messageType::request == message_type + ? factory.GetCreator<commands::UIDeleteWindowRequest>() + : factory.GetCreator<commands::UIDeleteWindowResponse>(); + } case hmi_apis::FunctionID::UI_SetMediaClockTimer: { return hmi_apis::messageType::request == message_type ? factory.GetCreator<commands::UISetMediaClockTimerRequest>() @@ -464,6 +490,11 @@ CommandCreator& HMICommandFactory::get_creator_factory( ? factory.GetCreator<commands::UIChangeRegistrationRequest>() : factory.GetCreator<commands::UIChangeRegistratioResponse>(); } + case hmi_apis::FunctionID::UI_CreateWindow: { + return hmi_apis::messageType::request == message_type + ? factory.GetCreator<commands::UICreateWindowRequest>() + : factory.GetCreator<commands::UICreateWindowResponse>(); + } case hmi_apis::FunctionID::UI_PerformAudioPassThru: { return hmi_apis::messageType::request == message_type ? factory.GetCreator<commands::UIPerformAudioPassThruRequest>() @@ -844,6 +875,9 @@ CommandCreator& HMICommandFactory::get_creator_factory( ? factory.GetCreator<commands::hmi::DialNumberRequest>() : factory.GetCreator<commands::hmi::DialNumberResponse>(); } + case hmi_apis::FunctionID::BasicCommunication_OnServiceUpdate: { + return factory.GetCreator<commands::hmi::OnServiceUpdateNotification>(); + } case hmi_apis::FunctionID::Navigation_OnWayPointChange: { return factory.GetCreator<commands::OnNaviWayPointChangeNotification>(); } @@ -868,8 +902,26 @@ CommandCreator& HMICommandFactory::get_creator_factory( : factory.GetCreator<commands::BCGetFilePathResponse>(); } case hmi_apis::FunctionID::BasicCommunication_OnSystemCapabilityUpdated: { - return factory - .GetCreator<commands::OnBCSystemCapabilityUpdatedNotification>(); + return (application_manager::commands::Command::CommandSource:: + SOURCE_HMI == source) + ? factory.GetCreator< + commands:: + OnBCSystemCapabilityUpdatedNotificationFromHMI>() + : factory.GetCreator< + commands::OnBCSystemCapabilityUpdatedNotification>(); + } + case hmi_apis::FunctionID::BasicCommunication_GetAppProperties: { + return hmi_apis::messageType::request == message_type + ? factory.GetCreator<commands::BCGetAppPropertiesRequest>() + : factory.GetCreator<commands::BCGetAppPropertiesResponse>(); + } + case hmi_apis::FunctionID::BasicCommunication_SetAppProperties: { + return hmi_apis::messageType::request == message_type + ? factory.GetCreator<commands::BCSetAppPropertiesRequest>() + : factory.GetCreator<commands::BCSetAppPropertiesResponse>(); + } + case hmi_apis::FunctionID::BasicCommunication_OnAppPropertiesChange: { + return factory.GetCreator<commands::OnAppPropertiesChangeNotification>(); } default: { return factory.GetCreator<InvalidCommand>(); } } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/mobile_command_factory.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/mobile_command_factory.cc index 0b91febe1b..c6f4b64636 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/mobile_command_factory.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/mobile_command_factory.cc @@ -40,12 +40,16 @@ #include "sdl_rpc_plugin/commands/mobile/alert_maneuver_response.h" #include "sdl_rpc_plugin/commands/mobile/alert_request.h" #include "sdl_rpc_plugin/commands/mobile/alert_response.h" +#include "sdl_rpc_plugin/commands/mobile/cancel_interaction_request.h" +#include "sdl_rpc_plugin/commands/mobile/cancel_interaction_response.h" #include "sdl_rpc_plugin/commands/mobile/change_registration_request.h" #include "sdl_rpc_plugin/commands/mobile/change_registration_response.h" #include "sdl_rpc_plugin/commands/mobile/close_application_request.h" #include "sdl_rpc_plugin/commands/mobile/close_application_response.h" #include "sdl_rpc_plugin/commands/mobile/create_interaction_choice_set_request.h" #include "sdl_rpc_plugin/commands/mobile/create_interaction_choice_set_response.h" +#include "sdl_rpc_plugin/commands/mobile/create_window_request.h" +#include "sdl_rpc_plugin/commands/mobile/create_window_response.h" #include "sdl_rpc_plugin/commands/mobile/delete_command_request.h" #include "sdl_rpc_plugin/commands/mobile/delete_command_response.h" #include "sdl_rpc_plugin/commands/mobile/delete_file_request.h" @@ -54,6 +58,8 @@ #include "sdl_rpc_plugin/commands/mobile/delete_interaction_choice_set_response.h" #include "sdl_rpc_plugin/commands/mobile/delete_sub_menu_request.h" #include "sdl_rpc_plugin/commands/mobile/delete_sub_menu_response.h" +#include "sdl_rpc_plugin/commands/mobile/delete_window_request.h" +#include "sdl_rpc_plugin/commands/mobile/delete_window_response.h" #include "sdl_rpc_plugin/commands/mobile/dial_number_request.h" #include "sdl_rpc_plugin/commands/mobile/dial_number_response.h" #include "sdl_rpc_plugin/commands/mobile/end_audio_pass_thru_request.h" @@ -174,6 +180,11 @@ CommandCreator& MobileCommandFactory::get_command_creator( ? factory.GetCreator<commands::AddCommandRequest>() : factory.GetCreator<commands::AddCommandResponse>(); } + case mobile_apis::FunctionID::CreateWindowID: { + return mobile_api::messageType::request == message_type + ? factory.GetCreator<commands::CreateWindowRequest>() + : factory.GetCreator<commands::CreateWindowResponse>(); + } case mobile_apis::FunctionID::DeleteCommandID: { return mobile_api::messageType::request == message_type ? factory.GetCreator<commands::DeleteCommandRequest>() @@ -194,6 +205,11 @@ CommandCreator& MobileCommandFactory::get_command_creator( ? factory.GetCreator<commands::ShowAppMenuRequest>() : factory.GetCreator<commands::ShowAppMenuResponse>(); } + case mobile_apis::FunctionID::DeleteWindowID: { + return mobile_api::messageType::request == message_type + ? factory.GetCreator<commands::DeleteWindowRequest>() + : factory.GetCreator<commands::DeleteWindowResponse>(); + } case mobile_apis::FunctionID::DeleteInteractionChoiceSetID: { return mobile_api::messageType::request == message_type ? factory.GetCreator< @@ -221,6 +237,11 @@ CommandCreator& MobileCommandFactory::get_command_creator( ? factory.GetCreator<commands::PerformAudioPassThruRequest>() : factory.GetCreator<commands::PerformAudioPassThruResponse>(); } + case mobile_apis::FunctionID::CancelInteractionID: { + return mobile_api::messageType::request == message_type + ? factory.GetCreator<commands::CancelInteractionRequest>() + : factory.GetCreator<commands::CancelInteractionResponse>(); + } case mobile_apis::FunctionID::CreateInteractionChoiceSetID: { return mobile_api::messageType::request == message_type ? factory.GetCreator< 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 b261b20c24..2a1261f643 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 @@ -44,7 +44,21 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "SdlRPCPlugin") bool SDLRPCPlugin::Init(app_mngr::ApplicationManager& app_manager, app_mngr::rpc_service::RPCService& rpc_service, app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) { + policy::PolicyHandlerInterface& policy_handler, + resumption::LastStateWrapperPtr 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::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; @@ -70,8 +84,14 @@ void SDLRPCPlugin::OnApplicationEvent( plugins::ApplicationEvent event, app_mngr::ApplicationSharedPtr application) { if (plugins::ApplicationEvent::kApplicationRegistered == event) { - application->AddExtension( - std::make_shared<SystemCapabilityAppExtension>(*this, *application)); + auto sys_cap_ext_ptr = + std::make_shared<SystemCapabilityAppExtension>(*this, *application); + application->AddExtension(sys_cap_ext_ptr); + // Processing automatic subscription to SystemCapabilities for DISPLAY type + const auto capability_type = + mobile_apis::SystemCapabilityType::eType::DISPLAYS; + LOG4CXX_DEBUG(logger_, "Subscription to DISPLAYS capability is enabled"); + sys_cap_ext_ptr->SubscribeTo(capability_type); } else if (plugins::ApplicationEvent::kDeleteApplicationData == event) { ClearSubscriptions(application); } @@ -84,6 +104,14 @@ void SDLRPCPlugin::ClearSubscriptions(app_mngr::ApplicationSharedPtr app) { } // namespace sdl_rpc_plugin -extern "C" application_manager::plugin_manager::RPCPlugin* Create() { +extern "C" __attribute__((visibility("default"))) +application_manager::plugin_manager::RPCPlugin* +Create() { return new sdl_rpc_plugin::SDLRPCPlugin(); } + +extern "C" __attribute__((visibility("default"))) void Delete( + application_manager::plugin_manager::RPCPlugin* data) { + delete data; + DELETE_THREAD_LOGGER(sdl_rpc_plugin::logger_); +} diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/CMakeLists.txt b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/CMakeLists.txt index 1a206c2cce..b21ab9dca8 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/CMakeLists.txt +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/CMakeLists.txt @@ -23,15 +23,8 @@ file(GLOB SOURCES ) set(LIBRARIES + sdl_rpc_plugin_static gmock - Utils - SmartObjects - HMI_API - MOBILE_API - connectionHandler - sdl_rpc_plugin - jsoncpp - Policy ) create_cotired_test("sdl_commands_test" "${SOURCES}" "${LIBRARIES}" ) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/basic_communication_get_system_time_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/basic_communication_get_system_time_request_test.cc index 0251c4873d..9cd87b053d 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/basic_communication_get_system_time_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/basic_communication_get_system_time_request_test.cc @@ -60,7 +60,7 @@ TEST_F(BasicCommunicationGetSystemTimeRequestTest, OnTimeout) { ON_CALL(app_mngr_, protocol_handler()) .WillByDefault(ReturnRef(mock_protocol_handler)); - EXPECT_CALL(mock_protocol_handler, NotifyOnFailedHandshake()); + EXPECT_CALL(mock_protocol_handler, NotifyOnGetSystemTimeFailed()); command->onTimeOut(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/bc_get_app_properties_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/bc_get_app_properties_request_test.cc new file mode 100644 index 0000000000..0d70226645 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/bc_get_app_properties_request_test.cc @@ -0,0 +1,367 @@ +/* + * 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 "gtest/gtest.h" + +#include "application_manager/commands/command_impl.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application.h" +#include "hmi/bc_get_app_properties_request.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace bc_get_app_properties_request_test { + +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; + +using am::commands::CommandImpl; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::BCGetAppPropertiesRequest; + +using testing::DoAll; +using testing::Return; +using testing::ReturnRef; +using testing::SaveArg; + +namespace { +const std::string kPolicyAppId = "00001"; +const uint32_t kCorrelationId = 1u; +const auto kSource = am::commands::Command::SOURCE_HMI; + +const std::string kAuthToken = "auth_token"; +const std::string kCertificate = "certificate"; +const std::string kTransportType = "WS"; +const std::string kHybridAppPreference = "local_app"; +const bool kEnabled = true; + +const std::string kNickname1 = "nickname1"; +const std::string kNickname2 = "nickname2"; +} // namespace + +bool CompareAppProperties(const smart_objects::SmartObject& app_propersties_so, + const policy::AppProperties& app_properties) { + return (app_propersties_so[strings::auth_token].asString() == + app_properties.auth_token) && + (app_propersties_so[strings::transport_type].asString() == + app_properties.transport_type) && + (app_propersties_so[strings::hybrid_app_preference].asString() == + app_properties.hybrid_app_preference); +} + +bool CompareNicknames(const smart_objects::SmartObject& nicknames_so, + const policy::StringArray& nicknames) { + if (nicknames_so.length() != nicknames.size()) { + return false; + } + + for (size_t i = 0; i < nicknames_so.length(); ++i) { + if (nicknames_so[i].asString() != nicknames[i]) { + return false; + } + } + return true; +} + +ACTION_P(SetTestAppProperties, app_properties) { + arg1 = app_properties; +} + +ACTION_P(SetTestNickNames, nicknames) { + *arg1 = nicknames; +} + +class BCGetAppPropertiesRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + BCGetAppPropertiesRequestTest() : mock_app_(CreateMockApp()) { + ON_CALL(app_mngr_, GetRPCService()) + .WillByDefault(ReturnRef(mock_rpc_service_)); + } + + MockAppPtr mock_app_; +}; + +TEST_F(BCGetAppPropertiesRequestTest, Run_PolicyAppId_Exist_SUCCESS) { + auto msg = CreateMessage(); + + (*msg)[strings::params][strings::correlation_id] = kCorrelationId; + (*msg)[strings::msg_params][strings::policy_app_id] = kPolicyAppId; + auto command = CreateCommand<BCGetAppPropertiesRequest>(msg); + + // Fills app properties with default test values + EXPECT_CALL(mock_policy_handler_, GetAppProperties(kPolicyAppId, _)) + .WillOnce(DoAll( + SetTestAppProperties(policy::AppProperties("", + kCertificate, + kEnabled, + kAuthToken, + kTransportType, + kHybridAppPreference)), + Return(true))); + + // Fills app nicknames with default test values + EXPECT_CALL(mock_policy_handler_, GetInitialAppData(kPolicyAppId, _, _)) + .WillOnce( + DoAll(SetTestNickNames(policy::StringArray{kNickname1, kNickname2}), + Return(true))); + + auto message_to_hmi = CreateMessage(); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + HMIMessageParametersAre( + kCorrelationId, + hmi_apis::FunctionID::BasicCommunication_GetAppProperties, + hmi_apis::Common_Result::SUCCESS), + kSource)) + .WillOnce(DoAll(SaveArg<0>(&message_to_hmi), Return(true))); + + ASSERT_TRUE(command->Init()); + command->Run(); + + const smart_objects::SmartObject& sent_app_properties = + (*message_to_hmi)[strings::msg_params][strings::properties][0]; + + EXPECT_FALSE(sent_app_properties.empty()); + + const std::string auth_token = + sent_app_properties[strings::auth_token].asString(); + const std::string transport_type = + sent_app_properties[strings::transport_type].asString(); + const std::string hybrid_app_preference = + sent_app_properties[strings::hybrid_app_preference].asString(); + // ENDPOINT should be omitted for local application properties. + EXPECT_FALSE(sent_app_properties.keyExists(strings::endpoint)); + + EXPECT_EQ(kAuthToken, auth_token); + EXPECT_EQ(kTransportType, transport_type); + EXPECT_EQ(kHybridAppPreference, hybrid_app_preference); + + EXPECT_TRUE(sent_app_properties.keyExists(strings::nicknames)); + + const auto nick_names = sent_app_properties[strings::nicknames]; + EXPECT_EQ(kNickname1, nick_names[0].asString()); + EXPECT_EQ(kNickname2, nick_names[1].asString()); +} + +TEST_F(BCGetAppPropertiesRequestTest, + PolicyAppIdExistsInMessage_GetAppPropertiesFailed_UNSUCCESS) { + auto msg = CreateMessage(); + + (*msg)[strings::params][strings::correlation_id] = kCorrelationId; + (*msg)[strings::msg_params][strings::policy_app_id] = kPolicyAppId; + auto command = CreateCommand<BCGetAppPropertiesRequest>(msg); + + EXPECT_CALL(mock_policy_handler_, GetAppProperties(kPolicyAppId, _)) + .WillOnce(Return(false)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + HMIMessageParametersAre( + kCorrelationId, + hmi_apis::FunctionID::BasicCommunication_GetAppProperties, + hmi_apis::Common_Result::DATA_NOT_AVAILABLE), + application_manager::commands::Command::SOURCE_SDL_TO_HMI)) + .WillOnce(Return(true)); + + ASSERT_TRUE(command->Init()); + command->Run(); +} + +TEST_F( + BCGetAppPropertiesRequestTest, + Run_PolicyAppIdIsAbsentInMessage_AppParametersAreAbsent_NickNamesAreAbsent_UNSUCCESS) { + auto msg = CreateMessage(); + + (*msg)[strings::params][strings::correlation_id] = kCorrelationId; + auto command = CreateCommand<BCGetAppPropertiesRequest>(msg); + + EXPECT_CALL(mock_policy_handler_, GetApplicationPolicyIDs()) + .WillOnce(Return(policy::StringArray())); + + EXPECT_CALL(mock_policy_handler_, GetAppProperties(_, _)).Times(0); + EXPECT_CALL(mock_policy_handler_, GetInitialAppData(_, _, _)).Times(0); + + auto message_to_hmi = CreateMessage(); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + HMIMessageParametersAre( + kCorrelationId, + hmi_apis::FunctionID::BasicCommunication_GetAppProperties, + hmi_apis::Common_Result::DATA_NOT_AVAILABLE), + Command::SOURCE_SDL_TO_HMI)) + .WillOnce(DoAll(SaveArg<0>(&message_to_hmi), Return(true))); + + ASSERT_TRUE(command->Init()); + command->Run(); + + EXPECT_FALSE( + (*message_to_hmi)[strings::msg_params].keyExists(strings::properties)); +} + +TEST_F(BCGetAppPropertiesRequestTest, + Run_PolicyAppIdIsAbsentInMessage_ReturnsAllAppProperties_SUCCESS) { + auto msg = CreateMessage(); + + (*msg)[strings::params][strings::correlation_id] = kCorrelationId; + auto command = CreateCommand<BCGetAppPropertiesRequest>(msg); + + const std::string test_policy_app_id1 = "test_policy_app_id1"; + const policy::AppProperties test_app1_properties("", + "cert1", + true, + "auth_token1", + "transport_type1", + "hybrid_app_preference1"); + const policy::StringArray test_nicknames1{"nickname1", "nickname2"}; + + const std::string test_policy_app_id2 = "test_policy_app_id2"; + const policy::AppProperties test_app2_properties("", + "cert2", + false, + "auth_token2", + "transport_type2", + "hybrid_app_preference2"); + const policy::StringArray test_nicknames2{"nickname3", "nickname4"}; + + EXPECT_CALL(mock_policy_handler_, GetApplicationPolicyIDs()) + .WillOnce(Return( + policy::StringArray{test_policy_app_id1, test_policy_app_id2})); + + EXPECT_CALL(mock_policy_handler_, GetAppProperties(test_policy_app_id1, _)) + .WillOnce( + DoAll(SetTestAppProperties(test_app1_properties), Return(true))); + EXPECT_CALL(mock_policy_handler_, + GetInitialAppData(test_policy_app_id1, _, _)) + .WillOnce(DoAll(SetTestNickNames(test_nicknames1), Return(true))); + + EXPECT_CALL(mock_policy_handler_, GetAppProperties(test_policy_app_id2, _)) + .WillOnce( + DoAll(SetTestAppProperties(test_app2_properties), Return(true))); + EXPECT_CALL(mock_policy_handler_, + GetInitialAppData(test_policy_app_id2, _, _)) + .WillOnce(DoAll(SetTestNickNames(test_nicknames2), Return(true))); + + auto message_to_hmi = CreateMessage(); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + HMIMessageParametersAre( + kCorrelationId, + hmi_apis::FunctionID::BasicCommunication_GetAppProperties, + hmi_apis::Common_Result::SUCCESS), + kSource)) + .WillOnce(DoAll(SaveArg<0>(&message_to_hmi), Return(true))); + + ASSERT_TRUE(command->Init()); + command->Run(); + + const auto& sent_app_properties = + (*message_to_hmi)[strings::msg_params][strings::properties]; + + EXPECT_EQ(2u, sent_app_properties.length()); + + // Compare test_app1 app_properties with sent app properties + const auto& sent_test_app1_properties = sent_app_properties[0]; + EXPECT_FALSE(sent_test_app1_properties.keyExists(strings::endpoint)); + EXPECT_TRUE( + CompareAppProperties(sent_test_app1_properties, test_app1_properties)); + + const auto& sent_test_app1_nicknames = + sent_app_properties[0][strings::nicknames]; + EXPECT_TRUE(CompareNicknames(sent_test_app1_nicknames, test_nicknames1)); + + // Compare test_app2 app_properties with sent app properties + const auto& sent_test_app2_properties = sent_app_properties[1]; + EXPECT_FALSE(sent_test_app2_properties.keyExists(strings::endpoint)); + EXPECT_TRUE( + CompareAppProperties(sent_test_app2_properties, test_app2_properties)); + + const auto& sent_test_app2_nicknames = + sent_app_properties[1][strings::nicknames]; + EXPECT_TRUE(CompareNicknames(sent_test_app2_nicknames, test_nicknames2)); +} + +TEST_F(BCGetAppPropertiesRequestTest, + Run_PolicyAppIdExist_NickNamesAreAbsent_SendEmptyArray_SUCCESS) { + auto msg = CreateMessage(); + + (*msg)[strings::params][strings::correlation_id] = kCorrelationId; + (*msg)[strings::msg_params][strings::policy_app_id] = kPolicyAppId; + auto command = CreateCommand<BCGetAppPropertiesRequest>(msg); + + // Fills app properties with default test values + EXPECT_CALL(mock_policy_handler_, GetAppProperties(kPolicyAppId, _)) + .WillOnce(DoAll( + SetTestAppProperties(policy::AppProperties("", + kCertificate, + kEnabled, + kAuthToken, + kTransportType, + kHybridAppPreference)), + Return(true))); + + // In the case when nicknames array is empty, SDL should forward the empty + // array to HMI in the app properties + EXPECT_CALL(mock_policy_handler_, GetInitialAppData(kPolicyAppId, _, _)) + .WillOnce(DoAll(SetTestNickNames(policy::StringArray{}), Return(true))); + + auto message_to_hmi = CreateMessage(); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + HMIMessageParametersAre( + kCorrelationId, + hmi_apis::FunctionID::BasicCommunication_GetAppProperties, + hmi_apis::Common_Result::SUCCESS), + kSource)) + .WillOnce(DoAll(SaveArg<0>(&message_to_hmi), Return(true))); + + ASSERT_TRUE(command->Init()); + command->Run(); + + const auto& sent_app_properties = + (*message_to_hmi)[strings::msg_params][strings::properties]; + + EXPECT_TRUE(sent_app_properties[0].keyExists(strings::nicknames)); + EXPECT_TRUE(sent_app_properties[0][strings::nicknames].empty()); +} + +} // namespace bc_get_app_properties_request_test +} // 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/bc_get_app_properties_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/bc_get_app_properties_response_test.cc new file mode 100644 index 0000000000..f9df8db1e3 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/bc_get_app_properties_response_test.cc @@ -0,0 +1,66 @@ +/* + * 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 names of the copyright holders 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/bc_get_app_properties_response.h" +#include "application_manager/commands/command_impl.h" +#include "application_manager/commands/commands_test.h" +#include "gtest/gtest.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace bc_get_app_properties_response { + +using sdl_rpc_plugin::commands::BCGetAppPropertiesResponse; + +class BCGetAppPropertiesResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(BCGetAppPropertiesResponseTest, RUN_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + + std::shared_ptr<BCGetAppPropertiesResponse> command( + CreateCommand<BCGetAppPropertiesResponse>(msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(msg)); + + ASSERT_TRUE(command->Init()); + command->Run(); +} + +} // namespace bc_get_app_properties_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/bc_set_app_properties_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/bc_set_app_properties_request_test.cc new file mode 100644 index 0000000000..5804476649 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/bc_set_app_properties_request_test.cc @@ -0,0 +1,304 @@ +/* + * 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 names of the copyright holders 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 "gtest/gtest.h" + +#include "application_manager/policies/policy_handler.h" +#include "hmi/bc_set_app_properties_request.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/policies/policy_handler.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace bc_set_app_properties_request { + +namespace am = ::application_manager; +namespace strings = am::strings; + +using sdl_rpc_plugin::commands::BCSetAppPropertiesRequest; +using ::testing::_; +using ::testing::ReturnRef; + +namespace { +const uint32_t kAppId = 1u; +const std::string kPolicyAppId = "00001"; +const std::string kToken = "TOKEN"; +const uint32_t kHmiAppId = 13u; +const uint32_t kCorrelationId = 1u; +const auto kSource = am::commands::Command::SOURCE_HMI; +} // namespace + +typedef std::shared_ptr<BCSetAppPropertiesRequest> BCSetAppPropertiesRequestPtr; + +class BCSetAppPropertiesRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + BCSetAppPropertiesRequestTest() : mock_app_(CreateMockApp()) { + ON_CALL((*mock_app_), app_id()).WillByDefault(Return(kAppId)); + ON_CALL(app_mngr_, event_dispatcher()) + .WillByDefault(ReturnRef(event_dispatcher_)); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); + ON_CALL(app_mngr_, application_by_hmi_app(_)) + .WillByDefault(Return(mock_app_)); + ON_CALL(app_mngr_, GetRPCService()) + .WillByDefault(ReturnRef(mock_rpc_service_)); + ON_CALL(mock_rpc_service_, ManageHMICommand(_, _)) + .WillByDefault(Return(true)); + } + + MessageSharedPtr CreateMessageWithCustomProperties( + const smart_objects::SmartObject& properties) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::correlation_id] = kCorrelationId; + (*msg)[strings::msg_params][strings::app_id] = kAppId; + (*msg)[strings::msg_params][strings::properties] = properties; + return msg; + } + + MockAppPtr mock_app_; +}; + +TEST_F(BCSetAppPropertiesRequestTest, + Run_NoAppPropertyChanges_AppIsSame_FailToUpdateAppList) { + smart_objects::SmartObject properties(smart_objects::SmartType_Map); + properties[strings::policy_app_id] = kPolicyAppId; + + MessageSharedPtr msg = CreateMessageWithCustomProperties(properties); + auto command = CreateCommand<BCSetAppPropertiesRequest>(msg); + + const auto change_status = + policy::PolicyHandler::AppPropertiesState::NO_CHANGES; + ON_CALL(mock_policy_handler_, + GetAppPropertiesStatus(properties, kPolicyAppId)) + .WillByDefault(Return(change_status)); + ON_CALL(mock_policy_handler_, IsNewApplication(kPolicyAppId)) + .WillByDefault(Return(false)); + + MessageSharedPtr notification = CreateMessage(); + ON_CALL(mock_message_helper_, + CreateOnAppPropertiesChangeNotification(kPolicyAppId, _)) + .WillByDefault(Return(notification)); + + EXPECT_CALL(mock_message_helper_, + CreateOnAppPropertiesChangeNotification(_, _)) + .Times(0); + EXPECT_CALL(mock_policy_handler_, + GetAppPropertiesStatus(properties, kPolicyAppId)); + EXPECT_CALL(mock_policy_handler_, OnSetAppProperties(properties)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs( + hmi_apis::FunctionID::BasicCommunication_SetAppProperties), + kSource)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(notification, kSource)) + .Times(0); + EXPECT_CALL(app_mngr_, CreatePendingLocalApplication(kPolicyAppId)).Times(0); + EXPECT_CALL(app_mngr_, SendUpdateAppList()).Times(0); + + ASSERT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(BCSetAppPropertiesRequestTest, + Run_AppAuthTokenChanged_AppIsSame_NoUpdateAppList) { + smart_objects::SmartObject properties(smart_objects::SmartType_Map); + properties[strings::auth_token] = kToken; + properties[strings::policy_app_id] = kPolicyAppId; + + MessageSharedPtr msg = CreateMessageWithCustomProperties(properties); + auto command = CreateCommand<BCSetAppPropertiesRequest>(msg); + + const auto change_status = + policy::PolicyHandler::AppPropertiesState::AUTH_TOKEN_CHANGED; + ON_CALL(mock_policy_handler_, + GetAppPropertiesStatus(properties, kPolicyAppId)) + .WillByDefault(Return(change_status)); + ON_CALL(mock_policy_handler_, IsNewApplication(kPolicyAppId)) + .WillByDefault(Return(false)); + + MessageSharedPtr notification = CreateMessage(); + ON_CALL(mock_message_helper_, + CreateOnAppPropertiesChangeNotification(kPolicyAppId, _)) + .WillByDefault(Return(notification)); + + EXPECT_CALL(mock_message_helper_, + CreateOnAppPropertiesChangeNotification(kPolicyAppId, _)); + EXPECT_CALL(mock_policy_handler_, + GetAppPropertiesStatus(properties, kPolicyAppId)); + EXPECT_CALL(mock_policy_handler_, OnSetAppProperties(properties)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs( + hmi_apis::FunctionID::BasicCommunication_SetAppProperties), + kSource)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(notification, kSource)); + EXPECT_CALL(app_mngr_, CreatePendingLocalApplication(kPolicyAppId)).Times(0); + EXPECT_CALL(app_mngr_, SendUpdateAppList()).Times(0); + + ASSERT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(BCSetAppPropertiesRequestTest, + Run_NoAppPropetiesChanged_AppIsNewAndEnabled_AppListUpdated) { + smart_objects::SmartObject properties(smart_objects::SmartType_Map); + properties[strings::policy_app_id] = kPolicyAppId; + properties[strings::enabled] = true; + + MessageSharedPtr msg = CreateMessageWithCustomProperties(properties); + auto command = CreateCommand<BCSetAppPropertiesRequest>(msg); + + const auto change_status = + policy::PolicyHandler::AppPropertiesState::NO_CHANGES; + ON_CALL(mock_policy_handler_, + GetAppPropertiesStatus(properties, kPolicyAppId)) + .WillByDefault(Return(change_status)); + ON_CALL(mock_policy_handler_, IsNewApplication(kPolicyAppId)) + .WillByDefault(Return(true)); + + MessageSharedPtr notification = CreateMessage(); + ON_CALL(mock_message_helper_, + CreateOnAppPropertiesChangeNotification(kPolicyAppId, _)) + .WillByDefault(Return(notification)); + + EXPECT_CALL(mock_message_helper_, + CreateOnAppPropertiesChangeNotification(kPolicyAppId, _)); + EXPECT_CALL(mock_policy_handler_, + GetAppPropertiesStatus(properties, kPolicyAppId)); + EXPECT_CALL(mock_policy_handler_, OnSetAppProperties(properties)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs( + hmi_apis::FunctionID::BasicCommunication_SetAppProperties), + kSource)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(notification, kSource)); + EXPECT_CALL(app_mngr_, CreatePendingLocalApplication(kPolicyAppId)); + EXPECT_CALL(app_mngr_, SendUpdateAppList()); + + ASSERT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(BCSetAppPropertiesRequestTest, + Run_AppEnabledFlagChanged_AppListUpdated) { + smart_objects::SmartObject properties(smart_objects::SmartType_Map); + properties[strings::policy_app_id] = kPolicyAppId; + properties[strings::enabled] = true; + + MessageSharedPtr msg = CreateMessageWithCustomProperties(properties); + auto command = CreateCommand<BCSetAppPropertiesRequest>(msg); + + const auto change_status = + policy::PolicyHandler::AppPropertiesState::ENABLED_FLAG_SWITCH; + ON_CALL(mock_policy_handler_, + GetAppPropertiesStatus(properties, kPolicyAppId)) + .WillByDefault(Return(change_status)); + ON_CALL(mock_policy_handler_, IsNewApplication(kPolicyAppId)) + .WillByDefault(Return(false)); + + MessageSharedPtr notification = CreateMessage(); + ON_CALL(mock_message_helper_, + CreateOnAppPropertiesChangeNotification(kPolicyAppId, _)) + .WillByDefault(Return(notification)); + + EXPECT_CALL(mock_message_helper_, + CreateOnAppPropertiesChangeNotification(kPolicyAppId, _)); + EXPECT_CALL(mock_policy_handler_, + GetAppPropertiesStatus(properties, kPolicyAppId)); + EXPECT_CALL(mock_policy_handler_, OnSetAppProperties(properties)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs( + hmi_apis::FunctionID::BasicCommunication_SetAppProperties), + kSource)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(notification, kSource)); + EXPECT_CALL(app_mngr_, CreatePendingLocalApplication(kPolicyAppId)); + EXPECT_CALL(app_mngr_, SendUpdateAppList()); + + ASSERT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(BCSetAppPropertiesRequestTest, + Run_AppEnabledFlagChangedToFalse_AppRemoveFromList_AppListUpdated) { + smart_objects::SmartObject properties(smart_objects::SmartType_Map); + properties[strings::policy_app_id] = kPolicyAppId; + properties[strings::enabled] = false; + + MessageSharedPtr msg = CreateMessageWithCustomProperties(properties); + auto command = CreateCommand<BCSetAppPropertiesRequest>(msg); + + const auto change_status = + policy::PolicyHandler::AppPropertiesState::ENABLED_FLAG_SWITCH; + ON_CALL(mock_policy_handler_, + GetAppPropertiesStatus(properties, kPolicyAppId)) + .WillByDefault(Return(change_status)); + ON_CALL(mock_policy_handler_, IsNewApplication(kPolicyAppId)) + .WillByDefault(Return(false)); + + MessageSharedPtr notification = CreateMessage(); + ON_CALL(mock_message_helper_, + CreateOnAppPropertiesChangeNotification(kPolicyAppId, _)) + .WillByDefault(Return(notification)); + + EXPECT_CALL(mock_message_helper_, + CreateOnAppPropertiesChangeNotification(kPolicyAppId, _)); + EXPECT_CALL(mock_policy_handler_, + GetAppPropertiesStatus(properties, kPolicyAppId)); + EXPECT_CALL(mock_policy_handler_, OnSetAppProperties(properties)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs( + hmi_apis::FunctionID::BasicCommunication_SetAppProperties), + kSource)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(notification, kSource)); + EXPECT_CALL(app_mngr_, CreatePendingLocalApplication(kPolicyAppId)).Times(0); + EXPECT_CALL(app_mngr_, RemovePendingApplication(kPolicyAppId)); + EXPECT_CALL(app_mngr_, SendUpdateAppList()); + + ASSERT_TRUE(command->Init()); + command->Run(); +} + +} // namespace bc_set_app_properties_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/bc_set_app_properties_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/bc_set_app_properties_response_test.cc new file mode 100644 index 0000000000..d4b7447d0d --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/bc_set_app_properties_response_test.cc @@ -0,0 +1,66 @@ +/* + * 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 names of the copyright holders 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 "gtest/gtest.h" + +#include "hmi/bc_set_app_properties_response.h" + +#include "application_manager/commands/commands_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace bc_set_app_properties_response { + +using sdl_rpc_plugin::commands::BCSetAppPropertiesResponse; + +class BCSetAppPropertiesResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(BCSetAppPropertiesResponseTest, RUN_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + + std::shared_ptr<BCSetAppPropertiesResponse> command( + CreateCommand<BCSetAppPropertiesResponse>(msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(msg)); + + ASSERT_TRUE(command->Init()); + command->Run(); +} + +} // namespace bc_set_app_properties_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/dummy_hmi_commands_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc index f5593bf241..c66cb81141 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 @@ -56,8 +56,6 @@ #include "hmi/dial_number_response.h" #include "hmi/get_system_info_request.h" #include "hmi/get_system_info_response.h" -#include "hmi/get_urls.h" -#include "hmi/get_urls_response.h" #include "hmi/mixing_audio_supported_request.h" #include "hmi/mixing_audio_supported_response.h" #include "hmi/navi_alert_maneuver_request.h" @@ -320,8 +318,6 @@ typedef Types<commands::OnStartDeviceDiscovery, commands::SDLActivateAppRequest, commands::SDLPolicyUpdateResponse, commands::SDLPolicyUpdate, - commands::GetUrlsResponse, - commands::GetUrls, commands::OnAppPermissionChangedNotification, commands::SDLGetListOfPermissionsResponse, commands::SDLGetListOfPermissionsRequest, diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_urls_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_urls_test.cc deleted file mode 100644 index b19207cc14..0000000000 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_urls_test.cc +++ /dev/null @@ -1,338 +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. - */ - -#include <stdint.h> -#include <string> - -#include "application_manager/commands/command.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/commands/commands_test.h" -#include "application_manager/commands/request_from_hmi.h" -#include "application_manager/event_engine/event_dispatcher.h" -#include "application_manager/message.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/policies/mock_policy_handler_interface.h" -#include "application_manager/policies/policy_handler.h" -#include "application_manager/smart_object_keys.h" -#include "gtest/gtest.h" -#include "hmi/get_urls.h" -#include "policy/mock_policy_manager.h" -#include "smart_objects/smart_object.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace get_urls { - -using namespace hmi_apis; -using namespace policy; -using ::test::components::application_manager_test::MockApplication; -using ::testing::_; -using ::testing::NiceMock; -using ::testing::SetArgReferee; -namespace am = ::application_manager; -namespace strings = ::application_manager::strings; -using am::commands::CommandImpl; -using am::commands::RequestFromHMI; -using policy::PolicyHandler; -using policy_test::MockPolicyHandlerInterface; -using sdl_rpc_plugin::commands::GetUrls; - -typedef std::shared_ptr<RequestFromHMI> RequestFromHMIPtr; - -namespace { -const uint32_t kInvalidAppId_ = 0u; -const uint32_t kAppIdForSending = 1u; -const uint32_t kConnectionKey = 2u; -const uint32_t kServiceType = 0u; -const std::string kInitialService = "0x0"; -const std::string kPolicyService = "7"; -const std::string kDefaultUrl = "URL is not found"; -const std::string kDefaultId = "default"; -const std::string kPolicyAppId = "policy_app_id"; -} // namespace - -class GetUrlsTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { - public: - MessageSharedPtr command_msg_; - RequestFromHMIPtr request_command_; - - GetUrlsTest() { - command_msg_ = - CreateMessage(ns_smart_device_link::ns_smart_objects::SmartType_Map); - (*command_msg_)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - (*command_msg_)[am::strings::msg_params][am::hmi_request::service] = - kInitialService; - - request_command_ = CreateCommand<GetUrls>(command_msg_); - } -}; - -TEST_F(GetUrlsTest, RUN_SUCCESS) { - EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); - // EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(_, _)); - - request_command_->Run(); -} - -TEST_F(GetUrlsTest, RUN_PolicyNotEnabled_UNSUCCESS) { - EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(false)); - - EXPECT_CALL(mock_rpc_service_, ManageHMICommand(command_msg_, _)) - .WillOnce(Return(true)); - - request_command_->Run(); - - EXPECT_EQ(am::MessageType::kResponse, - (*command_msg_)[strings::params][strings::message_type].asInt()); - EXPECT_EQ(Common_Result::DATA_NOT_AVAILABLE, - (*command_msg_)[strings::params][am::hmi_response::code].asInt()); -} - -TEST_F(GetUrlsTest, RUN_EmptyEndpoints_UNSUCCESS) { - EndpointUrls endpoints_; - EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kServiceType, _)) - .WillOnce(SetArgReferee<1>(endpoints_)); - EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); - - EXPECT_CALL(mock_rpc_service_, ManageHMICommand(command_msg_, _)) - .WillOnce(Return(true)); - - request_command_->Run(); - - EXPECT_EQ(am::MessageType::kResponse, - (*command_msg_)[strings::params][strings::message_type].asInt()); - EXPECT_EQ(Common_Result::DATA_NOT_AVAILABLE, - (*command_msg_)[strings::params][am::hmi_response::code].asInt()); -} - -#ifdef EXTENDED_POLICY -TEST_F(GetUrlsTest, ProcessPolicyServiceURLs_SUCCESS) { - (*command_msg_)[am::strings::msg_params][am::hmi_request::service] = - kPolicyService; - - EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); - - EndpointUrls endpoints_; - EndpointData data(kDefaultUrl); - endpoints_.push_back(data); - - EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kPolicyService, _)) - .WillOnce(SetArgReferee<1>(endpoints_)); - - MockAppPtr mock_app = CreateMockApp(); - - EXPECT_CALL(mock_policy_handler_, GetAppIdForSending()) - .WillOnce(Return(kAppIdForSending)); - - EXPECT_CALL(app_mngr_, application(kAppIdForSending)) - .WillOnce(Return(mock_app)); - EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kAppIdForSending)); - EXPECT_CALL(mock_rpc_service_, ManageHMICommand(command_msg_, _)) - .WillOnce(Return(true)); - - request_command_->Run(); - - EXPECT_FALSE((*command_msg_)[am::strings::msg_params].keyExists( - am::hmi_request::service)); - - EXPECT_EQ(am::MessageType::kResponse, - (*command_msg_)[strings::params][strings::message_type].asInt()); - EXPECT_EQ(Common_Result::SUCCESS, - (*command_msg_)[strings::params][am::hmi_response::code].asInt()); - - EXPECT_EQ(kAppIdForSending, - (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] - [strings::app_id] - .asInt()); - EXPECT_EQ(kDefaultUrl, - (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] - [strings::url] - .asString()); -} - -TEST_F(GetUrlsTest, ProcessPolicyServiceURLs_IncorrectIdForSending_UNSUCCESS) { - (*command_msg_)[am::strings::msg_params][am::hmi_request::service] = - kPolicyService; - - EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); - - EndpointUrls endpoints_; - EndpointData data(kDefaultUrl); - endpoints_.push_back(data); - - EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kPolicyService, _)) - .WillOnce(SetArgReferee<1>(endpoints_)); - - EXPECT_CALL(mock_policy_handler_, GetAppIdForSending()) - .WillOnce(Return(kInvalidAppId_)); - - EXPECT_CALL(mock_rpc_service_, ManageHMICommand(command_msg_, _)) - .WillOnce(Return(true)); - - EXPECT_CALL(app_mngr_, application(kInvalidAppId_)).Times(0); - - request_command_->Run(); -} - -TEST_F(GetUrlsTest, ProcessPolicyServiceURLs_ApplicationIsNotValid_UNSUCCESS) { - (*command_msg_)[am::strings::msg_params][am::hmi_request::service] = - kPolicyService; - - EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); - - EndpointUrls endpoints_; - EndpointData data(kDefaultUrl); - endpoints_.push_back(data); - - EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kPolicyService, _)) - .WillOnce(SetArgReferee<1>(endpoints_)); - - MockAppPtr invalid_mock_app; - - EXPECT_CALL(mock_policy_handler_, GetAppIdForSending()) - .WillOnce(Return(kAppIdForSending)); - - EXPECT_CALL(app_mngr_, application(kAppIdForSending)) - .WillOnce(Return(invalid_mock_app)); - - EXPECT_CALL(mock_rpc_service_, ManageHMICommand(command_msg_, _)) - .WillOnce(Return(true)); - - request_command_->Run(); - - EXPECT_EQ(am::MessageType::kResponse, - (*command_msg_)[strings::params][strings::message_type].asInt()); - EXPECT_EQ(Common_Result::DATA_NOT_AVAILABLE, - (*command_msg_)[strings::params][am::hmi_response::code].asInt()); -} - -TEST_F(GetUrlsTest, ProcessPolicyServiceURLs_FoundURLForApplication_SUCCESS) { - (*command_msg_)[am::strings::msg_params][am::hmi_request::service] = - kPolicyService; - - EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); - - EndpointUrls endpoints_; - EndpointData data(kDefaultUrl); - data.app_id = kPolicyAppId; - endpoints_.push_back(data); - - EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kPolicyService, _)) - .WillOnce(SetArgReferee<1>(endpoints_)); - - MockAppPtr mock_app = CreateMockApp(); - - EXPECT_CALL(mock_policy_handler_, GetAppIdForSending()) - .WillOnce(Return(kAppIdForSending)); - - EXPECT_CALL(app_mngr_, application(kAppIdForSending)) - .WillOnce(Return(mock_app)); - - EXPECT_CALL(*mock_app, policy_app_id()).WillOnce(Return(kPolicyAppId)); - - EXPECT_CALL(mock_rpc_service_, ManageHMICommand(command_msg_, _)) - .WillOnce(Return(true)); - - request_command_->Run(); - - EXPECT_FALSE((*command_msg_)[am::strings::msg_params].keyExists( - am::hmi_request::service)); - - EXPECT_EQ(am::MessageType::kResponse, - (*command_msg_)[strings::params][strings::message_type].asInt()); - EXPECT_EQ(Common_Result::SUCCESS, - (*command_msg_)[strings::params][am::hmi_response::code].asInt()); -} -#endif - -TEST_F(GetUrlsTest, DISABLED_ProcessServiceURLs_SUCCESS) { - (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] = - kDefaultUrl; - (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] - [am::hmi_response::policy_app_id] = "1"; - - EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); - - EndpointUrls endpoints_; - EndpointData data(kDefaultUrl); - data.app_id = "1"; - endpoints_.push_back(data); - EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kServiceType, _)) - .WillOnce(SetArgReferee<1>(endpoints_)); - - request_command_->Run(); - - EXPECT_FALSE((*command_msg_)[am::strings::msg_params].keyExists( - am::hmi_request::service)); - EXPECT_EQ(kDefaultUrl, - (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] - [am::strings::url] - .asString()); - EXPECT_EQ(endpoints_[0].app_id, - (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] - [am::hmi_response::policy_app_id] - .asString()); -} - -TEST_F(GetUrlsTest, ProcessServiceURLs_PolicyDefaultId_SUCCESS) { - (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] = - kDefaultUrl; - (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] - [am::hmi_response::policy_app_id] = kDefaultId; - - EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); - EndpointUrls endpoints_; - EndpointData data(kDefaultUrl); - endpoints_.push_back(data); - EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kServiceType, _)) - .WillOnce(SetArgReferee<1>(endpoints_)); - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application_by_policy_id(_)) - .WillOnce(Return(mock_app)); - request_command_->Run(); - - EXPECT_FALSE((*command_msg_)[am::strings::msg_params].keyExists( - am::hmi_request::service)); - EXPECT_TRUE( - (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] - .keyExists(am::hmi_response::policy_app_id)); -} - -} // namespace get_urls -} // 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/hmi_notifications_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc index 2f8f5c2849..26f7a63872 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 @@ -148,6 +148,11 @@ typedef NiceMock< #define NAVI true #define NOT_NAVI false +namespace { +const am::WindowID kDefaultWindowId = + mobile_apis::PredefinedWindows::DEFAULT_WINDOW; +} + ACTION_P(GetEventId, event_id) { *event_id = arg0.id(); } @@ -155,8 +160,8 @@ ACTION_P(GetArg, arg) { *arg = arg0; } -ACTION_P(GetArg3, result) { - arg3 = *result; +ACTION_P(GetArg4, result) { + arg4 = *result; } ACTION_P2(GetConnectIdPermissionConsent, connect_id, consent) { @@ -1103,6 +1108,7 @@ TEST_F(HMICommandsNotificationsTest, .WillOnce(ReturnRef(mock_state_controller_)); EXPECT_CALL(mock_state_controller_, SetRegularState(app_, + kDefaultWindowId, mobile_apis::HMILevel::HMI_NONE, mobile_apis::AudioStreamingState::NOT_AUDIBLE, mobile_apis::VideoStreamingState::NOT_STREAMABLE, @@ -1127,12 +1133,7 @@ TEST_F(HMICommandsNotificationsTest, EXPECT_CALL(app_mngr_, UnregisterApplication(_, _, _, _)).Times(0); EXPECT_CALL(app_mngr_, state_controller()) .WillOnce(ReturnRef(mock_state_controller_)); - EXPECT_CALL(mock_state_controller_, - SetRegularState(app_, - mobile_apis::HMILevel::HMI_NONE, - mobile_apis::AudioStreamingState::NOT_AUDIBLE, - mobile_apis::VideoStreamingState::NOT_STREAMABLE, - false)); + EXPECT_CALL(mock_state_controller_, ExitDefaultWindow(app_)); command->Run(); } @@ -1150,7 +1151,8 @@ TEST_F(HMICommandsNotificationsTest, EXPECT_CALL(app_mngr_, state_controller()) .WillOnce(ReturnRef(mock_state_controller_)); EXPECT_CALL(mock_state_controller_, - SetRegularState(_, mobile_apis::HMILevel::HMI_FULL, true)); + SetRegularState( + _, kDefaultWindowId, mobile_apis::HMILevel::HMI_FULL, true)); EXPECT_CALL(app_mngr_, get_settings()) .WillOnce(ReturnRef(app_mngr_settings_)); @@ -1351,8 +1353,10 @@ TEST_F(HMICommandsNotificationsTest, EXPECT_CALL(*app_ptr_, language()).WillRepeatedly(ReturnRef(kLang)); EXPECT_CALL(app_mngr_, state_controller()) .WillOnce(ReturnRef(mock_state_controller_)); - EXPECT_CALL(mock_state_controller_, - SetRegularState(app_, mobile_apis::HMILevel::HMI_NONE, false)); + EXPECT_CALL( + mock_state_controller_, + SetRegularState( + app_, kDefaultWindowId, mobile_apis::HMILevel::HMI_NONE, false)); EXPECT_CALL(mock_message_helper_, GetOnAppInterfaceUnregisteredNotificationToMobile( kAppId_, @@ -1429,7 +1433,8 @@ TEST_F(HMICommandsNotificationsTest, EXPECT_CALL(app_mngr_, active_application()).WillOnce(Return(app_)); EXPECT_CALL(app_mngr_, state_controller()) .WillOnce(ReturnRef(mock_state_controller_)); - EXPECT_CALL(mock_state_controller_, SetRegularState(app_, *it)); + EXPECT_CALL(mock_state_controller_, + SetRegularState(app_, kDefaultWindowId, *it)); command->Run(); } } @@ -1478,7 +1483,8 @@ TEST_F(HMICommandsNotificationsTest, EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(app_)); EXPECT_CALL(app_mngr_, state_controller()) .WillOnce(ReturnRef(mock_state_controller_)); - EXPECT_CALL(mock_state_controller_, SetRegularState(app_, *it)); + EXPECT_CALL(mock_state_controller_, + SetRegularState(app_, kDefaultWindowId, *it)); command->Run(); } } @@ -1885,8 +1891,8 @@ TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationValidApp) { policy::CheckPermissionResult result; result.hmi_level_permitted = policy::kRpcAllowed; - EXPECT_CALL(mock_policy_handler_, CheckPermissions(_, _, _, _)) - .WillOnce(GetArg3(&result)); + EXPECT_CALL(mock_policy_handler_, CheckPermissions(_, _, _, _, _)) + .WillOnce(GetArg4(&result)); EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_urls_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_app_properties_change_notification_test.cc index f030701710..0ab0bc5a35 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_urls_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_app_properties_change_notification_test.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Ford Motor Company + * Copyright (c) 2020, Ford Motor Company * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,59 +29,63 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ - #include <stdint.h> -#include <string> -#include "application_manager/application.h" -#include "application_manager/commands/command.h" #include "application_manager/commands/commands_test.h" -#include "application_manager/commands/response_to_hmi.h" +#include "application_manager/mock_application.h" #include "application_manager/mock_application_manager.h" #include "application_manager/smart_object_keys.h" #include "gtest/gtest.h" -#include "hmi/get_urls_response.h" +#include "hmi/on_app_properties_change_notification.h" #include "smart_objects/smart_object.h" namespace test { namespace components { namespace commands_test { namespace hmi_commands_test { -namespace get_urls_response { +namespace on_app_properties_change_notification { -using ::testing::_; -using ::testing::Return; -namespace am = ::application_manager; -namespace strings = ::application_manager::strings; -using am::commands::CommandImpl; -using am::commands::ResponseToHMI; -using sdl_rpc_plugin::commands::GetUrlsResponse; +using namespace application_manager; +using sdl_rpc_plugin::commands::OnAppPropertiesChangeNotification; -typedef std::shared_ptr<ResponseToHMI> ResponseToHMIPtr; +typedef std::shared_ptr<OnAppPropertiesChangeNotification> NotificationPtr; +typedef hmi_apis::Common_ServiceType::eType ServiceType; +typedef hmi_apis::Common_ServiceEvent::eType ServiceEvent; namespace { -const uint32_t kConnectionKey = 2u; +const uint32_t kConnectionKey = 1232u; +const uint32_t kHmiAppId = 321u; } // namespace -class GetUrlResponseTest : public CommandsTest<CommandsTestMocks::kIsNice> {}; +class OnAppPropertiesChangeNotificationTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + OnAppPropertiesChangeNotificationTest() + : message_(CreateMessage(smart_objects::SmartType_Map)) {} + + protected: + MessageSharedPtr message_; + NotificationPtr command_; +}; + +TEST_F(OnAppPropertiesChangeNotificationTest, SendNotificationToHMI) { + (*message_)[strings::msg_params][strings::app_id] = kConnectionKey; + command_ = CreateCommand<OnAppPropertiesChangeNotification>(message_); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(message_)).Times(1); -TEST_F(GetUrlResponseTest, RUN_SendRequest_SUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[strings::msg_params][strings::number] = "123"; - (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + auto mock_app = std::make_shared<NiceMock<MockApplication> >(); - ResponseToHMIPtr command(CreateCommand<GetUrlsResponse>(command_msg)); - EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app)); - command->Run(); + ON_CALL(*mock_app, hmi_app_id()).WillByDefault(Return(kHmiAppId)); - EXPECT_EQ((*command_msg)[strings::params][strings::protocol_type].asInt(), - CommandImpl::hmi_protocol_type_); - EXPECT_EQ((*command_msg)[strings::params][strings::protocol_version].asInt(), - CommandImpl::protocol_version_); + ASSERT_TRUE(command_->Init()); + command_->Run(); } -} // namespace get_urls_response +} // namespace on_app_properties_change_notification } // namespace hmi_commands_test } // namespace commands_test } // namespace components 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..f3ed480180 --- /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<OnBCSystemCapabilityUpdatedNotificationFromHMI> + 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<am::mobile_api::FunctionID::eType>( + (*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<CommandsTestMocks::kIsNice> { + protected: + OnBCSystemCapabilityUpdatedNotificationFromHMITest() + : message_(CreateMessage()) + , display_capability_( + (*message_)[am::strings::msg_params][strings::system_capability] + [strings::display_capabilities]) { + command_ = + CreateCommand<OnBCSystemCapabilityUpdatedNotificationFromHMI>(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::DISPLAYS; + + 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::DISPLAYS; + (*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::DISPLAYS; + (*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/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_bc_system_capability_updated_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_bc_system_capability_updated_notification_test.cc new file mode 100644 index 0000000000..cb8894749f --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_bc_system_capability_updated_notification_test.cc @@ -0,0 +1,118 @@ +/* + * 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.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 { + +using sdl_rpc_plugin::commands::OnBCSystemCapabilityUpdatedNotification; +using ::testing::_; +using ::testing::Return; + +typedef std::shared_ptr<OnBCSystemCapabilityUpdatedNotification> + OnBCSystemCapabilityUpdatedNotificationPtr; + +namespace strings = application_manager::strings; +namespace { +const uint32_t kConnectionKey = 1u; +} + +MATCHER_P(CheckDisplayCapabilities, display_capabilities, "") { + return display_capabilities == + (*arg)[strings::msg_params][strings::system_capability] + [strings::display_capabilities]; +} + +class OnBCSystemCapabilityUpdatedNotificationTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + protected: + void SetUp() OVERRIDE { + message_ = CreateMessage(); + (*message_)[strings::params][strings::connection_key] = kConnectionKey; + + command_ = CreateCommand<OnBCSystemCapabilityUpdatedNotification>(message_); + mock_app_ = CreateMockApp(); + } + + OnBCSystemCapabilityUpdatedNotificationPtr command_; + MockAppPtr mock_app_; + MessageSharedPtr message_; +}; + +TEST_F(OnBCSystemCapabilityUpdatedNotificationTest, + SystemDisplayCapabilities_SUCCESS) { + (*message_)[am::strings::msg_params][strings::system_capability] + [am::strings::system_capability_type] = + mobile_apis::SystemCapabilityType::DISPLAYS; + + smart_objects::SmartObjectSPtr system_display_capabilities = + std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType_Null); + + EXPECT_CALL(mock_hmi_capabilities_, system_display_capabilities()) + .Times(2) + .WillRepeatedly(Return(system_display_capabilities)); + + EXPECT_CALL( + mock_rpc_service_, + SendMessageToHMI(CheckDisplayCapabilities(*system_display_capabilities))); + + ASSERT_TRUE(command_->Init()); + command_->Run(); +} + +TEST_F(OnBCSystemCapabilityUpdatedNotificationTest, + SystemDisplayCapabilities_DATA_NOT_AVAILABLE) { + (*message_)[am::strings::msg_params][strings::system_capability] + [am::strings::system_capability_type] = + mobile_apis::SystemCapabilityType::DISPLAYS; + EXPECT_CALL(mock_hmi_capabilities_, system_display_capabilities()) + .WillOnce(Return(nullptr)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)).Times(0); + + ASSERT_TRUE(command_->Init()); + command_->Run(); +} + +} // namespace on_bc_system_capability_updated_notification +} // 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/on_driver_distraction_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc index 5e0083d395..fe6ba7c4e3 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc @@ -126,8 +126,8 @@ MATCHER_P2(CheckNotificationParams, function_id, state, "") { return is_function_id_matched && is_state_matched; } -ACTION_P(GetArg3, result) { - arg3 = *result; +ACTION_P(GetArg4, result) { + arg4 = *result; } ACTION_P(SetMessage, lockScreenDismissalWarning) { @@ -159,8 +159,8 @@ TEST_F(HMIOnDriverDistractionNotificationTest, policy::CheckPermissionResult result; result.hmi_level_permitted = policy::kRpcAllowed; - EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _)) - .WillOnce(GetArg3(&result)); + EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _, _)) + .WillOnce(GetArg4(&result)); MessageSharedPtr message_to_mobile( CreateMessage(smart_objects::SmartType_Map)); @@ -202,8 +202,9 @@ TEST_F(HMIOnDriverDistractionNotificationTest, policy::CheckPermissionResult result; result.hmi_level_permitted = policy::kRpcDisallowed; - EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _)) - .WillOnce(GetArg3(&result)); + EXPECT_CALL(app_mngr_, GetPolicyHandler()).Times(3); + EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _, _)) + .WillOnce(GetArg4(&result)); MessageSharedPtr pushed_message(CreateMessage(smart_objects::SmartType_Map)); EXPECT_CALL(*mock_app_, @@ -240,8 +241,8 @@ TEST_F(HMIOnDriverDistractionNotificationTest, policy::CheckPermissionResult result; result.hmi_level_permitted = policy::kRpcAllowed; - ON_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _)) - .WillByDefault(GetArg3(&result)); + ON_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _, _)) + .WillByDefault(GetArg4(&result)); MessageSharedPtr command_result; EXPECT_CALL(mock_rpc_service_, @@ -284,11 +285,11 @@ TEST_F(HMIOnDriverDistractionNotificationTest, policy::CheckPermissionResult result; result.hmi_level_permitted = policy::kRpcAllowed; - EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _)) - .WillOnce(GetArg3(&result)); - MessageSharedPtr message_to_mobile( CreateMessage(smart_objects::SmartType_Map)); + EXPECT_CALL(app_mngr_, GetPolicyHandler()).Times(2); + EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _, _)) + .WillOnce(GetArg4(&result)); EXPECT_CALL(mock_rpc_service_, ManageMobileCommand( CheckNotificationParams( @@ -331,8 +332,8 @@ TEST_F(HMIOnDriverDistractionNotificationTest, policy::CheckPermissionResult result; result.hmi_level_permitted = policy::kRpcAllowed; - EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _)) - .WillOnce(GetArg3(&result)); + EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _, _)) + .WillOnce(GetArg4(&result)); MessageSharedPtr message_to_mobile( CreateMessage(smart_objects::SmartType_Map)); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_service_status_update_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_service_status_update_notification_test.cc new file mode 100644 index 0000000000..a9bc97f842 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_service_status_update_notification_test.cc @@ -0,0 +1,96 @@ +/* + * 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 <stdint.h> + +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/smart_object_keys.h" +#include "gtest/gtest.h" +#include "hmi/on_service_update_notification.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace on_service_update_notification { + +using namespace application_manager; +using sdl_rpc_plugin::commands::hmi::OnServiceUpdateNotification; + +typedef std::shared_ptr<OnServiceUpdateNotification> NotificationPtr; +typedef hmi_apis::Common_ServiceType::eType ServiceType; +typedef hmi_apis::Common_ServiceEvent::eType ServiceEvent; + +namespace { +const uint32_t kConnectionKey = 1232u; +const uint32_t kHmi_app_id = 321u; +} // namespace + +class OnServiceUpdateNotificationTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + OnServiceUpdateNotificationTest() + : message_(CreateMessage(smart_objects::SmartType_Map)) {} + + public: + MessageSharedPtr message_; + NotificationPtr command_; +}; + +TEST_F(OnServiceUpdateNotificationTest, SendNotificationToHMI) { + (*message_)[strings::msg_params][hmi_notification::service_type] = + ServiceType::AUDIO; + (*message_)[strings::msg_params][hmi_notification::service_event] = + ServiceEvent::REQUEST_ACCEPTED; + (*message_)[strings::msg_params][strings::app_id] = kConnectionKey; + command_ = CreateCommand<OnServiceUpdateNotification>(message_); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(message_)).Times(1); + + auto mock_app = std::make_shared<NiceMock<MockApplication> >(); + + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app)); + + ON_CALL(*mock_app, hmi_app_id()).WillByDefault(Return(kHmi_app_id)); + + command_->Init(); + command_->Run(); +} + +} // namespace on_service_update_notification +} // 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/sdl_get_policy_configuration_data_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_policy_configuration_data_request_test.cc new file mode 100644 index 0000000000..b5263ece7d --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_policy_configuration_data_request_test.cc @@ -0,0 +1,180 @@ +/* + * 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/sdl_get_policy_configuration_data_request.h" +#include "application_manager/commands/command_request_test.h" +#include "gtest/gtest.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace sdl_get_policy_configuration_data_request { + +using testing::Return; + +using sdl_rpc_plugin::commands::SDLGetPolicyConfigurationDataRequest; +using test::components::policy_test::MockPolicyHandlerInterface; + +namespace strings = ::app_mngr::strings; +namespace hmi_response = ::app_mngr::hmi_response; + +class SDLGetPolicyConfigurationDataRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> {}; + +MATCHER_P(GetPolicyConfigurationDataFirstElementMatches, + string_first_element_value, + "") { + auto message = static_cast<smart_objects::SmartObject>(*arg); + if (!message.keyExists(strings::msg_params) || + !message[strings::msg_params].keyExists(strings::value)) { + return false; + } + + if (message[strings::msg_params][strings::value].getType() != + smart_objects::SmartType::SmartType_Array || + message[strings::msg_params][strings::value].empty()) { + return false; + } + + Json::Value msg_json_value(Json::ValueType::arrayValue); + + auto msg_value_first = message[strings::msg_params][strings::value][0]; + return msg_value_first.asString() == string_first_element_value; +} + +MATCHER_P(HMIResultCodeIs, result_code, "") { + return result_code == + static_cast<hmi_apis::Common_Result::eType>( + (*arg)[strings::params][hmi_response::code].asInt()); +} + +TEST_F(SDLGetPolicyConfigurationDataRequestTest, Run_Fail_DataNotAvailable) { + std::string kInvalidKey = "invalid_key"; + + PolicyTable pt; + ON_CALL(mock_policy_handler_, GetPolicyTableData()) + .WillByDefault(Return(pt.ToJsonValue())); + + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::msg_params][strings::policy_type] = kInvalidKey; + (*msg)[strings::msg_params][strings::property] = kInvalidKey; + + std::shared_ptr<SDLGetPolicyConfigurationDataRequest> command( + CreateCommand<SDLGetPolicyConfigurationDataRequest>(msg)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs(hmi_apis::Common_Result::DATA_NOT_AVAILABLE), + Command::SOURCE_SDL_TO_HMI)); + + command->Run(); +} + +void clear_new_line_symbol(std::string& str_to_clear) { + str_to_clear.erase( + std::remove_if(str_to_clear.begin(), + str_to_clear.end(), + [](char character) { return '\n' == character; }), + str_to_clear.end()); +} + +TEST_F(SDLGetPolicyConfigurationDataRequestTest, Run_Success) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::msg_params][strings::policy_type] = "module_config"; + (*msg)[strings::msg_params][strings::property] = "endpoints"; + + std::shared_ptr<SDLGetPolicyConfigurationDataRequest> command( + CreateCommand<SDLGetPolicyConfigurationDataRequest>(msg)); + + policy_table::ModuleConfig module_config_with_endpoints; + policy_table::URLList endpoint_url_list; + policy_table::URL urls; + urls.push_back("https://url1.com"); + urls.push_back("https://url2.com"); + endpoint_url_list["default"] = urls; + module_config_with_endpoints.endpoints["0x9"] = endpoint_url_list; + + PolicyTable pt; + pt.mark_initialized(); + pt.module_config.mark_initialized(); + pt.module_config = module_config_with_endpoints; + + ON_CALL(mock_policy_handler_, GetPolicyTableData()) + .WillByDefault(Return(pt.ToJsonValue())); + + auto json_val = module_config_with_endpoints.endpoints.ToJsonValue(); + Json::StreamWriterBuilder writer_builder; + writer_builder.settings_["indentation"] = ""; + std::string expected_string = Json::writeString(writer_builder, json_val); + clear_new_line_symbol(expected_string); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(GetPolicyConfigurationDataFirstElementMatches( + expected_string), + Command::SOURCE_SDL_TO_HMI)); + command->Run(); +} + +TEST_F(SDLGetPolicyConfigurationDataRequestTest, + Run_RetriveStringValueFromPolicy) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::msg_params][strings::policy_type] = + "consumer_friendly_messages"; + (*msg)[strings::msg_params][strings::property] = "version"; + + auto command = CreateCommand<SDLGetPolicyConfigurationDataRequest>(msg); + + const std::string version_test_value("version string"); + PolicyTable pt; + pt.mark_initialized(); + pt.consumer_friendly_messages->mark_initialized(); + pt.consumer_friendly_messages->version = + rpc::String<1, 100>(version_test_value); + + ON_CALL(mock_policy_handler_, GetPolicyTableData()) + .WillByDefault(Return(pt.ToJsonValue())); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(GetPolicyConfigurationDataFirstElementMatches( + version_test_value), + Command::SOURCE_SDL_TO_HMI)); + + command->Run(); +} + +} // namespace sdl_get_policy_configuration_data_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/sdl_get_user_friendly_message_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_user_friendly_message_request_test.cc index 5cac1c823f..0e87acef1f 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_user_friendly_message_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_user_friendly_message_request_test.cc @@ -110,6 +110,7 @@ TEST_F(SDLGetUserFriendlyMessageRequestTest, Run_LanguageSet_SUCCESS) { EXPECT_CALL(mock_policy_handler_, OnGetUserFriendlyMessage(msg_codes, kLanguageEn, kCorrelationID)); + command->Init(); command->Run(); } @@ -136,6 +137,7 @@ TEST_F(SDLGetUserFriendlyMessageRequestTest, Run_LanguageNotSet_SUCCESS) { EXPECT_CALL(mock_policy_handler_, OnGetUserFriendlyMessage(msg_codes, kLanguageEn, kCorrelationID)); + command->Init(); command->Run(); } @@ -150,6 +152,39 @@ TEST_F(SDLGetUserFriendlyMessageRequestTest, Run_NoMsgCodes_Canceled) { EXPECT_CALL(mock_message_helper_, CommonLanguageToString(_)).Times(0); EXPECT_CALL(mock_policy_handler_, OnGetUserFriendlyMessage(_, _, _)).Times(0); + command->Init(); + command->Run(); +} + +MATCHER_P(HMIRequestResultCodeIs, result_code, "") { + return result_code == + static_cast<hmi_apis::Common_Result::eType>( + (*arg)[strings::params][am::hmi_response::code].asInt()); +} + +TEST_F( + SDLGetUserFriendlyMessageRequestTest, + RUN_InvalidRequestInvalidSymbolsStringMandatoryParam_SendInvalidDataErrorResponse) { + const std::string kInvalidSyntaxString = "\n\t "; + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::correlation_id] = kCorrelationID; + (*msg)[strings::msg_params][strings::app_id] = kAppID; + + (*msg)[strings::msg_params][kMessageCodes] = + SmartObject(smart_objects::SmartType_Array); + (*msg)[strings::msg_params][kMessageCodes][0] = + SmartObject(kInvalidSyntaxString); + (*msg)[strings::msg_params][kMessageCodes][1] = SmartObject(kLanguageEn); + + (*msg)[strings::msg_params][strings::language] = kLanguage; + + std::shared_ptr<SDLGetUserFriendlyMessageRequest> command( + CreateCommand<SDLGetUserFriendlyMessageRequest>(msg)); + + EXPECT_CALL(mock_message_helper_, CommonLanguageToString(_)).Times(0); + EXPECT_CALL(mock_policy_handler_, OnGetUserFriendlyMessage(_, _, _)).Times(0); + + command->Init(); command->Run(); } 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 3fd3a39dca..4683fc62c7 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 @@ -145,7 +145,7 @@ TEST_F(UIGetCapabilitiesResponseTest, SetHmiZone_SUCCESS) { TEST_F(UIGetCapabilitiesResponseTest, SetAudioPassThru_SUCCESS) { MessageSharedPtr command_msg = CreateCommandMsg(); (*command_msg)[strings::msg_params][strings::audio_pass_thru_capabilities] = - smart_objects::SmartObject(smart_objects::SmartType_Array); + smart_objects::SmartObject(smart_objects::SmartType_Map); ResponseFromHMIPtr command( CreateCommand<UIGetCapabilitiesResponse>(command_msg)); @@ -153,9 +153,40 @@ TEST_F(UIGetCapabilitiesResponseTest, SetAudioPassThru_SUCCESS) { smart_objects::SmartObject audio_pass_thru_capabilities_so = (*command_msg)[strings::msg_params] [strings::audio_pass_thru_capabilities]; + + // hmi_capabilities will receive a list of capabilities, the first element + // being audio_pass_thru_capabilities_so + smart_objects::SmartObject audio_pass_thru_capabilities_list_so = + smart_objects::SmartObject(smart_objects::SmartType_Array); + audio_pass_thru_capabilities_list_so[0] = audio_pass_thru_capabilities_so; EXPECT_CALL( mock_hmi_capabilities_, - set_audio_pass_thru_capabilities(audio_pass_thru_capabilities_so)); + set_audio_pass_thru_capabilities(audio_pass_thru_capabilities_list_so)); + + command->Run(); +} + +TEST_F(UIGetCapabilitiesResponseTest, SetAudioPassThruList_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + + // if both audioPassThruCapabilities and audioPassThruCapabilitiesList are + // supplied, audioPassThruCapabilitiesList should be used + smart_objects::SmartObject audio_pass_thru_capabilities_so = + smart_objects::SmartObject(smart_objects::SmartType_Map); + smart_objects::SmartObject audio_pass_thru_capabilities_list_so = + smart_objects::SmartObject(smart_objects::SmartType_Array); + (*command_msg)[strings::msg_params][strings::audio_pass_thru_capabilities] = + audio_pass_thru_capabilities_so; + (*command_msg)[strings::msg_params] + [strings::audio_pass_thru_capabilities_list] = + audio_pass_thru_capabilities_list_so; + + ResponseFromHMIPtr command( + CreateCommand<UIGetCapabilitiesResponse>(command_msg)); + + EXPECT_CALL( + mock_hmi_capabilities_, + set_audio_pass_thru_capabilities(audio_pass_thru_capabilities_list_so)); command->Run(); } @@ -279,7 +310,7 @@ TEST_F(UIGetCapabilitiesResponseTest, SetVideoStreamingCapability_SUCCESS) { video_streaming_capability[strings::preferred_resolution] [strings::resolution_width] = 800; video_streaming_capability[strings::preferred_resolution] - [strings::resolution_height] = 350; + [strings::resolution_height] = 354; video_streaming_capability[strings::max_bitrate] = 10000; @@ -297,6 +328,12 @@ TEST_F(UIGetCapabilitiesResponseTest, SetVideoStreamingCapability_SUCCESS) { video_streaming_capability[strings::haptic_spatial_data_supported] = true; + video_streaming_capability[strings::diagonal_screen_size] = 7.47; + + video_streaming_capability[strings::pixel_per_inch] = 117.f; + + video_streaming_capability[strings::scale] = 1.f; + ResponseFromHMIPtr command( CreateCommand<UIGetCapabilitiesResponse>(command_msg)); @@ -306,6 +343,25 @@ 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<UIGetCapabilitiesResponse>(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(); +} + } // namespace ui_get_capabilities_response } // namespace hmi_commands_test } // namespace commands_test 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 113c6d32a0..dc7731bfc8 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 @@ -73,6 +73,8 @@ const uint32_t kDefaultTimeout = 1000u; const uint32_t kCorrelationId = 2u; const mobile_apis::FunctionID::eType kFunctionId = mobile_apis::FunctionID::AlertID; +const am::WindowID kDefaultWindowId = + mobile_apis::PredefinedWindows::DEFAULT_WINDOW; } // namespace class AlertRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { @@ -138,9 +140,9 @@ class AlertRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { *mock_app_, AreCommandLimitsExceeded(kFunctionId, am::TLimitSource::POLICY_TABLE)) .WillByDefault(Return(false)); - ON_CALL(*mock_app_, hmi_level()) + ON_CALL(*mock_app_, hmi_level(kDefaultWindowId)) .WillByDefault(Return(mobile_apis::HMILevel::HMI_FULL)); - ON_CALL(*mock_app_, hmi_level()) + ON_CALL(*mock_app_, hmi_level(kDefaultWindowId)) .WillByDefault(Return(mobile_apis::HMILevel::HMI_BACKGROUND)); } @@ -155,7 +157,8 @@ class AlertRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { } void ExpectCallHmiLevel(const mobile_apis::HMILevel::eType level) { - EXPECT_CALL(*mock_app_, hmi_level()).WillRepeatedly(Return(level)); + EXPECT_CALL(*mock_app_, hmi_level(kDefaultWindowId)) + .WillRepeatedly(Return(level)); } void ExpectManageMobileCommandWithResultCode( diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_window_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_window_request_test.cc new file mode 100644 index 0000000000..905c6ceb72 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_window_request_test.cc @@ -0,0 +1,460 @@ +/* + * 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 <stdint.h> +#include <memory> +#include <set> +#include <string> + +#include "mobile/create_window_request.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/hmi_state.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/mock_state_controller.h" +#include "gtest/gtest.h" +#include "interfaces/MOBILE_API.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace create_window_request { + +namespace am = application_manager; +using am::MockMessageHelper; +using am::commands::CommandImpl; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::CreateWindowRequest; +using namespace mobile_apis::PredefinedWindows; +using am::commands::Command; +using application_manager::WindowID; +using test::components::application_manager_test::MockStateController; +using test::components::policy_test::MockPolicyHandlerInterface; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; + +namespace { +const uint32_t kAppId = 1u; +const uint32_t kConnectionKey = 2u; +const int32_t kFunctionID = mobile_apis::FunctionID::CreateWindowID; +const WindowID kTestWindowId = 12; +const WindowID kDuplicateWindowID = 13; +const char* const kWindowName = "WindowName"; +const utils::custom_string::CustomString kAppName("TestApp"); +} // namespace + +MATCHER_P2(CheckMessageToMobile, result_code, success, "") { + const bool is_success = + (*arg)[am::strings::msg_params][am::strings::success].asBool() == success; + + const bool is_result_code_correct = + (*arg)[am::strings::msg_params][am::strings::result_code].asInt() == + static_cast<int32_t>(result_code); + return is_success && is_result_code_correct; +} + +class CreateWindowRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + CreateWindowRequestTest() { + mock_app_ = CreateMockApp(); + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + } + + protected: + MessageSharedPtr CreateMsgParams() { + auto msg = CreateMessage(); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg)[am::strings::params][am::strings::function_id] = kFunctionID; + return msg; + } + + void SetupHelperApplyWindowInitialState(const MockAppPtr& app, + const MessageSharedPtr& msg) { + am::HmiStatePtr state(new am::HmiState(app, app_mngr_)); + const auto window_type = static_cast<mobile_apis::WindowType::eType>( + (*msg)[am::strings::msg_params][am::strings::window_type].asInt()); + const auto window_id = static_cast<mobile_apis::WindowType::eType>( + (*msg)[am::strings::msg_params][am::strings::window_id].asInt()); + const auto window_name = + (*msg)[am::strings::msg_params][am::strings::window_name].asString(); + + state->set_window_type(window_type); + state->set_hmi_level(mobile_apis::HMILevel::INVALID_ENUM); + state->set_audio_streaming_state( + mobile_apis::AudioStreamingState::INVALID_ENUM); + state->set_video_streaming_state( + mobile_apis::VideoStreamingState::INVALID_ENUM); + state->set_system_context(mobile_apis::SystemContext::INVALID_ENUM); + ApplicationSharedPtr AppPtr = app; + ON_CALL(app_mngr_, + CreateRegularState(AppPtr, + window_type, + mobile_apis::HMILevel::INVALID_ENUM, + mobile_apis::AudioStreamingState::INVALID_ENUM, + mobile_apis::VideoStreamingState::INVALID_ENUM, + mobile_apis::SystemContext::INVALID_ENUM)) + .WillByDefault(Return(state)); + ON_CALL(*mock_app_, SetInitialState(kTestWindowId, window_name, state)) + .WillByDefault(Return()); + ON_CALL(app_mngr_, state_controller()) + .WillByDefault(ReturnRef(mock_state_controller)); + ON_CALL( + mock_state_controller, + OnAppWindowAdded( + AppPtr, window_id, window_type, mobile_apis::HMILevel::HMI_NONE)) + .WillByDefault(Return()); + } + + void SetUp() OVERRIDE { + using namespace application_manager; + display_capabilities_ = std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType_Array); + + smart_objects::SmartObject window_type_supported( + smart_objects::SmartType_Array); + + const uint32_t maximum_widgets_amount = 4; + smart_objects::SmartObject maximum_widgets(smart_objects::SmartType_Map); + maximum_widgets[strings::window_type] = mobile_apis::WindowType::WIDGET; + maximum_widgets[strings::maximum_number_of_windows] = + maximum_widgets_amount; + + window_type_supported[window_type_supported.length()] = maximum_widgets; + + (*display_capabilities_)[0][strings::window_type_supported] = + window_type_supported; + + ON_CALL(*mock_app_, display_capabilities()) + .WillByDefault(Return(display_capabilities_)); + + ON_CALL(mock_hmi_capabilities_, system_display_capabilities()) + .WillByDefault(Return(display_capabilities_)); + + window_params_map_lock_ptr_ = std::make_shared<sync_primitives::Lock>(); + + DataAccessor<am::WindowParamsMap> window_params_map( + test_window_params_map_, window_params_map_lock_ptr_); + ON_CALL(*mock_app_, window_optional_params_map()) + .WillByDefault(Return(window_params_map)); + } + + MockAppPtr mock_app_; + NiceMock<MockStateController> mock_state_controller; + std::shared_ptr<sync_primitives::Lock> window_params_map_lock_ptr_; + application_manager::WindowParamsMap test_window_params_map_; + smart_objects::SmartObjectSPtr display_capabilities_; +}; + +TEST_F(CreateWindowRequestTest, WindowID_ExpectDefaultWindowID) { + auto msg = CreateMsgParams(); + const auto command = CreateCommand<CreateWindowRequest>(msg); + EXPECT_EQ(mobile_apis::PredefinedWindows::DEFAULT_WINDOW, + command->window_id()); +} + +TEST_F(CreateWindowRequestTest, + Run_AppDoesNotExist_ExpectAppNotRegisteredResponseToMobile) { + const auto result_code = mobile_apis::Result::APPLICATION_NOT_REGISTERED; + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(CheckMessageToMobile(result_code, false), + Command::CommandSource::SOURCE_SDL)) + .WillOnce(Return(true)); + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(nullptr)); + + auto msg = CreateMsgParams(); + auto command = CreateCommand<CreateWindowRequest>(msg); + EXPECT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(CreateWindowRequestTest, + Run_WindowIDAlreadyExist_ExpectInvalidIDResponseToMobile) { + const auto result_code = mobile_apis::Result::INVALID_ID; + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(CheckMessageToMobile(result_code, false), + Command::CommandSource::SOURCE_SDL)) + .WillOnce(Return(true)); + ON_CALL(*mock_app_, WindowIdExists(kTestWindowId)) + .WillByDefault(Return(true)); + + auto msg = CreateMsgParams(); + (*msg)[am::strings::msg_params][am::strings::window_id] = kTestWindowId; + + auto command = CreateCommand<CreateWindowRequest>(msg); + EXPECT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(CreateWindowRequestTest, + Run_CreateWindowForMAINWindowType_ExpectInvalidDataResponseToMobile) { + const auto result_code = mobile_apis::Result::INVALID_DATA; + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(CheckMessageToMobile(result_code, false), + Command::CommandSource::SOURCE_SDL)) + .WillOnce(Return(true)); + ON_CALL(*mock_app_, WindowIdExists(kTestWindowId)) + .WillByDefault(Return(false)); + + auto msg = CreateMsgParams(); + (*msg)[am::strings::msg_params][am::strings::window_id] = kTestWindowId; + (*msg)[am::strings::msg_params][am::strings::window_type] = + mobile_apis::WindowType::eType::MAIN; + + auto command = CreateCommand<CreateWindowRequest>(msg); + EXPECT_TRUE(command->Init()); + command->Run(); +} + +TEST_F( + CreateWindowRequestTest, + Run_DuplicateUpdatesFromNotExistingWindowId_ExpectInvalidDataResponseToMobile) { + const auto result_code = mobile_apis::Result::INVALID_DATA; + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(CheckMessageToMobile(result_code, false), + Command::CommandSource::SOURCE_SDL)) + .WillOnce(Return(true)); + ON_CALL(*mock_app_, WindowIdExists(kTestWindowId)) + .WillByDefault(Return(false)); + ON_CALL(*mock_app_, WindowIdExists(kDuplicateWindowID)) + .WillByDefault(Return(false)); + + auto msg = CreateMsgParams(); + (*msg)[am::strings::msg_params][am::strings::window_id] = kTestWindowId; + (*msg)[am::strings::msg_params] + [am::strings::duplicate_updates_from_window_id] = kDuplicateWindowID; + + auto command = CreateCommand<CreateWindowRequest>(msg); + EXPECT_TRUE(command->Init()); + command->Run(); +} + +TEST_F( + CreateWindowRequestTest, + Run_DuplicateUpdatesFromExistingWindowId_ExpectUICreateWindowIsSentToHMI) { + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_CreateWindow), + Command::CommandSource::SOURCE_SDL_TO_HMI)) + .WillOnce(Return(true)); + ON_CALL(*mock_app_, WindowIdExists(kTestWindowId)) + .WillByDefault(Return(false)); + ON_CALL(*mock_app_, WindowIdExists(kDuplicateWindowID)) + .WillByDefault(Return(true)); + ON_CALL(*mock_app_, name()).WillByDefault(ReturnRef(kAppName)); + ON_CALL(*mock_app_, GetWindowNames()) + .WillByDefault(Return(std::vector<std::string>())); + + auto msg = CreateMsgParams(); + (*msg)[am::strings::msg_params][am::strings::window_id] = kTestWindowId; + (*msg)[am::strings::msg_params] + [am::strings::duplicate_updates_from_window_id] = kDuplicateWindowID; + (*msg)[am::strings::msg_params][am::strings::window_type] = + mobile_apis::WindowType::WIDGET; + + auto command = CreateCommand<CreateWindowRequest>(msg); + EXPECT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(CreateWindowRequestTest, + Run_WindowNameAppNameAreEqual_ExpectDuplicateNameResponseToMobile) { + const auto result_code = mobile_apis::Result::DUPLICATE_NAME; + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(CheckMessageToMobile(result_code, false), + Command::CommandSource::SOURCE_SDL)) + .WillOnce(Return(true)); + ON_CALL(*mock_app_, WindowIdExists(kTestWindowId)) + .WillByDefault(Return(false)); + ON_CALL(*mock_app_, name()).WillByDefault(ReturnRef(kAppName)); + + auto msg = CreateMsgParams(); + (*msg)[am::strings::msg_params][am::strings::window_id] = kTestWindowId; + (*msg)[am::strings::msg_params][am::strings::window_name] = kAppName; + + auto command = CreateCommand<CreateWindowRequest>(msg); + EXPECT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(CreateWindowRequestTest, + Run_AllParametersCorrect_ExpectUICreateWindowIsSentToHMI) { + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_CreateWindow), + Command::CommandSource::SOURCE_SDL_TO_HMI)) + .WillOnce(Return(true)); + ON_CALL(*mock_app_, WindowIdExists(kTestWindowId)) + .WillByDefault(Return(false)); + ON_CALL(*mock_app_, WindowIdExists(kDuplicateWindowID)) + .WillByDefault(Return(true)); + ON_CALL(*mock_app_, name()).WillByDefault(ReturnRef(kAppName)); + + const std::vector<std::string> windowNames = { + "WindowName_1", "WindowName_2", "WindowName_3"}; + ON_CALL(*mock_app_, GetWindowNames()).WillByDefault(Return(windowNames)); + + auto msg = CreateMsgParams(); + (*msg)[am::strings::msg_params][am::strings::window_id] = kTestWindowId; + (*msg)[am::strings::msg_params][am::strings::window_name] = kWindowName; + (*msg)[am::strings::msg_params] + [am::strings::duplicate_updates_from_window_id] = kDuplicateWindowID; + (*msg)[am::strings::msg_params][am::strings::associated_service_type] = + "MEDIA"; + (*msg)[am::strings::msg_params][am::strings::window_type] = + mobile_apis::WindowType::WIDGET; + + auto command = CreateCommand<CreateWindowRequest>(msg); + EXPECT_TRUE(command->Init()); + command->Run(); +} + +TEST_F( + CreateWindowRequestTest, + CheckWindowName_AllParametersCorrectCreateWindowForPrimaryWidget_SendMessageToHMI) { + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_CreateWindow), + Command::CommandSource::SOURCE_SDL_TO_HMI)) + .WillOnce(Return(true)); + ON_CALL(*mock_app_, WindowIdExists(kTestWindowId)) + .WillByDefault(Return(false)); + ON_CALL(*mock_app_, WindowIdExists(kDuplicateWindowID)) + .WillByDefault(Return(true)); + ON_CALL(*mock_app_, name()).WillByDefault(ReturnRef(kAppName)); + + auto msg = CreateMsgParams(); + (*msg)[am::strings::msg_params][am::strings::window_id] = + mobile_apis::PredefinedWindows::PRIMARY_WIDGET; + (*msg)[am::strings::msg_params][am::strings::window_name] = kWindowName; + (*msg)[am::strings::msg_params] + [am::strings::duplicate_updates_from_window_id] = kDuplicateWindowID; + (*msg)[am::strings::msg_params][am::strings::associated_service_type] = + "MEDIA"; + (*msg)[am::strings::msg_params][am::strings::window_type] = + mobile_apis::WindowType::WIDGET; + + auto command = CreateCommand<CreateWindowRequest>(msg); + EXPECT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(CreateWindowRequestTest, + OnEvent_InvalidFunctionId_MessageNotSendToMobile) { + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + auto msg = CreateMsgParams(); + auto command = CreateCommand<CreateWindowRequest>(msg); + EXPECT_TRUE(command->Init()); + Event event(hmi_apis::FunctionID::INVALID_ENUM); + command->on_event(event); +} + +TEST_F(CreateWindowRequestTest, + OnEvent_AppDoesNotExist_ExpectAppNotRegisteredResponseToMobile) { + const auto result_code = mobile_apis::Result::APPLICATION_NOT_REGISTERED; + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(CheckMessageToMobile(result_code, false), + Command::CommandSource::SOURCE_SDL)) + .WillOnce(Return(true)); + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(nullptr)); + + auto msg = CreateMsgParams(); + auto command = CreateCommand<CreateWindowRequest>(msg); + EXPECT_TRUE(command->Init()); + Event event(hmi_apis::FunctionID::UI_CreateWindow); + command->on_event(event); +} + +TEST_F(CreateWindowRequestTest, + OnEvent_RequestFailedOnHMISide_SendGenericErrorResponseToMobile) { + const auto result_code = mobile_apis::Result::GENERIC_ERROR; + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(CheckMessageToMobile(result_code, false), + Command::CommandSource::SOURCE_SDL)) + .WillOnce(Return(true)); + + auto msg = CreateMsgParams(); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::GENERIC_ERROR; + (*msg)[am::strings::msg_params][am::strings::window_name] = kWindowName; + (*msg)[am::strings::msg_params][am::strings::window_id] = kTestWindowId; + (*msg)[am::strings::msg_params][am::strings::window_type] = + mobile_apis::WindowType::eType::WIDGET; + + SetupHelperApplyWindowInitialState(mock_app_, msg); + + Event event(hmi_apis::FunctionID::UI_CreateWindow); + event.set_smart_object(*msg); + + auto command = CreateCommand<CreateWindowRequest>(msg); + EXPECT_TRUE(command->Init()); + command->on_event(event); +} + +TEST_F(CreateWindowRequestTest, + OnEvent_AllParametersCorrect_SendSuccessResponseToMobile) { + const auto result_code = mobile_apis::Result::SUCCESS; + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(CheckMessageToMobile(result_code, true), + Command::CommandSource::SOURCE_SDL)) + .WillOnce(Return(true)); + EXPECT_CALL(*mock_app_, UpdateHash()).Times(1); + auto msg = CreateMsgParams(); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*msg)[am::strings::msg_params][am::strings::window_name] = kWindowName; + (*msg)[am::strings::msg_params][am::strings::window_id] = kTestWindowId; + (*msg)[am::strings::msg_params][am::strings::window_type] = + mobile_apis::WindowType::eType::WIDGET; + + SetupHelperApplyWindowInitialState(mock_app_, msg); + + Event event(hmi_apis::FunctionID::UI_CreateWindow); + event.set_smart_object(*msg); + + auto command = CreateCommand<CreateWindowRequest>(msg); + EXPECT_TRUE(command->Init()); + command->on_event(event); +} + +} // namespace create_window_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_file_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_file_test.cc index 4081583099..cce53bb480 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_file_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_file_test.cc @@ -98,6 +98,8 @@ namespace { const uint32_t kConnectionKey = 1u; const uint32_t kCorrelationId = 10u; const int32_t kMenuId = 5; +const am::WindowID kDefaultWindowId = + mobile_apis::PredefinedWindows::DEFAULT_WINDOW; } // namespace class DeleteFileRequestTest @@ -134,7 +136,7 @@ TEST_F(DeleteFileRequestTest, Run_HMILevelNone_UNSUCCESS) { EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillOnce(Return(mock_app_)); - EXPECT_CALL(*mock_app_, hmi_level()) + EXPECT_CALL(*mock_app_, hmi_level(kDefaultWindowId)) .WillOnce(Return(am::mobile_api::HMILevel::HMI_NONE)); EXPECT_CALL(app_mngr_, get_settings()) @@ -161,7 +163,7 @@ TEST_F(DeleteFileRequestTest, Run_ValidFileName_SUCCESS) { EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillRepeatedly(Return(mock_app_)); - EXPECT_CALL(*mock_app_, hmi_level()) + EXPECT_CALL(*mock_app_, hmi_level(kDefaultWindowId)) .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); EXPECT_CALL(app_mngr_, get_settings()) @@ -191,7 +193,7 @@ TEST_F(DeleteFileRequestTest, Run_InvalidFile_UNSUCCESS) { (*message_)[am::strings::msg_params][am::strings::sync_file_name] = file_name; EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); - EXPECT_CALL(*mock_app_, hmi_level()) + EXPECT_CALL(*mock_app_, hmi_level(kDefaultWindowId)) .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); EXPECT_CALL(app_mngr_, get_settings()) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_window_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_window_request_test.cc new file mode 100644 index 0000000000..f951d5c2a7 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_window_request_test.cc @@ -0,0 +1,278 @@ +/* + * 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 <stdint.h> +#include <memory> +#include <set> +#include <string> + +#include "mobile/delete_window_request.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/hmi_state.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/mock_state_controller.h" +#include "gtest/gtest.h" +#include "interfaces/MOBILE_API.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace delete_window_request { + +namespace am = application_manager; +using am::MockMessageHelper; +using am::commands::CommandImpl; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::DeleteWindowRequest; +using namespace mobile_apis::PredefinedWindows; +using am::commands::Command; +using application_manager::WindowID; +using test::components::application_manager_test::MockStateController; +using test::components::policy_test::MockPolicyHandlerInterface; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; + +namespace { +const uint32_t kConnectionKey = 2u; +const int32_t kFunctionID = mobile_apis::FunctionID::DeleteWindowID; +const WindowID kTestWindowId = 12; +} // namespace + +MATCHER_P2(CheckMessageToMobile, result_code, success, "") { + const bool is_success = + (*arg)[am::strings::msg_params][am::strings::success].asBool() == success; + + const bool is_result_code_correct = + (*arg)[am::strings::msg_params][am::strings::result_code].asInt() == + static_cast<int32_t>(result_code); + return is_success && is_result_code_correct; +} + +class DeleteWindowRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + DeleteWindowRequestTest() { + mock_app_ = CreateMockApp(); + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + } + + protected: + MessageSharedPtr CreateMsgParams() { + auto msg = CreateMessage(); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg)[am::strings::params][am::strings::function_id] = kFunctionID; + return msg; + } + + MockAppPtr mock_app_; + NiceMock<MockStateController> mock_state_controller; +}; + +TEST_F(DeleteWindowRequestTest, WindowID_ExpectDefaultWindowID) { + auto msg = CreateMsgParams(); + const auto command = CreateCommand<DeleteWindowRequest>(msg); + EXPECT_EQ(mobile_apis::PredefinedWindows::DEFAULT_WINDOW, + command->window_id()); +} + +TEST_F(DeleteWindowRequestTest, + Run_AppDoesNotExist_ExpectAppNotRegisteredResponseToMobile) { + const auto result_code = mobile_apis::Result::APPLICATION_NOT_REGISTERED; + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(CheckMessageToMobile(result_code, false), + Command::CommandSource::SOURCE_SDL)) + .WillOnce(Return(true)); + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(nullptr)); + + auto msg = CreateMsgParams(); + auto command = CreateCommand<DeleteWindowRequest>(msg); + EXPECT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(DeleteWindowRequestTest, + Run_WindowIDForMainApplicationWindow_ExpectInvalidIDResponseToMobile) { + const auto result_code = mobile_apis::Result::INVALID_ID; + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(CheckMessageToMobile(result_code, false), + Command::CommandSource::SOURCE_SDL)) + .WillOnce(Return(true)); + + auto msg = CreateMsgParams(); + (*msg)[am::strings::msg_params][am::strings::window_id] = + mobile_apis::PredefinedWindows::DEFAULT_WINDOW; + + auto command = CreateCommand<DeleteWindowRequest>(msg); + EXPECT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(DeleteWindowRequestTest, + Run_WindowIDNotExist_ExpectInvalidIDResponseToMobile) { + const auto result_code = mobile_apis::Result::INVALID_ID; + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(CheckMessageToMobile(result_code, false), + Command::CommandSource::SOURCE_SDL)) + .WillOnce(Return(true)); + ON_CALL(*mock_app_, GetWindowIds()).WillByDefault(Return(am::WindowIds())); + + auto msg = CreateMsgParams(); + (*msg)[am::strings::msg_params][am::strings::window_id] = kTestWindowId; + + auto command = CreateCommand<DeleteWindowRequest>(msg); + EXPECT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(DeleteWindowRequestTest, + Run_AllParametersCorrect_ExpectUIDeleteWindowIsSentToHMI) { + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_DeleteWindow), + Command::CommandSource::SOURCE_SDL_TO_HMI)) + .WillOnce(Return(true)); + + ON_CALL(*mock_app_, GetWindowIds()) + .WillByDefault(Return(am::WindowIds(1, kTestWindowId))); + EXPECT_CALL(*mock_app_, WindowIdExists(kTestWindowId)).WillOnce(Return(true)); + auto msg = CreateMsgParams(); + (*msg)[am::strings::msg_params][am::strings::window_id] = kTestWindowId; + + auto command = CreateCommand<DeleteWindowRequest>(msg); + EXPECT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(DeleteWindowRequestTest, + Run_AllParametersCorrectDeleteWindowForPrimaryWidget_SendMessageToHMI) { + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_DeleteWindow), + Command::CommandSource::SOURCE_SDL_TO_HMI)) + .WillOnce(Return(true)); + const auto primary_widget_window_id = + mobile_apis::PredefinedWindows::PRIMARY_WIDGET; + ON_CALL(*mock_app_, GetWindowIds()) + .WillByDefault(Return(am::WindowIds(1, primary_widget_window_id))); + EXPECT_CALL(*mock_app_, WindowIdExists(primary_widget_window_id)) + .WillOnce(Return(true)); + auto msg = CreateMsgParams(); + (*msg)[am::strings::msg_params][am::strings::window_id] = + primary_widget_window_id; + + auto command = CreateCommand<DeleteWindowRequest>(msg); + EXPECT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(DeleteWindowRequestTest, + OnEvent_InvalidFunctionId_MessageNotSendToMobile) { + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + auto msg = CreateMsgParams(); + auto command = CreateCommand<DeleteWindowRequest>(msg); + EXPECT_TRUE(command->Init()); + Event event(hmi_apis::FunctionID::INVALID_ENUM); + command->on_event(event); +} + +TEST_F(DeleteWindowRequestTest, + OnEvent_AppDoesNotExist_ExpectAppNotRegisteredResponseToMobile) { + const auto result_code = mobile_apis::Result::APPLICATION_NOT_REGISTERED; + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(CheckMessageToMobile(result_code, false), + Command::CommandSource::SOURCE_SDL)) + .WillOnce(Return(true)); + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(nullptr)); + + auto msg = CreateMsgParams(); + auto command = CreateCommand<DeleteWindowRequest>(msg); + EXPECT_TRUE(command->Init()); + Event event(hmi_apis::FunctionID::UI_DeleteWindow); + command->on_event(event); +} + +TEST_F(DeleteWindowRequestTest, + OnEvent_RequestFailedOnHMISide_SendGenericErrorResponseToMobile) { + const auto result_code = mobile_apis::Result::GENERIC_ERROR; + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(CheckMessageToMobile(result_code, false), + Command::CommandSource::SOURCE_SDL)) + .WillOnce(Return(true)); + + auto msg = CreateMsgParams(); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::GENERIC_ERROR; + + Event event(hmi_apis::FunctionID::UI_DeleteWindow); + event.set_smart_object(*msg); + + auto command = CreateCommand<DeleteWindowRequest>(msg); + EXPECT_TRUE(command->Init()); + command->on_event(event); +} + +TEST_F(DeleteWindowRequestTest, + OnEvent_AllParametersCorrect_SendSuccessResponseToMobile) { + const auto result_code = mobile_apis::Result::SUCCESS; + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(CheckMessageToMobile(result_code, true), + Command::CommandSource::SOURCE_SDL)) + .WillOnce(Return(true)); + EXPECT_CALL(*mock_app_, UpdateHash()).Times(1); + EXPECT_CALL(*mock_app_, RemoveHMIState(kTestWindowId, _)).Times(1); + + auto msg = CreateMsgParams(); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*msg)[am::strings::msg_params][am::strings::window_id] = kTestWindowId; + + Event event(hmi_apis::FunctionID::UI_DeleteWindow); + event.set_smart_object(*msg); + + auto command = CreateCommand<DeleteWindowRequest>(msg); + EXPECT_TRUE(command->Init()); + command->on_event(event); +} + +} // namespace delete_window_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/get_system_capability_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/get_system_capability_request_test.cc new file mode 100644 index 0000000000..74c61410e8 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/get_system_capability_request_test.cc @@ -0,0 +1,124 @@ +/* + 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 "mobile/get_system_capability_request.h" + +#include "application_manager/commands/command_request_test.h" +#include "gtest/gtest.h" +#include "interfaces/MOBILE_API.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace get_system_capability_request_test { + +using sdl_rpc_plugin::commands::GetSystemCapabilityRequest; +using ::testing::_; +using ::testing::Return; +typedef std::shared_ptr<GetSystemCapabilityRequest> + GetSystemCapabilityRequestPtr; + +namespace strings = application_manager::strings; +namespace { +const uint32_t kConnectionKey = 1u; +} + +class GetSystemCapabilityRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + protected: + void SetUp() OVERRIDE { + message_ = CreateMessage(); + (*message_)[strings::params][strings::connection_key] = kConnectionKey; + + command_ = CreateCommand<GetSystemCapabilityRequest>(message_); + mock_app_ = CreateMockApp(); + + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + } + + GetSystemCapabilityRequestPtr command_; + MessageSharedPtr message_; + MockAppPtr mock_app_; +}; + +TEST_F( + GetSystemCapabilityRequestTest, + Run_GetSystemDisplayCapabilities_SendMessageToMobileWithSUCCESSResultCode) { + (*message_)[strings::msg_params][strings::system_capability_type] = + mobile_apis::SystemCapabilityType::DISPLAYS; + + smart_objects::SmartObjectSPtr system_display_capabilities( + std::make_shared<smart_objects::SmartObject>()); + + ON_CALL(*mock_app_, display_capabilities()) + .WillByDefault(Return(system_display_capabilities)); + + ON_CALL(mock_hmi_capabilities_, system_display_capabilities()) + .WillByDefault(Return(system_display_capabilities)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), + Command::CommandSource::SOURCE_SDL)); + + ASSERT_TRUE(command_->Init()); + command_->Run(); +} + +TEST_F( + GetSystemCapabilityRequestTest, + Run_GetSystemDisplayCapabilities_CapabilitiesNotExistSendMessageToMobileWithDATA_NOT_AVAILABLEResultCode) { + (*message_)[strings::msg_params][strings::system_capability_type] = + mobile_apis::SystemCapabilityType::DISPLAYS; + + EXPECT_CALL(*mock_app_, display_capabilities()).WillOnce(Return(nullptr)); + + ON_CALL(mock_hmi_capabilities_, system_display_capabilities()) + .WillByDefault(Return(nullptr)); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::DATA_NOT_AVAILABLE), + Command::CommandSource::SOURCE_SDL)); + + ASSERT_TRUE(command_->Init()); + command_->Run(); +} + +} // namespace get_system_capability_request_test +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/list_files_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/list_files_request_test.cc index 8b6f6696b7..06ecc1116e 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/list_files_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/list_files_request_test.cc @@ -60,6 +60,11 @@ namespace am = ::application_manager; using am::commands::MessageSharedPtr; using sdl_rpc_plugin::commands::ListFilesRequest; +namespace { +const am::WindowID kDefaultWindowId = + mobile_apis::PredefinedWindows::DEFAULT_WINDOW; +} + class ListFilesRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { public: @@ -86,7 +91,7 @@ TEST_F(ListFilesRequestTest, Run_TooManyHmiNone_UNSUCCESS) { std::shared_ptr<ListFilesRequest> command(CreateCommand<ListFilesRequest>()); ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); - ON_CALL(*app, hmi_level()) + ON_CALL(*app, hmi_level(kDefaultWindowId)) .WillByDefault(Return(mobile_apis::HMILevel::HMI_NONE)); const uint32_t kListFilesInNoneAllowed = 1u; @@ -121,7 +126,7 @@ TEST_F(ListFilesRequestTest, Run_SUCCESS) { ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); - ON_CALL(*app, hmi_level()) + ON_CALL(*app, hmi_level(kDefaultWindowId)) .WillByDefault(Return(mobile_apis::HMILevel::HMI_FULL)); ON_CALL(*app, increment_list_files_in_none_count()).WillByDefault(Return()); 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 1f514e09c5..e4536ddeea 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 @@ -65,6 +65,8 @@ namespace { const uint32_t kAppId = 5u; const uint32_t kCustomButtonId = 3u; const mobile_apis::ButtonName::eType kButtonName = mobile_apis::ButtonName::OK; +const am::WindowID kDefaultWindowId = + mobile_apis::PredefinedWindows::DEFAULT_WINDOW; } // namespace template <class NotificationT, @@ -217,7 +219,7 @@ TYPED_TEST(OnButtonNotificationCommandsTest, Run_CustomButton_SUCCESS) { this->template CreateCommand<Notification>(notification_msg)); typename TestFixture::MockAppPtr mock_app = this->CreateMockApp(); - ON_CALL(*mock_app, hmi_level()) + 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, IsSubscribedToSoftButton(kCustomButtonId)) @@ -229,6 +231,35 @@ TYPED_TEST(OnButtonNotificationCommandsTest, Run_CustomButton_SUCCESS) { command->Run(); } +TYPED_TEST(OnButtonNotificationCommandsTest, + Run_CustomButton_SUCCESS_BACKGROUND) { + typedef typename TestFixture::Notification Notification; + + MessageSharedPtr notification_msg( + this->CreateMessage(smart_objects::SmartType_Map)); + + (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = + mobile_apis::ButtonName::CUSTOM_BUTTON; + (*notification_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; + (*notification_msg)[am::strings::msg_params] + [am::hmi_response::custom_button_id] = kCustomButtonId; + + std::shared_ptr<Notification> command( + this->template CreateCommand<Notification>(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(this->app_mngr_, application(kAppId)).WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, IsSubscribedToSoftButton(kCustomButtonId)) + .WillOnce(Return(true)); + EXPECT_CALL(this->mock_rpc_service_, + SendMessageToMobile( + CheckNotificationMessage(TestFixture::kFunctionId), _)); + + command->Run(); +} + TYPED_TEST(OnButtonNotificationCommandsTest, Run_NoSubscribedApps_UNSUCCESS) { typedef typename TestFixture::Notification Notification; @@ -264,7 +295,7 @@ TYPED_TEST(OnButtonNotificationCommandsTest, Run_InvalidHmiLevel_UNSUCCESS) { std::vector<ApplicationSharedPtr> subscribed_apps_list; subscribed_apps_list.push_back(mock_app); - EXPECT_CALL(*mock_app, hmi_level()) + EXPECT_CALL(*mock_app, hmi_level(kDefaultWindowId)) .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_NONE)); EXPECT_CALL(this->app_mngr_, applications_by_button(kButtonName)) @@ -290,7 +321,7 @@ TYPED_TEST(OnButtonNotificationCommandsTest, std::vector<ApplicationSharedPtr> subscribed_apps_list; subscribed_apps_list.push_back(mock_app); - EXPECT_CALL(*mock_app, hmi_level()) + EXPECT_CALL(*mock_app, hmi_level(kDefaultWindowId)) .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_LIMITED)); EXPECT_CALL(this->app_mngr_, applications_by_button(kButtonName)) @@ -316,10 +347,11 @@ TYPED_TEST(OnButtonNotificationCommandsTest, Run_SUCCESS) { std::vector<ApplicationSharedPtr> subscribed_apps_list; subscribed_apps_list.push_back(mock_app); - EXPECT_CALL(*mock_app, hmi_level()) + 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)); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_keyboard_input_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_keyboard_input_notification_test.cc index 501b4d8631..b7b827bb4c 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_keyboard_input_notification_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_keyboard_input_notification_test.cc @@ -48,6 +48,8 @@ namespace strings = application_manager::strings; namespace { const uint32_t kConnectionKey = 1u; +const am::WindowID kDefaultWindowId = + mobile_apis::PredefinedWindows::DEFAULT_WINDOW; } // namespace using application_manager::ApplicationSet; @@ -102,7 +104,7 @@ TEST_F(OnKeyBoardInputNotificationTest, Run_ActionActive_SUCCESS) { EXPECT_CALL(*mock_app, is_perform_interaction_active()).WillOnce(Return(1)); EXPECT_CALL(*mock_app, perform_interaction_layout()) .WillOnce(Return(mobile_apis::LayoutMode::KEYBOARD)); - EXPECT_CALL(*mock_app, hmi_level()).Times(0); + EXPECT_CALL(*mock_app, hmi_level(kDefaultWindowId)).Times(0); EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kConnectionKey)); @@ -126,7 +128,7 @@ TEST_F(OnKeyBoardInputNotificationTest, Run_ActionNotActive_SUCCESS) { EXPECT_CALL(*mock_app, is_perform_interaction_active()) .WillRepeatedly(Return(0)); - EXPECT_CALL(*mock_app, hmi_level()) + EXPECT_CALL(*mock_app, hmi_level(kDefaultWindowId)) .WillOnce(Return(mobile_apis::HMILevel::eType::HMI_FULL)); EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kConnectionKey)); @@ -151,7 +153,7 @@ TEST_F(OnKeyBoardInputNotificationTest, Run_InvalidApp_NoNotification) { EXPECT_CALL(*mock_app, is_perform_interaction_active()) .WillRepeatedly(Return(0)); - EXPECT_CALL(*mock_app, hmi_level()) + EXPECT_CALL(*mock_app, hmi_level(kDefaultWindowId)) .WillOnce(Return(mobile_apis::HMILevel::eType::HMI_BACKGROUND)); EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)).Times(0); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_system_capability_updated_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_system_capability_updated_notification_test.cc new file mode 100644 index 0000000000..349ada66a2 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_system_capability_updated_notification_test.cc @@ -0,0 +1,236 @@ +/* + * 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 "mobile/on_system_capability_updated_notification.h" + +#include "application_manager/commands/commands_test.h" +#include "application_manager/display_capabilities_builder.h" +#include "gtest/gtest.h" +#include "sdl_rpc_plugin/extensions/system_capability_app_extension.h" +#include "sdl_rpc_plugin/sdl_rpc_plugin.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace on_system_capability_updated_notification { + +using sdl_rpc_plugin::commands::mobile::OnSystemCapabilityUpdatedNotification; +using ::testing::_; +using ::testing::Return; + +typedef std::shared_ptr<OnSystemCapabilityUpdatedNotification> + OnSystemCapabilityUpdatedNotificationPtr; + +namespace strings = application_manager::strings; +namespace { +const uint32_t kConnectionKey = 1u; +const uint32_t kAppId = 2u; +} // namespace + +MATCHER_P(CheckDisplayCapabilities, display_capabilities, "") { + return *display_capabilities == + (*arg)[strings::msg_params][strings::system_capability] + [strings::display_capabilities]; +} + +class OnSystemCapabilityUpdatedNotificationTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + protected: + void SetUp() OVERRIDE { + message_ = CreateMessage(); + (*message_)[strings::params][strings::connection_key] = kConnectionKey; + + command_ = CreateCommand<OnSystemCapabilityUpdatedNotification>(message_); + mock_app_ = CreateMockApp(); + } + + OnSystemCapabilityUpdatedNotificationPtr command_; + MockAppPtr mock_app_; + MessageSharedPtr message_; +}; + +TEST_F( + OnSystemCapabilityUpdatedNotificationTest, + Run_AppExistSubscribedToNotification_SystemDisplayCapabilitiesSendToMobile) { + (*message_)[am::strings::msg_params][strings::system_capability] + [am::strings::system_capability_type] = + mobile_apis::SystemCapabilityType::DISPLAYS; + + smart_objects::SmartObjectSPtr system_display_capabilities = + std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType_Null); + + ON_CALL(mock_hmi_capabilities_, system_display_capabilities()) + .WillByDefault(Return(system_display_capabilities)); + + sdl_rpc_plugin::SDLRPCPlugin sdl_rpc_plugin; + + std::shared_ptr<sdl_rpc_plugin::SystemCapabilityAppExtension> + system_capability_app_extension( + std::make_shared<sdl_rpc_plugin::SystemCapabilityAppExtension>( + sdl_rpc_plugin, *mock_app_)); + system_capability_app_extension->SubscribeTo( + mobile_apis::SystemCapabilityType::DISPLAYS); + application_manager::ApplicationSet apps({mock_app_}); + std::shared_ptr<sync_primitives::Lock> apps_lock_( + std::make_shared<sync_primitives::Lock>()); + DataAccessor<application_manager::ApplicationSet> apps_data( + DataAccessor<application_manager::ApplicationSet>(apps, apps_lock_)); + + ON_CALL(app_mngr_, applications()).WillByDefault(Return(apps_data)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + ON_CALL(*mock_app_, display_capabilities()).WillByDefault(Return(nullptr)); + ON_CALL(*mock_app_, + QueryInterface(sdl_rpc_plugin::SystemCapabilityAppExtension:: + SystemCapabilityAppExtensionUID)) + .WillByDefault(Return(system_capability_app_extension)); + application_manager::DisplayCapabilitiesBuilder builder(*mock_app_); + ON_CALL(*mock_app_, display_capabilities_builder()) + .WillByDefault(ReturnRef(builder)); + + EXPECT_CALL( + mock_rpc_service_, + SendMessageToMobile(CheckDisplayCapabilities(system_display_capabilities), + false)); + + ASSERT_TRUE(command_->Init()); + command_->Run(); +} + +TEST_F( + OnSystemCapabilityUpdatedNotificationTest, + Run_AppExistConnectionKeyNotEqualWithAppId_SystemDisplayCapabilitiesNotSendToMobile) { + (*message_)[am::strings::msg_params][strings::system_capability] + [am::strings::system_capability_type] = + mobile_apis::SystemCapabilityType::DISPLAYS; + + smart_objects::SmartObjectSPtr system_display_capabilities = + std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType_Null); + + ON_CALL(mock_hmi_capabilities_, system_display_capabilities()) + .WillByDefault(Return(system_display_capabilities)); + + sdl_rpc_plugin::SDLRPCPlugin sdl_rpc_plugin; + + std::shared_ptr<sdl_rpc_plugin::SystemCapabilityAppExtension> + system_capability_app_extension( + std::make_shared<sdl_rpc_plugin::SystemCapabilityAppExtension>( + sdl_rpc_plugin, *mock_app_)); + system_capability_app_extension->SubscribeTo( + mobile_apis::SystemCapabilityType::DISPLAYS); + application_manager::ApplicationSet apps({mock_app_}); + std::shared_ptr<sync_primitives::Lock> apps_lock_( + std::make_shared<sync_primitives::Lock>()); + DataAccessor<application_manager::ApplicationSet> apps_data( + DataAccessor<application_manager::ApplicationSet>(apps, apps_lock_)); + + ON_CALL(app_mngr_, applications()).WillByDefault(Return(apps_data)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kAppId)); + ON_CALL(*mock_app_, display_capabilities()).WillByDefault(Return(nullptr)); + ON_CALL(*mock_app_, + QueryInterface(sdl_rpc_plugin::SystemCapabilityAppExtension:: + SystemCapabilityAppExtensionUID)) + .WillByDefault(Return(system_capability_app_extension)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(_, _)).Times(0); + + ASSERT_TRUE(command_->Init()); + command_->Run(); +} + +TEST_F( + OnSystemCapabilityUpdatedNotificationTest, + Run_AppExistNotSubscribedToNotification_SystemDisplayCapabilitiesNotSendToMobile) { + (*message_)[am::strings::msg_params][strings::system_capability] + [am::strings::system_capability_type] = + mobile_apis::SystemCapabilityType::DISPLAYS; + + smart_objects::SmartObjectSPtr system_display_capabilities = + std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType_Null); + + ON_CALL(mock_hmi_capabilities_, system_display_capabilities()) + .WillByDefault(Return(system_display_capabilities)); + + sdl_rpc_plugin::SDLRPCPlugin sdl_rpc_plugin; + + std::shared_ptr<sdl_rpc_plugin::SystemCapabilityAppExtension> + system_capability_app_extension( + std::make_shared<sdl_rpc_plugin::SystemCapabilityAppExtension>( + sdl_rpc_plugin, *mock_app_)); + + application_manager::ApplicationSet apps({mock_app_}); + std::shared_ptr<sync_primitives::Lock> apps_lock_( + std::make_shared<sync_primitives::Lock>()); + DataAccessor<application_manager::ApplicationSet> apps_data( + DataAccessor<application_manager::ApplicationSet>(apps, apps_lock_)); + + ON_CALL(app_mngr_, applications()).WillByDefault(Return(apps_data)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + ON_CALL(*mock_app_, display_capabilities()).WillByDefault(Return(nullptr)); + ON_CALL(*mock_app_, + QueryInterface(sdl_rpc_plugin::SystemCapabilityAppExtension:: + SystemCapabilityAppExtensionUID)) + .WillByDefault(Return(system_capability_app_extension)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(_, _)).Times(0); + + ASSERT_TRUE(command_->Init()); + command_->Run(); +} + +TEST_F( + OnSystemCapabilityUpdatedNotificationTest, + Run_AppDataEmpty_SystemDisplayCapabilitiesUpdatedNotificationNotSendToMobile) { + (*message_)[am::strings::msg_params][strings::system_capability] + [am::strings::system_capability_type] = + mobile_apis::SystemCapabilityType::DISPLAYS; + application_manager::ApplicationSet apps; + std::shared_ptr<sync_primitives::Lock> apps_lock_( + std::make_shared<sync_primitives::Lock>()); + DataAccessor<application_manager::ApplicationSet> apps_data( + DataAccessor<application_manager::ApplicationSet>(apps, apps_lock_)); + + ON_CALL(app_mngr_, applications()).WillByDefault(Return(apps_data)); + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(_, _)).Times(0); + + ASSERT_TRUE(command_->Init()); + command_->Run(); +} + +} // namespace on_system_capability_updated_notification +} // namespace mobile_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_system_request_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_system_request_notification_test.cc index 69ed8fb311..ffa7203f1f 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_system_request_notification_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_system_request_notification_test.cc @@ -62,6 +62,7 @@ using testing::SaveArg; namespace { const uint32_t kConnectionKey = 1u; const std::string kPolicyAppId = "fake-app-id"; +const connection_handler::DeviceHandle kDeviceId = 1u; } // namespace class OnSystemRequestNotificationTest @@ -73,6 +74,7 @@ class OnSystemRequestNotificationTest ON_CALL(app_mngr_, application(kConnectionKey)) .WillByDefault(Return(mock_app_)); ON_CALL(*mock_app_, policy_app_id()).WillByDefault(Return(kPolicyAppId)); + ON_CALL(*mock_app_, device()).WillByDefault(Return(kDeviceId)); } protected: @@ -90,12 +92,14 @@ TEST_F(OnSystemRequestNotificationTest, Run_ProprietaryType_SUCCESS) { std::shared_ptr<OnSystemRequestNotification> command = CreateCommand<OnSystemRequestNotification>(msg); + PreConditions(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillRepeatedly(Return(mock_app_)); EXPECT_CALL(*mock_app_, policy_app_id()).WillOnce(Return(kPolicyAppId)); EXPECT_CALL(mock_policy_handler_, - IsRequestTypeAllowed(kPolicyAppId, request_type)) + IsRequestTypeAllowed(kDeviceId, kPolicyAppId, request_type)) .WillRepeatedly(Return(true)); #ifdef PROPRIETARY_MODE @@ -130,10 +134,13 @@ TEST_F(OnSystemRequestNotificationTest, Run_HTTPType_SUCCESS) { std::shared_ptr<OnSystemRequestNotification> command = CreateCommand<OnSystemRequestNotification>(msg); + PreConditions(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillOnce(Return(mock_app_)); EXPECT_CALL(*mock_app_, policy_app_id()).WillOnce(Return(kPolicyAppId)); - EXPECT_CALL(mock_policy_handler_, IsRequestTypeAllowed(_, _)) + EXPECT_CALL(mock_policy_handler_, + IsRequestTypeAllowed(kDeviceId, kPolicyAppId, request_type)) .WillOnce(Return(true)); EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)) @@ -167,7 +174,7 @@ TEST_F(OnSystemRequestNotificationTest, Run_InvalidApp_NoNotification) { EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillOnce(Return(MockAppPtr())); EXPECT_CALL(*mock_app_, policy_app_id()).Times(0); - EXPECT_CALL(mock_policy_handler_, IsRequestTypeAllowed(_, _)).Times(0); + EXPECT_CALL(mock_policy_handler_, IsRequestTypeAllowed(_, _, _)).Times(0); EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)).Times(0); @@ -187,10 +194,13 @@ TEST_F(OnSystemRequestNotificationTest, Run_RequestNotAllowed_NoNotification) { std::shared_ptr<OnSystemRequestNotification> command = CreateCommand<OnSystemRequestNotification>(msg); + PreConditions(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillOnce(Return(mock_app_)); EXPECT_CALL(*mock_app_, policy_app_id()).WillOnce(Return(kPolicyAppId)); - EXPECT_CALL(mock_policy_handler_, IsRequestTypeAllowed(_, _)) + EXPECT_CALL(mock_policy_handler_, + IsRequestTypeAllowed(kDeviceId, kPolicyAppId, request_type)) .WillOnce(Return(false)); EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)).Times(0); @@ -214,7 +224,7 @@ TEST_F( PreConditions(); EXPECT_CALL(mock_policy_handler_, - IsRequestTypeAllowed(kPolicyAppId, request_type)) + IsRequestTypeAllowed(kDeviceId, kPolicyAppId, request_type)) .WillOnce(Return(true)); EXPECT_CALL(mock_policy_handler_, IsRequestSubTypeAllowed(kPolicyAppId, request_subtype)) @@ -241,7 +251,7 @@ TEST_F(OnSystemRequestNotificationTest, PreConditions(); EXPECT_CALL(mock_policy_handler_, - IsRequestTypeAllowed(kPolicyAppId, request_type)) + IsRequestTypeAllowed(kDeviceId, kPolicyAppId, request_type)) .WillOnce(Return(true)); EXPECT_CALL(mock_policy_handler_, IsRequestSubTypeAllowed(kPolicyAppId, request_subtype)) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_tbt_client_state_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_tbt_client_state_notification_test.cc index f1e1a291d3..c43dea76e1 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_tbt_client_state_notification_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_tbt_client_state_notification_test.cc @@ -60,6 +60,8 @@ typedef std::shared_ptr<OnTBTClientStateNotification> NotificationPtr; namespace { const uint32_t kAppId = 1u; +const am::WindowID kDefaultWindowId = + mobile_apis::PredefinedWindows::DEFAULT_WINDOW; } // namespace class OnTBTClientStateNotificationTest @@ -79,7 +81,7 @@ TEST_F(OnTBTClientStateNotificationTest, Run_HmiLevelNone_UNSUCCESS) { EXPECT_CALL(app_mngr_, applications_with_navi()) .WillOnce(Return(applications_with_navi)); - EXPECT_CALL(*mock_app, hmi_level()) + EXPECT_CALL(*mock_app, hmi_level(kDefaultWindowId)) .WillOnce(Return(mobile_apis::HMILevel::HMI_NONE)); EXPECT_CALL(*mock_app, app_id()).Times(0); @@ -122,7 +124,7 @@ TEST_F(OnTBTClientStateNotificationTest, EXPECT_CALL(app_mngr_, applications_with_navi()) .WillOnce(Return(applications_with_navi)); - EXPECT_CALL(*mock_app, hmi_level()) + EXPECT_CALL(*mock_app, hmi_level(kDefaultWindowId)) .WillOnce(Return(mobile_apis::HMILevel::HMI_FULL)); EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kAppId)); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_way_point_change_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_way_point_change_notification_test.cc index 83958954cd..ec401ae2a8 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_way_point_change_notification_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_way_point_change_notification_test.cc @@ -59,19 +59,40 @@ using sdl_rpc_plugin::commands::OnWayPointChangeNotification; typedef std::shared_ptr<OnWayPointChangeNotification> NotificationPtr; namespace { -const uint32_t kAppId = 1u; +const uint32_t kApp1Id = 1u; +const uint32_t kApp2Id = 2u; } // namespace class OnWayPointChangeNotificationTest : public CommandsTest<CommandsTestMocks::kIsNice> { public: - OnWayPointChangeNotificationTest() - : command_(CreateCommand<OnWayPointChangeNotification>()) {} + OnWayPointChangeNotificationTest() {} + + void SetUp() OVERRIDE { + command_ = CreateCommand(); + } + + std::shared_ptr<OnWayPointChangeNotification> CreateCommand() { + InitCommand(CommandsTest<CommandsTestMocks::kIsNice>::kDefaultTimeout_); + message_ = CreateMessage(); + return std::make_shared<OnWayPointChangeNotification>( + message_, + app_mngr_, + mock_rpc_service_, + mock_hmi_capabilities_, + mock_policy_handler_); + } + + MessageSharedPtr CreateMessage( + const smart_objects::SmartType type = smart_objects::SmartType_Null) { + return std::make_shared<SmartObject>(type); + } NotificationPtr command_; + MessageSharedPtr message_; }; -MATCHER(CheckMessageData, "") { +MATCHER_P(CheckMessageData, appID, "") { const bool kIsMobileProtocolTypeCorrect = (*arg)[am::strings::params][am::strings::protocol_type].asInt() == am::commands::CommandImpl::mobile_protocol_type_; @@ -86,7 +107,7 @@ MATCHER(CheckMessageData, "") { const bool kIsConnectionKeyCorrect = (*arg)[am::strings::params][am::strings::connection_key].asUInt() == - kAppId; + appID; using namespace helpers; return Compare<bool, EQ, ALL>(true, @@ -99,11 +120,42 @@ MATCHER(CheckMessageData, "") { TEST_F(OnWayPointChangeNotificationTest, Run_NotEmptyListOfAppsSubscribedForWayPoints_SUCCESS) { std::set<uint32_t> apps_subscribed_for_way_points; - apps_subscribed_for_way_points.insert(kAppId); + apps_subscribed_for_way_points.insert(kApp1Id); EXPECT_CALL(app_mngr_, GetAppsSubscribedForWayPoints()) .WillOnce(Return(apps_subscribed_for_way_points)); - EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(CheckMessageData(), _)); + EXPECT_CALL(mock_rpc_service_, + SendMessageToMobile(CheckMessageData(kApp1Id), _)); + + command_->Run(); +} + +TEST_F(OnWayPointChangeNotificationTest, + Run_StoreWayPointsDuringNotification_SUCCESS) { + std::set<uint32_t> apps_subscribed_for_way_points; + apps_subscribed_for_way_points.insert(kApp1Id); + + EXPECT_CALL(app_mngr_, GetAppsSubscribedForWayPoints()) + .WillOnce(Return(apps_subscribed_for_way_points)); + EXPECT_CALL(mock_rpc_service_, + SendMessageToMobile(CheckMessageData(kApp1Id), _)); + EXPECT_CALL(app_mngr_, SaveWayPointsMessage(message_)); + + command_->Run(); +} + +TEST_F(OnWayPointChangeNotificationTest, + Run_BroadcastingWayPointsToAllApps_SUCCESS) { + std::set<uint32_t> apps_subscribed_for_way_points; + apps_subscribed_for_way_points.insert(kApp1Id); + apps_subscribed_for_way_points.insert(kApp2Id); + + EXPECT_CALL(app_mngr_, GetAppsSubscribedForWayPoints()) + .WillOnce(Return(apps_subscribed_for_way_points)); + EXPECT_CALL(mock_rpc_service_, + SendMessageToMobile(CheckMessageData(kApp1Id), _)); + EXPECT_CALL(mock_rpc_service_, + SendMessageToMobile(CheckMessageData(kApp2Id), _)); command_->Run(); } 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 b0df0e57d3..2915418d43 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 @@ -72,6 +72,8 @@ const std::string kCorrectDisplayText1 = "CorrectDisplayText1"; const std::string kCorrectDisplayText2 = "CorrectDisplayText2"; const std::string kFunctionId = "FunctionId"; const uint32_t kTimeoutForTTSSpeak = 1u; +const am::WindowID kDefaultWindowId = + mobile_apis::PredefinedWindows::DEFAULT_WINDOW; } // namespace class PerformAudioPassThruRequestTest @@ -109,7 +111,7 @@ class PerformAudioPassThruRequestTest msg_params_[field] = "prompt\\n"; } - EXPECT_CALL(*application_sptr_, hmi_level()) + EXPECT_CALL(*application_sptr_, hmi_level(kDefaultWindowId)) .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); CallRun caller(*command_sptr_); @@ -206,7 +208,7 @@ TEST_F(PerformAudioPassThruRequestTest, (*mobile_request)[am::strings::msg_params][am::strings::initial_prompt] = initial_prompt; - EXPECT_CALL(*application_sptr_, hmi_level()) + EXPECT_CALL(*application_sptr_, hmi_level(kDefaultWindowId)) .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); std::shared_ptr<PerformAudioPassThruRequest> command = CreateCommand<PerformAudioPassThruRequest>(mobile_request); @@ -286,7 +288,7 @@ TEST_F(PerformAudioPassThruRequestTest, } TEST_F(PerformAudioPassThruRequestTest, Run_HmiLevelNone_Rejected) { - EXPECT_CALL(*application_sptr_, hmi_level()) + EXPECT_CALL(*application_sptr_, hmi_level(kDefaultWindowId)) .WillOnce(Return(am::mobile_api::HMILevel::HMI_NONE)); CallRun caller(*command_sptr_); @@ -319,7 +321,7 @@ TEST_F(PerformAudioPassThruRequestTest, // First we need to call SendSpeakRequest() // to enable the "is_active_tts_speak" key - EXPECT_CALL(*application_sptr_, hmi_level()) + EXPECT_CALL(*application_sptr_, hmi_level(kDefaultWindowId)) .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); msg_params_[am::strings::initial_prompt][0][am::strings::text] = @@ -407,7 +409,7 @@ TEST_F(PerformAudioPassThruRequestTest, TEST_F(PerformAudioPassThruRequestTest, Run_InitPromptCorrect_SpeakAndPerformAPTRequestsSendMuteTrue) { - EXPECT_CALL(*application_sptr_, hmi_level()) + EXPECT_CALL(*application_sptr_, hmi_level(kDefaultWindowId)) .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); msg_params_[am::strings::initial_prompt][0][am::strings::text] = @@ -481,7 +483,7 @@ TEST_F(PerformAudioPassThruRequestTest, TEST_F(PerformAudioPassThruRequestTest, Run_InitPromptCorrect_SpeakAndPerformAPTRequestsSendMuteFalse) { - EXPECT_CALL(*application_sptr_, hmi_level()) + EXPECT_CALL(*application_sptr_, hmi_level(kDefaultWindowId)) .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); msg_params_[am::strings::initial_prompt][0][am::strings::text] = @@ -536,7 +538,7 @@ TEST_F(PerformAudioPassThruRequestTest, TEST_F( PerformAudioPassThruRequestTest, Run_InitPromptEmpty_PerformAndRecordStartNotificationsAndStartRecording) { - EXPECT_CALL(*application_sptr_, hmi_level()) + EXPECT_CALL(*application_sptr_, hmi_level(kDefaultWindowId)) .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); MessageSharedPtr start_record_result_msg; @@ -766,7 +768,7 @@ TEST_F(PerformAudioPassThruRequestTest, EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(true)); EXPECT_CALL(app_mngr_, StopAudioPassThru(_)); - EXPECT_CALL(*application_sptr_, hmi_level()) + EXPECT_CALL(*application_sptr_, hmi_level(kDefaultWindowId)) .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); msg_params_[am::strings::initial_prompt][0][am::strings::text] = diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/perform_interaction_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/perform_interaction_test.cc index f1f7c4c907..193229eeb0 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/perform_interaction_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/perform_interaction_test.cc @@ -70,35 +70,107 @@ namespace strings = ::application_manager::strings; namespace hmi_response = ::application_manager::hmi_response; namespace { +const int32_t kCorrelationId = 1u; const int32_t kCommandId = 1; const uint32_t kCmdId = 1u; const uint32_t kConnectionKey = 2u; +const int32_t kUiChoiceID = 1u; +const int32_t kVrChoiceID = 2u; +const int32_t kInvalidChoiceId = -1; } // namespace class PerformInteractionRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { public: - PerformInteractionRequestTest() : mock_app_(CreateMockApp()) {} + PerformInteractionRequestTest() + : mock_app_(CreateMockApp()) + , performinteraction_choice_set_lock_ptr_( + std::make_shared<sync_primitives::RecursiveLock>()) {} void SetUp() OVERRIDE { + smart_objects::SmartObject choice_set1( + smart_objects::SmartType::SmartType_Map); + smart_objects::SmartObject choice_set2( + smart_objects::SmartType::SmartType_Map); + + choice_set1[strings::choice_set] = + smart_objects::SmartType::SmartType_Array; + choice_set2[strings::choice_set] = + smart_objects::SmartType::SmartType_Array; + + choice_set1[strings::choice_set][0][strings::choice_id] = kUiChoiceID; + choice_set2[strings::choice_set][0][strings::choice_id] = kVrChoiceID; + + choice_set_map_[kCorrelationId].insert(std::make_pair( + kUiChoiceID, new smart_objects::SmartObject(choice_set1))); + choice_set_map_[kCorrelationId].insert(std::make_pair( + kVrChoiceID, new smart_objects::SmartObject(choice_set2))); + ON_CALL(app_mngr_, application(kConnectionKey)) .WillByDefault(Return(mock_app_)); ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + ON_CALL(*mock_app_, performinteraction_choice_set_map()) + .WillByDefault(Return(DataAccessor<app_mngr::PerformChoiceSetMap>( + choice_set_map_, performinteraction_choice_set_lock_ptr_))); } void ResultCommandExpectations(MessageSharedPtr msg, + bool success, + hmi_apis::Common_Result::eType result_code, const std::string& info) { - EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), - true); + EXPECT_EQ((*msg)[strings::msg_params][strings::success].asBool(), success); + EXPECT_EQ((*msg)[strings::msg_params][strings::result_code].asInt(), + static_cast<int32_t>(result_code)); + EXPECT_EQ((*msg)[strings::msg_params][strings::info].asString(), info); + } + + void HMIRequestExpectations(MessageSharedPtr msg, + hmi_apis::FunctionID::eType function_id, + const std::string& method_name) { + EXPECT_EQ((*msg)[strings::params][strings::function_id].asInt(), + static_cast<int32_t>(function_id)); EXPECT_EQ( - (*msg)[am::strings::msg_params][am::strings::result_code].asInt(), - static_cast<int32_t>(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); - EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::info].asString(), - info); + (*msg)[strings::msg_params][am::hmi_request::method_name].asString(), + method_name); + } + + MessageSharedPtr CreateRequestMessage( + const mobile_apis::InteractionMode::eType& interaction_mode) { + MessageSharedPtr request_msg = CreateMessage(smart_objects::SmartType_Map); + (*request_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*request_msg)[strings::params][strings::correlation_id] = kCorrelationId; + (*request_msg)[strings::msg_params][strings::interaction_mode] = + interaction_mode; + return request_msg; + } + + MessageSharedPtr CreateHMIResponseMessage( + const hmi_apis::Common_Result::eType& response_code, + const std::string& message_info, + const int32_t command_id = kCommandId) { + MessageSharedPtr response_msg = CreateMessage(smart_objects::SmartType_Map); + (*response_msg)[strings::params][hmi_response::code] = response_code; + (*response_msg)[strings::msg_params][strings::cmd_id] = command_id; + (*response_msg)[strings::msg_params][strings::info] = message_info; + return response_msg; + } + + MessageSharedPtr CreateHMIResponseMessageWithChoiceID( + const hmi_apis::Common_Result::eType& response_code, + const std::string& message_info, + const int32_t choice_id, + const int32_t command_id = kCommandId) { + MessageSharedPtr response_msg = + CreateHMIResponseMessage(response_code, message_info, kCommandId); + (*response_msg)[strings::msg_params][strings::choice_id] = choice_id; + return response_msg; } sync_primitives::Lock lock_; MockAppPtr mock_app_; + app_mngr::PerformChoiceSetMap choice_set_map_; + mutable std::shared_ptr<sync_primitives::RecursiveLock> + performinteraction_choice_set_lock_ptr_; }; TEST_F(PerformInteractionRequestTest, OnTimeout_VR_GENERIC_ERROR) { @@ -147,35 +219,101 @@ TEST_F(PerformInteractionRequestTest, OnTimeout_VR_GENERIC_ERROR) { } TEST_F(PerformInteractionRequestTest, + OnEvent_BOTHMode_UIChoiceIdReceivedFirst) { + MessageSharedPtr msg_from_mobile = + CreateRequestMessage(mobile_apis::InteractionMode::BOTH); + std::shared_ptr<PerformInteractionRequest> command = + CreateCommand<PerformInteractionRequest>(msg_from_mobile); + + ASSERT_TRUE(command->Init()); + + MessageSharedPtr response_msg_vr = CreateHMIResponseMessage( + hmi_apis::Common_Result::SUCCESS, "", kInvalidChoiceId); + am::event_engine::Event event_vr(hmi_apis::FunctionID::VR_PerformInteraction); + event_vr.set_smart_object(*response_msg_vr); + + MessageSharedPtr response_msg_ui = CreateHMIResponseMessageWithChoiceID( + hmi_apis::Common_Result::SUCCESS, "", kUiChoiceID); + am::event_engine::Event event_ui(hmi_apis::FunctionID::UI_PerformInteraction); + event_ui.set_smart_object(*response_msg_ui); + + MessageSharedPtr response_to_mobile; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + command->on_event(event_ui); + command->on_event(event_vr); + + EXPECT_EQ( + kUiChoiceID, + (*response_to_mobile)[strings::msg_params][strings::choice_id].asInt()); +} + +TEST_F(PerformInteractionRequestTest, + OnEvent_BOTHMode_VRChoiceIdReceivedFirst) { + MessageSharedPtr msg_from_mobile = + CreateRequestMessage(mobile_apis::InteractionMode::BOTH); + std::shared_ptr<PerformInteractionRequest> command = + CreateCommand<PerformInteractionRequest>(msg_from_mobile); + + ASSERT_TRUE(command->Init()); + + MessageSharedPtr response_msg_vr = CreateHMIResponseMessageWithChoiceID( + hmi_apis::Common_Result::SUCCESS, "", kVrChoiceID); + MessageSharedPtr response_msg_ui = CreateHMIResponseMessageWithChoiceID( + hmi_apis::Common_Result::SUCCESS, "", kInvalidChoiceId); + + am::event_engine::Event event_vr(hmi_apis::FunctionID::VR_PerformInteraction); + event_vr.set_smart_object(*response_msg_vr); + + am::event_engine::Event event_ui(hmi_apis::FunctionID::UI_PerformInteraction); + event_ui.set_smart_object(*response_msg_ui); + + MessageSharedPtr request_to_hmi; + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + _, am::commands::Command::CommandSource::SOURCE_SDL_TO_HMI)) + .WillOnce(DoAll(SaveArg<0>(&request_to_hmi), Return(true))); + + command->on_event(event_vr); + EXPECT_EQ(hmi_apis::FunctionID::UI_ClosePopUp, + (*request_to_hmi)[strings::params][strings::function_id].asInt()); + + MessageSharedPtr response_to_mobile; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + command->on_event(event_ui); + + EXPECT_EQ( + kVrChoiceID, + (*response_to_mobile)[strings::msg_params][strings::choice_id].asInt()); +} + +TEST_F(PerformInteractionRequestTest, OnEvent_VRHmiSendSuccess_UNSUPPORTED_RESOURCE) { MessageSharedPtr msg_from_mobile = - CreateMessage(smart_objects::SmartType_Map); - (*msg_from_mobile)[strings::params][strings::connection_key] = kConnectionKey; - (*msg_from_mobile)[strings::msg_params][strings::interaction_mode] = - mobile_apis::InteractionMode::VR_ONLY; + CreateRequestMessage(mobile_apis::InteractionMode::VR_ONLY); std::shared_ptr<PerformInteractionRequest> command = CreateCommand<PerformInteractionRequest>(msg_from_mobile); - command->Init(); + + ASSERT_TRUE(command->Init()); MockAppPtr mock_app; EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(mock_app)); MessageSharedPtr response_msg_vr = - CreateMessage(smart_objects::SmartType_Map); - (*response_msg_vr)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*response_msg_vr)[strings::msg_params][strings::cmd_id] = kCommandId; - (*response_msg_vr)[am::strings::msg_params][am::strings::info] = - "VR is not supported by system"; - + CreateHMIResponseMessage(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + "VR is not supported by system"); am::event_engine::Event event_vr(hmi_apis::FunctionID::VR_PerformInteraction); event_vr.set_smart_object(*response_msg_vr); MessageSharedPtr response_msg_ui = - CreateMessage(smart_objects::SmartType_Map); - (*response_msg_ui)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - + CreateHMIResponseMessage(hmi_apis::Common_Result::SUCCESS, ""); am::event_engine::Event event_ui(hmi_apis::FunctionID::UI_PerformInteraction); event_ui.set_smart_object(*response_msg_ui); @@ -197,61 +335,331 @@ TEST_F(PerformInteractionRequestTest, command->on_event(event_ui); ResultCommandExpectations(response_to_mobile, + false, + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, "VR is not supported by system"); } TEST_F(PerformInteractionRequestTest, OnEvent_UIHmiSendSuccess_UNSUPPORTED_RESOURCE) { MessageSharedPtr msg_from_mobile = - CreateMessage(smart_objects::SmartType_Map); - (*msg_from_mobile)[strings::params][strings::connection_key] = kConnectionKey; - (*msg_from_mobile)[strings::msg_params][strings::interaction_mode] = - mobile_apis::InteractionMode::VR_ONLY; + CreateRequestMessage(mobile_apis::InteractionMode::VR_ONLY); std::shared_ptr<PerformInteractionRequest> command = CreateCommand<PerformInteractionRequest>(msg_from_mobile); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + ASSERT_TRUE(command->Init()); + + MockAppPtr mock_app; + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(mock_app)); + + MessageSharedPtr response_msg_vr = + CreateHMIResponseMessage(hmi_apis::Common_Result::SUCCESS, ""); + am::event_engine::Event event_vr(hmi_apis::FunctionID::VR_PerformInteraction); + event_vr.set_smart_object(*response_msg_vr); + + MessageSharedPtr response_msg_ui = + CreateHMIResponseMessage(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + "UI is not supported by system"); + am::event_engine::Event event_ui(hmi_apis::FunctionID::UI_PerformInteraction); + event_ui.set_smart_object(*response_msg_ui); + + MessageSharedPtr response_to_mobile; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + command->on_event(event_vr); + command->on_event(event_ui); + + ResultCommandExpectations(response_to_mobile, + true, + hmi_apis::Common_Result::SUCCESS, + "UI is not supported by system"); +} + +TEST_F( + PerformInteractionRequestTest, + PrepareResultCodeAndResponseForMobile_GetVRResultCodeOnly_InVR_OnlyMode_SUCCESS) { + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + + MessageSharedPtr msg_from_mobile = + CreateRequestMessage(mobile_apis::InteractionMode::VR_ONLY); + std::shared_ptr<PerformInteractionRequest> command = + CreateCommand<PerformInteractionRequest>(msg_from_mobile); + + ASSERT_TRUE(command->Init()); + + MockAppPtr mock_app; + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(mock_app)); + + MessageSharedPtr response_msg_vr = + CreateHMIResponseMessage(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + "VR is not supported by system"); + am::event_engine::Event event_vr(hmi_apis::FunctionID::VR_PerformInteraction); + event_vr.set_smart_object(*response_msg_vr); + + MessageSharedPtr response_msg_ui = + CreateHMIResponseMessage(hmi_apis::Common_Result::SUCCESS, ""); + am::event_engine::Event event_ui(hmi_apis::FunctionID::UI_PerformInteraction); + event_ui.set_smart_object(*response_msg_ui); + + MessageSharedPtr response_to_mobile; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + command->on_event(event_vr); + command->on_event(event_ui); + + ResultCommandExpectations(response_to_mobile, + false, + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + "VR is not supported by system"); +} + +TEST_F( + PerformInteractionRequestTest, + PrepareResultCodeAndResponseForMobile_GetVR_ErrorInfoAndCode_InBOTH_Mode_With_UI_success_result_code) { + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + auto msg_from_mobile = + CreateRequestMessage(mobile_apis::InteractionMode::BOTH); + std::shared_ptr<PerformInteractionRequest> command = + CreateCommand<PerformInteractionRequest>(msg_from_mobile); + + ASSERT_TRUE(command->Init()); + MessageSharedPtr response_msg_vr = - CreateMessage(smart_objects::SmartType_Map); - (*response_msg_vr)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; + CreateHMIResponseMessage(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + "VR is not supported by system"); am::event_engine::Event event_vr(hmi_apis::FunctionID::VR_PerformInteraction); event_vr.set_smart_object(*response_msg_vr); MessageSharedPtr response_msg_ui = - CreateMessage(smart_objects::SmartType_Map); - (*response_msg_ui)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*response_msg_ui)[strings::msg_params][strings::cmd_id] = kCommandId; - (*response_msg_ui)[am::strings::msg_params][am::strings::info] = - "UI is not supported by system"; + CreateHMIResponseMessage(hmi_apis::Common_Result::SUCCESS, ""); + am::event_engine::Event event_ui(hmi_apis::FunctionID::UI_PerformInteraction); + event_ui.set_smart_object(*response_msg_ui); + + MessageSharedPtr response_to_mobile; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + MessageSharedPtr request_to_hmi; + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + _, am::commands::Command::CommandSource::SOURCE_SDL_TO_HMI)) + .WillOnce(DoAll(SaveArg<0>(&request_to_hmi), Return(true))); + + command->on_event(event_vr); + command->on_event(event_ui); + + HMIRequestExpectations(request_to_hmi, + hmi_apis::FunctionID::UI_ClosePopUp, + "UI.PerformInteraction"); + + ResultCommandExpectations(response_to_mobile, + true, + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + "VR is not supported by system"); +} +TEST_F( + PerformInteractionRequestTest, + PrepareResultCodeAndResponseForMobile_Send_GENERIC_ERROR_To_Mobile_When_different_valid_choice_ids_received_in_BOTH_mode_SUCCESS) { + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + MessageSharedPtr msg_from_mobile = + CreateRequestMessage(mobile_apis::InteractionMode::BOTH); + std::shared_ptr<PerformInteractionRequest> command = + CreateCommand<PerformInteractionRequest>(msg_from_mobile); + + ASSERT_TRUE(command->Init()); + + MessageSharedPtr response_msg_vr = CreateHMIResponseMessageWithChoiceID( + hmi_apis::Common_Result::SUCCESS, "", kVrChoiceID); + MessageSharedPtr response_msg_ui = CreateHMIResponseMessageWithChoiceID( + hmi_apis::Common_Result::SUCCESS, "", kUiChoiceID); + + am::event_engine::Event event_vr(hmi_apis::FunctionID::VR_PerformInteraction); + event_vr.set_smart_object(*response_msg_vr); am::event_engine::Event event_ui(hmi_apis::FunctionID::UI_PerformInteraction); event_ui.set_smart_object(*response_msg_ui); MessageSharedPtr response_to_mobile; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + MessageSharedPtr request_to_hmi; + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + _, am::commands::Command::CommandSource::SOURCE_SDL_TO_HMI)) + .WillOnce(DoAll(SaveArg<0>(&request_to_hmi), Return(true))); + command->on_event(event_vr); + command->on_event(event_ui); + + HMIRequestExpectations(request_to_hmi, + hmi_apis::FunctionID::UI_ClosePopUp, + "UI.PerformInteraction"); + + ResultCommandExpectations(response_to_mobile, + false, + hmi_apis::Common_Result::GENERIC_ERROR, + "Received two different choice IDs"); +} + +TEST_F( + PerformInteractionRequestTest, + VR_response_WARNINGS_UI_response_SUCCESS_MobileResponseContains_true_WARNINGS_warnings_info) { + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + auto msg_from_mobile = + CreateRequestMessage(mobile_apis::InteractionMode::VR_ONLY); + std::shared_ptr<PerformInteractionRequest> command = + CreateCommand<PerformInteractionRequest>(msg_from_mobile); + + ASSERT_TRUE(command->Init()); + + MessageSharedPtr response_msg_vr = CreateHMIResponseMessage( + hmi_apis::Common_Result::WARNINGS, "WARNING MESSAGE"); + am::event_engine::Event event_vr(hmi_apis::FunctionID::VR_PerformInteraction); + event_vr.set_smart_object(*response_msg_vr); + + MessageSharedPtr response_msg_ui = + CreateHMIResponseMessage(hmi_apis::Common_Result::SUCCESS, ""); + am::event_engine::Event event_ui(hmi_apis::FunctionID::UI_PerformInteraction); + event_ui.set_smart_object(*response_msg_ui); + + MessageSharedPtr response_to_mobile; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + MessageSharedPtr request_to_hmi; + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + _, am::commands::Command::CommandSource::SOURCE_SDL_TO_HMI)) + .WillOnce(DoAll(SaveArg<0>(&request_to_hmi), Return(true))); + + command->on_event(event_vr); + command->on_event(event_ui); + + HMIRequestExpectations(request_to_hmi, + hmi_apis::FunctionID::UI_ClosePopUp, + "UI.PerformInteraction"); + + ResultCommandExpectations(response_to_mobile, + true, + hmi_apis::Common_Result::WARNINGS, + "WARNING MESSAGE"); +} + +TEST_F( + PerformInteractionRequestTest, + VR_response_SUCCESS_UI_response_WARNINGS_MobileResponseContains_true_WARNINGS_warnings_info) { + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + auto msg_from_mobile = + CreateRequestMessage(mobile_apis::InteractionMode::BOTH); + std::shared_ptr<PerformInteractionRequest> command = + CreateCommand<PerformInteractionRequest>(msg_from_mobile); + + ASSERT_TRUE(command->Init()); + + MessageSharedPtr response_msg_vr = + CreateHMIResponseMessage(hmi_apis::Common_Result::SUCCESS, ""); + am::event_engine::Event event_vr(hmi_apis::FunctionID::VR_PerformInteraction); + event_vr.set_smart_object(*response_msg_vr); + + MessageSharedPtr response_msg_ui = CreateHMIResponseMessage( + hmi_apis::Common_Result::WARNINGS, "WARNING MESSAGE"); + am::event_engine::Event event_ui(hmi_apis::FunctionID::UI_PerformInteraction); + event_ui.set_smart_object(*response_msg_ui); + + MessageSharedPtr response_to_mobile; EXPECT_CALL( mock_rpc_service_, ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + MessageSharedPtr request_to_hmi; + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + _, am::commands::Command::CommandSource::SOURCE_SDL_TO_HMI)) + .WillOnce(DoAll(SaveArg<0>(&request_to_hmi), Return(true))); + command->on_event(event_vr); + command->on_event(event_ui); + + HMIRequestExpectations(request_to_hmi, + hmi_apis::FunctionID::UI_ClosePopUp, + "UI.PerformInteraction"); + + ResultCommandExpectations(response_to_mobile, + true, + hmi_apis::Common_Result::WARNINGS, + "WARNING MESSAGE"); +} + +TEST_F( + PerformInteractionRequestTest, + VR_response_UNSUPPORTED_RESOURCE_UI_response_WARNINGS_MobileResponseContains_false_UNSUPPORTED_RESOURSE_error_info) { + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + auto msg_from_mobile = + CreateRequestMessage(mobile_apis::InteractionMode::BOTH); + std::shared_ptr<PerformInteractionRequest> command = + CreateCommand<PerformInteractionRequest>(msg_from_mobile); + + ASSERT_TRUE(command->Init()); - EXPECT_CALL(*mock_app_, is_perform_interaction_active()) - .WillOnce(Return(false)); - EXPECT_CALL(*mock_app_, DeletePerformInteractionChoiceSet(_)); + MessageSharedPtr response_msg_vr = CreateHMIResponseMessage( + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, "VR error message"); + am::event_engine::Event event_vr(hmi_apis::FunctionID::VR_PerformInteraction); + event_vr.set_smart_object(*response_msg_vr); + + MessageSharedPtr response_msg_ui = CreateHMIResponseMessage( + hmi_apis::Common_Result::WARNINGS, "UI warning message"); + am::event_engine::Event event_ui(hmi_apis::FunctionID::UI_PerformInteraction); + event_ui.set_smart_object(*response_msg_ui); + MessageSharedPtr response_to_mobile; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + MessageSharedPtr request_to_hmi; + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + _, am::commands::Command::CommandSource::SOURCE_SDL_TO_HMI)) + .WillOnce(DoAll(SaveArg<0>(&request_to_hmi), Return(true))); + + command->on_event(event_vr); command->on_event(event_ui); + HMIRequestExpectations(request_to_hmi, + hmi_apis::FunctionID::UI_ClosePopUp, + "UI.PerformInteraction"); + ResultCommandExpectations(response_to_mobile, - "UI is not supported by system"); + true, + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + "UI warning message, VR error message"); } } // namespace perform_interaction_request diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/put_file_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/put_file_test.cc index e8e03484ed..8db533f446 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/put_file_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/put_file_test.cc @@ -78,6 +78,8 @@ const int64_t kZeroOffset = 0u; const std::string kStorageFolder = "./storage"; const std::string kFolder = "folder"; const std::string kAppFolder = "app_folder"; +const am::WindowID kDefaultWindowId = + mobile_apis::PredefinedWindows::DEFAULT_WINDOW; } // namespace class PutFileRequestTest @@ -99,7 +101,7 @@ class PutFileRequestTest ON_CALL(app_mngr_, application(kConnectionKey)) .WillByDefault(Return(mock_app_)); - ON_CALL(*mock_app_, hmi_level()) + ON_CALL(*mock_app_, hmi_level(kDefaultWindowId)) .WillByDefault(Return(mobile_apis::HMILevel::HMI_FULL)); } @@ -179,7 +181,7 @@ TEST_F(PutFileRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { } TEST_F(PutFileRequestTest, Run_HmiLevelNone_UNSUCCESS) { - EXPECT_CALL(*mock_app_, hmi_level()) + EXPECT_CALL(*mock_app_, hmi_level(kDefaultWindowId)) .WillOnce(Return(mobile_apis::HMILevel::HMI_NONE)); const uint32_t settings_put_file_in_none = 1u; 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 0e8374b75a..6376570106 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 @@ -67,6 +67,8 @@ using ::testing::_; using ::testing::DoAll; using ::testing::Return; using ::testing::ReturnRef; +using ::testing::SaveArg; +using ::testing::SetArgPointee; namespace am = ::application_manager; @@ -75,12 +77,18 @@ using sdl_rpc_plugin::commands::RegisterAppInterfaceRequest; namespace { const uint32_t kConnectionKey = 1u; +const uint32_t kConnectionKey2 = 2u; +const connection_handler::DeviceHandle kDeviceHandle = 3u; const hmi_apis::Common_Language::eType kHmiLanguage = hmi_apis::Common_Language::EN_US; const mobile_apis::Language::eType kMobileLanguage = mobile_apis::Language::EN_US; -const std::string kMacAddress = "test_mac_address"; -const std::string kAppId = "test_app_id"; +const mobile_apis::HybridAppPreference::eType kHybridAppPreference = + mobile_apis::HybridAppPreference::INVALID_ENUM; +const std::string kMacAddress1 = "test_mac_address1"; +const std::string kMacAddress2 = "test_mac_address2"; +const std::string kAppId1 = "test_app1_id"; +const std::string kAppId2 = "test_app2_id"; const std::string kFullAppId = "test_app_id_long"; const std::string kDummyString = "test_string"; const std::vector<uint32_t> kDummyDiagModes; @@ -94,7 +102,9 @@ class RegisterAppInterfaceRequestTest : msg_(CreateMessage()) , command_(CreateCommand<RegisterAppInterfaceRequest>(msg_)) , app_name_("test_app_name_") + , app2_name_("test_app2_name_") , lock_ptr_(std::make_shared<sync_primitives::Lock>()) + , pending_lock_ptr_(std::make_shared<sync_primitives::Lock>()) , mock_application_helper_( application_manager_test::MockApplicationHelper:: application_helper_mock()) { @@ -112,7 +122,7 @@ class RegisterAppInterfaceRequestTest void InitBasicMessage() { (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey; - (*msg_)[am::strings::msg_params][am::strings::app_id] = kAppId; + (*msg_)[am::strings::msg_params][am::strings::app_id] = kAppId1; (*msg_)[am::strings::msg_params][am::strings::full_app_id] = kFullAppId; (*msg_)[am::strings::msg_params][am::strings::app_name] = app_name_; (*msg_)[am::strings::msg_params][am::strings::language_desired] = @@ -130,11 +140,14 @@ class RegisterAppInterfaceRequestTest MockAppPtr CreateBasicMockedApp() { MockAppPtr mock_app = CreateMockApp(); ON_CALL(*mock_app, name()).WillByDefault(ReturnRef(app_name_)); - ON_CALL(*mock_app, mac_address()).WillByDefault(ReturnRef(kMacAddress)); + ON_CALL(*mock_app, mac_address()).WillByDefault(ReturnRef(kMacAddress1)); ON_CALL(*mock_app, app_icon_path()).WillByDefault(ReturnRef(kDummyString)); ON_CALL(*mock_app, language()).WillByDefault(ReturnRef(kMobileLanguage)); ON_CALL(*mock_app, ui_language()).WillByDefault(ReturnRef(kMobileLanguage)); - ON_CALL(*mock_app, policy_app_id()).WillByDefault(Return(kAppId)); + ON_CALL(*mock_app, is_cloud_app()).WillByDefault(Return(false)); + ON_CALL(*mock_app, hybrid_app_preference()) + .WillByDefault(ReturnRef(kHybridAppPreference)); + ON_CALL(*mock_app, policy_app_id()).WillByDefault(Return(kAppId1)); ON_CALL(*mock_app, msg_version()) .WillByDefault(ReturnRef(mock_semantic_version)); return mock_app; @@ -154,7 +167,7 @@ class RegisterAppInterfaceRequestTest void InitGetters() { ON_CALL(app_mngr_, GetCorrectMobileIDFromMessage(msg_)) - .WillByDefault(Return(kAppId)); + .WillByDefault(Return(kAppId1)); ON_CALL(app_mngr_, IsHMICooperating()).WillByDefault(Return(true)); ON_CALL(app_mngr_, resume_controller()) .WillByDefault(ReturnRef(mock_resume_crt_)); @@ -166,9 +179,31 @@ class RegisterAppInterfaceRequestTest .WillByDefault(ReturnRef(kDummyString)); ON_CALL(mock_hmi_capabilities_, ccpu_version()) .WillByDefault(ReturnRef(kDummyString)); + ON_CALL(mock_hmi_capabilities_, speech_capabilities()) + .WillByDefault(Return(smart_objects::SmartObjectSPtr())); + ON_CALL(mock_hmi_capabilities_, prerecorded_speech()) + .WillByDefault(Return(smart_objects::SmartObjectSPtr())); + ON_CALL(mock_hmi_capabilities_, vr_capabilities()) + .WillByDefault(Return(smart_objects::SmartObjectSPtr())); + ON_CALL(mock_hmi_capabilities_, display_capabilities()) + .WillByDefault(Return(smart_objects::SmartObjectSPtr())); + ON_CALL(mock_hmi_capabilities_, audio_pass_thru_capabilities()) + .WillByDefault(Return(smart_objects::SmartObjectSPtr())); + ON_CALL(mock_hmi_capabilities_, vehicle_type()) + .WillByDefault(Return(smart_objects::SmartObjectSPtr())); + ON_CALL(mock_hmi_capabilities_, button_capabilities()) + .WillByDefault(Return(smart_objects::SmartObjectSPtr())); + ON_CALL(mock_hmi_capabilities_, soft_button_capabilities()) + .WillByDefault(Return(smart_objects::SmartObjectSPtr())); + ON_CALL(mock_hmi_capabilities_, preset_bank_capabilities()) + .WillByDefault(Return(smart_objects::SmartObjectSPtr())); + ON_CALL(mock_hmi_capabilities_, hmi_zone_capabilities()) + .WillByDefault(Return(smart_objects::SmartObjectSPtr())); + ON_CALL(mock_hmi_capabilities_, pcm_stream_capabilities()) + .WillByDefault(Return(smart_objects::SmartObjectSPtr())); ON_CALL(app_mngr_settings_, supported_diag_modes()) .WillByDefault(ReturnRef(kDummyDiagModes)); - ON_CALL(mock_policy_handler_, GetAppRequestTypes(_)) + ON_CALL(mock_policy_handler_, GetAppRequestTypes(_, _)) .WillByDefault(Return(std::vector<std::string>())); ON_CALL(mock_policy_handler_, GetAppRequestTypeState(_)) .WillByDefault(Return(policy::RequestType::State::EMPTY)); @@ -180,9 +215,11 @@ class RegisterAppInterfaceRequestTest .WillByDefault(Return(policy::DeviceConsent::kDeviceAllowed)); ON_CALL(app_mngr_, GetDeviceTransportType(_)) .WillByDefault(Return(hmi_apis::Common_TransportType::WIFI)); - ON_CALL(app_mngr_, IsAppInReconnectMode(_)).WillByDefault(Return(false)); + ON_CALL(app_mngr_, IsAppInReconnectMode(_, _)).WillByDefault(Return(false)); ON_CALL(app_mngr_, application_by_policy_id(_)) .WillByDefault(Return(ApplicationSharedPtr())); + ON_CALL(app_mngr_, pending_application_by_policy_id(_)) + .WillByDefault(Return(ApplicationSharedPtr())); ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); ON_CALL( @@ -201,7 +238,7 @@ class RegisterAppInterfaceRequestTest void SetCommonExpectionsOnSwitchedApplication( MockAppPtr mock_app, mobile_apis::Result::eType response_result_code) { - EXPECT_CALL(mock_policy_handler_, AddApplication(_, _)).Times(0); + EXPECT_CALL(mock_policy_handler_, AddApplication(_, _, _)).Times(0); EXPECT_CALL( mock_rpc_service_, @@ -250,8 +287,11 @@ class RegisterAppInterfaceRequestTest std::shared_ptr<RegisterAppInterfaceRequest> command_; const utils::custom_string::CustomString app_name_; + const utils::custom_string::CustomString app2_name_; std::shared_ptr<sync_primitives::Lock> lock_ptr_; am::ApplicationSet app_set_; + std::shared_ptr<sync_primitives::Lock> pending_lock_ptr_; + am::AppsWaitRegistrationSet pending_app_set_; typedef IsNiceMock<policy_test::MockPolicyHandlerInterface, kMocksAreNice>::Result MockPolicyHandlerInterface; @@ -280,7 +320,7 @@ TEST_F(RegisterAppInterfaceRequestTest, Init_SUCCESS) { TEST_F(RegisterAppInterfaceRequestTest, Run_MinimalData_SUCCESS) { InitBasicMessage(); - (*msg_)[am::strings::msg_params][am::strings::hash_id] = kAppId; + (*msg_)[am::strings::msg_params][am::strings::hash_id] = kAppId1; EXPECT_CALL(app_mngr_, IsStopping()) .WillOnce(Return(false)) .WillOnce(Return(true)) @@ -289,20 +329,35 @@ TEST_F(RegisterAppInterfaceRequestTest, Run_MinimalData_SUCCESS) { EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); EXPECT_CALL(app_mngr_, IsApplicationForbidden(_, _)).WillOnce(Return(false)); + connection_handler::DeviceHandle handle = 1; + ON_CALL(mock_connection_handler_, + GetDataOnSessionKey(kConnectionKey, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(handle), Return(0))); + ON_CALL(mock_session_observer_, GetDataOnDeviceID(handle, _, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(kMacAddress1), Return(0))); + MockAppPtr mock_app = CreateBasicMockedApp(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(ApplicationSharedPtr())) - .WillRepeatedly(Return(mock_app)); + EXPECT_CALL(app_mngr_, reregister_application_by_policy_id(kAppId1)) + .WillOnce(Return(ApplicationSharedPtr())); + EXPECT_CALL(app_mngr_, application(kMacAddress1, kAppId1)) + .WillRepeatedly(Return(ApplicationSharedPtr())); ON_CALL(app_mngr_, applications()) .WillByDefault( Return(DataAccessor<am::ApplicationSet>(app_set_, lock_ptr_))); + ON_CALL(app_mngr_, pending_applications()) + .WillByDefault(Return(DataAccessor<am::AppsWaitRegistrationSet>( + pending_app_set_, pending_lock_ptr_))); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + ON_CALL(mock_policy_handler_, PolicyEnabled()).WillByDefault(Return(true)); - ON_CALL(mock_policy_handler_, GetInitialAppData(kAppId, _, _)) + ON_CALL(mock_policy_handler_, GetInitialAppData(kAppId1, _, _)) .WillByDefault(Return(true)); policy::StatusNotifier notify_upd_manager = std::make_shared<utils::CallNothing>(); - ON_CALL(mock_policy_handler_, AddApplication(_, _)) + ON_CALL(mock_policy_handler_, AddApplication(kMacAddress1, kAppId1, _)) .WillByDefault(Return(notify_upd_manager)); EXPECT_CALL(app_mngr_, RegisterApplication(msg_)).WillOnce(Return(mock_app)); @@ -323,6 +378,7 @@ TEST_F(RegisterAppInterfaceRequestTest, Run_MinimalData_SUCCESS) { ManageMobileCommand(_, am::commands::Command::SOURCE_SDL)) .Times(2); EXPECT_CALL(app_mngr_, SendDriverDistractionState(_)); + ASSERT_TRUE(command_->Init()); command_->Run(); } @@ -360,10 +416,21 @@ TEST_F(RegisterAppInterfaceRequestTest, EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); EXPECT_CALL(app_mngr_, IsApplicationForbidden(_, _)).WillOnce(Return(false)); + connection_handler::DeviceHandle handle = 1; + ON_CALL(mock_connection_handler_, + GetDataOnSessionKey(kConnectionKey, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(handle), Return(0))); + ON_CALL(mock_session_observer_, GetDataOnDeviceID(_, _, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(kMacAddress1), Return(0))); + MockAppPtr mock_app = CreateBasicMockedApp(); + EXPECT_CALL(app_mngr_, reregister_application_by_policy_id(kAppId1)) + .WillOnce(Return(ApplicationSharedPtr())); + EXPECT_CALL(app_mngr_, application(kMacAddress1, kAppId1)) + .WillRepeatedly(Return(ApplicationSharedPtr())); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(ApplicationSharedPtr())) - .WillRepeatedly(Return(mock_app)); + .WillOnce(Return(mock_app)); MessageSharedPtr expected_message = CreateMessage(smart_objects::SmartType_Map); @@ -387,25 +454,33 @@ TEST_F(RegisterAppInterfaceRequestTest, "test_templates_available"; display_capabilities[am::hmi_response::screen_params] = "test_screen_params"; + auto vehicle_type_ptr = std::make_shared<smart_objects::SmartObject>( + (*expected_message)[am::hmi_response::vehicle_type]); ON_CALL(mock_hmi_capabilities_, vehicle_type()) - .WillByDefault( - Return(&(*expected_message)[am::hmi_response::vehicle_type])); + .WillByDefault(Return(vehicle_type_ptr)); + + auto vr_capabilities_ptr = std::make_shared<smart_objects::SmartObject>( + (*expected_message)[am::strings::vr_capabilities]); ON_CALL(mock_hmi_capabilities_, vr_capabilities()) - .WillByDefault( - Return(&(*expected_message)[am::strings::vr_capabilities])); + .WillByDefault(Return(vr_capabilities_ptr)); + + auto display_capabilities_ptr = std::make_shared<smart_objects::SmartObject>( + (*expected_message)[am::hmi_response::display_capabilities]); ON_CALL(mock_hmi_capabilities_, display_capabilities()) - .WillByDefault( - Return(&(*expected_message)[am::hmi_response::display_capabilities])); + .WillByDefault(Return(display_capabilities_ptr)); ON_CALL(app_mngr_, applications()) .WillByDefault( Return(DataAccessor<am::ApplicationSet>(app_set_, lock_ptr_))); + ON_CALL(app_mngr_, pending_applications()) + .WillByDefault(Return(DataAccessor<am::AppsWaitRegistrationSet>( + pending_app_set_, pending_lock_ptr_))); ON_CALL(mock_policy_handler_, PolicyEnabled()).WillByDefault(Return(true)); - ON_CALL(mock_policy_handler_, GetInitialAppData(kAppId, _, _)) + ON_CALL(mock_policy_handler_, GetInitialAppData(kAppId1, _, _)) .WillByDefault(Return(true)); policy::StatusNotifier notify_upd_manager = std::make_shared<utils::CallNothing>(); - ON_CALL(mock_policy_handler_, AddApplication(_, _)) + ON_CALL(mock_policy_handler_, AddApplication(kMacAddress1, kAppId1, _)) .WillByDefault(Return(notify_upd_manager)); EXPECT_CALL(app_mngr_, RegisterApplication(msg_)).WillOnce(Return(mock_app)); @@ -444,7 +519,7 @@ TEST_F(RegisterAppInterfaceRequestTest, ManageMobileCommand(_, am::commands::Command::SOURCE_SDL)) .Times(2); EXPECT_CALL(app_mngr_, SendDriverDistractionState(_)); - + ASSERT_TRUE(command_->Init()); command_->Run(); } @@ -456,10 +531,19 @@ TEST_F(RegisterAppInterfaceRequestTest, (*msg_)[am::strings::msg_params][am::strings::hash_id] = request_hash_id; MockAppPtr mock_app = CreateBasicMockedApp(); - EXPECT_CALL(app_mngr_, application_by_policy_id(kAppId)) - .WillRepeatedly(Return(mock_app)); + app_set_.insert(mock_app); + EXPECT_CALL(app_mngr_, reregister_application_by_policy_id(kAppId1)) + .WillOnce(Return(mock_app)); + + connection_handler::DeviceHandle device_id = 1; + ON_CALL(mock_connection_handler_, + GetDataOnSessionKey(kConnectionKey, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(device_id), Return(0))); - EXPECT_CALL(app_mngr_, IsAppInReconnectMode(kAppId)).WillOnce(Return(true)); + ON_CALL(mock_session_observer_, GetDataOnDeviceID(device_id, _, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(kMacAddress1), Return(0))); + + EXPECT_CALL(*mock_app, device()).WillOnce(Return(kDeviceHandle)); EXPECT_CALL(app_mngr_, ProcessReconnection(_, kConnectionKey)); @@ -482,6 +566,7 @@ TEST_F(RegisterAppInterfaceRequestTest, SetCommonExpectionsOnSwitchedApplication(mock_app, mobile_apis::Result::SUCCESS); + ASSERT_TRUE(command_->Init()); command_->Run(); } @@ -492,11 +577,18 @@ TEST_F(RegisterAppInterfaceRequestTest, const std::string request_hash_id = "abc123"; (*msg_)[am::strings::msg_params][am::strings::hash_id] = request_hash_id; - MockAppPtr mock_app = CreateBasicMockedApp(); - EXPECT_CALL(app_mngr_, application_by_policy_id(kAppId)) - .WillRepeatedly(Return(mock_app)); + connection_handler::DeviceHandle device_id = 1; + ON_CALL(mock_connection_handler_, + GetDataOnSessionKey(kConnectionKey, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(device_id), Return(0))); - EXPECT_CALL(app_mngr_, IsAppInReconnectMode(kAppId)).WillOnce(Return(true)); + ON_CALL(mock_session_observer_, GetDataOnDeviceID(device_id, _, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(kMacAddress1), Return(0))); + + MockAppPtr mock_app = CreateBasicMockedApp(); + EXPECT_CALL(app_mngr_, reregister_application_by_policy_id(kAppId1)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, device()).WillOnce(Return(kDeviceHandle)); EXPECT_CALL(app_mngr_, ProcessReconnection(_, kConnectionKey)); @@ -520,7 +612,7 @@ TEST_F(RegisterAppInterfaceRequestTest, SetCommonExpectionsOnSwitchedApplication(mock_app, mobile_apis::Result::RESUME_FAILED); - + ASSERT_TRUE(command_->Init()); command_->Run(); } @@ -528,11 +620,18 @@ TEST_F(RegisterAppInterfaceRequestTest, SwitchApplication_NoHash_ExpectCleanupResumeFailed) { InitBasicMessage(); - MockAppPtr mock_app = CreateBasicMockedApp(); - EXPECT_CALL(app_mngr_, application_by_policy_id(kAppId)) - .WillRepeatedly(Return(mock_app)); + connection_handler::DeviceHandle device_id = 1; + ON_CALL(mock_connection_handler_, + GetDataOnSessionKey(kConnectionKey, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(device_id), Return(0))); + + ON_CALL(mock_session_observer_, GetDataOnDeviceID(device_id, _, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(kMacAddress1), Return(0))); - EXPECT_CALL(app_mngr_, IsAppInReconnectMode(kAppId)).WillOnce(Return(true)); + MockAppPtr mock_app = CreateBasicMockedApp(); + EXPECT_CALL(app_mngr_, reregister_application_by_policy_id(kAppId1)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, device()).WillOnce(Return(kDeviceHandle)); EXPECT_CALL(app_mngr_, ProcessReconnection(_, kConnectionKey)); @@ -550,6 +649,143 @@ TEST_F(RegisterAppInterfaceRequestTest, SetCommonExpectionsOnSwitchedApplication(mock_app, mobile_apis::Result::RESUME_FAILED); + ASSERT_TRUE(command_->Init()); + command_->Run(); +} + +TEST_F(RegisterAppInterfaceRequestTest, + RegisterApp_SameAppId_SameDeviceFailed) { + using namespace am; + + InitBasicMessage(); + + MockAppPtr mock_app1 = CreateBasicMockedApp(); + + app_set_.insert(mock_app1); + ON_CALL(app_mngr_, applications()) + .WillByDefault( + Return(DataAccessor<am::ApplicationSet>(app_set_, lock_ptr_))); + ON_CALL(app_mngr_, pending_applications()) + .WillByDefault(Return(DataAccessor<am::AppsWaitRegistrationSet>( + pending_app_set_, pending_lock_ptr_))); + + MockAppPtr mock_app2 = CreateBasicMockedApp(); + + connection_handler::DeviceHandle device_id = 1; + ON_CALL(mock_connection_handler_, + GetDataOnSessionKey(kConnectionKey, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(device_id), Return(0))); + + ON_CALL(mock_session_observer_, GetDataOnDeviceID(device_id, _, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(kMacAddress1), Return(0))); + + EXPECT_CALL(app_mngr_, reregister_application_by_policy_id(kAppId1)) + .WillOnce(Return(ApplicationSharedPtr())); + EXPECT_CALL(app_mngr_, application(kMacAddress1, kAppId1)) + .WillOnce(Return(mock_app1)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)).Times(0); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs( + mobile_apis::Result::APPLICATION_REGISTERED_ALREADY), + am::commands::Command::SOURCE_SDL)); + + ASSERT_TRUE(command_->Init()); + command_->Run(); +} + +TEST_F(RegisterAppInterfaceRequestTest, + RegisterApp_SameAppId_DifferentDevicesSuccess) { + MockAppPtr mock_app1 = CreateBasicMockedApp(); + const connection_handler::DeviceHandle device_id1 = 1u; + ON_CALL(*mock_app1, device()).WillByDefault(Return(device_id1)); + app_set_.insert(mock_app1); + ON_CALL(app_mngr_, applications()) + .WillByDefault( + Return(DataAccessor<am::ApplicationSet>(app_set_, lock_ptr_))); + ON_CALL(app_mngr_, pending_applications()) + .WillByDefault(Return(DataAccessor<am::AppsWaitRegistrationSet>( + pending_app_set_, pending_lock_ptr_))); + + InitBasicMessage(); + (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey2; + EXPECT_CALL(app_mngr_, IsStopping()) + .WillOnce(Return(false)) + .WillOnce(Return(true)) + .WillOnce(Return(false)); + ON_CALL(app_mngr_, IsHMICooperating()).WillByDefault(Return(false)); + EXPECT_CALL(app_mngr_, updateRequestTimeout(kConnectionKey2, _, _)); + EXPECT_CALL(app_mngr_, IsApplicationForbidden(kConnectionKey2, kAppId1)) + .WillOnce(Return(false)); + + connection_handler::DeviceHandle device_id2 = 2u; + ON_CALL(mock_connection_handler_, + GetDataOnSessionKey(kConnectionKey2, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(device_id2), Return(0))); + + ON_CALL(mock_session_observer_, GetDataOnDeviceID(device_id2, _, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(kMacAddress2), Return(0))); + + MockAppPtr mock_app2 = CreateBasicMockedApp(); + + ON_CALL(*mock_app2, device()).WillByDefault(Return(device_id2)); + ON_CALL(*mock_app2, mac_address()).WillByDefault(ReturnRef(kMacAddress2)); + EXPECT_CALL(app_mngr_, application(kMacAddress2, kAppId1)) + .WillRepeatedly(Return(ApplicationSharedPtr())); + EXPECT_CALL(app_mngr_, reregister_application_by_policy_id(kAppId1)) + .WillOnce(Return(ApplicationSharedPtr())); + + EXPECT_CALL(app_mngr_, application(kConnectionKey2)) + .WillOnce(Return(mock_app2)); + + ON_CALL(mock_policy_handler_, PolicyEnabled()).WillByDefault(Return(true)); + ON_CALL(mock_policy_handler_, GetInitialAppData(kAppId1, _, _)) + .WillByDefault(Return(true)); + policy::StatusNotifier notify_upd_manager = + std::make_shared<utils::CallNothing>(); + ON_CALL(mock_policy_handler_, AddApplication(kMacAddress2, kAppId1, _)) + .WillByDefault(Return(notify_upd_manager)); + + EXPECT_CALL(app_mngr_, RegisterApplication(msg_)).WillOnce(Return(mock_app2)); + + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs( + hmi_apis::FunctionID::BasicCommunication_OnAppRegistered), + _)) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs(hmi_apis::FunctionID::Buttons_OnButtonSubscription), + _)) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs(hmi_apis::FunctionID::VR_ChangeRegistration), _)) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs(hmi_apis::FunctionID::TTS_ChangeRegistration), _)) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs(hmi_apis::FunctionID::UI_ChangeRegistration), _)) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::SOURCE_SDL)) + .Times(2); + EXPECT_CALL(app_mngr_, SendDriverDistractionState(_)); + + ASSERT_TRUE(command_->Init()); command_->Run(); } 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 98c0ad098a..4b43c302e4 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 @@ -139,8 +139,21 @@ TEST_F(ResetGlobalPropertiesRequestTest, Run_InvalidVrHelp_UNSUCCESS) { mobile_apis::GlobalProperty::KEYBOARDPROPERTIES; EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + std::vector<std::string> help_prompt = {"help_prompt"}; + + EXPECT_CALL(app_mngr_settings_, help_prompt()) + .WillOnce(ReturnRef(help_prompt)); + + smart_objects::SmartObject so_help_prompt = + smart_objects::SmartObject(smart_objects::SmartType_Map); + so_help_prompt[am::strings::text] = help_prompt[0]; + so_help_prompt[am::strings::type] = + hmi_apis::Common_SpeechCapabilities::SC_TEXT; + smart_objects::SmartObject so_prompt = smart_objects::SmartObject(smart_objects::SmartType_Array); + so_prompt[0] = so_help_prompt; + EXPECT_CALL(*mock_app_, set_help_prompt(so_prompt)); std::vector<std::string> time_out_prompt; @@ -161,6 +174,15 @@ TEST_F(ResetGlobalPropertiesRequestTest, Run_InvalidVrHelp_UNSUCCESS) { EXPECT_CALL(*mock_app_, set_timeout_prompt(so_time_out_prompt)); + std::string vr_help_title("vr_help_title"); + EXPECT_CALL(app_mngr_settings_, vr_help_title()) + .WillOnce(ReturnRef(vr_help_title)); + + smart_objects::SmartObject so_vr_help_title = + smart_objects::SmartObject(smart_objects::SmartType_String); + so_vr_help_title = vr_help_title; + EXPECT_CALL(*mock_app_, set_vr_help_title(so_vr_help_title)); + EXPECT_CALL(*mock_app_, reset_vr_help_title()); EXPECT_CALL(*mock_app_, reset_vr_help()); @@ -190,8 +212,21 @@ TEST_F(ResetGlobalPropertiesRequestTest, Run_SUCCESS) { mobile_apis::GlobalProperty::KEYBOARDPROPERTIES; EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + + std::vector<std::string> help_prompt = {"help_prompt"}; + + EXPECT_CALL(app_mngr_settings_, help_prompt()) + .WillOnce(ReturnRef(help_prompt)); + + smart_objects::SmartObject so_help_prompt = + smart_objects::SmartObject(smart_objects::SmartType_Map); + so_help_prompt[am::strings::text] = help_prompt[0]; + so_help_prompt[am::strings::type] = + hmi_apis::Common_SpeechCapabilities::SC_TEXT; + smart_objects::SmartObject so_prompt = smart_objects::SmartObject(smart_objects::SmartType_Array); + so_prompt[0] = so_help_prompt; EXPECT_CALL(*mock_app_, set_help_prompt(so_prompt)); std::vector<std::string> time_out_prompt; @@ -212,6 +247,15 @@ TEST_F(ResetGlobalPropertiesRequestTest, Run_SUCCESS) { EXPECT_CALL(*mock_app_, set_timeout_prompt(so_time_out_prompt)); + std::string vr_help_title("vr_help_title"); + EXPECT_CALL(app_mngr_settings_, vr_help_title()) + .WillOnce(ReturnRef(vr_help_title)); + + smart_objects::SmartObject so_vr_help_title = + smart_objects::SmartObject(smart_objects::SmartType_String); + so_vr_help_title = vr_help_title; + EXPECT_CALL(*mock_app_, set_vr_help_title(so_vr_help_title)); + EXPECT_CALL(*mock_app_, reset_vr_help_title()); EXPECT_CALL(*mock_app_, reset_vr_help()); @@ -230,12 +274,8 @@ TEST_F(ResetGlobalPropertiesRequestTest, Run_SUCCESS) { EXPECT_CALL(*mock_app_, set_menu_title(msg_params[am::hmi_request::menu_title])); - const smart_objects::SmartObjectSPtr so_help_prompt = - std::make_shared<smart_objects::SmartObject>( - smart_objects::SmartType_Map); - EXPECT_CALL(*mock_app_, help_prompt()).WillOnce(Return(so_help_prompt.get())); - EXPECT_CALL(*mock_app_, timeout_prompt()) - .WillOnce(Return(so_help_prompt.get())); + EXPECT_CALL(*mock_app_, help_prompt()).WillOnce(Return(&so_help_prompt)); + EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(&so_help_prompt)); EXPECT_CALL( mock_rpc_service_, @@ -267,6 +307,15 @@ TEST_F(ResetGlobalPropertiesRequestTest, (*msg_)[am::strings::msg_params][am::strings::properties][0] = mobile_apis::GlobalProperty::VRHELPTITLE; + std::string vr_help_title("vr_help_title"); + EXPECT_CALL(app_mngr_settings_, vr_help_title()) + .WillOnce(ReturnRef(vr_help_title)); + + smart_objects::SmartObject so_vr_help_title = + smart_objects::SmartObject(smart_objects::SmartType_String); + so_vr_help_title = vr_help_title; + EXPECT_CALL(*mock_app_, set_vr_help_title(so_vr_help_title)); + EXPECT_CALL(*mock_app_, reset_vr_help_title()); EXPECT_CALL(*mock_app_, reset_vr_help()); EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); @@ -363,6 +412,15 @@ TEST_F(ResetGlobalPropertiesRequestTest, OnEvent_InvalidApp_NoHashUpdate) { (*msg_)[am::strings::msg_params][am::strings::properties][0] = mobile_apis::GlobalProperty::VRHELPTITLE; + std::string vr_help_title("vr_help_title"); + EXPECT_CALL(app_mngr_settings_, vr_help_title()) + .WillOnce(ReturnRef(vr_help_title)); + + smart_objects::SmartObject so_vr_help_title = + smart_objects::SmartObject(smart_objects::SmartType_String); + so_vr_help_title = vr_help_title; + EXPECT_CALL(*mock_app_, set_vr_help_title(so_vr_help_title)); + EXPECT_CALL(*mock_app_, reset_vr_help_title()); EXPECT_CALL(*mock_app_, reset_vr_help()); 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 3820112ea5..6b17aa238d 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 @@ -175,7 +175,7 @@ TEST_F(ScrollableMessageRequestTest, Init_CorrectTimeout_SUCCESS) { mobile_apis::InteractionMode::MANUAL_ONLY; EXPECT_EQ(kDefaultTimeout_, command_->default_timeout()); command_->Init(); - EXPECT_EQ(kTimeOut, command_->default_timeout()); + EXPECT_EQ(kTimeOut + kDefaultTimeout_, command_->default_timeout()); } TEST_F(ScrollableMessageRequestTest, Init_CorrectTimeout_UNSUCCESS) { @@ -183,7 +183,7 @@ TEST_F(ScrollableMessageRequestTest, Init_CorrectTimeout_UNSUCCESS) { mobile_apis::InteractionMode::MANUAL_ONLY; EXPECT_EQ(kDefaultTimeout_, command_->default_timeout()); command_->Init(); - EXPECT_EQ(kTimeOut, command_->default_timeout()); + EXPECT_EQ(kDefaultTimeout_, command_->default_timeout()); } TEST_F(ScrollableMessageRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/send_location_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/send_location_request_test.cc index 5d90453278..968c91b5ce 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/send_location_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/send_location_request_test.cc @@ -110,6 +110,8 @@ class SendLocationRequestTest (*message_)[strings::msg_params] = SmartObject(smart_objects::SmartType_Map); (*message_)[strings::msg_params][strings::address] = kCorrectAddress; + ON_CALL(mock_hmi_capabilities_, display_capabilities()) + .WillByDefault(Return(smart_objects::SmartObjectSPtr())); EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillOnce(Return(mock_app_)); @@ -130,8 +132,7 @@ class SendLocationRequestTest SmartObject(smart_objects::SmartType_Map); (*disp_cap_)[hmi_response::text_fields][0][strings::name] = field_name; EXPECT_CALL(mock_hmi_capabilities_, display_capabilities()) - .Times(2) - .WillRepeatedly(Return(disp_cap_.get())); + .WillOnce(Return(disp_cap_)); } void FinishSetup() { diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_display_layout_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_display_layout_test.cc index cc2f042eac..cc3b5925ce 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_display_layout_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_display_layout_test.cc @@ -160,6 +160,7 @@ TEST_F(SetDisplayLayoutRequestTest, ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + command->Init(); command->on_event(event); ResultCommandExpectations(ui_command_result, "UI is not supported by system"); @@ -178,6 +179,7 @@ TEST_F(SetDisplayLayoutRequestTest, Run_InvalidApp_UNSUCCESS) { MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), am::commands::Command::CommandSource::SOURCE_SDL)); + command->Init(); command->Run(); } @@ -188,7 +190,7 @@ TEST_F(SetDisplayLayoutRequestTest, Run_SUCCESS) { MockAppPtr mock_app(CreateMockApp()); EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillOnce(Return(mock_app)); - EXPECT_CALL(*mock_app, display_layout()).WillOnce(ReturnRef(kLayout)); + EXPECT_CALL(*mock_app, display_layout()).WillOnce(Return(kLayout)); EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kAppId)); EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) @@ -204,20 +206,60 @@ TEST_F(SetDisplayLayoutRequestTest, Run_SUCCESS) { ManageHMICommand(CheckMshCorrId(kCorrelationKey), _)) .WillOnce(Return(true)); + command->Init(); command->Run(); } TEST_F(SetDisplayLayoutRequestTest, OnEvent_InvalidEventId_UNSUCCESS) { - CommandPtr command(CreateCommand<SetDisplayLayoutRequest>()); + MessageSharedPtr msg(CreateMessage(smart_objects::SmartType_Map)); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + CommandPtr command(CreateCommand<SetDisplayLayoutRequest>(msg)); + am::event_engine::Event event(hmi_apis::FunctionID::INVALID_ENUM); - SmartObject msg(smart_objects::SmartType_Map); - event.set_smart_object(msg); + event.set_smart_object(*msg); + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + command->Init(); + command->on_event(event); +} + +TEST_F(SetDisplayLayoutRequestTest, OnEvent_AppVersion_v6_WARNING) { + am::event_engine::Event event(hmi_apis::FunctionID::UI_SetDisplayLayout); + MessageSharedPtr msg = CreateMessage(); + + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*msg)[am::strings::msg_params][am::hmi_response::display_capabilities] = 0; + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + event.set_smart_object(*msg); + MessageSharedPtr dispaly_capabilities_msg = CreateMessage(); + (*dispaly_capabilities_msg)[am::hmi_response::templates_available] = + "templates_available"; + + EXPECT_CALL(mock_hmi_capabilities_, display_capabilities()) + .WillOnce(Return(dispaly_capabilities_msg)); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::WARNINGS), + am::commands::Command::CommandSource::SOURCE_SDL)); + + CommandPtr command(CreateCommand<SetDisplayLayoutRequest>(msg)); + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + ::application_manager::Version app_version; + app_version.max_supported_api_version = + ::application_manager::APIVersion::kAPIV6; + EXPECT_CALL(*mock_app, version()).WillOnce(ReturnRef(app_version)); + + command->Init(); command->on_event(event); } -TEST_F(SetDisplayLayoutRequestTest, OnEvent_SUCCESS) { +TEST_F(SetDisplayLayoutRequestTest, OnEvent_AppVersion_v5_SUCCESS) { am::event_engine::Event event(hmi_apis::FunctionID::UI_SetDisplayLayout); MessageSharedPtr msg = CreateMessage(); @@ -232,13 +274,22 @@ TEST_F(SetDisplayLayoutRequestTest, OnEvent_SUCCESS) { "templates_available"; EXPECT_CALL(mock_hmi_capabilities_, display_capabilities()) - .WillOnce(Return(dispaly_capabilities_msg.get())); + .WillOnce(Return(dispaly_capabilities_msg)); EXPECT_CALL( mock_rpc_service_, ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), am::commands::Command::CommandSource::SOURCE_SDL)); CommandPtr command(CreateCommand<SetDisplayLayoutRequest>(msg)); + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + ::application_manager::Version app_version; + app_version.max_supported_api_version = + ::application_manager::APIVersion::kAPIV5; + EXPECT_CALL(*mock_app, version()).WillOnce(ReturnRef(app_version)); + + command->Init(); command->on_event(event); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_global_properties_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_global_properties_test.cc index 3e791aef01..9b72d41f7e 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_global_properties_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_global_properties_test.cc @@ -39,6 +39,7 @@ #include "application_manager/commands/command_request_test.h" #include "application_manager/event_engine/event.h" +#include "application_manager/message_helper.h" #include "application_manager/mock_application.h" #include "application_manager/mock_application_manager.h" #include "application_manager/mock_help_prompt_manager.h" @@ -70,6 +71,13 @@ const uint32_t kCmdId = 1u; const uint32_t kConnectionKey = 1u; const std::string kText = "one"; const uint32_t kPosition = 1u; + +const std::vector<hmi_apis::Common_Result::eType> success_result_codes{ + 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}; } // namespace class SetGlobalPropertiesRequestTest @@ -233,9 +241,16 @@ class SetGlobalPropertiesRequestTest ON_CALL(app_mngr_, application(kConnectionKey)) .WillByDefault(Return(mock_app_)); ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + ON_CALL(mock_app_manager_, hmi_interfaces()) + .WillByDefault(ReturnRef(mock_hmi_interfaces_)); + ON_CALL(mock_message_helper_, + MobileToHMIResult(mobile_apis::Result::UNSUPPORTED_RESOURCE)) + .WillByDefault(Return(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + ON_CALL(mock_message_helper_, + MobileToHMIResult(mobile_apis::Result::WARNINGS)) + .WillByDefault(Return(hmi_apis::Common_Result::WARNINGS)); } void ResultCommandExpectations(MessageSharedPtr msg, @@ -243,8 +258,8 @@ class SetGlobalPropertiesRequestTest EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), true); EXPECT_EQ( - (*msg)[am::strings::msg_params][am::strings::result_code].asInt(), - static_cast<int32_t>(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + static_cast<int32_t>(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE), + (*msg)[am::strings::msg_params][am::strings::result_code].asInt()); EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::info].asString(), info); } @@ -265,10 +280,128 @@ class SetGlobalPropertiesRequestTest GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); } + + // Checks total result code for each properties + void PrepareResultCodeForResponse_CheckTotalCode( + const hmi_apis::Common_Result::eType& ui_result, + const hmi_apis::Common_Result::eType& tts_result, + const hmi_apis::Common_Result::eType& rc_result, + const mobile_apis::Result::eType expected_total_result_code) { + using namespace application_manager; + using namespace hmi_apis; + + commands::ResponseInfo ui_properties_info( + ui_result, HmiInterfaces::HMI_INTERFACE_UI, mock_app_manager_); + commands::ResponseInfo tts_properties_info( + tts_result, HmiInterfaces::HMI_INTERFACE_TTS, mock_app_manager_); + commands::ResponseInfo rc_properties_info( + rc_result, HmiInterfaces::HMI_INTERFACE_RC, mock_app_manager_); + + MessageSharedPtr msg = CreateMsgParams(); + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + auto result = command->PrepareResultCodeForResponse( + ui_properties_info, tts_properties_info, rc_properties_info); + + EXPECT_EQ(expected_total_result_code, result); + } + + // Sets in rotation for each result UNSUPPROTED result code and checks total + // result code + void PrepareResultCodeForResponse_CheckAllResultsForSpecifiedTotalResult( + mobile_apis::Result::eType expected_total_result_code) { + using namespace application_manager; + using namespace hmi_apis; + + Common_Result::eType ui_result = + MessageHelper::MobileToHMIResult(expected_total_result_code); + Common_Result::eType tts_result = Common_Result::SUCCESS; + Common_Result::eType rc_result = Common_Result::SUCCESS; + + PrepareResultCodeForResponse_CheckTotalCode( + ui_result, tts_result, rc_result, expected_total_result_code); + + ui_result = Common_Result::SUCCESS; + tts_result = MessageHelper::MobileToHMIResult(expected_total_result_code); + + PrepareResultCodeForResponse_CheckTotalCode( + ui_result, tts_result, rc_result, expected_total_result_code); + + tts_result = Common_Result::SUCCESS; + rc_result = MessageHelper::MobileToHMIResult(expected_total_result_code); + + PrepareResultCodeForResponse_CheckTotalCode( + ui_result, tts_result, rc_result, expected_total_result_code); + } + + void PrepareResultForMobileResponse_CheckTotalReault( + const hmi_apis::Common_Result::eType& ui_result, + const hmi_apis::Common_Result::eType& tts_result, + const hmi_apis::Common_Result::eType& rc_result, + const bool expected_total_result) { + using namespace application_manager; + using namespace hmi_apis; + + commands::ResponseInfo ui_properties_info( + ui_result, HmiInterfaces::HMI_INTERFACE_UI, mock_app_manager_); + commands::ResponseInfo tts_properties_info( + tts_result, HmiInterfaces::HMI_INTERFACE_TTS, mock_app_manager_); + commands::ResponseInfo rc_properties_info( + rc_result, HmiInterfaces::HMI_INTERFACE_RC, mock_app_manager_); + + MessageSharedPtr msg = CreateMsgParams(); + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + bool result = command->PrepareResultForMobileResponse( + ui_properties_info, tts_properties_info, rc_properties_info); + + EXPECT_EQ(expected_total_result, result); + } + + void PrepareResultForMobileResponse_CheckResultsForAllCases() { + using namespace application_manager; + using namespace hmi_apis; + + Common_Result::eType ui_result = Common_Result::SUCCESS; + Common_Result::eType tts_result = Common_Result::SUCCESS; + Common_Result::eType rc_result = Common_Result::SUCCESS; + + PrepareResultForMobileResponse_CheckTotalReault( + ui_result, tts_result, rc_result, true); + + // Result code isn't success + EXPECT_FALSE(helpers::in_range(success_result_codes, + Common_Result::UNSUPPORTED_REQUEST)); + + ui_result = Common_Result::UNSUPPORTED_REQUEST; + tts_result = Common_Result::SUCCESS; + rc_result = Common_Result::SUCCESS; + + PrepareResultForMobileResponse_CheckTotalReault( + ui_result, tts_result, rc_result, false); + + ui_result = Common_Result::SUCCESS; + tts_result = Common_Result::UNSUPPORTED_REQUEST; + rc_result = Common_Result::SUCCESS; + + PrepareResultForMobileResponse_CheckTotalReault( + ui_result, tts_result, rc_result, false); + + ui_result = Common_Result::SUCCESS; + tts_result = Common_Result::SUCCESS; + rc_result = Common_Result::UNSUPPORTED_REQUEST; + + PrepareResultForMobileResponse_CheckTotalReault( + ui_result, tts_result, rc_result, false); + } + std::shared_ptr<sync_primitives::Lock> lock_ptr_; MockAppPtr mock_app_; std::shared_ptr<application_manager_test::MockHelpPromptManager> mock_help_prompt_manager_; + NiceMock<MockApplicationManager> mock_app_manager_; }; TEST_F(SetGlobalPropertiesRequestTest, @@ -332,6 +465,7 @@ TEST_F(SetGlobalPropertiesRequestTest, ManageHMICommand( HMIResultCodeIs(hmi_apis::FunctionID::TTS_SetGlobalProperties), _)) .WillOnce(Return(true)); + (*msg_vr)[am::strings::params][am::hmi_response::code] = hmi_apis::Common_Result::SUCCESS; Event event_vr(hmi_apis::FunctionID::TTS_SetGlobalProperties); @@ -1372,6 +1506,51 @@ TEST_F(SetGlobalPropertiesRequestTest, static_cast<int32_t>(hmi_apis::Common_Result::WARNINGS)); } +TEST_F(SetGlobalPropertiesRequestTest, + PrepareResultCodeForResponse_AllResultsAreSUCCESS_TotalResultSUCCESS) { + using namespace application_manager; + using namespace hmi_apis; + const auto expected_total_result = mobile_apis::Result::eType::SUCCESS; + + Common_Result::eType ui_result = Common_Result::SUCCESS; + Common_Result::eType tts_result = Common_Result::SUCCESS; + Common_Result::eType rc_result = Common_Result::SUCCESS; + + app_mngr::commands::ResponseInfo ui_properties_info( + ui_result, HmiInterfaces::HMI_INTERFACE_UI, mock_app_manager_); + + app_mngr::commands::ResponseInfo tts_properties_info( + tts_result, HmiInterfaces::HMI_INTERFACE_TTS, mock_app_manager_); + + app_mngr::commands::ResponseInfo rc_properties_info( + rc_result, HmiInterfaces::HMI_INTERFACE_RC, mock_app_manager_); + + MessageSharedPtr msg = CreateMsgParams(); + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + auto result = command->PrepareResultCodeForResponse( + ui_properties_info, tts_properties_info, rc_properties_info); + + EXPECT_EQ(expected_total_result, result); +} + +TEST_F(SetGlobalPropertiesRequestTest, + PrepareResultCodeForResponse_UNSUPPORTED) { + PrepareResultCodeForResponse_CheckAllResultsForSpecifiedTotalResult( + mobile_apis::Result::UNSUPPORTED_RESOURCE); +} + +TEST_F(SetGlobalPropertiesRequestTest, PrepareResultCodeForResponse_WARNINGS) { + PrepareResultCodeForResponse_CheckAllResultsForSpecifiedTotalResult( + mobile_apis::Result::WARNINGS); +} + +TEST_F(SetGlobalPropertiesRequestTest, + PrepareResultForMobileResponse_AllCases) { + PrepareResultForMobileResponse_CheckResultsForAllCases(); +} + } // namespace set_global_properties_request } // namespace mobile_commands_test } // namespace commands_test 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 ed0f52a521..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 @@ -31,6 +31,7 @@ */ #include <stdint.h> +#include <array> #include <memory> #include <set> #include <string> @@ -68,8 +69,28 @@ const uint32_t kAppId = 1u; const uint32_t kCmdId = 1u; const uint32_t kConnectionKey = 2u; const uint32_t kFunctionID = 3u; +const std::string kCurrentTemplatelayout = "current_template_layout"; +const std::string kNewTemplateLayout = "new_template_layout"; +const app_mngr::WindowID kCurrentWindowID = 1; +typedef std::array<int, 3> rgb_color_scheme; +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, "") { + const bool is_success = + (*arg)[am::strings::msg_params][am::strings::success].asBool() == success; + + const bool is_result_code_correct = + (*arg)[am::strings::msg_params][am::strings::result_code].asInt() == + static_cast<int32_t>(result_code); + return is_success && is_result_code_correct; +} + class ShowRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { public: ShowRequestTest() { @@ -104,6 +125,101 @@ class ShowRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { return msg; } + protected: + void SetUp() OVERRIDE { + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + ON_CALL(*mock_app_, WindowIdExists(kCurrentWindowID)) + .WillByDefault(Return(true)); + ON_CALL(*mock_app_, window_layout(kCurrentWindowID)) + .WillByDefault(Return(kCurrentTemplatelayout)); + } + + smart_objects::SmartObject CreateColorScheme( + const rgb_color_scheme& rgb_color_scheme) { + using namespace application_manager; + + smart_objects::SmartObject primary_color(smart_objects::SmartType_Map); + smart_objects::SmartObject secondary_color(smart_objects::SmartType_Map); + smart_objects::SmartObject background_color(smart_objects::SmartType_Map); + + primary_color[strings::red] = rgb_color_scheme[0]; + primary_color[strings::green] = rgb_color_scheme[1]; + primary_color[strings::blue] = rgb_color_scheme[2]; + + secondary_color[strings::red] = rgb_color_scheme[0]; + secondary_color[strings::green] = rgb_color_scheme[1]; + secondary_color[strings::blue] = rgb_color_scheme[2]; + + background_color[strings::red] = rgb_color_scheme[0]; + background_color[strings::green] = rgb_color_scheme[1]; + background_color[strings::blue] = rgb_color_scheme[2]; + + smart_objects::SmartObject color_scheme(smart_objects::SmartType_Map); + color_scheme[strings::primary_color] = primary_color; + color_scheme[strings::secondary_color] = secondary_color; + color_scheme[strings::background_color] = background_color; + + return color_scheme; + } + + smart_objects::SmartObject CreateTemplateConfiguration( + const std::string& layout) { + using namespace application_manager; + + smart_objects::SmartObject template_configuration( + smart_objects::SmartType_Map); + + template_configuration[strings::template_layout] = layout; + + template_configuration[strings::day_color_scheme] = + CreateColorScheme(kCurrentDayColorRGB); + + template_configuration[strings::night_color_scheme] = + CreateColorScheme(kCurrentNightColorRGB); + + return template_configuration; + } + + MessageSharedPtr CreateMessageWithTemplateLayout(const std::string& layout) { + auto msg = CreateMsgParams(); + (*msg)[app_mngr::strings::msg_params][app_mngr::strings::window_id] = + kCurrentWindowID; + (*msg)[am::strings::msg_params][am::strings::template_configuration] = + CreateTemplateConfiguration(layout); + + return msg; + } + + std::shared_ptr<ShowRequest> SetupHelperLayout( + const std::string& layout, + const rgb_color_scheme& day_colors, + const rgb_color_scheme& night_colors) { + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_Show), + Command::CommandSource::SOURCE_SDL_TO_HMI)) + .WillOnce(Return(true)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kConnectionKey)); + EXPECT_CALL(*mock_app_, WindowIdExists(kCurrentWindowID)) + .WillOnce(Return(true)); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + const auto current_day_color_scheme = CreateColorScheme(day_colors); + ON_CALL(*mock_app_, day_color_scheme(kCurrentWindowID)) + .WillByDefault(Return(current_day_color_scheme)); + const auto current_night_color_scheme = CreateColorScheme(night_colors); + ON_CALL(*mock_app_, night_color_scheme(kCurrentWindowID)) + .WillByDefault(Return(current_night_color_scheme)); + ON_CALL(*mock_app_, window_layout(kCurrentWindowID)) + .WillByDefault(Return(kCurrentTemplatelayout)); + + auto msg = CreateMessageWithTemplateLayout(layout); + + auto command(CreateCommand<ShowRequest>(msg)); + return command; + } + void TestSetupHelper(MessageSharedPtr msg, hmi_apis::Common_TextFieldName::eType field_name, const char* field) { @@ -269,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)); @@ -319,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); @@ -729,10 +846,14 @@ TEST_F(ShowRequestTest, Run_MainField1_MetadataTagWithNoFieldData) { hmi_apis::Common_Result::SUCCESS; (*ev_msg)[am::strings::msg_params][am::strings::app_id] = kConnectionKey; (*ev_msg)[am::strings::msg_params][am::strings::info] = ""; + (*ev_msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; Event event(hmi_apis::FunctionID::UI_Show); event.set_smart_object(*ev_msg); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + MessageSharedPtr ui_command_result; EXPECT_CALL( mock_rpc_service_, @@ -886,34 +1007,328 @@ TEST_F(ShowRequestTest, Run_CustomPresets_WrongSyntax) { command->Run(); } -TEST_F(ShowRequestTest, Run_InvalidApp_Canceled) { +TEST_F(ShowRequestTest, + Run_AppDoesNotExist_ExpectAppNotRegisteredResponseToMobile) { + const auto result_code = mobile_apis::Result::APPLICATION_NOT_REGISTERED; + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(CheckMessageToMobile(result_code, false), + Command::CommandSource::SOURCE_SDL)) + .WillOnce(Return(true)); + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(nullptr)); + + auto msg = CreateMsgParams(); + auto command = CreateCommand<ShowRequest>(msg); + ASSERT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_EmptyParams_Canceled) { MessageSharedPtr msg = CreateMsgParams(); std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(MockAppPtr())); + .WillOnce(Return(mock_app_)); EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); EXPECT_CALL(*mock_app_, app_id()).Times(0); EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)).Times(0); EXPECT_CALL(*mock_app_, set_show_command(_)).Times(0); + ASSERT_TRUE(command->Init()); command->Run(); } -TEST_F(ShowRequestTest, Run_EmptyParams_Canceled) { - MessageSharedPtr msg = CreateMsgParams(); +TEST_F(ShowRequestTest, + Run_WindowWithIDDoesNotExist_ExpectInvalidIDResponseToMobile) { + const auto result_code = mobile_apis::Result::INVALID_ID; + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(CheckMessageToMobile(result_code, false), + Command::CommandSource::SOURCE_SDL)) + .WillOnce(Return(true)); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + ON_CALL(*mock_app_, WindowIdExists(kCurrentWindowID)) + .WillByDefault(Return(false)); - std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + auto msg = CreateMsgParams(); + (*msg)[am::strings::msg_params][am::strings::window_id] = kCurrentWindowID; + + auto command = CreateCommand<ShowRequest>(msg); + ASSERT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(ShowRequestTest, + Run_NoLayoutChangeWithoutBothColorScheme_SendRequestToHMI_SUCCESS) { + auto msg = CreateMsgParams(); + (*msg)[app_mngr::strings::msg_params][app_mngr::strings::window_id] = + kCurrentWindowID; + (*msg)[am::strings::msg_params][am::strings::template_configuration] + [am::strings::template_layout] = kCurrentTemplatelayout; + + auto command(CreateCommand<ShowRequest>(msg)); + + auto message_to_hmi = CreateMessage(); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)) + .WillOnce(DoAll(SaveArg<0>(&message_to_hmi), Return(true))); + + ASSERT_TRUE(command->Init()); + command->Run(); + + const auto template_layout = + (*message_to_hmi)[am::strings::msg_params] + [am::strings::template_configuration] + [am::strings::template_layout] + .asString(); + EXPECT_EQ(kCurrentTemplatelayout, template_layout); +} + +TEST_F(ShowRequestTest, + Run_NoLayoutChangeDayColorSchemesNotEqual_Response_REJECTED) { + auto msg = CreateMessageWithTemplateLayout(kCurrentTemplatelayout); + + const auto current_day_color_scheme = CreateColorScheme(kNewDayColorRGB); + + auto command(CreateCommand<ShowRequest>(msg)); + + ON_CALL(*mock_app_, day_color_scheme(kCurrentWindowID)) + .WillByDefault(Return(current_day_color_scheme)); + + auto message_to_mobile = CreateMessage(); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&message_to_mobile), Return(true))); + + ASSERT_TRUE(command->Init()); + command->Run(); + + const bool success = + (*message_to_mobile)[am::strings::msg_params][am::strings::success] + .asBool(); + EXPECT_FALSE(success); + + const auto result_code = static_cast<mobile_apis::Result::eType>( + (*message_to_mobile)[am::strings::msg_params][am::strings::result_code] + .asUInt()); + + EXPECT_EQ(mobile_apis::Result::REJECTED, result_code); +} + +TEST_F(ShowRequestTest, + Run_NoLayoutChangeNightColorSchemesNotEqual_Response_REJECTED) { + auto msg = CreateMessageWithTemplateLayout(kCurrentTemplatelayout); + + const auto current_night_color_scheme = CreateColorScheme(kNewNightColorRGB); + + auto command(CreateCommand<ShowRequest>(msg)); + + ON_CALL(*mock_app_, day_color_scheme(kCurrentWindowID)) + .WillByDefault(Return(current_night_color_scheme)); + + auto message_to_mobile = CreateMessage(); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&message_to_mobile), Return(true))); + + ASSERT_TRUE(command->Init()); + command->Run(); + + const bool success = + (*message_to_mobile)[am::strings::msg_params][am::strings::success] + .asBool(); + EXPECT_FALSE(success); + const auto result_code = static_cast<mobile_apis::Result::eType>( + (*message_to_mobile)[am::strings::msg_params][am::strings::result_code] + .asUInt()); + + EXPECT_EQ(mobile_apis::Result::REJECTED, result_code); +} + +TEST_F(ShowRequestTest, + Run_LayoutNotChangeBothColorSchemeEqual_SendRequestToHMI_SUCCESS) { + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_Show), + Command::CommandSource::SOURCE_SDL_TO_HMI)) + .WillOnce(Return(true)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kConnectionKey)); + EXPECT_CALL(*mock_app_, WindowIdExists(kCurrentWindowID)) + .WillOnce(Return(true)); EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); - EXPECT_CALL(*mock_app_, app_id()).Times(0); - EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)).Times(0); - EXPECT_CALL(*mock_app_, set_show_command(_)).Times(0); + const auto current_day_color_scheme = CreateColorScheme(kCurrentDayColorRGB); + ON_CALL(*mock_app_, day_color_scheme(kCurrentWindowID)) + .WillByDefault(Return(current_day_color_scheme)); + const auto current_night_color_scheme = + CreateColorScheme(kCurrentNightColorRGB); + ON_CALL(*mock_app_, night_color_scheme(kCurrentWindowID)) + .WillByDefault(Return(current_night_color_scheme)); + ON_CALL(*mock_app_, window_layout(kCurrentWindowID)) + .WillByDefault(Return(kCurrentTemplatelayout)); + + auto msg = CreateMessageWithTemplateLayout(kCurrentTemplatelayout); + + auto command(CreateCommand<ShowRequest>(msg)); + ASSERT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(ShowRequestTest, + Run_LayoutChangeBothColorSchemeNotEqual_SendRequestToHMI_SUCCESS) { + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_Show), + Command::CommandSource::SOURCE_SDL_TO_HMI)) + .WillOnce(Return(true)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kConnectionKey)); + EXPECT_CALL(*mock_app_, WindowIdExists(kCurrentWindowID)) + .WillOnce(Return(true)); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + const auto current_day_color_scheme = CreateColorScheme(kNewDayColorRGB); + ON_CALL(*mock_app_, day_color_scheme(kCurrentWindowID)) + .WillByDefault(Return(current_day_color_scheme)); + const auto current_night_color_scheme = CreateColorScheme(kNewNightColorRGB); + ON_CALL(*mock_app_, night_color_scheme(kCurrentWindowID)) + .WillByDefault(Return(current_night_color_scheme)); + ON_CALL(*mock_app_, window_layout(kCurrentWindowID)) + .WillByDefault(Return(kCurrentTemplatelayout)); + + auto msg = CreateMessageWithTemplateLayout(kNewTemplateLayout); + + auto command(CreateCommand<ShowRequest>(msg)); + ASSERT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(ShowRequestTest, OnEvent_SuccessResultCode_ExpectSetWindowLayoutOnly) { + // Precondition + auto command = + SetupHelperLayout(kNewTemplateLayout, kNewDayColorRGB, kNewNightColorRGB); + ASSERT_TRUE(command->Init()); + command->Run(); + // Expectation + EXPECT_CALL(*mock_app_, + set_window_layout(kCurrentWindowID, kNewTemplateLayout)); + EXPECT_CALL(*mock_app_, set_day_color_scheme(_, _)); + EXPECT_CALL(*mock_app_, set_night_color_scheme(_, _)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + CheckMessageToMobile(mobile_apis::Result::SUCCESS, true), + Command::CommandSource::SOURCE_SDL)); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + + auto msg = CreateMessage(); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::SUCCESS; + (*msg)[am::strings::msg_params] = SmartObject(smart_objects::SmartType_Map); + + Event event(hmi_apis::FunctionID::UI_Show); + event.set_smart_object(*msg); + + command->on_event(event); +} + +TEST_F(ShowRequestTest, + OnEvent_SuccessResultCode_ExpectSetWindowLayoutAndSetDayColorScheme) { + // Precondition + auto command = SetupHelperLayout( + kNewTemplateLayout, kCurrentDayColorRGB, kNewNightColorRGB); + ASSERT_TRUE(command->Init()); + command->Run(); + // Expectation + EXPECT_CALL(*mock_app_, + set_window_layout(kCurrentWindowID, kNewTemplateLayout)); + EXPECT_CALL(*mock_app_, + set_day_color_scheme(kCurrentWindowID, + CreateColorScheme(kCurrentDayColorRGB))); + EXPECT_CALL(*mock_app_, set_night_color_scheme(_, _)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + CheckMessageToMobile(mobile_apis::Result::SUCCESS, true), + Command::CommandSource::SOURCE_SDL)); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + + auto msg = CreateMessage(); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::SUCCESS; + (*msg)[am::strings::msg_params] = SmartObject(smart_objects::SmartType_Map); + + Event event(hmi_apis::FunctionID::UI_Show); + event.set_smart_object(*msg); + + command->on_event(event); +} + +TEST_F(ShowRequestTest, + OnEvent_SuccessResultCode_ExpectSetWindowLayoutAndBothColorScheme) { + // Precondition + auto command = SetupHelperLayout( + kNewTemplateLayout, kCurrentDayColorRGB, kCurrentNightColorRGB); + ASSERT_TRUE(command->Init()); + command->Run(); + // Expectation + EXPECT_CALL(*mock_app_, + set_window_layout(kCurrentWindowID, kNewTemplateLayout)); + EXPECT_CALL(*mock_app_, + set_day_color_scheme(kCurrentWindowID, + CreateColorScheme(kCurrentDayColorRGB))); + EXPECT_CALL(*mock_app_, + set_night_color_scheme(kCurrentWindowID, + CreateColorScheme(kCurrentNightColorRGB))); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + CheckMessageToMobile(mobile_apis::Result::SUCCESS, true), + Command::CommandSource::SOURCE_SDL)); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + + auto msg = CreateMessage(); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::SUCCESS; + (*msg)[am::strings::msg_params] = SmartObject(smart_objects::SmartType_Map); + + Event event(hmi_apis::FunctionID::UI_Show); + event.set_smart_object(*msg); + command->on_event(event); +} + +TEST_F(ShowRequestTest, + OnEvent_SuccessResultCode_ExpectBothColorSchemeWithoutSetWindowLayout) { + // Precondition + auto command = SetupHelperLayout( + kCurrentTemplatelayout, kCurrentDayColorRGB, kCurrentNightColorRGB); + ASSERT_TRUE(command->Init()); command->Run(); + // Expectation + EXPECT_CALL(*mock_app_, set_window_layout(_, _)).Times(0); + EXPECT_CALL(*mock_app_, + set_day_color_scheme(kCurrentWindowID, + CreateColorScheme(kCurrentDayColorRGB))); + EXPECT_CALL(*mock_app_, + set_night_color_scheme(kCurrentWindowID, + CreateColorScheme(kCurrentNightColorRGB))); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + CheckMessageToMobile(mobile_apis::Result::SUCCESS, true), + Command::CommandSource::SOURCE_SDL)); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + + auto msg = CreateMessage(); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::SUCCESS; + (*msg)[am::strings::msg_params] = SmartObject(smart_objects::SmartType_Map); + + Event event(hmi_apis::FunctionID::UI_Show); + event.set_smart_object(*msg); + + command->on_event(event); } TEST_F(ShowRequestTest, OnEvent_SuccessResultCode_SUCCESS) { @@ -931,7 +1346,7 @@ TEST_F(ShowRequestTest, OnEvent_SuccessResultCode_SUCCESS) { event.set_smart_object(*msg); EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(mock_app_)); - + ASSERT_TRUE(command->Init()); command->on_event(event); } @@ -957,6 +1372,10 @@ TEST_F(ShowRequestTest, OnEvent_WrongFunctionID_Canceled) { MessageSharedPtr msg = CreateMessage(); (*msg)[am::strings::params][am::hmi_response::code] = mobile_apis::Result::SUCCESS; + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); 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 786f2b6bd1..f3bfe12ab1 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 @@ -162,7 +162,7 @@ TEST_F(SubscribeButtonRequestTest, Run_IsSubscribedToButton_UNSUCCESS) { (*button_caps_ptr)[0][am::hmi_response::button_name] = kButtonName; ON_CALL(mock_hmi_capabilities_, button_capabilities()) - .WillByDefault(Return(button_caps_ptr.get())); + .WillByDefault(Return(button_caps_ptr)); ON_CALL(*app, IsSubscribedToButton(_)).WillByDefault(Return(true)); @@ -193,7 +193,7 @@ TEST_F(SubscribeButtonRequestTest, Run_SUCCESS) { (*button_caps_ptr)[0][am::hmi_response::button_name] = kButtonName; ON_CALL(mock_hmi_capabilities_, button_capabilities()) - .WillByDefault(Return(button_caps_ptr.get())); + .WillByDefault(Return(button_caps_ptr)); ON_CALL(*app, IsSubscribedToButton(_)).WillByDefault(Return(false)); @@ -240,7 +240,7 @@ TEST_F(SubscribeButtonRequestTest, Run_NAV_SUCCESS) { (*button_caps_ptr)[0][am::hmi_response::button_name] = kButtonName; ON_CALL(mock_hmi_capabilities_, button_capabilities()) - .WillByDefault(Return(button_caps_ptr.get())); + .WillByDefault(Return(button_caps_ptr)); ON_CALL(*app, IsSubscribedToButton(_)).WillByDefault(Return(false)); @@ -289,7 +289,7 @@ TEST_F(SubscribeButtonRequestTest, Run_SUCCESS_App_Base_RPC_Version) { mobile_apis::ButtonName::PLAY_PAUSE; ON_CALL(mock_hmi_capabilities_, button_capabilities()) - .WillByDefault(Return(button_caps_ptr.get())); + .WillByDefault(Return(button_caps_ptr)); ON_CALL(*app, IsSubscribedToButton(_)).WillByDefault(Return(false)); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/system_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/system_request_test.cc index 7351cd67d3..211888d6be 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/system_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/system_request_test.cc @@ -74,6 +74,7 @@ const std::string kAppStorageFolder = "fake-storage"; const std::string kSystemFilesPath = "/fake/system/files"; const std::string kFileName = "Filename"; const uint32_t kHmiAppId = 3u; +const connection_handler::DeviceHandle kDeviceId = 1u; } // namespace class SystemRequestTest @@ -99,13 +100,15 @@ class SystemRequestTest ON_CALL(*mock_app_, policy_app_id()).WillByDefault(Return(kAppPolicyId)); ON_CALL(*mock_app_, folder_name()).WillByDefault(Return(kAppFolderName)); ON_CALL(*mock_app_, hmi_app_id()).WillByDefault(Return(kHmiAppId)); + ON_CALL(*mock_app_, device()).WillByDefault(Return(kDeviceId)); ON_CALL(app_mngr_settings_, system_files_path()) .WillByDefault(ReturnRef(kSystemFilesPath)); ON_CALL(app_mngr_settings_, app_storage_folder()) .WillByDefault(ReturnRef(kAppStorageFolder)); - ON_CALL(mock_policy_handler_, IsRequestTypeAllowed(kAppPolicyId, _)) + ON_CALL(mock_policy_handler_, + IsRequestTypeAllowed(kDeviceId, kAppPolicyId, _)) .WillByDefault(Return(true)); } @@ -146,9 +149,10 @@ TEST_F(SystemRequestTest, PreConditions(); - EXPECT_CALL(mock_policy_handler_, - IsRequestTypeAllowed(kAppPolicyId, - mobile_apis::RequestType::OEM_SPECIFIC)) + EXPECT_CALL( + mock_policy_handler_, + IsRequestTypeAllowed( + kDeviceId, kAppPolicyId, mobile_apis::RequestType::OEM_SPECIFIC)) .WillOnce(Return(true)); EXPECT_CALL(mock_policy_handler_, @@ -191,9 +195,10 @@ TEST_F( PreConditions(); - EXPECT_CALL(mock_policy_handler_, - IsRequestTypeAllowed(kAppPolicyId, - mobile_apis::RequestType::OEM_SPECIFIC)) + EXPECT_CALL( + mock_policy_handler_, + IsRequestTypeAllowed( + kDeviceId, kAppPolicyId, mobile_apis::RequestType::OEM_SPECIFIC)) .WillOnce(Return(true)); EXPECT_CALL(mock_policy_handler_, @@ -216,9 +221,10 @@ TEST_F(SystemRequestTest, Run_RequestTypeDisallowed_SendDisallowedResponse) { PreConditions(); - EXPECT_CALL(mock_policy_handler_, - IsRequestTypeAllowed(kAppPolicyId, - mobile_apis::RequestType::OEM_SPECIFIC)) + EXPECT_CALL( + mock_policy_handler_, + IsRequestTypeAllowed( + kDeviceId, kAppPolicyId, mobile_apis::RequestType::OEM_SPECIFIC)) .WillOnce(Return(false)); ExpectManageMobileCommandWithResultCode(mobile_apis::Result::DISALLOWED); @@ -241,9 +247,9 @@ TEST_F(SystemRequestTest, Run_RequestType_IconURL_Success) { const std::vector<uint8_t> binary_data = {1u, 2u}; (*msg)[am::strings::params][am::strings::binary_data] = binary_data; - EXPECT_CALL( - mock_policy_handler_, - IsRequestTypeAllowed(kAppPolicyId, mobile_apis::RequestType::ICON_URL)) + EXPECT_CALL(mock_policy_handler_, + IsRequestTypeAllowed( + kDeviceId, kAppPolicyId, mobile_apis::RequestType::ICON_URL)) .WillOnce(Return(true)); EXPECT_CALL(app_mngr_settings_, app_icons_folder()) .WillOnce(ReturnRef(kAppStorageFolder)); 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 98d20dbbc4..5735610051 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 @@ -70,7 +70,7 @@ TEST_F(UnsubscribeButtonRequestTest, MessageSharedPtr button_caps_ptr(CreateMessage(smart_objects::SmartType_Map)); (*button_caps_ptr)[0][am::hmi_response::button_name] = kButtonId; EXPECT_CALL(mock_hmi_capabilities_, button_capabilities()) - .WillOnce(Return(button_caps_ptr.get())); + .WillOnce(Return(button_caps_ptr)); MockAppPtr mock_app(CreateMockApp()); EXPECT_CALL(app_mngr_, application(kConnectionKey)) @@ -106,7 +106,7 @@ TEST_F(UnsubscribeButtonRequestTest, MessageSharedPtr button_caps_ptr(CreateMessage(smart_objects::SmartType_Map)); EXPECT_CALL(mock_hmi_capabilities_, button_capabilities()) - .WillOnce(Return(button_caps_ptr.get())); + .WillOnce(Return(button_caps_ptr)); EXPECT_CALL(mock_rpc_service_, ManageMobileCommand( @@ -129,7 +129,7 @@ TEST_F(UnsubscribeButtonRequestTest, Run_SUCCESS) { MessageSharedPtr button_caps_ptr(CreateMessage(smart_objects::SmartType_Map)); (*button_caps_ptr)[0][am::hmi_response::button_name] = kButtonId; EXPECT_CALL(mock_hmi_capabilities_, button_capabilities()) - .WillOnce(Return(button_caps_ptr.get())); + .WillOnce(Return(button_caps_ptr)); MockAppPtr mock_app(CreateMockApp()); EXPECT_CALL(app_mngr_, application(kConnectionKey)) @@ -172,7 +172,7 @@ TEST_F(UnsubscribeButtonRequestTest, Run_SUCCESS_Base_RPC_Version) { mobile_apis::ButtonName::PLAY_PAUSE; EXPECT_CALL(mock_hmi_capabilities_, button_capabilities()) - .WillRepeatedly(Return(button_caps_ptr.get())); + .WillRepeatedly(Return(button_caps_ptr)); MockAppPtr mock_app(CreateMockApp()); EXPECT_CALL(app_mngr_, application(kConnectionKey)) 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 0e556a6993..8c29cccfff 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,18 +45,25 @@ 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 Utils + jsoncpp + connectionHandler ) if(ENABLE_LOG) list(APPEND LIBRARIES log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) endif() -add_library("vehicle_info_plugin" SHARED ${MOBILE_COMMANDS} ${HMI_COMMANDS} ${VEHICLE_INFO_PLUGIN_SOURCES}) -target_link_libraries("vehicle_info_plugin" ${LIBRARIES}) +add_library("vehicle_info_plugin_static" ${MOBILE_COMMANDS} ${HMI_COMMANDS} ${VEHICLE_INFO_PLUGIN_SOURCES}) +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) + set(INSTALL_DESTINATION bin) diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/on_vi_vehicle_data_notification.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/on_vi_vehicle_data_notification.h index 103bfb56dc..be2f123f4a 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/on_vi_vehicle_data_notification.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/on_vi_vehicle_data_notification.h @@ -35,6 +35,7 @@ #include "application_manager/application_manager.h" #include "application_manager/commands/notification_from_hmi.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -55,10 +56,7 @@ class OnVIVehicleDataNotification **/ OnVIVehicleDataNotification( 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); + const VehicleInfoCommandParams& params); /** * @brief OnVIVehicleDataNotification class destructor diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_diagnostic_message_request.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_diagnostic_message_request.h index 162a6b338a..6ae6d1f7f6 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_diagnostic_message_request.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_diagnostic_message_request.h @@ -34,6 +34,7 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_VI_DIAGNOSTIC_MESSAGE_REQUEST_H_ #include "application_manager/commands/request_to_hmi.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -52,10 +53,7 @@ class VIDiagnosticMessageRequest : public app_mngr::commands::RequestToHMI { **/ VIDiagnosticMessageRequest( 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); + const VehicleInfoCommandParams& params); /** * @brief VIDiagnosticMessageRequest class destructor diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_diagnostic_message_response.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_diagnostic_message_response.h index a427bbe362..9b172b9e74 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_diagnostic_message_response.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_diagnostic_message_response.h @@ -34,6 +34,7 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_VI_DIAGNOSTIC_MESSAGE_RESPONSE_H_ #include "application_manager/commands/response_from_hmi.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -52,10 +53,7 @@ class VIDiagnosticMessageResponse : public app_mngr::commands::ResponseFromHMI { **/ VIDiagnosticMessageResponse( 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); + const VehicleInfoCommandParams& params); /** * @brief VIDiagnosticMessageResponse class destructor diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_dtcs_request.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_dtcs_request.h index df9e84eab4..c77464835b 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_dtcs_request.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_dtcs_request.h @@ -34,6 +34,7 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_VI_GET_DTCS_REQUEST_H_ #include "application_manager/commands/request_to_hmi.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -51,10 +52,7 @@ class VIGetDTCsRequest : public app_mngr::commands::RequestToHMI { * @param message Incoming SmartObject message **/ VIGetDTCsRequest(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); + const VehicleInfoCommandParams& params); /** * @brief VIGetDTCsRequest class destructor diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_dtcs_response.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_dtcs_response.h index d8351c1a61..f1ddcbe373 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_dtcs_response.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_dtcs_response.h @@ -34,6 +34,7 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_VI_GET_DTCS_RESPONSE_H_ #include "application_manager/commands/response_from_hmi.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -51,10 +52,7 @@ class VIGetDTCsResponse : public app_mngr::commands::ResponseFromHMI { * @param message Incoming SmartObject message **/ VIGetDTCsResponse(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); + const VehicleInfoCommandParams& params); /** * @brief VIGetDTCsResponse class destructor diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_vehicle_data_request.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_vehicle_data_request.h index 437e7c8933..bce49f8201 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_vehicle_data_request.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_vehicle_data_request.h @@ -34,6 +34,8 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_VI_GET_VEHICLE_DATA_REQUEST_H_ #include "application_manager/commands/request_to_hmi.h" +#include "vehicle_info_plugin/custom_vehicle_data_manager.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -51,10 +53,7 @@ class VIGetVehicleDataRequest : public app_mngr::commands::RequestToHMI { * @param message Incoming SmartObject message **/ VIGetVehicleDataRequest(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); + const VehicleInfoCommandParams& params); /** * @brief VIGetVehicleDataRequest class destructor @@ -67,6 +66,8 @@ class VIGetVehicleDataRequest : public app_mngr::commands::RequestToHMI { virtual void Run(); private: + CustomVehicleDataManager& custom_vehicle_data_manager_; + DISALLOW_COPY_AND_ASSIGN(VIGetVehicleDataRequest); }; diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_vehicle_data_response.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_vehicle_data_response.h index 651a0af79c..7504168aec 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_vehicle_data_response.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_vehicle_data_response.h @@ -35,6 +35,7 @@ #include "application_manager/application_manager.h" #include "application_manager/commands/response_from_hmi.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -52,10 +53,7 @@ class VIGetVehicleDataResponse : public app_mngr::commands::ResponseFromHMI { * @param message Incoming SmartObject message **/ VIGetVehicleDataResponse(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); + const VehicleInfoCommandParams& params); /** * @brief VIGetVehicleDataResponse class destructor diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_vehicle_type_request.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_vehicle_type_request.h index 1166d3f774..7f2e8389ad 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_vehicle_type_request.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_vehicle_type_request.h @@ -34,6 +34,7 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_VI_GET_VEHICLE_TYPE_REQUEST_H_ #include "application_manager/commands/request_to_hmi.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -51,10 +52,7 @@ class VIGetVehicleTypeRequest : public app_mngr::commands::RequestToHMI { * @param message Incoming SmartObject message **/ VIGetVehicleTypeRequest(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); + const VehicleInfoCommandParams& params); /** * @brief VIGetVehicleTypeRequest class destructor diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_vehicle_type_response.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_vehicle_type_response.h index 00c1944c0f..f71eda8077 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_vehicle_type_response.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_vehicle_type_response.h @@ -34,6 +34,7 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_VI_GET_VEHICLE_TYPE_RESPONSE_H_ #include "application_manager/commands/response_from_hmi.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -50,12 +51,8 @@ class VIGetVehicleTypeResponse : public app_mngr::commands::ResponseFromHMI { * * @param message Incoming SmartObject message **/ - VIGetVehicleTypeResponse( - const app_mngr::commands::MessageSharedPtr& message, - app_mngr::ApplicationManager& application_manager, - application_manager::rpc_service::RPCService& rpc_service, - application_manager::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle); + VIGetVehicleTypeResponse(const app_mngr::commands::MessageSharedPtr& message, + const VehicleInfoCommandParams& params); /** * @brief VIGetVehicleTypeResponse class destructor diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_is_ready_request.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_is_ready_request.h index 7a8ca3a4b6..fa9bfebad4 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_is_ready_request.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_is_ready_request.h @@ -34,6 +34,7 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_VI_IS_READY_REQUEST_H_ #include "application_manager/commands/request_to_hmi.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -52,10 +53,7 @@ class VIIsReadyRequest : public app_mngr::commands::RequestToHMI, * @param message Incoming SmartObject message **/ VIIsReadyRequest(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); + const VehicleInfoCommandParams& params); /** * @brief VIIsReadyRequest class destructor diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_is_ready_response.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_is_ready_response.h index e0ff20b8bb..f87d9370f5 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_is_ready_response.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_is_ready_response.h @@ -35,6 +35,7 @@ #include "application_manager/application_manager.h" #include "application_manager/commands/response_from_hmi.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -52,10 +53,7 @@ class VIIsReadyResponse : public app_mngr::commands::ResponseFromHMI { * @param message Incoming SmartObject message **/ VIIsReadyResponse(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); + const VehicleInfoCommandParams& params); /** * @brief VIIsReadyResponse class destructor diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_read_did_request.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_read_did_request.h index 1e91a4c3af..63bbf10e41 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_read_did_request.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_read_did_request.h @@ -34,6 +34,7 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_VI_READ_DID_REQUEST_H_ #include "application_manager/commands/request_to_hmi.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -51,10 +52,7 @@ class VIReadDIDRequest : public app_mngr::commands::RequestToHMI { * @param message Incoming SmartObject message **/ VIReadDIDRequest(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); + const VehicleInfoCommandParams& params); /** * @brief VIReadDIDRequest class destructor diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_read_did_response.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_read_did_response.h index f659f7ae87..307960e145 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_read_did_response.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_read_did_response.h @@ -34,6 +34,7 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_VI_READ_DID_RESPONSE_H_ #include "application_manager/commands/response_from_hmi.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -51,10 +52,7 @@ class VIReadDIDResponse : public app_mngr::commands::ResponseFromHMI { * @param message Incoming SmartObject message **/ VIReadDIDResponse(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); + const VehicleInfoCommandParams& params); /** * @brief VIReadDIDResponse class destructor diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_subscribe_vehicle_data_request.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_subscribe_vehicle_data_request.h index dab5989e9e..0e91006e52 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_subscribe_vehicle_data_request.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_subscribe_vehicle_data_request.h @@ -34,6 +34,8 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_VI_SUBSCRIBE_VEHICLE_DATA_REQUEST_H_ #include "application_manager/commands/request_to_hmi.h" +#include "vehicle_info_plugin/custom_vehicle_data_manager.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -52,10 +54,7 @@ class VISubscribeVehicleDataRequest : public app_mngr::commands::RequestToHMI { **/ VISubscribeVehicleDataRequest( 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); + const VehicleInfoCommandParams& params); /** * @brief VISubscribeVehicleDataRequest class destructor @@ -68,6 +67,8 @@ class VISubscribeVehicleDataRequest : public app_mngr::commands::RequestToHMI { virtual void Run(); private: + CustomVehicleDataManager& custom_vehicle_data_manager_; + DISALLOW_COPY_AND_ASSIGN(VISubscribeVehicleDataRequest); }; diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_subscribe_vehicle_data_response.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_subscribe_vehicle_data_response.h index 8eea8d0cfa..523867d87e 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_subscribe_vehicle_data_response.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_subscribe_vehicle_data_response.h @@ -34,6 +34,7 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_VI_SUBSCRIBE_VEHICLE_DATA_RESPONSE_H_ #include "application_manager/commands/response_from_hmi.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -53,10 +54,7 @@ class VISubscribeVehicleDataResponse **/ VISubscribeVehicleDataResponse( 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); + const VehicleInfoCommandParams& params); /** * @brief VISubscribeVehicleDataResponse class destructor diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_unsubscribe_vehicle_data_request.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_unsubscribe_vehicle_data_request.h index a8ebf34ea2..4e3cc59c2e 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_unsubscribe_vehicle_data_request.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_unsubscribe_vehicle_data_request.h @@ -34,6 +34,8 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_VI_UNSUBSCRIBE_VEHICLE_DATA_REQUEST_H_ #include "application_manager/commands/request_to_hmi.h" +#include "vehicle_info_plugin/custom_vehicle_data_manager.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -53,10 +55,7 @@ class VIUnsubscribeVehicleDataRequest **/ VIUnsubscribeVehicleDataRequest( 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); + const VehicleInfoCommandParams& params); /** * @brief VIUnsubscribeVehicleDataRequest class destructor @@ -69,6 +68,8 @@ class VIUnsubscribeVehicleDataRequest virtual void Run(); private: + CustomVehicleDataManager& custom_vehicle_data_manager_; + DISALLOW_COPY_AND_ASSIGN(VIUnsubscribeVehicleDataRequest); }; diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_unsubscribe_vehicle_data_response.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_unsubscribe_vehicle_data_response.h index 780d1e9eae..e8f2267ce6 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_unsubscribe_vehicle_data_response.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_unsubscribe_vehicle_data_response.h @@ -34,6 +34,7 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_VI_UNSUBSCRIBE_VEHICLE_DATA_RESPONSE_H_ #include "application_manager/commands/response_from_hmi.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -53,10 +54,7 @@ class VIUnsubscribeVehicleDataResponse **/ VIUnsubscribeVehicleDataResponse( 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); + const VehicleInfoCommandParams& params); /** * @brief VIUnsubscribeVehicleDataResponse class destructor diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/diagnostic_message_request.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/diagnostic_message_request.h index bd9ce31325..56f0e39621 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/diagnostic_message_request.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/diagnostic_message_request.h @@ -36,6 +36,7 @@ #include "application_manager/commands/command_request_impl.h" #include "utils/macro.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -53,10 +54,7 @@ class DiagnosticMessageRequest : public app_mngr::commands::CommandRequestImpl { * @param message Incoming SmartObject message **/ DiagnosticMessageRequest(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); + const VehicleInfoCommandParams& params); /** * @brief DiagnosticMessageRequest class destructor diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/diagnostic_message_response.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/diagnostic_message_response.h index 7b6364fe41..5308551f5a 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/diagnostic_message_response.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/diagnostic_message_response.h @@ -36,6 +36,7 @@ #include "application_manager/commands/command_response_impl.h" #include "utils/macro.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -54,10 +55,7 @@ class DiagnosticMessageResponse * @param message Incoming SmartObject message **/ DiagnosticMessageResponse(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); + const VehicleInfoCommandParams& params); /** * @brief DiagnosticMessageResponse class destructor diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/get_dtcs_request.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/get_dtcs_request.h index 9175900610..562d7f236b 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/get_dtcs_request.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/get_dtcs_request.h @@ -36,6 +36,7 @@ #include "application_manager/commands/command_request_impl.h" #include "utils/macro.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -53,10 +54,7 @@ class GetDTCsRequest : public app_mngr::commands::CommandRequestImpl { * @param message Incoming SmartObject message **/ GetDTCsRequest(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); + const VehicleInfoCommandParams& params); /** * @brief GetDTCsRequest class destructor diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/get_dtcs_response.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/get_dtcs_response.h index 473174fd0d..52836e895f 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/get_dtcs_response.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/get_dtcs_response.h @@ -36,6 +36,7 @@ #include "application_manager/commands/command_response_impl.h" #include "utils/macro.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -53,10 +54,7 @@ class GetDTCsResponse : public app_mngr::commands::CommandResponseImpl { * @param message Incoming SmartObject message **/ GetDTCsResponse(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); + const VehicleInfoCommandParams& params); /** * @brief GetDTCsResponse class destructor diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/get_vehicle_data_request.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/get_vehicle_data_request.h index ff04ca1e2c..8a594b0647 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/get_vehicle_data_request.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/get_vehicle_data_request.h @@ -36,12 +36,11 @@ #include "application_manager/commands/command_request_impl.h" #include "utils/macro.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; -class SmartObject; - namespace commands { /** @@ -55,10 +54,7 @@ class GetVehicleDataRequest : public app_mngr::commands::CommandRequestImpl { * @param message Incoming SmartObject message **/ GetVehicleDataRequest(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); + const VehicleInfoCommandParams& params); /** * @brief GetVehicleDataRequest class destructor @@ -73,6 +69,18 @@ class GetVehicleDataRequest : public app_mngr::commands::CommandRequestImpl { protected: virtual void on_event(const app_mngr::event_engine::Event& event); + private: + /** + * @brief CheckFrequency check if mobile does not spam SDL with frequent + * GetVehicleData requests + * @return + */ + bool CheckFrequency(application_manager::Application& app); + + std::set<std::string> pending_vehicle_data_; + + CustomVehicleDataManager& custom_vehicle_data_manager_; + DISALLOW_COPY_AND_ASSIGN(GetVehicleDataRequest); }; diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/get_vehicle_data_response.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/get_vehicle_data_response.h index 25fd27b67c..8d9722b2b6 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/get_vehicle_data_response.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/get_vehicle_data_response.h @@ -36,7 +36,7 @@ #include "application_manager/commands/command_response_impl.h" #include "utils/macro.h" - +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -53,10 +53,7 @@ class GetVehicleDataResponse : public app_mngr::commands::CommandResponseImpl { * @param message Incoming SmartObject message **/ GetVehicleDataResponse(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); + const VehicleInfoCommandParams& params); /** * @brief GetVehicleDataResponse class destructor diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/on_vehicle_data_notification.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/on_vehicle_data_notification.h index ce1b732775..9163e78b5e 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/on_vehicle_data_notification.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/on_vehicle_data_notification.h @@ -37,6 +37,8 @@ #include "application_manager/application.h" #include "application_manager/commands/command_notification_impl.h" #include "utils/macro.h" +#include "vehicle_info_plugin/custom_vehicle_data_manager.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -56,10 +58,7 @@ class OnVehicleDataNotification * @param message Incoming SmartObject message **/ OnVehicleDataNotification(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); + const VehicleInfoCommandParams& params); /** * @brief OnVehicleDataNotification class destructor @@ -79,6 +78,8 @@ class OnVehicleDataNotification */ void SendVehicleData(app_mngr::ApplicationConstSharedPtr app); + CustomVehicleDataManager& custom_vehicle_data_manager_; + DISALLOW_COPY_AND_ASSIGN(OnVehicleDataNotification); }; diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/read_did_request.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/read_did_request.h index d006cf02ef..8566075504 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/read_did_request.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/read_did_request.h @@ -36,7 +36,7 @@ #include "application_manager/commands/command_request_impl.h" #include "utils/macro.h" - +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -53,10 +53,7 @@ class ReadDIDRequest : public app_mngr::commands::CommandRequestImpl { * @param message Incoming SmartObject message **/ ReadDIDRequest(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); + const VehicleInfoCommandParams& params); /** * @brief ReadDIDRequest class destructor diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/read_did_response.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/read_did_response.h index d3c0e14c93..30e5aa45de 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/read_did_response.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/read_did_response.h @@ -36,7 +36,7 @@ #include "application_manager/commands/command_response_impl.h" #include "utils/macro.h" - +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -53,10 +53,7 @@ class ReadDIDResponse : public app_mngr::commands::CommandResponseImpl { * @param message Incoming SmartObject message **/ ReadDIDResponse(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); + const VehicleInfoCommandParams& params); /** * @brief ReadDIDResponse class destructor diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/subscribe_vehicle_data_request.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/subscribe_vehicle_data_request.h index 2671173ba3..663e64f2a0 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/subscribe_vehicle_data_request.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/subscribe_vehicle_data_request.h @@ -40,7 +40,9 @@ #include "application_manager/application.h" #include "application_manager/commands/command_request_impl.h" #include "utils/macro.h" +#include "vehicle_info_plugin/custom_vehicle_data_manager.h" #include "vehicle_info_plugin/vehicle_info_app_extension.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -60,10 +62,7 @@ class SubscribeVehicleDataRequest **/ SubscribeVehicleDataRequest( 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); + VehicleInfoCommandParams params); /** * @brief SubscribeButtonCommandRequest class destructor @@ -94,7 +93,7 @@ class SubscribeVehicleDataRequest * @return true, if there are registered apps subscribed for VI parameter, * otherwise - false */ - bool IsSomeoneSubscribedFor(const uint32_t param_id) const; + bool IsSomeoneSubscribedFor(const std::string& param_name) const; /** * @brief Adds VI parameters being subscribed by another or the same app to @@ -104,14 +103,13 @@ class SubscribeVehicleDataRequest void AddAlreadySubscribedVI(smart_objects::SmartObject& msg_params) const; /** - * @brief Removes subscription for VI parameters which subsription attempt - * returned an error + * @brief Actual subscription to pending vehicle data after successful + * response from HMI * @param app Pointer to application sent subscribe request * @param msg_params 'message_parameters' response section reference */ - void UnsubscribeFailedSubscriptions( - app_mngr::ApplicationSharedPtr app, - const smart_objects::SmartObject& msg_params) const; + bool SubscribePendingVehicleData(app_mngr::ApplicationSharedPtr app, + smart_objects::SmartObject& msg_params); /** * @brief Checks if current application and other applications @@ -134,6 +132,43 @@ class SubscribeVehicleDataRequest bool& out_result); /** + * @brief ConvertResponseToRequestName convert RPCSpec vehicle data names + * from response naming to request naming. + * This is workaround for cluster mode. + * Parameter named in request message as `cluster_mode` and in response + * message as `cluster_mode_status` + * @param name mobile RPCSpec vehicle data name + * @return hmi RPCSpec vehicle data name + */ + const std::string& ConvertResponseToRequestName(const std::string& name); + + /** + * @brief ConvertRequestToResponseName convert RPCSpec vehicle data names from + * request to response + * * This is workaround for cluster mode. + * Parameter named in request message as `cluster_mode` and in response + * message as `cluster_mode_status` + * @param name mobile RPCSpec vehicle data name + * @return hmi RPCSpec vehicle data name + */ + const std::string& ConvertRequestToResponseName(const std::string& name); + + /** + * @brief Appends data types for vehicle data in response to mobile + * @param msg_params 'message_parameters' response section reference + */ + void AppendDataTypesToMobileResponse( + smart_objects::SmartObject& msg_params) const; + + /** + * @brief Checks subscription status of certain vehicle_item + * @param vi_name name of vehicle item to be checked + * @param msg_params 'message_parameters' response section reference + */ + bool CheckSubscriptionStatus(std::string vi_name, + const smart_objects::SmartObject& msg_params); + + /** * @brief VI parameters which had been already subscribed by another apps * befor particular app subscribed for these parameters */ @@ -149,6 +184,8 @@ class SubscribeVehicleDataRequest */ VehicleInfoSubscriptions vi_waiting_for_subscribe_; + CustomVehicleDataManager& custom_vehicle_data_manager_; + DISALLOW_COPY_AND_ASSIGN(SubscribeVehicleDataRequest); }; diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/subscribe_vehicle_data_response.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/subscribe_vehicle_data_response.h index 2212af0846..39af8b019b 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/subscribe_vehicle_data_response.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/subscribe_vehicle_data_response.h @@ -36,7 +36,7 @@ #include "application_manager/commands/command_response_impl.h" #include "utils/macro.h" - +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -55,10 +55,7 @@ class SubscribeVehicleDataResponse **/ SubscribeVehicleDataResponse( 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); + const VehicleInfoCommandParams& params); /** * @brief UnsubscribeVehicleDataCommandRequest class destructor diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/unsubscribe_vehicle_data_request.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/unsubscribe_vehicle_data_request.h index b246dbc9ef..4f2a01244f 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/unsubscribe_vehicle_data_request.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/unsubscribe_vehicle_data_request.h @@ -37,7 +37,9 @@ #include "application_manager/application.h" #include "application_manager/commands/command_request_impl.h" #include "utils/macro.h" +#include "vehicle_info_plugin/custom_vehicle_data_manager.h" #include "vehicle_info_plugin/vehicle_info_app_extension.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -57,10 +59,7 @@ class UnsubscribeVehicleDataRequest **/ UnsubscribeVehicleDataRequest( 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); + const VehicleInfoCommandParams& params); /** * @brief UnsubscribeVehicleDataRequest class destructor @@ -91,7 +90,7 @@ class UnsubscribeVehicleDataRequest * @return true, if there are registered apps subscribed for VI parameter, * otherwise - false */ - bool IsSomeoneSubscribedFor(const uint32_t param_id) const; + bool IsSomeoneSubscribedFor(const std::string& param_name) const; /** * @brief Adds VI parameters being unsubscribed by another or the same app to @@ -101,16 +100,67 @@ class UnsubscribeVehicleDataRequest void AddAlreadyUnsubscribedVI(smart_objects::SmartObject& response) const; /** + * @brief Actual unsubscription from all pending vehicle data. To be called + * after successful HMI response + * @param app shared pointer to application, which initialized unsubscription + * @param msg_params 'message_params' response section reference + */ + bool UnsubscribePendingVehicleData( + app_mngr::ApplicationSharedPtr app, + const smart_objects::SmartObject& msg_params); + + /** + * @brief ConvertRequestToResponseName convert RPCSpec vehicle data names + * from hmi api to mobile api + * @param name mobile RPCSpec vehicle data name + * @return hmi RPCSpec vehicle data name + */ + const std::string& ConvertRequestToResponseName(const std::string& name); + + /** + * @brief ConvertResponseToRequestName convert RPCSpec vehicle data names + * from hmi api to mobile api + * @param name mobile RPCSpec vehicle data name + * @return hmi RPCSpec vehicle data name + */ + const std::string& ConvertResponseToRequestName(const std::string& name); + + /** + * @brief Appends data types for vehicle data in response to mobile + * @param msg_params 'message_parameters' response section reference + */ + void AppendDataTypesToMobileResponse( + smart_objects::SmartObject& msg_params) const; + + /** + * @brief Checks subscription status of certain vehicle_item + * @param key name of vehicle item to be checked + * @param msg_params 'message_parameters' response section reference + */ + bool CheckSubscriptionStatus(std::string key, + const smart_objects::SmartObject& msg_params); + + smart_objects::SmartObject response_params_; + + /** * @brief VI parameters which still being subscribed by another apps after * particular app had been unsubscribed from these parameters */ VehicleInfoSubscriptions vi_still_subscribed_by_another_apps_; /** - * @brief VI parameters which had been unsubscribed already by particular app + * @brief VI parameters which had been unsubscribed already by particular + * app */ VehicleInfoSubscriptions vi_already_unsubscribed_by_this_app_; + /** + * @brief VI parameters to be unsubscribed after HMI response + */ + VehicleInfoSubscriptions vi_waiting_for_unsubscribe_; + + CustomVehicleDataManager& custom_vehicle_data_manager_; + DISALLOW_COPY_AND_ASSIGN(UnsubscribeVehicleDataRequest); }; diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/unsubscribe_vehicle_data_response.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/unsubscribe_vehicle_data_response.h index 67f09a68a8..f181e7f8c3 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/unsubscribe_vehicle_data_response.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/unsubscribe_vehicle_data_response.h @@ -36,7 +36,7 @@ #include "application_manager/commands/command_response_impl.h" #include "utils/macro.h" - +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -55,10 +55,7 @@ class UnsubscribeVehicleDataResponse **/ UnsubscribeVehicleDataResponse( 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); + const VehicleInfoCommandParams& params); /** * @brief UnsubscribeVehicleDataResponse class destructor diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/custom_vehicle_data_manager.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/custom_vehicle_data_manager.h new file mode 100644 index 0000000000..9cac76b954 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/custom_vehicle_data_manager.h @@ -0,0 +1,55 @@ +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_VEHICLE_INFO_PLUGIN_INCLUDE_VEHICLE_INFO_PLUGIN_CUSTOM_VEHICLE_DATA_MANAGER_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_VEHICLE_INFO_PLUGIN_INCLUDE_VEHICLE_INFO_PLUGIN_CUSTOM_VEHICLE_DATA_MANAGER_H_ +#include <set> +#include <string> + +#include "application_manager/plugin_manager/rpc_plugin.h" +#include "application_manager/rpc_handler.h" +#include "smart_objects/smart_object.h" + +namespace vehicle_info_plugin { + +namespace plugin_manager = application_manager::plugin_manager; + +class CustomVehicleDataManager { + public: + /** + * @brief Creates message params (nested if needed) to be sent to HMI + * according to vehicle data item schema + * @param item_names set of names of vehicle data items to be processed + * @return smartMap with prepared message params + */ + virtual smart_objects::SmartObject CreateHMIMessageParams( + const std::set<std::string>& item_names) = 0; + + /** + * @brief Gets data type of vehicle data item + * @param vehicle_data_item_name name of vehicle data + * @return data type of vehicle_data if one found, item name otherwise + */ + virtual std::string GetVehicleDataItemType( + const std::string& vehicle_data_item_name) const = 0; + + /** + * @brief Creates message params (nested if needed) to be sent to Mobile + * according to vehicle data item schema + * @param input_params message params received from hmi + */ + virtual void CreateMobileMessageParams( + smart_objects::SmartObject& msg_params) = 0; + + virtual void OnPolicyEvent(plugin_manager::PolicyEvent policy_event) = 0; + + virtual bool IsValidCustomVehicleDataName(const std::string& name) const = 0; + + /** + * @brief Checks whether custom vehicle data name was removed after the last + * PTU or not + * @param name vehicle item name to check + * @return true if vehicle data with this name was removed after the last PTU + */ + virtual bool IsRemovedCustomVehicleDataName( + const std::string& name) const = 0; +}; +} // namespace vehicle_info_plugin +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_VEHICLE_INFO_PLUGIN_INCLUDE_VEHICLE_INFO_PLUGIN_CUSTOM_VEHICLE_DATA_MANAGER_H_ diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/custom_vehicle_data_manager_impl.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/custom_vehicle_data_manager_impl.h new file mode 100644 index 0000000000..239c4edb90 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/custom_vehicle_data_manager_impl.h @@ -0,0 +1,103 @@ +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_VEHICLE_DATA_VALIDATION_MANAGER_IMPL_H +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_VEHICLE_DATA_VALIDATION_MANAGER_IMPL_H + +#include <boost/optional.hpp> + +#include "smart_objects/smart_object.h" +#include "vehicle_info_plugin/custom_vehicle_data_manager.h" + +namespace rpc { +namespace policy_table_interface_base { +class VehicleDataItem; +} +} // namespace rpc + +namespace policy { +class VehicleDataItemProvider; +} + +namespace vehicle_info_plugin { +namespace policy_table = rpc::policy_table_interface_base; +namespace plugin_manager = application_manager::plugin_manager; + +typedef boost::optional<const policy_table::VehicleDataItem> OptionalDataItem; +typedef std::set<std::string> VehicleInfoSubscriptions; + +class CustomVehicleDataManagerImpl : public CustomVehicleDataManager { + public: + CustomVehicleDataManagerImpl( + policy::VehicleDataItemProvider& vehicle_data_provider, + application_manager::rpc_service::RPCService& rpc_service); + + virtual smart_objects::SmartObject CreateHMIMessageParams( + const std::set<std::string>& item_names) OVERRIDE; + + std::string GetVehicleDataItemType( + const std::string& vehicle_data_item_name) const OVERRIDE; + + virtual void CreateMobileMessageParams( + smart_objects::SmartObject& msg_params) OVERRIDE; + + void OnPolicyEvent(plugin_manager::PolicyEvent policy_event) OVERRIDE; + + bool IsValidCustomVehicleDataName(const std::string& name) const OVERRIDE; + + bool IsRemovedCustomVehicleDataName(const std::string& name) const OVERRIDE; + + private: + class RPCParams { + public: + RPCParams() {} + ~RPCParams() {} + + void addBoolParam( + const std::pair<std::string, smart_objects::SMember>& param) { + rpc_params_bool_.insert(param); + } + void addVDRParam( + const std::pair<std::string, smart_objects::SMember>& param) { + rpc_params_vdr_.insert(param); + } + void addParam(const std::pair<std::string, smart_objects::SMember>& param) { + rpc_params_.insert(param); + } + + const std::map<std::string, smart_objects::SMember>& getBoolParams() { + return rpc_params_bool_; + } + const std::map<std::string, smart_objects::SMember>& getVDRParams() { + return rpc_params_vdr_; + } + const std::map<std::string, smart_objects::SMember>& getParams() { + return rpc_params_; + } + + private: + std::map<std::string, smart_objects::SMember> rpc_params_bool_; + std::map<std::string, smart_objects::SMember> rpc_params_vdr_; + std::map<std::string, smart_objects::SMember> rpc_params_; + }; + + /** + * @brief Updates vehicle data schemas according to policy update. + */ + void UpdateVehicleDataItems(); + + const OptionalDataItem FindSchemaByNameNonRecursive( + const std::string& name) const; + const OptionalDataItem FindRemovedSchemaByNameNonRecursive( + const std::string& name) const; + const OptionalDataItem FindSchemaByKeyNonRecursive( + const std::string& key) const; + const OptionalDataItem FindSchemaByNameRecursive( + const std::string& name) const; + const OptionalDataItem FindSchemaByKeyRecursive( + const std::string& name) const; + + policy::VehicleDataItemProvider& vehicle_data_provider_; + application_manager::rpc_service::RPCService& rpc_service_; +}; + +} // namespace vehicle_info_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_VEHICLE_DATA_VALIDATION_MANAGER_IMPL_H diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_data_item_schema.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_data_item_schema.h new file mode 100644 index 0000000000..5ea73e2dec --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_data_item_schema.h @@ -0,0 +1,115 @@ +#ifndef VEHICLE_DATA_ITEM_SCHEMA_H +#define VEHICLE_DATA_ITEM_SCHEMA_H +#include "policy/policy_table/types.h" +#include "smart_objects/always_false_schema_item.h" +#include "smart_objects/always_true_schema_item.h" +#include "smart_objects/array_schema_item.h" +#include "smart_objects/bool_schema_item.h" +#include "smart_objects/enum_schema_item.h" +#include "smart_objects/number_schema_item.h" +#include "smart_objects/object_schema_item.h" +#include "smart_objects/schema_item.h" +#include "smart_objects/schema_item_parameter.h" +#include "smart_objects/smart_object.h" +#include "smart_objects/string_schema_item.h" +#include "utils/logger.h" + +namespace vehicle_info_plugin { +namespace smart_objects = ns_smart_device_link::ns_smart_objects; +namespace policy_table = rpc::policy_table_interface_base; + +class VehicleDataItemSchema; +typedef std::shared_ptr<VehicleDataItemSchema> VehicleDataItemSchemaPtr; +typedef smart_objects::TSchemaItemParameter<policy_table::VehicleDataItem> + PolicyDataItem; + +/** + * @brief VehicleData schema item. + **/ +class VehicleDataItemSchema : public smart_objects::ISchemaItem { + public: + enum SchemaType { MOBILE = 0, HMI }; + + /** + * @brief Create a new schema item. + * @param PolicyDataItem& SchemaItem for VehicleDataItem elements. + * @return Shared pointer to a new schema item. + **/ + static VehicleDataItemSchemaPtr create(PolicyDataItem& policy_item, + SchemaType schema_type); + + /** + * @brief Validate smart object. + * @param Object Object to validate. + * @param report__ object for reporting errors during validation + * @param MessageVersion to check mobile RPC version against RPC Spec History + * @param allow_unknown_enums + * false - unknown enum values (left as string values after applySchema) + * will be considered invalid. + * true - such values will be considered valid. + * @return ns_smart_objects::errors::eType + **/ + smart_objects::errors::eType validate( + const smart_objects::SmartObject& Object, + rpc::ValidationReport* report__, + const utils::SemanticVersion& MessageVersion = utils::SemanticVersion(), + const bool allow_unknown_enums = false) OVERRIDE; + + private: + /** + * @brief Constructor. + * @param PolicyDataItem& SchemaItem for VehicleDataItem elements. + * @param SchemaType defines api type for schema to be generated. + **/ + VehicleDataItemSchema(PolicyDataItem& policy_item, SchemaType schema_type); + + /* + * @brief Check whether provided type is POD type + * @param const std::string& type_name - name of type to check + * @return true - if type is POD type and false - if not + */ + const bool isPODType(const std::string& type_name) const; + + /* + * @brief Get Enum schema for provided type + * @param const std::string& type_name - name of enum type to provide + * @return Shared pointer to a new schema item. If no schema found - nullptr + * is returned. + */ + smart_objects::ISchemaItemPtr getEnumSchema( + const std::string& type_name) const; + + /** + * @brief Apply schema. + * @param Object Object to apply schema. + * @param remove_unknown_parameters contains true if need to remove unknown + * parameters from smart object otherwise contains false. + **/ + void applySchema(smart_objects::SmartObject& Object, + const bool remove_unknown_parameters, + const utils::SemanticVersion& MessageVersion) OVERRIDE; + + /** + * @brief Unapply schema. + * @param Object Object to unapply schema. + * @param remove_unknown_parameters contains true if need to remove unknown + * parameters + **/ + void unapplySchema(smart_objects::SmartObject& Object, + const bool remove_unknown_parameters) OVERRIDE; + + /* + * @brief Get schema for a POD type + * @param const VehicleDataItem& policy_item - item, that contains info about + * type + * @return Shared pointer to a new schema item. If no schema found - nullptr + * is returned. + */ + smart_objects::ISchemaItemPtr GetPODTypeSchema( + const policy_table::VehicleDataItem& policy_item, SchemaType schema_type); + + smart_objects::ISchemaItemPtr so_schema_item_; +}; + +} // namespace vehicle_info_plugin +#endif // VEHICLE_DATA_ITEM_SCHEMA_H diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_app_extension.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_app_extension.h index b3ba768b1b..fb7c2b0f82 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_app_extension.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_app_extension.h @@ -47,7 +47,7 @@ typedef mobile_apis::VehicleDataType::eType VehicleDataType; /** * @brief Defines set of vehicle info types */ -typedef std::set<mobile_apis::VehicleDataType::eType> VehicleInfoSubscriptions; +typedef std::set<std::string> VehicleInfoSubscriptions; class VehicleInfoAppExtension : public app_mngr::AppExtension { public: @@ -66,7 +66,7 @@ class VehicleInfoAppExtension : public app_mngr::AppExtension { * @param vehicle_data data to subscribe * @return true in case if subscription is successful */ - bool subscribeToVehicleInfo(const VehicleDataType vehicle_data); + bool subscribeToVehicleInfo(const std::string& vehicle_data); /** * @brief unsubscribeFromVehicleInfo remove vehicle_data from list of @@ -74,7 +74,7 @@ class VehicleInfoAppExtension : public app_mngr::AppExtension { * @param vehicle_data data to unsubscribe * @return true in case if unsubscription is successful */ - bool unsubscribeFromVehicleInfo(const VehicleDataType vehicle_data); + bool unsubscribeFromVehicleInfo(const std::string& vehicle_data); /** * @brief unsubscribeFromVehicleInfo unsubscribe from all vehicle info data */ @@ -87,7 +87,7 @@ class VehicleInfoAppExtension : public app_mngr::AppExtension { * @return true if extension is subscribed this vehicle_data_type, otherwise * return false */ - bool isSubscribedToVehicleInfo(const VehicleDataType vehicle_data_type) const; + bool isSubscribedToVehicleInfo(const std::string& vehicle_data_type) const; /** * @brief Subscriptions get list of subscriptions for application extension diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_command_factory.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_command_factory.h index 58100ba1ae..3356f0f823 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_command_factory.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_command_factory.h @@ -34,36 +34,37 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_VEHICLE_INFO_PLUGIN_INCLUDE_VEHICLE_INFO_PLUGIN_VEHICLE_INFO_COMMAND_FACTORY_H #include "application_manager/application_manager.h" +#include "vehicle_info_plugin/custom_vehicle_data_manager.h" #include "vehicle_info_plugin/vehicle_info_hmi_command_factory.h" #include "vehicle_info_plugin/vehicle_info_mobile_command_factory.h" namespace vehicle_info_plugin { -namespace app_mngr = application_manager; -namespace commands = application_manager::commands; - /** * @brief The Vehicle Info command factory. */ -class VehicleInfoCommandFactory : public app_mngr::CommandFactory { +class VehicleInfoCommandFactory : public application_manager::CommandFactory { public: - VehicleInfoCommandFactory(app_mngr::ApplicationManager& application_manager, - app_mngr::rpc_service::RPCService& rpc_service, - app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler); + VehicleInfoCommandFactory( + application_manager::ApplicationManager& application_manager, + application_manager::rpc_service::RPCService& rpc_service, + application_manager::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler, + CustomVehicleDataManager& custom_vehicle_data_manager); virtual ~VehicleInfoCommandFactory(); - app_mngr::CommandSharedPtr CreateCommand( - const commands::MessageSharedPtr& message, - commands::Command::CommandSource source) OVERRIDE; + application_manager::CommandSharedPtr CreateCommand( + const application_manager::commands::MessageSharedPtr& message, + application_manager::commands::Command::CommandSource source) OVERRIDE; bool IsAbleToProcess( const int32_t function_id, - const commands::Command::CommandSource source) const OVERRIDE; + const application_manager::commands::Command::CommandSource source) + const OVERRIDE; private: - std::unique_ptr<app_mngr::CommandFactory> hmi_command_factory_; - std::unique_ptr<app_mngr::CommandFactory> mob_command_factory_; + std::unique_ptr<application_manager::CommandFactory> hmi_command_factory_; + std::unique_ptr<application_manager::CommandFactory> mob_command_factory_; }; } // namespace vehicle_info_plugin diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_command_params.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_command_params.h new file mode 100644 index 0000000000..df8dbfd802 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_command_params.h @@ -0,0 +1,31 @@ +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_VEHICLE_INFO_PLUGIN_INCLUDE_VEHICLE_INFO_PLUGIN_VEHICLE_INFO_COMMAND_PARAMS_H +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_VEHICLE_INFO_PLUGIN_INCLUDE_VEHICLE_INFO_PLUGIN_VEHICLE_INFO_COMMAND_PARAMS_H + +namespace application_manager { +class ApplicationManager; +class HMICapabilities; +namespace rpc_service { +class RPCService; +} +class ApplicationManager; +} // namespace application_manager + +namespace policy { +class PolicyHandlerInterface; +} + +namespace vehicle_info_plugin { +namespace app_mngr = application_manager; + +class CustomVehicleDataManager; + +struct VehicleInfoCommandParams { + app_mngr::ApplicationManager& application_manager_; + app_mngr::rpc_service::RPCService& rpc_service_; + app_mngr::HMICapabilities& hmi_capabilities_; + policy::PolicyHandlerInterface& policy_handler_; + CustomVehicleDataManager& custom_vehicle_data_manager_; +}; +} // namespace vehicle_info_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_VEHICLE_INFO_PLUGIN_INCLUDE_VEHICLE_INFO_PLUGIN_VEHICLE_INFO_COMMAND_PARAMS_H diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_hmi_command_factory.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_hmi_command_factory.h index c927f3f2bb..60d81b5446 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_hmi_command_factory.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_hmi_command_factory.h @@ -34,6 +34,8 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_VEHICLE_INFO_PLUGIN_INCLUDE_VEHICLE_INFO_PLUGIN_VEHICLE_INFO_HMI_COMMAND_FACTORY_H #include "application_manager/application_manager.h" +#include "application_manager/command_factory.h" +#include "vehicle_info_plugin/custom_vehicle_data_manager.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -47,7 +49,8 @@ class VehicleInfoHmiCommandFactory : public app_mngr::CommandFactory { app_mngr::ApplicationManager& application_manager, app_mngr::rpc_service::RPCService& rpc_service, app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler); + policy::PolicyHandlerInterface& policy_handler, + CustomVehicleDataManager& custom_vehicle_data_manager); app_mngr::CommandSharedPtr CreateCommand( const app_mngr::commands::MessageSharedPtr& message, @@ -62,6 +65,7 @@ class VehicleInfoHmiCommandFactory : public app_mngr::CommandFactory { app_mngr::rpc_service::RPCService& rpc_service_; app_mngr::HMICapabilities& hmi_capabilities_; policy::PolicyHandlerInterface& policy_handler_; + CustomVehicleDataManager& custom_vehicle_data_manager_; app_mngr::CommandCreator& buildCommandCreator( const int32_t function_id, const int32_t message_type) const; diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_mobile_command_factory.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_mobile_command_factory.h index 41bd355852..e3403df5e5 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_mobile_command_factory.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_mobile_command_factory.h @@ -34,7 +34,8 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_VEHICLE_INFO_PLUGIN_INCLUDE_VEHICLE_INFO_PLUGIN_VEHICLE_INFO_MOBILE_COMMAND_FACTORY_H #include "application_manager/application_manager.h" - +#include "application_manager/command_factory.h" +#include "vehicle_info_plugin/custom_vehicle_data_manager.h" namespace vehicle_info_plugin { namespace app_mngr = application_manager; @@ -47,7 +48,8 @@ class VehicleInfoMobileCommandFactory : public app_mngr::CommandFactory { app_mngr::ApplicationManager& application_manager, app_mngr::rpc_service::RPCService& rpc_service, app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler); + policy::PolicyHandlerInterface& policy_handler, + CustomVehicleDataManager& custom_vehicle_data_manager); app_mngr::CommandSharedPtr CreateCommand( const app_mngr::commands::MessageSharedPtr& message, @@ -62,6 +64,7 @@ class VehicleInfoMobileCommandFactory : public app_mngr::CommandFactory { app_mngr::rpc_service::RPCService& rpc_service_; app_mngr::HMICapabilities& hmi_capabilities_; policy::PolicyHandlerInterface& policy_handler_; + CustomVehicleDataManager& custom_vehicle_data_manager_; app_mngr::CommandCreator& get_creator_factory( const mobile_apis::FunctionID::eType function_id, 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 d0e4926a65..80336b6967 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 @@ -34,6 +34,7 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_VEHICLE_INFO_PLUGIN_INCLUDE_VEHICLE_INFO_PLUGIN_VEHICLE_INFO_PLUGIN_H #include "application_manager/command_factory.h" +#include "vehicle_info_plugin/custom_vehicle_data_manager.h" namespace vehicle_info_plugin { class VehicleInfoAppExtension; @@ -47,7 +48,15 @@ class VehicleInfoPlugin : public plugins::RPCPlugin { bool Init(app_mngr::ApplicationManager& application_manager, app_mngr::rpc_service::RPCService& rpc_service, app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) OVERRIDE; + 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, @@ -70,13 +79,17 @@ class VehicleInfoPlugin : public plugins::RPCPlugin { VehicleInfoAppExtension& ext); private: + void UnsubscribeFromRemovedVDItems(); + smart_objects::SmartObjectSPtr GetUnsubscribeIVIRequest( + const std::vector<std::string>& ivi_names); void DeleteSubscriptions(app_mngr::ApplicationSharedPtr app); std::unique_ptr<app_mngr::CommandFactory> command_factory_; + std::unique_ptr<CustomVehicleDataManager> custom_vehicle_data_manager_; app_mngr::ApplicationManager* application_manager_; }; } // namespace vehicle_info_plugin extern "C" application_manager::plugin_manager::RPCPlugin* Create(); - +extern "C" void Delete(application_manager::plugin_manager::RPCPlugin* data); #endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_VEHICLE_INFO_PLUGIN_INCLUDE_VEHICLE_INFO_PLUGIN_VEHICLE_INFO_PLUGIN_H diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/on_vi_vehicle_data_notification.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/on_vi_vehicle_data_notification.cc index 23dd3da879..b8d1b3a100 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/on_vi_vehicle_data_notification.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/on_vi_vehicle_data_notification.cc @@ -40,15 +40,12 @@ namespace commands { OnVIVehicleDataNotification::OnVIVehicleDataNotification( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle) + const VehicleInfoCommandParams& params) : NotificationFromHMI(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handle) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) {} OnVIVehicleDataNotification::~OnVIVehicleDataNotification() {} @@ -62,9 +59,8 @@ void OnVIVehicleDataNotification::Run() { const smart_objects::SmartObject& msg_params = (*message_)[strings::msg_params]; if (msg_params.keyExists(strings::odometer)) { - application_manager_.IviInfoUpdated( - mobile_apis::VehicleDataType::VEHICLEDATA_ODOMETER, - msg_params[strings::odometer].asInt()); + application_manager_.IviInfoUpdated(strings::odometer, + msg_params[strings::odometer].asInt()); } SendNotificationToMobile(message_); diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_diagnostic_message_request.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_diagnostic_message_request.cc index 97d035a20b..ae64c74f26 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_diagnostic_message_request.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_diagnostic_message_request.cc @@ -38,16 +38,13 @@ using namespace application_manager; namespace commands { VIDiagnosticMessageRequest::VIDiagnosticMessageRequest( - const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle) + const app_mngr::commands::MessageSharedPtr& message, + const VehicleInfoCommandParams& params) : RequestToHMI(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handle) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) {} VIDiagnosticMessageRequest::~VIDiagnosticMessageRequest() {} diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_diagnostic_message_response.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_diagnostic_message_response.cc index f4079fc6fd..6482d97d10 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_diagnostic_message_response.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_diagnostic_message_response.cc @@ -40,15 +40,12 @@ namespace commands { VIDiagnosticMessageResponse::VIDiagnosticMessageResponse( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle) + const VehicleInfoCommandParams& params) : ResponseFromHMI(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handle) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) {} VIDiagnosticMessageResponse::~VIDiagnosticMessageResponse() {} diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_dtcs_request.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_dtcs_request.cc index d67d0909a9..620ee4c3e4 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_dtcs_request.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_dtcs_request.cc @@ -39,15 +39,12 @@ namespace commands { VIGetDTCsRequest::VIGetDTCsRequest( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle) + const VehicleInfoCommandParams& params) : RequestToHMI(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handle) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) {} VIGetDTCsRequest::~VIGetDTCsRequest() {} diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_dtcs_response.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_dtcs_response.cc index 494e779c4d..64e948a4e1 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_dtcs_response.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_dtcs_response.cc @@ -40,15 +40,12 @@ namespace commands { VIGetDTCsResponse::VIGetDTCsResponse( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle) + const VehicleInfoCommandParams& params) : ResponseFromHMI(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handle) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) {} VIGetDTCsResponse::~VIGetDTCsResponse() {} diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_data_request.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_data_request.cc index e2c1ed4e3a..eded6c685b 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_data_request.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_data_request.cc @@ -31,6 +31,7 @@ */ #include "vehicle_info_plugin/commands/hmi/vi_get_vehicle_data_request.h" +#include "application_manager/message_helper.h" namespace vehicle_info_plugin { using namespace application_manager; @@ -39,24 +40,39 @@ namespace commands { VIGetVehicleDataRequest::VIGetVehicleDataRequest( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle) + const VehicleInfoCommandParams& params) : RequestToHMI(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handle) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) + , custom_vehicle_data_manager_(params.custom_vehicle_data_manager_) {} VIGetVehicleDataRequest::~VIGetVehicleDataRequest() {} void VIGetVehicleDataRequest::Run() { LOG4CXX_AUTO_TRACE(logger_); + const auto& rpc_spec_vehicle_data = MessageHelper::vehicle_data(); + auto& msg_params = (*message_)[strings::msg_params]; + + smart_objects::SmartObject custom_data; + for (const auto& name : msg_params.enumerate()) { + const auto& found_it = rpc_spec_vehicle_data.find(name); + if (rpc_spec_vehicle_data.end() == found_it) { + custom_data[name] = msg_params[name]; + msg_params.erase(name); + } + } + + auto hmi_custom_msg_params = + custom_vehicle_data_manager_.CreateHMIMessageParams( + custom_data.enumerate()); + for (const auto& param : hmi_custom_msg_params.enumerate()) { + msg_params[param] = hmi_custom_msg_params[param]; + } SendRequest(); } } // namespace commands - } // namespace vehicle_info_plugin diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_data_response.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_data_response.cc index a4b778a487..763ddf1cfa 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_data_response.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_data_response.cc @@ -31,6 +31,8 @@ */ #include "vehicle_info_plugin/commands/hmi/vi_get_vehicle_data_response.h" #include "application_manager/event_engine/event.h" +#include "application_manager/policies/policy_handler_interface.h" + #include "interfaces/HMI_API.h" namespace vehicle_info_plugin { @@ -39,15 +41,12 @@ namespace commands { VIGetVehicleDataResponse::VIGetVehicleDataResponse( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle) + const VehicleInfoCommandParams& params) : ResponseFromHMI(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handle) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) {} VIGetVehicleDataResponse::~VIGetVehicleDataResponse() {} @@ -56,32 +55,14 @@ void VIGetVehicleDataResponse::Run() { event_engine::Event event(hmi_apis::FunctionID::VehicleInfo_GetVehicleData); - if ((*message_)[strings::params][strings::message_type] == - static_cast<int32_t>(hmi_apis::messageType::error_response)) { - smart_objects::SmartObject result(smart_objects::SmartType_Map); - - if ((*message_)[strings::params].keyExists(strings::data)) { - result[strings::msg_params] = (*message_)[strings::params][strings::data]; - result[strings::params][hmi_response::code] = - (*message_)[strings::params][hmi_response::code]; - result[strings::params][strings::correlation_id] = - (*message_)[strings::params][strings::correlation_id]; - result[strings::params][strings::error_msg] = - (*message_)[strings::params][strings::error_msg]; - result[strings::params][strings::message_type] = - (*message_)[strings::params][strings::message_type]; - result[strings::params][strings::protocol_type] = - (*message_)[strings::params][strings::protocol_type]; - result[strings::params][strings::protocol_version] = - (*message_)[strings::params][strings::protocol_version]; - } - - event.set_smart_object(result); - } else { - event.set_smart_object(*message_); + const bool error_response = + (*message_)[strings::params][strings::message_type] == + static_cast<int32_t>(hmi_apis::messageType::error_response); + if (!error_response) { policy_handler_.OnVehicleDataUpdated(*message_); } + event.set_smart_object(*message_); event.raise(application_manager_.event_dispatcher()); } diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_type_request.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_type_request.cc index 96d27a120b..250584bd12 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_type_request.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_type_request.cc @@ -39,15 +39,12 @@ namespace commands { VIGetVehicleTypeRequest::VIGetVehicleTypeRequest( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle) + const VehicleInfoCommandParams& params) : RequestToHMI(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handle) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) {} VIGetVehicleTypeRequest::~VIGetVehicleTypeRequest() {} diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_type_response.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_type_response.cc index add55f9a40..fb6eadf747 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_type_response.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_type_response.cc @@ -38,15 +38,12 @@ namespace commands { VIGetVehicleTypeResponse::VIGetVehicleTypeResponse( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle) + const VehicleInfoCommandParams& params) : ResponseFromHMI(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handle) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) {} VIGetVehicleTypeResponse::~VIGetVehicleTypeResponse() {} diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_is_ready_request.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_is_ready_request.cc index 6479676094..93781a7420 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_is_ready_request.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_is_ready_request.cc @@ -32,6 +32,7 @@ #include "vehicle_info_plugin/commands/hmi/vi_is_ready_request.h" #include "application_manager/message_helper.h" +#include "application_manager/policies/policy_handler_interface.h" #include "application_manager/rpc_service.h" namespace vehicle_info_plugin { @@ -41,16 +42,13 @@ namespace commands { VIIsReadyRequest::VIIsReadyRequest( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle) + const VehicleInfoCommandParams& params) : RequestToHMI(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handle) - , EventObserver(application_manager.event_dispatcher()) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) + , EventObserver(application_manager_.event_dispatcher()) {} VIIsReadyRequest::~VIIsReadyRequest() {} diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_is_ready_response.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_is_ready_response.cc index 0db30afb87..349a1137ce 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_is_ready_response.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_is_ready_response.cc @@ -38,15 +38,12 @@ namespace commands { VIIsReadyResponse::VIIsReadyResponse( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle) + const VehicleInfoCommandParams& params) : ResponseFromHMI(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handle) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) {} VIIsReadyResponse::~VIIsReadyResponse() {} diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_read_did_request.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_read_did_request.cc index fbcc59849d..47373bb4bf 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_read_did_request.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_read_did_request.cc @@ -39,15 +39,12 @@ namespace commands { VIReadDIDRequest::VIReadDIDRequest( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle) + const VehicleInfoCommandParams& params) : RequestToHMI(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handle) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) {} VIReadDIDRequest::~VIReadDIDRequest() {} diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_read_did_response.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_read_did_response.cc index 0b8d0f3055..7c2db1e875 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_read_did_response.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_read_did_response.cc @@ -39,15 +39,12 @@ namespace commands { VIReadDIDResponse::VIReadDIDResponse( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle) + const VehicleInfoCommandParams& params) : ResponseFromHMI(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handle) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) {} VIReadDIDResponse::~VIReadDIDResponse() {} diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_subscribe_vehicle_data_request.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_subscribe_vehicle_data_request.cc index 84e41a26dc..4c5f067d0d 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_subscribe_vehicle_data_request.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_subscribe_vehicle_data_request.cc @@ -31,6 +31,7 @@ */ #include "vehicle_info_plugin/commands/hmi/vi_subscribe_vehicle_data_request.h" +#include "application_manager/message_helper.h" namespace vehicle_info_plugin { using namespace application_manager; @@ -39,24 +40,39 @@ namespace commands { VISubscribeVehicleDataRequest::VISubscribeVehicleDataRequest( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle) + const VehicleInfoCommandParams& params) : RequestToHMI(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handle) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) + , custom_vehicle_data_manager_(params.custom_vehicle_data_manager_) {} VISubscribeVehicleDataRequest::~VISubscribeVehicleDataRequest() {} void VISubscribeVehicleDataRequest::Run() { LOG4CXX_AUTO_TRACE(logger_); + const auto& rpc_spec_vehicle_data = MessageHelper::vehicle_data(); + auto& msg_params = (*message_)[strings::msg_params]; + + smart_objects::SmartObject custom_data; + for (const auto& name : msg_params.enumerate()) { + const auto& found_it = rpc_spec_vehicle_data.find(name); + if (rpc_spec_vehicle_data.end() == found_it) { + custom_data[name] = msg_params[name]; + msg_params.erase(name); + } + } + + auto hmi_custom_msg_params = + custom_vehicle_data_manager_.CreateHMIMessageParams( + custom_data.enumerate()); + for (const auto& item : hmi_custom_msg_params.enumerate()) { + msg_params[item] = hmi_custom_msg_params[item]; + } SendRequest(); } } // namespace commands - } // namespace vehicle_info_plugin diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_subscribe_vehicle_data_response.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_subscribe_vehicle_data_response.cc index 25d876a125..061e13c766 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_subscribe_vehicle_data_response.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_subscribe_vehicle_data_response.cc @@ -39,15 +39,12 @@ namespace commands { VISubscribeVehicleDataResponse::VISubscribeVehicleDataResponse( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle) + const VehicleInfoCommandParams& params) : ResponseFromHMI(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handle) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) {} VISubscribeVehicleDataResponse::~VISubscribeVehicleDataResponse() {} diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_unsubscribe_vehicle_data_request.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_unsubscribe_vehicle_data_request.cc index 50565e95d2..aa24ac7375 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_unsubscribe_vehicle_data_request.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_unsubscribe_vehicle_data_request.cc @@ -31,6 +31,7 @@ */ #include "vehicle_info_plugin/commands/hmi/vi_unsubscribe_vehicle_data_request.h" +#include "application_manager/message_helper.h" namespace vehicle_info_plugin { using namespace application_manager; @@ -39,24 +40,39 @@ namespace commands { VIUnsubscribeVehicleDataRequest::VIUnsubscribeVehicleDataRequest( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle) + const VehicleInfoCommandParams& params) : RequestToHMI(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handle) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) + , custom_vehicle_data_manager_(params.custom_vehicle_data_manager_) {} VIUnsubscribeVehicleDataRequest::~VIUnsubscribeVehicleDataRequest() {} void VIUnsubscribeVehicleDataRequest::Run() { LOG4CXX_AUTO_TRACE(logger_); + const auto& rpc_spec_vehicle_data = MessageHelper::vehicle_data(); + auto& msg_params = (*message_)[strings::msg_params]; + + smart_objects::SmartObject custom_data; + for (const auto& name : msg_params.enumerate()) { + const auto& found_it = rpc_spec_vehicle_data.find(name); + if (rpc_spec_vehicle_data.end() == found_it) { + custom_data[name] = msg_params[name]; + msg_params.erase(name); + } + } + + auto hmi_custom_msg_params = + custom_vehicle_data_manager_.CreateHMIMessageParams( + custom_data.enumerate()); + for (const auto& param : hmi_custom_msg_params.enumerate()) { + msg_params[param] = true; + } SendRequest(); } } // namespace commands - } // namespace vehicle_info_plugin diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_unsubscribe_vehicle_data_response.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_unsubscribe_vehicle_data_response.cc index 722073edc7..01fc521b10 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_unsubscribe_vehicle_data_response.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_unsubscribe_vehicle_data_response.cc @@ -39,15 +39,12 @@ namespace commands { VIUnsubscribeVehicleDataResponse::VIUnsubscribeVehicleDataResponse( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle) + const VehicleInfoCommandParams& params) : ResponseFromHMI(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handle) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) {} VIUnsubscribeVehicleDataResponse::~VIUnsubscribeVehicleDataResponse() {} diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/diagnostic_message_request.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/diagnostic_message_request.cc index a1dfe1e936..ef6c284faf 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/diagnostic_message_request.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/diagnostic_message_request.cc @@ -46,15 +46,12 @@ namespace commands { DiagnosticMessageRequest::DiagnosticMessageRequest( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) + const VehicleInfoCommandParams& params) : CommandRequestImpl(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handler) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) {} DiagnosticMessageRequest::~DiagnosticMessageRequest() {} diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/diagnostic_message_response.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/diagnostic_message_response.cc index f5ad1c89a2..f5ccc4d0a7 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/diagnostic_message_response.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/diagnostic_message_response.cc @@ -41,15 +41,12 @@ namespace commands { DiagnosticMessageResponse::DiagnosticMessageResponse( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) + const VehicleInfoCommandParams& params) : CommandResponseImpl(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handler) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) {} DiagnosticMessageResponse::~DiagnosticMessageResponse() {} diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/get_dtcs_request.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/get_dtcs_request.cc index af941e3ea7..dfa1cf305b 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/get_dtcs_request.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/get_dtcs_request.cc @@ -44,15 +44,12 @@ namespace commands { GetDTCsRequest::GetDTCsRequest( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) + const VehicleInfoCommandParams& params) : CommandRequestImpl(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handler) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) {} GetDTCsRequest::~GetDTCsRequest() {} diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/get_dtcs_response.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/get_dtcs_response.cc index 894c564a0b..33945a2f00 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/get_dtcs_response.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/get_dtcs_response.cc @@ -41,15 +41,12 @@ namespace commands { GetDTCsResponse::GetDTCsResponse( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) + const VehicleInfoCommandParams& params) : CommandResponseImpl(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handler) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) {} GetDTCsResponse::~GetDTCsResponse() {} 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 8d762e30e5..d15cf6a580 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 @@ -32,12 +32,15 @@ */ #include "vehicle_info_plugin/commands/mobile/get_vehicle_data_request.h" +#include "vehicle_info_plugin/custom_vehicle_data_manager.h" + #include <string> #include "application_manager/application_impl.h" #include "application_manager/message_helper.h" #include "interfaces/HMI_API.h" #include "interfaces/MOBILE_API.h" +#include "policy/policy_table/types.h" namespace vehicle_info_plugin { using namespace application_manager; @@ -48,55 +51,57 @@ namespace str = strings; GetVehicleDataRequest::GetVehicleDataRequest( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) + const VehicleInfoCommandParams& params) : CommandRequestImpl(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handler) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) + , custom_vehicle_data_manager_(params.custom_vehicle_data_manager_) {} GetVehicleDataRequest::~GetVehicleDataRequest() {} void GetVehicleDataRequest::Run() { LOG4CXX_AUTO_TRACE(logger_); - int32_t app_id = - (*message_)[strings::params][strings::connection_key].asUInt(); - ApplicationSharedPtr app = application_manager_.application(app_id); + auto app = application_manager_.application(connection_key()); if (!app) { - LOG4CXX_ERROR(logger_, "NULL pointer"); + LOG4CXX_ERROR(logger_, "No such application : " << connection_key()); SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED); return; } - if (app->AreCommandLimitsExceeded( - static_cast<mobile_apis::FunctionID::eType>(function_id()), - application_manager::TLimitSource::CONFIG_FILE)) { - LOG4CXX_ERROR(logger_, "GetVehicleData frequency is too high."); + if (!CheckFrequency(*app)) { SendResponse(false, mobile_apis::Result::REJECTED); return; } - const VehicleData& vehicle_data = MessageHelper::vehicle_data(); - VehicleData::const_iterator it = vehicle_data.begin(); - smart_objects::SmartObject msg_params = + + auto hmi_msg_params = smart_objects::SmartObject(smart_objects::SmartType_Map); - msg_params[strings::app_id] = app->app_id(); - const uint32_t min_length_msg_params = 1; - for (; vehicle_data.end() != it; ++it) { - if (true == (*message_)[str::msg_params].keyExists(it->first) && - true == (*message_)[str::msg_params][it->first].asBool()) { - msg_params[it->first] = (*message_)[strings::msg_params][it->first]; + hmi_msg_params[strings::app_id] = app->app_id(); + + int params_count = 0; + auto& msg_params = (*message_)[strings::msg_params]; + for (const auto& name : msg_params.enumerate()) { + auto enabled = msg_params[name].asBool(); + if (!enabled) { + continue; } + hmi_msg_params[name] = msg_params[name]; + params_count++; } - if (msg_params.length() > min_length_msg_params) { + + const int minimal_params_count = 1; + + if (params_count >= minimal_params_count) { + for (const auto& param : msg_params.enumerate()) { + pending_vehicle_data_.insert(param); + } StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VehicleInfo); - SendHMIRequest( - hmi_apis::FunctionID::VehicleInfo_GetVehicleData, &msg_params, true); - return; + SendHMIRequest(hmi_apis::FunctionID::VehicleInfo_GetVehicleData, + &hmi_msg_params, + true); } else if (HasDisallowedParams()) { SendResponse(false, mobile_apis::Result::DISALLOWED); } else { @@ -111,16 +116,31 @@ void GetVehicleDataRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::VehicleInfo_GetVehicleData: { EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VehicleInfo); - hmi_apis::Common_Result::eType result_code = - static_cast<hmi_apis::Common_Result::eType>( - message[strings::params][hmi_response::code].asInt()); + auto result_code = static_cast<hmi_apis::Common_Result::eType>( + message[strings::params][hmi_response::code].asInt()); + auto mobile_result_code = GetMobileResultCode(result_code); bool result = PrepareResultForMobileResponse( result_code, HmiInterfaces::HMI_INTERFACE_VehicleInfo); std::string response_info; GetInfo(message, response_info); - result = result || - ((hmi_apis::Common_Result::DATA_NOT_AVAILABLE == result_code) && - (message[strings::msg_params].length() > 1)); + + auto data_not_available_with_params = [this, &result_code, &message]() { + if (hmi_apis::Common_Result::DATA_NOT_AVAILABLE != result_code) { + return false; + } + + const auto& vehicle_data = MessageHelper::vehicle_data(); + const auto& msg_params = message[strings::msg_params]; + for (const auto& item : msg_params.enumerate()) { + if (vehicle_data.end() != vehicle_data.find(item) || + custom_vehicle_data_manager_.IsValidCustomVehicleDataName(item)) { + return true; + } + } + return false; + }; + + result = result || data_not_available_with_params(); if (true == message[strings::msg_params].keyExists(hmi_response::method)) { @@ -129,8 +149,30 @@ void GetVehicleDataRequest::on_event(const event_engine::Event& event) { if (true == message[strings::params].keyExists(strings::error_msg)) { response_info = message[strings::params][strings::error_msg].asString(); } + + custom_vehicle_data_manager_.CreateMobileMessageParams( + const_cast<smart_objects::SmartObject&>( + message[strings::msg_params])); + + if (result) { + for (const auto& item : message[strings::msg_params].enumerate()) { + const auto& found_item = pending_vehicle_data_.find(item); + if (pending_vehicle_data_.end() == found_item) { + message[strings::msg_params].erase(item); + } + } + + if (message[strings::msg_params].empty() && + hmi_apis::Common_Result::DATA_NOT_AVAILABLE != result_code) { + response_info = "Failed to retrieve data from vehicle"; + SendResponse( + false, mobile_apis::Result::GENERIC_ERROR, response_info.c_str()); + return; + } + } + SendResponse(result, - MessageHelper::HMIToMobileResult(result_code), + mobile_result_code, response_info.empty() ? NULL : response_info.c_str(), &(message[strings::msg_params])); break; @@ -142,6 +184,15 @@ void GetVehicleDataRequest::on_event(const event_engine::Event& event) { } } -} // namespace commands +bool GetVehicleDataRequest::CheckFrequency(Application& app) { + if (app.AreCommandLimitsExceeded( + static_cast<mobile_apis::FunctionID::eType>(function_id()), + application_manager::TLimitSource::CONFIG_FILE)) { + LOG4CXX_ERROR(logger_, "GetVehicleData frequency is too high."); + return false; + } + return true; +} +} // namespace commands } // namespace vehicle_info_plugin diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/get_vehicle_data_response.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/get_vehicle_data_response.cc index f634915354..60a44745a5 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/get_vehicle_data_response.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/get_vehicle_data_response.cc @@ -42,15 +42,12 @@ namespace commands { GetVehicleDataResponse::GetVehicleDataResponse( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) + const VehicleInfoCommandParams& params) : CommandResponseImpl(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handler) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) {} GetVehicleDataResponse::~GetVehicleDataResponse() {} 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 7d34bbbe37..79134cae40 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 @@ -47,90 +47,74 @@ namespace commands { OnVehicleDataNotification::OnVehicleDataNotification( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - app_mngr::rpc_service::RPCService& rpc_service, - app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) + const VehicleInfoCommandParams& params) : CommandNotificationImpl(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handler) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) + , custom_vehicle_data_manager_(params.custom_vehicle_data_manager_) {} OnVehicleDataNotification::~OnVehicleDataNotification() {} void OnVehicleDataNotification::Run() { LOG4CXX_AUTO_TRACE(logger_); - std::vector<ApplicationSharedPtr> appNotification; - std::vector<ApplicationSharedPtr>::iterator appNotification_it = - appNotification.begin(); + std::vector<ApplicationSharedPtr> notify_apps; + std::vector<ApplicationSharedPtr>::iterator notified_app_it = + notify_apps.begin(); std::vector<smart_objects::SmartObject> appSO; - const VehicleData& vehicle_data = MessageHelper::vehicle_data(); - VehicleData::const_iterator it = vehicle_data.begin(); - - for (; vehicle_data.end() != it; ++it) { - if (true == (*message_)[strings::msg_params].keyExists(it->first)) { - LOG4CXX_DEBUG(logger_, "vehicle_data name" << it->first); - auto vehicle_data_value = - (*message_)[strings::msg_params][it->first].asInt(); - - application_manager_.IviInfoUpdated(it->second, vehicle_data_value); - - auto subscribed_to_ivi_predicate = [&it](const ApplicationSharedPtr app) { - DCHECK_OR_RETURN(app, false); - auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app); - return ext.isSubscribedToVehicleInfo(it->second); - }; - - const std::vector<ApplicationSharedPtr>& applications = - application_manager::FindAllApps(application_manager_.applications(), - subscribed_to_ivi_predicate); - - std::vector<ApplicationSharedPtr>::const_iterator app_it = - applications.begin(); - - for (; applications.end() != app_it; ++app_it) { - const ApplicationSharedPtr app = *app_it; - if (!app) { - LOG4CXX_ERROR(logger_, "NULL pointer"); - continue; - } - - appNotification_it = - find(appNotification.begin(), appNotification.end(), app); - if (appNotification_it == appNotification.end()) { - appNotification.push_back(app); - smart_objects::SmartObject msg_param = - smart_objects::SmartObject(smart_objects::SmartType_Map); - msg_param[it->first] = (*message_)[strings::msg_params][it->first]; - appSO.push_back(msg_param); - } else { - size_t idx = - std::distance(appNotification.begin(), appNotification_it); - appSO[idx][it->first] = (*message_)[strings::msg_params][it->first]; - } + custom_vehicle_data_manager_.CreateMobileMessageParams( + (*message_)[strings::msg_params]); + + const auto& param_names = (*message_)[strings::msg_params].enumerate(); + for (const auto& name : param_names) { + LOG4CXX_DEBUG(logger_, "vehicle_data name: " << name); + auto vehicle_data_value = (*message_)[strings::msg_params][name].asInt(); + application_manager_.IviInfoUpdated(name, vehicle_data_value); + + auto subscribed_to_ivi_predicate = [&name](const ApplicationSharedPtr app) { + DCHECK_OR_RETURN(app, false); + auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app); + return ext.isSubscribedToVehicleInfo(name); + }; + + const auto& applications = application_manager::FindAllApps( + application_manager_.applications(), subscribed_to_ivi_predicate); + for (const auto& app : applications) { + if (!app) { + LOG4CXX_ERROR(logger_, "NULL pointer"); + continue; + } + 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]; + 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]; } } } - LOG4CXX_DEBUG( - logger_, - "Number of Notifications to be send: " << appNotification.size()); + LOG4CXX_DEBUG(logger_, + "Number of Notifications to be send: " << notify_apps.size()); - for (size_t idx = 0; idx < appNotification.size(); idx++) { + for (size_t idx = 0; idx < notify_apps.size(); idx++) { LOG4CXX_INFO(logger_, "Send OnVehicleData PRNDL notification to " - << appNotification[idx]->name().c_str() - << " application id " << appNotification[idx]->app_id()); + << notify_apps[idx]->name().c_str() << " application id " + << notify_apps[idx]->app_id()); (*message_)[strings::params][strings::connection_key] = - appNotification[idx]->app_id(); + notify_apps[idx]->app_id(); (*message_)[strings::msg_params] = appSO[idx]; SendNotification(); } } } // namespace commands - } // namespace vehicle_info_plugin diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/read_did_request.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/read_did_request.cc index ed83f53516..c090df7852 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/read_did_request.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/read_did_request.cc @@ -45,15 +45,12 @@ namespace commands { ReadDIDRequest::ReadDIDRequest( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - app_mngr::rpc_service::RPCService& rpc_service, - app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) + const VehicleInfoCommandParams& params) : CommandRequestImpl(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handler) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) {} ReadDIDRequest::~ReadDIDRequest() {} diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/read_did_response.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/read_did_response.cc index f0b9e3097a..42e7fc1ba9 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/read_did_response.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/read_did_response.cc @@ -41,15 +41,12 @@ namespace commands { ReadDIDResponse::ReadDIDResponse( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - app_mngr::rpc_service::RPCService& rpc_service, - app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) + const VehicleInfoCommandParams& params) : CommandResponseImpl(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handler) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) {} ReadDIDResponse::~ReadDIDResponse() {} diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/subscribe_vehicle_data_request.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/subscribe_vehicle_data_request.cc index 815ffeb3d2..36d972d5fd 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/subscribe_vehicle_data_request.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/subscribe_vehicle_data_request.cc @@ -29,26 +29,28 @@ #include "vehicle_info_plugin/commands/mobile/subscribe_vehicle_data_request.h" +#include <boost/algorithm/string.hpp> #include "application_manager/application_impl.h" #include "application_manager/message_helper.h" +#include "smart_objects/enum_schema_item.h" #include "utils/helpers.h" #include "vehicle_info_plugin/vehicle_info_app_extension.h" +namespace VD_ResultCode = hmi_apis::Common_VehicleDataResultCode; + namespace vehicle_info_plugin { using namespace application_manager; namespace commands { SubscribeVehicleDataRequest::SubscribeVehicleDataRequest( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - app_mngr::rpc_service::RPCService& rpc_service, - app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) + VehicleInfoCommandParams params) : CommandRequestImpl(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handler) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) + , custom_vehicle_data_manager_(params.custom_vehicle_data_manager_) {} SubscribeVehicleDataRequest::~SubscribeVehicleDataRequest() {} @@ -73,6 +75,7 @@ void SubscribeVehicleDataRequest::Run() { app, info, result_code, response_params, msg_params, result); if (mobile_apis::Result::INVALID_ENUM != result_code) { + AppendDataTypesToMobileResponse(response_params); SendResponse(result, result_code, info.empty() ? NULL : info.c_str(), @@ -118,35 +121,121 @@ void SubscribeVehicleDataRequest::on_event(const event_engine::Event& event) { mobile_apis::Result::eType result_code = MessageHelper::HMIToMobileResult(hmi_result); + smart_objects::SmartObject converted_msg_params(message[strings::msg_params]); + custom_vehicle_data_manager_.CreateMobileMessageParams(converted_msg_params); + if (is_succeeded) { if (!vi_already_subscribed_by_this_app_.empty()) { result_code = mobile_apis::Result::IGNORED; response_info = "Already subscribed on some provided VehicleData."; } - if (!vi_waiting_for_subscribe_.empty()) { - LOG4CXX_DEBUG(logger_, "Subscribing to all pending VehicleData"); - VehicleInfoSubscriptions::const_iterator key = - vi_waiting_for_subscribe_.begin(); - for (; key != vi_waiting_for_subscribe_.end(); ++key) { - auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app); - ext.subscribeToVehicleInfo(*key); + for (const auto& param : converted_msg_params.enumerate()) { + const auto& converted_name = ConvertResponseToRequestName(param); + if (vi_waiting_for_subscribe_.end() == + vi_waiting_for_subscribe_.find(converted_name)) { + LOG4CXX_DEBUG(logger_, "erase " << converted_name); + converted_msg_params.erase(param); } } - } - UnsubscribeFailedSubscriptions(app, message[strings::msg_params]); + if (!SubscribePendingVehicleData(app, converted_msg_params)) { + result_code = mobile_apis::Result::GENERIC_ERROR; + response_info = "Subscription failed for some Vehicle data"; + SendResponse(false, result_code, response_info.c_str()); + return; + } + } if (!vi_already_subscribed_by_another_apps_.empty() || !vi_already_subscribed_by_this_app_.empty()) { - AddAlreadySubscribedVI( - const_cast<smart_objects::SmartObject&>(message[strings::msg_params])); + AddAlreadySubscribedVI(converted_msg_params); } + AppendDataTypesToMobileResponse(converted_msg_params); SendResponse(is_succeeded, result_code, response_info.empty() ? NULL : response_info.c_str(), - &(message[strings::msg_params])); + &converted_msg_params); +} + +void SubscribeVehicleDataRequest::AppendDataTypesToMobileResponse( + smart_objects::SmartObject& msg_params) const { + using namespace smart_objects; + + std::string oem_vehicle_data_type_str; + EnumConversionHelper<VehicleDataType>::EnumToString( + VehicleDataType::VEHICLEDATA_OEM_CUSTOM_DATA, &oem_vehicle_data_type_str); + + const auto& rpc_spec_vehicle_data = MessageHelper::vehicle_data(); + for (const auto& item : msg_params.enumerate()) { + const auto& rpc_spec_vehicle_data_item = rpc_spec_vehicle_data.find(item); + if (rpc_spec_vehicle_data.end() == rpc_spec_vehicle_data_item) { + msg_params[item][strings::data_type] = oem_vehicle_data_type_str; + msg_params[item][strings::oem_custom_data_type] = + custom_vehicle_data_manager_.GetVehicleDataItemType(item); + } else { + msg_params[item][strings::data_type] = rpc_spec_vehicle_data_item->second; + } + } +} + +bool SubscribeVehicleDataRequest::CheckSubscriptionStatus( + std::string vi_name, const smart_objects::SmartObject& msg_params) { + const auto subscribed_items = msg_params.enumerate(); + if (subscribed_items.end() == subscribed_items.find(vi_name)) { + LOG4CXX_WARN(logger_, + vi_name << " is waiting to be subscribed, but missing in " + "vehicle response."); + return false; + } + + auto res_code = msg_params[vi_name][strings::result_code].asInt(); + if (VD_ResultCode::VDRC_SUCCESS != res_code && + VD_ResultCode::VDRC_DATA_ALREADY_SUBSCRIBED != res_code) { + LOG4CXX_WARN(logger_, + "Subscription to " << vi_name << " for " << connection_key() + << " failed."); + return false; + } + return true; +} + +bool SubscribeVehicleDataRequest::SubscribePendingVehicleData( + ApplicationSharedPtr app, smart_objects::SmartObject& msg_params) { + LOG4CXX_DEBUG(logger_, "Subscribing to all pending VehicleData"); + + std::set<hmi_apis::Common_VehicleDataResultCode::eType> skiped_result_codes( + {VD_ResultCode::VDRC_TRUNCATED_DATA, + VD_ResultCode::VDRC_DISALLOWED, + VD_ResultCode::VDRC_USER_DISALLOWED, + VD_ResultCode::VDRC_INVALID_ID, + VD_ResultCode::VDRC_DATA_NOT_AVAILABLE, + VD_ResultCode::VDRC_DATA_NOT_SUBSCRIBED, + VD_ResultCode::VDRC_IGNORED}); + + for (auto vi_name = vi_waiting_for_subscribe_.begin(); + vi_name != vi_waiting_for_subscribe_.end();) { + const bool is_subscription_successful = CheckSubscriptionStatus( + ConvertRequestToResponseName(*vi_name), msg_params); + + if (is_subscription_successful) { + auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app); + ext.subscribeToVehicleInfo(*vi_name); + vi_name = vi_waiting_for_subscribe_.erase(vi_name); + } else { + auto res_code = + static_cast<hmi_apis::Common_VehicleDataResultCode::eType>( + msg_params[*vi_name][strings::result_code].asInt()); + if (skiped_result_codes.find(res_code) != skiped_result_codes.end()) { + msg_params[*vi_name][strings::result_code] = res_code; + vi_name = vi_waiting_for_subscribe_.erase(vi_name); + } else { + ++vi_name; + } + } + } + return vi_waiting_for_subscribe_.empty(); } bool SubscribeVehicleDataRequest::Init() { @@ -158,76 +247,33 @@ void SubscribeVehicleDataRequest::AddAlreadySubscribedVI( smart_objects::SmartObject& msg_params) const { LOG4CXX_AUTO_TRACE(logger_); using namespace mobile_apis; - auto vi_to_string = - [](const mobile_apis::VehicleDataType::eType vehicle_data) { - for (auto& vi_str_to_int_pair : MessageHelper::vehicle_data()) { - if (vehicle_data == vi_str_to_int_pair.second) { - return vi_str_to_int_pair.first; - } - } - return std::string(); - }; - VehicleInfoSubscriptions::const_iterator it_same_app = - vi_already_subscribed_by_this_app_.begin(); - for (; vi_already_subscribed_by_this_app_.end() != it_same_app; - ++it_same_app) { - msg_params[vi_to_string(*it_same_app)][strings::result_code] = + for (const auto& item : vi_already_subscribed_by_this_app_) { + msg_params[item][strings::result_code] = VehicleDataResultCode::VDRC_DATA_ALREADY_SUBSCRIBED; - msg_params[vi_to_string(*it_same_app)][strings::data_type] = *it_same_app; } - VehicleInfoSubscriptions::const_iterator it_another_app = - vi_already_subscribed_by_another_apps_.begin(); - for (; vi_already_subscribed_by_another_apps_.end() != it_another_app; - ++it_another_app) { - msg_params[vi_to_string(*it_another_app)][strings::result_code] = + for (const auto& item : vi_already_subscribed_by_another_apps_) { + msg_params[item][strings::result_code] = VehicleDataResultCode::VDRC_SUCCESS; - msg_params[vi_to_string(*it_another_app)][strings::data_type] = - *it_another_app; - } -} - -void SubscribeVehicleDataRequest::UnsubscribeFailedSubscriptions( - ApplicationSharedPtr app, - const smart_objects::SmartObject& msg_params) const { - LOG4CXX_AUTO_TRACE(logger_); - const VehicleData& vehicle_data = MessageHelper::vehicle_data(); - VehicleData::const_iterator it = vehicle_data.begin(); - - for (; vehicle_data.end() != it; ++it) { - if (msg_params.keyExists(it->first)) { - if (msg_params[it->first][strings::result_code].asInt() != - hmi_apis::Common_VehicleDataResultCode::VDRC_SUCCESS) { - LOG4CXX_DEBUG(logger_, - "Subscription for VehicleDataType " - << it->first - << " is unsuccessfull. " - "Unsubscribing app with connection key " - << connection_key() << " from it."); - VehicleInfoAppExtension::ExtractVIExtension(*app) - .unsubscribeFromVehicleInfo(it->second); - } - } } } struct SubscribedToIVIPredicate { - int32_t vehicle_info_; - SubscribedToIVIPredicate(int32_t vehicle_info) + std::string vehicle_info_; + SubscribedToIVIPredicate(std::string vehicle_info) : vehicle_info_(vehicle_info) {} bool operator()(const ApplicationSharedPtr app) const { DCHECK_OR_RETURN(app, false); auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app); - return ext.isSubscribedToVehicleInfo( - static_cast<mobile_apis::VehicleDataType::eType>(vehicle_info_)); + return ext.isSubscribedToVehicleInfo(vehicle_info_); } }; bool SubscribeVehicleDataRequest::IsSomeoneSubscribedFor( - const uint32_t param_id) const { + const std::string& param_name) const { LOG4CXX_AUTO_TRACE(logger_); - SubscribedToIVIPredicate finder(param_id); + SubscribedToIVIPredicate finder(param_name); DataAccessor<ApplicationSet> accessor = application_manager_.applications(); ApplicationSetConstIt it = std::find_if( accessor.GetData().begin(), accessor.GetData().end(), finder); @@ -241,86 +287,95 @@ void SubscribeVehicleDataRequest::CheckVISubscriptions( smart_objects::SmartObject& out_response_params, smart_objects::SmartObject& out_request_params, bool& out_result) { - // counter for items to subscribe - VehicleInfoSubscriptions::size_type items_to_subscribe = 0; - // counter for subscribed items by application - uint32_t subscribed_items = 0; + const bool is_interface_not_available = + (HmiInterfaces::STATE_NOT_AVAILABLE == + application_manager_.hmi_interfaces().GetInterfaceState( + HmiInterfaces::HMI_INTERFACE_VehicleInfo)); + + VehicleInfoSubscriptions::size_type subscribed_items = 0; + + auto app_already_subscribed = + [this, &out_response_params]( + const std::string& key_name, + const mobile_apis::VehicleDataType::eType vd_type) { + LOG4CXX_DEBUG( + logger_, + "App with connection key " + << connection_key() + << " is subscribed already for VehicleData: " << key_name); + vi_already_subscribed_by_this_app_.insert(key_name); + out_response_params[key_name][strings::data_type] = vd_type; + out_response_params[key_name][strings::result_code] = + mobile_apis::VehicleDataResultCode::VDRC_DATA_ALREADY_SUBSCRIBED; + }; - const VehicleData& vehicle_data = MessageHelper::vehicle_data(); - VehicleData::const_iterator it = vehicle_data.begin(); + auto another_app_subscribed = + [this, &out_response_params, &subscribed_items]( + const std::string& key_name, + const mobile_apis::VehicleDataType::eType vd_type, + vehicle_info_plugin::VehicleInfoAppExtension& ext) { + LOG4CXX_DEBUG(logger_, + "There are apps subscribed already for " + "VehicleDataType: " + << key_name); + + if (!ext.subscribeToVehicleInfo(key_name)) { + LOG4CXX_ERROR( + logger_, "Unable to subscribe for VehicleDataType: " << key_name); + return; + } + LOG4CXX_DEBUG( + logger_, + "App with connection key " + << connection_key() + << " have been subscribed for VehicleDataType: " << key_name); + vi_already_subscribed_by_another_apps_.insert(key_name); + out_response_params[key_name][strings::data_type] = vd_type; + out_response_params[key_name][strings::result_code] = + mobile_apis::VehicleDataResultCode::VDRC_SUCCESS; + ++subscribed_items; + }; - HmiInterfaces::InterfaceState interface_state = - application_manager_.hmi_interfaces().GetInterfaceState( - HmiInterfaces::HMI_INTERFACE_VehicleInfo); + auto first_subscription = [this, &out_request_params, &subscribed_items]( + const std::string& vi_name) { + out_request_params[vi_name] = (*message_)[strings::msg_params][vi_name]; - const bool is_interface_not_available = - interface_state == HmiInterfaces::STATE_NOT_AVAILABLE; - - for (; vehicle_data.end() != it; ++it) { - const std::string& key_name = it->first; - if ((*message_)[strings::msg_params].keyExists(key_name)) { - const bool is_key_enabled = - (*message_)[strings::msg_params][key_name].asBool(); - if (is_key_enabled) { - ++items_to_subscribe; - } - if (!is_interface_not_available && is_key_enabled) { - mobile_apis::VehicleDataType::eType key_type = it->second; - const auto is_subscribed = - VehicleInfoAppExtension::ExtractVIExtension(*app) - .isSubscribedToVehicleInfo(key_type); - if (is_subscribed) { - LOG4CXX_DEBUG(logger_, - "App with connection key " - << connection_key() - << " is subscribed already for VehicleDataType: " - << key_type); - ++subscribed_items; - vi_already_subscribed_by_this_app_.insert(key_type); - out_response_params[key_name][strings::data_type] = key_type; - out_response_params[key_name][strings::result_code] = - mobile_apis::VehicleDataResultCode::VDRC_DATA_ALREADY_SUBSCRIBED; - continue; - } + vi_waiting_for_subscribe_.insert(vi_name); + LOG4CXX_DEBUG( + logger_, + "App with connection key " + << connection_key() + << " will be subscribed for VehicleDataType: " << vi_name); + ++subscribed_items; + return true; + }; - if (IsSomeoneSubscribedFor(key_type)) { - LOG4CXX_DEBUG(logger_, - "There are apps subscribed already for " - "VehicleDataType: " - << key_type); - auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app); - - if (!ext.subscribeToVehicleInfo(key_type)) { - LOG4CXX_ERROR( - logger_, - "Unable to subscribe for VehicleDataType: " << key_type); - continue; - } - LOG4CXX_DEBUG( - logger_, - "App with connection key " - << connection_key() - << " have been subscribed for VehicleDataType: " << key_type); - ++subscribed_items; - vi_already_subscribed_by_another_apps_.insert(key_type); - out_response_params[key_name][strings::data_type] = key_type; - out_response_params[key_name][strings::result_code] = - mobile_apis::VehicleDataResultCode::VDRC_SUCCESS; - continue; - } + auto rpc_spec_vehicle_data = MessageHelper::vehicle_data(); + auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app); - out_request_params[key_name] = is_key_enabled; + VehicleInfoSubscriptions::size_type items_to_subscribe = 0; + auto item_names = (*message_)[strings::msg_params].enumerate(); + if (!is_interface_not_available) { + for (const auto& name : item_names) { + auto enabled = (*message_)[strings::msg_params][name].asBool(); + if (!enabled) { + continue; + } - if (is_key_enabled) { - vi_waiting_for_subscribe_.insert(key_type); - LOG4CXX_DEBUG( - logger_, - "App with connection key " - << connection_key() - << " will be subscribed for VehicleDataType: " << key_type); - ++subscribed_items; - } + auto vehicle_data = rpc_spec_vehicle_data.find(name); + auto vehicle_data_type = + (vehicle_data == rpc_spec_vehicle_data.end()) + ? VehicleDataType::VEHICLEDATA_OEM_CUSTOM_DATA + : vehicle_data->second; + if (ext.isSubscribedToVehicleInfo(name)) { + app_already_subscribed(name, vehicle_data_type); + } else if (IsSomeoneSubscribedFor(name)) { + another_app_subscribed(name, vehicle_data_type, ext); + } else if (!first_subscription(name)) { + continue; } + + ++items_to_subscribe; } } @@ -336,12 +391,14 @@ void SubscribeVehicleDataRequest::CheckVISubscriptions( out_info = "No data in the request"; } out_result = false; + return; } if (0 == subscribed_items && !is_interface_not_available) { out_result_code = mobile_apis::Result::IGNORED; out_info = "Already subscribed on provided VehicleData."; out_result = false; + return; } if (is_everything_already_subscribed) { @@ -352,8 +409,35 @@ void SubscribeVehicleDataRequest::CheckVISubscriptions( out_info = "Already subscribed on some provided VehicleData."; } out_result = true; + return; } } +const std::string& SubscribeVehicleDataRequest::ConvertResponseToRequestName( + const std::string& name) { + static std::map<std::string, std::string> parameter_name_conversion_map = { + {strings::cluster_modes, strings::cluster_mode_status}}; + const auto converted_it = parameter_name_conversion_map.find(name); + auto result = parameter_name_conversion_map.end() == converted_it + ? name + : converted_it->second; + return parameter_name_conversion_map.end() == converted_it + ? name + : converted_it->second; +} + +const std::string& SubscribeVehicleDataRequest::ConvertRequestToResponseName( + const std::string& name) { + static std::map<std::string, std::string> parameter_name_conversion_map = { + {strings::cluster_mode_status, strings::cluster_modes}}; + const auto converted_it = parameter_name_conversion_map.find(name); + auto result = parameter_name_conversion_map.end() == converted_it + ? name + : converted_it->second; + return parameter_name_conversion_map.end() == converted_it + ? name + : converted_it->second; +} + } // namespace commands } // namespace vehicle_info_plugin diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/subscribe_vehicle_data_response.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/subscribe_vehicle_data_response.cc index b0d09e1a5b..8330176af6 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/subscribe_vehicle_data_response.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/subscribe_vehicle_data_response.cc @@ -42,15 +42,12 @@ namespace commands { SubscribeVehicleDataResponse::SubscribeVehicleDataResponse( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - app_mngr::rpc_service::RPCService& rpc_service, - app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) + const VehicleInfoCommandParams& params) : CommandResponseImpl(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handler) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) {} SubscribeVehicleDataResponse::~SubscribeVehicleDataResponse() {} diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/unsubscribe_vehicle_data_request.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/unsubscribe_vehicle_data_request.cc index 40bd9182e7..32d63f0c35 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/unsubscribe_vehicle_data_request.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/unsubscribe_vehicle_data_request.cc @@ -39,6 +39,7 @@ #include "application_manager/smart_object_keys.h" #include "interfaces/HMI_API.h" #include "interfaces/MOBILE_API.h" +#include "smart_objects/enum_schema_item.h" #include "utils/helpers.h" #include "vehicle_info_plugin/vehicle_info_app_extension.h" @@ -48,15 +49,13 @@ namespace commands { UnsubscribeVehicleDataRequest::UnsubscribeVehicleDataRequest( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - app_mngr::rpc_service::RPCService& rpc_service, - app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) + const VehicleInfoCommandParams& params) : CommandRequestImpl(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handler) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) + , custom_vehicle_data_manager_(params.custom_vehicle_data_manager_) {} UnsubscribeVehicleDataRequest::~UnsubscribeVehicleDataRequest() {} @@ -74,67 +73,64 @@ void UnsubscribeVehicleDataRequest::Run() { int32_t items_to_unsubscribe = 0; int32_t unsubscribed_items = 0; - const VehicleData& vehicle_data = MessageHelper::vehicle_data(); - VehicleData::const_iterator it = vehicle_data.begin(); - smart_objects::SmartObject msg_params = smart_objects::SmartObject(smart_objects::SmartType_Map); - smart_objects::SmartObject response_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); + response_params_ = smart_objects::SmartObject(smart_objects::SmartType_Map); + + auto rpc_spec_vehicle_data = MessageHelper::vehicle_data(); + std::set<std::string> custom_vehicle_data; + + auto app_not_subscribed_response = [this](const std::string& key_name) { + LOG4CXX_DEBUG(logger_, + "App with connection key " + << connection_key() + << " is not subscribed for VehicleData: " << key_name); + vi_already_unsubscribed_by_this_app_.insert(key_name); + response_params_[key_name][strings::result_code] = + mobile_apis::VehicleDataResultCode::VDRC_DATA_NOT_SUBSCRIBED; + }; + + auto other_app_subscribed_response = [this](const std::string& key_name) { + LOG4CXX_DEBUG(logger_, + "There are apps still subscribed for " + "VehicleDataType: " + << key_name); + vi_still_subscribed_by_another_apps_.insert(key_name); + response_params_[key_name][strings::result_code] = + mobile_apis::VehicleDataResultCode::VDRC_SUCCESS; + }; + + auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app); + + const auto& param_names = (*message_)[strings::msg_params].enumerate(); + for (const auto& name : param_names) { + const bool enabled = (*message_)[strings::msg_params][name].asBool(); + if (!enabled) { + continue; + } - for (; vehicle_data.end() != it; ++it) { - const std::string& key_name = it->first; - if ((*message_)[strings::msg_params].keyExists(key_name)) { - bool is_key_enabled = (*message_)[strings::msg_params][key_name].asBool(); - if (is_key_enabled) { - ++items_to_unsubscribe; - - mobile_apis::VehicleDataType::eType key_type = it->second; - const auto is_subscribed = - VehicleInfoAppExtension::ExtractVIExtension(*app) - .isSubscribedToVehicleInfo(key_type); - if (!is_subscribed) { - ++unsubscribed_items; - vi_already_unsubscribed_by_this_app_.insert(key_type); - response_params[key_name][strings::data_type] = key_type; - response_params[key_name][strings::result_code] = - mobile_apis::VehicleDataResultCode::VDRC_DATA_NOT_SUBSCRIBED; - continue; - } - - if (!VehicleInfoAppExtension::ExtractVIExtension(*app) - .unsubscribeFromVehicleInfo(it->second)) { - LOG4CXX_ERROR(logger_, - "Unable to unsubscribe from " - "VehicleDataType: " - << key_type); - continue; - } - - LOG4CXX_DEBUG(logger_, - "Unsubscribed app with connection key " - << connection_key() - << " from VehicleDataType: " << key_type); - - ++unsubscribed_items; - - if (IsSomeoneSubscribedFor(key_type)) { - LOG4CXX_DEBUG(logger_, - "There are another apps still subscribed for " - "VehicleDataType: " - << key_type); - - vi_still_subscribed_by_another_apps_.insert(key_type); - response_params[key_name][strings::data_type] = key_type; - response_params[key_name][strings::result_code] = - mobile_apis::VehicleDataResultCode::VDRC_SUCCESS; - continue; - } - - msg_params[key_name] = is_key_enabled; - } + ++items_to_unsubscribe; + + if (!(ext.isSubscribedToVehicleInfo(name))) { + app_not_subscribed_response(name); + continue; + } + + LOG4CXX_DEBUG(logger_, + "Unsubscribed app with connection key " + << connection_key() << " from VehicleDataType: " << name); + + ++unsubscribed_items; + + if (IsSomeoneSubscribedFor(name)) { + other_app_subscribed_response(name); + ext.unsubscribeFromVehicleInfo(name); + continue; } + + vi_waiting_for_unsubscribe_.insert(name); + msg_params[name] = true; } bool is_everything_already_unsubscribed = @@ -142,6 +138,8 @@ void UnsubscribeVehicleDataRequest::Run() { vi_still_subscribed_by_another_apps_.size() + vi_already_unsubscribed_by_this_app_.size(); + AppendDataTypesToMobileResponse(response_params_); + if (0 == items_to_unsubscribe) { if (HasDisallowedParams()) { SendResponse(false, mobile_apis::Result::DISALLOWED); @@ -156,7 +154,7 @@ void UnsubscribeVehicleDataRequest::Run() { SendResponse(false, mobile_apis::Result::IGNORED, "Was not subscribed on any VehicleData.", - &response_params); + &response_params_); return; } @@ -165,9 +163,9 @@ void UnsubscribeVehicleDataRequest::Run() { SendResponse(false, mobile_apis::Result::IGNORED, "Some provided VehicleData was not subscribed.", - &response_params); + &response_params_); } else { - SendResponse(true, mobile_apis::Result::SUCCESS, NULL, &response_params); + SendResponse(true, mobile_apis::Result::SUCCESS, NULL, &response_params_); } return; } @@ -203,36 +201,56 @@ void UnsubscribeVehicleDataRequest::on_event(const event_engine::Event& event) { message[strings::params][hmi_response::code].asInt()); std::string response_info; GetInfo(message, response_info); - const bool result = PrepareResultForMobileResponse( + bool result = PrepareResultForMobileResponse( hmi_result, HmiInterfaces::HMI_INTERFACE_VehicleInfo); + auto hmi_response_msg_params = message[strings::msg_params]; + mobile_apis::Result::eType result_code = MessageHelper::HMIToMobileResult(hmi_result); + custom_vehicle_data_manager_.CreateMobileMessageParams( + hmi_response_msg_params); + + if (!vi_still_subscribed_by_another_apps_.empty() || + !vi_already_unsubscribed_by_this_app_.empty()) { + AddAlreadyUnsubscribedVI(hmi_response_msg_params); + } + if (result) { if (vi_already_unsubscribed_by_this_app_.size()) { result_code = mobile_apis::Result::IGNORED; response_info = "Some provided VehicleData was not subscribed."; } - } - if (!vi_still_subscribed_by_another_apps_.empty() || - !vi_already_unsubscribed_by_this_app_.empty()) { - AddAlreadyUnsubscribedVI( - const_cast<smart_objects::SmartObject&>(message[strings::msg_params])); - } + for (const auto& param : hmi_response_msg_params.enumerate()) { + const auto converted_param = ConvertResponseToRequestName(param); + if (vi_waiting_for_unsubscribe_.end() == + vi_waiting_for_unsubscribe_.find(converted_param)) { + hmi_response_msg_params.erase(param); + } + } - if (result) { - SetAllowedToTerminate(false); + if (!UnsubscribePendingVehicleData(app, hmi_response_msg_params)) { + result = false; + result_code = mobile_apis::Result::GENERIC_ERROR; + response_info = "Unsubscription failed for some Vehicle data"; + hmi_response_msg_params = smart_objects::SmartObject(); + } } - SendResponse(result, - result_code, - response_info.empty() ? NULL : response_info.c_str(), - &(message[strings::msg_params])); - if (result) { - application_manager_.TerminateRequest( - connection_key(), correlation_id(), function_id()); + + AppendDataTypesToMobileResponse(hmi_response_msg_params); + for (const auto& key : hmi_response_msg_params.enumerate()) { + response_params_[key] = hmi_response_msg_params[key]; } + + SendResponse( + result, + result_code, + response_info.empty() ? NULL : response_info.c_str(), + smart_objects::SmartType::SmartType_Null == response_params_.getType() + ? NULL + : &response_params_); } bool UnsubscribeVehicleDataRequest::Init() { @@ -240,25 +258,23 @@ bool UnsubscribeVehicleDataRequest::Init() { return true; } -struct SubscribedToIVIPredicate { - int32_t vehicle_info_; - SubscribedToIVIPredicate(int32_t vehicle_info) - : vehicle_info_(vehicle_info) {} - bool operator()(const ApplicationSharedPtr app) const { +bool UnsubscribeVehicleDataRequest::IsSomeoneSubscribedFor( + const std::string& param_name) const { + LOG4CXX_AUTO_TRACE(logger_); + const auto conn_key = connection_key(); + auto subscribed_to_ivi = [¶m_name, + &conn_key](const ApplicationSharedPtr app) { DCHECK_OR_RETURN(app, false); + if (conn_key == app->app_id()) { + return false; + } auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app); - return ext.isSubscribedToVehicleInfo( - static_cast<mobile_apis::VehicleDataType::eType>(vehicle_info_)); - } -}; + return (ext.isSubscribedToVehicleInfo(param_name)); + }; -bool UnsubscribeVehicleDataRequest::IsSomeoneSubscribedFor( - const uint32_t param_id) const { - LOG4CXX_AUTO_TRACE(logger_); - SubscribedToIVIPredicate finder(param_id); DataAccessor<ApplicationSet> accessor = application_manager_.applications(); ApplicationSetConstIt it = std::find_if( - accessor.GetData().begin(), accessor.GetData().end(), finder); + accessor.GetData().begin(), accessor.GetData().end(), subscribed_to_ivi); return it != accessor.GetData().end(); } @@ -266,20 +282,92 @@ void UnsubscribeVehicleDataRequest::AddAlreadyUnsubscribedVI( smart_objects::SmartObject& response) const { LOG4CXX_AUTO_TRACE(logger_); using namespace mobile_apis; - VehicleInfoSubscriptions::const_iterator it_same_app = - vi_already_unsubscribed_by_this_app_.begin(); - for (; vi_already_unsubscribed_by_this_app_.end() != it_same_app; - ++it_same_app) { - response[*it_same_app][strings::result_code] = + + for (const auto& item : vi_already_unsubscribed_by_this_app_) { + response[item][strings::result_code] = VehicleDataResultCode::VDRC_DATA_NOT_SUBSCRIBED; } - VehicleInfoSubscriptions::const_iterator it_another_app = - vi_still_subscribed_by_another_apps_.begin(); - for (; vi_still_subscribed_by_another_apps_.end() != it_another_app; - ++it_another_app) { - response[*it_another_app][strings::result_code] = - VehicleDataResultCode::VDRC_SUCCESS; + for (const auto& item : vi_still_subscribed_by_another_apps_) { + response[item][strings::result_code] = VehicleDataResultCode::VDRC_SUCCESS; + } +} + +bool UnsubscribeVehicleDataRequest::CheckSubscriptionStatus( + std::string key, const smart_objects::SmartObject& msg_params) { + const auto unsubscribed_items = msg_params.enumerate(); + if (unsubscribed_items.end() == unsubscribed_items.find(key)) { + LOG4CXX_WARN(logger_, + key << " is waiting to be unsubscribed, but missing in " + "vehicle response."); + return false; + } + + auto res_code = msg_params[key][strings::result_code].asInt(); + if (hmi_apis::Common_VehicleDataResultCode::VDRC_SUCCESS != res_code) { + LOG4CXX_WARN(logger_, + "Unubscribing from " << key << " for " << connection_key() + << " failed."); + return false; + } + return true; +} + +bool UnsubscribeVehicleDataRequest::UnsubscribePendingVehicleData( + ApplicationSharedPtr app, const smart_objects::SmartObject& msg_params) { + LOG4CXX_DEBUG(logger_, "Unsubscribing from all pending VehicleData"); + + for (const auto& vi_name : vi_waiting_for_unsubscribe_) { + const auto converted_item = ConvertRequestToResponseName(vi_name); + const bool is_unsubscription_successful = + CheckSubscriptionStatus(converted_item, msg_params); + if (is_unsubscription_successful) { + auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app); + ext.unsubscribeFromVehicleInfo(vi_name); + vi_waiting_for_unsubscribe_.erase(vi_name); + } + } + return vi_waiting_for_unsubscribe_.empty(); +} + +const std::string& UnsubscribeVehicleDataRequest::ConvertRequestToResponseName( + const std::string& name) { + static std::map<std::string, std::string> parameter_name_converion_map = { + {strings::cluster_mode_status, strings::cluster_modes}}; + const auto converted_it = parameter_name_converion_map.find(name); + return parameter_name_converion_map.end() == converted_it + ? name + : converted_it->second; +} + +const std::string& UnsubscribeVehicleDataRequest::ConvertResponseToRequestName( + const std::string& name) { + static std::map<std::string, std::string> parameter_name_converion_map = { + {strings::cluster_modes, strings::cluster_mode_status}}; + const auto converted_it = parameter_name_converion_map.find(name); + return parameter_name_converion_map.end() == converted_it + ? name + : converted_it->second; +} + +void UnsubscribeVehicleDataRequest::AppendDataTypesToMobileResponse( + smart_objects::SmartObject& msg_params) const { + using namespace smart_objects; + + std::string oem_vehicle_data_type_str; + EnumConversionHelper<VehicleDataType>::EnumToString( + VehicleDataType::VEHICLEDATA_OEM_CUSTOM_DATA, &oem_vehicle_data_type_str); + + const auto& rpc_spec_vehicle_data = MessageHelper::vehicle_data(); + for (const auto& item : msg_params.enumerate()) { + const auto& rpc_spec_vehicle_data_item = rpc_spec_vehicle_data.find(item); + if (rpc_spec_vehicle_data.end() == rpc_spec_vehicle_data_item) { + msg_params[item][strings::data_type] = oem_vehicle_data_type_str; + msg_params[item][strings::oem_custom_data_type] = + custom_vehicle_data_manager_.GetVehicleDataItemType(item); + } else { + msg_params[item][strings::data_type] = rpc_spec_vehicle_data_item->second; + } } } diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/unsubscribe_vehicle_data_response.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/unsubscribe_vehicle_data_response.cc index a4a486a5e7..352239c331 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/unsubscribe_vehicle_data_response.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/unsubscribe_vehicle_data_response.cc @@ -40,15 +40,12 @@ namespace commands { UnsubscribeVehicleDataResponse::UnsubscribeVehicleDataResponse( const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - app_mngr::rpc_service::RPCService& rpc_service, - app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) + const VehicleInfoCommandParams& params) : CommandResponseImpl(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handler) {} + params.application_manager_, + params.rpc_service_, + params.hmi_capabilities_, + params.policy_handler_) {} UnsubscribeVehicleDataResponse::~UnsubscribeVehicleDataResponse() {} diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/custom_vehicle_data_manager_impl.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/custom_vehicle_data_manager_impl.cc new file mode 100644 index 0000000000..9df6d922aa --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/custom_vehicle_data_manager_impl.cc @@ -0,0 +1,575 @@ +/** + * 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 "vehicle_info_plugin/custom_vehicle_data_manager_impl.h" +#include <strings.h> +#include <limits> +#include "policy/policy_table/types.h" +#include "vehicle_info_plugin/vehicle_data_item_schema.h" + +#include "application_manager/application_manager.h" +#include "application_manager/message_helper.h" +#include "application_manager/policies/custom_vehicle_data_provider.h" +#include "interfaces/MOBILE_API_schema.h" +#include "policy/policy_table/policy_enum_schema_factory.h" +#include "smart_objects/enum_schema_item.h" +#include "utils/helpers.h" +#include "utils/optional.h" + +CREATE_LOGGERPTR_GLOBAL(logger_, "VehicleInfoPlugin") + +namespace vehicle_info_plugin { + +template <typename T, typename U> +U GetOptional(const rpc::Optional<T>& optional, U def_val) { + return optional.is_initialized() ? static_cast<U>(*optional) : def_val; +} + +enum SearchMethod { RECURSIVE = 0, NON_RECURSIVE }; + +CustomVehicleDataManagerImpl::CustomVehicleDataManagerImpl( + policy::VehicleDataItemProvider& vehicle_data_provider, + application_manager::rpc_service::RPCService& rpc_service) + : vehicle_data_provider_(vehicle_data_provider) + , rpc_service_(rpc_service) {} + +std::string CustomVehicleDataManagerImpl::GetVehicleDataItemType( + const std::string& vehicle_data_item_name) const { + LOG4CXX_AUTO_TRACE(logger_); + const auto& schema = FindSchemaByNameNonRecursive(vehicle_data_item_name); + + return schema.is_initialized() ? std::string(schema->type) + : vehicle_data_item_name; +} + +bool CustomVehicleDataManagerImpl::IsValidCustomVehicleDataName( + const std::string& name) const { + const auto& schema = FindSchemaByNameNonRecursive(name); + return schema.is_initialized(); +} + +bool CustomVehicleDataManagerImpl::IsRemovedCustomVehicleDataName( + const std::string& name) const { + const auto& schema = FindRemovedSchemaByNameNonRecursive(name); + return schema.is_initialized(); +} + +void CustomVehicleDataManagerImpl::CreateMobileMessageParams( + smart_objects::SmartObject& msg_params) { + using namespace application_manager; + LOG4CXX_AUTO_TRACE(logger_); + + typedef std::function<smart_objects::SmartObject( + const smart_objects::SmartObject& input_params, + SearchMethod search_method)> + MobileMsgConstructor; + + MobileMsgConstructor fill_mobile_msg = + [this, &fill_mobile_msg]( + const smart_objects::SmartObject& input_params, + SearchMethod search_method) -> smart_objects::SmartObject { + smart_objects::SmartObject out_params; + + const auto& items = input_params.enumerate(); + for (const auto& key : items) { + auto schema = search_method == SearchMethod::RECURSIVE + ? FindSchemaByKeyRecursive(key) + : FindSchemaByKeyNonRecursive(key); + if (!schema.is_initialized()) { + LOG4CXX_DEBUG(logger_, "Schema for: " << key << " cannot be found"); + continue; + } + + const auto& item_name = schema->name; + if (policy_table::VehicleDataItem::kStruct == std::string(schema->type)) { + auto& input_param = input_params[key]; + if (*schema->array && + input_param.getType() == smart_objects::SmartType_Array) { + for (size_t i = 0; i < input_param.length(); i++) { + const auto param = + fill_mobile_msg(input_param[i], SearchMethod::RECURSIVE); + out_params[item_name][i] = param; + } + continue; + } else { + const auto param = + fill_mobile_msg(input_param, SearchMethod::RECURSIVE); + if (!param.empty()) { + out_params[item_name] = param; + continue; + } + } + } + + out_params[item_name] = input_params[key]; + } + + return out_params; + }; + + const auto& rpc_spec_vehicle_data = MessageHelper::vehicle_data(); + const auto& item_names = msg_params.enumerate(); + smart_objects::SmartObject params_to_convert; + + for (const auto& item_key : item_names) { + const auto& found_it = rpc_spec_vehicle_data.find(item_key); + if (found_it == rpc_spec_vehicle_data.end()) { + params_to_convert[item_key] = msg_params[item_key]; + msg_params.erase(item_key); + } + } + + const auto& mobile_msg_params = + fill_mobile_msg(params_to_convert, SearchMethod::NON_RECURSIVE); + for (const auto& name : mobile_msg_params.enumerate()) { + msg_params[name] = mobile_msg_params[name]; + } +} + +smart_objects::SmartObject CustomVehicleDataManagerImpl::CreateHMIMessageParams( + const std::set<std::string>& item_names) { + typedef std::function<smart_objects::SmartObject( + const policy_table::VehicleDataItem&)> + ParamsConstructor; + + auto fill_param = [](ParamsConstructor& constructor, + const policy_table::VehicleDataItem& param, + smart_objects::SmartObject* out_params) { + DCHECK_OR_RETURN_VOID(out_params) + const auto param_key = std::string(param.key); + const auto param_type = std::string(param.type); + if (policy_table::VehicleDataItem::kStruct == param_type) { + (*out_params)[param_key] = constructor(param); + } else { + (*out_params)[param_key] = true; + } + }; + + ParamsConstructor fill_hmi_params = + [&fill_hmi_params, + fill_param](const policy_table::VehicleDataItem& item) { + smart_objects::SmartObject out_params; + DCHECK(policy_table::VehicleDataItem::kStruct == + std::string(item.type)); + for (auto& param : *(item.params)) { + fill_param(fill_hmi_params, param, &out_params); + } + return out_params; + }; + + smart_objects::SmartObject out_params(smart_objects::SmartType_Map); + for (const auto& name : item_names) { + auto schema = FindSchemaByNameNonRecursive(name); + if (schema.is_initialized()) { + fill_param(fill_hmi_params, *schema, &out_params); + continue; + } + + auto removed_schema = FindRemovedSchemaByNameNonRecursive(name); + if (removed_schema.is_initialized()) { + fill_param(fill_hmi_params, *removed_schema, &out_params); + } + } + + return out_params; +} + +template <typename Comparer> +const OptionalDataItem FindSchema( + const std::vector<policy_table::VehicleDataItem>& oem_items, + SearchMethod search_method, + Comparer comparer) { + LOG4CXX_AUTO_TRACE(logger_); + + std::vector<policy_table::VehicleDataItem> items; + for (const auto& item : oem_items) { + if (comparer(item)) { + items.push_back(item); + } + if (search_method == SearchMethod::RECURSIVE && + policy_table::VehicleDataItem::kStruct == std::string(item.type)) { + auto found_in_params = + FindSchema(*(item.params), search_method, comparer); + if (found_in_params.is_initialized()) { + items.push_back(*found_in_params); + } + } + } + std::sort(items.begin(), + items.end(), + [](const policy_table::VehicleDataItem& left, + const policy_table::VehicleDataItem& right) { + if (!right.since.is_initialized()) { + return false; + } + if (!left.since.is_initialized()) { + return true; + } + const std::string l = *left.since; + const std::string r = *right.since; + return std::stof(l.c_str()) > std::stof(r.c_str()); + }); + + if (!items.empty()) { + return OptionalDataItem(*items.begin()); + } + + return OptionalDataItem(); +} + +void CustomVehicleDataManagerImpl::UpdateVehicleDataItems() { + using namespace ns_smart_device_link::ns_smart_objects; + using namespace policy_table; + + enum class SMemberType { + SMEMBER_MOBILE, + SMEMBER_HMI, + SMEMBER_BOOL_MOBILE, + SMEMBER_BOOL_HMI, + SMEMBER_VDR_MOBILE, + SMEMBER_VDR_HMI + }; + + auto get_custom_vdi = [this]() + -> std::vector<rpc::policy_table_interface_base::VehicleDataItem> { + using namespace rpc::policy_table_interface_base; + std::vector<VehicleDataItem> custom_vehicle_data_items; + auto vehicle_data_items = vehicle_data_provider_.GetVehicleDataItems(); + for (const auto& item : vehicle_data_items) { + policy_table::Parameter parameter_enum; + if (!policy_table::EnumFromJsonString(item.name, ¶meter_enum)) { + custom_vehicle_data_items.push_back(item); + } + } + return custom_vehicle_data_items; + }; + + auto vehicle_data_items = get_custom_vdi(); + + auto get_ischema_item = [](const VehicleDataItem& item, + SMemberType type, + std::vector<SMember> history = {}) -> SMember { + switch (type) { + case SMemberType::SMEMBER_BOOL_MOBILE: { + auto member_schema = + CBoolSchemaItem::create(TSchemaItemParameter<bool>()); + return SMember( + member_schema, + false, // root level items should not be mandatory + item.since.is_initialized() ? std::string(*item.since) : "", + item.until.is_initialized() ? std::string(*item.until) : "", + bool(*item.deprecated), + bool(*item.removed), + history); + } + case SMemberType::SMEMBER_VDR_MOBILE: { + // valid since struct_schema_items is not used in + // InitStructSchemaItem_VehicleDataResult + mobile_apis::MOBILE_API::TStructsSchemaItems mobile_struct_schema_items; + auto member_schema = + mobile_apis::MOBILE_API::InitStructSchemaItem_VehicleDataResult( + mobile_struct_schema_items); + return SMember( + member_schema, + false, // root level items should not be mandatory + item.since.is_initialized() ? std::string(*item.since) : "", + item.until.is_initialized() ? std::string(*item.until) : "", + bool(*item.deprecated), + bool(*item.removed), + history); + } + case SMemberType::SMEMBER_MOBILE: { + TSchemaItemParameter<VehicleDataItem> tschema_item(item); + auto member_schema = VehicleDataItemSchema::create( + tschema_item, VehicleDataItemSchema::SchemaType::MOBILE); + return SMember( + member_schema, + false, // root level items should not be mandatory + item.since.is_initialized() ? std::string(*item.since) : "", + item.until.is_initialized() ? std::string(*item.until) : "", + bool(*item.deprecated), + bool(*item.removed), + history); + } + case SMemberType::SMEMBER_BOOL_HMI: { + auto member_schema = + CBoolSchemaItem::create(TSchemaItemParameter<bool>()); + return SMember(member_schema, + false // root level items should not be mandatory + ); + } + case SMemberType::SMEMBER_VDR_HMI: { + // valid since struct_schema_items is not used in + // InitStructSchemaItem_Common_VehicleDataResult + hmi_apis::HMI_API::TStructsSchemaItems hmi_struct_schema_items; + auto member_schema = + hmi_apis::HMI_API::InitStructSchemaItem_Common_VehicleDataResult( + hmi_struct_schema_items); + return SMember( + member_schema, false // root level items should not be mandatory + ); + } + case SMemberType::SMEMBER_HMI: { + TSchemaItemParameter<VehicleDataItem> tschema_item(item); + auto member_schema = VehicleDataItemSchema::create( + tschema_item, VehicleDataItemSchema::SchemaType::HMI); + return SMember( + member_schema, false // root level items should not be mandatory + ); + } + default: { + auto member_schema = CAlwaysFalseSchemaItem::create(); + return SMember(member_schema, false); + } + } + }; + + auto get_vehicle_data_history = + [&vehicle_data_items](std::string name) -> std::vector<VehicleDataItem> { + std::vector<VehicleDataItem> result; + std::copy_if(vehicle_data_items.begin(), + vehicle_data_items.end(), + std::back_inserter(result), + [&name](VehicleDataItem& item) { return item.name == name; }); + + std::sort(result.begin(), + result.end(), + [](const policy_table::VehicleDataItem& left, + const policy_table::VehicleDataItem& right) { + if (!right.since.is_initialized()) { + return false; + } + if (!left.since.is_initialized()) { + return true; + } + const std::string l = *left.since; + const std::string r = *right.since; + return std::stof(l.c_str()) > std::stof(r.c_str()); + }); + + return result; + }; + + auto get_member_with_history = [&get_ischema_item]( + std::vector<VehicleDataItem> items, + SMemberType type) -> SMember { + std::vector<SMember> history = {}; + std::vector<SMemberType> types{SMemberType::SMEMBER_MOBILE, + SMemberType::SMEMBER_VDR_MOBILE, + SMemberType::SMEMBER_BOOL_MOBILE}; + if (helpers::in_range(types, type) && items.size() > 1) { + auto history_iterator = items.begin() + 1; + for (; history_iterator < items.end(); ++history_iterator) { + const auto& item = (*history_iterator); + history.push_back(get_ischema_item(item, type)); + } + } + + auto latest_item = (*items.begin()); + return get_ischema_item(latest_item, type, history); + }; + + CustomVehicleDataManagerImpl::RPCParams mobile_params; + CustomVehicleDataManagerImpl::RPCParams hmi_params; + + std::set<std::string> vehicle_data_names; + for (const auto& item : vehicle_data_items) { + vehicle_data_names.insert(item.name); + } + + for (const auto& name : vehicle_data_names) { + auto vehicle_data_history = get_vehicle_data_history(name); + const auto& vdi = vehicle_data_history.begin(); + + SMember member_bool_hmi = get_member_with_history( + vehicle_data_history, SMemberType::SMEMBER_BOOL_HMI); + SMember member_bool_mobile = get_member_with_history( + vehicle_data_history, SMemberType::SMEMBER_BOOL_MOBILE); + + SMember member_vdr_hmi = get_member_with_history( + vehicle_data_history, SMemberType::SMEMBER_VDR_HMI); + SMember member_vdr_mobile = get_member_with_history( + vehicle_data_history, SMemberType::SMEMBER_VDR_MOBILE); + SMember member_hmi = + get_member_with_history(vehicle_data_history, SMemberType::SMEMBER_HMI); + SMember member_mobile = get_member_with_history( + vehicle_data_history, SMemberType::SMEMBER_MOBILE); + + mobile_params.addBoolParam( + std::pair<std::string, SMember>(vdi->name, member_bool_mobile)); + mobile_params.addVDRParam( + std::pair<std::string, SMember>(vdi->name, member_vdr_mobile)); + mobile_params.addParam( + std::pair<std::string, SMember>(vdi->name, member_mobile)); + + hmi_params.addBoolParam( + std::pair<std::string, SMember>(vdi->key, member_bool_hmi)); + hmi_params.addVDRParam( + std::pair<std::string, SMember>(vdi->key, member_vdr_hmi)); + hmi_params.addParam(std::pair<std::string, SMember>(vdi->key, member_hmi)); + } + + std::vector<mobile_apis::FunctionID::eType> mobile_subscribe_functions{ + mobile_apis::FunctionID::SubscribeVehicleDataID, + mobile_apis::FunctionID::UnsubscribeVehicleDataID}; + + for (const auto& function_id : mobile_subscribe_functions) { + rpc_service_.UpdateMobileRPCParams(function_id, + mobile_apis::messageType::request, + mobile_params.getBoolParams()); + rpc_service_.UpdateMobileRPCParams(function_id, + mobile_apis::messageType::response, + mobile_params.getVDRParams()); + } + + std::vector<hmi_apis::FunctionID::eType> hmi_subscribe_functions{ + hmi_apis::FunctionID::VehicleInfo_SubscribeVehicleData, + hmi_apis::FunctionID::VehicleInfo_UnsubscribeVehicleData}; + + for (const auto& function_id : hmi_subscribe_functions) { + rpc_service_.UpdateHMIRPCParams(function_id, + hmi_apis::messageType::request, + hmi_params.getBoolParams()); + rpc_service_.UpdateHMIRPCParams(function_id, + hmi_apis::messageType::response, + hmi_params.getVDRParams()); + } + + rpc_service_.UpdateMobileRPCParams(mobile_apis::FunctionID::GetVehicleDataID, + mobile_apis::messageType::request, + mobile_params.getBoolParams()); + + rpc_service_.UpdateMobileRPCParams(mobile_apis::FunctionID::GetVehicleDataID, + mobile_apis::messageType::response, + mobile_params.getParams()); + + rpc_service_.UpdateMobileRPCParams(mobile_apis::FunctionID::OnVehicleDataID, + mobile_apis::messageType::notification, + mobile_params.getParams()); + + rpc_service_.UpdateHMIRPCParams( + hmi_apis::FunctionID::VehicleInfo_GetVehicleData, + hmi_apis::messageType::request, + hmi_params.getBoolParams()); + + rpc_service_.UpdateHMIRPCParams( + hmi_apis::FunctionID::VehicleInfo_GetVehicleData, + hmi_apis::messageType::response, + hmi_params.getParams()); + + rpc_service_.UpdateHMIRPCParams( + hmi_apis::FunctionID::VehicleInfo_OnVehicleData, + hmi_apis::messageType::notification, + hmi_params.getParams()); +} + +void CustomVehicleDataManagerImpl::OnPolicyEvent( + plugin_manager::PolicyEvent policy_event) { + using namespace plugin_manager; + LOG4CXX_AUTO_TRACE(logger_); + + switch (policy_event) { + case kApplicationPolicyUpdated: + UpdateVehicleDataItems(); + break; + case kApplicationsDisabled: + default: + return; + } +} + +const OptionalDataItem +CustomVehicleDataManagerImpl::FindSchemaByNameNonRecursive( + const std::string& name) const { + LOG4CXX_AUTO_TRACE(logger_); + + auto& oem_items = vehicle_data_provider_.GetVehicleDataItems(); + auto compare_by_name = [&name](const policy_table::VehicleDataItem& item) { + return (name == std::string(item.name)); + }; + + return FindSchema(oem_items, SearchMethod::NON_RECURSIVE, compare_by_name); +} + +const OptionalDataItem +CustomVehicleDataManagerImpl::FindRemovedSchemaByNameNonRecursive( + const std::string& name) const { + LOG4CXX_AUTO_TRACE(logger_); + + const auto& removed_oem_items = + vehicle_data_provider_.GetRemovedVehicleDataItems(); + auto compare_by_name = [&name](const policy_table::VehicleDataItem& item) { + return (name == std::string(item.name)); + }; + + return FindSchema( + removed_oem_items, SearchMethod::NON_RECURSIVE, compare_by_name); +} + +const OptionalDataItem CustomVehicleDataManagerImpl::FindSchemaByNameRecursive( + const std::string& name) const { + LOG4CXX_AUTO_TRACE(logger_); + + auto& oem_items = vehicle_data_provider_.GetVehicleDataItems(); + auto compare_by_name = [&name](const policy_table::VehicleDataItem& item) { + return (name == std::string(item.name)); + }; + + return FindSchema(oem_items, SearchMethod::RECURSIVE, compare_by_name); +} + +const OptionalDataItem +CustomVehicleDataManagerImpl::FindSchemaByKeyNonRecursive( + const std::string& key) const { + LOG4CXX_AUTO_TRACE(logger_); + + auto& oem_items = vehicle_data_provider_.GetVehicleDataItems(); + auto compare_by_key = [&key](const policy_table::VehicleDataItem& item) { + return (key == std::string(item.key)); + }; + + return FindSchema(oem_items, SearchMethod::NON_RECURSIVE, compare_by_key); +} + +const OptionalDataItem CustomVehicleDataManagerImpl::FindSchemaByKeyRecursive( + const std::string& key) const { + LOG4CXX_AUTO_TRACE(logger_); + + auto& oem_items = vehicle_data_provider_.GetVehicleDataItems(); + auto compare_by_key = [&key](const policy_table::VehicleDataItem& item) { + return (key == std::string(item.key)); + }; + + return FindSchema(oem_items, SearchMethod::RECURSIVE, compare_by_key); +} + +} // namespace vehicle_info_plugin diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_data_item_schema.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_data_item_schema.cc new file mode 100644 index 0000000000..750da9fa6e --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_data_item_schema.cc @@ -0,0 +1,188 @@ +#include "vehicle_info_plugin/vehicle_data_item_schema.h" +#include <limits> + +namespace vehicle_info_plugin { + +#ifdef ENABLE_LOG +CREATE_LOGGERPTR_LOCAL(vehicle_data_logger, "VehicleDataItemSchema"); +#endif // ENABLE_LOG + +VehicleDataItemSchema::VehicleDataItemSchema(PolicyDataItem& policy_item, + SchemaType schema_type) { + policy_table::VehicleDataItem policy_data_item; + policy_item.getValue(policy_data_item); + + auto get_object_schema = [&policy_data_item, + &schema_type]() -> decltype(so_schema_item_) { + smart_objects::Members members; + auto object_schema = smart_objects::CObjectSchemaItem::create(members); + + for (auto& e : *policy_data_item.params) { + auto schema_item = PolicyDataItem(e); + smart_objects::SMember member(create(schema_item, schema_type), + bool(e.mandatory), + std::string(*e.since), + std::string(*e.until), + bool(*e.deprecated), + bool(*e.removed)); + std::string name; + switch (schema_type) { + case VehicleDataItemSchema::SchemaType::HMI: + name = e.key; + break; + case VehicleDataItemSchema::SchemaType::MOBILE: + default: + name = e.name; + break; + } + object_schema->AddMemberSchemaItem(name, member); + } + + return object_schema; + }; + + auto get_schema = [&policy_data_item, + &get_object_schema, + &schema_type, + this]() -> decltype(so_schema_item_) { + // Check if policy item has POD type + if (isPODType(policy_data_item.type)) { + return GetPODTypeSchema(policy_data_item, schema_type); + } + + // Check if policy item has Struct type + if (policy_data_item.type == policy_table::VehicleDataItem::kStruct) { + return get_object_schema(); + } + + // Check if policy item has Enum type + auto enum_schema = getEnumSchema(policy_data_item.type); + if (enum_schema != nullptr) { + return enum_schema; + } + + // If an unknown type is present in the policy table, it is assumed that it + // is a future enum type. Since normal validation cannot be performed on + // this value, it is treated as a raw string instead + policy_data_item.type = "String"; + + return GetPODTypeSchema(policy_data_item, schema_type); + }; + + if (*policy_data_item.array) { + so_schema_item_ = smart_objects::CArraySchemaItem::create( + get_schema(), + policy_data_item.minsize.is_initialized() + ? smart_objects::TSchemaItemParameter<size_t>( + *policy_data_item.minsize) + : smart_objects::TSchemaItemParameter<size_t>(), + policy_data_item.maxsize.is_initialized() + ? smart_objects::TSchemaItemParameter<size_t>( + *policy_data_item.maxsize) + : smart_objects::TSchemaItemParameter<size_t>()); + } else { + so_schema_item_ = get_schema(); + } +} + +VehicleDataItemSchemaPtr VehicleDataItemSchema::create( + PolicyDataItem& policy_item, SchemaType schema_type) { + return VehicleDataItemSchemaPtr( + new VehicleDataItemSchema(policy_item, schema_type)); +} + +smart_objects::errors::eType +vehicle_info_plugin::VehicleDataItemSchema::validate( + const smart_objects::SmartObject& Object, + rpc::ValidationReport* report__, + const utils::SemanticVersion& MessageVersion, + const bool allow_unknown_enums) { + if (!so_schema_item_) { + std::string validation_info = + "Invalid type: " + + smart_objects::SmartObject::typeToString(Object.getType()); + report__->set_validation_info(validation_info); + return smart_objects::errors::eType::ERROR; + } + + return so_schema_item_->validate( + Object, report__, MessageVersion, allow_unknown_enums); +} + +smart_objects::ISchemaItemPtr VehicleDataItemSchema::GetPODTypeSchema( + const policy_table::VehicleDataItem& policy_item, SchemaType schema_type) { + using IntSchemaItem = smart_objects::TNumberSchemaItem<int64_t>; + using IntItemParam = smart_objects::TSchemaItemParameter<int64_t>; + using FloatSchemaItem = smart_objects::TNumberSchemaItem<double>; + using FloatItemParam = smart_objects::TSchemaItemParameter<double>; + using StringSchemaItem = smart_objects::CStringSchemaItem; + using StringItemParam = smart_objects::TSchemaItemParameter<size_t>; + using BoolSchemaItem = smart_objects::CBoolSchemaItem; + using BoolItemParam = smart_objects::TSchemaItemParameter<bool>; + + if (policy_item.type == policy_table::VehicleDataItem::kInteger) { + return IntSchemaItem::create(policy_item.minvalue.is_initialized() + ? IntItemParam(*policy_item.minvalue) + : IntItemParam(), + policy_item.maxvalue.is_initialized() + ? IntItemParam(*policy_item.maxvalue) + : IntItemParam()); + } + if (policy_item.type == policy_table::VehicleDataItem::kFloat || + policy_item.type == policy_table::VehicleDataItem::kDouble) { + return FloatSchemaItem::create( + policy_item.minvalue.is_initialized() + ? FloatItemParam(double(*policy_item.minvalue)) + : FloatItemParam(), + policy_item.maxvalue.is_initialized() + ? FloatItemParam(double(*policy_item.maxvalue)) + : FloatItemParam()); + } + if (policy_item.type == policy_table::VehicleDataItem::kString) { + return StringSchemaItem::create( + StringItemParam(policy_item.minlength.is_initialized() + ? *policy_item.minlength + : 0), + policy_item.maxlength.is_initialized() + ? StringItemParam(*policy_item.maxlength) + : StringItemParam()); + } + if (policy_item.type == policy_table::VehicleDataItem::kBoolean) { + return BoolSchemaItem::create(BoolItemParam(true)); + } + + std::string error_msg = std::string("Invalid POD type provided: ") + + std::string(policy_item.type); + LOG4CXX_ERROR(vehicle_data_logger, error_msg.c_str()); + return nullptr; +} + +const bool VehicleDataItemSchema::isPODType( + const std::string& type_name) const { + return std::find(policy_table::VehicleDataItem::kPODTypes.begin(), + policy_table::VehicleDataItem::kPODTypes.end(), + type_name) != policy_table::VehicleDataItem::kPODTypes.end(); +} + +smart_objects::ISchemaItemPtr VehicleDataItemSchema::getEnumSchema( + const std::string& type_name) const { + auto enum_schema = policy_table::EnumSchemaItemFactory::Get(type_name); + if (!enum_schema) { + LOG4CXX_ERROR(vehicle_data_logger, "NULL pointer: " << type_name); + } + return enum_schema; +} + +void VehicleDataItemSchema::applySchema( + smart_objects::SmartObject& Object, + const bool remove_unknown_parameters, + const utils::SemanticVersion& MessageVersion) { + so_schema_item_->applySchema( + Object, remove_unknown_parameters, MessageVersion); +} + +void VehicleDataItemSchema::unapplySchema( + smart_objects::SmartObject& Object, const bool remove_unknown_parameters) { + so_schema_item_->unapplySchema(Object, remove_unknown_parameters); +} +} // namespace vehicle_info_plugin diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_app_extension.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_app_extension.cc index 730812e9c8..149299d3bb 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_app_extension.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_app_extension.cc @@ -53,13 +53,13 @@ VehicleInfoAppExtension::~VehicleInfoAppExtension() { } bool VehicleInfoAppExtension::subscribeToVehicleInfo( - const VehicleDataType vehicle_data) { + const std::string& vehicle_data) { LOG4CXX_DEBUG(logger_, vehicle_data); return subscribed_data_.insert(vehicle_data).second; } bool VehicleInfoAppExtension::unsubscribeFromVehicleInfo( - const VehicleDataType vehicle_data) { + const std::string& vehicle_data) { LOG4CXX_DEBUG(logger_, vehicle_data); auto it = subscribed_data_.find(vehicle_data); if (it != subscribed_data_.end()) { @@ -75,7 +75,7 @@ void VehicleInfoAppExtension::unsubscribeFromVehicleInfo() { } bool VehicleInfoAppExtension::isSubscribedToVehicleInfo( - const VehicleDataType vehicle_data) const { + const std::string& vehicle_data) const { LOG4CXX_DEBUG(logger_, vehicle_data); return subscribed_data_.find(vehicle_data) != subscribed_data_.end(); } @@ -91,7 +91,7 @@ void VehicleInfoAppExtension::SaveResumptionData( smart_objects::SmartObject(smart_objects::SmartType_Array); int i = 0; for (const auto& subscription : subscribed_data_) { - resumption_data[application_vehicle_info][i] = subscription; + resumption_data[application_vehicle_info][i++] = subscription; } } @@ -99,13 +99,12 @@ void VehicleInfoAppExtension::ProcessResumption( const smart_objects::SmartObject& resumption_data) { const char* application_vehicle_info = "vehicleInfo"; if (resumption_data.keyExists(application_vehicle_info)) { - const smart_objects::SmartObject& subscriptions_ivi = - resumption_data[application_vehicle_info]; - for (size_t i = 0; i < subscriptions_ivi.length(); ++i) { - mobile_apis::VehicleDataType::eType ivi = - static_cast<mobile_apis::VehicleDataType::eType>( - (resumption_data[i]).asInt()); - subscribeToVehicleInfo(ivi); + const auto* subscriptions_ivi = + resumption_data[application_vehicle_info].asArray(); + if (subscriptions_ivi) { + for (const auto& ivi : (*subscriptions_ivi)) { + subscribeToVehicleInfo(ivi.asString()); + } } plugin_.ProcessResumptionSubscription(app_, *this); } diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_command_factory.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_command_factory.cc index 617925589f..52ee9f476d 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_command_factory.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_command_factory.cc @@ -36,15 +36,27 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "VehicleInfoPlugin") namespace vehicle_info_plugin { +namespace app_mngr = application_manager; +namespace commands = application_manager::commands; + VehicleInfoCommandFactory::VehicleInfoCommandFactory( app_mngr::ApplicationManager& application_manager, app_mngr::rpc_service::RPCService& rpc_service, app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) - : hmi_command_factory_(new VehicleInfoHmiCommandFactory( - application_manager, rpc_service, hmi_capabilities, policy_handler)) - , mob_command_factory_(new VehicleInfoMobileCommandFactory( - application_manager, rpc_service, hmi_capabilities, policy_handler)) { + policy::PolicyHandlerInterface& policy_handler, + CustomVehicleDataManager& custom_vehicle_data_manager) + : hmi_command_factory_( + new VehicleInfoHmiCommandFactory(application_manager, + rpc_service, + hmi_capabilities, + policy_handler, + custom_vehicle_data_manager)) + , mob_command_factory_( + new VehicleInfoMobileCommandFactory(application_manager, + rpc_service, + hmi_capabilities, + policy_handler, + custom_vehicle_data_manager)) { LOG4CXX_AUTO_TRACE(logger_); } diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_hmi_command_factory.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_hmi_command_factory.cc index dd3b43920a..e8d852b612 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_hmi_command_factory.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_hmi_command_factory.cc @@ -57,15 +57,75 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "VehicleInfoPlugin") namespace vehicle_info_plugin { namespace strings = app_mngr::strings; +template <typename VehicleInfoCommandType> +class VehicleInfoCommandCreator : public application_manager::CommandCreator { + public: + VehicleInfoCommandCreator(const VehicleInfoCommandParams& params) + : params_(params) {} + + private: + bool CanBeCreated() const override { + return true; + } + + application_manager::CommandSharedPtr create( + const application_manager::commands::MessageSharedPtr& message) + const override { + application_manager::CommandSharedPtr command( + new VehicleInfoCommandType(message, params_)); + return command; + } + + VehicleInfoCommandParams params_; +}; + +struct VehicleInfoInvalidCommand {}; + +template <> +class VehicleInfoCommandCreator<VehicleInfoInvalidCommand> + : public application_manager::CommandCreator { + public: + VehicleInfoCommandCreator(const VehicleInfoCommandParams& params) { + UNUSED(params); + } + + private: + bool CanBeCreated() const override { + return false; + } + + application_manager::CommandSharedPtr create( + const application_manager::commands::MessageSharedPtr& message) + const override { + UNUSED(message); + return application_manager::CommandSharedPtr(); + } +}; + +struct VehicleInfoCommandCreatorFactory { + VehicleInfoCommandCreatorFactory(const VehicleInfoCommandParams& params) + : params_(params) {} + + template <typename VehicleInfoCommandType> + application_manager::CommandCreator& GetCreator() { + LOG4CXX_AUTO_TRACE(logger_); + static VehicleInfoCommandCreator<VehicleInfoCommandType> res(params_); + return res; + } + const VehicleInfoCommandParams params_; +}; + VehicleInfoHmiCommandFactory::VehicleInfoHmiCommandFactory( application_manager::ApplicationManager& application_manager, application_manager::rpc_service::RPCService& rpc_service, application_manager::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) + policy::PolicyHandlerInterface& policy_handler, + CustomVehicleDataManager& custom_vehicle_data_manager) : application_manager_(application_manager) , rpc_service_(rpc_service) , hmi_capabilities_(hmi_capabilities) - , policy_handler_(policy_handler) { + , policy_handler_(policy_handler) + , custom_vehicle_data_manager_(custom_vehicle_data_manager) { LOG4CXX_AUTO_TRACE(logger_); } @@ -107,9 +167,12 @@ bool VehicleInfoHmiCommandFactory::IsAbleToProcess( app_mngr::CommandCreator& VehicleInfoHmiCommandFactory::buildCommandCreator( const int32_t function_id, const int32_t message_type) const { - auto factory = app_mngr::CommandCreatorFactory( - application_manager_, rpc_service_, hmi_capabilities_, policy_handler_); - + VehicleInfoCommandParams params = {application_manager_, + rpc_service_, + hmi_capabilities_, + policy_handler_, + custom_vehicle_data_manager_}; + auto factory = VehicleInfoCommandCreatorFactory(params); switch (function_id) { case hmi_apis::FunctionID::VehicleInfo_GetVehicleType: return hmi_apis::messageType::request == message_type @@ -150,7 +213,7 @@ app_mngr::CommandCreator& VehicleInfoHmiCommandFactory::buildCommandCreator( : factory.GetCreator<commands::VIDiagnosticMessageResponse>(); default: LOG4CXX_WARN(logger_, "Unsupported function_id: " << function_id); - return factory.GetCreator<app_mngr::InvalidCommand>(); + return factory.GetCreator<VehicleInfoInvalidCommand>(); } } } // namespace vehicle_info_plugin diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_mobile_command_factory.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_mobile_command_factory.cc index dffc836a89..c3c8d9c8d7 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_mobile_command_factory.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_mobile_command_factory.cc @@ -34,6 +34,9 @@ #include "application_manager/message.h" #include "interfaces/MOBILE_API.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" + +#include "vehicle_info_plugin/custom_vehicle_data_manager.h" #include "vehicle_info_plugin/commands/mobile/diagnostic_message_request.h" #include "vehicle_info_plugin/commands/mobile/diagnostic_message_response.h" @@ -54,21 +57,83 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "VehicleInfoPlugin") namespace vehicle_info_plugin { namespace strings = app_mngr::strings; +template <typename VehicleInfoCommandType> +class VehicleInfoCommandCreator : public application_manager::CommandCreator { + public: + VehicleInfoCommandCreator(const VehicleInfoCommandParams& params) + : params_(params) {} + + private: + bool CanBeCreated() const override { + return true; + } + + application_manager::CommandSharedPtr create( + const application_manager::commands::MessageSharedPtr& message) + const override { + application_manager::CommandSharedPtr command( + new VehicleInfoCommandType(message, params_)); + return command; + } + + VehicleInfoCommandParams params_; +}; + +struct VehicleInfoInvalidCommand {}; + +template <> +class VehicleInfoCommandCreator<VehicleInfoInvalidCommand> + : public application_manager::CommandCreator { + public: + VehicleInfoCommandCreator(const VehicleInfoCommandParams& params) { + UNUSED(params); + } + + private: + bool CanBeCreated() const override { + return false; + } + + application_manager::CommandSharedPtr create( + const application_manager::commands::MessageSharedPtr& message) + const override { + UNUSED(message); + return application_manager::CommandSharedPtr(); + } +}; + +struct VehicleInfoCommandCreatorFactory { + VehicleInfoCommandCreatorFactory(const VehicleInfoCommandParams& params) + : params_(params) {} + + template <typename VehicleInfoCommandType> + application_manager::CommandCreator& GetCreator() { + LOG4CXX_AUTO_TRACE(logger_); + static VehicleInfoCommandCreator<VehicleInfoCommandType> res(params_); + return res; + } + const VehicleInfoCommandParams params_; +}; + VehicleInfoMobileCommandFactory::VehicleInfoMobileCommandFactory( application_manager::ApplicationManager& application_manager, application_manager::rpc_service::RPCService& rpc_service, application_manager::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) + policy::PolicyHandlerInterface& policy_handler, + CustomVehicleDataManager& custom_vehicle_data_manager) : application_manager_(application_manager) , rpc_service_(rpc_service) , hmi_capabilities_(hmi_capabilities) - , policy_handler_(policy_handler) { + , policy_handler_(policy_handler) + , custom_vehicle_data_manager_(custom_vehicle_data_manager) { LOG4CXX_AUTO_TRACE(logger_); } app_mngr::CommandSharedPtr VehicleInfoMobileCommandFactory::CreateCommand( const app_mngr::commands::MessageSharedPtr& message, app_mngr::commands::Command::CommandSource source) { + UNUSED(source); + const mobile_apis::FunctionID::eType function_id = static_cast<mobile_apis::FunctionID::eType>( (*message)[strings::params][strings::function_id].asInt()); @@ -105,8 +170,12 @@ bool VehicleInfoMobileCommandFactory::IsAbleToProcess( app_mngr::CommandCreator& VehicleInfoMobileCommandFactory::get_command_creator( const mobile_apis::FunctionID::eType id, const mobile_apis::messageType::eType message_type) const { - auto factory = app_mngr::CommandCreatorFactory( - application_manager_, rpc_service_, hmi_capabilities_, policy_handler_); + VehicleInfoCommandParams params = {application_manager_, + rpc_service_, + hmi_capabilities_, + policy_handler_, + custom_vehicle_data_manager_}; + auto factory = VehicleInfoCommandCreatorFactory(params); switch (id) { case mobile_apis::FunctionID::GetVehicleDataID: { return mobile_apis::messageType::request == message_type @@ -141,21 +210,25 @@ app_mngr::CommandCreator& VehicleInfoMobileCommandFactory::get_command_creator( } default: {} } - return factory.GetCreator<app_mngr::InvalidCommand>(); + return factory.GetCreator<VehicleInfoInvalidCommand>(); } app_mngr::CommandCreator& VehicleInfoMobileCommandFactory::get_notification_creator( const mobile_apis::FunctionID::eType id) const { - auto factory = app_mngr::CommandCreatorFactory( - application_manager_, rpc_service_, hmi_capabilities_, policy_handler_); + VehicleInfoCommandParams params = {application_manager_, + rpc_service_, + hmi_capabilities_, + policy_handler_, + custom_vehicle_data_manager_}; + auto factory = VehicleInfoCommandCreatorFactory(params); switch (id) { case mobile_apis::FunctionID::OnVehicleDataID: { return factory.GetCreator<commands::OnVehicleDataNotification>(); } default: {} } - return factory.GetCreator<app_mngr::InvalidCommand>(); + return factory.GetCreator<VehicleInfoInvalidCommand>(); } app_mngr::CommandCreator& VehicleInfoMobileCommandFactory::get_creator_factory( @@ -183,8 +256,12 @@ app_mngr::CommandCreator& VehicleInfoMobileCommandFactory::get_creator_factory( } default: {} } - auto factory = app_mngr::CommandCreatorFactory( - application_manager_, rpc_service_, hmi_capabilities_, policy_handler_); - return factory.GetCreator<app_mngr::InvalidCommand>(); + VehicleInfoCommandParams params = {application_manager_, + rpc_service_, + hmi_capabilities_, + policy_handler_, + custom_vehicle_data_manager_}; + auto factory = VehicleInfoCommandCreatorFactory(params); + return factory.GetCreator<VehicleInfoInvalidCommand>(); } } // namespace vehicle_info_plugin 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 70210f704e..3e8ef6b29d 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 @@ -33,7 +33,9 @@ #include "vehicle_info_plugin/vehicle_info_plugin.h" #include "application_manager/message_helper.h" #include "application_manager/plugin_manager/plugin_keys.h" +#include "application_manager/rpc_handler.h" #include "application_manager/smart_object_keys.h" +#include "vehicle_info_plugin/custom_vehicle_data_manager_impl.h" #include "vehicle_info_plugin/vehicle_info_app_extension.h" #include "vehicle_info_plugin/vehicle_info_command_factory.h" @@ -42,6 +44,7 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "VehicleInfoPlugin") namespace strings = application_manager::strings; namespace plugins = application_manager::plugin_manager; +namespace commands = application_manager::commands; VehicleInfoPlugin::VehicleInfoPlugin() : application_manager_(nullptr) {} @@ -49,10 +52,37 @@ bool VehicleInfoPlugin::Init( application_manager::ApplicationManager& app_manager, application_manager::rpc_service::RPCService& rpc_service, application_manager::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) { + policy::PolicyHandlerInterface& policy_handler, + resumption::LastStateWrapperPtr last_state) { + UNUSED(last_state); application_manager_ = &app_manager; + custom_vehicle_data_manager_.reset( + new CustomVehicleDataManagerImpl(policy_handler, rpc_service)); command_factory_.reset(new vehicle_info_plugin::VehicleInfoCommandFactory( - app_manager, rpc_service, hmi_capabilities, policy_handler)); + app_manager, + rpc_service, + hmi_capabilities, + policy_handler, + *(custom_vehicle_data_manager_.get()))); + 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; } @@ -69,7 +99,10 @@ app_mngr::CommandFactory& VehicleInfoPlugin::GetCommandFactory() { return *command_factory_; } -void VehicleInfoPlugin::OnPolicyEvent(plugins::PolicyEvent event) {} +void VehicleInfoPlugin::OnPolicyEvent(plugins::PolicyEvent event) { + UnsubscribeFromRemovedVDItems(); + custom_vehicle_data_manager_->OnPolicyEvent(event); +} void VehicleInfoPlugin::OnApplicationEvent( plugins::ApplicationEvent event, @@ -77,11 +110,50 @@ void VehicleInfoPlugin::OnApplicationEvent( if (plugins::ApplicationEvent::kApplicationRegistered == event) { application->AddExtension( std::make_shared<VehicleInfoAppExtension>(*this, *application)); - } else if (plugins::ApplicationEvent::kDeleteApplicationData == event) { + } else if ((plugins::ApplicationEvent::kDeleteApplicationData == event) || + (plugins::ApplicationEvent::kApplicationUnregistered == event)) { DeleteSubscriptions(application); } } +void VehicleInfoPlugin::UnsubscribeFromRemovedVDItems() { + LOG4CXX_AUTO_TRACE(logger_); + typedef std::vector<std::string> StringsVector; + + auto get_items_to_unsubscribe = [this]() -> StringsVector { + StringsVector output_items_list; + auto applications = application_manager_->applications(); + for (auto& app : applications.GetData()) { + auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app); + auto subscription_names = ext.Subscriptions(); + for (auto& subscription_name : subscription_names) { + if (custom_vehicle_data_manager_->IsRemovedCustomVehicleDataName( + subscription_name)) { + ext.unsubscribeFromVehicleInfo(subscription_name); + if (!helpers::in_range(output_items_list, subscription_name)) { + LOG4CXX_DEBUG(logger_, + "Vehicle data item " + << subscription_name + << " has been removed by policy"); + output_items_list.push_back(subscription_name); + } + } + } + } + return output_items_list; + }; + + const StringsVector items_to_unsubscribe = get_items_to_unsubscribe(); + + if (items_to_unsubscribe.empty()) { + LOG4CXX_DEBUG(logger_, "There is no data to unsubscribe"); + return; + } + + auto message = GetUnsubscribeIVIRequest(items_to_unsubscribe); + application_manager_->GetRPCService().ManageHMICommand(message); +} + void VehicleInfoPlugin::ProcessResumptionSubscription( application_manager::Application& app, VehicleInfoAppExtension& ext) { LOG4CXX_AUTO_TRACE(logger_); @@ -89,13 +161,15 @@ void VehicleInfoPlugin::ProcessResumptionSubscription( smart_objects::SmartObject(smart_objects::SmartType_Map); msg_params[strings::app_id] = app.app_id(); const auto& subscriptions = ext.Subscriptions(); - for (auto& ivi_data : application_manager::MessageHelper::vehicle_data()) { - mobile_apis::VehicleDataType::eType type_id = ivi_data.second; - if (subscriptions.end() != subscriptions.find(type_id)) { - std::string key_name = ivi_data.first; - msg_params[key_name] = true; - } + if (subscriptions.empty()) { + LOG4CXX_DEBUG(logger_, "No vehicle data to subscribe. Exiting"); + return; + } + + for (const auto& item : subscriptions) { + msg_params[item] = true; } + smart_objects::SmartObjectSPtr request = application_manager::MessageHelper::CreateModuleInfoSO( hmi_apis::FunctionID::VehicleInfo_SubscribeVehicleData, @@ -105,38 +179,56 @@ void VehicleInfoPlugin::ProcessResumptionSubscription( } application_manager::ApplicationSharedPtr FindAppSubscribedToIVI( - mobile_apis::VehicleDataType::eType ivi_data, + const std::string& ivi_name, application_manager::ApplicationManager& app_mngr) { auto applications = app_mngr.applications(); for (auto& app : applications.GetData()) { auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app); - if (ext.isSubscribedToVehicleInfo(ivi_data)) { + if (ext.isSubscribedToVehicleInfo(ivi_name)) { return app; } } return application_manager::ApplicationSharedPtr(); } -smart_objects::SmartObjectSPtr GetUnsubscribeIVIRequest( - int32_t ivi_id, application_manager::ApplicationManager& app_mngr) { +smart_objects::SmartObjectSPtr VehicleInfoPlugin::GetUnsubscribeIVIRequest( + const std::vector<std::string>& ivi_names) { + LOG4CXX_AUTO_TRACE(logger_); using namespace smart_objects; - auto find_ivi_name = [ivi_id]() { + auto msg_params = smart_objects::SmartObject(smart_objects::SmartType_Map); + + auto find_ivi_name = [](const std::string& ivi_name) { for (auto item : application_manager::MessageHelper::vehicle_data()) { - if (ivi_id == item.second) { + if (ivi_name == item.first) { return item.first; } } return std::string(); }; - std::string key_name = find_ivi_name(); - DCHECK_OR_RETURN(!key_name.empty(), smart_objects::SmartObjectSPtr()); - auto msg_params = smart_objects::SmartObject(smart_objects::SmartType_Map); - msg_params[key_name] = true; + + for (const auto& ivi_name : ivi_names) { + // try to find the name in vehicle data types + std::string key_name = find_ivi_name(ivi_name); + + if (key_name.empty()) { + // the name hasn't been found in vehicle data types + if (custom_vehicle_data_manager_->IsValidCustomVehicleDataName( + ivi_name) || + custom_vehicle_data_manager_->IsRemovedCustomVehicleDataName( + ivi_name)) { + key_name = ivi_name; + } + } + + DCHECK_OR_RETURN(!key_name.empty(), smart_objects::SmartObjectSPtr()); + msg_params[key_name] = true; + } auto message = application_manager::MessageHelper::CreateMessageForHMI( - hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID()); + hmi_apis::messageType::request, + application_manager_->GetNextHMICorrelationID()); DCHECK(message); SmartObject& object = *message; @@ -151,18 +243,31 @@ void VehicleInfoPlugin::DeleteSubscriptions( application_manager::ApplicationSharedPtr app) { auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app); auto subscriptions = ext.Subscriptions(); + std::vector<std::string> ivi_to_unsubscribe; for (auto& ivi : subscriptions) { ext.unsubscribeFromVehicleInfo(ivi); auto still_subscribed_app = FindAppSubscribedToIVI(ivi, *application_manager_); if (!still_subscribed_app) { - auto message = GetUnsubscribeIVIRequest(ivi, *application_manager_); - application_manager_->GetRPCService().ManageHMICommand(message); + ivi_to_unsubscribe.push_back(ivi); } } + + if (!ivi_to_unsubscribe.empty()) { + auto message = GetUnsubscribeIVIRequest(ivi_to_unsubscribe); + application_manager_->GetRPCService().ManageHMICommand(message); + } } } // namespace vehicle_info_plugin -extern "C" application_manager::plugin_manager::RPCPlugin* Create() { +extern "C" __attribute__((visibility("default"))) +application_manager::plugin_manager::RPCPlugin* +Create() { return new vehicle_info_plugin::VehicleInfoPlugin(); } + +extern "C" __attribute__((visibility("default"))) void Delete( + application_manager::plugin_manager::RPCPlugin* data) { + delete data; + DELETE_THREAD_LOGGER(vehicle_info_plugin::logger_); +} 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 3ea4a50a8a..a8193c17f0 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 @@ -31,23 +31,30 @@ include(${CMAKE_SOURCE_DIR}/tools/cmake/helpers/sources.cmake) include_directories( + include ${GMOCK_INCLUDE_DIRECTORY} ${COMPONENTS_DIR}/application_manager/rpc_plugins/vehicle_info_plugin/include - ${COMPONENTS_DIR}/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/ + ${COMPONENTS_DIR}/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands ${COMPONENTS_DIR}/application_manager/test/include/ -) - - + ${COMPONENTS_DIR}/include/test/application_manager/ + ${COMPONENTS_DIR}/resumption/include/resumption/ + ) set(COMMANDS_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/commands) file(GLOB SOURCES ${COMPONENTS_DIR}/application_manager/test/mock_message_helper.cc ${COMPONENTS_DIR}/application_manager/test/mock_application_helper.cc ${COMPONENTS_DIR}/application_manager/src/smart_object_keys.cc + ${COMPONENTS_DIR}/${POLICY_PATH}/src/policy_table/types.cc + ${COMPONENTS_DIR}/${POLICY_PATH}/src/policy_table/validation.cc + ${COMPONENTS_DIR}/${POLICY_PATH}/src/policy_table/enums.cc ${COMMANDS_TEST_DIR}/hmi/* ${COMMANDS_TEST_DIR}/mobile/* + ${CMAKE_CURRENT_SOURCE_DIR}/custom_vehicle_data_manager_test.cc + ${CMAKE_CURRENT_SOURCE_DIR}/vehicle_data_item_schema_test.cc ${COMPONENTS_DIR}/application_manager/src/message.cc ${COMPONENTS_DIR}/application_manager/src/event_engine/* + ${COMPONENTS_DIR}/resumption/src/last_state_wrapper_impl.cc ) set(LIBRARIES @@ -58,6 +65,8 @@ set(LIBRARIES MOBILE_API connectionHandler vehicle_info_plugin + SmartObjects + formatters jsoncpp ) diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_data_request_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_data_request_test.cc new file mode 100644 index 0000000000..6bc956f65f --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_data_request_test.cc @@ -0,0 +1,110 @@ +/* + * 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/vi_get_vehicle_data_request.h" + +#include "gtest/gtest.h" + +#include "smart_objects/enum_schema_item.h" +#include "smart_objects/smart_object.h" +#include "vehicle_info_plugin/commands/vi_command_request_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vi_get_vehicle_data_request { + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; + +using vehicle_info_plugin::commands::VIGetVehicleDataRequest; + +namespace { +const std::string kMobileParam = "mobile_param"; +const std::string kHMIParam = "hmi_param"; +} // namespace + +class VIGetVehicleDataRequestTest + : public VICommandRequestTest<CommandsTestMocks::kIsNice> {}; + +MATCHER_P(EqualMsgParams, msg_params, "") { + using namespace app_mngr; + auto message = static_cast<smart_objects::SmartObject>(*arg); + if (!message.keyExists(strings::msg_params)) { + return false; + } + + return msg_params == message[strings::msg_params]; +} + +TEST_F(VIGetVehicleDataRequestTest, Run_Success) { + using namespace app_mngr; + auto command_msg = CreateMessage(smart_objects::SmartType_Map); + (*command_msg)[strings::msg_params][strings::rpm] = true; + (*command_msg)[strings::msg_params][kMobileParam] = true; + + am::VehicleData vehicle_data; + vehicle_data.insert(am::VehicleData::value_type( + strings::rpm, mobile_apis::VehicleDataType::VEHICLEDATA_RPM)); + ON_CALL(mock_message_helper_, vehicle_data()) + .WillByDefault(ReturnRef(vehicle_data)); + + std::string oem_vehicle_data_type_str; + smart_objects::EnumConversionHelper<mobile_apis::VehicleDataType::eType>:: + EnumToString(mobile_apis::VehicleDataType::VEHICLEDATA_OEM_CUSTOM_DATA, + &oem_vehicle_data_type_str); + + smart_objects::SmartObject hmi_params; + hmi_params[kHMIParam] = smart_objects::SmartType_Map; + hmi_params[kHMIParam][strings::data_type] = oem_vehicle_data_type_str; + ON_CALL(mock_custom_vehicle_data_manager_, CreateHMIMessageParams(_)) + .WillByDefault(Return(hmi_params)); + + smart_objects::SmartObject hmi_request_msg; + hmi_request_msg[strings::rpm] = + (*command_msg)[strings::msg_params][strings::rpm]; + hmi_request_msg[kHMIParam] = hmi_params[kHMIParam]; + + EXPECT_CALL(mock_rpc_service_, + SendMessageToHMI(EqualMsgParams(hmi_request_msg))); + + auto command = CreateCommandVI<VIGetVehicleDataRequest>(command_msg); + command->Run(); +} + +} // namespace vi_get_vehicle_data_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_data_response_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_data_response_test.cc index 575df4ce50..ea8dab0366 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_data_response_test.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_data_response_test.cc @@ -37,7 +37,6 @@ #include "gtest/gtest.h" #include "application_manager/application.h" -#include "application_manager/commands/commands_test.h" #include "application_manager/event_engine/event.h" #include "application_manager/message_helper.h" #include "application_manager/mock_application_manager.h" @@ -47,6 +46,7 @@ #include "application_manager/smart_object_keys.h" #include "hmi/vi_get_vehicle_data_response.h" #include "smart_objects/smart_object.h" +#include "vehicle_info_plugin/commands/vi_commands_test.h" namespace test { namespace components { @@ -74,7 +74,7 @@ const std::string kStrNumber = "123"; } // namespace class VIGetVehicleDataResponseTest - : public CommandsTest<CommandsTestMocks::kIsNice> {}; + : public VICommandsTest<CommandsTestMocks::kIsNice> {}; TEST_F(VIGetVehicleDataResponseTest, RUN_SUCCESS) { MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); @@ -84,7 +84,7 @@ TEST_F(VIGetVehicleDataResponseTest, RUN_SUCCESS) { hmi_apis::messageType::response; VIGetVehicleDataResponsePtr command( - CreateCommand<VIGetVehicleDataResponse>(command_msg)); + CreateCommandVI<VIGetVehicleDataResponse>(command_msg)); am::event_engine::Event event( hmi_apis::FunctionID::VehicleInfo_GetVehicleData); @@ -97,10 +97,12 @@ TEST_F(VIGetVehicleDataResponseTest, RUN_SUCCESS) { .WillOnce(ReturnRef(mock_event_dispatcher)); EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + ASSERT_TRUE(command->Init()); command->Run(); } -TEST_F(VIGetVehicleDataResponseTest, ErrorResponse_SUCCESS) { +TEST_F(VIGetVehicleDataResponseTest, + ErrorResponse_OnVehicleDataUpdated_NotCalled) { MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); (*command_msg)[strings::msg_params][strings::number] = kStrNumber; (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; @@ -108,7 +110,7 @@ TEST_F(VIGetVehicleDataResponseTest, ErrorResponse_SUCCESS) { hmi_apis::messageType::error_response; (*command_msg)[strings::params][strings::data][strings::slider_position] = 1; (*command_msg)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; + hmi_apis::Common_Result::ABORTED; (*command_msg)[strings::params][strings::correlation_id] = kCorrelationId; (*command_msg)[am::strings::params][am::strings::error_msg] = "test_error"; (*command_msg)[am::strings::params][am::strings::protocol_type] = @@ -116,33 +118,18 @@ TEST_F(VIGetVehicleDataResponseTest, ErrorResponse_SUCCESS) { (*command_msg)[strings::params][strings::protocol_version] = am::commands::CommandImpl::protocol_version_; - smart_objects::SmartObject result(smart_objects::SmartType_Map); - result[strings::msg_params] = (*command_msg)[strings::params][strings::data]; - result[strings::params][hmi_response::code] = - (*command_msg)[strings::params][hmi_response::code]; - result[strings::params][strings::correlation_id] = - (*command_msg)[strings::params][strings::correlation_id]; - result[strings::params][strings::error_msg] = - (*command_msg)[strings::params][strings::error_msg]; - result[strings::params][strings::message_type] = - (*command_msg)[strings::params][strings::message_type]; - result[strings::params][strings::protocol_type] = - (*command_msg)[strings::params][strings::protocol_type]; - result[strings::params][strings::protocol_version] = - (*command_msg)[strings::params][strings::protocol_version]; - VIGetVehicleDataResponsePtr command( - CreateCommand<VIGetVehicleDataResponse>(command_msg)); + CreateCommandVI<VIGetVehicleDataResponse>(command_msg)); - am::event_engine::Event event( - hmi_apis::FunctionID::VehicleInfo_GetVehicleData); - event.set_smart_object(result); + EXPECT_CALL(mock_policy_handler_, OnVehicleDataUpdated(*command_msg)) + .Times(0); MockEventDispatcher mock_event_dispatcher; EXPECT_CALL(app_mngr_, event_dispatcher()) .WillOnce(ReturnRef(mock_event_dispatcher)); EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + ASSERT_TRUE(command->Init()); command->Run(); } diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_is_ready_request_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_is_ready_request_test.cc index 8c77b492ee..c083bf4d60 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_is_ready_request_test.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_is_ready_request_test.cc @@ -34,7 +34,6 @@ #include "gtest/gtest.h" -#include "application_manager/commands/command_request_test.h" #include "application_manager/event_engine/event.h" #include "application_manager/hmi_interfaces.h" #include "application_manager/mock_application_manager.h" @@ -44,6 +43,7 @@ #include "application_manager/policies/mock_policy_handler_interface.h" #include "application_manager/smart_object_keys.h" #include "smart_objects/smart_object.h" +#include "vehicle_info_plugin/commands/vi_command_request_test.h" namespace test { namespace components { @@ -62,9 +62,9 @@ using vehicle_info_plugin::commands::VIIsReadyRequest; typedef std::shared_ptr<VIIsReadyRequest> VIIsReadyRequestPtr; class VIIsReadyRequestTest - : public CommandRequestTest<CommandsTestMocks::kIsNice> { + : public VICommandRequestTest<CommandsTestMocks::kIsNice> { public: - VIIsReadyRequestTest() : command_(CreateCommand<VIIsReadyRequest>()) {} + VIIsReadyRequestTest() : command_(CreateCommandVI<VIIsReadyRequest>()) {} void SetUpExpectations(bool is_vi_cooperating_available, bool is_send_message_to_hmi, diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_subscribe_vehicle_data_request_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_subscribe_vehicle_data_request_test.cc new file mode 100644 index 0000000000..fbaabfed06 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_subscribe_vehicle_data_request_test.cc @@ -0,0 +1,110 @@ +/* + * 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/vi_subscribe_vehicle_data_request.h" + +#include "gtest/gtest.h" + +#include "smart_objects/enum_schema_item.h" +#include "smart_objects/smart_object.h" +#include "vehicle_info_plugin/commands/vi_command_request_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vi_subscribe_vehicle_data_request { + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; + +using vehicle_info_plugin::commands::VISubscribeVehicleDataRequest; + +namespace { +const std::string kMobileParam = "mobile_param"; +const std::string kHMIParam = "hmi_param"; +} // namespace + +class VISubscribeVehicleDataRequestTest + : public VICommandRequestTest<CommandsTestMocks::kIsNice> {}; + +MATCHER_P(EqualMsgParams, msg_params, "") { + using namespace app_mngr; + auto message = static_cast<smart_objects::SmartObject>(*arg); + if (!message.keyExists(strings::msg_params)) { + return false; + } + + return msg_params == message[strings::msg_params]; +} + +TEST_F(VISubscribeVehicleDataRequestTest, Run_Success) { + using namespace app_mngr; + auto command_msg = CreateMessage(smart_objects::SmartType_Map); + (*command_msg)[strings::msg_params][strings::rpm] = true; + (*command_msg)[strings::msg_params][kMobileParam] = true; + + am::VehicleData vehicle_data; + vehicle_data.insert(am::VehicleData::value_type( + strings::rpm, mobile_apis::VehicleDataType::VEHICLEDATA_RPM)); + ON_CALL(mock_message_helper_, vehicle_data()) + .WillByDefault(ReturnRef(vehicle_data)); + + std::string oem_vehicle_data_type_str; + smart_objects::EnumConversionHelper<mobile_apis::VehicleDataType::eType>:: + EnumToString(mobile_apis::VehicleDataType::VEHICLEDATA_OEM_CUSTOM_DATA, + &oem_vehicle_data_type_str); + + smart_objects::SmartObject hmi_params; + hmi_params[kHMIParam] = smart_objects::SmartType_Map; + hmi_params[kHMIParam][strings::data_type] = oem_vehicle_data_type_str; + ON_CALL(mock_custom_vehicle_data_manager_, CreateHMIMessageParams(_)) + .WillByDefault(Return(hmi_params)); + + smart_objects::SmartObject hmi_request_msg; + hmi_request_msg[strings::rpm] = + (*command_msg)[strings::msg_params][strings::rpm]; + hmi_request_msg[kHMIParam] = hmi_params[kHMIParam]; + + EXPECT_CALL(mock_rpc_service_, + SendMessageToHMI(EqualMsgParams(hmi_request_msg))); + + auto command = CreateCommandVI<VISubscribeVehicleDataRequest>(command_msg); + command->Run(); +} + +} // namespace vi_subscribe_vehicle_data_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_unsubscribe_vehicle_data_request_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_unsubscribe_vehicle_data_request_test.cc new file mode 100644 index 0000000000..2ce04aa21a --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_unsubscribe_vehicle_data_request_test.cc @@ -0,0 +1,109 @@ +/* + * 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/vi_unsubscribe_vehicle_data_request.h" + +#include "gtest/gtest.h" + +#include "smart_objects/enum_schema_item.h" +#include "smart_objects/smart_object.h" +#include "vehicle_info_plugin/commands/vi_command_request_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vi_unsubscribe_vehicle_data_request { + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; + +using vehicle_info_plugin::commands::VIUnsubscribeVehicleDataRequest; + +namespace { +const std::string kMobileParam = "mobile_param"; +const std::string kHMIParam = "hmi_param"; +} // namespace + +class VIUnsubscribeVehicleDataRequestTest + : public VICommandRequestTest<CommandsTestMocks::kIsNice> {}; + +MATCHER_P(EqualMsgParams, msg_params, "") { + using namespace app_mngr; + auto message = static_cast<smart_objects::SmartObject>(*arg); + if (!message.keyExists(strings::msg_params)) { + return false; + } + + return msg_params == message[strings::msg_params]; +} + +TEST_F(VIUnsubscribeVehicleDataRequestTest, Run_Success) { + using namespace app_mngr; + auto command_msg = CreateMessage(smart_objects::SmartType_Map); + (*command_msg)[strings::msg_params][strings::rpm] = true; + (*command_msg)[strings::msg_params][kMobileParam] = true; + + am::VehicleData vehicle_data; + vehicle_data.insert(am::VehicleData::value_type( + strings::rpm, mobile_apis::VehicleDataType::VEHICLEDATA_RPM)); + ON_CALL(mock_message_helper_, vehicle_data()) + .WillByDefault(ReturnRef(vehicle_data)); + + std::string oem_vehicle_data_type_str; + smart_objects::EnumConversionHelper<mobile_apis::VehicleDataType::eType>:: + EnumToString(mobile_apis::VehicleDataType::VEHICLEDATA_OEM_CUSTOM_DATA, + &oem_vehicle_data_type_str); + + smart_objects::SmartObject hmi_params; + hmi_params[kHMIParam] = smart_objects::SmartType_Map; + hmi_params[kHMIParam][strings::data_type] = oem_vehicle_data_type_str; + ON_CALL(mock_custom_vehicle_data_manager_, CreateHMIMessageParams(_)) + .WillByDefault(Return(hmi_params)); + + smart_objects::SmartObject hmi_request_msg; + hmi_request_msg[strings::rpm] = true; + hmi_request_msg[kHMIParam] = true; + + EXPECT_CALL(mock_rpc_service_, + SendMessageToHMI(EqualMsgParams(hmi_request_msg))); + + auto command = CreateCommandVI<VIUnsubscribeVehicleDataRequest>(command_msg); + command->Run(); +} + +} // namespace vi_unsubscribe_vehicle_data_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/diagnostic_message_request_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/diagnostic_message_request_test.cc index 3763e033fc..afafd1c6c6 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/diagnostic_message_request_test.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/diagnostic_message_request_test.cc @@ -37,8 +37,6 @@ #include "gtest/gtest.h" #include "application_manager/application.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/commands/commands_test.h" #include "application_manager/event_engine/event.h" #include "application_manager/mock_application.h" #include "application_manager/mock_application_manager.h" @@ -47,6 +45,8 @@ #include "interfaces/MOBILE_API.h" #include "smart_objects/smart_object.h" #include "vehicle_info_plugin/commands/mobile/diagnostic_message_request.h" +#include "vehicle_info_plugin/commands/vi_command_request_test.h" +#include "vehicle_info_plugin/mock_custom_vehicle_data_manager.h" namespace test { namespace components { @@ -71,7 +71,7 @@ const uint32_t kDiagnosticMode = 5u; } // namespace class DiagnosticMessageRequestTest - : public CommandRequestTest<CommandsTestMocks::kIsNice> {}; + : public VICommandRequestTest<CommandsTestMocks::kIsNice> {}; TEST_F(DiagnosticMessageRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); @@ -79,7 +79,7 @@ TEST_F(DiagnosticMessageRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { kConnectionKey; DiagnosticMessageRequestPtr command( - CreateCommand<DiagnosticMessageRequest>(command_msg)); + CreateCommandVI<DiagnosticMessageRequest>(command_msg)); EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillOnce(Return(ApplicationSharedPtr())); @@ -100,7 +100,7 @@ TEST_F(DiagnosticMessageRequestTest, Run_NotSupportedDiagnosticMode_UNSUCCESS) { kConnectionKey; DiagnosticMessageRequestPtr command( - CreateCommand<DiagnosticMessageRequest>(command_msg)); + CreateCommandVI<DiagnosticMessageRequest>(command_msg)); MockAppPtr app(CreateMockApp()); EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); @@ -127,7 +127,7 @@ TEST_F(DiagnosticMessageRequestTest, Run_SUCCESS) { kConnectionKey; DiagnosticMessageRequestPtr command( - CreateCommand<DiagnosticMessageRequest>(command_msg)); + CreateCommandVI<DiagnosticMessageRequest>(command_msg)); MockAppPtr app(CreateMockApp()); EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); @@ -154,7 +154,7 @@ TEST_F(DiagnosticMessageRequestTest, OnEvent_UNSUCCESS) { Event event(hmi_apis::FunctionID::INVALID_ENUM); DiagnosticMessageRequestPtr command( - CreateCommand<DiagnosticMessageRequest>()); + CreateCommandVI<DiagnosticMessageRequest>()); EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); @@ -171,7 +171,7 @@ TEST_F(DiagnosticMessageRequestTest, OnEvent_SUCCESS) { event.set_smart_object(*event_message); DiagnosticMessageRequestPtr command( - CreateCommand<DiagnosticMessageRequest>()); + CreateCommandVI<DiagnosticMessageRequest>()); EXPECT_CALL( mock_rpc_service_, diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/get_dtcs_request_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/get_dtcs_request_test.cc index 1575fe2bd8..e4613feb83 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/get_dtcs_request_test.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/get_dtcs_request_test.cc @@ -37,8 +37,6 @@ #include "gtest/gtest.h" #include "application_manager/application.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/commands/commands_test.h" #include "application_manager/event_engine/event.h" #include "application_manager/mock_application.h" #include "application_manager/mock_application_manager.h" @@ -47,6 +45,7 @@ #include "interfaces/MOBILE_API.h" #include "mobile/get_dtcs_request.h" #include "smart_objects/smart_object.h" +#include "vehicle_info_plugin/commands/vi_command_request_test.h" namespace test { namespace components { @@ -67,13 +66,13 @@ namespace mobile_result = mobile_apis::Result; typedef std::shared_ptr<GetDTCsRequest> GetDTCsRequestPtr; class GetDTCsRequestTest - : public CommandRequestTest<CommandsTestMocks::kIsNice> { + : public VICommandRequestTest<CommandsTestMocks::kIsNice> { public: - GetDTCsRequestTest() : CommandRequestTest<CommandsTestMocks::kIsNice>() {} + GetDTCsRequestTest() : VICommandRequestTest<CommandsTestMocks::kIsNice>() {} }; TEST_F(GetDTCsRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { - GetDTCsRequestPtr command(CreateCommand<GetDTCsRequest>()); + GetDTCsRequestPtr command(CreateCommandVI<GetDTCsRequest>()); EXPECT_CALL(app_mngr_, application(_)) .WillOnce(Return(ApplicationSharedPtr())); @@ -93,7 +92,7 @@ TEST_F(GetDTCsRequestTest, Run_SUCCESS) { (*command_msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - GetDTCsRequestPtr command(CreateCommand<GetDTCsRequest>(command_msg)); + GetDTCsRequestPtr command(CreateCommandVI<GetDTCsRequest>(command_msg)); MockAppPtr app(CreateMockApp()); EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); @@ -107,7 +106,7 @@ TEST_F(GetDTCsRequestTest, Run_SUCCESS) { } TEST_F(GetDTCsRequestTest, OnEvent_UnknownEvent_UNSUCCESS) { - GetDTCsRequestPtr command(CreateCommand<GetDTCsRequest>()); + GetDTCsRequestPtr command(CreateCommandVI<GetDTCsRequest>()); Event event(hmi_apis::FunctionID::INVALID_ENUM); @@ -132,7 +131,7 @@ TEST_F(GetDTCsRequestTest, OnEvent_SUCCESS) { MockAppPtr app(CreateMockApp()); EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app)); - GetDTCsRequestPtr command(CreateCommand<GetDTCsRequest>()); + GetDTCsRequestPtr command(CreateCommandVI<GetDTCsRequest>()); command->on_event(event); } diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/get_vehicle_data_request_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/get_vehicle_data_request_test.cc index ed9fe9d1c0..d27e332601 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/get_vehicle_data_request_test.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/get_vehicle_data_request_test.cc @@ -37,8 +37,6 @@ #include "gtest/gtest.h" #include "application_manager/application.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/commands/commands_test.h" #include "application_manager/event_engine/event.h" #include "application_manager/message_helper.h" #include "application_manager/mock_application_manager.h" @@ -47,6 +45,8 @@ #include "interfaces/MOBILE_API.h" #include "mobile/get_vehicle_data_request.h" #include "smart_objects/smart_object.h" +#include "vehicle_info_plugin/commands/vi_command_request_test.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" namespace test { namespace components { @@ -70,20 +70,14 @@ const uint32_t kConnectionKey = 2u; } // namespace class GetVehicleDataRequestTest - : public CommandRequestTest<CommandsTestMocks::kIsNice> {}; + : public VICommandRequestTest<CommandsTestMocks::kIsNice> {}; class UnwrappedGetVehicleDataRequest : public GetVehicleDataRequest { public: - UnwrappedGetVehicleDataRequest(const MessageSharedPtr& message, - am::ApplicationManager& application_manager, - app_mngr::rpc_service::RPCService& rpc_service, - app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) - : GetVehicleDataRequest(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handler) {} + UnwrappedGetVehicleDataRequest( + const MessageSharedPtr& message, + const vehicle_info_plugin::VehicleInfoCommandParams& params) + : GetVehicleDataRequest(message, params) {} policy::RPCParams& get_disallowed_params() { return removed_parameters_permissions_.disallowed_params; @@ -93,7 +87,7 @@ class UnwrappedGetVehicleDataRequest : public GetVehicleDataRequest { }; TEST_F(GetVehicleDataRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { - GetVehicleDataRequestPtr command(CreateCommand<GetVehicleDataRequest>()); + GetVehicleDataRequestPtr command(CreateCommandVI<GetVehicleDataRequest>()); EXPECT_CALL(app_mngr_, application(_)) .WillOnce(Return(ApplicationSharedPtr())); @@ -115,7 +109,7 @@ TEST_F(GetVehicleDataRequestTest, Run_TooHighFrequency_UNSUCCESS) { kConnectionKey; GetVehicleDataRequestPtr command( - CreateCommand<GetVehicleDataRequest>(command_msg)); + CreateCommandVI<GetVehicleDataRequest>(command_msg)); MockAppPtr app(CreateMockApp()); EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); @@ -138,14 +132,17 @@ TEST_F(GetVehicleDataRequestTest, Run_EmptyMsgParams_UNSUCCESS) { kConnectionKey; GetVehicleDataRequestPtr command( - CreateCommand<GetVehicleDataRequest>(command_msg)); + CreateCommandVI<GetVehicleDataRequest>(command_msg)); const am::VehicleData kEmptyVehicleData; - EXPECT_CALL(mock_message_helper_, vehicle_data()) - .WillOnce(ReturnRef(kEmptyVehicleData)); + ON_CALL(mock_message_helper_, vehicle_data()) + .WillByDefault(ReturnRef(kEmptyVehicleData)); + smart_objects::SmartObject empty_hmi_custom_params; + ON_CALL(mock_custom_vehicle_data_manager_, CreateHMIMessageParams(_)) + .WillByDefault(Return(empty_hmi_custom_params)); MockAppPtr app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); + ON_CALL(app_mngr_, application(kConnectionKey)).WillByDefault(Return(app)); EXPECT_CALL( mock_rpc_service_, @@ -161,11 +158,15 @@ TEST_F(GetVehicleDataRequestTest, kConnectionKey; std::shared_ptr<UnwrappedGetVehicleDataRequest> command( - CreateCommand<UnwrappedGetVehicleDataRequest>(command_msg)); + CreateCommandVI<UnwrappedGetVehicleDataRequest>(command_msg)); + + smart_objects::SmartObject empty_hmi_custom_params; + ON_CALL(mock_custom_vehicle_data_manager_, CreateHMIMessageParams(_)) + .WillByDefault(Return(empty_hmi_custom_params)); const am::VehicleData kEmptyVehicleData; - EXPECT_CALL(mock_message_helper_, vehicle_data()) - .WillRepeatedly(ReturnRef(kEmptyVehicleData)); + ON_CALL(mock_message_helper_, vehicle_data()) + .WillByDefault(ReturnRef(kEmptyVehicleData)); policy::RPCParams& disallowed_params = command->get_disallowed_params(); disallowed_params.insert("test_param"); @@ -189,13 +190,13 @@ TEST_F(GetVehicleDataRequestTest, Run_SUCCESS) { (*command_msg)[am::strings::msg_params][kMsgParamKey] = true; GetVehicleDataRequestPtr command( - CreateCommand<GetVehicleDataRequest>(command_msg)); + CreateCommandVI<GetVehicleDataRequest>(command_msg)); am::VehicleData vehicle_data; vehicle_data.insert(am::VehicleData::value_type( kMsgParamKey, mobile_apis::VehicleDataType::VEHICLEDATA_SPEED)); - EXPECT_CALL(mock_message_helper_, vehicle_data()) - .WillOnce(ReturnRef(vehicle_data)); + ON_CALL(mock_message_helper_, vehicle_data()) + .WillByDefault(ReturnRef(vehicle_data)); MockAppPtr app(CreateMockApp()); EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); @@ -215,7 +216,7 @@ TEST_F(GetVehicleDataRequestTest, OnEvent_UnknownEvent_UNSUCCESS) { kConnectionKey; std::shared_ptr<UnwrappedGetVehicleDataRequest> command( - CreateCommand<UnwrappedGetVehicleDataRequest>(command_msg)); + CreateCommandVI<UnwrappedGetVehicleDataRequest>(command_msg)); Event event(hmi_apis::FunctionID::INVALID_ENUM); @@ -228,14 +229,18 @@ TEST_F(GetVehicleDataRequestTest, OnEvent_DataNotAvailable_SUCCESS) { const hmi_apis::Common_Result::eType hmi_response_code = hmi_apis::Common_Result::DATA_NOT_AVAILABLE; const mobile_result::eType mobile_response_code = - mobile_result::DATA_NOT_AVAILABLE; + mobile_result::VEHICLE_DATA_NOT_AVAILABLE; + + am::VehicleData vehicle_data; + ON_CALL(mock_message_helper_, vehicle_data()) + .WillByDefault(ReturnRef(vehicle_data)); MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); (*command_msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; std::shared_ptr<UnwrappedGetVehicleDataRequest> command( - CreateCommand<UnwrappedGetVehicleDataRequest>(command_msg)); + CreateCommandVI<UnwrappedGetVehicleDataRequest>(command_msg)); MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); (*event_msg)[am::strings::params][am::hmi_response::code] = hmi_response_code; diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/get_vehicle_data_response_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/get_vehicle_data_response_test.cc index fb14373bcf..ad7a14ce40 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/get_vehicle_data_response_test.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/get_vehicle_data_response_test.cc @@ -33,6 +33,8 @@ #include "gtest/gtest.h" #include "application_manager/commands/commands_test.h" +#include "vehicle_info_plugin/commands/vi_commands_test.h" + #include "mobile/get_vehicle_data_response.h" #include "smart_objects/smart_object.h" @@ -49,12 +51,12 @@ using vehicle_info_plugin::commands::GetVehicleDataResponse; typedef std::shared_ptr<GetVehicleDataResponse> GetVehicleDataResponsePtr; class GetVehicleDataResponseTest - : public CommandsTest<CommandsTestMocks::kIsNice> {}; + : public VICommandsTest<CommandsTestMocks::kIsNice> {}; TEST_F(GetVehicleDataResponseTest, GetVehicleDataResponse_SUCCESS) { MessageSharedPtr message(CreateMessage(smart_objects::SmartType_Map)); GetVehicleDataResponsePtr command( - CreateCommand<GetVehicleDataResponse>(message)); + CreateCommandVI<GetVehicleDataResponse>(message)); EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(message, _)); command->Run(); diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/on_vehicle_data_notification_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/on_vehicle_data_notification_test.cc index 8df00521de..82eb19c45f 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/on_vehicle_data_notification_test.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/on_vehicle_data_notification_test.cc @@ -43,6 +43,7 @@ #include "smart_objects/smart_object.h" #include "utils/custom_string.h" #include "utils/helpers.h" +#include "vehicle_info_plugin/commands/vi_commands_test.h" #include "vehicle_info_plugin/vehicle_info_app_extension.h" #include "vehicle_info_plugin/vehicle_info_plugin.h" @@ -72,7 +73,7 @@ const utils::custom_string::CustomString kAppName("test_app"); } // namespace class OnVehicleDataNotificationTest - : public CommandsTest<CommandsTestMocks::kIsNice> { + : public VICommandsTest<CommandsTestMocks::kIsNice> { public: OnVehicleDataNotificationTest() : mock_app_(CreateMockApp()) {} @@ -87,47 +88,47 @@ class OnVehicleDataNotificationTest MockAppPtr mock_app_; }; -TEST_F(OnVehicleDataNotificationTest, OnVehicleDataNotification_SUCCESS) { - MessageSharedPtr message(CreateMessage(smart_objects::SmartType_Map)); - smart_objects::SmartObject gps_data; - gps_data[am::strings::longitude_degrees] = 1.0; - gps_data[am::strings::latitude_degrees] = 1.0; - gps_data[am::strings::shifted] = true; +MATCHER_P(SmartObjectCheck, checker, "") { + return checker(arg); +} - (*message)[am::strings::msg_params][am::strings::gps] = gps_data; - (*message)[am::strings::msg_params][am::strings::speed] = 0; +TEST_F(OnVehicleDataNotificationTest, OnVehicleDataNotification_SUCCESS) { + am::VehicleData vehicle_data; + vehicle_data.insert(am::VehicleData::value_type( + am::strings::gps, mobile_apis::VehicleDataType::VEHICLEDATA_GPS)); + vehicle_data.insert(am::VehicleData::value_type( + am::strings::speed, mobile_apis::VehicleDataType::VEHICLEDATA_SPEED)); + ON_CALL(mock_message_helper_, vehicle_data()) + .WillByDefault(ReturnRef(vehicle_data)); - NotificationPtr command(CreateCommand<OnVehicleDataNotification>(message)); + application_manager::ApplicationSet apps; + apps.insert(mock_app_); + std::shared_ptr<sync_primitives::Lock> apps_lock = + std::make_shared<sync_primitives::Lock>(); + ApplicationSetDA apps_da(apps, apps_lock); + ON_CALL(app_mngr_, applications()).WillByDefault(Return(apps_da)); vehicle_info_plugin::VehicleInfoPlugin vi_plugin; VehicleInfoAppExtensionPtr vi_app_extention_ptr = std::make_shared<vehicle_info_plugin::VehicleInfoAppExtension>( vi_plugin, *mock_app_); - vi_app_extention_ptr->subscribeToVehicleInfo( - mobile_apis::VehicleDataType::VEHICLEDATA_GPS); - vi_app_extention_ptr->subscribeToVehicleInfo( - mobile_apis::VehicleDataType::VEHICLEDATA_SPEED); - - EXPECT_CALL(*mock_app_, - QueryInterface(vehicle_info_plugin::VehicleInfoAppExtension:: - VehicleInfoAppExtensionUID)) - .WillOnce(Return(vi_app_extention_ptr)); + vi_app_extention_ptr->subscribeToVehicleInfo("gps"); + vi_app_extention_ptr->subscribeToVehicleInfo("speed"); + ON_CALL(*mock_app_, + QueryInterface(vehicle_info_plugin::VehicleInfoAppExtension:: + VehicleInfoAppExtensionUID)) + .WillByDefault(Return(vi_app_extention_ptr)); - application_manager::ApplicationSet apps; - apps.insert(mock_app_); - std::shared_ptr<sync_primitives::Lock> apps_lock = - std::make_shared<sync_primitives::Lock>(); - ApplicationSetDA apps_da(apps, apps_lock); - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(apps_da)); + MessageSharedPtr message(CreateMessage(smart_objects::SmartType_Map)); + smart_objects::SmartObject gps_data; + gps_data[am::strings::longitude_degrees] = 1.0; + gps_data[am::strings::latitude_degrees] = 1.0; + gps_data[am::strings::shifted] = true; - am::VehicleData vehicle_data; - vehicle_data.insert(am::VehicleData::value_type( - am::strings::gps, mobile_apis::VehicleDataType::VEHICLEDATA_GPS)); - vehicle_data.insert(am::VehicleData::value_type( - am::strings::gps, mobile_apis::VehicleDataType::VEHICLEDATA_SPEED)); - EXPECT_CALL(mock_message_helper_, vehicle_data()) - .WillOnce(ReturnRef(vehicle_data)); + (*message)[am::strings::msg_params][am::strings::gps] = gps_data; + (*message)[am::strings::msg_params][am::strings::speed] = 0; + NotificationPtr command(CreateCommandVI<OnVehicleDataNotification>(message)); EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(message, _)); command->Run(); diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/read_did_request_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/read_did_request_test.cc index baf75bd93b..372d562965 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/read_did_request_test.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/read_did_request_test.cc @@ -36,8 +36,6 @@ #include "gtest/gtest.h" #include "application_manager/application.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/commands/commands_test.h" #include "application_manager/event_engine/event.h" #include "application_manager/mock_application.h" #include "application_manager/mock_application_manager.h" @@ -47,6 +45,7 @@ #include "interfaces/MOBILE_API.h" #include "smart_objects/smart_object.h" #include "vehicle_info_plugin/commands/mobile/read_did_request.h" +#include "vehicle_info_plugin/commands/vi_command_request_test.h" namespace test { namespace components { @@ -64,11 +63,11 @@ using am::event_engine::Event; using vehicle_info_plugin::commands::ReadDIDRequest; class ReadDIDRequestTest - : public CommandRequestTest<CommandsTestMocks::kIsNice> {}; + : public VICommandRequestTest<CommandsTestMocks::kIsNice> {}; TEST_F(ReadDIDRequestTest, OnEvent_WrongEventId_UNSUCCESS) { Event event(Event::EventID::INVALID_ENUM); - std::shared_ptr<ReadDIDRequest> command(CreateCommand<ReadDIDRequest>()); + std::shared_ptr<ReadDIDRequest> command(CreateCommandVI<ReadDIDRequest>()); EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); command->on_event(event); } @@ -76,7 +75,7 @@ TEST_F(ReadDIDRequestTest, OnEvent_WrongEventId_UNSUCCESS) { TEST_F(ReadDIDRequestTest, OnEvent_SUCCESS) { Event event(Event::EventID::VehicleInfo_ReadDID); - std::shared_ptr<ReadDIDRequest> command(CreateCommand<ReadDIDRequest>()); + std::shared_ptr<ReadDIDRequest> command(CreateCommandVI<ReadDIDRequest>()); const hmi_apis::Common_Result::eType hmi_response_code = hmi_apis::Common_Result::SUCCESS; @@ -98,7 +97,7 @@ TEST_F(ReadDIDRequestTest, OnEvent_SUCCESS) { } TEST_F(ReadDIDRequestTest, Run_AppNotRegistered_UNSUCCESS) { - std::shared_ptr<ReadDIDRequest> command(CreateCommand<ReadDIDRequest>()); + std::shared_ptr<ReadDIDRequest> command(CreateCommandVI<ReadDIDRequest>()); ON_CALL(app_mngr_, application(_)) .WillByDefault(Return(std::shared_ptr<am::Application>())); @@ -111,7 +110,7 @@ TEST_F(ReadDIDRequestTest, Run_AppNotRegistered_UNSUCCESS) { } TEST_F(ReadDIDRequestTest, Run_CommandLimitsExceeded_UNSUCCESS) { - std::shared_ptr<ReadDIDRequest> command(CreateCommand<ReadDIDRequest>()); + std::shared_ptr<ReadDIDRequest> command(CreateCommandVI<ReadDIDRequest>()); MockAppPtr app(CreateMockApp()); ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); @@ -127,7 +126,7 @@ TEST_F(ReadDIDRequestTest, Run_CommandLimitsExceeded_UNSUCCESS) { TEST_F(ReadDIDRequestTest, Run_EmptyDidLocation_UNSUCCESS) { MockAppPtr app(CreateMockApp()); - std::shared_ptr<ReadDIDRequest> command(CreateCommand<ReadDIDRequest>()); + std::shared_ptr<ReadDIDRequest> command(CreateCommandVI<ReadDIDRequest>()); ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); @@ -144,7 +143,7 @@ TEST_F(ReadDIDRequestTest, Run_SUCCESS) { MockAppPtr app(CreateMockApp()); MessageSharedPtr msg(CreateMessage(smart_objects::SmartType_Map)); (*msg)[am::strings::msg_params][am::strings::did_location]["SomeData"] = 0; - std::shared_ptr<ReadDIDRequest> command(CreateCommand<ReadDIDRequest>(msg)); + std::shared_ptr<ReadDIDRequest> command(CreateCommandVI<ReadDIDRequest>(msg)); ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/unsubscribe_vehicle_request_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/unsubscribe_vehicle_request_test.cc index 0126e7c762..450bb5ac26 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/unsubscribe_vehicle_request_test.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/unsubscribe_vehicle_request_test.cc @@ -39,9 +39,14 @@ #include "application_manager/mock_application_manager.h" #include "application_manager/mock_message_helper.h" #include "mobile/unsubscribe_vehicle_data_request.h" +#include "resumption/last_state_wrapper_impl.h" +#include "resumption/mock_last_state.h" +#include "vehicle_info_plugin/commands/vi_command_request_test.h" #include "vehicle_info_plugin/vehicle_info_app_extension.h" #include "vehicle_info_plugin/vehicle_info_plugin.h" +#include "application_manager/mock_rpc_handler.h" + namespace test { namespace components { namespace commands_test { @@ -63,25 +68,32 @@ const uint32_t kConnectionKey = 1u; const std::string kMsgParamKey = "test_key"; const mobile_apis::VehicleDataType::eType kVehicleType = mobile_apis::VehicleDataType::VEHICLEDATA_SPEED; +const std::string kVehicleTypeStr = am::strings::speed; } // namespace class UnsubscribeVehicleRequestTest - : public CommandRequestTest<CommandsTestMocks::kIsNice> { + : public VICommandRequestTest<CommandsTestMocks::kIsNice> { public: UnsubscribeVehicleRequestTest() : mock_app_(CreateMockApp()) , vi_app_extension_ptr_( std::make_shared<vehicle_info_plugin::VehicleInfoAppExtension>( vi_plugin_, *mock_app_)) - , app_set_lock_ptr_(std::make_shared<sync_primitives::Lock>()) {} + , app_set_lock_ptr_(std::make_shared<sync_primitives::Lock>()) + , mock_last_state_(std::make_shared<resumption::LastStateWrapperImpl>( + std::make_shared<resumption_test::MockLastState>())) {} protected: void UnsubscribeSuccessfully(); void SetUp() OVERRIDE { + ON_CALL(app_mngr_, GetRPCHandler()) + .WillByDefault(ReturnRef(mock_rpc_handler_)); + vi_plugin_.Init(app_mngr_, mock_rpc_service_, mock_hmi_capabilities_, - mock_policy_handler_); + mock_policy_handler_, + mock_last_state_); ON_CALL(*mock_app_, AddExtension(vi_app_extension_ptr_)); vi_plugin_.OnApplicationEvent(application_manager::plugin_manager:: ApplicationEvent::kApplicationRegistered, @@ -90,16 +102,19 @@ class UnsubscribeVehicleRequestTest QueryInterface(vehicle_info_plugin::VehicleInfoAppExtension:: VehicleInfoAppExtensionUID)) .WillByDefault(Return(vi_app_extension_ptr_)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); } MockAppPtr mock_app_; application_manager::AppExtensionPtr vi_app_extension_ptr_; std::shared_ptr<sync_primitives::Lock> app_set_lock_ptr_; vehicle_info_plugin::VehicleInfoPlugin vi_plugin_; + application_manager_test::MockRPCHandler mock_rpc_handler_; + resumption::LastStateWrapperPtr mock_last_state_; }; TEST_F(UnsubscribeVehicleRequestTest, Run_AppNotRegistered_UNSUCCESS) { - CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>()); + CommandPtr command(CreateCommandVI<UnsubscribeVehicleDataRequest>()); EXPECT_CALL(app_mngr_, application(_)) .WillOnce(Return(ApplicationSharedPtr())); @@ -117,11 +132,18 @@ TEST_F(UnsubscribeVehicleRequestTest, (*command_msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; (*command_msg)[am::strings::msg_params][am::strings::button_name] = - kVehicleType; + kVehicleTypeStr; am::VehicleData data; - EXPECT_CALL(mock_message_helper_, vehicle_data()).WillOnce(ReturnRef(data)); - CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg)); + EXPECT_CALL(mock_message_helper_, vehicle_data()) + .WillRepeatedly(ReturnRef(data)); + + smart_objects::SmartObject empty_hmi_custom_params; + ON_CALL(mock_custom_vehicle_data_manager_, CreateHMIMessageParams(_)) + .WillByDefault(Return(empty_hmi_custom_params)); + + CommandPtr command( + CreateCommandVI<UnsubscribeVehicleDataRequest>(command_msg)); EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillOnce(Return(mock_app_)); @@ -138,12 +160,15 @@ TEST_F(UnsubscribeVehicleRequestTest, MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); (*command_msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - (*command_msg)[am::strings::msg_params][kMsgParamKey] = true; + (*command_msg)[am::strings::msg_params][kVehicleTypeStr] = true; am::VehicleData vehicle_data; vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType)); - EXPECT_CALL(mock_message_helper_, vehicle_data()) - .WillOnce(ReturnRef(vehicle_data)); + ON_CALL(mock_message_helper_, vehicle_data()) + .WillByDefault(ReturnRef(vehicle_data)); + + smart_objects::SmartObject hmi_custom_params(smart_objects::SmartType_Map); + hmi_custom_params[kVehicleTypeStr] = true; EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillOnce(Return(mock_app_)); @@ -157,13 +182,14 @@ TEST_F(UnsubscribeVehicleRequestTest, vehicle_info_plugin::VehicleInfoAppExtension* vi_app_extension = dynamic_cast<vehicle_info_plugin::VehicleInfoAppExtension*>( vi_app_extension_ptr_.get()); - ASSERT_TRUE(vi_app_extension->subscribeToVehicleInfo(kVehicleType)); + ASSERT_TRUE(vi_app_extension->subscribeToVehicleInfo(kVehicleTypeStr)); application_manager::ApplicationSet app_set = {mock_app_}; DataAccessor<application_manager::ApplicationSet> accessor(app_set, app_set_lock_ptr_); // Expectations EXPECT_CALL(app_mngr_, applications()).WillRepeatedly(Return(accessor)); - CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg)); + CommandPtr command( + CreateCommandVI<UnsubscribeVehicleDataRequest>(command_msg)); command->Run(); } @@ -171,9 +197,12 @@ TEST_F(UnsubscribeVehicleRequestTest, Run_EmptyVehicleData_INVALID_DATA_SentToMobile) { am::VehicleData vehicle_data; EXPECT_CALL(mock_message_helper_, vehicle_data()) - .WillOnce(ReturnRef(vehicle_data)); + .WillRepeatedly(ReturnRef(vehicle_data)); + + smart_objects::SmartObject empty_hmi_custom_params; + ON_CALL(mock_custom_vehicle_data_manager_, CreateHMIMessageParams(_)) + .WillByDefault(Return(empty_hmi_custom_params)); - MockAppPtr mock_app(CreateMockApp()); EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillOnce(Return(mock_app_)); @@ -185,17 +214,21 @@ TEST_F(UnsubscribeVehicleRequestTest, (*command_msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; (*command_msg)[am::strings::msg_params][kMsgParamKey] = false; - CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg)); + CommandPtr command( + CreateCommandVI<UnsubscribeVehicleDataRequest>(command_msg)); command->Run(); } TEST_F(UnsubscribeVehicleRequestTest, Run_UnsubscribeFromNotSubscribedBeforeData_UNSUCCESS) { + smart_objects::SmartObject empty_hmi_custom_params; + ON_CALL(mock_custom_vehicle_data_manager_, CreateHMIMessageParams(_)) + .WillByDefault(Return(empty_hmi_custom_params)); + am::VehicleData vehicle_data; vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType)); EXPECT_CALL(mock_message_helper_, vehicle_data()) - .WillOnce(ReturnRef(vehicle_data)); - + .WillRepeatedly(ReturnRef(vehicle_data)); EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillOnce(Return(mock_app_)); @@ -207,7 +240,8 @@ TEST_F(UnsubscribeVehicleRequestTest, (*command_msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; (*command_msg)[am::strings::msg_params][kMsgParamKey] = true; - CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg)); + CommandPtr command( + CreateCommandVI<UnsubscribeVehicleDataRequest>(command_msg)); command->Run(); } @@ -216,15 +250,19 @@ TEST_F(UnsubscribeVehicleRequestTest, Run_UnsubscribeDataDisabled_UNSUCCESS) { (*command_msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + smart_objects::SmartObject empty_hmi_custom_params; + ON_CALL(mock_custom_vehicle_data_manager_, CreateHMIMessageParams(_)) + .WillByDefault(Return(empty_hmi_custom_params)); + + CommandPtr command( + CreateCommandVI<UnsubscribeVehicleDataRequest>(command_msg)); + am::VehicleData vehicle_data; vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType)); EXPECT_CALL(mock_message_helper_, vehicle_data()) - .WillOnce(ReturnRef(vehicle_data)); - CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg)); - - MockAppPtr mock_app(CreateMockApp()); + .WillRepeatedly(ReturnRef(vehicle_data)); EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); + .WillOnce(Return(mock_app_)); EXPECT_CALL( mock_rpc_service_, @@ -238,7 +276,8 @@ TEST_F(UnsubscribeVehicleRequestTest, OnEvent_DataNotSubscribed_IGNORED) { (*command_msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; (*command_msg)[am::strings::msg_params][kMsgParamKey] = true; - CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg)); + CommandPtr command( + CreateCommandVI<UnsubscribeVehicleDataRequest>(command_msg)); am::VehicleData vehicle_data; @@ -246,7 +285,11 @@ TEST_F(UnsubscribeVehicleRequestTest, OnEvent_DataNotSubscribed_IGNORED) { .WillRepeatedly(Return(mock_app_)); vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType)); EXPECT_CALL(mock_message_helper_, vehicle_data()) - .WillOnce(ReturnRef(vehicle_data)); + .WillRepeatedly(ReturnRef(vehicle_data)); + + smart_objects::SmartObject empty_hmi_custom_params; + ON_CALL(mock_custom_vehicle_data_manager_, CreateHMIMessageParams(_)) + .WillByDefault(Return(empty_hmi_custom_params)); EXPECT_CALL( mock_rpc_service_, @@ -276,7 +319,8 @@ TEST_F(UnsubscribeVehicleRequestTest, OnEvent_DataUnsubscribed_SUCCESS) { (*command_msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; (*command_msg)[am::strings::msg_params][kMsgParamKey] = true; - CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg)); + CommandPtr command( + CreateCommandVI<UnsubscribeVehicleDataRequest>(command_msg)); EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillRepeatedly(Return(mock_app_)); @@ -289,6 +333,11 @@ TEST_F(UnsubscribeVehicleRequestTest, OnEvent_DataUnsubscribed_SUCCESS) { message[am::strings::msg_params][kMsgParamKey] = true; test_event.set_smart_object(message); + am::VehicleData vehicle_data; + vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType)); + EXPECT_CALL(mock_message_helper_, vehicle_data()) + .WillRepeatedly(ReturnRef(vehicle_data)); + EXPECT_CALL( mock_rpc_service_, ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _)); diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/unsubscribe_vehicle_response_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/unsubscribe_vehicle_response_test.cc index 89dbfe1cdb..7c610c8adb 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/unsubscribe_vehicle_response_test.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/unsubscribe_vehicle_response_test.cc @@ -32,11 +32,13 @@ #include <stdint.h> #include <string> +#include "application_manager/mock_application_manager.h" #include "gtest/gtest.h" #include "mobile/unsubscribe_vehicle_data_response.h" -#include "application_manager/commands/commands_test.h" -#include "application_manager/mock_application_manager.h" +#include "vehicle_info_plugin/commands/vi_commands_test.h" +#include "vehicle_info_plugin/mock_custom_vehicle_data_manager.h" +#include "vehicle_info_plugin/vehicle_info_command_factory.h" namespace test { namespace components { @@ -55,7 +57,7 @@ using vehicle_info_plugin::commands::UnsubscribeVehicleDataResponse; namespace am = ::application_manager; class UnsubscribeVehicleResponseTest - : public CommandsTest<CommandsTestMocks::kIsNice> {}; + : public VICommandsTest<CommandsTestMocks::kIsNice> {}; MATCHER_P(ResultCodeIs, result_code, "") { return result_code == @@ -70,7 +72,7 @@ TEST_F(UnsubscribeVehicleResponseTest, (*command_msg)[am::strings::msg_params][am::strings::success] = false; std::shared_ptr<UnsubscribeVehicleDataResponse> command = - CreateCommand<UnsubscribeVehicleDataResponse>(command_msg); + CreateCommandVI<UnsubscribeVehicleDataResponse>(command_msg); EXPECT_CALL( mock_rpc_service_, @@ -84,7 +86,7 @@ TEST_F(UnsubscribeVehicleResponseTest, std::make_shared<SmartObject>(smart_objects::SmartType_Map); (*command_msg)[am::strings::msg_params][am::strings::success] = true; std::shared_ptr<UnsubscribeVehicleDataResponse> command = - CreateCommand<UnsubscribeVehicleDataResponse>(command_msg); + CreateCommandVI<UnsubscribeVehicleDataResponse>(command_msg); EXPECT_CALL( mock_rpc_service_, @@ -102,7 +104,7 @@ TEST_F(UnsubscribeVehicleResponseTest, (*command_msg)[am::strings::msg_params][am::strings::result_code] = result_type; std::shared_ptr<UnsubscribeVehicleDataResponse> command = - CreateCommand<UnsubscribeVehicleDataResponse>(command_msg); + CreateCommandVI<UnsubscribeVehicleDataResponse>(command_msg); command->Run(); } diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/custom_vehicle_data_manager_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/custom_vehicle_data_manager_test.cc new file mode 100644 index 0000000000..7d65d989bf --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/custom_vehicle_data_manager_test.cc @@ -0,0 +1,318 @@ +/* + * Copyright (c) 2018, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ + +#include "application_manager/mock_message_helper.h" +#include "application_manager/mock_rpc_service.h" +#include "application_manager/policies/mock_custom_vehicle_data_provider.h" +#include "gtest/gtest.h" +#include "test/application_manager/mock_application_manager.h" +#include "vehicle_info_plugin/custom_vehicle_data_manager_impl.h" + +namespace vehicle_info_plugin_test { + +using ::testing::NiceMock; +using ::testing::Return; +using ::testing::ReturnRef; + +using application_manager::MockMessageHelper; +namespace { +std::string kName = "rpm"; +std::string kKey = "VD_RPM"; +} // namespace +class CustomVehicleDataManagerTest : public ::testing::Test { + public: + CustomVehicleDataManagerTest() + : mock_message_helper_( + *application_manager::MockMessageHelper::message_helper_mock()) {} + + void SetUp() OVERRIDE {} + + void InitValidationManager(const policy_table::VehicleDataItems& items) { + using vehicle_info_plugin::CustomVehicleDataManagerImpl; + + ON_CALL(mock_custom_vehicle_data_provider_, GetVehicleDataItems()) + .WillByDefault(Return(items)); + ON_CALL(mock_custom_vehicle_data_provider_, GetRemovedVehicleDataItems()) + .WillByDefault(Return(policy_table::VehicleDataItems())); + custom_vd_manager_.reset(new CustomVehicleDataManagerImpl( + mock_custom_vehicle_data_provider_, mock_rpc_service_)); + } + + test::components::application_manager_test::MockApplicationManager + app_manager_mock_; + std::unique_ptr<vehicle_info_plugin::CustomVehicleDataManager> + custom_vd_manager_; + NiceMock<test::components::policy_test::MockCustomVehicleDataProvider> + mock_custom_vehicle_data_provider_; + NiceMock<test::components::application_manager_test::MockRPCService> + mock_rpc_service_; + MockMessageHelper& mock_message_helper_; +}; + +TEST_F(CustomVehicleDataManagerTest, CreateHMIMessageParamsEmptyItems) { + policy_table::VehicleDataItems schema_items; + InitValidationManager(schema_items); + const std::set<std::string> items; + const auto msg_params = custom_vd_manager_->CreateHMIMessageParams(items); + EXPECT_EQ(msg_params.getType(), smart_objects::SmartType_Map); + EXPECT_TRUE(msg_params.empty()); +} + +TEST_F(CustomVehicleDataManagerTest, CreateHMIMessageParamsOnePODItem) { + policy_table::VehicleDataItem rpm; + rpm.mark_initialized(); + rpm.name = kName; + rpm.type = "Integer"; + rpm.key = "OEM_REF_RPM"; + rpm.mandatory = false; + *rpm.array = false; + rpm.params->mark_initialized(); + + policy_table::VehicleDataItems schema_items; + schema_items.push_back(rpm); + InitValidationManager(schema_items); + + const std::set<std::string> items = {kName}; + const auto msg_params = custom_vd_manager_->CreateHMIMessageParams(items); + EXPECT_EQ(msg_params.getType(), smart_objects::SmartType_Map); + EXPECT_EQ(msg_params.length(), 1u); + EXPECT_TRUE(msg_params.keyExists("OEM_REF_RPM")); + auto key_value = msg_params["OEM_REF_RPM"]; + EXPECT_TRUE(key_value.asBool()); +} + +TEST_F(CustomVehicleDataManagerTest, CreateHMIMessageParamsSeveralPODItems) { + policy_table::VehicleDataItem rpm; + rpm.mark_initialized(); + rpm.name = kName; + rpm.type = "Integer"; + rpm.key = "OEM_REF_RPM"; + rpm.mandatory = false; + *rpm.array = false; + rpm.params->mark_initialized(); + + policy_table::VehicleDataItem speed; + speed.mark_initialized(); + speed.name = "speed"; + speed.type = "float"; + speed.key = "OEM_REF_SPEED"; + speed.mandatory = false; + *speed.array = false; + speed.params->mark_initialized(); + + policy_table::VehicleDataItems schema_items; + schema_items.push_back(rpm); + schema_items.push_back(speed); + InitValidationManager(schema_items); + + const std::set<std::string> items = {kName, "speed"}; + + const auto msg_params = custom_vd_manager_->CreateHMIMessageParams(items); + EXPECT_EQ(msg_params.getType(), smart_objects::SmartType_Map); + EXPECT_EQ(msg_params.length(), 2u); + + EXPECT_TRUE(msg_params.keyExists("OEM_REF_RPM")); + auto rpm_key_value = msg_params["OEM_REF_RPM"]; + EXPECT_TRUE(rpm_key_value.asBool()); + + EXPECT_TRUE(msg_params.keyExists("OEM_REF_SPEED")); + auto speed_key_value = msg_params["OEM_REF_SPEED"]; + EXPECT_TRUE(speed_key_value.asBool()); +} + +TEST_F(CustomVehicleDataManagerTest, + CreateHMIMessageParamsSchemaWithSeveralItemsRequestWithOneItem) { + policy_table::VehicleDataItem rpm; + rpm.mark_initialized(); + rpm.name = kName; + rpm.type = "Integer"; + rpm.key = "OEM_REF_RPM"; + rpm.mandatory = false; + *rpm.array = false; + rpm.params->mark_initialized(); + + policy_table::VehicleDataItem speed; + speed.mark_initialized(); + speed.name = "speed"; + speed.type = "float"; + speed.key = "OEM_REF_SPEED"; + speed.mandatory = false; + *speed.array = false; + speed.params->mark_initialized(); + + policy_table::VehicleDataItems schema_items; + schema_items.push_back(rpm); + schema_items.push_back(speed); + InitValidationManager(schema_items); + + const std::set<std::string> items = {kName}; + + const auto msg_params = custom_vd_manager_->CreateHMIMessageParams(items); + EXPECT_EQ(msg_params.getType(), smart_objects::SmartType_Map); + EXPECT_EQ(msg_params.length(), 1u); + + EXPECT_TRUE(msg_params.keyExists("OEM_REF_RPM")); + auto rpm_key_value = msg_params["OEM_REF_RPM"]; + EXPECT_TRUE(rpm_key_value.asBool()); +} + +TEST_F(CustomVehicleDataManagerTest, CreateHMIMessageParamsStructType) { + policy_table::VehicleDataItem alss; + alss.mark_initialized(); + alss.name = "ambientLightSensorStatus"; + alss.type = "AmbientLightStatus"; + alss.key = "OEM_REF_AMB_LIGHT"; + alss.mandatory = false; + alss.params->mark_initialized(); + + policy_table::VehicleDataItem lss; + lss.mark_initialized(); + lss.name = "LightSensorStatus"; + lss.type = "Struct"; + lss.key = "OEM_REF_SEN_LIGHT"; + lss.mandatory = false; + lss.params->mark_initialized(); + lss.params->push_back(alss); + + policy_table::VehicleDataItem hbo; + hbo.mark_initialized(); + hbo.name = "highBeamsOn"; + hbo.type = "Boolean"; + hbo.key = "OEM_REF_HIGH_BEAM"; + hbo.mandatory = true; + hbo.params->mark_initialized(); + + policy_table::VehicleDataItem lbo; + lbo.mark_initialized(); + lbo.name = "lowBeamsOn"; + lbo.type = "Boolean"; + lbo.key = "OEM_REF_LOW_BEAM"; + lbo.mandatory = false; + lbo.params->mark_initialized(); + + policy_table::VehicleDataItem hls; + hls.mark_initialized(); + hls.name = "headLampStatus"; + hls.type = "Struct"; + hls.key = "OEM_REF_HLSTATUS"; + hls.mandatory = false; + hls.params->mark_initialized(); + hls.params->push_back(lss); + hls.params->push_back(lbo); + hls.params->push_back(hbo); + + policy_table::VehicleDataItems schema_items; + schema_items.push_back(hls); + InitValidationManager(schema_items); + + const std::set<std::string> items = {"headLampStatus"}; + + const auto msg_params = custom_vd_manager_->CreateHMIMessageParams(items); + EXPECT_EQ(msg_params.getType(), smart_objects::SmartType_Map); + EXPECT_EQ(msg_params.length(), 1u); + + EXPECT_TRUE(msg_params.keyExists("OEM_REF_HLSTATUS")); + const auto head_lamp_status = msg_params["OEM_REF_HLSTATUS"]; + EXPECT_EQ(head_lamp_status.getType(), smart_objects::SmartType_Map); + + EXPECT_EQ(head_lamp_status.length(), 3u); + + EXPECT_TRUE(head_lamp_status.keyExists("OEM_REF_HIGH_BEAM")); + EXPECT_TRUE(head_lamp_status.keyExists("OEM_REF_LOW_BEAM")); + EXPECT_TRUE(head_lamp_status.keyExists("OEM_REF_SEN_LIGHT")); + + EXPECT_TRUE(head_lamp_status["OEM_REF_HIGH_BEAM"].asBool()); + EXPECT_TRUE(head_lamp_status["OEM_REF_LOW_BEAM"].asBool()); + auto light_sensor_status = head_lamp_status["OEM_REF_SEN_LIGHT"]; + + EXPECT_EQ(light_sensor_status.length(), 1u); + EXPECT_TRUE(light_sensor_status.keyExists("OEM_REF_AMB_LIGHT")); + EXPECT_TRUE(light_sensor_status["OEM_REF_AMB_LIGHT"].asBool()); +} + +TEST_F(CustomVehicleDataManagerTest, CreateHMIMessageParamsNoSchemaForItem) { + policy_table::VehicleDataItems schema_items; + InitValidationManager(schema_items); + + const std::set<std::string> items = {kName}; + + const auto msg_params = custom_vd_manager_->CreateHMIMessageParams(items); + EXPECT_EQ(msg_params.getType(), smart_objects::SmartType_Map); + EXPECT_TRUE(msg_params.empty()); +} + +TEST_F(CustomVehicleDataManagerTest, CreateMobileMessageParamsStruct) { + const application_manager::VehicleData kEmptyVehicleData; + ON_CALL(mock_message_helper_, vehicle_data()) + .WillByDefault(ReturnRef(kEmptyVehicleData)); + + policy_table::VehicleDataItems schema_items; + + policy_table::VehicleDataItem custom_vd_item11_struct; + custom_vd_item11_struct.mark_initialized(); + custom_vd_item11_struct.name = "custom_vd_item11_struct"; + custom_vd_item11_struct.type = "Struct"; + custom_vd_item11_struct.key = "OEM_REF_STRUCT"; + custom_vd_item11_struct.mandatory = false; + custom_vd_item11_struct.params->mark_initialized(); + + policy_table::VehicleDataItem struct_element_1_int; + struct_element_1_int.mark_initialized(); + struct_element_1_int.name = "struct_element_1_int"; + struct_element_1_int.type = "Integer"; + struct_element_1_int.key = "OEM_REF_STRUCT_1_INT"; + struct_element_1_int.mandatory = false; + struct_element_1_int.params->mark_initialized(); + custom_vd_item11_struct.params->push_back(struct_element_1_int); + schema_items.push_back(custom_vd_item11_struct); + InitValidationManager(schema_items); + + smart_objects::SmartObject msg_params(smart_objects::SmartType_Map); + msg_params["OEM_REF_STRUCT"] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + auto& oem_ref_struct = msg_params["OEM_REF_STRUCT"]; + oem_ref_struct["OEM_REF_STRUCT_1_INT"] = 100; + custom_vd_manager_->CreateMobileMessageParams(msg_params); + + EXPECT_EQ(msg_params.getType(), smart_objects::SmartType_Map); + EXPECT_TRUE(msg_params.keyExists("custom_vd_item11_struct")); + + auto& mobile_response_vd_item_11 = msg_params["custom_vd_item11_struct"]; + EXPECT_EQ(mobile_response_vd_item_11.getType(), smart_objects::SmartType_Map); + EXPECT_TRUE(mobile_response_vd_item_11.keyExists("struct_element_1_int")); + + auto& mobile_response_element1 = + mobile_response_vd_item_11["struct_element_1_int"]; + EXPECT_EQ(mobile_response_element1.getType(), + smart_objects::SmartType_Integer); + EXPECT_EQ(mobile_response_element1.asInt(), 100); +} +} // namespace vehicle_info_plugin_test diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/include/vehicle_info_plugin/commands/vi_command_request_test.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/include/vehicle_info_plugin/commands/vi_command_request_test.h new file mode 100644 index 0000000000..a6eac01e1c --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/include/vehicle_info_plugin/commands/vi_command_request_test.h @@ -0,0 +1,99 @@ +/* + * 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_VEHICLE_INFO_PLUGIN_TEST_INCLUDE_VIHICLE_INFO_PLUGIN_COMMANDS_VI_COMMAND_REQUEST_TEST_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_VEHICLE_INFO_PLUGIN_TEST_INCLUDE_VIHICLE_INFO_PLUGIN_COMMANDS_VI_COMMAND_REQUEST_TEST_H_ + +#include <stdint.h> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_impl.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" +#include "vehicle_info_plugin/mock_custom_vehicle_data_manager.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" + +namespace test { +namespace components { +namespace commands_test { + +using ::test::components::event_engine_test::MockEventDispatcher; +using ::testing::NiceMock; +using ::testing::Return; +using ::testing::SaveArg; +namespace am = ::application_manager; +using am::commands::Command; +using am::commands::CommandRequestImpl; +using am::event_engine::Event; + +template <const CommandsTestMocks kIsNice = CommandsTestMocks::kNotNice> +class VICommandRequestTest : public CommandRequestTest<kIsNice> { + public: + enum { kDefaultTimeout_ = 100 }; + + template <class Command> + std::shared_ptr<Command> CreateCommandVI() { + auto msg = CommandsTest<kIsNice>::CreateMessage(); + return CreateCommandVI<Command>(msg); + } + + template <class Command> + std::shared_ptr<Command> CreateCommandVI(MessageSharedPtr& msg) { + InitCommandVI(kDefaultTimeout_); + vehicle_info_plugin::VehicleInfoCommandParams params = { + CommandsTest<kIsNice>::app_mngr_, + CommandsTest<kIsNice>::mock_rpc_service_, + CommandsTest<kIsNice>::mock_hmi_capabilities_, + CommandsTest<kIsNice>::mock_policy_handler_, + mock_custom_vehicle_data_manager_}; + return std::make_shared<Command>(msg, params); + } + + testing::NiceMock<vehicle_info_plugin::MockCustomVehicleDataManager> + mock_custom_vehicle_data_manager_; + + protected: + VICommandRequestTest() : CommandRequestTest<kIsNice>() {} + + void InitCommandVI(const uint32_t& timeout) { + CommandRequestTest<kIsNice>::InitCommand(kDefaultTimeout_); + } +}; + +} // namespace commands_test +} // namespace components +} // namespace test + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_VEHICLE_INFO_PLUGIN_TEST_INCLUDE_VIHICLE_INFO_PLUGIN_COMMANDS_VI_COMMAND_REQUEST_TEST_H_ 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 new file mode 100644 index 0000000000..ae25acea87 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/include/vehicle_info_plugin/commands/vi_commands_test.h @@ -0,0 +1,104 @@ +/* + * 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_VEHICLE_INFO_PLUGIN_TEST_INCLUDE_VI_COMMAND_TEST_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_VEHICLE_INFO_PLUGIN_TEST_INCLUDE_VI_COMMAND_TEST_H_ + +#include <stdint.h> +#include "gtest/gtest.h" + +#include "application_manager/commands/command.h" +#include "smart_objects/smart_object.h" + +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager_settings.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "vehicle_info_plugin/mock_custom_vehicle_data_manager.h" +#include "vehicle_info_plugin/vehicle_info_command_params.h" + +namespace test { +namespace components { +namespace commands_test { + +namespace am = ::application_manager; + +using ::testing::_; +using ::testing::Mock; +using ::testing::NiceMock; +using ::testing::Return; +using ::testing::ReturnRef; + +using am::commands::MessageSharedPtr; +using ::smart_objects::SmartObject; + +template <const CommandsTestMocks kIsNice = CommandsTestMocks::kNotNice> +class VICommandsTest : public CommandsTest<kIsNice> { + public: + enum { kDefaultTimeout_ = 100 }; + + template <class Command> + std::shared_ptr<Command> CreateCommandVI() { + auto msg = CommandsTest<kIsNice>::CreateMessage(); + return CreateCommandVI<Command>(msg); + } + + template <class Command> + std::shared_ptr<Command> CreateCommandVI(MessageSharedPtr& msg) { + InitCommandVI(kDefaultTimeout_); + vehicle_info_plugin::VehicleInfoCommandParams params = { + CommandsTest<kIsNice>::app_mngr_, + CommandsTest<kIsNice>::mock_rpc_service_, + CommandsTest<kIsNice>::mock_hmi_capabilities_, + CommandsTest<kIsNice>::mock_policy_handler_, + mock_custom_vehicle_data_manager_}; + return std::make_shared<Command>(msg, params); + } + + testing::NiceMock<vehicle_info_plugin::MockCustomVehicleDataManager> + mock_custom_vehicle_data_manager_; + + protected: + void InitCommandVI(const uint32_t& timeout) { + ON_CALL(CommandsTest<kIsNice>::app_mngr_, get_settings()) + .WillByDefault(ReturnRef(CommandsTest<kIsNice>::app_mngr_settings_)); + ON_CALL(CommandsTest<kIsNice>::app_mngr_settings_, default_timeout()) + .WillByDefault(ReturnRef(timeout)); + } +}; +} // namespace commands_test +} // namespace components +} // namespace test + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_VEHICLE_INFO_PLUGIN_TEST_INCLUDE_VI_COMMAND_TEST_H_ diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/include/vehicle_info_plugin/mock_custom_vehicle_data_manager.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/include/vehicle_info_plugin/mock_custom_vehicle_data_manager.h new file mode 100644 index 0000000000..9a7435f980 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/include/vehicle_info_plugin/mock_custom_vehicle_data_manager.h @@ -0,0 +1,26 @@ +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_VEHICLE_INFO_PLUGIN_TEST_INCLUDE_VEHICLE_INFO_PLUGIN_MOCK_CUSTOM_VEHICLE_DATA_MANAGER_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_VEHICLE_INFO_PLUGIN_TEST_INCLUDE_VEHICLE_INFO_PLUGIN_MOCK_CUSTOM_VEHICLE_DATA_MANAGER_H_ + +#include "gmock/gmock.h" +#include "vehicle_info_plugin/custom_vehicle_data_manager.h" + +namespace vehicle_info_plugin { +namespace plugin_manager = application_manager::plugin_manager; +class MockCustomVehicleDataManager : public CustomVehicleDataManager { + public: + MOCK_METHOD1( + CreateHMIMessageParams, + smart_objects::SmartObject(const std::set<std::string>& msg_params)); + MOCK_METHOD1(CreateMobileMessageParams, + void(smart_objects::SmartObject& msg_params)); + MOCK_CONST_METHOD1(GetVehicleDataItemType, + std::string(const std::string& vehicle_data_item_name)); + MOCK_METHOD1(OnPolicyEvent, void(plugin_manager::PolicyEvent policy_event)); + MOCK_CONST_METHOD1(IsValidCustomVehicleDataName, + bool(const std::string& name)); + MOCK_CONST_METHOD1(IsRemovedCustomVehicleDataName, + bool(const std::string& name)); +}; + +} // namespace vehicle_info_plugin +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_VEHICLE_INFO_PLUGIN_TEST_INCLUDE_VEHICLE_INFO_PLUGIN_MOCK_CUSTOM_VEHICLE_DATA_MANAGER_H_ diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/vehicle_data_item_schema_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/vehicle_data_item_schema_test.cc new file mode 100644 index 0000000000..2443310409 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/vehicle_data_item_schema_test.cc @@ -0,0 +1,396 @@ +/* + * 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 "vehicle_info_plugin/vehicle_data_item_schema.h" +#include <limits> +#include <set> +#include <type_traits> +#include "formatters/formatter_json_rpc.h" +#include "formatters/generic_json_formatter.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" +#include "interfaces/HMI_API.h" +#include "smart_objects/smart_object.h" + +namespace vehicle_info_plugin_test { +using namespace vehicle_info_plugin; +using namespace rpc; +namespace smart_objects = ns_smart_device_link::ns_smart_objects; +namespace policy_table = rpc::policy_table_interface_base; + +using namespace ns_smart_device_link::ns_json_handler::strings; +using namespace hmi_apis; + +using ::testing::NiceMock; +using ::testing::Return; +using ::testing::ReturnRef; + +using ErrorCode = smart_objects::errors::eType; + +namespace { +const int kInvalidValue = std::numeric_limits<int32_t>::max(); +const int kDefaultInteger = 20; +const double kDefaultFloat = 10.05; +const bool kDefaultBoolean = true; +const std::string kDefaultString = "string value"; +const std::string kVehicleDataKey = "key"; +} // namespace + +typedef Common_ComponentVolumeStatus::eType TestEnumType; + +class VehicleDataItemSchemaTest : public ::testing::Test { + public: + /* + * @brief + * Specifies whether user wants to generate valid value of SmartObject or not. + */ + enum class SetValidItemValue { NO = 0, YES = 1 }; + + /* + * @brief + * VehicleDataTestObject struct combines schema and data structures for test + * object. + */ + struct VehicleDataTestObject { + VehicleDataTestObject(const int& key_number) { + schema.mark_initialized(); + schema.params->mark_initialized(); + schema.mandatory = true; + *schema.array = false; + // default value bounds + *schema.minvalue = 10; + *schema.maxvalue = 100; + // default string length + *schema.minlength = 5; + *schema.maxlength = 30; + // default array length + *schema.minsize = 5; + *schema.maxsize = 30; + // generate schema unique key + schema.key = kVehicleDataKey + std::to_string(key_number); + } + + policy_table::VehicleDataItem schema; + smart_objects::SmartObject data; + }; + + public: + VehicleDataItemSchemaTest() : key_number_(1) { + test_enum_.insert(TestEnumType::CVS_UNKNOWN); + test_enum_.insert(TestEnumType::CVS_NORMAL); + test_enum_.insert(TestEnumType::CVS_LOW); + test_enum_.insert(TestEnumType::CVS_FAULT); + test_enum_.insert(TestEnumType::CVS_ALERT); + test_enum_.insert(TestEnumType::CVS_NOT_SUPPORTED); + } + + void assertSmartObjectSize(const size_t& expected_size, + const size_t& actual_size) { + ASSERT_EQ(expected_size, actual_size); + } + + std::vector<VehicleDataTestObject> generatePODObjects( + const SetValidItemValue& set_valid_item) { + std::vector<VehicleDataTestObject> generated_objects; + VehicleDataTestObject custom_object(key_number_++); + + // Integer item + custom_object.schema.type = policy_table::VehicleDataItem::kInteger; + if (set_valid_item == SetValidItemValue::YES) { + custom_object.data = kDefaultInteger; + } else { + custom_object.data = kInvalidValue; + } + generated_objects.push_back(custom_object); + + // Float item + custom_object.schema.type = policy_table::VehicleDataItem::kFloat; + if (set_valid_item == SetValidItemValue::YES) { + custom_object.data = kDefaultFloat; + } else { + custom_object.data = kInvalidValue; + } + generated_objects.push_back(custom_object); + + // String item + custom_object.schema.type = policy_table::VehicleDataItem::kString; + if (set_valid_item == SetValidItemValue::YES) { + custom_object.data = kDefaultString; + } else { + custom_object.data = kInvalidValue; + } + generated_objects.push_back(custom_object); + + // Boolean item + custom_object.schema.type = policy_table::VehicleDataItem::kBoolean; + if (set_valid_item == SetValidItemValue::YES) { + custom_object.data = kDefaultBoolean; + } else { + custom_object.data = kInvalidValue; + } + generated_objects.push_back(custom_object); + + return generated_objects; + } + + VehicleDataTestObject generateTestObject( + const SetValidItemValue& set_valid_item) { + // Enum parameter + VehicleDataTestObject enum_object(key_number_++); + enum_object.schema.type = "ComponentVolumeStatus"; + enum_object.data = (set_valid_item == SetValidItemValue::YES) + ? TestEnumType::CVS_LOW + : kInvalidValue; + + // Integer parameter + VehicleDataTestObject int_object(key_number_++); + int_object.schema.type = policy_table::VehicleDataItem::kInteger; + int_object.data = (set_valid_item == SetValidItemValue::YES) + ? kDefaultInteger + : kInvalidValue; + + // Main object + VehicleDataTestObject main_object(key_number_++); + main_object.schema.type = policy_table::VehicleDataItem::kStruct; + *main_object.schema.params = std::vector<policy_table::VehicleDataItem>{ + enum_object.schema, int_object.schema}; + main_object.data[enum_object.schema.key] = enum_object.data; + main_object.data[int_object.schema.key] = int_object.data; + + assertSmartObjectSize(2u, main_object.data.length()); + return main_object; + } + + VehicleDataTestObject generateRecursiveTestObject( + const SetValidItemValue& set_valid_item) { + // Float item + VehicleDataTestObject float_object(key_number_++); + float_object.schema.type = policy_table::VehicleDataItem::kFloat; + if (set_valid_item == SetValidItemValue::YES) { + float_object.data = kDefaultFloat; + } else { + float_object.data = kInvalidValue; + } + + // String item + VehicleDataTestObject string_object(key_number_++); + string_object.schema.type = policy_table::VehicleDataItem::kString; + if (set_valid_item == SetValidItemValue::YES) { + string_object.data = kDefaultString; + } else { + string_object.data = kInvalidValue; + } + + // Sub Object + VehicleDataTestObject sub_object = generateTestObject(set_valid_item); + + // Main Object + VehicleDataTestObject main_object(key_number_++); + main_object.schema.type = policy_table::VehicleDataItem::kStruct; + *main_object.schema.params = std::vector<policy_table::VehicleDataItem>{ + float_object.schema, string_object.schema, sub_object.schema}; + main_object.data[float_object.schema.key] = float_object.data; + main_object.data[string_object.schema.key] = string_object.data; + main_object.data[sub_object.schema.key] = sub_object.data; + + assertSmartObjectSize(3u, main_object.data.length()); + return main_object; + } + + protected: + std::set<TestEnumType> test_enum_; + int key_number_; +}; + +TEST_F(VehicleDataItemSchemaTest, ValidatePOD_SUCCESS) { + rpc::ValidationReport report("RPC"); + auto valid_pod_objects = generatePODObjects(SetValidItemValue::YES); + + for (auto& object : valid_pod_objects) { + auto test_param = PolicyDataItem(object.schema); + auto result = VehicleDataItemSchema::create( + test_param, VehicleDataItemSchema::SchemaType::HMI); + EXPECT_EQ(ErrorCode::OK, result->validate(object.data, &report)); + EXPECT_EQ(std::string(""), rpc::PrettyFormat(report)); + } +} + +TEST_F(VehicleDataItemSchemaTest, ValidatePOD_FAIL) { + rpc::ValidationReport report("RPC"); + std::vector<VehicleDataTestObject> valid_pod_objects = + generatePODObjects(SetValidItemValue::NO); + + for (auto& object : valid_pod_objects) { + auto test_param = PolicyDataItem(object.schema); + auto result = VehicleDataItemSchema::create( + test_param, VehicleDataItemSchema::SchemaType::MOBILE); + EXPECT_NE(ErrorCode::OK, result->validate(object.data, &report)); + EXPECT_NE(std::string(""), rpc::PrettyFormat(report)); + } +} + +TEST_F(VehicleDataItemSchemaTest, ValidateEnum_SUCCESS) { + rpc::ValidationReport report("RPC"); + + VehicleDataTestObject test_enum_object(key_number_++); + test_enum_object.schema.type = "ComponentVolumeStatus"; + test_enum_object.data = TestEnumType::CVS_NORMAL; + + auto test_schema = PolicyDataItem(test_enum_object.schema); + + for (auto& enum_value : test_enum_) { + test_enum_object.data = enum_value; + auto result = VehicleDataItemSchema::create( + test_schema, VehicleDataItemSchema::SchemaType::HMI); + EXPECT_EQ(ErrorCode::OK, result->validate(test_enum_object.data, &report)); + EXPECT_EQ(std::string(""), rpc::PrettyFormat(report)); + } +} + +TEST_F(VehicleDataItemSchemaTest, ValidateEnum_FAIL) { + rpc::ValidationReport report("RPC"); + + VehicleDataTestObject test_enum_object(key_number_++); + test_enum_object.schema.type = "ComponentVolumeStatus"; + test_enum_object.data = kInvalidValue; + + auto test_schema = PolicyDataItem(test_enum_object.schema); + auto result = VehicleDataItemSchema::create( + test_schema, VehicleDataItemSchema::SchemaType::HMI); + EXPECT_EQ(ErrorCode::OUT_OF_RANGE, + result->validate(test_enum_object.data, &report)); + EXPECT_NE(std::string(""), rpc::PrettyFormat(report)); +} + +TEST_F(VehicleDataItemSchemaTest, ValidateObject_SUCCESS) { + rpc::ValidationReport report("RPC"); + VehicleDataTestObject complex_object = + generateTestObject(SetValidItemValue::YES); + auto test_schema = PolicyDataItem(complex_object.schema); + auto result = VehicleDataItemSchema::create( + test_schema, VehicleDataItemSchema::SchemaType::HMI); + EXPECT_EQ(ErrorCode::OK, result->validate(complex_object.data, &report)); + EXPECT_EQ(std::string(""), rpc::PrettyFormat(report)); +} + +TEST_F(VehicleDataItemSchemaTest, ValidateObject_FAIL) { + rpc::ValidationReport report("RPC"); + VehicleDataTestObject complex_object = + generateTestObject(SetValidItemValue::NO); + auto test_schema = PolicyDataItem(complex_object.schema); + auto result = VehicleDataItemSchema::create( + test_schema, VehicleDataItemSchema::SchemaType::HMI); + EXPECT_NE(ErrorCode::OK, result->validate(complex_object.data, &report)); + EXPECT_NE(std::string(""), rpc::PrettyFormat(report)); +} + +TEST_F(VehicleDataItemSchemaTest, ValidateRecursiveObject_SUCCESS) { + rpc::ValidationReport report("RPC"); + VehicleDataTestObject complex_recursive_object = + generateRecursiveTestObject(SetValidItemValue::YES); + auto test_schema = PolicyDataItem(complex_recursive_object.schema); + auto result = VehicleDataItemSchema::create( + test_schema, VehicleDataItemSchema::SchemaType::HMI); + EXPECT_EQ(ErrorCode::OK, + result->validate(complex_recursive_object.data, &report)); + EXPECT_EQ(std::string(""), rpc::PrettyFormat(report)); +} + +TEST_F(VehicleDataItemSchemaTest, ValidateRecursiveObject_FAIL) { + rpc::ValidationReport report("RPC"); + VehicleDataTestObject complex_recursive_object = + generateRecursiveTestObject(SetValidItemValue::NO); + auto test_schema = PolicyDataItem(complex_recursive_object.schema); + auto result = VehicleDataItemSchema::create( + test_schema, VehicleDataItemSchema::SchemaType::HMI); + EXPECT_NE(ErrorCode::OK, + result->validate(complex_recursive_object.data, &report)); + EXPECT_NE(std::string(""), rpc::PrettyFormat(report)); +} + +TEST_F(VehicleDataItemSchemaTest, ValidateArray_SUCCESS) { + rpc::ValidationReport report("RPC"); + VehicleDataTestObject array_object(key_number_++); + *array_object.schema.array = true; + array_object.schema.type = policy_table::VehicleDataItem::kInteger; + array_object.data = + smart_objects::SmartObject(smart_objects::SmartType_Array); + array_object.data.asArray()->push_back(smart_objects::SmartObject(10)); + array_object.data.asArray()->push_back(smart_objects::SmartObject(20)); + array_object.data.asArray()->push_back(smart_objects::SmartObject(30)); + array_object.data.asArray()->push_back(smart_objects::SmartObject(40)); + array_object.data.asArray()->push_back(smart_objects::SmartObject(50)); + array_object.data.asArray()->push_back(smart_objects::SmartObject(60)); + array_object.data.asArray()->push_back(smart_objects::SmartObject(70)); + + auto test_schema = PolicyDataItem(array_object.schema); + auto result = VehicleDataItemSchema::create( + test_schema, VehicleDataItemSchema::SchemaType::HMI); + EXPECT_EQ(ErrorCode::OK, result->validate(array_object.data, &report)); + EXPECT_EQ(std::string(""), rpc::PrettyFormat(report)); +} + +TEST_F(VehicleDataItemSchemaTest, ValidateArray_FAIL) { + rpc::ValidationReport report("RPC"); + VehicleDataTestObject array_object(key_number_++); + *array_object.schema.array = true; + array_object.schema.type = policy_table::VehicleDataItem::kInteger; + array_object.data = + smart_objects::SmartObject(smart_objects::SmartType_Array); + array_object.data.asArray()->push_back(smart_objects::SmartObject(10)); + array_object.data.asArray()->push_back(smart_objects::SmartObject(20)); + array_object.data.asArray()->push_back(smart_objects::SmartObject(30)); + + auto test_schema = PolicyDataItem(array_object.schema); + auto result = VehicleDataItemSchema::create( + test_schema, VehicleDataItemSchema::SchemaType::HMI); + EXPECT_NE(ErrorCode::OK, result->validate(array_object.data, &report)); + EXPECT_NE(std::string(""), rpc::PrettyFormat(report)); +} + +TEST_F(VehicleDataItemSchemaTest, ValidateUnknownType) { + rpc::ValidationReport report("RPC"); + + VehicleDataTestObject test_object_with_invalid_type(key_number_++); + // Set invalid name of type + test_object_with_invalid_type.schema.type = "omponentolumetatus"; + test_object_with_invalid_type.data = TestEnumType::CVS_NORMAL; + + auto test_schema = PolicyDataItem(test_object_with_invalid_type.schema); + auto result = VehicleDataItemSchema::create( + test_schema, VehicleDataItemSchema::SchemaType::HMI); + test_object_with_invalid_type.data = "CVS_NORMAL"; + EXPECT_EQ(ErrorCode::OK, + result->validate(test_object_with_invalid_type.data, &report)); + EXPECT_EQ(std::string(""), rpc::PrettyFormat(report)); +} + +} // namespace vehicle_info_plugin_test |