diff options
Diffstat (limited to 'src/components/application_manager/rpc_plugins/sdl_rpc_plugin')
3 files changed, 152 insertions, 60 deletions
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 c55dcb65fc..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 @@ -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) 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 14a94fd1a2..c2f4418b66 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" @@ -296,53 +297,73 @@ void RegisterAppInterfaceRequest::Run() { return; } + mobile_apis::Result::eType coincidence_result = CheckCoincidence(); + + if (mobile_apis::Result::SUCCESS != coincidence_result) { + LOG4CXX_ERROR(logger_, "Coincidence check failed."); + SendResponse(false, coincidence_result); + return; + } + 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()) { - 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) { - LOG4CXX_ERROR(logger_, "Coincidence check failed."); - SendResponse(false, coincidence_result); - return; } if (IsWhiteSpaceExist()) { @@ -458,6 +479,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]); } @@ -875,6 +902,12 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile( // 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)(); @@ -983,8 +1016,7 @@ 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]; @@ -1008,8 +1040,7 @@ mobile_apis::Result::eType RegisterAppInterfaceRequest::CheckCoincidence( 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(app); - continue; + return mobile_apis::Result::DUPLICATE_NAME; } const auto vr = app->vr_synonyms(); if (vr) { @@ -1018,8 +1049,7 @@ mobile_apis::Result::eType RegisterAppInterfaceRequest::CheckCoincidence( 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(app); - continue; + return mobile_apis::Result::DUPLICATE_NAME; } } @@ -1030,8 +1060,7 @@ mobile_apis::Result::eType RegisterAppInterfaceRequest::CheckCoincidence( 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(app); - continue; + return mobile_apis::Result::DUPLICATE_NAME; } } // End vr check @@ -1056,12 +1085,44 @@ mobile_apis::Result::eType RegisterAppInterfaceRequest::CheckCoincidence( } // 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 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 636175c56f..d5e001b7ac 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 @@ -83,6 +83,8 @@ 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 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"; @@ -102,6 +104,7 @@ class RegisterAppInterfaceRequestTest , 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()) { @@ -141,6 +144,9 @@ class RegisterAppInterfaceRequestTest 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, 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)); @@ -190,6 +196,8 @@ class RegisterAppInterfaceRequestTest 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( @@ -260,6 +268,8 @@ class RegisterAppInterfaceRequestTest 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; @@ -313,6 +323,9 @@ TEST_F(RegisterAppInterfaceRequestTest, Run_MinimalData_SUCCESS) { 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)); @@ -432,6 +445,9 @@ TEST_F(RegisterAppInterfaceRequestTest, 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(kAppId1, _, _)) .WillByDefault(Return(true)); @@ -622,6 +638,9 @@ TEST_F(RegisterAppInterfaceRequestTest, 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(); @@ -659,6 +678,9 @@ TEST_F(RegisterAppInterfaceRequestTest, 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; |