From fd89eef7fe4ffa530aa07ab6fcd9411e3a802327 Mon Sep 17 00:00:00 2001 From: Kozoriz Date: Thu, 1 Dec 2016 17:06:49 +0200 Subject: Add using of active hmi language in case requested does not exists SDL must use language which has been received via UI.GetLanguage responce from HMI Updated policy_manager, cache_manager for external_policy Added processing of active hmi language to cache_mamanager impl. Fixed defect : APPLINK-30398 --- .../src/policies/policy_handler.cc | 12 ++++- .../policy/policy_external/policy/policy_manager.h | 3 +- .../policy_external/include/policy/cache_manager.h | 8 +++- .../include/policy/cache_manager_interface.h | 3 +- .../include/policy/policy_manager_impl.h | 3 +- .../policy/policy_external/src/cache_manager.cc | 56 +++++++++++++--------- .../policy_external/src/policy_manager_impl.cc | 7 ++- 7 files changed, 61 insertions(+), 31 deletions(-) diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index 826e541795..ea2e390594 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -583,8 +583,18 @@ void PolicyHandler::OnGetUserFriendlyMessage( uint32_t correlation_id) { LOG4CXX_AUTO_TRACE(logger_); POLICY_LIB_CHECK_VOID(); - std::vector result = + +#ifdef EXTERNAL_PROPRIETARY + const std::string active_hmi_language = + application_manager::MessageHelper::CommonLanguageToString( + application_manager_.hmi_capabilities().active_ui_language()); + const std::vector result = + policy_manager_->GetUserFriendlyMessages( + message_codes, language, active_hmi_language); +#else + const std::vector result = policy_manager_->GetUserFriendlyMessages(message_codes, language); +#endif // EXTERNAL_PROPRIETARY // Send response to HMI with gathered data MessageHelper::SendGetUserFriendlyMessageResponse( result, correlation_id, application_manager_); diff --git a/src/components/include/policy/policy_external/policy/policy_manager.h b/src/components/include/policy/policy_external/policy/policy_manager.h index 8ff0154a7c..cc47e4f226 100644 --- a/src/components/include/policy/policy_external/policy/policy_manager.h +++ b/src/components/include/policy/policy_external/policy/policy_manager.h @@ -281,7 +281,8 @@ class PolicyManager : public usage_statistics::StatisticsManager { */ virtual std::vector GetUserFriendlyMessages( const std::vector& message_code, - const std::string& language) = 0; + const std::string& language, + const std::string& active_hmi_language) = 0; /** * Checks if the application is revoked diff --git a/src/components/policy/policy_external/include/policy/cache_manager.h b/src/components/policy/policy_external/include/policy/cache_manager.h index 522ec35575..cfe5224abe 100644 --- a/src/components/policy/policy_external/include/policy/cache_manager.h +++ b/src/components/policy/policy_external/include/policy/cache_manager.h @@ -145,11 +145,15 @@ class CacheManager : public CacheManagerInterface { * dependent on language and context. * @param msg_codes Context of message (Driver distraction, Grant permission * etc) - * @param language Language of the message + * @param language Requested language of the message + * @param active_hmi_language Last language has been received + * via UI.GetLanguage (used as first fallback language) * @return Array of appropriate messages parameters */ std::vector GetUserFriendlyMsg( - const std::vector& msg_codes, const std::string& language); + const std::vector& msg_codes, + const std::string& language, + const std::string& active_hmi_language); /** * @brief GetLockScreenIcon allows to obtain lock screen icon url; diff --git a/src/components/policy/policy_external/include/policy/cache_manager_interface.h b/src/components/policy/policy_external/include/policy/cache_manager_interface.h index c9c4e3103b..a91fefb1dc 100644 --- a/src/components/policy/policy_external/include/policy/cache_manager_interface.h +++ b/src/components/policy/policy_external/include/policy/cache_manager_interface.h @@ -144,7 +144,8 @@ class CacheManagerInterface { */ virtual std::vector GetUserFriendlyMsg( const std::vector& msg_codes, - const std::string& language) = 0; + const std::string& language, + const std::string& active_hmi_language) = 0; /** * @brief Get list of URL to send PTS to diff --git a/src/components/policy/policy_external/include/policy/policy_manager_impl.h b/src/components/policy/policy_external/include/policy/policy_manager_impl.h index 2fcf523e34..fee07c1b41 100644 --- a/src/components/policy/policy_external/include/policy/policy_manager_impl.h +++ b/src/components/policy/policy_external/include/policy/policy_manager_impl.h @@ -118,7 +118,8 @@ class PolicyManagerImpl : public PolicyManager { virtual std::vector GetUserFriendlyMessages( const std::vector& message_code, - const std::string& language); + const std::string& language, + const std::string& active_hmi_language); virtual bool IsApplicationRevoked(const std::string& app_id) const; diff --git a/src/components/policy/policy_external/src/cache_manager.cc b/src/components/policy/policy_external/src/cache_manager.cc index 43ab80c586..12d5c0d172 100644 --- a/src/components/policy/policy_external/src/cache_manager.cc +++ b/src/components/policy/policy_external/src/cache_manager.cc @@ -82,6 +82,16 @@ struct LanguageFinder { const std::string& language_; }; +policy_table::MessageString FindLanguage( + const policy_table::MessageLanguages& msg_languages, + const std::string& lang) { + LanguageFinder finder(lang); + policy_table::Languages::const_iterator it = std::find_if( + msg_languages.languages.begin(), msg_languages.languages.end(), finder); + return (msg_languages.languages.end() == it) ? policy_table::MessageString() + : it->second; +} + CacheManager::CacheManager() : CacheManagerInterface() , pt_(new policy_table::Table) @@ -1088,7 +1098,9 @@ const policy::VehicleInfo CacheManager::GetVehicleInfo() const { } std::vector CacheManager::GetUserFriendlyMsg( - const std::vector& msg_codes, const std::string& language) { + const std::vector& msg_codes, + const std::string& language, + const std::string& active_hmi_language) { LOG4CXX_AUTO_TRACE(logger_); std::vector result; CACHE_MANAGER_CHECK(result); @@ -1099,36 +1111,34 @@ std::vector CacheManager::GetUserFriendlyMsg( policy_table::MessageLanguages msg_languages = (*pt_->policy_table.consumer_friendly_messages->messages)[*it]; - policy_table::MessageString message_string; - // If message has no records with required language, fallback language // should be used instead. - LanguageFinder finder(language); - policy_table::Languages::const_iterator it_language = std::find_if( - msg_languages.languages.begin(), msg_languages.languages.end(), finder); + policy_table::MessageString message_string = + FindLanguage(msg_languages, language); - if (msg_languages.languages.end() == it_language) { + if (!message_string.is_valid()) { LOG4CXX_WARN(logger_, "Language " << language << " haven't been found for message code: " << *it); - - LanguageFinder fallback_language_finder("en-us"); - - policy_table::Languages::const_iterator it_fallback_language = - std::find_if(msg_languages.languages.begin(), - msg_languages.languages.end(), - fallback_language_finder); - - if (msg_languages.languages.end() == it_fallback_language) { - LOG4CXX_ERROR(logger_, - "No fallback language found for message code: " << *it); - continue; + policy_table::MessageString active_hmi_language_message_string = + FindLanguage(msg_languages, active_hmi_language); + if (!active_hmi_language_message_string.is_valid()) { + LOG4CXX_WARN(logger_, + "Active hmi language " + << active_hmi_language + << " haven't been found for message code: " << *it); + + policy_table::MessageString fallback_message_string = + FindLanguage(msg_languages, "en-us"); + if (!fallback_message_string.is_valid()) { + LOG4CXX_ERROR(logger_, + "No fallback language found for message code: " << *it); + continue; + } + message_string = fallback_message_string; } - - message_string = it_fallback_language->second; - } else { - message_string = it_language->second; + message_string = active_hmi_language_message_string; } UserFriendlyMessage msg; diff --git a/src/components/policy/policy_external/src/policy_manager_impl.cc b/src/components/policy/policy_external/src/policy_manager_impl.cc index 65cac9d289..7fdcf60ccc 100644 --- a/src/components/policy/policy_external/src/policy_manager_impl.cc +++ b/src/components/policy/policy_external/src/policy_manager_impl.cc @@ -772,8 +772,11 @@ bool PolicyManagerImpl::GetPriority(const std::string& policy_app_id, } std::vector PolicyManagerImpl::GetUserFriendlyMessages( - const std::vector& message_code, const std::string& language) { - return cache_->GetUserFriendlyMsg(message_code, language); + const std::vector& message_code, + const std::string& language, + const std::string& active_hmi_language) { + return cache_->GetUserFriendlyMsg( + message_code, language, active_hmi_language); } void PolicyManagerImpl::GetUserConsentForApp( -- cgit v1.2.1 From d6a9ecbd08996820569a8452797e268155f24d4b Mon Sep 17 00:00:00 2001 From: Kozoriz Date: Thu, 1 Dec 2016 17:54:47 +0200 Subject: Update tests according new functionality Updated mocks classes and their usage in tests Related task : APPLINK-30398 --- .../application_manager/test/policy_handler_test.cc | 18 ++++++++++++++++++ .../policy_external/policy/mock_policy_manager.h | 5 +++-- .../test/include/policy/mock_cache_manager.h | 5 +++-- .../test/policy_manager_impl_user_consent_test.cc | 4 +++- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/components/application_manager/test/policy_handler_test.cc b/src/components/application_manager/test/policy_handler_test.cc index 63c9227359..b5be5b15ac 100644 --- a/src/components/application_manager/test/policy_handler_test.cc +++ b/src/components/application_manager/test/policy_handler_test.cc @@ -66,6 +66,7 @@ #include "application_manager/policies/mock_policy_handler_observer.h" #include "application_manager/mock_event_dispatcher.h" #include "application_manager/mock_state_controller.h" +#include "application_manager/mock_hmi_capabilities.h" namespace test { namespace components { @@ -114,6 +115,7 @@ class PolicyHandlerTest : public ::testing::Test { utils::SharedPtr mock_policy_manager_; application_manager_test::MockApplicationManager app_manager_; MockMessageHelper& mock_message_helper_; + application_manager_test::MockHMICapabilities mock_hmi_capabilities_; const std::string kPolicyAppId_; const std::string kMacAddr_; const std::string kDeviceId_; @@ -880,9 +882,25 @@ TEST_F(PolicyHandlerTest, OnGetUserFriendlyMessage) { std::vector message_codes; const std::string language("ru-ru"); const uint32_t correlation_id = 2; +#ifdef EXTERNAL_PROPRIETARY + const hmi_apis::Common_Language::eType default_language = + hmi_apis::Common_Language::EN_US; + const std::string default_language_string = "EN_US"; + EXPECT_CALL(app_manager_, hmi_capabilities()) + .WillOnce(ReturnRef(mock_hmi_capabilities_)); + EXPECT_CALL(mock_message_helper_, CommonLanguageToString(default_language)) + .WillOnce(Return(default_language_string)); + EXPECT_CALL(mock_hmi_capabilities_, active_ui_language()) + .WillOnce(Return(default_language)); + EXPECT_CALL( + *mock_policy_manager_, + GetUserFriendlyMessages(message_codes, language, default_language_string)) + .WillOnce(Return(std::vector())); +#else EXPECT_CALL(*mock_policy_manager_, GetUserFriendlyMessages(message_codes, language)) .WillOnce(Return(std::vector())); +#endif // EXTERNAL_PROPRIETARY EXPECT_CALL(mock_message_helper_, SendGetUserFriendlyMessageResponse(_, _, _)); // Act diff --git a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h index e522c6801e..0a0471af40 100644 --- a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h +++ b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h @@ -116,10 +116,11 @@ class MockPolicyManager : public PolicyManager { MOCK_CONST_METHOD2(GetPriority, bool(const std::string& policy_app_id, std::string* priority)); - MOCK_METHOD2(GetUserFriendlyMessages, + MOCK_METHOD3(GetUserFriendlyMessages, std::vector( const std::vector& message_code, - const std::string& language)); + const std::string& language, + const std::string& active_hmi_language)); MOCK_CONST_METHOD1(IsApplicationRevoked, bool(const std::string& app_id)); MOCK_METHOD3( GetPermissionsForApp, diff --git a/src/components/policy/policy_external/test/include/policy/mock_cache_manager.h b/src/components/policy/policy_external/test/include/policy/mock_cache_manager.h index 518209d8fc..af528a4c24 100644 --- a/src/components/policy/policy_external/test/include/policy/mock_cache_manager.h +++ b/src/components/policy/policy_external/test/include/policy/mock_cache_manager.h @@ -83,10 +83,11 @@ class MockCacheManagerInterface : public ::policy::CacheManagerInterface { MOCK_CONST_METHOD1(GetCachedDeviceConsent, DeviceConsent(const std::string& device_id)); MOCK_METHOD1(SetVINValue, bool(const std::string& value)); - MOCK_METHOD2(GetUserFriendlyMsg, + MOCK_METHOD3(GetUserFriendlyMsg, std::vector( const std::vector& msg_codes, - const std::string& language)); + const std::string& language, + const std::string& active_hmi_language)); MOCK_METHOD2(GetUpdateUrls, void(const std::string& service_type, EndpointUrls& out_end_points)); diff --git a/src/components/policy/policy_external/test/policy_manager_impl_user_consent_test.cc b/src/components/policy/policy_external/test/policy_manager_impl_user_consent_test.cc index 3e0935cb55..be266a3a03 100644 --- a/src/components/policy/policy_external/test/policy_manager_impl_user_consent_test.cc +++ b/src/components/policy/policy_external/test/policy_manager_impl_user_consent_test.cc @@ -368,8 +368,10 @@ TEST_F(PolicyManagerImplTest2, message_code.push_back("SettingEnableUpdates"); message_code.push_back("AppPermissions"); const std::string language = "en-us"; + const std::string active_hmi_language = language; std::vector< ::policy::UserFriendlyMessage> result = - manager_->GetUserFriendlyMessages(message_code, language); + manager_->GetUserFriendlyMessages( + message_code, language, active_hmi_language); uint32_t size = result.size(); EXPECT_GT(size, 0u); std::vector< ::policy::UserFriendlyMessage>::iterator result_iter; -- cgit v1.2.1 From 5ce8496c7164c341505a131e9c2b87f4f20c0ee5 Mon Sep 17 00:00:00 2001 From: Kozoriz Date: Mon, 5 Dec 2016 08:36:08 +0200 Subject: Fix coding style fixed coding style in file which was not buildable. --- .../policy/policy_external/test/sql_pt_representation_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/policy/policy_external/test/sql_pt_representation_test.cc b/src/components/policy/policy_external/test/sql_pt_representation_test.cc index bc6249018e..ebc3080169 100644 --- a/src/components/policy/policy_external/test/sql_pt_representation_test.cc +++ b/src/components/policy/policy_external/test/sql_pt_representation_test.cc @@ -1095,7 +1095,7 @@ TEST(SQLPTRepresentationTest3, Init_TryInitNotExistingDataBase_ExpectResultFail) { // Arrange NiceMock policy_settings_; - const std::string not_existing_path = "/not/existing/path" + const std::string not_existing_path = "/not/existing/path"; ON_CALL(policy_settings_, app_storage_folder()) .WillByDefault(ReturnRef(not_existing_path)); SQLPTRepresentation reps; -- cgit v1.2.1